updated reports
This commit is contained in:
parent
78ede398f2
commit
ead2256589
@ -7,7 +7,9 @@ use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Exports\Common\Reports as Export;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Common\Report as Model;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Traits\Charts;
|
||||
use App\Traits\DateTime;
|
||||
use App\Utilities\Chartjs;
|
||||
@ -317,7 +319,7 @@ abstract class Report
|
||||
|
||||
$this->totals[$table][$date] += $amount;
|
||||
} else {
|
||||
$type = (($item->getTable() == 'invoices') || (($item->getTable() == 'transactions') && ($item->type == 'income'))) ? 'income' : 'expense';
|
||||
$type = (($item instanceof Invoice) || (($item instanceof Transaction) && ($item->type == 'income'))) ? 'income' : 'expense';
|
||||
|
||||
if ($type == 'income') {
|
||||
$this->rows[$table][$item->$id_field][$date] += $amount;
|
||||
|
@ -19,7 +19,7 @@ class Reports extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$classes = $categories = [];
|
||||
$totals = $icons = $categories = [];
|
||||
|
||||
$reports = Report::all();
|
||||
|
||||
@ -30,12 +30,12 @@ class Reports extends Controller
|
||||
|
||||
$class = Utility::getClassInstance($report);
|
||||
|
||||
$classes[$report->id] = $class;
|
||||
|
||||
$totals[$report->id] = $class->getTotal();
|
||||
$icons[$report->id] = $class->getIcon();
|
||||
$categories[$class->getCategory()][] = $report;
|
||||
}
|
||||
|
||||
return view('common.reports.index', compact('categories', 'classes'));
|
||||
return view('common.reports.index', compact('categories', 'totals', 'icons'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,11 +41,11 @@ class ExpenseSummary extends Report
|
||||
default:
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'bill', 'billed_at');
|
||||
Recurring::reflect($bills, 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at');
|
||||
|
||||
// Payments
|
||||
Recurring::reflect($payments, 'payment', 'paid_at');
|
||||
Recurring::reflect($payments, 'paid_at');
|
||||
$this->setTotals($payments, 'paid_at');
|
||||
|
||||
break;
|
||||
|
@ -31,11 +31,11 @@ class IncomeExpenseSummary extends Report
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at', true);
|
||||
|
||||
// Income Transactions
|
||||
Recurring::reflect($income_transactions, 'transaction', 'paid_at');
|
||||
Recurring::reflect($income_transactions, 'paid_at');
|
||||
$this->setTotals($income_transactions, 'paid_at', true);
|
||||
|
||||
// Bills
|
||||
@ -44,7 +44,7 @@ class IncomeExpenseSummary extends Report
|
||||
$this->setTotals($bills, 'billed_at', true);
|
||||
|
||||
// Expense Transactions
|
||||
Recurring::reflect($expense_transactions, 'transaction', 'paid_at');
|
||||
Recurring::reflect($expense_transactions, 'paid_at');
|
||||
$this->setTotals($expense_transactions, 'paid_at', true);
|
||||
|
||||
break;
|
||||
|
@ -41,11 +41,11 @@ class IncomeSummary extends Report
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at');
|
||||
|
||||
// Transactions
|
||||
Recurring::reflect($transactions, 'transaction', 'paid_at');
|
||||
Recurring::reflect($transactions, 'paid_at');
|
||||
$this->setTotals($transactions, 'paid_at');
|
||||
|
||||
break;
|
||||
|
@ -79,11 +79,11 @@ class ProfitLoss extends Report
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at', true, $this->tables['income']);
|
||||
|
||||
// Income Transactions
|
||||
Recurring::reflect($income_transactions, 'transaction', 'paid_at');
|
||||
Recurring::reflect($income_transactions, 'paid_at');
|
||||
$this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']);
|
||||
|
||||
// Bills
|
||||
@ -92,7 +92,7 @@ class ProfitLoss extends Report
|
||||
$this->setTotals($bills, 'billed_at', true, $this->tables['expense']);
|
||||
|
||||
// Expense Transactions
|
||||
Recurring::reflect($expense_transactions, 'transaction', 'paid_at');
|
||||
Recurring::reflect($expense_transactions, 'paid_at');
|
||||
$this->setTotals($expense_transactions, 'paid_at', true, $this->tables['expense']);
|
||||
|
||||
break;
|
||||
|
@ -62,12 +62,12 @@ class TaxSummary extends Report
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoice', 'invoiced_at');
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at');
|
||||
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'bill', 'billed_at');
|
||||
Recurring::reflect($bills, 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at');
|
||||
|
||||
break;
|
||||
@ -80,7 +80,7 @@ class TaxSummary extends Report
|
||||
// Make groups extensible
|
||||
$item = $this->applyGroups($item);
|
||||
|
||||
$db_table = $item->getTable();
|
||||
$type = (($item instanceof Invoice) || (($item instanceof Transaction) && ($item->type == 'income'))) ? 'income' : 'expense';
|
||||
|
||||
$date = $this->getFormattedDate(Date::parse($item->$date_field));
|
||||
|
||||
@ -97,8 +97,6 @@ class TaxSummary extends Report
|
||||
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]))
|
||||
{
|
||||
|
@ -2,12 +2,13 @@
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Sale\Invoice;
|
||||
use Date;
|
||||
|
||||
class Recurring
|
||||
{
|
||||
|
||||
public static function reflect(&$items, $type, $issued_date_field)
|
||||
public static function reflect(&$items, $issued_date_field)
|
||||
{
|
||||
foreach ($items as $key => $item) {
|
||||
if (!$item->recurring || !empty($item->parent_id)) {
|
||||
@ -30,7 +31,7 @@ class Recurring
|
||||
|
||||
$start_date = Date::parse($start->format('Y-m-d'));
|
||||
|
||||
if (($type == 'invoice') || ($type == 'bill')) {
|
||||
if (($item instanceof Invoice) || ($item instanceof Bill)) {
|
||||
// Days between invoiced/billed and due date
|
||||
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
|
||||
|
||||
@ -45,4 +46,4 @@ class Recurring
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,13 +42,13 @@
|
||||
<div class="col">
|
||||
<a href="{{ route('reports.show', $report->id) }}">
|
||||
<h5 class="card-title text-uppercase text-muted mb-0">{{ $report->name }}</h5>
|
||||
<span class="h2 font-weight-bold mb-0">{{ $classes[$report->id]->getTotal() }}</span>
|
||||
<span class="h2 font-weight-bold mb-0">{{ $totals[$report->id] }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<a href="{{ route('reports.show', $report->id) }}">
|
||||
<div class="icon icon-shape bg-orange text-white rounded-circle shadow">
|
||||
<i class="{{ $classes[$report->id]->getIcon() }}"></i>
|
||||
<i class="{{ $icons[$report->id] }}"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user