mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 23:22:52 +01:00
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Ninja\Reports;
|
||
|
|
||
|
use Auth;
|
||
|
use Utils;
|
||
|
use App\Models\Expense;
|
||
|
|
||
|
class ExpenseReport extends AbstractReport
|
||
|
{
|
||
|
public $columns = [
|
||
|
'vendor',
|
||
|
'client',
|
||
|
'date',
|
||
|
'category',
|
||
|
'expense_amount',
|
||
|
];
|
||
|
|
||
|
public function run()
|
||
|
{
|
||
|
$account = Auth::user()->account;
|
||
|
|
||
|
$expenses = Expense::scope()
|
||
|
->withArchived()
|
||
|
->with('client.contacts', 'vendor')
|
||
|
->where('expense_date', '>=', $this->startDate)
|
||
|
->where('expense_date', '<=', $this->endDate);
|
||
|
|
||
|
foreach ($expenses->get() as $expense) {
|
||
|
$amount = $expense->amountWithTax();
|
||
|
|
||
|
$this->data[] = [
|
||
|
$expense->vendor ? ($this->isExport ? $expense->vendor->name : $expense->vendor->present()->link) : '',
|
||
|
$expense->client ? ($this->isExport ? $expense->client->getDisplayName() : $expense->client->present()->link) : '',
|
||
|
$expense->present()->expense_date,
|
||
|
$expense->present()->category,
|
||
|
Utils::formatMoney($amount, $expense->currency_id),
|
||
|
];
|
||
|
|
||
|
$this->addToTotals($expense->expense_currency_id, 'amount', $amount);
|
||
|
$this->addToTotals($expense->invoice_currency_id, 'amount', 0);
|
||
|
}
|
||
|
}
|
||
|
}
|