akaunting/app/Reports/IncomeExpenseSummary.php

90 lines
2.8 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
{
2022-06-01 10:15:55 +03:00
public $default_name = 'reports.income_expense_summary';
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
public $icon = 'assessment';
public $type = 'summary';
public $chart = [
'income' => [
'bar' => [
'colors' => [
'#8bb475',
],
],
'donut' => [
//
],
],
'expense' => [
'bar' => [
'colors' => [
'#fb7185',
],
],
'donut' => [
//
],
],
];
public function setTables()
{
$this->tables = [
'income' => trans_choice('general.incomes', 1),
'expense' => trans_choice('general.expenses', 2),
];
}
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
2022-06-01 10:15:55 +03:00
switch ($this->getBasis()) {
2019-11-16 10:21:14 +03:00
case 'cash':
2022-06-01 10:15:55 +03:00
// Incomes
$incomes = $income_transactions->get();
$this->setTotals($incomes, 'paid_at', false, 'income');
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
// Expenses
$expenses = $expense_transactions->get();
$this->setTotals($expenses, 'paid_at', false, 'expense');
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');
2022-06-01 10:15:55 +03:00
$this->setTotals($invoices, 'issued_at', false, 'income');
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
// Incomes
$incomes = $income_transactions->isNotDocument()->get();
Recurring::reflect($incomes, 'paid_at');
$this->setTotals($incomes, 'paid_at', false, 'income');
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');
2022-06-01 10:15:55 +03:00
$this->setTotals($bills, 'issued_at', false, 'expense');
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
// Expenses
$expenses = $expense_transactions->isNotDocument()->get();
Recurring::reflect($expenses, 'paid_at');
$this->setTotals($expenses, 'paid_at', false, 'expense');
2019-11-16 10:21:14 +03:00
break;
}
}
}