Fixed some math things.

This commit is contained in:
James Cole
2015-07-26 19:42:28 +02:00
parent eef28d96f4
commit e211c9812e
9 changed files with 28 additions and 18 deletions

View File

@@ -236,6 +236,7 @@ class AccountRepository implements AccountRepositoryInterface
if (count($ids) > 0) {
$accounts = Auth::user()->accounts()->whereIn('id', $ids)->get();
}
bcscale(2);
$accounts->each(
function (Account $account) use ($start, $end) {
@@ -249,7 +250,7 @@ class AccountRepository implements AccountRepositoryInterface
// sum of piggy bank amounts on this account:
// diff between endBalance and piggyBalance.
// then, percentage.
$difference = $account->endBalance - $account->piggyBalance;
$difference = bcsub($account->endBalance, $account->piggyBalance);
$account->difference = $difference;
$account->percentage = $difference != 0 && $account->endBalance != 0 ? round((($difference / $account->endBalance) * 100)) : 100;
@@ -277,13 +278,15 @@ class AccountRepository implements AccountRepositoryInterface
$start = clone Session::get('start', new Carbon);
$end = clone Session::get('end', new Carbon);
bcscale(2);
$accounts->each(
function (Account $account) use ($start, $end) {
$account->startBalance = Steam::balance($account, $start);
$account->endBalance = Steam::balance($account, $end);
// diff (negative when lost, positive when gained)
$diff = $account->endBalance - $account->startBalance;
$diff = bcsub($account->endBalance, $account->startBalance);
if ($diff < 0 && $account->startBalance > 0) {
// percentage lost compared to start.

View File

@@ -82,10 +82,11 @@ class PiggyBankPart
*/
public function percentage()
{
bcscale(2);
if ($this->getCurrentamount() < $this->getCumulativeAmount()) {
$pct = 0;
// calculate halfway point?
if ($this->getCumulativeAmount() - $this->getCurrentamount() < $this->getAmountPerBar()) {
if (bcsub($this->getCumulativeAmount(), $this->getCurrentamount()) < $this->getAmountPerBar()) {
$left = $this->getCurrentamount() % $this->getAmountPerBar();
$pct = round($left / $this->getAmountPerBar() * 100);
}