mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-08-24 14:04:06 +00:00
Compare commits
620 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ad1e9c27e9 | ||
|
ab761696bf | ||
|
0713273a99 | ||
|
5668a3271b | ||
|
1eca105a91 | ||
|
3883b99c24 | ||
|
d6adbc697a | ||
|
a5789b1085 | ||
|
a6ccbcb795 | ||
|
1a6067f7ae | ||
|
cb735b18a9 | ||
|
909bd11147 | ||
|
1a76c606ed | ||
|
8c9b6796a1 | ||
|
844ab608d4 | ||
|
dc39094975 | ||
|
b32184d525 | ||
|
d95ae53ce2 | ||
|
5e3147ddeb | ||
|
9e594c6075 | ||
|
c0058c51ea | ||
|
b0b68d4243 | ||
|
22eb90212d | ||
|
94e264b6ce | ||
|
7ea15761a6 | ||
|
1ced4a089d | ||
|
648e63628c | ||
|
2847e2aff5 | ||
|
9dfaabb5d0 | ||
|
6a21f98ea4 | ||
|
4d5f4cc1c0 | ||
|
970ce6cb0d | ||
|
31cad5de00 | ||
|
e06db9e620 | ||
|
f57ac64dc2 | ||
|
57d7c1623f | ||
|
c86aa9cb3f | ||
|
48209d0d22 | ||
|
8f6a271cc0 | ||
|
a9b610f367 | ||
|
1046930f29 | ||
|
1b16e5e216 | ||
|
e16ba9ac70 | ||
|
71ac676b83 | ||
|
1b6c0d5d86 | ||
|
14db016e98 | ||
|
7e2e1626ac | ||
|
bce4e7e2bf | ||
|
ede327f3d3 | ||
|
82718a74dc | ||
|
eefd6141a1 | ||
|
7894f1871e | ||
|
0ef9b5b462 | ||
|
9ca75d134e | ||
|
b78776e1f7 | ||
|
f2f9f8fbab | ||
|
5b5acba816 | ||
|
9f2729d0ff | ||
|
afe98cda9f | ||
|
9c4d2e8791 | ||
|
cea170359f | ||
|
70bb8fbc89 | ||
|
82cd0adca6 | ||
|
e821f5b2b6 | ||
|
4cade467c6 | ||
|
b6c9639948 | ||
|
ca9319db34 | ||
|
beaec9a4c1 | ||
|
cbc44e8200 | ||
|
017b1a481a | ||
|
e15932fe4a | ||
|
08c044fe52 | ||
|
0e11245cb4 | ||
|
cde494d3ef | ||
|
9a15decdff | ||
|
186b986e02 | ||
|
cdbf5653ac | ||
|
c403dd7490 | ||
|
d15d9fdf2a | ||
|
0b618de44c | ||
|
875f19f728 | ||
|
7bb549732c | ||
|
b9baa93ae4 | ||
|
315479fcd3 | ||
|
1f1334a1fc | ||
|
bf0744e03a | ||
|
8fb9577660 | ||
|
90d58c5c39 | ||
|
b6aa79bb38 | ||
|
14a0de6b6a | ||
|
13e56b7249 | ||
|
3753901e38 | ||
|
e76075e29f | ||
|
284db7f90b | ||
|
cabdf4e380 | ||
|
9859052c4d | ||
|
0feeac9160 | ||
|
54b33a0b69 | ||
|
e08e7b2c9b | ||
|
782e2add88 | ||
|
f18a5a6f1b | ||
|
6fc971c4cb | ||
|
3250c4830d | ||
|
9e1a69217d | ||
|
46c26a64d8 | ||
|
2f12a70647 | ||
|
be190d1fa0 | ||
|
1e4888209b | ||
|
8aa2961c19 | ||
|
304cdabc96 | ||
|
c60e272eb3 | ||
|
c074f55cb2 | ||
|
e6af29646e | ||
|
b4213328fe | ||
|
8a7628c9dc | ||
|
d52c146e12 | ||
|
1910a4bd4b | ||
|
bd0c552f54 | ||
|
b29ea98de4 | ||
|
dd1db87806 | ||
|
6f9e446577 | ||
|
664230dca8 | ||
|
1a24e7e0aa | ||
|
9239815ce6 | ||
|
116e19ec06 | ||
|
fc0ad622eb | ||
|
2c5cdb8780 | ||
|
9a309f32fa | ||
|
e2e54d342a | ||
|
42f7529495 | ||
|
f172151252 | ||
|
e2ad38d3e0 | ||
|
40cc32fc5a | ||
|
436c034fdd | ||
|
286b1848d9 | ||
|
7fffebf6df | ||
|
b1764478ec | ||
|
6b6a799206 | ||
|
0a82ed901e | ||
|
d733c9ed14 | ||
|
a752ea489c | ||
|
876a24586f | ||
|
ea2779cf9a | ||
|
77aa36163d | ||
|
b581d8ecb7 | ||
|
83b404d01e | ||
|
8deb92c3e5 | ||
|
20a6e0170c | ||
|
944a78807c | ||
|
0b02d294f4 | ||
|
a5d86536c3 | ||
|
71c08cfe0c | ||
|
8ab0d5fc48 | ||
|
57f81ee4c8 | ||
|
5c28adf266 | ||
|
5a57398f81 | ||
|
8121a384ef | ||
|
8666197e05 | ||
|
1ea2b8bbcb | ||
|
a71cedd8a9 | ||
|
04c5f583f6 | ||
|
7716ff4e8c | ||
|
6b51a116d1 | ||
|
b2f14dc177 | ||
|
da1d3b82f9 | ||
|
6282d8c828 | ||
|
73129b0ce5 | ||
|
f71e7a2f28 | ||
|
341da327e3 | ||
|
3d8adfa7e4 | ||
|
279d7769f5 | ||
|
b7d3b40353 | ||
|
7ecd691ee2 | ||
|
f3398c7dec | ||
|
90644e662d | ||
|
f5c5cb7fb9 | ||
|
312e79921a | ||
|
b83d346a86 | ||
|
3eed67f108 | ||
|
15f0bc63b2 | ||
|
0a4b0ec929 | ||
|
560f6cbf24 | ||
|
9165e0238f | ||
|
97d6be6809 | ||
|
4de14eba0c | ||
|
6c64023bf7 | ||
|
a923c288e6 | ||
|
4c1d8e8e85 | ||
|
02f2def88b | ||
|
4bcacc5d68 | ||
|
913dbe6b1a | ||
|
ce8164dd87 | ||
|
a5b412f546 | ||
|
82bb352624 | ||
|
ebbf2659b1 | ||
|
d0084becea | ||
|
6af2b37ac2 | ||
|
814fc6eabd | ||
|
50278a679a | ||
|
d42e9c75ef | ||
|
00b3dced2c | ||
|
5c0c00188f | ||
|
2ec56626f3 | ||
|
e87456b2f8 | ||
|
3609b515e5 | ||
|
a1609542c3 | ||
|
4c4625583a | ||
|
7b479316ea | ||
|
b021c7690f | ||
|
2be060796e | ||
|
1b4d55cca4 | ||
|
a8cea4119d | ||
|
e247aace8d | ||
|
41553e9b86 | ||
|
e875587260 | ||
|
5377483345 | ||
|
4112acfb8d | ||
|
f3bc02e11c | ||
|
8e411a898b | ||
|
915edbecc9 | ||
|
975a6c34bf | ||
|
cdd988b4de | ||
|
b58bc97422 | ||
|
482688ac3c | ||
|
aea31b5e28 | ||
|
d7cbc53b4b | ||
|
f74c6c2d19 | ||
|
3080d2ddc4 | ||
|
4ad5881760 | ||
|
7e55d1a4fd | ||
|
7ef5eed6e2 | ||
|
10aa41a7ea | ||
|
1f9b362b6f | ||
|
4bf9bfb521 | ||
|
1d7119114d | ||
|
e1b6df6fb1 | ||
|
7cf38bb01e | ||
|
e34ec22845 | ||
|
46506abeb8 | ||
|
95654cc4d4 | ||
|
47aded820d | ||
|
24444ebf08 | ||
|
bdc0df8350 | ||
|
b2c9a2973c | ||
|
da2a347511 | ||
|
6fbc3ba060 | ||
|
02eff06cd3 | ||
|
7586d4b494 | ||
|
9059f0fee6 | ||
|
c2af9e3d20 | ||
|
0b51366526 | ||
|
e40260bd9c | ||
|
cf2842840d | ||
|
17fa8fcb2c | ||
|
0d2f9864e2 | ||
|
89cbd91204 | ||
|
f4d9b57887 | ||
|
4b2e4afca5 | ||
|
dd1ba30c48 | ||
|
3ba4570691 | ||
|
848cfabcba | ||
|
1bbd10b909 | ||
|
a16a4f813d | ||
|
91cfa963b2 | ||
|
a35557eb62 | ||
|
aad4e47b6a | ||
|
1b177723ae | ||
|
99dba92bd3 | ||
|
e13ccff056 | ||
|
46528dd29d | ||
|
4f611ad810 | ||
|
af41985a64 | ||
|
d0864e06b5 | ||
|
6f0366e146 | ||
|
e0cdbcb28c | ||
|
f19b99194c | ||
|
43a55e2e35 | ||
|
b2743825ca | ||
|
d4f6cce56e | ||
|
6092d206b6 | ||
|
c8ad83cc91 | ||
|
7d31071ff8 | ||
|
c975ef15f1 | ||
|
f855011d34 | ||
|
fbcf0929d8 | ||
|
d89e75cbe8 | ||
|
ccaa42ad74 | ||
|
56d8dce622 | ||
|
c79baf98cf | ||
|
d1cab9f68c | ||
|
69c5c93353 | ||
|
28ebd683e4 | ||
|
d752edd625 | ||
|
1dab45d493 | ||
|
b99982d02b | ||
|
fff17ac6c1 | ||
|
4086257983 | ||
|
bd9e0ac281 | ||
|
b075d6db5e | ||
|
befd79cf14 | ||
|
07f68d2b14 | ||
|
d14889bd27 | ||
|
91e40c14f9 | ||
|
b7b2206262 | ||
|
f344d0319c | ||
|
0c8a1682b6 | ||
|
39866be3f1 | ||
|
947e82fa0f | ||
|
0335a64a21 | ||
|
a9e57e1c34 | ||
|
8a8279f97a | ||
|
b968889552 | ||
|
4068df5e50 | ||
|
dc42370322 | ||
|
8c24f14ee5 | ||
|
494d1743a2 | ||
|
4a30d9f6bb | ||
|
ed6d25067c | ||
|
445ae7e10e | ||
|
6f45609161 | ||
|
f1230e47f7 | ||
|
7e0ef6d43e | ||
|
14f9da544a | ||
|
5a84036e16 | ||
|
4dccf7b7b5 | ||
|
66060dbed4 | ||
|
cfb824588f | ||
|
d2b4316d7a | ||
|
3af69b433d | ||
|
a6733fa255 | ||
|
4277c54009 | ||
|
66baa7554a | ||
|
ffca4b0543 | ||
|
3e3c48314f | ||
|
06ff450d31 | ||
|
07c57cc640 | ||
|
a67f10c99e | ||
|
2882bcbf7b | ||
|
67cc5b0280 | ||
|
b42b178b71 | ||
|
7de05cd173 | ||
|
3db43743d9 | ||
|
14638e4ed8 | ||
|
e756b93810 | ||
|
358d83dcfc | ||
|
331c231a94 | ||
|
4403b65bae | ||
|
a27d80d765 | ||
|
04272fff81 | ||
|
e963708c54 | ||
|
08c4542847 | ||
|
553e9270e5 | ||
|
8a7297e131 | ||
|
0f260da8e6 | ||
|
77560ab3a8 | ||
|
e3b2f2d9a8 | ||
|
74e01a52b9 | ||
|
dc28ba42ef | ||
|
406150620a | ||
|
43f59a1135 | ||
|
5c02eaa66c | ||
|
b4eac84097 | ||
|
ec3b356f86 | ||
|
bf99d5c299 | ||
|
a297131440 | ||
|
bae2161ee3 | ||
|
0fe0de1a7f | ||
|
e7845115f6 | ||
|
bc11c3fab2 | ||
|
1b7546f3f9 | ||
|
663be30117 | ||
|
cf34713518 | ||
|
3f56a8ec53 | ||
|
35d105588b | ||
|
122d988ed2 | ||
|
9fcc5e7a67 | ||
|
9a492c3731 | ||
|
4f752031f3 | ||
|
19be8bb891 | ||
|
693e1b08c7 | ||
|
9aad380518 | ||
|
8c518c8d58 | ||
|
9af89a19db | ||
|
939b18b86c | ||
|
108e775a15 | ||
|
653692ade0 | ||
|
72c6bfee7e | ||
|
ac92939429 | ||
|
052957bbd0 | ||
|
97e6afe3dc | ||
|
1fd028dfb8 | ||
|
c73866f47c | ||
|
b0e120abee | ||
|
b2da38d401 | ||
|
cabe2579fa | ||
|
18a845ac55 | ||
|
a4d14f8259 | ||
|
9d084e62f7 | ||
|
0393fcd704 | ||
|
edb5b2ed5e | ||
|
529bab1112 | ||
|
ab9212a4c9 | ||
|
b2cbba0f3b | ||
|
ca73ef8531 | ||
|
d13490cb6e | ||
|
73566e11c0 | ||
|
36ebd0f0ee | ||
|
efe290d96c | ||
|
da3988cc63 | ||
|
df6f4aecf8 | ||
|
db1a60b6df | ||
|
d79866f115 | ||
|
cdd18b229e | ||
|
cca2de9f1b | ||
|
6a58dbb207 | ||
|
779f461491 | ||
|
085eca6c02 | ||
|
25db11a8c7 | ||
|
76bcc68ab9 | ||
|
9daefaaca4 | ||
|
fbbbcc4e74 | ||
|
2e1f31a7f8 | ||
|
8a0ac81fd0 | ||
|
cdd50dfdd2 | ||
|
a05c8ca351 | ||
|
2ca584f097 | ||
|
687da83feb | ||
|
c799fc655d | ||
|
27848f55ce | ||
|
001a6e310e | ||
|
ad00bc2806 | ||
|
d8e3365345 | ||
|
5849fe2c30 | ||
|
690b498197 | ||
|
d5ddd447bc | ||
|
628c7cd055 | ||
|
f4887bbbf7 | ||
|
d8f291be6e | ||
|
02257e3887 | ||
|
bebfbf0b90 | ||
|
9cb3bfaa57 | ||
|
8e2c035536 | ||
|
6b56c2bf7c | ||
|
d91b9e71d5 | ||
|
344916d57e | ||
|
b1ef225bd0 | ||
|
b713eae009 | ||
|
098cc88d5f | ||
|
2476dd38b3 | ||
|
8fec569dbb | ||
|
ba92aa207c | ||
|
f7abf132e2 | ||
|
38919ae300 | ||
|
bba15cef24 | ||
|
e8792fa218 | ||
|
c5f81d4a94 | ||
|
a7b8c9d94d | ||
|
f4b9b7ae84 | ||
|
905a2432c6 | ||
|
89e4c3de25 | ||
|
86ea9db37e | ||
|
62a9fda1c2 | ||
|
49f7c1bbc1 | ||
|
9dc6f41c18 | ||
|
0a844e4313 | ||
|
53daa89fcb | ||
|
c5d31bccc5 | ||
|
b032825342 | ||
|
8377a2a0de | ||
|
57e49c225b | ||
|
6638f6fb5c | ||
|
71e1b58f1d | ||
|
a87cb0fc0b | ||
|
2e65f63e4a | ||
|
5fb2db4e28 | ||
|
238ae125b5 | ||
|
110d7f691c | ||
|
9fb9c7e3ee | ||
|
a95b1857fe | ||
|
ea97b817fc | ||
|
0eea85a884 | ||
|
eae4e988be | ||
|
bdf752bf7e | ||
|
a19fed5959 | ||
|
7474553832 | ||
|
52567116c2 | ||
|
a70b369aaf | ||
|
33a9e80d9d | ||
|
96ef409f75 | ||
|
8f5152e185 | ||
|
f5f17d1f40 | ||
|
b960f50f38 | ||
|
72e357b673 | ||
|
b33aa733c7 | ||
|
a6a2c0c182 | ||
|
3097ab84fa | ||
|
dd9ce3e06d | ||
|
560fc8b01c | ||
|
f72aba6939 | ||
|
03bc74cae9 | ||
|
7eaf8e3eeb | ||
|
b2b4732657 | ||
|
70473b7635 | ||
|
e4a9e23dfb | ||
|
f0fd5324ea | ||
|
addebad810 | ||
|
253466c533 | ||
|
885d0f1464 | ||
|
4743cc40a2 | ||
|
92bf9c9214 | ||
|
cd80d82ad4 | ||
|
1b7b6a676d | ||
|
1c61afca07 | ||
|
d4d812c195 | ||
|
ab7803f210 | ||
|
11007f0476 | ||
|
6b1884a9e0 | ||
|
1112a0761f | ||
|
807947fcd8 | ||
|
7afd8f99cb | ||
|
b14a15ce49 | ||
|
2e6ad0ce5d | ||
|
8cdbc96aa5 | ||
|
956019ff4a | ||
|
8279cf0e88 | ||
|
43c32abfe8 | ||
|
0e66939408 | ||
|
22d2a523fb | ||
|
bc825a8603 | ||
|
c9cfda34a1 | ||
|
e8dfbff73f | ||
|
62e41f1997 | ||
|
8c9f90f1b4 | ||
|
1453a78e49 | ||
|
7efaf51595 | ||
|
6bc6674ab1 | ||
|
d6c7ff0ccb | ||
|
28f655dba1 | ||
|
6a3de12894 | ||
|
c7940333ec | ||
|
8860378757 | ||
|
728fda0116 | ||
|
0c72e1831f | ||
|
7da21976ec | ||
|
b739859c64 | ||
|
d25665f843 | ||
|
1f41f7bd0f | ||
|
dd8638ca98 | ||
|
4ba9ff05b0 | ||
|
618aad5432 | ||
|
e46fc7501e | ||
|
7b91e98d46 | ||
|
85be218f92 | ||
|
71206e395e | ||
|
9b2d2e16b0 | ||
|
5ae01b382e | ||
|
d92a0753a6 | ||
|
f937a74507 | ||
|
c3584ad20c | ||
|
c049d5cfa6 | ||
|
6c9990e0be | ||
|
b34e4cd31b | ||
|
7852b8a785 | ||
|
6eeb60db5c | ||
|
d076cfc08f | ||
|
68a93ff97c | ||
|
295dcb4f65 | ||
|
d9849f60c0 | ||
|
7ebb68e36c | ||
|
f029f7607b | ||
|
2ba5733ebc | ||
|
3fe1d1d368 | ||
|
438c372583 | ||
|
797aa4858e | ||
|
8c858cd066 | ||
|
85aebd39b9 | ||
|
9a5a037424 | ||
|
7d557cbf91 | ||
|
dbbc85a576 | ||
|
eb78cf20c2 | ||
|
4a99399952 | ||
|
6075d75ee2 | ||
|
f4c56fee66 | ||
|
04c59304da | ||
|
4b3c31a11a | ||
|
14576d2753 | ||
|
72ca1c20c7 | ||
|
93645819b8 | ||
|
39468f871b | ||
|
faa47781d2 | ||
|
2c196bab6d | ||
|
9ae71075ef | ||
|
0013cdfa78 | ||
|
52f3f64f7b | ||
|
670fa77dd7 | ||
|
8baea2feb9 | ||
|
c56f937521 | ||
|
0b613c3b8c | ||
|
78f297e18f | ||
|
bd8a285d6d | ||
|
b44602fd55 | ||
|
41238903e1 | ||
|
a0c88e9b33 | ||
|
5d184aa53e | ||
|
9f9bf86a9f | ||
|
53af9345eb | ||
|
da6bcf04df | ||
|
ec4ec1a147 | ||
|
350e0b08b1 | ||
|
9340ca09e6 | ||
|
a1cef5c339 | ||
|
94875adb6c | ||
|
75a524c656 | ||
|
e1e94a788c | ||
|
8417f45d02 | ||
|
685310a368 | ||
|
45e7a4576a | ||
|
f8c5c15655 | ||
|
26190524f4 | ||
|
5d901a7ecb |
@@ -38,9 +38,14 @@ SEND_REGISTRATION_MAIL=true
|
||||
SEND_ERROR_MESSAGE=true
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
|
||||
CACHE_PREFIX=firefly
|
||||
|
||||
ANALYTICS_ID=
|
||||
SITE_OWNER=mail@example.com
|
||||
|
||||
PUSHER_KEY=
|
||||
PUSHER_SECRET=
|
||||
PUSHER_APP_ID=
|
||||
|
||||
DEMO_USERNAME=
|
||||
DEMO_PASSWORD=
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,5 +11,4 @@ result.html
|
||||
test-import.sh
|
||||
test-import-report.txt
|
||||
public/google*.html
|
||||
_ide_helper_models.php
|
||||
.env.backup
|
||||
|
@@ -5,14 +5,13 @@ php:
|
||||
|
||||
install:
|
||||
- phpenv config-rm xdebug.ini
|
||||
- composer selfupdate
|
||||
- rm composer.lock
|
||||
- composer update --no-scripts
|
||||
- php artisan clear-compiled
|
||||
- php artisan optimize
|
||||
- php artisan env
|
||||
- ./test.sh -r
|
||||
- php artisan env
|
||||
- cp .env.testing .env
|
||||
- mv storage/database/databasecopy.sqlite storage/database/database.sqlite
|
||||
|
||||
script:
|
||||
- phpunit
|
79
CHANGELOG.md
79
CHANGELOG.md
@@ -2,7 +2,84 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [4.1.7] - 2015-05-25
|
||||
|
||||
## [4.3.0] - 2015-12-26
|
||||
### Added
|
||||
- New method of keeping track of available budget, see issue #489
|
||||
- Support for Spanish
|
||||
- Firefly III now has an extended demo mode. Will expand further in the future.
|
||||
|
||||
|
||||
### Changed
|
||||
- New favicon
|
||||
- Import routine no longer gives transactions a description #483
|
||||
|
||||
|
||||
### Removed
|
||||
- All test data generation code.
|
||||
|
||||
### Fixed
|
||||
- Removed import accounts from search results #478
|
||||
- Redirect after delete will no longer go back to deleted item #477
|
||||
- Cannot math #482
|
||||
- Fixed bug in virtual balance field #479
|
||||
|
||||
## [4.2.2] - 2016-12-18
|
||||
### Added
|
||||
- New budget report (still a bit of a beta)
|
||||
- Can now edit user
|
||||
|
||||
### Changed
|
||||
- New config for specific events. Still need to build Notifications.
|
||||
|
||||
### Fixed
|
||||
- Various bugs
|
||||
- Issue #472 thanks to @zjean
|
||||
|
||||
## [4.2.1] - 2016-12-09
|
||||
### Added
|
||||
- BIC support (see #430)
|
||||
- New category report section and chart (see the general financial report)
|
||||
|
||||
|
||||
### Changed
|
||||
- Date range picker now also available on mobile devices (see #435)
|
||||
- Extended range of amounts for issue #439
|
||||
- Rewrote all routes. Old bookmarks may break.
|
||||
|
||||
## [4.2.0] - 2016-11-27
|
||||
### Added
|
||||
- Lots of (empty) tests
|
||||
- Expanded transaction lists (#377)
|
||||
- New charts at account view
|
||||
- First code for #305
|
||||
|
||||
|
||||
### Changed
|
||||
- Updated all email messages.
|
||||
- Made some fonts local
|
||||
|
||||
|
||||
### Deprecated
|
||||
- Initial release.
|
||||
|
||||
### Removed
|
||||
- Initial release.
|
||||
|
||||
### Fixed
|
||||
- Issue #408
|
||||
- Various issues with split journals
|
||||
- Issue #414, thx @zjean
|
||||
- Issue #419, thx @schwalberich
|
||||
- Issue #422, thx @xzaz
|
||||
- Various import bugs, such as #416 (@zjean)
|
||||
|
||||
|
||||
### Security
|
||||
- Initial release.
|
||||
|
||||
|
||||
## [4.1.7] - 2016-11-19
|
||||
### Added
|
||||
- Check for database table presence in console commands.
|
||||
- Category report
|
||||
|
18
README.md
18
README.md
@@ -1,15 +1,21 @@
|
||||
# Firefly III [](https://secure.php.net/downloads.php#v7.0.4) [](https://packagist.org/packages/grumpydictator/firefly-iii) [](https://scrutinizer-ci.com/g/JC5/firefly-iii/?branch=master)
|
||||
# Firefly III: A personal finances manager
|
||||
|
||||
[](https://travis-ci.org/JC5/firefly-iii)
|
||||
[](https://secure.php.net/downloads.php#v7.0.4) [](https://packagist.org/packages/grumpydictator/firefly-iii) [](https://scrutinizer-ci.com/g/JC5/firefly-iii/?branch=master)
|
||||
|
||||
## A personal finances manager
|
||||
[](https://travis-ci.org/JC5/firefly-iii) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UKUT455HUFA)
|
||||
|
||||
[](https://i.nder.be/hhfv03hp) [](https://i.nder.be/hhmwmqw9)
|
||||
[](https://i.nder.be/h2b37243) [](https://i.nder.be/hv70pbwc)
|
||||
|
||||
[](https://i.nder.be/g63q05m0) [](https://i.nder.be/c2g30ngg)
|
||||
[](https://i.nder.be/ccn0u2mp) [](https://i.nder.be/gm8hbh7z)
|
||||
|
||||
_(You can click on the images for a better view)_
|
||||
|
||||
"Firefly III" is a financial manager. It can help you keep track of expenses, income, budgets and everything in between. It even supports credit cards, shared household accounts and savings accounts! It's pretty fancy. You should use it to save and organise money.
|
||||
|
||||
## Try it out!
|
||||
|
||||
Try out Firefly III on the [demo site](https://firefly-iii.nder.be/).
|
||||
|
||||
## Installation
|
||||
|
||||
To install Firefly III, you'll need a web server (preferrably on Linux) and access to the command line. Then, please read the [installation guide](https://firefly-iii.github.io/installation-guide/).
|
||||
@@ -29,4 +35,6 @@ Firefly works on the principle that if you know where you're money is going, you
|
||||
|
||||
Firefly is pretty awesome. [You can read more about Firefly III, and its features, on the Github Pages](https://firefly-iii.github.io/).
|
||||
|
||||
If you like Firefly and if it helps you save lots of money, why not send me [a dime for every dollar saved](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UKUT455HUFA) (this is a joke, although the Paypal form works just fine, try it!)
|
||||
|
||||
If you want to contact me, please open an issue or [email me](mailto:thegrumpydictator@gmail.com).
|
||||
|
@@ -50,13 +50,10 @@ class CreateImport extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// find the file
|
||||
/** @var UserRepositoryInterface $userRepository */
|
||||
$userRepository = app(UserRepositoryInterface::class);
|
||||
$file = $this->argument('file');
|
||||
@@ -69,7 +66,6 @@ class CreateImport extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
// try to parse configuration data:
|
||||
$configurationData = json_decode(file_get_contents($configuration));
|
||||
if (is_null($configurationData)) {
|
||||
$this->error(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
|
||||
@@ -84,21 +80,17 @@ class CreateImport extends Command
|
||||
|
||||
/** @var ImportJobRepositoryInterface $jobRepository */
|
||||
$jobRepository = app(ImportJobRepositoryInterface::class, [$user]);
|
||||
|
||||
$job = $jobRepository->create($type);
|
||||
$job = $jobRepository->create($type);
|
||||
$this->line(sprintf('Created job "%s"...', $job->key));
|
||||
|
||||
// put the file in the proper place:
|
||||
Artisan::call('firefly:encrypt', ['file' => $file, 'key' => $job->key]);
|
||||
$this->line('Stored import data...');
|
||||
|
||||
// store the configuration in the job:
|
||||
$job->configuration = $configurationData;
|
||||
$job->status = 'settings_complete';
|
||||
$job->save();
|
||||
$this->line('Stored configuration...');
|
||||
|
||||
// if user wants to run it, do!
|
||||
if ($this->option('start') === true) {
|
||||
$this->line('The import will start in a moment. This process is not visible...');
|
||||
Log::debug('Go for import!');
|
||||
@@ -111,10 +103,10 @@ class CreateImport extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five exactly.
|
||||
*/
|
||||
private function validArguments(): bool
|
||||
{
|
||||
// find the file
|
||||
/** @var UserRepositoryInterface $userRepository */
|
||||
$userRepository = app(UserRepositoryInterface::class);
|
||||
$file = $this->argument('file');
|
||||
|
@@ -18,6 +18,7 @@ use FireflyIII\Import\Logging\CommandHandler;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -51,9 +52,7 @@ class Import extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
@@ -71,32 +70,15 @@ class Import extends Command
|
||||
$monolog = Log::getMonolog();
|
||||
$handler = new CommandHandler($this);
|
||||
$monolog->pushHandler($handler);
|
||||
$importProcedure = new ImportProcedure;
|
||||
$result = $importProcedure->runImport($job);
|
||||
|
||||
$result = ImportProcedure::runImport($job);
|
||||
|
||||
|
||||
/**
|
||||
* @var int $index
|
||||
* @var TransactionJournal $journal
|
||||
*/
|
||||
foreach ($result as $index => $journal) {
|
||||
if (!is_null($journal->id)) {
|
||||
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
|
||||
continue;
|
||||
}
|
||||
$this->error(sprintf('Could not store line #%d', $index));
|
||||
}
|
||||
|
||||
// display result to user:
|
||||
$this->presentResults($result);
|
||||
$this->line('The import has completed.');
|
||||
|
||||
// get any errors from the importer:
|
||||
$extendedStatus = $job->extended_status;
|
||||
if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
|
||||
$this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
|
||||
foreach ($extendedStatus['errors'] as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
}
|
||||
$this->presentErrors($job);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -122,4 +104,36 @@ class Import extends Command
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*/
|
||||
private function presentErrors(ImportJob $job)
|
||||
{
|
||||
$extendedStatus = $job->extended_status;
|
||||
if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
|
||||
$this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
|
||||
foreach ($extendedStatus['errors'] as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $result
|
||||
*/
|
||||
private function presentResults(Collection $result)
|
||||
{
|
||||
/**
|
||||
* @var int $index
|
||||
* @var TransactionJournal $journal
|
||||
*/
|
||||
foreach ($result as $index => $journal) {
|
||||
if (!is_null($journal->id)) {
|
||||
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
|
||||
continue;
|
||||
}
|
||||
$this->error(sprintf('Could not store line #%d', $index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,42 +60,26 @@ class ScanAttachments extends Command
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($attachments as $attachment) {
|
||||
$fileName = $attachment->fileName();
|
||||
|
||||
// try to grab file content:
|
||||
try {
|
||||
$content = $disk->get($fileName);
|
||||
} catch (FileNotFoundException $e) {
|
||||
$this->error(sprintf('Could not find data for attachment #%d', $attachment->id));
|
||||
continue;
|
||||
}
|
||||
// try to decrypt content.
|
||||
try {
|
||||
$decrypted = Crypt::decrypt($content);
|
||||
} catch (DecryptException $e) {
|
||||
$this->error(sprintf('Could not decrypt data of attachment #%d', $attachment->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
// make temp file:
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||
|
||||
// store content in temp file:
|
||||
file_put_contents($tmpfname, $decrypted);
|
||||
|
||||
// get md5 and mime
|
||||
$md5 = md5_file($tmpfname);
|
||||
$mime = mime_content_type($tmpfname);
|
||||
|
||||
// update attachment:
|
||||
$md5 = md5_file($tmpfname);
|
||||
$mime = mime_content_type($tmpfname);
|
||||
$attachment->md5 = $md5;
|
||||
$attachment->mime = $mime;
|
||||
$attachment->save();
|
||||
|
||||
|
||||
$this->line(sprintf('Fixed attachment #%d', $attachment->id));
|
||||
|
||||
// find file:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -72,12 +72,11 @@ class UpgradeDatabase extends Command
|
||||
}
|
||||
|
||||
|
||||
$subQuery = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->groupBy(['transaction_journals.id'])
|
||||
->select(['transaction_journals.id', DB::raw('COUNT(transactions.id) AS t_count')]);
|
||||
$subQuery = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->groupBy(['transaction_journals.id'])
|
||||
->select(['transaction_journals.id', DB::raw('COUNT(transactions.id) AS t_count')]);
|
||||
|
||||
$result = DB::table(DB::raw('(' . $subQuery->toSql() . ') AS derived'))
|
||||
->mergeBindings($subQuery->getQuery())
|
||||
@@ -98,11 +97,10 @@ class UpgradeDatabase extends Command
|
||||
|
||||
try {
|
||||
/** @var Transaction $opposing */
|
||||
$opposing = Transaction
|
||||
::where('transaction_journal_id', $journalId)
|
||||
->where('amount', $amount)->where('identifier', '=', 0)
|
||||
->whereNotIn('id', $processed)
|
||||
->first();
|
||||
$opposing = Transaction::where('transaction_journal_id', $journalId)
|
||||
->where('amount', $amount)->where('identifier', '=', 0)
|
||||
->whereNotIn('id', $processed)
|
||||
->first();
|
||||
} catch (QueryException $e) {
|
||||
Log::error($e->getMessage());
|
||||
$this->error('Firefly III could not find the "identifier" field in the "transactions" table.');
|
||||
|
@@ -17,14 +17,13 @@ use Crypt;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Schema;
|
||||
use stdClass;
|
||||
@@ -67,16 +66,16 @@ class VerifyDatabase extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reportObject('budget');
|
||||
$this->reportObject('category');
|
||||
$this->reportObject('tag');
|
||||
|
||||
// accounts with no transactions.
|
||||
$this->reportAccounts();
|
||||
// budgets with no limits
|
||||
$this->reportBudgetLimits();
|
||||
// budgets with no transactions
|
||||
$this->reportBudgets();
|
||||
// categories with no transactions
|
||||
$this->reportCategories();
|
||||
// tags with no transactions
|
||||
$this->reportTags();
|
||||
|
||||
// sum of transactions is not zero.
|
||||
$this->reportSum();
|
||||
// any deleted transaction journals that have transactions that are NOT deleted:
|
||||
@@ -101,14 +100,13 @@ class VerifyDatabase extends Command
|
||||
*/
|
||||
private function reportAccounts()
|
||||
{
|
||||
$set = Account
|
||||
::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
||||
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
|
||||
->whereNull('transactions.account_id')
|
||||
->get(
|
||||
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
|
||||
);
|
||||
$set = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
||||
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
|
||||
->whereNull('transactions.account_id')
|
||||
->get(
|
||||
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
|
||||
);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
@@ -124,87 +122,43 @@ class VerifyDatabase extends Command
|
||||
*/
|
||||
private function reportBudgetLimits()
|
||||
{
|
||||
$set = Budget
|
||||
::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
||||
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||
->groupBy(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email'])
|
||||
->whereNull('budget_limits.id')
|
||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']);
|
||||
$set = Budget::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
||||
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||
->groupBy(['budgets.id', 'budgets.name', 'budgets.encrypted', 'budgets.user_id', 'users.email'])
|
||||
->whereNull('budget_limits.id')
|
||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'budgets.encrypted', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
/** @var Budget $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
||||
$name = $entry->encrypted ? Crypt::decrypt($entry->name) : $entry->name;
|
||||
$line = sprintf(
|
||||
'Notice: User #%d (%s) has budget #%d ("%s") which has no budget limits.',
|
||||
$entry->user_id, $entry->email, $entry->id, Crypt::decrypt($entry->name)
|
||||
$entry->user_id, $entry->email, $entry->id, $name
|
||||
);
|
||||
$this->line($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on budgets without any transactions.
|
||||
*/
|
||||
private function reportBudgets()
|
||||
{
|
||||
$set = Budget
|
||||
::leftJoin('budget_transaction_journal', 'budgets.id', '=', 'budget_transaction_journal.budget_id')
|
||||
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||
->distinct()
|
||||
->whereNull('budget_transaction_journal.budget_id')
|
||||
->whereNull('budgets.deleted_at')
|
||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$line = 'Notice: User #' . $entry->user_id . ' (' . $entry->email . ') has budget #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||
. '") which has no transactions.';
|
||||
$this->line($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on categories without any transactions.
|
||||
*/
|
||||
private function reportCategories()
|
||||
{
|
||||
$set = Category
|
||||
::leftJoin('category_transaction_journal', 'categories.id', '=', 'category_transaction_journal.category_id')
|
||||
->leftJoin('users', 'categories.user_id', '=', 'users.id')
|
||||
->distinct()
|
||||
->whereNull('category_transaction_journal.category_id')
|
||||
->whereNull('categories.deleted_at')
|
||||
->get(['categories.id', 'categories.name', 'categories.user_id', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$line = 'Notice: User #' . $entry->user_id . ' (' . $entry->email . ') has category #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||
. '") which has no transactions.';
|
||||
$this->line($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on deleted accounts that still have not deleted transactions or journals attached to them.
|
||||
*/
|
||||
private function reportDeletedAccounts()
|
||||
{
|
||||
$set = Account
|
||||
::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->whereNotNull('accounts.deleted_at')
|
||||
->whereNotNull('transactions.id')
|
||||
->where(
|
||||
function (Builder $q) {
|
||||
$q->whereNull('transactions.deleted_at');
|
||||
$q->orWhereNull('transaction_journals.deleted_at');
|
||||
}
|
||||
)
|
||||
->get(
|
||||
['accounts.id as account_id', 'accounts.deleted_at as account_deleted_at', 'transactions.id as transaction_id',
|
||||
'transactions.deleted_at as transaction_deleted_at', 'transaction_journals.id as journal_id',
|
||||
'transaction_journals.deleted_at as journal_deleted_at']
|
||||
);
|
||||
$set = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->whereNotNull('accounts.deleted_at')
|
||||
->whereNotNull('transactions.id')
|
||||
->where(
|
||||
function (Builder $q) {
|
||||
$q->whereNull('transactions.deleted_at');
|
||||
$q->orWhereNull('transaction_journals.deleted_at');
|
||||
}
|
||||
)
|
||||
->get(
|
||||
['accounts.id as account_id', 'accounts.deleted_at as account_deleted_at', 'transactions.id as transaction_id',
|
||||
'transactions.deleted_at as transaction_deleted_at', 'transaction_journals.id as journal_id',
|
||||
'transaction_journals.deleted_at as journal_deleted_at']
|
||||
);
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$date = is_null($entry->transaction_deleted_at) ? $entry->journal_deleted_at : $entry->transaction_deleted_at;
|
||||
@@ -228,16 +182,18 @@ class VerifyDatabase extends Command
|
||||
TransactionType::TRANSFER => [AccountType::EXPENSE, AccountType::REVENUE],
|
||||
];
|
||||
foreach ($configuration as $transactionType => $accountTypes) {
|
||||
$set = TransactionJournal
|
||||
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', 'accounts.account_type_id')
|
||||
->leftJoin('users', 'users.id', '=', 'transaction_journals.user_id')
|
||||
->where('transaction_types.type', $transactionType)
|
||||
->whereIn('account_types.type', $accountTypes)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->get(['transaction_journals.id', 'transaction_journals.user_id', 'users.email', 'account_types.type as a_type', 'transaction_types.type']);
|
||||
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', 'accounts.account_type_id')
|
||||
->leftJoin('users', 'users.id', '=', 'transaction_journals.user_id')
|
||||
->where('transaction_types.type', $transactionType)
|
||||
->whereIn('account_types.type', $accountTypes)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.user_id', 'users.email', 'account_types.type as a_type',
|
||||
'transaction_types.type']
|
||||
);
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
sprintf(
|
||||
@@ -259,19 +215,18 @@ class VerifyDatabase extends Command
|
||||
*/
|
||||
private function reportJournals()
|
||||
{
|
||||
$set = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNotNull('transaction_journals.deleted_at')// USE THIS
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNotNull('transactions.id')
|
||||
->get(
|
||||
[
|
||||
'transaction_journals.id as journal_id',
|
||||
'transaction_journals.description',
|
||||
'transaction_journals.deleted_at as journal_deleted',
|
||||
'transactions.id as transaction_id',
|
||||
'transactions.deleted_at as transaction_deleted_at']
|
||||
);
|
||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNotNull('transaction_journals.deleted_at')// USE THIS
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNotNull('transactions.id')
|
||||
->get(
|
||||
[
|
||||
'transaction_journals.id as journal_id',
|
||||
'transaction_journals.description',
|
||||
'transaction_journals.deleted_at as journal_deleted',
|
||||
'transactions.id as transaction_id',
|
||||
'transactions.deleted_at as transaction_deleted_at']
|
||||
);
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
@@ -286,11 +241,10 @@ class VerifyDatabase extends Command
|
||||
*/
|
||||
private function reportNoTransactions()
|
||||
{
|
||||
$set = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->whereNull('transactions.transaction_journal_id')
|
||||
->get(['transaction_journals.id']);
|
||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->whereNull('transactions.transaction_journal_id')
|
||||
->get(['transaction_journals.id']);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
@@ -300,6 +254,39 @@ class VerifyDatabase extends Command
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
private function reportObject(string $name)
|
||||
{
|
||||
$plural = str_plural($name);
|
||||
$class = sprintf('FireflyIII\Models\%s', ucfirst($name));
|
||||
$field = $name == 'tag' ? 'tag' : 'name';
|
||||
$set = $class::leftJoin($name . '_transaction_journal', $plural . '.id', '=', $name . '_transaction_journal.' . $name . '_id')
|
||||
->leftJoin('users', $plural . '.user_id', '=', 'users.id')
|
||||
->distinct()
|
||||
->whereNull($name . '_transaction_journal.' . $name . '_id')
|
||||
->whereNull($plural . '.deleted_at')
|
||||
->get([$plural . '.id', $plural . '.' . $field . ' as name', $plural . '.user_id', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
||||
$objName = $entry->name;
|
||||
try {
|
||||
$objName = Crypt::decrypt($objName);
|
||||
} catch (DecryptException $e) {
|
||||
// it probably was not encrypted.
|
||||
}
|
||||
|
||||
$line = sprintf(
|
||||
'Notice: User #%d (%s) has %s #%d ("%s") which has no transactions.',
|
||||
$entry->user_id, $entry->email, $name, $entry->id, $objName
|
||||
);
|
||||
$this->line($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports for each user when the sum of their transactions is not zero.
|
||||
*/
|
||||
@@ -317,40 +304,18 @@ class VerifyDatabase extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on tags without any transactions.
|
||||
*/
|
||||
private function reportTags()
|
||||
{
|
||||
$set = Tag
|
||||
::leftJoin('tag_transaction_journal', 'tags.id', '=', 'tag_transaction_journal.tag_id')
|
||||
->leftJoin('users', 'tags.user_id', '=', 'users.id')
|
||||
->distinct()
|
||||
->whereNull('tag_transaction_journal.tag_id')
|
||||
->whereNull('tags.deleted_at')
|
||||
->get(['tags.id', 'tags.tag', 'tags.user_id', 'users.email']);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$line = 'Notice: User #' . $entry->user_id . ' (' . $entry->email . ') has tag #' . $entry->id . ' ("' . $entry->tag
|
||||
. '") which has no transactions.';
|
||||
$this->line($line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports on deleted transactions that are connected to a not deleted journal.
|
||||
*/
|
||||
private function reportTransactions()
|
||||
{
|
||||
$set = Transaction
|
||||
::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNotNull('transactions.deleted_at')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->get(
|
||||
['transactions.id as transaction_id', 'transactions.deleted_at as transaction_deleted', 'transaction_journals.id as journal_id',
|
||||
'transaction_journals.deleted_at']
|
||||
);
|
||||
$set = Transaction::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereNotNull('transactions.deleted_at')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->get(
|
||||
['transactions.id as transaction_id', 'transactions.deleted_at as transaction_deleted', 'transaction_journals.id as journal_id',
|
||||
'transaction_journals.deleted_at']
|
||||
);
|
||||
/** @var stdClass $entry */
|
||||
foreach ($set as $entry) {
|
||||
$this->error(
|
||||
@@ -365,12 +330,11 @@ class VerifyDatabase extends Command
|
||||
*/
|
||||
private function reportTransfersBudgets()
|
||||
{
|
||||
$set = TransactionJournal
|
||||
::distinct()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.id']);
|
||||
$set = TransactionJournal::distinct()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.id']);
|
||||
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
0
app/Console/Kernel.php
Executable file → Normal file
0
app/Console/Kernel.php
Executable file → Normal file
41
app/Events/BlockedBadLogin.php
Normal file
41
app/Events/BlockedBadLogin.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* BlockedBadLogin.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class LockedOutUser
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class BlockedBadLogin extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $email;
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a user gets themselves locked out.
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(string $email, string $ipAddress)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
42
app/Events/BlockedUseOfDomain.php
Normal file
42
app/Events/BlockedUseOfDomain.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* BlockedUseOfDomain.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class BlockedUseOfDomain
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class BlockedUseOfDomain extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $email;
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a user tries to register with a banned domain (on blocked domain list).
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(string $email, string $ipAddress)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
42
app/Events/BlockedUseOfEmail.php
Normal file
42
app/Events/BlockedUseOfEmail.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* BlockedUseOfEmail.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class BlockedUseOfEmail
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class BlockedUseOfEmail extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $email;
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a user tries to register with a banned email address (already used before).
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(string $email, string $ipAddress)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
42
app/Events/BlockedUserLogin.php
Normal file
42
app/Events/BlockedUserLogin.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* BlockedUserLogin.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class BlockedUserLogin
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class BlockedUserLogin extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $ipAddress;
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a blocked user logs in.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(User $user, string $ipAddress)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
38
app/Events/DeletedUser.php
Normal file
38
app/Events/DeletedUser.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* DeletedUser.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class DeletedUser
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class DeletedUser extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a user deletes themselves.
|
||||
*
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct(string $email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
}
|
41
app/Events/LockedOutUser.php
Normal file
41
app/Events/LockedOutUser.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* LockedOutUser.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class LockedOutUser
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class LockedOutUser extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $email;
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a user gets themselves locked out.
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(string $email, string $ipAddress)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
46
app/Events/RequestedNewPassword.php
Normal file
46
app/Events/RequestedNewPassword.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* RequestedNewPassword.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class RequestedNewPassword
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class RequestedNewPassword extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $ipAddress;
|
||||
public $token;
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a users tries to reset his or her password.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $token
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(User $user, string $token, string $ipAddress)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->token = $token;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
|
||||
}
|
0
app/Exceptions/Handler.php
Executable file → Normal file
0
app/Exceptions/Handler.php
Executable file → Normal file
@@ -292,57 +292,56 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
||||
private function getWorkSet()
|
||||
{
|
||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
||||
$this->workSet = Transaction
|
||||
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'transactions AS opposing', function (JoinClause $join) {
|
||||
$join->on('opposing.transaction_journal_id', '=', 'transactions.transaction_journal_id')
|
||||
->where('opposing.amount', '=', DB::raw('transactions.amount * -1'))
|
||||
->where('transactions.identifier', '=', 'opposing.identifier');
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('accounts AS opposing_accounts', 'opposing.account_id', '=', 'opposing_accounts.id')
|
||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', 'transaction_types.id')
|
||||
->leftJoin('transaction_currencies', 'transaction_journals.transaction_currency_id', '=', 'transaction_currencies.id')
|
||||
->whereIn('transactions.account_id', $accountIds)
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_journals.date', '>=', $this->start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $this->end->format('Y-m-d'))
|
||||
->where('transaction_journals.completed', 1)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNull('opposing.deleted_at')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transactions.identifier', 'ASC')
|
||||
->get(
|
||||
[
|
||||
'transactions.id',
|
||||
'transactions.amount',
|
||||
'transactions.description',
|
||||
'transactions.account_id',
|
||||
'accounts.name as account_name',
|
||||
'accounts.encrypted as account_name_encrypted',
|
||||
'transactions.identifier',
|
||||
$this->workSet = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'transactions AS opposing', function (JoinClause $join) {
|
||||
$join->on('opposing.transaction_journal_id', '=', 'transactions.transaction_journal_id')
|
||||
->where('opposing.amount', '=', DB::raw('transactions.amount * -1'))
|
||||
->where('transactions.identifier', '=', DB::raw('opposing.identifier'));
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('accounts AS opposing_accounts', 'opposing.account_id', '=', 'opposing_accounts.id')
|
||||
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', 'transaction_types.id')
|
||||
->leftJoin('transaction_currencies', 'transaction_journals.transaction_currency_id', '=', 'transaction_currencies.id')
|
||||
->whereIn('transactions.account_id', $accountIds)
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_journals.date', '>=', $this->start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $this->end->format('Y-m-d'))
|
||||
->where('transaction_journals.completed', 1)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNull('opposing.deleted_at')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transactions.identifier', 'ASC')
|
||||
->get(
|
||||
[
|
||||
'transactions.id',
|
||||
'transactions.amount',
|
||||
'transactions.description',
|
||||
'transactions.account_id',
|
||||
'accounts.name as account_name',
|
||||
'accounts.encrypted as account_name_encrypted',
|
||||
'transactions.identifier',
|
||||
|
||||
'opposing.id as opposing_id',
|
||||
'opposing.amount AS opposing_amount',
|
||||
'opposing.description as opposing_description',
|
||||
'opposing.account_id as opposing_account_id',
|
||||
'opposing_accounts.name as opposing_account_name',
|
||||
'opposing_accounts.encrypted as opposing_account_encrypted',
|
||||
'opposing.identifier as opposing_identifier',
|
||||
'opposing.id as opposing_id',
|
||||
'opposing.amount AS opposing_amount',
|
||||
'opposing.description as opposing_description',
|
||||
'opposing.account_id as opposing_account_id',
|
||||
'opposing_accounts.name as opposing_account_name',
|
||||
'opposing_accounts.encrypted as opposing_account_encrypted',
|
||||
'opposing.identifier as opposing_identifier',
|
||||
|
||||
'transaction_journals.id as transaction_journal_id',
|
||||
'transaction_journals.date',
|
||||
'transaction_journals.description as journal_description',
|
||||
'transaction_journals.encrypted as journal_encrypted',
|
||||
'transaction_journals.transaction_type_id',
|
||||
'transaction_types.type as transaction_type',
|
||||
'transaction_journals.transaction_currency_id',
|
||||
'transaction_currencies.code AS transaction_currency_code',
|
||||
'transaction_journals.id as transaction_journal_id',
|
||||
'transaction_journals.date',
|
||||
'transaction_journals.description as journal_description',
|
||||
'transaction_journals.encrypted as journal_encrypted',
|
||||
'transaction_journals.transaction_type_id',
|
||||
'transaction_types.type as transaction_type',
|
||||
'transaction_journals.transaction_currency_id',
|
||||
'transaction_currencies.code AS transaction_currency_code',
|
||||
|
||||
]
|
||||
);
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function collectVintageUploads():bool
|
||||
private function collectVintageUploads(): bool
|
||||
{
|
||||
// grab upload directory.
|
||||
$files = $this->uploadDisk->files();
|
||||
|
@@ -30,7 +30,7 @@ use ZipArchive;
|
||||
*
|
||||
* @package FireflyIII\Export
|
||||
*/
|
||||
class Processor
|
||||
class Processor implements ProcessorInterface
|
||||
{
|
||||
|
||||
/** @var Collection */
|
||||
|
67
app/Export/ProcessorInterface.php
Normal file
67
app/Export/ProcessorInterface.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* ProcessorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Export;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ProcessorInterface
|
||||
*
|
||||
* @package FireflyIII\Export
|
||||
*/
|
||||
interface ProcessorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Processor constructor.
|
||||
*
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct(array $settings);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function collectAttachments(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function collectJournals(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function collectOldUploads(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function convertJournals(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function createZipFile(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function exportJournals(): bool;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getFiles(): Collection;
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface AccountChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Account
|
||||
*/
|
||||
interface AccountChartGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function revenueAccounts(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $labels
|
||||
* @param array $dataSet
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function single(Account $account, array $labels, array $dataSet): array;
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsAccountChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Generator\Chart\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ChartJsAccountChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Account
|
||||
*/
|
||||
class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [], 'datasets' => [[
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => []]]];
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->difference > 0) {
|
||||
$data['labels'][] = $account->name;
|
||||
$data['datasets'][0]['data'][] = $account->difference;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
// language:
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
|
||||
$current = clone $start;
|
||||
while ($current <= $end) {
|
||||
$data['labels'][] = $current->formatLocalized($format);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$data['datasets'][] = [
|
||||
'label' => $account->name,
|
||||
'fillColor' => 'rgba(220,220,220,0.2)',
|
||||
'strokeColor' => 'rgba(220,220,220,1)',
|
||||
'pointColor' => 'rgba(220,220,220,1)',
|
||||
'pointStrokeColor' => '#fff',
|
||||
'pointHighlightFill' => '#fff',
|
||||
'pointHighlightStroke' => 'rgba(220,220,220,1)',
|
||||
'data' => $account->balances,
|
||||
];
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function revenueAccounts(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [], 'datasets' => [[
|
||||
'label' => trans('firefly.earned'),
|
||||
'data' => []]]];
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->difference > 0) {
|
||||
$data['labels'][] = $account->name;
|
||||
$data['datasets'][0]['data'][] = $account->difference;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $labels
|
||||
* @param array $dataSet
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function single(Account $account, array $labels, array $dataSet): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => $labels,
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $account->name,
|
||||
'data' => $dataSet,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
149
app/Generator/Chart/Basic/ChartJsGenerator.php
Normal file
149
app/Generator/Chart/Basic/ChartJsGenerator.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Basic;
|
||||
|
||||
use FireflyIII\Support\ChartColour;
|
||||
|
||||
/**
|
||||
* Class ChartJsGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Basic
|
||||
*/
|
||||
class ChartJsGenerator implements GeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Will generate a Chart JS compatible array from the given input. Expects this format
|
||||
*
|
||||
* Will take labels for all from first set.
|
||||
*
|
||||
* 0: [
|
||||
* 'label' => 'label of set',
|
||||
* 'type' => bar or line, optional
|
||||
* 'yAxisID' => ID of yAxis, optional, will not be included when unused.
|
||||
* 'fill' => if to fill a line? optional, will not be included when unused.
|
||||
* 'entries' =>
|
||||
* [
|
||||
* 'label-of-entry' => 'value'
|
||||
* ]
|
||||
* ]
|
||||
* 1: [
|
||||
* 'label' => 'label of another set',
|
||||
* 'type' => bar or line, optional
|
||||
* 'yAxisID' => ID of yAxis, optional, will not be included when unused.
|
||||
* 'fill' => if to fill a line? optional, will not be included when unused.
|
||||
* 'entries' =>
|
||||
* [
|
||||
* 'label-of-entry' => 'value'
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiSet(array $data): array
|
||||
{
|
||||
reset($data);
|
||||
$first = current($data);
|
||||
$labels = array_keys($first['entries']);
|
||||
|
||||
$chartData = [
|
||||
'count' => count($data),
|
||||
'labels' => $labels, // take ALL labels from the first set.
|
||||
'datasets' => [],
|
||||
];
|
||||
unset($first, $labels);
|
||||
|
||||
foreach ($data as $set) {
|
||||
$currentSet = [
|
||||
'label' => $set['label'],
|
||||
'type' => $set['type'] ?? 'line',
|
||||
'data' => array_values($set['entries']),
|
||||
];
|
||||
if (isset($set['yAxisID'])) {
|
||||
$currentSet['yAxisID'] = $set['yAxisID'];
|
||||
}
|
||||
if (isset($set['fill'])) {
|
||||
$currentSet['fill'] = $set['fill'];
|
||||
}
|
||||
|
||||
$chartData['datasets'][] = $currentSet;
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects data as:
|
||||
*
|
||||
* key => value
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $data): array
|
||||
{
|
||||
$chartData = [
|
||||
'datasets' => [
|
||||
0 => [],
|
||||
],
|
||||
'labels' => [],
|
||||
];
|
||||
$index = 0;
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
// make larger than 0
|
||||
if (bccomp($value, '0') === -1) {
|
||||
$value = bcmul($value, '-1');
|
||||
}
|
||||
|
||||
$chartData['datasets'][0]['data'][] = round($value, 2);
|
||||
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
||||
$chartData['labels'][] = $key;
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
|
||||
*
|
||||
* 'label-of-entry' => value
|
||||
* 'label-of-entry' => value
|
||||
*
|
||||
* @param string $setLabel
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function singleSet(string $setLabel, array $data): array
|
||||
{
|
||||
$chartData = [
|
||||
'count' => 1,
|
||||
'labels' => array_keys($data), // take ALL labels from the first set.
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $setLabel,
|
||||
'data' => array_values($data),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $chartData;
|
||||
}
|
||||
}
|
73
app/Generator/Chart/Basic/GeneratorInterface.php
Normal file
73
app/Generator/Chart/Basic/GeneratorInterface.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* GeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Basic;
|
||||
|
||||
/**
|
||||
* Interface GeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Basic
|
||||
*/
|
||||
interface GeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
|
||||
*
|
||||
* 0: [
|
||||
* 'label' => 'label of set',
|
||||
* 'entries' =>
|
||||
* [
|
||||
* 'label-of-entry' => 'value'
|
||||
* ]
|
||||
* ]
|
||||
* 1: [
|
||||
* 'label' => 'label of another set',
|
||||
* 'entries' =>
|
||||
* [
|
||||
* 'label-of-entry' => 'value'
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiSet(array $data): array;
|
||||
|
||||
/**
|
||||
* Expects data as:
|
||||
*
|
||||
* key => value
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $data): array;
|
||||
|
||||
/**
|
||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
|
||||
*
|
||||
* 'label-of-entry' => value
|
||||
* 'label-of-entry' => value
|
||||
*
|
||||
* @param string $setLabel
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function singleSet(string $setLabel, array $data): array;
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BillChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Bill;
|
||||
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface BillChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Bill
|
||||
*/
|
||||
interface BillChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $paid
|
||||
* @param string $unpaid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(string $paid, string $unpaid): array;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function single(Bill $bill, Collection $entries): array;
|
||||
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsBillChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Bill;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Support\ChartColour;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ChartJsBillChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Bill
|
||||
*/
|
||||
class ChartJsBillChartGenerator implements BillChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $paid
|
||||
* @param string $unpaid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(string $paid, string $unpaid): array
|
||||
{
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'data' => [round($unpaid, 2), round(bcmul($paid, '-1'), 2)],
|
||||
'backgroundColor' => [ChartColour::getColour(0), ChartColour::getColour(1)],
|
||||
],
|
||||
|
||||
],
|
||||
'labels' => [strval(trans('firefly.unpaid')), strval(trans('firefly.paid'))],
|
||||
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function single(Bill $bill, Collection $entries): array
|
||||
{
|
||||
$format = (string)trans('config.month');
|
||||
$data = ['count' => 3, 'labels' => [], 'datasets' => [],];
|
||||
$minAmount = [];
|
||||
$maxAmount = [];
|
||||
$actualAmount = [];
|
||||
/** @var Transaction $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry->date->formatLocalized($format);
|
||||
$minAmount[] = round($bill->amount_min, 2);
|
||||
$maxAmount[] = round($bill->amount_max, 2);
|
||||
// journalAmount has been collected in BillRepository::getJournals
|
||||
$actualAmount[] = bcmul($entry->transaction_amount, '-1');
|
||||
}
|
||||
|
||||
$data['datasets'][] = [
|
||||
'type' => 'bar',
|
||||
'label' => trans('firefly.minAmount'),
|
||||
'data' => $minAmount,
|
||||
];
|
||||
$data['datasets'][] = [
|
||||
'type' => 'line',
|
||||
'label' => trans('firefly.billEntry'),
|
||||
'data' => $actualAmount,
|
||||
];
|
||||
$data['datasets'][] = [
|
||||
'type' => 'bar',
|
||||
'label' => trans('firefly.maxAmount'),
|
||||
'data' => $maxAmount,
|
||||
];
|
||||
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Budget;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface BudgetChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Budget
|
||||
*/
|
||||
interface BudgetChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
* @param string $dateFormat
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function budgetLimit(Collection $entries, string $dateFormat): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function period(array $entries) : array;
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function year(Collection $budgets, Collection $entries): array;
|
||||
|
||||
}
|
@@ -1,175 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsBudgetChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Generator\Chart\Budget;
|
||||
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
|
||||
/**
|
||||
* Class ChartJsBudgetChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Budget
|
||||
*/
|
||||
class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param Collection $entries
|
||||
* @param string $dateFormat
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function budgetLimit(Collection $entries, string $dateFormat = 'month_and_day'): array
|
||||
{
|
||||
$format = strval(trans('config.' . $dateFormat));
|
||||
$data = [
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Amount',
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[0]->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = $entry[1];
|
||||
|
||||
}
|
||||
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $entries): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
$left = [];
|
||||
$spent = [];
|
||||
$overspent = [];
|
||||
$filtered = $entries->filter(
|
||||
function ($entry) {
|
||||
return ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0);
|
||||
}
|
||||
);
|
||||
foreach ($filtered as $entry) {
|
||||
$data['labels'][] = $entry[0];
|
||||
$left[] = round($entry[1], 2);
|
||||
$spent[] = round(bcmul($entry[2], '-1'), 2); // spent is coming in negative, must be positive
|
||||
$overspent[] = round(bcmul($entry[3], '-1'), 2); // same
|
||||
}
|
||||
|
||||
$data['datasets'][] = [
|
||||
'label' => trans('firefly.overspent'),
|
||||
'data' => $overspent,
|
||||
];
|
||||
$data['datasets'][] = [
|
||||
'label' => trans('firefly.left'),
|
||||
'data' => $left,
|
||||
];
|
||||
$data['datasets'][] = [
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => $spent,
|
||||
];
|
||||
|
||||
$data['count'] = 3;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function period(array $entries) : array
|
||||
{
|
||||
|
||||
$data = [
|
||||
'labels' => array_keys($entries),
|
||||
'datasets' => [
|
||||
0 => [
|
||||
'label' => trans('firefly.budgeted'),
|
||||
'data' => [],
|
||||
],
|
||||
1 => [
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
'count' => 2,
|
||||
];
|
||||
|
||||
foreach ($entries as $label => $entry) {
|
||||
// data set 0 is budgeted
|
||||
// data set 1 is spent:
|
||||
$data['datasets'][0]['data'][] = $entry['budgeted'];
|
||||
$data['datasets'][1]['data'][] = round(($entry['spent'] * -1), 2);
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function year(Collection $budgets, Collection $entries): array
|
||||
{
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($budgets as $budget) {
|
||||
$data['labels'][] = $budget->name;
|
||||
}
|
||||
// also add "no budget"
|
||||
$data['labels'][] = strval(trans('firefly.no_budget'));
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$array = [
|
||||
'label' => $entry[0]->formatLocalized($format),
|
||||
'data' => [],
|
||||
];
|
||||
array_shift($entry);
|
||||
$array['data'] = $entry;
|
||||
$data['datasets'][] = $array;
|
||||
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CategoryChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Category;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface CategoryChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Category
|
||||
*/
|
||||
interface CategoryChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $data): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mainReportChart(array $entries): array;
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriod(Collection $categories, Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function period(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriod(Collection $categories, Collection $entries): array;
|
||||
}
|
@@ -1,239 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsCategoryChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Generator\Chart\Category;
|
||||
|
||||
use FireflyIII\Support\ChartColour;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChartJsCategoryChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Category
|
||||
*/
|
||||
class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all(Collection $entries): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.earned'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[1];
|
||||
$spent = $entry[2];
|
||||
$earned = $entry[3];
|
||||
|
||||
$data['datasets'][0]['data'][] = bccomp($spent, '0') === 0 ? null : round(bcmul($spent, '-1'), 4);
|
||||
$data['datasets'][1]['data'][] = bccomp($earned, '0') === 0 ? null : round($earned, 4);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriod(Collection $categories, Collection $entries): array
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$data['labels'][] = $category->name;
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$date = $entry[0]->formatLocalized($format);
|
||||
array_shift($entry);
|
||||
$data['count']++;
|
||||
$data['datasets'][] = ['label' => $date, 'data' => $entry];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $entries): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry->spent != 0) {
|
||||
$data['labels'][] = $entry->name;
|
||||
$data['datasets'][0]['data'][] = round(bcmul($entry->spent, '-1'), 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mainReportChart(array $entries): array
|
||||
{
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => array_keys($entries),
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
|
||||
foreach ($entries as $row) {
|
||||
foreach ($row['in'] as $categoryId => $amount) {
|
||||
// get in:
|
||||
$data['datasets'][$categoryId . 'in']['data'][] = round($amount, 2);
|
||||
|
||||
// get out:
|
||||
$opposite = $row['out'][$categoryId];
|
||||
$data['datasets'][$categoryId . 'out']['data'][] = round($opposite, 2);
|
||||
|
||||
// set name:
|
||||
$data['datasets'][$categoryId . 'out']['label'] = $row['name'][$categoryId] . ' (' . strtolower(strval(trans('firefly.expenses'))) . ')';
|
||||
$data['datasets'][$categoryId . 'in']['label'] = $row['name'][$categoryId] . ' (' . strtolower(strval(trans('firefly.income'))) . ')';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// remove empty rows:
|
||||
foreach ($data['datasets'] as $key => $content) {
|
||||
if (array_sum($content['data']) === 0.0) {
|
||||
unset($data['datasets'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// re-key the datasets array:
|
||||
$data['datasets'] = array_values($data['datasets']);
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function period(Collection $entries): array
|
||||
{
|
||||
return $this->all($entries);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pieChart(array $entries): array
|
||||
{
|
||||
$data = [
|
||||
'datasets' => [
|
||||
0 => [],
|
||||
],
|
||||
'labels' => [],
|
||||
];
|
||||
$index = 0;
|
||||
foreach ($entries as $entry) {
|
||||
|
||||
if (bccomp($entry['amount'], '0') === -1) {
|
||||
$entry['amount'] = bcmul($entry['amount'], '-1');
|
||||
}
|
||||
|
||||
$data['datasets'][0]['data'][] = round($entry['amount'], 2);
|
||||
$data['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
||||
$data['labels'][] = $entry['name'];
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriod(Collection $categories, Collection $entries): array
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$data['labels'][] = $category->name;
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$date = $entry[0]->formatLocalized($format);
|
||||
array_shift($entry);
|
||||
$data['count']++;
|
||||
$data['datasets'][] = ['label' => $date, 'data' => $entry];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsPiggyBankChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChartJsPiggyBankChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||
*/
|
||||
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function history(Collection $set): array
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = (string)trans('config.month_and_day');
|
||||
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Diff',
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
$sum = '0';
|
||||
foreach ($set as $key => $value) {
|
||||
$date = new Carbon($key);
|
||||
$sum = bcadd($sum, $value);
|
||||
$data['labels'][] = $date->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = round($sum, 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@@ -1,180 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsReportChartGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Generator\Chart\Report;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ChartJsReportChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Report
|
||||
*/
|
||||
class ChartJsReportChartGenerator implements ReportChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Same as above but other translations.
|
||||
*
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOut(Collection $entries): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[0]->formatLocalized('%Y');
|
||||
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
||||
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOutSummarized(string $income, string $expense, int $count): array
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
$data['datasets'][0]['data'][] = round($income, 2);
|
||||
$data['datasets'][1]['data'][] = round($expense, 2);
|
||||
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
||||
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function netWorth(Collection $entries) : array
|
||||
{
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.net_worth'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = trim($entry['date']->formatLocalized($format));
|
||||
$data['datasets'][0]['data'][] = round($entry['net-worth'], 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOut(Collection $entries): array
|
||||
{
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[0]->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
||||
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOutSummarized(string $income, string $expense, int $count): array
|
||||
{
|
||||
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [trans('firefly.sum_of_year'), trans('firefly.average_of_year')],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
$data['datasets'][0]['data'][] = round($income, 2);
|
||||
$data['datasets'][1]['data'][] = round($expense, 2);
|
||||
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
||||
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ReportChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Report;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ReportChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Report
|
||||
*/
|
||||
interface ReportChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOut(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOutSummarized(string $income, string $expense, int $count): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function netWorth(Collection $entries) : array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOut(Collection $entries): array;
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOutSummarized(string $income, string $expense, int $count): array;
|
||||
|
||||
}
|
@@ -25,7 +25,7 @@ use Steam;
|
||||
/**
|
||||
* Class MonthReportGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Report\Standard
|
||||
* @package FireflyIII\Generator\Report\Audit
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
@@ -78,9 +78,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
$auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance;
|
||||
}
|
||||
|
||||
$reportType = 'audit';
|
||||
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
|
||||
|
||||
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
|
||||
$reportType = 'audit';
|
||||
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
|
||||
$hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date',
|
||||
'interest_date', 'book_date', 'process_date',
|
||||
// three new optional fields.
|
||||
@@ -88,10 +88,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
'from', 'to', 'budget', 'category', 'bill',
|
||||
// more new optional fields
|
||||
'internal_reference', 'notes',
|
||||
|
||||
'create_date', 'update_date',
|
||||
];
|
||||
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
|
||||
|
||||
|
||||
return view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow'))
|
||||
->with('start', $this->start)->with('end', $this->end)->with('accounts', $this->accounts)
|
||||
@@ -111,6 +110,16 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -144,4 +153,4 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,4 +24,4 @@ class MultiYearReportGenerator extends MonthReportGenerator
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@@ -25,4 +25,4 @@ class YearReportGenerator extends MonthReportGenerator
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
247
app/Generator/Report/Budget/MonthReportGenerator.php
Normal file
247
app/Generator/Report/Budget/MonthReportGenerator.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/**
|
||||
* MonthReportGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Report\Budget;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Generator\Report\Support;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class MonthReportGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Report\Budget
|
||||
*/
|
||||
class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
{
|
||||
/** @var Collection */
|
||||
private $accounts;
|
||||
/** @var Collection */
|
||||
private $budgets;
|
||||
/** @var Carbon */
|
||||
private $end;
|
||||
/** @var Collection */
|
||||
private $expenses;
|
||||
/** @var Collection */
|
||||
private $income;
|
||||
/** @var Carbon */
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* MonthReportGenerator constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->income = new Collection;
|
||||
$this->expenses = new Collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
|
||||
$budgetIds = join(',', $this->budgets->pluck('id')->toArray());
|
||||
$expenses = $this->getExpenses();
|
||||
$accountSummary = $this->summarizeByAccount($expenses);
|
||||
$budgetSummary = $this->summarizeByBudget($expenses);
|
||||
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
||||
$topExpenses = $this->getTopExpenses();
|
||||
|
||||
// render!
|
||||
return view('reports.budget.month', compact('accountIds', 'budgetIds', 'accountSummary', 'budgetSummary', 'averageExpenses', 'topExpenses'))
|
||||
->with('start', $this->start)->with('end', $this->end)
|
||||
->with('budgets', $this->budgets)
|
||||
->with('accounts', $this->accounts)
|
||||
->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
$this->budgets = $budgets;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setEndDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
$this->end = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface
|
||||
{
|
||||
$this->start = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @param int $sortFlag
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getAverages(Collection $collection, int $sortFlag): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
// opposing name and ID:
|
||||
$opposingId = $transaction->opposing_account_id;
|
||||
|
||||
// is not set?
|
||||
if (!isset($result[$opposingId])) {
|
||||
$name = $transaction->opposing_account_name;
|
||||
$result[$opposingId] = [
|
||||
'name' => $name,
|
||||
'count' => 1,
|
||||
'id' => $opposingId,
|
||||
'average' => $transaction->transaction_amount,
|
||||
'sum' => $transaction->transaction_amount,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$result[$opposingId]['count']++;
|
||||
$result[$opposingId]['sum'] = bcadd($result[$opposingId]['sum'], $transaction->transaction_amount);
|
||||
$result[$opposingId]['average'] = bcdiv($result[$opposingId]['sum'], strval($result[$opposingId]['count']));
|
||||
}
|
||||
|
||||
// sort result by average:
|
||||
$average = [];
|
||||
foreach ($result as $key => $row) {
|
||||
$average[$key] = floatval($row['average']);
|
||||
}
|
||||
|
||||
array_multisort($average, $sortFlag, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getExpenses(): Collection
|
||||
{
|
||||
if ($this->expenses->count() > 0) {
|
||||
Log::debug('Return previous set of expenses.');
|
||||
|
||||
return $this->expenses;
|
||||
}
|
||||
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->setBudgets($this->budgets)->withOpposingAccount()->disableFilter();
|
||||
|
||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
||||
$transactions = $collector->getJournals();
|
||||
$transactions = self::filterExpenses($transactions, $accountIds);
|
||||
$this->expenses = $transactions;
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getTopExpenses(): Collection
|
||||
{
|
||||
$transactions = $this->getExpenses()->sortBy('transaction_amount');
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function summarizeByAccount(Collection $collection): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$accountId = $transaction->account_id;
|
||||
$result[$accountId] = $result[$accountId] ?? '0';
|
||||
$result[$accountId] = bcadd($transaction->transaction_amount, $result[$accountId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function summarizeByBudget(Collection $collection): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$jrnlBudId = intval($transaction->transaction_journal_budget_id);
|
||||
$transBudId = intval($transaction->transaction_budget_id);
|
||||
$budgetId = max($jrnlBudId, $transBudId);
|
||||
$result[$budgetId] = $result[$budgetId] ?? '0';
|
||||
$result[$budgetId] = bcadd($transaction->transaction_amount, $result[$budgetId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
27
app/Generator/Report/Budget/MultiYearReportGenerator.php
Normal file
27
app/Generator/Report/Budget/MultiYearReportGenerator.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* MultiYearReportGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Report\Budget;
|
||||
|
||||
|
||||
/**
|
||||
* Class MultiYearReportGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Report\Budget
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
28
app/Generator/Report/Budget/YearReportGenerator.php
Normal file
28
app/Generator/Report/Budget/YearReportGenerator.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* YearReportGenerator.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Report\Budget;
|
||||
|
||||
|
||||
/**
|
||||
* Class YearReportGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Report\Budget
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
@@ -15,8 +15,8 @@ namespace FireflyIII\Generator\Report\Category;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Crypt;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Generator\Report\Support;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
@@ -60,10 +60,12 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
|
||||
$categoryIds = join(',', $this->categories->pluck('id')->toArray());
|
||||
$reportType = 'category';
|
||||
$accountSummary = $this->getAccountSummary();
|
||||
$categorySummary = $this->getCategorySummary();
|
||||
$averageExpenses = $this->getAverageExpenses();
|
||||
$averageIncome = $this->getAverageIncome();
|
||||
$expenses = $this->getExpenses();
|
||||
$income = $this->getIncome();
|
||||
$accountSummary = $this->getObjectSummary($this->summarizeByAccount($expenses), $this->summarizeByAccount($income));
|
||||
$categorySummary = $this->getObjectSummary($this->summarizeByCategory($expenses), $this->summarizeByCategory($income));
|
||||
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
||||
$averageIncome = $this->getAverages($income, SORT_DESC);
|
||||
$topExpenses = $this->getTopExpenses();
|
||||
$topIncome = $this->getTopIncome();
|
||||
|
||||
@@ -93,6 +95,16 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -130,61 +142,22 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @param int $sortFlag
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getAccountSummary(): array
|
||||
private function getAverages(Collection $collection, int $sortFlag): array
|
||||
{
|
||||
$spent = $this->getSpentAccountSummary();
|
||||
$earned = $this->getEarnedAccountSummary();
|
||||
$return = [];
|
||||
|
||||
/**
|
||||
* @var int $accountId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($spent as $accountId => $entry) {
|
||||
if (!isset($return[$accountId])) {
|
||||
$return[$accountId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$accountId]['spent'] = $entry;
|
||||
}
|
||||
unset($entry);
|
||||
|
||||
/**
|
||||
* @var int $accountId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($earned as $accountId => $entry) {
|
||||
if (!isset($return[$accountId])) {
|
||||
$return[$accountId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$accountId]['earned'] = $entry;
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getAverageExpenses(): array
|
||||
{
|
||||
$expenses = $this->getExpenses();
|
||||
$result = [];
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($expenses as $transaction) {
|
||||
foreach ($collection as $transaction) {
|
||||
// opposing name and ID:
|
||||
$opposingId = $transaction->opposing_account_id;
|
||||
|
||||
// is not set?
|
||||
if (!isset($result[$opposingId])) {
|
||||
$name = $transaction->opposing_account_name;
|
||||
$encrypted = intval($transaction->opposing_account_encrypted);
|
||||
$name = $encrypted === 1 ? Crypt::decrypt($name) : $name;
|
||||
$result[$opposingId] = [
|
||||
'name' => $name,
|
||||
'count' => 1,
|
||||
@@ -205,124 +178,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
$average[$key] = floatval($row['average']);
|
||||
}
|
||||
|
||||
array_multisort($average, SORT_ASC, $result);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getAverageIncome(): array
|
||||
{
|
||||
$expenses = $this->getIncome();
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($expenses as $transaction) {
|
||||
// opposing name and ID:
|
||||
$opposingId = $transaction->opposing_account_id;
|
||||
|
||||
// is not set?
|
||||
if (!isset($result[$opposingId])) {
|
||||
$name = $transaction->opposing_account_name;
|
||||
$encrypted = intval($transaction->opposing_account_encrypted);
|
||||
$name = $encrypted === 1 ? Crypt::decrypt($name) : $name;
|
||||
$result[$opposingId] = [
|
||||
'name' => $name,
|
||||
'count' => 1,
|
||||
'id' => $opposingId,
|
||||
'average' => $transaction->transaction_amount,
|
||||
'sum' => $transaction->transaction_amount,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$result[$opposingId]['count']++;
|
||||
$result[$opposingId]['sum'] = bcadd($result[$opposingId]['sum'], $transaction->transaction_amount);
|
||||
$result[$opposingId]['average'] = bcdiv($result[$opposingId]['sum'], strval($result[$opposingId]['count']));
|
||||
}
|
||||
|
||||
// sort result by average:
|
||||
$average = [];
|
||||
foreach ($result as $key => $row) {
|
||||
$average[$key] = floatval($row['average']);
|
||||
}
|
||||
|
||||
array_multisort($average, SORT_DESC, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getCategorySummary(): array
|
||||
{
|
||||
$spent = $this->getSpentCategorySummary();
|
||||
$earned = $this->getEarnedCategorySummary();
|
||||
$return = [];
|
||||
|
||||
/**
|
||||
* @var int $categoryId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($spent as $categoryId => $entry) {
|
||||
if (!isset($return[$categoryId])) {
|
||||
$return[$categoryId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$categoryId]['spent'] = $entry;
|
||||
}
|
||||
unset($entry);
|
||||
|
||||
/**
|
||||
* @var int $categoryId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($earned as $categoryId => $entry) {
|
||||
if (!isset($return[$categoryId])) {
|
||||
$return[$categoryId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$categoryId]['earned'] = $entry;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getEarnedAccountSummary(): array
|
||||
{
|
||||
$transactions = $this->getIncome();
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$accountId = $transaction->account_id;
|
||||
$result[$accountId] = $result[$accountId] ?? '0';
|
||||
$result[$accountId] = bcadd($transaction->transaction_amount, $result[$accountId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getEarnedCategorySummary(): array
|
||||
{
|
||||
$transactions = $this->getIncome();
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = intval($transaction->transaction_journal_category_id);
|
||||
$transCatId = intval($transaction->transaction_category_id);
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
}
|
||||
array_multisort($average, $sortFlag, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -373,43 +229,44 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $spent
|
||||
* @param array $earned
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSpentAccountSummary(): array
|
||||
private function getObjectSummary(array $spent, array $earned): array
|
||||
{
|
||||
$transactions = $this->getExpenses();
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$accountId = $transaction->account_id;
|
||||
$result[$accountId] = $result[$accountId] ?? '0';
|
||||
$result[$accountId] = bcadd($transaction->transaction_amount, $result[$accountId]);
|
||||
$return = [];
|
||||
|
||||
/**
|
||||
* @var int $accountId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($spent as $objectId => $entry) {
|
||||
if (!isset($return[$objectId])) {
|
||||
$return[$objectId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$objectId]['spent'] = $entry;
|
||||
}
|
||||
unset($entry);
|
||||
|
||||
/**
|
||||
* @var int $accountId
|
||||
* @var string $entry
|
||||
*/
|
||||
foreach ($earned as $objectId => $entry) {
|
||||
if (!isset($return[$objectId])) {
|
||||
$return[$objectId] = ['spent' => 0, 'earned' => 0];
|
||||
}
|
||||
|
||||
$return[$objectId]['earned'] = $entry;
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getSpentCategorySummary(): array
|
||||
{
|
||||
$transactions = $this->getExpenses();
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = intval($transaction->transaction_journal_category_id);
|
||||
$transCatId = intval($transaction->transaction_category_id);
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
@@ -418,14 +275,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
{
|
||||
$transactions = $this->getExpenses()->sortBy('transaction_amount');
|
||||
|
||||
$transactions = $transactions->each(
|
||||
function (Transaction $transaction) {
|
||||
if (intval($transaction->opposing_account_encrypted) === 1) {
|
||||
$transaction->opposing_account_name = Crypt::decrypt($transaction->opposing_account_name);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
@@ -436,14 +285,44 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
{
|
||||
$transactions = $this->getIncome()->sortByDesc('transaction_amount');
|
||||
|
||||
$transactions = $transactions->each(
|
||||
function (Transaction $transaction) {
|
||||
if (intval($transaction->opposing_account_encrypted) === 1) {
|
||||
$transaction->opposing_account_name = Crypt::decrypt($transaction->opposing_account_name);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function summarizeByAccount(Collection $collection): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$accountId = $transaction->account_id;
|
||||
$result[$accountId] = $result[$accountId] ?? '0';
|
||||
$result[$accountId] = bcadd($transaction->transaction_amount, $result[$accountId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function summarizeByCategory(Collection $collection): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($collection as $transaction) {
|
||||
$jrnlCatId = intval($transaction->transaction_journal_category_id);
|
||||
$transCatId = intval($transaction->transaction_category_id);
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -24,4 +24,4 @@ class MultiYearReportGenerator extends MonthReportGenerator
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@@ -25,4 +25,4 @@ class YearReportGenerator extends MonthReportGenerator
|
||||
/**
|
||||
* Doesn't do anything different.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@@ -57,4 +57,4 @@ class ReportGeneratorFactory
|
||||
}
|
||||
throw new FireflyException(sprintf('Cannot generate report. There is no "%s"-report for period "%s".', $type, $period));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,13 @@ interface ReportGeneratorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): ReportGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -57,4 +64,4 @@ interface ReportGeneratorInterface
|
||||
*/
|
||||
public function setStartDate(Carbon $date): ReportGeneratorInterface;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -38,10 +38,9 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
$helper = app(ReportHelperInterface::class);
|
||||
$bills = $helper->getBillReport($this->start, $this->end, $this->accounts);
|
||||
|
||||
// and some id's, joined:
|
||||
/** @var ReportHelperInterface $helper */
|
||||
$helper = app(ReportHelperInterface::class);
|
||||
$bills = $helper->getBillReport($this->start, $this->end, $this->accounts);
|
||||
$accountIds = join(',', $this->accounts->pluck('id')->toArray());
|
||||
$reportType = 'default';
|
||||
|
||||
@@ -64,6 +63,26 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
@@ -87,14 +106,4 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,6 +60,16 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -93,4 +103,4 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,6 +60,16 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): ReportGeneratorInterface
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -93,4 +103,4 @@ class YearReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Generator\Report\Category;
|
||||
namespace FireflyIII\Generator\Report;
|
||||
|
||||
use FireflyIII\Models\Transaction;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -88,4 +88,4 @@ class Support
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -34,25 +34,25 @@ class BudgetEventHandler
|
||||
/**
|
||||
* This method creates a new budget limit repetition when a new budget limit has been created.
|
||||
*
|
||||
* @param StoredBudgetLimit $event
|
||||
* @param StoredBudgetLimit $budgetLimitEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function storeRepetition(StoredBudgetLimit $event):bool
|
||||
public function storeRepetition(StoredBudgetLimit $budgetLimitEvent): bool
|
||||
{
|
||||
return $this->processRepetitionChange($event->budgetLimit, $event->end);
|
||||
return $this->processRepetitionChange($budgetLimitEvent->budgetLimit, $budgetLimitEvent->end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates, if present the budget limit repetition part of a budget limit.
|
||||
*
|
||||
* @param UpdatedBudgetLimit $event
|
||||
* @param UpdatedBudgetLimit $budgetLimitEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateRepetition(UpdatedBudgetLimit $event): bool
|
||||
public function updateRepetition(UpdatedBudgetLimit $budgetLimitEvent): bool
|
||||
{
|
||||
return $this->processRepetitionChange($event->budgetLimit, $event->end);
|
||||
return $this->processRepetitionChange($budgetLimitEvent->budgetLimit, $budgetLimitEvent->end);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ class BudgetEventHandler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function processRepetitionChange(BudgetLimit $budgetLimit, Carbon $date):bool
|
||||
private function processRepetitionChange(BudgetLimit $budgetLimit, Carbon $date): bool
|
||||
{
|
||||
$set = $budgetLimit->limitrepetitions()
|
||||
->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00'))
|
||||
|
@@ -33,15 +33,15 @@ class StoredJournalEventHandler
|
||||
/**
|
||||
* This method connects a new transfer to a piggy bank.
|
||||
*
|
||||
* @param StoredTransactionJournal $event
|
||||
* @param StoredTransactionJournal $storedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connectToPiggyBank(StoredTransactionJournal $event): bool
|
||||
public function connectToPiggyBank(StoredTransactionJournal $storedJournalEvent): bool
|
||||
{
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $event->journal;
|
||||
$piggyBankId = $event->piggyBankId;
|
||||
$journal = $storedJournalEvent->journal;
|
||||
$piggyBankId = $storedJournalEvent->piggyBankId;
|
||||
|
||||
Log::debug(sprintf('Trying to connect journal %d to piggy bank %d.', $journal->id, $piggyBankId));
|
||||
|
||||
@@ -101,11 +101,11 @@ class StoredJournalEventHandler
|
||||
$repetition->currentamount = bcadd($repetition->currentamount, $amount);
|
||||
$repetition->save();
|
||||
|
||||
/** @var PiggyBankEvent $event */
|
||||
$event = PiggyBankEvent::create(
|
||||
/** @var PiggyBankEvent $storedJournalEvent */
|
||||
$storedJournalEvent = PiggyBankEvent::create(
|
||||
['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]
|
||||
);
|
||||
Log::debug(sprintf('Created piggy bank event #%d', $event->id));
|
||||
Log::debug(sprintf('Created piggy bank event #%d', $storedJournalEvent->id));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -113,14 +113,14 @@ class StoredJournalEventHandler
|
||||
/**
|
||||
* This method grabs all the users rules and processes them.
|
||||
*
|
||||
* @param StoredTransactionJournal $event
|
||||
* @param StoredTransactionJournal $storedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function processRules(StoredTransactionJournal $event): bool
|
||||
public function processRules(StoredTransactionJournal $storedJournalEvent): bool
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
$journal = $event->journal;
|
||||
$journal = $storedJournalEvent->journal;
|
||||
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
@@ -150,13 +150,13 @@ class StoredJournalEventHandler
|
||||
/**
|
||||
* This method calls a special bill scanner that will check if the stored journal is part of a bill.
|
||||
*
|
||||
* @param StoredTransactionJournal $event
|
||||
* @param StoredTransactionJournal $storedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function scanBills(StoredTransactionJournal $event): bool
|
||||
public function scanBills(StoredTransactionJournal $storedJournalEvent): bool
|
||||
{
|
||||
$journal = $event->journal;
|
||||
$journal = $storedJournalEvent->journal;
|
||||
BillScanner::scan($journal);
|
||||
|
||||
return true;
|
||||
|
@@ -31,14 +31,14 @@ class UpdatedJournalEventHandler
|
||||
/**
|
||||
* This method will check all the rules when a journal is updated.
|
||||
*
|
||||
* @param UpdatedTransactionJournal $event
|
||||
* @param UpdatedTransactionJournal $updatedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function processRules(UpdatedTransactionJournal $event):bool
|
||||
public function processRules(UpdatedTransactionJournal $updatedJournalEvent): bool
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
$journal = $event->journal;
|
||||
$journal = $updatedJournalEvent->journal;
|
||||
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
@@ -67,13 +67,13 @@ class UpdatedJournalEventHandler
|
||||
/**
|
||||
* This method calls a special bill scanner that will check if the updated journal is part of a bill.
|
||||
*
|
||||
* @param UpdatedTransactionJournal $event
|
||||
* @param UpdatedTransactionJournal $updatedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function scanBills(UpdatedTransactionJournal $event): bool
|
||||
public function scanBills(UpdatedTransactionJournal $updatedJournalEvent): bool
|
||||
{
|
||||
$journal = $event->journal;
|
||||
$journal = $updatedJournalEvent->journal;
|
||||
BillScanner::scan($journal);
|
||||
|
||||
return true;
|
||||
|
@@ -15,9 +15,17 @@ namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use Exception;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Events\BlockedBadLogin;
|
||||
use FireflyIII\Events\BlockedUseOfDomain;
|
||||
use FireflyIII\Events\BlockedUseOfEmail;
|
||||
use FireflyIII\Events\BlockedUserLogin;
|
||||
use FireflyIII\Events\ConfirmedUser;
|
||||
use FireflyIII\Events\DeletedUser;
|
||||
use FireflyIII\Events\LockedOutUser;
|
||||
use FireflyIII\Events\RegisteredUser;
|
||||
use FireflyIII\Events\RequestedNewPassword;
|
||||
use FireflyIII\Events\ResentConfirmation;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Mail\Message;
|
||||
@@ -74,6 +82,210 @@ class UserEventHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BlockedBadLogin $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reportBadLogin(BlockedBadLogin $event)
|
||||
{
|
||||
$email = $event->email;
|
||||
$owner = env('SITE_OWNER');
|
||||
$ipAddress = $event->ipAddress;
|
||||
/** @var Configuration $sendmail */
|
||||
$sendmail = FireflyConfig::get('mail_for_bad_login', config('firefly.configuration.mail_for_bad_login'));
|
||||
Log::debug(sprintf('Now in reportBadLogin for email address %s', $email));
|
||||
Log::error(sprintf('User %s tried to login with bad credentials.', $email));
|
||||
if (is_null($sendmail) || (!is_null($sendmail) && $sendmail->data === false)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.blocked-bad-creds-html', 'emails.blocked-bad-creds-text'], ['email' => $email, 'ip' => $ipAddress],
|
||||
function (Message $message) use ($owner) {
|
||||
$message->to($owner, $owner)->subject('Blocked login attempt with bad credentials');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BlockedUserLogin $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reportBlockedUser(BlockedUserLogin $event): bool
|
||||
{
|
||||
$user = $event->user;
|
||||
$owner = env('SITE_OWNER');
|
||||
$email = $user->email;
|
||||
$ipAddress = $event->ipAddress;
|
||||
/** @var Configuration $sendmail */
|
||||
$sendmail = FireflyConfig::get('mail_for_blocked_login', config('firefly.configuration.mail_for_blocked_login'));
|
||||
Log::debug(sprintf('Now in reportBlockedUser for email address %s', $email));
|
||||
Log::error(sprintf('User #%d (%s) has their accout blocked (blocked_code is "%s") but tried to login.', $user->id, $email, $user->blocked_code));
|
||||
if (is_null($sendmail) || (!is_null($sendmail) && $sendmail->data === false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// send email message:
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.blocked-login-html', 'emails.blocked-login-text'],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'user_address' => $email,
|
||||
'ip' => $ipAddress,
|
||||
'code' => $user->blocked_code,
|
||||
], function (Message $message) use ($owner, $user) {
|
||||
$message->to($owner, $owner)->subject('Blocked login attempt of blocked user');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LockedOutUser $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reportLockout(LockedOutUser $event): bool
|
||||
{
|
||||
$email = $event->email;
|
||||
$owner = env('SITE_OWNER');
|
||||
$ipAddress = $event->ipAddress;
|
||||
/** @var Configuration $sendmail */
|
||||
$sendmail = FireflyConfig::get('mail_for_lockout', config('firefly.configuration.mail_for_lockout'));
|
||||
Log::debug(sprintf('Now in respondToLockout for email address %s', $email));
|
||||
Log::error(sprintf('User %s was locked out after too many invalid login attempts.', $email));
|
||||
if (is_null($sendmail) || (!is_null($sendmail) && $sendmail->data === false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// send email message:
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.locked-out-html', 'emails.locked-out-text'], ['email' => $email, 'ip' => $ipAddress], function (Message $message) use ($owner) {
|
||||
$message->to($owner, $owner)->subject('User was locked out');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BlockedUseOfDomain $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reportUseBlockedDomain(BlockedUseOfDomain $event): bool
|
||||
{
|
||||
$email = $event->email;
|
||||
$owner = env('SITE_OWNER');
|
||||
$ipAddress = $event->ipAddress;
|
||||
$parts = explode('@', $email);
|
||||
/** @var Configuration $sendmail */
|
||||
$sendmail = FireflyConfig::get('mail_for_blocked_domain', config('firefly.configuration.mail_for_blocked_domain'));
|
||||
Log::debug(sprintf('Now in reportUseBlockedDomain for email address %s', $email));
|
||||
Log::error(sprintf('Somebody tried to register using an email address (%s) connected to a banned domain (%s).', $email, $parts[1]));
|
||||
if (is_null($sendmail) || (!is_null($sendmail) && $sendmail->data === false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// send email message:
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.blocked-registration-html', 'emails.blocked-registration-text'],
|
||||
[
|
||||
'email_address' => $email,
|
||||
'blocked_domain' => $parts[1],
|
||||
'ip' => $ipAddress,
|
||||
], function (Message $message) use ($owner) {
|
||||
$message->to($owner, $owner)->subject('Blocked registration attempt with blocked domain');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BlockedUseOfEmail $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reportUseOfBlockedEmail(BlockedUseOfEmail $event): bool
|
||||
{
|
||||
$email = $event->email;
|
||||
$owner = env('SITE_OWNER');
|
||||
$ipAddress = $event->ipAddress;
|
||||
/** @var Configuration $sendmail */
|
||||
$sendmail = FireflyConfig::get('mail_for_blocked_email', config('firefly.configuration.mail_for_blocked_email'));
|
||||
Log::debug(sprintf('Now in reportUseOfBlockedEmail for email address %s', $email));
|
||||
Log::error(sprintf('Somebody tried to register using email address %s which is blocked (SHA2 hash).', $email));
|
||||
if (is_null($sendmail) || (!is_null($sendmail) && $sendmail->data === false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// send email message:
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.blocked-email-html', 'emails.blocked-email-text'],
|
||||
[
|
||||
'user_address' => $email,
|
||||
'ip' => $ipAddress,
|
||||
], function (Message $message) use ($owner) {
|
||||
$message->to($owner, $owner)->subject('Blocked registration attempt with blocked email address');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeletedUser $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function saveEmailAddress(DeletedUser $event): bool
|
||||
{
|
||||
Preferences::mark();
|
||||
$email = hash('sha256', $event->email);
|
||||
Log::debug(sprintf('Hash of email is %s', $email));
|
||||
/** @var Configuration $configuration */
|
||||
$configuration = FireflyConfig::get('deleted_users', []);
|
||||
$content = $configuration->data;
|
||||
if (!is_array($content)) {
|
||||
$content = [];
|
||||
}
|
||||
$content[] = $email;
|
||||
$configuration->data = $content;
|
||||
Log::debug('New content of deleted_users is ', $content);
|
||||
FireflyConfig::set('deleted_users', $content);
|
||||
|
||||
Preferences::mark();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will send a newly registered user a confirmation message, urging him or her to activate their account.
|
||||
*
|
||||
@@ -101,6 +313,33 @@ class UserEventHandler
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestedNewPassword $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendNewPassword(RequestedNewPassword $event): bool
|
||||
{
|
||||
$email = $event->user->email;
|
||||
$ipAddress = $event->ipAddress;
|
||||
$token = $event->token;
|
||||
|
||||
$url = route('password.reset', [$token]);
|
||||
|
||||
// send email.
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.password-html', 'emails.password-text'], ['url' => $url, 'ip' => $ipAddress], function (Message $message) use ($email) {
|
||||
$message->to($email, $email)->subject('Your password reset request');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will send the user a registration mail, welcoming him or her to Firefly III.
|
||||
* This message is only sent when the configuration of Firefly III says so.
|
||||
@@ -123,8 +362,8 @@ class UserEventHandler
|
||||
// send email.
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.registered-html', 'emails.registered'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) {
|
||||
$message->to($email, $email)->subject('Welcome to Firefly III! ');
|
||||
['emails.registered-html', 'emails.registered-text'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) {
|
||||
$message->to($email, $email)->subject('Welcome to Firefly III!');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
@@ -166,7 +405,6 @@ class UserEventHandler
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $ipAddress
|
||||
@@ -191,7 +429,7 @@ class UserEventHandler
|
||||
Preferences::setForUser($user, 'user_confirmed_code', $code);
|
||||
try {
|
||||
Mail::send(
|
||||
['emails.confirm-account-html', 'emails.confirm-account'], ['route' => $route, 'ip' => $ipAddress],
|
||||
['emails.confirm-account-html', 'emails.confirm-account-text'], ['route' => $route, 'ip' => $ipAddress],
|
||||
function (Message $message) use ($email) {
|
||||
$message->to($email, $email)->subject('Please confirm your Firefly III account');
|
||||
}
|
||||
|
@@ -13,7 +13,10 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Bill
|
||||
@@ -26,7 +29,11 @@ class Bill
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected $bills;
|
||||
private $bills;
|
||||
/** @var Carbon */
|
||||
private $endDate;
|
||||
/** @var Carbon */
|
||||
private $startDate;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,6 +51,43 @@ class Bill
|
||||
$this->bills->push($bill);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function filterBills()
|
||||
{
|
||||
Log::debug('Now in filterBills()');
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$start = $this->startDate;
|
||||
$end = $this->endDate;
|
||||
$lines = $this->bills->filter(
|
||||
function (BillLine $line) use ($repository, $start, $end) {
|
||||
// next expected match?
|
||||
$date = $start;
|
||||
Log::debug(sprintf('Now at bill line for bill "%s"', $line->getBill()->name));
|
||||
Log::debug(sprintf('Default date to use is start date: %s', $date->format('Y-m-d')));
|
||||
if ($line->isHit()) {
|
||||
$date = $line->getLastHitDate();
|
||||
Log::debug(sprintf('Line was hit, see date: %s. Always include it.', $date->format('Y-m-d')));
|
||||
|
||||
return $line;
|
||||
}
|
||||
$expected = $repository->nextExpectedMatch($line->getBill(), $date);
|
||||
Log::debug(sprintf('Next expected match is %s', $expected->format('Y-m-d')));
|
||||
if ($expected <= $end && $expected >= $start) {
|
||||
Log::debug('This date is inside report limits');
|
||||
|
||||
return $line;
|
||||
}
|
||||
Log::debug('This date is OUTSIDE report limits');
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$this->bills = $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -62,4 +106,20 @@ class Bill
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $endDate
|
||||
*/
|
||||
public function setEndDate(Carbon $endDate)
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $startDate
|
||||
*/
|
||||
public function setStartDate(Carbon $startDate)
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill as BillModel;
|
||||
|
||||
/**
|
||||
@@ -23,8 +24,6 @@ use FireflyIII\Models\Bill as BillModel;
|
||||
class BillLine
|
||||
{
|
||||
|
||||
/** @var bool */
|
||||
protected $active;
|
||||
/** @var string */
|
||||
protected $amount;
|
||||
/** @var BillModel */
|
||||
@@ -35,10 +34,19 @@ class BillLine
|
||||
protected $max;
|
||||
/** @var string */
|
||||
protected $min;
|
||||
|
||||
/** @var Carbon */
|
||||
private $lastHitDate;
|
||||
/** @var int */
|
||||
private $transactionJournalId;
|
||||
|
||||
/**
|
||||
* BillLine constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->lastHitDate = new Carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -71,6 +79,22 @@ class BillLine
|
||||
$this->bill = $bill;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getLastHitDate(): Carbon
|
||||
{
|
||||
return $this->lastHitDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $lastHitDate
|
||||
*/
|
||||
public function setLastHitDate(Carbon $lastHitDate)
|
||||
{
|
||||
$this->lastHitDate = $lastHitDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -124,15 +148,7 @@ class BillLine
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $active
|
||||
*/
|
||||
public function setActive(bool $active)
|
||||
{
|
||||
$this->active = $active;
|
||||
return intval($this->bill->active) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,4 +167,5 @@ class BillLine
|
||||
$this->hit = $hit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Expense.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Expense
|
||||
*
|
||||
* @package FireflyIII\Helpers\Collection
|
||||
*/
|
||||
class Expense
|
||||
{
|
||||
/** @var Collection */
|
||||
protected $expenses;
|
||||
/** @var string */
|
||||
protected $total = '0';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->expenses = new Collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $entry
|
||||
*/
|
||||
public function addOrCreateExpense(stdClass $entry)
|
||||
{
|
||||
$this->expenses->put($entry->id, $entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $add
|
||||
*/
|
||||
public function addToTotal(string $add)
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
if (bccomp('0', $add) === -1) {
|
||||
$add = bcmul($add, '-1');
|
||||
}
|
||||
|
||||
// if amount is positive, the original transaction
|
||||
// was a transfer. But since this is an expense report,
|
||||
// that amount must be negative.
|
||||
|
||||
$this->total = bcadd($this->total, $add);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getExpenses(): Collection
|
||||
{
|
||||
$set = $this->expenses->sortBy(
|
||||
function (stdClass $object) {
|
||||
return $object->amount;
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTotal(): string
|
||||
{
|
||||
return strval(round($this->total, 2));
|
||||
}
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Income.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Income
|
||||
*
|
||||
* @package FireflyIII\Helpers\Collection
|
||||
*/
|
||||
class Income
|
||||
{
|
||||
|
||||
/** @var Collection */
|
||||
protected $incomes;
|
||||
/** @var string */
|
||||
protected $total = '0';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->incomes = new Collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $entry
|
||||
*/
|
||||
public function addOrCreateIncome(stdClass $entry)
|
||||
{
|
||||
$this->incomes->put($entry->id, $entry);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $add
|
||||
*/
|
||||
public function addToTotal(string $add)
|
||||
{
|
||||
$add = strval(round($add, 2));
|
||||
$this->total = bcadd($this->total, $add);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getIncomes(): Collection
|
||||
{
|
||||
$set = $this->incomes->sortByDesc(
|
||||
function (stdClass $object) {
|
||||
return $object->amount;
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTotal(): string
|
||||
{
|
||||
return strval(round($this->total, 2));
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* JournalCollector.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Helpers\Collector;
|
||||
@@ -16,6 +26,7 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
@@ -49,6 +60,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
'transaction_types.type as transaction_type_type',
|
||||
'transaction_journals.bill_id',
|
||||
'bills.name as bill_name',
|
||||
'bills.name_encrypted as bill_name_encrypted',
|
||||
'transactions.id as id',
|
||||
'transactions.amount as transaction_amount',
|
||||
'transactions.description as transaction_description',
|
||||
@@ -60,6 +72,8 @@ class JournalCollector implements JournalCollectorInterface
|
||||
'account_types.type as account_type',
|
||||
];
|
||||
/** @var bool */
|
||||
private $filterInternalTransfers;
|
||||
/** @var bool */
|
||||
private $filterTransfers = false;
|
||||
/** @var bool */
|
||||
private $joinedBudget = false;
|
||||
@@ -127,6 +141,26 @@ class JournalCollector implements JournalCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function disableInternalFilter(): JournalCollectorInterface
|
||||
{
|
||||
$this->filterInternalTransfers = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function enableInternalFilter(): JournalCollectorInterface
|
||||
{
|
||||
$this->filterInternalTransfers = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -138,12 +172,27 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$set = $this->filterTransfers($set);
|
||||
Log::debug(sprintf('Count of set after filterTransfers() is %d', $set->count()));
|
||||
|
||||
// possibly filter "internal" transfers:
|
||||
$set = $this->filterInternalTransfers($set);
|
||||
Log::debug(sprintf('Count of set after filterInternalTransfers() is %d', $set->count()));
|
||||
|
||||
|
||||
// loop for decryption.
|
||||
$set->each(
|
||||
function (Transaction $transaction) {
|
||||
$transaction->date = new Carbon($transaction->date);
|
||||
$transaction->description = intval($transaction->encrypted) === 1 ? Crypt::decrypt($transaction->description) : $transaction->description;
|
||||
$transaction->bill_name = !is_null($transaction->bill_name) ? Crypt::decrypt($transaction->bill_name) : '';
|
||||
$transaction->description = $transaction->encrypted ? Crypt::decrypt($transaction->description) : $transaction->description;
|
||||
|
||||
if (!is_null($transaction->bill_name)) {
|
||||
$transaction->bill_name = $transaction->bill_name_encrypted ? Crypt::decrypt($transaction->bill_name) : $transaction->bill_name;
|
||||
}
|
||||
|
||||
try {
|
||||
$transaction->opposing_account_name = Crypt::decrypt($transaction->opposing_account_name);
|
||||
} catch (DecryptException $e) {
|
||||
// if this fails its already decrypted.
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
@@ -154,7 +203,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
* @return LengthAwarePaginator
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getPaginatedJournals():LengthAwarePaginator
|
||||
public function getPaginatedJournals(): LengthAwarePaginator
|
||||
{
|
||||
if ($this->run === true) {
|
||||
throw new FireflyException('Cannot getPaginatedJournals after run in JournalCollector.');
|
||||
@@ -244,6 +293,29 @@ class JournalCollector implements JournalCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): JournalCollectorInterface
|
||||
{
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
if (count($budgetIds) === 0) {
|
||||
return $this;
|
||||
}
|
||||
$this->joinBudgetTables();
|
||||
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) use ($budgetIds) {
|
||||
$q->whereIn('budget_transaction.budget_id', $budgetIds);
|
||||
$q->orWhereIn('budget_transaction_journal.budget_id', $budgetIds);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -383,6 +455,27 @@ class JournalCollector implements JournalCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withBudgetInformation(): JournalCollectorInterface
|
||||
{
|
||||
$this->joinBudgetTables();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withCategoryInformation(): JournalCollectorInterface
|
||||
{
|
||||
|
||||
$this->joinCategoryTables();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
@@ -457,6 +550,47 @@ class JournalCollector implements JournalCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function filterInternalTransfers(Collection $set): Collection
|
||||
{
|
||||
if ($this->filterInternalTransfers === false) {
|
||||
Log::debug('Did NO filtering for internal transfers on given set.');
|
||||
|
||||
return $set;
|
||||
}
|
||||
if ($this->joinedOpposing === false) {
|
||||
Log::error('Cannot filter internal transfers because no opposing information is present.');
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
$accountIds = $this->accountIds;
|
||||
$set = $set->filter(
|
||||
function (Transaction $transaction) use ($accountIds) {
|
||||
// both id's in $accountids?
|
||||
if (in_array($transaction->account_id, $accountIds) && in_array($transaction->opposing_account_id, $accountIds)) {
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Transaction #%d has #%d and #%d in set, so removed',
|
||||
$transaction->id, $transaction->account_id, $transaction->opposing_account_id
|
||||
), $accountIds
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the set of accounts used by the collector includes more than one asset
|
||||
* account, chances are the set include double entries: transfers get selected
|
||||
@@ -516,6 +650,8 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$this->joinedBudget = true;
|
||||
$this->query->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$this->query->leftJoin('budget_transaction', 'budget_transaction.transaction_id', '=', 'transactions.id');
|
||||
$this->fields[] = 'budget_transaction_journal.budget_id as transaction_journal_budget_id';
|
||||
$this->fields[] = 'budget_transaction.budget_id as transaction_budget_id';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,22 +673,25 @@ class JournalCollector implements JournalCollectorInterface
|
||||
private function joinOpposingTables()
|
||||
{
|
||||
if (!$this->joinedOpposing) {
|
||||
Log::debug('joinedOpposing is false');
|
||||
// join opposing transaction (hard):
|
||||
$this->query->leftJoin(
|
||||
'transactions as opposing', function (JoinClause $join) {
|
||||
$join->on('opposing.transaction_journal_id', '=', 'transactions.transaction_journal_id')
|
||||
->where('opposing.identifier', '=', 'transactions.identifier')
|
||||
->where('opposing.identifier', '=', DB::raw('transactions.identifier'))
|
||||
->where('opposing.amount', '=', DB::raw('transactions.amount * -1'));
|
||||
}
|
||||
);
|
||||
$this->query->leftJoin('accounts as opposing_accounts', 'opposing.account_id', '=', 'opposing_accounts.id');
|
||||
$this->query->leftJoin('account_types as opposing_account_types', 'opposing_accounts.account_type_id', '=', 'opposing_account_types.id');
|
||||
$this->query->whereNull('opposing.deleted_at');
|
||||
|
||||
$this->fields[] = 'opposing.account_id as opposing_account_id';
|
||||
$this->fields[] = 'opposing_accounts.name as opposing_account_name';
|
||||
$this->fields[] = 'opposing_accounts.encrypted as opposing_account_encrypted';
|
||||
$this->fields[] = 'opposing_account_types.type as opposing_account_type';
|
||||
|
||||
$this->fields[] = 'opposing.account_id as opposing_account_id';
|
||||
$this->fields[] = 'opposing_accounts.name as opposing_account_name';
|
||||
$this->fields[] = 'opposing_accounts.encrypted as opposing_account_encrypted';
|
||||
$this->fields[] = 'opposing_account_types.type as opposing_account_type';
|
||||
$this->joinedOpposing = true;
|
||||
Log::debug('joinedOpposing is now true!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,22 +712,21 @@ class JournalCollector implements JournalCollectorInterface
|
||||
*/
|
||||
private function startQuery(): EloquentBuilder
|
||||
{
|
||||
|
||||
$query = Transaction
|
||||
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transaction_journals.transaction_currency_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
/** @var EloquentBuilder $query */
|
||||
$query = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transaction_journals.transaction_currency_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
|
||||
return $query;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,20 +38,25 @@ interface JournalCollectorInterface
|
||||
*/
|
||||
public function disableFilter(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function disableInternalFilter(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function enableInternalFilter(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournals(): Collection;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withOpposingAccount(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginatedJournals():LengthAwarePaginator;
|
||||
public function getPaginatedJournals(): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
@@ -79,6 +84,14 @@ interface JournalCollectorInterface
|
||||
*/
|
||||
public function setBudget(Budget $budget): JournalCollectorInterface;
|
||||
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
@@ -136,6 +149,21 @@ interface JournalCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withBudgetInformation(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withCategoryInformation(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withOpposingAccount(): JournalCollectorInterface;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
@@ -145,4 +173,4 @@ interface JournalCollectorInterface
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): JournalCollectorInterface;
|
||||
}
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ class Help implements HelpInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute(string $route):bool
|
||||
public function hasRoute(string $route): bool
|
||||
{
|
||||
return Route::has($route);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class Help implements HelpInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache(string $route, string $language):bool
|
||||
public function inCache(string $route, string $language): bool
|
||||
{
|
||||
$line = sprintf('help.%s.%s', $route, $language);
|
||||
$result = Cache::has($line);
|
||||
@@ -120,7 +120,6 @@ class Help implements HelpInterface
|
||||
* @param string $language
|
||||
* @param string $content
|
||||
*
|
||||
* @internal param $title
|
||||
*/
|
||||
public function putInCache(string $route, string $language, string $content)
|
||||
{
|
||||
|
@@ -34,7 +34,7 @@ interface HelpInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromGithub(string $language, string $route):string;
|
||||
public function getFromGithub(string $language, string $route): string;
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
|
@@ -26,6 +26,7 @@ use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class BalanceReportHelper
|
||||
@@ -51,27 +52,31 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts): Balance
|
||||
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): Balance
|
||||
{
|
||||
Log::debug('Start of balance report');
|
||||
$balance = new Balance;
|
||||
$header = new BalanceHeader;
|
||||
$limitRepetitions = $this->budgetRepository->getAllBudgetLimitRepetitions($start, $end);
|
||||
foreach ($accounts as $account) {
|
||||
Log::debug(sprintf('Add account %s to headers.', $account->name));
|
||||
$header->addAccount($account);
|
||||
}
|
||||
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($limitRepetitions as $repetition) {
|
||||
$budget = $this->budgetRepository->find($repetition->budget_id);
|
||||
$line = $this->createBalanceLine($budget, $repetition, $accounts);
|
||||
Log::debug(sprintf('Create balance line for budget #%d ("%s") and repetition #%d', $budget->id, $budget->name, $repetition->id));
|
||||
$line = $this->createBalanceLine($budget, $repetition, $accounts);
|
||||
$balance->addBalanceLine($line);
|
||||
}
|
||||
Log::debug('Create rest of the things.');
|
||||
$noBudgetLine = $this->createNoBudgetLine($accounts, $start, $end);
|
||||
$coveredByTagLine = $this->createTagsBalanceLine($accounts, $start, $end);
|
||||
$leftUnbalancedLine = $this->createLeftUnbalancedLine($noBudgetLine, $coveredByTagLine);
|
||||
@@ -81,9 +86,12 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
$balance->addBalanceLine($leftUnbalancedLine);
|
||||
$balance->setBalanceHeader($header);
|
||||
|
||||
Log::debug('Clear unused budgets.');
|
||||
// remove budgets without expenses from balance lines:
|
||||
$balance = $this->removeUnusedBudgets($balance);
|
||||
|
||||
Log::debug('Return report.');
|
||||
|
||||
return $balance;
|
||||
}
|
||||
|
||||
|
@@ -26,11 +26,11 @@ use Illuminate\Support\Collection;
|
||||
interface BalanceReportHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts): Balance;
|
||||
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): Balance;
|
||||
}
|
||||
|
@@ -19,11 +19,8 @@ use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
|
||||
use FireflyIII\Helpers\Collection\BudgetLine;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class BudgetReportHelper
|
||||
@@ -45,40 +42,6 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBudgetPeriodReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
$budgets = $this->repository->getBudgets();
|
||||
$queryResult = $this->repository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
|
||||
$data = [];
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
|
||||
// do budget "zero"
|
||||
$emptyBudget = new Budget;
|
||||
$emptyBudget->id = 0;
|
||||
$emptyBudget->name = strval(trans('firefly.no_budget'));
|
||||
$budgets->push($emptyBudget);
|
||||
|
||||
// get all budgets and years.
|
||||
foreach ($budgets as $budget) {
|
||||
$data[$budget->id] = [
|
||||
'name' => $budget->name,
|
||||
'entries' => $this->repository->filterAmounts($queryResult, $budget->id, $periods),
|
||||
'sum' => '0',
|
||||
];
|
||||
}
|
||||
// filter out empty ones and fill sum:
|
||||
$data = $this->filterBudgetPeriodReport($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
@@ -183,32 +146,4 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
return $array;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters empty results from getBudgetPeriodReport
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterBudgetPeriodReport(array $data): array
|
||||
{
|
||||
/**
|
||||
* @var int $budgetId
|
||||
* @var array $set
|
||||
*/
|
||||
foreach ($data as $budgetId => $set) {
|
||||
$sum = '0';
|
||||
foreach ($set['entries'] as $amount) {
|
||||
$sum = bcadd($amount, $sum);
|
||||
}
|
||||
$data[$budgetId]['sum'] = $sum;
|
||||
if (bccomp('0', $sum) === 0) {
|
||||
unset($data[$budgetId]);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,15 +26,6 @@ use Illuminate\Support\Collection;
|
||||
interface BudgetReportHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBudgetPeriodReport(Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
|
@@ -17,19 +17,15 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
||||
use FireflyIII\Helpers\Collection\BillLine;
|
||||
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
|
||||
use FireflyIII\Helpers\Collection\Expense;
|
||||
use FireflyIII\Helpers\Collection\Income;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class ReportHelper
|
||||
@@ -70,16 +66,17 @@ class ReportHelper implements ReportHelperInterface
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$bills = $repository->getBillsForAccounts($accounts);
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setBills($bills);
|
||||
$journals = $collector->getJournals();
|
||||
$collection = new BillCollection;
|
||||
$collection->setStartDate($start);
|
||||
$collection->setEndDate($end);
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
$billLine = new BillLine;
|
||||
$billLine->setBill($bill);
|
||||
$billLine->setActive(intval($bill->active) === 1);
|
||||
$billLine->setMin(strval($bill->amount_min));
|
||||
$billLine->setMax(strval($bill->amount_max));
|
||||
$billLine->setHit(false);
|
||||
@@ -94,15 +91,19 @@ class ReportHelper implements ReportHelperInterface
|
||||
if (!is_null($first)) {
|
||||
$billLine->setTransactionJournalId($first->id);
|
||||
$billLine->setAmount($first->transaction_amount);
|
||||
$billLine->setLastHitDate($first->date);
|
||||
$billLine->setHit(true);
|
||||
}
|
||||
|
||||
// non active AND non hit? do not add:
|
||||
// bill is active, or bill is hit:
|
||||
if ($billLine->isActive() || $billLine->isHit()) {
|
||||
$collection->addBill($billLine);
|
||||
}
|
||||
}
|
||||
|
||||
// do some extra filtering.
|
||||
$collection->filterBills();
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
*
|
||||
* @return CategoryCollection
|
||||
*/
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts): CategoryCollection
|
||||
public function getCategoryReport(Collection $accounts, Carbon $start, Carbon $end): CategoryCollection
|
||||
{
|
||||
$object = new CategoryCollection;
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
@@ -131,57 +132,6 @@ class ReportHelper implements ReportHelperInterface
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users expenses during the period for a list of accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): Expense
|
||||
{
|
||||
$object = new Expense;
|
||||
|
||||
/** @var AccountTaskerInterface $tasker */
|
||||
$tasker = app(AccountTaskerInterface::class);
|
||||
$collection = $tasker->expenseReport($accounts, $accounts, $start, $end);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($collection as $entry) {
|
||||
$object->addToTotal($entry->amount);
|
||||
$object->addOrCreateExpense($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users incomes during the period for the given accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Income
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): Income
|
||||
{
|
||||
$object = new Income;
|
||||
/** @var AccountTaskerInterface $tasker */
|
||||
$tasker = app(AccountTaskerInterface::class);
|
||||
$collection = $tasker->incomeReport($accounts, $accounts, $start, $end);
|
||||
|
||||
/** @var stdClass $entry */
|
||||
foreach ($collection as $entry) {
|
||||
$object->addToTotal($entry->amount);
|
||||
$object->addOrCreateIncome($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
|
@@ -49,29 +49,7 @@ interface ReportHelperInterface
|
||||
*
|
||||
* @return CategoryCollection
|
||||
*/
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts): CategoryCollection;
|
||||
|
||||
/**
|
||||
* Get a full report on the users expenses during the period for a list of accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): Expense;
|
||||
|
||||
/**
|
||||
* Get a full report on the users incomes during the period for the given accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Income
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): Income;
|
||||
public function getCategoryReport(Collection $accounts, Carbon $start, Carbon $end): CategoryCollection;
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
|
@@ -13,19 +13,24 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Session;
|
||||
@@ -65,9 +70,18 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function create(string $what = 'asset')
|
||||
{
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$subTitle = trans('firefly.make_new_' . $what . '_account');
|
||||
Session::flash('preFilled', []);
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = ExpandedForm::makeSelectList($repository->get());
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$subTitle = trans('firefly.make_new_' . $what . '_account');
|
||||
Session::flash(
|
||||
'preFilled',
|
||||
[
|
||||
'currency_id' => $defaultCurrency->id,
|
||||
]
|
||||
);
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (session('accounts.create.fromStore') !== true) {
|
||||
@@ -77,7 +91,7 @@ class AccountController extends Controller
|
||||
Session::flash('gaEventCategory', 'accounts');
|
||||
Session::flash('gaEventAction', 'create-' . $what);
|
||||
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle'));
|
||||
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies'));
|
||||
|
||||
}
|
||||
|
||||
@@ -110,17 +124,24 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function destroy(ARI $repository, Account $account)
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||
$name = $account->name;
|
||||
$moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
|
||||
$type = $account->accountType->type;
|
||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||
$name = $account->name;
|
||||
$accountId = $account->id;
|
||||
$moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
|
||||
|
||||
$repository->destroy($account, $moveTo);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.' . $typeName . '_deleted', ['name' => $name])));
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(session('accounts.delete.url'));
|
||||
$uri = session('accounts.delete.url');
|
||||
if (!(strpos($uri, sprintf('accounts/show/%s', $accountId)) === false)) {
|
||||
// uri would point back to account
|
||||
$uri = route('accounts.index', [$typeName]);
|
||||
}
|
||||
|
||||
return redirect($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,6 +155,9 @@ class AccountController extends Controller
|
||||
$what = config('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = ExpandedForm::makeSelectList($repository->get());
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (session('accounts.edit.fromUpdate') !== true) {
|
||||
@@ -154,15 +178,17 @@ class AccountController extends Controller
|
||||
'accountRole' => $account->getMeta('accountRole'),
|
||||
'ccType' => $account->getMeta('ccType'),
|
||||
'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'),
|
||||
'BIC' => $account->getMeta('BIC'),
|
||||
'openingBalanceDate' => $openingBalanceDate,
|
||||
'openingBalance' => $openingBalanceAmount,
|
||||
'virtualBalance' => $account->virtual_balance,
|
||||
'currency_id' => $account->getMeta('currency_id'),
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
Session::flash('gaEventCategory', 'accounts');
|
||||
Session::flash('gaEventAction', 'edit-' . $what);
|
||||
|
||||
return view('accounts.edit', compact('account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what'));
|
||||
return view('accounts.edit', compact('currencies', 'account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,8 +199,7 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function index(ARI $repository, string $what)
|
||||
{
|
||||
$what = $what ?? 'asset';
|
||||
|
||||
$what = $what ?? 'asset';
|
||||
$subTitle = trans('firefly.' . $what . '_accounts');
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = config('firefly.accountTypesByIdentifier.' . $what);
|
||||
@@ -195,6 +220,7 @@ class AccountController extends Controller
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -202,13 +228,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountTaskerInterface $tasker
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Account $account
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function show(AccountTaskerInterface $tasker, ARI $repository, Account $account)
|
||||
public function show(JournalCollectorInterface $collector, Account $account)
|
||||
{
|
||||
if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
||||
return $this->redirectToOriginalAccount($account);
|
||||
@@ -217,61 +242,48 @@ class AccountController extends Controller
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
$subTitle = $account->name;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.single', [$account->id]);
|
||||
|
||||
// replace with journal collector:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
// grab those journals:
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id);
|
||||
|
||||
// grouped other months thing:
|
||||
// oldest transaction in account:
|
||||
$start = $repository->oldestJournalDate($account);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = Navigation::endOfX(new Carbon, $range);
|
||||
$entries = new Collection;
|
||||
// generate entries for each period (and cache those)
|
||||
$entries = $this->periodEntries($account);
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('account-show');
|
||||
$cache->addProperty($account->id);
|
||||
return view('accounts.show', compact('account', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function showAll(AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
$subTitle = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.all', [$account->id]);
|
||||
|
||||
if ($cache->has()) {
|
||||
$entries = $cache->get();
|
||||
// replace with journal collector:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id . '/all');
|
||||
|
||||
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
|
||||
}
|
||||
// get oldest and newest journal for account:
|
||||
$start = $repository->oldestJournalDate($account);
|
||||
$end = $repository->newestJournalDate($account);
|
||||
|
||||
// only include asset accounts when this account is an asset:
|
||||
$assets = new Collection;
|
||||
if (in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEFAULT])) {
|
||||
$assets = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||
}
|
||||
|
||||
while ($end >= $start) {
|
||||
$end = Navigation::startOfPeriod($end, $range);
|
||||
$currentEnd = Navigation::endOfPeriod($end, $range);
|
||||
$spent = $tasker->amountOutInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
|
||||
$earned = $tasker->amountInInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
$entries->push([$dateStr, $dateName, $spent, $earned]);
|
||||
$end = Navigation::subtractPeriod($end, $range, 1);
|
||||
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
|
||||
// same call, except "entries".
|
||||
return view('accounts.show', compact('account', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +292,7 @@ class AccountController extends Controller
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function showWithDate(Account $account, string $date)
|
||||
public function showByDate(Account $account, string $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
@@ -289,6 +301,7 @@ class AccountController extends Controller
|
||||
$subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.period', [$account->id, $carbon->format('Y-m-d')]);
|
||||
|
||||
// replace with journal collector:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
@@ -296,7 +309,8 @@ class AccountController extends Controller
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id . '/' . $date);
|
||||
|
||||
return view('accounts.show_with_date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon'));
|
||||
// same call, except "entries".
|
||||
return view('accounts.show', compact('account', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,7 +386,64 @@ class AccountController extends Controller
|
||||
return $array[$entryId];
|
||||
}
|
||||
|
||||
return '';
|
||||
return '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range)
|
||||
* and for each period, the amount of money spent and earned. This is a complex operation which is cached for
|
||||
* performance reasons.
|
||||
*
|
||||
* @param Account $account The account involved.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function periodEntries(Account $account): Collection
|
||||
{
|
||||
/** @var ARI $repository */
|
||||
$repository = app(ARI::class);
|
||||
/** @var AccountTaskerInterface $tasker */
|
||||
$tasker = app(AccountTaskerInterface::class);
|
||||
|
||||
$start = $repository->oldestJournalDate($account);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = Navigation::endOfX(new Carbon, $range);
|
||||
$entries = new Collection;
|
||||
|
||||
// properties for cache
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('account-show-period-entries');
|
||||
$cache->addProperty($account->id);
|
||||
|
||||
if ($cache->has()) {
|
||||
Log::debug('Entries are cached, return cache.');
|
||||
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
// only include asset accounts when this account is an asset:
|
||||
$assets = new Collection;
|
||||
if (in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEFAULT])) {
|
||||
$assets = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||
}
|
||||
Log::debug('Going to get period expenses and incomes.');
|
||||
while ($end >= $start) {
|
||||
$end = Navigation::startOfPeriod($end, $range);
|
||||
$currentEnd = Navigation::endOfPeriod($end, $range);
|
||||
$spent = $tasker->amountOutInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
|
||||
$earned = $tasker->amountInInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
$entries->push([$dateStr, $dateName, $spent, $earned]);
|
||||
$end = Navigation::subtractPeriod($end, $range, 1);
|
||||
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -61,8 +61,21 @@ class ConfigurationController extends Controller
|
||||
$singleUserMode = FireflyConfig::get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
|
||||
$mustConfirmAccount = FireflyConfig::get('must_confirm_account', config('firefly.configuration.must_confirm_account'))->data;
|
||||
$isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
||||
$siteOwner = env('SITE_OWNER');
|
||||
|
||||
return view('admin.configuration.index', compact('subTitle', 'subTitleIcon', 'singleUserMode', 'mustConfirmAccount', 'isDemoSite'));
|
||||
// email settings:
|
||||
$sendErrorMessage = [
|
||||
'mail_for_lockout' => FireflyConfig::get('mail_for_lockout', config('firefly.configuration.mail_for_lockout'))->data,
|
||||
'mail_for_blocked_domain' => FireflyConfig::get('mail_for_blocked_domain', config('firefly.configuration.mail_for_blocked_domain'))->data,
|
||||
'mail_for_blocked_email' => FireflyConfig::get('mail_for_blocked_email', config('firefly.configuration.mail_for_blocked_email'))->data,
|
||||
'mail_for_bad_login' => FireflyConfig::get('mail_for_bad_login', config('firefly.configuration.mail_for_bad_login'))->data,
|
||||
'mail_for_blocked_login' => FireflyConfig::get('mail_for_blocked_login', config('firefly.configuration.mail_for_blocked_login'))->data,
|
||||
];
|
||||
|
||||
return view(
|
||||
'admin.configuration.index',
|
||||
compact('subTitle', 'subTitleIcon', 'singleUserMode', 'mustConfirmAccount', 'isDemoSite', 'sendErrorMessage', 'siteOwner')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +84,7 @@ class ConfigurationController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(ConfigurationRequest $request)
|
||||
public function postIndex(ConfigurationRequest $request)
|
||||
{
|
||||
// get config values:
|
||||
$data = $request->getConfigurationData();
|
||||
@@ -81,6 +94,13 @@ class ConfigurationController extends Controller
|
||||
FireflyConfig::set('must_confirm_account', $data['must_confirm_account']);
|
||||
FireflyConfig::set('is_demo_site', $data['is_demo_site']);
|
||||
|
||||
// email settings
|
||||
FireflyConfig::set('mail_for_lockout', $data['mail_for_lockout']);
|
||||
FireflyConfig::set('mail_for_blocked_domain', $data['mail_for_blocked_domain']);
|
||||
FireflyConfig::set('mail_for_blocked_email', $data['mail_for_blocked_email']);
|
||||
FireflyConfig::set('mail_for_bad_login', $data['mail_for_bad_login']);
|
||||
FireflyConfig::set('mail_for_blocked_login', $data['mail_for_blocked_login']);
|
||||
|
||||
// flash message
|
||||
Session::flash('success', strval(trans('firefly.configuration_updated')));
|
||||
Preferences::mark();
|
||||
|
@@ -24,7 +24,7 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
@@ -16,9 +16,13 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\UserFormRequest;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class UserController
|
||||
@@ -27,28 +31,56 @@ use Preferences;
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
View::share('title', strval(trans('firefly.administration')));
|
||||
View::share('mainTitleIcon', 'fa-hand-spock-o');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return int
|
||||
* @return View
|
||||
*/
|
||||
public function edit(User $user)
|
||||
{
|
||||
return $user->id;
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (session('users.edit.fromUpdate') !== true) {
|
||||
Session::put('users.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('users.edit.fromUpdate');
|
||||
|
||||
$subTitle = strval(trans('firefly.edit_user', ['email' => $user->email]));
|
||||
$subTitleIcon = 'fa-user-o';
|
||||
$codes = [
|
||||
'' => strval(trans('firefly.no_block_code')),
|
||||
'bounced' => strval(trans('firefly.block_code_bounced')),
|
||||
'expired' => strval(trans('firefly.block_code_expired')),
|
||||
];
|
||||
|
||||
return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return View
|
||||
*/
|
||||
public function index(UserRepositoryInterface $repository)
|
||||
{
|
||||
$title = strval(trans('firefly.administration'));
|
||||
$mainTitleIcon = 'fa-hand-spock-o';
|
||||
$subTitle = strval(trans('firefly.user_administration'));
|
||||
$subTitleIcon = 'fa-users';
|
||||
$mustConfirmAccount = FireflyConfig::get('must_confirm_account', config('firefly.configuration.must_confirm_account'))->data;
|
||||
@@ -57,25 +89,27 @@ class UserController extends Controller
|
||||
// add meta stuff.
|
||||
$users->each(
|
||||
function (User $user) use ($mustConfirmAccount) {
|
||||
// is user activated?
|
||||
$isConfirmed = Preferences::getForUser($user, 'user_confirmed', false)->data;
|
||||
$list = ['user_confirmed', 'twoFactorAuthEnabled', 'twoFactorAuthSecret', 'registration_ip_address', 'confirmation_ip_address'];
|
||||
$preferences = Preferences::getArrayForUser($user, $list);
|
||||
|
||||
$user->activated = true;
|
||||
if ($isConfirmed === false && $mustConfirmAccount === true) {
|
||||
if (!($preferences['user_confirmed'] === true) && $mustConfirmAccount === true) {
|
||||
$user->activated = false;
|
||||
}
|
||||
|
||||
$user->isAdmin = $user->hasRole('owner');
|
||||
$is2faEnabled = Preferences::getForUser($user, 'twoFactorAuthEnabled', false)->data;
|
||||
$has2faSecret = !is_null(Preferences::getForUser($user, 'twoFactorAuthSecret'));
|
||||
$is2faEnabled = $preferences['twoFactorAuthEnabled'] === true;
|
||||
$has2faSecret = !is_null($preferences['twoFactorAuthSecret']);
|
||||
$user->has2FA = false;
|
||||
if ($is2faEnabled && $has2faSecret) {
|
||||
$user->has2FA = true;
|
||||
}
|
||||
$user->prefs = $preferences;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return view('admin.users.index', compact('title', 'mainTitleIcon', 'subTitle', 'subTitleIcon', 'users'));
|
||||
return view('admin.users.index', compact('subTitle', 'subTitleIcon', 'users'));
|
||||
|
||||
}
|
||||
|
||||
@@ -126,5 +160,41 @@ class UserController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserFormRequest $request
|
||||
* @param User $user
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(UserFormRequest $request, User $user)
|
||||
{
|
||||
$data = $request->getUserData();
|
||||
|
||||
// update password
|
||||
if (strlen($data['password']) > 0) {
|
||||
$user->password = bcrypt($data['password']);
|
||||
$user->save();
|
||||
}
|
||||
|
||||
// change blocked status and code:
|
||||
$user->blocked = $data['blocked'];
|
||||
$user->blocked_code = $data['blocked_code'];
|
||||
$user->save();
|
||||
|
||||
Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email])));
|
||||
Preferences::mark();
|
||||
|
||||
if (intval($request->get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('users.edit.fromUpdate', true);
|
||||
|
||||
return redirect(route('admin.users.edit', [$user->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect(session('users.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ class AttachmentController extends Controller
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return View
|
||||
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function delete(Attachment $attachment)
|
||||
{
|
||||
@@ -95,16 +95,12 @@ class AttachmentController extends Controller
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function download(Attachment $attachment)
|
||||
public function download(AttachmentRepositoryInterface $repository, Attachment $attachment)
|
||||
{
|
||||
// create a disk.
|
||||
$disk = Storage::disk('upload');
|
||||
$file = $attachment->fileName();
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
|
||||
if ($repository->exists($attachment)) {
|
||||
$content = $repository->getContent($attachment);
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||
$content = Crypt::decrypt($disk->get($file));
|
||||
|
||||
|
||||
Log::debug('Send file to user', ['file' => $quoted, 'size' => strlen($content)]);
|
||||
|
||||
@@ -118,8 +114,8 @@ class AttachmentController extends Controller
|
||||
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
||||
->header('Pragma', 'public')
|
||||
->header('Content-Length', strlen($content));
|
||||
|
||||
}
|
||||
|
||||
throw new FireflyException('Could not find the indicated attachment. The file is no longer there.');
|
||||
}
|
||||
|
||||
|
37
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file → Normal file
37
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file → Normal file
@@ -13,7 +13,9 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class ForgotPasswordController
|
||||
@@ -33,4 +35,39 @@ class ForgotPasswordController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reset link to the given user.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function sendResetLinkEmail(Request $request)
|
||||
{
|
||||
$this->validate($request, ['email' => 'required|email']);
|
||||
|
||||
// verify if the user is not a demo user. If so, we give him back an error.
|
||||
$user = User::where('email', $request->get('email'))->first();
|
||||
if (!is_null($user) && $user->hasRole('demo')) {
|
||||
return back()->withErrors(
|
||||
['email' => trans('firefly.cannot_reset_demo_user')]
|
||||
);
|
||||
}
|
||||
|
||||
$response = $this->broker()->sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
if ($response === Password::RESET_LINK_SENT) {
|
||||
return back()->with('status', trans($response));
|
||||
}
|
||||
|
||||
// If an error was returned by the password broker, we will get this message
|
||||
// translated so we can notify a user of the problem. We'll redirect back
|
||||
// to where the users came from so they can attempt this process again.
|
||||
return back()->withErrors(
|
||||
['email' => trans($response)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
73
app/Http/Controllers/Auth/LoginController.php
Executable file → Normal file
73
app/Http/Controllers/Auth/LoginController.php
Executable file → Normal file
@@ -14,15 +14,14 @@ namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Config;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Events\BlockedBadLogin;
|
||||
use FireflyIII\Events\BlockedUserLogin;
|
||||
use FireflyIII\Events\LockedOutUser;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Lang;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Swift_TransportException;
|
||||
|
||||
/**
|
||||
* Class LoginController
|
||||
@@ -31,16 +30,6 @@ use Swift_TransportException;
|
||||
*/
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
@@ -49,7 +38,7 @@ class LoginController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
protected $redirectTo = '/';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
@@ -64,25 +53,24 @@ class LoginController extends Controller
|
||||
/**
|
||||
* Handle a login request to the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$this->validateLogin($request);
|
||||
|
||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||
// the login attempts for this application. We'll key this by the username and
|
||||
// the IP address of the client making these requests into this application.
|
||||
if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
|
||||
$lockedOut = $this->hasTooManyLoginAttempts($request);
|
||||
if ($lockedOut) {
|
||||
$this->fireLockoutEvent($request);
|
||||
|
||||
event(new LockedOutUser($request->get('email'), $request->ip()));
|
||||
|
||||
return $this->sendLockoutResponse($request);
|
||||
}
|
||||
|
||||
$credentials = $this->credentials($request);
|
||||
$credentials['blocked'] = 0; // most not be blocked.
|
||||
$credentials['blocked'] = 0; // must not be blocked.
|
||||
|
||||
if ($this->guard()->attempt($credentials, $request->has('remember'))) {
|
||||
return $this->sendLoginResponse($request);
|
||||
@@ -93,10 +81,15 @@ class LoginController extends Controller
|
||||
/** @var User $foundUser */
|
||||
$foundUser = User::where('email', $credentials['email'])->where('blocked', 1)->first();
|
||||
if (!is_null($foundUser)) {
|
||||
// if it exists, show message:
|
||||
// user exists, but is blocked:
|
||||
$code = strlen(strval($foundUser->blocked_code)) > 0 ? $foundUser->blocked_code : 'general_blocked';
|
||||
$errorMessage = strval(trans('firefly.' . $code . '_error', ['email' => $credentials['email']]));
|
||||
$this->reportBlockedUserLoginAttempt($foundUser, $code, $request->ip());
|
||||
event(new BlockedUserLogin($foundUser, $request->ip()));
|
||||
}
|
||||
|
||||
// simply a bad login.
|
||||
if (is_null($foundUser)) {
|
||||
event(new BlockedBadLogin($credentials['email'], $request->ip()));
|
||||
}
|
||||
|
||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||
@@ -166,34 +159,4 @@ class LoginController extends Controller
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about the blocked attempt to login.
|
||||
* Perhaps in a later stage, simply log these messages.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $code
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedUserLoginAttempt(User $user, string $code, string $ipAddress)
|
||||
{
|
||||
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$fields = [
|
||||
'user_id' => $user->id,
|
||||
'user_address' => $user->email,
|
||||
'code' => $code,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-login-html', 'emails.blocked-login'], $fields, function (Message $message) use ($email, $user) {
|
||||
$message->to($email, $email)->subject('Blocked a login attempt from ' . trim($user->email) . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,21 +26,11 @@ use Illuminate\Support\Facades\Password;
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
* @method getEmailSubject()
|
||||
* @method getSendResetLinkEmailSuccessResponse()
|
||||
* @method getSendResetLinkEmailFailureResponse()
|
||||
* @method getSendResetLinkEmailSuccessResponse(string $response)
|
||||
* @method getSendResetLinkEmailFailureResponse(string $response)
|
||||
*/
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
|
57
app/Http/Controllers/Auth/RegisterController.php
Executable file → Normal file
57
app/Http/Controllers/Auth/RegisterController.php
Executable file → Normal file
@@ -14,17 +14,16 @@ namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use Config;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Events\BlockedUseOfDomain;
|
||||
use FireflyIII\Events\BlockedUseOfEmail;
|
||||
use FireflyIII\Events\RegisteredUser;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Session;
|
||||
use Swift_TransportException;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
@@ -34,16 +33,6 @@ use Validator;
|
||||
*/
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
@@ -93,8 +82,19 @@ class RegisterController extends Controller
|
||||
if ($this->isBlockedDomain($data['email'])) {
|
||||
$validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain'));
|
||||
|
||||
$this->reportBlockedDomainRegistrationAttempt($data['email'], $request->ip());
|
||||
event(new BlockedUseOfDomain($data['email'], $request->ip()));
|
||||
$this->throwValidationException($request, $validator);
|
||||
}
|
||||
|
||||
// is user a deleted user?
|
||||
$hash = hash('sha256', $data['email']);
|
||||
$configuration = FireflyConfig::get('deleted_users', []);
|
||||
$set = $configuration->data;
|
||||
Log::debug(sprintf('Hash of email is %s', $hash));
|
||||
Log::debug('Hashes of deleted users: ', $set);
|
||||
if (in_array($hash, $set)) {
|
||||
$validator->getMessageBag()->add('email', (string)trans('validation.deleted_user'));
|
||||
event(new BlockedUseOfEmail($data['email'], $request->ip()));
|
||||
$this->throwValidationException($request, $validator);
|
||||
}
|
||||
|
||||
@@ -202,31 +202,4 @@ class RegisterController extends Controller
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message home about a blocked domain and the address attempted to register.
|
||||
*
|
||||
* @param string $registrationMail
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
private function reportBlockedDomainRegistrationAttempt(string $registrationMail, string $ipAddress)
|
||||
{
|
||||
try {
|
||||
$email = env('SITE_OWNER', false);
|
||||
$parts = explode('@', $registrationMail);
|
||||
$domain = $parts[1];
|
||||
$fields = [
|
||||
'email_address' => $registrationMail,
|
||||
'blocked_domain' => $domain,
|
||||
'ip' => $ipAddress,
|
||||
];
|
||||
|
||||
Mail::send(
|
||||
['emails.blocked-registration-html', 'emails.blocked-registration'], $fields, function (Message $message) use ($email, $domain) {
|
||||
$message->to($email, $email)->subject('Blocked a registration attempt with domain ' . $domain . '.');
|
||||
}
|
||||
);
|
||||
} catch (Swift_TransportException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file → Normal file
10
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file → Normal file
@@ -22,16 +22,6 @@ use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
*/
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
|
@@ -38,10 +38,16 @@ class TwoFactorController extends Controller
|
||||
$user = auth()->user();
|
||||
|
||||
// to make sure the validator in the next step gets the secret, we push it in session
|
||||
$secret = Preferences::get('twoFactorAuthSecret', '')->data;
|
||||
$secret = Preferences::get('twoFactorAuthSecret', null)->data;
|
||||
$title = strval(trans('firefly.two_factor_title'));
|
||||
|
||||
if (strlen($secret) === 0) {
|
||||
// make sure the user has two factor configured:
|
||||
$has2FA = Preferences::get('twoFactorAuthEnabled', null)->data;
|
||||
if (is_null($has2FA) || $has2FA === false) {
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
if (strlen(strval($secret)) === 0) {
|
||||
throw new FireflyException('Your two factor authentication secret is empty, which it cannot be at this point. Please check the log files.');
|
||||
}
|
||||
Session::flash('two-factor-secret', $secret);
|
||||
|
@@ -99,13 +99,20 @@ class BillController extends Controller
|
||||
*/
|
||||
public function destroy(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$name = $bill->name;
|
||||
$name = $bill->name;
|
||||
$billId = $bill->id;
|
||||
$repository->destroy($bill);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.deleted_bill', ['name' => $name])));
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(session('bills.delete.url'));
|
||||
$uri = session('bills.delete.url');
|
||||
if (!(strpos($uri, sprintf('bills/show/%s', $billId)) === false)) {
|
||||
// uri would point back to bill
|
||||
$uri = route('bills.index');
|
||||
}
|
||||
|
||||
return redirect($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,10 +15,10 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||
use FireflyIII\Http\Requests\BudgetIncomeRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
@@ -26,8 +26,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use Session;
|
||||
@@ -42,6 +40,9 @@ use View;
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -55,6 +56,7 @@ class BudgetController extends Controller
|
||||
function ($request, $next) {
|
||||
View::share('title', trans('firefly.budgets'));
|
||||
View::share('mainTitleIcon', 'fa-tasks');
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -73,21 +75,15 @@ class BudgetController extends Controller
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
|
||||
// is custom view range?
|
||||
if (session('is_custom_range') === true) {
|
||||
$viewRange = 'custom';
|
||||
}
|
||||
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
$limitRepetition = $repository->updateLimitAmount($budget, $start, $end, $viewRange, $amount);
|
||||
if ($amount == 0) {
|
||||
$limitRepetition = null;
|
||||
}
|
||||
Preferences::mark();
|
||||
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]);
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0, 'amount' => $amount]);
|
||||
|
||||
}
|
||||
|
||||
@@ -134,15 +130,21 @@ class BudgetController extends Controller
|
||||
public function destroy(Budget $budget, BudgetRepositoryInterface $repository)
|
||||
{
|
||||
|
||||
$name = $budget->name;
|
||||
$name = $budget->name;
|
||||
$budgetId = $budget->id;
|
||||
$repository->destroy($budget);
|
||||
|
||||
|
||||
Session::flash('success', strval(trans('firefly.deleted_budget', ['name' => e($name)])));
|
||||
Preferences::mark();
|
||||
|
||||
$uri = session('budgets.delete.url');
|
||||
if (!(strpos($uri, sprintf('budgets/show/%s', $budgetId)) === false)) {
|
||||
// uri would point back to budget
|
||||
$uri = route('budgets.index');
|
||||
}
|
||||
|
||||
return redirect(session('budgets.delete.url'));
|
||||
return redirect($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,82 +169,27 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param AccountRepositoryInterface $accountRepository
|
||||
*
|
||||
* @return View
|
||||
*
|
||||
*/
|
||||
public function index(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
|
||||
public function index()
|
||||
{
|
||||
$repository->cleanupBudgets();
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$inactive = $repository->getInactiveBudgets();
|
||||
$spent = '0';
|
||||
$budgeted = '0';
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$repeatFreq = Config::get('firefly.range_to_repeat_freq.' . $range);
|
||||
|
||||
if (session('is_custom_range') === true) {
|
||||
$repeatFreq = 'custom';
|
||||
}
|
||||
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', new Carbon);
|
||||
/** @var Carbon $end */
|
||||
$budgets = $this->repository->getActiveBudgets();
|
||||
$inactive = $this->repository->getInactiveBudgets();
|
||||
$start = session('start', new Carbon);
|
||||
$end = session('end', new Carbon);
|
||||
$key = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd');
|
||||
$budgetIncomeTotal = Preferences::get($key, 1000)->data;
|
||||
$period = Navigation::periodShow($start, $range);
|
||||
$periodStart = $start->formatLocalized($this->monthAndDayFormat);
|
||||
$periodEnd = $end->formatLocalized($this->monthAndDayFormat);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
$startAsString = $start->format('Y-m-d');
|
||||
$endAsString = $end->format('Y-m-d');
|
||||
Log::debug('Now at /budgets');
|
||||
|
||||
// loop the budgets:
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
Log::debug(sprintf('Now at budget #%d ("%s")', $budget->id, $budget->name));
|
||||
$budget->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
|
||||
$allRepetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$otherRepetitions = new Collection;
|
||||
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($allRepetitions as $repetition) {
|
||||
if ($repetition->budget_id == $budget->id) {
|
||||
if ($repetition->budgetLimit->repeat_freq == $repeatFreq
|
||||
&& $repetition->startdate->format('Y-m-d') == $startAsString
|
||||
&& $repetition->enddate->format('Y-m-d') == $endAsString
|
||||
) {
|
||||
// do something
|
||||
$budget->currentRep = $repetition;
|
||||
continue;
|
||||
}
|
||||
$otherRepetitions->push($repetition);
|
||||
}
|
||||
}
|
||||
$budget->otherRepetitions = $otherRepetitions;
|
||||
|
||||
if (!is_null($budget->currentRep) && !is_null($budget->currentRep->id)) {
|
||||
$budgeted = bcadd($budgeted, $budget->currentRep->amount);
|
||||
}
|
||||
$spent = bcadd($spent, $budget->spent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
$budgetInformation = $this->collectBudgetInformation($budgets, $start, $end);
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
$available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end);
|
||||
$spent = array_sum(array_column($budgetInformation, 'spent'));
|
||||
$budgeted = array_sum(array_column($budgetInformation, 'budgeted'));
|
||||
|
||||
return view(
|
||||
'budgets.index', compact(
|
||||
'periodStart', 'periodEnd',
|
||||
'period', 'range', 'budgetIncomeTotal',
|
||||
'defaultCurrency', 'inactive', 'budgets',
|
||||
'spent', 'budgeted'
|
||||
)
|
||||
'budgets.index',
|
||||
compact('available', 'periodStart', 'periodEnd', 'budgetInformation', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -274,16 +221,14 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postUpdateIncome()
|
||||
public function postUpdateIncome(BudgetIncomeRequest $request)
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
/** @var Carbon $date */
|
||||
$date = session('start', new Carbon);
|
||||
$start = Navigation::startOfPeriod($date, $range);
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
$key = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd');
|
||||
$start = session('start', new Carbon);
|
||||
$end = session('end', new Carbon);
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
$amount = $request->get('amount');
|
||||
|
||||
Preferences::set($key, intval(Input::get('amount')));
|
||||
$this->repository->setAvailableBudget($defaultCurrency, $start, $end, $amount);
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(route('budgets.index'));
|
||||
@@ -299,12 +244,12 @@ class BudgetController extends Controller
|
||||
public function show(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository, Budget $budget)
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('first', Carbon::create()->startOfYear());
|
||||
$end = new Carbon;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
|
||||
$start = session('first', Carbon::create()->startOfYear());
|
||||
$end = new Carbon;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
$repetition = null;
|
||||
// collector:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setBudget($budget)->setLimit($pageSize)->setPage($page);
|
||||
@@ -326,26 +271,30 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param AccountRepositoryInterface $accountRepository
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function showWithRepetition(
|
||||
BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository, Budget $budget, LimitRepetition $repetition
|
||||
) {
|
||||
public function showByRepetition(Budget $budget, LimitRepetition $repetition)
|
||||
{
|
||||
if ($repetition->budgetLimit->budget->id != $budget->id) {
|
||||
throw new FireflyException('This budget limit is not part of this budget.');
|
||||
}
|
||||
$start = $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$start = $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$subTitle = trans(
|
||||
'firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]
|
||||
);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
|
||||
|
||||
// collector:
|
||||
@@ -420,19 +369,57 @@ class BudgetController extends Controller
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$format = strval(trans('config.month_and_day'));
|
||||
$start = session('start', new Carbon);
|
||||
$end = session('end', new Carbon);
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
$available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end);
|
||||
|
||||
/** @var Carbon $date */
|
||||
$date = session('start', new Carbon);
|
||||
$start = Navigation::startOfPeriod($date, $range);
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
$key = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd');
|
||||
$amount = Preferences::get($key, 1000);
|
||||
$displayStart = $start->formatLocalized($format);
|
||||
$displayEnd = $end->formatLocalized($format);
|
||||
|
||||
return view('budgets.income', compact('amount', 'displayStart', 'displayEnd'));
|
||||
return view('budgets.income', compact('available', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
|
||||
{
|
||||
// get account information
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
$return = [];
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$budgetId = $budget->id;
|
||||
$return[$budgetId] = [
|
||||
'spent' => $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end),
|
||||
'budgeted' => '0',
|
||||
'currentRep' => false,
|
||||
];
|
||||
$allRepetitions = $this->repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$otherRepetitions = new Collection;
|
||||
|
||||
// get all the limit repetitions relevant between start and end and examine them:
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($allRepetitions as $repetition) {
|
||||
if ($repetition->budget_id == $budget->id) {
|
||||
if ($repetition->startdate->isSameDay($start) && $repetition->enddate->isSameDay($end)
|
||||
) {
|
||||
$return[$budgetId]['currentRep'] = $repetition;
|
||||
$return[$budgetId]['budgeted'] = $repetition->amount;
|
||||
continue;
|
||||
}
|
||||
// otherwise it's just one of the many relevant repetitions:
|
||||
$otherRepetitions->push($repetition);
|
||||
}
|
||||
}
|
||||
$return[$budgetId]['otherRepetitions'] = $otherRepetitions;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Category;
|
||||
@@ -60,7 +61,6 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (session('categories.create.fromStore') !== true) {
|
||||
Session::put('categories.create.url', URL::previous());
|
||||
}
|
||||
@@ -98,13 +98,20 @@ class CategoryController extends Controller
|
||||
public function destroy(CRI $repository, Category $category)
|
||||
{
|
||||
|
||||
$name = $category->name;
|
||||
$name = $category->name;
|
||||
$categoryId = $category->id;
|
||||
$repository->destroy($category);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.deleted_category', ['name' => e($name)])));
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(session('categories.delete.url'));
|
||||
$uri = session('categories.delete.url');
|
||||
if (!(strpos($uri, sprintf('categories/show/%s', $categoryId)) === false)) {
|
||||
// uri would point back to category
|
||||
$uri = route('categories.index');
|
||||
}
|
||||
|
||||
return redirect($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,13 +191,13 @@ class CategoryController extends Controller
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$subTitle = $category->name;
|
||||
$subTitleIcon = 'fa-bar-chart';
|
||||
|
||||
// use journal collector
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setPage($page)->setLimit($pageSize)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('categories/show/' . $category->id);
|
||||
@@ -245,7 +252,7 @@ class CategoryController extends Controller
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function showWithDate(Category $category, string $date)
|
||||
public function showByDate(Category $category, string $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
@@ -253,17 +260,16 @@ class CategoryController extends Controller
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $category->name;
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
|
||||
// new collector:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setPage($page)->setLimit($pageSize)->setAllAssetAccounts()->setRange($start, $end)->setCategory($category);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('categories/show/' . $category->id . '/' . $date);
|
||||
|
||||
|
||||
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
|
||||
return view('categories.show-by-date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,11 +16,16 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@@ -37,7 +42,7 @@ use Steam;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -46,8 +51,49 @@ class AccountController extends Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(AccountChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function all(Account $account)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('chart.account.all');
|
||||
$cache->addProperty($account->id);
|
||||
if ($cache->has()) {
|
||||
Log::debug('Return chart.account.all from cache.');
|
||||
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
Log::debug('Regenerate chart.account.all from scratch.');
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$start = $repository->oldestJournalDate($account);
|
||||
$end = new Carbon;
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$current = clone $start;
|
||||
$previous = array_values($range)[0];
|
||||
$chartData = [];
|
||||
|
||||
while ($end >= $current) {
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = $range[$theDate] ?? $previous;
|
||||
$label = $current->formatLocalized($format);
|
||||
$chartData[$label] = $balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->singleSet($account->name, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,41 +110,124 @@ class AccountController extends Controller
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('expenseAccounts');
|
||||
$cache->addProperty('accounts');
|
||||
$cache->addProperty('chart.account.expense-accounts');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
||||
|
||||
$start->subDay();
|
||||
|
||||
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
$chartData = [];
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($startBalances, $endBalances) {
|
||||
$id = $account->id;
|
||||
$startBalance = $startBalances[$id] ?? '0';
|
||||
$endBalance = $endBalances[$id] ?? '0';
|
||||
$diff = bcsub($endBalance, $startBalance);
|
||||
$account->difference = round($diff, 2);
|
||||
foreach ($accounts as $account) {
|
||||
$id = $account->id;
|
||||
$startBalance = $startBalances[$id] ?? '0';
|
||||
$endBalance = $endBalances[$id] ?? '0';
|
||||
$diff = bcsub($endBalance, $startBalance);
|
||||
if (bccomp($diff, '0') !== 0) {
|
||||
$chartData[$account->name] = round($diff, 2);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$accounts = $accounts->sortByDesc(
|
||||
function (Account $account) {
|
||||
return $account->difference;
|
||||
}
|
||||
);
|
||||
|
||||
$data = $this->generator->expenseAccounts($accounts, $start, $end);
|
||||
}
|
||||
arsort($chartData);
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function expenseBudget(JournalCollectorInterface $collector, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.account.expense-budget');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$collector->setAccounts(new Collection([$account]))
|
||||
->setRange($start, $end)
|
||||
->withBudgetInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getJournals();
|
||||
$chartData = [];
|
||||
$result = [];
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlBudgetId = intval($transaction->transaction_journal_budget_id);
|
||||
$transBudgetId = intval($transaction->transaction_budget_id);
|
||||
$budgetId = max($jrnlBudgetId, $transBudgetId);
|
||||
$result[$budgetId] = $result[$budgetId] ?? '0';
|
||||
$result[$budgetId] = bcadd($transaction->transaction_amount, $result[$budgetId]);
|
||||
}
|
||||
|
||||
$names = $this->getBudgetNames(array_keys($result));
|
||||
foreach ($result as $budgetId => $amount) {
|
||||
$chartData[$names[$budgetId]] = $amount;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function expenseCategory(JournalCollectorInterface $collector, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.account.expense-category');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = intval($transaction->transaction_journal_category_id);
|
||||
$transCatId = intval($transaction->transaction_category_id);
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
foreach ($result as $categoryId => $amount) {
|
||||
$chartData[$names[$categoryId]] = $amount;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the balances for all the user's frontpage accounts.
|
||||
*
|
||||
@@ -108,12 +237,111 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function frontpage(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$frontPage = Preferences::get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
Log::debug('Default set is ', $defaultSet);
|
||||
$frontPage = Preferences::get('frontPageAccounts', $defaultSet);
|
||||
Log::debug('Frontpage preference set is ', $frontPage->data);
|
||||
if (count($frontPage->data) === 0) {
|
||||
$frontPage->data = $defaultSet;
|
||||
Log::debug('frontpage set is empty!');
|
||||
$frontPage->save();
|
||||
}
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
|
||||
return Response::json($this->accountBalanceChart($start, $end, $accounts));
|
||||
return Response::json($this->accountBalanceChart($accounts, $start, $end));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function incomeCategory(JournalCollectorInterface $collector, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.account.income-category');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// grab all journals:
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
$transactions = $collector->getJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = intval($transaction->transaction_journal_category_id);
|
||||
$transCatId = intval($transaction->transaction_category_id);
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
foreach ($result as $categoryId => $amount) {
|
||||
$chartData[$names[$categoryId]] = $amount;
|
||||
}
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $date
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function period(Account $account, string $date)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon($date);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
throw new FireflyException('"' . e($date) . '" does not seem to be a valid date. Should be in the format YYYY-MM-DD');
|
||||
}
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.account.period');
|
||||
$cache->addProperty($account->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$current = clone $start;
|
||||
$previous = array_values($range)[0];
|
||||
$chartData = [];
|
||||
|
||||
while ($end >= $current) {
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = $range[$theDate] ?? $previous;
|
||||
$label = $current->formatLocalized($format);
|
||||
$chartData[$label] = $balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->singleSet($account->name, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,9 +353,9 @@ class AccountController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function report(Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function report(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
return Response::json($this->accountBalanceChart($start, $end, $accounts));
|
||||
return Response::json($this->accountBalanceChart($accounts, $start, $end));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,13 +367,13 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function revenueAccounts(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$cache = new CacheProperties;
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$chartData = [];
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('revenueAccounts');
|
||||
$cache->addProperty('accounts');
|
||||
$cache->addProperty('chart.account.revenue-accounts');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
@@ -156,25 +384,19 @@ class AccountController extends Controller
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($startBalances, $endBalances) {
|
||||
$id = $account->id;
|
||||
$startBalance = $startBalances[$id] ?? '0';
|
||||
$endBalance = $endBalances[$id] ?? '0';
|
||||
$diff = bcsub($endBalance, $startBalance);
|
||||
$diff = bcmul($diff, '-1');
|
||||
$account->difference = round($diff, 2);
|
||||
foreach ($accounts as $account) {
|
||||
$id = $account->id;
|
||||
$startBalance = $startBalances[$id] ?? '0';
|
||||
$endBalance = $endBalances[$id] ?? '0';
|
||||
$diff = bcsub($endBalance, $startBalance);
|
||||
$diff = bcmul($diff, '-1');
|
||||
if (bccomp($diff, '0') !== 0) {
|
||||
$chartData[$account->name] = round($diff, 2);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$accounts = $accounts->sortByDesc(
|
||||
function (Account $account) {
|
||||
return $account->difference;
|
||||
}
|
||||
);
|
||||
|
||||
$data = $this->generator->revenueAccounts($accounts, $start, $end);
|
||||
arsort($chartData);
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -196,8 +418,7 @@ class AccountController extends Controller
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('frontpage');
|
||||
$cache->addProperty('single');
|
||||
$cache->addProperty('chart.account.single');
|
||||
$cache->addProperty($account->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
@@ -207,116 +428,115 @@ class AccountController extends Controller
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$current = clone $start;
|
||||
$previous = array_values($range)[0];
|
||||
$labels = [];
|
||||
$chartData = [];
|
||||
|
||||
while ($end >= $current) {
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = $range[$theDate] ?? $previous;
|
||||
|
||||
$labels[] = $current->formatLocalized($format);
|
||||
$chartData[] = $balance;
|
||||
$previous = $balance;
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = $range[$theDate] ?? $previous;
|
||||
$label = $current->formatLocalized($format);
|
||||
$chartData[$label] = $balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
$data = $this->generator->single($account, $labels, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $date
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function specificPeriod(Account $account, string $date)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon($date);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
throw new FireflyException('"' . e($date) . '" does not seem to be a valid date. Should be in the format YYYY-MM-DD');
|
||||
}
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('frontpage');
|
||||
$cache->addProperty('specificPeriod');
|
||||
$cache->addProperty($account->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$current = clone $start;
|
||||
$previous = array_values($range)[0];
|
||||
$labels = [];
|
||||
$chartData = [];
|
||||
|
||||
while ($end >= $current) {
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = $range[$theDate] ?? $previous;
|
||||
|
||||
$labels[] = $current->formatLocalized($format);
|
||||
$chartData[] = $balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
$data = $this->generator->single($account, $labels, $chartData);
|
||||
$data = $this->generator->singleSet($account->name, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function accountBalanceChart(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('account-balance-chart');
|
||||
$cache->addProperty('chart.account.account-balance-chart');
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
Log::debug('Return chart.account.account-balance-chart from cache.');
|
||||
|
||||
return $cache->get();
|
||||
}
|
||||
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
|
||||
|
||||
$chartData = [];
|
||||
foreach ($accounts as $account) {
|
||||
$balances = [];
|
||||
$current = clone $start;
|
||||
$range = Steam::balanceInRange($account, $start, clone $end);
|
||||
$previous = round(array_values($range)[0], 2);
|
||||
while ($current <= $end) {
|
||||
$format = $current->format('Y-m-d');
|
||||
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
||||
$previous = $balance;
|
||||
$balances[] = $balance;
|
||||
$current->addDay();
|
||||
$currentSet = [
|
||||
'label' => $account->name,
|
||||
'entries' => [],
|
||||
];
|
||||
$currentStart = clone $start;
|
||||
$range = Steam::balanceInRange($account, $start, clone $end);
|
||||
$previous = round(array_values($range)[0], 2);
|
||||
while ($currentStart <= $end) {
|
||||
$format = $currentStart->format('Y-m-d');
|
||||
$label = $currentStart->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
||||
$previous = $balance;
|
||||
$currentStart->addDay();
|
||||
$currentSet['entries'][$label] = $balance;
|
||||
}
|
||||
$account->balances = $balances;
|
||||
$chartData[] = $currentSet;
|
||||
}
|
||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $budgetIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getBudgetNames(array $budgetIds): array
|
||||
{
|
||||
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$budgets = $repository->getBudgets();
|
||||
$grouped = $budgets->groupBy('id')->toArray();
|
||||
$return = [];
|
||||
foreach ($budgetIds as $budgetId) {
|
||||
if (isset($grouped[$budgetId])) {
|
||||
$return[$budgetId] = $grouped[$budgetId][0]['name'];
|
||||
}
|
||||
}
|
||||
$return[0] = trans('firefly.no_budget');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Small helper function for some of the charts.
|
||||
*
|
||||
* @param array $categoryIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getCategoryNames(array $categoryIds): array
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$categories = $repository->getCategories();
|
||||
$grouped = $categories->groupBy('id')->toArray();
|
||||
$return = [];
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
if (isset($grouped[$categoryId])) {
|
||||
$return[$categoryId] = $grouped[$categoryId][0]['name'];
|
||||
}
|
||||
}
|
||||
$return[0] = trans('firefly.noCategory');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,8 +14,8 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@@ -32,7 +32,7 @@ use Response;
|
||||
class BillController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -41,8 +41,7 @@ class BillController extends Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(BillChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,45 +53,81 @@ class BillController extends Controller
|
||||
*/
|
||||
public function frontpage(BillRepositoryInterface $repository)
|
||||
{
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||
$data = $this->generator->frontpage($paid, $unpaid);
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.bill.frontpage');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||
$chartData = [
|
||||
strval(trans('firefly.unpaid')) => $unpaid,
|
||||
strval(trans('firefly.paid')) => $paid,
|
||||
];
|
||||
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the overview for a bill. The min/max amount and matched journals.
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function single(Bill $bill)
|
||||
public function single(JournalCollectorInterface $collector, Bill $bill)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('single');
|
||||
$cache->addProperty('bill');
|
||||
$cache->addProperty('chart.bill.single');
|
||||
$cache->addProperty($bill->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// get first transaction or today for start:
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAllAssetAccounts()->setBills(new Collection([$bill]));
|
||||
$results = $collector->getJournals();
|
||||
|
||||
// resort:
|
||||
$results = $collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->getJournals();
|
||||
$results = $results->sortBy(
|
||||
function (Transaction $transaction) {
|
||||
return $transaction->date->format('U');
|
||||
}
|
||||
);
|
||||
|
||||
$data = $this->generator->single($bill, $results);
|
||||
$chartData = [
|
||||
[
|
||||
'type' => 'bar',
|
||||
'label' => trans('firefly.min-amount'),
|
||||
'entries' => [],
|
||||
],
|
||||
[
|
||||
'type' => 'bar',
|
||||
'label' => trans('firefly.max-amount'),
|
||||
'entries' => [],
|
||||
],
|
||||
[
|
||||
'type' => 'line',
|
||||
'label' => trans('firefly.journal-amount'),
|
||||
'entries' => [],
|
||||
],
|
||||
];
|
||||
|
||||
/** @var Transaction $entry */
|
||||
foreach ($results as $entry) {
|
||||
$date = $entry->date->formatLocalized(strval(trans('config.month_and_day')));
|
||||
// minimum amount of bill:
|
||||
$chartData[0]['entries'][$date] = $bill->amount_min;
|
||||
// maximum amount of bill:
|
||||
$chartData[1]['entries'][$date] = $bill->amount_max;
|
||||
// amount of journal:
|
||||
$chartData[2]['entries'][$date] = bcmul($entry->transaction_amount, '-1');
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
@@ -14,7 +14,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
@@ -36,7 +36,7 @@ use Response;
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
|
||||
/** @var BudgetChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -45,8 +45,7 @@ class BudgetController extends Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(BudgetChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +65,7 @@ class BudgetController extends Controller
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($first);
|
||||
$cache->addProperty($last);
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('chart.budget.budget');
|
||||
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
@@ -77,7 +76,7 @@ class BudgetController extends Controller
|
||||
|
||||
$budgetCollection = new Collection([$budget]);
|
||||
$last = Navigation::endOfX($last, $range, $final); // not to overshoot.
|
||||
$entries = new Collection;
|
||||
$entries = [];
|
||||
while ($first < $last) {
|
||||
|
||||
// periodspecific dates:
|
||||
@@ -85,13 +84,14 @@ class BudgetController extends Controller
|
||||
$currentEnd = Navigation::endOfPeriod($first, $range);
|
||||
// sub another day because reasons.
|
||||
$currentEnd->subDay();
|
||||
$spent = $repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
|
||||
$entry = [$first, ($spent * -1)];
|
||||
$entries->push($entry);
|
||||
$first = Navigation::addPeriod($first, $range, 0);
|
||||
$spent = $repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
|
||||
$format = Navigation::periodShow($first, $range);
|
||||
$entries[$format] = bcmul($spent, '-1');
|
||||
$first = Navigation::addPeriod($first, $range, 0);
|
||||
}
|
||||
|
||||
$data = $this->generator->budgetLimit($entries, 'month');
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $entries);
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -113,25 +113,25 @@ class BudgetController extends Controller
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('budget-limit');
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty('chart.budget.budget.limit');
|
||||
$cache->addProperty($repetition->id);
|
||||
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$entries = new Collection;
|
||||
$entries = [];
|
||||
$amount = $repetition->amount;
|
||||
$budgetCollection = new Collection([$budget]);
|
||||
while ($start <= $end) {
|
||||
$spent = $repository->spentInPeriod($budgetCollection, new Collection, $start, $start);
|
||||
$amount = bcadd($amount, $spent);
|
||||
$entries->push([clone $start, round($amount, 2)]);
|
||||
$spent = $repository->spentInPeriod($budgetCollection, new Collection, $start, $start);
|
||||
$amount = bcadd($amount, $spent);
|
||||
$format = $start->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$entries[$format] = $amount;
|
||||
|
||||
$start->addDay();
|
||||
}
|
||||
$data = $this->generator->budgetLimit($entries, 'month_and_day');
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.left')), $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -152,14 +152,30 @@ class BudgetController extends Controller
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('chart.budget.frontpage');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$allEntries = new Collection;
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent_in_budget')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.left_to_spend')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.overspent')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
@@ -167,27 +183,41 @@ class BudgetController extends Controller
|
||||
$reps = $this->filterRepetitions($repetitions, $budget, $start, $end);
|
||||
|
||||
if ($reps->count() === 0) {
|
||||
$collection = $this->spentInPeriodSingle($repository, $budget, $start, $end);
|
||||
$allEntries = $allEntries->merge($collection);
|
||||
$row = $this->spentInPeriodSingle($repository, $budget, $start, $end);
|
||||
if (bccomp($row['spent'], '0') !== 0 || bccomp($row['repetition_left'], '0') !== 0) {
|
||||
$chartData[0]['entries'][$row['name']] = bcmul($row['spent'], '-1');
|
||||
$chartData[1]['entries'][$row['name']] = $row['repetition_left'];
|
||||
$chartData[2]['entries'][$row['name']] = bcmul($row['repetition_overspent'], '-1');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$collection = $this->spentInPeriodMulti($repository, $budget, $reps);
|
||||
$allEntries = $allEntries->merge($collection);
|
||||
$rows = $this->spentInPeriodMulti($repository, $budget, $reps);
|
||||
foreach ($rows as $row) {
|
||||
if (bccomp($row['spent'], '0') !== 0 || bccomp($row['repetition_left'], '0') !== 0) {
|
||||
$chartData[0]['entries'][$row['name']] = bcmul($row['spent'], '-1');
|
||||
$chartData[1]['entries'][$row['name']] = $row['repetition_left'];
|
||||
$chartData[2]['entries'][$row['name']] = bcmul($row['repetition_overspent'], '-1');
|
||||
}
|
||||
}
|
||||
unset($rows, $row);
|
||||
|
||||
}
|
||||
$entry = $this->spentInPeriodWithout($start, $end);
|
||||
$allEntries->push($entry);
|
||||
$data = $this->generator->frontpage($allEntries);
|
||||
// for no budget:
|
||||
$row = $this->spentInPeriodWithout($start, $end);
|
||||
if (bccomp($row['repetition_overspent'], '0') !== 0) {
|
||||
$chartData[0]['entries'][$row['name']] = bcmul($row['spent'], '-1');
|
||||
$chartData[1]['entries'][$row['name']] = $row['repetition_left'];
|
||||
$chartData[2]['entries'][$row['name']] = bcmul($row['repetition_overspent'], '-1');
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO use the NEW query that will be in the repository. Because that query will be shared between the budget period report (table for all budgets)
|
||||
* TODO and this chart (a single budget)
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
@@ -196,7 +226,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function period(BudgetRepositoryInterface $repository, Budget $budget, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function period(BudgetRepositoryInterface $repository, Budget $budget, Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
@@ -204,31 +234,19 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($budget->id);
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('period');
|
||||
$cache->addProperty('chart.budget.period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// the expenses:
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
$result = $repository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end);
|
||||
$entries = $repository->filterAmounts($result, $budget->id, $periods);
|
||||
// get the expenses
|
||||
$budgeted = [];
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
$entries = $repository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end);
|
||||
$key = Navigation::preferredCarbonFormat($start, $end);
|
||||
$range = Navigation::preferredRangeFormat($start, $end);
|
||||
|
||||
// the budget limits:
|
||||
$range = '1D';
|
||||
$key = 'Y-m-d';
|
||||
if ($start->diffInMonths($end) > 1) {
|
||||
$range = '1M';
|
||||
$key = 'Y-m';
|
||||
}
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
$range = '1Y';
|
||||
$key = 'Y';
|
||||
}
|
||||
|
||||
// get the budget limits (if any)
|
||||
$repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$current = clone $start;
|
||||
while ($current < $end) {
|
||||
@@ -249,18 +267,66 @@ class BudgetController extends Controller
|
||||
$current = clone $currentEnd;
|
||||
}
|
||||
|
||||
// join them:
|
||||
$result = [];
|
||||
// join them into one set of data:
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent')),
|
||||
'type' => 'bar',
|
||||
'entries' => [],
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.budgeted')),
|
||||
'type' => 'bar',
|
||||
'entries' => [],
|
||||
],
|
||||
];
|
||||
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$nice = $periods[$period];
|
||||
$result[$nice] = [
|
||||
'spent' => isset($entries[$period]) ? $entries[$period] : '0',
|
||||
'budgeted' => isset($entries[$period]) ? $budgeted[$period] : 0,
|
||||
];
|
||||
$label = $periods[$period];
|
||||
$spent = isset($entries[$budget->id]['entries'][$period]) ? $entries[$budget->id]['entries'][$period] : '0';
|
||||
$limit = isset($budgeted[$period]) ? $budgeted[$period] : 0;
|
||||
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 2);
|
||||
$chartData[1]['entries'][$label] = $limit;
|
||||
|
||||
}
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function periodNoBudget(BudgetRepositoryInterface $repository, Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('chart.budget.no-budget');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$data = $this->generator->period($result);
|
||||
// the expenses:
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
$entries = $repository->getNoBudgetPeriodReport($accounts, $start, $end);
|
||||
$chartData = [];
|
||||
|
||||
// join them:
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
$spent = isset($entries['entries'][$period]) ? $entries['entries'][$period] : '0';
|
||||
$chartData[$label] = bcmul($spent, '-1');
|
||||
}
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -289,17 +355,25 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the following values:
|
||||
* 0 =>
|
||||
* 'name' => name of budget + repetition
|
||||
* 'repetition_left' => left in budget repetition (always zero)
|
||||
* 'repetition_overspent' => spent more than budget repetition? (always zero)
|
||||
* 'spent' => actually spent in period for budget
|
||||
* 1 => (etc)
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Collection $repetitions
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
private function spentInPeriodMulti(BudgetRepositoryInterface $repository, Budget $budget, Collection $repetitions): Collection
|
||||
private function spentInPeriodMulti(BudgetRepositoryInterface $repository, Budget $budget, Collection $repetitions): array
|
||||
{
|
||||
$format = strval(trans('config.month_and_day'));
|
||||
$collection = new Collection;
|
||||
$name = $budget->name;
|
||||
$return = [];
|
||||
$format = strval(trans('config.month_and_day'));
|
||||
$name = $budget->name;
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$expenses = $repository->spentInPeriod(new Collection([$budget]), new Collection, $repetition->startdate, $repetition->enddate);
|
||||
@@ -312,43 +386,60 @@ class BudgetController extends Controller
|
||||
}
|
||||
$amount = $repetition->amount;
|
||||
$left = bccomp(bcadd($amount, $expenses), '0') < 1 ? '0' : bcadd($amount, $expenses);
|
||||
$spent = bccomp(bcadd($amount, $expenses), '0') < 1 ? bcmul($amount, '-1') : $expenses;
|
||||
$spent = $expenses;
|
||||
$overspent = bccomp(bcadd($amount, $expenses), '0') < 1 ? bcadd($amount, $expenses) : '0';
|
||||
$array = [$name, $left, $spent, $overspent, $amount, $spent];
|
||||
$collection->push($array);
|
||||
$return[] = [
|
||||
'name' => $name,
|
||||
'repetition_left' => $left,
|
||||
'repetition_overspent' => $overspent,
|
||||
'spent' => $spent,
|
||||
];
|
||||
}
|
||||
|
||||
return $collection;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the following values:
|
||||
* 'name' => name of budget
|
||||
* 'repetition_left' => left in budget repetition (always zero)
|
||||
* 'repetition_overspent' => spent more than budget repetition? (always zero)
|
||||
* 'spent' => actually spent in period for budget
|
||||
*
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
private function spentInPeriodSingle(BudgetRepositoryInterface $repository, Budget $budget, Carbon $start, Carbon $end): Collection
|
||||
private function spentInPeriodSingle(BudgetRepositoryInterface $repository, Budget $budget, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$collection = new Collection;
|
||||
$amount = '0';
|
||||
$left = '0';
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$overspent = '0';
|
||||
$array = [$budget->name, $left, $spent, $overspent, $amount, $spent];
|
||||
$collection->push($array);
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
$array = [
|
||||
'name' => $budget->name,
|
||||
'repetition_left' => '0',
|
||||
'repetition_overspent' => '0',
|
||||
'spent' => $spent,
|
||||
];
|
||||
|
||||
return $collection;
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the following values:
|
||||
* 'name' => "no budget" in local language
|
||||
* 'repetition_left' => left in budget repetition (always zero)
|
||||
* 'repetition_overspent' => spent more than budget repetition? (always zero)
|
||||
* 'spent' => actually spent in period for budget
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function spentInPeriodWithout(Carbon $start, Carbon $end):array
|
||||
private function spentInPeriodWithout(Carbon $start, Carbon $end): array
|
||||
{
|
||||
// collector
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
@@ -360,7 +451,13 @@ class BudgetController extends Controller
|
||||
foreach ($journals as $entry) {
|
||||
$sum = bcadd($entry->transaction_amount, $sum);
|
||||
}
|
||||
$array = [
|
||||
'name' => strval(trans('firefly.no_budget')),
|
||||
'repetition_left' => '0',
|
||||
'repetition_overspent' => $sum,
|
||||
'spent' => '0',
|
||||
];
|
||||
|
||||
return [trans('firefly.no_budget'), '0', '0', $sum, '0', '0'];
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
364
app/Http/Controllers/Chart/BudgetReportController.php
Normal file
364
app/Http/Controllers/Chart/BudgetReportController.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetReportController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
* Separate controller because many helper functions are shared.
|
||||
*
|
||||
* Class BudgetReportController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Chart
|
||||
*/
|
||||
class BudgetReportController extends Controller
|
||||
{
|
||||
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $accountRepository;
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $budgetRepository;
|
||||
/** @var GeneratorInterface */
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
$this->budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $others
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function accountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others)
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.budget.report.account-expense');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($budgets);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($others);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$names = [];
|
||||
$set = $this->getExpenses($accounts, $budgets, $start, $end);
|
||||
$grouped = $this->groupByOpposingAccount($set);
|
||||
$chartData = [];
|
||||
$total = '0';
|
||||
|
||||
foreach ($grouped as $accountId => $amount) {
|
||||
if (!isset($names[$accountId])) {
|
||||
$account = $this->accountRepository->find(intval($accountId));
|
||||
$names[$accountId] = $account->name;
|
||||
}
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$accountId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect all transactions NOT in these budgets.
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $others
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others)
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.budget.report.budget-expense');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($budgets);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($others);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$names = [];
|
||||
$set = $this->getExpenses($accounts, $budgets, $start, $end);
|
||||
$grouped = $this->groupByBudget($set);
|
||||
$total = '0';
|
||||
$chartData = [];
|
||||
|
||||
foreach ($grouped as $budgetId => $amount) {
|
||||
if (!isset($names[$budgetId])) {
|
||||
$budget = $this->budgetRepository->find(intval($budgetId));
|
||||
$names[$budgetId] = $budget->name;
|
||||
}
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$budgetId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect all transactions NOT in these budgets.
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function mainChart(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.budget.report.main');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($budgets);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
|
||||
$function = Navigation::preferredEndOfPeriod($start, $end);
|
||||
$chartData = [];
|
||||
$currentStart = clone $start;
|
||||
$limits = $repository->getAllBudgetLimitRepetitions($start, $end); // also for ALL budgets.
|
||||
|
||||
// prep chart data:
|
||||
foreach ($budgets as $budget) {
|
||||
$chartData[$budget->id] = [
|
||||
'label' => strval(trans('firefly.spent_in_specific_budget', ['budget' => $budget->name])),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$budget->id . '-sum'] = [
|
||||
'label' => strval(trans('firefly.sum_of_expenses_in_budget', ['budget' => $budget->name])),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$budget->id . '-left'] = [
|
||||
'label' => strval(trans('firefly.left_in_budget_limit', ['budget' => $budget->name])),
|
||||
'type' => 'bar',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
}
|
||||
$sumOfExpenses = [];
|
||||
$leftOfLimits = [];
|
||||
while ($currentStart < $end) {
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd = $currentEnd->$function();
|
||||
$expenses = $this->groupByBudget($this->getExpenses($accounts, $budgets, $currentStart, $currentEnd));
|
||||
$label = $currentStart->formatLocalized($format);
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$currentExpenses = $expenses[$budget->id] ?? '0';
|
||||
$sumOfExpenses[$budget->id] = $sumOfExpenses[$budget->id] ?? '0';
|
||||
$sumOfExpenses[$budget->id] = bcadd($currentExpenses, $sumOfExpenses[$budget->id]);
|
||||
$chartData[$budget->id]['entries'][$label] = round(bcmul($currentExpenses, '-1'), 2);
|
||||
$chartData[$budget->id . '-sum']['entries'][$label] = round(bcmul($sumOfExpenses[$budget->id], '-1'), 2);
|
||||
|
||||
$limit = $this->filterLimits($limits, $budget, $currentStart);
|
||||
if (!is_null($limit->id)) {
|
||||
$leftOfLimits[$limit->id] = $leftOfLimits[$limit->id] ?? strval($limit->amount);
|
||||
$leftOfLimits[$limit->id] = bcadd($leftOfLimits[$limit->id], $currentExpenses);
|
||||
$chartData[$budget->id . '-left']['entries'][$label] = round($leftOfLimits[$limit->id], 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $limits
|
||||
* @param $budget
|
||||
* @param $currentStart
|
||||
*
|
||||
* @return LimitRepetition
|
||||
*/
|
||||
private function filterLimits(Collection $limits, Budget $budget, Carbon $date): LimitRepetition
|
||||
{
|
||||
Log::debug(sprintf('Start of filterLimits with %d limits.', $limits->count()));
|
||||
$filtered = $limits->filter(
|
||||
function (LimitRepetition $limit) use ($budget, $date) {
|
||||
if ($limit->budget_id !== $budget->id) {
|
||||
Log::debug(sprintf('LimitRepetition has budget #%d but expecting #%d', $limit->budget_id, $budget->id));
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($date < $limit->startdate || $date > $limit->enddate) {
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Date %s is not between %s and %s',
|
||||
$date->format('Y-m-d'), $limit->startdate->format('Y-m-d'), $limit->enddate->format('Y-m-d')
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $limit;
|
||||
}
|
||||
);
|
||||
if ($filtered->count() === 1) {
|
||||
return $filtered->first();
|
||||
}
|
||||
|
||||
return new LimitRepetition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setBudgets($budgets)->withOpposingAccount()->disableFilter();
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$transactions = $collector->getJournals();
|
||||
$set = MonthReportGenerator::filterExpenses($transactions, $accountIds);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function groupByBudget(Collection $set): array
|
||||
{
|
||||
// group by category ID:
|
||||
$grouped = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$jrnlBudId = intval($transaction->transaction_journal_budget_id);
|
||||
$transBudId = intval($transaction->transaction_budget_id);
|
||||
$budgetId = max($jrnlBudId, $transBudId);
|
||||
$grouped[$budgetId] = $grouped[$budgetId] ?? '0';
|
||||
$grouped[$budgetId] = bcadd($transaction->transaction_amount, $grouped[$budgetId]);
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function groupByOpposingAccount(Collection $set): array
|
||||
{
|
||||
$grouped = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$accountId = $transaction->opposing_account_id;
|
||||
$grouped[$accountId] = $grouped[$accountId] ?? '0';
|
||||
$grouped[$accountId] = bcadd($transaction->transaction_amount, $grouped[$accountId]);
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Category;
|
||||
@@ -26,7 +26,6 @@ use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class CategoryController
|
||||
@@ -35,7 +34,7 @@ use stdClass;
|
||||
*/
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/** @var CategoryChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -45,7 +44,7 @@ class CategoryController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(CategoryChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,34 +58,42 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function all(CRI $repository, AccountRepositoryInterface $accountRepository, Category $category)
|
||||
{
|
||||
$start = $repository->firstUseDate($category);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$categoryCollection = new Collection([$category]);
|
||||
$end = new Carbon;
|
||||
$entries = new Collection;
|
||||
$cache = new CacheProperties;
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('categories');
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.all');
|
||||
$cache->addProperty($category->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$start = $repository->firstUseDate($category);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = new Carbon;
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.earned')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
];
|
||||
|
||||
while ($start <= $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||
$spent = $repository->spentInPeriod($categoryCollection, $accounts, $start, $currentEnd);
|
||||
$earned = $repository->earnedInPeriod($categoryCollection, $accounts, $start, $currentEnd);
|
||||
$date = Navigation::periodShow($start, $range);
|
||||
$entries->push([clone $start, $date, $spent, $earned]);
|
||||
$start = Navigation::addPeriod($start, $range, 0);
|
||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
|
||||
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $currentEnd);
|
||||
$label = Navigation::periodShow($start, $range);
|
||||
$chartData[0]['entries'][$label] = bcmul($spent, '-1');
|
||||
$chartData[1]['entries'][$label] = $earned;
|
||||
$start = Navigation::addPeriod($start, $range, 0);
|
||||
}
|
||||
$entries = $entries->reverse();
|
||||
$entries = $entries->slice(0, 48);
|
||||
$entries = $entries->reverse();
|
||||
$data = $this->generator->all($entries);
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -122,34 +129,125 @@ class CategoryController extends Controller
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('frontpage');
|
||||
$cache->addProperty('chart.category.frontpage');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$chartData = [];
|
||||
$categories = $repository->getCategories();
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||
$set = new Collection;
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
|
||||
if (bccomp($spent, '0') === -1) {
|
||||
$category->spent = $spent;
|
||||
$set->push($category);
|
||||
$chartData[$category->name] = bcmul($spent, '-1');
|
||||
}
|
||||
}
|
||||
// this is a "fake" entry for the "no category" entry.
|
||||
$entry = new stdClass;
|
||||
$entry->name = trans('firefly.no_category');
|
||||
$entry->spent = $repository->spentInPeriodWithoutCategory(new Collection, $start, $end);
|
||||
$set->push($entry);
|
||||
$chartData[strval(trans('firefly.no_category'))] = bcmul($repository->spentInPeriodWithoutCategory(new Collection, $start, $end), '-1');
|
||||
|
||||
$set = $set->sortBy('spent');
|
||||
$data = $this->generator->frontpage($set);
|
||||
// sort
|
||||
arsort($chartData);
|
||||
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse|mixed
|
||||
*/
|
||||
public function reportPeriod(CRI $repository, Category $category, Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.category.period');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
$cache->addProperty($category);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$expenses = $repository->periodExpenses(new Collection([$category]), $accounts, $start, $end);
|
||||
$income = $repository->periodIncome(new Collection([$category]), $accounts, $start, $end);
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.earned')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
];
|
||||
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
$spent = $expenses[$category->id]['entries'][$period] ?? '0';
|
||||
$chartData[0]['entries'][$label] = bcmul($spent, '-1');
|
||||
$chartData[1]['entries'][$label] = $income[$category->id]['entries'][$period] ?? '0';
|
||||
}
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse|mixed
|
||||
*/
|
||||
public function reportPeriodNoCategory(CRI $repository, Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.category.period.no-cat');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$expenses = $repository->periodExpensesNoCategory($accounts, $start, $end);
|
||||
$income = $repository->periodIncomeNoCategory($accounts, $start, $end);
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.earned')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
];
|
||||
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
$spent = $expenses['entries'][$period] ?? '0';
|
||||
$chartData[0]['entries'][$label] = bcmul($spent, '-1');
|
||||
$chartData[1]['entries'][$label] = $income['entries'][$period] ?? '0';
|
||||
|
||||
}
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,33 +280,47 @@ class CategoryController extends Controller
|
||||
*/
|
||||
private function makePeriodChart(CRI $repository, Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
$categoryCollection = new Collection([$category]);
|
||||
$cache = new CacheProperties;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('chart.category.period-chart');
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('specific-period');
|
||||
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$entries = new Collection;
|
||||
|
||||
// chart data
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.spent')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
[
|
||||
'label' => strval(trans('firefly.earned')),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
],
|
||||
];
|
||||
|
||||
while ($start <= $end) {
|
||||
$spent = $repository->spentInPeriod($categoryCollection, $accounts, $start, $start);
|
||||
$earned = $repository->earnedInPeriod($categoryCollection, $accounts, $start, $start);
|
||||
$date = Navigation::periodShow($start, '1D');
|
||||
$entries->push([clone $start, $date, $spent, $earned]);
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start);
|
||||
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start);
|
||||
$label = Navigation::periodShow($start, '1D');
|
||||
|
||||
$chartData[0]['entries'][$label] = bcmul($spent, '-1');
|
||||
$chartData[1]['entries'][$label] = $earned;
|
||||
|
||||
|
||||
$start->addDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->period($entries);
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
@@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -24,8 +24,8 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Navigation;
|
||||
use Response;
|
||||
|
||||
@@ -33,8 +33,6 @@ use Response;
|
||||
/**
|
||||
* Separate controller because many helper functions are shared.
|
||||
*
|
||||
* TODO much of this code is actually repeated. First for the object (category, account), then for the direction (in / out).
|
||||
*
|
||||
* Class CategoryReportController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Chart
|
||||
@@ -46,7 +44,7 @@ class CategoryReportController extends Controller
|
||||
private $accountRepository;
|
||||
/** @var CategoryRepositoryInterface */
|
||||
private $categoryRepository;
|
||||
/** @var CategoryChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
@@ -57,7 +55,7 @@ class CategoryReportController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->generator = app(CategoryChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
$this->categoryRepository = app(CategoryRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
@@ -79,39 +77,46 @@ class CategoryReportController extends Controller
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$names = [];
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.report.account-expense');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($categories);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($others);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// collect journals (just like the category report does):
|
||||
$set = $this->getExpenses($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByOpposingAccount($set);
|
||||
$names = [];
|
||||
$set = $this->getExpenses($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByOpposingAccount($set);
|
||||
$chartData = [];
|
||||
$total = '0';
|
||||
|
||||
// show the grouped results:
|
||||
$result = [];
|
||||
$total = '0';
|
||||
foreach ($grouped as $accountId => $amount) {
|
||||
if (!isset($names[$accountId])) {
|
||||
$account = $this->accountRepository->find(intval($accountId));
|
||||
$names[$accountId] = $account->name;
|
||||
}
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$result[] = ['name' => $names[$accountId], 'id' => $accountId, 'amount' => $amount];
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$accountId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect all transactions NOT in these categories.
|
||||
// TODO include transfers
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
Log::debug(sprintf('Sum of others in accountExpense is %f', $sum));
|
||||
$sum = bcsub($sum, $total);
|
||||
$result[] = ['name' => trans('firefly.everything_else'), 'id' => 0, 'amount' => $sum];
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($result);
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
@@ -129,37 +134,45 @@ class CategoryReportController extends Controller
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$names = [];
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.report.account-income');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($categories);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($others);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// collect journals (just like the category report does):
|
||||
$set = $this->getIncome($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByOpposingAccount($set);
|
||||
|
||||
// loop and show the grouped results:
|
||||
$result = [];
|
||||
$total = '0';
|
||||
$names = [];
|
||||
$set = $this->getIncome($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByOpposingAccount($set);
|
||||
$chartData = [];
|
||||
$total = '0';
|
||||
|
||||
foreach ($grouped as $accountId => $amount) {
|
||||
if (!isset($names[$accountId])) {
|
||||
$account = $this->accountRepository->find(intval($accountId));
|
||||
$names[$accountId] = $account->name;
|
||||
}
|
||||
$total = bcadd($total, $amount);
|
||||
$result[] = ['name' => $names[$accountId], 'id' => $accountId, 'amount' => $amount];
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$accountId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect others?
|
||||
// TODO include transfers
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
Log::debug(sprintf('Sum of others in accountIncome is %f', $sum));
|
||||
$sum = bcsub($sum, $total);
|
||||
$result[] = ['name' => trans('firefly.everything_else'), 'id' => 0, 'amount' => $sum];
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($result);
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
@@ -177,39 +190,46 @@ class CategoryReportController extends Controller
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$names = [];
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.report.category-expense');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($categories);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($others);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// collect journals (just like the category report does):
|
||||
$set = $this->getExpenses($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByCategory($set);
|
||||
$names = [];
|
||||
$set = $this->getExpenses($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByCategory($set);
|
||||
$total = '0';
|
||||
$chartData = [];
|
||||
|
||||
// show the grouped results:
|
||||
$result = [];
|
||||
$total = '0';
|
||||
foreach ($grouped as $categoryId => $amount) {
|
||||
if (!isset($names[$categoryId])) {
|
||||
$category = $this->categoryRepository->find(intval($categoryId));
|
||||
$names[$categoryId] = $category->name;
|
||||
}
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$result[] = ['name' => $names[$categoryId], 'id' => $categoryId, 'amount' => $amount];
|
||||
$amount = bcmul($amount, '-1');
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$categoryId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect all transactions NOT in these categories.
|
||||
// TODO include transfers
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
Log::debug(sprintf('Sum of others in categoryExpense is %f', $sum));
|
||||
$sum = bcsub($sum, $total);
|
||||
$result[] = ['name' => trans('firefly.everything_else'), 'id' => 0, 'amount' => $sum];
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($result);
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
@@ -227,37 +247,43 @@ class CategoryReportController extends Controller
|
||||
{
|
||||
/** @var bool $others */
|
||||
$others = intval($others) === 1;
|
||||
$names = [];
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.report.category-income');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($categories);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($others);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// collect journals (just like the category report does):
|
||||
$set = $this->getIncome($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByCategory($set);
|
||||
$names = [];
|
||||
$set = $this->getIncome($accounts, $categories, $start, $end);
|
||||
$grouped = $this->groupByCategory($set);
|
||||
$total = '0';
|
||||
$chartData = [];
|
||||
|
||||
// loop and show the grouped results:
|
||||
$result = [];
|
||||
$total = '0';
|
||||
foreach ($grouped as $categoryId => $amount) {
|
||||
if (!isset($names[$categoryId])) {
|
||||
$category = $this->categoryRepository->find(intval($categoryId));
|
||||
$names[$categoryId] = $category->name;
|
||||
}
|
||||
$total = bcadd($total, $amount);
|
||||
$result[] = ['name' => $names[$categoryId], 'id' => $categoryId, 'amount' => $amount];
|
||||
$total = bcadd($total, $amount);
|
||||
$chartData[$names[$categoryId]] = $amount;
|
||||
}
|
||||
|
||||
// also collect others?
|
||||
// TODO include transfers
|
||||
if ($others) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
Log::debug(sprintf('Sum of others in categoryIncome is %f', $sum));
|
||||
$sum = bcsub($sum, $total);
|
||||
$result[] = ['name' => trans('firefly.everything_else'), 'id' => 0, 'amount' => $sum];
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcsub($sum, $total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->pieChart($result);
|
||||
$data = $this->generator->pieChart($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
@@ -272,43 +298,99 @@ class CategoryReportController extends Controller
|
||||
*/
|
||||
public function mainChart(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
// determin optimal period:
|
||||
$period = '1D';
|
||||
$format = 'month_and_day';
|
||||
if ($start->diffInMonths($end) > 1) {
|
||||
$period = '1M';
|
||||
$format = 'month';
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.category.report.main');
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($categories);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
if ($start->diffInMonths($end) > 13) {
|
||||
$period = '1Y';
|
||||
$format = 'year';
|
||||
}
|
||||
Log::debug(sprintf('Period is %s', $period));
|
||||
$data = [];
|
||||
$current = clone $start;
|
||||
while ($current < $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($current, $period);
|
||||
$expenses = $this->groupByCategory($this->getExpenses($accounts, $categories, $current, $currentEnd));
|
||||
$income = $this->groupByCategory($this->getIncome($accounts, $categories, $current, $currentEnd));
|
||||
$label = $current->formatLocalized(strval(trans('config.' . $format)));
|
||||
$data[$label] = [
|
||||
'in' => [],
|
||||
'out' => [],
|
||||
|
||||
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
|
||||
$function = Navigation::preferredEndOfPeriod($start, $end);
|
||||
$chartData = [];
|
||||
$currentStart = clone $start;
|
||||
|
||||
// prep chart data:
|
||||
foreach ($categories as $category) {
|
||||
$chartData[$category->id . '-in'] = [
|
||||
'label' => $category->name . ' (' . strtolower(strval(trans('firefly.income'))) . ')',
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$category->id . '-out'] = [
|
||||
'label' => $category->name . ' (' . strtolower(strval(trans('firefly.expenses'))) . ')',
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
// total in, total out:
|
||||
$chartData[$category->id . '-total-in'] = [
|
||||
'label' => $category->name . ' (' . strtolower(strval(trans('firefly.sum_of_income'))) . ')',
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$category->id . '-total-out'] = [
|
||||
'label' => $category->name . ' (' . strtolower(strval(trans('firefly.sum_of_expenses'))) . ')',
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
}
|
||||
$sumOfIncome = [];
|
||||
$sumOfExpense = [];
|
||||
|
||||
while ($currentStart < $end) {
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd = $currentEnd->$function();
|
||||
$expenses = $this->groupByCategory($this->getExpenses($accounts, $categories, $currentStart, $currentEnd));
|
||||
$income = $this->groupByCategory($this->getIncome($accounts, $categories, $currentStart, $currentEnd));
|
||||
$label = $currentStart->formatLocalized($format);
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
// get sum, and get label:
|
||||
$categoryId = $category->id;
|
||||
$data[$label]['name'][$categoryId] = $category->name;
|
||||
$data[$label]['in'][$categoryId] = $income[$categoryId] ?? '0';
|
||||
$data[$label]['out'][$categoryId] = $expenses[$categoryId] ?? '0';
|
||||
$labelIn = $category->id . '-in';
|
||||
$labelOut = $category->id . '-out';
|
||||
$labelSumIn = $category->id . '-total-in';
|
||||
$labelSumOut = $category->id . '-total-out';
|
||||
$currentIncome = $income[$category->id] ?? '0';
|
||||
$currentExpense = $expenses[$category->id] ?? '0';
|
||||
|
||||
|
||||
// add to sum:
|
||||
$sumOfIncome[$category->id] = $sumOfIncome[$category->id] ?? '0';
|
||||
$sumOfExpense[$category->id] = $sumOfExpense[$category->id] ?? '0';
|
||||
$sumOfIncome[$category->id] = bcadd($sumOfIncome[$category->id], $currentIncome);
|
||||
$sumOfExpense[$category->id] = bcadd($sumOfExpense[$category->id], $currentExpense);
|
||||
|
||||
// add to chart:
|
||||
$chartData[$labelIn]['entries'][$label] = $currentIncome;
|
||||
$chartData[$labelOut]['entries'][$label] = $currentExpense;
|
||||
$chartData[$labelSumIn]['entries'][$label] = $sumOfIncome[$category->id];
|
||||
$chartData[$labelSumOut]['entries'][$label] = $sumOfExpense[$category->id];
|
||||
}
|
||||
|
||||
$current = Navigation::addPeriod($current, $period, 0);
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
}
|
||||
// remove all empty entries to prevent cluttering:
|
||||
$newSet = [];
|
||||
foreach ($chartData as $key => $entry) {
|
||||
if (!array_sum($entry['entries']) == 0) {
|
||||
$newSet[$key] = $chartData[$key];
|
||||
}
|
||||
}
|
||||
if (count($newSet) === 0) {
|
||||
$newSet = $chartData;
|
||||
}
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
$cache->store($data);
|
||||
|
||||
$data = $this->generator->mainReportChart($data);
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
@@ -391,4 +473,4 @@ class CategoryReportController extends Controller
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,13 +13,12 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Response;
|
||||
|
||||
|
||||
@@ -31,7 +30,7 @@ use Response;
|
||||
class PiggyBankController extends Controller
|
||||
{
|
||||
|
||||
/** @var PiggyBankChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ class PiggyBankController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(PiggyBankChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,26 +55,24 @@ class PiggyBankController extends Controller
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('piggy-history');
|
||||
$cache->addProperty('chart.piggy-bank.history');
|
||||
$cache->addProperty($piggyBank->id);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$set = $repository->getEvents($piggyBank);
|
||||
$set = $set->reverse();
|
||||
$collection = [];
|
||||
$set = $repository->getEvents($piggyBank);
|
||||
$set = $set->reverse();
|
||||
$chartData = [];
|
||||
$sum = '0';
|
||||
/** @var PiggyBankEvent $entry */
|
||||
foreach ($set as $entry) {
|
||||
$date = $entry->date->format('Y-m-d');
|
||||
$amount = $entry->amount;
|
||||
if (isset($collection[$date])) {
|
||||
$amount = bcadd($amount, $collection[$date]);
|
||||
}
|
||||
$collection[$date] = $amount;
|
||||
$label = $entry->date->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$sum = bcadd($sum, $entry->amount);
|
||||
$chartData[$label] = $sum;
|
||||
}
|
||||
|
||||
$data = $this->generator->history(new Collection($collection));
|
||||
$data = $this->generator->singleSet($piggyBank->name, $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
@@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
@@ -32,7 +32,7 @@ use Steam;
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
||||
/** @var ReportChartGeneratorInterface */
|
||||
/** @var GeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -42,47 +42,42 @@ class ReportController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app(ReportChartGeneratorInterface::class);
|
||||
$this->generator = app(GeneratorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This chart, by default, is shown on the multi-year and year report pages,
|
||||
* which means that giving it a 2 week "period" should be enough granularity.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function netWorth(Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function netWorth(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('netWorth');
|
||||
$cache->addProperty('chart.report.net-worth');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$current = clone $start;
|
||||
$entries = new Collection;
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$current = clone $start;
|
||||
$chartData = [];
|
||||
while ($current < $end) {
|
||||
$balances = Steam::balancesById($ids, $current);
|
||||
$sum = $this->arraySum($balances);
|
||||
$entries->push(
|
||||
[
|
||||
'date' => clone $current,
|
||||
'net-worth' => $sum,
|
||||
]
|
||||
);
|
||||
|
||||
$balances = Steam::balancesById($ids, $current);
|
||||
$sum = $this->arraySum($balances);
|
||||
$label = $current->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$chartData[$label] = $sum;
|
||||
$current->addDays(7);
|
||||
}
|
||||
$data = $this->generator->netWorth($entries);
|
||||
|
||||
$data = $this->generator->singleSet(strval(trans('firefly.net_worth')), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -90,216 +85,141 @@ class ReportController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Shows income and expense, debet/credit: operations
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function operations(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.report.operations');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
|
||||
$source = $this->getChartData($accounts, $start, $end);
|
||||
$chartData = [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'type' => 'bar',
|
||||
'entries' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'type' => 'bar',
|
||||
'entries' => [],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($source['earned'] as $date => $amount) {
|
||||
$carbon = new Carbon($date);
|
||||
$label = $carbon->formatLocalized($format);
|
||||
$earned = $chartData[0]['entries'][$label] ?? '0';
|
||||
$chartData[0]['entries'][$label] = bcadd($earned, $amount);
|
||||
}
|
||||
foreach ($source['spent'] as $date => $amount) {
|
||||
$carbon = new Carbon($date);
|
||||
$label = $carbon->formatLocalized($format);
|
||||
$spent = $chartData[1]['entries'][$label] ?? '0';
|
||||
$chartData[1]['entries'][$label] = bcadd($spent, $amount);
|
||||
}
|
||||
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows sum income and expense, debet/credit: operations
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInOut(Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function sum(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('yearInOut');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$chartSource = $this->getYearData($accounts, $start, $end);
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
// data = method X
|
||||
$data = $this->multiYearInOut($chartSource['earned'], $chartSource['spent'], $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
// data = method Y
|
||||
$data = $this->singleYearInOut($chartSource['earned'], $chartSource['spent'], $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @internal param AccountRepositoryInterface $repository
|
||||
*/
|
||||
public function yearInOutSummarized(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('yearInOutSummarized');
|
||||
$cache->addProperty('chart.report.sum');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$chartSource = $this->getYearData($accounts, $start, $end);
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
// per year
|
||||
$data = $this->multiYearInOutSummarized($chartSource['earned'], $chartSource['spent'], $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
$source = $this->getChartData($accounts, $start, $end);
|
||||
$numbers = [
|
||||
'sum_earned' => '0',
|
||||
'avg_earned' => '0',
|
||||
'count_earned' => 0,
|
||||
'sum_spent' => '0',
|
||||
'avg_spent' => '0',
|
||||
'count_spent' => 0,
|
||||
];
|
||||
foreach ($source['earned'] as $amount) {
|
||||
$numbers['sum_earned'] = bcadd($amount, $numbers['sum_earned']);
|
||||
$numbers['count_earned']++;
|
||||
}
|
||||
// per month!
|
||||
$data = $this->singleYearInOutSummarized($chartSource['earned'], $chartSource['spent'], $start, $end);
|
||||
if ($numbers['count_earned'] > 0) {
|
||||
$numbers['avg_earned'] = $numbers['sum_earned'] / $numbers['count_earned'];
|
||||
}
|
||||
foreach ($source['spent'] as $amount) {
|
||||
$numbers['sum_spent'] = bcadd($amount, $numbers['sum_spent']);
|
||||
$numbers['count_spent']++;
|
||||
}
|
||||
if ($numbers['count_spent'] > 0) {
|
||||
$numbers['avg_spent'] = $numbers['sum_spent'] / $numbers['count_spent'];
|
||||
}
|
||||
|
||||
$chartData = [
|
||||
[
|
||||
'label' => strval(trans('firefly.income')),
|
||||
'type' => 'bar',
|
||||
'entries' => [
|
||||
strval(trans('firefly.sum_of_period')) => $numbers['sum_earned'],
|
||||
strval(trans('firefly.average_in_period')) => $numbers['avg_earned'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'type' => 'bar',
|
||||
'entries' => [
|
||||
strval(trans('firefly.sum_of_period')) => $numbers['sum_spent'],
|
||||
strval(trans('firefly.average_in_period')) => $numbers['avg_spent'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
|
||||
$incomeSum = $this->pluckFromArray($start->year, $earned);
|
||||
$expenseSum = $this->pluckFromArray($start->year, $spent);
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
|
||||
$currentIncome = $this->pluckFromArray($start->year, $earned);
|
||||
$currentExpense = $this->pluckFromArray($start->year, $spent);
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @param array $set
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function pluckFromArray($year, array $set)
|
||||
{
|
||||
$sum = '0';
|
||||
foreach ($set as $date => $amount) {
|
||||
if (substr($date, 0, 4) == $year) {
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
}
|
||||
|
||||
return $sum;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
// per month? simply use each month.
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
// total income and total expenses:
|
||||
$date = $start->format('Y-m');
|
||||
$incomeSum = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$expenseSum = isset($spent[$date]) ? $spent[$date] : 0;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
$date = $start->format('Y-m');
|
||||
$currentIncome = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$currentExpense = isset($spent[$date]) ? $spent[$date] : 0;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function arraySum($array) : string
|
||||
private function arraySum($array): string
|
||||
{
|
||||
$sum = '0';
|
||||
foreach ($array as $entry) {
|
||||
@@ -310,31 +230,45 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the incomes and expenses for the given periods, grouped per month. Will cache its results
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getYearData(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
private function getChartData(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.report.get-chart-data');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
|
||||
$tasker = app(AccountTaskerInterface::class);
|
||||
$currentStart = clone $start;
|
||||
$spentArray = [];
|
||||
$earnedArray = [];
|
||||
while ($currentStart <= $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($currentStart, '1M');
|
||||
$date = $currentStart->format('Y-m');
|
||||
$spent = $tasker->amountOutInPeriod($accounts, $accounts, $currentStart, $currentEnd);
|
||||
$earned = $tasker->amountInInPeriod($accounts, $accounts, $currentStart, $currentEnd);
|
||||
$spentArray[$date] = bcmul($spent, '-1');
|
||||
$earnedArray[$date] = $earned;
|
||||
$currentStart = Navigation::addPeriod($currentStart, '1M', 0);
|
||||
$currentEnd = Navigation::endOfPeriod($currentStart, '1M');
|
||||
$label = $currentStart->format('Y-m') . '-01';
|
||||
$spent = $tasker->amountOutInPeriod($accounts, $accounts, $currentStart, $currentEnd);
|
||||
$earned = $tasker->amountInInPeriod($accounts, $accounts, $currentStart, $currentEnd);
|
||||
$spentArray[$label] = bcmul($spent, '-1');
|
||||
$earnedArray[$label] = $earned;
|
||||
$currentStart = Navigation::addPeriod($currentStart, '1M', 0);
|
||||
}
|
||||
|
||||
return [
|
||||
$result = [
|
||||
'spent' => $spentArray,
|
||||
'earned' => $earnedArray,
|
||||
];
|
||||
$cache->store($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
44
app/Http/Controllers/Controller.php
Executable file → Normal file
44
app/Http/Controllers/Controller.php
Executable file → Normal file
@@ -13,11 +13,17 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Session;
|
||||
use View;
|
||||
use FireflyConfig;
|
||||
|
||||
/**
|
||||
* Class Controller
|
||||
@@ -44,7 +50,10 @@ class Controller extends BaseController
|
||||
View::share('hideCategories', false);
|
||||
View::share('hideBills', false);
|
||||
View::share('hideTags', false);
|
||||
|
||||
$isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
||||
View::share('IS_DEMO_SITE', $isDemoSite);
|
||||
View::share('DEMO_USERNAME', env('DEMO_USERNAME',''));
|
||||
View::share('DEMO_PASSWORD', env('DEMO_PASSWORD',''));
|
||||
|
||||
// translations:
|
||||
|
||||
@@ -60,4 +69,37 @@ class Controller extends BaseController
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isOpeningBalance(TransactionJournal $journal): bool
|
||||
{
|
||||
return TransactionJournal::transactionTypeStr($journal) === TransactionType::OPENING_BALANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
protected function redirectToAccount(TransactionJournal $journal)
|
||||
{
|
||||
$valid = [AccountType::DEFAULT, AccountType::ASSET];
|
||||
$transactions = $journal->transactions;
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$account = $transaction->account;
|
||||
if (in_array($account->accountType->type, $valid)) {
|
||||
return redirect(route('accounts.show', [$account->id]));
|
||||
}
|
||||
|
||||
}
|
||||
Session::flash('error', strval(trans('firefly.cannot_redirect_to_account')));
|
||||
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -60,14 +60,14 @@ class CurrencyController extends Controller
|
||||
$subTitle = trans('firefly.create_currency');
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (session('currency.create.fromStore') !== true) {
|
||||
Session::put('currency.create.url', URL::previous());
|
||||
if (session('currencies.create.fromStore') !== true) {
|
||||
Session::put('currencies.create.url', URL::previous());
|
||||
}
|
||||
Session::forget('currency.create.fromStore');
|
||||
Session::forget('currencies.create.fromStore');
|
||||
Session::flash('gaEventCategory', 'currency');
|
||||
Session::flash('gaEventAction', 'create');
|
||||
|
||||
return view('currency.create', compact('subTitleIcon', 'subTitle'));
|
||||
return view('currencies.create', compact('subTitleIcon', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,54 +85,54 @@ class CurrencyController extends Controller
|
||||
Cache::forget('FFCURRENCYSYMBOL');
|
||||
Cache::forget('FFCURRENCYCODE');
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
return redirect(route('currencies.index'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|View
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
*/
|
||||
public function delete(TransactionCurrency $currency)
|
||||
public function delete(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
if (!$repository->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
|
||||
|
||||
// put previous url in session
|
||||
Session::put('currency.delete.url', URL::previous());
|
||||
Session::put('currencies.delete.url', URL::previous());
|
||||
Session::flash('gaEventCategory', 'currency');
|
||||
Session::flash('gaEventAction', 'delete');
|
||||
$subTitle = trans('form.delete_currency', ['name' => $currency->name]);
|
||||
|
||||
|
||||
return view('currency.delete', compact('currency', 'subTitle'));
|
||||
return view('currencies.delete', compact('currency', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(TransactionCurrency $currency)
|
||||
public function destroy(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
if (!$repository->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
return redirect(route('currencies.index'));
|
||||
}
|
||||
|
||||
$repository->destroy($currency);
|
||||
Session::flash('success', trans('firefly.deleted_currency', ['name' => $currency->name]));
|
||||
if (auth()->user()->hasRole('owner')) {
|
||||
$currency->forceDelete();
|
||||
}
|
||||
|
||||
return redirect(session('currency.delete.url'));
|
||||
return redirect(session('currencies.delete.url'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,14 +147,14 @@ class CurrencyController extends Controller
|
||||
$currency->symbol = htmlentities($currency->symbol);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (session('currency.edit.fromUpdate') !== true) {
|
||||
Session::put('currency.edit.url', URL::previous());
|
||||
if (session('currencies.edit.fromUpdate') !== true) {
|
||||
Session::put('currencies.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('currency.edit.fromUpdate');
|
||||
Session::forget('currencies.edit.fromUpdate');
|
||||
Session::flash('gaEventCategory', 'currency');
|
||||
Session::flash('gaEventAction', 'edit');
|
||||
|
||||
return view('currency.edit', compact('currency', 'subTitle', 'subTitleIcon'));
|
||||
return view('currencies.edit', compact('currency', 'subTitle', 'subTitleIcon'));
|
||||
|
||||
}
|
||||
|
||||
@@ -170,11 +170,11 @@ class CurrencyController extends Controller
|
||||
|
||||
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
Session::flash('warning', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')]));
|
||||
Session::flash('warning', trans('firefly.ask_site_owner', ['site_owner' => env('SITE_OWNER')]));
|
||||
}
|
||||
|
||||
|
||||
return view('currency.index', compact('currencies', 'defaultCurrency'));
|
||||
return view('currencies.index', compact('currencies', 'defaultCurrency'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +189,7 @@ class CurrencyController extends Controller
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.');
|
||||
|
||||
return redirect(session('currency.create.url'));
|
||||
return redirect(session('currencies.create.url'));
|
||||
}
|
||||
|
||||
$data = $request->getCurrencyData();
|
||||
@@ -197,13 +197,13 @@ class CurrencyController extends Controller
|
||||
Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));
|
||||
|
||||
if (intval(Input::get('create_another')) === 1) {
|
||||
Session::put('currency.create.fromStore', true);
|
||||
Session::put('currencies.create.fromStore', true);
|
||||
|
||||
return redirect(route('currency.create'))->withInput();
|
||||
return redirect(route('currencies.create'))->withInput();
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect(session('currency.create.url'));
|
||||
return redirect(session('currencies.create.url'));
|
||||
|
||||
|
||||
}
|
||||
@@ -226,49 +226,13 @@ class CurrencyController extends Controller
|
||||
|
||||
|
||||
if (intval(Input::get('return_to_edit')) === 1) {
|
||||
Session::put('currency.edit.fromUpdate', true);
|
||||
Session::put('currencies.edit.fromUpdate', true);
|
||||
|
||||
return redirect(route('currency.edit', [$currency->id]));
|
||||
return redirect(route('currencies.edit', [$currency->id]));
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect(session('currency.edit.url'));
|
||||
return redirect(session('currencies.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function canDeleteCurrency(TransactionCurrency $currency): bool
|
||||
{
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// has transactions still
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the only currency left
|
||||
if ($repository->get()->count() === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$defaultCode = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
||||
if ($currency->code === $defaultCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the system
|
||||
$defaultSystemCode = config('firefly.default_currency', 'EUR');
|
||||
if ($currency->code === $defaultSystemCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// can be deleted
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,11 +17,12 @@ namespace FireflyIII\Http\Controllers;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Export\Processor;
|
||||
use FireflyIII\Export\ProcessorInterface;
|
||||
use FireflyIII\Http\Requests\ExportFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI;
|
||||
use Preferences;
|
||||
use Response;
|
||||
@@ -56,25 +57,25 @@ class ExportController extends Controller
|
||||
/**
|
||||
* @param ExportJob $job
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function download(ExportJob $job)
|
||||
public function download(ExportJobRepositoryInterface $repository, ExportJob $job)
|
||||
{
|
||||
$disk = Storage::disk('export');
|
||||
$file = $job->key . '.zip';
|
||||
$date = date('Y-m-d \a\t H-i-s');
|
||||
$name = 'Export job on ' . $date . '.zip';
|
||||
$quoted = sprintf('"%s"', addcslashes($name, '"\\'));
|
||||
|
||||
if (!$disk->exists($file)) {
|
||||
if (!$repository->exists($job)) {
|
||||
throw new FireflyException('Against all expectations, zip file "' . $file . '" does not exist.');
|
||||
}
|
||||
$content = $repository->getContent($job);
|
||||
|
||||
|
||||
$job->change('export_downloaded');
|
||||
|
||||
return response($disk->get($file), 200)
|
||||
return response($content, 200)
|
||||
->header('Content-Description', 'File Transfer')
|
||||
->header('Content-Type', 'application/octet-stream')
|
||||
->header('Content-Disposition', 'attachment; filename=' . $quoted)
|
||||
@@ -83,7 +84,7 @@ class ExportController extends Controller
|
||||
->header('Expires', '0')
|
||||
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
||||
->header('Pragma', 'public')
|
||||
->header('Content-Length', $disk->size($file));
|
||||
->header('Content-Length', strlen($content));
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +134,6 @@ class ExportController extends Controller
|
||||
*/
|
||||
public function postIndex(ExportFormRequest $request, AccountRepositoryInterface $repository, EJRI $jobs)
|
||||
{
|
||||
set_time_limit(0);
|
||||
$job = $jobs->findByKey($request->get('job'));
|
||||
$settings = [
|
||||
'accounts' => $repository->getAccountsById($request->get('accounts')),
|
||||
@@ -146,7 +146,9 @@ class ExportController extends Controller
|
||||
];
|
||||
|
||||
$job->change('export_status_make_exporter');
|
||||
$processor = new Processor($settings);
|
||||
|
||||
/** @var ProcessorInterface $processor */
|
||||
$processor = app(ProcessorInterface::class, [$settings]);
|
||||
|
||||
/*
|
||||
* Collect journals:
|
||||
|
@@ -15,10 +15,11 @@ namespace FireflyIII\Http\Controllers;
|
||||
use Artisan;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -62,6 +63,7 @@ class HomeController extends Controller
|
||||
// a possible problem with the budgets.
|
||||
if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
|
||||
$isCustomRange = true;
|
||||
//Preferences::set('viewRange', 'custom');
|
||||
Log::debug('Range is now marked as "custom".');
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ class HomeController extends Controller
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
Session::forget(['start', 'end', 'viewRange', 'range', 'is_custom_range']);
|
||||
|
||||
Session::clear();
|
||||
Artisan::call('cache:clear');
|
||||
@@ -121,7 +123,6 @@ class HomeController extends Controller
|
||||
*/
|
||||
public function index(ARI $repository)
|
||||
{
|
||||
|
||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||
$count = $repository->count($types);
|
||||
|
||||
@@ -142,18 +143,20 @@ class HomeController extends Controller
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$collector = new JournalCollector(auth()->user());
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1);
|
||||
$set = $collector->getJournals();
|
||||
// zero bills? Hide some elements from view.
|
||||
/** @var BillRepositoryInterface $billRepository */
|
||||
$billRepository = app(BillRepositoryInterface::class);
|
||||
$billCount = $billRepository->getBills()->count();
|
||||
|
||||
if (count($set) > 0) {
|
||||
$transactions[] = [$set, $account];
|
||||
}
|
||||
foreach ($accounts as $account) {
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1);
|
||||
$set = $collector->getJournals();
|
||||
$transactions[] = [$set, $account];
|
||||
}
|
||||
|
||||
return view(
|
||||
'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage')
|
||||
'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -164,13 +167,54 @@ class HomeController extends Controller
|
||||
public function routes()
|
||||
{
|
||||
// these routes are not relevant for the help pages:
|
||||
$ignore = ['login', 'registe', 'logout', 'two-fac', 'lost-two', 'confirm', 'resend', 'do_confirm', 'testFla', 'json.', 'piggy-banks.add',
|
||||
'piggy-banks.remove', 'preferences.', 'rules.rule.up', 'rules.rule.down', 'rules.rule-group.up', 'rules.rule-group.down', 'popup.report',
|
||||
'admin.users.domains.block-', 'import.json', 'help.',
|
||||
$ignore = [
|
||||
// login and two-factor routes:
|
||||
'login',
|
||||
'registe',
|
||||
'password.rese',
|
||||
'logout',
|
||||
'two-fac',
|
||||
'lost-two',
|
||||
'confirm',
|
||||
'resend',
|
||||
'do_confirm',
|
||||
// test troutes
|
||||
'test-flash',
|
||||
'all-routes',
|
||||
// json routes
|
||||
'json.',
|
||||
// routes that point to modals or that redirect immediately.
|
||||
'piggy-banks.add',
|
||||
'piggy-banks.remove',
|
||||
'rules.rule.up',
|
||||
'attachments.download',
|
||||
'bills.rescan',
|
||||
'rules.rule.down',
|
||||
'rules.rule-group.up',
|
||||
'rules.rule-group.down',
|
||||
'popup.',
|
||||
'error',
|
||||
'flush',
|
||||
//'preferences.',
|
||||
'admin.users.domains.block-',
|
||||
'help.',
|
||||
// ajax routes:
|
||||
'import.json',
|
||||
// charts:
|
||||
'chart.',
|
||||
// report data:
|
||||
'report-data.',
|
||||
|
||||
// others:
|
||||
'debugbar',
|
||||
'attachments.preview',
|
||||
'budgets.income',
|
||||
'currencies.default',
|
||||
|
||||
|
||||
];
|
||||
$routes = Route::getRoutes();
|
||||
|
||||
echo '<pre>';
|
||||
$return = '<pre>';
|
||||
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
@@ -178,15 +222,13 @@ class HomeController extends Controller
|
||||
$methods = $route->getMethods();
|
||||
|
||||
if (!is_null($name) && strlen($name) > 0 && in_array('GET', $methods) && !$this->startsWithAny($ignore, $name)) {
|
||||
echo sprintf('touch %s.md', $name) . "\n";
|
||||
$return .= sprintf('touch %s.md', $name) . "\n";
|
||||
|
||||
}
|
||||
}
|
||||
echo '</pre>';
|
||||
$return .= '</pre><hr />';
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
return ' ';
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,10 +250,7 @@ class HomeController extends Controller
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private
|
||||
function startsWithAny(
|
||||
array $array, string $needle
|
||||
): bool
|
||||
private function startsWithAny(array $array, string $needle): bool
|
||||
{
|
||||
foreach ($array as $entry) {
|
||||
if ((substr($needle, 0, strlen($entry)) === $entry)) {
|
||||
|
@@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
||||
use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Requests\ImportUploadRequest;
|
||||
use FireflyIII\Import\ImportProcedure;
|
||||
use FireflyIII\Import\ImportProcedureInterface;
|
||||
use FireflyIII\Import\Setup\SetupInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
@@ -145,10 +145,13 @@ class ImportController extends Controller
|
||||
return $this->redirectToCorrectStep($job);
|
||||
}
|
||||
|
||||
// if there is a tag (there might not be), we can link to it:
|
||||
$tagId = $job->extended_status['importTag'] ?? 0;
|
||||
|
||||
$subTitle = trans('firefly.import_finished');
|
||||
$subTitleIcon = 'fa-star';
|
||||
|
||||
return view('import.finished', compact('job', 'subTitle', 'subTitleIcon'));
|
||||
return view('import.finished', compact('job', 'subTitle', 'subTitleIcon', 'tagId'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,13 +315,14 @@ class ImportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param ImportProcedureInterface $importProcedure
|
||||
* @param ImportJob $job
|
||||
*/
|
||||
public function start(ImportJob $job)
|
||||
public function start(ImportProcedureInterface $importProcedure, ImportJob $job)
|
||||
{
|
||||
set_time_limit(0);
|
||||
if ($job->status == 'settings_complete') {
|
||||
ImportProcedure::runImport($job);
|
||||
$importProcedure->runImport($job);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +334,7 @@ class ImportController extends Controller
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
*/
|
||||
public function status(ImportJob $job)
|
||||
{
|
||||
{ //
|
||||
Log::debug('Now in status()', ['job' => $job->key]);
|
||||
if (!$this->jobInCorrectStep($job, 'status')) {
|
||||
return $this->redirectToCorrectStep($job);
|
||||
|
@@ -102,7 +102,6 @@ class JsonController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @internal param ARI $accountRepository
|
||||
*/
|
||||
public function boxIn(AccountTaskerInterface $accountTasker, AccountRepositoryInterface $repository)
|
||||
{
|
||||
|
@@ -78,14 +78,16 @@ class NewUserController extends Controller
|
||||
$this->createAssetAccount($request, $repository);
|
||||
|
||||
// create savings account
|
||||
if (strlen($request->get('savings_balance')) > 0) {
|
||||
$savingBalance = strval($request->get('savings_balance')) === '' ? '0' : strval($request->get('savings_balance'));
|
||||
if (bccomp($savingBalance, '0') !== 0) {
|
||||
$this->createSavingsAccount($request, $repository);
|
||||
$count++;
|
||||
}
|
||||
|
||||
|
||||
// create credit card.
|
||||
if (strlen($request->get('credit_card_limit')) > 0) {
|
||||
$limit = strval($request->get('credit_card_limit')) === '' ? '0' : strval($request->get('credit_card_limit'));
|
||||
if (bccomp($limit, '0') !== 0) {
|
||||
$this->storeCreditCard($request, $repository);
|
||||
$count++;
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use Session;
|
||||
use Steam;
|
||||
use URL;
|
||||
@@ -149,13 +150,18 @@ class PiggyBankController extends Controller
|
||||
*/
|
||||
public function destroy(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
|
||||
|
||||
Session::flash('success', strval(trans('firefly.deleted_piggy_bank', ['name' => e($piggyBank->name)])));
|
||||
Preferences::mark();
|
||||
$piggyBankId = $piggyBank->id;
|
||||
$repository->destroy($piggyBank);
|
||||
|
||||
return redirect(session('piggy-banks.delete.url'));
|
||||
$uri = session('piggy-banks.delete.url');
|
||||
if (!(strpos($uri, sprintf('piggy-banks/show/%s', $piggyBankId)) === false)) {
|
||||
// uri would point back to piggy bank
|
||||
$uri = route('piggy-banks.index');
|
||||
}
|
||||
|
||||
return redirect($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,6 +249,8 @@ class PiggyBankController extends Controller
|
||||
|
||||
/**
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function order(PiggyBankRepositoryInterface $repository)
|
||||
{
|
||||
@@ -257,6 +265,8 @@ class PiggyBankController extends Controller
|
||||
$repository->setOrder(intval($id), ($order + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json(['result' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -46,7 +46,7 @@ class ReportController extends Controller
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function info(Request $request)
|
||||
public function general(Request $request)
|
||||
{
|
||||
$attributes = $request->get('attributes') ?? [];
|
||||
$attributes = $this->parseAttributes($attributes);
|
||||
@@ -133,8 +133,8 @@ class ReportController extends Controller
|
||||
|
||||
$budget->name = strval(trans('firefly.leftUnbalanced'));
|
||||
$journals = $journals->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
$tags = $journal->tags()->where('tagMode', 'balancingAct')->count();
|
||||
function (Transaction $transaction) {
|
||||
$tags = $transaction->transactionJournal->tags()->where('tagMode', 'balancingAct')->count();
|
||||
if ($tags === 0) {
|
||||
return true;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user