diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index fd6ef9bd58..b25e7a61e8 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -1316,7 +1316,7 @@ class BaseExport return $query->whereBetween($this->date_key, [now()->subDays(365), now()])->orderBy($this->date_key, 'ASC'); case 'this_year': - $first_month_of_year = $this->company->getSetting('first_month_of_year') ?? 1; + $first_month_of_year = $this->company->first_month_of_year ?? 1; $fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1); if (now()->lt($fin_year_start)) { @@ -1328,7 +1328,7 @@ class BaseExport return $query->whereBetween($this->date_key, [$this->start_date, $this->end_date])->orderBy($this->date_key, 'ASC'); case 'last_year': - $first_month_of_year = $this->company->getSetting('first_month_of_year') ?? 1; + $first_month_of_year = $this->company->first_month_of_year ?? 1; $fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1); $fin_year_start->subYearNoOverflow(); diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index b7793771c0..af6f19c7a5 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -83,11 +83,7 @@ class ProfitLoss */ - protected array $payload; - - protected Company $company; - - public function __construct(Company $company, array $payload) + public function __construct(protected Company $company, protected array $payload) { $this->currency_api = new CurrencyApi(); @@ -631,13 +627,32 @@ class ProfitLoss break; case 'last_year': - $this->start_date = (new \Carbon\Carbon('-1 year'))->startOfYear(); - $this->end_date = (new \Carbon\Carbon('-1 year'))->endOfYear(); + + $first_month_of_year = $this->company->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'); + break; case 'this_year': - $this->start_date = now()->startOfYear(); - $this->end_date = now(); + + $first_month_of_year = $this->company->first_month_of_year ?? 1; + $fin_year_start = now()->createFromDate(now()->year, $first_month_of_year, 1); + + 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'); + break; case 'custom':