From 66f2df9677b9761039cc46a2cd812fd59583b165 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 26 Apr 2016 22:21:34 +0200 Subject: [PATCH] Some code cleanup and I sneaked in a chart optimisation. --- app/Helpers/Collection/Expense.php | 27 +++++++++++-------------- app/Helpers/Collection/Income.php | 26 ++++++++++++------------ app/Helpers/Csv/Converter/AccountId.php | 12 +++-------- public/js/ff/charts.js | 4 ++-- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index f69a2db8ae..c963b631e3 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -33,26 +33,25 @@ class Expense */ public function addOrCreateExpense(TransactionJournal $entry) { - $accountId = $entry->account_id; $amount = strval(round($entry->journalAmount, 2)); if (bccomp('0', $amount) === -1) { $amount = bcmul($amount, '-1'); } - if (!$this->expenses->has($accountId)) { - $newObject = new stdClass; - $newObject->amount = $amount; - $newObject->name = Crypt::decrypt($entry->account_name); - $newObject->count = 1; - $newObject->id = $accountId; - $this->expenses->put($accountId, $newObject); - } else { - $existing = $this->expenses->get($accountId); - $existing->amount = bcadd($existing->amount, $amount); - $existing->count++; - $this->expenses->put($accountId, $existing); + $object = new stdClass; + $object->amount = $amount; + $object->name = Crypt::decrypt($entry->account_name); + $object->count = 1; + $object->id = $accountId; + + // overrule some properties: + if ($this->expenses->has($accountId)) { + $object = $this->expenses->get($accountId); + $object->amount = bcadd($object->amount, $amount); + $object->count++; } + $this->expenses->put($accountId, $object); } /** @@ -60,8 +59,6 @@ class Expense */ public function addToTotal(string $add) { - - $add = strval(round($add, 2)); if (bccomp('0', $add) === -1) { $add = bcmul($add, '-1'); diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index c5cf254b3d..a618a5a058 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -34,21 +34,21 @@ class Income */ public function addOrCreateIncome(TransactionJournal $entry) { - $accountId = $entry->account_id; - if (!$this->incomes->has($accountId)) { - $newObject = new stdClass; - $newObject->amount = strval(round($entry->journalAmount, 2)); - $newObject->name = Crypt::decrypt($entry->account_name); - $newObject->count = 1; - $newObject->id = $accountId; - $this->incomes->put($accountId, $newObject); - } else { - $existing = $this->incomes->get($accountId); - $existing->amount = bcadd($existing->amount, $entry->journalAmount); - $existing->count++; - $this->incomes->put($accountId, $existing); + + $object = new stdClass; + $object->amount = strval(round($entry->journalAmount, 2)); + $object->name = Crypt::decrypt($entry->account_name); + $object->count = 1; + $object->id = $accountId; + + // overrule some properties: + if ($this->incomes->has($accountId)) { + $object = $this->incomes->get($accountId); + $object->amount = bcadd($object->amount, $entry->journalAmount); + $object->count++; } + $this->incomes->put($accountId, $object); } /** diff --git a/app/Helpers/Csv/Converter/AccountId.php b/app/Helpers/Csv/Converter/AccountId.php index a25a599f1f..5336b703fd 100644 --- a/app/Helpers/Csv/Converter/AccountId.php +++ b/app/Helpers/Csv/Converter/AccountId.php @@ -20,15 +20,9 @@ class AccountId extends BasicConverter implements ConverterInterface { /** @var AccountRepositoryInterface $repository */ $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface'); - - // is mapped? Then it's easy! - if (isset($this->mapped[$this->index][$this->value])) { - /** @var Account $account */ - $account = $repository->find($this->mapped[$this->index][$this->value]); - } else { - /** @var Account $account */ - $account = $repository->find($this->value); - } + $account = isset($this->mapped[$this->index][$this->value]) + ? $repository->find($this->mapped[$this->index][$this->value]) + : $repository->find($this->value); return $account; } diff --git a/public/js/ff/charts.js b/public/js/ff/charts.js index 7e30624236..83fa029dda 100644 --- a/public/js/ff/charts.js +++ b/public/js/ff/charts.js @@ -156,8 +156,8 @@ var defaultColumnOptions = { callback: function (tickValue, index, ticks) { "use strict"; return accounting.formatMoney(tickValue); - - } + }, + beginAtZero: true } }] },