mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-10 03:34:37 -04:00
Added credit report
This commit is contained in:
parent
49815448df
commit
1e0c46d9ba
@ -75,6 +75,7 @@ class ReportController extends BaseController
|
|||||||
'activity',
|
'activity',
|
||||||
'aging',
|
'aging',
|
||||||
'client',
|
'client',
|
||||||
|
'credit',
|
||||||
'document',
|
'document',
|
||||||
'expense',
|
'expense',
|
||||||
'invoice',
|
'invoice',
|
||||||
|
59
app/Ninja/Reports/CreditReport.php
Normal file
59
app/Ninja/Reports/CreditReport.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ninja\Reports;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use Auth;
|
||||||
|
|
||||||
|
class CreditReport extends AbstractReport
|
||||||
|
{
|
||||||
|
public function getColumns()
|
||||||
|
{
|
||||||
|
$columns = [
|
||||||
|
'client' => [],
|
||||||
|
'amount' => [],
|
||||||
|
'balance' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$account = Auth::user()->account;
|
||||||
|
|
||||||
|
$clients = Client::scope()
|
||||||
|
->orderBy('name')
|
||||||
|
->withArchived()
|
||||||
|
->with(['credits' => function ($query) {
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $amount && ! $balance) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = [
|
||||||
|
$this->isExport ? $client->getDisplayName() : $client->present()->link,
|
||||||
|
$account->formatMoney($amount, $client),
|
||||||
|
$account->formatMoney($balance, $client),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->data[] = $row;
|
||||||
|
|
||||||
|
$this->addToTotals($client->currency_id, 'amount', $amount);
|
||||||
|
$this->addToTotals($client->currency_id, 'balance', $balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user