Compare commits

...

386 Commits

Author SHA1 Message Date
James Cole
ad44f99dbf Merge branch 'release/4.8.0.2' 2019-08-17 12:38:04 +02:00
James Cole
12a64fefc8 Fix test. 2019-08-17 12:31:55 +02:00
James Cole
2ee8cbbae4 Update change logs and files for new version. 2019-08-17 12:27:15 +02:00
James Cole
34c19b145c Updated strings. 2019-08-17 12:24:16 +02:00
James Cole
c5e047ea02 Update copyright 2019-08-17 12:13:02 +02:00
James Cole
fc78c32fca Add newline to files 2019-08-17 12:09:03 +02:00
James Cole
b53cbbe469 Fix test coverage. 2019-08-17 12:08:09 +02:00
James Cole
1d4434698e Fix some tests. 2019-08-17 11:32:05 +02:00
James Cole
6d1bfd3956 Code cleanup 2019-08-17 10:54:16 +02:00
James Cole
1974d5f1e3 Code cleanup 2019-08-17 10:48:28 +02:00
James Cole
c235e42d6c Bill report URL must be set. 2019-08-17 10:48:09 +02:00
James Cole
342985d52a Code cleanup 2019-08-17 10:47:51 +02:00
James Cole
c2296c3ad5 Code cleanup 2019-08-17 10:47:29 +02:00
James Cole
23479790fe Code cleanup 2019-08-17 10:47:10 +02:00
James Cole
44823c6fec Code cleanup 2019-08-17 10:46:55 +02:00
James Cole
acfdf7dc90 Code cleanup 2019-08-17 10:46:40 +02:00
James Cole
6038a68ba9 Code cleanup 2019-08-17 10:46:32 +02:00
James Cole
79cf61b653 Fix #2434 2019-08-17 08:29:35 +02:00
James Cole
b97d3d3627 And fix sorting. 2019-08-17 08:04:41 +02:00
James Cole
7f887e294a Fix some charts. 2019-08-17 08:00:27 +02:00
James Cole
6f78735bc5 Fix some report issues. 2019-08-17 07:47:39 +02:00
James Cole
3e242aaca6 Clean up login controller. 2019-08-17 06:35:45 +02:00
James Cole
0796e422d4 Cleanup showLoginForm() 2019-08-17 06:24:49 +02:00
James Cole
fbd7c9ae07 Remove logout method (is the same) 2019-08-17 06:23:12 +02:00
James Cole
5cfb1b63dc Remove inspection warnings. 2019-08-17 06:22:42 +02:00
James Cole
f09d0e87e4 Remove inspection, add TODO's, make code a bit simpler. 2019-08-16 21:38:35 +02:00
James Cole
820358af73 Remove unused code. 2019-08-16 21:23:20 +02:00
James Cole
5a2998c80e Simplify bill overview. 2019-08-16 21:21:38 +02:00
James Cole
a32df0066e Fix form inconsistencies. 2019-08-16 19:08:20 +02:00
James Cole
02db333d46 Update for balance box in report. 2019-08-16 17:54:38 +02:00
James Cole
070f46c755 Budget box is multi-currency. 2019-08-16 08:27:08 +02:00
James Cole
b4a732bf77 Namespace errors, spotted by @davids3 #2392 2019-08-16 07:24:04 +02:00
James Cole
d8eb59736e Improve report boxes one by one #2428 2019-08-16 06:21:10 +02:00
James Cole
41c15b0cf8 Forgot auth in API 2019-08-16 06:20:16 +02:00
James Cole
fdf99400bc Some TODO's for the future. 2019-08-16 06:20:07 +02:00
James Cole
1ba45afeab Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2019-08-16 05:22:24 +02:00
James Cole
1819ece55d Merge pull request #2429 from GeoffreyFrogeye/emd_date
Fix typo in BudgetRepository (emd_date)
2019-08-16 05:15:50 +02:00
James Cole
78335210db Cleanup API middleware. 2019-08-16 05:08:56 +02:00
Geoffrey “Frogeye” Preud'homme
ca23bb6272 Fix typo in BudgetRepository (emd_date) 2019-08-15 23:23:06 +02:00
James Cole
eed84e18bb Fix #2423 2019-08-14 20:25:38 +02:00
James Cole
12641f96b1 Fix #2422 2019-08-14 20:23:11 +02:00
James Cole
1b97c4d58f Fix date for recurring transactions #2407 2019-08-14 20:06:16 +02:00
James Cole
ee3a2ef41c Fix report issues. 2019-08-14 19:51:46 +02:00
James Cole
084ceb0c4e Report fixes for #2418 2019-08-14 19:06:05 +02:00
James Cole
2497c4ee5c Fix #2426 2019-08-14 17:54:15 +02:00
James Cole
757a118f87 Change comment [skip ci] 2019-08-14 06:16:44 +02:00
James Cole
97908932e6 Fix #2393 2019-08-13 19:01:30 +02:00
James Cole
4c73ad8306 Fix #2402 2019-08-13 18:50:18 +02:00
James Cole
10a2078661 Fix #2404 2019-08-13 18:45:44 +02:00
James Cole
3fb09136cf Fix #2410 2019-08-13 18:38:15 +02:00
James Cole
843cced454 Fix #2405 2019-08-13 16:45:04 +02:00
James Cole
71a501868f Fix docker build back to original script. 2019-08-13 16:26:27 +02:00
James Cole
0a0ad8200a Fix #2414 2019-08-13 16:24:36 +02:00
James Cole
a9baf54b12 Fix #2416 2019-08-13 16:02:28 +02:00
James Cole
ed565136fc Fix #2415 2019-08-13 16:00:35 +02:00
James Cole
4719b87314 Try the ARM thing with my own version of the script. 2019-08-12 19:53:54 +02:00
James Cole
24b30af018 Install extension. 2019-08-12 19:31:42 +02:00
James Cole
e9f4695355 Fix ARM script. 2019-08-12 18:44:57 +02:00
James Cole
5b969fa014 Fix LDAP in ARM 2019-08-12 18:34:32 +02:00
James Cole
499e713683 Remove unused methods. 2019-08-12 18:24:33 +02:00
James Cole
5eadb51b78 Some refactoring. 2019-08-12 18:19:13 +02:00
James Cole
713a962005 Log errors instead of giving exceptions 2019-08-12 18:19:06 +02:00
James Cole
d96e77a3ec Use new methods from category repository 2019-08-12 18:18:51 +02:00
James Cole
bc68c367c8 Refactor earnedInperiod and spentInPeriod 2019-08-12 18:18:26 +02:00
James Cole
33e241d39a Remove initial balance accounts from auto-complete. 2019-08-12 18:17:43 +02:00
James Cole
e67812bf64 Method is no longer used. 2019-08-12 18:17:15 +02:00
James Cole
1090ce6597 Remove sum, make multi-currency 2019-08-12 18:16:28 +02:00
James Cole
e358f19548 Make method static 2019-08-12 18:16:12 +02:00
James Cole
eac406d62d Merge tag '4.8.0.1' into develop
4.8.0.1
2019-08-12 18:12:03 +02:00
James Cole
142a488ab3 Merge branch 'release/4.8.0.1' 2019-08-12 18:12:02 +02:00
James Cole
893c83e086 Fix tests. 2019-08-12 17:36:37 +02:00
James Cole
76dad84ba6 Updated translations. 2019-08-12 17:12:11 +02:00
James Cole
6e78d4efa7 Update version. 2019-08-12 17:11:05 +02:00
James Cole
66ffbf9e47 Rename version so Ctrl-F doesn't pick them up 2019-08-12 17:10:58 +02:00
James Cole
c499899988 Update version and changelog. 2019-08-12 17:10:33 +02:00
James Cole
77ea246fc3 New files for future release. 2019-08-12 16:59:23 +02:00
James Cole
80f9896f2a Remove unused lines. 2019-08-12 16:58:45 +02:00
James Cole
90c60e55f7 Fix #2401 2019-08-12 16:54:48 +02:00
James Cole
b085ee3437 Fix #2395 2019-08-11 19:14:13 +02:00
James Cole
3b3f24fe56 Fix #2399 2019-08-11 18:58:30 +02:00
James Cole
1d2c834b2c Code for #2397 2019-08-11 17:32:00 +02:00
James Cole
cc243f9fb7 Remove unused methods. 2019-08-11 07:29:13 +02:00
James Cole
788bde5562 Fix some tag related issues. 2019-08-11 07:29:05 +02:00
James Cole
f67a9547cc Box is now positive. 2019-08-11 07:26:06 +02:00
James Cole
8545d73119 Fix tests 2019-08-11 07:25:59 +02:00
James Cole
c4964cf603 Merge pull request #2382 from mfix22/patch-1
Fix ranger.yml config
2019-08-11 07:25:30 +02:00
James Cole
903b4e520c New Docker files. 2019-08-10 17:21:58 +02:00
James Cole
c0033ae56b Code cleanup in AccountForm. 2019-08-10 17:11:57 +02:00
James Cole
3daddd690f Fix all views. 2019-08-10 16:50:37 +02:00
James Cole
0d9bae6ec2 Fix the references for AccountForm. 2019-08-10 16:36:15 +02:00
James Cole
6e2978231b Refactor the expandedform methods. First commit to see how Scrutinizer likes this. This commit will break most views. 2019-08-10 15:09:44 +02:00
James Cole
0097c66522 Refactor journal repositories. 2019-08-10 14:41:08 +02:00
James Cole
93f1854be0 Refactor journal repository and fix tests. 2019-08-10 13:42:33 +02:00
James Cole
b7f3c53688 Fix #2388 2019-08-10 11:17:23 +02:00
James Cole
94b8bb8f66 Cleanup journal repository 2019-08-10 08:42:46 +02:00
James Cole
edb038c822 Update composer file. 2019-08-10 08:42:14 +02:00
James Cole
b6a9204c4f See what happens in the build now. 2019-08-10 07:19:37 +02:00
James Cole
1d1b335cac Fix #2384 2019-08-10 07:18:18 +02:00
James Cole
0516065f5a Cleanup todo's [skip ci] 2019-08-10 07:05:19 +02:00
James Cole
606f33ceeb Add disclaimer for Firefly III analytics code. 2019-08-10 07:05:07 +02:00
James Cole
cb1db06a7c Remove unnecessary loops. 2019-08-10 07:04:54 +02:00
James Cole
7b0ccdbdb4 Split request 2019-08-10 07:04:31 +02:00
James Cole
55cf9fa9d0 Update link in readme. 2019-08-10 06:16:58 +02:00
James Cole
b3156e9798 New command for php config in ARM image. 2019-08-10 06:16:50 +02:00
Michael Fix
8e51b3edef Fix ranger.yml config 2019-08-09 13:40:11 -07:00
James Cole
6f8b1f3b9d Fix link in readme [skip ci] 2019-08-09 21:06:59 +02:00
James Cole
3b81b7a904 Merge tag '4.8.0' into develop
4.8.0
2019-08-09 21:03:15 +02:00
James Cole
81cc138700 Merge branch 'release/4.8.0' 2019-08-09 21:03:12 +02:00
James Cole
5b908b77f3 Final changelog things. Also triggers a build. 2019-08-09 21:02:46 +02:00
James Cole
a248544641 Some more last-minute fixes. 2019-08-09 20:33:57 +02:00
James Cole
b09504d0f7 Fix broken duplication test routine. 2019-08-09 18:35:34 +02:00
James Cole
1e3d85439e Last minute fixes in test code and UI 2019-08-09 18:06:43 +02:00
James Cole
392317b01f Meta data fixes. 2019-08-09 18:06:16 +02:00
James Cole
9d73fb8193 Update donation link [skip ci] 2019-08-09 06:14:51 +02:00
James Cole
64427ef004 New icons [skip ci] 2019-08-09 06:13:40 +02:00
James Cole
fd2f4e1459 Fix test coverage. 2019-08-09 05:58:52 +02:00
James Cole
dcbc2ca0c3 Update JS dependencies. 2019-08-09 05:46:50 +02:00
James Cole
55a5838b3c Small update to readme [skip ci] 2019-08-08 18:09:07 +02:00
James Cole
d7a3fcf26d Update changelog and readme. 2019-08-08 18:00:44 +02:00
James Cole
c8c8fce55f Update language stuff 2019-08-08 17:52:46 +02:00
James Cole
c32f3254c5 Make sure 2FA works as expected. 2019-08-08 17:52:37 +02:00
James Cole
3dff8dfaf8 Warning if you change your language. 2019-08-08 17:08:36 +02:00
James Cole
53c7c6685b New language! 2019-08-08 17:05:13 +02:00
James Cole
564f00561e New language! 2019-08-08 17:04:17 +02:00
James Cole
c27db00550 Updated strings. 2019-08-08 17:04:06 +02:00
James Cole
717d1a3612 Getting close enough for inclusion. 2019-08-08 17:03:19 +02:00
James Cole
9bd238b45f Switch some fields. 2019-08-07 18:52:42 +02:00
James Cole
d81128d8c6 Fix help for transaction thing. 2019-08-07 18:51:35 +02:00
James Cole
bdf76cf9b2 Reference .env file. 2019-08-06 19:24:25 +02:00
James Cole
aabf8ce8cc Fix redirect in link controller. 2019-08-06 19:23:18 +02:00
James Cole
8bcf8095a9 Switch around text [skip ci] 2019-08-06 05:42:15 +02:00
James Cole
efc6b0e45a Add a todo [skip ci] 2019-08-06 05:39:05 +02:00
James Cole
00d785d891 New middleware that should make sure the new forms redirect as well. 2019-08-05 19:45:20 +02:00
James Cole
e37100ae97 Sync between command line and FF 2019-08-05 17:07:19 +02:00
James Cole
a077d58e9c Update libraries, add some views. 2019-08-04 19:54:31 +02:00
James Cole
cc56a981cd Fix problem with type of transaction. 2019-08-04 17:26:00 +02:00
James Cole
2147caf3ef Fix tests 2019-08-04 11:12:24 +02:00
James Cole
62b5cf04ad Refactor tests and code to handle new 2FA methods. 2019-08-04 10:27:37 +02:00
James Cole
d3be043aa7 Some experimental docker changes. 2019-08-04 08:01:13 +02:00
James Cole
933f02d1d9 Extra upgrade text. 2019-08-04 07:43:01 +02:00
James Cole
02c92318fb One command to upgrade, not 27 2019-08-04 07:41:32 +02:00
James Cole
a328d393d3 Clear cache 2019-08-04 07:29:31 +02:00
James Cole
a06868b0c3 Add element for cash account. 2019-08-04 07:29:25 +02:00
James Cole
d38766e5db Firefly III can generate new backup codes. 2019-08-04 07:21:11 +02:00
James Cole
e41211bed7 Can use backup codes to login. 2019-08-04 07:10:18 +02:00
James Cole
0b6c3efe8d Can now disable MFA 2019-08-04 07:10:05 +02:00
James Cole
616d921bef Can disable MFA 2019-08-04 07:09:51 +02:00
James Cole
ea52a52022 New MFA submit routine with history. 2019-08-04 07:00:47 +02:00
James Cole
cc76be1aad Enable the creation of a MFA token in users auth app, and store the MFA secret in profile. 2019-08-03 20:09:09 +02:00
James Cole
2554840714 Index can now handle new MFA method. 2019-08-03 19:57:24 +02:00
James Cole
e1e351aad7 Add new MFA middleware 2019-08-03 19:54:30 +02:00
James Cole
e9de7bbf15 Disable the MFA middleware. 2019-08-03 19:53:30 +02:00
James Cole
2bf3bdb3de Basic MFA view 2019-08-03 19:49:38 +02:00
James Cole
0a2bc99630 Republish configuration file, and edit it. 2019-08-03 19:49:32 +02:00
James Cole
7f1bd19e45 remove "twoFactorAuthEnabled" from preferences. Kill switches for all code that references them (easier for refactor) 2019-08-03 19:46:12 +02:00
James Cole
f8d2292fa8 Upgrade libraries. 2019-08-03 19:35:20 +02:00
James Cole
b0bd35503f Add MFA code in prep of new MFA routine 2019-08-03 19:19:55 +02:00
James Cole
0b8427f881 Add some TODO's, refactor some code. 2019-08-03 19:17:59 +02:00
James Cole
cf121fea50 Improve test coverage. 2019-08-03 14:45:37 +02:00
James Cole
75c2529d3e Improve test coverage. 2019-08-03 10:50:43 +02:00
James Cole
b8b59b13a7 Allow bread crumb for bills. 2019-08-03 08:33:05 +02:00
James Cole
12c1fa2367 Add new search keywords 2019-08-03 08:32:55 +02:00
James Cole
febaab62f7 Various fixes. Sorry, lazy day. 2019-08-03 06:27:56 +02:00
James Cole
43dbad4e4c Merge tag '4.7.17.6' into develop
4.7.17.6

# Conflicts:
#	.travis.yml
#	app/Http/Controllers/Import/JobConfigurationController.php
#	app/Http/Controllers/Transaction/SingleController.php
#	config/firefly.php
2019-08-03 05:11:58 +02:00
James Cole
2089ee14e9 Merge branch 'hotfix/4.7.17.6' 2019-08-03 05:10:21 +02:00
James Cole
ec8e1d5a7a Version update 2019-08-03 05:10:06 +02:00
James Cole
2d7494f8cd Fix similar XSS issues. 2019-08-03 05:08:35 +02:00
James Cole
8717f469b1 Fix #2370 2019-08-03 05:08:20 +02:00
James Cole
40dd2e0f7f Improve test coverage. 2019-08-03 04:46:47 +02:00
James Cole
00dee03709 Update version again. 2019-08-02 21:21:38 +02:00
James Cole
ca9f8b56f7 Merge tag '4.7.17.5' into develop
4.7.17.5

# Conflicts:
#	resources/views/v1/transactions/convert.twig
2019-08-02 20:59:57 +02:00
James Cole
ece0c99dbb Merge branch 'hotfix/4.7.17.5' 2019-08-02 20:59:23 +02:00
James Cole
b217acfe26 New version + correct credits. 2019-08-02 20:59:06 +02:00
James Cole
15d4d185bb Fix #2363 2019-08-02 20:57:36 +02:00
James Cole
3435cb937c Merge tag '4.7.17.4' into develop
4.7.17.4

# Conflicts:
#	config/firefly.php
#	resources/views/v1/transactions/convert.twig
2019-08-02 17:10:55 +02:00
James Cole
c9f4cf4f34 Merge branch 'hotfix/4.7.17.4' 2019-08-02 17:08:34 +02:00
James Cole
1b3d3de969 Update version. 2019-08-02 17:08:24 +02:00
James Cole
e80d616ef4 Fix #2367 2019-08-02 17:05:54 +02:00
James Cole
2ddf48f15c Fix #2366 2019-08-02 16:46:45 +02:00
James Cole
692b256f3f Fix #2365 2019-08-02 16:44:48 +02:00
James Cole
3ad4e04e2a Fix #2364 2019-08-02 16:43:36 +02:00
James Cole
427de0594d Fix #2363 2019-08-02 16:42:16 +02:00
James Cole
6ac08de71d First steps for reconciliation fix. 2019-08-02 16:31:36 +02:00
James Cole
494f783a2b Fix #2333 2019-08-02 08:28:51 +02:00
James Cole
59801b8bc1 Fix #2332 2019-08-02 05:49:20 +02:00
James Cole
3dbde59787 Fix #2331 2019-08-02 05:44:51 +02:00
James Cole
ac903b88ba Fix search 2019-08-02 05:32:30 +02:00
James Cole
fc70afa3ea Improve test coverage. 2019-08-02 05:25:24 +02:00
James Cole
4bd8e1b11e Fix #2328 2019-08-02 05:24:51 +02:00
James Cole
04bf92d946 Fix #2188 2019-08-01 21:07:40 +02:00
James Cole
eb2ee0c683 Extend cases for #2179 2019-08-01 17:19:32 +02:00
James Cole
324e0e7e30 Fix #2361 2019-08-01 17:17:26 +02:00
James Cole
81dce5d7c7 Fix #2179 2019-08-01 06:22:07 +02:00
James Cole
b049ca27f1 Improve test coverage. 2019-08-01 06:21:44 +02:00
James Cole
9b574ce7ad Improve test coverage. 2019-07-31 16:53:09 +02:00
James Cole
5524941c90 Update rule handling and views. 2019-07-27 15:01:13 +02:00
James Cole
67c0ef6ec6 Improve test coverage. 2019-07-27 13:54:06 +02:00
James Cole
d94d34ca63 Expand test coverage. 2019-07-26 17:48:24 +02:00
James Cole
6ff4a0b45c Improve test coverage. 2019-07-25 14:19:49 +02:00
James Cole
ee95606ec0 Improve test coverage. 2019-07-24 19:02:41 +02:00
James Cole
226e2f7185 Improve test coverage. 2019-07-23 17:33:23 +02:00
James Cole
1e7e0facf1 Improve test coverage. 2019-07-22 19:23:14 +02:00
James Cole
b7a4b0fdfd Refactored a lot of tests. 2019-07-21 17:15:06 +02:00
James Cole
5242c0368b Fixes #2153 2019-07-21 06:02:02 +02:00
James Cole
8f9ba21f4d Fix test coverage. 2019-07-20 22:32:40 +02:00
James Cole
58d370a893 Fix #1860 2019-07-20 22:32:32 +02:00
James Cole
3b8e95fcca Fix #1652 2019-07-20 16:48:35 +02:00
James Cole
889b7e9a18 Improve mass controller and test controllers. 2019-07-20 16:02:50 +02:00
James Cole
6d34cfb940 Implemented new link thing. 2019-07-20 06:47:34 +02:00
James Cole
63832b31f8 Improve test coverage 2019-07-20 06:22:37 +02:00
James Cole
4de537ce76 New code for edit transaction, and some tests. 2019-07-19 16:08:42 +02:00
James Cole
a42992efb0 Merge tag '4.7.17.3' into develop
4.7.17.3

# Conflicts:
#	changelog.md
#	config/firefly.php
2019-07-16 19:24:07 +02:00
James Cole
7d482aa24c Merge branch 'hotfix/4.7.17.3' 2019-07-16 19:22:58 +02:00
James Cole
a9f34e9dd1 Update version. 2019-07-16 19:22:45 +02:00
James Cole
f795cb07e1 Fixes #2339 2019-07-16 19:22:35 +02:00
James Cole
17a66b3056 Fixes #2337 2019-07-16 19:22:14 +02:00
James Cole
531161db09 Fixes #2338 2019-07-16 19:21:58 +02:00
James Cole
2772a1bb3b Now supports file uploads 2019-07-15 21:00:35 +02:00
James Cole
0263e2b720 Remove unused extension. 2019-07-15 19:27:03 +02:00
James Cole
5d81de6117 Merge tag '4.7.17.2' into develop
4.7.17.2

# Conflicts:
#	app/Support/Twig/Extension/Transaction.php
#	changelog.md
#	config/firefly.php
2019-07-15 19:14:06 +02:00
James Cole
806ea2edbd Merge tag '4.7.17.1' into develop
4.7.17.1

# Conflicts:
#	changelog.md
#	config/firefly.php
2019-07-15 16:51:50 +02:00
James Cole
24efe9a096 Attempt to fix uploads. 2019-07-13 20:58:00 +02:00
James Cole
2210b8054d Fix Google Ana;ytics. 2019-07-13 20:57:29 +02:00
James Cole
3eb695f2ad Fix test for convert controller. 2019-07-13 20:57:06 +02:00
James Cole
7fd3f77c3e Make sure the convert controller works again. 2019-07-05 19:43:16 +02:00
James Cole
3c5c14ff5a Refactored the bulk edit controller. 2019-07-04 17:31:47 +02:00
James Cole
54623061d8 Make sure the date is passed on when running the cron job. 2019-07-02 06:11:06 +02:00
James Cole
5bbe1eab7c Expand test coverage and improve transaction management code. 2019-07-01 20:22:35 +02:00
James Cole
94acb50a6f Update meta files. 2019-07-01 20:21:54 +02:00
James Cole
6197c77303 Improve recurrences 2019-06-29 19:47:40 +02:00
James Cole
947b83cbd1 Improve test coverage. 2019-06-29 19:47:31 +02:00
James Cole
003d07504f Improve test coverage. 2019-06-29 08:14:28 +02:00
James Cole
cf904eb677 Big bunch of code to improve test coverage. 2019-06-25 19:24:01 +02:00
James Cole
6d68020cf4 Merge pull request #2318 from SanderKleykens/feature/ingbelgium
CSV file fix for ING Belgium
2019-06-24 08:07:28 +02:00
Sander Kleykens
9e9e5bd6dd CSV file fix for ING Belgium
Parse the description and opposing account information (IBAN and name) from ING Belgium CSV files.
2019-06-23 22:24:52 +02:00
James Cole
43d753e5bd Improve test coverage and efficiency for accounts and budgets. 2019-06-23 11:13:36 +02:00
James Cole
8f25562923 Refactor fiscal helper in tests. 2019-06-23 10:40:46 +02:00
James Cole
29158acfff New language string. 2019-06-23 10:39:59 +02:00
James Cole
c98d2187a0 Removed unused test file. 2019-06-23 10:38:54 +02:00
James Cole
b3349f1f9d New test suite 2019-06-23 05:53:10 +02:00
James Cole
9f50c5db3d Finalise account tests 2019-06-23 05:53:01 +02:00
James Cole
311659ba0d Move command around. 2019-06-23 05:52:33 +02:00
James Cole
956ec23d3c Remove unnecessary slash from in_array() 2019-06-22 13:09:25 +02:00
James Cole
940a730827 Fix reconciliation. 2019-06-22 13:09:11 +02:00
James Cole
2710a30a7c Warn about expensive code in test environment. 2019-06-22 10:25:57 +02:00
James Cole
0f70cc5780 Improve account CRUD and tests. 2019-06-22 10:25:34 +02:00
James Cole
150818e673 Do composer update for new commands. 2019-06-22 10:24:26 +02:00
James Cole
317fea6cb9 Remove unused collector. 2019-06-22 10:24:16 +02:00
James Cole
abf70a235a Debug the account-create controller. 2019-06-22 05:51:32 +02:00
James Cole
74a3d155b0 Rename some fields in account overviews. 2019-06-21 19:10:24 +02:00
James Cole
c72cc2482a New command in all lists. 2019-06-21 19:10:14 +02:00
James Cole
2d3d7f7720 Some generic code refactoring. 2019-06-21 19:10:02 +02:00
James Cole
fb1af395f9 New command and test 2019-06-21 19:07:11 +02:00
James Cole
f3123802a9 Composer update. 2019-06-21 19:06:56 +02:00
James Cole
b2628a290b make sure rules fire for events. 2019-06-21 19:06:50 +02:00
James Cole
47c2d0eaf1 Expand unit tests 2019-06-21 19:05:36 +02:00
James Cole
e80cde86d6 Remove dead code. 2019-06-21 19:05:28 +02:00
James Cole
72c0d7a874 Improve test coverage and quality 2019-06-16 13:16:46 +02:00
James Cole
1ce1a84c9e Sync some translations. 2019-06-16 13:16:26 +02:00
James Cole
3a34037f30 Sync some translations. 2019-06-16 13:16:18 +02:00
James Cole
bc33d1b67d Renamed various fields from their old camel casing to new ones. 2019-06-16 13:16:04 +02:00
James Cole
23d7abd55f Cleanup expected and unexpected bugs in the factories. 2019-06-16 13:15:32 +02:00
James Cole
4a1e56671b New PHPUnit config 2019-06-16 13:15:06 +02:00
James Cole
5d1cfc661f Optimise test code. 2019-06-13 18:07:49 +02:00
James Cole
162c8af6ca Update some meta files. 2019-06-13 18:07:38 +02:00
James Cole
b46f641b62 New funding doc for GitHub 2019-06-13 18:03:33 +02:00
James Cole
6964424bdc Finish command tests 2019-06-13 15:48:35 +02:00
James Cole
6bcb2ec144 Expand test coverage 2019-06-13 07:17:31 +02:00
James Cole
aacd218056 Improve test coverage. 2019-06-13 06:39:05 +02:00
James Cole
6fdfa722dd Remove having clause for #2306 2019-06-12 05:39:02 +02:00
James Cole
5f768a0525 Fix budget limit test, and a bug in the other currencies corrector. 2019-06-11 21:21:50 +02:00
James Cole
b632405a11 Fix for #2306 2019-06-11 21:04:17 +02:00
James Cole
9e2a2bca0a Remove references to old command + remove old command. 2019-06-11 20:10:59 +02:00
James Cole
6675749349 Split and simplify command. 2019-06-11 20:09:13 +02:00
James Cole
2ab9d2e6ee Improve test coverage. 2019-06-10 20:14:00 +02:00
James Cole
8efb73694d Full API coverage. 2019-06-09 15:28:54 +02:00
James Cole
d95544d588 Improve code coverage for rules. 2019-06-09 10:27:23 +02:00
James Cole
c02ab6f6d8 Fix route calls [skip ci] 2019-06-09 10:27:11 +02:00
James Cole
2b76b4a2b2 Re-implement transaction and transaction link tests. 2019-06-09 09:58:55 +02:00
James Cole
851c4d2907 Clean up code [skip ci] 2019-06-09 09:41:23 +02:00
James Cole
42bd5d05b5 Renaming methods must also be included in api.php 2019-06-09 09:40:21 +02:00
James Cole
9d0a5c97c2 Implement rule group and rule tests 2019-06-09 09:40:08 +02:00
James Cole
a1929b0521 Suppress PHPMD messages and make sure to use route() [skip ci] 2019-06-09 09:39:56 +02:00
James Cole
57cfd7e3bc Add separate request classes for rule groups and triggers. 2019-06-09 09:39:23 +02:00
James Cole
55345fa931 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2019-06-09 08:26:29 +02:00
James Cole
3c2dfc52bc API updates. 2019-06-09 08:26:23 +02:00
James Cole
73e32efd79 Merge pull request #2303 from JurajMlich/master
Correct ratesapi URL
2019-06-09 08:25:50 +02:00
Juraj Mlich
ced12ca83f Correct ratesapi URL 2019-06-08 16:04:37 +02:00
James Cole
85f9c256a1 Refactor some code for recurrences. 2019-06-08 06:19:21 +02:00
James Cole
7c2c24d330 Rename env variables. 2019-06-08 06:18:55 +02:00
James Cole
3681bf258b Composer update 2019-06-08 06:18:43 +02:00
James Cole
8b5551fc26 Replace \get_class with get_class 2019-06-07 18:20:15 +02:00
James Cole
779650f63d Deprecate the export function. 2019-06-07 18:19:24 +02:00
James Cole
9c5df6ab6e Clean up some code. 2019-06-07 18:13:54 +02:00
James Cole
fba3cb6d90 Remove unnecessary backslash 2019-06-07 17:58:11 +02:00
James Cole
e4a9abc315 Clean up repositories and cron code. 2019-06-07 17:57:46 +02:00
James Cole
a845cb9af9 Removed some todo's. 2019-06-05 19:38:28 +02:00
James Cole
9b7835c9ed Various API updates. 2019-06-04 20:42:11 +02:00
James Cole
6a6d67f2b4 Split group update now works. 2019-06-02 16:33:25 +02:00
James Cole
f46834e203 Remove some serious duplicates. 2019-06-02 06:39:54 +02:00
James Cole
2a2f29533d Some improvements, also edit screen. 2019-06-01 20:38:18 +02:00
James Cole
0a6e20eae4 Remove last references 2019-05-31 13:36:13 +02:00
James Cole
e15c35de64 Migrated all code to group collector. 2019-05-31 13:35:33 +02:00
James Cole
eb6329e556 Various code cleanup as suggested by PHPStorm. 2019-05-30 12:39:06 +02:00
James Cole
8b7e87ae57 Big refactor to remove the deprecated transaction collector. 2019-05-30 12:31:19 +02:00
James Cole
10a6ff9bf8 make sure reports work as expected. 2019-05-30 06:23:25 +02:00
James Cole
bdf48227bb Merge branch 'v480' into develop
# Conflicts:
#	public/v1/js/app.js
2019-05-29 22:03:43 +02:00
James Cole
ad32c30f82 Changes for the merge with 4.8.0. 2019-05-29 22:03:07 +02:00
James Cole
9e235ac5c8 Final fix before we merge back into develop and wreck havoc on everybody. 2019-05-29 22:02:15 +02:00
James Cole
bff156aad4 Add copyright things. 2019-05-29 21:56:39 +02:00
James Cole
7e2159d12c Removed a lot of references to the old collector. 2019-05-29 21:52:08 +02:00
James Cole
280b2efee6 New translations 2019-05-29 18:30:52 +02:00
James Cole
d13317095f Replace transaction collector. 2019-05-29 18:28:28 +02:00
James Cole
627ef09f11 Can store and submit transactions. 2019-05-25 10:04:56 +02:00
James Cole
3ec7336d5c Add some stuff for edge cases. 2019-05-25 09:17:46 +02:00
James Cole
47e0f6ed89 Bug catching in form. 2019-05-24 05:47:26 +02:00
James Cole
8f1928c933 Error reporting in new form. 2019-05-24 05:29:04 +02:00
James Cole
695244c928 Bug fix in budget search 2019-05-24 05:28:41 +02:00
James Cole
6e9128d894 Catch errors, prep to render them. 2019-05-17 06:52:16 +02:00
James Cole
9a53f17fff Fix for #2270 2019-05-16 19:37:32 +02:00
James Cole
91183a91b6 Will make submit form possible. 2019-05-12 19:21:14 +02:00
James Cole
7aef52870f Make sure all custom fields are included in form. 2019-05-12 13:46:20 +02:00
James Cole
5d09d7e923 Add custom component for date. 2019-05-12 07:40:24 +02:00
James Cole
fd28589395 Fix model and add debug info. 2019-05-11 05:32:09 +02:00
James Cole
c0029af929 Update composer lock file. 2019-05-09 20:05:52 +02:00
James Cole
43a17d8676 Lots of new code and first submission thing. 2019-05-08 19:57:07 +02:00
James Cole
4c8f26f25e Remove encryption parameter 2019-05-05 16:16:03 +02:00
James Cole
9015a5e0c1 Updated lock files. 2019-05-05 08:09:43 +02:00
James Cole
8676764513 Remove various sort routines. 2019-05-04 20:58:43 +02:00
James Cole
d5c5fa4fad Lots of new code for new transaction screen. 2019-05-04 20:58:11 +02:00
James Cole
912fe99981 New code for overview. Temp submit. 2019-04-19 07:00:19 +02:00
James Cole
4d3af1dcde Basic list, no functionalities. 2019-04-18 20:05:40 +02:00
James Cole
66c55b7bbe Improve tests, models and views. 2019-04-16 16:20:46 +02:00
James Cole
5ac39dbdef Clean up tests, test only the important things. 2019-04-12 04:53:18 +02:00
James Cole
6f063a134f Reset some code. 2019-04-11 06:06:25 +02:00
James Cole
966186cccd Disable all tests that may need some work in 4.8.0 2019-04-10 19:03:33 +02:00
James Cole
784d990e20 Remove slash from method call. 2019-04-09 20:05:20 +02:00
James Cole
80896b7181 Some code optimisations. 2019-04-09 15:42:25 +02:00
James Cole
97726c3822 Disable all kinds of tests until upgrades are complete. 2019-04-09 15:32:48 +02:00
James Cole
63070bffc3 Merge branch 'develop' into v480
* develop:
  Fix #2204
  CSV file fix for Belfius
2019-04-09 07:51:11 +02:00
James Cole
b3e48ede70 Fix #2204 2019-04-08 20:40:12 +02:00
James Cole
13afd4582f First attempt at displaying a group. 2019-04-08 20:31:31 +02:00
James Cole
4eb8b1a7da Merge pull request #2209 from SanderKleykens/feature/belfius
CSV file fix for Belfius
2019-04-08 11:39:39 +02:00
Sander Kleykens
251e9f9ba1 CSV file fix for Belfius
Correct the description for outgoing recurring transactions in Belfius CSV files
2019-04-06 20:47:35 +02:00
James Cole
c7bf167f81 New stale config. 2019-04-06 11:50:16 +02:00
James Cole
c07ca12574 Merge branch 'develop' into v480
* develop:
  docs: Fix minor typo
  docs: Fix minor typo
  Experimental Ranger config.
2019-04-06 11:09:58 +02:00
James Cole
bc735e3a59 Update scripts. 2019-04-06 11:09:14 +02:00
James Cole
47fdf4b1a2 Validate account info 2019-04-06 11:08:46 +02:00
James Cole
c519b4d0df Is now capable of updating transactions over the API. 2019-04-06 08:10:50 +02:00
James Cole
846fb57520 Merge pull request #2206 from eddybrando/patch-1
docs: Fix minor typo
2019-03-31 15:16:17 +02:00
Eddybrando Vásquez
88001f4bc4 docs: Fix minor typo
Use proper verb tense
2019-03-31 14:46:18 +02:00
James Cole
b692cccdfb User can submit new journal through API. 2019-03-31 13:36:49 +02:00
James Cole
50a071119b Merge pull request #2205 from eddybrando/patch-1
docs: Fix minor typo
2019-03-30 21:54:24 +01:00
Eddybrando Vásquez
66d275a90d docs: Fix minor typo
Replace "you're" with "your".
2019-03-30 21:46:07 +01:00
James Cole
c07ef3658b Refactor installer. 2019-03-30 11:03:39 +01:00
James Cole
636eeffaed Experimental Ranger config. 2019-03-30 07:39:16 +01:00
James Cole
5b1fb5354e Update API and transaction components. 2019-03-30 07:09:52 +01:00
James Cole
484ed6a585 Introduce group collector to API 2019-03-25 15:14:09 +01:00
James Cole
11e537810a Merge branch 'develop' into v480
* develop:
  Update Docker files slightly (yes I am a nitpicker).
  - Fixed copying Dockerfile.amd64 to Dockerfile.arm in the 2nd last commit
  entrypoint.sh: Wait for DB to start up
  Misc Optimizations: Changes on Dockerfile*

# Conflicts:
#	.deploy/docker/entrypoint.sh
2019-03-24 14:56:08 +01:00
James Cole
cc67445f35 Update Docker files slightly (yes I am a nitpicker). 2019-03-24 14:54:46 +01:00
James Cole
c4ceb9d2cd Merge pull request #2192 from hulloanson/docker-wait-db
Docker's entrypoint.sh: wait for DB before running DB-dependent artisan commands
2019-03-24 14:53:10 +01:00
James Cole
bc43ea2c25 Update version etc. 2019-03-24 14:52:45 +01:00
James Cole
c946a4040f First working version of the group collector. 2019-03-24 14:48:12 +01:00
hulloanson
f5c415f079 - Fixed copying Dockerfile.amd64 to Dockerfile.arm in the 2nd last commit 2019-03-24 18:21:04 +08:00
hulloanson
638f361479 entrypoint.sh: Wait for DB to start up
- Added wait-for-it.sh

- use wait-for-it.sh to wait for pgsql / mysql DB before running
`artisan` commands
2019-03-24 18:00:25 +08:00
hulloanson
ff23898c83 Misc Optimizations: Changes on Dockerfile*
- Moved lenghty docker-php-ext-install before adding contents of
FIREFLY_PATH to reduce build time after minor changes in FIREFLY_PATH
2019-03-24 17:59:17 +08:00
James Cole
d94b23b15d Build a new collector and first view online. 2019-03-24 09:23:36 +01:00
James Cole
fb304de75e Final commands. 2019-03-24 09:23:10 +01:00
James Cole
5f76b563dc Update composer stuff. 2019-03-24 09:23:00 +01:00
James Cole
ce30375341 Refactor upgrade and verify commands. 2019-03-23 18:58:06 +01:00
James Cole
1b0be2a47e Refactor upgrade and verify commands. 2019-03-23 08:10:59 +01:00
James Cole
a89be86ca4 Merge branch 'develop' into v480
* develop:
  Update config for Romanian.
  German string
  Romanian strings.
  Fix #2166
2019-03-22 18:29:52 +01:00
James Cole
f84655e339 Update config for Romanian. 2019-03-22 18:29:34 +01:00
James Cole
a0cead6548 German string 2019-03-22 18:27:05 +01:00
James Cole
4dbc5f1413 Romanian strings. 2019-03-22 18:26:46 +01:00
James Cole
943620c035 Fix #2166 2019-03-22 06:56:01 +01:00
James Cole
a1268ffd39 Command updates. 2019-03-20 18:47:51 +01:00
James Cole
fcd98b4d33 Revamp upgrade commands. 2019-03-20 18:31:00 +01:00
James Cole
e411d7a825 Improve upgrade command structure. 2019-03-18 16:53:05 +01:00
James Cole
3545d894fd Improve factories and tests. 2019-03-18 16:52:49 +01:00
James Cole
200a4b18a8 First full implementation of new storage routine. 2019-03-17 17:05:16 +01:00
James Cole
6bd2b4f288 Merge branch 'develop' into v480
* develop: (21 commits)
  Update lock file
  Update change logs and config files.
  Enable norsk, update version of DB
  Various language string updates.
  Norwegian strings.
  Improve installer middleware for Sandstorm.
  Fix some issues with importer #2166
  Other delete thing.
  More debug things.
  Extra debug info for #2159 and some kernel changes.
  Extra debug info for #2159
  Fix #2173
  Rename class and add copyright statement @wrouesnel #2167
  Fix LDAP auth configuration paths.
  Fix some cache issues and a version bump.
  Updated file list.
  Updated list.
  New file list.
  Update composer file.
  Small fix in changelog.
  ...
2019-03-17 12:34:36 +01:00
James Cole
c4d57af936 Merge tag '4.7.17' into develop
4.7.17
2019-03-17 09:40:14 +01:00
James Cole
431cf08401 Various improvements. 2019-03-08 05:47:51 +01:00
James Cole
e6d7c0ddbd Merge branch 'develop' into v480
* develop:
  Fix test for PHPUnit8
  Update version and changelog.
  Fix issue with bill display
  Update language strings.
2019-03-06 13:43:11 +01:00
James Cole
e4fb223f77 Code for 4.8.0 2019-03-05 17:26:49 +01:00
1349 changed files with 89449 additions and 58859 deletions

View File

@@ -1,185 +0,0 @@
# You can leave this on "local". If you change it to production most console commands will ask for extra confirmation.
# Never set it to "testing".
APP_ENV=${FF_APP_ENV}
# Set to true if you want to see debug information in error screens.
APP_DEBUG=${APP_DEBUG}
# This should be your email address
SITE_OWNER=${SITE_OWNER}
# The encryption key for your database and sessions. Keep this very secure.
# If you generate a new one all existing data must be considered LOST.
# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it
APP_KEY=${FF_APP_KEY}
# Change this value to your preferred time zone.
# Example: Europe/Amsterdam
TZ=${TZ}
# This variable must match your installation's external address but keep in mind that
# it's only used on the command line as a fallback value.
APP_URL=${APP_URL}
# TRUSTED_PROXIES is a useful variable when using Docker and/or a reverse proxy.
TRUSTED_PROXIES=${TRUSTED_PROXIES}
# The log channel defines where your log entries go to.
# 'daily' is the default logging mode giving you 5 daily rotated log files in /storage/logs/.
# Several other options exist. You can use 'single' for one big fat error log (not recommended).
# Also available are 'syslog', 'errorlog' and 'stdout' which will log to the system itself.
LOG_CHANNEL=stdout
# Log level. You can set this from least severe to most severe:
# debug, info, notice, warning, error, critical, alert, emergency
# If you set it to debug your logs will grow large, and fast. If you set it to emergency probably
# nothing will get logged, ever.
APP_LOG_LEVEL=${APP_LOG_LEVEL}
# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III
# For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html
DB_CONNECTION=${FF_DB_CONNECTION}
DB_HOST=${FF_DB_HOST}
DB_PORT=${FF_DB_PORT}
DB_DATABASE=${FF_DB_NAME}
DB_USERNAME=${FF_DB_USER}
DB_PASSWORD="${FF_DB_PASSWORD}"
# PostgreSQL supports SSL. You can configure it here.
PGSQL_SSL=${PGSQL_SSL}
PGSQL_SSL_MODE=${PGSQL_SSL_MODE}
PGSQL_SSL_ROOT_CERT=${PGSQL_SSL_ROOT_CERT}
PGSQL_SSL_CERT=${PGSQL_SSL_CERT}
PGSQL_SSL_KEY=${PGSQL_SSL_KEY}
PGSQL_SSL_CRL_FILE=${PGSQL_SSL_CRL_FILE}
# If you're looking for performance improvements, you could install memcached.
CACHE_DRIVER=file
SESSION_DRIVER=file
# You can configure another file storage backend if you cannot use the local storage option.
# To set this up, fill in the following variables. The upload path is used to store uploaded
# files and the export path is to store exported data (before download).
SFTP_HOST=${SFTP_HOST}
SFTP_PORT=${SFTP_PORT}
SFTP_UPLOAD_PATH=${SFTP_UPLOAD_PATH}
SFTP_EXPORT_PATH=${SFTP_EXPORT_PATH}
# SFTP uses either the username/password combination or the private key to authenticate.
SFTP_USERNAME=${SFTP_USERNAME}
SFTP_PASSWORD="${SFTP_PASSWORD}"
SFTP_PRIV_KEY=${SFTP_PRIV_KEY}
# Cookie settings. Should not be necessary to change these.
COOKIE_PATH="/"
COOKIE_DOMAIN=
COOKIE_SECURE=false
# If you want Firefly III to mail you, update these settings
# For instructions, see: https://firefly-iii.readthedocs.io/en/latest/installation/mail.html
MAIL_DRIVER=${MAIL_DRIVER}
MAIL_HOST=${MAIL_HOST}
MAIL_PORT=${MAIL_PORT}
MAIL_FROM=${MAIL_FROM}
MAIL_USERNAME=${MAIL_USERNAME}
MAIL_PASSWORD="${MAIL_PASSWORD}"
MAIL_ENCRYPTION=${MAIL_ENCRYPTION}
# Other mail drivers:
MAILGUN_DOMAIN=${MAILGUN_DOMAIN}
MAILGUN_SECRET=${MAILGUN_SECRET}
MANDRILL_SECRET=${MANDRILL_SECRET}
SPARKPOST_SECRET=${SPARKPOST_SECRET}
# Firefly III can send you the following messages
SEND_REGISTRATION_MAIL=true
SEND_ERROR_MESSAGE=false
# These messages contain (sensitive) transaction information:
SEND_REPORT_JOURNALS=${SEND_REPORT_JOURNALS}
# Set a Mapbox API key here (see mapbox.com) so there might be a map available at various places.
MAPBOX_API_KEY=${MAPBOX_API_KEY}
# Firefly III currently supports two provider for live Currency Exchange Rates:
# "fixer" is the default (for backward compatibility), and "ratesapi" is the new one.
# RatesApi.IO (see https://ratesapi.io) is a FREE and OPEN SOURCE live currency exchange rates,
# built compatible with Fixer.IO, based on data published by European Central Bank, and don't require API key.
CER_PROVIDER=${CER_PROVIDER}
# If you have select "fixer" as default currency exchange rates,
# set a Fixer IO API key here (see https://fixer.io) to enable live currency exchange rates.
# Please note that this WILL ONLY WORK FOR PAID fixer.io accounts because they severely limited
# the free API up to the point where you might as well offer nothing.
FIXER_API_KEY=${FIXER_API_KEY}
# If you wish to track your own behavior over Firefly III, set a valid analytics tracker ID here.
ANALYTICS_ID=${ANALYTICS_ID}
# Most parts of the database are encrypted by default, but you can turn this off if you want to.
# This makes it easier to migrate your database. Not that some fields will never be decrypted.
USE_ENCRYPTION=true
# Firefly III has two options for user authentication. "eloquent" is the default,
# and "ldap" for LDAP servers.
# For full instructions on these settings please visit:
# https://firefly-iii.readthedocs.io/en/latest/installation/authentication.html
LOGIN_PROVIDER=${LOGIN_PROVIDER}
# LDAP connection configuration
ADLDAP_CONNECTION_SCHEME=${ADLDAP_CONNECTION_SCHEME}
ADLDAP_AUTO_CONNECT=${ADLDAP_AUTO_CONNECT}
# LDAP connection settings
ADLDAP_CONTROLLERS=${ADLDAP_CONTROLLERS}
ADLDAP_PORT=${ADLDAP_PORT}
ADLDAP_TIMEOUT=${ADLDAP_TIMEOUT}
ADLDAP_BASEDN="${ADLDAP_BASEDN}"
ADLDAP_FOLLOW_REFFERALS=${ADLDAP_FOLLOW_REFFERALS}
ADLDAP_USE_SSL=${ADLDAP_USE_SSL}
ADLDAP_USE_TLS=${ADLDAP_USE_TLS}
ADLDAP_ADMIN_USERNAME=${ADLDAP_ADMIN_USERNAME}
ADLDAP_ADMIN_PASSWORD="${ADLDAP_ADMIN_PASSWORD}"
ADLDAP_ACCOUNT_PREFIX="${ADLDAP_ACCOUNT_PREFIX}"
ADLDAP_ACCOUNT_SUFFIX="${ADLDAP_ACCOUNT_SUFFIX}"
# LDAP authentication settings.
ADLDAP_PASSWORD_SYNC=${ADLDAP_PASSWORD_SYNC}
ADLDAP_LOGIN_FALLBACK=${ADLDAP_LOGIN_FALLBACK}
ADLDAP_DISCOVER_FIELD=${ADLDAP_DISCOVER_FIELD}
ADLDAP_AUTH_FIELD=${ADLDAP_AUTH_FIELD}
# Will allow SSO if your server provides an AUTH_USER field.
WINDOWS_SSO_DISCOVER=${WINDOWS_SSO_DISCOVER}
WINDOWS_SSO_KEY=${WINDOWS_SSO_KEY}
# field to sync as local username.
ADLDAP_SYNC_FIELD=${ADLDAP_SYNC_FIELD}
# You can disable the X-Frame-Options header if it interfears with tools like
# Organizr. This is at your own risk.
DISABLE_FRAME_HEADER=${DISABLE_FRAME_HEADER}
# Leave the following configuration vars as is.
# Unless you like to tinker and know what you're doing.
APP_NAME=FireflyIII
ADLDAP_CONNECTION=default
BROADCAST_DRIVER=log
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
CACHE_PREFIX=firefly
SEARCH_RESULT_LIMIT=50
PUSHER_KEY=
PUSHER_SECRET=
PUSHER_ID=
DEMO_USERNAME=
DEMO_PASSWORD=
IS_DOCKER=true
IS_SANDSTORM=false
IS_HEROKU=false
BUNQ_USE_SANDBOX=false
FFIII_LAYOUT=v1

View File

@@ -3,8 +3,6 @@
# build image
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
if [ "$TRAVIS_BRANCH" == "develop" ]; then
echo "Build develop amd64"
docker build -t jc5x/firefly-iii:develop-amd64 -f Dockerfile.amd64 .

View File

@@ -2,7 +2,6 @@
docker run --rm --privileged multiarch/qemu-user-static:register --reset
# get qemu-arm-static binary
mkdir tmp
pushd tmp && \

View File

@@ -2,8 +2,6 @@
echo "Now in entrypoint.sh for Firefly III"
lscpu
# make sure the correct directories exists (suggested by @chrif):
echo "Making directories..."
mkdir -p $FIREFLY_PATH/storage/app/public
@@ -27,12 +25,6 @@ then
echo "Touched!"
fi
if [[ $FF_DB_CONNECTION == "sqlite" ]]
then
touch $FIREFLY_PATH/storage/database/database.sqlite
echo "Touched!"
fi
# make sure we own the volumes:
echo "Run chown on ${FIREFLY_PATH}/storage..."
chown -R www-data:www-data -R $FIREFLY_PATH/storage
@@ -43,22 +35,64 @@ chmod -R 775 $FIREFLY_PATH/storage
echo "Remove log file..."
rm -f $FIREFLY_PATH/storage/logs/laravel.log
echo "Map environment variables on .env file..."
cat $FIREFLY_PATH/.deploy/docker/.env.docker | envsubst > $FIREFLY_PATH/.env
echo "Dump auto load..."
composer dump-autoload
echo "Discover packages..."
php artisan package:discover
echo "Run various artisan commands..."
if [[ -z "$DB_PORT" ]]; then
if [[ $DB_CONNECTION == "pgsql" ]]; then
DB_PORT=5432
elif [[ $DB_CONNECTION == "mysql" ]]; then
DB_PORT=3306
fi
fi
if [[ ! -z "$DB_PORT" ]]; then
$FIREFLY_PATH/.deploy/docker/wait-for-it.sh "${DB_HOST}:${DB_PORT}" -- echo "db is up. Time to execute artisan commands"
fi
#env $(grep -v "^\#" .env | xargs)
php artisan cache:clear
php artisan migrate --seed
php artisan firefly:decrypt-all
php artisan firefly:upgrade-database
php artisan firefly:verify
php artisan firefly-iii:decrypt-all
# there are 12 upgrade commands
php artisan firefly-iii:transaction-identifiers
php artisan firefly-iii:migrate-to-groups
php artisan firefly-iii:account-currencies
php artisan firefly-iii:transfer-currencies
php artisan firefly-iii:other-currencies
php artisan firefly-iii:migrate-notes
php artisan firefly-iii:migrate-attachments
php artisan firefly-iii:bills-to-rules
php artisan firefly-iii:bl-currency
php artisan firefly-iii:cc-liabilities
php artisan firefly-iii:back-to-journals
php artisan firefly-iii:rename-account-meta
# there are 13 verify commands
php artisan firefly-iii:fix-piggies
php artisan firefly-iii:create-link-types
php artisan firefly-iii:create-access-tokens
php artisan firefly-iii:remove-bills
php artisan firefly-iii:enable-currencies
php artisan firefly-iii:fix-transfer-budgets
php artisan firefly-iii:fix-uneven-amount
php artisan firefly-iii:delete-zero-amount
php artisan firefly-iii:delete-orphaned-transactions
php artisan firefly-iii:delete-empty-journals
php artisan firefly-iii:delete-empty-groups
php artisan firefly-iii:fix-account-types
php artisan firefly-iii:rename-meta-fields
# report commands
php artisan firefly-iii:report-empty-objects
php artisan firefly-iii:report-sum
php artisan passport:install
php artisan cache:clear
php artisan firefly:instructions install
echo "Go!"
exec apache2-foreground
exec apache2-foreground

178
.deploy/docker/wait-for-it.sh Executable file
View File

@@ -0,0 +1,178 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
WAITFORIT_cmdname=${0##*/}
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
else
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
fi
WAITFORIT_PID=$!
trap "kill -INT -$WAITFORIT_PID" INT
wait $WAITFORIT_PID
WAITFORIT_RESULT=$?
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
fi
return $WAITFORIT_RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
WAITFORIT_hostport=(${1//:/ })
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
shift 1
;;
--child)
WAITFORIT_CHILD=1
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
;;
-h)
WAITFORIT_HOST="$2"
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
WAITFORIT_HOST="${1#*=}"
shift 1
;;
-p)
WAITFORIT_PORT="$2"
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
WAITFORIT_PORT="${1#*=}"
shift 1
;;
-t)
WAITFORIT_TIMEOUT="$2"
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
WAITFORIT_TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
WAITFORIT_CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"
else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
fi
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
wait_for
WAITFORIT_RESULT=$?
exit $WAITFORIT_RESULT
else
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
wait_for_wrapper
WAITFORIT_RESULT=$?
else
wait_for
WAITFORIT_RESULT=$?
fi
fi
if [[ $WAITFORIT_CLI != "" ]]; then
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
fi
exec "${WAITFORIT_CLI[@]}"
else
exit $WAITFORIT_RESULT
fi

View File

@@ -2,9 +2,13 @@ en_US
es_ES
de_DE
fr_FR
ro_RO
it_IT
nl_NL
pl_PL
pt_BR
ru_RU
nb_NO
nb_NO
cs_CZ
id_ID
hu_HU

View File

@@ -44,17 +44,17 @@ spec:
- image: firefly-local
name: firefly-local
env:
- name: FF_APP_ENV
- name: APP_ENV
value: "local"
- name: FF_APP_KEY
- name: APP_KEY
value: "S0m3R@nd0mString0f32Ch@rsEx@ct1y"
- name: FF_DB_HOST
- name: DB_HOST
value: "172.17.0.9"
- name: FF_DB_NAME
- name: DB_NAME
value: "firefly_db"
- name: FF_DB_USER
- name: DB_USER
value: "firefly_db"
- name: FF_DB_PASSWORD
- name: DB_PASSWORD
value: "password"
volumeMounts:
- mountPath: "/var/www/firefly-iii/storage/export"

View File

@@ -8,8 +8,8 @@ APP_DEBUG=false
# This should be your email address
SITE_OWNER=mail@example.com
# The encryption key for your database and sessions. Keep this very secure.
# If you generate a new one all existing data must be considered LOST.
# The encryption key for your sessions. Keep this very secure.
# If you generate a new one existing data must be considered LOST.
# Change it to a string of exactly 32 chars or use command `php artisan key:generate` to generate it
APP_KEY=SomeRandomStringOf32CharsExactly
@@ -22,6 +22,7 @@ TZ=Europe/Amsterdam
APP_URL=http://localhost
# TRUSTED_PROXIES is a useful variable when using Docker and/or a reverse proxy.
# Set it to ** and reverse proxies work just fine.
TRUSTED_PROXIES=
# The log channel defines where your log entries go to.
@@ -39,6 +40,7 @@ APP_LOG_LEVEL=notice
# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III
# For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html
DB_CONNECTION=mysql
# If you use DOCKER COMPOSE, change this variable to "firefly_iii_db"
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
@@ -101,10 +103,11 @@ SEND_REPORT_JOURNALS=true
MAPBOX_API_KEY=
# Firefly III currently supports two provider for live Currency Exchange Rates:
# "fixer" is the default (for backward compatibility), and "ratesapi" is the new one.
# "fixer", and "ratesapi".
# RatesApi.IO (see https://ratesapi.io) is a FREE and OPEN SOURCE live currency exchange rates,
# built compatible with Fixer.IO, based on data published by European Central Bank, and don't require API key.
CER_PROVIDER=fixer
# built compatible with Fixer.IO, based on data published by European Central Bank, and doesn't require API key.
CER_PROVIDER=ratesapi
# If you have select "fixer" as default currency exchange rates,
# set a Fixer IO API key here (see https://fixer.io) to enable live currency exchange rates.
# Please note that this WILL ONLY WORK FOR PAID fixer.io accounts because they severely limited
@@ -114,10 +117,6 @@ FIXER_API_KEY=
# If you wish to track your own behavior over Firefly III, set a valid analytics tracker ID here.
ANALYTICS_ID=
# Most parts of the database are encrypted by default, but you can turn this off if you want to.
# This makes it easier to migrate your database. Not that some fields will never be decrypted.
USE_ENCRYPTION=true
# Firefly III has two options for user authentication. "eloquent" is the default,
# and "ldap" for LDAP servers.
# For full instructions on these settings please visit:
@@ -179,6 +178,7 @@ PUSHER_ID=
DEMO_USERNAME=
DEMO_PASSWORD=
IS_DOCKER=false
USE_ENCRYPTION=false
IS_SANDSTORM=false
IS_HEROKU=false
BUNQ_USE_SANDBOX=false

5
.github/funding.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
# These are supported funding model platforms
#github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: JC5
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UKUT455HUFA

8
.github/ranger.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
# in .github/ranger.yml
comments:
-
action: delete_comment
pattern: 1
-
action: delete_comment
pattern: ":+1:"

1
.github/stale.yml vendored
View File

@@ -14,6 +14,7 @@ exemptLabels:
- feature
- bug
- possible-bug
- "possible bug"
- announcement
# Set to true to ignore issues in a project (defaults to false)

View File

@@ -1,5 +1,100 @@
# 4.8.0.2 (API 0.10.0)
- [Issue 2203](https://github.com/firefly-iii/firefly-iii/issues/2203) Reconciliation inconsistencies.
- [Issue 2392](https://github.com/firefly-iii/firefly-iii/issues/2392) Bad namespace leads to installation errors.
- [Issue 2393](https://github.com/firefly-iii/firefly-iii/issues/2393) Missing budget selector.
- [Issue 2402](https://github.com/firefly-iii/firefly-iii/issues/2402) bad amounts in default report
- [Issue 2405](https://github.com/firefly-iii/firefly-iii/issues/2405) Due date can't be edited.
- [Issue 2404](https://github.com/firefly-iii/firefly-iii/issues/2404) bad page indicator in the "no category" transaction overview.
- [Issue 2407](https://github.com/firefly-iii/firefly-iii/issues/2407) Fix recurring transaction dates
- [Issue 2410](https://github.com/firefly-iii/firefly-iii/issues/2410) Transaction links inconsistent
- [Issue 2414](https://github.com/firefly-iii/firefly-iii/issues/2414) Can't edit recurring transactions
- [Issue 2415](https://github.com/firefly-iii/firefly-iii/issues/2415) Return here + reset form results in empty transaction form
- [Issue 2416](https://github.com/firefly-iii/firefly-iii/issues/2416) Some form inconsistencies.
- [Issue 2418](https://github.com/firefly-iii/firefly-iii/issues/2418) Reports are inaccurate or broken.
- [Issue 2422](https://github.com/firefly-iii/firefly-iii/issues/2422) PHP error when matching transactions.
- [Issue 2423](https://github.com/firefly-iii/firefly-iii/issues/2423) Reports are inaccurate or broken.
- [Issue 2426](https://github.com/firefly-iii/firefly-iii/issues/2426) Inconsistent documentation and instructions.
- [Issue 2427](https://github.com/firefly-iii/firefly-iii/issues/2427) Deleted account and "initial balance" accounts may appear in dropdowns.
- [Issue 2428](https://github.com/firefly-iii/firefly-iii/issues/2428) Reports are inaccurate or broken.
- [Issue 2429](https://github.com/firefly-iii/firefly-iii/issues/2429) Typo leads to SQL errors in available budgets API
- [Issue 2431](https://github.com/firefly-iii/firefly-iii/issues/2431) Issues creating new recurring transactions.
- [Issue 2434](https://github.com/firefly-iii/firefly-iii/issues/2434) You can edit the initial balance transaction but it fails to save.
- ARM build should work now.
# 4.8.0.1 (API 0.10.0)
- The balance box on the dashboard shows only negative numbers, skewing the results.
- Selecting or using tags in new transactions results in an error.
- Editing a transaction with tags will drop the tags from the transaction.
- [Issue 2382](https://github.com/firefly-iii/firefly-iii/issues/2382) Ranger config
- [Issue 2384](https://github.com/firefly-iii/firefly-iii/issues/2384) When upgrading manually, you may see: `The command "generate-keys" does not exist.`
- [Issue 2385](https://github.com/firefly-iii/firefly-iii/issues/2385) When upgrading manually, the firefly:verify command may fail to run.
- [Issue 2388](https://github.com/firefly-iii/firefly-iii/issues/2388) When registering as a new user, leaving the opening balance at 0 will give you an error.
- [Issue 2395](https://github.com/firefly-iii/firefly-iii/issues/2395) Editing split transactions is broken.
- [Issue 2397](https://github.com/firefly-iii/firefly-iii/issues/2397) Transfers are stored the wrong way around.
- [Issue 2399](https://github.com/firefly-iii/firefly-iii/issues/2399) Not all account balances are updated after you create a new transaction.
- [Issue 2401](https://github.com/firefly-iii/firefly-iii/issues/2401) Could not delete a split from a split transaction.
# 4.8.0 (API 0.10.0)
- Hungarian translation!
- New database model that changes the concept of "split transactions";
- New installation routine with rewritten database integrity tests and upgrade code;
- Rewritten screen to create transactions which will now completely rely on the API;
- Most terminal commands now have the prefix `firefly-iii`.
- New MFA code that will generate backup codes for you and is more robust. MFA will have to be re-enabled for ALL users.
- This will probably be the last Firefly III version to have import routines for files, Bunq and others. These will be moved to separate applications that use the Firefly III API.
- The export function has been removed.
- [Issue 1652](https://github.com/firefly-iii/firefly-iii/issues/1652), new strings to use during the import.
- [Issue 1860](https://github.com/firefly-iii/firefly-iii/issues/1860), fixing the default currency not being on top in a JSON box.
- [Issue 2031](https://github.com/firefly-iii/firefly-iii/issues/2031), a fix for Triodos imports.
- [Issue 2153](https://github.com/firefly-iii/firefly-iii/issues/2153), problems with editing credit cards.
- [Issue 2179](https://github.com/firefly-iii/firefly-iii/issues/2179), consistent and correct redirect behavior.
- [Issue 2180](https://github.com/firefly-iii/firefly-iii/issues/2180), API issues with foreign amounts.
- [Issue 2187](https://github.com/firefly-iii/firefly-iii/issues/2187), bulk editing reconciled transactions was broken.
- [Issue 2188](https://github.com/firefly-iii/firefly-iii/issues/2188), redirect loop in bills
- [Issue 2189](https://github.com/firefly-iii/firefly-iii/issues/2189), bulk edit could not handle tags.
- [Issue 2203](https://github.com/firefly-iii/firefly-iii/issues/2203), [issue 2208](https://github.com/firefly-iii/firefly-iii/issues/2208), [issue 2352](https://github.com/firefly-iii/firefly-iii/issues/2352), reconciliation fixes
- [Issue 2204](https://github.com/firefly-iii/firefly-iii/issues/2204), transaction type fix
- [Issue 2211](https://github.com/firefly-iii/firefly-iii/issues/2211), mass edit fixes.
- [Issue 2212](https://github.com/firefly-iii/firefly-iii/issues/2212), bug in the API when deleting objects.
- [Issue 2214](https://github.com/firefly-iii/firefly-iii/issues/2214), could not view attachment.
- [Issue 2219](https://github.com/firefly-iii/firefly-iii/issues/2219), max amount was a little low.
- [Issue 2239](https://github.com/firefly-iii/firefly-iii/issues/2239), fixed ordering issue.
- [Issue 2246](https://github.com/firefly-iii/firefly-iii/issues/2246), could not disable EUR.
- [Issue 2268](https://github.com/firefly-iii/firefly-iii/issues/2268), could not import into liability accounts.
- [Issue 2293](https://github.com/firefly-iii/firefly-iii/issues/2293), could not trigger rule on deposits in some circumstances
- [Issue 2314](https://github.com/firefly-iii/firefly-iii/issues/2314), could not trigger rule on transfers in some circumstances
- [Issue 2325](https://github.com/firefly-iii/firefly-iii/issues/2325), some balance issues on the frontpage.
- [Issue 2328](https://github.com/firefly-iii/firefly-iii/issues/2328), some date range issues in reports
- [Issue 2331](https://github.com/firefly-iii/firefly-iii/issues/2331), some broken fields in reports.
- [Issue 2333](https://github.com/firefly-iii/firefly-iii/issues/2333), API issues with piggy banks.
- [Issue 2355](https://github.com/firefly-iii/firefly-iii/issues/2355), configuration issues with LDAP
- [Issue 2361](https://github.com/firefly-iii/firefly-iii/issues/2361), some ordering issues.
- Updated API to reflect the changes in the database.
- New API end-point for a summary of your data.
- Some new API charts.
# 4.7.17.6 (API 0.9.2)
- XSS issue in liability account redirect, found by [@0x2500](https://github.com/0x2500).
# 4.7.17.5 (API 0.9.2)
- Several XSS issues, found by [@0x2500](https://github.com/0x2500).
# 4.7.17.4 (API 0.9.2)
- Several XSS issues, found by [@0x2500](https://github.com/0x2500).
# 4.7.17.3 (API 0.9.2)
- XSS bug in file uploads (x2), found by [@dayn1ne](https://github.com/dayn1ne).
- XSS bug in search, found by [@dayn1ne](https://github.com/dayn1ne).
# 4.7.17.2 (API 0.9.2)
- XSS bug in budget title.
- XSS bug in budget title, found by [@dayn1ne](https://github.com/dayn1ne).
# 4.7.17 (API 0.9.2)
- Support for Norwegian!

View File

@@ -11,7 +11,7 @@ mkdir -p /var/log
mkdir -p /var/log/mysql
mkdir -p /var/log/nginx
# Wipe /var/run, since pidfiles and socket files from previous launches should go away
# TODO someday: I'd prefer a tmpfs for these.
# Someday: I'd prefer a tmpfs for these.
rm -rf /var/run
mkdir -p /var/run
rm -rf /var/tmp

View File

@@ -15,8 +15,8 @@ const pkgdef :Spk.PackageDefinition = (
manifest = (
appTitle = (defaultText = "Firefly III"),
appVersion = 28,
appMarketingVersion = (defaultText = "4.7.17.2"),
appVersion = 34,
appMarketingVersion = (defaultText = "4.8.0.2"),
actions = [
# Define your "new document" handlers here.

View File

@@ -25,13 +25,13 @@ sed -i 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# zh_TW.UTF-8 UTF-8/zh_TW.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# nb_NO.UTF-8 UTF-8/nb_NO.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# ro_RO.UTF-8 UTF-8/ro_RO.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# id_ID.UTF-8 UTF-8/id_ID.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/# hu_HU.UTF-8 UTF-8/hu_HU.UTF-8 UTF-8/g' /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
# actually add repository
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E9C74FEEA2098A6E
add-apt-repository "deb http://packages.dotdeb.org jessie all"

View File

@@ -1,7 +1,7 @@
sudo: required
language: bash
env:
- VERSION=4.7.17.2
- VERSION=4.8.0.2
dist: xenial
@@ -26,4 +26,4 @@ script:
# build everything
- .deploy/docker/build-amd64.sh
- .deploy/docker/build-arm.sh
- .deploy/docker/manifest.sh
- .deploy/docker/manifest.sh

View File

@@ -1,27 +1,37 @@
FROM php:7.2-apache
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.4" maintainer="thegrumpydictator@gmail.com"
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install some stuff
RUN apt-get update && apt-get install -y libpng-dev \
libicu-dev \
unzip \
gettext-base \
libldap2-dev \
libpq-dev \
locales \
libmemcached-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
# Ensure correct app directory permission, then `composer install`
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
@@ -31,24 +41,6 @@ COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Run a lot of installation commands:
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
a2enmod rewrite && a2enmod ssl && \
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)/ && \
docker-php-ext-install -j$(nproc) zip bcmath ldap gd pdo_pgsql pdo_mysql intl opcache && \
pecl install memcached-3.1.3 && \
docker-php-ext-enable memcached && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
echo "de_DE.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen && \
locale-gen && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Expose port 80
EXPOSE 80

View File

@@ -1,27 +1,38 @@
FROM php:7.2-apache
ARG ARCH
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.4" maintainer="thegrumpydictator@gmail.com"
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install some stuff
RUN apt-get update && apt-get install -y libpng-dev \
libicu-dev \
unzip \
gettext-base \
libldap2-dev \
libpq-dev \
locales \
libmemcached-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
# Ensure correct app directory permission, then `composer install`
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
@@ -31,25 +42,6 @@ COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Run a lot of installation commands:
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
a2enmod rewrite && a2enmod ssl && \
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)/ && \
docker-php-ext-install -j$(nproc) zip bcmath ldap gd pdo_pgsql pdo_mysql intl opcache && \
pecl install memcached-3.1.3 && \
docker-php-ext-enable memcached && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
echo "de_DE.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen && \
locale-gen && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Expose port 80
EXPOSE 80

View File

@@ -1,26 +1,34 @@
FROM arm32v7/php:7.2.8-apache-stretch
FROM arm32v7/php:7.2-apache-stretch
ARG ARCH
COPY tmp/qemu-arm-static /usr/bin/qemu-arm-static
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.4" maintainer="thegrumpydictator@gmail.com"
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install some stuff
RUN apt-get update && apt-get install -y libpng-dev \
libicu-dev \
unzip \
gettext-base \
libldap2-dev \
libpq-dev \
locales \
libmemcached-dev
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
# Ensure correct app directory permission, then `composer install`
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
@@ -30,19 +38,6 @@ COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Run a lot of installation commands:
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
a2enmod rewrite && a2enmod ssl && \
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)/ && \
docker-php-ext-install -j$(nproc) zip bcmath ldap gd pdo_pgsql pdo_mysql intl opcache && \
pecl install memcached-3.1.3 && \
docker-php-ext-enable memcached && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
echo "de_DE.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen && \
locale-gen && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# Expose port 80
EXPOSE 80

View File

@@ -1,26 +1,34 @@
FROM arm32v7/php:7.2.8-apache-stretch
FROM arm32v7/php:7.2-apache-stretch
ARG ARCH
COPY tmp/qemu-arm-static /usr/bin/qemu-arm-static
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.4" maintainer="thegrumpydictator@gmail.com"
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install some stuff
RUN apt-get update && apt-get install -y libpng-dev \
libicu-dev \
unzip \
gettext-base \
libldap2-dev \
libpq-dev \
locales \
libmemcached-dev
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
# Ensure correct app directory permission, then `composer install`
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
@@ -30,19 +38,6 @@ COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Run a lot of installation commands:
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
a2enmod rewrite && a2enmod ssl && \
docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine)/ && \
docker-php-ext-install -j$(nproc) zip bcmath ldap gd pdo_pgsql pdo_mysql intl opcache && \
pecl install memcached-3.1.3 && \
docker-php-ext-enable memcached && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
echo "de_DE.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen && \
locale-gen && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# Expose port 80
EXPOSE 80

View File

@@ -34,7 +34,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Returns basic information about this installation.
*
* @codeCoverageIgnore
* Class AboutController.
*/
class AboutController extends Controller
@@ -51,8 +51,10 @@ class AboutController extends Controller
$phpVersion = str_replace($search, $replace, PHP_VERSION);
$phpOs = str_replace($search, $replace, PHP_OS);
$currentDriver = DB::getDriverName();
$data
= [
= [
'version' => config('firefly.version'),
'api_version' => config('firefly.api_version'),
'php_version' => $phpVersion,
@@ -67,7 +69,6 @@ class AboutController extends Controller
* Returns information about the user.
*
* @param Request $request
*
* @return JsonResponse
*/
public function user(Request $request): JsonResponse

View File

@@ -23,17 +23,16 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\AccountRequest;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Api\V1\Requests\AccountStoreRequest;
use FireflyIII\Api\V1\Requests\AccountUpdateRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AccountTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -48,7 +47,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AccountController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AccountController extends Controller
{
@@ -58,6 +57,8 @@ class AccountController extends Controller
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -78,8 +79,9 @@ class AccountController extends Controller
/**
* Remove the specified resource from storage.
*
* @param \FireflyIII\Models\Account $account
* @param Account $account
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function delete(Account $account): JsonResponse
@@ -94,6 +96,7 @@ class AccountController extends Controller
*
* @param Request $request
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
@@ -134,12 +137,14 @@ class AccountController extends Controller
/**
* List all of them.
* List all piggies.
*
* @param Request $request
* @param Account $account
*
* @return JsonResponse]
* @codeCoverageIgnore
*
* @return JsonResponse
*/
public function piggyBanks(Request $request, Account $account): JsonResponse
{
@@ -179,7 +184,7 @@ class AccountController extends Controller
* @param Request $request
* @param Account $account
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function show(Request $request, Account $account): JsonResponse
{
@@ -198,13 +203,13 @@ class AccountController extends Controller
/**
* Store a new instance.
*
* @param AccountRequest $request
* @param AccountStoreRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function store(AccountRequest $request): JsonResponse
public function store(AccountStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$data = $request->getAllAccountData();
$account = $this->repository->store($data);
$manager = new Manager;
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
@@ -220,12 +225,15 @@ class AccountController extends Controller
}
/**
* Show all transactions.
* Show all transaction groups related to the account.
*
* @codeCoverageIgnore
*
* @param Request $request
* @param Account $account
*
* @return JsonResponse
*
*/
public function transactions(Request $request, Account $account): JsonResponse
{
@@ -242,41 +250,31 @@ class AccountController extends Controller
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
if ($this->repository->isAsset($account)) {
$collector->setAccounts(new Collection([$account]));
}
if (!$this->repository->isAsset($account)) {
$collector->setOpposingAccounts(new Collection([$account]));
}
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($admin)->setAccounts(new Collection([$account]))
->withAPIInformation()->setLimit($pageSize)->setPage($this->parameters->get('page'))->setTypes($types);
// set range if necessary:
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator->setPath(route('api.v1.accounts.transactions', [$account->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.accounts.transactions', [$account->id]) . $this->buildParams());
$groups = $paginator->getCollection();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource = new FractalCollection($groups, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
@@ -285,14 +283,14 @@ class AccountController extends Controller
/**
* Update account.
*
* @param AccountRequest $request
* @param Account $account
* @param AccountUpdateRequest $request
* @param Account $account
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function update(AccountRequest $request, Account $account): JsonResponse
public function update(AccountUpdateRequest $request, Account $account): JsonResponse
{
$data = $request->getAll();
$data = $request->getAllAccountData();
$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);
$this->repository->update($account, $data);
$manager = new Manager;

View File

@@ -23,7 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\AttachmentRequest;
use FireflyIII\Api\V1\Requests\AttachmentStoreRequest;
use FireflyIII\Api\V1\Requests\AttachmentUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Models\Attachment;
@@ -39,11 +40,12 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
use function strlen;
/**
* Class AttachmentController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AttachmentController extends Controller
{
@@ -52,6 +54,7 @@ class AttachmentController extends Controller
/**
* AccountController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -70,7 +73,7 @@ class AttachmentController extends Controller
/**
* Remove the specified resource from storage.
*
* @codeCoverageIgnore
* @param Attachment $attachment
*
* @return JsonResponse
@@ -86,9 +89,9 @@ class AttachmentController extends Controller
* Download an attachment.
*
* @param Attachment $attachment
*
* @codeCoverageIgnore
* @return LaravelResponse
* @throws FireflyException
* @throws FireflyException
*/
public function download(Attachment $attachment): LaravelResponse
{
@@ -110,7 +113,7 @@ class AttachmentController extends Controller
->header('Expires', '0')
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->header('Pragma', 'public')
->header('Content-Length', \strlen($content));
->header('Content-Length', strlen($content));
return $response;
}
@@ -121,7 +124,7 @@ class AttachmentController extends Controller
* Display a listing of the resource.
*
* @param Request $request
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
@@ -158,9 +161,8 @@ class AttachmentController extends Controller
/**
* Display the specified resource.
*
* @param Request $request
* @param Request $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function show(Request $request, Attachment $attachment): JsonResponse
@@ -181,12 +183,12 @@ class AttachmentController extends Controller
/**
* Store a newly created resource in storage.
*
* @param AttachmentRequest $request
* @param AttachmentStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(AttachmentRequest $request): JsonResponse
public function store(AttachmentStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$attachment = $this->repository->store($data);
@@ -206,12 +208,12 @@ class AttachmentController extends Controller
/**
* Update the specified resource in storage.
*
* @param AttachmentRequest $request
* @param Attachment $attachment
* @param AttachmentUpdateRequest $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function update(AttachmentRequest $request, Attachment $attachment): JsonResponse
public function update(AttachmentUpdateRequest $request, Attachment $attachment): JsonResponse
{
$data = $request->getAll();
$this->repository->update($attachment, $data);
@@ -230,8 +232,8 @@ class AttachmentController extends Controller
/**
* Upload an attachment.
*
* @param Request $request
* @codeCoverageIgnore
* @param Request $request
* @param Attachment $attachment
*
* @return JsonResponse

View File

@@ -42,7 +42,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AvailableBudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AvailableBudgetController extends Controller
{
@@ -50,7 +50,9 @@ class AvailableBudgetController extends Controller
private $repository;
/**
* AccountController constructor.
* AvailableBudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -72,6 +74,8 @@ class AvailableBudgetController extends Controller
*
* @param AvailableBudget $availableBudget
*
* @codeCoverageIgnore
*
* @return JsonResponse
*/
public function delete(AvailableBudget $availableBudget): JsonResponse
@@ -87,6 +91,7 @@ class AvailableBudgetController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -97,21 +102,11 @@ class AvailableBudgetController extends Controller
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of available budgets. Count it and split it.
$collection = $this->repository->getAvailableBudgets();
// filter list on start and end date, if present.
// TODO: put this in the query.
$start = $this->parameters->get('start');
$end = $this->parameters->get('end');
if (null !== $start && null !== $end) {
$collection = $collection->filter(
function (AvailableBudget $availableBudget) use ($start, $end) {
return $availableBudget->start_date->gte($start) && $availableBudget->end_date->lte($end);
}
);
}
// get list of available budgets. Count it and split it.
$collection = $this->repository->getAvailableBudgetsByDate($start, $end);
$count = $collection->count();
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -135,10 +130,11 @@ class AvailableBudgetController extends Controller
/**
* Display the specified resource.
*
* @param Request $request
* @param AvailableBudget $availableBudget
* @param Request $request
* @param AvailableBudget $availableBudget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, AvailableBudget $availableBudget): JsonResponse
{
@@ -191,7 +187,7 @@ class AvailableBudgetController extends Controller
* Update the specified resource in storage.
*
* @param AvailableBudgetRequest $request
* @param AvailableBudget $availableBudget
* @param AvailableBudget $availableBudget
*
* @return JsonResponse
*/

View File

@@ -26,14 +26,14 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\BillRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\BillTransformer;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -47,6 +47,8 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BillController.
*
*
*/
class BillController extends Controller
{
@@ -56,6 +58,8 @@ class BillController extends Controller
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -78,9 +82,10 @@ class BillController extends Controller
* Display a listing of the resource.
*
* @param Request $request
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function attachments(Request $request, Bill $bill): JsonResponse
{
@@ -114,9 +119,10 @@ class BillController extends Controller
/**
* Remove the specified resource from storage.
*
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Bill $bill): JsonResponse
{
@@ -131,6 +137,7 @@ class BillController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -157,9 +164,10 @@ class BillController extends Controller
* List all of them.
*
* @param Request $request
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(Request $request, Bill $bill): JsonResponse
{
@@ -198,9 +206,10 @@ class BillController extends Controller
* Show the specified bill.
*
* @param Request $request
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Bill $bill): JsonResponse
{
@@ -250,9 +259,10 @@ class BillController extends Controller
*
* @param Request $request
*
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Bill $bill): JsonResponse
{
@@ -267,24 +277,35 @@ class BillController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setBills(new Collection([$bill]));
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// include source + destination account name and type.
->setBill($bill)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
// do parameter stuff on new group collector.
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
// get paginator.
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.bills.transactions', [$bill->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -297,7 +318,7 @@ class BillController extends Controller
* Update a bill.
*
* @param BillRequest $request
* @param Bill $bill
* @param Bill $bill
*
* @return JsonResponse
*/

View File

@@ -23,16 +23,17 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use Exception;
use FireflyIII\Api\V1\Requests\BudgetLimitRequest;
use FireflyIII\Api\V1\Requests\BudgetRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\Transformers\BudgetTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -46,7 +47,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BudgetController extends Controller
{
@@ -56,6 +57,8 @@ class BudgetController extends Controller
/**
* BudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -76,11 +79,11 @@ class BudgetController extends Controller
/**
* Display a listing of the resource.
*
* @param Request $request
* @param Budget $budget
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function budgetLimits(Request $request, Budget $budget): JsonResponse
{
@@ -113,6 +116,7 @@ class BudgetController extends Controller
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Budget $budget): JsonResponse
{
@@ -127,6 +131,7 @@ class BudgetController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -163,9 +168,10 @@ class BudgetController extends Controller
* Show a budget.
*
* @param Request $request
* @param Budget $budget
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Budget $budget): JsonResponse
{
@@ -189,6 +195,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(BudgetRequest $request): JsonResponse
{
@@ -213,9 +220,9 @@ class BudgetController extends Controller
* Store a newly created resource in storage.
*
* @param BudgetLimitRequest $request
* @param Budget $budget
*
* @param Budget $budget
* @return JsonResponse
* @throws Exception
*/
public function storeBudgetLimit(BudgetLimitRequest $request, Budget $budget): JsonResponse
{
@@ -240,9 +247,10 @@ class BudgetController extends Controller
*
* @param Request $request
*
* @param Budget $budget
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Budget $budget): JsonResponse
{
@@ -264,25 +272,33 @@ class BudgetController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setBudget($budget);
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on budget.
->setBudget($budget)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.budgets.transactions', [$budget->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
@@ -296,7 +312,7 @@ class BudgetController extends Controller
* Update a budget.
*
* @param BudgetRequest $request
* @param Budget $budget
* @param Budget $budget
*
* @return JsonResponse
*/

View File

@@ -26,12 +26,12 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\BudgetLimitRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -43,11 +43,10 @@ use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BudgetLimitController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BudgetLimitController extends Controller
{
@@ -56,7 +55,9 @@ class BudgetLimitController extends Controller
private $repository;
/**
* AccountController constructor.
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -79,6 +80,7 @@ class BudgetLimitController extends Controller
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(BudgetLimit $budgetLimit): JsonResponse
{
@@ -93,6 +95,7 @@ class BudgetLimitController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -131,10 +134,11 @@ class BudgetLimitController extends Controller
/**
* Display the specified resource.
*
* @param Request $request
* @param Request $request
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
@@ -158,6 +162,7 @@ class BudgetLimitController extends Controller
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(BudgetLimitRequest $request): JsonResponse
{
@@ -184,10 +189,11 @@ class BudgetLimitController extends Controller
/**
* Show all transactions.
*
* @param Request $request
* @param Request $request
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
@@ -202,21 +208,31 @@ class BudgetLimitController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setBudget($budgetLimit->budget);
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on budget.
->setBudget($budgetLimit->budget)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.budget_limits.transactions', [$budgetLimit->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -229,7 +245,7 @@ class BudgetLimitController extends Controller
* Update the specified resource in storage.
*
* @param BudgetLimitRequest $request
* @param BudgetLimit $budgetLimit
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
*/

View File

@@ -25,14 +25,12 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\CategoryRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\CategoryTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -46,7 +44,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CategoryController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class CategoryController extends Controller
{
@@ -56,6 +54,8 @@ class CategoryController extends Controller
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -80,6 +80,7 @@ class CategoryController extends Controller
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Category $category): JsonResponse
{
@@ -94,6 +95,7 @@ class CategoryController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -131,10 +133,11 @@ class CategoryController extends Controller
/**
* Show the category.
*
* @param Request $request
* @param Request $request
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Category $category): JsonResponse
{
@@ -181,11 +184,12 @@ class CategoryController extends Controller
/**
* Show all transactions.
*
* @param Request $request
* @param Request $request
*
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Category $category): JsonResponse
{
@@ -200,28 +204,33 @@ class CategoryController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setCategory($category);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on category.
->setCategory($category)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.categories.transactions', [$category->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -234,7 +243,7 @@ class CategoryController extends Controller
* Update the category.
*
* @param CategoryRequest $request
* @param Category $category
* @param Category $category
*
* @return JsonResponse
*/

View File

@@ -26,22 +26,22 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
/**
* Class AccountController
*/
class AccountController extends Controller
{
use ApiSupport;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** @var AccountRepositoryInterface */
@@ -49,6 +49,7 @@ class AccountController extends Controller
/**
* AccountController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -69,22 +70,19 @@ class AccountController extends Controller
}
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function expenseOverview(Request $request): JsonResponse
public function expenseOverview(DateRequest $request): JsonResponse
{
// parameters for chart:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
$start->subDay();
// prep some vars:
@@ -128,7 +126,7 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
@@ -156,32 +154,31 @@ class AccountController extends Controller
return response()->json($chartData);
}
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function overview(Request $request): JsonResponse
public function overview(DateRequest $request): JsonResponse
{
// parameters for chart:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
// user's preferences
$defaultSet = $this->repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
$default = app('amount')->getDefaultCurrency();
if (0 === \count($frontPage->data)) {
// @codeCoverageIgnoreStart
if (0 === count($frontPage->data)) {
$frontPage->data = $defaultSet;
$frontPage->save();
}
// @codeCoverageIgnoreEnd
// get accounts:
$accounts = $this->repository->getAccountsById($frontPage->data);
@@ -190,7 +187,7 @@ class AccountController extends Controller
foreach ($accounts as $account) {
$currency = $this->repository->getAccountCurrency($account);
if (null === $currency) {
$currency = $default;
$currency = $default; // @codeCoverageIgnore
}
$currentSet = [
'label' => $account->name,
@@ -202,7 +199,7 @@ class AccountController extends Controller
'yAxisID' => 0, // 0, 1, 2
'entries' => [],
];
/** @var Carbon $currentStart */
$currentStart = clone $start;
$range = app('steam')->balanceInRange($account, $start, clone $end);
$previous = round(array_values($range)[0], 12);
@@ -221,22 +218,19 @@ class AccountController extends Controller
}
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function revenueOverview(Request $request): JsonResponse
public function revenueOverview(DateRequest $request): JsonResponse
{
// parameters for chart:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
$start->subDay();
// prep some vars:
@@ -267,7 +261,8 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => bcmul($diff, '-1'),
'diff_float' => (float)$diff * -1,
// For some reason this line is never covered in code coverage:
'diff_float' => ((float)$diff) * -1, // @codeCoverageIgnore
'currency_id' => $currencyId,
];
}
@@ -280,7 +275,7 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
@@ -308,41 +303,4 @@ class AccountController extends Controller
return response()->json($chartData);
}
/**
* Small helper function for the revenue and expense account charts.
* TODO should include Trait instead of doing this.
*
* @param array $names
*
* @return array
*/
protected function expandNames(array $names): array
{
$result = [];
foreach ($names as $entry) {
$result[$entry['name']] = 0;
}
return $result;
}
/**
* Small helper function for the revenue and expense account charts.
* TODO should include Trait instead of doing this.
*
* @param Collection $accounts
*
* @return array
*/
protected function extractNames(Collection $accounts): array
{
$return = [];
/** @var Account $account */
foreach ($accounts as $account) {
$return[$account->id] = $account->name;
}
return $return;
}
}

View File

@@ -42,6 +42,7 @@ class AvailableBudgetController extends Controller
/**
* AvailableBudgetController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{

View File

@@ -26,11 +26,10 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
/**
@@ -43,6 +42,7 @@ class CategoryController extends Controller
/**
* AccountController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -61,21 +61,22 @@ class CategoryController extends Controller
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
* TODO after 4.8,0, simplify
*/
public function overview(Request $request): JsonResponse
public function overview(DateRequest $request): JsonResponse
{
// parameters for chart:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$tempData = [];
$spent = $this->categoryRepository->spentInPeriodPerCurrency(new Collection, new Collection, $start, $end);
$earned = $this->categoryRepository->earnedInPeriodPerCurrency(new Collection, new Collection, $start, $end);
@@ -127,7 +128,7 @@ class CategoryController extends Controller
'entries' => [],
];
}
$amount = round($income['spent'], $decimalPlaces);
$amount = round($income['earned'], $decimalPlaces);
$categories[$categoryName] = isset($categories[$categoryName]) ? $categories[$categoryName] + $amount : $amount;
$tempData[$key]['entries'][$categoryName]
= $amount;

View File

@@ -32,6 +32,7 @@ use Illuminate\Http\JsonResponse;
/**
* Class ConfigurationController.
* @codeCoverageIgnore
*/
class ConfigurationController extends Controller
{
@@ -41,7 +42,8 @@ class ConfigurationController extends Controller
private $repository;
/**
* BudgetController constructor.
* ConfigurationController constructor.
*
*/
public function __construct()
{
@@ -78,10 +80,9 @@ class ConfigurationController extends Controller
* Update the configuration.
*
* @param ConfigurationRequest $request
* @param string $name
* @param string $name
*
* @return JsonResponse
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function update(ConfigurationRequest $request, string $name): JsonResponse
{
@@ -96,7 +97,6 @@ class ConfigurationController extends Controller
* Get all config values.
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getConfigData(): array
{

View File

@@ -37,7 +37,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* Class Controller.
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.NumberOfChildren)
*
*/
class Controller extends BaseController
{
@@ -61,7 +61,6 @@ class Controller extends BaseController
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function buildParams(): string
{
@@ -86,7 +85,6 @@ class Controller extends BaseController
* Method to grab all parameters from the URI.
*
* @return ParameterBag
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getParameters(): ParameterBag
{

View File

@@ -26,18 +26,14 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\CurrencyRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -55,7 +51,7 @@ use FireflyIII\Transformers\CurrencyExchangeRateTransformer;
use FireflyIII\Transformers\CurrencyTransformer;
use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -70,7 +66,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CurrencyController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class CurrencyController extends Controller
{
@@ -82,6 +78,7 @@ class CurrencyController extends Controller
/**
* CurrencyRepository constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -104,10 +101,11 @@ class CurrencyController extends Controller
/**
* Display a list of accounts.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function accounts(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -130,7 +128,7 @@ class CurrencyController extends Controller
// filter list on currency preference:
$collection = $unfiltered->filter(
function (Account $account) use ($currency, $accountRepository) {
static function (Account $account) use ($currency, $accountRepository) {
$currencyId = (int)$accountRepository->getMetaValue($account, 'currency_id');
return $currencyId === $currency->id;
@@ -161,11 +159,12 @@ class CurrencyController extends Controller
/**
* Display a listing of the resource.
*
* @param Request $request
* @param Request $request
*
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function availableBudgets(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -180,18 +179,11 @@ class CurrencyController extends Controller
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of available budgets. Count it and split it.
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$repository->setUser($admin);
$unfiltered = $repository->getAvailableBudgets();
// filter list.
$collection = $unfiltered->filter(
function (AvailableBudget $availableBudget) use ($currency) {
return $availableBudget->transaction_currency_id === $currency->id;
}
);
$collection = $repository->getAvailableBudgetsByCurrency($currency);
$count = $collection->count();
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -216,10 +208,11 @@ class CurrencyController extends Controller
/**
* List all bills
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function bills(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -236,7 +229,7 @@ class CurrencyController extends Controller
// filter and paginate list:
$collection = $unfiltered->filter(
function (Bill $bill) use ($currency) {
static function (Bill $bill) use ($currency) {
return $bill->transaction_currency_id === $currency->id;
}
);
@@ -263,29 +256,21 @@ class CurrencyController extends Controller
/**
* List all budget limits
*
* @param Request $request
* @param Request $request
*
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function budgetLimits(Request $request, TransactionCurrency $currency): JsonResponse
{
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$manager = new Manager;
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$unfiltered = $repository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end'));
// TODO replace this
// filter budget limits on currency ID
$collection = $unfiltered->filter(
function (BudgetLimit $budgetLimit) use ($currency) {
return $budgetLimit->transaction_currency_id === $currency->id;
}
);
$repository = app(BudgetRepositoryInterface::class);
$manager = new Manager;
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $repository->getAllBudgetLimitsByCurrency($currency, $this->parameters->get('start'), $this->parameters->get('end'));
$count = $collection->count();
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
@@ -306,10 +291,11 @@ class CurrencyController extends Controller
/**
* Show a list of known exchange rates
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function cer(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -341,10 +327,11 @@ class CurrencyController extends Controller
/**
* Remove the specified resource from storage.
*
* @param TransactionCurrency $currency
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*/
public function delete(TransactionCurrency $currency): JsonResponse
{
@@ -366,10 +353,11 @@ class CurrencyController extends Controller
/**
* Disable a currency.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function disable(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -398,10 +386,11 @@ class CurrencyController extends Controller
/**
* Enable a currency.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function enable(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -429,6 +418,7 @@ class CurrencyController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -460,10 +450,11 @@ class CurrencyController extends Controller
/**
* Make the currency a default currency.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function makeDefault(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -491,11 +482,12 @@ class CurrencyController extends Controller
/**
* List all recurring transactions.
*
* @param Request $request
* @param Request $request
*
* @param TransactionCurrency $currency
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function recurrences(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -513,7 +505,7 @@ class CurrencyController extends Controller
// filter selection
$collection = $unfiltered->filter(
function (Recurrence $recurrence) use ($currency) {
static function (Recurrence $recurrence) use ($currency) {
/** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions as $transaction) {
if ($transaction->transaction_currency_id === $currency->id || $transaction->foreign_currency_id === $currency->id) {
@@ -550,10 +542,11 @@ class CurrencyController extends Controller
/**
* List all of them.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -567,7 +560,7 @@ class CurrencyController extends Controller
$unfiltered = $repository->getAll();
$collection = $unfiltered->filter(
function (Rule $rule) use ($currency) {
static function (Rule $rule) use ($currency) {
/** @var RuleTrigger $trigger */
foreach ($rule->ruleTriggers as $trigger) {
if ('currency_is' === $trigger->trigger_type && $currency->name === $trigger->trigger_value) {
@@ -603,10 +596,11 @@ class CurrencyController extends Controller
/**
* Show a currency.
*
* @param Request $request
* @param Request $request
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -663,11 +657,12 @@ class CurrencyController extends Controller
/**
* Show all transactions.
*
* @param Request $request
* @param Request $request
*
* @param TransactionCurrency $currency
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, TransactionCurrency $currency): JsonResponse
{
@@ -682,28 +677,33 @@ class CurrencyController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setCurrency($currency);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on currency.
->setCurrency($currency)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -715,7 +715,7 @@ class CurrencyController extends Controller
/**
* Update a currency.
*
* @param CurrencyRequest $request
* @param CurrencyRequest $request
* @param TransactionCurrency $currency
*
* @return JsonResponse

View File

@@ -37,6 +37,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CurrencyExchangeRateController
* @codeCoverageIgnore
*/
class CurrencyExchangeRateController extends Controller
{
@@ -45,6 +46,7 @@ class CurrencyExchangeRateController extends Controller
/**
* CurrencyExchangeRateController constructor.
*
*/
public function __construct()
{
@@ -88,6 +90,7 @@ class CurrencyExchangeRateController extends Controller
throw new FireflyException('Unknown destination currency.');
}
/** @var Carbon $dateObj */
$dateObj = Carbon::createFromFormat('Y-m-d', $request->get('date') ?? date('Y-m-d'));
$this->parameters->set('from', $fromCurrency->code);
$this->parameters->set('to', $toCurrency->code);

View File

@@ -23,14 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\ImportJobTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -52,7 +50,8 @@ class ImportController extends Controller
private $repository;
/**
* LinkTypeController constructor.
* ImportController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -73,6 +72,7 @@ class ImportController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function listAll(Request $request): JsonResponse
{
@@ -104,10 +104,11 @@ class ImportController extends Controller
}
/**
* @param Request $request
* @param Request $request
* @param ImportJob $importJob
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, ImportJob $importJob): JsonResponse
{
@@ -127,10 +128,11 @@ class ImportController extends Controller
/**
* Show all transactions
*
* @param Request $request
* @param Request $request
* @param ImportJob $importJob
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, ImportJob $importJob): JsonResponse
{
@@ -151,29 +153,33 @@ class ImportController extends Controller
if (null !== $tag) {
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setTag($tag);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on tag.
->setTag($tag)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
}
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');

View File

@@ -25,15 +25,13 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\LinkTypeRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\LinkType;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\LinkTypeTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -47,7 +45,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class LinkTypeController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class LinkTypeController extends Controller
{
@@ -60,6 +58,8 @@ class LinkTypeController extends Controller
/**
* LinkTypeController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -84,6 +84,7 @@ class LinkTypeController extends Controller
*
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*/
public function delete(LinkType $linkType): JsonResponse
{
@@ -100,7 +101,8 @@ class LinkTypeController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -135,10 +137,11 @@ class LinkTypeController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param LinkType $linkType
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, LinkType $linkType): JsonResponse
{
@@ -190,10 +193,11 @@ class LinkTypeController extends Controller
/**
* Delete the resource.
*
* @param Request $request
* @param Request $request
* @param LinkType $linkType
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, LinkType $linkType): JsonResponse
{
@@ -211,28 +215,33 @@ class LinkTypeController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setJournalIds($journalIds);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on journal IDs.
->setJournalIds($journalIds)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -246,7 +255,7 @@ class LinkTypeController extends Controller
* Update object.
*
* @param LinkTypeRequest $request
* @param LinkType $linkType
* @param LinkType $linkType
*
* @return JsonResponse
* @throws FireflyException

View File

@@ -42,7 +42,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class PiggyBankController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class PiggyBankController extends Controller
{
@@ -52,6 +52,8 @@ class PiggyBankController extends Controller
/**
* PiggyBankController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -76,6 +78,7 @@ class PiggyBankController extends Controller
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(PiggyBank $piggyBank): JsonResponse
{
@@ -89,7 +92,8 @@ class PiggyBankController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -126,10 +130,11 @@ class PiggyBankController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function piggyBankEvents(Request $request, PiggyBank $piggyBank): JsonResponse
{
@@ -161,10 +166,11 @@ class PiggyBankController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, PiggyBank $piggyBank): JsonResponse
{
@@ -214,7 +220,7 @@ class PiggyBankController extends Controller
* Update piggy bank.
*
* @param PiggyBankRequest $request
* @param PiggyBank $piggyBank
* @param PiggyBank $piggyBank
*
* @return JsonResponse
*/

View File

@@ -45,12 +45,14 @@ class PreferenceController extends Controller
{
/**
* LinkTypeController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
static function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$repository = app(AccountRepositoryInterface::class);
@@ -59,7 +61,7 @@ class PreferenceController extends Controller
// an important fallback is that the frontPageAccount array gets refilled automatically
// when it turns up empty.
$frontPageAccounts = app('preferences')->getForUser($user, 'frontPageAccounts', [])->data;
if (0 === \count($frontPageAccounts)) {
if (0 === count($frontPageAccounts)) {
/** @var Collection $accounts */
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$accountIds = $accounts->pluck('id')->toArray();
@@ -76,7 +78,8 @@ class PreferenceController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -85,7 +88,7 @@ class PreferenceController extends Controller
$available = [
'language', 'customFiscalYear', 'fiscalYearStart', 'currencyPreference',
'transaction_journal_optional_fields', 'frontPageAccounts', 'viewRange',
'listPageSize, twoFactorAuthEnabled',
'listPageSize',
];
$preferences = new Collection;
@@ -111,17 +114,16 @@ class PreferenceController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* Return a single preference by name.
*
* @param Request $request
* @param Request $request
* @param Preference $preference
*
* @return JsonResponse
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @codeCoverageIgnore
*/
public function show(Request $request, Preference $preference): JsonResponse
{
@@ -144,10 +146,9 @@ class PreferenceController extends Controller
* Update a preference.
*
* @param PreferenceRequest $request
* @param Preference $preference
* @param Preference $preference
*
* @return JsonResponse
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function update(PreferenceRequest $request, Preference $preference): JsonResponse
{
@@ -165,7 +166,6 @@ class PreferenceController extends Controller
$newValue = (int)$data['data'];
break;
case 'customFiscalYear':
case 'twoFactorAuthEnabled':
$newValue = 1 === (int)$data['data'];
break;
}

View File

@@ -23,17 +23,16 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\RecurrenceRequest;
use FireflyIII\Api\V1\Requests\RecurrenceStoreRequest;
use FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -56,6 +55,8 @@ class RecurrenceController extends Controller
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -80,6 +81,7 @@ class RecurrenceController extends Controller
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Recurrence $recurrence): JsonResponse
{
@@ -93,7 +95,8 @@ class RecurrenceController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -130,10 +133,11 @@ class RecurrenceController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Recurrence $recurrence): JsonResponse
{
@@ -155,13 +159,13 @@ class RecurrenceController extends Controller
/**
* Store new object.
*
* @param RecurrenceRequest $request
* @param RecurrenceStoreRequest $request
*
* @return JsonResponse
*/
public function store(RecurrenceRequest $request): JsonResponse
public function store(RecurrenceStoreRequest $request): JsonResponse
{
$recurrence = $this->repository->store($request->getAll());
$recurrence = $this->repository->store($request->getAllRecurrenceData());
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
@@ -178,10 +182,11 @@ class RecurrenceController extends Controller
/**
* Show transactions for this recurrence.
*
* @param Request $request
* @param Request $request
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Recurrence $recurrence): JsonResponse
{
@@ -199,28 +204,32 @@ class RecurrenceController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setJournalIds($journalIds);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on journal IDs.
->setJournalIds($journalIds)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -232,6 +241,7 @@ class RecurrenceController extends Controller
/**
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*/
public function trigger(): JsonResponse
{
@@ -256,14 +266,14 @@ class RecurrenceController extends Controller
/**
* Update single recurrence.
*
* @param RecurrenceRequest $request
* @param Recurrence $recurrence
* @param RecurrenceUpdateRequest $request
* @param Recurrence $recurrence
*
* @return JsonResponse
*/
public function update(RecurrenceRequest $request, Recurrence $recurrence): JsonResponse
public function update(RecurrenceUpdateRequest $request, Recurrence $recurrence): JsonResponse
{
$data = $request->getAll();
$data = $request->getAllRecurrenceData();
$category = $this->repository->update($recurrence, $data);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';

View File

@@ -23,22 +23,22 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use Carbon\Carbon;
use FireflyIII\Api\V1\Requests\RuleRequest;
use FireflyIII\Api\V1\Requests\RuleTestRequest;
use FireflyIII\Api\V1\Requests\RuleTriggerRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Models\AccountType;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngine;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Manager;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
@@ -48,6 +48,7 @@ use Log;
/**
* Class RuleController
*
*/
class RuleController extends Controller
{
@@ -58,6 +59,7 @@ class RuleController extends Controller
/**
* RuleController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -84,6 +86,7 @@ class RuleController extends Controller
* @param Rule $rule
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Rule $rule): JsonResponse
{
@@ -97,7 +100,8 @@ class RuleController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -135,9 +139,10 @@ class RuleController extends Controller
* List single resource.
*
* @param Request $request
* @param Rule $rule
* @param Rule $rule
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Rule $rule): JsonResponse
{
@@ -179,55 +184,32 @@ class RuleController extends Controller
}
/**
* @param Request $request
* @param Rule $rule
* @param RuleTestRequest $request
* @param Rule $rule
*
* @return JsonResponse
* @throws FireflyException
*/
public function testRule(Request $request, Rule $rule): JsonResponse
public function testRule(RuleTestRequest $request, Rule $rule): JsonResponse
{
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$page = 0 === (int)$request->query('page') ? 1 : (int)$request->query('page');
$startDate = null === $request->query('start_date') ? null : Carbon::createFromFormat('Y-m-d', $request->query('start_date'));
$endDate = null === $request->query('end_date') ? null : Carbon::createFromFormat('Y-m-d', $request->query('end_date'));
$searchLimit = 0 === (int)$request->query('search_limit') ? (int)config('firefly.test-triggers.limit') : (int)$request->query('search_limit');
$triggerLimit = 0 === (int)$request->query('triggered_limit') ? (int)config('firefly.test-triggers.range') : (int)$request->query('triggered_limit');
$accountList = '' === (string)$request->query('accounts') ? [] : explode(',', $request->query('accounts'));
$accounts = new Collection;
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $this->accountRepository->findNull((int)$accountId);
if (null !== $account && AccountType::ASSET === $account->accountType->type) {
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
if (null === $account) {
Log::debug(sprintf('No asset account with id "%s"', $accountId));
}
}
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$parameters = $request->getTestParameters();
/** @var Rule $rule */
Log::debug(sprintf('Now testing rule #%d, "%s"', $rule->id, $rule->title));
/** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class);
// set all parameters:
$matcher->setRule($rule);
$matcher->setStartDate($startDate);
$matcher->setEndDate($endDate);
$matcher->setSearchLimit($searchLimit);
$matcher->setTriggeredLimit($triggerLimit);
$matcher->setAccounts($accounts);
$matcher->setStartDate($parameters['start_date']);
$matcher->setEndDate($parameters['end_date']);
$matcher->setSearchLimit($parameters['search_limit']);
$matcher->setTriggeredLimit($parameters['trigger_limit']);
$matcher->setAccounts($parameters['accounts']);
$matchingTransactions = $matcher->findTransactionsByRule();
$matchingTransactions = $matchingTransactions->unique('id');
// make paginator out of results.
$count = $matchingTransactions->count();
$transactions = $matchingTransactions->slice(($page - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($transactions, $count, $pageSize, $this->parameters->get('page'));
$count = count($matchingTransactions);
$transactions = array_slice($matchingTransactions, ($parameters['page'] - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($transactions, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rules.test', [$rule->id]) . $this->buildParams());
// resulting list is presented as JSON thing.
@@ -235,8 +217,8 @@ class RuleController extends Controller
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($matchingTransactions, $transformer, 'transactions');
@@ -248,45 +230,38 @@ class RuleController extends Controller
/**
* Execute the given rule group on a set of existing transactions.
*
* @param Request $request
* @param Rule $rule
* @param RuleTriggerRequest $request
* @param Rule $rule
*
* @return JsonResponse
*/
public function triggerRule(Request $request, Rule $rule): JsonResponse
public function triggerRule(RuleTriggerRequest $request, Rule $rule): JsonResponse
{
// Get parameters specified by the user
/** @var User $user */
$user = auth()->user();
$startDate = new Carbon($request->get('start_date'));
$endDate = new Carbon($request->get('end_date'));
$accountList = '' === (string)$request->query('accounts') ? [] : explode(',', $request->query('accounts'));
$accounts = new Collection;
$parameters = $request->getTriggerParameters();
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $this->accountRepository->findNull((int)$accountId);
if (null !== $account && $this->accountRepository->isAsset($account)) {
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
if (null === $account) {
Log::debug(sprintf('No asset account with id "%s"', $accountId));
}
/** @var RuleEngine $ruleEngine */
$ruleEngine = app(RuleEngine::class);
$ruleEngine->setUser(auth()->user());
$rules = [$rule->id];
$ruleEngine->setRulesToApply($rules);
$ruleEngine->setTriggerMode(RuleEngine::TRIGGER_STORE);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($parameters['accounts']);
$collector->setRange($parameters['start_date'], $parameters['end_date']);
$journals = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($journals as $journal) {
Log::debug('Start of new journal.');
$ruleEngine->processJournalArray($journal);
Log::debug('Done with all rules for this group + done with journal.');
}
// Create a job to do the work asynchronously
$job = new ExecuteRuleOnExistingTransactions($rule);
// Apply parameters to the job
$job->setUser($user);
$job->setAccounts($accounts);
$job->setStartDate($startDate);
$job->setEndDate($endDate);
// Dispatch a new job to execute it in a queue
$this->dispatch($job);
return response()->json([], 204);
}
@@ -294,13 +269,59 @@ class RuleController extends Controller
* Update a rule.
*
* @param RuleRequest $request
* @param Rule $rule
* @param Rule $rule
*
* @return JsonResponse
*/
public function update(RuleRequest $request, Rule $rule): JsonResponse
{
$rule = $this->ruleRepository->update($rule, $request->getAll());
$rule = $this->ruleRepository->update($rule, $request->getAll());
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* @param Request $request
* @param Rule $rule
* @return JsonResponse
*/
public function moveDown(Request $request, Rule $rule): JsonResponse
{
$this->ruleRepository->moveDown($rule);
$rule = $this->ruleRepository->find($rule->id);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* @param Request $request
* @param Rule $rule
* @return JsonResponse
*/
public function moveUp(Request $request, Rule $rule): JsonResponse
{
$this->ruleRepository->moveUp($rule);
$rule = $this->ruleRepository->find($rule->id);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));

View File

@@ -23,19 +23,21 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use Carbon\Carbon;
use Exception;
use FireflyIII\Api\V1\Requests\RuleGroupRequest;
use FireflyIII\Api\V1\Requests\RuleGroupTestRequest;
use FireflyIII\Api\V1\Requests\RuleGroupTriggerRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Models\AccountType;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngine;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -48,7 +50,6 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
use Log;
/**
* Class RuleGroupController
*/
@@ -61,6 +62,7 @@ class RuleGroupController extends Controller
/**
* RuleGroupController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -87,6 +89,7 @@ class RuleGroupController extends Controller
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(RuleGroup $ruleGroup): JsonResponse
{
@@ -100,7 +103,8 @@ class RuleGroupController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -134,10 +138,11 @@ class RuleGroupController extends Controller
}
/**
* @param Request $request
* @param Request $request
* @param RuleGroup $group
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(Request $request, RuleGroup $group): JsonResponse
{
@@ -174,10 +179,11 @@ class RuleGroupController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, RuleGroup $ruleGroup): JsonResponse
{
@@ -220,23 +226,24 @@ class RuleGroupController extends Controller
}
/**
* @param Request $request
* @param RuleGroupTestRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function testGroup(Request $request, RuleGroup $group): JsonResponse
public function testGroup(RuleGroupTestRequest $request, RuleGroup $group): JsonResponse
{
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
Log::debug('Now in testGroup()');
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
if (0 === $rules->count()) {
throw new FireflyException('No rules in this rule group.');
}
$parameters = $this->getTestParameters($request);
$accounts = $this->getAccountParameter($parameters['account_list']);
$matchingTransactions = new Collection;
$parameters = $request->getTestParameters();
$matchingTransactions = [];
Log::debug(sprintf('Going to test %d rules', $rules->count()));
/** @var Rule $rule */
@@ -250,18 +257,19 @@ class RuleGroupController extends Controller
$matcher->setEndDate($parameters['end_date']);
$matcher->setSearchLimit($parameters['search_limit']);
$matcher->setTriggeredLimit($parameters['trigger_limit']);
$matcher->setAccounts($accounts);
$matcher->setAccounts($parameters['accounts']);
$result = $matcher->findTransactionsByRule();
$matchingTransactions = $result->merge($matchingTransactions);
$result = $matcher->findTransactionsByRule();
/** @noinspection AdditionOperationOnArraysInspection */
$matchingTransactions = $result + $matchingTransactions;
}
$matchingTransactions = $matchingTransactions->unique('id');
// make paginator out of results.
$count = $matchingTransactions->count();
$transactions = $matchingTransactions->slice(($parameters['page'] - 1) * $parameters['page_size'], $parameters['page_size']);
$count = count($matchingTransactions);
$transactions = array_slice($matchingTransactions, ($parameters['page'] - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($transactions, $count, $parameters['page_size'], $parameters['page']);
$paginator = new LengthAwarePaginator($transactions, $count, $pageSize, $parameters['page']);
$paginator->setPath(route('api.v1.rule_groups.test', [$group->id]) . $this->buildParams());
// resulting list is presented as JSON thing.
@@ -269,8 +277,7 @@ class RuleGroupController extends Controller
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($matchingTransactions, $transformer, 'transactions');
@@ -282,47 +289,42 @@ class RuleGroupController extends Controller
/**
* Execute the given rule group on a set of existing transactions.
*
* @param Request $request
* @param RuleGroupTriggerRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws Exception
*/
public function triggerGroup(Request $request, RuleGroup $group): JsonResponse
public function triggerGroup(RuleGroupTriggerRequest $request, RuleGroup $group): JsonResponse
{
// Get parameters specified by the user
/** @var User $user */
$user = auth()->user();
$startDate = new Carbon($request->get('start_date'));
$endDate = new Carbon($request->get('end_date'));
$accountList = '' === (string)$request->query('accounts') ? [] : explode(',', $request->query('accounts'));
$accounts = new Collection;
$parameters = $request->getTriggerParameters();
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $this->accountRepository->findNull((int)$accountId);
if (null !== $account && AccountType::ASSET === $account->accountType->type) {
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
if (null === $account) {
Log::debug(sprintf('No asset account with id "%s"', $accountId));
}
/** @var Collection $collection */
$collection = $this->ruleGroupRepository->getActiveRules($group);
$rules = [];
/** @var Rule $item */
foreach ($collection as $item) {
$rules[] = $item->id;
}
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
foreach ($rules as $rule) {
// Create a job to do the work asynchronously
$job = new ExecuteRuleOnExistingTransactions($rule);
// start looping.
/** @var RuleEngine $ruleEngine */
$ruleEngine = app(RuleEngine::class);
$ruleEngine->setUser(auth()->user());
$ruleEngine->setRulesToApply($rules);
$ruleEngine->setTriggerMode(RuleEngine::TRIGGER_STORE);
// Apply parameters to the job
$job->setUser($user);
$job->setAccounts($accounts);
$job->setStartDate($startDate);
$job->setEndDate($endDate);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($parameters['accounts']);
$collector->setRange($parameters['start_date'], $parameters['end_date']);
$journals = $collector->getExtractedJournals();
// Dispatch a new job to execute it in a queue
$this->dispatch($job);
/** @var array $journal */
foreach ($journals as $journal) {
Log::debug('Start of new journal.');
$ruleEngine->processJournalArray($journal);
Log::debug('Done with all rules for this group + done with journal.');
}
return response()->json([], 204);
@@ -330,10 +332,9 @@ class RuleGroupController extends Controller
/**
* Update a rule group.
* TODO update order of rule group
*
* @param RuleGroupRequest $request
* @param RuleGroup $ruleGroup
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
*/
@@ -351,51 +352,49 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* @param array $accounts
*
* @return Collection
*/
private function getAccountParameter(array $accounts): Collection
{
$return = new Collection;
foreach ($accounts as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $this->accountRepository->findNull((int)$accountId);
if (null !== $account && AccountType::ASSET === $account->accountType->type) {
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$return->push($account);
}
if (null === $account) {
Log::debug(sprintf('No asset account with id "%s"', $accountId));
}
}
return $return;
}
/**
* @param Request $request
*
* @return array
* @param RuleGroup $ruleGroup
* @return JsonResponse
*/
private function getTestParameters(Request $request): array
public function moveDown(Request $request, RuleGroup $ruleGroup): JsonResponse
{
return [
'page_size' => (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data,
'page' => 0 === (int)$request->query('page') ? 1 : (int)$request->query('page'),
'start_date' => null === $request->query('start_date') ? null : Carbon::createFromFormat('Y-m-d', $request->query('start_date')),
'end_date' => null === $request->query('end_date') ? null : Carbon::createFromFormat('Y-m-d', $request->query('end_date')),
'search_limit' => 0 === (int)$request->query('search_limit') ? (int)config('firefly.test-triggers.limit') : (int)$request->query('search_limit'),
'trigger_limit' => 0 === (int)$request->query('triggered_limit')
? (int)config('firefly.test-triggers.range')
: (int)$request->query(
'triggered_limit'
),
'account_list' => '' === (string)$request->query('accounts') ? [] : explode(',', $request->query('accounts')),
];
$this->ruleGroupRepository->moveDown($ruleGroup);
$ruleGroup = $this->ruleGroupRepository->find($ruleGroup->id);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* @param Request $request
* @param RuleGroup $ruleGroup
* @return JsonResponse
*/
public function moveUp(Request $request, RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->moveUp($ruleGroup);
$ruleGroup = $this->ruleGroupRepository->find($ruleGroup->id);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
}

View File

@@ -26,12 +26,12 @@ namespace FireflyIII\Api\V1\Controllers;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use Exception;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -40,7 +40,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
/**
@@ -58,7 +57,8 @@ class SummaryController extends Controller
private $currencyRepos;
/**
* AccountController constructor.
* SummaryController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -84,21 +84,19 @@ class SummaryController extends Controller
}
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
* @throws Exception
*/
public function basic(Request $request): JsonResponse
public function basic(DateRequest $request): JsonResponse
{
// parameters for boxes:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
$dates = $request->getAll();
$start = $dates['start'];
$end = $dates['end'];
$code = $request->get('currency_code');
// balance information:
$balanceData = $this->getBalanceInformation($start, $end);
$billData = $this->getBillInformation($start, $end);
@@ -106,9 +104,15 @@ class SummaryController extends Controller
$networthData = $this->getNetWorthInfo($start, $end);
$total = array_merge($balanceData, $billData, $spentData, $networthData);
// TODO: liabilities with icon line-chart
// give new keys
$return = [];
foreach ($total as $entry) {
if (null === $code || (null !== $code && $code === $entry['currency_code'])) {
$return[$entry['key']] = $entry;
}
}
return response()->json($total);
return response()->json($return);
}
@@ -121,7 +125,6 @@ class SummaryController extends Controller
* @param Carbon $end
*
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
{
@@ -137,25 +140,6 @@ class SummaryController extends Controller
return $result;
}
/**
* This method will scroll through the results of the spentInPeriodMc() array and return the correct info.
*
* @param array $spentInfo
* @param TransactionCurrency $currency
*
* @return float
*/
private function findInSpentArray(array $spentInfo, TransactionCurrency $currency): float
{
foreach ($spentInfo as $array) {
if ($array['currency_id'] === $currency->id) {
return $array['amount'];
}
}
return 0.0;
}
/**
* @param Carbon $start
* @param Carbon $end
@@ -170,36 +154,47 @@ class SummaryController extends Controller
$sums = [];
$return = [];
// collect income of user:
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)
->setTypes([TransactionType::DEPOSIT])
->withOpposingAccount();
$set = $collector->getTransactions();
/** @var Transaction $transaction */
foreach ($set as $transaction) {
$currencyId = (int)$transaction->transaction_currency_id;
// collect income of user using the new group collector.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setRange($start, $end)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::DEPOSIT]);
$set = $collector->getExtractedJournals();
/** @var array $transactionJournal */
foreach ($set as $transactionJournal) {
$currencyId = (int)$transactionJournal['currency_id'];
$incomes[$currencyId] = $incomes[$currencyId] ?? '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], $transaction->transaction_amount);
$incomes[$currencyId] = bcadd($incomes[$currencyId], bcmul($transactionJournal['amount'], '-1'));
$sums[$currencyId] = $sums[$currencyId] ?? '0';
$sums[$currencyId] = bcadd($sums[$currencyId], $transaction->transaction_amount);
$sums[$currencyId] = bcadd($sums[$currencyId], bcmul($transactionJournal['amount'], '-1'));
}
// collect expenses:
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)
->setTypes([TransactionType::WITHDRAWAL])
->withOpposingAccount();
$set = $collector->getTransactions();
/** @var Transaction $transaction */
foreach ($set as $transaction) {
$currencyId = (int)$transaction->transaction_currency_id;
// collect expenses of user using the new group collector.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setRange($start, $end)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes([TransactionType::WITHDRAWAL]);
$set = $collector->getExtractedJournals();
/** @var array $transactionJournal */
foreach ($set as $transactionJournal) {
$currencyId = (int)$transactionJournal['currency_id'];
$expenses[$currencyId] = $expenses[$currencyId] ?? '0';
$expenses[$currencyId] = bcadd($expenses[$currencyId], $transaction->transaction_amount);
$expenses[$currencyId] = bcadd($expenses[$currencyId], $transactionJournal['amount']);
$sums[$currencyId] = $sums[$currencyId] ?? '0';
$sums[$currencyId] = bcadd($sums[$currencyId], $transaction->transaction_amount);
$sums[$currencyId] = bcadd($sums[$currencyId], $transactionJournal['amount']);
}
// format amounts:
@@ -315,6 +310,7 @@ class SummaryController extends Controller
* @param Carbon $end
*
* @return array
* @throws Exception
*/
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
{
@@ -354,6 +350,25 @@ class SummaryController extends Controller
return $return;
}
/**
* This method will scroll through the results of the spentInPeriodMc() array and return the correct info.
*
* @param array $spentInfo
* @param TransactionCurrency $currency
*
* @return float
*/
private function findInSpentArray(array $spentInfo, TransactionCurrency $currency): float
{
foreach ($spentInfo as $array) {
if ($array['currency_id'] === $currency->id) {
return $array['amount'];
}
}
return 0.0; // @codeCoverageIgnore
}
/**
* @param Carbon $start
* @param Carbon $end
@@ -389,7 +404,7 @@ class SummaryController extends Controller
$netWorthSet = $netWorthHelper->getNetWorthByCurrency($filtered, $date);
$return = [];
foreach ($netWorthSet as $index => $data) {
foreach ($netWorthSet as $data) {
/** @var TransactionCurrency $currency */
$currency = $data['currency'];
$amount = round($data['balance'], $currency->decimal_places);

View File

@@ -24,20 +24,19 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use Carbon\Carbon;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Api\V1\Requests\TagRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\TagTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Manager;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
@@ -55,7 +54,9 @@ class TagController extends Controller
private $repository;
/**
* RuleController constructor.
* TagController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -74,52 +75,22 @@ class TagController extends Controller
}
/**
* @param Request $request
* @param DateRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function cloud(Request $request): JsonResponse
public function cloud(DateRequest $request): JsonResponse
{
// parameters for cloud:
$start = (string)$request->get('start');
$end = (string)$request->get('end');
if ('' === $start || '' === $end) {
throw new FireflyException('Start and end are mandatory parameters.');
}
$start = Carbon::createFromFormat('Y-m-d', $start);
$end = Carbon::createFromFormat('Y-m-d', $end);
// parameters for boxes:
$dates = $request->getAll();
$start = $dates['start'];
$end = $dates['end'];
// get all tags:
$tags = $this->repository->get();
$min = null;
$max = 0;
$return = [
'tags' => [],
];
/** @var Tag $tag */
foreach ($tags as $tag) {
$earned = (float)$this->repository->earnedInPeriod($tag, $start, $end);
$spent = (float)$this->repository->spentInPeriod($tag, $start, $end);
$size = ($spent * -1) + $earned;
$min = $min ?? $size;
if ($size > 0) {
$max = $size > $max ? $size : $max;
$return['tags'][] = [
'tag' => $tag->tag,
'id' => $tag->id,
'size' => $size,
];
}
}
foreach ($return['tags'] as $index => $info) {
$return['tags'][$index]['relative'] = $return['tags'][$index]['size'] / $max;
}
$return['min'] = $min;
$return['max'] = $max;
$tags = $this->repository->get();
$cloud = $this->getTagCloud($tags, $start, $end);
return response()->json($return);
return response()->json($cloud);
}
/**
@@ -128,6 +99,7 @@ class TagController extends Controller
* @param Tag $tag
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Tag $tag): JsonResponse
{
@@ -141,7 +113,8 @@ class TagController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -178,9 +151,10 @@ class TagController extends Controller
* List single resource.
*
* @param Request $request
* @param Tag $tag
* @param Tag $tag
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Tag $tag): JsonResponse
{
@@ -225,9 +199,10 @@ class TagController extends Controller
* Show all transactions.
*
* @param Request $request
* @param Tag $tag
* @param Tag $tag
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Tag $tag): JsonResponse
{
@@ -242,28 +217,32 @@ class TagController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setTag($tag);
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on tag.
->setTag($tag)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -276,7 +255,7 @@ class TagController extends Controller
* Update a rule.
*
* @param TagRequest $request
* @param Tag $tag
* @param Tag $tag
*
* @return JsonResponse
*/
@@ -295,4 +274,54 @@ class TagController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
/**
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
* @return array
*/
private function getTagCloud(Collection $tags, Carbon $start, Carbon $end): array
{
$min = null;
$max = 0;
$cloud = [
'tags' => [],
];
/** @var Tag $tag */
foreach ($tags as $tag) {
$earned = (float)$this->repository->earnedInPeriod($tag, $start, $end);
$spent = (float)$this->repository->spentInPeriod($tag, $start, $end);
$size = ($spent * -1) + $earned;
$min = $min ?? $size;
if ($size > 0) {
$max = $size > $max ? $size : $max;
$cloud['tags'][] = [
'tag' => $tag->tag,
'id' => $tag->id,
'size' => $size,
];
}
}
$cloud = $this->analyseTagCloud($cloud, $min, $max);
return $cloud;
}
/**
* @param array $cloud
* @param float $min
* @param float $max
* @return array
*/
private function analyseTagCloud(array $cloud, float $min, float $max): array
{
foreach (array_keys($cloud['tags']) as $index) {
$cloud['tags'][$index]['relative'] = round($cloud['tags'][$index]['size'] / $max, 4);
}
$cloud['min'] = $min;
$cloud['max'] = $max;
return $cloud;
}
}

View File

@@ -24,43 +24,51 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\TransactionRequest;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Api\V1\Requests\TransactionStoreRequest;
use FireflyIII\Api\V1\Requests\TransactionUpdateRequest;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\PiggyBankEventTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use League\Fractal\Manager;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionController
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TransactionController extends Controller
{
use TransactionFilter;
/** @var TransactionGroupRepositoryInterface Group repository. */
private $groupRepository;
/** @var JournalRepositoryInterface The journal repository */
private $repository;
/** @var JournalAPIRepositoryInterface Journal API repos */
private $journalAPIRepository;
/**
* TransactionController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -70,9 +78,12 @@ class TransactionController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var JournalRepositoryInterface repository */
$this->repository = app(JournalRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
$this->journalAPIRepository = app(JournalAPIRepositoryInterface::class);
$this->repository->setUser($admin);
$this->groupRepository->setUser($admin);
$this->journalAPIRepository->setUser($admin);
return $next($request);
}
@@ -80,18 +91,19 @@ class TransactionController extends Controller
}
/**
* @param Request $request
* @param Transaction $transaction
* @param Request $request
* @param TransactionJournal $transactionJournal
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function attachments(Request $request, Transaction $transaction): JsonResponse
public function attachments(Request $request, TransactionJournal $transactionJournal): JsonResponse
{
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$attachments = $this->repository->getAttachmentsByTr($transaction);
$attachments = $this->journalAPIRepository->getAttachments($transactionJournal);
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
@@ -106,14 +118,29 @@ class TransactionController extends Controller
/**
* Remove the specified resource from storage.
*
* @param \FireflyIII\Models\Transaction $transaction
* @param TransactionGroup $transactionGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Transaction $transaction): JsonResponse
public function delete(TransactionGroup $transactionGroup): JsonResponse
{
$journal = $transaction->transactionJournal;
$this->repository->destroy($journal);
$this->repository->destroyGroup($transactionGroup);
return response()->json([], 204);
}
/**
* Remove the specified resource from storage.
*
* @param TransactionJournal $transactionJournal
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function deleteJournal(TransactionJournal $transactionJournal): JsonResponse
{
$this->repository->destroyJournal($transactionJournal);
return response()->json([], 204);
}
@@ -124,6 +151,7 @@ class TransactionController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -138,27 +166,31 @@ class TransactionController extends Controller
/** @var User $admin */
$admin = auth()->user();
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($admin);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
if (\in_array(TransactionType::TRANSFER, $types, true)) {
$collector->removeFilter(InternalTransferFilter::class);
}
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// all info needed for the API:
->withAPIInformation()
// set page size:
->setLimit($pageSize)
// set page to retrieve
->setPage($this->parameters->get('page'))
// set types of transactions to return.
->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$collector->setTypes($types);
$paginator = $collector->getPaginatedTransactions();
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
@@ -168,18 +200,19 @@ class TransactionController extends Controller
}
/**
* @param Request $request
* @param Transaction $transaction
* @param Request $request
* @param TransactionJournal $transactionJournal
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function piggyBankEvents(Request $request, Transaction $transaction): JsonResponse
public function piggyBankEvents(Request $request, TransactionJournal $transactionJournal): JsonResponse
{
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$events = $this->repository->getPiggyBankEventsbyTr($transaction);
$events = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal);
/** @var PiggyBankEventTransformer $transformer */
$transformer = app(PiggyBankEventTransformer::class);
@@ -194,38 +227,38 @@ class TransactionController extends Controller
/**
* Show a single transaction.
*
* @param Request $request
* @param Transaction $transaction
* @param Request $request
* @param TransactionGroup $transactionGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, Transaction $transaction): JsonResponse
public function show(Request $request, TransactionGroup $transactionGroup): JsonResponse
{
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
// collect transactions using the journal collector
$collector = app(TransactionCollectorInterface::class);
$collector->setUser(auth()->user());
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
// filter on specific journals.
$collector->setJournals(new Collection([$transaction->transactionJournal]));
/** @var User $admin */
$admin = auth()->user();
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on transaction group.
->setTransactionGroup($transactionGroup)
// all info needed for the API:
->withAPIInformation();
// add filter to remove transactions:
$transactionType = $transaction->transactionJournal->transactionType->type;
if ($transactionType === TransactionType::WITHDRAWAL) {
$collector->addFilter(PositiveAmountFilter::class);
$selectedGroup = $collector->getGroups()->first();
if (null === $selectedGroup) {
throw new NotFoundHttpException();
}
if (!($transactionType === TransactionType::WITHDRAWAL)) {
$collector->addFilter(NegativeAmountFilter::class); // @codeCoverageIgnore
}
$transactions = $collector->getTransactions();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
@@ -233,48 +266,47 @@ class TransactionController extends Controller
/**
* Store a new transaction.
*
* @param TransactionRequest $request
* @param TransactionStoreRequest $request
*
* @param JournalRepositoryInterface $repository
*
* @throws FireflyException
* @return JsonResponse
* @throws FireflyException
*/
public function store(TransactionRequest $request, JournalRepositoryInterface $repository): JsonResponse
public function store(TransactionStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$data['user'] = auth()->user()->id;
$journal = $repository->store($data);
event(new StoredTransactionJournal($journal));
Log::channel('audit')
->info('Store new transaction over API.', $data);
$transactionGroup = $this->groupRepository->store($data);
event(new StoredTransactionGroup($transactionGroup));
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
// collect transactions using the journal collector
$collector = app(TransactionCollectorInterface::class);
$collector->setUser(auth()->user());
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
// filter on specific journals.
$collector->setJournals(new Collection([$journal]));
/** @var User $admin */
$admin = auth()->user();
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on transaction group.
->setTransactionGroup($transactionGroup)
// all info needed for the API:
->withAPIInformation();
// add filter to remove transactions:
$transactionType = $journal->transactionType->type;
if ($transactionType === TransactionType::WITHDRAWAL) {
$collector->addFilter(PositiveAmountFilter::class);
$selectedGroup = $collector->getGroups()->first();
if (null === $selectedGroup) {
throw new NotFoundHttpException(); // @codeCoverageIgnore
}
if (!($transactionType === TransactionType::WITHDRAWAL)) {
$collector->addFilter(NegativeAmountFilter::class);
}
$transactions = $collector->getTransactions();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
@@ -283,47 +315,42 @@ class TransactionController extends Controller
/**
* Update a transaction.
*
* @param TransactionRequest $request
* @param JournalRepositoryInterface $repository
* @param Transaction $transaction
* @param TransactionUpdateRequest $request
* @param TransactionGroup $transactionGroup
*
* @return JsonResponse
*/
public function update(TransactionRequest $request, JournalRepositoryInterface $repository, Transaction $transaction): JsonResponse
public function update(TransactionUpdateRequest $request, TransactionGroup $transactionGroup): JsonResponse
{
$data = $request->getAll();
$data['user'] = auth()->user()->id;
$journal = $repository->update($transaction->transactionJournal, $data);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
Log::debug('Now in update routine.');
$data = $request->getAll();
$transactionGroup = $this->groupRepository->update($transactionGroup, $data);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
event(new UpdatedTransactionJournal($journal));
event(new UpdatedTransactionGroup($transactionGroup));
// needs a lot of extra data to match the journal collector. Or just expand that one.
// collect transactions using the journal collector
$collector = app(TransactionCollectorInterface::class);
$collector->setUser(auth()->user());
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
// filter on specific journals.
$collector->setJournals(new Collection([$journal]));
/** @var User $admin */
$admin = auth()->user();
// use new group collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
->setUser($admin)
// filter on transaction group.
->setTransactionGroup($transactionGroup)
// all info needed for the API:
->withAPIInformation();
// add filter to remove transactions:
$transactionType = $journal->transactionType->type;
if ($transactionType === TransactionType::WITHDRAWAL) {
$collector->addFilter(PositiveAmountFilter::class);
$selectedGroup = $collector->getGroups()->first();
if (null === $selectedGroup) {
throw new NotFoundHttpException(); // @codeCoverageIgnore
}
if (!($transactionType === TransactionType::WITHDRAWAL)) {
$collector->addFilter(NegativeAmountFilter::class);
}
$transactions = $collector->getTransactions();
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');

View File

@@ -53,7 +53,8 @@ class TransactionLinkController extends Controller
private $repository;
/**
* JournalLinkController constructor.
* TransactionLinkController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -80,6 +81,7 @@ class TransactionLinkController extends Controller
* @param TransactionJournalLink $link
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(TransactionJournalLink $link): JsonResponse
{
@@ -93,7 +95,8 @@ class TransactionLinkController extends Controller
*
* @param Request $request
*
* @return JsonResponse]
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -102,7 +105,7 @@ class TransactionLinkController extends Controller
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
// read type from URI
$name = $request->get('name') ?? null;
$name = $request->get('name');
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
@@ -134,10 +137,11 @@ class TransactionLinkController extends Controller
/**
* List single resource.
*
* @param Request $request
* @param Request $request
* @param TransactionJournalLink $journalLink
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, TransactionJournalLink $journalLink): JsonResponse
{

View File

@@ -42,7 +42,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class UserController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class UserController extends Controller
{
@@ -52,6 +52,7 @@ class UserController extends Controller
/**
* UserController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -69,10 +70,11 @@ class UserController extends Controller
/**
* Remove the specified resource from storage.
*
* @param \FireflyIII\User $user
* @param User $user
*
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*/
public function delete(User $user): JsonResponse
{
@@ -92,6 +94,7 @@ class UserController extends Controller
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
@@ -127,9 +130,10 @@ class UserController extends Controller
* Show a single user.
*
* @param Request $request
* @param User $user
* @param User $user
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Request $request, User $user): JsonResponse
{
@@ -180,7 +184,7 @@ class UserController extends Controller
* Update a user.
*
* @param UserRequest $request
* @param User $user
* @param User $user
*
* @return JsonResponse
*/

View File

@@ -1,141 +0,0 @@
<?php
/**
* AccountRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\IsBoolean;
/**
* Class AccountRequest
*/
class AccountRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
$active = true;
$includeNetWorth = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('include_net_worth')) {
$includeNetWorth = $this->boolean('include_net_worth');
}
$data = [
'name' => $this->string('name'),
'active' => $active,
'include_net_worth' => $includeNetWorth,
'accountType' => $this->string('type'),
'account_type_id' => null,
'currency_id' => $this->integer('currency_id'),
'currency_code' => $this->string('currency_code'),
'virtualBalance' => $this->string('virtual_balance'),
'iban' => $this->string('iban'),
'BIC' => $this->string('bic'),
'accountNumber' => $this->string('account_number'),
'accountRole' => $this->string('account_role'),
'openingBalance' => $this->string('opening_balance'),
'openingBalanceDate' => $this->date('opening_balance_date'),
'ccType' => $this->string('credit_card_type'),
'ccMonthlyPaymentDate' => $this->string('monthly_payment_date'),
'notes' => $this->string('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];
if ('liability' === $data['accountType']) {
$data['openingBalance'] = bcmul($this->string('liability_amount'), '-1');
$data['openingBalanceDate'] = $this->date('liability_start_date');
$data['accountType'] = $this->string('liability_type');
$data['account_type_id'] = null;
}
return $data;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$accountRoles = implode(',', config('firefly.accountRoles'));
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
$rules = [
'name' => 'required|min:1|uniqueAccountForUser',
'type' => 'required|in:' . $types,
'iban' => 'iban|nullable',
'bic' => 'bic|nullable',
'account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser',
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',
'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'active' => [new IsBoolean],
'include_net_worth' => [new IsBoolean],
'account_role' => 'in:' . $accountRoles . '|required_if:type,asset',
'credit_card_type' => 'in:' . $ccPaymentTypes . '|required_if:account_role,ccAsset',
'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
'liability_amount' => 'required_if:type,liability|min:0|numeric',
'liability_start_date' => 'required_if:type,liability|date',
'interest' => 'required_if:type,liability|between:0,100|numeric',
'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',
'notes' => 'min:0|max:65536',
];
switch ($this->method()) {
default:
break;
case 'PUT':
case 'PATCH':
$account = $this->route()->parameter('account');
$rules['name'] .= ':' . $account->id;
$rules['account_number'] .= ':' . $account->id;
$rules['type'] = 'in:' . $types;
break;
}
return $rules;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* AccountStoreRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\IsBoolean;
/**
* Class AccountStoreRequest
* @codeCoverageIgnore
*/
class AccountStoreRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$accountRoles = implode(',', config('firefly.accountRoles'));
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
$rules = [
'name' => 'required|min:1|uniqueAccountForUser',
'type' => 'required|' . sprintf('in:%s', $types),
'iban' => 'iban|nullable',
'bic' => 'bic|nullable',
'account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser',
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',
'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'active' => [new IsBoolean],
'include_net_worth' => [new IsBoolean],
'account_role' => sprintf('in:%s|required_if:type,asset', $accountRoles),
'credit_card_type' => sprintf('in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),
'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
'liability_amount' => 'required_if:type,liability|min:0|numeric',
'liability_start_date' => 'required_if:type,liability|date',
'interest' => 'required_if:type,liability|between:0,100|numeric',
'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',
'notes' => 'min:0|max:65536',
];
return $rules;
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* AccountUpdateRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\IsBoolean;
/**
* Class AccountUpdateRequest
* @codeCoverageIgnore
*/
class AccountUpdateRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$account = $this->route()->parameter('account');
$accountRoles = implode(',', config('firefly.accountRoles'));
$types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));
$rules = [
'name' => sprintf('required|min:1|uniqueAccountForUser:%d', $account->id),
'type' => sprintf('in:%s', $types),
'iban' => 'iban|nullable',
'bic' => 'bic|nullable',
'account_number' => sprintf('between:1,255|nullable|uniqueAccountNumberForUser:%d', $account->id),
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',
'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'active' => [new IsBoolean],
'include_net_worth' => [new IsBoolean],
'account_role' => sprintf('in:%s|required_if:type,asset', $accountRoles),
'credit_card_type' => sprintf('in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),
'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
'liability_amount' => 'required_if:type,liability|min:0|numeric',
'liability_start_date' => 'required_if:type,liability|date',
'interest' => 'required_if:type,liability|between:0,100|numeric',
'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',
'notes' => 'min:0|max:65536',
];
return $rules;
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* AttachmentRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
* AttachmentStoreRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
@@ -25,14 +25,14 @@ namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Models\Bill;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Rules\IsValidAttachmentModel;
/**
* Class AttachmentRequest
* Class AttachmentStoreRequest
* @codeCoverageIgnore
*/
class AttachmentRequest extends Request
class AttachmentStoreRequest extends Request
{
/**
* Authorize logged in users.
@@ -69,31 +69,20 @@ class AttachmentRequest extends Request
public function rules(): array
{
$models = implode(
',', [
str_replace('FireflyIII\\Models\\', '', Bill::class),
str_replace('FireflyIII\\Models\\', '', ImportJob::class),
str_replace('FireflyIII\\Models\\', '', TransactionJournal::class),
str_replace('FireflyIII\\Models\\', '', Transaction::class),
]
',',
[
str_replace('FireflyIII\\Models\\', '', Bill::class),
str_replace('FireflyIII\\Models\\', '', ImportJob::class),
str_replace('FireflyIII\\Models\\', '', TransactionJournal::class),
]
);
$model = $this->string('model');
$rules = [
return [
'filename' => 'required|between:1,255',
'title' => 'between:1,255',
'notes' => 'between:1,65000',
'model' => sprintf('required|in:%s', $models),
'model_id' => ['required', 'numeric', new IsValidAttachmentModel($model)],
];
switch ($this->method()) {
default:
break;
case 'PUT':
case 'PATCH':
unset($rules['model'], $rules['model_id']);
$rules['filename'] = 'between:1,255';
break;
}
return $rules;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* AttachmentUpdateRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
/**
* ClassAttachmentUpdateRequest
*
* @codeCoverageIgnore
*/
class AttachmentUpdateRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
return [
'filename' => $this->string('filename'),
'title' => $this->string('title'),
'notes' => $this->string('notes'),
'model' => $this->string('model'),
'model_id' => $this->integer('model_id'),
];
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
return [
'filename' => 'between:1,255',
'title' => 'between:1,255',
'notes' => 'between:1,65000',
];
}
}

View File

@@ -25,6 +25,8 @@ namespace FireflyIII\Api\V1\Requests;
/**
* Class AvailableBudgetRequest
*
* @codeCoverageIgnore
*/
class AvailableBudgetRequest extends Request
{

View File

@@ -29,6 +29,10 @@ use Illuminate\Validation\Validator;
/**
* Class BillRequest
*
* TODO AFTER 4.8,0: split this into two request classes.
*
* @codeCoverageIgnore
*/
class BillRequest extends Request
{
@@ -76,6 +80,7 @@ class BillRequest extends Request
* The rules that the incoming request must be matched against.
*
* @return array
*
*/
public function rules(): array
{
@@ -88,7 +93,6 @@ class BillRequest extends Request
'date' => 'required|date',
'repeat_freq' => 'required|in:weekly,monthly,quarterly,half-year,yearly',
'skip' => 'between:0,31',
'automatch' => [new IsBoolean],
'active' => [new IsBoolean],
'notes' => 'between:1,65536',
];
@@ -108,14 +112,14 @@ class BillRequest extends Request
/**
* Configure the validator instance.
*
* @param Validator $validator
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
static function (Validator $validator) {
$data = $validator->getData();
$min = (float)($data['amount_min'] ?? 0);
$max = (float)($data['amount_max'] ?? 0);

View File

@@ -23,9 +23,11 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
/**
* Class BudgetLimitRequest
*
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class BudgetLimitRequest extends Request
{

View File

@@ -28,6 +28,8 @@ use FireflyIII\Rules\IsBoolean;
/**
* Class BudgetRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class BudgetRequest extends Request
{

View File

@@ -27,6 +27,8 @@ use FireflyIII\Models\Category;
/**
* Class CategoryRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class CategoryRequest extends Request
{

View File

@@ -28,6 +28,7 @@ use FireflyIII\Rules\IsBoolean;
/**
* Class ConfigurationRequest
* @codeCoverageIgnore
*/
class ConfigurationRequest extends Request
{

View File

@@ -28,6 +28,8 @@ use FireflyIII\Rules\IsBoolean;
/**
* Class CurrencyRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class CurrencyRequest extends Request
{

View File

@@ -1,7 +1,8 @@
<?php
/**
* ReconciliationUpdateRequest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* DateRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
@@ -18,54 +19,53 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Requests;
namespace FireflyIII\Api\V1\Requests;
/**
* Class ReconciliationUpdateRequest.
* Request class for end points that require date parameters.
*
* Class DateRequest
*/
class ReconciliationUpdateRequest extends Request
class DateRequest extends Request
{
/**
* Verify the request.
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow logged in users
// Only allow authenticated users
return auth()->check();
}
/**
* Returns and validates the data required to update a reconciliation.
* Get all data from the request.
*
* @return array
*/
public function getJournalData(): array
public function getAll(): array
{
$data = [
'tags' => explode(',', $this->string('tags')),
'amount' => $this->string('amount'),
'category' => $this->string('category'),
return [
'start' => $this->date('start'),
'end' => $this->date('end'),
];
return $data;
}
/**
* Rules for this request.
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$rules = [
'amount' => 'numeric|required',
'category' => 'between:1,255|nullable',
return [
'start' => 'required|date',
'end' => 'required|date|after:start',
];
return $rules;
}
}

View File

@@ -29,6 +29,8 @@ use Illuminate\Validation\Rule;
/**
*
* Class LinkTypeRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class LinkTypeRequest extends Request
{

View File

@@ -25,10 +25,13 @@ namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Rules\IsAssetAccountId;
use FireflyIII\Rules\ZeroOrMore;
/**
*
* Class PiggyBankRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class PiggyBankRequest extends Request
{
@@ -75,7 +78,7 @@ class PiggyBankRequest extends Request
'name' => 'required|between:1,255|uniquePiggyBankForUser',
'account_id' => ['required', 'belongsToUser:accounts', new IsAssetAccountId],
'target_amount' => 'required|numeric|more:0',
'current_amount' => 'numeric|more:0|lte:target_amount',
'current_amount' => ['numeric', new ZeroOrMore, 'lte:target_amount'],
'start_date' => 'date|nullable',
'target_date' => 'date|nullable|after:start_date',
'notes' => 'max:65000',

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Requests;
/**
*
* Class PreferenceRequest
* @codeCoverageIgnore
*/
class PreferenceRequest extends Request
{

View File

@@ -1,214 +0,0 @@
<?php
/**
* RecurrenceRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Validation\RecurrenceValidation;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
/**
* Class RecurrenceRequest
*/
class RecurrenceRequest extends Request
{
use RecurrenceValidation, TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
$active = true;
$applyRules = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('apply_rules')) {
$applyRules = $this->boolean('apply_rules');
}
$return = [
'recurrence' => [
'type' => $this->string('type'),
'title' => $this->string('title'),
'description' => $this->string('description'),
'first_date' => $this->date('first_date'),
'repeat_until' => $this->date('repeat_until'),
'repetitions' => $this->integer('nr_of_repetitions'),
'apply_rules' => $applyRules,
'active' => $active,
],
'meta' => [
'piggy_bank_id' => $this->integer('piggy_bank_id'),
'piggy_bank_name' => $this->string('piggy_bank_name'),
'tags' => explode(',', $this->string('tags')),
],
'transactions' => $this->getTransactionData(),
'repetitions' => $this->getRepetitionData(),
];
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$today = Carbon::now()->addDay();
return [
'type' => 'required|in:withdrawal,transfer,deposit',
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
'description' => 'between:1,65000',
'first_date' => sprintf('required|date|after:%s', $today->format('Y-m-d')),
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
'nr_of_repetitions' => 'numeric|between:1,31',
'tags' => 'between:1,64000',
'piggy_bank_id' => 'numeric',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
$this->validateOneTransaction($validator);
$this->validateOneRepetition($validator);
$this->validateRecurrenceRepetition($validator);
$this->validateRepetitionMoment($validator);
$this->validateForeignCurrencyInformation($validator);
$this->validateAccountInformation($validator);
}
);
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int)$repetition['skip'],
'weekend' => (int)$repetition['weekend'],
];
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = [
'amount' => $transaction['amount'],
'currency_id' => isset($transaction['currency_id']) ? (int)$transaction['currency_id'] : null,
'currency_code' => $transaction['currency_code'] ?? null,
'foreign_amount' => $transaction['foreign_amount'] ?? null,
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? (int)$transaction['foreign_currency_id'] : null,
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null,
'budget_name' => $transaction['budget_name'] ?? null,
'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null,
'category_name' => $transaction['category_name'] ?? null,
'source_id' => isset($transaction['source_id']) ? (int)$transaction['source_id'] : null,
'source_name' => isset($transaction['source_name']) ? (string)$transaction['source_name'] : null,
'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null,
'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null,
'description' => $transaction['description'],
];
}
return $return;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* RecurrenceStoreRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Validation\RecurrenceValidation;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
/**
* Class RecurrenceStoreRequest
*/
class RecurrenceStoreRequest extends Request
{
use RecurrenceValidation, TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
return $this->rulesRecurrence();
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
$this->validateOneRecurrenceTransaction($validator);
$this->validateOneRepetition($validator);
$this->validateRecurrenceRepetition($validator);
$this->validateRepetitionMoment($validator);
$this->validateForeignCurrencyInformation($validator);
$this->validateAccountInformation($validator);
}
);
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* RecurrenceUpdateRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Validation\RecurrenceValidation;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
/**
* Class RecurrenceUpdateRequest
*/
class RecurrenceUpdateRequest extends Request
{
use RecurrenceValidation, TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
return $this->rulesRecurrence();
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
$this->validateOneTransaction($validator);
$this->validateOneRepetition($validator);
$this->validateRecurrenceRepetition($validator);
$this->validateRepetitionMoment($validator);
$this->validateForeignCurrencyInformation($validator);
$this->validateAccountInformation($validator);
}
);
}
}

View File

@@ -24,16 +24,205 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Http\Requests\Request as FireflyIIIRequest;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
/**
* Class Request.
*
* Technically speaking this class does not have to be extended like this but who knows what the future brings.
*
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
class Request extends FireflyIIIRequest
{
/**
* @return array
*/
public function getAllAccountData(): array
{
$active = true;
$includeNetWorth = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('include_net_worth')) {
$includeNetWorth = $this->boolean('include_net_worth');
}
$data = [
'name' => $this->string('name'),
'active' => $active,
'include_net_worth' => $includeNetWorth,
'account_type' => $this->string('type'),
'account_type_id' => null,
'currency_id' => $this->integer('currency_id'),
'currency_code' => $this->string('currency_code'),
'virtual_balance' => $this->string('virtual_balance'),
'iban' => $this->string('iban'),
'BIC' => $this->string('bic'),
'account_number' => $this->string('account_number'),
'account_role' => $this->string('account_role'),
'opening_balance' => $this->string('opening_balance'),
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('credit_card_type'),
'cc_Monthly_payment_date' => $this->string('monthly_payment_date'),
'notes' => $this->string('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];
if ('liability' === $data['account_type']) {
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
$data['account_type'] = $this->string('liability_type');
$data['account_type_id'] = null;
}
return $data;
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAllRecurrenceData(): array
{
$active = true;
$applyRules = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
if (null !== $this->get('apply_rules')) {
$applyRules = $this->boolean('apply_rules');
}
$return = [
'recurrence' => [
'type' => $this->string('type'),
'title' => $this->string('title'),
'description' => $this->string('description'),
'first_date' => $this->date('first_date'),
'repeat_until' => $this->date('repeat_until'),
'repetitions' => $this->integer('nr_of_repetitions'),
'apply_rules' => $applyRules,
'active' => $active,
],
'meta' => [
'piggy_bank_id' => $this->integer('piggy_bank_id'),
'piggy_bank_name' => $this->string('piggy_bank_name'),
'tags' => explode(',', $this->string('tags')),
],
'transactions' => $this->getRecurrenceTransactionData(),
'repetitions' => $this->getRecurrenceRepetitionData(),
];
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
protected function rulesRecurrence(): array
{
$today = Carbon::now()->addDay();
return [
'type' => 'required|in:withdrawal,transfer,deposit',
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
'description' => 'between:1,65000',
'first_date' => sprintf('required|date|after:%s', $today->format('Y-m-d')),
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
'nr_of_repetitions' => 'numeric|between:1,31',
'tags' => 'between:1,64000',
'piggy_bank_id' => 'numeric',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
protected function getRecurrenceRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int)$repetition['skip'],
'weekend' => (int)$repetition['weekend'],
];
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
protected function getRecurrenceTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = [
'amount' => $transaction['amount'],
'currency_id' => isset($transaction['currency_id']) ? (int)$transaction['currency_id'] : null,
'currency_code' => $transaction['currency_code'] ?? null,
'foreign_amount' => $transaction['foreign_amount'] ?? null,
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? (int)$transaction['foreign_currency_id'] : null,
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null,
'budget_name' => $transaction['budget_name'] ?? null,
'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null,
'category_name' => $transaction['category_name'] ?? null,
'source_id' => isset($transaction['source_id']) ? (int)$transaction['source_id'] : null,
'source_name' => isset($transaction['source_name']) ? (string)$transaction['source_name'] : null,
'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null,
'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null,
'description' => $transaction['description'],
'type' => $this->string('type'),
];
}
return $return;
}
}

View File

@@ -28,8 +28,9 @@ use FireflyIII\Rules\IsBoolean;
/**
*
* @codeCoverageIgnore
* Class RuleGroupRequest
* TODO AFTER 4.8,0: split this into two request classes.
*/
class RuleGroupRequest extends Request
{

View File

@@ -0,0 +1,148 @@
<?php
/**
* RuleGroupTestRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class RuleGroupTestRequest
*/
class RuleGroupTestRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* @return array
*/
public function getTestParameters(): array
{
$return = [
'page' => $this->getPage(),
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'search_limit' => $this->getSearchLimit(),
'trigger_limit' => $this->getTriggerLimit(),
'accounts' => $this->getAccounts(),
];
return $return;
}
/**
* @return array
*/
public function rules(): array
{
return [];
}
/**
* @param string $field
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
/**
* @return int
*/
private function getPage(): int
{
return 0 === (int)$this->query('page') ? 1 : (int)$this->query('page');
}
/**
* @return int
*/
private function getSearchLimit(): int
{
return 0 === (int)$this->query('search_limit') ? (int)config('firefly.test-triggers.limit') : (int)$this->query('search_limit');
}
/**
* @return int
*/
private function getTriggerLimit(): int
{
return 0 === (int)$this->query('triggered_limit') ? (int)config('firefly.test-triggers.range') : (int)$this->query('triggered_limit');
}
/**
* @return Collection
*/
private function getAccounts(): Collection
{
$accountList = '' === (string)$this->query('accounts') ? [] : explode(',', $this->query('accounts'));
$accounts = new Collection;
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $accountRepository->findNull((int)$accountId);
if ($this->validAccount($account)) {
/** @noinspection NullPointerExceptionInspection */
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
}
return $accounts;
}
/**
* @param Account|null $account
* @return bool
*/
private function validAccount(?Account $account): bool
{
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* RuleGroupTriggerRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class RuleGroupTriggerRequest
*/
class RuleGroupTriggerRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* @return array
*/
public function getTriggerParameters(): array
{
$return = [
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'accounts' => $this->getAccounts(),
];
return $return;
}
/**
* @return array
*/
public function rules(): array
{
return [
'start_date' => 'required|date',
'end_date' => 'required|date|after:start_date',
];
}
/**
* @param string $field
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
/**
* @return Collection
*/
private function getAccounts(): Collection
{
$accountList = '' === (string)$this->query('accounts') ? [] : explode(',', $this->query('accounts'));
$accounts = new Collection;
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $accountRepository->findNull((int)$accountId);
if ($this->validAccount($account)) {
/** @noinspection NullPointerExceptionInspection */
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
}
return $accounts;
}
/**
* @param Account|null $account
* @return bool
*/
private function validAccount(?Account $account): bool
{
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}

View File

@@ -25,10 +25,12 @@ namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\IsBoolean;
use Illuminate\Validation\Validator;
use function is_array;
/**
* Class RuleRequest
*
*/
class RuleRequest extends Request
{
@@ -117,7 +119,7 @@ class RuleRequest extends Request
/**
* Configure the validator instance.
*
* @param Validator $validator
* @param Validator $validator
*
* @return void
*/
@@ -136,13 +138,13 @@ class RuleRequest extends Request
*
* @param Validator $validator
*/
protected function atLeastOneAction(Validator $validator): void
protected function atLeastOneTrigger(Validator $validator): void
{
$data = $validator->getData();
$actions = $data['actions'] ?? [];
$data = $validator->getData();
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (0 === \count($actions)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
if (0 === count($triggers)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
}
}
@@ -151,37 +153,16 @@ class RuleRequest extends Request
*
* @param Validator $validator
*/
protected function atLeastOneTrigger(Validator $validator): void
protected function atLeastOneAction(Validator $validator): void
{
$data = $validator->getData();
$triggers = $data['triggers'] ?? [];
// need at least one trugger
if (0 === \count($triggers)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
$data = $validator->getData();
$actions = $data['actions'] ?? [];
// need at least one trigger
if (0 === count($actions)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
}
}
/**
* @return array
*/
private function getRuleActions(): array
{
$actions = $this->get('actions');
$return = [];
if (\is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* @return array
*/
@@ -189,7 +170,7 @@ class RuleRequest extends Request
{
$triggers = $this->get('triggers');
$return = [];
if (\is_array($triggers)) {
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
@@ -202,4 +183,25 @@ class RuleRequest extends Request
return $return;
}
/**
* @return array
*/
private function getRuleActions(): array
{
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
}

View File

@@ -0,0 +1,148 @@
<?php
/**
* RuleTestRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class RuleTestRequest
*/
class RuleTestRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* @return array
*/
public function getTestParameters(): array
{
$return = [
'page' => $this->getPage(),
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'search_limit' => $this->getSearchLimit(),
'trigger_limit' => $this->getTriggerLimit(),
'accounts' => $this->getAccounts(),
];
return $return;
}
/**
* @return array
*/
public function rules(): array
{
return [];
}
/**
* @param string $field
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
/**
* @return int
*/
private function getPage(): int
{
return 0 === (int)$this->query('page') ? 1 : (int)$this->query('page');
}
/**
* @return int
*/
private function getSearchLimit(): int
{
return 0 === (int)$this->query('search_limit') ? (int)config('firefly.test-triggers.limit') : (int)$this->query('search_limit');
}
/**
* @return int
*/
private function getTriggerLimit(): int
{
return 0 === (int)$this->query('triggered_limit') ? (int)config('firefly.test-triggers.range') : (int)$this->query('triggered_limit');
}
/**
* @return Collection
*/
private function getAccounts(): Collection
{
$accountList = '' === (string)$this->query('accounts') ? [] : explode(',', $this->query('accounts'));
$accounts = new Collection;
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $accountRepository->findNull((int)$accountId);
if ($this->validAccount($account)) {
/** @noinspection NullPointerExceptionInspection */
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
}
return $accounts;
}
/**
* @param Account|null $account
* @return bool
*/
private function validAccount(?Account $account): bool
{
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* RuleTriggerRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class RuleTriggerRequest
*/
class RuleTriggerRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* @return array
*/
public function getTriggerParameters(): array
{
$return = [
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'accounts' => $this->getAccounts(),
];
return $return;
}
/**
* @return array
*/
public function rules(): array
{
return [
'start_date' => 'required|date',
'end_date' => 'required|date|after:start_date',
];
}
/**
* @param string $field
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
/**
* @return Collection
*/
private function getAccounts(): Collection
{
$accountList = '' === (string)$this->query('accounts') ? [] : explode(',', $this->query('accounts'));
$accounts = new Collection;
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
foreach ($accountList as $accountId) {
Log::debug(sprintf('Searching for asset account with id "%s"', $accountId));
$account = $accountRepository->findNull((int)$accountId);
if ($this->validAccount($account)) {
/** @noinspection NullPointerExceptionInspection */
Log::debug(sprintf('Found account #%d ("%s") and its an asset account', $account->id, $account->name));
$accounts->push($account);
}
}
return $accounts;
}
/**
* @param Account|null $account
* @return bool
*/
private function validAccount(?Account $account): bool
{
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}

View File

@@ -28,6 +28,10 @@ use FireflyIII\Models\Tag;
/**
* Class TagRequest
*
* @codeCoverageIgnore
*
* TODO AFTER 4.8,0: split this into two request classes.
*/
class TagRequest extends Request
{

View File

@@ -81,7 +81,7 @@ class TransactionLinkRequest extends Request
/**
* Configure the validator instance.
*
* @param Validator $validator
* @param Validator $validator
*
* @return void
*/

View File

@@ -1,222 +0,0 @@
<?php
/**
* TransactionRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsDateOrTime;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
/**
* Class TransactionRequest
*/
class TransactionRequest extends Request
{
use TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data. Is pretty complex because of all the ??-statements.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @return array
*/
public function getAll(): array
{
$data = [
'type' => $this->string('type'),
'date' => $this->dateTime('date'),
'description' => $this->string('description'),
'piggy_bank_id' => $this->integer('piggy_bank_id'),
'piggy_bank_name' => $this->string('piggy_bank_name'),
'bill_id' => $this->integer('bill_id'),
'bill_name' => $this->string('bill_name'),
'tags' => explode(',', $this->string('tags')),
'notes' => $this->string('notes'),
'sepa-cc' => $this->string('sepa_cc'),
'sepa-ct-op' => $this->string('sepa_ct_op'),
'sepa-ct-id' => $this->string('sepa_ct_id'),
'sepa-db' => $this->string('sepa_db'),
'sepa-country' => $this->string('sepa_country'),
'sepa-ep' => $this->string('sepa_ep'),
'sepa-ci' => $this->string('sepa_ci'),
'sepa-batch-id' => $this->string('sepa_batch_id'),
'interest_date' => $this->date('interest_date'),
'book_date' => $this->date('book_date'),
'process_date' => $this->date('process_date'),
'due_date' => $this->date('due_date'),
'payment_date' => $this->date('payment_date'),
'invoice_date' => $this->date('invoice_date'),
'internal_reference' => $this->string('internal_reference'),
'bunq_payment_id' => $this->string('bunq_payment_id'),
'external_id' => $this->string('external_id'),
'original-source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'transactions' => $this->getTransactionData(),
];
return $data;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function rules(): array
{
$rules = [
// basic fields for journal:
'type' => 'required|in:withdrawal,deposit,transfer,opening-balance,reconciliation',
'description' => 'between:1,255',
'date' => ['required', new IsDateOrTime],
'piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser],
'piggy_bank_name' => ['between:1,255', 'nullable', new BelongsUser],
'bill_id' => ['numeric', 'nullable', 'mustExist:bills,id', new BelongsUser],
'bill_name' => ['between:1,255', 'nullable', new BelongsUser],
'tags' => 'between:1,255',
// then, custom fields for journal
'notes' => 'min:1,max:50000|nullable',
// SEPA fields:
'sepa_cc' => 'min:1,max:255|nullable',
'sepa_ct_op' => 'min:1,max:255|nullable',
'sepa_ct_id' => 'min:1,max:255|nullable',
'sepa_db' => 'min:1,max:255|nullable',
'sepa_country' => 'min:1,max:255|nullable',
'sepa_ep' => 'min:1,max:255|nullable',
'sepa_ci' => 'min:1,max:255|nullable',
'sepa_batch_id' => 'min:1,max:255|nullable',
// dates
'interest_date' => 'date|nullable',
'book_date' => 'date|nullable',
'process_date' => 'date|nullable',
'due_date' => 'date|nullable',
'payment_date' => 'date|nullable',
'invoice_date' => 'date|nullable',
'internal_reference' => 'min:1,max:255|nullable',
'bunq_payment_id' => 'min:1,max:255|nullable',
'external_id' => 'min:1,max:255|nullable',
// transaction rules (in array for splits):
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.description' => 'nullable|between:1,255',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.budget_name' => ['between:1,255', 'nullable', new BelongsUser],
'transactions.*.category_id' => ['mustExist:categories,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.reconciled' => [new IsBoolean],
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
if ('PUT' === $this->method()) {
unset($rules['type'], $rules['piggy_bank_id'], $rules['piggy_bank_name']);
}
return $rules;
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
$this->validateOneTransaction($validator);
$this->validateDescriptions($validator);
$this->validateJournalDescription($validator);
$this->validateSplitDescriptions($validator);
$this->validateForeignCurrencyInformation($validator);
$this->validateAccountInformation($validator);
$this->validateSplitAccounts($validator);
}
);
}
/**
* Get transaction data.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @return array
*/
private function getTransactionData(): array
{
$return = [];
foreach ($this->get('transactions') as $index => $transaction) {
$return[] = [
'amount' => $transaction['amount'],
'description' => $transaction['description'] ?? null,
'currency_id' => isset($transaction['currency_id']) ? (int)$transaction['currency_id'] : null,
'currency_code' => $transaction['currency_code'] ?? null,
'foreign_amount' => $transaction['foreign_amount'] ?? null,
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? (int)$transaction['foreign_currency_id'] : null,
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null,
'budget_name' => $transaction['budget_name'] ?? null,
'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null,
'category_name' => $transaction['category_name'] ?? null,
'source_id' => isset($transaction['source_id']) ? (int)$transaction['source_id'] : null,
'source_name' => isset($transaction['source_name']) ? (string)$transaction['source_name'] : null,
'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null,
'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null,
'reconciled' => $this->convertBoolean((string)($transaction['reconciled'] ?? 'false')),
'identifier' => $index,
];
}
return $return;
}
}

View File

@@ -0,0 +1,278 @@
<?php
/**
* TransactionStoreRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsDateOrTime;
use FireflyIII\Support\NullArrayObject;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
/**
* Class TransactionStoreRequest
*/
class TransactionStoreRequest extends Request
{
use TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data. Is pretty complex because of all the ??-statements.
*
* @return array
*/
public function getAll(): array
{
$data = [
'group_title' => $this->string('group_title'),
'transactions' => $this->getTransactionData(),
];
return $data;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$rules = [
// basic fields for group:
'group_title' => 'between:1,255',
// transaction rules (in array for splits):
'transactions.*.type' => 'required|in:withdrawal,deposit,transfer,opening-balance,reconciliation',
'transactions.*.date' => ['required', new IsDateOrTime],
'transactions.*.order' => 'numeric|min:0',
// currency info
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
// amount
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
// description
'transactions.*.description' => 'nullable|between:1,255',
// source of transaction
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
// destination of transaction
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
// budget, category, bill and piggy
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.budget_name' => ['between:1,255', 'nullable', new BelongsUser],
'transactions.*.category_id' => ['mustExist:categories,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.bill_id' => ['numeric', 'nullable', 'mustExist:bills,id', new BelongsUser],
'transactions.*.bill_name' => ['between:1,255', 'nullable', new BelongsUser],
'transactions.*.piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser],
'transactions.*.piggy_bank_name' => ['between:1,255', 'nullable', new BelongsUser],
// other interesting fields
'transactions.*.reconciled' => [new IsBoolean],
'transactions.*.notes' => 'min:1,max:50000|nullable',
'transactions.*.tags' => 'between:1,255',
// meta info fields
'transactions.*.internal_reference' => 'min:1,max:255|nullable',
'transactions.*.external_id' => 'min:1,max:255|nullable',
'transactions.*.recurrence_id' => 'min:1,max:255|nullable',
'transactions.*.bunq_payment_id' => 'min:1,max:255|nullable',
// SEPA fields:
'transactions.*.sepa_cc' => 'min:1,max:255|nullable',
'transactions.*.sepa_ct_op' => 'min:1,max:255|nullable',
'transactions.*.sepa_ct_id' => 'min:1,max:255|nullable',
'transactions.*.sepa_db' => 'min:1,max:255|nullable',
'transactions.*.sepa_country' => 'min:1,max:255|nullable',
'transactions.*.sepa_ep' => 'min:1,max:255|nullable',
'transactions.*.sepa_ci' => 'min:1,max:255|nullable',
'transactions.*.sepa_batch_id' => 'min:1,max:255|nullable',
// dates
'transactions.*.interest_date' => 'date|nullable',
'transactions.*.book_date' => 'date|nullable',
'transactions.*.process_date' => 'date|nullable',
'transactions.*.due_date' => 'date|nullable',
'transactions.*.payment_date' => 'date|nullable',
'transactions.*.invoice_date' => 'date|nullable',
];
return $rules;
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator) {
// must submit at least one transaction.
$this->validateOneTransaction($validator);
// all journals must have a description
$this->validateDescriptions($validator);
// all transaction types must be equal:
$this->validateTransactionTypes($validator);
// validate foreign currency info
$this->validateForeignCurrencyInformation($validator);
// validate all account info
$this->validateAccountInformation($validator);
// validate source/destination is equal, depending on the transaction journal type.
$this->validateEqualAccounts($validator);
// the group must have a description if > 1 journal.
$this->validateGroupDescription($validator);
}
);
}
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $index => $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue($object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue($object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string)$object['amount']),
'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']),
// description.
'description' => $this->stringFromValue($object['description']),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->stringFromValue($object['source_name']),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->stringFromValue($object['destination_name']),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->stringFromValue($object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->stringFromValue($object['category_name']),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->stringFromValue($object['bill_name']),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue($object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->stringFromValue($object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->stringFromValue($object['internal_reference']),
'external_id' => $this->stringFromValue($object['external_id']),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->stringFromValue($object['bunq_payment_id']),
'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
'sepa_db' => $this->stringFromValue($object['sepa_db']),
'sepa_country' => $this->stringFromValue($object['sepa_country']),
'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
'process_date' => $this->dateFromValue($object['process_date']),
'due_date' => $this->dateFromValue($object['due_date']),
'payment_date' => $this->dateFromValue($object['payment_date']),
'invoice_date' => $this->dateFromValue($object['invoice_date']),
];
}
return $return;
}
}

View File

@@ -0,0 +1,324 @@
<?php
/**
* TransactionUpdateRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsDateOrTime;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
use Log;
/**
* Class TransactionUpdateRequest
*/
class TransactionUpdateRequest extends Request
{
use TransactionValidation;
/** @var array Array values. */
private $arrayFields;
/** @var array Boolean values. */
private $booleanFields;
/** @var array Fields that contain date values. */
private $dateFields;
/** @var array Fields that contain integer values. */
private $integerFields;
/** @var array Fields that contain string values. */
private $stringFields;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow authenticated users
return auth()->check();
}
/**
* Get all data. Is pretty complex because of all the ??-statements.
*
* @return array
*/
public function getAll(): array
{
$this->integerFields = [
'order',
'currency_id',
'foreign_currency_id',
'transaction_journal_id',
'source_id',
'destination_id',
'budget_id',
'category_id',
'bill_id',
'recurrence_id',
];
$this->dateFields = [
'date',
'interest_date',
'book_date',
'process_date',
'due_date',
'payment_date',
'invoice_date',
];
$this->stringFields = [
'type',
'currency_code',
'foreign_currency_code',
'amount',
'foreign_amount',
'description',
'source_name',
'destination_name',
'budget_name',
'category_name',
'bill_name',
'notes',
'internal_reference',
'external_id',
'bunq_payment_id',
'sepa_cc',
'sepa_ct_op',
'sepa_ct_id',
'sepa_db',
'sepa_country',
'sepa_ep',
'sepa_ci',
'sepa_batch_id',
];
$this->booleanFields = [
'reconciled',
];
$this->arrayFields = [
'tags',
];
$data = [
'transactions' => $this->getTransactionData(),
];
if ($this->has('group_title')) {
$data['group_title'] = $this->string('group_title');
}
return $data;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$rules = [
// basic fields for group:
'group_title' => 'between:1,255',
// transaction rules (in array for splits):
'transactions.*.type' => 'in:withdrawal,deposit,transfer,opening-balance,reconciliation',
'transactions.*.date' => [new IsDateOrTime],
'transactions.*.order' => 'numeric|min:0',
// currency info
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
// amount
'transactions.*.amount' => 'numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|gte:0',
// description
'transactions.*.description' => 'nullable|between:1,255',
// source of transaction
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
// destination of transaction
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
// budget, category, bill and piggy
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.budget_name' => ['between:1,255', 'nullable', new BelongsUser],
'transactions.*.category_id' => ['mustExist:categories,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.bill_id' => ['numeric', 'nullable', 'mustExist:bills,id', new BelongsUser],
'transactions.*.bill_name' => ['between:1,255', 'nullable', new BelongsUser],
// other interesting fields
'transactions.*.reconciled' => [new IsBoolean],
'transactions.*.notes' => 'min:1,max:50000|nullable',
'transactions.*.tags' => 'between:0,255',
// meta info fields
'transactions.*.internal_reference' => 'min:1,max:255|nullable',
'transactions.*.external_id' => 'min:1,max:255|nullable',
'transactions.*.recurrence_id' => 'min:1,max:255|nullable',
'transactions.*.bunq_payment_id' => 'min:1,max:255|nullable',
// SEPA fields:
'transactions.*.sepa_cc' => 'min:1,max:255|nullable',
'transactions.*.sepa_ct_op' => 'min:1,max:255|nullable',
'transactions.*.sepa_ct_id' => 'min:1,max:255|nullable',
'transactions.*.sepa_db' => 'min:1,max:255|nullable',
'transactions.*.sepa_country' => 'min:1,max:255|nullable',
'transactions.*.sepa_ep' => 'min:1,max:255|nullable',
'transactions.*.sepa_ci' => 'min:1,max:255|nullable',
'transactions.*.sepa_batch_id' => 'min:1,max:255|nullable',
// dates
'transactions.*.interest_date' => 'date|nullable',
'transactions.*.book_date' => 'date|nullable',
'transactions.*.process_date' => 'date|nullable',
'transactions.*.due_date' => 'date|nullable',
'transactions.*.payment_date' => 'date|nullable',
'transactions.*.invoice_date' => 'date|nullable',
];
return $rules;
}
/**
* Configure the validator instance.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
/** @var TransactionGroup $transactionGroup */
$transactionGroup = $this->route()->parameter('transactionGroup');
$validator->after(
function (Validator $validator) use ($transactionGroup) {
// must submit at least one transaction.
$this->validateOneTransaction($validator);
// if more than one, verify that there are journal ID's present.
$this->validateJournalIds($validator, $transactionGroup);
// all transaction types must be equal:
$this->validateTransactionTypesForUpdate($validator);
// validate source/destination is equal, depending on the transaction journal type.
$this->validateEqualAccountsForUpdate($validator, $transactionGroup);
// If type is set, source + destination info is mandatory.
// Not going to do this. Not sure where the demand came from.
// validate that the currency fits the source and/or destination account.
// validate all account info
$this->validateAccountInformationUpdate($validator);
// The currency info must match the accounts involved.
// Instead will ignore currency info as much as possible.
// TODO if the transaction_journal_id is empty, some fields are mandatory, like the amount!
// all journals must have a description
//$this->validateDescriptions($validator);
// // validate foreign currency info
// $this->validateForeignCurrencyInformation($validator);
//
//
//
// // make sure all splits have valid source + dest info
// $this->validateSplitAccounts($validator);
// the group must have a description if > 1 journal.
// $this->validateGroupDescription($validator);
}
);
}
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
Log::debug('Now in getTransactionData()');
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $index => $transaction) {
// default response is to update nothing in the transaction:
$current = [];
// for each field, add it to the array if a reference is present in the request:
foreach ($this->integerFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->integerFromValue((string)$transaction[$fieldName]);
}
}
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->stringFromValue((string)$transaction[$fieldName]);
}
}
foreach ($this->dateFields as $fieldName) {
Log::debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->dateFromValue((string)$transaction[$fieldName]);
Log::debug(sprintf('New value: "%s"', (string)$transaction[$fieldName]));
}
}
foreach ($this->booleanFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->convertBoolean((string)$transaction[$fieldName]);
}
}
foreach ($this->arrayFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
}
}
$return[] = $current;
}
return $return;
}
}

View File

@@ -31,6 +31,8 @@ use FireflyIII\User;
/**
* Class UserRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
*/
class UserRequest extends Request
{

View File

@@ -0,0 +1,83 @@
<?php
/**
* CorrectDatabase.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use Artisan;
use Illuminate\Console\Command;
use Schema;
/**
* Class CorrectDatabase
* @codeCoverageIgnore
*/
class CorrectDatabase extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Will correct the integrity of your database, if necessary.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:correct-database';
/**
* Execute the console command.
*/
public function handle(): int
{
// if table does not exist, return false
if (!Schema::hasTable('users')) {
return 1;
}
$commands = [
'firefly-iii:fix-piggies',
'firefly-iii:create-link-types',
'firefly-iii:create-access-tokens',
'firefly-iii:remove-bills',
'firefly-iii:enable-currencies',
'firefly-iii:fix-transfer-budgets',
'firefly-iii:fix-uneven-amount',
'firefly-iii:delete-zero-amount',
'firefly-iii:delete-orphaned-transactions',
'firefly-iii:delete-empty-journals',
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:rename-meta-fields',
];
foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command));
Artisan::call($command);
$result = Artisan::output();
echo $result;
}
return 0;
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* VerifySkeleton.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use Illuminate\Console\Command;
/**
* Class CorrectionSkeleton
*/
class CorrectionSkeleton extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'DESCRIPTION HERE';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:CORR_COMMAND';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
//
$this->warn('Congrats, you found the skeleton command. Boo!');
return 0;
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* CreateAccessTokens.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Console\Command;
/**
* Class CreateAccessTokens
*/
class CreateAccessTokens extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates user access tokens which are used for command line access to personal data.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:create-access-tokens';
/**
* Execute the console command.
*
* @return int
* @throws Exception
*/
public function handle(): int
{
// make repository:
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$start = microtime(true);
$count = 0;
$users = $repository->all();
/** @var User $user */
foreach ($users as $user) {
$pref = app('preferences')->getForUser($user, 'access_token', null);
if (null === $pref) {
$token = $user->generateAccessToken();
app('preferences')->setForUser($user, 'access_token', $token);
$this->line(sprintf('Generated access token for user %s', $user->email));
++$count;
}
}
if (0 === $count) {
$this->info('All access tokens OK!');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verify access tokens in %s seconds.', $end));
return 0;
}
}

View File

@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/**
* CreateLinkTypes.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\LinkType;
use Illuminate\Console\Command;
/**
* Class CreateLinkTypes. Created all link types in case a migration hasn't fired.
*/
class CreateLinkTypes extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates all link types.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:create-link-types';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): int
{
$start = microtime(true);
$count = 0;
$set = [
'Related' => ['relates to', 'relates to'],
'Refund' => ['(partially) refunds', 'is (partially) refunded by'],
'Paid' => ['(partially) pays for', 'is (partially) paid for by'],
'Reimbursement' => ['(partially) reimburses', 'is (partially) reimbursed by'],
];
foreach ($set as $name => $values) {
$link = LinkType::where('name', $name)
->first();
if (null === $link) {
$link = new LinkType;
$link->name = $name;
$link->inward = $values[1];
$link->outward = $values[0];
++$count;
$this->line(sprintf('Created missing link type "%s"', $name));
}
$link->editable = false;
$link->save();
}
if (0 === $count) {
$this->info('All link types OK!');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified link types in %s seconds', $end));
return 0;
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
* DeleteEmptyGroups.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
/**
* Class DeleteEmptyGroups
*/
class DeleteEmptyGroups extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete empty transaction groups.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:delete-empty-groups';
/**
* Execute the console command.
*
* @return mixed
* @throws Exception;
*/
public function handle(): int
{
$start = microtime(true);
$groups = array_unique(TransactionJournal::get(['transaction_group_id'])->pluck('transaction_group_id')->toArray());
$count = TransactionGroup::whereNull('deleted_at')->whereNotIn('id', $groups)->count();
if (0 === $count) {
$this->info('No empty transaction groups.');
}
if ($count > 0) {
$this->info(sprintf('Deleted %d empty transaction group(s).', $count));
TransactionGroup::whereNull('deleted_at')->whereNotIn('id', $groups)->delete();
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty groups in %s seconds', $end));
return 0;
}
}

View File

@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
/**
* DeleteEmptyJournals.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use DB;
use Exception;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Log;
/**
* Class DeleteEmptyJournals
*/
class DeleteEmptyJournals extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete empty and uneven transaction journals.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:delete-empty-journals';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->deleteUnevenJournals();
$this->deleteEmptyJournals();
return 0;
}
private function deleteEmptyJournals(): void
{
$start = microtime(true);
$count = 0;
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->whereNull('transactions.transaction_journal_id')
->get(['transaction_journals.id']);
foreach ($set as $entry) {
try {
TransactionJournal::find($entry->id)->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::info(sprintf('Could not delete entry: %s', $e->getMessage()));
}
// @codeCoverageIgnoreEnd
$this->info(sprintf('Deleted empty transaction journal #%d', $entry->id));
++$count;
}
if (0 === $count) {
$this->info('No empty transaction journals.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty journals in %s seconds', $end));
}
/**
* Delete transactions and their journals if they have an uneven number of transactions.
*/
private function deleteUnevenJournals(): void
{
$set = Transaction
::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id')
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']);
$total = 0;
foreach ($set as $row) {
$count = (int)$row->the_count;
if (1 === $count % 2) {
// uneven number, delete journal and transactions:
try {
TransactionJournal::find((int)$row->transaction_journal_id)->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::info(sprintf('Could not delete journal: %s', $e->getMessage()));
}
// @codeCoverageIgnoreEnd
Transaction::where('transaction_journal_id', (int)$row->transaction_journal_id)->delete();
$this->info(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id));
$total++;
}
}
if (0 === $total) {
$this->info('No uneven transaction journals.');
}
}
}

View File

@@ -0,0 +1,138 @@
<?php
declare(strict_types=1);
/**
* DeleteOrphanedTransactions.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Log;
use stdClass;
/**
* Deletes transactions where the journal has been deleted.
*/
class DeleteOrphanedTransactions extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Deletes orphaned transactions.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:delete-orphaned-transactions';
/**
* Execute the console command.
*
* @return int
* @throws Exception
*/
public function handle(): int
{
$start = microtime(true);
$this->deleteOrphanedTransactions();
$this->deleteFromOrphanedAccounts();
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified orphans in %s seconds', $end));
return 0;
}
/**
*
*/
private function deleteFromOrphanedAccounts(): void
{
$set
= Transaction
::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->whereNotNull('accounts.deleted_at')
->get(['transactions.*']);
$count = 0;
/** @var Transaction $transaction */
foreach ($set as $transaction) {
// delete journals
$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
if ($journal) {
try {
$journal->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::info(sprintf('Could not delete journal %s', $e->getMessage()));
}
// @codeCoverageIgnoreEnd
}
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
$this->line(
sprintf('Deleted transaction journal #%d because account #%d was already deleted.',
$transaction->transaction_journal_id, $transaction->account_id)
);
$count++;
}
if (0 === $count) {
$this->info('No orphaned accounts.');
}
}
/**
* @throws Exception
*/
private function deleteOrphanedTransactions(): void
{
$count = 0;
$set = Transaction
::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->whereNotNull('transaction_journals.deleted_at')
->whereNull('transactions.deleted_at')
->whereNotNull('transactions.id')
->get(
[
'transaction_journals.id as journal_id',
'transactions.id as transaction_id',
]
);
/** @var stdClass $entry */
foreach ($set as $entry) {
$transaction = Transaction::find((int)$entry->transaction_id);
$transaction->delete();
$this->info(
sprintf(
'Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.',
$entry->transaction_id,
$entry->journal_id
)
);
++$count;
}
if (0 === $count) {
$this->info('No orphaned transactions.');
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* DeleteZeroAmount.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
/**
* Class DeleteZeroAmount
*/
class DeleteZeroAmount extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete transactions with zero amount.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:delete-zero-amount';
/**
* Execute the console command.
* @return int
*/
public function handle(): int
{
$start = microtime(true);
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$set = array_unique($set);
/** @var Collection $journals */
$journals = TransactionJournal::whereIn('id', $set)->get();
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$this->info(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id));
try {
$journal->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
$this->line($e->getMessage());
}
// @codeCoverageIgnoreEnd
Transaction::where('transaction_journal_id', $journal->id)->delete();
}
if (0 === $journals->count()) {
$this->info('No zero-amount transaction journals.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified zero-amount integrity in %s seconds', $end));
return 0;
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
/**
* EnableCurrencies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
/**
* Class EnableCurrencies
*/
class EnableCurrencies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enables all currencies in use.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:enable-currencies';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): int
{
$start = microtime(true);
$found = [];
// get all meta entries
/** @var Collection $meta */
$meta = AccountMeta::where('name', 'currency_id')->groupBy('data')->get(['data']);
foreach ($meta as $entry) {
$found[] = (int)$entry->data;
}
// get all from journals:
/** @var Collection $journals */
$journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
foreach ($journals as $entry) {
$found[] = (int)$entry->transaction_currency_id;
}
// get all from transactions
/** @var Collection $transactions */
$transactions = Transaction::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
foreach ($transactions as $entry) {
$found[] = (int)$entry->transaction_currency_id;
}
// get all from budget limits
/** @var Collection $limits */
$limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
foreach ($limits as $entry) {
$found[] = (int)$entry->transaction_currency_id;
}
$found = array_unique($found);
$this->info(sprintf('%d different currencies are currently in use.', count($found)));
$disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count();
if ($disabled > 0) {
$this->info(sprintf('%d were (was) still disabled. This has been corrected.', $disabled));
}
if (0 === $disabled) {
$this->info('All currencies are correctly enabled or disabled.');
}
TransactionCurrency::whereIn('id', $found)->update(['enabled' => true]);
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified currencies in %s seconds.', $end));
return 0;
}
}

View File

@@ -0,0 +1,256 @@
<?php
declare(strict_types=1);
/**
* FixAccountTypes.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command;
/**
* Class FixAccountTypes
*/
class FixAccountTypes extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make sure all journals have the correct from/to account types.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-account-types';
/** @var array */
private $expected;
/** @var AccountFactory */
private $factory;
/** @var array */
private $fixable;
/** @var int */
private $count;
/**
* Execute the console command.
*
* @return int
* @throws FireflyException
*/
public function handle(): int
{
$this->stupidLaravel();
$start = microtime(true);
$this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script:
$this->fixable = [
// transfers from asset to liability and vice versa
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN),
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT),
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE),
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET),
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET),
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
// withdrawals with a revenue account as destination instead of an expense account.
sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
// deposits with an expense account as source instead of a revenue account.
sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),
];
$this->expected = config('firefly.source_dests');
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
foreach ($journals as $journal) {
$this->inspectJournal($journal);
}
if (0 === $this->count) {
$this->info('All account types are OK!');
}
if (0 !== $this->count) {
$this->info(sprintf('Acted on %d transaction(s)!', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verifying account types took %s seconds', $end));
return 0;
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
{
$this->count = 0;
}
/**
* @param TransactionJournal $journal
* @param string $type
* @param Transaction $source
* @param Transaction $dest
* @throws FireflyException
*/
private function fixJournal(TransactionJournal $journal, string $type, Transaction $source, Transaction $dest): void
{
$this->count++;
// variables:
$combination = sprintf('%s%s%s', $type, $source->account->accountType->type, $dest->account->accountType->type);
switch ($combination) {
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE):
// from an asset to a liability should be a withdrawal:
$withdrawal = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$journal->transactionType()->associate($withdrawal);
$journal->save();
$this->info(sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id));
// check it again:
$this->inspectJournal($journal);
break;
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET):
// from a liability to an asset should be a deposit.
$deposit = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$journal->transactionType()->associate($deposit);
$journal->save();
$this->info(sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id));
// check it again:
$this->inspectJournal($journal);
break;
case sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE):
// withdrawals with a revenue account as destination instead of an expense account.
$this->factory->setUser($journal->user);
$oldDest = $dest->account;
$result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE);
$dest->account()->associate($result);
$dest->save();
$this->info(
sprintf(
'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id,
$oldDest->id, $oldDest->name,
$result->id, $result->name
)
);
$this->inspectJournal($journal);
break;
case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET):
// deposits with an expense account as source instead of a revenue account.
// find revenue account.
$this->factory->setUser($journal->user);
$result = $this->factory->findOrCreate($source->account->name, AccountType::REVENUE);
$oldSource = $dest->account;
$source->account()->associate($result);
$source->save();
$this->info(
sprintf(
'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id,
$oldSource->id, $oldSource->name,
$result->id, $result->name
)
);
$this->inspectJournal($journal);
break;
default:
$this->info(sprintf('The source account of %s #%d cannot be of type "%s".', $type, $journal->id, $source->account->accountType->type));
$this->info(sprintf('The destination account of %s #%d cannot be of type "%s".', $type, $journal->id, $dest->account->accountType->type));
break;
}
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getDestinationTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '>', 0);
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getSourceTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '<', 0);
}
/**
* @param TransactionJournal $journal
*
* @throws FireflyException
*/
private function inspectJournal(TransactionJournal $journal): void
{
$count = $journal->transactions()->count();
if (2 !== $count) {
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
return;
}
$type = $journal->transactionType->type;
$sourceTransaction = $this->getSourceTransaction($journal);
$sourceAccount = $sourceTransaction->account;
$sourceAccountType = $sourceAccount->accountType->type;
$destTransaction = $this->getDestinationTransaction($journal);
$destAccount = $destTransaction->account;
$destAccountType = $destAccount->accountType->type;
if (!isset($this->expected[$type])) {
// @codeCoverageIgnoreStart
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
return;
// @codeCoverageIgnoreEnd
}
if (!isset($this->expected[$type][$sourceAccountType])) {
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return;
}
$expectedTypes = $this->expected[$type][$sourceAccountType];
if (!in_array($destAccountType, $expectedTypes, true)) {
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
/**
* FixPiggies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command;
/**
* Report (and fix) piggy banks. Make sure there are only transfers linked to piggy bank events.
*
* Class FixPiggies
*/
class FixPiggies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fixes common issues with piggy banks.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-piggies';
/** @var int */
private $count;
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): int
{
$this->count = 0;
$start = microtime(true);
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
/** @var PiggyBankEvent $event */
foreach ($set as $event) {
if (null === $event->transaction_journal_id) {
continue;
}
/** @var TransactionJournal $journal */
$journal = $event->transactionJournal;
// @codeCoverageIgnoreStart
if (null === $journal) {
$event->transaction_journal_id = null;
$event->save();
$this->count++;
continue;
}
// @codeCoverageIgnoreEnd
$type = $journal->transactionType->type;
if (TransactionType::TRANSFER !== $type) {
$event->transaction_journal_id = null;
$event->save();
$this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id));
$this->count++;
continue;
}
}
if (0 === $this->count) {
$this->line('All piggy bank events are correct.');
}
if (0 !== $this->count) {
$this->line(sprintf('Fixed %d piggy bank event(s).', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->line(sprintf('Verified the content of %d piggy bank events in %s seconds.', $set->count(), $end));
return 0;
}
}

View File

@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/**
* FixUnevenAmount.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use DB;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use stdClass;
/**
* Class FixUnevenAmount
*/
class FixUnevenAmount extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix journals with uneven amounts.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-uneven-amount';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$start = microtime(true);
$count = 0;
// get invalid journals
$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) {
if (0 !== bccomp((string)$entry->the_sum, '0')) {
$this->fixJournal((int)$entry->transaction_journal_id);
$count++;
}
}
if (0 === $count) {
$this->info('Amount integrity OK!');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified amount integrity in %s seconds', $end));
return 0;
}
/**
* @param int $param
*/
private function fixJournal(int $param): void
{
// one of the transactions is bad.
$journal = TransactionJournal::find($param);
if (!$journal) {
return; // @codeCoverageIgnore
}
/** @var Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
$amount = bcmul('-1', (string)$source->amount);
// fix amount of destination:
/** @var Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
$destination->amount = $amount;
$destination->save();
$message = sprintf('Corrected amount in transaction journal #%d', $param);
$this->line($message);
}
}

View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* RemoveBills.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command;
/**
* Class RemoveBills
*/
class RemoveBills extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove bills from transactions that shouldn\'t have one.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:remove-bills';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): int
{
$start = microtime(true);
/** @var TransactionType $withdrawal */
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journals = TransactionJournal::whereNotNull('bill_id')->where('transaction_type_id', '!=', $withdrawal->id)->get();
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$this->line(sprintf('Transaction journal #%d should not be linked to bill #%d.', $journal->id, $journal->bill_id));
$journal->bill_id = null;
$journal->save();
}
if (0 === $journals->count()) {
$this->info('All transaction journals have correct bill information.');
}
if ($journals->count() > 0) {
$this->info('Fixed all transaction journals so they have correct bill information.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified bills / journals in %s seconds', $end));
return 0;
}
}

View File

@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
/**
* RenameMetaFields.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use DB;
use Illuminate\Console\Command;
/**
* Class RenameMetaFields
*/
class RenameMetaFields extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Rename changed meta fields.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:rename-meta-fields';
/** @var int */
private $count;
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->count = 0;
$start = microtime(true);
$changes = [
'original-source' => 'original_source',
'importHash' => 'import_hash',
'importHashV2' => 'import_hash_v2',
'sepa-cc' => 'sepa_cc',
'sepa-ct-op' => 'sepa_ct_op',
'sepa-ct-id' => 'sepa_ct_id',
'sepa-db' => 'sepa_db',
'sepa-country' => 'sepa_country',
'sepa-ep' => 'sepa_ep',
'sepa-ci' => 'sepa_ci',
'sepa-batch-id' => 'sepa_batch_id',
];
foreach ($changes as $original => $update) {
$this->rename($original, $update);
}
if (0 === $this->count) {
$this->line('All meta fields are correct.');
}
if (0 !== $this->count) {
$this->line(sprintf('Renamed %d meta field(s).', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Renamed meta fields in %s seconds', $end));
return 0;
}
/**
* @param string $original
* @param string $update
*/
private function rename(string $original, string $update): void
{
$count = DB::table('journal_meta')
->where('name', '=', $original)
->update(['name' => $update]);
$this->count += $count;
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/**
* TransferBudgets.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command;
/**
* Class TransferBudgets
*/
class TransferBudgets extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Removes budgets from transfers.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-transfer-budgets';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$start = microtime(true);
$set = TransactionJournal::distinct()
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
->whereNotIn('transaction_types.type', [TransactionType::WITHDRAWAL])
->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.*']);
$count = 0;
/** @var TransactionJournal $entry */
foreach ($set as $entry) {
$this->info(sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $entry->id, $entry->transactionType->type));
$entry->budgets()->sync([]);
$count++;
}
if (0 === $count) {
$this->info('No invalid budget/journal entries.');
}
if (0 !== $count) {
$this->line(sprintf('Corrected %d invalid budget/journal entries (entry).', $count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified budget/journals in %s seconds.', $end));
return 0;
}
}

View File

@@ -1,150 +0,0 @@
<?php
/**
* CreateExport.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use Carbon\Carbon;
use FireflyIII\Export\ProcessorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
/**
* Class CreateExport.
*
* Generates export from the command line.
*
* @codeCoverageIgnore
*/
class CreateExport extends Command
{
use VerifiesAccessToken;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Use this command to create a new import. Your user ID can be found on the /profile page.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature
= 'firefly:create-export
{--user= : The user ID that the import should import for.}
{--token= : The user\'s access token.}
{--with_attachments : Include user\'s attachments?}
{--with_uploads : Include user\'s uploads?}';
/**
* Execute the console command.
*
* @return int
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function handle(): int
{
if (!$this->verifyAccessToken()) {
$this->error('Invalid access token.');
return 1;
}
$this->line('Full export is running...');
// make repositories
/** @var UserRepositoryInterface $userRepository */
$userRepository = app(UserRepositoryInterface::class);
/** @var ExportJobRepositoryInterface $jobRepository */
$jobRepository = app(ExportJobRepositoryInterface::class);
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
/** @var JournalRepositoryInterface $journalRepository */
$journalRepository = app(JournalRepositoryInterface::class);
// set user
$user = $userRepository->findNull((int)$this->option('user'));
if (null === $user) {
return 1;
}
$jobRepository->setUser($user);
$journalRepository->setUser($user);
$accountRepository->setUser($user);
// first date
$firstJournal = $journalRepository->firstNull();
$first = new Carbon;
if (null !== $firstJournal) {
$first = $firstJournal->date;
}
// create job and settings.
$job = $jobRepository->create();
$settings = [
'accounts' => $accountRepository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]),
'startDate' => $first,
'endDate' => new Carbon,
'exportFormat' => 'csv',
'includeAttachments' => $this->option('with_attachments'),
'includeOldUploads' => $this->option('with_uploads'),
'job' => $job,
];
/** @var ProcessorInterface $processor */
$processor = app(ProcessorInterface::class);
$processor->setSettings($settings);
$processor->collectJournals();
$processor->convertJournals();
$processor->exportJournals();
if ($settings['includeAttachments']) {
$processor->collectAttachments();
}
if ($settings['includeOldUploads']) {
$processor->collectOldUploads();
}
$processor->createZipFile();
$disk = Storage::disk('export');
$fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s'));
$localPath = storage_path('export') . '/' . $job->key . '.zip';
// "move" from local to export disk
$disk->put($fileName, file_get_contents($localPath));
unlink($localPath);
$this->line('The export has finished! You can find the ZIP file in export disk with file name:');
$this->line($fileName);
return 0;
}
}

View File

@@ -1,304 +0,0 @@
<?php
/**
* CreateImport.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
use FireflyIII\Import\Routine\RoutineInterface;
use FireflyIII\Import\Storage\ImportArrayStorage;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command;
use Log;
/**
* Class CreateImport.
*
* @codeCoverageIgnore
*/
class CreateImport extends Command
{
use VerifiesAccessToken;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Use this command to create a new import. Your user ID can be found on the /profile page.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature
= 'firefly:create-import
{file? : The file to import.}
{configuration? : The configuration file to use for the import.}
{--type=csv : The file type of the import.}
{--provider=file : The file type of the import.}
{--user=1 : The user ID that the import should import for.}
{--token= : The user\'s access token.}
{--start : Starts the job immediately.}';
/**
* Run the command.
*
* @throws FireflyException
*/
public function handle(): int
{
if (!$this->verifyAccessToken()) {
$this->errorLine('Invalid access token.');
return 1;
}
/** @var UserRepositoryInterface $userRepository */
$userRepository = app(UserRepositoryInterface::class);
$file = (string)$this->argument('file');
$configuration = (string)$this->argument('configuration');
$user = $userRepository->findNull((int)$this->option('user'));
$cwd = getcwd();
$provider = strtolower((string)$this->option('provider'));
$configurationData = [];
if (null === $user) {
$this->errorLine('User is NULL.');
return 1;
}
if (!$this->validArguments()) {
$this->errorLine('Invalid arguments.');
return 1;
}
if ('' !== $configuration) {
$configurationData = json_decode(file_get_contents($configuration), true);
if (null === $configurationData) {
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return 1;
}
}
$this->infoLine(sprintf('Going to create a job to import file: %s', $file));
$this->infoLine(sprintf('Using configuration file: %s', $configuration));
$this->infoLine(sprintf('Import into user: #%d (%s)', $user->id, $user->email));
$this->infoLine(sprintf('Type of import: %s', $provider));
/** @var ImportJobRepositoryInterface $jobRepository */
$jobRepository = app(ImportJobRepositoryInterface::class);
$jobRepository->setUser($user);
$importJob = $jobRepository->create($provider);
$this->infoLine(sprintf('Created job "%s"', $importJob->key));
// make sure that job has no prerequisites.
if ((bool)config(sprintf('import.has_prereq.%s', $provider))) {
// make prerequisites thing.
$class = (string)config(sprintf('import.prerequisites.%s', $provider));
if (!class_exists($class)) {
throw new FireflyException(sprintf('No class to handle prerequisites for "%s".', $provider)); // @codeCoverageIgnore
}
/** @var PrerequisitesInterface $object */
$object = app($class);
$object->setUser($user);
if (!$object->isComplete()) {
$this->errorLine(sprintf('Import provider "%s" has prerequisites that can only be filled in using the browser.', $provider));
return 1;
}
}
// store file as attachment.
if ('' !== $file) {
$messages = $jobRepository->storeCLIUpload($importJob, 'import_file', $file);
if ($messages->count() > 0) {
$this->errorLine($messages->first());
return 1;
}
$this->infoLine('File content saved.');
}
$this->infoLine('Job configuration saved.');
$jobRepository->setConfiguration($importJob, $configurationData);
$jobRepository->setStatus($importJob, 'ready_to_run');
if (true === $this->option('start')) {
$this->infoLine('The import routine has started. The process is not visible. Please wait.');
Log::debug('Go for import!');
// run it!
$key = sprintf('import.routine.%s', $provider);
$className = config($key);
if (null === $className || !class_exists($className)) {
// @codeCoverageIgnoreStart
$this->errorLine(sprintf('No routine for provider "%s"', $provider));
return 1;
// @codeCoverageIgnoreEnd
}
// keep repeating this call until job lands on "provider_finished"
$valid = ['provider_finished'];
$count = 0;
while (!\in_array($importJob->status, $valid, true) && $count < 6) {
Log::debug(sprintf('Now in loop #%d.', $count + 1));
/** @var RoutineInterface $routine */
$routine = app($className);
$routine->setImportJob($importJob);
try {
$routine->run();
} catch (FireflyException|Exception $e) {
$message = 'The import routine crashed: ' . $e->getMessage();
Log::error($message);
Log::error($e->getTraceAsString());
// set job errored out:
$jobRepository->setStatus($importJob, 'error');
$this->errorLine($message);
return 1;
}
$count++;
}
if ('provider_finished' === $importJob->status) {
$this->infoLine('Import has finished. Please wait for storage of data.');
// set job to be storing data:
$jobRepository->setStatus($importJob, 'storing_data');
/** @var ImportArrayStorage $storage */
$storage = app(ImportArrayStorage::class);
$storage->setImportJob($importJob);
try {
$storage->store();
} catch (FireflyException|Exception $e) {
$message = 'The import routine crashed: ' . $e->getMessage();
Log::error($message);
Log::error($e->getTraceAsString());
// set job errored out:
$jobRepository->setStatus($importJob, 'error');
$this->errorLine($message);
return 1;
}
// set storage to be finished:
$jobRepository->setStatus($importJob, 'storage_finished');
}
// give feedback:
$this->infoLine('Job has finished.');
if (null !== $importJob->tag) {
$this->infoLine(sprintf('%d transaction(s) have been imported.', $importJob->tag->transactionJournals->count()));
$this->infoLine(sprintf('You can find your transactions under tag "%s"', $importJob->tag->tag));
}
if (null === $importJob->tag) {
$this->errorLine('No transactions have been imported :(.');
}
if (\count($importJob->errors) > 0) {
$this->infoLine(sprintf('%d error(s) occurred:', \count($importJob->errors)));
foreach ($importJob->errors as $err) {
$this->errorLine('- ' . $err);
}
}
}
// clear cache for user:
app('preferences')->setForUser($user, 'lastActivity', microtime());
return 0;
}
/**
* @param string $message
* @param array|null $data
*/
private function errorLine(string $message, array $data = null): void
{
Log::error($message, $data ?? []);
$this->error($message);
}
/**
* @param string $message
* @param array $data
*/
private function infoLine(string $message, array $data = null): void
{
Log::info($message, $data ?? []);
$this->line($message);
}
/**
* Verify user inserts correct arguments.
*
* @noinspection MultipleReturnStatementsInspection
* @return bool
*/
private function validArguments(): bool
{
$file = (string)$this->argument('file');
$configuration = (string)$this->argument('configuration');
$cwd = getcwd();
$validTypes = config('import.options.file.import_formats');
$type = strtolower($this->option('type'));
$provider = strtolower($this->option('provider'));
$enabled = (bool)config(sprintf('import.enabled.%s', $provider));
if (false === $enabled) {
$this->errorLine(sprintf('Provider "%s" is not enabled.', $provider));
return false;
}
if ('file' === $provider && !\in_array($type, $validTypes, true)) {
$this->errorLine(sprintf('Cannot import file of type "%s"', $type));
return false;
}
if ('file' === $provider && !file_exists($file)) {
$this->errorLine(sprintf('Firefly III cannot find file "%s" (working directory: "%s").', $file, $cwd));
return false;
}
if ('file' === $provider && !file_exists($configuration)) {
$this->errorLine(sprintf('Firefly III cannot find configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return false;
}
return true;
}
}

View File

@@ -1,111 +0,0 @@
<?php
/**
* DecryptAttachment.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use Illuminate\Console\Command;
use Log;
/**
* Class DecryptAttachment.
*
* @codeCoverageIgnore
*/
class DecryptAttachment extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Decrypts an attachment and dumps the content in a file in the given directory.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature
= 'firefly:decrypt-attachment {id:The ID of the attachment.} {name:The file name of the attachment.}
{directory:Where the file must be stored.}';
/**
* Execute the console command.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @return int
*/
public function handle(): int
{
/** @var AttachmentRepositoryInterface $repository */
$repository = app(AttachmentRepositoryInterface::class);
$attachmentId = (int)$this->argument('id');
$attachment = $repository->findWithoutUser($attachmentId);
$attachmentName = trim((string)$this->argument('name'));
$storagePath = realpath(trim((string)$this->argument('directory')));
if (null === $attachment) {
$this->error(sprintf('No attachment with id #%d', $attachmentId));
Log::error(sprintf('DecryptAttachment: No attachment with id #%d', $attachmentId));
return 1;
}
if ($attachmentName !== $attachment->filename) {
$this->error('File name does not match.');
Log::error('DecryptAttachment: File name does not match.');
return 1;
}
if (!is_dir($storagePath)) {
$this->error(sprintf('Path "%s" is not a directory.', $storagePath));
Log::error(sprintf('DecryptAttachment: Path "%s" is not a directory.', $storagePath));
return 1;
}
if (!is_writable($storagePath)) {
$this->error(sprintf('Path "%s" is not writable.', $storagePath));
Log::error(sprintf('DecryptAttachment: Path "%s" is not writable.', $storagePath));
return 1;
}
$fullPath = $storagePath . DIRECTORY_SEPARATOR . $attachment->filename;
$content = $repository->getContent($attachment);
$this->line(sprintf('Going to write content for attachment #%d into file "%s"', $attachment->id, $fullPath));
$result = file_put_contents($fullPath, $content);
if (false === $result) {
$this->error('Could not write to file.');
return 1;
}
$this->info(sprintf('%d bytes written. Exiting now..', $result));
return 0;
}
}

View File

@@ -28,7 +28,6 @@ use Crypt;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Preference;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Log;
@@ -50,14 +49,15 @@ class DecryptDatabase extends Command
*
* @var string
*/
protected $signature = 'firefly:decrypt-all';
protected $signature = 'firefly-iii:decrypt-all';
/**
* Execute the console command.
*
* @return mixed
* @return int
* @throws FireflyException
*/
public function handle()
public function handle(): int
{
$this->line('Going to decrypt the database.');
$tables = [
@@ -113,7 +113,7 @@ class DecryptDatabase extends Command
$this->line(sprintf('Decrypted the data in table "%s".', $table));
// mark as decrypted:
$configName = sprintf('is_decrypted_%s', $table);
FireflyConfig::set($configName, true);
app('fireflyconfig')->set($configName, true);
}
$this->info('Done!');
@@ -129,7 +129,7 @@ class DecryptDatabase extends Command
private function isDecrypted(string $table): bool
{
$configName = sprintf('is_decrypted_%s', $table);
$configVar = FireflyConfig::get($configName, false);
$configVar = app('fireflyconfig')->get($configName, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
@@ -139,9 +139,11 @@ class DecryptDatabase extends Command
/**
* @param $value
* Tries to decrypt data. Will only throw an exception when the MAC is invalid.
*
* @return mixed
* @param $value
* @return string
* @throws FireflyException
*/
private function tryDecrypt($value)
{
@@ -149,7 +151,7 @@ class DecryptDatabase extends Command
$value = Crypt::decrypt($value);
} catch (DecryptException $e) {
if ('The MAC is invalid.' === $e->getMessage()) {
throw new FireflyException($e->getMessage());
throw new FireflyException($e->getMessage()); // @codeCoverageIgnore
}
Log::debug(sprintf('Could not decrypt. %s', $e->getMessage()));
}

View File

@@ -1,165 +0,0 @@
<?php
/**
* Import.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\RoutineInterface;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Tag;
use Illuminate\Console\Command;
use Log;
/**
* Class Import.
*
* @codeCoverageIgnore
*/
class Import extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'This will start a new import.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly:start-import {key}';
/**
* Run the import routine.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @throws FireflyException
*/
public function handle(): int
{
Log::debug('Start start-import command');
$jobKey = (string)$this->argument('key');
/** @var ImportJob $job */
$job = ImportJob::where('key', $jobKey)->first();
if (null === $job) {
$this->errorLine(sprintf('No job found with key "%s"', $jobKey));
return 1;
}
if (!$this->isValid($job)) {
$this->errorLine('Job is not valid for some reason. Exit.');
return 1;
}
$this->infoLine(sprintf('Going to import job with key "%s" of type "%s"', $job->key, $job->file_type));
// actually start job:
$type = 'csv' === $job->file_type ? 'file' : $job->file_type;
$key = sprintf('import.routine.%s', $type);
$className = config($key);
if (null === $className || !class_exists($className)) {
throw new FireflyException(sprintf('Cannot find import routine class for job of type "%s".', $type)); // @codeCoverageIgnore
}
/** @var RoutineInterface $routine */
$routine = app($className);
$routine->setImportJob($job);
$routine->run();
/**
* @var int $index
* @var string $error
*/
foreach ($job->errors as $index => $error) {
$this->errorLine(sprintf('Error importing line #%d: %s', $index, $error));
}
/** @var Tag $tag */
$tag = $job->tag()->first();
$count = 0;
if (null === $tag) {
$count = $tag->transactionJournals()->count();
}
$this->infoLine(sprintf('The import has finished. %d transactions have been imported.', $count));
return 0;
}
/**
* Displays an error.
*
* @param string $message
* @param array|null $data
*/
private function errorLine(string $message, array $data = null): void
{
Log::error($message, $data ?? []);
$this->error($message);
}
/**
* Displays an informational message.
*
* @param string $message
* @param array $data
*/
private function infoLine(string $message, array $data = null): void
{
Log::info($message, $data ?? []);
$this->line($message);
}
/**
* Check if job is valid to be imported.
*
* @param ImportJob $job
*
* @return bool
*/
private function isValid(ImportJob $job): bool
{
if (null === $job) {
$this->errorLine('This job does not seem to exist.');
return false;
}
if ('configured' !== $job->status) {
Log::error(sprintf('This job is not ready to be imported (status is %s).', $job->status));
$this->errorLine('This job is not ready to be imported.');
return false;
}
return true;
}
}

View File

@@ -0,0 +1,332 @@
<?php
/**
* CreateCSVImport.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands\Import;
use Exception;
use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\RoutineInterface;
use FireflyIII\Import\Storage\ImportArrayStorage;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Console\Command;
use Log;
/**
* Class CreateCSVImport.
*/
class CreateCSVImport extends Command
{
use VerifiesAccessToken;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Use this command to create a new CSV file import.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature
= 'firefly-iii:csv-import
{file? : The CSV file to import.}
{configuration? : The configuration file to use for the import.}
{--user=1 : The user ID that the import should import for.}
{--token= : The user\'s access token.}';
/** @var UserRepositoryInterface */
private $userRepository;
/** @var ImportJobRepositoryInterface */
private $importRepository;
/** @var ImportJob */
private $importJob;
/**
* Run the command.
*/
public function handle(): int
{
$this->stupidLaravel();
// @codeCoverageIgnoreStart
if (!$this->verifyAccessToken()) {
$this->errorLine('Invalid access token.');
return 1;
}
if (!$this->validArguments()) {
$this->errorLine('Invalid arguments.');
return 1;
}
// @codeCoverageIgnoreEnd
/** @var User $user */
$user = $this->userRepository->findNull((int)$this->option('user'));
$file = (string)$this->argument('file');
$configuration = (string)$this->argument('configuration');
$this->importRepository->setUser($user);
$configurationData = json_decode(file_get_contents($configuration), true);
$this->importJob = $this->importRepository->create('file');
// inform user (and log it)
$this->infoLine(sprintf('Import file : %s', $file));
$this->infoLine(sprintf('Configuration file : %s', $configuration));
$this->infoLine(sprintf('User : #%d (%s)', $user->id, $user->email));
$this->infoLine(sprintf('Job : %s', $this->importJob->key));
try {
$this->storeFile($file);
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
return 1;
}
// job is ready to go
$this->importRepository->setConfiguration($this->importJob, $configurationData);
$this->importRepository->setStatus($this->importJob, 'ready_to_run');
$this->infoLine('The import routine has started. The process is not visible. Please wait.');
Log::debug('Go for import!');
// keep repeating this call until job lands on "provider_finished"
try {
$this->processFile();
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
return 1;
}
// then store data:
try {
$this->storeData();
} catch (FireflyException $e) {
$this->errorLine($e->getMessage());
return 1;
}
// give feedback:
$this->giveFeedback();
// clear cache for user:
app('preferences')->setForUser($user, 'lastActivity', microtime());
return 0;
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
{
$this->userRepository = app(UserRepositoryInterface::class);
$this->importRepository = app(ImportJobRepositoryInterface::class);
}
/**
* @param string $message
* @param array|null $data
* @codeCoverageIgnore
*/
private function errorLine(string $message, array $data = null): void
{
Log::error($message, $data ?? []);
$this->error($message);
}
/**
* @param string $message
* @param array $data
* @codeCoverageIgnore
*/
private function infoLine(string $message, array $data = null): void
{
Log::info($message, $data ?? []);
$this->line($message);
}
/**
* Verify user inserts correct arguments.
*
* @noinspection MultipleReturnStatementsInspection
* @return bool
* @codeCoverageIgnore
*/
private function validArguments(): bool
{
$file = (string)$this->argument('file');
$configuration = (string)$this->argument('configuration');
$cwd = getcwd();
$enabled = (bool)config('import.enabled.file');
if (false === $enabled) {
$this->errorLine('CSV Provider is not enabled.');
return false;
}
if (!file_exists($file)) {
$this->errorLine(sprintf('Firefly III cannot find file "%s" (working directory: "%s").', $file, $cwd));
return false;
}
if (!file_exists($configuration)) {
$this->errorLine(sprintf('Firefly III cannot find configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return false;
}
$configurationData = json_decode(file_get_contents($configuration), true);
if (null === $configurationData) {
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
return false;
}
return true;
}
/**
* Store the supplied file as an attachment to this job.
*
* @param string $file
* @throws FireflyException
*/
private function storeFile(string $file): void
{
// store file as attachment.
if ('' !== $file) {
$messages = $this->importRepository->storeCLIUpload($this->importJob, 'import_file', $file);
if ($messages->count() > 0) {
throw new FireflyException($messages->first());
}
}
}
/**
* Keep repeating import call until job lands on "provider_finished".
*
* @throws FireflyException
*/
private function processFile(): void
{
$className = config('import.routine.file');
$valid = ['provider_finished'];
$count = 0;
while (!in_array($this->importJob->status, $valid, true) && $count < 6) {
Log::debug(sprintf('Now in loop #%d.', $count + 1));
/** @var RoutineInterface $routine */
$routine = app($className);
$routine->setImportJob($this->importJob);
try {
$routine->run();
} catch (FireflyException|Exception $e) {
$message = 'The import routine crashed: ' . $e->getMessage();
Log::error($message);
Log::error($e->getTraceAsString());
// set job errored out:
$this->importRepository->setStatus($this->importJob, 'error');
throw new FireflyException($message);
}
$count++;
}
$this->importRepository->setStatus($this->importJob, 'provider_finished');
$this->importJob->status = 'provider_finished';
}
/**
*
* @throws FireflyException
*/
private function storeData(): void
{
if ('provider_finished' === $this->importJob->status) {
$this->infoLine('Import has finished. Please wait for storage of data.');
// set job to be storing data:
$this->importRepository->setStatus($this->importJob, 'storing_data');
/** @var ImportArrayStorage $storage */
$storage = app(ImportArrayStorage::class);
$storage->setImportJob($this->importJob);
try {
$storage->store();
} catch (FireflyException|Exception $e) {
$message = 'The import routine crashed: ' . $e->getMessage();
Log::error($message);
Log::error($e->getTraceAsString());
// set job errored out:
$this->importRepository->setStatus($this->importJob, 'error');
throw new FireflyException($message);
}
// set storage to be finished:
$this->importRepository->setStatus($this->importJob, 'storage_finished');
}
}
/**
*
*/
private function giveFeedback(): void
{
$this->infoLine('Job has finished.');
if (null !== $this->importJob->tag) {
$this->infoLine(sprintf('%d transaction(s) have been imported.', $this->importJob->tag->transactionJournals->count()));
$this->infoLine(sprintf('You can find your transactions under tag "%s"', $this->importJob->tag->tag));
}
if (null === $this->importJob->tag) {
$this->errorLine('No transactions have been imported :(.');
}
if (count($this->importJob->errors) > 0) {
$this->infoLine(sprintf('%d error(s) occurred:', count($this->importJob->errors)));
foreach ($this->importJob->errors as $err) {
$this->errorLine('- ' . $err);
}
}
}
}

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