1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Ninja/Reports/CreditReport.php

66 lines
1.9 KiB
PHP
Raw Normal View History

2018-01-24 19:26:26 +01:00
<?php
namespace App\Ninja\Reports;
use App\Models\Client;
use Auth;
class CreditReport extends AbstractReport
{
public function getColumns()
{
$columns = [
'client' => [],
'amount' => [],
'balance' => [],
2018-01-26 13:11:23 +01:00
'user' => ['columnSelector-false'],
2018-01-24 19:26:26 +01:00
];
return $columns;
}
public function run()
{
$account = Auth::user()->account;
2018-02-28 13:43:15 +01:00
$subgroup = $this->options['subgroup'];
2018-01-24 19:26:26 +01:00
$clients = Client::scope()
->orderBy('name')
->withArchived()
2018-02-28 13:43:15 +01:00
->with(['contacts', 'user', 'credits' => function ($query) {
2018-01-24 19:26:26 +01:00
$query->where('credit_date', '>=', $this->startDate)
->where('credit_date', '<=', $this->endDate)
->withArchived();
}]);
foreach ($clients->get() as $client) {
$amount = 0;
$balance = 0;
foreach ($client->credits as $credit) {
$amount += $credit->amount;
$balance += $credit->balance;
2018-02-27 08:14:39 +01:00
2018-02-28 13:43:15 +01:00
$dimension = $this->getDimension($client);
$this->addChartData($dimension, $credit->credit_date, $credit->amount);
2018-01-24 19:26:26 +01:00
}
if (! $amount && ! $balance) {
continue;
}
$row = [
$this->isExport ? $client->getDisplayName() : $client->present()->link,
$account->formatMoney($amount, $client),
$account->formatMoney($balance, $client),
2018-01-26 13:11:23 +01:00
$client->user->getDisplayName(),
2018-01-24 19:26:26 +01:00
];
$this->data[] = $row;
$this->addToTotals($client->currency_id, 'amount', $amount);
$this->addToTotals($client->currency_id, 'balance', $balance);
}
}
}