From f47ae3b636c1950f03f7d5dca26e4ed5ac15c57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Mon, 8 Jun 2020 18:48:59 +0300 Subject: [PATCH] use collections --- app/Abstracts/DocumentModel.php | 6 +++--- app/Widgets/ExpensesByCategory.php | 2 +- app/Widgets/IncomeByCategory.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Abstracts/DocumentModel.php b/app/Abstracts/DocumentModel.php index c23263c11..2bb94e137 100644 --- a/app/Abstracts/DocumentModel.php +++ b/app/Abstracts/DocumentModel.php @@ -65,10 +65,10 @@ abstract class DocumentModel extends Model { $percent = 0; - $discount = $this->totals()->where('code', 'discount')->value('amount'); + $discount = $this->totals->where('code', 'discount')->pluck('amount')->first(); if ($discount) { - $sub_total = $this->totals()->where('code', 'sub_total')->value('amount'); + $sub_total = $this->totals->where('code', 'sub_total')->pluck('amount')->first(); $percent = number_format((($discount * 100) / $sub_total), 0); } @@ -171,7 +171,7 @@ abstract class DocumentModel extends Model { $amount = $this->amount; - collect($this->totals)->where('code', 'tax')->each(function ($tax) use(&$amount) { + $this->totals->where('code', 'tax')->each(function ($tax) use(&$amount) { $amount -= $tax->amount; }); diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index b44ef7e15..2ec6ab13e 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -18,7 +18,7 @@ class ExpensesByCategory extends Widget Category::with('expense_transactions')->expense()->each(function ($category) { $amount = 0; - $this->applyFilters($category->expense_transactions())->each(function ($transaction) use (&$amount) { + $this->applyFilters($category->expense_transactions)->each(function ($transaction) use (&$amount) { $amount += $transaction->getAmountConvertedToDefault(); }); diff --git a/app/Widgets/IncomeByCategory.php b/app/Widgets/IncomeByCategory.php index 8d34286e0..482e933f0 100644 --- a/app/Widgets/IncomeByCategory.php +++ b/app/Widgets/IncomeByCategory.php @@ -18,7 +18,7 @@ class IncomeByCategory extends Widget Category::with('income_transactions')->income()->each(function ($category) { $amount = 0; - $this->applyFilters($category->income_transactions())->each(function ($transaction) use (&$amount) { + $this->applyFilters($category->income_transactions)->each(function ($transaction) use (&$amount) { $amount += $transaction->getAmountConvertedToDefault(); });