From 42f6b004851c30c547105d03ea7dad7f5f25179c Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 24 Oct 2018 17:32:00 +0300 Subject: [PATCH] fixed #566 --- app/Http/Controllers/Banking/Transactions.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index d2ef17e91..dc6645709 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -39,12 +39,12 @@ class Transactions extends Controller if ($type != 'income') { $this->addTransactions(Payment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1)); - $this->addTransactions(BillPayment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1), trans_choice('general.bills', 1)); + $this->addTransactions(BillPayment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1)); } if ($type != 'expense') { $this->addTransactions(Revenue::collect(['paid_at'=> 'desc']), trans_choice('general.incomes', 1)); - $this->addTransactions(InvoicePayment::collect(['paid_at'=> 'desc']), trans_choice('general.incomes', 1), trans_choice('general.invoices', 1)); + $this->addTransactions(InvoicePayment::collect(['paid_at'=> 'desc']), trans_choice('general.incomes', 1)); } $transactions = $this->getTransactions($request); @@ -57,27 +57,29 @@ class Transactions extends Controller * * @param $items * @param $type - * @param $category */ - protected function addTransactions($items, $type, $category = null) + protected function addTransactions($items, $type) { foreach ($items as $item) { - $data = [ + if (!empty($item->category)) { + $category_name = $item->category->name; + } else { + if ($type == trans_choice('general.incomes', 1)) { + $category_name = $item->invoice->category->name; + } else { + $category_name = $item->bill->category->name; + } + } + + $this->transactions[] = (object) [ 'paid_at' => $item->paid_at, 'account_name' => $item->account->name, 'type' => $type, 'description' => $item->description, 'amount' => $item->amount, 'currency_code' => $item->currency_code, + 'category_name' => $category_name, ]; - - if (!is_null($category)) { - $data['category_name'] = $category; - } else { - $data['category_name'] = $item->category->name; - } - - $this->transactions[] = (object) $data; } }