diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 885680b23..5bf8617d1 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -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; diff --git a/app/Http/Controllers/Common/Reports.php b/app/Http/Controllers/Common/Reports.php index e85805e51..a5052ed27 100644 --- a/app/Http/Controllers/Common/Reports.php +++ b/app/Http/Controllers/Common/Reports.php @@ -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')); } /** diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index ab3343cd8..9d756284b 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -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; diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 1996ce070..ace5fb31f 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -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; diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index 8c0c60e1e..8cfa4c899 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -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; diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index fc5767893..89c43e152 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -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; diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 8fdf3b0d3..547df5783 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -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])) { diff --git a/app/Utilities/Recurring.php b/app/Utilities/Recurring.php index 94085ff93..1ddd772d3 100644 --- a/app/Utilities/Recurring.php +++ b/app/Utilities/Recurring.php @@ -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 } } } -} \ No newline at end of file +} diff --git a/resources/views/common/reports/index.blade.php b/resources/views/common/reports/index.blade.php index c450dc1c7..97dbdfaf8 100644 --- a/resources/views/common/reports/index.blade.php +++ b/resources/views/common/reports/index.blade.php @@ -42,13 +42,13 @@