Akaunting/app/Reports/IncomeSummary.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2019-11-16 07:21:14 +00:00
<?php
namespace App\Reports;
2019-11-23 18:47:20 +00:00
use App\Abstracts\Report;
2019-11-16 07:21:14 +00:00
use App\Models\Banking\Transaction;
2020-12-23 22:28:38 +00:00
use App\Models\Document\Document;
2019-11-16 07:21:14 +00:00
use App\Utilities\Recurring;
class IncomeSummary extends Report
{
2022-06-01 07:15:55 +00:00
public $default_name = 'reports.income_summary';
2020-01-16 12:39:37 +00:00
2022-06-01 07:15:55 +00:00
public $icon = 'payments';
public $type = 'summary';
2019-11-16 07:21:14 +00:00
public $chart = [
2022-06-01 07:15:55 +00:00
'bar' => [
'colors' => [
'#8bb475',
2019-11-16 07:21:14 +00:00
],
2022-06-01 07:15:55 +00:00
],
'donut' => [
//
2019-11-16 07:21:14 +00:00
],
];
2022-06-01 07:15:55 +00:00
public function setTables()
{
$this->tables = [
'income' => trans_choice('general.incomes', 1),
];
}
2020-01-28 22:06:12 +00:00
public function setData()
2019-11-16 07:21:14 +00:00
{
2020-06-06 18:47:02 +00:00
$transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
2019-11-16 07:21:14 +00:00
2022-06-01 07:15:55 +00:00
switch ($this->getBasis()) {
2019-11-16 07:21:14 +00:00
case 'cash':
2022-06-01 07:15:55 +00:00
// Incomes
$incomes = $transactions->get();
$this->setTotals($incomes, 'paid_at', false, 'income');
2019-11-16 07:21:14 +00:00
break;
default:
// Invoices
2020-12-23 22:28:38 +00:00
$invoices = $this->applyFilters(Document::invoice()->with('recurring', 'transactions')->accrued(), ['date_field' => 'issued_at'])->get();
Recurring::reflect($invoices, 'issued_at');
2022-06-01 07:15:55 +00:00
$this->setTotals($invoices, 'issued_at', false, 'income');
2019-11-16 07:21:14 +00:00
2022-06-01 07:15:55 +00:00
// Incomes
$incomes = $transactions->isNotDocument()->get();
Recurring::reflect($incomes, 'paid_at');
$this->setTotals($incomes, 'paid_at', false, 'income');
2019-11-16 07:21:14 +00:00
break;
}
}
}