opp dashlets fiscal year filters

This commit is contained in:
yuri
2018-12-18 15:13:40 +02:00
parent 3175ff9a76
commit 35076148cc
5 changed files with 36 additions and 5 deletions
@@ -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"
}
@@ -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"
}
@@ -18,7 +18,7 @@
},
"dateFilter": {
"type": "enum",
"options": ["currentYear", "currentQuarter", "between"],
"options": ["currentYear", "currentQuarter", "currentFiscalYear", "currentFiscalQuarter", "between"],
"default": "currentYear",
"translation": "Global.options.dateSearchRanges"
}
@@ -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"
},
@@ -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];
}