akaunting/app/Reports/IncomeExpenseSummary.php

57 lines
2.1 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;
2020-12-24 01:28:38 +03:00
use App\Models\Document\Document;
2019-11-16 10:21:14 +03:00
use App\Utilities\Recurring;
class IncomeExpenseSummary extends Report
{
2020-01-16 15:39:37 +03:00
public $default_name = 'reports.summary.income_expense';
2019-11-16 10:21:14 +03:00
2020-01-16 15:39:37 +03:00
public $icon = 'fa fa-chart-pie';
2020-01-04 13:42:58 +03:00
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
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
$expense_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':
2020-01-27 22:41:08 +03:00
// Revenues
$revenues = $income_transactions->get();
$this->setTotals($revenues, 'paid_at', true);
2019-11-16 10:21:14 +03:00
2020-01-27 22:41:08 +03:00
// Payments
$payments = $expense_transactions->get();
$this->setTotals($payments, 'paid_at', true);
2019-11-16 10:21:14 +03:00
break;
default:
// Invoices
2020-12-24 01:28:38 +03:00
$invoices = $this->applyFilters(Document::invoice()->with('recurring', 'transactions')->accrued(), ['date_field' => 'issued_at'])->get();
Recurring::reflect($invoices, 'issued_at');
$this->setTotals($invoices, 'issued_at', true);
2019-11-16 10:21:14 +03:00
2020-01-27 22:41:08 +03:00
// Revenues
$revenues = $income_transactions->isNotDocument()->get();
Recurring::reflect($revenues, 'paid_at');
$this->setTotals($revenues, 'paid_at', true);
2019-11-16 10:21:14 +03:00
// Bills
2020-12-24 01:28:38 +03:00
$bills = $this->applyFilters(Document::bill()->with('recurring', 'transactions')->accrued(), ['date_field' => 'issued_at'])->get();
Recurring::reflect($bills, 'issued_at');
$this->setTotals($bills, 'issued_at', true);
2019-11-16 10:21:14 +03:00
2020-01-27 22:41:08 +03:00
// Payments
$payments = $expense_transactions->isNotDocument()->get();
Recurring::reflect($payments, 'paid_at');
$this->setTotals($payments, 'paid_at', true);
2019-11-16 10:21:14 +03:00
break;
}
}
}