From fa487e7f921bf6b08947c26c09ca9aa96a175a5b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 17 Jul 2023 18:43:56 +1000 Subject: [PATCH] Add this year / last year --- app/Export/CSV/BaseExport.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index fe876bf989ad..31583b000bf2 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -734,6 +734,19 @@ class BaseExport if(now()->lt($fin_year_start)) $fin_year_start->subYearNoOverflow(); + $this->start_date = $fin_year_start->format('Y-m-d'); + $this->end_date = $fin_year_start->copy()->addYear()->subDay()->format('Y-m-d'); + return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC'); + case 'last_year': + + $first_month_of_year = $this->company->getSetting('first_month_of_year') ?? 1; + $fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1); + + $fin_year_start->subYearNoOverflow(); + + if(now()->subYear()->lt($fin_year_start)) + $fin_year_start->subYearNoOverflow(); + $this->start_date = $fin_year_start->format('Y-m-d'); $this->end_date = $fin_year_start->copy()->addYear()->subDay()->format('Y-m-d'); return $query->whereBetween($this->date_key, [now()->startOfYear(), now()])->orderBy($this->date_key, 'ASC');