This commit is contained in:
James Cole 2016-04-21 11:03:04 +02:00
parent 0ef5eeeb55
commit 3972882a33
2 changed files with 9 additions and 0 deletions

View File

@ -175,6 +175,7 @@ class PiggyBankController extends Controller
$piggyBank->savedSoFar = round($piggyBank->currentRelevantRep()->currentamount, 2);
$piggyBank->percentage = $piggyBank->savedSoFar != 0 ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0;
$piggyBank->leftToSave = bcsub($piggyBank->targetamount, $piggyBank->savedSoFar);
$piggyBank->percentage = $piggyBank->percentage > 100 ? 100 : $piggyBank->percentage;
/*
* Fill account information:

View File

@ -169,6 +169,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
$piggyBank->save();
// if the piggy bank is now smaller than the current relevant rep,
// remove money from the rep.
$repetition = $piggyBank->currentRelevantRep();
if ($repetition->currentamount > $piggyBank->targetamount) {
$repetition->currentamount = $piggyBank->targetamount;
$repetition->save();
}
return $piggyBank;
}
}