From a7a89ff28bb422a86ed1d94347db157fd2854f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 4 Aug 2022 12:09:54 +0300 Subject: [PATCH] fixed financial year filter --- app/Abstracts/Listeners/Report.php | 23 ++++++++++++++++++++++- app/Traits/DateTime.php | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/Listeners/Report.php b/app/Abstracts/Listeners/Report.php index eee1f4715..e5a02b2cb 100644 --- a/app/Abstracts/Listeners/Report.php +++ b/app/Abstracts/Listeners/Report.php @@ -40,11 +40,32 @@ abstract class Report { $now = Date::now(); + $financial_start = setting('localisation.financial_start'); + $setting = explode('-', $financial_start); + $financial_start_day = ! empty($setting[0]) ? $setting[0] : '01'; + + $format = ($financial_start == '01-01') + ? $this->getYearlyDateFormat() + : (($financial_start_day != '01') ? $this->getDailyDateFormat() : $this->getMonthlyDateFormat()); + $years = []; $y = $now->addYears(2); + for ($i = 0; $i < 10; $i++) { - $years[$y->year] = $y->year; + $financial_year = $this->getFinancialYear($y->year); + + if ($financial_start == '01-01') { + $title = $financial_year->getStartDate()->copy()->format($format); + } else { + $start = $financial_year->getStartDate()->copy()->format($format); + $end = $financial_year->getEndDate()->copy()->format($format); + + $title = $start . ' - ' . $end; + } + + $years[$y->year] = $title; + $y->subYear(); } diff --git a/app/Traits/DateTime.php b/app/Traits/DateTime.php index 07a76487a..e6fe60e7c 100644 --- a/app/Traits/DateTime.php +++ b/app/Traits/DateTime.php @@ -189,6 +189,13 @@ trait DateTime return $date_picker_shortcuts; } + public function getDailyDateFormat($year = null) + { + $format = 'd M Y'; + + return $format; + } + public function getMonthlyDateFormat($year = null) { $format = 'M Y';