mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-29 06:34:37 +00:00 
			
		
		
		
	Fixed some math things.
This commit is contained in:
		| @@ -38,7 +38,7 @@ class ChartJsBillChartGenerator implements BillChartGenerator | ||||
|         /** @var Bill $entry */ | ||||
|         foreach ($unpaid as $entry) { // loop unpaid: | ||||
|             $description          = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')'; | ||||
|             $amount               = ($entry[0]->amount_max + $entry[0]->amount_min) / 2; | ||||
|             $amount               = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2); | ||||
|             $unpaidDescriptions[] = $description; | ||||
|             $unpaidAmount         = bcadd($unpaidAmount, $amount); | ||||
|             unset($amount, $description); | ||||
|   | ||||
| @@ -44,7 +44,7 @@ class GoogleBillChartGenerator implements BillChartGenerator | ||||
|         /** @var Bill $entry */ | ||||
|         foreach ($unpaid as $entry) { | ||||
|             $description          = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')'; | ||||
|             $amount               = ($entry[0]->amount_max + $entry[0]->amount_min) / 2; | ||||
|             $amount               = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2); | ||||
|             $unpaidDescriptions[] = $description; | ||||
|             $unpaidAmount         = bcadd($unpaidAmount, $amount); | ||||
|             unset($amount, $description); | ||||
|   | ||||
| @@ -49,10 +49,12 @@ class UpdateJournalConnection | ||||
|         if (is_null($repetition)) { | ||||
|             return; | ||||
|         } | ||||
|         $amount = $journal->amount; | ||||
|         $diff   = $amount - $event->amount; // update current repetition | ||||
|         bcscale(2); | ||||
|  | ||||
|         $repetition->currentamount += $diff; | ||||
|         $amount = $journal->amount; | ||||
|         $diff   = bcsub($amount, $event->amount); // update current repetition | ||||
|  | ||||
|         $repetition->currentamount = bcadd($repetition->currentamount, $diff); | ||||
|         $repetition->save(); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -79,7 +79,7 @@ class ReportHelper implements ReportHelperInterface | ||||
|         foreach ($accounts as $account) { | ||||
|             $start = bcadd($start, $account->startBalance); | ||||
|             $end   = bcadd($end, $account->endBalance); | ||||
|             $diff  = bcadd($diff, ($account->endBalance - $account->startBalance)); | ||||
|             $diff  = bcadd($diff, bcsub($account->endBalance, $account->startBalance)); | ||||
|         } | ||||
|  | ||||
|         $object = new AccountCollection; | ||||
| @@ -255,6 +255,8 @@ class ReportHelper implements ReportHelperInterface | ||||
|         $repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); | ||||
|         $set        = $repository->getBudgets(); | ||||
|  | ||||
|         bcscale(2); | ||||
|  | ||||
|         foreach ($set as $budget) { | ||||
|  | ||||
|             $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); | ||||
| @@ -277,9 +279,9 @@ class ReportHelper implements ReportHelperInterface | ||||
|                 $budgetLine->setBudget($budget); | ||||
|                 $budgetLine->setRepetition($repetition); | ||||
|                 $expenses  = $repository->spentInPeriodCorrected($budget, $repetition->startdate, $repetition->enddate, $shared); | ||||
|                 $left      = $expenses < $repetition->amount ? $repetition->amount - $expenses : 0; | ||||
|                 $left      = $expenses < $repetition->amount ? bcsub($repetition->amount, $expenses) : 0; | ||||
|                 $spent     = $expenses > $repetition->amount ? 0 : $expenses; | ||||
|                 $overspent = $expenses > $repetition->amount ? $expenses - $repetition->amount : 0; | ||||
|                 $overspent = $expenses > $repetition->amount ? bcsub($expenses, $repetition->amount) : 0; | ||||
|  | ||||
|                 $budgetLine->setLeft($left); | ||||
|                 $budgetLine->setSpent($spent); | ||||
|   | ||||
| @@ -161,7 +161,7 @@ class JsonController extends Controller | ||||
|         } | ||||
|         /** @var Bill $entry */ | ||||
|         foreach ($unpaid as $entry) { | ||||
|             $current = ($entry[0]->amount_max + $entry[0]->amount_min) / 2; | ||||
|             $current = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2); | ||||
|             $amount  = bcadd($amount, $current); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -47,10 +47,11 @@ class PiggyBankController extends Controller | ||||
|      */ | ||||
|     public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank) | ||||
|     { | ||||
|         bcscale(2); | ||||
|         $date          = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date); | ||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; | ||||
|         $leftToSave    = $piggyBank->targetamount - $savedSoFar; | ||||
|         $leftToSave    = bcsub($piggyBank->targetamount, $savedSoFar); | ||||
|         $maxAmount     = min($leftOnAccount, $leftToSave); | ||||
|  | ||||
|         return view('piggy-banks.add', compact('piggyBank', 'maxAmount')); | ||||
| @@ -173,7 +174,7 @@ class PiggyBankController extends Controller | ||||
|         foreach ($piggyBanks as $piggyBank) { | ||||
|             $piggyBank->savedSoFar = round($piggyBank->currentRelevantRep()->currentamount, 2); | ||||
|             $piggyBank->percentage = $piggyBank->savedSoFar != 0 ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0; | ||||
|             $piggyBank->leftToSave = $piggyBank->targetamount - $piggyBank->savedSoFar; | ||||
|             $piggyBank->leftToSave = bcsub($piggyBank->targetamount, $piggyBank->savedSoFar); | ||||
|  | ||||
|             /* | ||||
|              * Fill account information: | ||||
| @@ -211,7 +212,7 @@ class PiggyBankController extends Controller | ||||
|  | ||||
|         if (is_array($data)) { | ||||
|             foreach ($data as $order => $id) { | ||||
|                 $repository->setOrder(intval($id), (intval($order) + 1)); | ||||
|                 $repository->setOrder(intval($id), ($order + 1)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -225,13 +226,13 @@ class PiggyBankController extends Controller | ||||
|      */ | ||||
|     public function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank) | ||||
|     { | ||||
|         bcscale(2); | ||||
|         $amount        = round(Input::get('amount'), 2); | ||||
|         $date          = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date); | ||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount; | ||||
|         $leftToSave    = $piggyBank->targetamount - $savedSoFar; | ||||
|         $leftToSave    = bcsub($piggyBank->targetamount, $savedSoFar); | ||||
|         $maxAmount     = round(min($leftOnAccount, $leftToSave), 2); | ||||
|         bcscale(2); | ||||
|  | ||||
|         if ($amount <= $maxAmount) { | ||||
|             $repetition                = $piggyBank->currentRelevantRep(); | ||||
|   | ||||
| @@ -246,10 +246,11 @@ class TransactionController extends Controller | ||||
|      */ | ||||
|     public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||
|     { | ||||
|         bcscale(2); | ||||
|         $journal->transactions->each( | ||||
|             function (Transaction $t) use ($journal, $repository) { | ||||
|                 $t->before = $repository->getAmountBefore($journal, $t); | ||||
|                 $t->after  = $t->before + $t->amount; | ||||
|                 $t->after  = bcadd($t->before, $t->amount); | ||||
|             } | ||||
|         ); | ||||
|         $what     = strtolower($journal->transactionType->type); | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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); | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user