forked from akaunting/akaunting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfitLoss.php
84 lines (68 loc) · 3.05 KB
/
ProfitLoss.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace App\Reports;
use App\Abstracts\Report;
use App\Models\Banking\Transaction;
use App\Models\Document\Document;
use App\Utilities\Recurring;
class ProfitLoss extends Report
{
public $default_name = 'reports.profit_loss';
public $category = 'general.accounting';
public $icon = 'fa fa-heart';
public function setViews()
{
parent::setViews();
$this->views['content.header'] = 'reports.profit_loss.content.header';
$this->views['content.footer'] = 'reports.profit_loss.content.footer';
$this->views['table.header'] = 'reports.profit_loss.table.header';
$this->views['table.footer'] = 'reports.profit_loss.table.footer';
}
public function setTables()
{
$this->tables = [
'income' => trans_choice('general.incomes', 1),
'expense' => trans_choice('general.expenses', 2),
];
}
public function setData()
{
$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']);
switch ($this->getSetting('basis')) {
case 'cash':
// Revenues
$revenues = $income_transactions->get();
$this->setTotals($revenues, 'paid_at', true, $this->tables['income'], false);
// Payments
$payments = $expense_transactions->get();
$this->setTotals($payments, 'paid_at', true, $this->tables['expense'], false);
break;
default:
// Invoices
$invoices = $this->applyFilters(Document::invoice()->with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'issued_at'])->get();
Recurring::reflect($invoices, 'issued_at');
$this->setTotals($invoices, 'issued_at', true, $this->tables['income'], false);
// Revenues
$revenues = $income_transactions->isNotDocument()->get();
Recurring::reflect($revenues, 'paid_at');
$this->setTotals($revenues, 'paid_at', true, $this->tables['income'], false);
// Bills
$bills = $this->applyFilters(Document::bill()->with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'issued_at'])->get();
Recurring::reflect($bills, 'issued_at');
$this->setTotals($bills, 'issued_at', true, $this->tables['expense'], false);
// Payments
$payments = $expense_transactions->isNotDocument()->get();
Recurring::reflect($payments, 'paid_at');
$this->setTotals($payments, 'paid_at', true, $this->tables['expense'], false);
break;
}
}
public function getFields()
{
return [
$this->getGroupField(),
$this->getPeriodField(),
$this->getBasisField(),
];
}
}