use collections

This commit is contained in:
Denis Duliçi 2020-06-08 18:48:59 +03:00
parent b3beb31d40
commit f47ae3b636
3 changed files with 5 additions and 5 deletions

View File

@ -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;
});

View File

@ -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();
});

View File

@ -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();
});