Compare commits

...

145 Commits

Author SHA1 Message Date
github-actions
23c4352c18 Auto commit for release 'develop' on 2024-12-27 2024-12-27 22:03:16 +01:00
James Cole
2dddaa36d5 Actions will default to php 8.4 2024-12-27 19:51:20 +01:00
James Cole
8ab7cf2388 Merge branch 'v6.2' into develop
# Conflicts:
#	composer.lock
#	config/firefly.php
#	package-lock.json
2024-12-27 19:50:05 +01:00
James Cole
f191086adb Enable cache again. 2024-12-27 19:47:35 +01:00
James Cole
68b446db18 Final changes. 2024-12-27 19:46:40 +01:00
James Cole
3d49d81856 Expand some multi currency things. 2024-12-27 16:36:01 +01:00
James Cole
96493425d1 Convert more of the budget view to native currency. 2024-12-27 13:42:48 +01:00
James Cole
419975285c Fix nullpointer 2024-12-27 13:02:23 +01:00
github-actions
aa5bde122e Auto commit for release 'branch-v6.2' on 2024-12-27 2024-12-27 12:43:57 +01:00
James Cole
0fa3c2bd8d Fix issue with prefilled piggy banks. 2024-12-27 12:39:26 +01:00
James Cole
b9249a4d96 Update commands. 2024-12-27 09:30:41 +01:00
James Cole
6638ca270f Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-27 07:36:37 +01:00
James Cole
9bfef892f8 Remove lots of debug logs 2024-12-27 07:36:30 +01:00
github-actions
32e5efec7c Auto commit for release 'branch-v6.2' on 2024-12-27 2024-12-27 07:29:17 +01:00
James Cole
36457455ca Rename and clean up commands. 2024-12-27 07:24:47 +01:00
James Cole
062c148e43 Rename all correction commands. 2024-12-27 06:56:08 +01:00
James Cole
2314ce8004 Refactor and renam commands. 2024-12-27 06:48:58 +01:00
James Cole
a3ff73903a Fix bad error message. 2024-12-27 05:44:03 +01:00
James Cole
7c8445707e Add moar debug. 2024-12-26 14:12:05 +01:00
James Cole
291e73da4b Rename bills to subscriptions 2024-12-26 13:41:57 +01:00
James Cole
286a29ca3e Display for bills. 2024-12-26 11:28:31 +01:00
github-actions
71cf6c6a5e Auto commit for release 'branch-v6.2' on 2024-12-26 2024-12-26 10:24:39 +01:00
James Cole
1e8f0adaf8 Fix broken account balance. 2024-12-26 10:20:40 +01:00
James Cole
33531244aa Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2
# Conflicts:
#	app/Http/Controllers/Chart/AccountController.php
#	app/Support/Steam.php
2024-12-26 09:19:04 +01:00
James Cole
06049a9a28 Update various pages, clean up some code. 2024-12-26 09:16:17 +01:00
James Cole
d313f5fdf5 Fix chart balance. 2024-12-26 08:53:16 +01:00
github-actions
f4868126c1 Auto commit for release 'branch-v6.2' on 2024-12-26 2024-12-26 05:25:46 +01:00
James Cole
00147e98dd Fix home chart. 2024-12-26 05:21:28 +01:00
James Cole
6d22663ca2 Fix charts and balances. 2024-12-26 05:11:32 +01:00
James Cole
756bb9cf5e Fix overview, skip chart for now. 2024-12-25 11:59:15 +01:00
James Cole
399d7968f5 Fix another null. 2024-12-25 08:30:00 +01:00
James Cole
966b68f42e Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-25 08:29:50 +01:00
James Cole
134c551c12 Remove some comments, add others. 2024-12-25 08:23:17 +01:00
github-actions
9aeca15355 Auto commit for release 'branch-v6.2' on 2024-12-25 2024-12-25 08:17:59 +01:00
James Cole
6c6d31830b Fix nullpointer 2024-12-25 08:14:07 +01:00
github-actions
e8cc321898 Auto commit for release 'branch-v6.2' on 2024-12-25 2024-12-25 07:13:41 +01:00
James Cole
e73fe06f7e Expand currency view in accounts. 2024-12-25 07:10:02 +01:00
James Cole
98b579c042 Fix native display. 2024-12-24 19:03:47 +01:00
James Cole
7b3a5c1afd Frontpage seems to be multi currency aware. 2024-12-24 16:56:31 +01:00
James Cole
7e2e49e129 Convert more charts. 2024-12-24 10:29:07 +01:00
James Cole
e8ef630424 Expand native amount things. 2024-12-24 06:34:12 +01:00
James Cole
8805bcf6f6 Various updates to display native/foreign amounts. 2024-12-23 17:32:15 +01:00
James Cole
ff5c9a3aa0 Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-23 14:35:34 +01:00
James Cole
3a274dcaa7 Little debug page with routes. 2024-12-23 14:35:27 +01:00
github-actions
ddfededf02 Auto commit for release 'branch-v6.2' on 2024-12-23 2024-12-23 08:40:29 +01:00
James Cole
e1785898ba Add notes to audit report. 2024-12-23 08:35:33 +01:00
James Cole
ae09200f42 Fix import 2024-12-23 08:26:35 +01:00
James Cole
847984f678 New rule triggers for account balance. 2024-12-23 08:22:54 +01:00
James Cole
42305672ac Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-23 07:14:12 +01:00
James Cole
25a56d9f72 Chart no longer as a line chart. 2024-12-23 07:13:59 +01:00
James Cole
cea52c0ac7 Merge pull request #9571 from firefly-iii/dependabot/composer/develop/phpunit/phpunit-10.5.40
Bump phpunit/phpunit from 10.5.39 to 10.5.40
2024-12-23 07:02:55 +01:00
James Cole
1b33ff9c25 Merge pull request #9573 from firefly-iii/dependabot/npm_and_yarn/develop/i18next-24.2.0
Bump i18next from 24.1.2 to 24.2.0
2024-12-23 07:02:41 +01:00
github-actions
8f9f08b96f Auto commit for release 'branch-v6.2' on 2024-12-23 2024-12-23 07:01:44 +01:00
James Cole
594ba205bb Merge pull request #9574 from firefly-iii/dependabot/npm_and_yarn/develop/vite-6.0.5
Bump vite from 6.0.3 to 6.0.5
2024-12-23 07:01:29 +01:00
James Cole
3c65b46aa5 Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2
# Conflicts:
#	app/Support/Steam.php
2024-12-23 06:56:31 +01:00
James Cole
1cf9c76329 Fix array bug. 2024-12-23 06:55:14 +01:00
dependabot[bot]
495f5c71c3 Bump vite from 6.0.3 to 6.0.5
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 6.0.3 to 6.0.5.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v6.0.5/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-23 03:12:47 +00:00
dependabot[bot]
7e80f607b7 Bump i18next from 24.1.2 to 24.2.0
Bumps [i18next](https://github.com/i18next/i18next) from 24.1.2 to 24.2.0.
- [Release notes](https://github.com/i18next/i18next/releases)
- [Changelog](https://github.com/i18next/i18next/blob/master/CHANGELOG.md)
- [Commits](https://github.com/i18next/i18next/compare/v24.1.2...v24.2.0)

---
updated-dependencies:
- dependency-name: i18next
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-23 03:12:31 +00:00
dependabot[bot]
1b57bc7889 Bump phpunit/phpunit from 10.5.39 to 10.5.40
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.5.39 to 10.5.40.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.5.40/ChangeLog-10.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/10.5.39...10.5.40)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-23 03:01:52 +00:00
github-actions
c0499df4ec Auto commit for release 'branch-v6.2' on 2024-12-22 2024-12-22 20:37:54 +01:00
James Cole
d90ac519f7 Clean up balance methods. 2024-12-22 20:32:58 +01:00
James Cole
a0e92b6969 Clean up variety of account balance methods. 2024-12-22 19:42:06 +01:00
James Cole
df49dd23e2 Try to convert balance to native, still internal debates. 2024-12-22 16:41:55 +01:00
James Cole
d4525da6bc Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-22 15:54:06 +01:00
James Cole
25b11bd20b Add preference for native amounts. 2024-12-22 15:53:59 +01:00
github-actions
705aac419a Auto commit for release 'branch-v6.2' on 2024-12-22 2024-12-22 14:00:37 +01:00
James Cole
f6e642f72e Add and remove exchange rates 2024-12-22 13:19:23 +01:00
James Cole
565bd87959 Code cleanup 2024-12-22 08:43:12 +01:00
James Cole
5751f7e5a3 Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2
# Conflicts:
#	app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php
#	app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php
#	routes/api.php
2024-12-22 08:28:44 +01:00
James Cole
f5a755d4fc Various changes 2024-12-22 08:27:01 +01:00
github-actions
a500de8ab1 Auto commit for release 'branch-v6.2' on 2024-12-22 2024-12-22 07:05:15 +01:00
James Cole
303548a5fe Clean up command. 2024-12-22 07:01:16 +01:00
James Cole
68de905698 Remove command. 2024-12-22 06:59:05 +01:00
James Cole
9240b9868b Optimize memory usage. 2024-12-22 06:55:07 +01:00
James Cole
0e2e155cc6 Expand notifications. 2024-12-22 06:44:01 +01:00
James Cole
bffa0088b4 Extend warning with IP + host etc. 2024-12-22 06:33:37 +01:00
James Cole
2e993857e8 APIs and views for exchange rates. 2024-12-22 06:24:45 +01:00
James Cole
117a376fc3 Expand page for currency exchange rates. 2024-12-21 21:31:28 +01:00
James Cole
1daffedde0 First page for currency exchange rates. 2024-12-21 21:01:03 +01:00
James Cole
0e8fdd76a6 Index for exchange rates. 2024-12-21 18:35:05 +01:00
James Cole
7ff4f29bcb Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-21 12:51:52 +01:00
James Cole
9e4cff2b23 Add a little debug, less massive recalculations. 2024-12-21 12:51:40 +01:00
github-actions
4aaea89f2c Auto commit for release 'branch-v6.2' on 2024-12-21 2024-12-21 12:27:07 +01:00
James Cole
4fbf7b38fb Do not pull in invalid transactions 2024-12-21 11:40:34 +01:00
James Cole
76075401f9 Recalculate amounts. 2024-12-21 11:33:58 +01:00
James Cole
e2a20dd63d Command to recalculate foreign amounts. 2024-12-21 11:20:48 +01:00
James Cole
b52a1f3eb1 Respond to currency changes. 2024-12-21 07:12:11 +01:00
James Cole
7fd5a88122 Add more column conversions. 2024-12-20 05:31:16 +01:00
James Cole
1a1baa5cda Add observers for amounts. 2024-12-20 05:20:37 +01:00
James Cole
577d671a0c Add native amount column 2024-12-19 06:21:17 +01:00
James Cole
380029ffd8 Fix missing method. 2024-12-18 16:57:11 +01:00
github-actions
76cc27a267 Auto commit for release 'branch-v6.2' on 2024-12-18 2024-12-18 16:45:41 +01:00
James Cole
e8a6f30e4e Merge branch 'develop' into v6.2
# Conflicts:
#	composer.lock
#	config/firefly.php
#	package-lock.json
2024-12-18 16:39:22 +01:00
James Cole
2d10f255c2 Fix reference to old method. 2024-12-18 16:18:06 +01:00
James Cole
ee76cc6761 Fix methods 2024-12-18 16:13:32 +01:00
James Cole
d4e4907363 Add option for manual activation. 2024-12-15 19:59:36 +01:00
James Cole
c205e93876 Fix https://github.com/firefly-iii/firefly-iii/issues/7288 2024-12-15 19:51:46 +01:00
James Cole
3b24bb99bb Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-15 19:51:37 +01:00
James Cole
2814cd1b2a Better name 2024-12-15 19:51:30 +01:00
github-actions
5285e1ac14 Auto commit for release 'branch-v6.2' on 2024-12-15 2024-12-15 16:16:13 +01:00
James Cole
48a999cf91 Fix old reference. 2024-12-15 16:11:48 +01:00
github-actions
6bb297e76f Auto commit for release 'branch-v6.2' on 2024-12-15 2024-12-15 10:32:00 +01:00
James Cole
bc698f67ea Merge branch 'main' into v6.2 2024-12-15 09:07:04 +01:00
James Cole
2d0aa207d4 Fix various piggy bank errors 2024-12-15 08:50:57 +01:00
James Cole
4a75e9c262 Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-15 08:20:52 +01:00
James Cole
ee7c4b8863 Fix user test notification. 2024-12-15 08:20:42 +01:00
github-actions
53cce6510c Auto commit for release 'branch-v6.2' on 2024-12-14 2024-12-14 22:20:13 +01:00
James Cole
8f3cf38f77 Remove exception because it breaks the upgrade. 2024-12-14 22:12:56 +01:00
James Cole
f33766a062 Make column nullable so migration does not fail. 2024-12-14 22:06:53 +01:00
James Cole
ac5e62c65d Merge branch 'main' into v6.2 2024-12-14 21:56:26 +01:00
github-actions
e2289ce1e6 Auto commit for release 'branch-v6.2' on 2024-12-14 2024-12-14 21:55:42 +01:00
James Cole
28d7e24d30 Fix piggy bank orders 2024-12-14 20:16:08 +01:00
James Cole
6a62f781e9 Multi account piggy banks. 2024-12-14 17:32:03 +01:00
James Cole
fb6c67fa04 Fix https://github.com/firefly-iii/firefly-iii/issues/9532 2024-12-14 08:10:58 +01:00
James Cole
03e9e3dbdb Expand all notifications. 2024-12-14 08:03:18 +01:00
James Cole
5520992861 Clean up and fix notifications. 2024-12-14 07:52:02 +01:00
James Cole
5f1502eea7 Clean up code. 2024-12-14 07:22:46 +01:00
James Cole
b3560ff525 Clean up notifications 2024-12-14 07:13:01 +01:00
James Cole
8030167ffc Clean up notifications, fix first user notification. 2024-12-14 07:05:08 +01:00
James Cole
fd2c1615cf Start cleaning up notifications. 2024-12-14 06:57:57 +01:00
James Cole
b976239580 Fix all test channels for user and owner. 2024-12-14 06:30:27 +01:00
James Cole
7d8d773f8f Clean up some code. 2024-12-14 05:45:54 +01:00
James Cole
b930ad4da7 Update code and packages 2024-12-14 05:43:13 +01:00
James Cole
abad7cdf16 Update packages and notification settings 2024-12-14 05:39:55 +01:00
James Cole
0e5eb036b0 Unknown user warning. 2024-12-12 07:09:17 +01:00
James Cole
d995bfc081 Update all owner events so they support all channels 2024-12-12 06:33:48 +01:00
James Cole
c920070ce2 Expand settings for notifications. 2024-12-11 07:23:46 +01:00
James Cole
c35ff3174a Add support for Pushover 2024-12-09 07:34:01 +01:00
James Cole
94085ee940 Add config for ntfy 2024-12-09 06:27:37 +01:00
James Cole
c841fa3620 Remove references to discord. 2024-12-09 06:00:43 +01:00
James Cole
2f7a1c941e Expand test notification framework. 2024-12-08 16:28:22 +01:00
James Cole
c06fb8daf6 Expand notifications settings. 2024-12-07 09:41:09 +01:00
James Cole
26948a058a Expand UI for notifications. 2024-12-07 08:05:51 +01:00
James Cole
1220564f30 Fix creating piggies 2024-12-07 08:05:29 +01:00
James Cole
ea4be9dd0c Expand forms and improve validation for multi-account piggy banks 2024-12-06 08:10:31 +01:00
James Cole
4819b5ac5d More code for multi account piggy banks. 2024-12-04 06:38:47 +01:00
James Cole
d740814f88 API works for multi-account piggies, the rest throws an exception 2024-12-01 18:32:05 +01:00
James Cole
cdf1ebf3f7 Better ability to store piggy banks. 2024-12-01 18:16:48 +01:00
James Cole
f2fab5d4ee Update code for piggy banks. 2024-12-01 06:48:15 +01:00
James Cole
21a6927279 Rename fields for piggy bank 2024-11-30 16:02:30 +01:00
James Cole
92190bbc54 Rename fields in piggy bank. 2024-11-30 15:57:11 +01:00
James Cole
9ad005e31f Add edit button for notes https://github.com/firefly-iii/firefly-iii/issues/5523 2024-11-30 06:19:21 +01:00
James Cole
f5c56e02da API allows update/set of budget limit notes. https://github.com/firefly-iii/firefly-iii/issues/5523 2024-11-30 05:42:59 +01:00
James Cole
c25c0d37c5 Replace constants with enums. 2024-11-27 08:08:52 +01:00
James Cole
4ba1c5bcfc New set of PHP 8.4 files 2024-11-26 18:04:32 +01:00
807 changed files with 18868 additions and 11767 deletions

View File

@@ -1369,12 +1369,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
} }
}, },
"autoload": { "autoload": {
@@ -1517,12 +1517,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
} }
}, },
"autoload": { "autoload": {
@@ -2329,12 +2329,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
} }
}, },
"autoload": { "autoload": {

View File

@@ -26,8 +26,7 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/php-cs-fixer cd $SCRIPT_DIR/php-cs-fixer
composer update --quiet composer update --quiet
rm -f .php-cs-fixer.cache rm -f .php-cs-fixer.cache
PHP_CS_FIXER_IGNORE_ENV=true PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix \
./vendor/bin/php-cs-fixer fix \
--config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \ --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \
--format=txt \ --format=txt \
--allow-risky=yes --allow-risky=yes

View File

@@ -10,7 +10,7 @@ on:
phpversion: phpversion:
description: 'PHP version' description: 'PHP version'
required: true required: true
default: '8.3' default: '8.4'
schedule: schedule:
- cron: '0 3 * * MON' - cron: '0 3 * * MON'

View File

@@ -19,7 +19,7 @@ jobs:
- name: Setup PHP with Xdebug - name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: '8.3' php-version: '8.4'
coverage: xdebug coverage: xdebug
extensions: >- extensions: >-
bcmath bcmath

View File

@@ -30,6 +30,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Api\AccountFilter; use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -89,11 +90,11 @@ class AccountController extends Controller
$currency = $this->repository->getAccountCurrency($account) ?? $defaultCurrency; $currency = $this->repository->getAccountCurrency($account) ?? $defaultCurrency;
if (in_array($account->accountType->type, $this->balanceTypes, true)) { if (in_array($account->accountType->type, $this->balanceTypes, true)) {
$balance = app('steam')->balance($account, $date); $balance = Steam::finalAccountBalance($account, $date);
$nameWithBalance = sprintf( $nameWithBalance = sprintf(
'%s (%s)', '%s (%s)',
$account->name, $account->name,
app('amount')->formatAnything($currency, $balance, false) app('amount')->formatAnything($currency, $balance['balance'], false)
); );
} }

View File

@@ -68,12 +68,11 @@ class PiggyBankController extends Controller
{ {
$data = $request->getData(); $data = $request->getData();
$piggies = $this->piggyRepository->searchPiggyBank($data['query'], $this->parameters->get('limit')); $piggies = $this->piggyRepository->searchPiggyBank($data['query'], $this->parameters->get('limit'));
$defaultCurrency = app('amount')->getDefaultCurrency();
$response = []; $response = [];
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($piggies as $piggy) { foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; $currency = $piggy->transactionCurrency;
$objectGroup = $piggy->objectGroups()->first(); $objectGroup = $piggy->objectGroups()->first();
$response[] = [ $response[] = [
'id' => (string) $piggy->id, 'id' => (string) $piggy->id,
@@ -99,13 +98,12 @@ class PiggyBankController extends Controller
{ {
$data = $request->getData(); $data = $request->getData();
$piggies = $this->piggyRepository->searchPiggyBank($data['query'], $this->parameters->get('limit')); $piggies = $this->piggyRepository->searchPiggyBank($data['query'], $this->parameters->get('limit'));
$defaultCurrency = app('amount')->getDefaultCurrency();
$response = []; $response = [];
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($piggies as $piggy) { foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; $currency = $piggy->transactionCurrency;
$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0'; $currentAmount = $this->piggyRepository->getCurrentAmount($piggy);
$objectGroup = $piggy->objectGroups()->first(); $objectGroup = $piggy->objectGroups()->first();
$response[] = [ $response[] = [
'id' => (string) $piggy->id, 'id' => (string) $piggy->id,
@@ -114,7 +112,7 @@ class PiggyBankController extends Controller
'%s (%s / %s)', '%s (%s / %s)',
$piggy->name, $piggy->name,
app('amount')->formatAnything($currency, $currentAmount, false), app('amount')->formatAnything($currency, $currentAmount, false),
app('amount')->formatAnything($currency, $piggy->targetamount, false), app('amount')->formatAnything($currency, $piggy->target_amount, false),
), ),
'currency_id' => (string) $currency->id, 'currency_id' => (string) $currency->id,
'currency_name' => $currency->name, 'currency_name' => $currency->name,

View File

@@ -116,13 +116,13 @@ class AccountController extends Controller
]; ];
// TODO this code is also present in the V2 chart account controller so this method is due to be deprecated. // TODO this code is also present in the V2 chart account controller so this method is due to be deprecated.
$currentStart = clone $start; $currentStart = clone $start;
$range = app('steam')->balanceInRange($account, $start, clone $end); $range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative);
// 2022-10-11 this method no longer converts to float. // 2022-10-11 this method no longer converts to float.
$previous = array_values($range)[0]; $previous = array_values($range)[0];
while ($currentStart <= $end) { while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d'); $format = $currentStart->format('Y-m-d');
$label = $currentStart->toAtomString(); $label = $currentStart->toAtomString();
$balance = array_key_exists($format, $range) ? $range[$format] : $previous; $balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
$previous = $balance; $previous = $balance;
$currentStart->addDay(); $currentStart->addDay();
$currentSet['entries'][$label] = $balance; $currentSet['entries'][$label] = $balance;

View File

@@ -55,6 +55,7 @@ abstract class Controller extends BaseController
/** @var array<int, string> */ /** @var array<int, string> */
protected array $allowedSort; protected array $allowedSort;
protected ParameterBag $parameters; protected ParameterBag $parameters;
protected bool $convertToNative = false;
/** /**
* Controller constructor. * Controller constructor.
@@ -68,7 +69,9 @@ abstract class Controller extends BaseController
$this->parameters = $this->getParameters(); $this->parameters = $this->getParameters();
if (auth()->check()) { if (auth()->check()) {
$language = app('steam')->getLanguage(); $language = app('steam')->getLanguage();
$this->convertToNative = app('preferences')->get('convert_to_native', false)->data;
app()->setLocale($language); app()->setLocale($language);
} }
return $next($request); return $next($request);

View File

@@ -29,13 +29,13 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -63,14 +63,17 @@ class PurgeController extends Controller
Bill::whereUserId($user->id)->onlyTrashed()->forceDelete(); Bill::whereUserId($user->id)->onlyTrashed()->forceDelete();
// piggies // piggies
$set = PiggyBank::leftJoin('accounts', 'accounts.id', 'piggy_banks.account_id') $repository = app(PiggyBankRepositoryInterface::class);
->where('accounts.user_id', $user->id)->onlyTrashed()->get(['piggy_banks.*']) $repository->setUser($user);
; $repository->purgeAll();
// $set = PiggyBank::leftJoin('accounts', 'accounts.id', 'piggy_banks.account_id')
/** @var PiggyBank $piggy */ // ->where('accounts.user_id', $user->id)->onlyTrashed()->get(['piggy_banks.*'])
foreach ($set as $piggy) { // ;
$piggy->forceDelete(); //
} // /** @var PiggyBank $piggy */
// foreach ($set as $piggy) {
// $piggy->forceDelete();
// }
// rule group // rule group
RuleGroup::whereUserId($user->id)->onlyTrashed()->forceDelete(); RuleGroup::whereUserId($user->id)->onlyTrashed()->forceDelete();

View File

@@ -111,7 +111,7 @@ class ListController extends Controller
// types to get, page size: // types to get, page size:
$pageSize = $this->parameters->get('limit'); $pageSize = $this->parameters->get('limit');
// get list of budgets. Count it and split it. // get list of piggy banks. Count it and split it.
$collection = $this->repository->getPiggyBanks($account); $collection = $this->repository->getPiggyBanks($account);
$count = $collection->count(); $count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@@ -69,6 +69,7 @@ class StoreController extends Controller
$data = $request->getAll(); $data = $request->getAll();
$data['start_date'] = $data['start']; $data['start_date'] = $data['start'];
$data['end_date'] = $data['end']; $data['end_date'] = $data['end'];
$data['notes'] = $data['notes'];
$data['budget_id'] = $budget->id; $data['budget_id'] = $budget->id;
$budgetLimit = $this->blRepository->store($data); $budgetLimit = $this->blRepository->store($data);

View File

@@ -28,6 +28,7 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer;
use FireflyIII\Transformers\AttachmentTransformer; use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\PiggyBankEventTransformer; use FireflyIII\Transformers\PiggyBankEventTransformer;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -58,6 +59,38 @@ class ListController extends Controller
); );
} }
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/piggy_banks/listAccountByPiggyBank
*
* List single resource.
*
* @throws FireflyException
*/
public function accounts(PiggyBank $piggyBank): JsonResponse
{
// types to get, page size:
$pageSize = $this->parameters->get('limit');
$manager = $this->getManager();
$collection = $piggyBank->accounts;
$count = $collection->count();
$events = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.piggy-banks.accounts', [$piggyBank->id]).$this->buildParams());
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($events, $transformer, 'accounts');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/** /**
* This endpoint is documented at: * This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/piggy_banks/listAttachmentByPiggyBank * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/piggy_banks/listAttachmentByPiggyBank

View File

@@ -72,7 +72,7 @@ class ShowController extends Controller
// types to get, page size: // types to get, page size:
$pageSize = $this->parameters->get('limit'); $pageSize = $this->parameters->get('limit');
// get list of budgets. Count it and split it. // get list of piggy banks. Count it and split it.
$collection = $this->repository->getPiggyBanks(); $collection = $this->repository->getPiggyBanks();
$count = $collection->count(); $count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@@ -62,7 +62,6 @@ class AccountController extends Controller
*/ */
public function search(Request $request): JsonResponse|Response public function search(Request $request): JsonResponse|Response
{ {
app('log')->debug('Now in account search()');
$manager = $this->getManager(); $manager = $this->getManager();
$query = trim((string) $request->get('query')); $query = trim((string) $request->get('query'));
$field = trim((string) $request->get('field')); $field = trim((string) $request->get('field'));
@@ -70,6 +69,7 @@ class AccountController extends Controller
if ('' === $query || !in_array($field, $this->validFields, true)) { if ('' === $query || !in_array($field, $this->validFields, true)) {
return response(null, 422); return response(null, 422);
} }
app('log')->debug(sprintf('Now in account search("%s", "%s")', $field, $query));
$types = $this->mapAccountTypes($type); $types = $this->mapAccountTypes($type);
/** @var AccountSearch $search */ /** @var AccountSearch $search */

View File

@@ -27,19 +27,21 @@ namespace FireflyIII\Api\V1\Controllers\Summary;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest; use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface; use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
/** /**
* Class BasicController * Class BasicController
@@ -120,6 +122,9 @@ class BasicController extends Controller
private function getBalanceInformation(Carbon $start, Carbon $end): array private function getBalanceInformation(Carbon $start, Carbon $end): array
{ {
// some config settings
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
$default = app('amount')->getDefaultCurrency();
// prep some arrays: // prep some arrays:
$incomes = []; $incomes = [];
$expenses = []; $expenses = [];
@@ -133,16 +138,17 @@ class BasicController extends Controller
$set = $collector->getExtractedJournals(); $set = $collector->getExtractedJournals();
/** @var array $transactionJournal */ /** @var array $journal */
foreach ($set as $transactionJournal) { foreach ($set as $journal) {
$currencyId = (int)$transactionJournal['currency_id']; $currencyId = $convertToNative ? $default->id : (int) $journal['currency_id'];
$amount = Amount::getAmountFromJournal($journal);
$incomes[$currencyId] ??= '0'; $incomes[$currencyId] ??= '0';
$incomes[$currencyId] = bcadd( $incomes[$currencyId] = bcadd(
$incomes[$currencyId], $incomes[$currencyId],
bcmul($transactionJournal['amount'], '-1') bcmul($amount, '-1')
); );
$sums[$currencyId] ??= '0'; $sums[$currencyId] ??= '0';
$sums[$currencyId] = bcadd($sums[$currencyId], bcmul($transactionJournal['amount'], '-1')); $sums[$currencyId] = bcadd($sums[$currencyId], bcmul($amount, '-1'));
} }
// collect expenses of user using the new group collector. // collect expenses of user using the new group collector.
@@ -151,13 +157,14 @@ class BasicController extends Controller
$collector->setRange($start, $end)->setPage($this->parameters->get('page'))->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); $collector->setRange($start, $end)->setPage($this->parameters->get('page'))->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$set = $collector->getExtractedJournals(); $set = $collector->getExtractedJournals();
/** @var array $transactionJournal */ /** @var array $journal */
foreach ($set as $transactionJournal) { foreach ($set as $journal) {
$currencyId = (int)$transactionJournal['currency_id']; $currencyId = $convertToNative ? $default->id : (int) $journal['currency_id'];
$amount = Amount::getAmountFromJournal($journal);
$expenses[$currencyId] ??= '0'; $expenses[$currencyId] ??= '0';
$expenses[$currencyId] = bcadd($expenses[$currencyId], $transactionJournal['amount']); $expenses[$currencyId] = bcadd($expenses[$currencyId], $amount);
$sums[$currencyId] ??= '0'; $sums[$currencyId] ??= '0';
$sums[$currencyId] = bcadd($sums[$currencyId], $transactionJournal['amount']); $sums[$currencyId] = bcadd($sums[$currencyId], $amount);
} }
// format amounts: // format amounts:
@@ -274,19 +281,22 @@ class BasicController extends Controller
$available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end); $available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end);
$budgets = $this->budgetRepository->getActiveBudgets(); $budgets = $this->budgetRepository->getActiveBudgets();
$spent = $this->opsRepository->sumExpenses($start, $end, null, $budgets); $spent = $this->opsRepository->sumExpenses($start, $end, null, $budgets);
$days = (int) $today->diffInDays($end, true) + 1;
Log::debug(sprintf('Now in getLeftToSpendInfo("%s", "%s")', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));
foreach ($spent as $row) { foreach ($spent as $row) {
// either an amount was budgeted or 0 is available. // either an amount was budgeted or 0 is available.
$amount = (string)($available[$row['currency_id']] ?? '0'); $currencyId = $row['currency_id'];
$amount = (string) ($available[$currencyId] ?? '0');
$spentInCurrency = $row['sum']; $spentInCurrency = $row['sum'];
$leftToSpend = bcadd($amount, $spentInCurrency); $leftToSpend = bcadd($amount, $spentInCurrency);
$days = (int)$today->diffInDays($end, true) + 1;
$perDay = '0'; $perDay = '0';
if (0 !== $days && bccomp($leftToSpend, '0') > -1) { if (0 !== $days && bccomp($leftToSpend, '0') > -1) {
$perDay = bcdiv($leftToSpend, (string) $days); $perDay = bcdiv($leftToSpend, (string) $days);
} }
Log::debug(sprintf('Spent %s %s', $row['currency_code'], $row['sum']));
$return[] = [ $return[] = [
'key' => sprintf('left-to-spend-in-%s', $row['currency_code']), 'key' => sprintf('left-to-spend-in-%s', $row['currency_code']),
'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $row['currency_symbol']]), 'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $row['currency_symbol']]),
@@ -311,9 +321,11 @@ class BasicController extends Controller
private function getNetWorthInfo(Carbon $start, Carbon $end): array private function getNetWorthInfo(Carbon $start, Carbon $end): array
{ {
Log::debug('getNetWorthInfo');
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$date = today(config('app.timezone'))->startOfDay(); $date = now(config('app.timezone'));
// start and end in the future? use $end // start and end in the future? use $end
if ($this->notInDateRange($date, $start, $end)) { if ($this->notInDateRange($date, $start, $end)) {
/** @var Carbon $date */ /** @var Carbon $date */
@@ -323,9 +335,7 @@ class BasicController extends Controller
/** @var NetWorthInterface $netWorthHelper */ /** @var NetWorthInterface $netWorthHelper */
$netWorthHelper = app(NetWorthInterface::class); $netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper->setUser($user); $netWorthHelper->setUser($user);
$allAccounts = $this->accountRepository->getActiveAccountsByType( $allAccounts = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value]);
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT]
);
// filter list on preference of being included. // filter list on preference of being included.
$filtered = $allAccounts->filter( $filtered = $allAccounts->filter(
@@ -360,6 +370,7 @@ class BasicController extends Controller
'sub_title' => '', 'sub_title' => '',
]; ];
} }
Log::debug('End of getNetWorthInfo');
return $return; return $return;
} }

View File

@@ -48,6 +48,7 @@ class StoreRequest extends FormRequest
'amount' => $this->convertString('amount'), 'amount' => $this->convertString('amount'),
'currency_id' => $this->convertInteger('currency_id'), 'currency_id' => $this->convertInteger('currency_id'),
'currency_code' => $this->convertString('currency_code'), 'currency_code' => $this->convertString('currency_code'),
'notes' => $this->stringWithNewlines('notes'),
]; ];
} }
@@ -62,6 +63,7 @@ class StoreRequest extends FormRequest
'amount' => ['required', new IsValidPositiveAmount()], 'amount' => ['required', new IsValidPositiveAmount()],
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
'notes' => 'nullable|min:0|max:32768',
]; ];
} }
} }

View File

@@ -51,7 +51,12 @@ class UpdateRequest extends FormRequest
'amount' => ['amount', 'convertString'], 'amount' => ['amount', 'convertString'],
'currency_id' => ['currency_id', 'convertInteger'], 'currency_id' => ['currency_id', 'convertInteger'],
'currency_code' => ['currency_code', 'convertString'], 'currency_code' => ['currency_code', 'convertString'],
'notes' => ['notes', 'stringWithNewlines'],
]; ];
if (false === $this->has('notes')) {
// ignore notes, not submitted.
unset($fields['notes']);
}
return $this->getAllData($fields); return $this->getAllData($fields);
} }
@@ -67,6 +72,7 @@ class UpdateRequest extends FormRequest
'amount' => ['nullable', new IsValidPositiveAmount()], 'amount' => ['nullable', new IsValidPositiveAmount()],
'currency_id' => 'numeric|exists:transaction_currencies,id', 'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:51|exists:transaction_currencies,code', 'currency_code' => 'min:3|max:51|exists:transaction_currencies,code',
'notes' => 'nullable|min:0|max:32768',
]; ];
} }

View File

@@ -24,10 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\PiggyBank; namespace FireflyIII\Api\V1\Requests\Models\PiggyBank;
use FireflyIII\Rules\IsValidPositiveAmount; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Rules\IsValidZeroOrMoreAmount;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Validator;
/** /**
* Class StoreRequest * Class StoreRequest
@@ -47,18 +52,38 @@ class StoreRequest extends FormRequest
]; ];
$data = $this->getAllData($fields); $data = $this->getAllData($fields);
$data['name'] = $this->convertString('name'); $data['name'] = $this->convertString('name');
$data['account_id'] = $this->convertInteger('account_id'); $data['accounts'] = $this->parseAccounts($this->get('accounts'));
$data['targetamount'] = $this->convertString('target_amount'); $data['target_amount'] = $this->convertString('target_amount');
$data['current_amount'] = $this->convertString('current_amount'); $data['start_date'] = $this->getCarbonDate('start_date');
$data['startdate'] = $this->getCarbonDate('start_date'); $data['target_date'] = $this->getCarbonDate('target_date');
$data['targetdate'] = $this->getCarbonDate('target_date');
$data['notes'] = $this->stringWithNewlines('notes'); $data['notes'] = $this->stringWithNewlines('notes');
$data['object_group_id'] = $this->convertInteger('object_group_id'); $data['object_group_id'] = $this->convertInteger('object_group_id');
$data['transaction_currency_id'] = $this->convertInteger('transaction_currency_id');
$data['transaction_currency_code'] = $this->convertString('transaction_currency_code');
$data['object_group_title'] = $this->convertString('object_group_title'); $data['object_group_title'] = $this->convertString('object_group_title');
return $data; return $data;
} }
private function parseAccounts(mixed $array): array
{
if (!is_array($array)) {
return [];
}
$return = [];
foreach ($array as $entry) {
if (!is_array($entry)) {
continue;
}
$return[] = [
'account_id' => $this->integerFromValue((string) ($entry['account_id'] ?? '0')),
'current_amount' => $this->clearString((string) ($entry['current_amount'] ?? '0')),
];
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
*/ */
@@ -66,14 +91,79 @@ class StoreRequest extends FormRequest
{ {
return [ return [
'name' => 'required|min:1|max:255|uniquePiggyBankForUser', 'name' => 'required|min:1|max:255|uniquePiggyBankForUser',
'current_amount' => ['nullable', new IsValidPositiveAmount()], 'accounts' => 'required',
'account_id' => 'required|numeric|belongsToUser:accounts,id', 'accounts.*' => 'array|required',
'accounts.*.account_id' => 'required|numeric|belongsToUser:accounts,id',
'accounts.*.current_amount' => ['numeric', new IsValidZeroOrMoreAmount()],
'object_group_id' => 'numeric|belongsToUser:object_groups,id', 'object_group_id' => 'numeric|belongsToUser:object_groups,id',
'object_group_title' => ['min:1', 'max:255'], 'object_group_title' => ['min:1', 'max:255'],
'target_amount' => ['required', new IsValidPositiveAmount()], 'target_amount' => ['required', new IsValidZeroOrMoreAmount()],
'start_date' => 'date|nullable', 'start_date' => 'date|nullable',
'transaction_currency_id' => 'exists:transaction_currencies,id|required_without:transaction_currency_code',
'transaction_currency_code' => 'exists:transaction_currencies,code|required_without:transaction_currency_id',
'target_date' => 'date|nullable|after:start_date', 'target_date' => 'date|nullable|after:start_date',
'notes' => 'max:65000', 'notes' => 'max:65000',
]; ];
} }
/**
* Can only store money on liabilities and asset accounts.
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator): void {
// validate start before end only if both are there.
$data = $validator->getData();
$currency = $this->getCurrencyFromData($data);
$targetAmount = (string) ($data['target_amount'] ?? '0');
$currentAmount = '0';
if (array_key_exists('accounts', $data) && is_array($data['accounts'])) {
$repository = app(AccountRepositoryInterface::class);
$types = config('firefly.piggy_bank_account_types');
foreach ($data['accounts'] as $index => $array) {
$accountId = (int) ($array['account_id'] ?? 0);
$account = $repository->find($accountId);
if (null !== $account) {
// check currency here.
$accountCurrency = $repository->getAccountCurrency($account);
$isMultiCurrency = $repository->getMetaValue($account, 'is_multi_currency');
$currentAmount = bcadd($currentAmount, (string) ($array['current_amount'] ?? '0'));
if ($accountCurrency->id !== $currency->id && 'true' !== $isMultiCurrency) {
$validator->errors()->add(sprintf('accounts.%d', $index), trans('validation.invalid_account_currency'));
}
$type = $account->accountType->type;
if (!in_array($type, $types, true)) {
$validator->errors()->add(sprintf('accounts.%d', $index), trans('validation.invalid_account_type'));
}
}
}
}
if (-1 === bccomp($targetAmount, $currentAmount) && 1 === bccomp($targetAmount, '0')) {
$validator->errors()->add('target_amount', trans('validation.current_amount_too_much'));
}
}
);
if ($validator->fails()) {
Log::channel('audit')->error(sprintf('Validation errors in %s', __CLASS__), $validator->errors()->toArray());
}
}
private function getCurrencyFromData(array $data): TransactionCurrency
{
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
$currency = TransactionCurrency::whereCode($data['transaction_currency_code'])->first();
if (null !== $currency) {
return $currency;
}
}
if (array_key_exists('transaction_currency_id', $data) && '' !== (string) $data['transaction_currency_id']) {
$currency = TransactionCurrency::find((int) $data['transaction_currency_id']);
if (null !== $currency) {
return $currency;
}
}
throw new FireflyException('Unexpected empty currency.');
}
} }

View File

@@ -119,7 +119,7 @@ class StoreRequest extends FormRequest
'description' => 'min:1|max:32768|nullable', 'description' => 'min:1|max:32768|nullable',
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title', 'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
'rule_group_title' => 'nullable|min:1|max:255|required_without:rule_group_id|belongsToUser:rule_groups,title', 'rule_group_title' => 'nullable|min:1|max:255|required_without:rule_group_id|belongsToUser:rule_groups,title',
'trigger' => 'required|in:store-journal,update-journal', 'trigger' => 'required|in:store-journal,update-journal,manual-activation',
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers), 'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024', 'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
'triggers.*.stop_processing' => [new IsBoolean()], 'triggers.*.stop_processing' => [new IsBoolean()],

View File

@@ -138,7 +138,7 @@ class UpdateRequest extends FormRequest
'description' => 'min:1|max:32768|nullable', 'description' => 'min:1|max:32768|nullable',
'rule_group_id' => 'belongsToUser:rule_groups', 'rule_group_id' => 'belongsToUser:rule_groups',
'rule_group_title' => 'nullable|min:1|max:255|belongsToUser:rule_groups,title', 'rule_group_title' => 'nullable|min:1|max:255|belongsToUser:rule_groups,title',
'trigger' => 'in:store-journal,update-journal', 'trigger' => 'in:store-journal,update-journal.manual-activation',
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers), 'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024', 'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
'triggers.*.stop_processing' => [new IsBoolean()], 'triggers.*.stop_processing' => [new IsBoolean()],

View File

@@ -40,9 +40,9 @@ use Illuminate\Support\Facades\Log;
*/ */
class AccountController extends Controller class AccountController extends Controller
{ {
private AccountRepositoryInterface $repository;
private TransactionCurrency $default;
private ExchangeRateConverter $converter; private ExchangeRateConverter $converter;
private TransactionCurrency $default;
private AccountRepositoryInterface $repository;
/** /**
* AccountController constructor. * AccountController constructor.

View File

@@ -45,9 +45,9 @@ class AccountController extends Controller
use CollectsAccountsFromFilter; use CollectsAccountsFromFilter;
use ValidatesUserGroupTrait; use ValidatesUserGroupTrait;
private AccountRepositoryInterface $repository;
private ChartData $chartData; private ChartData $chartData;
private TransactionCurrency $default; private TransactionCurrency $default;
private AccountRepositoryInterface $repository;
public function __construct() public function __construct()
{ {
@@ -118,22 +118,21 @@ class AccountController extends Controller
'native_entries' => [], 'native_entries' => [],
]; ];
$currentStart = clone $params['start']; $currentStart = clone $params['start'];
$range = app('steam')->balanceInRange($account, $params['start'], clone $params['end'], $currency); $range = app('steam')->finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToNative);
$rangeConverted = app('steam')->balanceInRangeConverted($account, $params['start'], clone $params['end'], $this->default);
$previous = array_values($range)[0]; $previous = array_values($range)[0]['balance'];
$previousConverted = array_values($rangeConverted)[0]; $previousNative = array_values($range)[0]['native_balance'];
while ($currentStart <= $params['end']) { while ($currentStart <= $params['end']) {
$format = $currentStart->format('Y-m-d'); $format = $currentStart->format('Y-m-d');
$label = $currentStart->toAtomString(); $label = $currentStart->toAtomString();
$balance = array_key_exists($format, $range) ? $range[$format] : $previous; $balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
$balanceConverted = array_key_exists($format, $rangeConverted) ? $rangeConverted[$format] : $previousConverted; $balanceNative = array_key_exists($format, $range) ? $range[$format]['balance_native'] : $previousNative;
$previous = $balance; $previous = $balance;
$previousConverted = $balanceConverted; $previousNative = $balanceNative;
$currentStart->addDay(); $currentStart->addDay();
$currentSet['entries'][$label] = $balance; $currentSet['entries'][$label] = $balance;
$currentSet['native_entries'][$label] = $balanceConverted; $currentSet['native_entries'][$label] = $balanceNative;
} }
$this->chartData->add($currentSet); $this->chartData->add($currentSet);
} }

View File

@@ -45,9 +45,10 @@ class BalanceController extends Controller
use CleansChartData; use CleansChartData;
use CollectsAccountsFromFilter; use CollectsAccountsFromFilter;
private AccountRepositoryInterface $repository;
private GroupCollectorInterface $collector;
private ChartData $chartData; private ChartData $chartData;
private GroupCollectorInterface $collector;
private AccountRepositoryInterface $repository;
// private TransactionCurrency $default; // private TransactionCurrency $default;
public function __construct() public function __construct()

View File

@@ -55,8 +55,9 @@ class Controller extends BaseController
use ValidatesUserGroupTrait; use ValidatesUserGroupTrait;
protected const string CONTENT_TYPE = 'application/vnd.api+json'; protected const string CONTENT_TYPE = 'application/vnd.api+json';
protected ParameterBag $parameters;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY]; protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
protected ParameterBag $parameters;
protected bool $convertToNative = false;
public function __construct() public function __construct()
{ {
@@ -92,8 +93,8 @@ class Controller extends BaseController
if ($page < 1) { if ($page < 1) {
$page = 1; $page = 1;
} }
if ($page > (2 ^ 16)) { if ($page > 2 ** 16) {
$page = (2 ^ 16); $page = 2 ** 16;
} }
$bag->set('page', $page); $bag->set('page', $page);

View File

@@ -48,6 +48,7 @@ class AccountController extends Controller
use Actions\DetachRelationship; use Actions\DetachRelationship;
use Actions\FetchMany; use Actions\FetchMany;
// use Actions\FetchOne; // use Actions\FetchOne;
use Actions\FetchRelated; use Actions\FetchRelated;
use Actions\FetchRelationship; use Actions\FetchRelationship;

View File

@@ -36,9 +36,8 @@ use Illuminate\Support\Facades\Log;
class IndexController extends Controller class IndexController extends Controller
{ {
public const string RESOURCE_KEY = 'accounts'; public const string RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY, UserRoleEnum::MANAGE_TRANSACTIONS]; protected array $acceptedRoles = [UserRoleEnum::READ_ONLY, UserRoleEnum::MANAGE_TRANSACTIONS];
private AccountRepositoryInterface $repository;
/** /**
* AccountController constructor. * AccountController constructor.

View File

@@ -39,9 +39,8 @@ use Illuminate\Http\JsonResponse;
class ShowController extends Controller class ShowController extends Controller
{ {
public const string RESOURCE_KEY = 'accounts'; public const string RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY, UserRoleEnum::MANAGE_TRANSACTIONS]; protected array $acceptedRoles = [UserRoleEnum::READ_ONLY, UserRoleEnum::MANAGE_TRANSACTIONS];
private AccountRepositoryInterface $repository;
/** /**
* AccountController constructor. * AccountController constructor.

View File

@@ -0,0 +1,67 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\ExchangeRate;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Model\ExchangeRate\DestroyRequest;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DestroyController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(ExchangeRateRepositoryInterface::class);
$this->repository->setUserGroup($this->validateUserGroup($request));
return $next($request);
}
);
}
public function destroy(DestroyRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse
{
$date = $request->getDate();
$rate = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null === $rate) {
throw new NotFoundHttpException();
}
$this->repository->deleteRate($rate);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\ExchangeRate;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* Class ShowController
*/
class IndexController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(ExchangeRateRepositoryInterface::class);
$this->repository->setUserGroup($this->validateUserGroup($request));
return $next($request);
}
);
}
public function index(): JsonResponse
{
$piggies = $this->repository->getAll();
$pageSize = $this->parameters->get('limit');
$count = $piggies->count();
$piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page'));
var_dump('here we are');
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* ShowController.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\ExchangeRate;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\V2\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* Class ShowController
*/
class ShowController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(ExchangeRateRepositoryInterface::class);
$this->repository->setUserGroup($this->validateUserGroup($request));
return $next($request);
}
);
}
public function show(TransactionCurrency $from, TransactionCurrency $to): JsonResponse
{
$pageSize = $this->parameters->get('limit');
$page = $this->parameters->get('page');
$rates = $this->repository->getRates($from, $to);
$count = $rates->count();
$rates = $rates->slice(($page - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($rates, $count, $pageSize, $page);
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\ExchangeRate;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Model\ExchangeRate\StoreRequest;
use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\V2\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
class StoreController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(ExchangeRateRepositoryInterface::class);
$this->repository->setUserGroup($this->validateUserGroup($request));
return $next($request);
}
);
}
public function store(StoreRequest $request): JsonResponse
{
$date = $request->getDate();
$rate = $request->getRate();
$from = $request->getFromCurrency();
$to = $request->getToCurrency();
// already has rate?
$object = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null !== $object) {
// just update it, no matter.
$rate = $this->repository->updateExchangeRate($object, $rate, $date);
}
if (null === $object) {
// store new
$rate = $this->repository->storeExchangeRate($from, $to, $rate, $date);
}
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters);
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $rate, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\ExchangeRate;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Model\ExchangeRate\UpdateRequest;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Repositories\UserGroups\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\V2\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
class UpdateController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(ExchangeRateRepositoryInterface::class);
$this->repository->setUserGroup($this->validateUserGroup($request));
return $next($request);
}
);
}
public function update(UpdateRequest $request, CurrencyExchangeRate $exchangeRate): JsonResponse
{
$date = $request->getDate();
$rate = $request->getRate();
$exchangeRate = $this->repository->updateExchangeRate($exchangeRate, $rate, $date);
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters);
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $exchangeRate, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* IndexController.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\TransactionCurrency;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Model\TransactionCurrency\IndexRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use FireflyIII\Transformers\V2\CurrencyTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
class IndexController extends Controller
{
public const string RESOURCE_KEY = 'transaction-currencies';
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
private CurrencyRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class);
// new way of user group validation
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
return $next($request);
}
);
}
public function index(IndexRequest $request): JsonResponse
{
$settings = $request->getAll();
if (true === $settings['enabled']) {
$currencies = $this->repository->get();
}
if (true !== $settings['enabled']) {
$currencies = $this->repository->getAll();
}
$pageSize = $this->parameters->get('limit');
$count = $currencies->count();
// depending on the sort parameters, this list must not be split, because the
// order is calculated in the account transformer and by that time it's too late.
$accounts = $currencies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
$transformer = new CurrencyTransformer();
$this->parameters->set('pageSize', $pageSize);
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Controllers\Model\TransactionCurrency;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use FireflyIII\Transformers\V2\CurrencyTransformer;
use Illuminate\Http\JsonResponse;
/**
* Class ShowController
*/
class ShowController extends Controller
{
public const string RESOURCE_KEY = 'transaction-currencies';
private CurrencyRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class);
// new way of user group validation
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
return $next($request);
}
);
}
public function show(TransactionCurrency $currency): JsonResponse
{
$groups = $currency->userGroups()->where('user_groups.id', $this->repository->getUserGroup()->id)->get();
$enabled = $groups->count() > 0;
$default = false;
/** @var UserGroup $group */
foreach ($groups as $group) {
$default = 1 === $group->pivot->group_default;
}
$currency->userGroupEnabled = $enabled;
$currency->userGroupDefault = $default;
$transformer = new CurrencyTransformer();
$transformer->setParameters($this->parameters);
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $currency, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -73,6 +73,16 @@ class AutocompleteRequest extends FormRequest
return $array; return $array;
} }
private function getAccountTypeParameter(array $types): array
{
$return = [];
foreach ($types as $type) {
$return = array_merge($return, $this->mapAccountTypes($type));
}
return array_unique($return);
}
public function rules(): array public function rules(): array
{ {
$valid = array_keys($this->types); $valid = array_keys($this->types);
@@ -86,14 +96,4 @@ class AutocompleteRequest extends FormRequest
'transaction_types' => 'nullable|in:todo', 'transaction_types' => 'nullable|in:todo',
]; ];
} }
private function getAccountTypeParameter(array $types): array
{
$return = [];
foreach ($types as $type) {
$return = array_merge($return, $this->mapAccountTypes($type));
}
return array_unique($return);
}
} }

View File

@@ -40,6 +40,7 @@ class BalanceChartRequest extends FormRequest
use ChecksLogin; use ChecksLogin;
use ConvertsDataTypes; use ConvertsDataTypes;
use ValidatesUserGroupTrait; use ValidatesUserGroupTrait;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY]; protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/** /**

View File

@@ -0,0 +1,51 @@
<?php
/*
* DestroyRequest.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Model\ExchangeRate;
use Carbon\Carbon;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
class DestroyRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
public function getDate(): Carbon
{
return $this->getCarbonDate('date');
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'date' => 'required|date|after:1900-01-01|before:2099-12-31',
];
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* DestroyRequest.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Model\ExchangeRate;
use Carbon\Carbon;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
public function getDate(): ?Carbon
{
return $this->getCarbonDate('date');
}
public function getRate(): string
{
return (string) $this->get('rate');
}
public function getFromCurrency(): TransactionCurrency
{
return TransactionCurrency::where('code', $this->get('from'))->first();
}
public function getToCurrency(): TransactionCurrency
{
return TransactionCurrency::where('code', $this->get('to'))->first();
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'date' => 'required|date|after:1900-01-01|before:2099-12-31',
'rate' => 'required|numeric|gt:0',
'from' => 'required|exists:transaction_currencies,code',
'to' => 'required|exists:transaction_currencies,code',
];
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*
* DestroyRequest.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Model\ExchangeRate;
use Carbon\Carbon;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
public function getDate(): ?Carbon
{
return $this->getCarbonDate('date');
}
public function getRate(): string
{
return (string) $this->get('rate');
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'date' => 'date|after:1900-01-01|before:2099-12-31',
'rate' => 'required|numeric|gt:0',
];
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* IndexRequest.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Model\TransactionCurrency;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use FireflyIII\Support\Request\GetFilterInstructions;
use FireflyIII\Support\Request\GetSortInstructions;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class IndexRequest
*
* Lots of code stolen from the SingleDateRequest.
*/
class IndexRequest extends FormRequest
{
use AccountFilter;
use ChecksLogin;
use ConvertsDataTypes;
use GetFilterInstructions;
use GetSortInstructions;
public function getAll(): array
{
return [
'enabled' => $this->convertBoolean($this->get('enabled')),
];
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'enabled' => 'nullable|boolean',
];
}
}

View File

@@ -1,5 +1,25 @@
<?php <?php
/*
* ConvertsDatesToUTC.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1); declare(strict_types=1);
/* /*
* ConvertDatesToUTC.php * ConvertDatesToUTC.php
@@ -21,7 +41,7 @@ declare(strict_types=1);
* along with this program. If not, see https://www.gnu.org/licenses/. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Correction;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
@@ -31,17 +51,10 @@ use Illuminate\Database\QueryException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class ConvertDatesToUTC extends Command class ConvertsDatesToUTC extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:migrate-to-utc';
/** /**
* The console command description. * The console command description.
* *
@@ -49,11 +62,22 @@ class ConvertDatesToUTC extends Command
*/ */
protected $description = 'Convert stored dates to UTC.'; protected $description = 'Convert stored dates to UTC.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'correction:convert-to-utc';
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle(): int public function handle(): int
{ {
$this->friendlyWarning('Please do not use this command.');
return 0;
/** /**
* @var string $model * @var string $model
* @var array $fields * @var array $fields

View File

@@ -1,253 +0,0 @@
<?php
/*
* CorrectAmounts.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RuleTrigger;
use Illuminate\Console\Command;
/**
* Class ReportSkeleton
*/
class CorrectAmounts extends Command
{
use ShowsFriendlyMessages;
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
protected $signature = 'firefly-iii:fix-amount-pos-neg';
public function handle(): int
{
// auto budgets must be positive
$this->fixAutoBudgets();
// available budgets must be positive
$this->fixAvailableBudgets();
// bills must be positive (both amounts)
$this->fixBills();
// budget limits must be positive
$this->fixBudgetLimits();
// currency_exchange_rates must be positive
$this->fixExchangeRates();
// piggy_bank_repetitions must be positive
$this->fixRepetitions();
// piggy_banks must be positive
$this->fixPiggyBanks();
// recurrences_transactions amount must be positive
$this->fixRecurrences();
// rule_triggers must be positive or zero (amount_less, amount_more, amount_is)
$this->fixRuleTriggers();
return 0;
}
private function fixAutoBudgets(): void
{
$set = AutoBudget::where('amount', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All auto budget amounts are positive.');
return;
}
/** @var AutoBudget $item */
foreach ($set as $item) {
$item->amount = app('steam')->positive($item->amount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d auto budget amount(s).', $count));
}
private function fixAvailableBudgets(): void
{
$set = AvailableBudget::where('amount', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All available budget amounts are positive.');
return;
}
/** @var AvailableBudget $item */
foreach ($set as $item) {
$item->amount = app('steam')->positive($item->amount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d available budget amount(s).', $count));
}
private function fixBills(): void
{
$set = Bill::where('amount_min', '<', 0)->orWhere('amount_max', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All bill amounts are positive.');
return;
}
/** @var Bill $item */
foreach ($set as $item) {
$item->amount_min = app('steam')->positive($item->amount_min);
$item->amount_max = app('steam')->positive($item->amount_max);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d bill amount(s).', $count));
}
private function fixBudgetLimits(): void
{
$set = BudgetLimit::where('amount', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All budget limit amounts are positive.');
return;
}
/** @var BudgetLimit $item */
foreach ($set as $item) {
$item->amount = app('steam')->positive($item->amount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d budget limit amount(s).', $count));
}
private function fixExchangeRates(): void
{
$set = CurrencyExchangeRate::where('rate', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All currency exchange rates are positive.');
return;
}
/** @var CurrencyExchangeRate $item */
foreach ($set as $item) {
$item->rate = app('steam')->positive($item->rate);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count));
}
private function fixRepetitions(): void
{
$set = PiggyBankRepetition::where('currentamount', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All piggy bank repetition amounts are positive.');
return;
}
/** @var PiggyBankRepetition $item */
foreach ($set as $item) {
$item->currentamount = app('steam')->positive($item->currentamount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d piggy bank repetition amount(s).', $count));
}
private function fixPiggyBanks(): void
{
$set = PiggyBank::where('targetamount', '<', 0)->get();
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All piggy bank amounts are positive.');
return;
}
/** @var PiggyBank $item */
foreach ($set as $item) {
$item->targetamount = app('steam')->positive($item->targetamount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d piggy bank amount(s).', $count));
}
private function fixRecurrences(): void
{
$set = RecurrenceTransaction::where('amount', '<', 0)
->orWhere('foreign_amount', '<', 0)
->get()
;
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('All recurring transaction amounts are positive.');
return;
}
/** @var RecurrenceTransaction $item */
foreach ($set as $item) {
$item->amount = app('steam')->positive($item->amount);
$item->foreign_amount = app('steam')->positive($item->foreign_amount);
$item->save();
}
$this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count));
}
private function fixRuleTriggers(): void
{
$set = RuleTrigger::whereIn('trigger_type', ['amount_less', 'amount_more', 'amount_is'])->get();
$fixed = 0;
/** @var RuleTrigger $item */
foreach ($set as $item) {
// basic check:
$check = 0;
try {
$check = bccomp((string)$item->trigger_value, '0');
} catch (\ValueError $e) {
$this->friendlyError(sprintf('Rule #%d contained invalid %s-trigger "%s". The trigger has been removed, and the rule is disabled.', $item->rule_id, $item->trigger_type, $item->trigger_value));
$item->rule->active = false;
$item->rule->save();
$item->forceDelete();
}
if (-1 === $check) {
++$fixed;
$item->trigger_value = app('steam')->positive($item->trigger_value);
$item->save();
}
}
if (0 === $fixed) {
$this->friendlyPositive('All rule trigger amounts are positive.');
return;
}
$this->friendlyInfo(sprintf('Corrected %d rule trigger amount(s).', $fixed));
}
}

View File

@@ -4,12 +4,9 @@ namespace FireflyIII\Console\Commands\Correction;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/**
* Class CorrectionSkeleton
* TODO DONT FORGET TO ADD THIS TO THE DOCKER BUILD
*/
class CorrectionSkeleton extends Command class CorrectionSkeleton extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'DESCRIPTION HERE'; protected $description = 'DESCRIPTION HERE';
protected $signature = 'firefly-iii:CORR_COMMAND'; protected $signature = 'firefly-iii:CORR_COMMAND';

View File

@@ -29,15 +29,12 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsAccountOrder extends Command
* Class FixAccountOrder
*/
class FixAccountOrder extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Make sure account order is correct.'; protected $description = 'Make sure account order is correct.';
protected $signature = 'firefly-iii:fix-account-order'; protected $signature = 'correction:account-order';
private AccountRepositoryInterface $repository; private AccountRepositoryInterface $repository;
@@ -54,8 +51,6 @@ class FixAccountOrder extends Command
$this->repository->resetAccountOrder(); $this->repository->resetAccountOrder();
} }
$this->friendlyPositive('All accounts are ordered correctly');
return 0; return 0;
} }

View File

@@ -36,15 +36,12 @@ use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Query\JoinClause;
/** class CorrectsAccountTypes extends Command
* Class FixAccountTypes
*/
class FixAccountTypes extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Make sure all journals have the correct from/to account types.'; protected $description = 'Make sure all journals have the correct from/to account types.';
protected $signature = 'firefly-iii:fix-account-types'; protected $signature = 'correction:account-types';
private int $count; private int $count;
private array $expected; private array $expected;
private AccountFactory $factory; private AccountFactory $factory;
@@ -120,9 +117,6 @@ class FixAccountTypes extends Command
} }
} }
} }
if (0 === $this->count) {
$this->friendlyPositive('All account types are OK');
}
if (0 !== $this->count) { if (0 !== $this->count) {
app('log')->debug(sprintf('%d journals had to be fixed.', $this->count)); app('log')->debug(sprintf('%d journals had to be fixed.', $this->count));
$this->friendlyInfo(sprintf('Acted on %d transaction(s)', $this->count)); $this->friendlyInfo(sprintf('Acted on %d transaction(s)', $this->count));

View File

@@ -0,0 +1,185 @@
<?php
/*
* CorrectAmounts.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RuleTrigger;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CorrectsAmounts extends Command
{
use ShowsFriendlyMessages;
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
protected $signature = 'correction:amounts';
public function handle(): int
{
// auto budgets must be positive
$this->fixAutoBudgets();
// available budgets must be positive
$this->fixAvailableBudgets();
// bills must be positive (both amounts)
$this->fixBills();
// budget limits must be positive
$this->fixBudgetLimits();
// currency_exchange_rates must be positive
$this->fixExchangeRates();
// piggy_banks must be positive
$this->fixPiggyBanks();
// recurrences_transactions amount must be positive
$this->fixRecurrences();
// rule_triggers must be positive or zero (amount_less, amount_more, amount_is)
$this->fixRuleTriggers();
return 0;
}
private function fixAutoBudgets(): void
{
$count = AutoBudget::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d auto budget amount(s).', $count));
}
private function fixAvailableBudgets(): void
{
$count = AvailableBudget::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d available budget amount(s).', $count));
}
private function fixBills(): void
{
$count = 0;
$count += Bill::where('amount_max', '<', 0)->update(['amount_max' => DB::raw('amount_max * -1')]);
$count += Bill::where('amount_min', '<', 0)->update(['amount_min' => DB::raw('amount_min * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d bill amount(s).', $count));
}
private function fixBudgetLimits(): void
{
$count = BudgetLimit::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d budget limit amount(s).', $count));
}
private function fixExchangeRates(): void
{
$count = CurrencyExchangeRate::where('rate', '<', 0)->update(['rate' => DB::raw('rate * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count));
}
private function fixPiggyBanks(): void
{
$count = PiggyBank::where('target_amount', '<', 0)->update(['target_amount' => DB::raw('target_amount * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d piggy bank amount(s).', $count));
}
private function fixRecurrences(): void
{
$count = 0;
$count += RecurrenceTransaction::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
$count += RecurrenceTransaction::where('foreign_amount', '<', 0)->update(['foreign_amount' => DB::raw('foreign_amount * -1')]);
if (0 === $count) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count));
}
/**
* Foreach loop is unavoidable here.
*/
private function fixRuleTriggers(): void
{
$set = RuleTrigger::whereIn('trigger_type', ['amount_less', 'amount_more', 'amount_is'])->get();
$fixed = 0;
/** @var RuleTrigger $item */
foreach ($set as $item) {
$result = $this->fixRuleTrigger($item);
if (true === $result) {
++$fixed;
}
}
if (0 === $fixed) {
return;
}
$this->friendlyInfo(sprintf('Corrected %d rule trigger amount(s).', $fixed));
}
private function fixRuleTrigger(RuleTrigger $item): bool
{
try {
$check = bccomp((string) $item->trigger_value, '0');
} catch (\ValueError $e) {
$this->friendlyError(sprintf('Rule #%d contained invalid %s-trigger "%s". The trigger has been removed, and the rule is disabled.', $item->rule_id, $item->trigger_type, $item->trigger_value));
$item->rule->active = false;
$item->rule->save();
$item->forceDelete();
return false;
}
if (-1 === $check) {
$item->trigger_value = app('steam')->positive($item->trigger_value);
$item->save();
return true;
}
return false;
}
}

View File

@@ -37,15 +37,12 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Symfony\Component\Console\Command\Command as CommandAlias; use Symfony\Component\Console\Command\Command as CommandAlias;
/** class CorrectsCurrencies extends Command
* Class EnableCurrencies
*/
class EnableCurrencies extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Enables all currencies in use.'; protected $description = 'Enables all currencies in use.';
protected $signature = 'firefly-iii:enable-currencies'; protected $signature = 'correction:currencies';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -27,14 +27,11 @@ namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsDatabase extends Command
* Class CorrectDatabase
*/
class CorrectDatabase extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Will correct the integrity of your database, if necessary.'; protected $description = 'Will validate and correct the integrity of your database, if necessary.';
protected $signature = 'firefly-iii:correct-database'; protected $signature = 'firefly-iii:correct-database';
/** /**
@@ -49,32 +46,36 @@ class CorrectDatabase extends Command
return 1; return 1;
} }
$commands = [ $commands = [
'firefly-iii:fix-piggies', 'correction:restore-oauth-keys',
'firefly-iii:create-link-types', 'correction:timezones',
'firefly-iii:create-access-tokens', 'correction:create-group-memberships',
'firefly-iii:remove-bills', 'correction:group-information',
'firefly-iii:fix-amount-pos-neg', 'correction:piggy-banks',
'firefly-iii:enable-currencies', 'correction:link-types',
'firefly-iii:fix-transfer-budgets', 'correction:access-tokens',
'firefly-iii:fix-uneven-amount', 'correction:bills',
'firefly-iii:delete-zero-amount', 'correction:amounts',
'firefly-iii:delete-orphaned-transactions', 'correction:currencies',
'firefly-iii:delete-empty-journals', 'correction:transfer-budgets',
'firefly-iii:delete-empty-groups', 'correction:uneven-amounts',
'firefly-iii:fix-account-types', 'correction:zero-amounts',
'firefly-iii:fix-ibans', 'correction:orphaned-transactions',
'firefly-iii:fix-account-order', 'correction:empty-journals',
'firefly-iii:rename-meta-fields', 'correction:empty-groups',
'firefly-iii:fix-ob-currencies', 'correction:account-types',
'firefly-iii:fix-long-descriptions', 'correction:ibans',
'firefly-iii:fix-recurring-transactions', 'correction:account-order',
'firefly-iii:upgrade-group-information', 'correction:meta-fields',
'firefly-iii:fix-transaction-types', 'correction:opening-balance-currencies',
'firefly-iii:fix-frontpage-accounts', 'correction:long-descriptions',
// new! 'correction:recurring-transactions',
'firefly-iii:unify-group-accounts', 'correction:frontpage-accounts',
'firefly-iii:trigger-credit-recalculation', 'correction:group-accounts',
'firefly-iii:migrate-preferences', 'correction:recalculates-liabilities',
'correction:preferences',
// 'correction:transaction-types', // resource heavy, disabled.
// 'correction:recalculate-native-amounts', // not necessary, disabled.
'firefly-iii:report-integrity',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {
$this->friendlyLine(sprintf('Now executing command "%s"', $command)); $this->friendlyLine(sprintf('Now executing command "%s"', $command));

View File

@@ -31,15 +31,12 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsFrontpageAccounts extends Command
* Class FixFrontpageAccounts
*/
class FixFrontpageAccounts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.'; protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.';
protected $signature = 'firefly-iii:fix-frontpage-accounts'; protected $signature = 'correction:frontpage-accounts';
/** /**
* Execute the console command. * Execute the console command.
@@ -55,7 +52,6 @@ class FixFrontpageAccounts extends Command
$this->fixPreference($preference); $this->fixPreference($preference);
} }
} }
$this->friendlyPositive('Account preferences are OK');
return 0; return 0;
} }

View File

@@ -31,15 +31,12 @@ use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsGroupAccounts extends Command
* Class FixGroupAccounts
*/
class FixGroupAccounts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Unify the source / destination accounts of split groups.'; protected $description = 'Unify the source / destination accounts of split groups.';
protected $signature = 'firefly-iii:unify-group-accounts'; protected $signature = 'correction:group-accounts';
/** /**
* Execute the console command. * Execute the console command.
@@ -64,8 +61,6 @@ class FixGroupAccounts extends Command
$handler->unifyAccounts($event); $handler->unifyAccounts($event);
} }
$this->friendlyPositive('Updated possible inconsistent transaction groups.');
return 0; return 0;
} }
} }

View File

@@ -1,8 +1,8 @@
<?php <?php
/* /*
* UpdateGroupInformation.php * CorrectsGroupInformation.php
* Copyright (c) 2022 james@firefly-iii.org * Copyright (c) 2024 james@firefly-iii.org.
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
* *
@@ -17,12 +17,12 @@
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -45,15 +45,12 @@ use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
/** class CorrectsGroupInformation extends Command
* Class UpdateGroupInformation
*/
class UpdateGroupInformation extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Makes sure that every object is linked to a group'; protected $description = 'Makes sure that every object is linked to a group';
protected $signature = 'firefly-iii:upgrade-group-information'; protected $signature = 'correction:group-information';
/** /**
* Execute the console command. * Execute the console command.
@@ -79,7 +76,7 @@ class UpdateGroupInformation extends Command
{ {
$group = $user->userGroup; $group = $user->userGroup;
if (null === $group) { if (null === $group) {
$this->friendlyWarning(sprintf('User "%s" has no group.', $user->email)); $this->friendlyWarning(sprintf('User "%s" has no group. Please run "php artisan firefly-iii:create-group-memberships"', $user->email));
return; return;
} }

View File

@@ -30,15 +30,12 @@ use FireflyIII\Models\AccountType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** class CorrectsIbans extends Command
* Class FixIbans
*/
class FixIbans extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Removes spaces from IBANs'; protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans'; protected $signature = 'correction:ibans';
private int $count = 0; private int $count = 0;
/** /**
@@ -49,9 +46,6 @@ class FixIbans extends Command
$accounts = Account::whereNotNull('iban')->get(); $accounts = Account::whereNotNull('iban')->get();
$this->filterIbans($accounts); $this->filterIbans($accounts);
$this->countAndCorrectIbans($accounts); $this->countAndCorrectIbans($accounts);
if (0 === $this->count) {
$this->friendlyPositive('All IBANs are valid.');
}
return 0; return 0;
} }

View File

@@ -28,24 +28,22 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/** class CorrectsLongDescriptions extends Command
* Class FixLongDescriptions
*/
class FixLongDescriptions extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
private const int MAX_LENGTH = 1000; private const int MAX_LENGTH = 1000;
protected $description = 'Fixes long descriptions in journals and groups.'; protected $description = 'Fixes long descriptions in journals and groups.';
protected $signature = 'firefly-iii:fix-long-descriptions'; protected $signature = 'correction:long-descriptions';
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle(): int public function handle(): int
{ {
$journals = TransactionJournal::get(['id', 'description']); $journals = TransactionJournal::where(DB::raw('LENGTH(description)'), '>', self::MAX_LENGTH)->get(['id', 'description']);
$count = 0; $count = 0;
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
@@ -58,7 +56,7 @@ class FixLongDescriptions extends Command
} }
} }
$groups = TransactionGroup::get(['id', 'title']); $groups = TransactionGroup::where(DB::raw('LENGTH(title)'), '>', self::MAX_LENGTH)->get(['id', 'title']);
/** @var TransactionGroup $group */ /** @var TransactionGroup $group */
foreach ($groups as $group) { foreach ($groups as $group) {
@@ -69,9 +67,6 @@ class FixLongDescriptions extends Command
++$count; ++$count;
} }
} }
if (0 === $count) {
$this->friendlyPositive('All transaction group and journal title lengths are within bounds.');
}
return 0; return 0;
} }

View File

@@ -26,16 +26,14 @@ namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/** class CorrectsMetaDataFields extends Command
* Class RenameMetaFields
*/
class RenameMetaFields extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Rename changed meta fields.'; protected $description = 'Rename changed meta fields.';
protected $signature = 'firefly-iii:rename-meta-fields'; protected $signature = 'correction:meta-fields';
private int $count = 0; private int $count = 0;
@@ -61,9 +59,6 @@ class RenameMetaFields extends Command
foreach ($changes as $original => $update) { foreach ($changes as $original => $update) {
$this->rename($original, $update); $this->rename($original, $update);
} }
if (0 === $this->count) {
$this->friendlyPositive('All meta fields are correct.');
}
if (0 !== $this->count) { if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Renamed %d meta field(s).', $this->count)); $this->friendlyInfo(sprintf('Renamed %d meta field(s).', $this->count));
} }
@@ -73,7 +68,7 @@ class RenameMetaFields extends Command
private function rename(string $original, string $update): void private function rename(string $original, string $update): void
{ {
$total = \DB::table('journal_meta') $total = DB::table('journal_meta')
->where('name', '=', $original) ->where('name', '=', $original)
->update(['name' => $update]) ->update(['name' => $update])
; ;

View File

@@ -0,0 +1,238 @@
<?php
declare(strict_types=1);
/*
* RecalculateNativeAmounts.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Handlers\Observer\TransactionObserver;
use FireflyIII\Models\Account;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\Repositories\UserGroup\UserGroupRepositoryInterface;
use FireflyIII\Repositories\UserGroups\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder as DatabaseBuilder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class CorrectsNativeAmounts extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Recalculate native amounts for all objects.';
protected $signature = 'correction:recalculate-native-amounts';
/**
* Execute the console command.
*/
public function handle(): int
{
Log::debug('Will update all native amounts. This may take some time.');
$this->friendlyWarning('Recalculating native amounts for all objects. This may take some time!');
/** @var UserGroupRepositoryInterface $repository */
$repository = app(UserGroupRepositoryInterface::class);
/** @var UserGroup $userGroup */
foreach ($repository->getAll() as $userGroup) {
$this->recalculateForGroup($userGroup);
}
$this->friendlyInfo('Recalculated all native amounts.');
return 0;
}
private function recalculateForGroup(UserGroup $userGroup): void
{
Log::debug(sprintf('Now recalculating for user group #%d', $userGroup->id));
$this->recalculateAccounts($userGroup);
// do a check with the group's currency so we can skip some stuff.
Preferences::mark();
$currency = app('amount')->getDefaultCurrencyByUserGroup($userGroup);
$this->recalculatePiggyBanks($userGroup, $currency);
$this->recalculateBudgets($userGroup, $currency);
$this->recalculateAvailableBudgets($userGroup, $currency);
$this->recalculateBills($userGroup, $currency);
$this->calculateTransactions($userGroup, $currency);
}
private function recalculateAccounts(UserGroup $userGroup): void
{
$set = $userGroup->accounts()->where(function (EloquentBuilder $q): void {
$q->whereNotNull('virtual_balance');
$q->orWhere('virtual_balance', '!=', '');
})->get();
/** @var Account $account */
foreach ($set as $account) {
$account->touch();
}
Log::debug(sprintf('Recalculated %d accounts for user group #%d.', $set->count(), $userGroup->id));
}
private function recalculatePiggyBanks(UserGroup $userGroup, TransactionCurrency $currency): void
{
$converter = new ExchangeRateConverter();
$converter->setUserGroup($userGroup);
$converter->setIgnoreSettings(true);
$repository = app(PiggyBankRepositoryInterface::class);
$repository->setUserGroup($userGroup);
$set = $repository->getPiggyBanks();
$set = $set->filter(
static function (PiggyBank $piggyBank) use ($currency) {
return $currency->id !== $piggyBank->transaction_currency_id;
}
);
foreach ($set as $piggyBank) {
$piggyBank->encrypted = false;
$piggyBank->save();
foreach ($piggyBank->accounts as $account) {
$account->pivot->native_current_amount = null;
if (0 !== bccomp($account->pivot->current_amount, '0')) {
$account->pivot->native_current_amount = $converter->convert($piggyBank->transactionCurrency, $currency, today(), $account->pivot->current_amount);
}
$account->pivot->save();
}
$this->recalculatePiggyBankEvents($piggyBank);
}
Log::debug(sprintf('Recalculated %d piggy banks for user group #%d.', $set->count(), $userGroup->id));
}
private function recalculatePiggyBankEvents(PiggyBank $piggyBank): void
{
$set = $piggyBank->piggyBankEvents()->get();
$set->each(
static function (PiggyBankEvent $event): void {
$event->touch();
}
);
Log::debug(sprintf('Recalculated %d piggy bank events.', $set->count()));
}
private function recalculateBudgets(UserGroup $userGroup, TransactionCurrency $currency): void
{
$set = $userGroup->budgets()->get();
/** @var Budget $budget */
foreach ($set as $budget) {
$this->recalculateBudgetLimits($budget, $currency);
$this->recalculateAutoBudgets($budget, $currency);
}
Log::debug(sprintf('Recalculated %d budgets.', $set->count()));
}
private function recalculateBudgetLimits(Budget $budget, TransactionCurrency $currency): void
{
$set = $budget->budgetlimits()->where('transaction_currency_id', '!=', $currency->id)->get();
/** @var BudgetLimit $limit */
foreach ($set as $limit) {
Log::debug(sprintf('Will now touch BL #%d', $limit->id));
$limit->touch();
Log::debug(sprintf('Done with touch BL #%d', $limit->id));
}
Log::debug(sprintf('Recalculated %d budget limits for budget #%d.', $set->count(), $budget->id));
}
private function recalculateAutoBudgets(Budget $budget, TransactionCurrency $currency): void
{
$set = $budget->autoBudgets()->where('transaction_currency_id', '!=', $currency->id)->get();
/** @var AutoBudget $autoBudget */
foreach ($set as $autoBudget) {
$autoBudget->touch();
}
Log::debug(sprintf('Recalculated %d auto budgets for budget #%d.', $set->count(), $budget->id));
}
private function recalculateAvailableBudgets(UserGroup $userGroup, TransactionCurrency $currency): void
{
Log::debug('Start with available budgets.');
$set = $userGroup->availableBudgets()->where('transaction_currency_id', '!=', $currency->id)->get();
/** @var AvailableBudget $budget */
foreach ($set as $budget) {
$budget->touch();
}
Log::debug(sprintf('Recalculated %d available budgets.', $set->count()));
}
private function recalculateBills(UserGroup $userGroup, TransactionCurrency $currency): void
{
$set = $userGroup->bills()->where('transaction_currency_id', '!=', $currency->id)->get();
/** @var Bill $bill */
foreach ($set as $bill) {
$bill->touch();
}
Log::debug(sprintf('Recalculated %d bills.', $set->count()));
}
private function calculateTransactions(UserGroup $userGroup, TransactionCurrency $currency): void
{
// custom query because of the potential size of this update.
$set = DB::table('transactions')
->join('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_group_id', $userGroup->id)
->where(function (DatabaseBuilder $q1) use ($currency): void {
$q1->where(function (DatabaseBuilder $q2) use ($currency): void {
$q2->whereNot('transactions.transaction_currency_id', $currency->id)->whereNull('transactions.foreign_currency_id');
})->orWhere(function (DatabaseBuilder $q3) use ($currency): void {
$q3->whereNot('transactions.transaction_currency_id', $currency->id)->whereNot('transactions.foreign_currency_id', $currency->id);
});
})
// ->where(static function (DatabaseBuilder $q) use ($currency): void {
// $q->whereNot('transactions.transaction_currency_id', $currency->id)
// ->whereNot('transactions.foreign_currency_id', $currency->id)
// ;
// })
->get(['transactions.id'])
;
TransactionObserver::$recalculate = false;
foreach ($set as $item) {
// here we are.
$transaction = Transaction::find($item->id);
$transaction->touch();
}
TransactionObserver::$recalculate = true;
Log::debug(sprintf('Recalculated %d transactions.', $set->count()));
}
}

View File

@@ -35,15 +35,12 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** class CorrectsOpeningBalanceCurrencies extends Command
* Class CorrectOpeningBalanceCurrencies
*/
class CorrectOpeningBalanceCurrencies extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.'; protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.';
protected $signature = 'firefly-iii:fix-ob-currencies'; protected $signature = 'correction:opening-balance-currencies';
/** /**
* Execute the console command. * Execute the console command.
@@ -62,10 +59,6 @@ class CorrectOpeningBalanceCurrencies extends Command
$message = sprintf('Corrected %d opening balance transaction(s).', $count); $message = sprintf('Corrected %d opening balance transaction(s).', $count);
$this->friendlyInfo($message); $this->friendlyInfo($message);
} }
if (0 === $count) {
$message = 'There was nothing to fix in the opening balance transactions.';
$this->friendlyPositive($message);
}
return 0; return 0;
} }

View File

@@ -29,17 +29,12 @@ use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsPiggyBanks extends Command
* Report (and fix) piggy banks.
*
* Class FixPiggies
*/
class FixPiggies extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Fixes common issues with piggy banks.'; protected $description = 'Fixes common issues with piggy banks.';
protected $signature = 'firefly-iii:fix-piggies'; protected $signature = 'correction:piggy-banks';
/** /**
* Execute the console command. * Execute the console command.
@@ -66,9 +61,6 @@ class FixPiggies extends Command
continue; continue;
} }
} }
if (0 === $count) {
$this->friendlyPositive('All piggy bank events are OK.');
}
if (0 !== $count) { if (0 !== $count) {
$this->friendlyInfo(sprintf('Fixed %d piggy bank event(s).', $count)); $this->friendlyInfo(sprintf('Fixed %d piggy bank event(s).', $count));
} }

View File

@@ -28,11 +28,11 @@ use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias; use Symfony\Component\Console\Command\Command as CommandAlias;
class MigratePreferences extends Command class CorrectsPreferences extends Command
{ {
protected $description = 'Give Firefly III preferences a user group ID so they can be made administration specific.'; protected $description = 'Give Firefly III preferences a user group ID so they can be made administration specific.';
protected $signature = 'firefly-iii:migrate-preferences'; protected $signature = 'correction:preferences';
/** /**
* Execute the console command. * Execute the console command.
@@ -50,7 +50,7 @@ class MigratePreferences extends Command
if (null === $preference) { if (null === $preference) {
continue; continue;
} }
if (null !== $preference->user_group_id) { if (null === $preference->user_group_id) {
$preference->user_group_id = $user->user_group_id; $preference->user_group_id = $user->user_group_id;
$preference->save(); $preference->save();
++$count; ++$count;

View File

@@ -33,15 +33,12 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsRecurringTransactions extends Command
* Class FixRecurringTransactions
*/
class FixRecurringTransactions extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Fixes recurring transactions with the wrong transaction type.'; protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions'; protected $signature = 'correction:recurring-transactions';
private int $count = 0; private int $count = 0;
private RecurringRepositoryInterface $recurringRepos; private RecurringRepositoryInterface $recurringRepos;
private UserRepositoryInterface $userRepos; private UserRepositoryInterface $userRepos;
@@ -53,9 +50,6 @@ class FixRecurringTransactions extends Command
{ {
$this->stupidLaravel(); $this->stupidLaravel();
$this->correctTransactions(); $this->correctTransactions();
if (0 === $this->count) {
$this->friendlyPositive('All recurring transactions are OK.');
}
return 0; return 0;
} }

View File

@@ -1,5 +1,25 @@
<?php <?php
/*
* CorrectsTimezoneInformation.php
* Copyright (c) 2024 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1); declare(strict_types=1);
/* /*
* AddTimezonesToDates.php * AddTimezonesToDates.php
@@ -21,7 +41,7 @@ declare(strict_types=1);
* along with this program. If not, see https://www.gnu.org/licenses/. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AccountBalance; use FireflyIII\Models\AccountBalance;
@@ -41,16 +61,25 @@ use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class AddTimezonesToDates extends Command class CorrectsTimezoneInformation extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
/** public static array $models
* The name and signature of the console command. = [
* AccountBalance::class => ['date'], // done
* @var string AvailableBudget::class => ['start_date', 'end_date'], // done
*/ Bill::class => ['date', 'end_date', 'extension_date'], // done
protected $signature = 'firefly-iii:add-timezones-to-dates'; BudgetLimit::class => ['start_date', 'end_date'], // done
CurrencyExchangeRate::class => ['date'], // done
InvitedUser::class => ['expires'],
PiggyBankEvent::class => ['date'],
PiggyBankRepetition::class => ['start_date', 'target_date'],
PiggyBank::class => ['start_date', 'target_date'], // done
Recurrence::class => ['first_date', 'repeat_until', 'latest_date'],
Tag::class => ['date'],
TransactionJournal::class => ['date'],
];
/** /**
* The console command description. * The console command description.
@@ -59,20 +88,12 @@ class AddTimezonesToDates extends Command
*/ */
protected $description = 'Make sure all dates have a timezone.'; protected $description = 'Make sure all dates have a timezone.';
public static array $models = [ /**
AccountBalance::class => ['date'], // done * The name and signature of the console command.
AvailableBudget::class => ['start_date', 'end_date'], // done *
Bill::class => ['date', 'end_date', 'extension_date'], // done * @var string
BudgetLimit::class => ['start_date', 'end_date'], // done */
CurrencyExchangeRate::class => ['date'], // done protected $signature = 'correction:timezones';
InvitedUser::class => ['expires'],
PiggyBankEvent::class => ['date'],
PiggyBankRepetition::class => ['startdate', 'targetdate'],
PiggyBank::class => ['startdate', 'targetdate'], // done
Recurrence::class => ['first_date', 'repeat_until', 'latest_date'],
Tag::class => ['date'],
TransactionJournal::class => ['date'],
];
/** /**
* Execute the console command. * Execute the console command.
@@ -106,8 +127,6 @@ class AddTimezonesToDates extends Command
Log::error($e->getMessage()); Log::error($e->getMessage());
} }
if (0 === $count) { if (0 === $count) {
$this->friendlyPositive(sprintf('Timezone information is present in field "%s" of model "%s".', $field, $shortModel));
return; return;
} }
$this->friendlyInfo(sprintf('Adding timezone information to field "%s" of model "%s".', $field, $shortModel)); $this->friendlyInfo(sprintf('Adding timezone information to field "%s" of model "%s".', $field, $shortModel));

View File

@@ -32,16 +32,14 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/** class CorrectsTransactionTypes extends Command
* Class FixTransactionTypes
*/
class FixTransactionTypes extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Make sure all transactions are of the correct type, based on source + dest.'; protected $description = 'Make sure all transactions are of the correct type, based on source + dest.';
protected $signature = 'firefly-iii:fix-transaction-types'; protected $signature = 'correction:transaction-types';
/** /**
* Execute the console command. * Execute the console command.
@@ -50,6 +48,7 @@ class FixTransactionTypes extends Command
{ {
$count = 0; $count = 0;
$journals = $this->collectJournals(); $journals = $this->collectJournals();
Log::debug(sprintf('In FixTransactionTypes, found %d journals.', $journals->count()));
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {

View File

@@ -29,15 +29,12 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CorrectsTransferBudgets extends Command
* Class TransferBudgets
*/
class TransferBudgets extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Removes budgets from transfers.'; protected $description = 'Removes budgets from transfers.';
protected $signature = 'firefly-iii:fix-transfer-budgets'; protected $signature = 'correction:transfer-budgets';
/** /**
* Execute the console command. * Execute the console command.
@@ -60,10 +57,6 @@ class TransferBudgets extends Command
$entry->budgets()->sync([]); $entry->budgets()->sync([]);
++$count; ++$count;
} }
if (0 === $count) {
$message = 'No invalid budget/journal entries.';
$this->friendlyPositive($message);
}
if (0 !== $count) { if (0 !== $count) {
$message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count); $message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count);
app('log')->debug($message); app('log')->debug($message);

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
@@ -32,15 +33,12 @@ use FireflyIII\Support\Models\AccountBalanceCalculator;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/** class CorrectsUnevenAmount extends Command
* Class FixUnevenAmount
*/
class FixUnevenAmount extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Fix journals with uneven amounts.'; protected $description = 'Fix journals with uneven amounts.';
protected $signature = 'firefly-iii:fix-uneven-amount'; protected $signature = 'correction:uneven-amounts';
private int $count; private int $count;
/** /**
@@ -54,13 +52,112 @@ class FixUnevenAmount extends Command
$this->matchCurrencies(); $this->matchCurrencies();
if (config('firefly.feature_flags.running_balance_column')) { if (config('firefly.feature_flags.running_balance_column')) {
$this->friendlyInfo('Will recalculate transaction running balance columns. This may take a LONG time. Please be patient.'); $this->friendlyInfo('Will recalculate transaction running balance columns. This may take a LONG time. Please be patient.');
AccountBalanceCalculator::recalculateAll(true); AccountBalanceCalculator::recalculateAll(false);
$this->friendlyInfo('Done recalculating transaction running balance columns.'); $this->friendlyInfo('Done recalculating transaction running balance columns.');
} }
return 0; return 0;
} }
private function convertOldStyleTransfers(): void
{
Log::debug('convertOldStyleTransfers()');
// select transactions with a foreign amount and a foreign currency. and it's a transfer. and they are different.
$transactions = Transaction::distinct()
->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
->where('transaction_types.type', TransactionTypeEnum::TRANSFER->value)
->whereNotNull('foreign_currency_id')
->whereNotNull('foreign_amount')->get(['transactions.transaction_journal_id'])
;
$count = 0;
Log::debug(sprintf('Found %d potential journal(s)', $transactions->count()));
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($transaction->transaction_journal_id);
if (null === $journal) {
Log::debug('Found no journal, continue.');
continue;
}
// needs to be a transfer.
if (TransactionType::TRANSFER !== $journal->transactionType->type) {
Log::debug('Must be a transfer, continue.');
continue;
}
/** @var null|Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
/** @var null|Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $destination || null === $source) {
Log::debug('Source or destination transaction is NULL, continue.');
// will be picked up later.
continue;
}
if ($source->transaction_currency_id === $destination->transaction_currency_id) {
Log::debug('Ready to swap data between transactions.');
$destination->foreign_currency_id = $source->transaction_currency_id;
$destination->foreign_amount = app('steam')->positive($source->amount);
$destination->transaction_currency_id = $source->foreign_currency_id;
$destination->amount = app('steam')->positive($source->foreign_amount);
$destination->balance_dirty = true;
$source->balance_dirty = true;
$destination->save();
$source->save();
$this->friendlyWarning(sprintf('Corrected foreign amounts of transfer #%d.', $journal->id));
++$count;
}
}
}
private function fixUnevenAmounts(): void
{
$journals = \DB::table('transactions')
->groupBy('transaction_journal_id')
->whereNull('deleted_at')
->get(['transaction_journal_id', \DB::raw('SUM(amount) AS the_sum')])
;
/** @var \stdClass $entry */
foreach ($journals as $entry) {
$sum = (string) $entry->the_sum;
if (!is_numeric($sum)
|| '' === $sum // @phpstan-ignore-line
|| str_contains($sum, 'e')
|| str_contains($sum, ',')) {
$message = sprintf(
'Journal #%d has an invalid sum ("%s"). No sure what to do.',
$entry->transaction_journal_id,
$entry->the_sum
);
$this->friendlyWarning($message);
app('log')->warning($message);
++$this->count;
continue;
}
$res = -1;
try {
$res = bccomp($sum, '0');
} catch (\ValueError $e) {
$this->friendlyError(sprintf('Could not bccomp("%s", "0").', $sum));
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
if (0 !== $res) {
$this->fixJournal($entry->transaction_journal_id);
}
}
}
private function fixJournal(int $param): void private function fixJournal(int $param): void
{ {
// one of the transactions is bad. // one of the transactions is bad.
@@ -129,78 +226,6 @@ class FixUnevenAmount extends Command
++$this->count; ++$this->count;
} }
private function fixUnevenAmounts(): void
{
$journals = \DB::table('transactions')
->groupBy('transaction_journal_id')
->whereNull('deleted_at')
->get(['transaction_journal_id', \DB::raw('SUM(amount) AS the_sum')])
;
/** @var \stdClass $entry */
foreach ($journals as $entry) {
$sum = (string) $entry->the_sum;
if (!is_numeric($sum)
|| '' === $sum // @phpstan-ignore-line
|| str_contains($sum, 'e')
|| str_contains($sum, ',')) {
$message = sprintf(
'Journal #%d has an invalid sum ("%s"). No sure what to do.',
$entry->transaction_journal_id,
$entry->the_sum
);
$this->friendlyWarning($message);
app('log')->warning($message);
++$this->count;
continue;
}
$res = -1;
try {
$res = bccomp($sum, '0');
} catch (\ValueError $e) {
$this->friendlyError(sprintf('Could not bccomp("%s", "0").', $sum));
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
if (0 !== $res) {
$this->fixJournal($entry->transaction_journal_id);
}
}
if (0 === $this->count) {
$this->friendlyPositive('Database amount integrity is OK');
}
}
private function matchCurrencies(): void
{
$journals = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', 'transactions.transaction_journal_id')
->where('transactions.transaction_currency_id', '!=', \DB::raw('transaction_journals.transaction_currency_id'))
->get(['transaction_journals.*'])
;
$count = 0;
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
if (!$this->isForeignCurrencyTransfer($journal)) {
Transaction::where('transaction_journal_id', $journal->id)->update(['transaction_currency_id' => $journal->transaction_currency_id]);
++$count;
continue;
}
Log::debug(sprintf('Can skip foreign currency transfer #%d.', $journal->id));
}
if (0 === $count) {
$this->friendlyPositive('Journal currency integrity is OK');
return;
}
$this->friendlyPositive(sprintf('Fixed %d journal(s) with mismatched currencies.', $journals->count()));
}
private function isForeignCurrencyTransfer(TransactionJournal $journal): bool private function isForeignCurrencyTransfer(TransactionJournal $journal): bool
{ {
if (TransactionType::TRANSFER !== $journal->transactionType->type) { if (TransactionType::TRANSFER !== $journal->transactionType->type) {
@@ -235,63 +260,29 @@ class FixUnevenAmount extends Command
return false; return false;
} }
private function convertOldStyleTransfers(): void private function matchCurrencies(): void
{ {
Log::debug('convertOldStyleTransfers()'); $journals = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', 'transactions.transaction_journal_id')
// select transactions with a foreign amount and a foreign currency. and it's a transfer. and they are different. ->where('transactions.transaction_currency_id', '!=', \DB::raw('transaction_journals.transaction_currency_id'))
$transactions = Transaction::distinct() ->get(['transaction_journals.*'])
->whereNotNull('foreign_currency_id')
->whereNotNull('foreign_amount')->get(['transactions.transaction_journal_id'])
; ;
$count = 0; $count = 0;
Log::debug(sprintf('Found %d potential journal(s)', $transactions->count())); /** @var TransactionJournal $journal */
foreach ($journals as $journal) {
/** @var Transaction $transaction */ if (!$this->isForeignCurrencyTransfer($journal)) {
foreach ($transactions as $transaction) { Transaction::where('transaction_journal_id', $journal->id)->update(['transaction_currency_id' => $journal->transaction_currency_id]);
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($transaction->transaction_journal_id);
if (null === $journal) {
Log::debug('Found no journal, continue.');
continue;
}
// needs to be a transfer.
if (TransactionType::TRANSFER !== $journal->transactionType->type) {
Log::debug('Must be a transfer, continue.');
continue;
}
/** @var null|Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
/** @var null|Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $destination || null === $source) {
Log::debug('Source or destination transaction is NULL, continue.');
// will be picked up later.
continue;
}
if ($source->transaction_currency_id === $destination->transaction_currency_id) {
Log::debug('Ready to swap data between transactions.');
$destination->foreign_currency_id = $source->transaction_currency_id;
$destination->foreign_amount = app('steam')->positive($source->amount);
$destination->transaction_currency_id = $source->foreign_currency_id;
$destination->amount = app('steam')->positive($source->foreign_amount);
$destination->balance_dirty = true;
$source->balance_dirty = true;
$destination->save();
$source->save();
$this->friendlyWarning(sprintf('Corrected foreign amounts of transfer #%d.', $journal->id));
++$count; ++$count;
continue;
} }
Log::debug(sprintf('Can skip foreign currency transfer #%d.', $journal->id));
} }
if (0 === $count) { if (0 === $count) {
$this->friendlyPositive('No "old style" foreign currency transfers.');
return; return;
} }
$this->friendlyPositive(sprintf('Fixed %d journal(s) with mismatched currencies.', $journals->count()));
} }
} }

View File

@@ -29,16 +29,13 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CreatesAccessTokens extends Command
* Class CreateAccessTokens
*/
class CreateAccessTokens extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Creates user access tokens which are used for command line access to personal data.'; protected $description = 'Creates user access tokens which are used for command line access to personal data.';
protected $signature = 'firefly-iii:create-access-tokens'; protected $signature = 'correction:access-tokens';
/** /**
* Execute the console command. * Execute the console command.
@@ -64,9 +61,6 @@ class CreateAccessTokens extends Command
++$count; ++$count;
} }
} }
if (0 === $count) {
$this->friendlyPositive('Verified access tokens.');
}
return 0; return 0;
} }

View File

@@ -1,8 +1,8 @@
<?php <?php
/* /*
* CreateGroupMemberships.php * CreatesGroupMemberships.php
* Copyright (c) 2023 james@firefly-iii.org * Copyright (c) 2024 james@firefly-iii.org.
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
* *
@@ -17,12 +17,12 @@
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\UserRoleEnum; use FireflyIII\Enums\UserRoleEnum;
@@ -33,16 +33,13 @@ use FireflyIII\Models\UserRole;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CreatesGroupMemberships extends Command
* Class CreateGroupMemberships
*/
class CreateGroupMemberships extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '560_create_group_memberships'; public const string CONFIG_NAME = '560_create_group_memberships';
protected $description = 'Update group memberships'; protected $description = 'Update group memberships';
protected $signature = 'firefly-iii:create-group-memberships'; protected $signature = 'correction:create-group-memberships';
/** /**
* Execute the console command. * Execute the console command.
@@ -52,7 +49,6 @@ class CreateGroupMemberships extends Command
public function handle(): int public function handle(): int
{ {
$this->createGroupMemberships(); $this->createGroupMemberships();
$this->friendlyPositive('Validated group memberships');
return 0; return 0;
} }

View File

@@ -28,16 +28,13 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\LinkType; use FireflyIII\Models\LinkType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class CreatesLinkTypes extends Command
* Class CreateLinkTypes. Created all link types in case a migration hasn't fired.
*/
class CreateLinkTypes extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Creates all link types.'; protected $description = 'Creates all link types.';
protected $signature = 'firefly-iii:create-link-types'; protected $signature = 'correction:link-types';
/** /**
* Execute the console command. * Execute the console command.
@@ -66,9 +63,6 @@ class CreateLinkTypes extends Command
$link->editable = false; $link->editable = false;
$link->save(); $link->save();
} }
if (0 === $count) {
$this->friendlyPositive('All link types are OK');
}
return 0; return 0;
} }

View File

@@ -29,15 +29,12 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RemovesBills extends Command
* Class RemoveBills
*/
class RemoveBills extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Remove bills from transactions that shouldn\'t have one.'; protected $description = 'Remove bills from transactions that shouldn\'t have one.';
protected $signature = 'firefly-iii:remove-bills'; protected $signature = 'correction:bills';
/** /**
* Execute the console command. * Execute the console command.
@@ -60,7 +57,6 @@ class RemoveBills extends Command
if ($journals->count() > 0) { if ($journals->count() > 0) {
$this->friendlyInfo('Fixed all transaction journals so they have correct bill information.'); $this->friendlyInfo('Fixed all transaction journals so they have correct bill information.');
} }
$this->friendlyPositive('All bills and journals are OK');
return 0; return 0;
} }

View File

@@ -29,15 +29,12 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RemovesEmptyGroups extends Command
* Class DeleteEmptyGroups
*/
class DeleteEmptyGroups extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Delete empty transaction groups.'; protected $description = 'Delete empty transaction groups.';
protected $signature = 'firefly-iii:delete-empty-groups'; protected $signature = 'correction:empty-groups';
/** /**
* Execute the console command. * Execute the console command.
@@ -61,9 +58,6 @@ class DeleteEmptyGroups extends Command
TransactionGroup::whereNull('deleted_at')->whereIn('id', $chunk)->delete(); TransactionGroup::whereNull('deleted_at')->whereIn('id', $chunk)->delete();
} }
} }
if (0 === $total) {
$this->friendlyInfo('Verified there are no empty groups.');
}
return 0; return 0;
} }

View File

@@ -30,16 +30,13 @@ use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
/** class RemovesEmptyJournals extends Command
* Class DeleteEmptyJournals
*/
class DeleteEmptyJournals extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Delete empty and uneven transaction journals.'; protected $description = 'Delete empty and uneven transaction journals.';
protected $signature = 'firefly-iii:delete-empty-journals'; protected $signature = 'correction:empty-journals';
/** /**
* Execute the console command. * Execute the console command.
@@ -82,9 +79,6 @@ class DeleteEmptyJournals extends Command
++$total; ++$total;
} }
} }
if (0 === $total) {
$this->friendlyPositive('No uneven transaction journals.');
}
} }
private function deleteEmptyJournals(): void private function deleteEmptyJournals(): void
@@ -107,8 +101,5 @@ class DeleteEmptyJournals extends Command
$this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id)); $this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id));
++$count; ++$count;
} }
if (0 === $count) {
$this->friendlyPositive('No empty transaction journals.');
}
} }
} }

View File

@@ -32,13 +32,13 @@ use Illuminate\Console\Command;
/** /**
* Deletes transactions where the journal has been deleted. * Deletes transactions where the journal has been deleted.
*/ */
class DeleteOrphanedTransactions extends Command class RemovesOrphanedTransactions extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Deletes orphaned transactions.'; protected $description = 'Deletes orphaned transactions.';
protected $signature = 'firefly-iii:delete-orphaned-transactions'; protected $signature = 'correction:orphaned-transactions';
/** /**
* Execute the console command. * Execute the console command.
@@ -63,7 +63,7 @@ class DeleteOrphanedTransactions extends Command
; ;
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->friendlyPositive('No orphaned journals.'); // $this->friendlyPositive('No orphaned journals.');
return; return;
} }
@@ -116,9 +116,6 @@ class DeleteOrphanedTransactions extends Command
++$count; ++$count;
} }
} }
if (0 === $count) {
$this->friendlyPositive('No orphaned transactions.');
}
} }
private function deleteFromOrphanedAccounts(): void private function deleteFromOrphanedAccounts(): void
@@ -147,8 +144,5 @@ class DeleteOrphanedTransactions extends Command
); );
++$count; ++$count;
} }
if (0 === $count) {
$this->friendlyPositive('No orphaned accounts.');
}
} }
} }

View File

@@ -29,16 +29,13 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RemovesZeroAmount extends Command
* Class DeleteZeroAmount
*/
class DeleteZeroAmount extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Delete transactions with zero amount.'; protected $description = 'Delete transactions with zero amount.';
protected $signature = 'firefly-iii:delete-zero-amount'; protected $signature = 'correction:zero-amounts';
/** /**
* Execute the console command. * Execute the console command.
@@ -56,9 +53,6 @@ class DeleteZeroAmount extends Command
Transaction::where('transaction_journal_id', $journal->id)->delete(); Transaction::where('transaction_journal_id', $journal->id)->delete();
} }
if (0 === $journals->count()) {
$this->friendlyPositive('No zero-amount transaction journals.');
}
return 0; return 0;
} }

View File

@@ -1,8 +1,8 @@
<?php <?php
/** /*
* RestoreOAuthKeys.php * RestoresOAuthKeys.php
* Copyright (c) 2020 james@firefly-iii.org * Copyright (c) 2024 james@firefly-iii.org.
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
* *
@@ -17,26 +17,23 @@
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Support\System\OAuthKeys; use FireflyIII\Support\System\OAuthKeys;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RestoresOAuthKeys extends Command
* Class RestoreOAuthKeys
*/
class RestoreOAuthKeys extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Will restore the OAuth keys generated for the system.'; protected $description = 'Will restore the OAuth keys generated for the system.';
protected $signature = 'firefly-iii:restore-oauth-keys'; protected $signature = 'correction:restore-oauth-keys';
/** /**
* Execute the console command. * Execute the console command.
@@ -76,7 +73,6 @@ class RestoreOAuthKeys extends Command
return; return;
} }
$this->friendlyPositive('OAuth keys are OK');
} }
private function keysInDatabase(): bool private function keysInDatabase(): bool

View File

@@ -28,13 +28,10 @@ use FireflyIII\Models\Account;
use FireflyIII\Services\Internal\Support\CreditRecalculateService; use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class TriggersCreditCalculation extends Command
* Class CorrectionSkeleton
*/
class TriggerCreditCalculation extends Command
{ {
protected $description = 'Triggers the credit recalculation service for liabilities.'; protected $description = 'Triggers the credit recalculation service for liabilities.';
protected $signature = 'firefly-iii:trigger-credit-recalculation'; protected $signature = 'correction:recalculates-liabilities';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -36,10 +36,7 @@ use FireflyIII\Support\Export\ExportDataGenerator;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** class ExportsData extends Command
* Class ExportData
*/
class ExportData extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
use VerifiesAccessToken; use VerifiesAccessToken;

View File

@@ -4,10 +4,6 @@ namespace FireflyIII\Console\Commands\Integrity;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/**
* Class ReportSkeleton
* TODO DONT FORGET TO ADD THIS TO THE DOCKER BUILD
*/
class ReportSkeleton extends Command class ReportSkeleton extends Command
{ {

View File

@@ -31,16 +31,13 @@ use FireflyIII\Models\Category;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class ReportsEmptyObjects extends Command
* Class ReportEmptyObjects
*/
class ReportEmptyObjects extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Reports on empty database objects.'; protected $description = 'Reports on empty database objects.';
protected $signature = 'firefly-iii:report-empty-objects'; protected $signature = 'integrity:empty-objects';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -27,10 +27,7 @@ namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class ReportsIntegrity extends Command
* Class ReportIntegrity
*/
class ReportIntegrity extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -48,11 +45,9 @@ class ReportIntegrity extends Command
return 1; return 1;
} }
$commands = [ $commands = [
'firefly-iii:add-timezones-to-dates', // 'firefly-iii:add-timezones-to-dates',
'firefly-iii:create-group-memberships', 'integrity:empty-objects',
'firefly-iii:report-empty-objects', 'integrity:total-sums',
'firefly-iii:report-sum',
'firefly-iii:upgrade-group-information',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {
$this->friendlyLine(sprintf('Now executing %s', $command)); $this->friendlyLine(sprintf('Now executing %s', $command));

View File

@@ -29,15 +29,12 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class ReportsSums extends Command
* Class ReportSkeleton
*/
class ReportSum extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Report on the total sum of transactions. Must be 0.'; protected $description = 'Report on the total sum of transactions. Must be 0.';
protected $signature = 'firefly-iii:report-sum'; protected $signature = 'integrity:total-sums';
/** /**
* Execute the console command. * Execute the console command.
@@ -59,18 +56,22 @@ class ReportSum extends Command
/** @var User $user */ /** @var User $user */
foreach ($userRepository->all() as $user) { foreach ($userRepository->all() as $user) {
$sum = (string)$user->transactions()->selectRaw('SUM(amount) + SUM(foreign_amount) as total')->value('total'); $sum = (string) $user->transactions()->selectRaw('SUM(amount) as total')->value('total');
if (!is_numeric($sum)) { $foreign = (string) $user->transactions()->selectRaw('SUM(foreign_amount) as total')->value('total');
$message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $sum); $sum = '' === $sum ? '0' : $sum;
$foreign = '' === $foreign ? '0' : $foreign;
$total = bcadd($sum, $foreign);
if (!is_numeric($total)) {
$message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $total);
$this->friendlyError($message); $this->friendlyError($message);
continue; continue;
} }
if (0 !== bccomp($sum, '0')) { if (0 !== bccomp($total, '0')) {
$message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $total);
$this->friendlyError($message); $this->friendlyError($message);
} }
if (0 === bccomp($sum, '0')) { if (0 === bccomp($total, '0')) {
$this->friendlyPositive(sprintf('Amount integrity OK for user #%d', $user->id)); $this->friendlyPositive(sprintf('Amount integrity OK for user #%d', $user->id));
} }
} }

View File

@@ -28,7 +28,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Command\Command as CommandAlias; use Symfony\Component\Console\Command\Command as CommandAlias;
class LaravelPassportKeys extends Command class CallsLaravelPassportKeys extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -28,10 +28,7 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use PDO; use PDO;
/** class CreatesDatabase extends Command
* Class CreateDatabase
*/
class CreateDatabase extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -29,16 +29,13 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
/** class CreatesFirstUser extends Command
* Class CreateFirstUser
*/
class CreateFirstUser extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Creates a new user and gives admin rights. Outputs the password on the command line. Strictly for testing.'; protected $description = 'Creates a new user and gives admin rights. Outputs the password on the command line. Strictly for testing.';
protected $signature = 'firefly-iii:create-first-user {email}'; protected $signature = 'system:create-first-user {email}';
private UserRepositoryInterface $repository; private UserRepositoryInterface $repository;
/** /**

View File

@@ -44,13 +44,11 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
/** /**
* Class ForceDecimalSize
*
* This command was inspired by https://github.com/elliot-gh. It will check all amount fields * This command was inspired by https://github.com/elliot-gh. It will check all amount fields
* and their values and correct them to the correct number of decimal places. This fixes issues where * and their values and correct them to the correct number of decimal places. This fixes issues where
* Firefly III would store 0.01 as 0.01000000000000000020816681711721685132943093776702880859375. * Firefly III would store 0.01 as 0.01000000000000000020816681711721685132943093776702880859375.
*/ */
class ForceDecimalSize extends Command class ForcesDecimalSize extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -83,8 +81,8 @@ class ForceDecimalSize extends Command
'currency_exchange_rates' => ['rate', 'user_rate'], 'currency_exchange_rates' => ['rate', 'user_rate'],
'limit_repetitions' => ['amount'], 'limit_repetitions' => ['amount'],
'piggy_bank_events' => ['amount'], 'piggy_bank_events' => ['amount'],
'piggy_bank_repetitions' => ['currentamount'], 'piggy_bank_repetitions' => ['current_amount'],
'piggy_banks' => ['targetamount'], 'piggy_banks' => ['target_amount'],
'recurrences_transactions' => ['amount', 'foreign_amount'], 'recurrences_transactions' => ['amount', 'foreign_amount'],
'transactions' => ['amount', 'foreign_amount'], 'transactions' => ['amount', 'foreign_amount'],
]; ];

View File

@@ -33,10 +33,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
/** class ForcesMigrations extends Command
* Class ForceMigration
*/
class ForceMigration extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
use VerifiesAccessToken; use VerifiesAccessToken;

View File

@@ -27,16 +27,13 @@ namespace FireflyIII\Console\Commands\System;
use FireflyIII\Support\System\GeneratesInstallationId; use FireflyIII\Support\System\GeneratesInstallationId;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class OutputsInstructions extends Command
* Class UpgradeFireflyInstructions.
*/
class UpgradeFireflyInstructions extends Command
{ {
use GeneratesInstallationId; use GeneratesInstallationId;
protected $description = 'Instructions in case of upgrade trouble.'; protected $description = 'Instructions in case of upgrade trouble.';
protected $signature = 'firefly:instructions {task}'; protected $signature = 'firefly-iii:instructions {task=install}';
/** /**
* Execute the console command. * Execute the console command.
@@ -79,7 +76,7 @@ class UpgradeFireflyInstructions extends Command
} }
$prefix = 'v'; $prefix = 'v';
if (str_starts_with($version, 'develop')) { if (str_starts_with($version, 'develop') || str_starts_with($version, 'branch')) {
$prefix = ''; $prefix = '';
} }
@@ -94,6 +91,8 @@ class UpgradeFireflyInstructions extends Command
$this->boxedInfo('There are no extra upgrade instructions.'); $this->boxedInfo('There are no extra upgrade instructions.');
$this->boxed('Firefly III should be ready for use.'); $this->boxed('Firefly III should be ready for use.');
$this->boxed(''); $this->boxed('');
$this->donationText();
$this->boxed('');
$this->showLine(); $this->showLine();
return; return;
@@ -102,6 +101,8 @@ class UpgradeFireflyInstructions extends Command
$this->boxed(sprintf('Thank you for updating to Firefly III, %s%s!', $prefix, $version)); $this->boxed(sprintf('Thank you for updating to Firefly III, %s%s!', $prefix, $version));
$this->boxedInfo($text); $this->boxedInfo($text);
$this->boxed(''); $this->boxed('');
$this->donationText();
$this->boxed('');
$this->showLine(); $this->showLine();
} }
@@ -213,6 +214,8 @@ class UpgradeFireflyInstructions extends Command
$this->boxedInfo('There are no extra installation instructions.'); $this->boxedInfo('There are no extra installation instructions.');
$this->boxed('Firefly III should be ready for use.'); $this->boxed('Firefly III should be ready for use.');
$this->boxed(''); $this->boxed('');
$this->donationText();
$this->boxed('');
$this->showLine(); $this->showLine();
return; return;
@@ -221,6 +224,15 @@ class UpgradeFireflyInstructions extends Command
$this->boxed(sprintf('Thank you for installing Firefly III, %s%s!', $prefix, $version)); $this->boxed(sprintf('Thank you for installing Firefly III, %s%s!', $prefix, $version));
$this->boxedInfo($text); $this->boxedInfo($text);
$this->boxed(''); $this->boxed('');
$this->donationText();
$this->boxed('');
$this->showLine(); $this->showLine();
} }
private function donationText(): void
{
$this->boxed('Did you know you can support the development of Firefly III?');
$this->boxed('You can donate in many ways, like GitHub Sponsors or Patreon.');
$this->boxed('For more information, please visit https://bit.ly/donate-to-Firefly-III');
}
} }

View File

@@ -26,10 +26,7 @@ namespace FireflyIII\Console\Commands\System;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class OutputsVersion extends Command
* Class OutputVersion
*/
class OutputVersion extends Command
{ {
protected $description = 'Outputs the Firefly III version'; protected $description = 'Outputs the Firefly III version';

View File

@@ -29,10 +29,7 @@ use FireflyIII\Models\Attachment;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
/** class ScansAttachments extends Command
* Class ScanAttachments.
*/
class ScanAttachments extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -27,10 +27,7 @@ namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class SetsLatestVersion extends Command
* Class SetLatestVersion
*/
class SetLatestVersion extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -29,9 +29,6 @@ use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use League\Flysystem\FilesystemException; use League\Flysystem\FilesystemException;
/**
* Class VerifySecurityAlerts
*/
class VerifySecurityAlerts extends Command class VerifySecurityAlerts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -40,9 +40,6 @@ use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/**
* Class ApplyRules
*/
class ApplyRules extends Command class ApplyRules extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -128,7 +125,7 @@ class ApplyRules extends Command
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]); $ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]);
// add the date as a filter: // add the date as a filter:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $this->startDate->format('Y-m-d')]); $ruleEngine->addOperator(['type' => 'date_after', 'value' => $this->start_date->format('Y-m-d')]);
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $this->endDate->format('Y-m-d')]); $ruleEngine->addOperator(['type' => 'date_before', 'value' => $this->endDate->format('Y-m-d')]);
// start running rules. // start running rules.
@@ -296,7 +293,7 @@ class ApplyRules extends Command
[$inputEnd, $inputStart] = [$inputStart, $inputEnd]; [$inputEnd, $inputStart] = [$inputStart, $inputEnd];
} }
$this->startDate = $inputStart; $this->start_date = $inputStart;
$this->endDate = $inputEnd; $this->endDate = $inputEnd;
} }

View File

@@ -34,9 +34,6 @@ use FireflyIII\Support\Cronjobs\RecurringCronjob;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/**
* Class Cron
*/
class Cron extends Command class Cron extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;

View File

@@ -32,16 +32,13 @@ use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
/** class AddsTransactionIdentifiers extends Command
* Class TransactionIdentifier
*/
class TransactionIdentifier extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_transaction_identifier'; public const string CONFIG_NAME = '480_transaction_identifier';
protected $description = 'Fixes transaction identifiers.'; protected $description = 'Fixes transaction identifiers.';
protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:480-transaction-identifiers {--F|force : Force the execution of this command.}';
private JournalCLIRepositoryInterface $cliRepository; private JournalCLIRepositoryInterface $cliRepository;
private int $count; private int $count;

View File

@@ -30,15 +30,12 @@ use FireflyIII\Models\Preference;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
/** class RemovesDatabaseDecryption extends Command
* Class DecryptDatabase
*/
class DecryptDatabase extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Decrypts the database.'; protected $description = 'Decrypts the database.';
protected $signature = 'firefly-iii:decrypt-all'; protected $signature = 'upgrade:480-decrypt-all';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -28,16 +28,13 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Support\Models\AccountBalanceCalculator; use FireflyIII\Support\Models\AccountBalanceCalculator;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RepairsAccountBalances extends Command
* Class CorrectionSkeleton
*/
class CorrectAccountBalance extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '610_correct_balances'; public const string CONFIG_NAME = '610_correct_balances';
protected $description = 'Recalculate all account balance amounts'; protected $description = 'Recalculate all account balance amounts';
protected $signature = 'firefly-iii:correct-account-balance {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:610-account-balances {--F|force : Force the execution of this command.}';
public function handle(): int public function handle(): int
{ {
@@ -59,12 +56,6 @@ class CorrectAccountBalance extends Command
return 0; return 0;
} }
private function correctBalanceAmounts(): void
{
return;
AccountBalanceCalculator::recalculateAll(true);
}
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
@@ -76,4 +67,10 @@ class CorrectAccountBalance extends Command
{ {
app('fireflyconfig')->set(self::CONFIG_NAME, true); app('fireflyconfig')->set(self::CONFIG_NAME, true);
} }
private function correctBalanceAmounts(): void
{
return;
AccountBalanceCalculator::recalculateAll(true);
}
} }

View File

@@ -27,16 +27,13 @@ namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class RepairsPostgresSequences extends Command
* Class FixPostgresSequences
*/
class FixPostgresSequences extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Fixes issues with PostgreSQL sequences.'; protected $description = 'Fixes issues with PostgreSQL sequences.';
protected $signature = 'firefly-iii:fix-pgsql-sequences'; protected $signature = 'upgrade:600-pgsql-sequences';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -4,10 +4,6 @@ namespace FireflyIII\Console\Commands\Upgrade;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/**
* Class UpgradeSkeleton.
* TODO DONT FORGET TO ADD THIS TO THE DOCKER BUILD
*/
class UpgradeSkeleton extends Command class UpgradeSkeleton extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -15,7 +11,7 @@ class UpgradeSkeleton extends Command
protected $description = 'SOME DESCRIPTION'; protected $description = 'SOME DESCRIPTION';
protected $signature = 'firefly-iii:UPGRSKELETON {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:UPGRSKELETON {--F|force : Force the execution of this command.}';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -36,17 +36,14 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class UpgradesAccountCurrencies extends Command
* Class AccountCurrencies
*/
class AccountCurrencies extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '480_account_currencies'; public const string CONFIG_NAME = '480_account_currencies';
protected $description = 'Give all accounts proper currency info.'; protected $description = 'Give all accounts proper currency info.';
protected $signature = 'firefly-iii:account-currencies {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:480-account-currencies {--F|force : Force the execution of this command.}';
private AccountRepositoryInterface $accountRepos; private AccountRepositoryInterface $accountRepos;
private int $count; private int $count;
private UserRepositoryInterface $userRepos; private UserRepositoryInterface $userRepos;

View File

@@ -29,10 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class UpgradesAccountMetaData extends Command
* Class RenameAccountMeta
*/
class RenameAccountMeta extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -40,7 +37,7 @@ class RenameAccountMeta extends Command
protected $description = 'Rename account meta-data to new format.'; protected $description = 'Rename account meta-data to new format.';
protected $signature = 'firefly-iii:rename-account-meta {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:480-account-meta {--F|force : Force the execution of this command.}';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -30,10 +30,7 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class UpgradesAttachments extends Command
* Class MigrateAttachments
*/
class MigrateAttachments extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -41,7 +38,7 @@ class MigrateAttachments extends Command
protected $description = 'Migrates attachment meta-data.'; protected $description = 'Migrates attachment meta-data.';
protected $signature = 'firefly-iii:migrate-attachments {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:480-attachments {--F|force : Force the execution of this command.}';
/** /**
* Execute the console command. * Execute the console command.

View File

@@ -36,10 +36,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class UpgradesBillsToRules extends Command
* Class MigrateToRules
*/
class MigrateToRules extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -47,7 +44,7 @@ class MigrateToRules extends Command
protected $description = 'Migrate bills to rules.'; protected $description = 'Migrate bills to rules.';
protected $signature = 'firefly-iii:bills-to-rules {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:480-bills-to-rules {--F|force : Force the execution of this command.}';
private BillRepositoryInterface $billRepository; private BillRepositoryInterface $billRepository;
private int $count; private int $count;
private RuleGroupRepositoryInterface $ruleGroupRepository; private RuleGroupRepositoryInterface $ruleGroupRepository;

View File

@@ -28,10 +28,7 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** class UpgradesBudgetLimitPeriods extends Command
* Class AppendBudgetLimitPeriods
*/
class AppendBudgetLimitPeriods extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -39,7 +36,7 @@ class AppendBudgetLimitPeriods extends Command
protected $description = 'Append budget limits with their (estimated) timeframe.'; protected $description = 'Append budget limits with their (estimated) timeframe.';
protected $signature = 'firefly-iii:budget-limit-periods {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:550-budget-limit-periods {--F|force : Force the execution of this command.}';
/** /**
* Execute the console command. * Execute the console command.

Some files were not shown because too many files have changed in this diff Show More