akaunting/app/Reports/ExpenseSummary.php

63 lines
1.6 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Reports;
2019-11-23 21:47:20 +03:00
use App\Abstracts\Report;
2019-11-16 10:21:14 +03:00
use App\Models\Banking\Transaction;
2019-12-31 15:49:09 +03:00
use App\Models\Purchase\Bill;
2019-11-16 10:21:14 +03:00
use App\Utilities\Recurring;
class ExpenseSummary extends Report
{
public $icon = 'fa fa-shopping-cart';
public $chart = [
'line' => [
'width' => '0',
'height' => '300',
'options' => [
2020-01-02 15:20:20 +03:00
'color' => '#ef3232',
2020-01-02 15:36:27 +03:00
'legend' => [
'display' => false,
],
2019-11-16 10:21:14 +03:00
],
'backgroundColor' => '#ef3232',
'color' => '#ef3232',
],
];
2020-01-04 13:42:58 +03:00
public function getDefaultName()
2019-11-16 10:21:14 +03:00
{
return trans('reports.summary.expense');
}
2020-01-04 13:42:58 +03:00
public function getCategory()
{
return trans('reports.income_expense');
}
2019-11-16 10:21:14 +03:00
public function getTotals()
{
$payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) {
case 'cash':
// Payments
$this->setTotals($payments, 'paid_at');
break;
default:
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at');
// Payments
Recurring::reflect($payments, 'payment', 'paid_at');
$this->setTotals($payments, 'paid_at');
break;
}
}
}