Skip to content

Commit

Permalink
quarterly based reports should consider financial year start
Browse files Browse the repository at this point in the history
  • Loading branch information
sevannerse committed Feb 5, 2021
1 parent 74ee6fd commit db11b0c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions app/Abstracts/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Traits\DateTime;
use App\Traits\SearchString;
use App\Utilities\Chartjs;
use Carbon\CarbonPeriod;
use Date;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -388,15 +389,26 @@ public function getFormattedDate($date)
switch ($this->getSetting('period')) {
case 'yearly':
$i = $date->copy()->format($this->getYearlyDateFormat());

break;
case 'quarterly':
$start = $date->copy()->startOfQuarter()->format($this->getQuarterlyDateFormat($this->year));
$end = $date->copy()->endOfQuarter()->format($this->getQuarterlyDateFormat($this->year));
$quarters = $this->getFiscalBaseQuarters($this->year);

foreach ($quarters as $quarter) {
if ($date->lessThan($quarter->getStartDate()) || $date->greaterThan($quarter->getEndDate())) {
continue;
}

$start = $quarter->getStartDate()->format($this->getQuarterlyDateFormat($this->year));
$end = $quarter->getEndDate()->format($this->getQuarterlyDateFormat($this->year));
}

$i = $start . '-' . $end;

break;
default:
$i = $date->copy()->format($this->getMonthlyDateFormat($this->year));

break;
}

Expand Down Expand Up @@ -502,4 +514,16 @@ public function getChartField()
],
];
}

private function getFiscalBaseQuarters($year)
{
$periods = [];
$fiscal_start = $this->getFinancialStart($year);

for ($i = 0; $i < 4; $i++) {
$periods[] = CarbonPeriod::create($fiscal_start->copy()->addQuarters($i), $fiscal_start->copy()->addQuarters($i + 1)->subDay());
}

return $periods;
}
}

0 comments on commit db11b0c

Please sign in to comment.