Skip to content

Firefly III: a personal finances manager

Updated various files for #506

James Coleac86e7523341
diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php
index 6e21f8ad74..b651770829 100644
--- a/app/Generator/Chart/Basic/ChartJsGenerator.php
+++ b/app/Generator/Chart/Basic/ChartJsGenerator.php
@@ -58,7 +58,7 @@ class ChartJsGenerator implements GeneratorInterface
{
reset($data);
$first = current($data);
- $labels = array_keys($first['entries']);
+ $labels = is_array($first['entries']) ? array_keys($first['entries']) : [];
$chartData = [
'count' => count($data),
diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.php
index 594f26c6d8..9b14902d40 100644
--- a/app/Helpers/Collection/BalanceLine.php
+++ b/app/Helpers/Collection/BalanceLine.php
@@ -35,27 +35,10 @@ class BalanceLine
/** @var BudgetModel */
protected $budget;
- /** @var int */
- protected $role = self::ROLE_DEFAULTROLE;
-
/** @var BudgetLimit */
protected $budgetLimit;
-
- /**
- * @return BudgetLimit
- */
- public function getBudgetLimit(): BudgetLimit
- {
- return $this->budgetLimit;
- }
-
- /**
- * @param BudgetLimit $budgetLimit
- */
- public function setBudgetLimit(BudgetLimit $budgetLimit)
- {
- $this->budgetLimit = $budgetLimit;
- }
+ /** @var int */
+ protected $role = self::ROLE_DEFAULTROLE;
/**
*
@@ -106,6 +89,22 @@ class BalanceLine
$this->budget = $budget;
}
+ /**
+ * @return BudgetLimit
+ */
+ public function getBudgetLimit(): BudgetLimit
+ {
+ return $this->budgetLimit;
+ }
+
+ /**
+ * @param BudgetLimit $budgetLimit
+ */
+ public function setBudgetLimit(BudgetLimit $budgetLimit)
+ {
+ $this->budgetLimit = $budgetLimit;
+ }
+
/**
* @return Carbon
*/
diff --git a/app/Helpers/Collection/Budget.php b/app/Helpers/Collection/Budget.php
index 8821940b3e..f590cb6216 100644
--- a/app/Helpers/Collection/Budget.php
+++ b/app/Helpers/Collection/Budget.php
@@ -60,7 +60,6 @@ class Budget
*/
public function addBudgeted(string $add): Budget
{
- $add = strval(round($add, 2));
$this->budgeted = bcadd($this->budgeted, $add);
return $this;
@@ -73,7 +72,6 @@ class Budget
*/
public function addLeft(string $add): Budget
{
- $add = strval(round($add, 2));
$this->left = bcadd($this->left, $add);
return $this;
@@ -86,7 +84,6 @@ class Budget
*/
public function addOverspent(string $add): Budget
{
- $add = strval(round($add, 2));
$this->overspent = bcadd($this->overspent, $add);
return $this;
@@ -99,7 +96,6 @@ class Budget
*/
public function addSpent(string $add): Budget
{
- $add = strval(round($add, 2));
$this->spent = bcadd($this->spent, $add);
return $this;
@@ -168,7 +164,7 @@ class Budget
*/
public function setOverspent(string $overspent): Budget
{
- $this->overspent = strval(round($overspent, 2));
+ $this->overspent = $overspent;
return $this;
}
@@ -188,7 +184,7 @@ class Budget
*/
public function setSpent(string $spent): Budget
{
- $this->spent = strval(round($spent, 2));
+ $this->spent = $spent;
return $this;
}
diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.php
index 7090d387ba..faa4119a86 100644
--- a/app/Helpers/Collection/Category.php
+++ b/app/Helpers/Collection/Category.php
@@ -55,7 +55,6 @@ class Category
*/
public function addTotal(string $add)
{
- $add = strval(round($add, 2));
$this->total = bcadd($this->total, $add);
}
@@ -79,7 +78,7 @@ class Category
*/
public function getTotal(): string
{
- return strval(round($this->total, 2));
+ return $this->total;
}
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index 8bf0047e6f..5391d06883 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -128,7 +128,7 @@ class AccountController extends Controller
$endBalance = $endBalances[$id] ?? '0';
$diff = bcsub($endBalance, $startBalance);
if (bccomp($diff, '0') !== 0) {
- $chartData[$account->name] = round($diff, 2);
+ $chartData[$account->name] = $diff;
}
}
arsort($chartData);
@@ -391,7 +391,7 @@ class AccountController extends Controller
$diff = bcsub($endBalance, $startBalance);
$diff = bcmul($diff, '-1');
if (bccomp($diff, '0') !== 0) {
- $chartData[$account->name] = round($diff, 2);
+ $chartData[$account->name] = $diff;
}
}
@@ -475,11 +475,11 @@ class AccountController extends Controller
];
$currentStart = clone $start;
$range = Steam::balanceInRange($account, $start, clone $end);
- $previous = round(array_values($range)[0], 2);
+ $previous = array_values($range)[0];
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->formatLocalized(strval(trans('config.month_and_day')));
- $balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
+ $balance = isset($range[$format]) ? round($range[$format], 12) : $previous;
$previous = $balance;
$currentStart->addDay();
$currentSet['entries'][$label] = $balance;
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 958cb45d36..80fb6142aa 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -231,9 +231,9 @@ class BudgetController extends Controller
$current = clone $start;
while ($current < $end) {
- $currentStart = Navigation::startOfPeriod($current, $range);
- $currentEnd = Navigation::endOfPeriod($current, $range);
- $budgetLimits = $repository->getBudgetLimits($budget, $currentStart, $currentEnd);
+ $currentStart = Navigation::startOfPeriod($current, $range);
+ $currentEnd = Navigation::endOfPeriod($current, $range);
+ $budgetLimits = $repository->getBudgetLimits($budget, $currentStart, $currentEnd);
$index = $currentStart->format($key);
$budgeted[$index] = $budgetLimits->sum('amount');
$currentEnd->addDay();
@@ -258,7 +258,7 @@ class BudgetController extends Controller
$label = $periods[$period];
$spent = isset($entries[$budget->id]['entries'][$period]) ? $entries[$budget->id]['entries'][$period] : '0';
$limit = isset($budgeted[$period]) ? $budgeted[$period] : 0;
- $chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 2);
+ $chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = $limit;
}
diff --git a/app/Http/Controllers/Chart/BudgetReportController.php b/app/Http/Controllers/Chart/BudgetReportController.php
index 7dee6d99f0..70070ee2f3 100644
--- a/app/Http/Controllers/Chart/BudgetReportController.php
+++ b/app/Http/Controllers/Chart/BudgetReportController.php
@@ -245,8 +245,8 @@ class BudgetReportController extends Controller
$currentExpenses = $expenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = $sumOfExpenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = bcadd($currentExpenses, $sumOfExpenses[$budget->id]);
- $chartData[$budget->id]['entries'][$label] = round(bcmul($currentExpenses, '-1'), 2);
- $chartData[$budget->id . '-sum']['entries'][$label] = round(bcmul($sumOfExpenses[$budget->id], '-1'), 2);
+ $chartData[$budget->id]['entries'][$label] = bcmul($currentExpenses, '-1');
+ $chartData[$budget->id . '-sum']['entries'][$label] = bcmul($sumOfExpenses[$budget->id], '-1');
if (count($budgetLimits) > 0) {
$budgetLimitId = $budgetLimits->first()->id;
diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php
index 3adfdc2973..12a9c396a9 100644
--- a/app/Http/Controllers/NewUserController.php
+++ b/app/Http/Controllers/NewUserController.php
@@ -117,7 +117,7 @@ class NewUserController extends Controller
'virtualBalance' => 0,
'active' => true,
'accountRole' => 'defaultAsset',
- 'openingBalance' => round($request->input('bank_balance'), 2),
+ 'openingBalance' => round($request->input('bank_balance'), 12),
'openingBalanceDate' => new Carbon,
'openingBalanceCurrency' => intval($request->input('amount_currency_id_bank_balance')),
];
@@ -142,7 +142,7 @@ class NewUserController extends Controller
'virtualBalance' => 0,
'active' => true,
'accountRole' => 'savingAsset',
- 'openingBalance' => round($request->input('savings_balance'), 2),
+ 'openingBalance' => round($request->input('savings_balance'), 12),
'openingBalanceDate' => new Carbon,
'openingBalanceCurrency' => intval($request->input('amount_currency_id_savings_balance')),
];
@@ -163,7 +163,7 @@ class NewUserController extends Controller
'name' => 'Credit card',
'iban' => null,
'accountType' => 'asset',
- 'virtualBalance' => round($request->get('credit_card_limit'), 2),
+ 'virtualBalance' => round($request->get('credit_card_limit'), 12),
'active' => true,
'accountRole' => 'ccAsset',
'openingBalance' => null,
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php
index 6e2fabe084..94c4409bdd 100644
--- a/app/Http/Controllers/PiggyBankController.php
+++ b/app/Http/Controllers/PiggyBankController.php
@@ -219,7 +219,7 @@ class PiggyBankController extends Controller
$accounts = [];
/** @var PiggyBank $piggyBank */
foreach ($piggyBanks as $piggyBank) {
- $piggyBank->savedSoFar = round($piggyBank->currentRelevantRep()->currentamount, 2);
+ $piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
$piggyBank->percentage = $piggyBank->savedSoFar != 0 ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0;
$piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar));
$piggyBank->percentage = $piggyBank->percentage > 100 ? 100 : $piggyBank->percentage;
@@ -234,7 +234,7 @@ class PiggyBankController extends Controller
'balance' => Steam::balanceIgnoreVirtual($account, $end),
'leftForPiggyBanks' => $piggyBank->leftOnAccount($end),
'sumOfSaved' => strval($piggyBank->savedSoFar),
- 'sumOfTargets' => strval(round($piggyBank->targetamount, 2)),
+ 'sumOfTargets' => $piggyBank->targetamount,
'leftToSave' => $piggyBank->leftToSave,
];
} else {
@@ -279,15 +279,15 @@ class PiggyBankController extends Controller
*/
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
- $amount = strval(round($request->get('amount'), 2));
+ $amount = $request->get('amount');
/** @var Carbon $date */
$date = session('end', Carbon::now()->endOfMonth());
$leftOnAccount = $piggyBank->leftOnAccount($date);
$savedSoFar = strval($piggyBank->currentRelevantRep()->currentamount);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
- $maxAmount = round(min($leftOnAccount, $leftToSave), 2);
+ $maxAmount = strval(min(round($leftOnAccount, 12), round($leftToSave, 12)));
- if ($amount <= $maxAmount) {
+ if (bccomp($amount, $maxAmount) === -1) {
$repetition = $piggyBank->currentRelevantRep();
$currentAmount = $repetition->currentamount ?? '0';
$repetition->currentamount = bcadd($currentAmount, $amount);
@@ -319,11 +319,11 @@ class PiggyBankController extends Controller
*/
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
- $amount = strval(round($request->get('amount'), 2));
+ $amount = strval(round($request->get('amount'), 12));
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
- if ($amount <= $savedSoFar) {
+ if (bccomp($amount, $savedSoFar) === -1) {
$repetition = $piggyBank->currentRelevantRep();
$repetition->currentamount = bcsub($repetition->currentamount, $amount);
$repetition->save();
diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php
index 8b234d3e36..5676e902a8 100644
--- a/app/Http/Controllers/Transaction/MassController.php
+++ b/app/Http/Controllers/Transaction/MassController.php
@@ -214,7 +214,7 @@ class MassController extends Controller
'source_account_name' => $sourceAccountName,
'destination_account_id' => intval($destAccountId),
'destination_account_name' => $destAccountName,
- 'amount' => round($request->get('amount')[$journal->id], 4),
+ 'amount' => round($request->get('amount')[$journal->id], 12),
'currency_id' => intval($request->get('amount_currency_id_amount_' . $journal->id)),
'date' => new Carbon($request->get('date')[$journal->id]),
'interest_date' => $journal->interest_date,
diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php
index 087bfc8f36..7d4cd17761 100644
--- a/app/Http/Controllers/Transaction/SplitController.php
+++ b/app/Http/Controllers/Transaction/SplitController.php
@@ -138,7 +138,7 @@ class SplitController extends Controller
$data = $this->arrayFromInput($request);
$journal = $repository->updateSplitJournal($journal, $data);
- $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
+ $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
// save attachments:
$this->attachments->saveAttachmentsForModel($journal, $files);
@@ -257,7 +257,7 @@ class SplitController extends Controller
'source_account_name' => $transaction['source_account_name'],
'destination_account_id' => $transaction['destination_account_id'],
'destination_account_name' => $transaction['destination_account_name'],
- 'amount' => round($transaction['destination_amount'], 2),
+ 'amount' => round($transaction['destination_amount'], 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'],
];
@@ -292,7 +292,7 @@ class SplitController extends Controller
'source_account_name' => $transaction['source_account_name'] ?? '',
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
'destination_account_name' => $transaction['destination_account_name'] ?? '',
- 'amount' => round($transaction['amount'] ?? 0, 2),
+ 'amount' => round($transaction['amount'] ?? 0, 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'] ?? '',
];
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index 1e219707ee..364898614c 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -43,13 +43,13 @@ class AccountFormRequest extends Request
'active' => intval($this->input('active')) === 1,
'accountType' => $this->input('what'),
'currency_id' => intval($this->input('currency_id')),
- 'virtualBalance' => round($this->input('virtualBalance'), 2),
+ 'virtualBalance' => round($this->input('virtualBalance'), 12),
'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')),
'iban' => trim(strval($this->input('iban'))),
'BIC' => trim(strval($this->input('BIC'))),
'accountNumber' => trim(strval($this->input('accountNumber'))),
'accountRole' => $this->input('accountRole'),
- 'openingBalance' => round($this->input('openingBalance'), 2),
+ 'openingBalance' => round($this->input('openingBalance'), 12),
'openingBalanceDate' => new Carbon((string)$this->input('openingBalanceDate')),
'openingBalanceCurrency' => intval($this->input('amount_currency_id_openingBalance')),
'ccType' => $this->input('ccType'),
diff --git a/app/Http/Requests/BillFormRequest.php b/app/Http/Requests/BillFormRequest.php
index b16ce0ec33..c27a24377d 100644
--- a/app/Http/Requests/BillFormRequest.php
+++ b/app/Http/Requests/BillFormRequest.php
@@ -40,10 +40,10 @@ class BillFormRequest extends Request
return [
'name' => $this->get('name'),
'match' => $this->get('match'),
- 'amount_min' => round($this->get('amount_min'), 2),
+ 'amount_min' => round($this->get('amount_min'), 12),
'amount_currency_id_amount_min' => intval($this->get('amount_currency_id_amount_min')),
'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')),
- 'amount_max' => round($this->get('amount_max'), 2),
+ 'amount_max' => round($this->get('amount_max'), 12),
'date' => new Carbon($this->get('date')),
'repeat_freq' => $this->get('repeat_freq'),
'skip' => intval($this->get('skip')),
diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php
index 7f582042a7..69734b26bf 100644
--- a/app/Http/Requests/JournalFormRequest.php
+++ b/app/Http/Requests/JournalFormRequest.php
@@ -59,7 +59,7 @@ class JournalFormRequest extends Request
// transaction / journal data:
'description' => $this->getFieldOrEmptyString('description'),
- 'amount' => round($this->get('amount'), 2),
+ 'amount' => round($this->get('amount'), 12),
'budget_id' => intval($this->get('budget_id')),
'category' => $this->getFieldOrEmptyString('category'),
'source_account_id' => intval($this->get('source_account_id')),
diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankFormRequest.php
index 684ad148d9..3411975166 100644
--- a/app/Http/Requests/PiggyBankFormRequest.php
+++ b/app/Http/Requests/PiggyBankFormRequest.php
@@ -41,7 +41,7 @@ class PiggyBankFormRequest extends Request
'name' => trim($this->get('name')),
'startdate' => new Carbon,
'account_id' => intval($this->get('account_id')),
- 'targetamount' => round($this->get('targetamount'), 2),
+ 'targetamount' => round($this->get('targetamount'), 12),
'targetdate' => strlen(strval($this->get('targetdate'))) > 0 ? new Carbon($this->get('targetdate')) : null,
'note' => trim(strval($this->get('note'))),
];
diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.php
index 539838c794..2bf7100677 100644
--- a/app/Http/Requests/SplitJournalFormRequest.php
+++ b/app/Http/Requests/SplitJournalFormRequest.php
@@ -93,7 +93,7 @@ class SplitJournalFormRequest extends Request
$category = $this->get('category')[$index] ?? '';
$transaction = [
'description' => $description,
- 'amount' => round($this->get('amount')[$index], 2),
+ 'amount' => round($this->get('amount')[$index], 12),
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
'category' => trim($category),
'source_account_id' => isset($this->get('source_account_id')[$index])
diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php
index 6b64a2b862..ab0fceb6b7 100644
--- a/app/Import/Converter/Amount.php
+++ b/app/Import/Converter/Amount.php
@@ -62,7 +62,7 @@ class Amount extends BasicConverter implements ConverterInterface
$this->setCertainty(90);
- return round(floatval($value), 4);
+ return round(floatval($value), 12);
}
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 2d07b89f37..a4a2813cb9 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -318,7 +318,7 @@ class Account extends Model
*/
public function setVirtualBalanceAttribute($value)
{
- $this->attributes['virtual_balance'] = strval(round($value, 2));
+ $this->attributes['virtual_balance'] = strval(round($value, 12));
}
/**
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index a536caa18e..bf67e0f730 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -29,9 +29,6 @@ class Bill extends Model
{
use ValidatingTrait;
- /** @var array */
- protected $dates = ['created_at', 'updated_at', 'deleted_at'];
-
/**
* The attributes that should be casted to native types.
*
@@ -49,6 +46,8 @@ class Bill extends Model
'name_encrypted' => 'boolean',
'match_encrypted' => 'boolean',
];
+ /** @var array */
+ protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
'automatch', 'active',];
@@ -105,7 +104,7 @@ class Bill extends Model
*/
public function setAmountMaxAttribute($value)
{
- $this->attributes['amount_max'] = strval(round($value, 2));
+ $this->attributes['amount_max'] = strval(round($value, 12));
}
/**
@@ -113,7 +112,7 @@ class Bill extends Model
*/
public function setAmountMinAttribute($value)
{
- $this->attributes['amount_min'] = strval(round($value, 2));
+ $this->attributes['amount_min'] = strval(round($value, 12));
}
/**
diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php
index 04ad13e6b4..a6c2b68f97 100644
--- a/app/Models/BudgetLimit.php
+++ b/app/Models/BudgetLimit.php
@@ -81,7 +81,7 @@ class BudgetLimit extends Model
*/
public function setAmountAttribute($value)
{
- $this->attributes['amount'] = strval(round($value, 2));
+ $this->attributes['amount'] = strval(round($value, 12));
}
}
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index e9b6b4a980..34c742bd7f 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -35,7 +35,7 @@ class PiggyBank extends Model
* @var array
*/
protected $casts
- = [
+ = [
'created_at' => 'date',
'updated_at' => 'date',
'deleted_at' => 'date',
@@ -168,6 +168,6 @@ class PiggyBank extends Model
*/
public function setTargetamountAttribute($value)
{
- $this->attributes['targetamount'] = strval(round($value, 2));
+ $this->attributes['targetamount'] = strval(round($value, 12));
}
}
diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php
index 50e3398f26..258da0331b 100644
--- a/app/Support/ExpandedForm.php
+++ b/app/Support/ExpandedForm.php
@@ -506,7 +506,7 @@ class ExpandedForm
// make sure value is formatted nicely:
if (!is_null($value) && $value !== '') {
- $value = round($value, 2);
+ $value = round($value, $defaultCurrency->decimal_places);
}