mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Some math fixes. Not bugs.
This commit is contained in:
@@ -60,9 +60,10 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
|
|
||||||
|
|
||||||
$accounts = $this->query->getAllAccounts($date, $end, $shared);
|
$accounts = $this->query->getAllAccounts($date, $end, $shared);
|
||||||
$start = 0;
|
$start = '0';
|
||||||
$end = 0;
|
$end = '0';
|
||||||
$diff = 0;
|
$diff = '0';
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
// remove cash account, if any:
|
// remove cash account, if any:
|
||||||
$accounts = $accounts->filter(
|
$accounts = $accounts->filter(
|
||||||
@@ -77,9 +78,9 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
|
|
||||||
// summarize:
|
// summarize:
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$start += $account->startBalance;
|
$start = bcadd($start, $account->startBalance);
|
||||||
$end += $account->endBalance;
|
$end = bcadd($end, $account->endBalance);
|
||||||
$diff += ($account->endBalance - $account->startBalance);
|
$diff = bcadd($diff, ($account->endBalance - $account->startBalance));
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new AccountCollection;
|
$object = new AccountCollection;
|
||||||
|
@@ -205,7 +205,8 @@ class AccountController extends Controller
|
|||||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||||
|
|
||||||
];
|
];
|
||||||
$account = $repository->store($accountData);
|
|
||||||
|
$account = $repository->store($accountData);
|
||||||
|
|
||||||
Session::flash('success', 'New account "' . $account->name . '" stored!');
|
Session::flash('success', 'New account "' . $account->name . '" stored!');
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
@@ -93,6 +93,7 @@ class BudgetController extends Controller
|
|||||||
{
|
{
|
||||||
$start = clone $repetition->startdate;
|
$start = clone $repetition->startdate;
|
||||||
$end = $repetition->enddate;
|
$end = $repetition->enddate;
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
@@ -113,8 +114,8 @@ class BudgetController extends Controller
|
|||||||
/*
|
/*
|
||||||
* Sum of expenses on this day:
|
* Sum of expenses on this day:
|
||||||
*/
|
*/
|
||||||
$sum = $repository->expensesOnDayCorrected($budget, $start);
|
$sum = $repository->expensesOnDayCorrected($budget, $start);
|
||||||
$amount += $sum;
|
$amount = bcadd($amount, $sum);
|
||||||
$entries->push([clone $start, $amount]);
|
$entries->push([clone $start, $amount]);
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
}
|
}
|
||||||
|
@@ -70,6 +70,7 @@ class HomeController extends Controller
|
|||||||
{
|
{
|
||||||
$types = Config::get('firefly.accountTypesByIdentifier.asset');
|
$types = Config::get('firefly.accountTypesByIdentifier.asset');
|
||||||
$count = $repository->countAccounts($types);
|
$count = $repository->countAccounts($types);
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
|
|
||||||
if ($count == 0) {
|
if ($count == 0) {
|
||||||
@@ -92,7 +93,7 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
$savingsTotal = 0;
|
$savingsTotal = 0;
|
||||||
foreach ($savings as $savingAccount) {
|
foreach ($savings as $savingAccount) {
|
||||||
$savingsTotal += Steam::balance($savingAccount, $end);
|
$savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sum = $repository->sumOfEverything();
|
$sum = $repository->sumOfEverything();
|
||||||
|
@@ -36,6 +36,7 @@ class JsonController extends Controller
|
|||||||
{
|
{
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
// works for json too!
|
// works for json too!
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
@@ -54,7 +55,7 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
$amount += $repository->billPaymentsInRange($bill, $start, $end);
|
$amount = bcadd($amount, $repository->billPaymentsInRange($bill, $start, $end));
|
||||||
}
|
}
|
||||||
unset($bill, $bills);
|
unset($bill, $bills);
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ class JsonController extends Controller
|
|||||||
if ($balance == 0) {
|
if ($balance == 0) {
|
||||||
// find a transfer TO the credit card which should account for
|
// find a transfer TO the credit card which should account for
|
||||||
// anything paid. If not, the CC is not yet used.
|
// anything paid. If not, the CC is not yet used.
|
||||||
$amount += $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount');
|
$amount = bcadd($amount, $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
@@ -90,6 +91,7 @@ class JsonController extends Controller
|
|||||||
$amount = 0;
|
$amount = 0;
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
// works for json too!
|
// works for json too!
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
@@ -131,7 +133,7 @@ class JsonController extends Controller
|
|||||||
/** @var Bill $entry */
|
/** @var Bill $entry */
|
||||||
foreach ($unpaid as $entry) {
|
foreach ($unpaid as $entry) {
|
||||||
$current = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
$current = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
||||||
$amount += $current;
|
$amount = bcadd($amount, $current);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
|
@@ -166,6 +166,7 @@ class PiggyBankController extends Controller
|
|||||||
/** @var Collection $piggyBanks */
|
/** @var Collection $piggyBanks */
|
||||||
$piggyBanks = $piggyRepository->getPiggyBanks();
|
$piggyBanks = $piggyRepository->getPiggyBanks();
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
/** @var PiggyBank $piggyBank */
|
/** @var PiggyBank $piggyBank */
|
||||||
@@ -188,9 +189,9 @@ class PiggyBankController extends Controller
|
|||||||
'leftToSave' => $piggyBank->leftToSave
|
'leftToSave' => $piggyBank->leftToSave
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$accounts[$account->id]['sumOfSaved'] += $piggyBank->savedSoFar;
|
$accounts[$account->id]['sumOfSaved'] = bcadd($accounts[$account->id]['sumOfSaved'], $piggyBank->savedSoFar);
|
||||||
$accounts[$account->id]['sumOfTargets'] += floatval($piggyBank->targetamount);
|
$accounts[$account->id]['sumOfTargets'] = bcadd($accounts[$account->id]['sumOfTargets'], $piggyBank->targetamount);
|
||||||
$accounts[$account->id]['leftToSave'] += $piggyBank->leftToSave;
|
$accounts[$account->id]['leftToSave'] = bcadd($accounts[$account->id]['leftToSave'], $piggyBank->leftToSave);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,10 +231,11 @@ class PiggyBankController extends Controller
|
|||||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
|
||||||
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
$leftToSave = $piggyBank->targetamount - $savedSoFar;
|
||||||
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
if ($amount <= $maxAmount) {
|
if ($amount <= $maxAmount) {
|
||||||
$repetition = $piggyBank->currentRelevantRep();
|
$repetition = $piggyBank->currentRelevantRep();
|
||||||
$repetition->currentamount += $amount;
|
$repetition->currentamount = bcadd($repetition->currentamount, $amount);
|
||||||
$repetition->save();
|
$repetition->save();
|
||||||
|
|
||||||
// create event
|
// create event
|
||||||
|
Reference in New Issue
Block a user