FIxes for date ranges when considering 'this year in a financial year context'
This commit is contained in:
parent
9a50dcb65c
commit
1e014cf1b3
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
Loading…
Reference in New Issue