diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 6a121f0a8..e99744209 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -371,7 +371,15 @@ abstract class Report { switch ($this->getSetting('period')) { case 'yearly': - $i = $date->copy()->format($this->getYearlyDateFormat()); + $financial_year = $this->getFinancialYear($this->year); + + if ($date->greaterThanOrEqualTo($financial_year->getStartDate()) && $date->lessThanOrEqualTo($financial_year->getEndDate())) { + if (setting('localisation.financial_year_denote') == 'begins') { + $i = $financial_year->getStartDate()->copy()->format($this->getYearlyDateFormat()); + } else { + $i = $financial_year->getEndDate()->copy()->format($this->getYearlyDateFormat()); + } + } break; case 'quarterly': diff --git a/app/Http/Controllers/Settings/Localisation.php b/app/Http/Controllers/Settings/Localisation.php index 6f4b1f709..b538d865e 100644 --- a/app/Http/Controllers/Settings/Localisation.php +++ b/app/Http/Controllers/Settings/Localisation.php @@ -41,12 +41,18 @@ class Localisation extends Controller 'both' => trans('settings.localisation.discount_location.both'), ]; + $financial_year_denote_options = [ + 'begins' => trans('settings.localisation.financial_year_denote.begins'), + 'ends' => trans('settings.localisation.financial_year_denote.ends'), + ]; + return view('settings.localisation.edit', compact( 'timezones', 'date_formats', 'date_separators', 'percent_positions', - 'discount_locations' + 'discount_locations', + 'financial_year_denote_options' )); } } diff --git a/app/Traits/DateTime.php b/app/Traits/DateTime.php index 0f3fbe5ea..6bcaa4fe8 100644 --- a/app/Traits/DateTime.php +++ b/app/Traits/DateTime.php @@ -110,14 +110,20 @@ trait DateTime $financial_start = Date::create($year, $month, $day); - // Check if FS is in last calendar year - if ($now->diffInDays($financial_start, false) > 0) { + if (setting('localisation.financial_year_denote') == 'ends' && $financial_start->dayOfYear != 1) { $financial_start->subYear(); } return $financial_start; } + public function getFinancialYear($year = null) + { + $start = $this->getFinancialStart($year); + + return CarbonPeriod::create($start, $start->copy()->addYear()->subDay()); + } + public function getFinancialQuarters($year = null) { $quarters = []; diff --git a/config/setting.php b/config/setting.php index 6e4eb2620..ef2537a45 100644 --- a/config/setting.php +++ b/config/setting.php @@ -103,6 +103,7 @@ return [ 'date_separator' => env('SETTING_FALLBACK_LOCALISATION_DATE_SEPARATOR', 'space'), 'percent_position' => env('SETTING_FALLBACK_LOCALISATION_PERCENT_POSITION', 'after'), 'discount_location' => env('SETTING_FALLBACK_LOCALISATION_DISCOUNT_LOCATION', 'total'), + 'financial_year_denote' => env('SETTING_FALLBACK_LOCALISATION_FINANCIAL_YEAR_DENOTE', 'ends'), ], 'invoice' => [ 'number_prefix' => env('SETTING_FALLBACK_INVOICE_NUMBER_PREFIX', 'INV-'), diff --git a/resources/lang/en-GB/settings.php b/resources/lang/en-GB/settings.php index 36a5920ed..c5bf423e3 100644 --- a/resources/lang/en-GB/settings.php +++ b/resources/lang/en-GB/settings.php @@ -36,6 +36,11 @@ return [ 'total' => 'At total', 'both' => 'Both line and total', ], + 'financial_year_denote' => [ + 'title' => 'Financial Year Denote', + 'begins' => 'By the year it begins', + 'ends' => 'By the year it ends', + ], ], 'invoice' => [ diff --git a/resources/lang/tr-TR/settings.php b/resources/lang/tr-TR/settings.php index 921bf64e5..b2bc9bf44 100644 --- a/resources/lang/tr-TR/settings.php +++ b/resources/lang/tr-TR/settings.php @@ -35,6 +35,11 @@ return [ 'total' => 'Toplamda', 'both' => 'Satırda ve toplamda', ], + 'financial_year_denote' => [ + 'title' => 'Mali Yıl Gösterimi', + 'begins' => 'Başlangıç Yılı', + 'ends' => 'Bitiş Yılı', + ], ], 'invoice' => [ diff --git a/resources/views/settings/localisation/edit.blade.php b/resources/views/settings/localisation/edit.blade.php index 4d825715e..29f588924 100644 --- a/resources/views/settings/localisation/edit.blade.php +++ b/resources/views/settings/localisation/edit.blade.php @@ -20,6 +20,8 @@