akaunting/app/Reports/ExpenseSummary.php

57 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
{
2020-01-16 15:39:37 +03:00
public $default_name = 'reports.summary.expense';
2019-11-16 10:21:14 +03:00
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-29 01:06:12 +03:00
public function setData()
2019-11-16 10:21:14 +03:00
{
2020-06-06 21:47:02 +03:00
$transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
2019-11-16 10:21:14 +03:00
2020-06-12 13:38:58 +03:00
switch ($this->getSetting('basis')) {
2019-11-16 10:21:14 +03:00
case 'cash':
// Payments
2020-01-27 22:41:08 +03:00
$payments = $transactions->get();
2019-11-16 10:21:14 +03:00
$this->setTotals($payments, 'paid_at');
break;
default:
// Bills
2020-06-07 12:11:37 +03:00
$bills = $this->applyFilters(Bill::with('recurring', 'transactions')->accrued(), ['date_field' => 'billed_at'])->get();
2020-01-18 13:11:19 +03:00
Recurring::reflect($bills, 'billed_at');
2019-11-16 10:21:14 +03:00
$this->setTotals($bills, 'billed_at');
// Payments
2020-01-27 22:41:08 +03:00
$payments = $transactions->isNotDocument()->get();
2020-01-18 13:11:19 +03:00
Recurring::reflect($payments, 'paid_at');
2019-11-16 10:21:14 +03:00
$this->setTotals($payments, 'paid_at');
break;
}
}
}