mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix to make sure that the index respects the fiscal year.
This commit is contained in:
parent
f80de95bb0
commit
aeab5f0333
@ -52,7 +52,7 @@ class FiscalHelper implements FiscalHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function endOfFiscalYear(Carbon $date): Carbon
|
public function endOfFiscalYear(Carbon $date): Carbon
|
||||||
{
|
{
|
||||||
// get start of fiscal year for passed date
|
Log::debug(sprintf('Now in endOfFiscalYear(%s).', $date->format('Y-m-d')));
|
||||||
$endDate = $this->startOfFiscalYear($date);
|
$endDate = $this->startOfFiscalYear($date);
|
||||||
if (true === $this->useCustomFiscalYear) {
|
if (true === $this->useCustomFiscalYear) {
|
||||||
// add 1 year and sub 1 day
|
// add 1 year and sub 1 day
|
||||||
@ -62,6 +62,7 @@ class FiscalHelper implements FiscalHelperInterface
|
|||||||
if (false === $this->useCustomFiscalYear) {
|
if (false === $this->useCustomFiscalYear) {
|
||||||
$endDate->endOfYear();
|
$endDate->endOfYear();
|
||||||
}
|
}
|
||||||
|
Log::debug(sprintf('Result of endOfFiscalYear(%s) = %s', $date->format('Y-m-d'), $endDate->format('Y-m-d')));
|
||||||
|
|
||||||
return $endDate;
|
return $endDate;
|
||||||
}
|
}
|
||||||
@ -73,6 +74,12 @@ class FiscalHelper implements FiscalHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function startOfFiscalYear(Carbon $date): Carbon
|
public function startOfFiscalYear(Carbon $date): Carbon
|
||||||
{
|
{
|
||||||
|
// because PHP is stupid:
|
||||||
|
if ($date->day >= 28) {
|
||||||
|
$date->day = 28;
|
||||||
|
Log::info(sprintf('Corrected date to %s', $date->format('Y-m-d')));
|
||||||
|
}
|
||||||
|
|
||||||
// get start mm-dd. Then create a start date in the year passed.
|
// get start mm-dd. Then create a start date in the year passed.
|
||||||
$startDate = clone $date;
|
$startDate = clone $date;
|
||||||
if (true === $this->useCustomFiscalYear) {
|
if (true === $this->useCustomFiscalYear) {
|
||||||
@ -89,6 +96,8 @@ class FiscalHelper implements FiscalHelperInterface
|
|||||||
$startDate->startOfYear();
|
$startDate->startOfYear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::debug(sprintf('Result of startOfFiscalYear(%s) = %s', $date->format('Y-m-d'), $startDate->format('Y-m-d')));
|
||||||
|
|
||||||
return $startDate;
|
return $startDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Support;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -583,7 +584,6 @@ class Navigation
|
|||||||
'1W' => 'endOfWeek',
|
'1W' => 'endOfWeek',
|
||||||
'1M' => 'endOfMonth',
|
'1M' => 'endOfMonth',
|
||||||
'3M' => 'lastOfQuarter',
|
'3M' => 'lastOfQuarter',
|
||||||
'1Y' => 'endOfYear',
|
|
||||||
'custom' => 'startOfMonth', // this only happens in test situations.
|
'custom' => 'startOfMonth', // this only happens in test situations.
|
||||||
];
|
];
|
||||||
$end = clone $start;
|
$end = clone $start;
|
||||||
@ -604,6 +604,15 @@ class Navigation
|
|||||||
|
|
||||||
return $end;
|
return $end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure 1Y takes the fiscal year into account.
|
||||||
|
if ('1Y' === $range) {
|
||||||
|
/** @var FiscalHelperInterface $fiscalHelper */
|
||||||
|
$fiscalHelper = app(FiscalHelperInterface::class);
|
||||||
|
return $fiscalHelper->endOfFiscalYear($end);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
throw new FireflyException(sprintf('updateEndDate cannot handle range "%s"', $range));
|
throw new FireflyException(sprintf('updateEndDate cannot handle range "%s"', $range));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +631,6 @@ class Navigation
|
|||||||
'1W' => 'startOfWeek',
|
'1W' => 'startOfWeek',
|
||||||
'1M' => 'startOfMonth',
|
'1M' => 'startOfMonth',
|
||||||
'3M' => 'firstOfQuarter',
|
'3M' => 'firstOfQuarter',
|
||||||
'1Y' => 'startOfYear',
|
|
||||||
'custom' => 'startOfMonth', // this only happens in test situations.
|
'custom' => 'startOfMonth', // this only happens in test situations.
|
||||||
];
|
];
|
||||||
if (isset($functionMap[$range])) {
|
if (isset($functionMap[$range])) {
|
||||||
@ -641,6 +649,14 @@ class Navigation
|
|||||||
|
|
||||||
return $start;
|
return $start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure 1Y takes the fiscal year into account.
|
||||||
|
if ('1Y' === $range) {
|
||||||
|
/** @var FiscalHelperInterface $fiscalHelper */
|
||||||
|
$fiscalHelper = app(FiscalHelperInterface::class);
|
||||||
|
return $fiscalHelper->startOfFiscalYear($start);
|
||||||
|
}
|
||||||
|
|
||||||
throw new FireflyException(sprintf('updateStartDate cannot handle range "%s"', $range));
|
throw new FireflyException(sprintf('updateStartDate cannot handle range "%s"', $range));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user