v2 first commit

This commit is contained in:
denisdulici
2019-11-16 10:21:14 +03:00
parent 5b23e9c2c4
commit 6d50fa8442
3075 changed files with 3451681 additions and 65594 deletions

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Reports;
use App\Abstracts\Reports\Report;
use App\Models\Banking\Transaction;
use App\Models\Expense\Bill;
use App\Utilities\Recurring;
class ExpenseSummary extends Report
{
public $category = 'income-expense';
public $icon = 'fa fa-shopping-cart';
public $chart = [
'line' => [
'width' => '0',
'height' => '300',
'options' => [
'color' => '#ef3232'
],
'backgroundColor' => '#ef3232',
'color' => '#ef3232',
],
];
public function getName()
{
return trans('reports.summary.expense');
}
public function getTotals()
{
$payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) {
case 'cash':
// Payments
$this->setTotals($payments, 'paid_at');
break;
default:
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at');
// Payments
Recurring::reflect($payments, 'payment', 'paid_at');
$this->setTotals($payments, 'paid_at');
break;
}
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Reports;
use App\Abstracts\Reports\Report;
use App\Models\Banking\Transaction;
use App\Models\Expense\Bill;
use App\Models\Income\Invoice;
use App\Utilities\Recurring;
class IncomeExpenseSummary extends Report
{
public $category = 'income-expense';
public $icon = 'fa fa-chart-pie';
public function getName()
{
return trans('reports.summary.income_expense');
}
public function getTotals()
{
$revenues = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
$payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) {
case 'cash':
// Revenues
$this->setTotals($revenues, 'paid_at', true);
// Payments
$this->setTotals($payments, 'paid_at', true);
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);
// Revenues
Recurring::reflect($revenues, 'revenue', 'paid_at');
$this->setTotals($revenues, 'paid_at', true);
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at', true);
// Payments
Recurring::reflect($payments, 'payment', 'paid_at');
$this->setTotals($payments, 'paid_at', true);
break;
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Reports;
use App\Abstracts\Reports\Report;
use App\Models\Banking\Transaction;
use App\Models\Income\Invoice;
use App\Utilities\Recurring;
class IncomeSummary extends Report
{
public $category = 'income-expense';
public $icon = 'fa fa-money-bill';
public $chart = [
'line' => [
'width' => '0',
'height' => '300',
'options' => [
'color' => '#328aef'
],
'backgroundColor' => '#328aef',
'color' => '#328aef',
],
];
public function getName()
{
return trans('reports.summary.income');
}
public function getTotals()
{
$revenues = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) {
case 'cash':
// Revenues
$this->setTotals($revenues, 'paid_at');
break;
default:
// Invoices
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
$this->setTotals($invoices, 'invoiced_at');
// Revenues
Recurring::reflect($revenues, 'revenue', 'paid_at');
$this->setTotals($revenues, 'paid_at');
break;
}
}
}

115
app/Reports/ProfitLoss.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
namespace App\Reports;
use App\Abstracts\Reports\Report;
use App\Models\Banking\Transaction;
use App\Models\Expense\Bill;
use App\Models\Income\Invoice;
use App\Models\Setting\Category;
use App\Utilities\Recurring;
class ProfitLoss extends Report
{
public $category = 'accounting';
public $icon = 'fa fa-heart';
public $chart = false;
public function getName()
{
return trans('reports.profit_loss');
}
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 getTableRowList()
{
$this->cat_list = Category::type(['income', 'expense'])->enabled()->orderBy('name')->get();
return collect($this->cat_list)->pluck('name', 'id')->toArray();
}
public function setRows()
{
$list = $this->getTableRowList();
foreach ($this->dates as $date) {
foreach ($this->tables as $t_id => $t_name) {
foreach ($list as $id => $name) {
$cat = $this->cat_list->where('id', $id)->first();
if ($cat->type != $t_id) {
continue;
}
$this->rows[$t_name][$id][$date] = 0;
}
}
}
}
public function getTotals()
{
$revenues = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
$payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
switch ($this->report->basis) {
case 'cash':
// Revenues
$this->setTotals($revenues, 'paid_at', true, $this->tables['income']);
// Payments
$this->setTotals($payments, 'paid_at', true, $this->tables['expense']);
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, $this->tables['income']);
// Revenues
Recurring::reflect($revenues, 'revenue', 'paid_at');
$this->setTotals($revenues, 'paid_at', true, $this->tables['income']);
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at', true, $this->tables['expense']);
// Payments
Recurring::reflect($payments, 'payment', 'paid_at');
$this->setTotals($payments, 'paid_at', true, $this->tables['expense']);
break;
}
// TODO: move to views
foreach ($this->totals as $table => $dates) {
foreach ($dates as $date => $total) {
if (!isset($this->net_profit[$date])) {
$this->net_profit[$date] = 0;
}
$this->net_profit[$date] += $total;
}
}
}
}

132
app/Reports/TaxSummary.php Normal file
View File

@@ -0,0 +1,132 @@
<?php
namespace App\Reports;
use App\Abstracts\Reports\Report;
use App\Models\Banking\Transaction;
use App\Models\Expense\Bill;
use App\Models\Income\Invoice;
use App\Models\Setting\Tax;
use App\Traits\Currencies;
use App\Utilities\Recurring;
use Date;
class TaxSummary extends Report
{
use Currencies;
public $category = 'accounting';
public $icon = 'fa fa-percent';
public $chart = false;
public function getName()
{
return trans('reports.summary.tax');
}
public function setViews()
{
parent::setViews();
$this->views['content.header'] = 'reports.tax_summary.content.header';
$this->views['table.header'] = 'reports.tax_summary.table.header';
$this->views['table.footer'] = 'reports.tax_summary.table.footer';
}
public function setTables()
{
$taxes = Tax::enabled()->where('rate', '<>', '0')->orderBy('name')->pluck('name')->toArray();
$this->tables = array_combine($taxes, $taxes);
}
public function getTableRowList()
{
return [
'income' => trans_choice('general.incomes', 2),
'expense' => trans_choice('general.expenses', 2),
];
}
public function getTotals()
{
switch ($this->report->basis) {
case 'cash':
// Invoice Payments
$invoices = $this->applyFilters(Transaction::type('income')->isDocument()->with(['invoice', 'invoice.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get();
$this->setTotals($invoices, 'paid_at');
// Bill Payments
$bills = $this->applyFilters(Transaction::type('expense')->isDocument()->with(['bill', 'bill.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get();
$this->setTotals($bills, 'paid_at');
break;
default:
// Invoices
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
$this->setTotals($invoices, 'invoiced_at');
// Bills
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
Recurring::reflect($bills, 'bill', 'billed_at');
$this->setTotals($bills, 'billed_at');
break;
}
}
public function setTotals($items, $date_field, $check_type = false, $table = 'default')
{
foreach ($items as $item) {
// Make groups extensible
$item = $this->applyGroups($item);
$db_table = $item->getTable();
$date = $this->getFormattedDate(Date::parse($item->$date_field));
if ($date_field == 'paid_at') {
$document_type = ($item->type == 'income') ? 'invoice' : 'bill';
$item_totals = $item->$document_type->totals;
$type_item = $item->$document_type;
} else {
$item_totals = $item->totals;
}
foreach ($item_totals as $item_total) {
if ($item_total->code != 'tax') {
continue;
}
$type = (($db_table == 'invoices') || (($db_table == 'transactions') && ($item->type == 'income'))) ? 'income' : 'expense';
if (!isset($this->rows[$item_total->name][$type][$date]) ||
!isset($this->totals[$item_total->name][$date]))
{
continue;
}
if ($date_field == 'paid_at') {
$rate = ($item->amount * 100) / $type_item->amount;
$item_amount = ($item_total->amount / 100) * $rate;
} else {
$item_amount = $item_total->amount;
}
$amount = $this->convertToDefault($item_amount, $item->currency_code, $item->currency_rate);
if ($type == 'income') {
$this->rows[$item_total->name][$type][$date] += $amount;
$this->totals[$item_total->name][$date] += $amount;
} else {
$this->rows[$item_total->name][$type][$date] -= $amount;
$this->totals[$item_total->name][$date] -= $amount;
}
}
}
}
}