Add totals for AR Summary Reports

This commit is contained in:
David Bomba 2023-07-24 07:42:55 +10:00
parent 8797388254
commit e0e0c238c6

View File

@ -19,7 +19,6 @@ use App\Models\Invoice;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use Carbon\Carbon;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use League\Csv\Writer; use League\Csv\Writer;
@ -33,6 +32,8 @@ class ARSummaryReport extends BaseExport
public Client $client; public Client $client;
private float $total = 0;
public array $report_keys = [ public array $report_keys = [
'client_name', 'client_name',
'client_number', 'client_number',
@ -101,7 +102,7 @@ class ARSummaryReport extends BaseExport
{ {
$this->client = $client; $this->client = $client;
return [ $row = [
$this->client->present()->name(), $this->client->present()->name(),
$this->client->number, $this->client->number,
$this->client->id_number, $this->client->id_number,
@ -111,7 +112,12 @@ class ARSummaryReport extends BaseExport
$this->getAgingAmount('90'), $this->getAgingAmount('90'),
$this->getAgingAmount('120'), $this->getAgingAmount('120'),
$this->getAgingAmount('120+'), $this->getAgingAmount('120+'),
Number::formatMoney($this->total, $this->client),
]; ];
$this->total = 0;
return $row;
} }
private function getCurrent(): string private function getCurrent(): string
@ -128,6 +134,8 @@ class ARSummaryReport extends BaseExport
}) })
->sum('balance'); ->sum('balance');
$this->total += $amount;
return Number::formatMoney($amount, $this->client); return Number::formatMoney($amount, $this->client);
} }
@ -153,6 +161,8 @@ class ARSummaryReport extends BaseExport
->whereBetween('due_date', [$to, $from]) ->whereBetween('due_date', [$to, $from])
->sum('balance'); ->sum('balance');
$this->total += $amount;
return Number::formatMoney($amount, $this->client); return Number::formatMoney($amount, $this->client);
} }