mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 23:22:52 +01:00
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Ninja\Reports;
|
|
|
|
use Auth;
|
|
use App\Models\Client;
|
|
|
|
class ClientReport extends AbstractReport
|
|
{
|
|
public $columns = [
|
|
'client',
|
|
'amount',
|
|
'paid',
|
|
'balance',
|
|
];
|
|
|
|
public function run()
|
|
{
|
|
$account = Auth::user()->account;
|
|
|
|
$clients = Client::scope()
|
|
->withArchived()
|
|
->with('contacts')
|
|
->with(['invoices' => function($query) {
|
|
$query->where('invoice_date', '>=', $this->startDate)
|
|
->where('invoice_date', '<=', $this->endDate)
|
|
->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
|
|
->where('is_recurring', '=', false)
|
|
->withArchived();
|
|
}]);
|
|
|
|
foreach ($clients->get() as $client) {
|
|
$amount = 0;
|
|
$paid = 0;
|
|
|
|
foreach ($client->invoices as $invoice) {
|
|
$amount += $invoice->amount;
|
|
$paid += $invoice->getAmountPaid();
|
|
}
|
|
|
|
$this->data[] = [
|
|
$this->isExport ? $client->getDisplayName() : $client->present()->link,
|
|
$account->formatMoney($amount, $client),
|
|
$account->formatMoney($paid, $client),
|
|
$account->formatMoney($amount - $paid, $client)
|
|
];
|
|
|
|
$this->addToTotals($client->currency_id, 'amount', $amount);
|
|
$this->addToTotals($client->currency_id, 'paid', $paid);
|
|
$this->addToTotals($client->currency_id, 'balance', $amount - $paid);
|
|
}
|
|
}
|
|
}
|