akaunting/app/Reports/IncomeSummary.php

55 lines
1.4 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\Sale\Invoice;
2019-11-16 10:21:14 +03:00
use App\Utilities\Recurring;
class IncomeSummary extends Report
{
2020-01-16 15:39:37 +03:00
public $default_name = 'reports.summary.income';
2019-11-16 10:21:14 +03:00
public $icon = 'fa fa-money-bill';
public $chart = [
'line' => [
'width' => '0',
'height' => '300',
'options' => [
2020-01-02 15:20:20 +03:00
'color' => '#328aef',
2020-01-02 15:36:27 +03:00
'legend' => [
'display' => false,
],
2019-11-16 10:21:14 +03:00
],
'backgroundColor' => '#328aef',
'color' => '#328aef',
],
];
public function getTotals()
{
$transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
2019-11-16 10:21:14 +03:00
2020-01-16 15:39:37 +03:00
switch ($this->model->settings->basis) {
2019-11-16 10:21:14 +03:00
case 'cash':
// Transactions
$this->setTotals($transactions, 'paid_at');
2019-11-16 10:21:14 +03:00
break;
default:
// Invoices
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
2020-01-18 13:11:19 +03:00
Recurring::reflect($invoices, 'invoiced_at');
2019-11-16 10:21:14 +03:00
$this->setTotals($invoices, 'invoiced_at');
// Transactions
2020-01-18 13:11:19 +03:00
Recurring::reflect($transactions, 'paid_at');
$this->setTotals($transactions, 'paid_at');
2019-11-16 10:21:14 +03:00
break;
}
}
}