Compare commits

...

452 Commits

Author SHA1 Message Date
James Cole
adc52f7b63 Merge branch 'release/5.5.8' into main 2021-04-18 07:28:12 +02:00
James Cole
f8cf02bda1 Make sure debug does timezone right. 2021-04-18 07:28:00 +02:00
James Cole
4b14ad9770 Update packages. 2021-04-18 07:23:05 +02:00
James Cole
2a630b0a50 Rebuild frontend, new translations. 2021-04-18 07:22:10 +02:00
James Cole
1a311664e8 Rebuild frontend. 2021-04-17 20:53:42 +02:00
James Cole
0a4e3edf43 Rebuild frontend, add version to JS calls against caching. 2021-04-17 15:57:51 +02:00
James Cole
9b0b80d1d4 Various fixes for v2 issues in 5.5.7 2021-04-17 15:53:11 +02:00
James Cole
dcd123a9ec Fix #4668 2021-04-17 05:39:56 +02:00
James Cole
e06452d97c Fix #4664 2021-04-16 05:55:23 +02:00
James Cole
e5b4e7afe0 Recreate frontend for correct date #4660 2021-04-15 06:39:07 +02:00
James Cole
0ea22269a0 Fix #4663 2021-04-15 06:15:17 +02:00
James Cole
577dcfa938 Rebuild frontend. 2021-04-14 20:07:39 +02:00
James Cole
99f08da4df Fix #4656 2021-04-13 19:01:43 +02:00
James Cole
2f9724e7ca Fix nullpointers. 2021-04-13 06:26:51 +02:00
James Cole
8cda89569c Update .env.example 2021-04-12 15:50:13 +00:00
James Cole
5421e30293 Add text #4637 2021-04-12 17:25:40 +02:00
James Cole
a2deff0f7a Whoops 2021-04-12 15:28:06 +02:00
James Cole
bff661fe69 Merge branch 'main' into develop 2021-04-12 14:10:52 +02:00
James Cole
f6b890e284 Fix #4652 2021-04-12 14:09:17 +02:00
James Cole
acb8fa522b Merge tag '5.5.7' into develop
5.5.7
2021-04-12 06:30:46 +02:00
James Cole
b47614c965 Merge branch 'release/5.5.7' into main 2021-04-12 06:30:44 +02:00
James Cole
9af458df49 Updates for new release. 2021-04-12 06:30:12 +02:00
James Cole
a67e2b597d Fix #4646 2021-04-12 06:16:00 +02:00
James Cole
3c36eed461 Rebuild frontend. 2021-04-11 07:43:07 +02:00
James Cole
5a7c3bd716 Rebuild v1 2021-04-11 07:27:25 +02:00
James Cole
43476167d8 Remove lots of debug comments. 2021-04-11 07:26:52 +02:00
James Cole
d357eaeb51 Update meta files for new release. 2021-04-11 07:26:37 +02:00
James Cole
2e118c5f22 Fix #4635 2021-04-11 06:49:46 +02:00
James Cole
8e95530ca8 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2021-04-10 17:56:30 +02:00
James Cole
a04a6845f7 Merge pull request #4627 from devfaz/add_bill_nobill
added has_no_bill and has_any_bill search parameters
2021-04-10 12:01:43 +02:00
Fabian Zimmermann
185e9b66d6 added has_no_bill and has_any_bill search parameters 2021-04-10 10:59:59 +02:00
James Cole
93a7c51dd1 Update meta files 2021-04-10 08:01:55 +02:00
James Cole
f9ac40a811 Improve layout of v2 auth forms 2021-04-10 06:36:28 +02:00
James Cole
b0027acf34 Make sure that migrations work on old MySQL servers. 2021-04-10 06:36:09 +02:00
James Cole
f5e5854479 Rebuild frontend 2021-04-09 19:35:03 +02:00
James Cole
95d72d065b Fix #4628 2021-04-09 16:02:50 +02:00
James Cole
56b2fa69bc Fix for #4625 2021-04-09 09:02:00 +02:00
James Cole
e614427925 Fix some submit issues. 2021-04-09 07:03:19 +02:00
James Cole
34dc1f9f53 Merge branch 'release/5.5.6' into main 2021-04-09 06:20:39 +02:00
James Cole
94d9b78a33 Merge tag '5.5.6' into develop
5.5.6
2021-04-09 06:20:39 +02:00
James Cole
b9d949d259 Changelog and version. 2021-04-09 06:20:10 +02:00
James Cole
3376e1e663 Fix issue in date format. 2021-04-09 06:19:43 +02:00
James Cole
ea98c2631f Merge branch 'release/5.5.5' into main 2021-04-09 06:07:05 +02:00
James Cole
50b9fe649d Merge tag '5.5.5' into develop
5.5.5
2021-04-09 06:07:05 +02:00
James Cole
56054531a3 Jump to 5.5.5 2021-04-09 06:06:41 +02:00
James Cole
1912e46113 Remove strict CSP header for #4622 2021-04-09 06:05:27 +02:00
James Cole
075f951cfe Merge tag '5.5.4' into develop
5.5.4
2021-04-09 03:06:18 +02:00
James Cole
26aad765ae Merge branch 'release/5.5.4' into main 2021-04-09 03:06:16 +02:00
James Cole
73ba78d46d Update libraries for new release. 2021-04-09 03:05:37 +02:00
James Cole
0d5dd40134 Updated changelog. 2021-04-09 02:59:23 +02:00
James Cole
f0d84ad142 Update readme. 2021-04-09 02:55:57 +02:00
James Cole
0b4ebf644d Rebuild frontend 2021-04-09 02:07:34 +02:00
James Cole
5b60db120f Submit was broken. 2021-04-08 17:49:25 +02:00
James Cole
f2073a4494 Fix various issues in forms. 2021-04-08 17:41:19 +02:00
James Cole
3e12d26afd Disable almost all things. 2021-04-08 16:47:16 +02:00
James Cole
e458208966 Rebuild frontend 2021-04-08 16:09:09 +02:00
James Cole
e28a77dc87 Add nonce to build. 2021-04-08 12:30:21 +02:00
James Cole
a709596ccb Add headers. 2021-04-08 12:27:54 +02:00
James Cole
849c7dfe02 Strict headers and CSS nonce 2021-04-08 12:10:04 +02:00
James Cole
e580093a34 Weird headers. 2021-04-08 12:05:08 +02:00
James Cole
4fa7a5c1bc Update headers 2021-04-08 11:58:21 +02:00
James Cole
d668007fee Remove style thing 2021-04-08 11:55:10 +02:00
James Cole
6cbccf3be6 Small change in headers 2021-04-08 11:50:59 +02:00
James Cole
9cd75dda1a Link to issue. 2021-04-08 11:34:24 +02:00
James Cole
56dff7ea67 Rebuild new layout. 2021-04-08 11:21:20 +02:00
James Cole
6160f99e92 Update transactions. 2021-04-08 10:23:35 +02:00
James Cole
115639a004 Clean up some code. 2021-04-08 10:13:35 +02:00
James Cole
a0c98c7d9f Update packages. 2021-04-08 09:54:05 +02:00
James Cole
7842700bf1 Do not report specific error. 2021-04-08 06:50:00 +02:00
James Cole
4ecda4d4e0 Add some special headers. 2021-04-07 20:47:40 +02:00
James Cole
c76d140d0b Allow a new config var 2021-04-07 18:24:06 +02:00
James Cole
4f42eb1796 Fix nullpointers. 2021-04-07 14:18:43 +02:00
James Cole
c67b10e38d Fix nullpointer. 2021-04-07 14:17:03 +02:00
James Cole
614ceabd45 Fix #4593 2021-04-07 11:35:53 +02:00
James Cole
a94b2e8806 Extra if 2021-04-07 10:52:38 +02:00
James Cole
732616984b Fix nullpointer. 2021-04-07 09:32:12 +02:00
James Cole
eddf0c1200 Various code cleanup. 2021-04-07 07:53:05 +02:00
James Cole
49013264d5 Various code cleanup. 2021-04-07 07:32:54 +02:00
James Cole
f12744ad8c Various code cleanup. 2021-04-07 07:28:43 +02:00
James Cole
4ddcb0c965 Do not report on OAuth exceptions. 2021-04-07 05:56:50 +02:00
James Cole
0846d4898f Various code cleanup. 2021-04-07 05:55:51 +02:00
James Cole
cb746200fa Various code cleanup. 2021-04-06 18:48:02 +02:00
James Cole
fe06a1f7a0 Various code cleanup. 2021-04-06 18:36:37 +02:00
James Cole
9c1cee738d Update translations. 2021-04-06 17:12:58 +02:00
James Cole
7cc778673a Various code cleanup. 2021-04-06 17:12:31 +02:00
James Cole
38d0f0427f Various code cleanup. 2021-04-06 17:00:16 +02:00
James Cole
8572280b7b Update CI scripts. 2021-04-06 17:00:00 +02:00
James Cole
69b1769f22 Refactor old methods. 2021-04-06 13:30:09 +02:00
James Cole
5ceef2e9c3 Various code cleanup. 2021-04-06 08:51:27 +02:00
James Cole
d32446b171 Various code cleanup. 2021-04-05 22:12:57 +02:00
James Cole
d8ca39ffea Code for #4607 2021-04-05 22:12:11 +02:00
James Cole
d47bddde62 Change code for #4607 2021-04-05 21:53:28 +02:00
James Cole
e4802ec958 Clean up some code. 2021-04-05 21:52:55 +02:00
James Cole
6d855e119d Update frontend. 2021-04-05 14:18:49 +02:00
James Cole
7ab81e493a Delete accounts. 2021-04-05 12:49:02 +02:00
James Cole
fa0397e431 Fix #4603 2021-04-05 12:42:34 +02:00
James Cole
aba3b361be Update composer. 2021-04-05 12:42:20 +02:00
James Cole
1cf188ee08 Add some if-statements to the migrations. 2021-04-05 10:56:56 +02:00
James Cole
f5983f08fd Rename parameter 2021-04-05 10:56:41 +02:00
James Cole
b812c2e09f Simplify account creation. 2021-04-05 10:56:08 +02:00
James Cole
d7466efbe1 Merge pull request #4602 from firefly-iii/dependabot/composer/develop/predis/predis-1.1.7
Bump predis/predis from 1.1.6 to 1.1.7
2021-04-05 07:19:25 +02:00
dependabot[bot]
dff30af9f2 Bump predis/predis from 1.1.6 to 1.1.7
Bumps [predis/predis](https://github.com/predis/predis) from 1.1.6 to 1.1.7.
- [Release notes](https://github.com/predis/predis/releases)
- [Changelog](https://github.com/predis/predis/blob/v1.1.7/CHANGELOG.md)
- [Commits](https://github.com/predis/predis/compare/v1.1.6...v1.1.7)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-05 05:06:58 +00:00
James Cole
25dcb73e27 Fix #4600 2021-04-05 06:14:13 +02:00
James Cole
63ed3d09d5 Increase digits in bcscale. 2021-04-04 18:01:16 +02:00
James Cole
caf1e6010b Add browser TZ to debug page. 2021-04-04 17:57:46 +02:00
James Cole
2d97408c1f Move debug view so it can be made universal. 2021-04-04 17:54:11 +02:00
James Cole
01c0d76c5a Add info about reset. 2021-04-04 16:05:35 +02:00
James Cole
7c7032d951 Add info about reset. 2021-04-04 16:04:39 +02:00
James Cole
6e722f5833 Ignore 404's. 2021-04-04 15:53:17 +02:00
James Cole
d3502c56d3 Fix #4593 2021-04-04 12:48:44 +02:00
James Cole
1b8eb3cd68 Move some views. 2021-04-04 08:43:33 +02:00
James Cole
bc7bd84221 Add missing library 2021-04-04 08:33:10 +02:00
James Cole
85b22341a4 Various updates. 2021-04-04 08:31:15 +02:00
James Cole
f8c725e5b2 Merge branch 'feature/api-bulk-transaction-move' into develop 2021-04-04 07:28:54 +02:00
James Cole
e6344e4f51 Update changelog. 2021-04-04 07:28:35 +02:00
James Cole
8eac10bf89 Simplify routine. 2021-04-04 07:25:52 +02:00
James Cole
c1da0eeced Update chart to include time. 2021-04-04 07:25:42 +02:00
James Cole
0a6d5b1766 Fix error views. 2021-04-03 20:51:19 +02:00
James Cole
4035ac09ce Clean up error display. 2021-04-03 20:46:37 +02:00
James Cole
f81a7cfac0 Merge tag '5.5.3' into develop
5.5.3
2021-04-03 18:50:37 +02:00
James Cole
2b086879cc Merge branch 'release/5.5.3' into main 2021-04-03 18:50:36 +02:00
James Cole
a3091f7509 Final code for 5.3.3 2021-04-03 18:48:21 +02:00
James Cole
70a6ac0038 Make it easier to login for demo users. 2021-04-03 14:03:54 +02:00
James Cole
468a53d587 Add API route to move transactions from one account to another. 2021-04-03 13:56:45 +02:00
James Cole
51f3b17ad2 Clean up handler. 2021-04-03 13:19:11 +02:00
James Cole
a864d3bd56 Rebuild frontend 2021-04-03 12:52:50 +02:00
James Cole
a4d5aa0d10 Do not report on authentication exceptions. 2021-04-03 12:46:50 +02:00
James Cole
aff5ac2c0a Update changelog and version. 2021-04-03 12:39:01 +02:00
James Cole
effe92a05c Make sure the email error mails everything. 2021-04-03 12:32:29 +02:00
James Cole
a4ca6dfd38 Update email message paths for #4586 2021-04-03 12:30:34 +02:00
James Cole
e6012e1ca2 Fix email templates and handler for #4586 2021-04-03 12:25:35 +02:00
James Cole
472497cafd Fix #4586 2021-04-03 12:16:29 +02:00
James Cole
34f4b16a63 Rebuild frontend. 2021-04-03 10:40:31 +02:00
James Cole
7f55a870d9 Merge tag '5.5.2' into develop
5.5.2
2021-04-03 07:40:01 +02:00
James Cole
6a37ad7c15 Merge branch 'release/5.5.2' into main 2021-04-03 07:40:00 +02:00
James Cole
788981d170 Expand changelog and readme. 2021-04-03 07:39:23 +02:00
James Cole
f377c92d8a Fix percentage call. 2021-04-03 07:32:48 +02:00
James Cole
0dc3068f7f Rebuild frontend and update packages. 2021-04-03 07:22:21 +02:00
James Cole
1ad8ec6dd1 Update transactions. 2021-04-03 07:17:42 +02:00
James Cole
18a80f3519 Update code for API 2021-04-03 07:16:43 +02:00
James Cole
82f8b091c1 Do not run auto budgets for inactive budgets #4582 2021-04-03 06:04:17 +02:00
James Cole
71785bae57 Upgrade frontend. 2021-04-02 22:33:31 +02:00
James Cole
6d979a68f2 Fix missing first_date 2021-04-02 16:31:24 +02:00
James Cole
ef852ef963 Update changelog 2021-04-02 07:06:39 +02:00
James Cole
00b0ce6c6e Add dates for #4575, fiddle with comments for #4578 2021-04-02 06:59:55 +02:00
James Cole
5750087d37 Fix nullpointer in bill transformer. 2021-04-02 06:57:31 +02:00
James Cole
a2ae977550 Tag and recurrence as date-time string 2021-04-02 06:18:04 +02:00
James Cole
b893651223 Turn dates into date-times. 2021-04-01 21:06:40 +02:00
James Cole
e221d37d2b Convert dates into date-times for #4571 2021-04-01 20:56:11 +02:00
James Cole
f0acab21a3 Add timezone to template for #4571 2021-04-01 06:48:06 +02:00
James Cole
93dc5fae09 Fix #4571 2021-04-01 06:47:56 +02:00
James Cole
40746db53e Add timezone to debug for #4571 2021-04-01 06:47:33 +02:00
James Cole
4404db650c Fix #4574 2021-04-01 06:19:01 +02:00
James Cole
ab968a56e6 Fix #4572 2021-04-01 06:15:50 +02:00
James Cole
246a3d000a Make sure admin page is not empty. 2021-04-01 06:15:32 +02:00
James Cole
cbcf251bb3 Fix #4570 2021-03-31 19:36:08 +02:00
James Cole
0756054690 Sort expenses and revenue by percentage. 2021-03-31 08:10:46 +02:00
James Cole
b6109ca93e Update some translations. 2021-03-31 07:03:15 +02:00
James Cole
823ee2cea0 Clean up operations repository for #4566 2021-03-31 06:54:32 +02:00
James Cole
18f6052681 Part of #4566 2021-03-31 06:29:08 +02:00
James Cole
4f2ab72567 Ref #4567 2021-03-31 06:08:02 +02:00
James Cole
bc6a2c2cca Fix #4562 2021-03-30 08:12:48 +02:00
James Cole
7a6a911f7f Fix #4560 2021-03-30 06:32:42 +02:00
James Cole
abeff39829 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2021-03-30 06:11:04 +02:00
James Cole
4d18c1bf83 Add if statement for DB migration issue. 2021-03-29 18:53:31 +02:00
James Cole
8a818059f2 Merge pull request #4554 from firefly-iii/dependabot/composer/develop/vimeo/psalm-4.7.0
Bump vimeo/psalm from 4.6.4 to 4.7.0
2021-03-29 08:37:56 +00:00
James Cole
3768262224 Merge pull request #4553 from firefly-iii/dependabot/composer/develop/league/commonmark-1.5.8
Bump league/commonmark from 1.5.7 to 1.5.8
2021-03-29 08:25:22 +00:00
dependabot[bot]
b790a0731e Bump vimeo/psalm from 4.6.4 to 4.7.0
Bumps [vimeo/psalm](https://github.com/vimeo/psalm) from 4.6.4 to 4.7.0.
- [Release notes](https://github.com/vimeo/psalm/releases)
- [Commits](https://github.com/vimeo/psalm/compare/4.6.4...4.7.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-29 05:09:49 +00:00
dependabot[bot]
c38b9eeb08 Bump league/commonmark from 1.5.7 to 1.5.8
Bumps [league/commonmark](https://github.com/thephpleague/commonmark) from 1.5.7 to 1.5.8.
- [Release notes](https://github.com/thephpleague/commonmark/releases)
- [Changelog](https://github.com/thephpleague/commonmark/blob/latest/CHANGELOG-1.x.md)
- [Commits](https://github.com/thephpleague/commonmark/compare/1.5.7...1.5.8)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-29 05:09:20 +00:00
James Cole
22b376da71 Regenerate frontend. 2021-03-29 06:54:53 +02:00
James Cole
fde53abb1a Enable edit function 2021-03-29 06:53:51 +02:00
James Cole
c32e09a2b3 Fix #4551 2021-03-29 06:53:30 +02:00
James Cole
a243f3d7c2 Call to bad function breaks several reports, fix #4547 2021-03-28 20:42:03 +02:00
James Cole
3586c76b95 Parse improvements for budget overview. 2021-03-28 14:34:02 +02:00
James Cole
c9d9840235 Merge branch 'release/5.5.1' into main 2021-03-28 12:06:08 +02:00
James Cole
10390953fe Merge tag '5.5.1' into develop
5.5.1
2021-03-28 12:06:08 +02:00
James Cole
d6c6bc05ad Set correct version :( 2021-03-28 12:05:56 +02:00
James Cole
a17601e2a8 Update meta files and build. 2021-03-28 11:59:25 +02:00
James Cole
93d481b515 Merge branch 'release/5.5.0' into main
# Conflicts:
#	config/firefly.php
#	frontend/src/scss/_variables.scss
#	frontend/yarn.lock
#	public/v2/css/app.css
#	public/v2/css/app.css.map
#	public/v2/js/transactions/edit.js
#	public/v2/js/transactions/edit.js.map
#	public/v2/js/vendor.js
#	public/v2/js/vendor.js.map
2021-03-28 11:56:01 +02:00
James Cole
13b8ba3746 Rebuild frontend, final files for 5.5.0 2021-03-28 11:53:27 +02:00
James Cole
e6fbd9259d Remove some newlines 2021-03-28 11:47:34 +02:00
James Cole
b5eeacc128 Code cleanup. 2021-03-28 11:46:23 +02:00
James Cole
2c575f3ca5 Code cleanup. 2021-03-28 11:43:07 +02:00
James Cole
5abbb8a807 Code cleanup. 2021-03-28 11:39:26 +02:00
James Cole
6401b5c9eb Clean up readme and old code. 2021-03-28 10:37:01 +02:00
James Cole
7edc1a2571 Files for new release. 2021-03-27 20:10:05 +01:00
James Cole
f489add855 Update releases.md 2021-03-27 20:03:24 +01:00
James Cole
adfdcdb9c6 Files for new reelase. 2021-03-27 20:01:28 +01:00
James Cole
922050a79b Should be enough to fix order issues. 2021-03-27 15:28:11 +01:00
James Cole
436bef01da Always reset order. 2021-03-27 15:13:48 +01:00
James Cole
b7ba6f81da Option for showing active/inactive accounts. 2021-03-27 15:06:40 +01:00
James Cole
381b09d68b Sortable account list. 2021-03-27 10:19:22 +01:00
James Cole
fbed65d464 Fix broken preference 2021-03-26 06:31:25 +01:00
James Cole
bcd612d42f First frontend with working account lists. No sorting. 2021-03-26 06:14:35 +01:00
James Cole
eac2293778 Remove some debug info. 2021-03-24 19:28:07 +01:00
James Cole
72deff81f9 Fix some alignments and a translation. 2021-03-24 06:28:32 +01:00
James Cole
a8e9ba3041 Fix #4520 2021-03-24 06:06:18 +01:00
James Cole
3e73641378 Rebuild CSS 2021-03-23 18:45:27 +01:00
James Cole
7cf44a604a Rebuild frontpage. 2021-03-23 18:39:01 +01:00
James Cole
9003db6eba Fix #4529 2021-03-23 18:38:24 +01:00
James Cole
d1c87e1c21 Fix issues where rule action would use old data. 2021-03-23 06:42:26 +01:00
James Cole
ccaadd1f52 Update php7/8 detection code. 2021-03-23 06:23:30 +01:00
James Cole
e64653eaff Update firefly.php 2021-03-22 05:46:20 +00:00
James Cole
abb0f3d2be Whoops. 2021-03-22 06:45:13 +01:00
James Cole
7f48a1b6ee Fix validation, update version. 2021-03-22 06:40:36 +01:00
James Cole
4affed8f68 Rebuild frontend, first working edit form (with feedback) 2021-03-21 20:38:44 +01:00
James Cole
1088a43866 Rebuild frontend, first working edit form (no feedback) 2021-03-21 18:48:47 +01:00
James Cole
e0d0f49bfd Merge branch 'release/5.5.0-beta.3' into main
# Conflicts:
#	frontend/yarn.lock
2021-03-21 11:11:25 +01:00
James Cole
ee5b4d6a03 Update packages. 2021-03-21 11:10:11 +01:00
James Cole
7062294419 Rebuild front 2021-03-21 11:09:12 +01:00
James Cole
97a687e40a Final things. 2021-03-21 11:06:08 +01:00
James Cole
206845575c Code cleanup 2021-03-21 09:15:40 +01:00
James Cole
da1751940e Add flame 2021-03-21 09:03:49 +01:00
James Cole
9502544abf Update icons and favicons. 2021-03-21 08:56:51 +01:00
James Cole
b975ed87a0 Remove old Firefly III favicon 2021-03-21 08:54:56 +01:00
James Cole
cbf3118b8a Fix tests 2021-03-21 08:13:19 +01:00
James Cole
657726e667 First run of all tests 2021-03-21 07:30:44 +01:00
James Cole
eb90dac89d Transaction tests work. 2021-03-21 07:09:39 +01:00
James Cole
4c2f758f69 Tests also validate existing data. 2021-03-20 19:17:22 +01:00
James Cole
e577db4635 Catch for RSA 2021-03-20 18:42:38 +01:00
James Cole
b1023cdfda Update test routine. 2021-03-20 15:40:20 +01:00
James Cole
f15da8e4b3 Update test routine. 2021-03-20 15:39:49 +01:00
James Cole
5df6135a0e Make sure expectations work. 2021-03-20 15:28:44 +01:00
James Cole
186cbed777 Refactor available budget test 2021-03-20 08:00:58 +01:00
James Cole
bc5aa4b4cd Update test code. 2021-03-20 07:21:13 +01:00
James Cole
836f0ecf3f Fix tests for account 2021-03-20 07:02:06 +01:00
James Cole
e32f14578c Update frontend. 2021-03-19 09:19:37 +01:00
James Cole
03d3ede036 Expand test code. 2021-03-19 06:12:28 +01:00
James Cole
b4d44fdd2b Fix #4514 2021-03-16 17:39:21 +01:00
James Cole
a93da2a912 Expand some test helpers. 2021-03-16 17:20:41 +01:00
James Cole
df86c89acc Some test scripts. 2021-03-16 14:34:11 +01:00
James Cole
690edb8fcc Some notes in code. 2021-03-16 07:23:53 +01:00
James Cole
a43bd745d1 make sure all forms work as expected for b3. 2021-03-16 06:42:58 +01:00
James Cole
d5ee87ddee Fix some edge cases in recurrences. 2021-03-15 19:51:55 +01:00
James Cole
a0b46d9d8a Fix meta services for recurrences. 2021-03-15 10:31:11 +01:00
James Cole
1783f0beb1 Extra content to fix recurrences. 2021-03-15 08:51:21 +01:00
James Cole
8d84dfb3aa Small bugfixes for issues in beta 2 2021-03-15 07:45:46 +01:00
James Cole
b9bf5c9856 Merge pull request #4510 from firefly-iii/dependabot/composer/develop/vimeo/psalm-4.6.3
Bump vimeo/psalm from 4.6.2 to 4.6.3
2021-03-15 06:43:45 +00:00
dependabot[bot]
83be7c1886 Bump vimeo/psalm from 4.6.2 to 4.6.3
Bumps [vimeo/psalm](https://github.com/vimeo/psalm) from 4.6.2 to 4.6.3.
- [Release notes](https://github.com/vimeo/psalm/releases)
- [Commits](https://github.com/vimeo/psalm/compare/4.6.2...4.6.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-15 05:09:48 +00:00
James Cole
81404d934c Fix RSA token creation. 2021-03-14 20:14:51 +01:00
James Cole
1a73b6d20d 5.5.0-beta.2 2021-03-14 20:05:06 +01:00
James Cole
1817160d48 Update meta data for new release. 2021-03-14 20:03:27 +01:00
James Cole
5eb1f93851 Most model tests now working. 2021-03-14 16:42:10 +01:00
James Cole
beece4dcbb Fix tests for transaction storage. 2021-03-14 16:08:49 +01:00
James Cole
288052905e Expand all test models. 2021-03-14 10:41:17 +01:00
James Cole
40a463d62a Expand test cases. 2021-03-14 06:20:23 +01:00
James Cole
d82fe2ab4c Max out the number of iterations 2021-03-14 04:55:48 +01:00
James Cole
fc4d4a455b Rebuild frontend 2021-03-13 21:32:24 +01:00
James Cole
e113225b37 Merge pull request #4503 from Aethiran/develop
Fixed amountPerPeriod not respecting bill skips
2021-03-13 19:39:52 +00:00
James Cole
07f62b0d5c Fix budget limit tests 2021-03-13 20:01:42 +01:00
James Cole
25bc0b0b78 Expand test cases. 2021-03-13 19:47:19 +01:00
James Cole
1f50f65bb7 Finish budget tests. 2021-03-13 19:03:08 +01:00
Mirko Berger
2a4486a8dc Fixed typecast 2021-03-13 17:25:04 +01:00
James Cole
fdcd6befb6 Completed bill tests. 2021-03-13 17:16:38 +01:00
James Cole
c9f7f877c0 Expand API test to bill store. 2021-03-13 16:47:29 +01:00
Mirko Berger
5ab156c7ad Fixed amountPerPeriod not respecting bill skips 2021-03-13 15:43:45 +01:00
James Cole
bdb298740a Also test attachments. 2021-03-13 14:33:48 +01:00
James Cole
bd040c80b2 Fix account API tests. 2021-03-13 13:26:45 +01:00
James Cole
7118abe28d Fix some tests for account API 2021-03-13 12:01:01 +01:00
James Cole
668b169a5e Fix parsing of bill ID. 2021-03-13 06:25:25 +01:00
James Cole
a03e000af1 Small code cleanup. 2021-03-12 20:25:15 +01:00
James Cole
81f5224b11 Clean up old tests. 2021-03-12 18:31:19 +01:00
James Cole
a05d006fa7 Update installation commands. 2021-03-12 06:30:40 +01:00
James Cole
748d61fb8f Various code reshuffelling. 2021-03-12 06:20:01 +01:00
James Cole
97561ab9c9 Some code cleanup and a new migration. 2021-03-12 06:17:50 +01:00
James Cole
aec70cf6a0 Add invalid transaction type. 2021-03-12 06:11:50 +01:00
James Cole
b0c9745982 Make sure rules respect active flag. 2021-03-12 06:11:34 +01:00
James Cole
ab5df484e8 Merge pull request #4491 from firefly-iii/dependabot/npm_and_yarn/frontend/elliptic-6.5.4
Bump elliptic from 6.5.3 to 6.5.4 in /frontend
2021-03-11 08:31:30 +00:00
dependabot[bot]
cecef98d7d Bump elliptic from 6.5.3 to 6.5.4 in /frontend
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4.
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.3...v6.5.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-11 07:48:16 +00:00
James Cole
625e31d053 Fix tags and rule groups. 2021-03-11 06:29:07 +01:00
James Cole
75c8ec7c0a Merge pull request #4488 from KaihatsuOnline/patch-1
Set Japanese Yen decimal places to zero in the TransactionCurrencySeeder
2021-03-10 14:58:17 +00:00
KaihatsuOnline
31df959935 Set Japanese Yen decimal places to zero in the TransactionCurrencySeeder. 2021-03-10 23:54:42 +09:00
James Cole
238a582d8a Update validators so they can handle one field at a time. 2021-03-10 06:34:03 +01:00
James Cole
5f4b025be5 Store location correctly. 2021-03-08 18:21:49 +01:00
James Cole
e0c3c91bf2 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2021-03-08 17:56:27 +01:00
James Cole
2a975c302f Fix some stuff in account API calls. still need to solve location. 2021-03-08 17:56:21 +01:00
James Cole
9369d908c8 Merge pull request #4480 from firefly-iii/dependabot/npm_and_yarn/develop/postcss-8.2.7
Bump postcss from 8.2.6 to 8.2.7
2021-03-08 12:55:50 +01:00
James Cole
83f38eb8c8 Merge pull request #4481 from firefly-iii/dependabot/npm_and_yarn/develop/jquery-3.6.0
Bump jquery from 3.5.1 to 3.6.0
2021-03-08 12:55:36 +01:00
James Cole
4d34160ede Verify sorting 2021-03-08 09:56:40 +01:00
dependabot[bot]
ddaec93550 Bump jquery from 3.5.1 to 3.6.0
Bumps [jquery](https://github.com/jquery/jquery) from 3.5.1 to 3.6.0.
- [Release notes](https://github.com/jquery/jquery/releases)
- [Commits](https://github.com/jquery/jquery/compare/3.5.1...3.6.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-08 05:07:55 +00:00
dependabot[bot]
66e0cea18d Bump postcss from 8.2.6 to 8.2.7
Bumps [postcss](https://github.com/postcss/postcss) from 8.2.6 to 8.2.7.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.2.6...8.2.7)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-08 05:07:42 +00:00
James Cole
e3161a8b9c Can now update order of accounts efficiently. 2021-03-07 16:19:14 +01:00
James Cole
91394553c3 Add some routes for transfers. 2021-03-07 15:26:42 +01:00
James Cole
414c99489c Final patches in API 2021-03-07 12:16:03 +01:00
James Cole
ba163f82d1 Webhook API 2021-03-07 12:13:22 +01:00
James Cole
c4882231d1 Submit user preferences. 2021-03-07 09:46:12 +01:00
James Cole
d6dd6795fe Can again destroy data. 2021-03-07 08:16:33 +01:00
James Cole
f2e5e7d182 Fix config routes. 2021-03-07 07:43:18 +01:00
James Cole
7606757d78 Add "about" paths. 2021-03-07 06:30:59 +01:00
James Cole
ea07b831f2 Fix reference to recurrence update 2021-03-07 06:15:13 +01:00
James Cole
9cc20bbea7 All model API things done! 2021-03-06 22:22:51 +01:00
James Cole
9632f69b15 Recreate routes for transaction links. 2021-03-06 22:15:17 +01:00
James Cole
b11e3145c5 Implement currency routes. 2021-03-06 21:39:29 +01:00
James Cole
fa5d33caf5 Add routes for transactions. 2021-03-06 20:52:42 +01:00
James Cole
93a31337fc Add transaction API, untested. 2021-03-06 20:05:17 +01:00
James Cole
a8a1eca89e Add tags 2021-03-06 19:04:09 +01:00
James Cole
4ba713e553 Fix rule group API 2021-03-06 18:00:49 +01:00
James Cole
cfa9e8b318 Set up and manage rule endpoints. 2021-03-06 17:43:06 +01:00
James Cole
2437759368 Recurring transactions. 2021-03-06 16:15:39 +01:00
James Cole
b43ea5c108 Add bills and piggy banks 2021-03-06 15:00:34 +01:00
James Cole
84263b9ee8 API routes for object groups. 2021-03-06 14:50:48 +01:00
James Cole
2b2d10d1f1 Reformat API routes. 2021-03-06 12:45:49 +01:00
James Cole
1c041b9543 Clean up budget and limit routes. 2021-03-06 08:40:51 +01:00
James Cole
c53f8b6dfc Refer to the correct model. 2021-03-06 07:22:13 +01:00
James Cole
1c661a86b6 Temporary reshuffeling to fix API 2021-03-06 07:20:49 +01:00
James Cole
0afebb26e0 Expend API. 2021-03-05 20:17:39 +01:00
James Cole
0cb0a628e3 Added new API routes. 2021-03-05 16:28:59 +01:00
James Cole
30d653faee Updated API code. 2021-03-05 07:03:28 +01:00
James Cole
b0d4ebbf4b Different logo 2021-03-04 16:19:19 +01:00
James Cole
711999f589 Export data in API. 2021-03-04 06:28:16 +01:00
James Cole
fcf578784f Some API route cleanup. 2021-03-03 17:06:18 +01:00
James Cole
4f76ea560d First edit that works locally. Rebuilt CSS. 2021-03-03 07:03:44 +01:00
James Cole
df9c9ce044 Clean up some API endpoints. 2021-03-03 07:02:57 +01:00
James Cole
1f12d81008 Merged. 2021-03-01 15:31:16 +01:00
James Cole
736f7963d1 Make sure components are edit-ready. 2021-03-01 15:27:27 +01:00
James Cole
b38e2a994d Merge pull request #4458 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/popperjs/core-2.8.6
Bump @popperjs/core from 2.8.4 to 2.8.6 in /frontend
2021-03-01 07:43:38 +00:00
James Cole
b8bd232622 Merge pull request #4457 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/v-calendar-2.2.4
Bump v-calendar from 2.2.3 to 2.2.4 in /frontend
2021-03-01 07:43:30 +00:00
James Cole
27bc33add3 Merge pull request #4452 from firefly-iii/dependabot/composer/develop/vimeo/psalm-4.6.2
Bump vimeo/psalm from 4.6.1 to 4.6.2
2021-03-01 07:43:22 +00:00
James Cole
0703343748 Merge pull request #4453 from firefly-iii/dependabot/npm_and_yarn/develop/vue-i18n-8.23.0
Bump vue-i18n from 8.22.4 to 8.23.0
2021-03-01 07:43:14 +00:00
James Cole
584963f360 Merge pull request #4451 from firefly-iii/dependabot/npm_and_yarn/develop/laravel-mix-6.0.13
Bump laravel-mix from 6.0.11 to 6.0.13
2021-03-01 07:43:05 +00:00
James Cole
054e563c59 Merge pull request #4450 from firefly-iii/dependabot/composer/develop/laravel/passport-10.1.1
Bump laravel/passport from 10.1.0 to 10.1.1
2021-03-01 07:42:32 +00:00
dependabot[bot]
fd1dc9ca04 Bump @popperjs/core from 2.8.4 to 2.8.6 in /frontend
Bumps [@popperjs/core](https://github.com/popperjs/popper-core) from 2.8.4 to 2.8.6.
- [Release notes](https://github.com/popperjs/popper-core/releases)
- [Commits](https://github.com/popperjs/popper-core/compare/v2.8.4...v2.8.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:41:40 +00:00
dependabot[bot]
e5669fcfab Bump v-calendar from 2.2.3 to 2.2.4 in /frontend
Bumps [v-calendar](https://github.com/nathanreyes/v-calendar) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/nathanreyes/v-calendar/releases)
- [Commits](https://github.com/nathanreyes/v-calendar/compare/v2.2.3...v2.2.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:41:20 +00:00
James Cole
a7f57e10eb Merge pull request #4454 from firefly-iii/dependabot/composer/develop/phpstan/phpstan-0.12.80
Bump phpstan/phpstan from 0.12.78 to 0.12.80
2021-03-01 05:24:10 +00:00
James Cole
c9dea3f531 Merge pull request #4455 from firefly-iii/dependabot/composer/develop/mockery/mockery-1.4.3
Bump mockery/mockery from 1.4.2 to 1.4.3
2021-03-01 05:23:42 +00:00
James Cole
ef74016a13 Merge pull request #4456 from firefly-iii/dependabot/composer/develop/laravel/framework-8.29.0
Bump laravel/framework from 8.28.1 to 8.29.0
2021-03-01 05:23:32 +00:00
dependabot[bot]
ff6a0d2cb5 Bump laravel/framework from 8.28.1 to 8.29.0
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.28.1 to 8.29.0.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.28.1...v8.29.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:09:08 +00:00
dependabot[bot]
4af923ac78 Bump mockery/mockery from 1.4.2 to 1.4.3
Bumps [mockery/mockery](https://github.com/mockery/mockery) from 1.4.2 to 1.4.3.
- [Release notes](https://github.com/mockery/mockery/releases)
- [Changelog](https://github.com/mockery/mockery/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mockery/mockery/compare/1.4.2...1.4.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:08:40 +00:00
dependabot[bot]
34f1e8a56b Bump phpstan/phpstan from 0.12.78 to 0.12.80
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.78 to 0.12.80.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.78...0.12.80)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:08:22 +00:00
dependabot[bot]
968ff30058 Bump vue-i18n from 8.22.4 to 8.23.0
Bumps [vue-i18n](https://github.com/kazupon/vue-i18n) from 8.22.4 to 8.23.0.
- [Release notes](https://github.com/kazupon/vue-i18n/releases)
- [Changelog](https://github.com/kazupon/vue-i18n/blob/v8.x/CHANGELOG.md)
- [Commits](https://github.com/kazupon/vue-i18n/compare/v8.22.4...v8.23.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:08:08 +00:00
dependabot[bot]
aaf0c5d276 Bump vimeo/psalm from 4.6.1 to 4.6.2
Bumps [vimeo/psalm](https://github.com/vimeo/psalm) from 4.6.1 to 4.6.2.
- [Release notes](https://github.com/vimeo/psalm/releases)
- [Commits](https://github.com/vimeo/psalm/compare/4.6.1...4.6.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:08:02 +00:00
dependabot[bot]
4b2392c966 Bump laravel-mix from 6.0.11 to 6.0.13
Bumps [laravel-mix](https://github.com/JeffreyWay/laravel-mix) from 6.0.11 to 6.0.13.
- [Release notes](https://github.com/JeffreyWay/laravel-mix/releases)
- [Changelog](https://github.com/JeffreyWay/laravel-mix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/JeffreyWay/laravel-mix/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:07:51 +00:00
dependabot[bot]
9bcf56157d Bump laravel/passport from 10.1.0 to 10.1.1
Bumps [laravel/passport](https://github.com/laravel/passport) from 10.1.0 to 10.1.1.
- [Release notes](https://github.com/laravel/passport/releases)
- [Changelog](https://github.com/laravel/passport/blob/10.x/CHANGELOG.md)
- [Commits](https://github.com/laravel/passport/compare/v10.1.0...v10.1.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 05:07:42 +00:00
James Cole
43e8779e3b Fix #4435 2021-02-27 05:59:40 +01:00
James Cole
2287339781 Split controllers 2021-02-27 05:53:27 +01:00
James Cole
4d9aafbeaf Go to end of day. 2021-02-26 18:09:48 +01:00
James Cole
5944cda03a Rebuild frontend. 2021-02-26 06:39:20 +01:00
James Cole
9aa743b31b Update frontend. 2021-02-25 06:27:43 +01:00
James Cole
6bd6b1eb95 Fix https://github.com/firefly-iii/firefly-iii/issues/4426 2021-02-24 06:01:43 +01:00
James Cole
fc0202eb74 Fix performance issues in budget controller. 2021-02-23 18:49:54 +01:00
James Cole
fd0dc3d289 Experimental fix for https://github.com/firefly-iii/firefly-iii/issues/4424 2021-02-23 17:43:34 +01:00
James Cole
aa4695bbbf Recreate frontend. 2021-02-23 06:50:57 +01:00
James Cole
09d751076e Single event 2021-02-23 06:45:09 +01:00
James Cole
419c1a75dd Better event. 2021-02-23 06:42:04 +01:00
James Cole
fb821ea63e Better event. 2021-02-23 06:39:25 +01:00
James Cole
f1be63e8bf Better event. 2021-02-23 06:38:46 +01:00
James Cole
7725b2a723 Better event. 2021-02-23 06:37:56 +01:00
James Cole
f5a83fa84f Better event. 2021-02-23 06:36:44 +01:00
James Cole
c1d090db67 Better event. 2021-02-23 06:33:00 +01:00
James Cole
7aaec92ae6 Better event. 2021-02-23 06:31:51 +01:00
James Cole
afe6f07e61 Better event. 2021-02-23 06:31:07 +01:00
James Cole
b151ec0c85 Better event. 2021-02-23 06:30:08 +01:00
James Cole
978c56b16b Better event. 2021-02-23 06:28:12 +01:00
James Cole
fbbf002451 Better event. 2021-02-23 06:27:07 +01:00
James Cole
13cd9312f8 Add some extra text. 2021-02-23 06:26:46 +01:00
James Cole
a534c142c1 Extra debug for https://github.com/firefly-iii/firefly-iii/issues/4424 2021-02-23 06:20:17 +01:00
James Cole
89ece0ce78 Clean up events from account 2021-02-22 19:58:10 +01:00
James Cole
9b65f468a0 Better event for location. 2021-02-22 19:41:54 +01:00
James Cole
e1826cdfb2 Simplify description field. 2021-02-22 19:38:21 +01:00
James Cole
97d12cd77a Remove logs. 2021-02-22 18:50:12 +01:00
James Cole
5b5c988aa3 Rebuild frontend, do not use store in components. 2021-02-22 18:43:26 +01:00
James Cole
6d9acd1dc2 Event for clone 2021-02-22 18:41:03 +01:00
James Cole
860fc507b7 Remove comments 2021-02-22 18:40:46 +01:00
James Cole
5f1d4292ad Merge pull request #4422 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/popperjs/core-2.8.2
Bump @popperjs/core from 2.7.0 to 2.8.2 in /frontend
2021-02-22 13:07:52 +00:00
James Cole
7e2cda7f41 Merge pull request #4421 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/sass-1.32.8
Bump sass from 1.32.7 to 1.32.8 in /frontend
2021-02-22 13:07:42 +00:00
James Cole
ef394e1024 Merge pull request #4420 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/lodash-4.17.21
Bump lodash from 4.17.20 to 4.17.21 in /frontend
2021-02-22 05:48:06 +00:00
dependabot[bot]
f2f0d82f89 Bump @popperjs/core from 2.7.0 to 2.8.2 in /frontend
Bumps [@popperjs/core](https://github.com/popperjs/popper-core) from 2.7.0 to 2.8.2.
- [Release notes](https://github.com/popperjs/popper-core/releases)
- [Commits](https://github.com/popperjs/popper-core/compare/v2.7.0...v2.8.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:41:42 +00:00
dependabot[bot]
2032ef6662 Bump sass from 1.32.7 to 1.32.8 in /frontend
Bumps [sass](https://github.com/sass/dart-sass) from 1.32.7 to 1.32.8.
- [Release notes](https://github.com/sass/dart-sass/releases)
- [Changelog](https://github.com/sass/dart-sass/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sass/dart-sass/compare/1.32.7...1.32.8)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:41:22 +00:00
dependabot[bot]
7b5c41d541 Bump lodash from 4.17.20 to 4.17.21 in /frontend
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:38:21 +00:00
James Cole
f844197954 Merge pull request #4416 from firefly-iii/dependabot/composer/develop/vimeo/psalm-4.6.1
Bump vimeo/psalm from 4.5.2 to 4.6.1
2021-02-22 05:28:50 +00:00
James Cole
0353e4aa95 Merge pull request #4417 from firefly-iii/dependabot/composer/develop/laravel/framework-8.28.1
Bump laravel/framework from 8.27.0 to 8.28.1
2021-02-22 05:28:43 +00:00
James Cole
3ee93de280 Merge pull request #4418 from firefly-iii/dependabot/composer/develop/phpstan/phpstan-0.12.78
Bump phpstan/phpstan from 0.12.76 to 0.12.78
2021-02-22 05:28:33 +00:00
dependabot[bot]
1175c1d676 Bump phpstan/phpstan from 0.12.76 to 0.12.78
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.76 to 0.12.78.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.76...0.12.78)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:07:36 +00:00
dependabot[bot]
6d51d0cc79 Bump laravel/framework from 8.27.0 to 8.28.1
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.27.0 to 8.28.1.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.27.0...v8.28.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:07:25 +00:00
dependabot[bot]
12e19c0a70 Bump vimeo/psalm from 4.5.2 to 4.6.1
Bumps [vimeo/psalm](https://github.com/vimeo/psalm) from 4.5.2 to 4.6.1.
- [Release notes](https://github.com/vimeo/psalm/releases)
- [Commits](https://github.com/vimeo/psalm/compare/4.5.2...4.6.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-22 05:07:07 +00:00
James Cole
00f25836c0 Remove extra logging. 2021-02-19 16:25:36 +01:00
James Cole
c4669ade29 Fix #4412 2021-02-19 16:24:52 +01:00
James Cole
2b06279f05 Fix transaction submission. 2021-02-17 06:54:00 +01:00
James Cole
252ea7277b Drop table. 2021-02-17 06:51:03 +01:00
James Cole
20c45aa0e0 Rebuild frontend 2021-02-17 06:46:26 +01:00
James Cole
c34a5ed3e4 Location is submitted and added to the array through events. 2021-02-17 06:37:33 +01:00
James Cole
5ff7884596 Remove unused translation #4406 2021-02-17 06:19:49 +01:00
James Cole
e04245de96 Refactor some API routes. 2021-02-17 06:17:48 +01:00
James Cole
25e4d78119 API will display journal location. 2021-02-16 10:19:20 +01:00
James Cole
d5d0e6b4ba Give journals a location. 2021-02-16 09:53:28 +01:00
James Cole
2f14753405 Refactor API code. 2021-02-16 09:52:39 +01:00
James Cole
5e7c57744c Update frontend. 2021-02-15 20:32:29 +01:00
James Cole
0ac0dbc774 Merge pull request #4399 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/sass-loader-11.0.1
Bump sass-loader from 10.1.1 to 11.0.1 in /frontend
2021-02-15 06:08:13 +00:00
James Cole
0b368edd97 Merge pull request #4396 from firefly-iii/dependabot/composer/develop/phpstan/phpstan-0.12.76
Bump phpstan/phpstan from 0.12.73 to 0.12.76
2021-02-15 05:43:19 +00:00
James Cole
d0e7fe37bb Merge pull request #4397 from firefly-iii/dependabot/composer/develop/laravel/framework-8.27.0
Bump laravel/framework from 8.26.1 to 8.27.0
2021-02-15 05:43:11 +00:00
James Cole
c2d9dcf696 Merge pull request #4395 from firefly-iii/dependabot/composer/develop/vimeo/psalm-4.5.2
Bump vimeo/psalm from 4.4.1 to 4.5.2
2021-02-15 05:43:01 +00:00
James Cole
4efc0ffc6e Merge pull request #4398 from firefly-iii/dependabot/npm_and_yarn/develop/postcss-8.2.6
Bump postcss from 8.2.5 to 8.2.6
2021-02-15 05:42:53 +00:00
James Cole
e64b5dcf3a Fix https://github.com/firefly-iii/firefly-iii/issues/4394 2021-02-15 06:39:55 +01:00
dependabot[bot]
cb4b6f7023 Bump sass-loader from 10.1.1 to 11.0.1 in /frontend
Bumps [sass-loader](https://github.com/webpack-contrib/sass-loader) from 10.1.1 to 11.0.1.
- [Release notes](https://github.com/webpack-contrib/sass-loader/releases)
- [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/sass-loader/compare/v10.1.1...v11.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-15 05:39:11 +00:00
dependabot[bot]
784b24fe3c Bump postcss from 8.2.5 to 8.2.6
Bumps [postcss](https://github.com/postcss/postcss) from 8.2.5 to 8.2.6.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.2.5...8.2.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-15 05:07:38 +00:00
dependabot[bot]
fba23c927b Bump laravel/framework from 8.26.1 to 8.27.0
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.26.1 to 8.27.0.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.26.1...v8.27.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-15 05:07:29 +00:00
dependabot[bot]
5771b8c3c6 Bump phpstan/phpstan from 0.12.73 to 0.12.76
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.73 to 0.12.76.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.73...0.12.76)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-15 05:07:05 +00:00
dependabot[bot]
5c7ba4e065 Bump vimeo/psalm from 4.4.1 to 4.5.2
Bumps [vimeo/psalm](https://github.com/vimeo/psalm) from 4.4.1 to 4.5.2.
- [Release notes](https://github.com/vimeo/psalm/releases)
- [Commits](https://github.com/vimeo/psalm/compare/4.4.1...4.5.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-15 05:06:54 +00:00
James Cole
e51f593a2d Split components for future recycling. 2021-02-14 19:13:42 +01:00
James Cole
bfd925fbfe Rebuild frontend. 2021-02-14 10:43:58 +01:00
James Cole
993fe3ae0a Stop using window.sessionStart, start using smart code. 2021-02-14 07:54:05 +01:00
James Cole
70aaa67cfc Update frontend. 2021-02-14 07:53:20 +01:00
James Cole
45f918963e Rebuild frontend. 2021-02-13 20:04:18 +01:00
James Cole
1ecc454f70 Fix issue in rule engine. 2021-02-12 20:15:23 +01:00
James Cole
95966cdcd4 Update frontend 2021-02-12 20:15:07 +01:00
James Cole
b1f2780fb6 Update build script 2021-02-10 07:00:45 +01:00
James Cole
416f8e2855 Build frontend 2021-02-10 06:55:56 +01:00
James Cole
1558da60aa Fix #4007 2021-02-08 15:12:04 +01:00
James Cole
18a9d90d46 Merge pull request #4363 from firefly-iii/dependabot/npm_and_yarn/develop/postcss-8.2.5 2021-02-08 09:27:54 +01:00
dependabot[bot]
934ae994cc Bump postcss from 8.2.4 to 8.2.5
Bumps [postcss](https://github.com/postcss/postcss) from 8.2.4 to 8.2.5.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.2.4...8.2.5)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 08:22:24 +00:00
James Cole
ee4b38c279 Merge pull request #4362 from firefly-iii/dependabot/npm_and_yarn/frontend/develop/sass-loader-11.0.0
Bump sass-loader from 10.1.1 to 11.0.0 in /frontend
2021-02-08 06:44:31 +01:00
James Cole
2171ed7912 Merge pull request #4358 from firefly-iii/dependabot/npm_and_yarn/develop/uiv-1.2.3
Bump uiv from 1.2.2 to 1.2.3
2021-02-08 06:44:19 +01:00
James Cole
4e274e6a09 Merge pull request #4359 from firefly-iii/dependabot/composer/develop/phpunit/phpunit-9.5.2
Bump phpunit/phpunit from 9.5.1 to 9.5.2
2021-02-08 06:43:17 +01:00
James Cole
1be0cf99b9 Merge pull request #4357 from firefly-iii/dependabot/composer/develop/phpstan/phpstan-0.12.73
Bump phpstan/phpstan from 0.12.70 to 0.12.73
2021-02-08 06:42:25 +01:00
dependabot[bot]
60a41887cb Bump sass-loader from 10.1.1 to 11.0.0 in /frontend
Bumps [sass-loader](https://github.com/webpack-contrib/sass-loader) from 10.1.1 to 11.0.0.
- [Release notes](https://github.com/webpack-contrib/sass-loader/releases)
- [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/sass-loader/compare/v10.1.1...v11.0.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:41:48 +00:00
James Cole
f9582cd4fe Merge pull request #4360 from firefly-iii/dependabot/composer/develop/nunomaduro/larastan-0.7.0
Bump nunomaduro/larastan from 0.6.13 to 0.7.0
2021-02-08 06:41:40 +01:00
James Cole
edcd5d56c9 Merge pull request #4361 from firefly-iii/dependabot/composer/develop/laravel/framework-8.26.1
Bump laravel/framework from 8.25.0 to 8.26.1
2021-02-08 06:41:31 +01:00
dependabot[bot]
14fa91d17f Bump laravel/framework from 8.25.0 to 8.26.1
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.25.0 to 8.26.1.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.25.0...v8.26.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:08:41 +00:00
dependabot[bot]
e411e629ce Bump nunomaduro/larastan from 0.6.13 to 0.7.0
Bumps [nunomaduro/larastan](https://github.com/nunomaduro/larastan) from 0.6.13 to 0.7.0.
- [Release notes](https://github.com/nunomaduro/larastan/releases)
- [Changelog](https://github.com/nunomaduro/larastan/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nunomaduro/larastan/compare/v0.6.13...v0.7.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:07:55 +00:00
dependabot[bot]
5626b11b66 Bump phpunit/phpunit from 9.5.1 to 9.5.2
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.1 to 9.5.2.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.1...9.5.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:07:26 +00:00
dependabot[bot]
eee42a0f99 Bump uiv from 1.2.2 to 1.2.3
Bumps [uiv](https://github.com/uiv-lib/uiv) from 1.2.2 to 1.2.3.
- [Release notes](https://github.com/uiv-lib/uiv/releases)
- [Commits](https://github.com/uiv-lib/uiv/compare/v1.2.2...v1.2.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:07:11 +00:00
dependabot[bot]
03787e3d74 Bump phpstan/phpstan from 0.12.70 to 0.12.73
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 0.12.70 to 0.12.73.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Commits](https://github.com/phpstan/phpstan/compare/0.12.70...0.12.73)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-08 05:07:09 +00:00
James Cole
b9e7d99a87 Rebuil frontend. 2021-02-05 08:21:52 +01:00
James Cole
b0ac0ea0cf Catch undefined var 2021-02-05 06:57:12 +01:00
James Cole
8e42f25a1e Rebuild frontend 2021-02-05 06:45:27 +01:00
James Cole
d69843d4bc Rebuild frontend 2021-02-03 19:52:47 +01:00
James Cole
fdba28fad7 Experimental refactor of API code. 2021-02-03 14:57:37 +01:00
James Cole
3b2dd93316 Code to fix https://github.com/firefly-iii/firefly-iii/issues/4340 2021-02-03 10:41:41 +01:00
James Cole
2ad7336605 Fix #4340 2021-02-03 06:46:03 +01:00
James Cole
84ad8529df Fix #4339 2021-02-03 06:31:14 +01:00
James Cole
e441df367d Fix #4338 2021-02-03 06:25:58 +01:00
James Cole
08fcff2a98 Make it easier to switch between v1/v2 layout. 2021-02-03 06:25:46 +01:00
James Cole
957e34a57a Make it easier to switch between v1/v2 layout. 2021-02-02 19:20:44 +01:00
James Cole
71239dbf5b Fix #4334 2021-02-02 07:00:51 +01:00
James Cole
c5d27f0148 Make it easier to switch between v1/v2 layout. 2021-02-01 06:57:29 +01:00
James Cole
b8340ddb59 Make it easier to switch between v1/v2 layout. 2021-02-01 06:47:33 +01:00
James Cole
f16b7c4286 Make it easier to switch between v1/v2 layout. 2021-02-01 06:43:19 +01:00
James Cole
b126177546 Fix reference to pagination template. 2021-02-01 06:38:33 +01:00
James Cole
1121377d2d Make it easier to switch between v1/v2 layout. 2021-02-01 06:31:43 +01:00
James Cole
f9220b8999 Make it easier to switch between v1/v2 layout. 2021-02-01 06:29:45 +01:00
James Cole
be05513ecd Rename files so the old layout will take over. 2021-01-31 20:38:05 +01:00
James Cole
ffe18c63a5 Make it easier to switch between v1/v2 layout. 2021-01-31 20:35:54 +01:00
James Cole
fd8a59924d Make it easier to switch between v1/v2 layout. 2021-01-31 20:35:44 +01:00
James Cole
fdd9d81701 Make it easier to switch between v1/v2 layout. 2021-01-31 20:31:40 +01:00
James Cole
2dd2d0ef58 New frontend. 2021-01-31 20:31:27 +01:00
James Cole
329c3b14d5 Make it easier to switch between v1/v2 layout. 2021-01-31 20:31:13 +01:00
James Cole
27815d0311 Make it easier to switch between v1/v2 layout. 2021-01-31 20:29:17 +01:00
James Cole
21da959203 Make it easier to switch between v1/v2 layout. 2021-01-31 20:26:24 +01:00
James Cole
d60c5a26de New frontend. 2021-01-31 07:26:52 +01:00
James Cole
d4c9f53b10 Update some components. 2021-01-30 12:24:55 +01:00
James Cole
02cd0600ea Update some copyrights. 2021-01-29 18:50:35 +01:00
James Cole
7ffc621638 Merge tag '5.5.0-beta.1' into develop
5.5.0-beta.1
2021-01-29 18:21:08 +01:00
1550 changed files with 61503 additions and 72365 deletions

View File

@@ -10,6 +10,19 @@ parameters:
- '#is neither abstract nor final#'
- '#Control structures using switch should not be used\.#'
- '#has a nullable return type declaration#'
- '#with a nullable type declaration#'
- '#with null as default value#'
- '#Constructor in [a-zA-Z0-9\\_]+ has parameter \$[a-zA-Z0-9\\_]+ with default value#'
-
message: '#Function compact\(\) should not be used.#'
paths:
- ../app/Http/Controllers
- ../app/Support/Http/Controllers/RenderPartialViews.php
- ../app/Support/Form/FormSupport.php
- ../app/Support/Form/CurrencyForm.php
- ../app/Support/Form/AccountForm.php
- ../app/Support/ExpandedForm.php
- ../app/Generator/Report
paths:
- ../app
- ../database
@@ -17,4 +30,4 @@ parameters:
- ../bootstrap/app.php
# The level 8 is the highest level. original was 5
level: 5
level: 2

View File

@@ -1,12 +1,33 @@
#!/usr/bin/env bash
#
# phpstan.sh
# Copyright (c) 2021 james@firefly-iii.org
#
# This file is part of Firefly III (https://github.com/firefly-iii).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Install composer packages
composer install --no-scripts --no-ansi
#composer install --no-scripts --no-ansi
# enable test .env file.
cp .ci/.env.ci .env
# Do static code analysis.
./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress
# ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress
./vendor/bin/phpstan analyse -c .ci/phpstan.neon
exit 0

View File

@@ -1,9 +1,30 @@
#!/usr/bin/env bash
#
# phpunit.sh
# Copyright (c) 2021 james@firefly-iii.org
#
# This file is part of Firefly III (https://github.com/firefly-iii).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# enable test .env file.
cp .ci/.env.ci ../.env
# download test database
# TODO no longer exists
wget --quiet https://raw.githubusercontent.com/firefly-iii/test-data/main/test_db.sqlite -o storage/database/test_db.sqlite
# run phpunit

View File

@@ -13,6 +13,7 @@ nb_NO
nl_NL
pl_PL
pt_BR
pt_PT
ro_RO
ru_RU
sk_SK

View File

@@ -118,6 +118,7 @@ REDIS_CACHE_DB="1"
COOKIE_PATH="/"
COOKIE_DOMAIN=
COOKIE_SECURE=false
COOKIE_SAMESITE=lax
# If you want Firefly III to mail you, update these settings
# For instructions, see: https://docs.firefly-iii.org/advanced-installation/email
@@ -154,8 +155,16 @@ SEND_REPORT_JOURNALS=true
# Set a Mapbox API key here (see mapbox.com) so there might be a map available at various places.
# If you use Docker or similar, you can set this variable from a file by appending it with _FILE
# Take note: it is no longer necessary to set this value, and it will be removed in future versions.
MAPBOX_API_KEY=
#
# Instead of the mapbox API key, just set this value to true if you want to set the location
# of certain things, like transactions. Since this involves an external service, it's optional
# and disabled by default.
#
ENABLE_EXTERNAL_MAP=false
# The map will default to this location:
MAP_DEFAULT_LAT=51.983333
MAP_DEFAULT_LONG=5.916667
@@ -166,6 +175,10 @@ MAP_DEFAULT_ZOOM=6
# For full instructions on these settings please visit:
# https://docs.firefly-iii.org/advanced-installation/authentication
# If you use Docker or similar, you can set this variable from a file by appending it with _FILE
#
# If you enable 'ldap' AND you run Docker, the Docker image will contact packagist.org
# This is necessary to download the required packages.
#
LOGIN_PROVIDER=eloquent
# It's also possible to change the way users are authenticated. You could use Authelia for example.
@@ -319,6 +332,7 @@ BROADCAST_DRIVER=log
QUEUE_DRIVER=sync
CACHE_PREFIX=firefly
PUSHER_KEY=
IPINFO_TOKEN=
PUSHER_SECRET=
PUSHER_ID=
DEMO_USERNAME=

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
/node_modules
/frontend/node_modules
/frontend/fonts
/frontend/images
/public/hot
/public/storage
/storage/*.key

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Account;
@@ -43,7 +42,6 @@ class AccountController extends Controller
private array $balanceTypes;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*/
@@ -90,7 +88,7 @@ class AccountController extends Controller
}
$return[] = [
'id' => $account->id,
'id' => (string)$account->id,
'name' => $account->name,
'name_with_balance' => $nameWithBalance,
'type' => $account->accountType->type,
@@ -104,8 +102,6 @@ class AccountController extends Controller
// custom order.
$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];
usort(
$return, function ($a, $b) use ($order) {
$pos_a = array_search($a['type'], $order);

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Bill;
@@ -38,7 +37,6 @@ class BillController extends Controller
{
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*/
@@ -69,13 +67,12 @@ class BillController extends Controller
$filtered = $result->map(
static function (Bill $item) {
return [
'id' => $item->id,
'id' => (string)$item->id,
'name' => $item->name,
];
}
);
return response()->json($filtered->toArray());
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Budget;
@@ -38,7 +37,6 @@ class BudgetController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
* BudgetController constructor.
*/
@@ -69,7 +67,7 @@ class BudgetController extends Controller
$filtered = $result->map(
static function (Budget $item) {
return [
'id' => $item->id,
'id' => (string)$item->id,
'name' => $item->name,
];
}

View File

@@ -37,7 +37,6 @@ class CategoryController extends Controller
{
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
*/
@@ -68,7 +67,7 @@ class CategoryController extends Controller
$filtered = $result->map(
static function (Category $item) {
return [
'id' => $item->id,
'id' => (string)$item->id,
'name' => $item->name,
];
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\TransactionCurrency;
@@ -38,7 +37,6 @@ class CurrencyController extends Controller
{
private CurrencyRepositoryInterface $repository;
/**
* CurrencyController constructor.
*/
@@ -62,7 +60,7 @@ class CurrencyController extends Controller
*
* @return JsonResponse
*/
public function currenciesWithCode(AutocompleteRequest $request): JsonResponse
public function currencies(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$collection = $this->repository->searchCurrency($data['query'], $data['limit']);
@@ -71,8 +69,8 @@ class CurrencyController extends Controller
/** @var TransactionCurrency $currency */
foreach ($collection as $currency) {
$result[] = [
'id' => $currency->id,
'name' => sprintf('%s (%s)', $currency->name, $currency->code),
'id' => (string)$currency->id,
'name' => $currency->name,
'code' => $currency->code,
'symbol' => $currency->symbol,
'decimal_places' => $currency->decimal_places,
@@ -87,7 +85,7 @@ class CurrencyController extends Controller
*
* @return JsonResponse
*/
public function currencies(AutocompleteRequest $request): JsonResponse
public function currenciesWithCode(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$collection = $this->repository->searchCurrency($data['query'], $data['limit']);
@@ -96,8 +94,8 @@ class CurrencyController extends Controller
/** @var TransactionCurrency $currency */
foreach ($collection as $currency) {
$result[] = [
'id' => $currency->id,
'name' => $currency->name,
'id' => (string)$currency->id,
'name' => sprintf('%s (%s)', $currency->name, $currency->code),
'code' => $currency->code,
'symbol' => $currency->symbol,
'decimal_places' => $currency->decimal_places,

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\ObjectGroup;
@@ -38,7 +37,6 @@ class ObjectGroupController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* CurrencyController constructor.
*/
@@ -68,10 +66,10 @@ class ObjectGroupController extends Controller
$return = [];
$result = $this->repository->search($data['query'], $data['limit']);
/** @var ObjectGroup $account */
/** @var ObjectGroup $objectGroup */
foreach ($result as $objectGroup) {
$return[] = [
'id' => $objectGroup->id,
'id' => (string)$objectGroup->id,
'name' => $objectGroup->title,
'title' => $objectGroup->title,
];

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\PiggyBank;
@@ -37,11 +36,9 @@ use Illuminate\Http\JsonResponse;
*/
class PiggyBankController extends Controller
{
private AccountRepositoryInterface $accountRepository;
private PiggyBankRepositoryInterface $piggyRepository;
private AccountRepositoryInterface $accountRepository;
/**
* PiggyBankController constructor.
*/
@@ -78,7 +75,7 @@ class PiggyBankController extends Controller
foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;
$response[] = [
'id' => $piggy->id,
'id' => (string)$piggy->id,
'name' => $piggy->name,
'currency_id' => $currency->id,
'currency_name' => $currency->name,
@@ -106,7 +103,7 @@ class PiggyBankController extends Controller
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;
$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';
$response[] = [
'id' => $piggy->id,
'id' => (string)$piggy->id,
'name' => $piggy->name,
'name_with_balance' => sprintf(
'%s (%s / %s)', $piggy->name, app('amount')->formatAnything($currency, $currentAmount, false),

View File

@@ -23,13 +23,56 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class RecurrenceController
*/
class RecurrenceController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param AutocompleteRequest $request
*
* @return JsonResponse
*/
public function recurring(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$rules = $this->repository->searchRecurrence($data['query'], $data['limit']);
$response = [];
/** @var Rule $rule */
foreach ($rules as $rule) {
$response[] = [
'id' => (string)$rule->id,
'name' => $rule->title,
'description' => $rule->description,
];
}
return response()->json($response);
}
}

View File

@@ -23,13 +23,56 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class RuleController
*/
class RuleController extends Controller
{
private RuleRepositoryInterface $repository;
/**
* RuleController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RuleRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param AutocompleteRequest $request
*
* @return JsonResponse
*/
public function rules(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$rules = $this->repository->searchRule($data['query'], $data['limit']);
$response = [];
/** @var Rule $rule */
foreach ($rules as $rule) {
$response[] = [
'id' => (string)$rule->id,
'name' => $rule->title,
'description' => $rule->description,
];
}
return response()->json($response);
}
}

View File

@@ -23,13 +23,55 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class RuleGroupController
*/
class RuleGroupController extends Controller
{
private RuleGroupRepositoryInterface $repository;
/**
* RuleGroupController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RuleGroupRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param AutocompleteRequest $request
*
* @return JsonResponse
*/
public function ruleGroups(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$groups = $this->repository->searchRuleGroup($data['query'], $data['limit']);
$response = [];
/** @var RuleGroup $group */
foreach ($groups as $group) {
$response[] = [
'id' => (string)$group->id,
'name' => $group->title,
'description' => $group->description,
];
}
return response()->json($response);
}
}

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\Tag;
@@ -38,7 +37,6 @@ class TagController extends Controller
{
private TagRepositoryInterface $repository;
/**
* TagController constructor.
*/
@@ -71,7 +69,7 @@ class TagController extends Controller
/** @var Tag $tag */
foreach ($result as $tag) {
$array[] = [
'id' => $tag->id,
'id' => (string)$tag->id,
'name' => $tag->tag,
'tag' => $tag->tag,
];

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\TransactionJournal;
@@ -38,10 +37,8 @@ use Illuminate\Support\Collection;
*/
class TransactionController extends Controller
{
private JournalRepositoryInterface $repository;
private TransactionGroupRepositoryInterface $groupRepository;
private JournalRepositoryInterface $repository;
/**
* TransactionController constructor.
@@ -63,7 +60,6 @@ class TransactionController extends Controller
);
}
/**
* @param AutocompleteRequest $request
*
@@ -81,8 +77,8 @@ class TransactionController extends Controller
/** @var TransactionJournal $journal */
foreach ($filtered as $journal) {
$array[] = [
'id' => $journal->id,
'transaction_group_id' => $journal->transaction_group_id,
'id' => (string)$journal->id,
'transaction_group_id' => (string)$journal->transaction_group_id,
'name' => $journal->description,
'description' => $journal->description,
];
@@ -102,7 +98,7 @@ class TransactionController extends Controller
$result = new Collection;
if (is_numeric($data['query'])) {
// search for group, not journal.
$firstResult = $this->groupRepository->find((int) $data['query']);
$firstResult = $this->groupRepository->find((int)$data['query']);
if (null !== $firstResult) {
// group may contain multiple journals, each a result:
foreach ($firstResult->transactionJournals as $journal) {
@@ -120,8 +116,8 @@ class TransactionController extends Controller
/** @var TransactionJournal $journal */
foreach ($result as $journal) {
$array[] = [
'id' => $journal->id,
'transaction_group_id' => $journal->transaction_group_id,
'id' => (string)$journal->id,
'transaction_group_id' => (string)$journal->transaction_group_id,
'name' => sprintf('#%d: %s', $journal->transaction_group_id, $journal->description),
'description' => sprintf('#%d: %s', $journal->transaction_group_id, $journal->description),
];

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Models\TransactionType;
@@ -37,7 +36,6 @@ class TransactionTypeController extends Controller
{
private TransactionTypeRepositoryInterface $repository;
/**
* TransactionTypeController constructor.
*/
@@ -69,7 +67,7 @@ class TransactionTypeController extends Controller
foreach ($types as $type) {
// different key for consistency.
$array[] = [
'id' => $type->id,
'id' => (string)$type->id,
'name' => $type->type,
'type' => $type->type,
];

View File

@@ -1,259 +0,0 @@
<?php
/**
* BudgetLimitController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\BudgetLimitStoreRequest;
use FireflyIII\Api\V1\Requests\BudgetLimitUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\BudgetLimitTransformer;
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\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class BudgetLimitController.
*/
class BudgetLimitController extends Controller
{
use TransactionFilter;
private BudgetLimitRepositoryInterface $blRepository;
private BudgetRepositoryInterface $repository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->repository->setUser($user);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(BudgetLimit $budgetLimit): JsonResponse
{
$this->blRepository->destroyBudgetLimit($budgetLimit);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request): JsonResponse
{
$manager = $this->getManager();
$manager->parseIncludes('budget');
$budgetId = (int)($request->get('budget_id') ?? 0);
$budget = $this->repository->findNull($budgetId);
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$this->parameters->set('budget_id', $budgetId);
$collection = new Collection;
if (null === $budget) {
$collection = $this->blRepository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end'));
}
if (null !== $budget) {
$collection = $this->blRepository->getBudgetLimits($budget, $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'));
$paginator->setPath(route('api.v1.budget_limits.index') . $this->buildParams());
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Display the specified resource.
*
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(BudgetLimit $budgetLimit): JsonResponse
{
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a newly created resource in storage.
*
* @param BudgetLimitStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(BudgetLimitStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$data['start_date'] = $data['start'];
$data['end_date'] = $data['end'];
$budgetLimit = $this->blRepository->store($data);
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show all transactions.
*
* @param Request $request
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager();
/** @var User $admin */
$admin = auth()->user();
// 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->setTypes($types);
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.budget_limits.transactions', [$budgetLimit->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update the specified resource in storage.
*
* @param BudgetLimitUpdateRequest $request
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
*/
public function update(BudgetLimitUpdateRequest $request, BudgetLimit $budgetLimit): JsonResponse
{
$data = $request->getAll();
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -26,10 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Api\V1\Requests\Data\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;
@@ -44,9 +43,7 @@ class AccountController extends Controller
use ApiSupport;
private CurrencyRepositoryInterface $currencyRepository;
private AccountRepositoryInterface $repository;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
@@ -71,92 +68,6 @@ class AccountController extends Controller
);
}
/**
* @param DateRequest $request
*
* @return JsonResponse
*/
public function expenseOverview(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->repository->getAccountsByType([AccountType::EXPENSE]);
$accountNames = $this->extractNames($accounts);
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int) $accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int) $currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
$diff = bcsub($endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float) $diff,
'currency_id' => $currencyId,
];
}
}
}
// sort temp array by amount.
$amounts = array_column($tempData, 'diff_float');
array_multisort($amounts, SORT_DESC, $tempData);
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$currentSet = [
'label' => trans('firefly.box_spent_in_currency', ['currency' => $currency->symbol]),
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'type' => 'bar', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => $this->expandNames($tempData),
];
$chartData[$currencyId] = $currentSet;
}
// loop temp data and place data in correct array:
foreach ($tempData as $entry) {
$currencyId = $entry['currency_id'];
$name = $entry['name'];
$chartData[$currencyId]['entries'][$name] = round((float) $entry['difference'], $chartData[$currencyId]['currency_decimal_places']);
}
$chartData = array_values($chartData);
return response()->json($chartData);
}
/**
* @param DateRequest $request
*
@@ -175,12 +86,12 @@ class AccountController extends Controller
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
$default = app('amount')->getDefaultCurrency();
// @codeCoverageIgnoreStart
if (0 === count($frontPage->data)) {
$frontPage->data = $defaultSet;
$frontPage->save();
}
// @codeCoverageIgnoreEnd
// get accounts:
$accounts = $this->repository->getAccountsById($frontPage->data);
@@ -189,16 +100,16 @@ class AccountController extends Controller
foreach ($accounts as $account) {
$currency = $this->repository->getAccountCurrency($account);
if (null === $currency) {
$currency = $default; // @codeCoverageIgnore
$currency = $default;
}
$currentSet = [
'label' => $account->name,
'currency_id' => $currency->id,
'currency_id' => (string)$currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'start_date' => $start->format('Y-m-d'),
'end_date' => $end->format('Y-m-d'),
'start_date' => $start->toAtomString(),
'end_date' => $end->toAtomString(),
'type' => 'line', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => [],
@@ -206,11 +117,11 @@ class AccountController extends Controller
/** @var Carbon $currentStart */
$currentStart = clone $start;
$range = app('steam')->balanceInRange($account, $start, clone $end);
$previous = round((float) array_values($range)[0], 12);
$previous = round((float)array_values($range)[0], 12);
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->format('Y-m-d');
$balance = array_key_exists($format, $range) ? round((float) $range[$format], 12) : $previous;
$label = $currentStart->toAtomString();
$balance = array_key_exists($format, $range) ? round((float)$range[$format], 12) : $previous;
$previous = $balance;
$currentStart->addDay();
$currentSet['entries'][$label] = $balance;
@@ -220,91 +131,4 @@ class AccountController extends Controller
return response()->json($chartData);
}
/**
* @param DateRequest $request
*
* @return JsonResponse
*/
public function revenueOverview(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->repository->getAccountsByType([AccountType::REVENUE]);
$accountNames = $this->extractNames($accounts);
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int) $accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int) $currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
$diff = bcsub($endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => bcmul($diff, '-1'),
// For some reason this line is never covered in code coverage:
'diff_float' => ((float) $diff) * -1, // @codeCoverageIgnore
'currency_id' => $currencyId,
];
}
}
}
// sort temp array by amount.
$amounts = array_column($tempData, 'diff_float');
array_multisort($amounts, SORT_DESC, $tempData);
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$currentSet = [
'label' => trans('firefly.box_earned_in_currency', ['currency' => $currency->symbol]),
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'type' => 'bar', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => $this->expandNames($tempData),
];
$chartData[$currencyId] = $currentSet;
}
// loop temp data and place data in correct array:
foreach ($tempData as $entry) {
$currencyId = $entry['currency_id'];
$name = $entry['name'];
$chartData[$currencyId]['entries'][$name] = round((float) $entry['difference'], $chartData[$currencyId]['currency_decimal_places']);
}
$chartData = array_values($chartData);
return response()->json($chartData);
}
}

View File

@@ -1,115 +0,0 @@
<?php
/**
* AvailableBudgetController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Chart;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class AvailableBudgetController
*/
class AvailableBudgetController extends Controller
{
private OperationsRepositoryInterface $opsRepository;
private BudgetRepositoryInterface $repository;
/**
* AvailableBudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository->setUser($user);
$this->opsRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param AvailableBudget $availableBudget
*
* @return JsonResponse
*/
public function overview(AvailableBudget $availableBudget): JsonResponse
{
$currency = $availableBudget->transactionCurrency;
$budgets = $this->repository->getActiveBudgets();
$newBudgetInformation = $this->opsRepository->sumExpenses($availableBudget->start_date, $availableBudget->end_date, null, $budgets);
$spent = '0';
foreach ($newBudgetInformation as $currencyId => $info) {
if ($currencyId === (int) $availableBudget->transaction_currency_id) {
$spent = $info['sum'];
}
}
$left = bcadd($availableBudget->amount, $spent);
// left less than zero? Set to zero.
if (-1 === bccomp($left, '0')) {
$left = '0';
}
$chartData = [
[
'label' => trans('firefly.spent'),
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'type' => 'pie',
'yAxisID' => 0, // 0, 1, 2
'entries' => [$spent * -1],
],
[
'label' => trans('firefly.left'),
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'type' => 'line', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => [round((float) $left, $currency->decimal_places)],
],
];
return response()->json($chartData);
}
}

View File

@@ -1,297 +0,0 @@
<?php
/**
* BudgetController.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/**
* Class BudgetController
*/
class BudgetController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
private OperationsRepositoryInterface $opsRepository;
private BudgetRepositoryInterface $repository;
/**
* BudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
return $next($request);
}
);
}
/**
* [
* 'label' => 'label for entire set'
* 'currency_id' => 0,
* 'currency_code' => 'EUR',
* 'currency_symbol' => '$',
* 'currency_decimal_places' => 2,
* 'type' => 'bar', // line, area or bar
* 'yAxisID' => 0, // 0, 1, 2
* 'entries' => ['a' => 1, 'b' => 4],
* ],
*
* @param DateRequest $request
*
* @return JsonResponse
*/
public function overview(DateRequest $request): JsonResponse
{
$dates = $request->getAll();
$budgets = $this->repository->getActiveBudgets();
$budgetNames = [];
$currencyNames = [];
$sets = [];
/** @var Budget $budget */
foreach ($budgets as $budget) {
$expenses = $this->getExpenses($budget, $dates['start'], $dates['end']);
$expenses = $this->filterNulls($expenses);
foreach ($expenses as $set) {
$budgetNames[] = $set['budget_name'];
$currencyNames[] = $set['currency_name'];
$sets[] = $set;
}
}
$budgetNames = array_unique($budgetNames);
$currencyNames = array_unique($currencyNames);
$basic = $this->createSets($budgetNames, $currencyNames);
$filled = $this->fillSets($basic, $sets);
$keys = array_values($filled);
return response()->json($keys);
}
/**
* @param Collection $limits
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
protected function getExpenses(Budget $budget, Carbon $start, Carbon $end): array
{
$limits = $this->blRepository->getBudgetLimits($budget, $start, $end);
if (0 === $limits->count()) {
return $this->getExpenseInRange($budget, $start, $end);
}
$arr = [];
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
$arr[] = $this->getExpensesForLimit($limit);
}
return $arr;
}
/**
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getExpenseInRange(Budget $budget, Carbon $start, Carbon $end): array
{
$spent = $this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget]), null);
$return = [];
/** @var array $set */
foreach ($spent as $set) {
$current = [
'label' => sprintf('%s (%s)', $budget->name, $set['currency_name']),
'budget_name' => $budget->name,
'start_date' => $start->format('Y-m-d'),
'end_date' => $end->format('Y-m-d'),
'currency_id' => (int) $set['currency_id'],
'currency_code' => $set['currency_code'],
'currency_name' => $set['currency_name'],
'currency_symbol' => $set['currency_symbol'],
'currency_decimal_places' => (int) $set['currency_decimal_places'],
'type' => 'bar', // line, area or bar,
'entries' => [],
];
$sumSpent = bcmul($set['sum'], '-1'); // spent
$current['entries']['spent'] = $sumSpent;
$current['entries']['amount'] = '0';
$current['entries']['spent_capped'] = $sumSpent;
$current['entries']['left'] = '0';
$current['entries']['overspent'] = '0';
$return[] = $current;
}
return $return;
}
/**
* @param BudgetLimit $limit
*
* @return array
*/
private function getExpensesForLimit(BudgetLimit $limit): array
{
$budget = $limit->budget;
$spent = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection([$budget]), $limit->transactionCurrency);
$currency = $limit->transactionCurrency;
// when limited to a currency, the count is always one. Or it's empty.
$set = array_shift($spent);
if (null === $set) {
return [];
}
$return = [
'label' => sprintf('%s (%s)', $budget->name, $set['currency_name']),
'budget_name' => $budget->name,
'start_date' => $limit->start_date->format('Y-m-d'),
'end_date' => $limit->end_date->format('Y-m-d'),
'currency_id' => (int) $currency->id,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => (int) $currency->decimal_places,
'type' => 'bar', // line, area or bar,
'entries' => [],
];
$sumSpent = bcmul($set['sum'], '-1'); // spent
$return['entries']['spent'] = $sumSpent;
$return['entries']['amount'] = $limit->amount;
$return['entries']['spent_capped'] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent;
$return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left
$return['entries']['overspent'] = 1 === bccomp($limit->amount, $sumSpent) ? '0' : bcmul(bcadd($set['sum'], $limit->amount), '-1'); // overspent
return $return;
}
/**
* @param array $expenses
*
* @return array
*/
private function filterNulls(array $expenses): array
{
$return = [];
/** @var array|null $arr */
foreach ($expenses as $arr) {
if ([] !== $arr) {
$return[] = $arr;
}
}
return $return;
}
/**
* @param array $budgetNames
* @param array $currencyNames
*
* @return array
*/
private function createSets(array $budgetNames, array $currencyNames): array
{
$return = [];
foreach ($currencyNames as $currencyName) {
$entries = [];
foreach ($budgetNames as $budgetName) {
$label = sprintf('%s (%s)', $budgetName, $currencyName);
$entries[$label] = '0';
}
// left
$return['left'] = [
'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName),
'data_type' => 'left',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// spent_capped
$return['spent_capped'] = [
'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName),
'data_type' => 'spent_capped',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// overspent
$return['overspent'] = [
'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName),
'data_type' => 'overspent',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
}
return $return;
}
/**
* @param array $basic
* @param array $sets
*
* @return array
*/
private function fillSets(array $basic, array $sets): array
{
foreach ($sets as $set) {
$label = $set['label'];
$basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];
$basic['left']['entries'][$label] = $set['entries']['left'];
$basic['overspent']['entries'][$label] = $set['entries']['overspent'];
}
return $basic;
}
}

View File

@@ -1,157 +0,0 @@
<?php
/**
* CategoryController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class CategoryController
*/
class CategoryController extends Controller
{
private CategoryRepositoryInterface $categoryRepository;
private NoCategoryRepositoryInterface $noCatRepository;
private OperationsRepositoryInterface $opsRepository;
private array $categories;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->categoryRepository = app(CategoryRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->noCatRepository = app(NoCategoryRepositoryInterface::class);
$this->categories = [];
$this->categoryRepository->setUser($user);
$this->opsRepository->setUser($user);
$this->noCatRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param DateRequest $request
*
* @return JsonResponse
*/
public function overview(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$tempData = [];
$spentWith = $this->opsRepository->listExpenses($start, $end);
$spentWithout = $this->noCatRepository->listExpenses($start, $end);
/** @var array $set */
foreach ([$spentWith, $spentWithout,] as $set) {
$tempData = $this->processArray($tempData, $set);
}
$chartData = $this->sortArray($tempData);
return response()->json($chartData);
}
/**
* @param array $tempData
* @param array $set
*
* @return array
*/
private function processArray(array $tempData, array $set): array
{
foreach ($set as $currency) {
foreach ($currency['categories'] as $category) {
$this->categories[] = $category['name'];
$outKey = sprintf('%d-e', $currency['currency_id']);
$tempData[$outKey] = $tempData[$outKey] ?? [
'currency_id' => $currency['currency_id'],
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'currency_code' => $currency['currency_code'],
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'type' => 'bar', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => [],
];
foreach ($category['transaction_journals'] as $journal) {
// is it expense or income?
$currentKey = sprintf('%d-%s', $currency['currency_id'], 'e');
$name = $category['name'];
$tempData[$currentKey]['entries'][$name] = $tempData[$currentKey]['entries'][$name] ?? '0';
$tempData[$currentKey]['entries'][$name] = bcadd($tempData[$currentKey]['entries'][$name], $journal['amount']);
}
}
}
return $tempData;
}
/**
* @param array $tempData
*
* @return array
*/
private function sortArray(array $tempData): array
{
// re-sort every spent array and add 0 for missing entries.
foreach ($tempData as $index => $set) {
$oldSet = $set['entries'];
$newSet = [];
foreach ($this->categories as $category) {
$value = $oldSet[$category] ?? '0';
$value = -1 === bccomp($value, '0') ? bcmul($value, '-1') : $value;
$newSet[$category] = $value;
}
$tempData[$index]['entries'] = $newSet;
}
return array_values($tempData);
}
}

View File

@@ -1,117 +0,0 @@
<?php
/**
* ConfigurationController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\ConfigurationRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class ConfigurationController.
*
* @codeCoverageIgnore
*/
class ConfigurationController extends Controller
{
/** @var UserRepositoryInterface The user repository */
private $repository;
/**
* ConfigurationController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(UserRepositoryInterface::class);
/** @var User $admin */
$admin = auth()->user();
if (!$this->repository->hasRole($admin, 'owner')) {
throw new FireflyException('200005: You need the "owner" role to do this.'); // @codeCoverageIgnore
}
return $next($request);
}
);
}
/**
* Show all configuration.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$configData = $this->getConfigData();
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Get all config values.
*
* @return array
*/
private function getConfigData(): array
{
/** @var Configuration $isDemoSite */
$isDemoSite = app('fireflyconfig')->get('is_demo_site');
/** @var Configuration $updateCheck */
$updateCheck = app('fireflyconfig')->get('permission_update_check');
/** @var Configuration $lastCheck */
$lastCheck = app('fireflyconfig')->get('last_update_check');
/** @var Configuration $singleUser */
$singleUser = app('fireflyconfig')->get('single_user_mode');
return [
'is_demo_site' => null === $isDemoSite ? null : $isDemoSite->data,
'permission_update_check' => null === $updateCheck ? null : (int) $updateCheck->data,
'last_update_check' => null === $lastCheck ? null : (int) $lastCheck->data,
'single_user_mode' => null === $singleUser ? null : $singleUser->data,
];
}
/**
* Update the configuration.
*
* @param ConfigurationRequest $request
* @param string $name
*
* @return JsonResponse
*/
public function update(ConfigurationRequest $request, string $name): JsonResponse
{
$data = $request->getAll();
app('fireflyconfig')->set($name, $data['value']);
$configData = $this->getConfigData();
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/*
* AccountController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Data\Bulk;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\Bulk\MoveTransactionsRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use Illuminate\Http\JsonResponse;
/**
* Class AccountController
*/
class AccountController extends Controller
{
private AccountRepositoryInterface $repository;
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param MoveTransactionsRequest $request
*
* @return JsonResponse
*/
public function moveTransactions(MoveTransactionsRequest $request): JsonResponse
{
$accountIds = $request->getAll();
$original = $this->repository->findNull($accountIds['original_account']);
$destination = $this->repository->findNull($accountIds['destination_account']);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->moveTransactions($original, $destination);
return response()->json([], 204);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
/*
* DestroyController.php
* Copyright (c) 2020 james@firefly-iii.org
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Data;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DataDestroyRequest;
use FireflyIII\Api\V1\Requests\Data\DestroyRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@@ -52,9 +52,12 @@ use Illuminate\Http\JsonResponse;
class DestroyController extends Controller
{
/**
* @param DestroyRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function destroy(DataDestroyRequest $request): JsonResponse
public function destroy(DestroyRequest $request): JsonResponse
{
$objects = $request->getObjects();

View File

@@ -0,0 +1,204 @@
<?php
declare(strict_types=1);
/*
* AccountController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Data\Export;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\Export\ExportRequest;
use FireflyIII\Support\Export\ExportDataGenerator;
use Illuminate\Http\Response as LaravelResponse;
use League\Csv\CannotInsertRecord;
/**
* Class ExportController
*/
class ExportController extends Controller
{
private ExportDataGenerator $exporter;
/**
* ExportController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->exporter = app(ExportDataGenerator::class);
$this->exporter->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function accounts(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportAccounts(true);
return $this->returnExport('accounts');
}
/**
* @param string $key
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
private function returnExport(string $key): LaravelResponse
{
$date = date('Y-m-d-H-i-s');
$fileName = sprintf('%s-export-%s.csv', $date, $key);
$data = $this->exporter->export();
/** @var LaravelResponse $response */
$response = response($data[$key]);
$response
->header('Content-Description', 'File Transfer')
->header('Content-Type', 'application/octet-stream')
->header('Content-Disposition', 'attachment; filename=' . $fileName)
->header('Content-Transfer-Encoding', 'binary')
->header('Connection', 'Keep-Alive')
->header('Expires', '0')
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->header('Pragma', 'public')
->header('Content-Length', (string)strlen($data[$key]));
return $response;
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function bills(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportBills(true);
return $this->returnExport('bills');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function budgets(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportBudgets(true);
return $this->returnExport('budgets');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function categories(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportCategories(true);
return $this->returnExport('categories');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function piggyBanks(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportPiggies(true);
return $this->returnExport('piggies');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function recurring(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportRecurring(true);
return $this->returnExport('recurrences');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function rules(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportRules(true);
return $this->returnExport('rules');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function tags(ExportRequest $request): LaravelResponse
{
$this->exporter->setExportTags(true);
return $this->returnExport('tags');
}
/**
* @param ExportRequest $request
*
* @return LaravelResponse
* @throws CannotInsertRecord
*/
public function transactions(ExportRequest $request): LaravelResponse
{
$params = $request->getAll();
$this->exporter->setStart($params['start']);
$this->exporter->setEnd($params['end']);
$this->exporter->setAccounts($params['accounts']);
$this->exporter->setExportTransactions(true);
return $this->returnExport('transactions');
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* DateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\OperationsRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use Illuminate\Http\JsonResponse;
/**
*
* Class AccountController
*
* Shows expense information grouped or limited by date.
* Ie. all expenses grouped by account + currency.
*/
class AccountController extends Controller
{
use ApiSupport;
private CurrencyRepositoryInterface $currencyRepository;
private OperationsRepositoryInterface $opsRepository;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->currencyRepository->setUser($user);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->opsRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$expenses = $this->opsRepository->sumExpensesBySource($start, $end, $assetAccounts);
$result = [];
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$expense['id'],
'name' => $expense['name'],
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function expense(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$expenseAccounts = $request->getExpenseAccounts();
$expenses = $this->opsRepository->sumExpensesByDestination($start, $end, $assetAccounts, $expenseAccounts);
$result = [];
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$expense['id'],
'name' => $expense['name'],
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -0,0 +1,166 @@
<?php
declare(strict_types=1);
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class BillController
*/
class BillController extends Controller
{
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Expenses per bill, possibly filtered by bill and account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function bill(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$bills = $request->getBills();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// get all bills:
if (0 === $bills->count()) {
$bills = $this->repository->getBills();
}
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$collector->setBills($bills);
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$billId = (int)$journal['bill_id'];
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
$key = sprintf('%d-%d', $billId, $currencyId);
$foreignKey = sprintf('%d-%d', $billId, $foreignCurrencyId);
if (0 !== $currencyId) {
$response[$key] = $response[$key] ?? [
'id' => (string)$billId,
'name' => $journal['bill_name'],
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$key]['difference'] = bcadd($response[$key]['difference'], $journal['amount']);
$response[$key]['difference_float'] = (float)$response[$key]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignKey] = $response[$foreignKey] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignKey]['difference'] = bcadd($response[$foreignKey]['difference'], $journal['foreign_amount']);
$response[$foreignKey]['difference_float'] = (float)$response[$foreignKey]['difference'];
}
}
return response()->json(array_values($response));
}
/**
* Expenses for no bill filtered by account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noBill(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$collector->withoutBill();
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
* BudgetController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/**
* Class BudgetController
*/
class BudgetController extends Controller
{
private NoBudgetRepositoryInterface $noRepository;
private OperationsRepositoryInterface $opsRepository;
private BudgetRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(BudgetRepositoryInterface::class);
$this->noRepository = app(NoBudgetRepositoryInterface::class);
$user = auth()->user();
$this->opsRepository->setUser($user);
$this->repository->setUser($user);
$this->noRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function budget(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$budgets = $request->getBudgets();
$assetAccounts = $request->getAssetAccounts();
$result = [];
if (0 === $budgets->count()) {
$budgets = $this->repository->getActiveBudgets();
}
/** @var Budget $budget */
foreach ($budgets as $budget) {
$expenses = $this->opsRepository->sumExpenses($start, $end, $assetAccounts, new Collection([$budget]), null);
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$budget->id,
'name' => $budget->name,
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
}
return response()->json($result);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noBudget(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$result = [];
$expenses = $this->noRepository->sumExpenses($start, $end, $assetAccounts, null);
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
* CategoryController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/**
* Class CategoryController
*/
class CategoryController extends Controller
{
private NoCategoryRepositoryInterface $noRepository;
private OperationsRepositoryInterface $opsRepository;
private CategoryRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(CategoryRepositoryInterface::class);
$this->noRepository = app(NoCategoryRepositoryInterface::class);
$user = auth()->user();
$this->opsRepository->setUser($user);
$this->repository->setUser($user);
$this->noRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$categories = $request->getCategories();
$assetAccounts = $request->getAssetAccounts();
$result = [];
if (0 === $categories->count()) {
$categories = $this->repository->getCategories();
}
/** @var Category $category */
foreach ($categories as $category) {
$expenses = $this->opsRepository->sumExpenses($start, $end, $assetAccounts, new Collection([$category]));
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$category->id,
'name' => $category->name,
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
}
return response()->json($result);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$result = [];
$expenses = $this->noRepository->sumExpenses($start, $end, $assetAccounts);
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -1,131 +0,0 @@
<?php
declare(strict_types=1);
/*
* DateController.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DateController
*
* Shows expense information grouped or limited by date.
* Ie. all expenses grouped by account + currency.
*/
class DateController extends Controller
{
use ApiSupport;
private CurrencyRepositoryInterface $currencyRepository;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->currencyRepository->setUser($user);
return $next($request);
}
);
}
/**
*
*/
public function basic(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->repository->getAccountsByType([AccountType::EXPENSE]);
$accountNames = $this->extractNames($accounts);
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
$diff = bcsub($endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
$tempData[] = [
'id' => $accountId,
'name' => $accountNames[$accountId],
'difference' => bcmul($diff, '-1'),
'difference_float' => ((float)$diff) * -1,
'currency_id' => $currencyId,
'currency_code' => $currencies[$currencyId]->code,
];
}
}
}
// sort temp array by amount.
$amounts = array_column($tempData, 'difference_float');
array_multisort($amounts, SORT_ASC, $tempData);
return response()->json($tempData);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use Illuminate\Http\JsonResponse;
/**
* Class PeriodController
*/
class PeriodController extends Controller
{
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,172 @@
<?php
declare(strict_types=1);
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Insight\Expense;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class TagController
*/
class TagController extends Controller
{
private TagRepositoryInterface $repository;
/**
* TagController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(TagRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Expenses for no tag filtered by account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noTag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$collector->withoutTags();
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
/**
* Expenses per tag, possibly filtered by tag and account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function tag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$tags = $request->getTags();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// get all tags:
if (0 === $tags->count()) {
$tags = $this->repository->get();
}
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
/** @var array $tag */
foreach ($journal['tags'] as $tag) {
$tagId = $tag['id'];
$key = sprintf('%d-%d', $tagId, $currencyId);
$foreignKey = sprintf('%d-%d', $tagId, $foreignCurrencyId);
// on currency ID
if (0 !== $currencyId) {
$response[$key] = $response[$key] ?? [
'id' => (string)$tagId,
'name' => $tag['name'],
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$key]['difference'] = bcadd($response[$key]['difference'], $journal['amount']);
$response[$key]['difference_float'] = (float)$response[$key]['difference'];
}
// on foreign ID
if (0 !== $foreignCurrencyId) {
$response[$foreignKey] = $journal[$foreignKey] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignKey]['difference'] = bcadd($response[$foreignKey]['difference'], $journal['foreign_amount']);
$response[$foreignKey]['difference_float'] = (float)$response[$foreignKey]['difference'];
}
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,136 @@
<?php
/*
* DateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Income;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\OperationsRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use Illuminate\Http\JsonResponse;
/**
*
* Class AccountController
*
* Shows income information grouped or limited by date.
* Ie. all income grouped by account + currency.
* TODO same code as Expense/AccountController.
*/
class AccountController extends Controller
{
use ApiSupport;
private CurrencyRepositoryInterface $currencyRepository;
private OperationsRepositoryInterface $opsRepository;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->currencyRepository->setUser($user);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->opsRepository->setUser($user);
return $next($request);
}
);
}
/**
* TODO same code as Expense/AccountController.
* TODO does not actually include the name of the expense account.
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$income = $this->opsRepository->sumIncomeByDestination($start, $end, $assetAccounts);
$result = [];
/** @var array $entry */
foreach ($income as $entry) {
$result[] = [
'id' => (string)$entry['id'],
'name' => $entry['name'],
'difference' => $entry['sum'],
'difference_float' => (float)$entry['sum'],
'currency_id' => (string)$entry['currency_id'],
'currency_code' => $entry['currency_code'],
];
}
return response()->json($result);
}
/**
* TODO does not actually include the name of the expense account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function revenue(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$revenueAccounts = $request->getRevenueAccounts();
$income = $this->opsRepository->sumIncomeBySource($start, $end, $assetAccounts, $revenueAccounts);
$result = [];
/** @var array $entry */
foreach ($income as $entry) {
$result[] = [
'id' => (string)$entry['id'],
'name' => $entry['name'],
'difference' => $entry['sum'],
'difference_float' => (float)$entry['sum'],
'currency_id' => (string)$entry['currency_id'],
'currency_code' => $entry['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -0,0 +1,128 @@
<?php
/*
* CategoryController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Income;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/**
* Class CategoryController
* TODO same as opposing category controller
*/
class CategoryController extends Controller
{
private NoCategoryRepositoryInterface $noRepository;
private OperationsRepositoryInterface $opsRepository;
private CategoryRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(CategoryRepositoryInterface::class);
$this->noRepository = app(NoCategoryRepositoryInterface::class);
$user = auth()->user();
$this->opsRepository->setUser($user);
$this->repository->setUser($user);
$this->noRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$categories = $request->getCategories();
$assetAccounts = $request->getAssetAccounts();
$result = [];
if (0 === $categories->count()) {
$categories = $this->repository->getCategories();
}
/** @var Category $category */
foreach ($categories as $category) {
$expenses = $this->opsRepository->sumIncome($start, $end, $assetAccounts, new Collection([$category]));
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$category->id,
'name' => $category->name,
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
}
return response()->json($result);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$result = [];
$expenses = $this->noRepository->sumIncome($start, $end, $assetAccounts);
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -1,131 +0,0 @@
<?php
declare(strict_types=1);
/*
* DateController.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Insight\Income;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DateController
*
* Shows income information grouped or limited by date.
* Ie. all income grouped by revenue + currency.
*/
class DateController extends Controller
{
use ApiSupport;
private CurrencyRepositoryInterface $currencyRepository;
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->currencyRepository->setUser($user);
return $next($request);
}
);
}
/**
*
*/
public function basic(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->repository->getAccountsByType([AccountType::REVENUE]);
$accountNames = $this->extractNames($accounts);
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
$endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
$diff = bcsub($endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
$tempData[] = [
'id' => $accountId,
'name' => $accountNames[$accountId],
'difference' => $diff,
'difference_float' => (float)$diff,
'currency_id' => $currencyId,
'currency_code' => $currencies[$currencyId]->code,
];
}
}
}
// sort temp array by amount.
$amounts = array_column($tempData, 'difference_float');
array_multisort($amounts, SORT_ASC, $tempData);
return response()->json($tempData);
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Income;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use Illuminate\Http\JsonResponse;
/**
* Class PeriodController
*/
class PeriodController extends Controller
{
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::DEPOSIT])->setRange($start, $end)->setDestinationAccounts($accounts);
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], app('steam')->positive($journal['amount']));
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd(
$response[$foreignCurrencyId]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,177 @@
<?php
declare(strict_types=1);
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Insight\Income;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class TagController
*/
class TagController extends Controller
{
private TagRepositoryInterface $repository;
/**
* TagController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(TagRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Expenses for no tag filtered by account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noTag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::DEPOSIT])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->withoutTags();
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], app('steam')->positive($journal['amount']));
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd(
$response[$foreignCurrencyId]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
/**
* Expenses per tag, possibly filtered by tag and account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function tag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$tags = $request->getTags();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// get all tags:
if (0 === $tags->count()) {
$tags = $this->repository->get();
}
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::DEPOSIT])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
/** @var array $tag */
foreach ($journal['tags'] as $tag) {
$tagId = $tag['id'];
$key = sprintf('%d-%d', $tagId, $currencyId);
$foreignKey = sprintf('%d-%d', $tagId, $foreignCurrencyId);
// on currency ID
if (0 !== $currencyId) {
$response[$key] = $response[$key] ?? [
'id' => (string)$tagId,
'name' => $tag['name'],
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$key]['difference'] = bcadd($response[$key]['difference'], app('steam')->positive($journal['amount']));
$response[$key]['difference_float'] = (float)$response[$key]['difference'];
}
// on foreign ID
if (0 !== $foreignCurrencyId) {
$response[$foreignKey] = $journal[$foreignKey] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignKey]['difference'] = bcadd(
$response[$foreignKey]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignKey]['difference_float'] = (float)$response[$foreignKey]['difference'];
}
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* AccountController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Transfer;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Repositories\Account\OperationsRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use Illuminate\Http\JsonResponse;
/**
* Class AccountController
*/
class AccountController extends Controller
{
use ApiSupport;
private OperationsRepositoryInterface $opsRepository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->opsRepository->setUser($user);
return $next($request);
}
);
}
/**
* TODO same code as Expense/AccountController.
* TODO does not actually include the name of the expense account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$transfers = $this->opsRepository->sumTransfers($start, $end, $assetAccounts);
return response()->json($transfers);
}
}

View File

@@ -0,0 +1,126 @@
<?php
/*
* CategoryController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Transfer;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/**
* Class CategoryController
*/
class CategoryController extends Controller
{
private NoCategoryRepositoryInterface $noRepository;
private OperationsRepositoryInterface $opsRepository;
private CategoryRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(CategoryRepositoryInterface::class);
$this->noRepository = app(NoCategoryRepositoryInterface::class);
$user = auth()->user();
$this->opsRepository->setUser($user);
$this->repository->setUser($user);
$this->noRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$categories = $request->getCategories();
$assetAccounts = $request->getAssetAccounts();
$result = [];
if (0 === $categories->count()) {
$categories = $this->repository->getCategories();
}
/** @var Category $category */
foreach ($categories as $category) {
$expenses = $this->opsRepository->sumTransfers($start, $end, $assetAccounts, new Collection([$category]));
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'id' => (string)$category->id,
'name' => $category->name,
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
}
return response()->json($result);
}
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
$result = [];
$expenses = $this->noRepository->sumTransfers($start, $end, $assetAccounts);
/** @var array $expense */
foreach ($expenses as $expense) {
$result[] = [
'difference' => $expense['sum'],
'difference_float' => (float)$expense['sum'],
'currency_id' => (string)$expense['currency_id'],
'currency_code' => $expense['currency_code'],
];
}
return response()->json($result);
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* PeriodController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Transfer;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use Illuminate\Http\JsonResponse;
/**
* Class PeriodController
*/
class PeriodController extends Controller
{
/**
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::TRANSFER])->setRange($start, $end)->setDestinationAccounts($accounts);
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], app('steam')->positive($journal['amount']));
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd(
$response[$foreignCurrencyId]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
}

View File

@@ -0,0 +1,178 @@
<?php
/*
* TagController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Insight\Transfer;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class TagController
*/
class TagController extends Controller
{
private TagRepositoryInterface $repository;
/**
* TagController constructor.
* TODO lots of copying and pasting here.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(TagRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Expenses for no tag filtered by account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function noTag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::TRANSFER])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->withoutTags();
$genericSet = $collector->getExtractedJournals();
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
if (0 !== $currencyId) {
$response[$currencyId] = $response[$currencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], app('steam')->positive($journal['amount']));
$response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];
}
if (0 !== $foreignCurrencyId) {
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignCurrencyId]['difference'] = bcadd(
$response[$foreignCurrencyId]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];
}
}
return response()->json(array_values($response));
}
/**
* Transfers per tag, possibly filtered by tag and account.
*
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function tag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
$tags = $request->getTags();
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
// get all tags:
if (0 === $tags->count()) {
$tags = $this->repository->get();
}
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::TRANSFER])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];
/** @var array $tag */
foreach ($journal['tags'] as $tag) {
$tagId = $tag['id'];
$key = sprintf('%d-%d', $tagId, $currencyId);
$foreignKey = sprintf('%d-%d', $tagId, $foreignCurrencyId);
// on currency ID
if (0 !== $currencyId) {
$response[$key] = $response[$key] ?? [
'id' => (string)$tagId,
'name' => $tag['name'],
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$currencyId,
'currency_code' => $journal['currency_code'],
];
$response[$key]['difference'] = bcadd($response[$key]['difference'], app('steam')->positive($journal['amount']));
$response[$key]['difference_float'] = (float)$response[$key]['difference'];
}
// on foreign ID
if (0 !== $foreignCurrencyId) {
$response[$foreignKey] = $journal[$foreignKey] ?? [
'difference' => '0',
'difference_float' => 0,
'currency_id' => (string)$foreignCurrencyId,
'currency_code' => $journal['foreign_currency_code'],
];
$response[$foreignKey]['difference'] = bcadd(
$response[$foreignKey]['difference'], app('steam')->positive($journal['foreign_amount'])
);
$response[$foreignKey]['difference_float'] = (float)$response[$foreignKey]['difference'];
}
}
}
return response()->json(array_values($response));
}
}

View File

@@ -1,274 +0,0 @@
<?php
/**
* LinkTypeController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\LinkTypeStoreRequest;
use FireflyIII\Api\V1\Requests\LinkTypeUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\LinkType;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\LinkTypeTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class LinkTypeController.
*/
class LinkTypeController extends Controller
{
use TransactionFilter;
/** @var LinkTypeRepositoryInterface The link type repository */
private $repository;
/** @var UserRepositoryInterface The user repository */
private $userRepository;
/**
* LinkTypeController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(LinkTypeRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param LinkType $linkType
*
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*/
public function delete(LinkType $linkType): JsonResponse
{
if (false === $linkType->editable) {
throw new FireflyException('200020: Link type cannot be changed.');
}
$this->repository->destroy($linkType);
return response()->json([], 204);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
// create some objects:
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$collection = $this->repository->get();
$count = $collection->count();
$linkTypes = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($linkTypes, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.link_types.index') . $this->buildParams());
/** @var LinkTypeTransformer $transformer */
$transformer = app(LinkTypeTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($linkTypes, $transformer, 'link_types');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param LinkType $linkType
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(LinkType $linkType): JsonResponse
{
$manager = $this->getManager();
/** @var LinkTypeTransformer $transformer */
$transformer = app(LinkTypeTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store new object.
*
* @param LinkTypeStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(LinkTypeStoreRequest $request): JsonResponse
{
/** @var User $admin */
$admin = auth()->user();
if (!$this->userRepository->hasRole($admin, 'owner')) {
throw new FireflyException('200005: You need the "owner" role to do this.'); // @codeCoverageIgnore
}
$data = $request->getAll();
// if currency ID is 0, find the currency by the code:
$linkType = $this->repository->store($data);
$manager = $this->getManager();
/** @var LinkTypeTransformer $transformer */
$transformer = app(LinkTypeTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Delete the resource.
*
* @param Request $request
* @param LinkType $linkType
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, LinkType $linkType): JsonResponse
{
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager();
// whatever is returned by the query, it must be part of these journals:
$journalIds = $this->repository->getJournalIds($linkType);
/** @var User $admin */
$admin = auth()->user();
// 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'));
}
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update object.
*
* @param LinkTypeUpdateRequest $request
* @param LinkType $linkType
*
* @return JsonResponse
* @throws FireflyException
*/
public function update(LinkTypeUpdateRequest $request, LinkType $linkType): JsonResponse
{
if (false === $linkType->editable) {
throw new FireflyException('200020: Link type cannot be changed.');
}
/** @var User $admin */
$admin = auth()->user();
if (!$this->userRepository->hasRole($admin, 'owner')) {
throw new FireflyException('200005: You need the "owner" role to do this.'); // @codeCoverageIgnore
}
$data = $request->getAll();
$this->repository->update($linkType, $data);
$manager = $this->getManager();
/** @var LinkTypeTransformer $transformer */
$transformer = app(LinkTypeTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* AccountController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Account;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
public const RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param Account $account
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function destroy(Account $account): JsonResponse
{
$this->repository->destroy($account, null);
return response()->json([], 204);
}
}

View File

@@ -21,16 +21,13 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\Account;
use FireflyIII\Api\V1\Requests\AccountStoreRequest;
use FireflyIII\Api\V1\Requests\AccountUpdateRequest;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AccountTransformer;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
@@ -41,20 +38,18 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class AccountController.
* Class ListController
*/
class AccountController extends Controller
class ListController extends Controller
{
use AccountFilter, TransactionFilter;
use TransactionFilter;
public const RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
@@ -65,11 +60,8 @@ class AccountController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
// @var AccountRepositoryInterface repository
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}
@@ -85,7 +77,7 @@ class AccountController extends Controller
public function attachments(Account $account): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->repository->getAttachments($account);
$count = $collection->count();
@@ -105,60 +97,6 @@ class AccountController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Remove the specified resource from storage.
*
* @param Account $account
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function delete(Account $account): JsonResponse
{
$this->repository->destroy($account, null);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
{
$manager = $this->getManager();
$type = $request->get('type') ?? 'all';
$this->parameters->set('type', $type);
// types to get, page size:
$types = $this->mapAccountTypes($this->parameters->get('type'));
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$collection = $this->repository->getAccountsByType($types);
$count = $collection->count();
$accounts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.accounts.index') . $this->buildParams());
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List all piggies.
*
@@ -173,7 +111,7 @@ class AccountController extends Controller
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getPiggyBanks($account);
@@ -195,47 +133,6 @@ class AccountController extends Controller
}
/**
* Show single instance.
*
* @param Account $account
*
* @return JsonResponse
*/
public function show(Account $account): JsonResponse
{
$manager = $this->getManager();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a new instance.
*
* @param AccountStoreRequest $request
*
* @return JsonResponse
*/
public function store(AccountStoreRequest $request): JsonResponse
{
$data = $request->getAllAccountData();
$account = $this->repository->store($data);
$manager = $this->getManager();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show all transaction groups related to the account.
*
@@ -248,7 +145,7 @@ class AccountController extends Controller
*/
public function transactions(Request $request, Account $account): JsonResponse
{
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
@@ -285,27 +182,4 @@ class AccountController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update account.
*
* @param AccountUpdateRequest $request
* @param Account $account
*
* @return JsonResponse
*/
public function update(AccountUpdateRequest $request, Account $account): JsonResponse
{
$data = $request->getUpdateData();
$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);
$this->repository->update($account, $data);
$manager = $this->getManager();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Account;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Transformers\AccountTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
use AccountFilter;
public const RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
{
$manager = $this->getManager();
$type = $request->get('type') ?? 'all';
$this->parameters->set('type', $type);
// types to get, page size:
$types = $this->mapAccountTypes($this->parameters->get('type'));
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$this->repository->resetAccountOrder();
$collection = $this->repository->getAccountsByType($types);
$count = $collection->count();
$accounts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.accounts.index') . $this->buildParams());
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show single instance.
*
* @param Account $account
*
* @return JsonResponse
*/
public function show(Account $account): JsonResponse
{
// get list of accounts. Count it and split it.
$this->repository->resetAccountOrder();
$account->refresh();
$manager = $this->getManager();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* AccountController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Account;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Account\StoreRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
public const RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store a new instance.
*
* @param StoreRequest $request
*
* @return JsonResponse
*/
public function store(StoreRequest $request): JsonResponse
{
$data = $request->getAllAccountData();
$this->repository->resetAccountOrder();
$account = $this->repository->store($data);
$manager = $this->getManager();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* AccountController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Account;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Account\UpdateRequest;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
use Log;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
public const RESOURCE_KEY = 'accounts';
private AccountRepositoryInterface $repository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update account.
*
* @param UpdateRequest $request
* @param Account $account
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Account $account): JsonResponse
{
Log::debug(sprintf('Now in %s', __METHOD__));
$data = $request->getUpdateData();
$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);
$account = $this->repository->update($account, $data);
$manager = $this->getManager();
$account->refresh();
/** @var AccountTransformer $transformer */
$transformer = app(AccountTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Attachment;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Middleware\ApiDemoUser;
use FireflyIII\Models\Attachment;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private AttachmentRepositoryInterface $repository;
/**
* DestroyController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']);
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AttachmentRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @codeCoverageIgnore
*
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function destroy(Attachment $attachment): JsonResponse
{
$this->repository->destroy($attachment);
return response()->json([], 204);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* AttachmentController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -21,38 +21,31 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\Attachment;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Middleware\ApiDemoUser;
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;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response as LaravelResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use Log;
use function strlen;
/**
* Class AttachmentController.
* Class ShowController
*/
class AttachmentController extends Controller
class ShowController extends Controller
{
/** @var AttachmentRepositoryInterface The attachment repository */
private $repository;
private AttachmentRepositoryInterface $repository;
/**
* AccountController constructor.
* ShowController constructor.
*
* @codeCoverageIgnore
*/
@@ -67,28 +60,11 @@ class AttachmentController extends Controller
$this->repository = app(AttachmentRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @codeCoverageIgnore
*
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function delete(Attachment $attachment): JsonResponse
{
$this->repository->destroy($attachment);
return response()->json([], 204);
}
/**
* Download an attachment.
*
@@ -124,7 +100,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', (string)strlen($content));
return $response;
}
@@ -142,9 +118,9 @@ class AttachmentController extends Controller
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
// get list of attachments. Count it and split it.
$collection = $this->repository->get();
$count = $collection->count();
$attachments = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -181,76 +157,4 @@ class AttachmentController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a newly created resource in storage.
*
* @param AttachmentStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(AttachmentStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$attachment = $this->repository->store($data);
$manager = $this->getManager();
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update the specified resource in storage.
*
* @param AttachmentUpdateRequest $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function update(AttachmentUpdateRequest $request, Attachment $attachment): JsonResponse
{
$data = $request->getAll();
$this->repository->update($attachment, $data);
$manager = $this->getManager();
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Upload an attachment.
*
* @codeCoverageIgnore
*
* @param Request $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function upload(Request $request, Attachment $attachment): JsonResponse
{
/** @var AttachmentHelperInterface $helper */
$helper = app(AttachmentHelperInterface::class);
$body = $request->getContent();
if ('' === $body) {
Log::error('Body of attachment is empty.');
return response()->json([], 422);
}
$helper->saveAttachmentFromApi($attachment, $body);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Attachment;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Middleware\ApiDemoUser;
use FireflyIII\Api\V1\Requests\Models\Attachment\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Models\Attachment;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use League\Fractal\Resource\Item;
use Log;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private AttachmentRepositoryInterface $repository;
/**
* StoreController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']);
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AttachmentRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Store a newly created resource in storage.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(StoreRequest $request): JsonResponse
{
Log::debug(sprintf('Now in %s', __METHOD__));
$data = $request->getAll();
$attachment = $this->repository->store($data);
$manager = $this->getManager();
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Upload an attachment.
*
* @codeCoverageIgnore
*
* @param Request $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function upload(Request $request, Attachment $attachment): JsonResponse
{
/** @var AttachmentHelperInterface $helper */
$helper = app(AttachmentHelperInterface::class);
$body = $request->getContent();
if ('' === $body) {
Log::error('Body of attachment is empty.');
return response()->json([], 422);
}
$helper->saveAttachmentFromApi($attachment, $body);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Attachment;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Middleware\ApiDemoUser;
use FireflyIII\Api\V1\Requests\Models\Attachment\UpdateRequest;
use FireflyIII\Models\Attachment;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private AttachmentRepositoryInterface $repository;
/**
* UpdateController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']);
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AttachmentRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Update the specified resource in storage.
*
* @param UpdateRequest $request
* @param Attachment $attachment
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Attachment $attachment): JsonResponse
{
$data = $request->getAll();
$this->repository->update($attachment, $data);
$manager = $this->getManager();
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private AvailableBudgetRepositoryInterface $abRepository;
/**
* AvailableBudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->abRepository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param AvailableBudget $availableBudget
*
* @codeCoverageIgnore
*
* @return JsonResponse
*/
public function destroy(AvailableBudget $availableBudget): JsonResponse
{
$this->abRepository->destroyAvailableBudget($availableBudget);
return response()->json([], 204);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* AvailableBudgetController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -21,12 +21,10 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget;
use FireflyIII\Api\V1\Requests\AvailableBudgetRequest;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Transformers\AvailableBudgetTransformer;
use FireflyIII\User;
@@ -37,9 +35,9 @@ use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class AvailableBudgetController.
* Class ShowController
*/
class AvailableBudgetController extends Controller
class ShowController extends Controller
{
private AvailableBudgetRepositoryInterface $abRepository;
@@ -63,22 +61,6 @@ class AvailableBudgetController extends Controller
);
}
/**
* Remove the specified resource from storage.
*
* @param AvailableBudget $availableBudget
*
* @codeCoverageIgnore
*
* @return JsonResponse
*/
public function delete(AvailableBudget $availableBudget): JsonResponse
{
$this->abRepository->destroyAvailableBudget($availableBudget);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
@@ -90,7 +72,7 @@ class AvailableBudgetController extends Controller
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$start = $this->parameters->get('start');
$end = $this->parameters->get('end');
@@ -135,77 +117,4 @@ class AvailableBudgetController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a newly created resource in storage.
*
* @param AvailableBudgetRequest $request
*
* @return JsonResponse
*/
public function store(AvailableBudgetRequest $request): JsonResponse
{
$data = $request->getAll();
$data['start']->startOfDay();
$data['end']->endOfDay();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'], $data['currency_code']);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrency();
}
$data['currency'] = $currency;
$availableBudget = $this->abRepository->store($data);
$manager = $this->getManager();
/** @var AvailableBudgetTransformer $transformer */
$transformer = app(AvailableBudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update the specified resource in storage.
*
* @param AvailableBudgetRequest $request
* @param AvailableBudget $availableBudget
*
* @return JsonResponse
*/
public function update(AvailableBudgetRequest $request, AvailableBudget $availableBudget): JsonResponse
{
$data = $request->getAll();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
if (null === $currency) {
// use default currency:
$currency = app('amount')->getDefaultCurrency();
}
$currency->enabled = true;
$currency->save();
unset($data['currency_code']);
$data['currency_id'] = $currency->id;
$this->abRepository->updateAvailableBudget($availableBudget, $data);
$manager = $this->getManager();
/** @var AvailableBudgetTransformer $transformer */
$transformer = app(AvailableBudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\AvailableBudget\Request;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Transformers\AvailableBudgetTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private AvailableBudgetRepositoryInterface $abRepository;
/**
* AvailableBudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->abRepository->setUser($user);
return $next($request);
}
);
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return JsonResponse
*/
public function store(Request $request): JsonResponse
{
$data = $request->getAll();
$data['start']->startOfDay();
$data['end']->endOfDay();
// currency is not mandatory:
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
$data['currency_id'] = $currency->id;
unset($data['currency_code']);
}
if (!array_key_exists('currency_id', $data)) {
$currency = app('amount')->getDefaultCurrencyByUser(auth()->user());
$data['currency_id'] = $currency->id;
}
$availableBudget = $this->abRepository->store($data);
$manager = $this->getManager();
/** @var AvailableBudgetTransformer $transformer */
$transformer = app(AvailableBudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\AvailableBudget\Request;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Transformers\AvailableBudgetTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private AvailableBudgetRepositoryInterface $abRepository;
/**
* AvailableBudgetController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->abRepository->setUser($user);
return $next($request);
}
);
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param AvailableBudget $availableBudget
*
* @return JsonResponse
*/
public function update(Request $request, AvailableBudget $availableBudget): JsonResponse
{
$data = $request->getAll();
// find and validate currency ID
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null) ?? app('amount')->getDefaultCurrency();
$currency->enabled = true;
$currency->save();
unset($data['currency_code']);
$data['currency_id'] = $currency->id;
}
$this->abRepository->updateAvailableBudget($availableBudget, $data);
$manager = $this->getManager();
/** @var AvailableBudgetTransformer $transformer */
$transformer = app(AvailableBudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Bill;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Bill $bill): JsonResponse
{
$this->repository->destroy($bill);
return response()->json([], 204);
}
}

View File

@@ -1,8 +1,7 @@
<?php
/**
* BillController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -22,17 +21,14 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\Bill;
use FireflyIII\Api\V1\Requests\BillUpdateRequest;
use FireflyIII\Api\V1\Requests\BillStoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Api\V1\Controllers\Controller;
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\TransactionGroupTransformer;
use FireflyIII\User;
@@ -41,18 +37,16 @@ use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class BillController.
* Class ListController
*/
class BillController extends Controller
class ListController extends Controller
{
use TransactionFilter;
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*
@@ -63,12 +57,8 @@ class BillController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}
@@ -86,7 +76,7 @@ class BillController extends Controller
public function attachments(Bill $bill): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->repository->getAttachments($bill);
$count = $collection->count();
@@ -106,46 +96,6 @@ class BillController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Remove the specified resource from storage.
*
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Bill $bill): JsonResponse
{
$this->repository->destroy($bill);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$bills = $this->repository->getBills();
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$count = $bills->count();
$bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($bills, $transformer, 'bills');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List all of them.
*
@@ -159,7 +109,7 @@ class BillController extends Controller
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getRulesForBill($bill);
@@ -173,8 +123,6 @@ class BillController extends Controller
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@@ -182,48 +130,6 @@ class BillController extends Controller
}
/**
* Show the specified bill.
*
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Bill $bill): JsonResponse
{
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a bill.
*
* @param BillStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(BillStoreRequest $request): JsonResponse
{
$bill = $this->repository->store($request->getAll());
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show all transactions.
*
@@ -236,7 +142,7 @@ class BillController extends Controller
*/
public function transactions(Request $request, Bill $bill): JsonResponse
{
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
@@ -282,27 +188,4 @@ class BillController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update a bill.
*
* @param BillUpdateRequest $request
* @param Bill $bill
*
* @return JsonResponse
*/
public function update(BillUpdateRequest $request, Bill $bill): JsonResponse
{
$data = $request->getAll();
$bill = $this->repository->update($bill, $data);
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,107 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Bill;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Transformers\BillTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$this->repository->correctOrder();
$bills = $this->repository->getBills();
$manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$count = $bills->count();
$bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($bills, $transformer, 'bills');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show the specified bill.
*
* @param Bill $bill
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Bill $bill): JsonResponse
{
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Bill;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Bill\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\BillTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
use TransactionFilter;
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store a bill.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(StoreRequest $request): JsonResponse
{
$data = $request->getAll();
$bill = $this->repository->store($data);
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Bill;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Bill\UpdateRequest;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Transformers\BillTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private BillRepositoryInterface $repository;
/**
* BillController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update a bill.
*
* @param UpdateRequest $request
* @param Bill $bill
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Bill $bill): JsonResponse
{
$data = $request->getAll();
$bill = $this->repository->update($bill, $data);
$manager = $this->getManager();
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Budget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
* DestroyController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BudgetRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Budget $budget): JsonResponse
{
$this->repository->destroy($budget);
return response()->json([], 204);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* BudgetController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -21,11 +21,9 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\Budget;
use FireflyIII\Api\V1\Requests\BudgetStoreRequest;
use FireflyIII\Api\V1\Requests\BudgetUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
@@ -33,7 +31,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\Transformers\BudgetTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
@@ -41,24 +38,19 @@ use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class BudgetController.
/***
* Class ListController
*/
class BudgetController extends Controller
class ListController extends Controller
{
use TransactionFilter;
/** @var BudgetLimitRepositoryInterface */
private $blRepository;
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
private BudgetLimitRepositoryInterface $blRepository;
private BudgetRepositoryInterface $repository;
/**
* BudgetController constructor.
* ListController constructor.
*
* @codeCoverageIgnore
*/
@@ -67,49 +59,16 @@ class BudgetController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->repository->setUser($admin);
$this->blRepository->setUser($admin);
$this->repository->setUser(auth()->user());
$this->blRepository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Display a listing of the resource.
*
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function budgetLimits(Budget $budget): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$this->parameters->set('budget_id', $budget->id);
$collection = $this->blRepository->getBudgetLimits($budget, $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'));
$paginator->setPath(route('api.v1.budgets.budget_limits', [$budget->id]) . $this->buildParams());
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param Budget $budget
*
@@ -119,7 +78,7 @@ class BudgetController extends Controller
public function attachments(Budget $budget): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->repository->getAttachments($budget);
$count = $collection->count();
@@ -139,93 +98,30 @@ class BudgetController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Remove the specified resource from storage.
*
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Budget $budget): JsonResponse
{
$this->repository->destroy($budget);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getBudgets();
$count = $collection->count();
$budgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($budgets, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.budgets.index') . $this->buildParams());
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgets, $transformer, 'budgets');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show a budget.
*
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Budget $budget): JsonResponse
public function budgetLimits(Budget $budget): JsonResponse
{
$manager = $this->getManager();
$manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$this->parameters->set('budget_id', $budget->id);
$collection = $this->blRepository->getBudgetLimits($budget, $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'));
$paginator->setPath(route('api.v1.budgets.budget_limits', [$budget->id]) . $this->buildParams());
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store a budget.
*
* @param BudgetStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(BudgetStoreRequest $request): JsonResponse
{
$budget = $this->repository->store($request->getAll());
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
@@ -242,7 +138,7 @@ class BudgetController extends Controller
*/
public function transactions(Request $request, Budget $budget): JsonResponse
{
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// user can overrule page size with limit parameter.
$limit = $this->parameters->get('limit');
@@ -286,36 +182,10 @@ class BudgetController extends Controller
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update a budget.
*
* @param BudgetUpdateRequest $request
* @param Budget $budget
*
* @return JsonResponse
*/
public function update(BudgetUpdateRequest $request, Budget $budget): JsonResponse
{
$data = $request->getAll();
$budget = $this->repository->update($budget, $data);
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Budget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Transformers\BudgetTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
private BudgetRepositoryInterface $repository;
/**
* ListController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->repository->setUser(auth()->user());
$this->blRepository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getBudgets();
$count = $collection->count();
$budgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($budgets, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.budgets.index') . $this->buildParams());
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgets, $transformer, 'budgets');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show a budget.
*
* @param Budget $budget
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Budget $budget): JsonResponse
{
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Budget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Budget\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Transformers\BudgetTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
* StoreController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BudgetRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store a budget.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(StoreRequest $request): JsonResponse
{
$budget = $this->repository->store($request->getAll());
$budget->refresh();
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Budget;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Budget\UpdateRequest;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Transformers\BudgetTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private BudgetRepositoryInterface $repository;
/**
* UpdateController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(BudgetRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update a budget.
*
* @param UpdateRequest $request
* @param Budget $budget
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Budget $budget): JsonResponse
{
$data = $request->getAll();
$budget = $this->repository->update($budget, $data);
$manager = $this->getManager();
/** @var BudgetTransformer $transformer */
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Budget $budget, BudgetLimit $budgetLimit): JsonResponse
{
if ($budget->id !== $budgetLimit->budget_id) {
throw new FireflyException('20028: The budget limit does not belong to the budget.');
}
$this->blRepository->destroyBudgetLimit($budgetLimit);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
use TransactionFilter;
private BudgetLimitRepositoryInterface $blRepository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Show all transactions.
*
* @param Request $request
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
{
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager();
/** @var User $admin */
$admin = auth()->user();
// 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);
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
$collector->setTypes($types);
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.budgets.limits.transactions', [$budget->id, $budgetLimit->id]) . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,154 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
private BudgetRepositoryInterface $repository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->repository->setUser($user);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Display a listing of the budget limits for this budget..
*
* @param Request $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(Request $request, Budget $budget): JsonResponse
{
$manager = $this->getManager();
$manager->parseIncludes('budget');
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->blRepository->getBudgetLimits($budget, $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'));
$paginator->setPath(route('api.v1.budgets.limits.index', [$budget->id]) . $this->buildParams());
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Display a listing of the budget limits for this budget..
*
* @param DateRequest $request
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function indexAll(DateRequest $request): JsonResponse
{
$manager = $this->getManager();
$manager->parseIncludes('budget');
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->blRepository->getAllBudgetLimits($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'));
$paginator->setPath(route('api.v1.budget-limits.index') . $this->buildParams());
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param Request $request
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
*/
public function show(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
{
if ((int)$budget->id !== (int)$budgetLimit->budget_id) {
throw new FireflyException('20028: The budget limit does not belong to the budget.');
}
// continue!
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\BudgetLimit\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Store a newly created resource in storage.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function store(StoreRequest $request, Budget $budget): JsonResponse
{
$data = $request->getAll();
$data['start_date'] = $data['start'];
$data['end_date'] = $data['end'];
$data['budget_id'] = $budget->id;
$budgetLimit = $this->blRepository->store($data);
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\BudgetLimit\UpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private BudgetLimitRepositoryInterface $blRepository;
/**
* BudgetLimitController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->blRepository->setUser($user);
return $next($request);
}
);
}
/**
* Update the specified resource in storage.
*
* @param UpdateRequest $request
* @param Budget $budget
* @param BudgetLimit $budgetLimit
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
{
if ((int)$budget->id !== (int)$budgetLimit->budget_id) {
throw new FireflyException('20028: The budget limit does not belong to the budget.');
}
$data = $request->getAll();
$data['budget_id'] = $budget->id;
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
$manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Category;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Category $category): JsonResponse
{
$this->repository->destroy($category);
return response()->json([], 204);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* CategoryController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -21,17 +21,14 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\Category;
use FireflyIII\Api\V1\Requests\CategoryStoreRequest;
use FireflyIII\Api\V1\Requests\CategoryUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\CategoryTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
@@ -39,16 +36,15 @@ use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class CategoryController.
* Class ListController
*/
class CategoryController extends Controller
class ListController extends Controller
{
use TransactionFilter;
private CategoryRepositoryInterface $repository;
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
@@ -60,12 +56,8 @@ class CategoryController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}
@@ -81,7 +73,7 @@ class CategoryController extends Controller
public function attachments(Category $category): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->repository->getAttachments($category);
$count = $collection->count();
@@ -101,98 +93,6 @@ class CategoryController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Remove the specified resource from storage.
*
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(Category $category): JsonResponse
{
$this->repository->destroy($category);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getCategories();
$count = $collection->count();
$categories = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($categories, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.categories.index') . $this->buildParams());
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($categories, $transformer, 'categories');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show the category.
*
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Category $category): JsonResponse
{
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store new category.
*
* @param CategoryStoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(CategoryStoreRequest $request): JsonResponse
{
$category = $this->repository->store($request->getAll());
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show all transactions.
*
@@ -205,7 +105,7 @@ class CategoryController extends Controller
*/
public function transactions(Request $request, Category $category): JsonResponse
{
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
@@ -249,28 +149,4 @@ class CategoryController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update the category.
*
* @param CategoryUpdateRequest $request
* @param Category $category
*
* @return JsonResponse
*/
public function update(CategoryUpdateRequest $request, Category $category): JsonResponse
{
$data = $request->getAll();
$category = $this->repository->update($category, $data);
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,113 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Category;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Transformers\CategoryTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Display a listing of the resource.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getCategories();
$count = $collection->count();
$categories = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($categories, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.categories.index') . $this->buildParams());
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($categories, $transformer, 'categories');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show the category.
*
* @param Category $category
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Category $category): JsonResponse
{
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Category;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Category\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Transformers\CategoryTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store new category.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(StoreRequest $request): JsonResponse
{
$category = $this->repository->store($request->getAll());
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Category;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Category\UpdateRequest;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Transformers\CategoryTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update the category.
*
* @param UpdateRequest $request
* @param Category $category
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Category $category): JsonResponse
{
$data = $request->getAll();
$category = $this->repository->update($category, $data);
$manager = $this->getManager();
/** @var CategoryTransformer $transformer */
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\ObjectGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* ObjectGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(ObjectGroupRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* Remove the specified resource from storage.
*
* @param ObjectGroup $objectGroup
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function destroy(ObjectGroup $objectGroup): JsonResponse
{
$this->repository->destroy($objectGroup);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,131 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\ObjectGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\Transformers\BillTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* ObjectGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(ObjectGroupRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* List all bills
*
* @param ObjectGroup $objectGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function bills(ObjectGroup $objectGroup): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of piggy banks. Count it and split it.
$collection = $this->repository->getBills($objectGroup);
$count = $collection->count();
$bills = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.currencies.bills', [$objectGroup->id]) . $this->buildParams());
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($bills, $transformer, 'bills');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List all piggies under the object group.
*
* @param ObjectGroup $objectGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function piggyBanks(ObjectGroup $objectGroup): JsonResponse
{
// create some objects:
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of piggy banks. Count it and split it.
$collection = $this->repository->getPiggyBanks($objectGroup);
$count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.object-groups.piggy_banks', [$objectGroup->id]) . $this->buildParams());
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* GroupController.php
* Copyright (c) 2019 james@firefly-iii.org
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -21,14 +21,12 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\Models\ObjectGroup;
use FireflyIII\Api\V1\Requests\ObjectGroupUpdateRequest;
use FireflyIII\Models\Account;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\Transformers\ObjectGroupTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -38,13 +36,12 @@ use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class GroupController.
* Class ShowController
*/
class ObjectGroupController extends Controller
class ShowController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* ObjectGroupController constructor.
*
@@ -65,21 +62,6 @@ class ObjectGroupController extends Controller
);
}
/**
* Remove the specified resource from storage.
*
* @param ObjectGroup $objectGroup
*
* @codeCoverageIgnore
* @return JsonResponse
*/
public function delete(ObjectGroup $objectGroup): JsonResponse
{
$this->repository->destroy($objectGroup);
return response()->json([], 204);
}
/**
* Display a listing of the resource.
*
@@ -93,9 +75,9 @@ class ObjectGroupController extends Controller
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of accounts. Count it and split it.
$this->repository->resetOrder();
$collection = $this->repository->get();
$count = $collection->count();
$objectGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -114,43 +96,6 @@ class ObjectGroupController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List all piggies under the object group.
*
* @param ObjectGroup $objectGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function piggyBanks(ObjectGroup $objectGroup): JsonResponse
{
// create some objects:
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of piggy banks. Count it and split it.
$collection = $this->repository->getPiggyBanks($objectGroup);
$count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.object-groups.piggy_banks', [$objectGroup->id]) . $this->buildParams());
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show single instance.
*
@@ -161,29 +106,8 @@ class ObjectGroupController extends Controller
public function show(ObjectGroup $objectGroup): JsonResponse
{
$manager = $this->getManager();
/** @var ObjectGroupTransformer $transformer */
$transformer = app(ObjectGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($objectGroup, $transformer, 'object_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update object.
*
* @param ObjectGroupUpdateRequest $request
* @param Account $account
*
* @return JsonResponse
*/
public function update(ObjectGroupUpdateRequest $request, ObjectGroup $objectGroup): JsonResponse
{
$data = $request->getUpdateData();
$this->repository->update($objectGroup, $data);
$this->repository->sort();
$manager = $this->getManager();
$this->repository->resetOrder();
$objectGroup->refresh();
/** @var ObjectGroupTransformer $transformer */
$transformer = app(ObjectGroupTransformer::class);

View File

@@ -0,0 +1,82 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\ObjectGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\ObjectGroup\UpdateRequest;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\Transformers\ObjectGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* ObjectGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(ObjectGroupRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* @param UpdateRequest $request
* @param ObjectGroup $objectGroup
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, ObjectGroup $objectGroup): JsonResponse
{
$data = $request->getUpdateData();
$this->repository->update($objectGroup, $data);
$this->repository->resetOrder();
$manager = $this->getManager();
/** @var ObjectGroupTransformer $transformer */
$transformer = app(ObjectGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($objectGroup, $transformer, 'object_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\PiggyBank;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private PiggyBankRepositoryInterface $repository;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(PiggyBankRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(PiggyBank $piggyBank): JsonResponse
{
$this->repository->destroy($piggyBank);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,122 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\PiggyBank;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\PiggyBankEventTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
private PiggyBankRepositoryInterface $repository;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(PiggyBankRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function attachments(PiggyBank $piggyBank): JsonResponse
{
$manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$collection = $this->repository->getAttachments($piggyBank);
$count = $collection->count();
$attachments = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.piggy_banks.attachments', [$piggyBank->id]) . $this->buildParams());
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function piggyBankEvents(PiggyBank $piggyBank): JsonResponse
{
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$manager = $this->getManager();
$collection = $this->repository->getEvents($piggyBank);
$count = $collection->count();
$events = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.piggy_banks.events', [$piggyBank->id]) . $this->buildParams());
/** @var PiggyBankEventTransformer $transformer */
$transformer = app(PiggyBankEventTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($events, $transformer, 'piggy_bank_events');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,114 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\PiggyBank;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private PiggyBankRepositoryInterface $repository;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(PiggyBankRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getPiggyBanks();
$count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.piggy_banks.index') . $this->buildParams());
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param PiggyBank $piggyBank
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(PiggyBank $piggyBank): JsonResponse
{
$manager = $this->getManager();
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\PiggyBank;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\PiggyBank\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private PiggyBankRepositoryInterface $repository;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(PiggyBankRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store new object.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(StoreRequest $request): JsonResponse
{
$piggyBank = $this->repository->store($request->getAll());
$manager = $this->getManager();
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\PiggyBank;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\PiggyBank\UpdateRequest;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private PiggyBankRepositoryInterface $repository;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(PiggyBankRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update piggy bank.
*
* @param UpdateRequest $request
* @param PiggyBank $piggyBank
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, PiggyBank $piggyBank): JsonResponse
{
$data = $request->getAll();
$piggyBank = $this->repository->update($piggyBank, $data);
if (array_key_exists('current_amount', $data) && '' !== $data['current_amount']) {
$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);
}
$manager = $this->getManager();
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Recurrence $recurrence): JsonResponse
{
$this->repository->destroy($recurrence);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
use TransactionFilter;
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Show transactions for this recurrence.
*
* @param Request $request
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function transactions(Request $request, Recurrence $recurrence): JsonResponse
{
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type);
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager();
// whatever is returned by the query, it must be part of these journals:
$journalIds = $this->repository->getJournalIds($recurrence);
/** @var User $admin */
$admin = auth()->user();
// 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'));
}
$paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,115 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->repository->getAll();
$count = $collection->count();
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.recurrences.index') . $this->buildParams());
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($piggyBanks, $transformer, 'recurrences');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param Recurrence $recurrence
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Recurrence $recurrence): JsonResponse
{
$manager = $this->getManager();
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($recurrence, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Recurrence\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Store new object.
*
* @param StoreRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function store(StoreRequest $request): JsonResponse
{
$data = $request->getAll();
$recurrence = $this->repository->store($data);
$manager = $this->getManager();
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($recurrence, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Recurrence\UpdateRequest;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
return $next($request);
}
);
}
/**
* Update single recurrence.
*
* @param UpdateRequest $request
* @param Recurrence $recurrence
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Recurrence $recurrence): JsonResponse
{
$data = $request->getAll();
$recurrence = $this->repository->update($recurrence, $data);
$manager = $this->getManager();
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($recurrence, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param Rule $rule
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(Rule $rule): JsonResponse
{
$this->ruleRepository->destroy($rule);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\User;
/**
* Class ListController
*/
class ListController extends Controller
{
private AccountRepositoryInterface $accountRepository;
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($user);
return $next($request);
}
);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
return $next($request);
}
);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->ruleRepository->getAll();
$count = $collection->count();
$rules = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rules.index') . $this->buildParams());
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param Rule $rule
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(Rule $rule): JsonResponse
{
$manager = $this->getManager();
/** @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', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Rule\StoreRequest;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
return $next($request);
}
);
}
/**
* Store new object.
*
* @param StoreRequest $request
*
* @return JsonResponse
*/
public function store(StoreRequest $request): JsonResponse
{
$rule = $this->ruleRepository->store($request->getAll());
$manager = $this->getManager();
/** @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', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,151 @@
<?php
/*
* TriggerController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Rule\TestRequest;
use FireflyIII\Api\V1\Requests\Models\Rule\TriggerRequest;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class TriggerController
*/
class TriggerController extends Controller
{
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param TestRequest $request
* @param Rule $rule
*
* @return JsonResponse
*/
public function testRule(TestRequest $request, Rule $rule): JsonResponse
{
$parameters = $request->getTestParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules(new Collection([$rule]));
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => implode(',', $parameters['accounts'])]);
}
// file the rule(s)
$transactions = $ruleEngine->find();
$count = $transactions->count();
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rules.test', [$rule->id]) . $this->buildParams());
// resulting list is presented as JSON thing.
$manager = $this->getManager();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Execute the given rule group on a set of existing transactions.
*
* @param TriggerRequest $request
* @param Rule $rule
*
* @return JsonResponse
*/
public function triggerRule(TriggerRequest $request, Rule $rule): JsonResponse
{
// Get parameters specified by the user
$parameters = $request->getTriggerParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules(new Collection([$rule]));
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => implode(',', $parameters['accounts'])]);
}
// file the rule(s)
$ruleEngine->fire();
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Rule;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Rule\UpdateRequest;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private RuleRepositoryInterface $ruleRepository;
/**
* RuleController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleRepository->setUser($user);
return $next($request);
}
);
}
/**
* Update a rule.
*
* @param UpdateRequest $request
* @param Rule $rule
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, Rule $rule): JsonResponse
{
$data = $request->getAll();
$rule = $this->ruleRepository->update($rule, $data);
$manager = $this->getManager();
/** @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', self::CONTENT_TYPE);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->destroy($ruleGroup, null);
return response()->json([], 204);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param RuleGroup $group
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(RuleGroup $group): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->ruleGroupRepository->getRules($group);
$count = $collection->count();
$rules = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.rules', [$group->id]) . $this->buildParams());
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

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