1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00
invoiceninja/app/Ninja/Reports/ClientReport.php
2017-01-30 18:05:31 +02:00

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);
}
}
}