From 0d33ffd3110b9c3ea54b7f9045bf0d53f4f6474e Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 29 Jan 2020 01:06:12 +0300 Subject: [PATCH] renamed function --- app/Abstracts/Report.php | 26 ++++++++++++++----------- app/Http/Controllers/Common/Reports.php | 6 +++--- app/Reports/ExpenseSummary.php | 2 +- app/Reports/IncomeExpenseSummary.php | 2 +- app/Reports/IncomeSummary.php | 2 +- app/Reports/ProfitLoss.php | 2 +- app/Reports/TaxSummary.php | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 62c8c771f..ee824f5c2 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -84,7 +84,7 @@ abstract class Report $this->load(); } - abstract public function getTotals(); + abstract public function setData(); public function load() { @@ -94,7 +94,7 @@ abstract class Report $this->setDates(); $this->setFilters(); $this->setRows(); - $this->getTotals(); + $this->setData(); $this->loaded = true; } @@ -118,20 +118,24 @@ abstract class Report return $this->icon; } - public function getTotal() + public function getGrandTotal() { if (!$this->loaded) { $this->load(); } - $sum = 0; + if (!empty($this->footer_totals)) { + $sum = 0; - foreach ($this->footer_totals as $total) { - $sum += is_array($total) ? array_sum($total) : $total; + foreach ($this->footer_totals as $total) { + $sum += is_array($total) ? array_sum($total) : $total; + } + + $total = money($sum, setting('default.currency'), true); + } else { + $total = trans('general.na'); } - $total = money($sum, setting('default.currency'), true); - return $total; } @@ -369,15 +373,15 @@ abstract class Report { $print_url = 'common/reports/' . $this->model->id . '/' . $action . '?year='. $this->year; - collect(request('accounts'))->each(function($item) use(&$print_url) { + collect(request('accounts'))->each(function($item) use (&$print_url) { $print_url .= '&accounts[]=' . $item; }); - collect(request('customers'))->each(function($item) use(&$print_url) { + collect(request('customers'))->each(function($item) use (&$print_url) { $print_url .= '&customers[]=' . $item; }); - collect(request('categories'))->each(function($item) use(&$print_url) { + collect(request('categories'))->each(function($item) use (&$print_url) { $print_url .= '&categories[]=' . $item; }); diff --git a/app/Http/Controllers/Common/Reports.php b/app/Http/Controllers/Common/Reports.php index 81407af59..bfb075f36 100644 --- a/app/Http/Controllers/Common/Reports.php +++ b/app/Http/Controllers/Common/Reports.php @@ -38,7 +38,7 @@ class Reports extends Controller $ttl = 3600 * 6; // 6 hours $totals[$report->id] = Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) { - return $class->getTotal(); + return $class->getGrandTotal(); }); $icons[$report->id] = $class->getIcon(); @@ -63,7 +63,7 @@ class Reports extends Controller $class = Utility::getClassInstance($report); // Update cache - Cache::put('reports.totals.' . $report->id, $class->getTotal()); + Cache::put('reports.totals.' . $report->id, $class->getGrandTotal()); return $class->show(); } @@ -267,7 +267,7 @@ class Reports extends Controller return; } - Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getTotal()); + Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getGrandTotal()); }); return redirect()->back(); diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index cc1cea2e7..9335c730a 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -28,7 +28,7 @@ class ExpenseSummary extends Report ], ]; - public function getTotals() + public function setData() { $transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 3f0136873..2e74f99c5 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -14,7 +14,7 @@ class IncomeExpenseSummary extends Report public $icon = 'fa fa-chart-pie'; - public function getTotals() + public function setData() { $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index a109ba49e..acc6608f7 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -28,7 +28,7 @@ class IncomeSummary extends Report ], ]; - public function getTotals() + public function setData() { $transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index 8ee91bff5..af944e645 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -38,7 +38,7 @@ class ProfitLoss extends Report ]; } - public function getTotals() + public function setData() { $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 44b4c076d..1e3668930 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -42,7 +42,7 @@ class TaxSummary extends Report $this->tables = array_combine($taxes, $taxes); } - public function getTotals() + public function setData() { switch ($this->model->settings->basis) { case 'cash':