2017-01-22 11:09:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Reports;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Auth;
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
class AgingReport extends AbstractReport
|
|
|
|
{
|
2018-01-21 14:53:43 +01:00
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return [
|
2018-01-23 19:32:11 +01:00
|
|
|
'client' => [],
|
|
|
|
'invoice_number' => [],
|
|
|
|
'invoice_date' => [],
|
|
|
|
'due_date' => [],
|
|
|
|
'age' => [],
|
|
|
|
'amount' => [],
|
|
|
|
'balance' => [],
|
2018-01-21 14:53:43 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
|
|
|
|
$clients = Client::scope()
|
2017-03-31 08:01:07 +02:00
|
|
|
->orderBy('name')
|
2017-01-22 11:09:29 +01:00
|
|
|
->withArchived()
|
|
|
|
->with('contacts')
|
2017-01-30 17:05:31 +01:00
|
|
|
->with(['invoices' => function ($query) {
|
2017-01-22 11:09:29 +01:00
|
|
|
$query->invoices()
|
|
|
|
->whereIsPublic(true)
|
|
|
|
->withArchived()
|
|
|
|
->where('balance', '>', 0)
|
|
|
|
->where('invoice_date', '>=', $this->startDate)
|
|
|
|
->where('invoice_date', '<=', $this->endDate)
|
|
|
|
->with(['invoice_items']);
|
|
|
|
}]);
|
|
|
|
|
|
|
|
foreach ($clients->get() as $client) {
|
|
|
|
foreach ($client->invoices as $invoice) {
|
|
|
|
$this->data[] = [
|
|
|
|
$this->isExport ? $client->getDisplayName() : $client->present()->link,
|
|
|
|
$this->isExport ? $invoice->invoice_number : $invoice->present()->link,
|
|
|
|
$invoice->present()->invoice_date,
|
2017-10-26 09:56:59 +02:00
|
|
|
$invoice->present()->partial_due_date ?: $invoice->present()->due_date,
|
2017-01-22 11:09:29 +01:00
|
|
|
$invoice->present()->age,
|
|
|
|
$account->formatMoney($invoice->amount, $client),
|
|
|
|
$account->formatMoney($invoice->balance, $client),
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->addToTotals($client->currency_id, $invoice->present()->ageGroup, $invoice->balance);
|
|
|
|
|
|
|
|
//$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);
|
|
|
|
//$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
|
|
|
|
//$this->addToTotals($client->currency_id, 'balance', $invoice->balance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|