Skip to content

Firefly III: a personal finances manager

Catch 0 start balance.

James Colebbc7b54a38c8
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);
}