From de260adca4f2afdf67558aadeade3d8c58d4225e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 03:00:40 +0000 Subject: [PATCH 01/10] Bump postcss from 8.4.19 to 8.4.20 Bumps [postcss](https://github.com/postcss/postcss) from 8.4.19 to 8.4.20. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.19...8.4.20) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index b744a074b9..53819cebb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4247,9 +4247,9 @@ postcss@^7.0.36: source-map "^0.6.1" postcss@^8.1.10, postcss@^8.2.15, postcss@^8.4, postcss@^8.4.14: - version "8.4.19" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.19.tgz#61178e2add236b17351897c8bcc0b4c8ecab56fc" - integrity sha512-h+pbPsyhlYj6N2ozBmHhHrs9DzGmbaarbLvWipMRO7RLS+v4onj26MPFXA5OBYFxyqYhUJK456SwDcY9H2/zsA== + version "8.4.20" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.20.tgz#64c52f509644cecad8567e949f4081d98349dc56" + integrity sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g== dependencies: nanoid "^3.3.4" picocolors "^1.0.0" From 388ee14dfc410f52a992aa9ca330101bb9ae250a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Dec 2022 03:00:27 +0000 Subject: [PATCH 02/10] Bump fakerphp/faker from 1.20.0 to 1.21.0 Bumps [fakerphp/faker](https://github.com/FakerPHP/Faker) from 1.20.0 to 1.21.0. - [Release notes](https://github.com/FakerPHP/Faker/releases) - [Changelog](https://github.com/FakerPHP/Faker/blob/main/CHANGELOG.md) - [Commits](https://github.com/FakerPHP/Faker/compare/v1.20.0...v1.21.0) --- updated-dependencies: - dependency-name: fakerphp/faker dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index ebc19d159c..9992f6baa6 100644 --- a/composer.lock +++ b/composer.lock @@ -8880,20 +8880,20 @@ }, { "name": "fakerphp/faker", - "version": "v1.20.0", + "version": "v1.21.0", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "37f751c67a5372d4e26353bd9384bc03744ec77b" + "reference": "92efad6a967f0b79c499705c69b662f738cc9e4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/37f751c67a5372d4e26353bd9384bc03744ec77b", - "reference": "37f751c67a5372d4e26353bd9384bc03744ec77b", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/92efad6a967f0b79c499705c69b662f738cc9e4d", + "reference": "92efad6a967f0b79c499705c69b662f738cc9e4d", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", + "php": "^7.4 || ^8.0", "psr/container": "^1.0 || ^2.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" }, @@ -8904,7 +8904,8 @@ "bamarni/composer-bin-plugin": "^1.4.1", "doctrine/persistence": "^1.3 || ^2.0", "ext-intl": "*", - "symfony/phpunit-bridge": "^4.4 || ^5.2" + "phpunit/phpunit": "^9.5.26", + "symfony/phpunit-bridge": "^5.4.16" }, "suggest": { "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", @@ -8916,7 +8917,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "v1.20-dev" + "dev-main": "v1.21-dev" } }, "autoload": { @@ -8941,9 +8942,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.20.0" + "source": "https://github.com/FakerPHP/Faker/tree/v1.21.0" }, - "time": "2022-07-20T13:12:54+00:00" + "time": "2022-12-13T13:54:32+00:00" }, { "name": "hamcrest/hamcrest-php", From b0da22ddf2eb253e9001c7c0b5cadf7fb20485af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Dec 2022 03:00:37 +0000 Subject: [PATCH 03/10] Bump laravel/framework from 9.43.0 to 9.44.0 Bumps [laravel/framework](https://github.com/laravel/framework) from 9.43.0 to 9.44.0. - [Release notes](https://github.com/laravel/framework/releases) - [Changelog](https://github.com/laravel/framework/blob/9.x/CHANGELOG.md) - [Commits](https://github.com/laravel/framework/compare/v9.43.0...v9.44.0) --- updated-dependencies: - dependency-name: laravel/framework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index ebc19d159c..51d0db5036 100644 --- a/composer.lock +++ b/composer.lock @@ -1856,16 +1856,16 @@ }, { "name": "laravel/framework", - "version": "v9.43.0", + "version": "v9.44.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "011f2e1d49a11c22519a7899b46ddf3bc5b0f40b" + "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/011f2e1d49a11c22519a7899b46ddf3bc5b0f40b", - "reference": "011f2e1d49a11c22519a7899b46ddf3bc5b0f40b", + "url": "https://api.github.com/repos/laravel/framework/zipball/60808a7d9acd53461fd69634c08fc7e0a99fbf98", + "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98", "shasum": "" }, "require": { @@ -2038,7 +2038,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-12-06T14:26:07+00:00" + "time": "2022-12-15T14:56:36+00:00" }, { "name": "laravel/passport", @@ -2618,16 +2618,16 @@ }, { "name": "league/config", - "version": "v1.1.1", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/thephpleague/config.git", - "reference": "a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e" + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/config/zipball/a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e", - "reference": "a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e", + "url": "https://api.github.com/repos/thephpleague/config/zipball/754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", "shasum": "" }, "require": { @@ -2636,7 +2636,7 @@ "php": "^7.4 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^0.12.90", + "phpstan/phpstan": "^1.8.2", "phpunit/phpunit": "^9.5.5", "scrutinizer/ocular": "^1.8.1", "unleashedtech/php-coding-standard": "^3.1", @@ -2696,7 +2696,7 @@ "type": "github" } ], - "time": "2021-08-14T12:15:32+00:00" + "time": "2022-12-11T20:36:23+00:00" }, { "name": "league/csv", From 3fe5e5ea8ca78bc26dbe77825879c15aee9da853 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Dec 2022 03:00:53 +0000 Subject: [PATCH 04/10] Bump jquery from 3.6.1 to 3.6.2 Bumps [jquery](https://github.com/jquery/jquery) from 3.6.1 to 3.6.2. - [Release notes](https://github.com/jquery/jquery/releases) - [Commits](https://github.com/jquery/jquery/compare/3.6.1...3.6.2) --- updated-dependencies: - dependency-name: jquery dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 53819cebb0..e09f145210 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3290,9 +3290,9 @@ jest-worker@^27.4.5: supports-color "^8.0.0" jquery@^3: - version "3.6.1" - resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.1.tgz#fab0408f8b45fc19f956205773b62b292c147a16" - integrity sha512-opJeO4nCucVnsjiXOE+/PcCgYw9Gwpvs/a6B1LL/lQhwWwpbVEVYDZ1FokFr8PRc7ghYlrFPuyHuiiDNTQxmcw== + version "3.6.2" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.2.tgz#8302bbc9160646f507bdf59d136a478b312783c4" + integrity sha512-/e7ulNIEEYk1Z/l4X0vpxGt+B/dNsV8ghOPAWZaJs8pkGvsSC0tm33aMGylXcj/U7y4IcvwtMXPMyBFZn/gK9A== js-tokens@^4.0.0: version "4.0.0" From 395b6ecb765119fa7d053e9a07fbb775c8870ec6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 21 Dec 2022 19:11:52 +0100 Subject: [PATCH 05/10] Make sure cache is cleared after transaction deletion. --- app/Http/Controllers/Transaction/DeleteController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Transaction/DeleteController.php b/app/Http/Controllers/Transaction/DeleteController.php index b023d78317..a540dcd2e9 100644 --- a/app/Http/Controllers/Transaction/DeleteController.php +++ b/app/Http/Controllers/Transaction/DeleteController.php @@ -137,6 +137,7 @@ class DeleteController extends Controller Log::debug(sprintf('Now going to trigger updated account event for account #%d', $account->id)); event(new UpdatedAccount($account)); } + app('preferences')->mark(); return redirect($this->getPreviousUrl('transactions.delete.url')); From e43372b2ce171aab01d87dec79a1f17727660244 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 21 Dec 2022 19:12:47 +0100 Subject: [PATCH 06/10] Fix error --- app/Http/Controllers/Auth/RegisterController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c7a5511215..e21fa46e75 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -148,7 +148,7 @@ class RegisterController extends Controller $allowRegistration = $this->allowedToRegister(); if (false === $allowRegistration) { - $message = 'Registration is currently not available.'; + $message = 'Registration is currently not available. If you are the administrator, you can enable this in the administration.'; return view('error', compact('message')); } From c47980a737cba29f42b1c0ec47365224620d663a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Dec 2022 05:06:39 +0100 Subject: [PATCH 07/10] Remove many references to (float) --- .../Controllers/Chart/AccountController.php | 4 +- .../Insight/Expense/AccountController.php | 4 +- .../Insight/Expense/BillController.php | 8 +- .../Insight/Expense/BudgetController.php | 4 +- .../Insight/Expense/CategoryController.php | 4 +- .../Insight/Expense/PeriodController.php | 4 +- .../Insight/Transfer/TagController.php | 2 +- .../Controllers/Summary/BasicController.php | 16 +-- .../V1/Requests/Models/Bill/StoreRequest.php | 7 +- .../V1/Requests/Models/Bill/UpdateRequest.php | 7 +- .../Requests/User/PreferenceStoreRequest.php | 1 + .../Requests/User/PreferenceUpdateRequest.php | 1 + .../Commands/Upgrade/MigrateToGroups.php | 2 +- app/Factory/TagFactory.php | 4 +- .../Chart/Basic/ChartJsGenerator.php | 4 +- .../Controllers/Account/EditController.php | 4 +- .../Controllers/Account/IndexController.php | 4 +- .../Account/ReconcileController.php | 4 +- app/Http/Controllers/Bill/EditController.php | 4 +- .../Budget/AvailableBudgetController.php | 2 +- .../Budget/BudgetLimitController.php | 46 ++++---- .../Controllers/Budget/EditController.php | 44 ++++--- .../Controllers/Budget/IndexController.php | 2 +- .../Controllers/Chart/AccountController.php | 8 +- .../Controllers/Chart/BudgetController.php | 6 +- .../Controllers/Chart/ReportController.php | 4 +- .../Controllers/Json/FrontpageController.php | 7 +- .../Controllers/Json/ReconcileController.php | 4 +- .../PiggyBank/AmountController.php | 6 +- .../Controllers/PiggyBank/EditController.php | 35 +++--- .../Controllers/Report/BudgetController.php | 6 +- .../Controllers/Report/CategoryController.php | 2 +- .../Transaction/MassController.php | 2 +- app/Repositories/Account/AccountTasker.php | 4 +- .../Budget/NoBudgetRepository.php | 2 +- .../Budget/OperationsRepository.php | 2 +- .../PiggyBank/ModifiesPiggyBanks.php | 4 +- app/Support/Amount.php | 47 ++++---- .../Category/WholePeriodChartGenerator.php | 4 +- app/Support/Form/CurrencyForm.php | 4 +- app/Support/Steam.php | 109 +++++++++++------- 41 files changed, 230 insertions(+), 208 deletions(-) diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.php index 264c1a97a0..463803a488 100644 --- a/app/Api/V1/Controllers/Chart/AccountController.php +++ b/app/Api/V1/Controllers/Chart/AccountController.php @@ -127,11 +127,11 @@ class AccountController extends Controller ]; $currentStart = clone $start; $range = app('steam')->balanceInRange($account, $start, clone $end); - $previous = round((float) array_values($range)[0], 12); + $previous = $range[0] ?? '0'; while ($currentStart <= $end) { $format = $currentStart->format('Y-m-d'); $label = $currentStart->toAtomString(); - $balance = array_key_exists($format, $range) ? round((float) $range[$format], 12) : $previous; + $balance = array_key_exists($format, $range) ? $range[$format] : $previous; $previous = $balance; $currentStart->addDay(); $currentSet['entries'][$label] = $balance; diff --git a/app/Api/V1/Controllers/Insight/Expense/AccountController.php b/app/Api/V1/Controllers/Insight/Expense/AccountController.php index cb2f74ca68..5cf8835f90 100644 --- a/app/Api/V1/Controllers/Insight/Expense/AccountController.php +++ b/app/Api/V1/Controllers/Insight/Expense/AccountController.php @@ -94,7 +94,7 @@ class AccountController extends Controller 'id' => (string) $expense['id'], 'name' => $expense['name'], 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; @@ -126,7 +126,7 @@ class AccountController extends Controller 'id' => (string) $expense['id'], 'name' => $expense['name'], 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; diff --git a/app/Api/V1/Controllers/Insight/Expense/BillController.php b/app/Api/V1/Controllers/Insight/Expense/BillController.php index 4bcf455c23..9b4872b84f 100644 --- a/app/Api/V1/Controllers/Insight/Expense/BillController.php +++ b/app/Api/V1/Controllers/Insight/Expense/BillController.php @@ -101,7 +101,7 @@ class BillController extends Controller 'currency_code' => $journal['currency_code'], ]; $response[$key]['difference'] = bcadd($response[$key]['difference'], $journal['amount']); - $response[$key]['difference_float'] = (float) $response[$key]['difference']; + $response[$key]['difference_float'] = (float) $response[$key]['difference']; // intentional float } if (0 !== $foreignCurrencyId) { $response[$foreignKey] = $response[$foreignKey] ?? [ @@ -111,7 +111,7 @@ class BillController extends Controller 'currency_code' => $journal['foreign_currency_code'], ]; $response[$foreignKey]['difference'] = bcadd($response[$foreignKey]['difference'], $journal['foreign_amount']); - $response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; + $response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float } } @@ -154,7 +154,7 @@ class BillController extends Controller 'currency_code' => $journal['currency_code'], ]; $response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']); - $response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; + $response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; // intentional float } if (0 !== $foreignCurrencyId) { $response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [ @@ -164,7 +164,7 @@ class BillController extends Controller 'currency_code' => $journal['foreign_currency_code'], ]; $response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']); - $response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; + $response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; // intentional float } } diff --git a/app/Api/V1/Controllers/Insight/Expense/BudgetController.php b/app/Api/V1/Controllers/Insight/Expense/BudgetController.php index cf135f6abd..cc9fc38593 100644 --- a/app/Api/V1/Controllers/Insight/Expense/BudgetController.php +++ b/app/Api/V1/Controllers/Insight/Expense/BudgetController.php @@ -91,7 +91,7 @@ class BudgetController extends Controller 'id' => (string) $budget->id, 'name' => $budget->name, 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; @@ -120,7 +120,7 @@ class BudgetController extends Controller foreach ($expenses as $expense) { $result[] = [ 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; diff --git a/app/Api/V1/Controllers/Insight/Expense/CategoryController.php b/app/Api/V1/Controllers/Insight/Expense/CategoryController.php index cc2b25fc4a..121c45d635 100644 --- a/app/Api/V1/Controllers/Insight/Expense/CategoryController.php +++ b/app/Api/V1/Controllers/Insight/Expense/CategoryController.php @@ -92,7 +92,7 @@ class CategoryController extends Controller 'id' => (string) $category->id, 'name' => $category->name, 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; @@ -121,7 +121,7 @@ class CategoryController extends Controller foreach ($expenses as $expense) { $result[] = [ 'difference' => $expense['sum'], - 'difference_float' => (float) $expense['sum'], + 'difference_float' => (float) $expense['sum'], // intentional float 'currency_id' => (string) $expense['currency_id'], 'currency_code' => $expense['currency_code'], ]; diff --git a/app/Api/V1/Controllers/Insight/Expense/PeriodController.php b/app/Api/V1/Controllers/Insight/Expense/PeriodController.php index 6d32267b8f..4a7e321cf4 100644 --- a/app/Api/V1/Controllers/Insight/Expense/PeriodController.php +++ b/app/Api/V1/Controllers/Insight/Expense/PeriodController.php @@ -66,7 +66,7 @@ class PeriodController extends Controller 'currency_code' => $journal['currency_code'], ]; $response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']); - $response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; + $response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; // intentional float } if (0 !== $foreignCurrencyId) { $response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [ @@ -76,7 +76,7 @@ class PeriodController extends Controller 'currency_code' => $journal['foreign_currency_code'], ]; $response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']); - $response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; + $response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; // intentional float } } diff --git a/app/Api/V1/Controllers/Insight/Transfer/TagController.php b/app/Api/V1/Controllers/Insight/Transfer/TagController.php index edd0ab859f..bae49e777c 100644 --- a/app/Api/V1/Controllers/Insight/Transfer/TagController.php +++ b/app/Api/V1/Controllers/Insight/Transfer/TagController.php @@ -171,7 +171,7 @@ class TagController extends Controller $response[$foreignKey]['difference'] = bcadd( $response[$foreignKey]['difference'], app('steam')->positive($journal['foreign_amount']) ); - $response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; + $response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float } } } diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.php index af1ad594f2..6a204c99a6 100644 --- a/app/Api/V1/Controllers/Summary/BasicController.php +++ b/app/Api/V1/Controllers/Summary/BasicController.php @@ -188,7 +188,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('balance-in-%s', $currency->code), 'title' => trans('firefly.box_balance_in_currency', ['currency' => $currency->symbol]), - 'monetary_value' => round((float) $sums[$currencyId] ?? 0, $currency->decimal_places), + 'monetary_value' => $sums[$currencyId] ?? '0', 'currency_id' => $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, @@ -201,7 +201,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('spent-in-%s', $currency->code), 'title' => trans('firefly.box_spent_in_currency', ['currency' => $currency->symbol]), - 'monetary_value' => round((float) ($expenses[$currencyId] ?? 0), $currency->decimal_places), + 'monetary_value' => $expenses[$currencyId] ?? '0', 'currency_id' => $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, @@ -213,7 +213,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('earned-in-%s', $currency->code), 'title' => trans('firefly.box_earned_in_currency', ['currency' => $currency->symbol]), - 'monetary_value' => round((float) ($incomes[$currencyId] ?? 0), $currency->decimal_places), + 'monetary_value' => $incomes[$currencyId] ?? '0', 'currency_id' => $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, @@ -251,7 +251,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('bills-paid-in-%s', $currency->code), 'title' => trans('firefly.box_bill_paid_in_currency', ['currency' => $currency->symbol]), - 'monetary_value' => round((float) $amount, $currency->decimal_places), + 'monetary_value' => $amount, 'currency_id' => $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, @@ -271,7 +271,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('bills-unpaid-in-%s', $currency->code), 'title' => trans('firefly.box_bill_unpaid_in_currency', ['currency' => $currency->symbol]), - 'monetary_value' => round((float) $amount, $currency->decimal_places), + 'monetary_value' => $amount, 'currency_id' => $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, @@ -315,7 +315,7 @@ class BasicController extends Controller $return[] = [ 'key' => sprintf('left-to-spend-in-%s', $row['currency_code']), 'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $row['currency_symbol']]), - 'monetary_value' => round((float) $leftToSpend, $row['currency_decimal_places']), + 'monetary_value' => $leftToSpend, 'currency_id' => $row['currency_id'], 'currency_code' => $row['currency_code'], 'currency_symbol' => $row['currency_symbol'], @@ -373,8 +373,8 @@ class BasicController extends Controller foreach ($netWorthSet as $data) { /** @var TransactionCurrency $currency */ $currency = $data['currency']; - $amount = round((float) $data['balance'], $currency->decimal_places); - if (0.0 === $amount) { + $amount = $data['balance']; + if (0 === bccomp($amount, '0')) { continue; } // return stuff diff --git a/app/Api/V1/Requests/Models/Bill/StoreRequest.php b/app/Api/V1/Requests/Models/Bill/StoreRequest.php index 5e3c757dfd..e227803368 100644 --- a/app/Api/V1/Requests/Models/Bill/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Bill/StoreRequest.php @@ -104,9 +104,10 @@ class StoreRequest extends FormRequest $validator->after( static function (Validator $validator) { $data = $validator->getData(); - $min = (float) ($data['amount_min'] ?? 0); - $max = (float) ($data['amount_max'] ?? 0); - if ($min > $max) { + $min = $data['amount_min'] ?? '0'; + $max = $data['amount_max'] ?? '0'; + + if (1 === bccomp($min, $max)) { $validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max')); } } diff --git a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php index 0159fe68ed..a4d8bb5146 100644 --- a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php +++ b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php @@ -105,9 +105,10 @@ class UpdateRequest extends FormRequest static function (Validator $validator) { $data = $validator->getData(); if (array_key_exists('amount_min', $data) && array_key_exists('amount_max', $data)) { - $min = (float) ($data['amount_min'] ?? 0); - $max = (float) ($data['amount_max'] ?? 0); - if ($min > $max) { + $min = $data['amount_min'] ?? '0'; + $max = $data['amount_max'] ?? '0'; + + if (1 === bccomp($min, $max)) { $validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max')); } } diff --git a/app/Api/V1/Requests/User/PreferenceStoreRequest.php b/app/Api/V1/Requests/User/PreferenceStoreRequest.php index e652950b25..c626ccdfa5 100644 --- a/app/Api/V1/Requests/User/PreferenceStoreRequest.php +++ b/app/Api/V1/Requests/User/PreferenceStoreRequest.php @@ -46,6 +46,7 @@ class PreferenceStoreRequest extends FormRequest if ('false' === $array['data']) { $array['data'] = false; } + // TODO remove float if (is_numeric($array['data'])) { $array['data'] = (float) $array['data']; } diff --git a/app/Api/V1/Requests/User/PreferenceUpdateRequest.php b/app/Api/V1/Requests/User/PreferenceUpdateRequest.php index 7f389c872e..9a40f689c7 100644 --- a/app/Api/V1/Requests/User/PreferenceUpdateRequest.php +++ b/app/Api/V1/Requests/User/PreferenceUpdateRequest.php @@ -47,6 +47,7 @@ class PreferenceUpdateRequest extends FormRequest if ('false' === $array['data']) { $array['data'] = false; } + // TODO remove float if (is_numeric($array['data'])) { $array['data'] = (float) $array['data']; } diff --git a/app/Console/Commands/Upgrade/MigrateToGroups.php b/app/Console/Commands/Upgrade/MigrateToGroups.php index 7085092e7a..ec13761b51 100644 --- a/app/Console/Commands/Upgrade/MigrateToGroups.php +++ b/app/Console/Commands/Upgrade/MigrateToGroups.php @@ -330,7 +330,7 @@ class MigrateToGroups extends Command { $set = $journal->transactions->filter( static function (Transaction $subject) use ($transaction) { - $amount = (float) $transaction->amount * -1 === (float) $subject->amount; + $amount = (float) $transaction->amount * -1 === (float) $subject->amount; // intentional float $identifier = $transaction->identifier === $subject->identifier; Log::debug(sprintf('Amount the same? %s', var_export($amount, true))); Log::debug(sprintf('ID the same? %s', var_export($identifier, true))); diff --git a/app/Factory/TagFactory.php b/app/Factory/TagFactory.php index 66fa91707d..2803bdcdd9 100644 --- a/app/Factory/TagFactory.php +++ b/app/Factory/TagFactory.php @@ -81,8 +81,8 @@ class TagFactory public function create(array $data): ?Tag { $zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level']; - $latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude']; - $longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude']; + $latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude']; // intentional float + $longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude']; // intentional float $array = [ 'user_id' => $this->user->id, 'tag' => trim($data['tag']), diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php index 4aa3f0cb9c..18d45c86a6 100644 --- a/app/Generator/Chart/Basic/ChartJsGenerator.php +++ b/app/Generator/Chart/Basic/ChartJsGenerator.php @@ -59,7 +59,7 @@ class ChartJsGenerator implements GeneratorInterface $index = 0; foreach ($data as $key => $valueArray) { // make larger than 0 - $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $valueArray['amount']); + $chartData['datasets'][0]['data'][] = app('steam')->positive((string) $valueArray['amount']); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol']; $chartData['labels'][] = $key; @@ -174,7 +174,7 @@ class ChartJsGenerator implements GeneratorInterface $index = 0; foreach ($data as $key => $value) { // make larger than 0 - $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $value); + $chartData['datasets'][0]['data'][] = app('steam')->positive((string) $value); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['labels'][] = $key; diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index d51232e5cf..49848992a0 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -143,9 +143,9 @@ class EditController extends Controller 'BIC' => $repository->getMetaValue($account, 'BIC'), 'opening_balance_date' => $openingBalanceDate, 'liability_type_id' => $account->account_type_id, - 'opening_balance' => number_format((float) $openingBalanceAmount, $currency->decimal_places, '.', ''), + 'opening_balance' => app('steam')->bcround($openingBalanceAmount, $currency->decimal_places), 'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'), - 'virtual_balance' => number_format((float) $account->virtual_balance, $currency->decimal_places, '.', ''), + 'virtual_balance' => app('steam')->bcround($account->virtual_balance, $currency->decimal_places), 'currency_id' => $currency->id, 'include_net_worth' => $includeNetWorth, 'interest' => $repository->getMetaValue($account, 'interest'), diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index 2a23f4ee2a..c8d275aa74 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -108,7 +108,7 @@ class IndexController extends Controller $account->startBalance = $this->isInArray($startBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id); $account->difference = bcsub($account->endBalance, $account->startBalance); - $account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', ''); + $account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4); $account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type)); $account->current_debt = '0'; @@ -174,7 +174,7 @@ class IndexController extends Controller $account->startBalance = $this->isInArray($startBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id); $account->difference = bcsub($account->endBalance, $account->startBalance); - $account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', ''); + $account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4); $account->interestPeriod = (string) trans( sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')) ); diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 63d804caf1..cde88cbd16 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -128,8 +128,8 @@ class ReconcileController extends Controller $startDate = clone $start; $startDate->subDay(); - $startBalance = number_format((float) app('steam')->balance($account, $startDate), $currency->decimal_places, '.', ''); - $endBalance = number_format((float) app('steam')->balance($account, $end), $currency->decimal_places, '.', ''); + $startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places); + $endBalance = app('steam')->bcround( app('steam')->balance($account, $end), $currency->decimal_places); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); $subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]); diff --git a/app/Http/Controllers/Bill/EditController.php b/app/Http/Controllers/Bill/EditController.php index 0c4f459045..31adf6a27b 100644 --- a/app/Http/Controllers/Bill/EditController.php +++ b/app/Http/Controllers/Bill/EditController.php @@ -89,8 +89,8 @@ class EditController extends Controller } $currency = app('amount')->getDefaultCurrency(); - $bill->amount_min = round((float) $bill->amount_min, $currency->decimal_places); - $bill->amount_max = round((float) $bill->amount_max, $currency->decimal_places); + $bill->amount_min = app('steam')->bcround($bill->amount_min, $currency->decimal_places); + $bill->amount_max = app('steam')->bcround($bill->amount_max, $currency->decimal_places); $rules = $this->repository->getRulesForBill($bill); $defaultCurrency = app('amount')->getDefaultCurrency(); diff --git a/app/Http/Controllers/Budget/AvailableBudgetController.php b/app/Http/Controllers/Budget/AvailableBudgetController.php index 55e5bfbc19..0fd7961b52 100644 --- a/app/Http/Controllers/Budget/AvailableBudgetController.php +++ b/app/Http/Controllers/Budget/AvailableBudgetController.php @@ -162,7 +162,7 @@ class AvailableBudgetController extends Controller */ public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end) { - $availableBudget->amount = number_format((float) $availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', ''); + $availableBudget->amount = app('steam')->bcround($availableBudget->amount, $availableBudget->transactionCurrency->decimal_places); return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end')); } diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.php index b89884e40b..6e2e4cbd89 100644 --- a/app/Http/Controllers/Budget/BudgetLimitController.php +++ b/app/Http/Controllers/Budget/BudgetLimitController.php @@ -65,7 +65,7 @@ class BudgetLimitController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.budgets')); + app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-pie-chart'); $this->repository = app(BudgetRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); @@ -78,9 +78,9 @@ class BudgetLimitController extends Controller } /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end + * @param Budget $budget + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -107,8 +107,8 @@ class BudgetLimitController extends Controller } /** - * @param Request $request - * @param BudgetLimit $budgetLimit + * @param Request $request + * @param BudgetLimit $budgetLimit * * @return RedirectResponse|Redirector */ @@ -121,7 +121,7 @@ class BudgetLimitController extends Controller } /** - * @param Request $request + * @param Request $request * * @return JsonResponse * @throws FireflyException @@ -130,14 +130,14 @@ class BudgetLimitController extends Controller { Log::debug('Going to store new budget-limit.', $request->all()); // first search for existing one and update it if necessary. - $currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id')); - $budget = $this->repository->find((int) $request->get('budget_id')); + $currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id')); + $budget = $this->repository->find((int)$request->get('budget_id')); if (null === $currency || null === $budget) { throw new FireflyException('No valid currency or budget.'); } $start = Carbon::createFromFormat('Y-m-d', $request->get('start')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end')); - $amount = (string) $request->get('amount'); + $amount = (string)$request->get('amount'); $start->startOfDay(); $end->startOfDay(); @@ -150,17 +150,17 @@ class BudgetLimitController extends Controller $limit = $this->blRepository->find($budget, $currency, $start, $end); // sanity check on amount: - if ((float) $amount === 0.0) { + if (0 === bccomp($amount, '0')) { if (null !== $limit) { $this->blRepository->destroyBudgetLimit($limit); } // return empty=ish array: return response()->json([]); } - if ((int) $amount > 268435456) { + if ((int)$amount > 268435456) { // intentional cast to integer $amount = '268435456'; } - if((float) $amount < 0.0) { + if (-1 === bccomp($amount, '0')) { $amount = bcmul($amount, '-1'); } @@ -172,7 +172,7 @@ class BudgetLimitController extends Controller $limit = $this->blRepository->store( [ 'budget_id' => $request->get('budget_id'), - 'currency_id' => (int) $request->get('transaction_currency_id'), + 'currency_id' => (int)$request->get('transaction_currency_id'), 'start_date' => $start, 'end_date' => $end, 'amount' => $amount, @@ -187,7 +187,7 @@ class BudgetLimitController extends Controller $array['spent'] = $spentArr[$currency->id]['sum'] ?? '0'; $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); - $array['days_left'] = (string) $this->activeDaysLeft($start, $end); + $array['days_left'] = (string)$this->activeDaysLeft($start, $end); // left per day: $array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']); @@ -201,20 +201,20 @@ class BudgetLimitController extends Controller } /** - * @param Request $request - * @param BudgetLimit $budgetLimit + * @param Request $request + * @param BudgetLimit $budgetLimit * * @return JsonResponse */ public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse { - $amount = (string) $request->get('amount'); + $amount = (string)$request->get('amount'); if ('' === $amount) { $amount = '0'; } // sanity check on amount: - if ((float) $amount === 0.0) { + if (0 === bccomp($amount, '0')) { $budgetId = $budgetLimit->budget_id; $currency = $budgetLimit->transactionCurrency; $this->blRepository->destroyBudgetLimit($budgetLimit); @@ -226,10 +226,10 @@ class BudgetLimitController extends Controller ]; return response()->json($array); } - if ((int) $amount > 268435456) { // 268 million + if ((int)$amount > 268435456) { // 268 million, intentional integer $amount = '268435456'; } - if((float) $amount < 0.0) { + if (-1 === bccomp($amount, '0')) { $amount = bcmul($amount, '-1'); } @@ -246,12 +246,12 @@ class BudgetLimitController extends Controller $array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0'; $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); - $array['days_left'] = (string) $this->activeDaysLeft($limit->start_date, $limit->end_date); + $array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date); // left per day: $array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']); // left per day formatted. - $array['amount'] = number_format((float) $limit['amount'], $limit->transactionCurrency->decimal_places, '.', ''); + $array['amount'] = app('steam')->bcround($limit['amount'], $limit->transactionCurrency->decimal_places); $array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']); return response()->json($array); diff --git a/app/Http/Controllers/Budget/EditController.php b/app/Http/Controllers/Budget/EditController.php index da94091bc4..e72561074e 100644 --- a/app/Http/Controllers/Budget/EditController.php +++ b/app/Http/Controllers/Budget/EditController.php @@ -56,7 +56,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.budgets')); + app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-pie-chart'); $this->repository = app(BudgetRepositoryInterface::class); $this->attachments = app(AttachmentHelperInterface::class); @@ -69,41 +69,41 @@ class EditController extends Controller /** * Budget edit form. * - * @param Request $request - * @param Budget $budget + * @param Request $request + * @param Budget $budget * * @return Factory|View */ public function edit(Request $request, Budget $budget) { - $subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]); + $subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]); $autoBudget = $this->repository->getAutoBudget($budget); // auto budget types $autoBudgetTypes = [ - 0 => (string) trans('firefly.auto_budget_none'), - AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'), - AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'), + 0 => (string)trans('firefly.auto_budget_none'), + AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), + AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), ]; $autoBudgetPeriods = [ - 'daily' => (string) trans('firefly.auto_budget_period_daily'), - 'weekly' => (string) trans('firefly.auto_budget_period_weekly'), - 'monthly' => (string) trans('firefly.auto_budget_period_monthly'), - 'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'), - 'half_year' => (string) trans('firefly.auto_budget_period_half_year'), - 'yearly' => (string) trans('firefly.auto_budget_period_yearly'), + 'daily' => (string)trans('firefly.auto_budget_period_daily'), + 'weekly' => (string)trans('firefly.auto_budget_period_weekly'), + 'monthly' => (string)trans('firefly.auto_budget_period_monthly'), + 'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'), + 'half_year' => (string)trans('firefly.auto_budget_period_half_year'), + 'yearly' => (string)trans('firefly.auto_budget_period_yearly'), ]; // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); $currency = app('amount')->getDefaultCurrency(); $preFilled = [ - 'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active, - 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id, + 'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active, + 'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, ]; if ($autoBudget) { $amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; - $preFilled['auto_budget_amount'] = number_format((float) $amount, $autoBudget->transactionCurrency->decimal_places, '.', ''); + $preFilled['auto_budget_amount'] = app('steam')->bcround($amount, $autoBudget->transactionCurrency->decimal_places); } // put previous url in session if not redirect from store (not "return_to_edit"). @@ -119,8 +119,8 @@ class EditController extends Controller /** * Budget update routine. * - * @param BudgetFormUpdateRequest $request - * @param Budget $budget + * @param BudgetFormUpdateRequest $request + * @param Budget $budget * * @return RedirectResponse */ @@ -129,7 +129,7 @@ class EditController extends Controller $data = $request->getBudgetData(); $this->repository->update($budget, $data); - $request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name])); + $request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name])); $this->repository->cleanupBudgets(); app('preferences')->mark(); @@ -141,19 +141,17 @@ class EditController extends Controller $this->attachments->saveAttachmentsForModel($budget, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); } - if (1 === (int) $request->get('return_to_edit')) { - + if (1 === (int)$request->get('return_to_edit')) { $request->session()->put('budgets.edit.fromUpdate', true); $redirect = redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]); - } return $redirect; diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index 6986b402d7..ee24285984 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -210,7 +210,7 @@ class IndexController extends Controller $currency = $limit->transactionCurrency ?? $defaultCurrency; $array['budgeted'][] = [ 'id' => $limit->id, - 'amount' => number_format((float) $limit->amount, $currency->decimal_places, '.', ''), + 'amount' => app('steam')->bcround($limit->amount, $currency->decimal_places), 'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat), 'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat), 'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end), diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 9e90abf404..a4e60b70a6 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -127,7 +127,7 @@ class AccountController extends Controller $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float) $diff, + 'diff_float' => (float) $diff, // intentional float 'currency_id' => $currencyId, ]; } @@ -492,7 +492,7 @@ class AccountController extends Controller $theDate = $current->format('Y-m-d'); $balance = $range[$theDate] ?? $previous; $label = $current->isoFormat($format); - $entries[$label] = (float) $balance; + $entries[$label] = $balance; $previous = $balance; $current->addDay(); } @@ -502,7 +502,7 @@ class AccountController extends Controller case '1M': case '1Y': while ($end >= $current) { - $balance = (float) app('steam')->balance($account, $current, $currency); + $balance = app('steam')->balance($account, $current, $currency); $label = app('navigation')->periodShow($current, $step); $entries[$label] = $balance; $current = app('navigation')->addPeriod($current, $step, 0); @@ -586,7 +586,7 @@ class AccountController extends Controller $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float) $diff, + 'diff_float' => (float) $diff, // intentional float 'currency_id' => $currencyId, ]; } diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index e58025f58a..4857670459 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -483,13 +483,13 @@ class BudgetController extends Controller // get budget limit in this period for this currency. $limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd); if (null !== $limit) { - $chartData[1]['entries'][$title] = round((float) $limit->amount, $currency->decimal_places); + $chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places); } // get spent amount in this period for this currency. $sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency); $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0'); - $chartData[0]['entries'][$title] = round((float) $amount, $currency->decimal_places); + $chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places); $currentStart = clone $currentEnd; $currentStart->addDay()->startOfDay(); @@ -534,7 +534,7 @@ class BudgetController extends Controller $title = $currentStart->isoFormat($titleFormat); $sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency); $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0'); - $chartData[$title] = round((float) $amount, $currency->decimal_places); + $chartData[$title] = app('steam')->bcround($amount, $currency->decimal_places); $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); } diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php index 9d8950bd24..360fd65f68 100644 --- a/app/Http/Controllers/Chart/ReportController.php +++ b/app/Http/Controllers/Chart/ReportController.php @@ -243,8 +243,8 @@ class ReportController extends Controller while ($currentStart <= $end) { $key = $currentStart->format($format); $title = $currentStart->isoFormat($titleFormat); - $income['entries'][$title] = round((float) ($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']); - $expense['entries'][$title] = round((float) ($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']); + $income['entries'][$title] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']); + $expense['entries'][$title] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']); $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); } diff --git a/app/Http/Controllers/Json/FrontpageController.php b/app/Http/Controllers/Json/FrontpageController.php index 1f6a0902f8..67fcdab3a7 100644 --- a/app/Http/Controllers/Json/FrontpageController.php +++ b/app/Http/Controllers/Json/FrontpageController.php @@ -1,4 +1,5 @@ targetamount) { + if (0 !== bccomp($piggyBank->targetamount, '0')) { $pct = round(($amount / $piggyBank->targetamount) * 100); } @@ -70,12 +71,10 @@ class FrontpageController extends Controller if (!empty($info)) { try { $html = view('json.piggy-banks', compact('info'))->render(); - } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage())); $html = 'Could not render view.'; } - } return response()->json(['html' => $html]); diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index 5968f060e4..ba680a7801 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -238,8 +238,8 @@ class ReconcileController extends Controller $startDate->subDay(); $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); - $startBalance = round((float) app('steam')->balance($account, $startDate), $currency->decimal_places); - $endBalance = round((float) app('steam')->balance($account, $end), $currency->decimal_places); + $startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places); + $endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places); // get the transactions $selectionStart = clone $start; diff --git a/app/Http/Controllers/PiggyBank/AmountController.php b/app/Http/Controllers/PiggyBank/AmountController.php index 46802f9f4c..8b5292c100 100644 --- a/app/Http/Controllers/PiggyBank/AmountController.php +++ b/app/Http/Controllers/PiggyBank/AmountController.php @@ -78,7 +78,7 @@ class AmountController extends Controller $leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone'))); $savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank); $maxAmount = $leftOnAccount; - if (0.000 !== (float) $piggyBank->targetamount) { + if (0 !== bccomp($piggyBank->targetamount,'0')) { $leftToSave = bcsub($piggyBank->targetamount, $savedSoFar); $maxAmount = min($leftOnAccount, $leftToSave); } @@ -102,7 +102,7 @@ class AmountController extends Controller $savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank); $maxAmount = $leftOnAccount; - if (0.000 !== (float) $piggyBank->targetamount) { + if (0 !== bccomp($piggyBank->targetamount,'0')) { $leftToSave = bcsub($piggyBank->targetamount, $savedSoFar); $maxAmount = min($leftOnAccount, $leftToSave); } @@ -182,7 +182,7 @@ class AmountController extends Controller return redirect(route('piggy-banks.index')); } - $amount = number_format((float) $request->get('amount'), 12, '.', ''); + $amount = (string) $request->get('amount'); session()->flash( 'error', diff --git a/app/Http/Controllers/PiggyBank/EditController.php b/app/Http/Controllers/PiggyBank/EditController.php index ad8337f00c..3857b2b491 100644 --- a/app/Http/Controllers/PiggyBank/EditController.php +++ b/app/Http/Controllers/PiggyBank/EditController.php @@ -56,7 +56,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->attachments = app(AttachmentHelperInterface::class); @@ -70,13 +70,13 @@ class EditController extends Controller /** * Edit a piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ public function edit(PiggyBank $piggyBank) { - $subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); + $subTitle = (string)trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); $subTitleIcon = 'fa-pencil'; $note = $piggyBank->notes()->first(); // Flash some data to fill the form. @@ -87,15 +87,16 @@ class EditController extends Controller $currency = Amount::getDefaultCurrency(); } - $preFilled = ['name' => $piggyBank->name, - 'account_id' => $piggyBank->account_id, - 'targetamount' => number_format((float) $piggyBank->targetamount, $currency->decimal_places, '.', ''), - 'targetdate' => $targetDate, - 'startdate' => $startDate, - 'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '', - 'notes' => null === $note ? '' : $note->text, + $preFilled = [ + 'name' => $piggyBank->name, + 'account_id' => $piggyBank->account_id, + 'targetamount' => app('steam')->bcround($piggyBank->targetamount, $currency->decimal_places), + 'targetdate' => $targetDate, + 'startdate' => $startDate, + 'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '', + 'notes' => null === $note ? '' : $note->text, ]; - if (0.0 === (float) $piggyBank->targetamount) { + if (0 === bccomp($piggyBank->targetamount, '0')) { $preFilled['targetamount'] = ''; } session()->flash('preFilled', $preFilled); @@ -112,8 +113,8 @@ class EditController extends Controller /** * Update a piggy bank. * - * @param PiggyBankUpdateRequest $request - * @param PiggyBank $piggyBank + * @param PiggyBankUpdateRequest $request + * @param PiggyBank $piggyBank * * @return RedirectResponse|Redirector */ @@ -122,7 +123,7 @@ class EditController extends Controller $data = $request->getPiggyBankData(); $piggyBank = $this->piggyRepos->update($piggyBank, $data); - session()->flash('success', (string) trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name])); + session()->flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name])); app('preferences')->mark(); // store new attachment(s): @@ -132,7 +133,7 @@ class EditController extends Controller $this->attachments->saveAttachmentsForModel($piggyBank, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { @@ -140,12 +141,10 @@ class EditController extends Controller } $redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url')); - if (1 === (int) $request->get('return_to_edit')) { - + if (1 === (int)$request->get('return_to_edit')) { session()->put('piggy-banks.edit.fromUpdate', true); $redirect = redirect(route('piggy-banks.edit', [$piggyBank->id])); - } return $redirect; diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index 331396c26d..20a5016076 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -187,7 +187,7 @@ class BudgetController extends Controller $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float } } } @@ -266,7 +266,7 @@ class BudgetController extends Controller $total = $sums[$currencyId]['sum'] ?? '0'; $pct = '0'; if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) { - $pct = round((float) bcmul(bcdiv($sum, $total), '100')); + $pct = round((float) bcmul(bcdiv($sum, $total), '100')); // intentional float } $report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct; } @@ -383,7 +383,7 @@ class BudgetController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float) $journal['amount'], // intentional float 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index 945b0868a7..5b2294f67b 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -301,7 +301,7 @@ class CategoryController extends Controller $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float } } } diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index decccf47f3..ccc1dc5f52 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -146,7 +146,7 @@ class MassController extends Controller // reverse amounts foreach ($journals as $index => $journal) { - $journals[$index]['amount'] = number_format((float) app('steam')->positive($journal['amount']), $journal['currency_decimal_places'], '.', ''); + $journals[$index]['amount'] = app('steam')->bcround(app('steam')->positive($journal['amount']), $journal['currency_decimal_places']); $journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] ? null : app('steam')->positive($journal['foreign_amount']); } diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php index d57725ec61..37df7a76df 100644 --- a/app/Repositories/Account/AccountTasker.php +++ b/app/Repositories/Account/AccountTasker.php @@ -140,7 +140,7 @@ class AccountTasker implements AccountTaskerInterface // Obtain a list of columns $sum = []; foreach ($report['accounts'] as $accountId => $row) { - $sum[$accountId] = (float) $row['sum']; + $sum[$accountId] = (float) $row['sum']; // intentional float } array_multisort($sum, SORT_ASC, $report['accounts']); @@ -235,7 +235,7 @@ class AccountTasker implements AccountTaskerInterface // Obtain a list of columns $sum = []; foreach ($report['accounts'] as $accountId => $row) { - $sum[$accountId] = (float) $row['sum']; + $sum[$accountId] = (float) $row['sum']; // intentional float } array_multisort($sum, SORT_DESC, $report['accounts']); diff --git a/app/Repositories/Budget/NoBudgetRepository.php b/app/Repositories/Budget/NoBudgetRepository.php index 9a0d1df208..32a8897686 100644 --- a/app/Repositories/Budget/NoBudgetRepository.php +++ b/app/Repositories/Budget/NoBudgetRepository.php @@ -138,7 +138,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], 'currency_decimal_places' => $currency['decimal_places'], - 'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''), + 'amount' => app('steam')->bcround($spent, $currency['decimal_places']), ]; } diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index cf2777b26d..6e80d50305 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -275,7 +275,7 @@ class OperationsRepository implements OperationsRepositoryInterface 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], 'currency_decimal_places' => $currency['decimal_places'], - 'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''), + 'amount' => app('steam')->bcround($spent, $currency['decimal_places']), ]; } diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index 0c2be397a5..3b6d41e9c4 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -96,7 +96,7 @@ trait ModifiesPiggyBanks $savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount; $maxAmount = $leftOnAccount; $leftToSave = null; - if (0.0 !== (float)$piggyBank->targetamount) { + if (0 !== bccomp($piggyBank->targetamount, '0')) { $leftToSave = bcsub($piggyBank->targetamount, $savedSoFar); $maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount; } @@ -383,7 +383,7 @@ trait ModifiesPiggyBanks // if the piggy bank is now smaller than the current relevant rep, // remove money from the rep. $repetition = $this->getRepetition($piggyBank); - if (null !== $repetition && $repetition->currentamount > $piggyBank->targetamount && 0.0 !== (float)$piggyBank->targetamount) { + if (null !== $repetition && $repetition->currentamount > $piggyBank->targetamount && 0 !== bccomp($piggyBank->targetamount, '0')) { $difference = bcsub($piggyBank->targetamount, $repetition->currentamount); // an amount will be removed, create "negative" event: diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 4ef63ea5bc..02a71a513d 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -1,4 +1,5 @@ formatFlat($format->symbol, (int) $format->decimal_places, $amount, $coloured); + return $this->formatFlat($format->symbol, (int)$format->decimal_places, $amount, $coloured); } /** * This method will properly format the given number, in color or "black and white", * as a currency, given two things: the currency required and the current locale. * - * @param string $symbol - * @param int $decimalPlaces - * @param string $amount - * @param bool $coloured + * @param string $symbol + * @param int $decimalPlaces + * @param string $amount + * @param bool $coloured * * @return string * @@ -78,13 +79,13 @@ class Amount $fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol); $fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces); $fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces); - $result = $fmt->format((float) $amount); + $result = $fmt->format((float)app('steam')->bcround($amount, $decimalPlaces)); // intentional float if (true === $coloured) { - if ($amount > 0) { + if (1 === bccomp($amount, '0')) { return sprintf('%s', $result); } - if ($amount < 0) { + if (-1 === bccomp($amount, '0')) { return sprintf('%s', $result); } @@ -133,7 +134,7 @@ class Amount } $cache->store(config('firefly.default_currency', 'EUR')); - return (string) config('firefly.default_currency', 'EUR'); + return (string)config('firefly.default_currency', 'EUR'); } /** @@ -150,7 +151,7 @@ class Amount } /** - * @param User $user + * @param User $user * * @return TransactionCurrency * @throws FireflyException @@ -167,7 +168,7 @@ class Amount $currencyPrefStr = $currencyPreference ? $currencyPreference->data : 'EUR'; // at this point the currency preference could be encrypted, if coming from an old version. - $currencyCode = $this->tryDecrypt((string) $currencyPrefStr); + $currencyCode = $this->tryDecrypt((string)$currencyPrefStr); // could still be json encoded: /** @var TransactionCurrency|null $currency */ @@ -182,7 +183,7 @@ class Amount } /** - * @param string $value + * @param string $value * * @return string */ @@ -251,8 +252,8 @@ class Amount } /** - * @param array $info - * @param string $field + * @param array $info + * @param string $field * * @return bool */ @@ -268,10 +269,10 @@ class Amount * string $sign = $localeconv['negative_sign'] * bool $csPrecedes = $localeconv['n_cs_precedes']. * - * @param bool $sepBySpace - * @param int $signPosn - * @param string $sign - * @param bool $csPrecedes + * @param bool $sepBySpace + * @param int $signPosn + * @param string $sign + * @param bool $csPrecedes * * @return string * @@ -326,11 +327,11 @@ class Amount } // default is amount before currency - $format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE; + $format = $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE; if ($csPrecedes) { // alternative is currency before amount - $format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE; + $format = $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE; } return $format; diff --git a/app/Support/Chart/Category/WholePeriodChartGenerator.php b/app/Support/Chart/Category/WholePeriodChartGenerator.php index 867cb3f337..ebd0974f55 100644 --- a/app/Support/Chart/Category/WholePeriodChartGenerator.php +++ b/app/Support/Chart/Category/WholePeriodChartGenerator.php @@ -105,8 +105,8 @@ class WholePeriodChartGenerator $earnedInfoKey = sprintf('earned-in-%s', $code); $spentAmount = $spent[$key][$currencyId]['sum'] ?? '0'; $earnedAmount = $earned[$key][$currencyId]['sum'] ?? '0'; - $chartData[$spentInfoKey]['entries'][$label] = round((float) $spentAmount, $currency['currency_decimal_places']); - $chartData[$earnedInfoKey]['entries'][$label] = round((float) $earnedAmount, $currency['currency_decimal_places']); + $chartData[$spentInfoKey]['entries'][$label] = app('steam')->bcround($spentAmount, $currency['currency_decimal_places']); + $chartData[$earnedInfoKey]['entries'][$label] = app('steam')->bcround($earnedAmount, $currency['currency_decimal_places']); } $current = app('navigation')->addPeriod($current, $step, 0); } diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php index 042478a958..04c96adafd 100644 --- a/app/Support/Form/CurrencyForm.php +++ b/app/Support/Form/CurrencyForm.php @@ -92,7 +92,7 @@ class CurrencyForm // make sure value is formatted nicely: if (null !== $value && '' !== $value) { - $value = round((float) $value, $defaultCurrency->decimal_places); + $value = app('steam')->bcround($value, $defaultCurrency->decimal_places); } try { $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); @@ -161,7 +161,7 @@ class CurrencyForm // make sure value is formatted nicely: if (null !== $value && '' !== $value) { - $value = round((float) $value, $defaultCurrency->decimal_places); + $value = app('steam')->bcround($value, $defaultCurrency->decimal_places); } try { $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); diff --git a/app/Support/Steam.php b/app/Support/Steam.php index d567323b79..c563d89979 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -1,4 +1,5 @@ setUser($account->user); - $currencyId = (int) $repository->getMetaValue($account, 'currency_id'); + $currencyId = (int)$repository->getMetaValue($account, 'currency_id'); $transactions = $account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) @@ -77,8 +78,8 @@ class Steam } /** - * @param array $transactions - * @param string $key + * @param array $transactions + * @param string $key * * @return string */ @@ -87,7 +88,7 @@ class Steam $sum = '0'; /** @var array $transaction */ foreach ($transactions as $transaction) { - $value = (string) ($transaction[$key] ?? '0'); + $value = (string)($transaction[$key] ?? '0'); $value = '' === $value ? '0' : $value; $sum = bcadd($sum, $value); } @@ -95,15 +96,35 @@ class Steam return $sum; } + /** + * https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers + * + * @param string $number + * @param int $precision + * @return string + */ + public function bcround(string $number, int $precision = 0): string + { + if (str_contains($number, '.')) { + if ($number[0] !== '-') { + return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision); + } + + return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision); + } + + return $number; + } + /** * Gets the balance for the given account during the whole range, using this format:. * * [yyyy-mm-dd] => 123,2 * - * @param Account $account - * @param Carbon $start - * @param Carbon $end - * @param TransactionCurrency|null $currency + * @param Account $account + * @param Carbon $start + * @param Carbon $end + * @param TransactionCurrency|null $currency * * @return array * @throws FireflyException @@ -134,7 +155,7 @@ class Steam $repository->setUser($account->user); $currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user); } - $currencyId = (int) $currency->id; + $currencyId = (int)$currency->id; $start->addDay(); @@ -162,14 +183,14 @@ class Steam /** @var Transaction $entry */ foreach ($set as $entry) { // normal amount and foreign amount - $modified = null === $entry->modified ? '0' : (string) $entry->modified; - $foreignModified = null === $entry->modified_foreign ? '0' : (string) $entry->modified_foreign; + $modified = null === $entry->modified ? '0' : (string)$entry->modified; + $foreignModified = null === $entry->modified_foreign ? '0' : (string)$entry->modified_foreign; $amount = '0'; - if ($currencyId === (int) $entry->transaction_currency_id || 0 === $currencyId) { + if ($currencyId === (int)$entry->transaction_currency_id || 0 === $currencyId) { // use normal amount: $amount = $modified; } - if ($currencyId === (int) $entry->foreign_currency_id) { + if ($currencyId === (int)$entry->foreign_currency_id) { // use foreign amount: $amount = $foreignModified; } @@ -188,9 +209,9 @@ class Steam /** * Gets balance at the end of current month by default * - * @param Account $account - * @param Carbon $date - * @param TransactionCurrency|null $currency + * @param Account $account + * @param Carbon $date + * @param TransactionCurrency|null $currency * * @return string * @throws FireflyException @@ -228,7 +249,7 @@ class Steam ->get(['transactions.foreign_amount'])->toArray(); $foreignBalance = $this->sumTransactions($transactions, 'foreign_amount'); $balance = bcadd($nativeBalance, $foreignBalance); - $virtual = null === $account->virtual_balance ? '0' : (string) $account->virtual_balance; + $virtual = null === $account->virtual_balance ? '0' : (string)$account->virtual_balance; $balance = bcadd($balance, $virtual); $cache->store($balance); @@ -239,8 +260,8 @@ class Steam /** * This method always ignores the virtual balance. * - * @param Collection $accounts - * @param Carbon $date + * @param Collection $accounts + * @param Carbon $date * * @return array * @throws JsonException @@ -272,8 +293,8 @@ class Steam /** * Same as above, but also groups per currency. * - * @param Collection $accounts - * @param Carbon $date + * @param Collection $accounts + * @param Carbon $date * * @return array * @throws JsonException @@ -303,8 +324,8 @@ class Steam } /** - * @param Account $account - * @param Carbon $date + * @param Account $account + * @param Carbon $date * * @return array */ @@ -326,7 +347,7 @@ class Steam $return = []; /** @var stdClass $entry */ foreach ($balances as $entry) { - $return[(int) $entry->transaction_currency_id] = (string) $entry->sum_for_currency; + $return[(int)$entry->transaction_currency_id] = (string)$entry->sum_for_currency; } $cache->store($return); @@ -334,7 +355,7 @@ class Steam } /** - * @param string $string + * @param string $string * * @return string */ @@ -393,7 +414,7 @@ class Steam } /** - * @param array $accounts + * @param array $accounts * * @return array */ @@ -409,7 +430,7 @@ class Steam foreach ($set as $entry) { $date = new Carbon($entry->max_date, config('app.timezone')); $date->setTimezone(config('app.timezone')); - $list[(int) $entry->account_id] = $date; + $list[(int)$entry->account_id] = $date; } return $list; @@ -456,7 +477,7 @@ class Steam } /** - * @param string $locale + * @param string $locale * * @return array */ @@ -489,8 +510,8 @@ class Steam /** * Make sure URL is safe. * - * @param string $unknownUrl - * @param string $safeUrl + * @param string $unknownUrl + * @param string $safeUrl * * @return string */ @@ -515,7 +536,7 @@ class Steam } /** - * @param string $amount + * @param string $amount * * @return string */ @@ -539,7 +560,7 @@ class Steam * Convert a scientific notation to float * Additionally fixed a problem with PHP <= 5.2.x with big integers * - * @param string $value + * @param string $value * @return string */ public function floatalize(string $value): string @@ -554,15 +575,15 @@ class Steam $post = strlen(substr($number, strpos($number, '.') + 1)); $mantis = substr($value, strpos($value, 'E') + 1); if ($mantis < 0) { - $post += abs((int) $mantis); + $post += abs((int)$mantis); } - return number_format((float) $value, $post, '.', ''); + return number_format((float)$value, $post, '.', ''); } - return number_format((float) $value, 0, '.', ''); + return number_format((float)$value, 0, '.', ''); } /** - * @param string|null $amount + * @param string|null $amount * * @return string|null */ @@ -576,7 +597,7 @@ class Steam } /** - * @param string $string + * @param string $string * * @return int */ @@ -588,28 +609,28 @@ class Steam // has a K in it, remove the K and multiply by 1024. $bytes = bcmul(rtrim($string, 'k'), '1024'); - return (int) $bytes; + return (int)$bytes; } if (false !== stripos($string, 'm')) { // has a M in it, remove the M and multiply by 1048576. $bytes = bcmul(rtrim($string, 'm'), '1048576'); - return (int) $bytes; + return (int)$bytes; } if (false !== stripos($string, 'g')) { // has a G in it, remove the G and multiply by (1024)^3. $bytes = bcmul(rtrim($string, 'g'), '1073741824'); - return (int) $bytes; + return (int)$bytes; } - return (int) $string; + return (int)$string; } /** - * @param string $amount + * @param string $amount * * @return string */ From 22a237d3165fa0c9b9b617e7471e0d8295fbf23e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Dec 2022 05:47:50 +0100 Subject: [PATCH 08/10] Add passport settings --- .env.example | 9 ++++ composer.lock | 126 ++++++++++++++++++++++---------------------- config/passport.php | 62 ++++++++++++++++++++++ 3 files changed, 134 insertions(+), 63 deletions(-) create mode 100644 config/passport.php diff --git a/.env.example b/.env.example index 7d52539c30..3a5465cffd 100644 --- a/.env.example +++ b/.env.example @@ -195,6 +195,15 @@ AUTHENTICATION_GUARD=web AUTHENTICATION_GUARD_HEADER=REMOTE_USER AUTHENTICATION_GUARD_EMAIL= +# +# Firefly III generates a basic keypair for your OAuth tokens. +# If you want, you can overrule the key with your own (secure) value. +# It's also possible to set PASSPORT_PUBLIC_KEY_FILE or PASSPORT_PRIVATE_KEY_FILE +# if you're using Docker secrets or similar solutions for secret management +# +PASSPORT_PRIVATE_KEY= +PASSPORT_PUBLIC_KEY= + # # Extra authentication settings # diff --git a/composer.lock b/composer.lock index ade3a38986..92fc7f8d21 100644 --- a/composer.lock +++ b/composer.lock @@ -470,16 +470,16 @@ }, { "name": "doctrine/dbal", - "version": "3.5.1", + "version": "3.5.2", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "f38ee8aaca2d58ee88653cb34a6a3880c23f38a5" + "reference": "63e513cebbbaf96a6795e5c5ee34d205831bfc85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/f38ee8aaca2d58ee88653cb34a6a3880c23f38a5", - "reference": "f38ee8aaca2d58ee88653cb34a6a3880c23f38a5", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/63e513cebbbaf96a6795e5c5ee34d205831bfc85", + "reference": "63e513cebbbaf96a6795e5c5ee34d205831bfc85", "shasum": "" }, "require": { @@ -492,16 +492,16 @@ "psr/log": "^1|^2|^3" }, "require-dev": { - "doctrine/coding-standard": "10.0.0", - "jetbrains/phpstorm-stubs": "2022.2", - "phpstan/phpstan": "1.8.10", + "doctrine/coding-standard": "11.0.0", + "jetbrains/phpstorm-stubs": "2022.3", + "phpstan/phpstan": "1.9.2", "phpstan/phpstan-strict-rules": "^1.4", - "phpunit/phpunit": "9.5.25", - "psalm/plugin-phpunit": "0.17.0", + "phpunit/phpunit": "9.5.27", + "psalm/plugin-phpunit": "0.18.4", "squizlabs/php_codesniffer": "3.7.1", "symfony/cache": "^5.4|^6.0", "symfony/console": "^4.4|^5.4|^6.0", - "vimeo/psalm": "4.29.0" + "vimeo/psalm": "4.30.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -561,7 +561,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.5.1" + "source": "https://github.com/doctrine/dbal/tree/3.5.2" }, "funding": [ { @@ -577,7 +577,7 @@ "type": "tidelift" } ], - "time": "2022-10-24T07:26:18+00:00" + "time": "2022-12-19T08:17:34+00:00" }, { "name": "doctrine/deprecations", @@ -1136,16 +1136,16 @@ }, { "name": "firebase/php-jwt", - "version": "v6.3.1", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "ddfaddcb520488b42bca3a75e17e9dd53c3667da" + "reference": "ea7dda77098b96e666c5ef382452f94841e439cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/ddfaddcb520488b42bca3a75e17e9dd53c3667da", - "reference": "ddfaddcb520488b42bca3a75e17e9dd53c3667da", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/ea7dda77098b96e666c5ef382452f94841e439cd", + "reference": "ea7dda77098b96e666c5ef382452f94841e439cd", "shasum": "" }, "require": { @@ -1192,9 +1192,9 @@ ], "support": { "issues": "https://github.com/firebase/php-jwt/issues", - "source": "https://github.com/firebase/php-jwt/tree/v6.3.1" + "source": "https://github.com/firebase/php-jwt/tree/v6.3.2" }, - "time": "2022-11-01T21:20:08+00:00" + "time": "2022-12-19T17:10:46+00:00" }, { "name": "fruitcake/php-cors", @@ -1856,16 +1856,16 @@ }, { "name": "laravel/framework", - "version": "v9.44.0", + "version": "v9.45.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98" + "reference": "faeb20d3fc61b69790068161ab42bcf2d5faccbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/60808a7d9acd53461fd69634c08fc7e0a99fbf98", - "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98", + "url": "https://api.github.com/repos/laravel/framework/zipball/faeb20d3fc61b69790068161ab42bcf2d5faccbc", + "reference": "faeb20d3fc61b69790068161ab42bcf2d5faccbc", "shasum": "" }, "require": { @@ -1876,7 +1876,7 @@ "ext-openssl": "*", "fruitcake/php-cors": "^1.2", "laravel/serializable-closure": "^1.2.2", - "league/commonmark": "^2.2", + "league/commonmark": "^2.2.1", "league/flysystem": "^3.8.0", "monolog/monolog": "^2.0", "nesbot/carbon": "^2.62.1", @@ -1885,7 +1885,7 @@ "psr/container": "^1.1.1|^2.0.1", "psr/log": "^1.0|^2.0|^3.0", "psr/simple-cache": "^1.0|^2.0|^3.0", - "ramsey/uuid": "^4.2.2", + "ramsey/uuid": "^4.7", "symfony/console": "^6.0.9", "symfony/error-handler": "^6.0", "symfony/finder": "^6.0", @@ -1946,7 +1946,7 @@ "ably/ably-php": "^1.0", "aws/aws-sdk-php": "^3.235.5", "doctrine/dbal": "^2.13.3|^3.1.4", - "fakerphp/faker": "^1.9.2", + "fakerphp/faker": "^1.21", "guzzlehttp/guzzle": "^7.5", "league/flysystem-aws-s3-v3": "^3.0", "league/flysystem-ftp": "^3.0", @@ -1954,7 +1954,7 @@ "league/flysystem-read-only": "^3.3", "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.5.1", - "orchestra/testbench-core": "^7.11", + "orchestra/testbench-core": "^7.16", "pda/pheanstalk": "^4.0", "phpstan/phpstan": "^1.4.7", "phpunit/phpunit": "^9.5.8", @@ -2038,7 +2038,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-12-15T14:56:36+00:00" + "time": "2022-12-21T19:37:46+00:00" }, { "name": "laravel/passport", @@ -2838,16 +2838,16 @@ }, { "name": "league/flysystem", - "version": "3.11.0", + "version": "3.12.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "7e423e5dd240a60adfab9bde058d7668863b7731" + "reference": "2aef65a47e44f2d6f9938f720f6dd697e7ba7b76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/7e423e5dd240a60adfab9bde058d7668863b7731", - "reference": "7e423e5dd240a60adfab9bde058d7668863b7731", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/2aef65a47e44f2d6f9938f720f6dd697e7ba7b76", + "reference": "2aef65a47e44f2d6f9938f720f6dd697e7ba7b76", "shasum": "" }, "require": { @@ -2909,7 +2909,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.11.0" + "source": "https://github.com/thephpleague/flysystem/tree/3.12.0" }, "funding": [ { @@ -2925,7 +2925,7 @@ "type": "tidelift" } ], - "time": "2022-12-02T14:39:57+00:00" + "time": "2022-12-20T20:21:10+00:00" }, { "name": "league/fractal", @@ -3664,16 +3664,16 @@ }, { "name": "nunomaduro/collision", - "version": "v6.3.1", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/nunomaduro/collision.git", - "reference": "0f6349c3ed5dd28467087b08fb59384bb458a22b" + "reference": "83699b231e7f277bfa2e823788973bf4082f019a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/collision/zipball/0f6349c3ed5dd28467087b08fb59384bb458a22b", - "reference": "0f6349c3ed5dd28467087b08fb59384bb458a22b", + "url": "https://api.github.com/repos/nunomaduro/collision/zipball/83699b231e7f277bfa2e823788973bf4082f019a", + "reference": "83699b231e7f277bfa2e823788973bf4082f019a", "shasum": "" }, "require": { @@ -3748,20 +3748,20 @@ "type": "patreon" } ], - "time": "2022-09-29T12:29:49+00:00" + "time": "2022-12-23T21:36:49+00:00" }, { "name": "nunomaduro/termwind", - "version": "v1.14.2", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/termwind.git", - "reference": "9a8218511eb1a0965629ff820dda25985440aefc" + "reference": "594ab862396c16ead000de0c3c38f4a5cbe1938d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/9a8218511eb1a0965629ff820dda25985440aefc", - "reference": "9a8218511eb1a0965629ff820dda25985440aefc", + "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/594ab862396c16ead000de0c3c38f4a5cbe1938d", + "reference": "594ab862396c16ead000de0c3c38f4a5cbe1938d", "shasum": "" }, "require": { @@ -3818,7 +3818,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/termwind/issues", - "source": "https://github.com/nunomaduro/termwind/tree/v1.14.2" + "source": "https://github.com/nunomaduro/termwind/tree/v1.15.0" }, "funding": [ { @@ -3834,7 +3834,7 @@ "type": "github" } ], - "time": "2022-10-28T22:51:32+00:00" + "time": "2022-12-20T19:00:15+00:00" }, { "name": "nyholm/psr7", @@ -4161,16 +4161,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.17", + "version": "3.0.18", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "dbc2307d5c69aeb22db136c52e91130d7f2ca761" + "reference": "f28693d38ba21bb0d9f0c411ee5dae2b178201da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/dbc2307d5c69aeb22db136c52e91130d7f2ca761", - "reference": "dbc2307d5c69aeb22db136c52e91130d7f2ca761", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/f28693d38ba21bb0d9f0c411ee5dae2b178201da", + "reference": "f28693d38ba21bb0d9f0c411ee5dae2b178201da", "shasum": "" }, "require": { @@ -4251,7 +4251,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.17" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.18" }, "funding": [ { @@ -4267,7 +4267,7 @@ "type": "tidelift" } ], - "time": "2022-10-24T10:51:50+00:00" + "time": "2022-12-17T18:26:50+00:00" }, { "name": "pragmarx/google2fa", @@ -5107,23 +5107,23 @@ }, { "name": "ramsey/uuid", - "version": "4.6.0", + "version": "4.7.0", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "ad63bc700e7d021039e30ce464eba384c4a1d40f" + "reference": "5ed9ad582647bbc3864ef78db34bdc1afdcf9b49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/ad63bc700e7d021039e30ce464eba384c4a1d40f", - "reference": "ad63bc700e7d021039e30ce464eba384c4a1d40f", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/5ed9ad582647bbc3864ef78db34bdc1afdcf9b49", + "reference": "5ed9ad582647bbc3864ef78db34bdc1afdcf9b49", "shasum": "" }, "require": { "brick/math": "^0.8.8 || ^0.9 || ^0.10", "ext-json": "*", "php": "^8.0", - "ramsey/collection": "^1.0" + "ramsey/collection": "^1.2" }, "replace": { "rhumsaa/uuid": "self.version" @@ -5183,7 +5183,7 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.6.0" + "source": "https://github.com/ramsey/uuid/tree/4.7.0" }, "funding": [ { @@ -5195,7 +5195,7 @@ "type": "tidelift" } ], - "time": "2022-11-05T23:03:38+00:00" + "time": "2022-12-19T22:30:49+00:00" }, { "name": "rcrowe/twigbridge", @@ -9405,16 +9405,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.19", + "version": "9.2.22", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559" + "reference": "e4bf60d2220b4baaa0572986b5d69870226b06df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c77b56b63e3d2031bd8997fcec43c1925ae46559", - "reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e4bf60d2220b4baaa0572986b5d69870226b06df", + "reference": "e4bf60d2220b4baaa0572986b5d69870226b06df", "shasum": "" }, "require": { @@ -9470,7 +9470,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.19" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.22" }, "funding": [ { @@ -9478,7 +9478,7 @@ "type": "github" } ], - "time": "2022-11-18T07:47:47+00:00" + "time": "2022-12-18T16:40:55+00:00" }, { "name": "phpunit/php-file-iterator", diff --git a/config/passport.php b/config/passport.php new file mode 100644 index 0000000000..d314b51ede --- /dev/null +++ b/config/passport.php @@ -0,0 +1,62 @@ + envNonEmpty('AUTHENTICATION_GUARD', 'web'), + + /* + |-------------------------------------------------------------------------- + | Encryption Keys + |-------------------------------------------------------------------------- + | + | Passport uses encryption keys while generating secure access tokens for + | your application. By default, the keys are stored as local files but + | can be set via environment variables when that is more convenient. + | + */ + + 'private_key' => env('PASSPORT_PRIVATE_KEY'), + + 'public_key' => env('PASSPORT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Client UUIDs + |-------------------------------------------------------------------------- + | + | By default, Passport uses auto-incrementing primary keys when assigning + | IDs to clients. However, if Passport is installed using the provided + | --uuids switch, this will be set to "true" and UUIDs will be used. + | + */ + + 'client_uuids' => false, + + /* + |-------------------------------------------------------------------------- + | Personal Access Client + |-------------------------------------------------------------------------- + | + | If you enable client hashing, you should set the personal access client + | ID and unhashed secret within your environment file. The values will + | get used while issuing fresh personal access tokens to your users. + | + */ + + 'personal_access_client' => [ + 'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'), + 'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'), + ], + +]; From 5f6772260d03969be04e99b9bfb0ef09867e361e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Dec 2022 05:48:04 +0100 Subject: [PATCH 09/10] Remove null exceptions --- .../Controllers/Account/EditController.php | 3 +- .../Controllers/Account/IndexController.php | 7 ++- app/Http/Requests/PiggyBankUpdateRequest.php | 2 +- .../PiggyBank/ModifiesPiggyBanks.php | 3 ++ .../Support/CreditRecalculateService.php | 54 +++++++++++-------- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index 49848992a0..363896bfe8 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -135,6 +135,7 @@ class EditController extends Controller // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); + $virtualBalance = null === $account->virtual_balance ? '0' : $account->virtual_balance; $preFilled = [ 'account_number' => $repository->getMetaValue($account, 'account_number'), 'account_role' => $repository->getMetaValue($account, 'account_role'), @@ -145,7 +146,7 @@ class EditController extends Controller 'liability_type_id' => $account->account_type_id, 'opening_balance' => app('steam')->bcround($openingBalanceAmount, $currency->decimal_places), 'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'), - 'virtual_balance' => app('steam')->bcround($account->virtual_balance, $currency->decimal_places), + 'virtual_balance' => app('steam')->bcround($virtualBalance, $currency->decimal_places), 'currency_id' => $currency->id, 'include_net_worth' => $includeNetWorth, 'interest' => $repository->getMetaValue($account, 'interest'), diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index c8d275aa74..31cbad77ac 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -167,14 +167,19 @@ class IndexController extends Controller $endBalances = app('steam')->balancesByAccounts($accounts, $end); $activities = app('steam')->getLastActivities($ids); + $accounts->each( function (Account $account) use ($activities, $startBalances, $endBalances) { + + $interest = (string)$this->repository->getMetaValue($account, 'interest'); + $interest = '' === $interest ? '0' : $interest; + // See reference nr. 68 $account->lastActivityDate = $this->isInArrayDate($activities, $account->id); $account->startBalance = $this->isInArray($startBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id); $account->difference = bcsub($account->endBalance, $account->startBalance); - $account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4); + $account->interest = app('steam')->bcround($interest, 4); $account->interestPeriod = (string) trans( sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')) ); diff --git a/app/Http/Requests/PiggyBankUpdateRequest.php b/app/Http/Requests/PiggyBankUpdateRequest.php index d48268a5de..9655612d3f 100644 --- a/app/Http/Requests/PiggyBankUpdateRequest.php +++ b/app/Http/Requests/PiggyBankUpdateRequest.php @@ -45,7 +45,7 @@ class PiggyBankUpdateRequest extends FormRequest 'name' => $this->convertString('name'), 'startdate' => $this->getCarbonDate('startdate'), 'account_id' => $this->convertInteger('account_id'), - 'targetamount' => $this->convertString('targetamount'), + 'targetamount' => trim($this->convertString('targetamount')), 'targetdate' => $this->getCarbonDate('targetdate'), 'notes' => $this->stringWithNewlines('notes'), 'object_group_title' => $this->convertString('object_group'), diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index 3b6d41e9c4..d43ff1def1 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -446,6 +446,9 @@ trait ModifiesPiggyBanks if (array_key_exists('targetamount', $data) && '' !== $data['targetamount']) { $piggyBank->targetamount = $data['targetamount']; } + if (array_key_exists('targetamount', $data) && '' === $data['targetamount']) { + $piggyBank->targetamount = '0'; + } if (array_key_exists('targetdate', $data) && '' !== $data['targetdate']) { $piggyBank->targetdate = $data['targetdate']; } diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index e67346304d..4147714aa6 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -99,7 +99,7 @@ class CreditRecalculateService } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @throws FireflyException */ @@ -121,7 +121,7 @@ class CreditRecalculateService } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Account * @throws FireflyException @@ -132,8 +132,8 @@ class CreditRecalculateService } /** - * @param TransactionJournal $journal - * @param string $direction + * @param TransactionJournal $journal + * @param string $direction * * @return Account * @throws FireflyException @@ -154,7 +154,7 @@ class CreditRecalculateService } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Account * @throws FireflyException @@ -189,7 +189,7 @@ class CreditRecalculateService } /** - * @param Account $account + * @param Account $account */ private function processWorkAccount(Account $account): void { @@ -205,7 +205,7 @@ class CreditRecalculateService $factory->crud($account, 'start_of_debt', $startOfDebt); // get direction of liability: - $direction = (string) $this->repository->getMetaValue($account, 'liability_direction'); + $direction = (string)$this->repository->getMetaValue($account, 'liability_direction'); // now loop all transactions (except opening balance and credit thing) $transactions = $account->transactions()->get(); @@ -220,24 +220,36 @@ class CreditRecalculateService } /** - * @param Account $account - * @param string $direction - * @param Transaction $transaction - * @param string $amount + * @param Account $account + * @param string $direction + * @param Transaction $transaction + * @param string $amount * * @return string */ private function processTransaction(Account $account, string $direction, Transaction $transaction, string $amount): string { Log::debug(sprintf('Now in %s(#%d, %s)', __METHOD__, $transaction->id, $amount)); - $journal = $transaction->transactionJournal; - $groupId = $journal->transaction_group_id; - $type = $journal->transactionType->type; + $journal = $transaction->transactionJournal; + $foreignCurrency = $transaction->foreignCurrency; + $accountCurrency = $this->repository->getAccountCurrency($account); + $groupId = $journal->transaction_group_id; + $type = $journal->transactionType->type; + + Log::debug(sprintf('Account currency is #%d (%s)', $accountCurrency->id, $accountCurrency->code)); + if ('' === $direction) { Log::debug('Since direction is "", do nothing.'); return $amount; } + // amount to use depends on the currency: + $usedAmount = $transaction->amount; + if (null !== $foreignCurrency && $foreignCurrency->id === $accountCurrency->id) { + $usedAmount = $transaction->foreign_amount; + Log::debug('Will now use foreign amount!'); + } + Log::debug(sprintf('Processing group #%d, journal #%d of type "%s"', $journal->id, $groupId, $type)); @@ -246,8 +258,8 @@ class CreditRecalculateService // to a credit-liability doesn't increase the amount (yet) if ( $type === TransactionType::WITHDRAWAL - && (int) $account->id === (int) $transaction->account_id - && 1 === bccomp($transaction->amount, '0') + && (int)$account->id === (int)$transaction->account_id + && 1 === bccomp($usedAmount, '0') && 'credit' === $direction ) { Log::debug(sprintf('Is withdrawal into credit liability #%d, does not influence the amount due.', $transaction->account_id)); @@ -258,8 +270,8 @@ class CreditRecalculateService // likewise deposit into a credit debt does not change the amount if ( $type === TransactionType::DEPOSIT - && (int) $account->id === (int) $transaction->account_id - && -1 === bccomp($transaction->amount, '0') + && (int)$account->id === (int)$transaction->account_id + && -1 === bccomp($usedAmount, '0') && 'credit' === $direction ) { Log::debug(sprintf('Is deposit from liability #%d,does not influence the amount left.', $transaction->account_id)); @@ -268,7 +280,7 @@ class CreditRecalculateService } if (in_array($type, [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER], true)) { - $amount = bcadd($amount, bcmul($transaction->amount, '-1')); + $amount = bcadd($amount, bcmul($usedAmount, '-1')); } Log::debug(sprintf('Amount is now %s', $amount)); @@ -276,7 +288,7 @@ class CreditRecalculateService } /** - * @param Account|null $account + * @param Account|null $account */ public function setAccount(?Account $account): void { @@ -284,7 +296,7 @@ class CreditRecalculateService } /** - * @param TransactionGroup $group + * @param TransactionGroup $group */ public function setGroup(TransactionGroup $group): void { From 63184ac298a59c79d8da45215f6368f8467524b7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Dec 2022 05:52:34 +0100 Subject: [PATCH 10/10] Add strict type --- config/passport.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/passport.php b/config/passport.php index d314b51ede..f025442040 100644 --- a/config/passport.php +++ b/config/passport.php @@ -1,4 +1,5 @@