akaunting/app/Reports/IncomeExpenseSummary.php

54 lines
1.9 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;
use App\Models\Sale\Invoice;
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
2019-11-16 10:21:14 +03:00
public function getTotals()
{
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
$expense_transactions = $this->applyFilters(Transaction::type('expense')->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':
// Income Transactions
$this->setTotals($income_transactions, 'paid_at', true);
2019-11-16 10:21:14 +03:00
// Expense Transactions
$this->setTotals($expense_transactions, 'paid_at', true);
2019-11-16 10:21:14 +03:00
break;
default:
// Invoices
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
$this->setTotals($invoices, 'invoiced_at', true);
// Income Transactions
Recurring::reflect($income_transactions, 'transaction', 'paid_at');
$this->setTotals($income_transactions, 'paid_at', true);
2019-11-16 10:21:14 +03:00
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at', true);
// Expense Transactions
Recurring::reflect($expense_transactions, 'transaction', 'paid_at');
$this->setTotals($expense_transactions, 'paid_at', true);
2019-11-16 10:21:14 +03:00
break;
}
}
}