Working on tax report

This commit is contained in:
Hillel Coren 2018-01-24 09:59:16 +02:00
parent c8a51a6265
commit 20331f2b17

View File

@ -4,6 +4,7 @@ namespace App\Ninja\Reports;
use Barracuda\ArchiveStream\Archive; use Barracuda\ArchiveStream\Archive;
use App\Models\Expense; use App\Models\Expense;
use App\Models\TaxRate;
use Auth; use Auth;
use Utils; use Utils;
@ -11,16 +12,21 @@ class ExpenseReport extends AbstractReport
{ {
public function getColumns() public function getColumns()
{ {
return [ $columns = [
'vendor' => [], 'vendor' => [],
'client' => [], 'client' => [],
'date' => [], 'date' => [],
'category' => [], 'category' => [],
'amount' => [], 'amount' => [],
'tax' => ['columnSelector-false'],
'public_notes' => ['columnSelector-false'], 'public_notes' => ['columnSelector-false'],
'private_notes' => ['columnSelector-false'], 'private_notes' => ['columnSelector-false'],
]; ];
if (TaxRate::scope()->count()) {
$columns['tax'] = ['columnSelector-false'];
}
return $columns;
} }
public function run() public function run()
@ -57,17 +63,22 @@ class ExpenseReport extends AbstractReport
foreach ($expenses->get() as $expense) { foreach ($expenses->get() as $expense) {
$amount = $expense->amountWithTax(); $amount = $expense->amountWithTax();
$this->data[] = [ $row = [
$expense->vendor ? ($this->isExport ? $expense->vendor->name : $expense->vendor->present()->link) : '', $expense->vendor ? ($this->isExport ? $expense->vendor->name : $expense->vendor->present()->link) : '',
$expense->client ? ($this->isExport ? $expense->client->getDisplayName() : $expense->client->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), $this->isExport ? $expense->present()->expense_date : link_to($expense->present()->url, $expense->present()->expense_date),
$expense->present()->category, $expense->present()->category,
Utils::formatMoney($amount, $expense->currency_id), Utils::formatMoney($amount, $expense->currency_id),
$expense->present()->taxAmount,
$expense->public_notes, $expense->public_notes,
$expense->private_notes, $expense->private_notes,
]; ];
if (TaxRate::scope()->count()) {
$row[] = $expense->present()->taxAmount;
}
$this->data[] = $row;
$this->addToTotals($expense->expense_currency_id, 'amount', $amount); $this->addToTotals($expense->expense_currency_id, 'amount', $amount);
$this->addToTotals($expense->invoice_currency_id, 'amount', 0); $this->addToTotals($expense->invoice_currency_id, 'amount', 0);
} }