use collections
This commit is contained in:
parent
b3beb31d40
commit
f47ae3b636
@ -65,10 +65,10 @@ abstract class DocumentModel extends Model
|
|||||||
{
|
{
|
||||||
$percent = 0;
|
$percent = 0;
|
||||||
|
|
||||||
$discount = $this->totals()->where('code', 'discount')->value('amount');
|
$discount = $this->totals->where('code', 'discount')->pluck('amount')->first();
|
||||||
|
|
||||||
if ($discount) {
|
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);
|
$percent = number_format((($discount * 100) / $sub_total), 0);
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ abstract class DocumentModel extends Model
|
|||||||
{
|
{
|
||||||
$amount = $this->amount;
|
$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;
|
$amount -= $tax->amount;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class ExpensesByCategory extends Widget
|
|||||||
Category::with('expense_transactions')->expense()->each(function ($category) {
|
Category::with('expense_transactions')->expense()->each(function ($category) {
|
||||||
$amount = 0;
|
$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();
|
$amount += $transaction->getAmountConvertedToDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class IncomeByCategory extends Widget
|
|||||||
Category::with('income_transactions')->income()->each(function ($category) {
|
Category::with('income_transactions')->income()->each(function ($category) {
|
||||||
$amount = 0;
|
$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();
|
$amount += $transaction->getAmountConvertedToDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user