From 35076148cc91e5ff4d2ab68f2b03e9b2104b6ead Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 18 Dec 2018 15:13:40 +0200 Subject: [PATCH] opp dashlets fiscal year filters --- .../dashlets/OpportunitiesByLeadSource.json | 2 +- .../dashlets/OpportunitiesByStage.json | 2 +- .../metadata/dashlets/SalesByMonth.json | 2 +- .../metadata/dashlets/SalesPipeline.json | 2 +- .../Espo/Modules/Crm/Services/Opportunity.php | 33 ++++++++++++++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByLeadSource.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByLeadSource.json index 2f1726c19f..384d3274e1 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByLeadSource.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByLeadSource.json @@ -18,7 +18,7 @@ }, "dateFilter": { "type": "enum", - "options": ["currentYear", "currentQuarter", "currentMonth", "ever", "between"], + "options": ["currentYear", "currentQuarter", "currentMonth", "currentFiscalYear", "currentFiscalQuarter", "ever", "between"], "default": "currentYear", "translation": "Global.options.dateSearchRanges" } diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByStage.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByStage.json index ef75b4ba2a..6b8b3735db 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByStage.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/OpportunitiesByStage.json @@ -18,7 +18,7 @@ }, "dateFilter": { "type": "enum", - "options": ["currentYear", "currentQuarter", "currentMonth", "ever", "between"], + "options": ["currentYear", "currentQuarter", "currentMonth", "currentFiscalYear", "currentFiscalQuarter", "ever", "between"], "default": "currentYear", "translation": "Global.options.dateSearchRanges" } diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesByMonth.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesByMonth.json index fbcef30f5b..0c51226d2a 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesByMonth.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesByMonth.json @@ -18,7 +18,7 @@ }, "dateFilter": { "type": "enum", - "options": ["currentYear", "currentQuarter", "between"], + "options": ["currentYear", "currentQuarter", "currentFiscalYear", "currentFiscalQuarter", "between"], "default": "currentYear", "translation": "Global.options.dateSearchRanges" } diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesPipeline.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesPipeline.json index 449c2dac22..fdd8722bd5 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesPipeline.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/SalesPipeline.json @@ -18,7 +18,7 @@ }, "dateFilter": { "type": "enum", - "options": ["currentYear", "currentQuarter", "currentMonth", "ever", "between"], + "options": ["currentYear", "currentQuarter", "currentMonth", "currentFiscalYear", "currentFiscalQuarter", "ever", "between"], "default": "currentYear", "translation": "Global.options.dateSearchRanges" }, diff --git a/application/Espo/Modules/Crm/Services/Opportunity.php b/application/Espo/Modules/Crm/Services/Opportunity.php index e8f2619533..a690218ee2 100644 --- a/application/Espo/Modules/Crm/Services/Opportunity.php +++ b/application/Espo/Modules/Crm/Services/Opportunity.php @@ -291,7 +291,7 @@ class Opportunity extends \Espo\Services\Record if ($dt && $dtTo) { $interval = new \DateInterval('P1M'); - while ($dt->getTimestamp() <= $dtTo->getTimestamp()) { + while ($dt->getTimestamp() < $dtTo->getTimestamp()) { $month = $dt->format('Y-m'); if (!array_key_exists($month, $result)) { $result[$month] = 0; @@ -351,6 +351,37 @@ class Opportunity extends \Espo\Services\Record $dt->modify('first day of this month')->format('Y-m-d'), $dt->add(new \DateInterval('P1M'))->format('Y-m-d') ]; + case 'currentFiscalYear': + $dtToday = new \DateTime(); + $dt = new \DateTime(); + $fiscalYearShift = $this->getConfig()->get('fiscalYearShift', 0); + $dt->modify('first day of January this year')->modify('+' . $fiscalYearShift . ' months'); + if (intval($dtToday->format('m')) < $fiscalYearShift + 1) { + $dt->modify('-1 year'); + } + return [ + $dt->format('Y-m-d'), + $dt->add(new \DateInterval('P1Y'))->format('Y-m-d') + ]; + case 'currentFiscalQuarter': + $dtToday = new \DateTime(); + $dt = new \DateTime(); + $fiscalYearShift = $this->getConfig()->get('fiscalYearShift', 0); + $dt->modify('first day of January this year')->modify('+' . $fiscalYearShift . ' months'); + $month = intval($dtToday->format('m')); + $quarterShift = floor(($month - $fiscalYearShift - 1) / 3); + if ($quarterShift) { + if ($quarterShift >= 0) { + $dt->add(new \DateInterval('P'.($quarterShift * 3).'M')); + } else { + $quarterShift *= -1; + $dt->sub(new \DateInterval('P'.($quarterShift * 3).'M')); + } + } + return [ + $dt->format('Y-m-d'), + $dt->add(new \DateInterval('P3M'))->format('Y-m-d') + ]; } return [0, 0]; }