From bbc7b54a38c8098f13d9af521ad866186b615264 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 21 Mar 2015 08:55:55 +0100 Subject: [PATCH] Catch 0 start balance. --- app/Repositories/Account/AccountRepository.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index dad416f93c..c114f803bc 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -144,13 +144,17 @@ class AccountRepository implements AccountRepositoryInterface // diff (negative when lost, positive when gained) $diff = $account->endBalance - $account->startBalance; - if ($diff < 0) { + if ($diff < 0 && $account->startBalance > 0) { // percentage lost compared to start. $pct = (($diff * -1) / $account->startBalance) * 100; } else { - $pct = ($diff / $account->startBalance) * 100; + if ($diff >= 0 && $account->startBalance > 0) { + $pct = ($diff / $account->startBalance) * 100; + } else { + $pct = 0; + } } - $pct = $pct > 100 ? 100 : $pct; + $pct = $pct > 100 ? 100 : $pct; $account->difference = $diff; $account->percentage = round($pct); }