1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Ninja/Reports/ExpenseReport.php
2017-03-31 09:01:07 +03:00

46 lines
1.5 KiB
PHP

<?php
namespace App\Ninja\Reports;
use App\Models\Expense;
use Auth;
use Utils;
class ExpenseReport extends AbstractReport
{
public $columns = [
'vendor',
'client',
'date',
'category',
'amount',
];
public function run()
{
$account = Auth::user()->account;
$expenses = Expense::scope()
->orderBy('expense_date', 'desc')
->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) : '',
$this->isExport ? $expense->present()->expense_date : link_to($expense->present()->url, $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);
}
}
}