mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 14:21:20 +00:00
Compare commits
548 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ddcf1120f | ||
|
|
d45c74915c | ||
|
|
57d6677131 | ||
|
|
05e73344eb | ||
|
|
fff8f96490 | ||
|
|
1ccfb34246 | ||
|
|
b30bd00993 | ||
|
|
6b2d9fe816 | ||
|
|
531114279d | ||
|
|
944aaff0fa | ||
|
|
6bafa6819d | ||
|
|
8d7091285a | ||
|
|
579e95219a | ||
|
|
4a746881e3 | ||
|
|
9122f1b642 | ||
|
|
8b033ed4a8 | ||
|
|
8e53a63243 | ||
|
|
4de01e7387 | ||
|
|
f85ab74e2b | ||
|
|
8bb7d5de3f | ||
|
|
68424e485c | ||
|
|
ac34285eed | ||
|
|
e605a82573 | ||
|
|
1061764426 | ||
|
|
8d93e410f7 | ||
|
|
9336cdcc5d | ||
|
|
7639c03646 | ||
|
|
2da55bff9c | ||
|
|
6ea5d45dec | ||
|
|
e9504a3899 | ||
|
|
7bff2fd1e5 | ||
|
|
694712e933 | ||
|
|
aa675559e6 | ||
|
|
2af19d675a | ||
|
|
4588d16fc2 | ||
|
|
5dbd3031be | ||
|
|
59c16eba77 | ||
|
|
8c21ec96d1 | ||
|
|
2c00a8353d | ||
|
|
19e7a76f85 | ||
|
|
f16a186faf | ||
|
|
456dd39ec4 | ||
|
|
5b69a697e4 | ||
|
|
20d279fee4 | ||
|
|
cd55d819af | ||
|
|
dce51da92f | ||
|
|
6118cf6041 | ||
|
|
4ae8bffd4d | ||
|
|
5ebe86d5b6 | ||
|
|
317d97a310 | ||
|
|
082aa1d8e3 | ||
|
|
2f2963676f | ||
|
|
f2d388f742 | ||
|
|
d79008495a | ||
|
|
43f1867fb8 | ||
|
|
043c28628c | ||
|
|
9540854c8a | ||
|
|
b951a6ca66 | ||
|
|
26561a395d | ||
|
|
0a884c8718 | ||
|
|
b393e3c662 | ||
|
|
c36062210f | ||
|
|
861381fbb6 | ||
|
|
b9019f9590 | ||
|
|
fcfa877e89 | ||
|
|
d61849eefe | ||
|
|
bc83bd6ec8 | ||
|
|
c18c94e565 | ||
|
|
77d077ec08 | ||
|
|
021d0e6359 | ||
|
|
7f4fd2c52f | ||
|
|
8ffe098e3b | ||
|
|
a2ca86ca74 | ||
|
|
deef018806 | ||
|
|
c3f8b2ea56 | ||
|
|
e3696b6055 | ||
|
|
b82b340668 | ||
|
|
a8b01c439b | ||
|
|
6ec686ca7e | ||
|
|
fdb664fecb | ||
|
|
09f838089b | ||
|
|
db0fe918b8 | ||
|
|
8ca696d547 | ||
|
|
b7ccb1ce5c | ||
|
|
5f0033e466 | ||
|
|
477adba3e1 | ||
|
|
eb15ca8ebd | ||
|
|
dbf5907c20 | ||
|
|
e95deb9443 | ||
|
|
e19c36b5c4 | ||
|
|
fdd589db4f | ||
|
|
cd4e45d8f5 | ||
|
|
e6e31b9cab | ||
|
|
b676b1fef9 | ||
|
|
58bfb35fa6 | ||
|
|
09131e8c36 | ||
|
|
1d6ca91c01 | ||
|
|
fa00ba2edd | ||
|
|
65114c8483 | ||
|
|
d033985141 | ||
|
|
5badfbee93 | ||
|
|
44a61842f0 | ||
|
|
70b61af572 | ||
|
|
53a53d393d | ||
|
|
6c95b5757b | ||
|
|
693b3e5a6f | ||
|
|
aac1338bdd | ||
|
|
2979137102 | ||
|
|
0068675f3b | ||
|
|
6c1a22ea7f | ||
|
|
2869b92e6b | ||
|
|
8a38ce1964 | ||
|
|
3a7c5566ed | ||
|
|
1bed8c2b08 | ||
|
|
e24500b306 | ||
|
|
6251914419 | ||
|
|
8d9e943d57 | ||
|
|
f71bc5d323 | ||
|
|
a8082b2b3f | ||
|
|
510b72303d | ||
|
|
4666d4bbaa | ||
|
|
025f1e9502 | ||
|
|
b4c05098a9 | ||
|
|
3c8ee6f7f7 | ||
|
|
8b34135b08 | ||
|
|
d4b7c6689f | ||
|
|
d72aadfb00 | ||
|
|
00ff8ae166 | ||
|
|
cffcf49b26 | ||
|
|
ad55aa8b85 | ||
|
|
accbdea942 | ||
|
|
22144b78ea | ||
|
|
c03ab269f0 | ||
|
|
0c6c4d5959 | ||
|
|
e4e1873770 | ||
|
|
3b3579025d | ||
|
|
5cf8f2f4f4 | ||
|
|
c4ff05b1ba | ||
|
|
2bf54d0b8e | ||
|
|
2a63888546 | ||
|
|
cb8294cbd2 | ||
|
|
c9a99be183 | ||
|
|
5d2e026e5a | ||
|
|
568fdad52a | ||
|
|
174fb65fed | ||
|
|
2e77c45ae8 | ||
|
|
1b674a0abf | ||
|
|
4beb8b1f6b | ||
|
|
3c4abb7b60 | ||
|
|
970c73c221 | ||
|
|
6797c1255f | ||
|
|
0ed159b553 | ||
|
|
faa8679804 | ||
|
|
e3d2253958 | ||
|
|
3f7b7996c0 | ||
|
|
9229ff54df | ||
|
|
204ab8f427 | ||
|
|
8ee6c0789d | ||
|
|
be188e7266 | ||
|
|
1a43b62750 | ||
|
|
eaa8321aa8 | ||
|
|
f01f0071dd | ||
|
|
ec69cc3590 | ||
|
|
102dac1eb8 | ||
|
|
d54c5f1f99 | ||
|
|
c2e0e00c47 | ||
|
|
f24e387363 | ||
|
|
09715b83e4 | ||
|
|
e4f197bbc9 | ||
|
|
de64cef48d | ||
|
|
b85329b371 | ||
|
|
215f9a4245 | ||
|
|
80ce7a64ba | ||
|
|
65f3dc0656 | ||
|
|
f9b6b841b6 | ||
|
|
d4f2d649e8 | ||
|
|
15b057fe68 | ||
|
|
9cb549f4a1 | ||
|
|
4d67578458 | ||
|
|
71faaf1c19 | ||
|
|
0187f29b4b | ||
|
|
9b6ccdd43a | ||
|
|
e82deddefb | ||
|
|
780bec35bb | ||
|
|
27d80fd370 | ||
|
|
952328d55c | ||
|
|
f747f3bd10 | ||
|
|
11c3aca58d | ||
|
|
5ef2067836 | ||
|
|
de9728895e | ||
|
|
19774f32c2 | ||
|
|
e62b979708 | ||
|
|
69eef30ad3 | ||
|
|
71a41bc00d | ||
|
|
dd508dbc49 | ||
|
|
13ad40402a | ||
|
|
98712f288c | ||
|
|
a29a78e199 | ||
|
|
767267c89e | ||
|
|
b3801f65cf | ||
|
|
44a1d6b3d4 | ||
|
|
7a1528d1e4 | ||
|
|
c970a25d58 | ||
|
|
0a78b0b130 | ||
|
|
69f6dc09d3 | ||
|
|
467e708617 | ||
|
|
3a84591e61 | ||
|
|
a527066216 | ||
|
|
ef9823035f | ||
|
|
513ee4c7d9 | ||
|
|
fcc9b3a588 | ||
|
|
71eed45b77 | ||
|
|
6940f00492 | ||
|
|
1c85c20fa9 | ||
|
|
ae30b02405 | ||
|
|
89b7a9d3ac | ||
|
|
dc25fc99b3 | ||
|
|
6e6957a9ab | ||
|
|
0609e7db06 | ||
|
|
f57097b79e | ||
|
|
7e988d97d3 | ||
|
|
2795042c2c | ||
|
|
c3c86545fc | ||
|
|
3fe14a3d56 | ||
|
|
bad5740728 | ||
|
|
c164553ba1 | ||
|
|
e6c72b2995 | ||
|
|
cbcefabbff | ||
|
|
97cfa3f3ae | ||
|
|
803a008821 | ||
|
|
658730928b | ||
|
|
310db374c8 | ||
|
|
dc5bd648cf | ||
|
|
b6be9e6ade | ||
|
|
04f71496e3 | ||
|
|
1eed142423 | ||
|
|
f1e0ad0df0 | ||
|
|
f8fa5f1ba5 | ||
|
|
c187563267 | ||
|
|
fcdbbd5dbc | ||
|
|
6604d04c60 | ||
|
|
63be574a14 | ||
|
|
2414f998ba | ||
|
|
90e2ecad4f | ||
|
|
87a3f5c715 | ||
|
|
a4ef81ebd8 | ||
|
|
67fc810fc2 | ||
|
|
e13a61645d | ||
|
|
aae4a78fd4 | ||
|
|
3947da5e27 | ||
|
|
4e4ce2f77c | ||
|
|
d9a2e081bd | ||
|
|
e60dde7ce5 | ||
|
|
699b138999 | ||
|
|
8f191b497f | ||
|
|
fd013d617c | ||
|
|
a8bda38035 | ||
|
|
411de9aa23 | ||
|
|
f0abe497ef | ||
|
|
9c8be83f5d | ||
|
|
45335af8cf | ||
|
|
945e433bb7 | ||
|
|
70729fdb0c | ||
|
|
4a435e5701 | ||
|
|
427747c6b8 | ||
|
|
be9407cb57 | ||
|
|
c380d3d2a0 | ||
|
|
489b0eb12d | ||
|
|
7c73629962 | ||
|
|
ff619eca1c | ||
|
|
134a39fd71 | ||
|
|
506509b1b2 | ||
|
|
02a36316be | ||
|
|
8549c7c81b | ||
|
|
5a0be7d2ad | ||
|
|
c6f44c6398 | ||
|
|
04a8a0e6a1 | ||
|
|
8a175d147b | ||
|
|
5fbc319b20 | ||
|
|
8e3ba7caf2 | ||
|
|
182aaa7d27 | ||
|
|
ec17d466f7 | ||
|
|
79c2445117 | ||
|
|
aa59db1609 | ||
|
|
814b106be2 | ||
|
|
3901ea0fbe | ||
|
|
65133107be | ||
|
|
08d15cfc5e | ||
|
|
3c89f9a5f1 | ||
|
|
dbc6bc8206 | ||
|
|
dc38291ef5 | ||
|
|
3bb634ed5b | ||
|
|
4bdcfe4d30 | ||
|
|
3b74784486 | ||
|
|
5226664a3d | ||
|
|
6d23823b63 | ||
|
|
da3a56c144 | ||
|
|
58aa54d8cf | ||
|
|
e525e673a8 | ||
|
|
445dbf8779 | ||
|
|
6a27bea2a3 | ||
|
|
13163f9c5c | ||
|
|
fde08f922b | ||
|
|
266ce00872 | ||
|
|
623a70a0d1 | ||
|
|
1d7b738040 | ||
|
|
edc8dd2601 | ||
|
|
31dc932ca4 | ||
|
|
edb355941c | ||
|
|
cddaccb7f7 | ||
|
|
a905cce2c9 | ||
|
|
b9f110ac2b | ||
|
|
7cc24417b3 | ||
|
|
b304284d70 | ||
|
|
c382fb1577 | ||
|
|
77244f4e2c | ||
|
|
8beab5f5bc | ||
|
|
902ae3f0cf | ||
|
|
519ef4e486 | ||
|
|
699e04f371 | ||
|
|
d73de0e60d | ||
|
|
8e0b7d2a73 | ||
|
|
04283cf2d6 | ||
|
|
d60b4aa56f | ||
|
|
9cfeda1b0c | ||
|
|
5e1bd8e1eb | ||
|
|
9b495d212b | ||
|
|
b6fdd0070b | ||
|
|
eea387ad0c | ||
|
|
9cdb0f173a | ||
|
|
51063230d0 | ||
|
|
1111478b7f | ||
|
|
c99c9b441f | ||
|
|
b5065a0276 | ||
|
|
c79a577060 | ||
|
|
091596e80e | ||
|
|
0b4efe4ae1 | ||
|
|
1f9b7faa60 | ||
|
|
762d7bcc34 | ||
|
|
a2145f6b49 | ||
|
|
b48de98865 | ||
|
|
a23179dd83 | ||
|
|
5c18794122 | ||
|
|
f04011f6a7 | ||
|
|
893498238e | ||
|
|
474fa9dea0 | ||
|
|
d8a8574dda | ||
|
|
935fb015d3 | ||
|
|
8bbd3063ec | ||
|
|
92c5cabd70 | ||
|
|
e5db5a7b5c | ||
|
|
28cf123da3 | ||
|
|
5069367873 | ||
|
|
234e656ff6 | ||
|
|
aeadfbdd6a | ||
|
|
39288cfb0b | ||
|
|
5e430968c1 | ||
|
|
154b74ce6f | ||
|
|
2e26303b66 | ||
|
|
51ddcd9ee1 | ||
|
|
9d5d1c0a41 | ||
|
|
6058ccff0d | ||
|
|
a8ec4fe2fd | ||
|
|
65ccb2d443 | ||
|
|
0e929602a8 | ||
|
|
5329e026dc | ||
|
|
a7412e43b3 | ||
|
|
eeae24e058 | ||
|
|
17b6cc43d5 | ||
|
|
b69a2ef0cd | ||
|
|
6d1296094e | ||
|
|
c4039b53e6 | ||
|
|
64831b4c86 | ||
|
|
1dec270907 | ||
|
|
f72f8b03df | ||
|
|
0b47e5d05d | ||
|
|
a487c7b4b2 | ||
|
|
3838b21459 | ||
|
|
7801274d33 | ||
|
|
a505406ee7 | ||
|
|
9487a95c13 | ||
|
|
3b2fe13902 | ||
|
|
db2898dfe5 | ||
|
|
e08fd399d2 | ||
|
|
e45ffba010 | ||
|
|
f7fde93ed2 | ||
|
|
3cf53604a1 | ||
|
|
e041a5e037 | ||
|
|
6c8e10255b | ||
|
|
3464ab1527 | ||
|
|
82e74a2afd | ||
|
|
771ebde295 | ||
|
|
4ce4c3138c | ||
|
|
d37b46effc | ||
|
|
0868aac750 | ||
|
|
4ff5f33966 | ||
|
|
e1aebbe12b | ||
|
|
8273f467b6 | ||
|
|
74664afa68 | ||
|
|
c05f344371 | ||
|
|
ec1507d644 | ||
|
|
8cdc1f0014 | ||
|
|
2b1ab5c6ef | ||
|
|
01fedc0bf8 | ||
|
|
1bd82d71a2 | ||
|
|
1e9dacb6e4 | ||
|
|
94939ea3d3 | ||
|
|
c3ff69d147 | ||
|
|
0fad9d4ac7 | ||
|
|
70cd8ffb72 | ||
|
|
61535bf4b8 | ||
|
|
4adcbf9e48 | ||
|
|
3eba3167fd | ||
|
|
0608fd7732 | ||
|
|
1f41f27e89 | ||
|
|
ded0df9303 | ||
|
|
2a7ba1893a | ||
|
|
6b3b19632a | ||
|
|
98bb0731df | ||
|
|
a102f7044e | ||
|
|
f1028dbaed | ||
|
|
438ce5c3db | ||
|
|
b995a1d091 | ||
|
|
e072f83507 | ||
|
|
79154bba25 | ||
|
|
613eb7522c | ||
|
|
0eb5653713 | ||
|
|
0d624f021b | ||
|
|
b263047f4e | ||
|
|
4410e1bbd7 | ||
|
|
8c3871e8de | ||
|
|
2eafd3cc15 | ||
|
|
368df66947 | ||
|
|
9f9a3ea8fd | ||
|
|
f66286105f | ||
|
|
0f0f912370 | ||
|
|
9fa0e37a5d | ||
|
|
a0cb51ff70 | ||
|
|
a6305ddea4 | ||
|
|
fb8638fe6a | ||
|
|
0009f1f865 | ||
|
|
d449c35025 | ||
|
|
1893d1a2c2 | ||
|
|
0c4539e4fa | ||
|
|
feacddd1d7 | ||
|
|
0c44fe6ce0 | ||
|
|
17fb6983d8 | ||
|
|
5fb73bdb01 | ||
|
|
7f082ea389 | ||
|
|
9856a1831a | ||
|
|
dd17a20b60 | ||
|
|
665a52b106 | ||
|
|
f68d33870b | ||
|
|
49d13b12a5 | ||
|
|
674ab7e41f | ||
|
|
5b3eb3ba82 | ||
|
|
e28d3f3b5a | ||
|
|
870d8b5008 | ||
|
|
6aa240e9a3 | ||
|
|
b55a4047d0 | ||
|
|
a07d87318c | ||
|
|
dd6555c903 | ||
|
|
e8c40b6044 | ||
|
|
91c17a0b2a | ||
|
|
2ed0ea0243 | ||
|
|
df2f92433a | ||
|
|
68b3fc72bf | ||
|
|
df5bb14758 | ||
|
|
e24199bbbe | ||
|
|
2c6099556b | ||
|
|
f98215a5da | ||
|
|
b6b6888493 | ||
|
|
f8e5b9be43 | ||
|
|
692210214f | ||
|
|
cff2546c0c | ||
|
|
f0cc1200f3 | ||
|
|
e83a9af455 | ||
|
|
fb84f9d9cf | ||
|
|
118a2515e1 | ||
|
|
63e891b0f7 | ||
|
|
9891080b57 | ||
|
|
bc7a7e55af | ||
|
|
9b8a029de1 | ||
|
|
11b5575422 | ||
|
|
06336aa580 | ||
|
|
aa8c1d6e9c | ||
|
|
9a4d5d8abf | ||
|
|
3c5631bca3 | ||
|
|
84f85f87b2 | ||
|
|
c35db5976f | ||
|
|
8d1fcf988c | ||
|
|
bbf8f2dd69 | ||
|
|
2f6436e34f | ||
|
|
9cbb03107d | ||
|
|
ee44d7fb2e | ||
|
|
6a0fcd9cf0 | ||
|
|
43cfe3b858 | ||
|
|
dba83c1c03 | ||
|
|
053e139d00 | ||
|
|
04f791a839 | ||
|
|
a4029c9490 | ||
|
|
d471dfec43 | ||
|
|
494bbd46d0 | ||
|
|
1525b9ad06 | ||
|
|
19847ee80b | ||
|
|
fddf1f146c | ||
|
|
5f19cb1c0c | ||
|
|
aaeae992e1 | ||
|
|
a0e7be9d45 | ||
|
|
78faf7e14c | ||
|
|
98f84c2c37 | ||
|
|
278805043e | ||
|
|
dc5215e41e | ||
|
|
7e11691ea4 | ||
|
|
c83dfc44d6 | ||
|
|
68a01b1735 | ||
|
|
0307b58d17 | ||
|
|
9d1508049e | ||
|
|
42322055f9 | ||
|
|
5de8fce156 | ||
|
|
29ff92f833 | ||
|
|
359007c5bf | ||
|
|
bbe40518e4 | ||
|
|
b26f3c0cc6 | ||
|
|
552b4b67a6 | ||
|
|
7fbf359efd | ||
|
|
052b804855 | ||
|
|
67cc611495 | ||
|
|
7e2c24b82e | ||
|
|
4a6bbd4dca | ||
|
|
166bfba5b9 | ||
|
|
87b8ac5f4e | ||
|
|
46b4100291 | ||
|
|
83090ade94 | ||
|
|
44b7a42d5a | ||
|
|
1a5617d430 | ||
|
|
fa818e0924 | ||
|
|
f87b531fe1 | ||
|
|
82fd0c4d37 | ||
|
|
26ceb9e3be | ||
|
|
743458b853 | ||
|
|
920e5f6fbe | ||
|
|
fc0dd22769 | ||
|
|
c7c61ce280 | ||
|
|
5f5a603f71 | ||
|
|
d611858883 | ||
|
|
dbc9ce76a0 | ||
|
|
62386e2e40 |
@@ -3,6 +3,7 @@ APP_DEBUG=true
|
|||||||
APP_FORCE_SSL=false
|
APP_FORCE_SSL=false
|
||||||
APP_FORCE_ROOT=
|
APP_FORCE_ROOT=
|
||||||
APP_KEY=TestTestTestTestTestTestTestTest
|
APP_KEY=TestTestTestTestTestTestTestTest
|
||||||
|
APP_LOG=daily
|
||||||
APP_LOG_LEVEL=debug
|
APP_LOG_LEVEL=debug
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ REDIS_HOST=127.0.0.1
|
|||||||
REDIS_PASSWORD=null
|
REDIS_PASSWORD=null
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
MAIL_DRIVER=smtp
|
MAIL_DRIVER=log
|
||||||
MAIL_HOST=mailtrap.io
|
MAIL_HOST=mailtrap.io
|
||||||
MAIL_PORT=2525
|
MAIL_PORT=2525
|
||||||
MAIL_FROM=changeme@example.com
|
MAIL_FROM=changeme@example.com
|
||||||
|
|||||||
14
.github/CONTRIBUTING.md
vendored
14
.github/CONTRIBUTING.md
vendored
@@ -4,20 +4,12 @@
|
|||||||
|
|
||||||
## Feature requests
|
## Feature requests
|
||||||
|
|
||||||
If you are requesting a new feature, please check out the list of [often requested features](https://firefly-iii.github.io/requested-features/).
|
I am always interested in expanding Firefly III's many features. If you are requesting a new feature, please check out the list of [often requested features](https://firefly-iii.github.io/requested-features/).
|
||||||
|
|
||||||
## Bugs
|
|
||||||
|
|
||||||
If you find a bug, please take the time and see if the [demo site](https://firefly-iii.nder.be/) is also suffering from this bug. Include as many log files and details as you think are necessary.
|
|
||||||
|
|
||||||
## Installation problems
|
|
||||||
|
|
||||||
Take the time to read the [installation guide FAQ](https://firefly-iii.github.io/installation-guide-faq/) and make sure you search through closed issues for the problems other people have had. Your problem may be among them!
|
|
||||||
|
|
||||||
## Pull requests
|
## Pull requests
|
||||||
|
|
||||||
I can only accept pull requests against the `develop` branch, never the `master` branch.
|
When contributing to Firefly III, please first discuss the change you wish to make via issue, email, or any other method. I can only accept pull requests against the `develop` branch, never the `master` branch.
|
||||||
|
|
||||||
## Translations :us: :fr: :de:
|
## Translations :us: :fr: :de:
|
||||||
|
|
||||||
If you see a spelling error, grammatical error or a weird translation in your language, please join [our CrowdIn](https://crowdin.com/project/firefly-iii) project. There, you can submit your translations and fixes. The GitHub repository will download these automatically and they will be included in the next release.
|
If you see a spelling error, grammatical error or a weird translation in your language, please join [our CrowdIn](https://crowdin.com/project/firefly-iii) project. There, you can submit your translations and fixes. The GitHub repository will download these automatically and they will be included in the next release.
|
||||||
|
|||||||
11
.github/SUPPORT.md
vendored
Normal file
11
.github/SUPPORT.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Welcome to Firefly III on Github!
|
||||||
|
|
||||||
|
:+1::tada: Thank you for taking the time to contribute something to Firefly III!
|
||||||
|
|
||||||
|
## Bugs
|
||||||
|
|
||||||
|
First of all: thank you for reporting a bug instead of ditching the tool altogether. If you find a bug, please take the time and see if the [demo site](https://firefly-iii.nder.be/) is also suffering from this bug. Include as many log files and details as you think are necessary. Bugs have a lot of priority!
|
||||||
|
|
||||||
|
## Installation problems
|
||||||
|
|
||||||
|
Please take the time to read the [installation guide FAQ](https://firefly-iii.github.io/installation-guide-faq/) and make sure you search through closed issues for the problems other people have had. Your problem may be among them! If not, open an issue and I will help where I can.
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ Homestead.json
|
|||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
.env
|
.env
|
||||||
public/google*.html
|
public/google*.html
|
||||||
|
report.html
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ install:
|
|||||||
- php artisan optimize
|
- php artisan optimize
|
||||||
- php artisan env
|
- php artisan env
|
||||||
- cp .env.testing .env
|
- cp .env.testing .env
|
||||||
- mv storage/database/databasecopy.sqlite storage/database/database.sqlite
|
- wget -q https://github.com/firefly-iii/test-data/raw/master/storage/database.sqlite -O storage/database/database.sqlite
|
||||||
- mkdir -p build/logs
|
- mkdir -p build/logs
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit -c phpunit.coverage.xml
|
- phpunit -c phpunit.xml
|
||||||
|
|
||||||
after_success:
|
#after_success:
|
||||||
- travis_retry php vendor/bin/coveralls -x storage/build/clover.xml
|
# - travis_retry php vendor/bin/coveralls -x storage/build/clover.xml
|
||||||
|
|
||||||
# safelist
|
# safelist
|
||||||
branches:
|
branches:
|
||||||
|
|||||||
99
CHANGELOG.md
99
CHANGELOG.md
@@ -2,6 +2,105 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [4.6.3.1] - 2017-07-23
|
||||||
|
### Fixed
|
||||||
|
- Hotfix to close issue #715
|
||||||
|
|
||||||
|
|
||||||
|
## [4.6.3] - 2017-07-23
|
||||||
|
|
||||||
|
This will be the last release to support PHP 7.0.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- New guidelines and new introduction tour to aid new users.
|
||||||
|
- Rules can now be applied at will to transactions, not just rule groups.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Improved category overview.
|
||||||
|
- Improved budget overview.
|
||||||
|
- Improved budget report.
|
||||||
|
- Improved command line import responsiveness and speed.
|
||||||
|
- All code comparisons are now strict.
|
||||||
|
- Improve search page.
|
||||||
|
- Charts are easier to read thanks to @simonsmiley
|
||||||
|
- Fixed #708.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed bug where import would not respect default account. #694
|
||||||
|
- Fixed various broken paths
|
||||||
|
- Fixed several import inconsistencies.
|
||||||
|
- Various bug fixes.
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Initial release.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [4.6.2] - 2017-07-08
|
||||||
|
### Added
|
||||||
|
- Links added to boxes, idea by @simonsmiley
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Various bugs in import routine
|
||||||
|
|
||||||
|
## [4.6.1] - 2017-07-02
|
||||||
|
### Fixed
|
||||||
|
- Fixed several small issues all around.
|
||||||
|
|
||||||
|
## [4.6.0] - 2017-06-28
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Revamped import routine. Will be buggy.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Issue #667, postgresql reported by @skibbipl.
|
||||||
|
- Issue #680 by @Xeli
|
||||||
|
- Fixed #660
|
||||||
|
- Fixes #672, reported by @dzaikos
|
||||||
|
- Translation error fixed by
|
||||||
|
- Fix a bug where the balance routine forgot to account for accounts without a currency preference.
|
||||||
|
- Various other bugfixes.
|
||||||
|
|
||||||
|
## [4.5.0] - 2017-06-07
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Better support for multi-currency transactions and display of transactions, accounts and everything. This requires a database overhaul (moving the currency information to specific transactions) so be careful when upgrading.
|
||||||
|
- Translations for Spanish and Slovenian.
|
||||||
|
- New interface for budget page, ~~stolen from~~ inspired by YNAB.
|
||||||
|
- Expanded Docker to work with postgresql as well, thanks to @kressh
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- PostgreSQL support in database upgrade routine (#644, reported by @skibbipl)
|
||||||
|
- Frontpage budget chart was off, fix by @nhaarman
|
||||||
|
- Was not possible to remove opening balance.
|
||||||
|
|
||||||
|
## [4.4.3] - 2017-05-03
|
||||||
|
### Added
|
||||||
|
- Added support for Slovenian
|
||||||
|
- Removed support for Spanish. No translations whatsoever by the guy who requested it.
|
||||||
|
- Removed support for Russian. Same thing.
|
||||||
|
- Removed support for Croatian. Same thing.
|
||||||
|
- Removed support for Chinese Traditional, Hong Kong. Same thing.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- The journal collector, an internal piece of code to collect transactions, now uses a slightly different method of collecting journals. This may cause problems.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Issue #638 as reported by [worldworm](https://github.com/worldworm).
|
||||||
|
- Possible fix for #624
|
||||||
|
|
||||||
|
## [4.4.2] - 2017-04-27
|
||||||
|
### Fixed
|
||||||
|
- Fixed a bug where the opening balance could not be stored.
|
||||||
|
|
||||||
|
## [4.4.1] - 2017-04-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Support for deployment on Heroku
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Bug in new-user routine.
|
||||||
|
|
||||||
## [4.4.0] - 2017-04-23
|
## [4.4.0] - 2017-04-23
|
||||||
### Added
|
### Added
|
||||||
- Firefly III can now handle foreign currencies better, including some code to get the exchange rate live from the web.
|
- Firefly III can now handle foreign currencies better, including some code to get the exchange rate live from the web.
|
||||||
|
|||||||
46
CODE_OF_CONDUCT.md
Normal file
46
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at thegrumpydictator@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||||
|
|
||||||
|
[homepage]: http://contributor-covenant.org
|
||||||
|
[version]: http://contributor-covenant.org/version/1/4/
|
||||||
@@ -11,13 +11,14 @@ RUN apt-get update -y && \
|
|||||||
libtidy-dev \
|
libtidy-dev \
|
||||||
libxml2-dev \
|
libxml2-dev \
|
||||||
libsqlite3-dev \
|
libsqlite3-dev \
|
||||||
|
libpq-dev \
|
||||||
libbz2-dev \
|
libbz2-dev \
|
||||||
gettext-base \
|
gettext-base \
|
||||||
locales && \
|
locales && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN docker-php-ext-install -j$(nproc) curl gd intl json mcrypt readline tidy zip bcmath xml mbstring pdo_sqlite pdo_mysql bz2
|
RUN docker-php-ext-install -j$(nproc) curl gd intl json mcrypt readline tidy zip bcmath xml mbstring pdo_sqlite pdo_mysql bz2 pdo_pgsql
|
||||||
|
|
||||||
# Generate locales supported by firefly
|
# Generate locales supported by firefly
|
||||||
RUN echo "en_US.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
|
RUN echo "en_US.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
|
||||||
|
|||||||
1
Procfile
Normal file
1
Procfile
Normal file
@@ -0,0 +1 @@
|
|||||||
|
web: vendor/bin/heroku-php-nginx -C nginx_app.conf public/
|
||||||
27
README.md
27
README.md
@@ -10,9 +10,11 @@
|
|||||||
|
|
||||||
## Try it out!
|
## Try it out!
|
||||||
|
|
||||||
Try out Firefly III on the [demo site](https://firefly-iii.nder.be/).
|
[](https://heroku.com/deploy?template=https://github.com/firefly-iii/firefly-iii/tree/master)
|
||||||
|
|
||||||
## Installation
|
Firefly III can be run on Heroku. Register for a free Heroku account and instantly run Firefly III on your very own cloud instance. There is also a [demo site](https://firefly-iii.nder.be) with an example financial administration already present.
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
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/using-installing.html).
|
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/using-installing.html).
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ Personal financial management is pretty difficult, and everybody has their own a
|
|||||||
|
|
||||||
Firefly works on the principle that if you know where you're money is going, you can stop it from going there.
|
Firefly works on the principle that if you know where you're money is going, you can stop it from going there.
|
||||||
|
|
||||||
#### Some advantages of using Firefly
|
### Some advantages of using Firefly
|
||||||
|
|
||||||
- Firefly can import any CSV file, so migrating from other systems is easy.
|
- Firefly can import any CSV file, so migrating from other systems is easy.
|
||||||
- Firefly runs on your own server, so you are fully in control of your data. Remember, there is no such thing as "the cloud", it’s just somebody else’s computer!
|
- Firefly runs on your own server, so you are fully in control of your data. Remember, there is no such thing as "the cloud", it’s just somebody else’s computer!
|
||||||
@@ -31,6 +33,25 @@ 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/).
|
Firefly is pretty awesome. [You can read more about Firefly III, and its features, on the Github Pages](https://firefly-iii.github.io/).
|
||||||
|
|
||||||
|
### Contributing
|
||||||
|
|
||||||
|
Please read [CONTRIBUTING.md](https://github.com/firefly-iii/firefly-iii/blob/master/.github/CONTRIBUTING.md) for details on contributing, and the process for submitting pull requests. Please check out the [code of conduct](https://github.com/firefly-iii/firefly-iii/blob/master/CODE_OF_CONDUCT.md) as well.
|
||||||
|
|
||||||
|
### Versioning
|
||||||
|
|
||||||
|
We use [SemVer](http://semver.org/) for versioning. For the versions available, see [the tags](https://github.com/firefly-iii/firefly-iii/tags) on this repository.
|
||||||
|
|
||||||
|
### Authors
|
||||||
|
|
||||||
|
* James Cole
|
||||||
|
* Over time, [many people have contributed to Firefly III](https://github.com/firefly-iii/firefly-iii/graphs/contributors).
|
||||||
|
|
||||||
|
### License
|
||||||
|
|
||||||
|
This work [is licensed](https://github.com/firefly-iii/firefly-iii/blob/master/LICENSE) under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).
|
||||||
|
|
||||||
|
### Other stuff
|
||||||
|
|
||||||
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 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).
|
If you want to contact me, please open an issue or [email me](mailto:thegrumpydictator@gmail.com).
|
||||||
|
|||||||
59
app.json
Normal file
59
app.json
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"name": "Firefly III",
|
||||||
|
"description": "A free and open source personal finances manager",
|
||||||
|
"repository": "https://github.com/firefly-iii/firefly-iii",
|
||||||
|
"logo": "https://raw.githubusercontent.com/firefly-iii/firefly-iii/master/public/mstile-150x150.png",
|
||||||
|
"keywords": [
|
||||||
|
"finance",
|
||||||
|
"finances",
|
||||||
|
"manager",
|
||||||
|
"management",
|
||||||
|
"euro",
|
||||||
|
"dollar",
|
||||||
|
"laravel",
|
||||||
|
"money",
|
||||||
|
"currency",
|
||||||
|
"financials",
|
||||||
|
"financial",
|
||||||
|
"budgets",
|
||||||
|
"administration",
|
||||||
|
"tool",
|
||||||
|
"tooling",
|
||||||
|
"help",
|
||||||
|
"helper",
|
||||||
|
"assistant",
|
||||||
|
"planning",
|
||||||
|
"organizing",
|
||||||
|
"bills",
|
||||||
|
"personal finance",
|
||||||
|
"budgets",
|
||||||
|
"budgeting",
|
||||||
|
"budgeting tool",
|
||||||
|
"budgeting application",
|
||||||
|
"transactions",
|
||||||
|
"self hosted",
|
||||||
|
"self-hosted",
|
||||||
|
"transfers",
|
||||||
|
"management"
|
||||||
|
],
|
||||||
|
"website": "https://firefly-iii.github.io/",
|
||||||
|
"addons": [
|
||||||
|
{
|
||||||
|
"plan": "heroku-postgresql"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"postdeploy": "export APP_KEY=$(php artisan --no-ansi key:generate --show)"
|
||||||
|
},
|
||||||
|
"buildpacks": [
|
||||||
|
{
|
||||||
|
"url": "heroku/php"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"APP_KEY": {
|
||||||
|
"description": "This key is used to encrypt your data.",
|
||||||
|
"value": "base64:If1gJN4pyycXTq+WS5TjneDympKuu+8SKvTl6RZnhJg="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,10 +14,14 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Console\Commands;
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
use Artisan;
|
use Artisan;
|
||||||
|
use FireflyIII\Import\Logging\CommandHandler;
|
||||||
|
use FireflyIII\Import\Routine\ImportRoutine;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\MessageBag;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Monolog\Formatter\LineFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateImport
|
* Class CreateImport
|
||||||
@@ -51,6 +55,7 @@ class CreateImport extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five exactly.
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
@@ -73,30 +78,55 @@ class CreateImport extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info(sprintf('Going to create a job to import file: %s', $file));
|
$this->line(sprintf('Going to create a job to import file: %s', $file));
|
||||||
$this->info(sprintf('Using configuration file: %s', $configuration));
|
$this->line(sprintf('Using configuration file: %s', $configuration));
|
||||||
$this->info(sprintf('Import into user: #%d (%s)', $user->id, $user->email));
|
$this->line(sprintf('Import into user: #%d (%s)', $user->id, $user->email));
|
||||||
$this->info(sprintf('Type of import: %s', $type));
|
$this->line(sprintf('Type of import: %s', $type));
|
||||||
|
|
||||||
|
|
||||||
/** @var ImportJobRepositoryInterface $jobRepository */
|
/** @var ImportJobRepositoryInterface $jobRepository */
|
||||||
$jobRepository = app(ImportJobRepositoryInterface::class);
|
$jobRepository = app(ImportJobRepositoryInterface::class);
|
||||||
$jobRepository->setUser($user);
|
$jobRepository->setUser($user);
|
||||||
$job = $jobRepository->create($type);
|
$job = $jobRepository->create($type);
|
||||||
$this->line(sprintf('Created job "%s"...', $job->key));
|
$this->line(sprintf('Created job "%s"', $job->key));
|
||||||
|
|
||||||
|
|
||||||
Artisan::call('firefly:encrypt-file', ['file' => $file, 'key' => $job->key]);
|
Artisan::call('firefly:encrypt-file', ['file' => $file, 'key' => $job->key]);
|
||||||
$this->line('Stored import data...');
|
$this->line('Stored import data...');
|
||||||
|
|
||||||
|
|
||||||
$job->configuration = $configurationData;
|
$job->configuration = $configurationData;
|
||||||
$job->status = 'settings_complete';
|
$job->status = 'configured';
|
||||||
$job->save();
|
$job->save();
|
||||||
$this->line('Stored configuration...');
|
$this->line('Stored configuration...');
|
||||||
|
|
||||||
|
|
||||||
if ($this->option('start') === true) {
|
if ($this->option('start') === true) {
|
||||||
$this->line('The import will start in a moment. This process is not visible...');
|
$this->line('The import will start in a moment. This process is not visible...');
|
||||||
Log::debug('Go for import!');
|
Log::debug('Go for import!');
|
||||||
Artisan::call('firefly:start-import', ['key' => $job->key]);
|
|
||||||
$this->line('Done!');
|
// normally would refer to other firefly:start-import but that doesn't seem to work all to well...
|
||||||
|
$monolog = Log::getMonolog();
|
||||||
|
$handler = new CommandHandler($this);
|
||||||
|
$formatter = new LineFormatter(null, null, false, true);
|
||||||
|
$handler->setFormatter($formatter);
|
||||||
|
$monolog->pushHandler($handler);
|
||||||
|
|
||||||
|
|
||||||
|
// start the actual routine:
|
||||||
|
/** @var ImportRoutine $routine */
|
||||||
|
$routine = app(ImportRoutine::class);
|
||||||
|
$routine->setJob($job);
|
||||||
|
$routine->run();
|
||||||
|
|
||||||
|
// give feedback.
|
||||||
|
/** @var MessageBag $error */
|
||||||
|
foreach ($routine->errors as $index => $error) {
|
||||||
|
$this->error(sprintf('Error importing line #%d: %s', $index, $error));
|
||||||
|
}
|
||||||
|
$this->line(
|
||||||
|
sprintf('The import has finished. %d transactions have been imported out of %d records.', $routine->journals->count(), $routine->lines)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Console\Commands;
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
use FireflyIII\Import\ImportProcedure;
|
|
||||||
use FireflyIII\Import\Logging\CommandHandler;
|
use FireflyIII\Import\Logging\CommandHandler;
|
||||||
|
use FireflyIII\Import\Routine\ImportRoutine;
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\MessageBag;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,15 +74,18 @@ class Import extends Command
|
|||||||
$monolog = Log::getMonolog();
|
$monolog = Log::getMonolog();
|
||||||
$handler = new CommandHandler($this);
|
$handler = new CommandHandler($this);
|
||||||
$monolog->pushHandler($handler);
|
$monolog->pushHandler($handler);
|
||||||
$importProcedure = new ImportProcedure;
|
|
||||||
$result = $importProcedure->runImport($job);
|
|
||||||
|
|
||||||
// display result to user:
|
/** @var ImportRoutine $routine */
|
||||||
$this->presentResults($result);
|
$routine = app(ImportRoutine::class);
|
||||||
$this->line('The import has completed.');
|
$routine->setJob($job);
|
||||||
|
$routine->run();
|
||||||
|
|
||||||
// get any errors from the importer:
|
/** @var MessageBag $error */
|
||||||
$this->presentErrors($job);
|
foreach ($routine->errors as $index => $error) {
|
||||||
|
$this->error(sprintf('Error importing line #%d: %s', $index, $error));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->line(sprintf('The import has finished. %d transactions have been imported out of %d records.', $routine->journals->count(), $routine->lines));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,12 +98,14 @@ class Import extends Command
|
|||||||
private function isValid(ImportJob $job): bool
|
private function isValid(ImportJob $job): bool
|
||||||
{
|
{
|
||||||
if (is_null($job)) {
|
if (is_null($job)) {
|
||||||
|
Log::error('This job does not seem to exist.');
|
||||||
$this->error('This job does not seem to exist.');
|
$this->error('This job does not seem to exist.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($job->status != 'settings_complete') {
|
if ($job->status !== 'configured') {
|
||||||
|
Log::error(sprintf('This job is not ready to be imported (status is %s).', $job->status));
|
||||||
$this->error('This job is not ready to be imported.');
|
$this->error('This job is not ready to be imported.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -109,36 +113,4 @@ class Import extends Command
|
|||||||
|
|
||||||
return true;
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,11 @@ use Illuminate\Database\QueryException;
|
|||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Schema;
|
use Schema;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UpgradeDatabase
|
* Class UpgradeDatabase
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // it just touches a lot of things.
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Console\Commands
|
* @package FireflyIII\Console\Commands
|
||||||
*/
|
*/
|
||||||
@@ -72,11 +74,59 @@ class UpgradeDatabase extends Command
|
|||||||
$this->repairPiggyBanks();
|
$this->repairPiggyBanks();
|
||||||
$this->updateAccountCurrencies();
|
$this->updateAccountCurrencies();
|
||||||
$this->updateJournalCurrencies();
|
$this->updateJournalCurrencies();
|
||||||
|
$this->currencyInfoToTransactions();
|
||||||
|
$this->verifyCurrencyInfo();
|
||||||
$this->info('Firefly III database is up to date.');
|
$this->info('Firefly III database is up to date.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the currency id info to the transaction instead of the journal.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // cannot be helped.
|
||||||
|
*/
|
||||||
|
private function currencyInfoToTransactions()
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
$set = TransactionJournal::with('transactions')->get();
|
||||||
|
/** @var TransactionJournal $journal */
|
||||||
|
foreach ($set as $journal) {
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
if (is_null($transaction->transaction_currency_id)) {
|
||||||
|
$transaction->transaction_currency_id = $journal->transaction_currency_id;
|
||||||
|
$transaction->save();
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read and use the foreign amounts when present.
|
||||||
|
if ($journal->hasMeta('foreign_amount')) {
|
||||||
|
$amount = Steam::positive($journal->getMeta('foreign_amount'));
|
||||||
|
|
||||||
|
// update both transactions:
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
$transaction->foreign_amount = $amount;
|
||||||
|
if (bccomp($transaction->amount, '0') === -1) {
|
||||||
|
// update with negative amount:
|
||||||
|
$transaction->foreign_amount = bcmul($amount, '-1');
|
||||||
|
}
|
||||||
|
// set foreign currency id:
|
||||||
|
$transaction->foreign_currency_id = intval($journal->getMeta('foreign_currency_id'));
|
||||||
|
$transaction->save();
|
||||||
|
}
|
||||||
|
$journal->deleteMeta('foreign_amount');
|
||||||
|
$journal->deleteMeta('foreign_currency_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->line(sprintf('Updated currency information for %d transactions', $count));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate budget repetitions to new format.
|
* Migrate budget repetitions to new format.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 5.
|
||||||
*/
|
*/
|
||||||
private function migrateRepetitions()
|
private function migrateRepetitions()
|
||||||
{
|
{
|
||||||
@@ -104,6 +154,8 @@ class UpgradeDatabase extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure there are only transfers linked to piggy bank events.
|
* Make sure there are only transfers linked to piggy bank events.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // cannot be helped.
|
||||||
*/
|
*/
|
||||||
private function repairPiggyBanks()
|
private function repairPiggyBanks()
|
||||||
{
|
{
|
||||||
@@ -111,6 +163,7 @@ class UpgradeDatabase extends Command
|
|||||||
if (!Schema::hasTable('piggy_bank_events')) {
|
if (!Schema::hasTable('piggy_bank_events')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
||||||
/** @var PiggyBankEvent $event */
|
/** @var PiggyBankEvent $event */
|
||||||
foreach ($set as $event) {
|
foreach ($set as $event) {
|
||||||
@@ -162,7 +215,7 @@ class UpgradeDatabase extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Make sure all accounts have proper currency info.
|
||||||
*/
|
*/
|
||||||
private function updateAccountCurrencies()
|
private function updateAccountCurrencies()
|
||||||
{
|
{
|
||||||
@@ -172,42 +225,38 @@ class UpgradeDatabase extends Command
|
|||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
// get users preference, fall back to system pref.
|
// get users preference, fall back to system pref.
|
||||||
$defaultCurrencyCode = Preferences::getForUser($account->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
$defaultCurrencyCode = Preferences::getForUser($account->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
|
||||||
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
||||||
$accountCurrency = intval($account->getMeta('currency_id'));
|
$accountCurrency = intval($account->getMeta('currency_id'));
|
||||||
$openingBalance = $account->getOpeningBalance();
|
$openingBalance = $account->getOpeningBalance();
|
||||||
$openingBalanceCurrency = intval($openingBalance->transaction_currency_id);
|
$obCurrency = intval($openingBalance->transaction_currency_id);
|
||||||
|
|
||||||
// both 0? set to default currency:
|
// both 0? set to default currency:
|
||||||
if ($accountCurrency === 0 && $openingBalanceCurrency === 0) {
|
if ($accountCurrency === 0 && $obCurrency === 0) {
|
||||||
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $defaultCurrency->id]);
|
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $defaultCurrency->id]);
|
||||||
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
|
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// opening balance 0, account not zero? just continue:
|
|
||||||
if ($accountCurrency > 0 && $openingBalanceCurrency === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// account is set to 0, opening balance is not?
|
// account is set to 0, opening balance is not?
|
||||||
if ($accountCurrency === 0 && $openingBalanceCurrency > 0) {
|
if ($accountCurrency === 0 && $obCurrency > 0) {
|
||||||
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $openingBalanceCurrency]);
|
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $obCurrency]);
|
||||||
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
|
$this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $defaultCurrencyCode));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// both are equal, just continue:
|
|
||||||
if ($accountCurrency === $openingBalanceCurrency) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// do not match:
|
// do not match:
|
||||||
if ($accountCurrency !== $openingBalanceCurrency) {
|
if ($accountCurrency !== $obCurrency) {
|
||||||
// update opening balance:
|
// update opening balance:
|
||||||
$openingBalance->transaction_currency_id = $accountCurrency;
|
$openingBalance->transaction_currency_id = $accountCurrency;
|
||||||
$openingBalance->save();
|
$openingBalance->save();
|
||||||
$this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name));
|
$this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// opening balance 0, account not zero? just continue:
|
||||||
|
// both are equal, just continue:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -269,9 +318,11 @@ class UpgradeDatabase extends Command
|
|||||||
$repository = app(CurrencyRepositoryInterface::class);
|
$repository = app(CurrencyRepositoryInterface::class);
|
||||||
$notification = '%s #%d uses %s but should use %s. It has been updated. Please verify this in Firefly III.';
|
$notification = '%s #%d uses %s but should use %s. It has been updated. Please verify this in Firefly III.';
|
||||||
$transfer = 'Transfer #%d has been updated to use the correct currencies. Please verify this in Firefly III.';
|
$transfer = 'Transfer #%d has been updated to use the correct currencies. Please verify this in Firefly III.';
|
||||||
|
$driver = DB::connection()->getDriverName();
|
||||||
|
$pgsql = ['pgsql', 'postgresql'];
|
||||||
|
|
||||||
foreach ($types as $type => $operator) {
|
foreach ($types as $type => $operator) {
|
||||||
$set = TransactionJournal
|
$query = TransactionJournal
|
||||||
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->leftJoin(
|
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->leftJoin(
|
||||||
'transactions', function (JoinClause $join) use ($operator) {
|
'transactions', function (JoinClause $join) use ($operator) {
|
||||||
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', $operator, '0');
|
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', $operator, '0');
|
||||||
@@ -280,9 +331,15 @@ class UpgradeDatabase extends Command
|
|||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||||
->where('transaction_types.type', $type)
|
->where('transaction_types.type', $type)
|
||||||
->where('account_meta.name', 'currency_id')
|
->where('account_meta.name', 'currency_id');
|
||||||
->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data'))
|
if (in_array($driver, $pgsql)) {
|
||||||
->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']);
|
$query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('cast(account_meta.data as int)'));
|
||||||
|
}
|
||||||
|
if (!in_array($driver, $pgsql)) {
|
||||||
|
$query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$set = $query->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']);
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($set as $journal) {
|
foreach ($set as $journal) {
|
||||||
$expectedCurrency = $repository->find(intval($journal->expected_currency_id));
|
$expectedCurrency = $repository->find(intval($journal->expected_currency_id));
|
||||||
@@ -334,4 +391,25 @@ class UpgradeDatabase extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function verifyCurrencyInfo()
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
$transactions = Transaction::get();
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$currencyId = intval($transaction->transaction_currency_id);
|
||||||
|
$foreignId = intval($transaction->foreign_currency_id);
|
||||||
|
if ($currencyId === $foreignId) {
|
||||||
|
$transaction->foreign_currency_id = null;
|
||||||
|
$transaction->foreign_amount = null;
|
||||||
|
$transaction->save();
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->line(sprintf('Updated currency information for %d transactions', $count));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ class UpgradeFireflyInstructions extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->argument('task') == 'update') {
|
if ($this->argument('task') === 'update') {
|
||||||
$this->updateInstructions();
|
$this->updateInstructions();
|
||||||
}
|
}
|
||||||
if ($this->argument('task') == 'install') {
|
if ($this->argument('task') === 'install') {
|
||||||
$this->installInstructions();
|
$this->installInstructions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ class VerifyDatabase extends Command
|
|||||||
{
|
{
|
||||||
$plural = str_plural($name);
|
$plural = str_plural($name);
|
||||||
$class = sprintf('FireflyIII\Models\%s', ucfirst($name));
|
$class = sprintf('FireflyIII\Models\%s', ucfirst($name));
|
||||||
$field = $name == 'tag' ? 'tag' : 'name';
|
$field = $name === 'tag' ? 'tag' : 'name';
|
||||||
$set = $class::leftJoin($name . '_transaction_journal', $plural . '.id', '=', $name . '_transaction_journal.' . $name . '_id')
|
$set = $class::leftJoin($name . '_transaction_journal', $plural . '.id', '=', $name . '_transaction_journal.' . $name . '_id')
|
||||||
->leftJoin('users', $plural . '.user_id', '=', 'users.id')
|
->leftJoin('users', $plural . '.user_id', '=', 'users.id')
|
||||||
->distinct()
|
->distinct()
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ class StoredTransactionJournal extends Event
|
|||||||
|
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var TransactionJournal */
|
||||||
public $journal;
|
public $journal;
|
||||||
|
/** @var int */
|
||||||
public $piggyBankId;
|
public $piggyBankId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class UpdatedTransactionJournal extends Event
|
|||||||
|
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var TransactionJournal */
|
||||||
public $journal;
|
public $journal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||||
->leftJoin('accounts AS opposing_accounts', 'opposing.account_id', '=', 'opposing_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_types', 'transaction_journals.transaction_type_id', 'transaction_types.id')
|
||||||
->leftJoin('transaction_currencies', 'transaction_journals.transaction_currency_id', '=', 'transaction_currencies.id')
|
->leftJoin('transaction_currencies', 'transactions.transaction_currency_id', '=', 'transaction_currencies.id')
|
||||||
->whereIn('transactions.account_id', $accountIds)
|
->whereIn('transactions.account_id', $accountIds)
|
||||||
->where('transaction_journals.user_id', $this->job->user_id)
|
->where('transaction_journals.user_id', $this->job->user_id)
|
||||||
->where('transaction_journals.date', '>=', $this->start->format('Y-m-d'))
|
->where('transaction_journals.date', '>=', $this->start->format('Y-m-d'))
|
||||||
@@ -338,7 +338,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
'transaction_journals.encrypted as journal_encrypted',
|
'transaction_journals.encrypted as journal_encrypted',
|
||||||
'transaction_journals.transaction_type_id',
|
'transaction_journals.transaction_type_id',
|
||||||
'transaction_types.type as transaction_type',
|
'transaction_types.type as transaction_type',
|
||||||
'transaction_journals.transaction_currency_id',
|
'transactions.transaction_currency_id',
|
||||||
'transaction_currencies.code AS transaction_currency_code',
|
'transaction_currencies.code AS transaction_currency_code',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ final class Entry
|
|||||||
$entry->budget_name = $object->budget_name ?? '';
|
$entry->budget_name = $object->budget_name ?? '';
|
||||||
|
|
||||||
// update description when transaction description is different:
|
// update description when transaction description is different:
|
||||||
if (!is_null($object->description) && $object->description != $entry->description) {
|
if (!is_null($object->description) && $object->description !== $entry->description) {
|
||||||
$entry->description = $entry->description . ' (' . $object->description . ')';
|
$entry->description = $entry->description . ' (' . $object->description . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,9 +110,16 @@ class ChartJsGenerator implements GeneratorInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
// sort by value, keep keys.
|
// sort by value, keep keys.
|
||||||
|
// different sort when values are positive and when they're negative.
|
||||||
asort($data);
|
asort($data);
|
||||||
|
$next = next($data);
|
||||||
|
if (!is_bool($next) && bccomp($next, '0') === 1) {
|
||||||
|
// next is positive, sort other way around.
|
||||||
|
arsort($data);
|
||||||
|
}
|
||||||
|
unset($next);
|
||||||
|
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
|
|
||||||
// make larger than 0
|
// make larger than 0
|
||||||
|
|||||||
@@ -22,10 +22,15 @@ interface GeneratorInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
|
* Will generate a Chart JS compatible array from the given input. Expects this format
|
||||||
|
*
|
||||||
|
* Will take labels for all from first set.
|
||||||
*
|
*
|
||||||
* 0: [
|
* 0: [
|
||||||
* 'label' => 'label of set',
|
* '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' =>
|
* 'entries' =>
|
||||||
* [
|
* [
|
||||||
* 'label-of-entry' => 'value'
|
* 'label-of-entry' => 'value'
|
||||||
@@ -33,12 +38,16 @@ interface GeneratorInterface
|
|||||||
* ]
|
* ]
|
||||||
* 1: [
|
* 1: [
|
||||||
* 'label' => 'label of another set',
|
* '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' =>
|
* 'entries' =>
|
||||||
* [
|
* [
|
||||||
* 'label-of-entry' => 'value'
|
* 'label-of-entry' => 'value'
|
||||||
* ]
|
* ]
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
|||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Steam;
|
use Steam;
|
||||||
|
|
||||||
@@ -147,6 +148,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
*/
|
*/
|
||||||
private function getAuditReport(Account $account, Carbon $date): array
|
private function getAuditReport(Account $account, Carbon $date): array
|
||||||
{
|
{
|
||||||
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
@@ -155,15 +158,21 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
$journals = $journals->reverse();
|
$journals = $journals->reverse();
|
||||||
$dayBeforeBalance = Steam::balance($account, $date);
|
$dayBeforeBalance = Steam::balance($account, $date);
|
||||||
$startBalance = $dayBeforeBalance;
|
$startBalance = $dayBeforeBalance;
|
||||||
|
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
|
||||||
|
|
||||||
/** @var Transaction $journal */
|
/** @var Transaction $journal */
|
||||||
foreach ($journals as $transaction) {
|
foreach ($journals as $transaction) {
|
||||||
$transaction->before = $startBalance;
|
$transaction->before = $startBalance;
|
||||||
$transactionAmount = $transaction->transaction_amount;
|
$transactionAmount = $transaction->transaction_amount;
|
||||||
$newBalance = bcadd($startBalance, $transactionAmount);
|
|
||||||
$transaction->after = $newBalance;
|
if ($currency->id === $transaction->foreign_currency_id) {
|
||||||
$startBalance = $newBalance;
|
$transactionAmount = $transaction->transaction_foreign_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newBalance = bcadd($startBalance, $transactionAmount);
|
||||||
|
$transaction->after = $newBalance;
|
||||||
|
$startBalance = $newBalance;
|
||||||
|
$transaction->currency = $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Support;
|
use FireflyIII\Generator\Report\Support;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -156,11 +159,13 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL])
|
->setTypes([TransactionType::WITHDRAWAL])
|
||||||
->setBudgets($this->budgets)->withOpposingAccount()->disableFilter();
|
->setBudgets($this->budgets)->withOpposingAccount();
|
||||||
|
$collector->removeFilter(TransferFilter::class);
|
||||||
|
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
|
||||||
$transactions = $collector->getJournals();
|
$transactions = $collector->getJournals();
|
||||||
$transactions = self::filterExpenses($transactions, $accountIds);
|
|
||||||
$this->expenses = $transactions;
|
$this->expenses = $transactions;
|
||||||
|
|
||||||
return $transactions;
|
return $transactions;
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Support;
|
use FireflyIII\Generator\Report\Support;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -166,11 +170,13 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setCategories($this->categories)->withOpposingAccount()->disableFilter();
|
->setCategories($this->categories)->withOpposingAccount();
|
||||||
|
$collector->removeFilter(TransferFilter::class);
|
||||||
|
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
|
||||||
$transactions = $collector->getJournals();
|
$transactions = $collector->getJournals();
|
||||||
$transactions = self::filterExpenses($transactions, $accountIds);
|
|
||||||
$this->expenses = $transactions;
|
$this->expenses = $transactions;
|
||||||
|
|
||||||
return $transactions;
|
return $transactions;
|
||||||
@@ -190,9 +196,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setCategories($this->categories)->withOpposingAccount();
|
->setCategories($this->categories)->withOpposingAccount();
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(NegativeAmountFilter::class);
|
||||||
|
|
||||||
$transactions = $collector->getJournals();
|
$transactions = $collector->getJournals();
|
||||||
$transactions = self::filterIncome($transactions, $accountIds);
|
|
||||||
$this->income = $transactions;
|
$this->income = $transactions;
|
||||||
|
|
||||||
return $transactions;
|
return $transactions;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace FireflyIII\Generator\Report;
|
|||||||
|
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,61 +24,6 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class Support
|
class Support
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $collection
|
|
||||||
* @param array $accounts
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public static function filterExpenses(Collection $collection, array $accounts): Collection
|
|
||||||
{
|
|
||||||
return self::filterTransactions($collection, $accounts, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $collection
|
|
||||||
* @param array $accounts
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public static function filterIncome(Collection $collection, array $accounts): Collection
|
|
||||||
{
|
|
||||||
return self::filterTransactions($collection, $accounts, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $collection
|
|
||||||
* @param array $accounts
|
|
||||||
* @param int $modifier
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public static function filterTransactions(Collection $collection, array $accounts, int $modifier): Collection
|
|
||||||
{
|
|
||||||
$result = $collection->filter(
|
|
||||||
function (Transaction $transaction) use ($accounts, $modifier) {
|
|
||||||
$opposing = $transaction->opposing_account_id;
|
|
||||||
// remove internal transfer
|
|
||||||
if (in_array($opposing, $accounts)) {
|
|
||||||
Log::debug(sprintf('Filtered #%d because its opposite is in accounts.', $transaction->id));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// remove positive amount
|
|
||||||
if (bccomp($transaction->transaction_amount, '0') === $modifier) {
|
|
||||||
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $transaction;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Support;
|
use FireflyIII\Generator\Report\Support;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
@@ -162,11 +166,14 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setTags($this->tags)->withOpposingAccount()->disableFilter();
|
->setTags($this->tags)->withOpposingAccount();
|
||||||
|
$collector->removeFilter(TransferFilter::class);
|
||||||
|
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$transactions = self::filterExpenses($transactions, $accountIds);
|
|
||||||
$this->expenses = $transactions;
|
$this->expenses = $transactions;
|
||||||
|
|
||||||
return $transactions;
|
return $transactions;
|
||||||
@@ -186,9 +193,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setTags($this->tags)->withOpposingAccount();
|
->setTags($this->tags)->withOpposingAccount();
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(NegativeAmountFilter::class);
|
||||||
|
|
||||||
$transactions = $collector->getJournals();
|
$transactions = $collector->getJournals();
|
||||||
$transactions = self::filterIncome($transactions, $accountIds);
|
|
||||||
$this->income = $transactions;
|
$this->income = $transactions;
|
||||||
|
|
||||||
return $transactions;
|
return $transactions;
|
||||||
|
|||||||
@@ -14,76 +14,95 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Handlers\Events;
|
namespace FireflyIII\Handlers\Events;
|
||||||
|
|
||||||
use FireflyIII\Events\StoredTransactionJournal;
|
use FireflyIII\Events\StoredTransactionJournal;
|
||||||
use FireflyIII\Models\PiggyBank;
|
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
|
||||||
use FireflyIII\Models\PiggyBankRepetition;
|
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface as JRI;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface as PRI;
|
||||||
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface as RGRI;
|
||||||
use FireflyIII\Rules\Processor;
|
use FireflyIII\Rules\Processor;
|
||||||
use FireflyIII\Support\Events\BillScanner;
|
use FireflyIII\Support\Events\BillScanner;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* Class StoredJournalEventHandler
|
* Class StoredJournalEventHandler
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Handlers\Events
|
* @package FireflyIII\Handlers\Events
|
||||||
*/
|
*/
|
||||||
class StoredJournalEventHandler
|
class StoredJournalEventHandler
|
||||||
{
|
{
|
||||||
|
/** @var JRI */
|
||||||
|
public $journalRepository;
|
||||||
|
/** @var PRI */
|
||||||
|
public $repository;
|
||||||
|
|
||||||
|
/** @var RGRI */
|
||||||
|
public $ruleGroupRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoredJournalEventHandler constructor.
|
||||||
|
*
|
||||||
|
* @param PRI $repository
|
||||||
|
* @param JRI $journalRepository
|
||||||
|
* @param RGRI $ruleGroupRepository
|
||||||
|
*/
|
||||||
|
public function __construct(PRI $repository, JRI $journalRepository, RGRI $ruleGroupRepository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
$this->journalRepository = $journalRepository;
|
||||||
|
$this->ruleGroupRepository = $ruleGroupRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method connects a new transfer to a piggy bank.
|
* This method connects a new transfer to a piggy bank.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
* @param StoredTransactionJournal $event
|
* @param StoredTransactionJournal $event
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function connectToPiggyBank(StoredTransactionJournal $event): bool
|
public function connectToPiggyBank(StoredTransactionJournal $event): bool
|
||||||
{
|
{
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $event->journal;
|
$journal = $event->journal;
|
||||||
$piggyBankId = $event->piggyBankId;
|
$piggyBankId = $event->piggyBankId;
|
||||||
Log::debug(sprintf('Trying to connect journal %d to piggy bank %d.', $journal->id, $piggyBankId));
|
$piggyBank = $this->repository->find($piggyBankId);
|
||||||
|
|
||||||
/*
|
// is a transfer?
|
||||||
* Will only continue when journal is a transfer.
|
if (!$this->journalRepository->isTransfer($journal)) {
|
||||||
*/
|
|
||||||
Log::debug(sprintf('Journal transaction type is %s', $journal->transactionType->type));
|
|
||||||
if ($journal->transactionType->type !== TransactionType::TRANSFER) {
|
|
||||||
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
|
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// piggy exists?
|
||||||
* Verify existence of piggy bank:
|
if (is_null($piggyBank->id)) {
|
||||||
*/
|
Log::error(sprintf('There is no piggy bank with ID #%d', $piggyBankId));
|
||||||
if (!$this->verifyExistence($event)) {
|
|
||||||
Log::error(sprintf('No such piggy bank or no repetition on %s', $journal->date->format('Y-m-d')));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// repetition exists?
|
||||||
* Get relevant data:
|
$repetition = $this->repository->getRepetition($piggyBank, $journal->date);
|
||||||
*/
|
if (is_null($repetition->id)) {
|
||||||
$piggyBank = $journal->user->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
|
||||||
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
|
|
||||||
$amount = $this->getExactAmount($journal, $piggyBank, $repetition);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the amount
|
||||||
|
$amount = $this->repository->getExactAmount($piggyBank, $repetition, $journal);
|
||||||
if (bccomp($amount, '0') === 0) {
|
if (bccomp($amount, '0') === 0) {
|
||||||
Log::debug('Amount is zero, will not create event.');
|
Log::debug('Amount is zero, will not create event.');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$repetition->currentamount = bcadd($repetition->currentamount, $amount);
|
// update amount
|
||||||
$repetition->save();
|
$this->repository->addAmountToRepetition($repetition, $amount);
|
||||||
|
$event = $this->repository->createEventWithJournal($piggyBank, $amount, $journal);
|
||||||
|
|
||||||
/** @var PiggyBankEvent $event */
|
|
||||||
$event = 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', $event->id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -100,16 +119,11 @@ class StoredJournalEventHandler
|
|||||||
{
|
{
|
||||||
// get all the user's rule groups, with the rules, order by 'order'.
|
// get all the user's rule groups, with the rules, order by 'order'.
|
||||||
$journal = $storedJournalEvent->journal;
|
$journal = $storedJournalEvent->journal;
|
||||||
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
$groups = $this->ruleGroupRepository->getActiveGroups($journal->user);
|
||||||
//
|
|
||||||
/** @var RuleGroup $group */
|
/** @var RuleGroup $group */
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
$rules = $group->rules()
|
$rules = $this->ruleGroupRepository->getActiveStoreRules($group);
|
||||||
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
|
||||||
->where('rule_triggers.trigger_type', 'user_action')
|
|
||||||
->where('rule_triggers.trigger_value', 'store-journal')
|
|
||||||
->where('rules.active', 1)
|
|
||||||
->get(['rules.*']);
|
|
||||||
/** @var Rule $rule */
|
/** @var Rule $rule */
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
|
|
||||||
@@ -117,9 +131,8 @@ class StoredJournalEventHandler
|
|||||||
$processor->handleTransactionJournal($journal);
|
$processor->handleTransactionJournal($journal);
|
||||||
|
|
||||||
if ($rule->stop_processing) {
|
if ($rule->stop_processing) {
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,81 +153,4 @@ class StoredJournalEventHandler
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 6 but I can live with it.
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param PiggyBank $piggyBank
|
|
||||||
* @param PiggyBankRepetition $repetition
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getExactAmount(TransactionJournal $journal, PiggyBank $piggyBank, PiggyBankRepetition $repetition): string
|
|
||||||
{
|
|
||||||
$amount = $journal->amountPositive();
|
|
||||||
$sources = $journal->sourceAccountList()->pluck('id')->toArray();
|
|
||||||
$room = bcsub(strval($piggyBank->targetamount), strval($repetition->currentamount));
|
|
||||||
$compare = bcmul($repetition->currentamount, '-1');
|
|
||||||
|
|
||||||
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
|
||||||
|
|
||||||
// if piggy account matches source account, the amount is positive
|
|
||||||
if (in_array($piggyBank->account_id, $sources)) {
|
|
||||||
$amount = bcmul($amount, '-1');
|
|
||||||
Log::debug(sprintf('Account #%d is the source, so will remove amount from piggy bank.', $piggyBank->account_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if the amount is positive, make sure it fits in piggy bank:
|
|
||||||
if (bccomp($amount, '0') === 1 && bccomp($room, $amount) === -1) {
|
|
||||||
// amount is positive and $room is smaller than $amount
|
|
||||||
Log::debug(sprintf('Room in piggy bank for extra money is %f', $room));
|
|
||||||
Log::debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
|
||||||
Log::debug(sprintf('New amount is %f', $room));
|
|
||||||
|
|
||||||
return $room;
|
|
||||||
}
|
|
||||||
|
|
||||||
// amount is negative and $currentamount is smaller than $amount
|
|
||||||
if (bccomp($amount, '0') === -1 && bccomp($compare, $amount) === 1) {
|
|
||||||
Log::debug(sprintf('Max amount to remove is %f', $repetition->currentamount));
|
|
||||||
Log::debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
|
||||||
Log::debug(sprintf('New amount is %f', $compare));
|
|
||||||
|
|
||||||
return $compare;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param StoredTransactionJournal $event
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function verifyExistence(StoredTransactionJournal $event): bool
|
|
||||||
{
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
$journal = $event->journal;
|
|
||||||
$piggyBankId = $event->piggyBankId;
|
|
||||||
|
|
||||||
/** @var PiggyBank $piggyBank */
|
|
||||||
$piggyBank = $journal->user->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
|
||||||
|
|
||||||
if (is_null($piggyBank)) {
|
|
||||||
Log::error('No such piggy bank!');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Log::debug(sprintf('Found piggy bank #%d: "%s"', $piggyBank->id, $piggyBank->name));
|
|
||||||
// update piggy bank rep for date of transaction journal.
|
|
||||||
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
|
|
||||||
if (is_null($repetition)) {
|
|
||||||
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,16 +17,31 @@ namespace FireflyIII\Handlers\Events;
|
|||||||
use FireflyIII\Events\UpdatedTransactionJournal;
|
use FireflyIII\Events\UpdatedTransactionJournal;
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use FireflyIII\Rules\Processor;
|
use FireflyIII\Rules\Processor;
|
||||||
use FireflyIII\Support\Events\BillScanner;
|
use FireflyIII\Support\Events\BillScanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* Class UpdatedJournalEventHandler
|
* Class UpdatedJournalEventHandler
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Handlers\Events
|
* @package FireflyIII\Handlers\Events
|
||||||
*/
|
*/
|
||||||
class UpdatedJournalEventHandler
|
class UpdatedJournalEventHandler
|
||||||
{
|
{
|
||||||
|
/** @var RuleGroupRepositoryInterface */
|
||||||
|
public $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoredJournalEventHandler constructor.
|
||||||
|
*
|
||||||
|
* @param RuleGroupRepositoryInterface $ruleGroupRepository
|
||||||
|
*/
|
||||||
|
public function __construct(RuleGroupRepositoryInterface $ruleGroupRepository)
|
||||||
|
{
|
||||||
|
$this->repository = $ruleGroupRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will check all the rules when a journal is updated.
|
* This method will check all the rules when a journal is updated.
|
||||||
@@ -39,16 +54,11 @@ class UpdatedJournalEventHandler
|
|||||||
{
|
{
|
||||||
// get all the user's rule groups, with the rules, order by 'order'.
|
// get all the user's rule groups, with the rules, order by 'order'.
|
||||||
$journal = $updatedJournalEvent->journal;
|
$journal = $updatedJournalEvent->journal;
|
||||||
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
$groups = $this->repository->getActiveGroups($journal->user);
|
||||||
//
|
|
||||||
/** @var RuleGroup $group */
|
/** @var RuleGroup $group */
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
$rules = $group->rules()
|
$rules = $this->repository->getActiveUpdateRules($group);
|
||||||
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
|
||||||
->where('rule_triggers.trigger_type', 'user_action')
|
|
||||||
->where('rule_triggers.trigger_value', 'update-journal')
|
|
||||||
->where('rules.active', 1)
|
|
||||||
->get(['rules.*']);
|
|
||||||
/** @var Rule $rule */
|
/** @var Rule $rule */
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
$processor = Processor::make($rule);
|
$processor = Processor::make($rule);
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ namespace FireflyIII\Handlers\Events;
|
|||||||
|
|
||||||
use FireflyIII\Events\RegisteredUser;
|
use FireflyIII\Events\RegisteredUser;
|
||||||
use FireflyIII\Events\RequestedNewPassword;
|
use FireflyIII\Events\RequestedNewPassword;
|
||||||
|
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
|
||||||
|
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Illuminate\Mail\Message;
|
|
||||||
use Log;
|
use Log;
|
||||||
use Mail;
|
use Mail;
|
||||||
use Swift_TransportException;
|
use Swift_TransportException;
|
||||||
@@ -68,15 +69,14 @@ class UserEventHandler
|
|||||||
|
|
||||||
// send email.
|
// send email.
|
||||||
try {
|
try {
|
||||||
Mail::send(
|
Mail::to($email)->send(new RequestedNewPasswordMail($url, $ipAddress));
|
||||||
['emails.password-html', 'emails.password-text'], ['url' => $url, 'ip' => $ipAddress], function (Message $message) use ($email) {
|
// @codeCoverageIgnoreStart
|
||||||
$message->to($email, $email)->subject('Your password reset request');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (Swift_TransportException $e) {
|
} catch (Swift_TransportException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,23 +93,23 @@ class UserEventHandler
|
|||||||
|
|
||||||
$sendMail = env('SEND_REGISTRATION_MAIL', true);
|
$sendMail = env('SEND_REGISTRATION_MAIL', true);
|
||||||
if (!$sendMail) {
|
if (!$sendMail) {
|
||||||
return true;
|
return true; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
// get the email address
|
// get the email address
|
||||||
$email = $event->user->email;
|
$email = $event->user->email;
|
||||||
$address = route('index');
|
$uri = route('index');
|
||||||
$ipAddress = $event->ipAddress;
|
$ipAddress = $event->ipAddress;
|
||||||
|
|
||||||
// send email.
|
// send email.
|
||||||
try {
|
try {
|
||||||
Mail::send(
|
Mail::to($email)->send(new RegisteredUserMail($uri, $ipAddress));
|
||||||
['emails.registered-html', 'emails.registered-text'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) {
|
// @codeCoverageIgnoreStart
|
||||||
$message->to($email, $email)->subject('Welcome to Firefly III!');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (Swift_TransportException $e) {
|
} catch (Swift_TransportException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ namespace FireflyIII\Helpers\Attachments;
|
|||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\Models\Attachment;
|
use FireflyIII\Models\Attachment;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
|
use Log;
|
||||||
use Storage;
|
use Storage;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
|
||||||
@@ -28,6 +30,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|||||||
class AttachmentHelper implements AttachmentHelperInterface
|
class AttachmentHelper implements AttachmentHelperInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var Collection */
|
||||||
|
public $attachments;
|
||||||
/** @var MessageBag */
|
/** @var MessageBag */
|
||||||
public $errors;
|
public $errors;
|
||||||
/** @var MessageBag */
|
/** @var MessageBag */
|
||||||
@@ -49,6 +53,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
$this->allowedMimes = (array)config('firefly.allowedMimes');
|
$this->allowedMimes = (array)config('firefly.allowedMimes');
|
||||||
$this->errors = new MessageBag;
|
$this->errors = new MessageBag;
|
||||||
$this->messages = new MessageBag;
|
$this->messages = new MessageBag;
|
||||||
|
$this->attachments = new Collection;
|
||||||
$this->uploadDisk = Storage::disk('upload');
|
$this->uploadDisk = Storage::disk('upload');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +69,14 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAttachments(): Collection
|
||||||
|
{
|
||||||
|
return $this->attachments;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return MessageBag
|
* @return MessageBag
|
||||||
*/
|
*/
|
||||||
@@ -110,7 +123,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
$md5 = md5_file($file->getRealPath());
|
$md5 = md5_file($file->getRealPath());
|
||||||
$name = $file->getClientOriginalName();
|
$name = $file->getClientOriginalName();
|
||||||
$class = get_class($model);
|
$class = get_class($model);
|
||||||
$count = auth()->user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
$count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||||
|
|
||||||
if ($count > 0) {
|
if ($count > 0) {
|
||||||
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
|
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
|
||||||
@@ -137,7 +150,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$attachment = new Attachment; // create Attachment object.
|
$attachment = new Attachment; // create Attachment object.
|
||||||
$attachment->user()->associate(auth()->user());
|
$attachment->user()->associate($model->user);
|
||||||
$attachment->attachable()->associate($model);
|
$attachment->attachable()->associate($model);
|
||||||
$attachment->md5 = md5_file($file->getRealPath());
|
$attachment->md5 = md5_file($file->getRealPath());
|
||||||
$attachment->filename = $file->getClientOriginalName();
|
$attachment->filename = $file->getClientOriginalName();
|
||||||
@@ -145,17 +158,21 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
$attachment->size = $file->getSize();
|
$attachment->size = $file->getSize();
|
||||||
$attachment->uploaded = 0;
|
$attachment->uploaded = 0;
|
||||||
$attachment->save();
|
$attachment->save();
|
||||||
|
Log::debug('Created attachment:', $attachment->toArray());
|
||||||
|
|
||||||
$fileObject = $file->openFile('r');
|
$fileObject = $file->openFile('r');
|
||||||
$fileObject->rewind();
|
$fileObject->rewind();
|
||||||
$content = $fileObject->fread($file->getSize());
|
$content = $fileObject->fread($file->getSize());
|
||||||
$encrypted = Crypt::encrypt($content);
|
$encrypted = Crypt::encrypt($content);
|
||||||
|
Log::debug(sprintf('Full file length is %d and upload size is %d.', strlen($content), $file->getSize()));
|
||||||
|
Log::debug(sprintf('Encrypted content is %d', strlen($encrypted)));
|
||||||
|
|
||||||
// store it:
|
// store it:
|
||||||
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
||||||
|
|
||||||
$attachment->uploaded = 1; // update attachment
|
$attachment->uploaded = 1; // update attachment
|
||||||
$attachment->save();
|
$attachment->save();
|
||||||
|
$this->attachments->push($attachment);
|
||||||
|
|
||||||
$name = e($file->getClientOriginalName()); // add message:
|
$name = e($file->getClientOriginalName()); // add message:
|
||||||
$msg = (string)trans('validation.file_attached', ['name' => $name]);
|
$msg = (string)trans('validation.file_attached', ['name' => $name]);
|
||||||
@@ -188,6 +205,8 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param UploadedFile $file
|
* @param UploadedFile $file
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -218,7 +237,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!$this->validSize($file)) {
|
if (!$this->validSize($file)) {
|
||||||
return false;
|
return false; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
if ($this->hasFile($file, $model)) {
|
if ($this->hasFile($file, $model)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace FireflyIII\Helpers\Attachments;
|
|||||||
|
|
||||||
use FireflyIII\Models\Attachment;
|
use FireflyIII\Models\Attachment;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +33,11 @@ interface AttachmentHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentLocation(Attachment $attachment): string;
|
public function getAttachmentLocation(Attachment $attachment): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAttachments(): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return MessageBag
|
* @return MessageBag
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Helpers\Chart;
|
namespace FireflyIII\Helpers\Chart;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Report\Support;
|
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
@@ -91,6 +94,7 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
if ($this->collectOtherObjects && $direction === 'expense') {
|
if ($this->collectOtherObjects && $direction === 'expense') {
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
|
$collector->setUser($this->user);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
$journals = $collector->getJournals();
|
$journals = $collector->getJournals();
|
||||||
$sum = strval($journals->sum('transaction_amount'));
|
$sum = strval($journals->sum('transaction_amount'));
|
||||||
@@ -102,6 +106,7 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
if ($this->collectOtherObjects && $direction === 'income') {
|
if ($this->collectOtherObjects && $direction === 'income') {
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
|
$collector->setUser($this->user);
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
||||||
$journals = $collector->getJournals();
|
$journals = $collector->getJournals();
|
||||||
$sum = strval($journals->sum('transaction_amount'));
|
$sum = strval($journals->sum('transaction_amount'));
|
||||||
@@ -114,6 +119,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -126,6 +133,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Collection $budgets
|
* @param Collection $budgets
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -138,6 +147,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Collection $categories
|
* @param Collection $categories
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -150,6 +161,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param bool $collectOtherObjects
|
* @param bool $collectOtherObjects
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -162,6 +175,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -174,6 +189,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -186,6 +203,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param Collection $tags
|
* @param Collection $tags
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -198,6 +217,8 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
* @return MetaPieChartInterface
|
* @return MetaPieChartInterface
|
||||||
@@ -209,23 +230,32 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTransactions(string $direction)
|
/**
|
||||||
|
* @param string $direction
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
protected function getTransactions(string $direction): Collection
|
||||||
{
|
{
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
|
||||||
$modifier = -1;
|
|
||||||
if ($direction === 'expense') {
|
|
||||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
|
||||||
$modifier = 1;
|
|
||||||
}
|
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
|
$collector->addFilter(NegativeAmountFilter::class);
|
||||||
|
if ($direction === 'expense') {
|
||||||
|
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
$collector->removeFilter(NegativeAmountFilter::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$collector->setUser($this->user);
|
||||||
$collector->setAccounts($this->accounts);
|
$collector->setAccounts($this->accounts);
|
||||||
$collector->setRange($this->start, $this->end);
|
$collector->setRange($this->start, $this->end);
|
||||||
$collector->setTypes($types);
|
$collector->setTypes($types);
|
||||||
$collector->withOpposingAccount();
|
$collector->withOpposingAccount();
|
||||||
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
|
||||||
if ($direction === 'income') {
|
if ($direction === 'income') {
|
||||||
$collector->disableFilter();
|
$collector->removeFilter(TransferFilter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->budgets->count() > 0) {
|
if ($this->budgets->count() > 0) {
|
||||||
@@ -240,11 +270,7 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
$collector->withBudgetInformation();
|
$collector->withBudgetInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
$accountIds = $this->accounts->pluck('id')->toArray();
|
return $collector->getJournals();
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = Support::filterTransactions($transactions, $accountIds, $modifier);
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,6 +312,7 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
$chartData = [];
|
$chartData = [];
|
||||||
$names = [];
|
$names = [];
|
||||||
$repository = app($this->repositories[$type]);
|
$repository = app($this->repositories[$type]);
|
||||||
|
$repository->setUser($this->user);
|
||||||
foreach ($array as $objectId => $amount) {
|
foreach ($array as $objectId => $amount) {
|
||||||
if (!isset($names[$objectId])) {
|
if (!isset($names[$objectId])) {
|
||||||
$object = $repository->find(intval($objectId));
|
$object = $repository->find(intval($objectId));
|
||||||
@@ -300,6 +327,11 @@ class MetaPieChart implements MetaPieChartInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function groupByTag(Collection $set): array
|
private function groupByTag(Collection $set): array
|
||||||
{
|
{
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
|
|||||||
@@ -147,13 +147,13 @@ class BalanceLine
|
|||||||
if ($this->getBudget() instanceof BudgetModel && !is_null($this->getBudget()->id)) {
|
if ($this->getBudget() instanceof BudgetModel && !is_null($this->getBudget()->id)) {
|
||||||
return $this->getBudget()->name;
|
return $this->getBudget()->name;
|
||||||
}
|
}
|
||||||
if ($this->getRole() == self::ROLE_DEFAULTROLE) {
|
if ($this->getRole() === self::ROLE_DEFAULTROLE) {
|
||||||
return strval(trans('firefly.no_budget'));
|
return strval(trans('firefly.no_budget'));
|
||||||
}
|
}
|
||||||
if ($this->getRole() == self::ROLE_TAGROLE) {
|
if ($this->getRole() === self::ROLE_TAGROLE) {
|
||||||
return strval(trans('firefly.coveredWithTags'));
|
return strval(trans('firefly.coveredWithTags'));
|
||||||
}
|
}
|
||||||
if ($this->getRole() == self::ROLE_DIFFROLE) {
|
if ($this->getRole() === self::ROLE_DIFFROLE) {
|
||||||
return strval(trans('firefly.leftUnbalanced'));
|
return strval(trans('firefly.leftUnbalanced'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class Bill
|
|||||||
{
|
{
|
||||||
$set = $this->bills->sortBy(
|
$set = $this->bills->sortBy(
|
||||||
function (BillLine $bill) {
|
function (BillLine $bill) {
|
||||||
$active = intval($bill->getBill()->active) == 0 ? 1 : 0;
|
$active = intval($bill->getBill()->active) === 0 ? 1 : 0;
|
||||||
$name = $bill->getBill()->name;
|
$name = $bill->getBill()->name;
|
||||||
|
|
||||||
return $active . $name;
|
return $active . $name;
|
||||||
|
|||||||
@@ -18,12 +18,17 @@ use Carbon\Carbon;
|
|||||||
use Crypt;
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Helpers\Filter\FilterInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
@@ -55,25 +60,39 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
'transaction_journals.description',
|
'transaction_journals.description',
|
||||||
'transaction_journals.date',
|
'transaction_journals.date',
|
||||||
'transaction_journals.encrypted',
|
'transaction_journals.encrypted',
|
||||||
'transaction_currencies.code as transaction_currency_code',
|
|
||||||
'transaction_types.type as transaction_type_type',
|
'transaction_types.type as transaction_type_type',
|
||||||
'transaction_journals.bill_id',
|
'transaction_journals.bill_id',
|
||||||
'bills.name as bill_name',
|
'bills.name as bill_name',
|
||||||
'bills.name_encrypted as bill_name_encrypted',
|
'bills.name_encrypted as bill_name_encrypted',
|
||||||
'transactions.id as id',
|
'transactions.id as id',
|
||||||
'transactions.amount as transaction_amount',
|
|
||||||
'transactions.description as transaction_description',
|
'transactions.description as transaction_description',
|
||||||
'transactions.account_id',
|
'transactions.account_id',
|
||||||
'transactions.identifier',
|
'transactions.identifier',
|
||||||
'transactions.transaction_journal_id',
|
'transactions.transaction_journal_id',
|
||||||
|
|
||||||
|
'transactions.amount as transaction_amount',
|
||||||
|
|
||||||
|
'transactions.transaction_currency_id as transaction_currency_id',
|
||||||
|
'transaction_currencies.code as transaction_currency_code',
|
||||||
|
'transaction_currencies.symbol as transaction_currency_symbol',
|
||||||
|
'transaction_currencies.decimal_places as transaction_currency_dp',
|
||||||
|
|
||||||
|
'transactions.foreign_amount as transaction_foreign_amount',
|
||||||
|
'transactions.foreign_currency_id as foreign_currency_id',
|
||||||
|
'foreign_currencies.code as foreign_currency_code',
|
||||||
|
'foreign_currencies.symbol as foreign_currency_symbol',
|
||||||
|
'foreign_currencies.decimal_places as foreign_currency_dp',
|
||||||
|
|
||||||
'accounts.name as account_name',
|
'accounts.name as account_name',
|
||||||
'accounts.encrypted as account_encrypted',
|
'accounts.encrypted as account_encrypted',
|
||||||
'account_types.type as account_type',
|
'account_types.type as account_type',
|
||||||
];
|
];
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $filterInternalTransfers;
|
|
||||||
/** @var bool */
|
|
||||||
private $filterTransfers = false;
|
private $filterTransfers = false;
|
||||||
|
/** @var array */
|
||||||
|
private $filters = [InternalTransferFilter::class];
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $joinedBudget = false;
|
private $joinedBudget = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@@ -95,6 +114,22 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filter
|
||||||
|
*
|
||||||
|
* @return JournalCollectorInterface
|
||||||
|
*/
|
||||||
|
public function addFilter(string $filter): JournalCollectorInterface
|
||||||
|
{
|
||||||
|
$interfaces = class_implements($filter);
|
||||||
|
if (in_array(FilterInterface::class, $interfaces)) {
|
||||||
|
Log::debug(sprintf('Enabled filter %s', $filter));
|
||||||
|
$this->filters[] = $filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@@ -119,36 +154,6 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
return $this->count;
|
return $this->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return JournalCollectorInterface
|
|
||||||
*/
|
|
||||||
public function disableFilter(): JournalCollectorInterface
|
|
||||||
{
|
|
||||||
$this->filterTransfers = false;
|
|
||||||
|
|
||||||
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
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@@ -157,14 +162,9 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
$this->run = true;
|
$this->run = true;
|
||||||
/** @var Collection $set */
|
/** @var Collection $set */
|
||||||
$set = $this->query->get(array_values($this->fields));
|
$set = $this->query->get(array_values($this->fields));
|
||||||
Log::debug(sprintf('Count of set is %d', $set->count()));
|
|
||||||
$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()));
|
|
||||||
|
|
||||||
|
// run all filters:
|
||||||
|
$set = $this->filter($set);
|
||||||
|
|
||||||
// loop for decryption.
|
// loop for decryption.
|
||||||
$set->each(
|
$set->each(
|
||||||
@@ -204,6 +204,22 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
return $journals;
|
return $journals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filter
|
||||||
|
*
|
||||||
|
* @return JournalCollectorInterface
|
||||||
|
*/
|
||||||
|
public function removeFilter(string $filter): JournalCollectorInterface
|
||||||
|
{
|
||||||
|
$key = array_search($filter, $this->filters, true);
|
||||||
|
if (!($key === false)) {
|
||||||
|
Log::debug(sprintf('Removed filter %s', $filter));
|
||||||
|
unset($this->filters[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
*
|
*
|
||||||
@@ -219,6 +235,7 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($accounts->count() > 1) {
|
if ($accounts->count() > 1) {
|
||||||
|
$this->addFilter(TransferFilter::class);
|
||||||
$this->filterTransfers = true;
|
$this->filterTransfers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +259,7 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($accounts->count() > 1) {
|
if ($accounts->count() > 1) {
|
||||||
|
$this->addFilter(TransferFilter::class);
|
||||||
$this->filterTransfers = true;
|
$this->filterTransfers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +482,9 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function setUser(User $user)
|
public function setUser(User $user)
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Journal collector now collecting for user #%d', $user->id));
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
$this->startQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -472,19 +492,22 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function startQuery()
|
public function startQuery()
|
||||||
{
|
{
|
||||||
|
Log::debug('journalCollector::startQuery');
|
||||||
/** @var EloquentBuilder $query */
|
/** @var EloquentBuilder $query */
|
||||||
$query = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
$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('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
|
||||||
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
|
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
||||||
|
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transactions.transaction_currency_id')
|
||||||
|
->leftJoin('transaction_currencies as foreign_currencies', 'foreign_currencies.id', 'transactions.foreign_currency_id')
|
||||||
->whereNull('transactions.deleted_at')
|
->whereNull('transactions.deleted_at')
|
||||||
->whereNull('transaction_journals.deleted_at')
|
->whereNull('transaction_journals.deleted_at')
|
||||||
->where('transaction_journals.user_id', $this->user->id)
|
->where('transaction_journals.user_id', $this->user->id)
|
||||||
->orderBy('transaction_journals.date', 'DESC')
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC');
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
|
->orderBy('transaction_journals.description', 'DESC');
|
||||||
|
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
|
|
||||||
@@ -560,79 +583,23 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
private function filterInternalTransfers(Collection $set): Collection
|
private function filter(Collection $set): Collection
|
||||||
{
|
{
|
||||||
if ($this->filterInternalTransfers === false) {
|
// create all possible filters:
|
||||||
Log::debug('Did NO filtering for internal transfers on given set.');
|
$filters = [
|
||||||
|
InternalTransferFilter::class => new InternalTransferFilter($this->accountIds),
|
||||||
return $set;
|
OpposingAccountFilter::class => new OpposingAccountFilter($this->accountIds),
|
||||||
}
|
TransferFilter::class => new TransferFilter,
|
||||||
if ($this->joinedOpposing === false) {
|
PositiveAmountFilter::class => new PositiveAmountFilter,
|
||||||
Log::info('Cannot filter internal transfers because no opposing information is present.');
|
NegativeAmountFilter::class => new NegativeAmountFilter,
|
||||||
|
];
|
||||||
return $set;
|
Log::debug(sprintf('Will run %d filters on the set.', count($this->filters)));
|
||||||
}
|
foreach ($this->filters as $enabled) {
|
||||||
|
if (isset($filters[$enabled])) {
|
||||||
$accountIds = $this->accountIds;
|
Log::debug(sprintf('Before filter %s: %d', $enabled, $set->count()));
|
||||||
$set = $set->filter(
|
$set = $filters[$enabled]->filter($set);
|
||||||
function (Transaction $transaction) use ($accountIds) {
|
Log::debug(sprintf('After filter %s: %d', $enabled, $set->count()));
|
||||||
// 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
|
|
||||||
* on both the source, and then again on the destination account.
|
|
||||||
*
|
|
||||||
* This method filters them out by removing transfers that have been selected twice.
|
|
||||||
*
|
|
||||||
* @param Collection $set
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function filterTransfers(Collection $set): Collection
|
|
||||||
{
|
|
||||||
if ($this->filterTransfers) {
|
|
||||||
$count = [];
|
|
||||||
$new = new Collection;
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
if ($transaction->transaction_type_type !== TransactionType::TRANSFER) {
|
|
||||||
$new->push($transaction);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// make property string:
|
|
||||||
$journalId = $transaction->transaction_journal_id;
|
|
||||||
$amount = Steam::positive($transaction->transaction_amount);
|
|
||||||
$accountIds = [intval($transaction->account_id), intval($transaction->opposing_account_id)];
|
|
||||||
sort($accountIds);
|
|
||||||
$key = $journalId . '-' . join(',', $accountIds) . '-' . $amount;
|
|
||||||
Log::debug(sprintf('Key is %s', $key));
|
|
||||||
if (!isset($count[$key])) {
|
|
||||||
// not yet counted? add to new set and count it:
|
|
||||||
$new->push($transaction);
|
|
||||||
$count[$key] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $set;
|
return $set;
|
||||||
|
|||||||
@@ -28,26 +28,18 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
interface JournalCollectorInterface
|
interface JournalCollectorInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param string $filter
|
||||||
|
*
|
||||||
|
* @return JournalCollectorInterface
|
||||||
|
*/
|
||||||
|
public function addFilter(string $filter): JournalCollectorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function count(): int;
|
public function count(): int;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return JournalCollectorInterface
|
|
||||||
*/
|
|
||||||
public function disableFilter(): JournalCollectorInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return JournalCollectorInterface
|
|
||||||
*/
|
|
||||||
public function disableInternalFilter(): JournalCollectorInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return JournalCollectorInterface
|
|
||||||
*/
|
|
||||||
public function enableInternalFilter(): JournalCollectorInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@@ -58,6 +50,13 @@ interface JournalCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function getPaginatedJournals(): LengthAwarePaginator;
|
public function getPaginatedJournals(): LengthAwarePaginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filter
|
||||||
|
*
|
||||||
|
* @return JournalCollectorInterface
|
||||||
|
*/
|
||||||
|
public function removeFilter(string $filter): JournalCollectorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
*
|
*
|
||||||
|
|||||||
56
app/Helpers/Filter/AmountFilter.php
Normal file
56
app/Helpers/Filter/AmountFilter.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AmountFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AmountFilter
|
||||||
|
*
|
||||||
|
* This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount
|
||||||
|
* ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class AmountFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/** @var int */
|
||||||
|
private $modifier = 0;
|
||||||
|
|
||||||
|
public function __construct(int $modifier)
|
||||||
|
{
|
||||||
|
$this->modifier = $modifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set->filter(
|
||||||
|
function (Transaction $transaction) {
|
||||||
|
// remove by amount
|
||||||
|
if (bccomp($transaction->transaction_amount, '0') === $this->modifier) {
|
||||||
|
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Helpers/Filter/EmptyFilter.php
Normal file
34
app/Helpers/Filter/EmptyFilter.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* EmptyFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EmptyFilter
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class EmptyFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Helpers/Filter/FilterInterface.php
Normal file
26
app/Helpers/Filter/FilterInterface.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FilterInterface.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
interface FilterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection;
|
||||||
|
|
||||||
|
}
|
||||||
73
app/Helpers/Filter/InternalTransferFilter.php
Normal file
73
app/Helpers/Filter/InternalTransferFilter.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* InternalTransferFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InternalTransferFilter
|
||||||
|
*
|
||||||
|
* This filter removes any filters that are from A to B or from B to A given a set of
|
||||||
|
* account id's (in $parameters) where A and B are mentioned. So transfers between the mentioned
|
||||||
|
* accounts will be removed.
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class InternalTransferFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/** @var array */
|
||||||
|
private $accounts = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InternalTransferFilter constructor.
|
||||||
|
*
|
||||||
|
* @param array $accounts
|
||||||
|
*/
|
||||||
|
public function __construct(array $accounts)
|
||||||
|
{
|
||||||
|
$this->accounts = $accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set->filter(
|
||||||
|
function (Transaction $transaction) {
|
||||||
|
if (is_null($transaction->opposing_account_id)) {
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
// both id's in $parameters?
|
||||||
|
if (in_array($transaction->account_id, $this->accounts) && in_array($transaction->opposing_account_id, $this->accounts)) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'Transaction #%d has #%d and #%d in set, so removed',
|
||||||
|
$transaction->id, $transaction->account_id, $transaction->opposing_account_id
|
||||||
|
), $this->accounts
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
47
app/Helpers/Filter/NegativeAmountFilter.php
Normal file
47
app/Helpers/Filter/NegativeAmountFilter.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* NegativeAmountFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class NegativeAmountFilter
|
||||||
|
*
|
||||||
|
* This filter removes entries with a negative amount (the original modifier is -1).
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class NegativeAmountFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set->filter(
|
||||||
|
function (Transaction $transaction) {
|
||||||
|
// remove by amount
|
||||||
|
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||||
|
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Helpers/Filter/OpposingAccountFilter.php
Normal file
63
app/Helpers/Filter/OpposingAccountFilter.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OpposingAccountFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OpposingAccountFilter
|
||||||
|
*
|
||||||
|
* This filter is similar to the internal transfer filter but only removes transactions when the opposing account is
|
||||||
|
* amongst $parameters (list of account ID's).
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class OpposingAccountFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/** @var array */
|
||||||
|
private $accounts = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InternalTransferFilter constructor.
|
||||||
|
*
|
||||||
|
* @param array $accounts
|
||||||
|
*/
|
||||||
|
public function __construct(array $accounts)
|
||||||
|
{
|
||||||
|
$this->accounts = $accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set->filter(
|
||||||
|
function (Transaction $transaction) {
|
||||||
|
$opposing = $transaction->opposing_account_id;
|
||||||
|
// remove internal transfer
|
||||||
|
if (in_array($opposing, $this->accounts)) {
|
||||||
|
Log::debug(sprintf('Filtered #%d because its opposite is in accounts.', $transaction->id), $this->accounts);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Helpers/Filter/PositiveAmountFilter.php
Normal file
50
app/Helpers/Filter/PositiveAmountFilter.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PositiveAmountFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PositiveAmountFilter
|
||||||
|
*
|
||||||
|
* This filter removes entries with a negative amount (the original modifier is -1).
|
||||||
|
*
|
||||||
|
* This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount
|
||||||
|
* ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class PositiveAmountFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
return $set->filter(
|
||||||
|
function (Transaction $transaction) {
|
||||||
|
// remove by amount
|
||||||
|
if (bccomp($transaction->transaction_amount, '0') === 1) {
|
||||||
|
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Helpers/Filter/TransferFilter.php
Normal file
58
app/Helpers/Filter/TransferFilter.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TransferFilter.php
|
||||||
|
* Copyright (c) 2017 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\Filter;
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TransferFilter
|
||||||
|
*
|
||||||
|
* This filter removes any transfers that are in the collection twice (from A to B and from B to A).
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Filter
|
||||||
|
*/
|
||||||
|
class TransferFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
$count = [];
|
||||||
|
$new = new Collection;
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($set as $transaction) {
|
||||||
|
if ($transaction->transaction_type_type !== TransactionType::TRANSFER) {
|
||||||
|
$new->push($transaction);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// make property string:
|
||||||
|
$journalId = $transaction->transaction_journal_id;
|
||||||
|
$amount = Steam::positive($transaction->transaction_amount);
|
||||||
|
$accountIds = [intval($transaction->account_id), intval($transaction->opposing_account_id)];
|
||||||
|
sort($accountIds);
|
||||||
|
$key = $journalId . '-' . join(',', $accountIds) . '-' . $amount;
|
||||||
|
if (!isset($count[$key])) {
|
||||||
|
// not yet counted? add to new set and count it:
|
||||||
|
$new->push($transaction);
|
||||||
|
$count[$key] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ use Route;
|
|||||||
*/
|
*/
|
||||||
class Help implements HelpInterface
|
class Help implements HelpInterface
|
||||||
{
|
{
|
||||||
|
const CACHEKEY = 'help_%s_%s';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
|
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ class Help implements HelpInterface
|
|||||||
*/
|
*/
|
||||||
public function getFromCache(string $route, string $language): string
|
public function getFromCache(string $route, string $language): string
|
||||||
{
|
{
|
||||||
$line = sprintf('help.%s.%s', $route, $language);
|
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||||
|
|
||||||
return Cache::get($line);
|
return Cache::get($line);
|
||||||
}
|
}
|
||||||
@@ -64,12 +65,12 @@ class Help implements HelpInterface
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log::debug(sprintf('Status code is %d', $result->status_code));
|
Log::debug(sprintf('Status code is %d', $result->status_code));
|
||||||
|
|
||||||
if ($result->status_code === 200) {
|
if ($result->status_code === 200) {
|
||||||
$content = trim($result->body);
|
$content = trim($result->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($content) > 0) {
|
if (strlen($content) > 0) {
|
||||||
Log::debug('Content is longer than zero. Expect something.');
|
Log::debug('Content is longer than zero. Expect something.');
|
||||||
$converter = new CommonMarkConverter();
|
$converter = new CommonMarkConverter();
|
||||||
@@ -98,7 +99,7 @@ class Help implements HelpInterface
|
|||||||
*/
|
*/
|
||||||
public function inCache(string $route, string $language): bool
|
public function inCache(string $route, string $language): bool
|
||||||
{
|
{
|
||||||
$line = sprintf('help.%s.%s', $route, $language);
|
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||||
$result = Cache::has($line);
|
$result = Cache::has($line);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
||||||
@@ -120,7 +121,7 @@ class Help implements HelpInterface
|
|||||||
*/
|
*/
|
||||||
public function putInCache(string $route, string $language, string $content)
|
public function putInCache(string $route, string $language, string $content)
|
||||||
{
|
{
|
||||||
$key = sprintf('help.%s.%s', $route, $language);
|
$key = sprintf(self::CACHEKEY, $route, $language);
|
||||||
if (strlen($content) > 0) {
|
if (strlen($content) > 0) {
|
||||||
Log::debug(sprintf('Will store entry in cache: %s', $key));
|
Log::debug(sprintf('Will store entry in cache: %s', $key));
|
||||||
Cache::put($key, $content, 10080); // a week.
|
Cache::put($key, $content, 10080); // a week.
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
|
|||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$leftEntry = $tagsLeft->filter(
|
$leftEntry = $tagsLeft->filter(
|
||||||
function (Tag $tag) use ($account) {
|
function (Tag $tag) use ($account) {
|
||||||
return $tag->account_id == $account->id;
|
return $tag->account_id === $account->id;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$left = '0';
|
$left = '0';
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
|||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
foreach ($set as $budget) {
|
foreach ($set as $budget) {
|
||||||
$budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end);
|
$budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end);
|
||||||
if ($budgetLimits->count() == 0) { // no budget limit(s) for this budget
|
if ($budgetLimits->count() === 0) { // no budget limit(s) for this budget
|
||||||
|
|
||||||
$spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);// spent for budget in time range
|
$spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);// spent for budget in time range
|
||||||
if (bccomp($spent, '0') === -1) {
|
if (bccomp($spent, '0') === -1) {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ class PopupReport implements PopupReportInterface
|
|||||||
$journals = $journals->filter(
|
$journals = $journals->filter(
|
||||||
function (Transaction $transaction) use ($report) {
|
function (Transaction $transaction) use ($report) {
|
||||||
// get the destinations:
|
// get the destinations:
|
||||||
$destinations = $transaction->destinationAccountList($transaction->transactionJournal)->pluck('id')->toArray();
|
$destinations = $transaction->transactionJournal->destinationAccountList()->pluck('id')->toArray();
|
||||||
|
|
||||||
// do these intersect with the current list?
|
// do these intersect with the current list?
|
||||||
return !empty(array_intersect($report, $destinations));
|
return !empty(array_intersect($report, $destinations));
|
||||||
@@ -196,4 +196,4 @@ class PopupReport implements PopupReportInterface
|
|||||||
|
|
||||||
return $journals;
|
return $journals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,4 +80,4 @@ interface PopupReportInterface
|
|||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function byIncome(Account $account, array $attributes): Collection;
|
public function byIncome(Account $account, array $attributes): Collection;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
return view(
|
return view(
|
||||||
'accounts.edit', compact(
|
'accounts.edit', compact(
|
||||||
'allCurrencies', 'currencySelectList', 'account', 'currency', 'subTitle', 'subTitleIcon', 'openingBalance', 'what', 'roles'
|
'allCurrencies', 'currencySelectList', 'account', 'currency', 'subTitle', 'subTitleIcon', 'what', 'roles'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -219,8 +219,8 @@ class AccountController extends Controller
|
|||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$startBalances = Steam::balancesById($ids, $start);
|
$startBalances = Steam::balancesByAccounts($accounts, $start);
|
||||||
$endBalances = Steam::balancesById($ids, $end);
|
$endBalances = Steam::balancesByAccounts($accounts, $end);
|
||||||
$activities = Steam::getLastActivities($ids);
|
$activities = Steam::getLastActivities($ids);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
@@ -293,8 +293,8 @@ class AccountController extends Controller
|
|||||||
$periods = $this->getPeriodOverview($account);
|
$periods = $this->getPeriodOverview($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
// grab journals, but be prepared to jump a period back to get the right ones:
|
// grab journals, but be prepared to jump a period back to get the right ones:
|
||||||
Log::info('Now at loop start.');
|
Log::info('Now at loop start.');
|
||||||
while ($count === 0 && $loop < 3) {
|
while ($count === 0 && $loop < 3) {
|
||||||
@@ -308,7 +308,7 @@ class AccountController extends Controller
|
|||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('accounts/show/' . $account->id . '/' . $moment);
|
$journals->setPath('accounts/show/' . $account->id . '/' . $moment);
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -316,7 +316,7 @@ class AccountController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
|
'firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
|
|||||||
@@ -98,10 +98,13 @@ class AttachmentController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function download(AttachmentRepositoryInterface $repository, Attachment $attachment)
|
public function download(AttachmentRepositoryInterface $repository, Attachment $attachment)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if ($repository->exists($attachment)) {
|
if ($repository->exists($attachment)) {
|
||||||
$content = $repository->getContent($attachment);
|
$content = $repository->getContent($attachment);
|
||||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||||
|
|
||||||
|
|
||||||
/** @var LaravelResponse $response */
|
/** @var LaravelResponse $response */
|
||||||
$response = response($content, 200);
|
$response = response($content, 200);
|
||||||
$response
|
$response
|
||||||
@@ -149,7 +152,8 @@ class AttachmentController extends Controller
|
|||||||
{
|
{
|
||||||
$image = 'images/page_green.png';
|
$image = 'images/page_green.png';
|
||||||
|
|
||||||
if ($attachment->mime == 'application/pdf') {
|
|
||||||
|
if ($attachment->mime === 'application/pdf') {
|
||||||
$image = 'images/page_white_acrobat.png';
|
$image = 'images/page_white_acrobat.png';
|
||||||
}
|
}
|
||||||
$file = public_path($image);
|
$file = public_path($image);
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class BillController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function rescan(Request $request, BillRepositoryInterface $repository, Bill $bill)
|
public function rescan(Request $request, BillRepositoryInterface $repository, Bill $bill)
|
||||||
{
|
{
|
||||||
if (intval($bill->active) == 0) {
|
if (intval($bill->active) === 0) {
|
||||||
$request->session()->flash('warning', strval(trans('firefly.cannot_scan_inactive_bill')));
|
$request->session()->flash('warning', strval(trans('firefly.cannot_scan_inactive_bill')));
|
||||||
|
|
||||||
return redirect(URL::previous());
|
return redirect(URL::previous());
|
||||||
@@ -206,7 +206,7 @@ class BillController extends Controller
|
|||||||
/** @var Carbon $date */
|
/** @var Carbon $date */
|
||||||
$date = session('start');
|
$date = session('start');
|
||||||
$year = $date->year;
|
$year = $date->year;
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$yearAverage = $repository->getYearAverage($bill, $date);
|
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||||
$overallAverage = $repository->getOverallAverage($bill);
|
$overallAverage = $repository->getOverallAverage($bill);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Amount;
|
use Amount;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Http\Requests\BudgetFormRequest;
|
use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||||
@@ -80,7 +81,7 @@ class BudgetController extends Controller
|
|||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
|
||||||
if ($amount == 0) {
|
if ($amount === 0) {
|
||||||
$budgetLimit = null;
|
$budgetLimit = null;
|
||||||
}
|
}
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
@@ -166,16 +167,38 @@ class BudgetController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param string|null $moment
|
||||||
|
*
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(string $moment = null)
|
||||||
{
|
{
|
||||||
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
|
$start = session('start', new Carbon);
|
||||||
|
$end = session('end', new Carbon);
|
||||||
|
|
||||||
|
// make date if present:
|
||||||
|
if (!is_null($moment) || strlen(strval($moment)) !== 0) {
|
||||||
|
try {
|
||||||
|
$start = new Carbon($moment);
|
||||||
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// start and end are already defined.
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$next = clone $end;
|
||||||
|
$next->addDay();
|
||||||
|
$prev = clone $start;
|
||||||
|
$prev->subDay();
|
||||||
|
$prev = Navigation::startOfPeriod($prev, $range);
|
||||||
|
|
||||||
|
|
||||||
$this->repository->cleanupBudgets();
|
$this->repository->cleanupBudgets();
|
||||||
|
|
||||||
|
|
||||||
$budgets = $this->repository->getActiveBudgets();
|
$budgets = $this->repository->getActiveBudgets();
|
||||||
$inactive = $this->repository->getInactiveBudgets();
|
$inactive = $this->repository->getInactiveBudgets();
|
||||||
$start = session('start', new Carbon);
|
|
||||||
$end = session('end', new Carbon);
|
|
||||||
$periodStart = $start->formatLocalized($this->monthAndDayFormat);
|
$periodStart = $start->formatLocalized($this->monthAndDayFormat);
|
||||||
$periodEnd = $end->formatLocalized($this->monthAndDayFormat);
|
$periodEnd = $end->formatLocalized($this->monthAndDayFormat);
|
||||||
$budgetInformation = $this->collectBudgetInformation($budgets, $start, $end);
|
$budgetInformation = $this->collectBudgetInformation($budgets, $start, $end);
|
||||||
@@ -184,9 +207,44 @@ class BudgetController extends Controller
|
|||||||
$spent = array_sum(array_column($budgetInformation, 'spent'));
|
$spent = array_sum(array_column($budgetInformation, 'spent'));
|
||||||
$budgeted = array_sum(array_column($budgetInformation, 'budgeted'));
|
$budgeted = array_sum(array_column($budgetInformation, 'budgeted'));
|
||||||
|
|
||||||
|
// select thing for last 12 periods:
|
||||||
|
$previousLoop = [];
|
||||||
|
$previousDate = clone $start;
|
||||||
|
$count = 0;
|
||||||
|
while ($count < 12) {
|
||||||
|
$previousDate->subDay();
|
||||||
|
$previousDate = Navigation::startOfPeriod($previousDate, $range);
|
||||||
|
$format = $previousDate->format('Y-m-d');
|
||||||
|
$previousLoop[$format] = Navigation::periodShow($previousDate, $range);
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// select thing for next 12 periods:
|
||||||
|
$nextLoop = [];
|
||||||
|
$nextDate = clone $end;
|
||||||
|
$nextDate->addDay();
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
|
while ($count < 12) {
|
||||||
|
$format = $nextDate->format('Y-m-d');
|
||||||
|
$nextLoop[$format] = Navigation::periodShow($nextDate, $range);
|
||||||
|
$nextDate = Navigation::endOfPeriod($nextDate, $range);
|
||||||
|
$count++;
|
||||||
|
$nextDate->addDay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// display info
|
||||||
|
$currentMonth = Navigation::periodShow($start, $range);
|
||||||
|
$nextText = Navigation::periodShow($next, $range);
|
||||||
|
$prevText = Navigation::periodShow($prev, $range);
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'budgets.index',
|
'budgets.index',
|
||||||
compact('available', 'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets', 'spent', 'budgeted')
|
compact(
|
||||||
|
'available', 'currentMonth', 'next', 'nextText', 'prev', 'prevText',
|
||||||
|
'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets',
|
||||||
|
'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +293,7 @@ class BudgetController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
@@ -244,7 +302,7 @@ class BudgetController extends Controller
|
|||||||
Log::info('Now at no-budget loop start.');
|
Log::info('Now at no-budget loop start.');
|
||||||
while ($count === 0 && $loop < 3) {
|
while ($count === 0 && $loop < 3) {
|
||||||
$loop++;
|
$loop++;
|
||||||
Log::info('Count is zero, search for journals.');
|
Log::info(sprintf('Count is zero, search for journals between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
||||||
@@ -252,7 +310,7 @@ class BudgetController extends Controller
|
|||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('/budgets/list/no-budget');
|
$journals->setPath('/budgets/list/no-budget');
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -260,7 +318,7 @@ class BudgetController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.without_budget_between',
|
'firefly.without_budget_between',
|
||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
@@ -299,7 +357,7 @@ class BudgetController extends Controller
|
|||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = session('first', Carbon::create()->startOfYear());
|
$start = session('first', Carbon::create()->startOfYear());
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$limits = $this->getLimits($budget, $start, $end);
|
$limits = $this->getLimits($budget, $start, $end);
|
||||||
$repetition = null;
|
$repetition = null;
|
||||||
@@ -326,11 +384,11 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
||||||
{
|
{
|
||||||
if ($budgetLimit->budget->id != $budget->id) {
|
if ($budgetLimit->budget->id !== $budget->id) {
|
||||||
throw new FireflyException('This budget limit is not part of this budget.');
|
throw new FireflyException('This budget limit is not part of this budget.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.budget_in_period', [
|
'firefly.budget_in_period', [
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
@@ -198,7 +199,7 @@ class CategoryController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
@@ -211,11 +212,11 @@ class CategoryController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount();
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount();
|
||||||
$collector->disableInternalFilter();
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('/categories/list/no-category');
|
$journals->setPath('/categories/list/no-category');
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -223,7 +224,7 @@ class CategoryController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.without_category_between',
|
'firefly.without_category_between',
|
||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
@@ -246,7 +247,7 @@ class CategoryController extends Controller
|
|||||||
// default values:
|
// default values:
|
||||||
$subTitle = $category->name;
|
$subTitle = $category->name;
|
||||||
$subTitleIcon = 'fa-bar-chart';
|
$subTitleIcon = 'fa-bar-chart';
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
@@ -294,11 +295,12 @@ class CategoryController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||||
->setCategory($category)->withBudgetInformation()->withCategoryInformation()->disableInternalFilter();
|
->setCategory($category)->withBudgetInformation()->withCategoryInformation();
|
||||||
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('categories/show/' . $category->id);
|
$journals->setPath('categories/show/' . $category->id);
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -306,7 +308,7 @@ class CategoryController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.journals_in_period_for_category',
|
'firefly.journals_in_period_for_category',
|
||||||
['name' => $category->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
|
['name' => $category->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
@@ -402,14 +404,17 @@ class CategoryController extends Controller
|
|||||||
// count journals without budget in this period:
|
// count journals without budget in this period:
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()->withOpposingAccount()->disableInternalFilter();
|
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()
|
||||||
|
->withOpposingAccount();
|
||||||
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$count = $collector->getJournals()->count();
|
$count = $collector->getJournals()->count();
|
||||||
|
|
||||||
// amount transferred
|
// amount transferred
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()
|
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()
|
||||||
->withOpposingAccount()->setTypes([TransactionType::TRANSFER])->disableInternalFilter();
|
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
|
||||||
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
|
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
|
||||||
|
|
||||||
// amount spent
|
// amount spent
|
||||||
@@ -458,7 +463,7 @@ class CategoryController extends Controller
|
|||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||||
$first = $repository->firstUseDate($category);
|
$first = $repository->firstUseDate($category);
|
||||||
if ($first->year == 1900) {
|
if ($first->year === 1900) {
|
||||||
$first = new Carbon;
|
$first = new Carbon;
|
||||||
}
|
}
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
@@ -488,7 +493,8 @@ class CategoryController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->setCategory($category)
|
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->setCategory($category)
|
||||||
->withOpposingAccount()->setTypes([TransactionType::TRANSFER])->disableInternalFilter();
|
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
|
||||||
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
|
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
|
||||||
|
|
||||||
$entries->push(
|
$entries->push(
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Controllers\Chart;
|
namespace FireflyIII\Http\Controllers\Chart;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
@@ -115,9 +114,8 @@ class AccountController extends Controller
|
|||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$startBalances = Steam::balancesByAccounts($accounts, $start);
|
||||||
$startBalances = Steam::balancesById($ids, $start);
|
$endBalances = Steam::balancesByAccounts($accounts, $end);
|
||||||
$endBalances = Steam::balancesById($ids, $end);
|
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
@@ -129,6 +127,7 @@ class AccountController extends Controller
|
|||||||
$chartData[$account->name] = $diff;
|
$chartData[$account->name] = $diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arsort($chartData);
|
arsort($chartData);
|
||||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
@@ -336,7 +335,7 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@@ -411,9 +410,8 @@ class AccountController extends Controller
|
|||||||
$accounts = $repository->getAccountsByType([AccountType::REVENUE]);
|
$accounts = $repository->getAccountsByType([AccountType::REVENUE]);
|
||||||
|
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$startBalances = Steam::balancesByAccounts($accounts, $start);
|
||||||
$startBalances = Steam::balancesById($ids, $start);
|
$endBalances = Steam::balancesByAccounts($accounts, $end);
|
||||||
$endBalances = Steam::balancesById($ids, $end);
|
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$id = $account->id;
|
$id = $account->id;
|
||||||
@@ -427,7 +425,7 @@ class AccountController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
arsort($chartData);
|
arsort($chartData);
|
||||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
|
$data = $this->generator->singleSet(strval(trans('firefly.earned')), $chartData);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
|
|||||||
use Navigation;
|
use Navigation;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetController
|
* Class BudgetController
|
||||||
@@ -123,7 +124,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function budgetLimit(Budget $budget, BudgetLimit $budgetLimit)
|
public function budgetLimit(Budget $budget, BudgetLimit $budgetLimit)
|
||||||
{
|
{
|
||||||
if ($budgetLimit->budget->id != $budget->id) {
|
if ($budgetLimit->budget->id !== $budget->id) {
|
||||||
throw new FireflyException('This budget limit is not part of this budget.');
|
throw new FireflyException('This budget limit is not part of this budget.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,12 +321,12 @@ class BudgetController extends Controller
|
|||||||
['label' => strval(trans('firefly.overspent')), 'entries' => [], 'type' => 'bar',],
|
['label' => strval(trans('firefly.overspent')), 'entries' => [], 'type' => 'bar',],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
// get relevant repetitions:
|
// get relevant repetitions:
|
||||||
$limits = $this->repository->getBudgetLimits($budget, $start, $end);
|
$limits = $this->repository->getBudgetLimits($budget, $start, $end);
|
||||||
$expenses = $this->getExpensesForBudget($limits, $budget, $start, $end);
|
$expenses = $this->getExpensesForBudget($limits, $budget, $start, $end);
|
||||||
|
|
||||||
foreach ($expenses as $name => $row) {
|
foreach ($expenses as $name => $row) {
|
||||||
$chartData[0]['entries'][$name] = $row['spent'];
|
$chartData[0]['entries'][$name] = $row['spent'];
|
||||||
$chartData[1]['entries'][$name] = $row['left'];
|
$chartData[1]['entries'][$name] = $row['left'];
|
||||||
@@ -529,9 +530,7 @@ class BudgetController extends Controller
|
|||||||
$rows = $this->spentInPeriodMulti($budget, $limits);
|
$rows = $this->spentInPeriodMulti($budget, $limits);
|
||||||
foreach ($rows as $name => $row) {
|
foreach ($rows as $name => $row) {
|
||||||
if (bccomp($row['spent'], '0') !== 0 || bccomp($row['left'], '0') !== 0) {
|
if (bccomp($row['spent'], '0') !== 0 || bccomp($row['left'], '0') !== 0) {
|
||||||
$return[$name]['spent'] = bcmul($row['spent'], '-1');
|
$return[$name] = $row;
|
||||||
$return[$name]['left'] = $row['left'];
|
|
||||||
$return[$name]['overspent'] = bcmul($row['overspent'], '-1');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($rows, $row);
|
unset($rows, $row);
|
||||||
@@ -563,6 +562,7 @@ class BudgetController extends Controller
|
|||||||
/** @var BudgetLimit $budgetLimit */
|
/** @var BudgetLimit $budgetLimit */
|
||||||
foreach ($limits as $budgetLimit) {
|
foreach ($limits as $budgetLimit) {
|
||||||
$expenses = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $budgetLimit->start_date, $budgetLimit->end_date);
|
$expenses = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $budgetLimit->start_date, $budgetLimit->end_date);
|
||||||
|
$expenses = Steam::positive($expenses);
|
||||||
|
|
||||||
if ($limits->count() > 1) {
|
if ($limits->count() > 1) {
|
||||||
$name = $budget->name . ' ' . trans(
|
$name = $budget->name . ' ' . trans(
|
||||||
@@ -578,10 +578,14 @@ class BudgetController extends Controller
|
|||||||
* left: amount of budget limit min spent, or 0 when < 0.
|
* left: amount of budget limit min spent, or 0 when < 0.
|
||||||
* spent: spent, or amount of budget limit when > amount
|
* spent: spent, or amount of budget limit when > amount
|
||||||
*/
|
*/
|
||||||
$amount = $budgetLimit->amount;
|
$amount = $budgetLimit->amount;
|
||||||
$left = bccomp(bcadd($amount, $expenses), '0') < 1 ? '0' : bcadd($amount, $expenses);
|
$leftInLimit = bcsub($amount, $expenses);
|
||||||
$spent = bccomp($expenses, $amount) === 1 ? $expenses : bcmul($amount, '-1');
|
$hasOverspent = bccomp($leftInLimit, '0') === -1;
|
||||||
$overspent = bccomp(bcadd($amount, $expenses), '0') < 1 ? bcadd($amount, $expenses) : '0';
|
|
||||||
|
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
|
||||||
|
$spent = $hasOverspent ? $amount : $expenses;
|
||||||
|
$overspent = $hasOverspent ? Steam::positive($leftInLimit) : '0';
|
||||||
|
|
||||||
$return[$name] = [
|
$return[$name] = [
|
||||||
'left' => $left,
|
'left' => $left,
|
||||||
'overspent' => $overspent,
|
'overspent' => $overspent,
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Support;
|
|
||||||
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
@@ -234,12 +236,15 @@ class BudgetReportController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setBudgets($budgets)->withOpposingAccount()->disableFilter();
|
->setBudgets($budgets)->withOpposingAccount();
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
$collector->removeFilter(TransferFilter::class);
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = Support::filterExpenses($transactions, $accountIds);
|
|
||||||
|
|
||||||
return $set;
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
$start = $repository->firstUseDate($category);
|
$start = $repository->firstUseDate($category);
|
||||||
|
|
||||||
if ($start->year == 1900) {
|
if ($start->year === 1900) {
|
||||||
$start = new Carbon;
|
$start = new Carbon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,10 +277,10 @@ class CategoryController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
|
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
|
||||||
{
|
{
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$start = Navigation::startOfPeriod($date, $range);
|
$start = Navigation::startOfPeriod($date, $range);
|
||||||
$end = Navigation::endOfPeriod($date, $range);
|
$end = Navigation::endOfPeriod($date, $range);
|
||||||
$data = $this->makePeriodChart($repository, $category, $start, $end);
|
$data = $this->makePeriodChart($repository, $category, $start, $end);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
@@ -336,9 +336,9 @@ class CategoryController extends Controller
|
|||||||
$sum = bcadd($spent, $earned);
|
$sum = bcadd($spent, $earned);
|
||||||
$label = trim(Navigation::periodShow($start, '1D'));
|
$label = trim(Navigation::periodShow($start, '1D'));
|
||||||
|
|
||||||
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'),12);
|
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
|
||||||
$chartData[1]['entries'][$label] = round($earned,12);
|
$chartData[1]['entries'][$label] = round($earned, 12);
|
||||||
$chartData[2]['entries'][$label] = round($sum,12);
|
$chartData[2]['entries'][$label] = round($sum, 12);
|
||||||
|
|
||||||
|
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
|
|||||||
@@ -16,9 +16,12 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
|
|
||||||
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@@ -244,7 +247,7 @@ class CategoryReportController extends Controller
|
|||||||
// remove all empty entries to prevent cluttering:
|
// remove all empty entries to prevent cluttering:
|
||||||
$newSet = [];
|
$newSet = [];
|
||||||
foreach ($chartData as $key => $entry) {
|
foreach ($chartData as $key => $entry) {
|
||||||
if (!array_sum($entry['entries']) == 0) {
|
if (!array_sum($entry['entries']) === 0) {
|
||||||
$newSet[$key] = $chartData[$key];
|
$newSet[$key] = $chartData[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,12 +274,15 @@ class CategoryReportController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setCategories($categories)->withOpposingAccount()->disableFilter();
|
->setCategories($categories)->withOpposingAccount();
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
$collector->removeFilter(TransferFilter::class);
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = MonthReportGenerator::filterExpenses($transactions, $accountIds);
|
|
||||||
|
|
||||||
return $set;
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -293,11 +299,13 @@ class CategoryReportController extends Controller
|
|||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setCategories($categories)->withOpposingAccount();
|
->setCategories($categories)->withOpposingAccount();
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = MonthReportGenerator::filterIncome($transactions, $accountIds);
|
|
||||||
|
|
||||||
return $set;
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(NegativeAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,11 +67,10 @@ class ReportController extends Controller
|
|||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
while ($current < $end) {
|
while ($current < $end) {
|
||||||
$balances = Steam::balancesById($ids, $current);
|
$balances = Steam::balancesByAccounts($accounts, $current);
|
||||||
$sum = $this->arraySum($balances);
|
$sum = $this->arraySum($balances);
|
||||||
$label = $current->formatLocalized(strval(trans('config.month_and_day')));
|
$label = $current->formatLocalized(strval(trans('config.month_and_day')));
|
||||||
$chartData[$label] = $sum;
|
$chartData[$label] = $sum;
|
||||||
@@ -104,7 +103,7 @@ class ReportController extends Controller
|
|||||||
$cache->addProperty($accounts);
|
$cache->addProperty($accounts);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
//return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
|
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
|
||||||
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
|
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
|
||||||
@@ -250,7 +249,7 @@ class ReportController extends Controller
|
|||||||
$cache->addProperty($accounts);
|
$cache->addProperty($accounts);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Tag\MonthReportGenerator;
|
|
||||||
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@@ -228,7 +231,7 @@ class TagReportController extends Controller
|
|||||||
// remove all empty entries to prevent cluttering:
|
// remove all empty entries to prevent cluttering:
|
||||||
$newSet = [];
|
$newSet = [];
|
||||||
foreach ($chartData as $key => $entry) {
|
foreach ($chartData as $key => $entry) {
|
||||||
if (!array_sum($entry['entries']) == 0) {
|
if (!array_sum($entry['entries']) === 0) {
|
||||||
$newSet[$key] = $chartData[$key];
|
$newSet[$key] = $chartData[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,12 +306,15 @@ class TagReportController extends Controller
|
|||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withOpposingAccount()->disableFilter();
|
->setTags($tags)->withOpposingAccount();
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
$collector->removeFilter(TransferFilter::class);
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = MonthReportGenerator::filterExpenses($transactions, $accountIds);
|
|
||||||
|
|
||||||
return $set;
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -325,11 +331,13 @@ class TagReportController extends Controller
|
|||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
->setTags($tags)->withOpposingAccount();
|
->setTags($tags)->withOpposingAccount();
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
|
||||||
$transactions = $collector->getJournals();
|
|
||||||
$set = MonthReportGenerator::filterIncome($transactions, $accountIds);
|
|
||||||
|
|
||||||
return $set;
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
|
$collector->addFilter(NegativeAmountFilter::class);
|
||||||
|
|
||||||
|
$transactions = $collector->getJournals();
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -356,4 +364,4 @@ class TagReportController extends Controller
|
|||||||
return $grouped;
|
return $grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
|
use Log;
|
||||||
|
use Route;
|
||||||
use Session;
|
use Session;
|
||||||
use URL;
|
use URL;
|
||||||
use View;
|
use View;
|
||||||
@@ -47,22 +50,50 @@ class Controller extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
// for transaction lists:
|
||||||
View::share('hideBudgets', false);
|
View::share('hideBudgets', false);
|
||||||
View::share('hideCategories', false);
|
View::share('hideCategories', false);
|
||||||
View::share('hideBills', false);
|
View::share('hideBills', false);
|
||||||
View::share('hideTags', false);
|
View::share('hideTags', false);
|
||||||
|
|
||||||
|
// is site a demo site?
|
||||||
$isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
$isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
||||||
View::share('IS_DEMO_SITE', $isDemoSite);
|
View::share('IS_DEMO_SITE', $isDemoSite);
|
||||||
View::share('DEMO_USERNAME', env('DEMO_USERNAME', ''));
|
View::share('DEMO_USERNAME', env('DEMO_USERNAME', ''));
|
||||||
View::share('DEMO_PASSWORD', env('DEMO_PASSWORD', ''));
|
View::share('DEMO_PASSWORD', env('DEMO_PASSWORD', ''));
|
||||||
|
|
||||||
// translations:
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
|
// translations for specific strings:
|
||||||
$this->monthFormat = (string)trans('config.month');
|
$this->monthFormat = (string)trans('config.month');
|
||||||
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
||||||
$this->dateTimeFormat = (string)trans('config.date_time');
|
$this->dateTimeFormat = (string)trans('config.date_time');
|
||||||
|
|
||||||
|
// get shown-intro-preference:
|
||||||
|
if (auth()->check()) {
|
||||||
|
// some routes have a "what" parameter, which indicates a special page:
|
||||||
|
$specificPage = is_null(Route::current()->parameter('what')) ? '' : '_' . Route::current()->parameter('what');
|
||||||
|
$page = str_replace('.', '_', Route::currentRouteName());
|
||||||
|
|
||||||
|
// indicator if user has seen the help for this page ( + special page):
|
||||||
|
$key = 'shown_demo_' . $page . $specificPage;
|
||||||
|
// is there an intro for this route?
|
||||||
|
$intro = config('intro.' . $page);
|
||||||
|
$specialIntro = config('intro.' . $page . $specificPage);
|
||||||
|
$shownDemo = true;
|
||||||
|
|
||||||
|
// either must be array and either must be > 0
|
||||||
|
if ((is_array($intro) || is_array($specialIntro)) && (count($intro) > 0 || count($specialIntro) > 0)) {
|
||||||
|
$shownDemo = Preferences::get($key, false)->data;
|
||||||
|
Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %d', $key, $shownDemo));
|
||||||
|
}
|
||||||
|
|
||||||
|
View::share('shownDemo', $shownDemo);
|
||||||
|
View::share('current_route_name', $page);
|
||||||
|
View::share('original_route_name', Route::currentRouteName());
|
||||||
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,62 +25,95 @@ use Response;
|
|||||||
*/
|
*/
|
||||||
class HelpController extends Controller
|
class HelpController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var HelpInterface */
|
||||||
|
private $help;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HelpController constructor.
|
* HelpController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
$this->help = app(HelpInterface::class);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param HelpInterface $help
|
|
||||||
* @param $route
|
* @param $route
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function show(HelpInterface $help, string $route)
|
public function show(string $route)
|
||||||
{
|
{
|
||||||
|
|
||||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
$html = $this->getHelpText($route, $language);
|
||||||
|
|
||||||
if (!$help->hasRoute($route)) {
|
return Response::json(['html' => $html]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
* @param string $language
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getHelpText(string $route, string $language): string
|
||||||
|
{
|
||||||
|
// get language and default variables.
|
||||||
|
|
||||||
|
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||||
|
|
||||||
|
// if no such route, log error and return default text.
|
||||||
|
if (!$this->help->hasRoute($route)) {
|
||||||
Log::error('No such route: ' . $route);
|
Log::error('No such route: ' . $route);
|
||||||
|
|
||||||
return Response::json($content);
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($help->inCache($route, $language)) {
|
// help content may be cached:
|
||||||
$content = $help->getFromCache($route, $language);
|
if ($this->help->inCache($route, $language)) {
|
||||||
|
$content = $this->help->getFromCache($route, $language);
|
||||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||||
|
|
||||||
return Response::json($content);
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $help->getFromGithub($route, $language);
|
// get help content from Github:
|
||||||
$notYourLanguage = '<p><em>' . strval(trans('firefly.help_may_not_be_your_language')) . '</em></p>';
|
$content = $this->help->getFromGithub($route, $language);
|
||||||
|
|
||||||
// get backup language content (try English):
|
// content will have 0 length when Github failed. Try en_US when it does:
|
||||||
if (strlen($content) === 0) {
|
if (strlen($content) === 0) {
|
||||||
$language = 'en_US';
|
$language = 'en_US';
|
||||||
if ($help->inCache($route, $language)) {
|
|
||||||
|
// also check cache first:
|
||||||
|
if ($this->help->inCache($route, $language)) {
|
||||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||||
$content = $notYourLanguage . $help->getFromCache($route, $language);
|
$content = $this->help->getFromCache($route, $language);
|
||||||
}
|
|
||||||
if (!$help->inCache($route, $language)) {
|
return $content;
|
||||||
$content = trim($notYourLanguage . $help->getFromGithub($route, $language));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$content = $this->help->getFromGithub($route, $language);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($content === $notYourLanguage) {
|
// help still empty?
|
||||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
if (strlen($content) !== 0) {
|
||||||
|
$this->help->putInCache($route, $language, $content);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$help->putInCache($route, $language, $content);
|
return '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||||
|
|
||||||
return Response::json($content);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
|
use Route as RouteFacade;
|
||||||
use Session;
|
use Session;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ class HomeController extends Controller
|
|||||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||||
$count = $repository->count($types);
|
$count = $repository->count($types);
|
||||||
|
|
||||||
if ($count == 0) {
|
if ($count === 0) {
|
||||||
return redirect(route('new-user.index'));
|
return redirect(route('new-user.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +122,6 @@ class HomeController extends Controller
|
|||||||
$start = session('start', Carbon::now()->startOfMonth());
|
$start = session('start', Carbon::now()->startOfMonth());
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$showTour = Preferences::get('tour', true)->data;
|
|
||||||
$accounts = $repository->getAccountsById($frontPage->data);
|
$accounts = $repository->getAccountsById($frontPage->data);
|
||||||
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
||||||
|
|
||||||
@@ -137,10 +138,34 @@ class HomeController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount')
|
'index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function routes()
|
||||||
|
{
|
||||||
|
$set = RouteFacade::getRoutes();
|
||||||
|
$ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.'];
|
||||||
|
/** @var Route $route */
|
||||||
|
foreach ($set as $route) {
|
||||||
|
$name = $route->getName();
|
||||||
|
if (!is_null($name) && in_array('GET', $route->methods()) && strlen($name) > 0) {
|
||||||
|
$found = false;
|
||||||
|
foreach ($ignore as $string) {
|
||||||
|
if (strpos($name, $string) !== false) {
|
||||||
|
$found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
echo 'touch ' . $route->getName() . '.md;';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ' ';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,32 +12,29 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Crypt;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Requests\ImportUploadRequest;
|
use FireflyIII\Http\Requests\ImportUploadRequest;
|
||||||
use FireflyIII\Import\ImportProcedureInterface;
|
use FireflyIII\Import\Configurator\ConfiguratorInterface;
|
||||||
use FireflyIII\Import\Setup\SetupInterface;
|
use FireflyIII\Import\Routine\ImportRoutine;
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response as LaravelResponse;
|
use Illuminate\Http\Response as LaravelResponse;
|
||||||
use Log;
|
use Log;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
|
||||||
use SplFileObject;
|
|
||||||
use Storage;
|
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportController
|
* Class ImportController.
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Http\Controllers
|
* @package FireflyIII\Http\Controllers
|
||||||
*/
|
*/
|
||||||
class ImportController extends Controller
|
class ImportController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var ImportJobRepositoryInterface */
|
||||||
|
public $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -48,7 +45,8 @@ class ImportController extends Controller
|
|||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
View::share('mainTitleIcon', 'fa-archive');
|
View::share('mainTitleIcon', 'fa-archive');
|
||||||
View::share('title', trans('firefly.import_data_full'));
|
View::share('title', trans('firefly.import_index_title'));
|
||||||
|
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -56,28 +54,7 @@ class ImportController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the last step before the import starts.
|
* This is step 3. This repeats until the job is configured.
|
||||||
*
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
|
||||||
*/
|
|
||||||
public function complete(ImportJob $job)
|
|
||||||
{
|
|
||||||
Log::debug('Now in complete()', ['job' => $job->key]);
|
|
||||||
if (!$this->jobInCorrectStep($job, 'complete')) {
|
|
||||||
return $this->redirectToCorrectStep($job);
|
|
||||||
}
|
|
||||||
$subTitle = trans('firefly.import_complete');
|
|
||||||
$subTitleIcon = 'fa-star';
|
|
||||||
|
|
||||||
return view('import.complete', compact('job', 'subTitle', 'subTitleIcon'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is step 3.
|
|
||||||
* This is the first step in configuring the job. It can only be executed
|
|
||||||
* when the job is set to "import_status_never_started".
|
|
||||||
*
|
*
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
@@ -86,37 +63,43 @@ class ImportController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function configure(ImportJob $job)
|
public function configure(ImportJob $job)
|
||||||
{
|
{
|
||||||
Log::debug('Now at start of configure()');
|
// create configuration class:
|
||||||
if (!$this->jobInCorrectStep($job, 'configure')) {
|
$configurator = $this->makeConfigurator($job);
|
||||||
return $this->redirectToCorrectStep($job);
|
|
||||||
}
|
|
||||||
|
|
||||||
// actual code
|
// is the job already configured?
|
||||||
$importer = $this->makeImporter($job);
|
if ($configurator->isJobConfigured()) {
|
||||||
$importer->configure();
|
$this->repository->updateStatus($job, 'configured');
|
||||||
$data = $importer->getConfigurationData();
|
|
||||||
$subTitle = trans('firefly.configure_import');
|
return redirect(route('import.status', [$job->key]));
|
||||||
|
}
|
||||||
|
$view = $configurator->getNextView();
|
||||||
|
$data = $configurator->getNextData();
|
||||||
|
$subTitle = trans('firefly.import_config_bread_crumb');
|
||||||
$subTitleIcon = 'fa-wrench';
|
$subTitleIcon = 'fa-wrench';
|
||||||
|
|
||||||
return view('import.' . $job->file_type . '.configure', compact('data', 'job', 'subTitle', 'subTitleIcon'));
|
return view($view, compact('data', 'job', 'subTitle', 'subTitleIcon'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a JSON file of the job's config and send it to the user.
|
* Generate a JSON file of the job's configuration and send it to the user.
|
||||||
*
|
*
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return LaravelResponse
|
||||||
*/
|
*/
|
||||||
public function download(ImportJob $job)
|
public function download(ImportJob $job)
|
||||||
{
|
{
|
||||||
Log::debug('Now in download()', ['job' => $job->key]);
|
Log::debug('Now in download()', ['job' => $job->key]);
|
||||||
$config = $job->configuration;
|
$config = $job->configuration;
|
||||||
|
|
||||||
|
// This is CSV import specific:
|
||||||
$config['column-roles-complete'] = false;
|
$config['column-roles-complete'] = false;
|
||||||
$config['column-mapping-complete'] = false;
|
$config['column-mapping-complete'] = false;
|
||||||
|
$config['initial-config-complete'] = false;
|
||||||
$config['delimiter'] = $config['delimiter'] === "\t" ? 'tab' : $config['delimiter'];
|
$config['delimiter'] = $config['delimiter'] === "\t" ? 'tab' : $config['delimiter'];
|
||||||
$result = json_encode($config, JSON_PRETTY_PRINT);
|
|
||||||
$name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
|
$result = json_encode($config, JSON_PRETTY_PRINT);
|
||||||
|
$name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
|
||||||
|
|
||||||
/** @var LaravelResponse $response */
|
/** @var LaravelResponse $response */
|
||||||
$response = response($result, 200);
|
$response = response($result, 200);
|
||||||
@@ -134,26 +117,6 @@ class ImportController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return View
|
|
||||||
*/
|
|
||||||
public function finished(ImportJob $job)
|
|
||||||
{
|
|
||||||
if (!$this->jobInCorrectStep($job, 'finished')) {
|
|
||||||
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', 'tagId'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is step 1. Upload a file.
|
* This is step 1. Upload a file.
|
||||||
*
|
*
|
||||||
@@ -161,8 +124,7 @@ class ImportController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
Log::debug('Now at index');
|
$subTitle = trans('firefly.import_index_sub_title');
|
||||||
$subTitle = trans('firefly.import_data_index');
|
|
||||||
$subTitleIcon = 'fa-home';
|
$subTitleIcon = 'fa-home';
|
||||||
$importFileTypes = [];
|
$importFileTypes = [];
|
||||||
$defaultImportType = config('firefly.default_import_format');
|
$defaultImportType = config('firefly.default_import_format');
|
||||||
@@ -175,42 +137,75 @@ class ImportController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This is step 2. It creates an Import Job. Stores the import.
|
||||||
|
*
|
||||||
|
* @param ImportUploadRequest $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
|
*/
|
||||||
|
public function initialize(ImportUploadRequest $request)
|
||||||
|
{
|
||||||
|
Log::debug('Now in initialize()');
|
||||||
|
|
||||||
|
// create import job:
|
||||||
|
$type = $request->get('import_file_type');
|
||||||
|
$job = $this->repository->create($type);
|
||||||
|
Log::debug('Created new job', ['key' => $job->key, 'id' => $job->id]);
|
||||||
|
|
||||||
|
// process file:
|
||||||
|
$this->repository->processFile($job, $request->files->get('import_file'));
|
||||||
|
|
||||||
|
// process config, if present:
|
||||||
|
if ($request->files->has('configuration_file')) {
|
||||||
|
$this->repository->processConfiguration($job, $request->files->get('configuration_file'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->repository->updateStatus($job, 'initialized');
|
||||||
|
|
||||||
|
return redirect(route('import.configure', [$job->key]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Show status of import job in JSON.
|
||||||
|
*
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function json(ImportJob $job)
|
public function json(ImportJob $job)
|
||||||
{
|
{
|
||||||
$result = [
|
$result = [
|
||||||
'showPercentage' => false,
|
'started' => false,
|
||||||
'started' => false,
|
'finished' => false,
|
||||||
'finished' => false,
|
'running' => false,
|
||||||
'running' => false,
|
'errors' => array_values($job->extended_status['errors']),
|
||||||
'errors' => $job->extended_status['errors'],
|
'percentage' => 0,
|
||||||
'percentage' => 0,
|
'show_percentage' => false,
|
||||||
'steps' => $job->extended_status['total_steps'],
|
'steps' => $job->extended_status['steps'],
|
||||||
'stepsDone' => $job->extended_status['steps_done'],
|
'done' => $job->extended_status['done'],
|
||||||
'statusText' => trans('firefly.import_status_' . $job->status),
|
'statusText' => trans('firefly.import_status_job_' . $job->status),
|
||||||
'finishedText' => '',
|
'status' => $job->status,
|
||||||
|
'finishedText' => '',
|
||||||
];
|
];
|
||||||
$percentage = 0;
|
|
||||||
if ($job->extended_status['total_steps'] !== 0) {
|
if ($job->extended_status['steps'] !== 0) {
|
||||||
$percentage = round(($job->extended_status['steps_done'] / $job->extended_status['total_steps']) * 100, 0);
|
$result['percentage'] = round(($job->extended_status['done'] / $job->extended_status['steps']) * 100, 0);
|
||||||
|
$result['show_percentage'] = true;
|
||||||
}
|
}
|
||||||
if ($job->status === 'import_complete') {
|
|
||||||
$tagId = $job->extended_status['importTag'];
|
if ($job->status === 'finished') {
|
||||||
|
$tagId = $job->extended_status['tag'];
|
||||||
/** @var TagRepositoryInterface $repository */
|
/** @var TagRepositoryInterface $repository */
|
||||||
$repository = app(TagRepositoryInterface::class);
|
$repository = app(TagRepositoryInterface::class);
|
||||||
$tag = $repository->find($tagId);
|
$tag = $repository->find($tagId);
|
||||||
$result['finished'] = true;
|
$result['finished'] = true;
|
||||||
$result['finishedText'] = trans('firefly.import_finished_link', ['link' => route('tags.show', [$tag->id]), 'tag' => $tag->tag]);
|
$result['finishedText'] = trans('firefly.import_status_finished_job', ['link' => route('tags.show', [$tag->id, 'all']), 'tag' => $tag->tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($job->status === 'import_running') {
|
if ($job->status === 'running') {
|
||||||
$result['started'] = true;
|
$result['started'] = true;
|
||||||
$result['running'] = true;
|
$result['running'] = true;
|
||||||
$result['showPercentage'] = true;
|
|
||||||
$result['percentage'] = $percentage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response::json($result);
|
return Response::json($result);
|
||||||
@@ -219,286 +214,82 @@ class ImportController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Step 4. Save the configuration.
|
* Step 4. Save the configuration.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
* @param ImportJobRepositoryInterface $repository
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
||||||
*/
|
|
||||||
public function postConfigure(Request $request, ImportJobRepositoryInterface $repository, ImportJob $job)
|
|
||||||
{
|
|
||||||
Log::debug('Now in postConfigure()', ['job' => $job->key]);
|
|
||||||
if (!$this->jobInCorrectStep($job, 'process')) {
|
|
||||||
return $this->redirectToCorrectStep($job);
|
|
||||||
}
|
|
||||||
Log::debug('Continue postConfigure()', ['job' => $job->key]);
|
|
||||||
|
|
||||||
// actual code
|
|
||||||
$importer = $this->makeImporter($job);
|
|
||||||
$data = $request->all();
|
|
||||||
$files = $request->files;
|
|
||||||
$importer->saveImportConfiguration($data, $files);
|
|
||||||
|
|
||||||
// update job:
|
|
||||||
$repository->updateStatus($job, 'import_configuration_saved');
|
|
||||||
|
|
||||||
// return redirect to settings.
|
|
||||||
// this could loop until the user is done.
|
|
||||||
return redirect(route('import.settings', [$job->key]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This step 6. Depending on the importer, this will process the
|
|
||||||
* settings given and store them.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function postSettings(Request $request, ImportJob $job)
|
public function postConfigure(Request $request, ImportJob $job)
|
||||||
{
|
{
|
||||||
Log::debug('Now in postSettings()', ['job' => $job->key]);
|
Log::debug('Now in postConfigure()', ['job' => $job->key]);
|
||||||
if (!$this->jobInCorrectStep($job, 'store-settings')) {
|
$configurator = $this->makeConfigurator($job);
|
||||||
return $this->redirectToCorrectStep($job);
|
|
||||||
}
|
// is the job already configured?
|
||||||
$importer = $this->makeImporter($job);
|
if ($configurator->isJobConfigured()) {
|
||||||
$importer->storeSettings($request);
|
return redirect(route('import.status', [$job->key]));
|
||||||
|
|
||||||
// return redirect to settings (for more settings perhaps)
|
|
||||||
return redirect(route('import.settings', [$job->key]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Step 5. Depending on the importer, this will show the user settings to
|
|
||||||
* fill in.
|
|
||||||
*
|
|
||||||
* @param ImportJobRepositoryInterface $repository
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @return View
|
|
||||||
*/
|
|
||||||
public function settings(ImportJobRepositoryInterface $repository, ImportJob $job)
|
|
||||||
{
|
|
||||||
Log::debug('Now in settings()', ['job' => $job->key]);
|
|
||||||
if (!$this->jobInCorrectStep($job, 'settings')) {
|
|
||||||
return $this->redirectToCorrectStep($job);
|
|
||||||
}
|
|
||||||
Log::debug('Continue in settings()');
|
|
||||||
$importer = $this->makeImporter($job);
|
|
||||||
$subTitle = trans('firefly.settings_for_import');
|
|
||||||
$subTitleIcon = 'fa-wrench';
|
|
||||||
|
|
||||||
// now show settings screen to user.
|
|
||||||
if ($importer->requireUserSettings()) {
|
|
||||||
Log::debug('Job requires user config.');
|
|
||||||
$data = $importer->getDataForSettings();
|
|
||||||
$view = $importer->getViewForSettings();
|
|
||||||
|
|
||||||
return view($view, compact('data', 'job', 'subTitle', 'subTitleIcon'));
|
|
||||||
}
|
|
||||||
Log::debug('Job does NOT require user config.');
|
|
||||||
|
|
||||||
$repository->updateStatus($job, 'settings_complete');
|
|
||||||
|
|
||||||
// if no more settings, save job and continue to process thing.
|
|
||||||
return redirect(route('import.complete', [$job->key]));
|
|
||||||
|
|
||||||
// ask the importer for the requested action.
|
|
||||||
// for example pick columns or map data.
|
|
||||||
// depends of course on the data in the job.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ImportProcedureInterface $importProcedure
|
|
||||||
* @param ImportJob $job
|
|
||||||
*/
|
|
||||||
public function start(ImportProcedureInterface $importProcedure, ImportJob $job)
|
|
||||||
{
|
|
||||||
set_time_limit(0);
|
|
||||||
if ($job->status == 'settings_complete') {
|
|
||||||
$importProcedure->runImport($job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the last step before the import starts.
|
|
||||||
*
|
|
||||||
* @param ImportJob $job
|
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
$subTitle = trans('firefly.import_status');
|
|
||||||
$subTitleIcon = 'fa-star';
|
|
||||||
|
|
||||||
return view('import.status', compact('job', 'subTitle', 'subTitleIcon'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is step 2. It creates an Import Job. Stores the import.
|
|
||||||
*
|
|
||||||
* @param ImportUploadRequest $request
|
|
||||||
* @param ImportJobRepositoryInterface $repository
|
|
||||||
* @param UserRepositoryInterface $userRepository
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
||||||
*/
|
|
||||||
public function upload(ImportUploadRequest $request, ImportJobRepositoryInterface $repository, UserRepositoryInterface $userRepository)
|
|
||||||
{
|
|
||||||
Log::debug('Now in upload()');
|
|
||||||
// create import job:
|
|
||||||
$type = $request->get('import_file_type');
|
|
||||||
$job = $repository->create($type);
|
|
||||||
Log::debug('Created new job', ['key' => $job->key, 'id' => $job->id]);
|
|
||||||
|
|
||||||
/** @var UploadedFile $upload */
|
|
||||||
$upload = $request->files->get('import_file');
|
|
||||||
$newName = $job->key . '.upload';
|
|
||||||
$uploaded = new SplFileObject($upload->getRealPath());
|
|
||||||
$content = $uploaded->fread($uploaded->getSize());
|
|
||||||
$contentEncrypted = Crypt::encrypt($content);
|
|
||||||
$disk = Storage::disk('upload');
|
|
||||||
|
|
||||||
// user is demo user, replace upload with prepared file.
|
|
||||||
if ($userRepository->hasRole(auth()->user(), 'demo')) {
|
|
||||||
$stubsDisk = Storage::disk('stubs');
|
|
||||||
$content = $stubsDisk->get('demo-import.csv');
|
|
||||||
$contentEncrypted = Crypt::encrypt($content);
|
|
||||||
$disk->put($newName, $contentEncrypted);
|
|
||||||
Log::debug('Replaced upload with demo file.');
|
|
||||||
|
|
||||||
// also set up prepared configuration.
|
|
||||||
$configuration = json_decode($stubsDisk->get('demo-configuration.json'), true);
|
|
||||||
$repository->setConfiguration($job, $configuration);
|
|
||||||
Log::debug('Set configuration for demo user', $configuration);
|
|
||||||
|
|
||||||
// also flash info
|
|
||||||
Session::flash('info', trans('demo.import-configure-security'));
|
|
||||||
}
|
|
||||||
if (!$userRepository->hasRole(auth()->user(), 'demo')) {
|
|
||||||
// user is not demo, process original upload:
|
|
||||||
$disk->put($newName, $contentEncrypted);
|
|
||||||
Log::debug('Uploaded file', ['name' => $upload->getClientOriginalName(), 'size' => $upload->getSize(), 'mime' => $upload->getClientMimeType()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// store configuration file's content into the job's configuration thing. Otherwise, leave it empty.
|
|
||||||
// demo user's configuration upload is ignored completely.
|
|
||||||
if ($request->files->has('configuration_file') && !auth()->user()->hasRole('demo')) {
|
|
||||||
/** @var UploadedFile $configFile */
|
|
||||||
$configFile = $request->files->get('configuration_file');
|
|
||||||
Log::debug(
|
|
||||||
'Uploaded configuration file',
|
|
||||||
['name' => $configFile->getClientOriginalName(), 'size' => $configFile->getSize(), 'mime' => $configFile->getClientMimeType()]
|
|
||||||
);
|
|
||||||
|
|
||||||
$configFileObject = new SplFileObject($configFile->getRealPath());
|
|
||||||
$configRaw = $configFileObject->fread($configFileObject->getSize());
|
|
||||||
$configuration = json_decode($configRaw, true);
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
if (!is_null($configuration) && is_array($configuration)) {
|
|
||||||
Log::debug('Found configuration', $configuration);
|
|
||||||
$repository->setConfiguration($job, $configuration);
|
|
||||||
}
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
}
|
||||||
|
$data = $request->all();
|
||||||
|
$configurator->configureJob($data);
|
||||||
|
|
||||||
|
// return to configure
|
||||||
return redirect(route('import.configure', [$job->key]));
|
return redirect(route('import.configure', [$job->key]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
* @param string $method
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
private function jobInCorrectStep(ImportJob $job, string $method): bool
|
public function start(ImportJob $job)
|
||||||
{
|
{
|
||||||
Log::debug('Now in jobInCorrectStep()', ['job' => $job->key, 'method' => $method]);
|
/** @var ImportRoutine $routine */
|
||||||
switch ($method) {
|
$routine = app(ImportRoutine::class);
|
||||||
case 'configure':
|
$routine->setJob($job);
|
||||||
case 'process':
|
$result = $routine->run();
|
||||||
return $job->status === 'import_status_never_started';
|
if ($result) {
|
||||||
case 'settings':
|
return Response::json(['run' => 'ok']);
|
||||||
case 'store-settings':
|
|
||||||
Log::debug(sprintf('Job %d with key %s has status %s', $job->id, $job->key, $job->status));
|
|
||||||
|
|
||||||
return $job->status === 'import_configuration_saved';
|
|
||||||
case 'finished':
|
|
||||||
return $job->status === 'import_complete';
|
|
||||||
case 'complete':
|
|
||||||
return $job->status === 'settings_complete';
|
|
||||||
case 'status':
|
|
||||||
return ($job->status === 'settings_complete') || ($job->status === 'import_running');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // @codeCoverageIgnore
|
throw new FireflyException('Job did not complete succesfully.');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
* @return SetupInterface
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
private function makeImporter(ImportJob $job): SetupInterface
|
public function status(ImportJob $job)
|
||||||
{
|
{
|
||||||
// create proper importer (depends on job)
|
$statuses = ['configured', 'running', 'finished'];
|
||||||
$type = strtolower($job->file_type);
|
if (!in_array($job->status, $statuses)) {
|
||||||
|
return redirect(route('import.configure', [$job->key]));
|
||||||
// validate type:
|
|
||||||
$validTypes = array_keys(config('firefly.import_formats'));
|
|
||||||
|
|
||||||
|
|
||||||
if (in_array($type, $validTypes)) {
|
|
||||||
/** @var SetupInterface $importer */
|
|
||||||
$importer = app('FireflyIII\Import\Setup\\' . ucfirst($type) . 'Setup');
|
|
||||||
$importer->setJob($job);
|
|
||||||
|
|
||||||
return $importer;
|
|
||||||
}
|
}
|
||||||
throw new FireflyException(sprintf('"%s" is not a valid file type', $type)); // @codeCoverageIgnore
|
$subTitle = trans('firefly.import_status_sub_title');
|
||||||
|
$subTitleIcon = 'fa-star';
|
||||||
|
|
||||||
|
return view('import.status', compact('job', 'subTitle', 'subTitleIcon'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ImportJob $job
|
* @param ImportJob $job
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return ConfiguratorInterface
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
private function redirectToCorrectStep(ImportJob $job)
|
private function makeConfigurator(ImportJob $job): ConfiguratorInterface
|
||||||
{
|
{
|
||||||
Log::debug('Now in redirectToCorrectStep()', ['job' => $job->key]);
|
$type = $job->file_type;
|
||||||
switch ($job->status) {
|
$key = sprintf('firefly.import_configurators.%s', $type);
|
||||||
case 'import_status_never_started':
|
$className = config($key);
|
||||||
Log::debug('Will redirect to configure()');
|
if (is_null($className)) {
|
||||||
|
throw new FireflyException('Cannot find configurator class for this job.'); // @codeCoverageIgnore
|
||||||
return redirect(route('import.configure', [$job->key]));
|
|
||||||
case 'import_configuration_saved':
|
|
||||||
Log::debug('Will redirect to settings()');
|
|
||||||
|
|
||||||
return redirect(route('import.settings', [$job->key]));
|
|
||||||
case 'settings_complete':
|
|
||||||
Log::debug('Will redirect to complete()');
|
|
||||||
|
|
||||||
return redirect(route('import.complete', [$job->key]));
|
|
||||||
case 'import_complete':
|
|
||||||
Log::debug('Will redirect to finished()');
|
|
||||||
|
|
||||||
return redirect(route('import.finished', [$job->key]));
|
|
||||||
}
|
}
|
||||||
|
/** @var ConfiguratorInterface $configurator */
|
||||||
|
$configurator = app($className);
|
||||||
|
$configurator->setJob($job);
|
||||||
|
|
||||||
throw new FireflyException('Cannot redirect for job state ' . $job->status); // @codeCoverageIgnore
|
|
||||||
|
|
||||||
|
return $configurator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class JavascriptController extends Controller
|
|||||||
* @param AccountRepositoryInterface $repository
|
* @param AccountRepositoryInterface $repository
|
||||||
* @param CurrencyRepositoryInterface $currencyRepository
|
* @param CurrencyRepositoryInterface $currencyRepository
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
|
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
|
||||||
{
|
{
|
||||||
@@ -63,7 +63,7 @@ class JavascriptController extends Controller
|
|||||||
/**
|
/**
|
||||||
* @param CurrencyRepositoryInterface $repository
|
* @param CurrencyRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function currencies(CurrencyRepositoryInterface $repository)
|
public function currencies(CurrencyRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
@@ -71,8 +71,8 @@ class JavascriptController extends Controller
|
|||||||
$data = ['currencies' => [],];
|
$data = ['currencies' => [],];
|
||||||
/** @var TransactionCurrency $currency */
|
/** @var TransactionCurrency $currency */
|
||||||
foreach ($currencies as $currency) {
|
foreach ($currencies as $currency) {
|
||||||
$currencyId = $currency->id;
|
$currencyId = $currency->id;
|
||||||
$entry = ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol];
|
$entry = ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol];
|
||||||
$data['currencies'][$currencyId] = $entry;
|
$data['currencies'][$currencyId] = $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class ExchangeController extends Controller
|
|||||||
/** @var CurrencyRepositoryInterface $repository */
|
/** @var CurrencyRepositoryInterface $repository */
|
||||||
$repository = app(CurrencyRepositoryInterface::class);
|
$repository = app(CurrencyRepositoryInterface::class);
|
||||||
$rate = $repository->getExchangeRate($fromCurrency, $toCurrency, $date);
|
$rate = $repository->getExchangeRate($fromCurrency, $toCurrency, $date);
|
||||||
$amount = null;
|
|
||||||
if (is_null($rate->id)) {
|
if (is_null($rate->id)) {
|
||||||
Log::debug(sprintf('No cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d')));
|
Log::debug(sprintf('No cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d')));
|
||||||
$preferred = env('EXCHANGE_RATE_SERVICE', config('firefly.preferred_exchange_service'));
|
$preferred = env('EXCHANGE_RATE_SERVICE', config('firefly.preferred_exchange_service'));
|
||||||
@@ -63,4 +62,4 @@ class ExchangeController extends Controller
|
|||||||
return Response::json($return);
|
return Response::json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
166
app/Http/Controllers/Json/IntroController.php
Normal file
166
app/Http/Controllers/Json/IntroController.php
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* IntroController.php
|
||||||
|
* Copyright (c) 2017 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\Json;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
|
use Log;
|
||||||
|
use Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class IntroController
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Http\Controllers\Json
|
||||||
|
*/
|
||||||
|
class IntroController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
* @param string $specificPage
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function getIntroSteps(string $route, string $specificPage = '')
|
||||||
|
{
|
||||||
|
$steps = $this->getBasicSteps($route);
|
||||||
|
$specificSteps = $this->getSpecificSteps($route, $specificPage);
|
||||||
|
if (count($specificSteps) === 0) {
|
||||||
|
return Response::json($steps);
|
||||||
|
}
|
||||||
|
if ($this->hasOutroStep($route)) {
|
||||||
|
// save last step:
|
||||||
|
$lastStep = $steps[count($steps) - 1];
|
||||||
|
// remove last step:
|
||||||
|
array_pop($steps);
|
||||||
|
// merge arrays and add last step again
|
||||||
|
$steps = array_merge($steps, $specificSteps);
|
||||||
|
$steps[] = $lastStep;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!$this->hasOutroStep($route)) {
|
||||||
|
$steps = array_merge($steps, $specificSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response::json($steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasOutroStep(string $route): bool
|
||||||
|
{
|
||||||
|
$routeKey = str_replace('.', '_', $route);
|
||||||
|
$elements = config(sprintf('intro.%s', $routeKey));
|
||||||
|
if (!is_array($elements)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$keys = array_keys($elements);
|
||||||
|
|
||||||
|
return in_array('outro', $keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
* @param string $specialPage
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function postEnable(string $route, string $specialPage = '')
|
||||||
|
{
|
||||||
|
$route = str_replace('.', '_', $route);
|
||||||
|
$key = 'shown_demo_' . $route;
|
||||||
|
if ($specialPage !== '') {
|
||||||
|
$key .= '_' . $specialPage;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||||
|
Preferences::set($key, false);
|
||||||
|
|
||||||
|
return Response::json(['message' => trans('firefly.intro_boxes_after_refresh')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
* @param string $specialPage
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function postFinished(string $route, string $specialPage = '')
|
||||||
|
{
|
||||||
|
$key = 'shown_demo_' . $route;
|
||||||
|
if ($specialPage !== '') {
|
||||||
|
$key .= '_' . $specialPage;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||||
|
Preferences::set($key, true);
|
||||||
|
|
||||||
|
return Response::json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getBasicSteps(string $route): array
|
||||||
|
{
|
||||||
|
$routeKey = str_replace('.', '_', $route);
|
||||||
|
$elements = config(sprintf('intro.%s', $routeKey));
|
||||||
|
$steps = [];
|
||||||
|
if (is_array($elements) && count($elements) > 0) {
|
||||||
|
foreach ($elements as $key => $options) {
|
||||||
|
$currentStep = $options;
|
||||||
|
|
||||||
|
// get the text:
|
||||||
|
$currentStep['intro'] = trans('intro.' . $route . '_' . $key);
|
||||||
|
|
||||||
|
|
||||||
|
// save in array:
|
||||||
|
$steps[] = $currentStep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $route
|
||||||
|
* @param string $specificPage
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getSpecificSteps(string $route, string $specificPage): array
|
||||||
|
{
|
||||||
|
$steps = [];
|
||||||
|
|
||||||
|
// user is on page with specific instructions:
|
||||||
|
if (strlen($specificPage) > 0) {
|
||||||
|
$routeKey = str_replace('.', '_', $route);
|
||||||
|
$elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
|
||||||
|
if (is_array($elements) && count($elements) > 0) {
|
||||||
|
foreach ($elements as $key => $options) {
|
||||||
|
$currentStep = $options;
|
||||||
|
|
||||||
|
// get the text:
|
||||||
|
$currentStep['intro'] = trans('intro.' . $route . '_' . $specificPage . '_' . $key);
|
||||||
|
|
||||||
|
// save in array:
|
||||||
|
$steps[] = $currentStep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,12 +15,10 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Amount;
|
use Amount;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
@@ -28,7 +26,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Preferences;
|
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,10 +113,11 @@ class JsonController extends Controller
|
|||||||
* Since both this method and the chart use the exact same data, we can suffice
|
* Since both this method and the chart use the exact same data, we can suffice
|
||||||
* with calling the one method in the bill repository that will get this amount.
|
* with calling the one method in the bill repository that will get this amount.
|
||||||
*/
|
*/
|
||||||
$amount = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
$amount = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||||
$amount = bcmul($amount, '-1');
|
$amount = bcmul($amount, '-1');
|
||||||
|
$currency = Amount::getDefaultCurrency();
|
||||||
|
|
||||||
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$data = ['box' => 'bills-paid', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
@@ -131,19 +129,19 @@ class JsonController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function boxBillsUnpaid(BillRepositoryInterface $repository)
|
public function boxBillsUnpaid(BillRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$start = session('start', Carbon::now()->startOfMonth());
|
$start = session('start', Carbon::now()->startOfMonth());
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$amount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
$amount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||||
$data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$currency = Amount::getDefaultCurrency();
|
||||||
|
$data = ['box' => 'bills-unpaid', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AccountTaskerInterface $accountTasker
|
|
||||||
* @param AccountRepositoryInterface $repository
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
* @internal param AccountTaskerInterface $accountTasker
|
||||||
|
* @internal param AccountRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function boxIn()
|
public function boxIn()
|
||||||
@@ -167,18 +165,19 @@ class JsonController extends Controller
|
|||||||
->setTypes([TransactionType::DEPOSIT])
|
->setTypes([TransactionType::DEPOSIT])
|
||||||
->withOpposingAccount();
|
->withOpposingAccount();
|
||||||
|
|
||||||
$amount = strval($collector->getJournals()->sum('transaction_amount'));
|
$amount = strval($collector->getJournals()->sum('transaction_amount'));
|
||||||
$data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$currency = Amount::getDefaultCurrency();
|
||||||
|
$data = ['box' => 'in', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AccountTaskerInterface $accountTasker
|
|
||||||
* @param AccountRepositoryInterface $repository
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
* @internal param AccountTaskerInterface $accountTasker
|
||||||
|
* @internal param AccountRepositoryInterface $repository
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function boxOut()
|
public function boxOut()
|
||||||
{
|
{
|
||||||
@@ -200,9 +199,9 @@ class JsonController extends Controller
|
|||||||
$collector->setAllAssetAccounts()->setRange($start, $end)
|
$collector->setAllAssetAccounts()->setRange($start, $end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL])
|
->setTypes([TransactionType::WITHDRAWAL])
|
||||||
->withOpposingAccount();
|
->withOpposingAccount();
|
||||||
$amount = strval($collector->getJournals()->sum('transaction_amount'));
|
$amount = strval($collector->getJournals()->sum('transaction_amount'));
|
||||||
|
$currency = Amount::getDefaultCurrency();
|
||||||
$data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
$data = ['box' => 'out', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
@@ -236,16 +235,6 @@ class JsonController extends Controller
|
|||||||
return Response::json($return);
|
return Response::json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
|
||||||
public function endTour()
|
|
||||||
{
|
|
||||||
Preferences::set('tour', false);
|
|
||||||
|
|
||||||
return Response::json('true');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a JSON list of all beneficiaries.
|
* Returns a JSON list of all beneficiaries.
|
||||||
*
|
*
|
||||||
@@ -292,34 +281,6 @@ class JsonController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function tour()
|
|
||||||
{
|
|
||||||
$pref = Preferences::get('tour', true);
|
|
||||||
if (!$pref) {
|
|
||||||
throw new FireflyException('Cannot find preference for tour. Exit.'); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
$headers = ['main-content', 'sidebar-toggle', 'account-menu', 'budget-menu', 'report-menu', 'transaction-menu', 'option-menu', 'main-content-end'];
|
|
||||||
$steps = [];
|
|
||||||
foreach ($headers as $header) {
|
|
||||||
$steps[] = [
|
|
||||||
'element' => '#' . $header,
|
|
||||||
'title' => trans('help.' . $header . '-title'),
|
|
||||||
'content' => trans('help.' . $header . '-text'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$steps[0]['orphan'] = true;// orphan and backdrop for first element.
|
|
||||||
$steps[0]['backdrop'] = true;
|
|
||||||
$steps[1]['placement'] = 'left';// sidebar position left:
|
|
||||||
$steps[7]['orphan'] = true; // final in the center again.
|
|
||||||
$steps[7]['backdrop'] = true;
|
|
||||||
$template = view('json.tour')->render();
|
|
||||||
|
|
||||||
return Response::json(['steps' => $steps, 'template' => $template]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param JournalCollectorInterface $collector
|
* @param JournalCollectorInterface $collector
|
||||||
* @param string $what
|
* @param string $what
|
||||||
@@ -364,7 +325,7 @@ class JsonController extends Controller
|
|||||||
$keys = array_keys(config('firefly.rule-triggers'));
|
$keys = array_keys(config('firefly.rule-triggers'));
|
||||||
$triggers = [];
|
$triggers = [];
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if ($key != 'user_action') {
|
if ($key !== 'user_action') {
|
||||||
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class NewUserController extends Controller
|
|||||||
View::share('title', trans('firefly.welcome'));
|
View::share('title', trans('firefly.welcome'));
|
||||||
View::share('mainTitleIcon', 'fa-fire');
|
View::share('mainTitleIcon', 'fa-fire');
|
||||||
|
|
||||||
|
|
||||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||||
$count = $repository->count($types);
|
$count = $repository->count($types);
|
||||||
|
|
||||||
@@ -74,30 +73,13 @@ class NewUserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository)
|
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$count = 1;
|
|
||||||
// create normal asset account:
|
// create normal asset account:
|
||||||
$this->createAssetAccount($request, $repository);
|
$this->createAssetAccount($request, $repository);
|
||||||
|
|
||||||
// create savings account
|
// create savings account
|
||||||
$savingBalance = strval($request->get('savings_balance')) === '' ? '0' : strval($request->get('savings_balance'));
|
$this->createSavingsAccount($request, $repository);
|
||||||
if (bccomp($savingBalance, '0') !== 0) {
|
|
||||||
$this->createSavingsAccount($request, $repository);
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Session::flash('success', strval(trans('firefly.stored_new_accounts_new_user')));
|
||||||
// create credit card.
|
|
||||||
$limit = strval($request->get('credit_card_limit')) === '' ? '0' : strval($request->get('credit_card_limit'));
|
|
||||||
if (bccomp($limit, '0') !== 0) {
|
|
||||||
$this->storeCreditCard($request, $repository);
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
$message = strval(trans('firefly.stored_new_accounts_new_user'));
|
|
||||||
if ($count == 1) {
|
|
||||||
$message = strval(trans('firefly.stored_new_account_new_user'));
|
|
||||||
}
|
|
||||||
|
|
||||||
Session::flash('success', $message);
|
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
return redirect(route('index'));
|
return redirect(route('index'));
|
||||||
@@ -112,15 +94,15 @@ class NewUserController extends Controller
|
|||||||
private function createAssetAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
|
private function createAssetAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
|
||||||
{
|
{
|
||||||
$assetAccount = [
|
$assetAccount = [
|
||||||
'name' => $request->get('bank_name'),
|
'name' => $request->get('bank_name'),
|
||||||
'iban' => null,
|
'iban' => null,
|
||||||
'accountType' => 'asset',
|
'accountType' => 'asset',
|
||||||
'virtualBalance' => 0,
|
'virtualBalance' => 0,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'accountRole' => 'defaultAsset',
|
'accountRole' => 'defaultAsset',
|
||||||
'openingBalance' => round($request->input('bank_balance'), 12),
|
'openingBalance' => round($request->input('bank_balance'), 12),
|
||||||
'openingBalanceDate' => new Carbon,
|
'openingBalanceDate' => new Carbon,
|
||||||
'openingBalanceCurrency' => intval($request->input('amount_currency_id_bank_balance')),
|
'currency_id' => intval($request->input('amount_currency_id_bank_balance')),
|
||||||
];
|
];
|
||||||
|
|
||||||
$repository->store($assetAccount);
|
$repository->store($assetAccount);
|
||||||
@@ -137,44 +119,19 @@ class NewUserController extends Controller
|
|||||||
private function createSavingsAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
|
private function createSavingsAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
|
||||||
{
|
{
|
||||||
$savingsAccount = [
|
$savingsAccount = [
|
||||||
'name' => $request->get('bank_name') . ' savings account',
|
'name' => $request->get('bank_name') . ' savings account',
|
||||||
'iban' => null,
|
'iban' => null,
|
||||||
'accountType' => 'asset',
|
'accountType' => 'asset',
|
||||||
'virtualBalance' => 0,
|
'virtualBalance' => 0,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'accountRole' => 'savingAsset',
|
'accountRole' => 'savingAsset',
|
||||||
'openingBalance' => round($request->input('savings_balance'), 12),
|
'openingBalance' => round($request->input('savings_balance'), 12),
|
||||||
'openingBalanceDate' => new Carbon,
|
'openingBalanceDate' => new Carbon,
|
||||||
'openingBalanceCurrency' => intval($request->input('amount_currency_id_savings_balance')),
|
'currency_id' => intval($request->input('amount_currency_id_savings_balance')),
|
||||||
];
|
];
|
||||||
$repository->store($savingsAccount);
|
$repository->store($savingsAccount);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param NewUserFormRequest $request
|
|
||||||
* @param AccountRepositoryInterface $repository
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function storeCreditCard(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
|
|
||||||
{
|
|
||||||
$creditAccount = [
|
|
||||||
'name' => 'Credit card',
|
|
||||||
'iban' => null,
|
|
||||||
'accountType' => 'asset',
|
|
||||||
'virtualBalance' => round($request->get('credit_card_limit'), 12),
|
|
||||||
'active' => true,
|
|
||||||
'accountRole' => 'ccAsset',
|
|
||||||
'openingBalance' => null,
|
|
||||||
'openingBalanceDate' => null,
|
|
||||||
'openingBalanceCurrency' => intval($request->input('amount_currency_id_credit_card_limit')),
|
|
||||||
'ccType' => 'monthlyFull',
|
|
||||||
'ccMonthlyPaymentDate' => Carbon::now()->year . '-01-01',
|
|
||||||
];
|
|
||||||
$repository->store($creditAccount);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class PiggyBankController extends Controller
|
|||||||
/** @var Carbon $date */
|
/** @var Carbon $date */
|
||||||
$date = session('end', Carbon::now()->endOfMonth());
|
$date = session('end', Carbon::now()->endOfMonth());
|
||||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount?? '0';
|
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0';
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
|
|
||||||
@@ -276,18 +276,29 @@ class PiggyBankController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$amount = $request->get('amount');
|
$amount = $request->get('amount');
|
||||||
|
$currency = Amount::getDefaultCurrency();
|
||||||
if ($repository->canAddAmount($piggyBank, $amount)) {
|
if ($repository->canAddAmount($piggyBank, $amount)) {
|
||||||
$repository->addAmount($piggyBank, $amount);
|
$repository->addAmount($piggyBank, $amount);
|
||||||
Session::flash('success', strval(trans('firefly.added_amount_to_piggy', ['amount' => Amount::format($amount, false), 'name' => $piggyBank->name])));
|
Session::flash(
|
||||||
|
'success', strval(
|
||||||
|
trans(
|
||||||
|
'firefly.added_amount_to_piggy',
|
||||||
|
['amount' => Amount::formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
return redirect(route('piggy-banks.index'));
|
return redirect(route('piggy-banks.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.');
|
Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.');
|
||||||
Session::flash('error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
|
Session::flash(
|
||||||
|
'error', strval(
|
||||||
|
trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return redirect(route('piggy-banks.index'));
|
return redirect(route('piggy-banks.index'));
|
||||||
}
|
}
|
||||||
@@ -301,11 +312,13 @@ class PiggyBankController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$amount = $request->get('amount');
|
$amount = $request->get('amount');
|
||||||
|
$currency = Amount::getDefaultCurrency();
|
||||||
if ($repository->canRemoveAmount($piggyBank, $amount)) {
|
if ($repository->canRemoveAmount($piggyBank, $amount)) {
|
||||||
$repository->removeAmount($piggyBank, $amount);
|
$repository->removeAmount($piggyBank, $amount);
|
||||||
Session::flash(
|
Session::flash(
|
||||||
'success', strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::format($amount, false), 'name' => $piggyBank->name]))
|
'success',
|
||||||
|
strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => $piggyBank->name]))
|
||||||
);
|
);
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
@@ -314,7 +327,11 @@ class PiggyBankController extends Controller
|
|||||||
|
|
||||||
$amount = strval(round($request->get('amount'), 12));
|
$amount = strval(round($request->get('amount'), 12));
|
||||||
|
|
||||||
Session::flash('error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
|
Session::flash(
|
||||||
|
'error', strval(
|
||||||
|
trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return redirect(route('piggy-banks.index'));
|
return redirect(route('piggy-banks.index'));
|
||||||
}
|
}
|
||||||
@@ -380,7 +397,7 @@ class PiggyBankController extends Controller
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect($this->getPreviousUri('piggy-banks.edit.uri'));
|
return redirect($this->getPreviousUri('piggy-banks.create.uri'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,12 +56,8 @@ class PreferencesController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function code(Google2FA $google2fa)
|
public function code(Google2FA $google2fa)
|
||||||
{
|
{
|
||||||
$domain = $this->getDomain();
|
$domain = $this->getDomain();
|
||||||
$secretKey = 'FIREFLYIII';
|
$secret = $google2fa->generateSecretKey(16);
|
||||||
$secretKey = str_pad($secretKey, intval(pow(2, ceil(log(strlen($secretKey), 2)))), 'X');
|
|
||||||
|
|
||||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
|
||||||
$secret = $google2fa->generateSecretKey(16, $secretKey);
|
|
||||||
Session::flash('two-factor-secret', $secret);
|
Session::flash('two-factor-secret', $secret);
|
||||||
$image = $google2fa->getQRCodeInline('Firefly III at ' . $domain, auth()->user()->email, $secret, 150);
|
$image = $google2fa->getQRCodeInline('Firefly III at ' . $domain, auth()->user()->email, $secret, 150);
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class CategoryController extends Controller
|
|||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
|
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
|
||||||
if (bccomp($spent, '0') !== 0) {
|
if (bccomp($spent, '0') !== 0) {
|
||||||
$report[$category->id] = ['name' => $category->name, 'spent' => $spent];
|
$report[$category->id] = ['name' => $category->name, 'spent' => $spent, 'id' => $category->id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ namespace FireflyIII\Http\Controllers\Report;
|
|||||||
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|||||||
@@ -13,12 +13,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use ExpandedForm;
|
||||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||||
|
use FireflyIII\Http\Requests\SelectTransactionsRequest;
|
||||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||||
|
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Models\RuleTrigger;
|
use FireflyIII\Models\RuleTrigger;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use FireflyIII\Rules\TransactionMatcher;
|
use FireflyIII\Rules\TransactionMatcher;
|
||||||
@@ -188,6 +194,41 @@ class RuleController extends Controller
|
|||||||
return view('rules.rule.edit', compact('rule', 'subTitle', 'primaryTrigger', 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'));
|
return view('rules.rule.edit', compact('rule', 'subTitle', 'primaryTrigger', 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the given rule on a set of existing transactions
|
||||||
|
*
|
||||||
|
* @param SelectTransactionsRequest $request
|
||||||
|
* @param AccountRepositoryInterface $repository
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
* @internal param RuleGroup $ruleGroup
|
||||||
|
*/
|
||||||
|
public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, Rule $rule)
|
||||||
|
{
|
||||||
|
// Get parameters specified by the user
|
||||||
|
$accounts = $repository->getAccountsById($request->get('accounts'));
|
||||||
|
$startDate = new Carbon($request->get('start_date'));
|
||||||
|
$endDate = new Carbon($request->get('end_date'));
|
||||||
|
|
||||||
|
// Create a job to do the work asynchronously
|
||||||
|
$job = new ExecuteRuleOnExistingTransactions($rule);
|
||||||
|
|
||||||
|
// Apply parameters to the job
|
||||||
|
$job->setUser(auth()->user());
|
||||||
|
$job->setAccounts($accounts);
|
||||||
|
$job->setStartDate($startDate);
|
||||||
|
$job->setEndDate($endDate);
|
||||||
|
|
||||||
|
// Dispatch a new job to execute it in a queue
|
||||||
|
$this->dispatch($job);
|
||||||
|
|
||||||
|
// Tell the user that the job is queued
|
||||||
|
Session::flash('success', strval(trans('firefly.applied_rule_selection', ['title' => $rule->title])));
|
||||||
|
|
||||||
|
return redirect()->route('rules.index');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RuleGroupRepositoryInterface $repository
|
* @param RuleGroupRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
@@ -238,6 +279,25 @@ class RuleController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AccountRepositoryInterface $repository
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function selectTransactions(AccountRepositoryInterface $repository, Rule $rule)
|
||||||
|
{
|
||||||
|
// does the user have shared accounts?
|
||||||
|
$accounts = $repository->getAccountsByType([AccountType::ASSET]);
|
||||||
|
$accountList = ExpandedForm::makeSelectList($accounts);
|
||||||
|
$checkedAccounts = array_keys($accountList);
|
||||||
|
$first = session('first')->format('Y-m-d');
|
||||||
|
$today = Carbon::create()->format('Y-m-d');
|
||||||
|
$subTitle = (string)trans('firefly.apply_rule_selection', ['title' => $rule->title]);
|
||||||
|
|
||||||
|
return view('rules.rule.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'rule', 'subTitle'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RuleFormRequest $request
|
* @param RuleFormRequest $request
|
||||||
* @param RuleRepositoryInterface $repository
|
* @param RuleRepositoryInterface $repository
|
||||||
@@ -282,7 +342,7 @@ class RuleController extends Controller
|
|||||||
// build trigger array from response
|
// build trigger array from response
|
||||||
$triggers = $this->getValidTriggerList($request);
|
$triggers = $this->getValidTriggerList($request);
|
||||||
|
|
||||||
if (count($triggers) == 0) {
|
if (count($triggers) === 0) {
|
||||||
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
|
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,19 +354,66 @@ class RuleController extends Controller
|
|||||||
$matcher->setLimit($limit);
|
$matcher->setLimit($limit);
|
||||||
$matcher->setRange($range);
|
$matcher->setRange($range);
|
||||||
$matcher->setTriggers($triggers);
|
$matcher->setTriggers($triggers);
|
||||||
$matchingTransactions = $matcher->findMatchingTransactions();
|
$matchingTransactions = $matcher->findTransactionsByTriggers();
|
||||||
|
|
||||||
// Warn the user if only a subset of transactions is returned
|
// Warn the user if only a subset of transactions is returned
|
||||||
$warning = '';
|
$warning = '';
|
||||||
if (count($matchingTransactions) == $limit) {
|
if (count($matchingTransactions) === $limit) {
|
||||||
$warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]);
|
$warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]);
|
||||||
}
|
}
|
||||||
if (count($matchingTransactions) == 0) {
|
if (count($matchingTransactions) === 0) {
|
||||||
$warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]);
|
$warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return json response
|
// Return json response
|
||||||
$view = view('list.journals-tiny-tasker', ['transactions' => $matchingTransactions])->render();
|
$view = view('list.journals-tiny', ['transactions' => $matchingTransactions])->render();
|
||||||
|
|
||||||
|
return Response::json(['html' => $view, 'warning' => $warning]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method allows the user to test a certain set of rule triggers. The rule triggers are grabbed from
|
||||||
|
* the rule itself.
|
||||||
|
*
|
||||||
|
* This method will parse and validate those rules and create a "TransactionMatcher" which will attempt
|
||||||
|
* to find transaction journals matching the users input. A maximum range of transactions to try (range) and
|
||||||
|
* a maximum number of transactions to return (limit) are set as well.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function testTriggersByRule(Rule $rule)
|
||||||
|
{
|
||||||
|
|
||||||
|
$triggers = $rule->ruleTriggers;
|
||||||
|
|
||||||
|
if (count($triggers) === 0) {
|
||||||
|
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = config('firefly.test-triggers.limit');
|
||||||
|
$range = config('firefly.test-triggers.range');
|
||||||
|
|
||||||
|
/** @var TransactionMatcher $matcher */
|
||||||
|
$matcher = app(TransactionMatcher::class);
|
||||||
|
$matcher->setLimit($limit);
|
||||||
|
$matcher->setRange($range);
|
||||||
|
$matcher->setRule($rule);
|
||||||
|
$matchingTransactions = $matcher->findTransactionsByRule();
|
||||||
|
|
||||||
|
// Warn the user if only a subset of transactions is returned
|
||||||
|
$warning = '';
|
||||||
|
if (count($matchingTransactions) === $limit) {
|
||||||
|
$warning = trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]);
|
||||||
|
}
|
||||||
|
if (count($matchingTransactions) === 0) {
|
||||||
|
$warning = trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return json response
|
||||||
|
$view = view('list.journals-tiny', ['transactions' => $matchingTransactions])->render();
|
||||||
|
|
||||||
return Response::json(['html' => $view, 'warning' => $warning]);
|
return Response::json(['html' => $view, 'warning' => $warning]);
|
||||||
}
|
}
|
||||||
@@ -440,7 +547,7 @@ class RuleController extends Controller
|
|||||||
|
|
||||||
/** @var RuleTrigger $entry */
|
/** @var RuleTrigger $entry */
|
||||||
foreach ($rule->ruleTriggers as $entry) {
|
foreach ($rule->ruleTriggers as $entry) {
|
||||||
if ($entry->trigger_type != 'user_action') {
|
if ($entry->trigger_type !== 'user_action') {
|
||||||
$count = ($index + 1);
|
$count = ($index + 1);
|
||||||
$triggers[] = view(
|
$triggers[] = view(
|
||||||
'rules.partials.trigger',
|
'rules.partials.trigger',
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ class RuleGroupController extends Controller
|
|||||||
$this->dispatch($job);
|
$this->dispatch($job);
|
||||||
|
|
||||||
// Tell the user that the job is queued
|
// Tell the user that the job is queued
|
||||||
Session::flash('success', strval(trans('firefly.executed_group_on_existing_transactions', ['title' => $ruleGroup->title])));
|
Session::flash('success', strval(trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title])));
|
||||||
|
|
||||||
return redirect()->route('rules.index');
|
return redirect()->route('rules.index');
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ class RuleGroupController extends Controller
|
|||||||
$checkedAccounts = array_keys($accountList);
|
$checkedAccounts = array_keys($accountList);
|
||||||
$first = session('first')->format('Y-m-d');
|
$first = session('first')->format('Y-m-d');
|
||||||
$today = Carbon::create()->format('Y-m-d');
|
$today = Carbon::create()->format('Y-m-d');
|
||||||
$subTitle = (string)trans('firefly.execute_on_existing_transactions');
|
$subTitle = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]);
|
||||||
|
|
||||||
return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup', 'subTitle'));
|
return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup', 'subTitle'));
|
||||||
}
|
}
|
||||||
@@ -246,14 +246,14 @@ class RuleGroupController extends Controller
|
|||||||
* @param RuleGroupRepositoryInterface $repository
|
* @param RuleGroupRepositoryInterface $repository
|
||||||
* @param RuleGroup $ruleGroup
|
* @param RuleGroup $ruleGroup
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
|
public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'title' => $request->input('title'),
|
'title' => $request->input('title'),
|
||||||
'description' => $request->input('description'),
|
'description' => $request->input('description'),
|
||||||
'active' => intval($request->input('active')) == 1,
|
'active' => intval($request->input('active')) === 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
$repository->update($ruleGroup, $data);
|
$repository->update($ruleGroup, $data);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use FireflyIII\Support\Search\SearchInterface;
|
use FireflyIII\Support\Search\SearchInterface;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Response;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,47 +51,29 @@ class SearchController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request, SearchInterface $searcher)
|
public function index(Request $request, SearchInterface $searcher)
|
||||||
{
|
{
|
||||||
// yes, hard coded values:
|
$fullQuery = $request->get('q');
|
||||||
$minSearchLen = 1;
|
|
||||||
$limit = 20;
|
|
||||||
|
|
||||||
// ui stuff:
|
// parse search terms:
|
||||||
$subTitle = '';
|
$searcher->parseQuery($fullQuery);
|
||||||
|
$query = $searcher->getWordsAsString();
|
||||||
|
$subTitle = trans('breadcrumbs.search_result', ['query' => $query]);
|
||||||
|
|
||||||
// query stuff
|
return view('search.index', compact('query', 'fullQuery', 'subTitle'));
|
||||||
$query = null;
|
}
|
||||||
$result = [];
|
|
||||||
$rawQuery = $request->get('q');
|
|
||||||
$hasModifiers = true;
|
|
||||||
$modifiers = [];
|
|
||||||
|
|
||||||
if (!is_null($request->get('q')) && strlen($request->get('q')) >= $minSearchLen) {
|
public function search(Request $request, SearchInterface $searcher)
|
||||||
// parse query, find modifiers:
|
{
|
||||||
// set limit for search
|
$fullQuery = $request->get('query');
|
||||||
$searcher->setLimit($limit);
|
|
||||||
$searcher->parseQuery($request->get('q'));
|
|
||||||
|
|
||||||
$transactions = $searcher->searchTransactions();
|
// parse search terms:
|
||||||
$accounts = new Collection;
|
$searcher->parseQuery($fullQuery);
|
||||||
$categories = new Collection;
|
$searcher->setLimit(20);
|
||||||
$tags = new Collection;
|
$transactions = $searcher->searchTransactions();
|
||||||
$budgets = new Collection;
|
$html = view('search.search', compact('transactions'))->render();
|
||||||
|
|
||||||
// no special search thing?
|
return Response::json(['count' => $transactions->count(), 'html' => $html]);
|
||||||
if (!$searcher->hasModifiers()) {
|
|
||||||
$hasModifiers = false;
|
|
||||||
$accounts = $searcher->searchAccounts();
|
|
||||||
$categories = $searcher->searchCategories();
|
|
||||||
$budgets = $searcher->searchBudgets();
|
|
||||||
$tags = $searcher->searchTags();
|
|
||||||
}
|
|
||||||
$query = $searcher->getWordsAsString();
|
|
||||||
$subTitle = trans('firefly.search_results_for', ['query' => $query]);
|
|
||||||
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('search.index', compact('rawQuery', 'hasModifiers', 'modifiers', 'subTitle', 'limit', 'query', 'result'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||||
use FireflyIII\Http\Requests\TagFormRequest;
|
use FireflyIII\Http\Requests\TagFormRequest;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
@@ -235,7 +236,7 @@ class TagController extends Controller
|
|||||||
// default values:
|
// default values:
|
||||||
$subTitle = $tag->tag;
|
$subTitle = $tag->tag;
|
||||||
$subTitleIcon = 'fa-tag';
|
$subTitleIcon = 'fa-tag';
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
@@ -245,6 +246,7 @@ class TagController extends Controller
|
|||||||
$periods = new Collection;
|
$periods = new Collection;
|
||||||
$apiKey = env('GOOGLE_MAPS_API_KEY', '');
|
$apiKey = env('GOOGLE_MAPS_API_KEY', '');
|
||||||
$sum = '0';
|
$sum = '0';
|
||||||
|
$path = 'tags/show/' . $tag->id;
|
||||||
|
|
||||||
|
|
||||||
// prep for "all" view.
|
// prep for "all" view.
|
||||||
@@ -253,6 +255,7 @@ class TagController extends Controller
|
|||||||
$start = $repository->firstUseDate($tag);
|
$start = $repository->firstUseDate($tag);
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
$sum = $repository->sumOfTag($tag);
|
$sum = $repository->sumOfTag($tag);
|
||||||
|
$path = 'tags/show/' . $tag->id . '/all';
|
||||||
}
|
}
|
||||||
|
|
||||||
// prep for "specific date" view.
|
// prep for "specific date" view.
|
||||||
@@ -282,15 +285,15 @@ class TagController extends Controller
|
|||||||
Log::info('Now at tag loop start.');
|
Log::info('Now at tag loop start.');
|
||||||
while ($count === 0 && $loop < 3) {
|
while ($count === 0 && $loop < 3) {
|
||||||
$loop++;
|
$loop++;
|
||||||
Log::info('Count is zero, search for journals.');
|
Log::info(sprintf('Count is zero, search for journals between %s and %s (pagesize %d, page %d).', $start, $end, $pageSize, $page));
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||||
->setTag($tag)->withBudgetInformation()->withCategoryInformation();
|
->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class);
|
||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('tags/show/' . $tag->id);
|
$journals->setPath($path);
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -298,7 +301,7 @@ class TagController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.journals_in_period_for_tag',
|
'firefly.journals_in_period_for_tag',
|
||||||
['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
|
|||||||
@@ -174,14 +174,23 @@ class ConvertController extends Controller
|
|||||||
switch ($joined) {
|
switch ($joined) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
||||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
|
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
|
||||||
|
// one
|
||||||
$destination = $sourceAccount;
|
$destination = $sourceAccount;
|
||||||
break;
|
break;
|
||||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: // two
|
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
|
||||||
|
// two
|
||||||
$destination = $accountRepository->find(intval($data['destination_account_asset']));
|
$destination = $accountRepository->find(intval($data['destination_account_asset']));
|
||||||
break;
|
break;
|
||||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
|
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
|
||||||
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five
|
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
|
||||||
|
// three and five
|
||||||
|
if ($data['destination_account_expense'] === '') {
|
||||||
|
// destination is a cash account.
|
||||||
|
$destination = $accountRepository->getCashAccount();
|
||||||
|
|
||||||
|
return $destination;
|
||||||
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $data['destination_account_expense'],
|
'name' => $data['destination_account_expense'],
|
||||||
'accountType' => 'expense',
|
'accountType' => 'expense',
|
||||||
@@ -191,8 +200,9 @@ class ConvertController extends Controller
|
|||||||
];
|
];
|
||||||
$destination = $accountRepository->store($data);
|
$destination = $accountRepository->store($data);
|
||||||
break;
|
break;
|
||||||
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: // four
|
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
|
||||||
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six
|
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
|
||||||
|
// four and six
|
||||||
$destination = $destinationAccount;
|
$destination = $destinationAccount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -219,8 +229,16 @@ class ConvertController extends Controller
|
|||||||
switch ($joined) {
|
switch ($joined) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
|
||||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
|
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
|
||||||
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six
|
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
|
||||||
|
|
||||||
|
if ($data['source_account_revenue'] === '') {
|
||||||
|
// destination is a cash account.
|
||||||
|
$destination = $accountRepository->getCashAccount();
|
||||||
|
|
||||||
|
return $destination;
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $data['source_account_revenue'],
|
'name' => $data['source_account_revenue'],
|
||||||
'accountType' => 'revenue',
|
'accountType' => 'revenue',
|
||||||
@@ -230,14 +248,14 @@ class ConvertController extends Controller
|
|||||||
];
|
];
|
||||||
$source = $accountRepository->store($data);
|
$source = $accountRepository->store($data);
|
||||||
break;
|
break;
|
||||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: // two
|
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
|
||||||
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five
|
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
|
||||||
$source = $sourceAccount;
|
$source = $sourceAccount;
|
||||||
break;
|
break;
|
||||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
|
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
|
||||||
$source = $destinationAccount;
|
$source = $destinationAccount;
|
||||||
break;
|
break;
|
||||||
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: // four
|
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
|
||||||
$source = $accountRepository->find(intval($data['source_account_asset']));
|
$source = $accountRepository->find(intval($data['source_account_asset']));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use FireflyIII\Http\Requests\MassDeleteJournalRequest;
|
|||||||
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
@@ -85,7 +86,7 @@ class MassController extends Controller
|
|||||||
foreach ($ids as $journalId) {
|
foreach ($ids as $journalId) {
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
$journal = $repository->find(intval($journalId));
|
$journal = $repository->find(intval($journalId));
|
||||||
if (!is_null($journal->id) && $journalId == $journal->id) {
|
if (!is_null($journal->id) && $journalId === $journal->id) {
|
||||||
$set->push($journal);
|
$set->push($journal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,8 +127,7 @@ class MassController extends Controller
|
|||||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||||
$budgets = $budgetRepository->getBudgets();
|
$budgets = $budgetRepository->getBudgets();
|
||||||
|
|
||||||
// skip transactions that have multiple destinations
|
// skip transactions that have multiple destinations, multiple sources or are an opening balance.
|
||||||
// or multiple sources:
|
|
||||||
$filtered = new Collection;
|
$filtered = new Collection;
|
||||||
$messages = [];
|
$messages = [];
|
||||||
/**
|
/**
|
||||||
@@ -135,8 +135,8 @@ class MassController extends Controller
|
|||||||
* @var TransactionJournal $journal
|
* @var TransactionJournal $journal
|
||||||
*/
|
*/
|
||||||
foreach ($journals as $index => $journal) {
|
foreach ($journals as $index => $journal) {
|
||||||
$sources = $journal->sourceAccountList($journal);
|
$sources = $journal->sourceAccountList();
|
||||||
$destinations = $journal->destinationAccountList($journal);
|
$destinations = $journal->destinationAccountList();
|
||||||
if ($sources->count() > 1) {
|
if ($sources->count() > 1) {
|
||||||
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
@@ -146,6 +146,10 @@ class MassController extends Controller
|
|||||||
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($journal->transactionType->type === TransactionType::OPENING_BALANCE) {
|
||||||
|
$messages[] = trans('firefly.cannot_edit_opening_balance');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$filtered->push($journal);
|
$filtered->push($journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,13 +162,21 @@ class MassController extends Controller
|
|||||||
Session::flash('gaEventCategory', 'transactions');
|
Session::flash('gaEventCategory', 'transactions');
|
||||||
Session::flash('gaEventAction', 'mass-edit');
|
Session::flash('gaEventAction', 'mass-edit');
|
||||||
|
|
||||||
// set some values to be used in the edit routine:
|
// collect some useful meta data for the mass edit:
|
||||||
$filtered->each(
|
$filtered->each(
|
||||||
function (TransactionJournal $journal) {
|
function (TransactionJournal $journal) {
|
||||||
$journal->amount = $journal->amountPositive();
|
$transaction = $journal->positiveTransaction();
|
||||||
$sources = $journal->sourceAccountList();
|
$currency = $transaction->transactionCurrency;
|
||||||
$destinations = $journal->destinationAccountList();
|
$journal->amount = floatval($transaction->amount);
|
||||||
$journal->transaction_count = $journal->transactions()->count();
|
$sources = $journal->sourceAccountList();
|
||||||
|
$destinations = $journal->destinationAccountList();
|
||||||
|
$journal->transaction_count = $journal->transactions()->count();
|
||||||
|
$journal->currency_symbol = $currency->symbol;
|
||||||
|
$journal->transaction_type_type = $journal->transactionType->type;
|
||||||
|
|
||||||
|
$journal->foreign_amount = floatval($transaction->foreign_amount);
|
||||||
|
$journal->foreign_currency = $transaction->foreignCurrency;
|
||||||
|
|
||||||
if (!is_null($sources->first())) {
|
if (!is_null($sources->first())) {
|
||||||
$journal->source_account_id = $sources->first()->id;
|
$journal->source_account_id = $sources->first()->id;
|
||||||
$journal->source_account_name = $sources->first()->editname;
|
$journal->source_account_name = $sources->first()->editname;
|
||||||
@@ -201,13 +213,17 @@ class MassController extends Controller
|
|||||||
if ($journal) {
|
if ($journal) {
|
||||||
// get optional fields:
|
// get optional fields:
|
||||||
$what = strtolower($journal->transactionTypeStr());
|
$what = strtolower($journal->transactionTypeStr());
|
||||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||||
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
|
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
|
||||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||||
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
||||||
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
|
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
|
||||||
$category = $request->get('category')[$journal->id];
|
$category = $request->get('category')[$journal->id];
|
||||||
$tags = $journal->tags->pluck('tag')->toArray();
|
$tags = $journal->tags->pluck('tag')->toArray();
|
||||||
|
$amount = round($request->get('amount')[$journal->id], 12);
|
||||||
|
$foreignAmount = isset($request->get('foreign_amount')[$journal->id]) ? round($request->get('foreign_amount')[$journal->id], 12) : null;
|
||||||
|
$foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?
|
||||||
|
intval($request->get('foreign_currency_id')[$journal->id]) : null;
|
||||||
|
|
||||||
// build data array
|
// build data array
|
||||||
$data = [
|
$data = [
|
||||||
@@ -218,16 +234,19 @@ class MassController extends Controller
|
|||||||
'source_account_name' => $sourceAccountName,
|
'source_account_name' => $sourceAccountName,
|
||||||
'destination_account_id' => intval($destAccountId),
|
'destination_account_id' => intval($destAccountId),
|
||||||
'destination_account_name' => $destAccountName,
|
'destination_account_name' => $destAccountName,
|
||||||
'amount' => round($request->get('amount')[$journal->id], 12),
|
'amount' => $foreignAmount,
|
||||||
'currency_id' => $journal->transaction_currency_id,
|
'native_amount' => $amount,
|
||||||
|
'source_amount' => $amount,
|
||||||
'date' => new Carbon($request->get('date')[$journal->id]),
|
'date' => new Carbon($request->get('date')[$journal->id]),
|
||||||
'interest_date' => $journal->interest_date,
|
'interest_date' => $journal->interest_date,
|
||||||
'book_date' => $journal->book_date,
|
'book_date' => $journal->book_date,
|
||||||
'process_date' => $journal->process_date,
|
'process_date' => $journal->process_date,
|
||||||
'budget_id' => intval($budgetId),
|
'budget_id' => intval($budgetId),
|
||||||
|
'currency_id' => $foreignCurrencyId,
|
||||||
|
'foreign_amount' => $foreignAmount,
|
||||||
|
'destination_amount' => $foreignAmount,
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'tags' => $tags,
|
'tags' => $tags,
|
||||||
|
|
||||||
];
|
];
|
||||||
// call repository update function.
|
// call repository update function.
|
||||||
$repository->update($journal, $data);
|
$repository->update($journal, $data);
|
||||||
@@ -235,6 +254,7 @@ class MassController extends Controller
|
|||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
Session::flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
Session::flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
|||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@@ -54,6 +55,9 @@ class SingleController extends Controller
|
|||||||
/** @var PiggyBankRepositoryInterface */
|
/** @var PiggyBankRepositoryInterface */
|
||||||
private $piggyBanks;
|
private $piggyBanks;
|
||||||
|
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -74,6 +78,7 @@ class SingleController extends Controller
|
|||||||
$this->piggyBanks = app(PiggyBankRepositoryInterface::class);
|
$this->piggyBanks = app(PiggyBankRepositoryInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
$this->currency = app(CurrencyRepositoryInterface::class);
|
$this->currency = app(CurrencyRepositoryInterface::class);
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
View::share('title', trans('firefly.transactions'));
|
View::share('title', trans('firefly.transactions'));
|
||||||
View::share('mainTitleIcon', 'fa-repeat');
|
View::share('mainTitleIcon', 'fa-repeat');
|
||||||
@@ -93,27 +98,35 @@ class SingleController extends Controller
|
|||||||
$category = $journal->categories()->first();
|
$category = $journal->categories()->first();
|
||||||
$categoryName = is_null($category) ? '' : $category->name;
|
$categoryName = is_null($category) ? '' : $category->name;
|
||||||
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
$transaction = $journal->transactions()->first();
|
||||||
|
$amount = Steam::positive($transaction->amount);
|
||||||
|
$foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);
|
||||||
|
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'description' => $journal->description,
|
'description' => $journal->description,
|
||||||
'source_account_id' => $source->id,
|
'source_account_id' => $source->id,
|
||||||
'source_account_name' => $source->name,
|
'source_account_name' => $source->name,
|
||||||
'destination_account_id' => $destination->id,
|
'destination_account_id' => $destination->id,
|
||||||
'destination_account_name' => $destination->name,
|
'destination_account_name' => $destination->name,
|
||||||
'amount' => $journal->amountPositive(),
|
'amount' => $amount,
|
||||||
'date' => $journal->date->format('Y-m-d'),
|
'source_amount' => $amount,
|
||||||
'budget_id' => $budgetId,
|
'destination_amount' => $foreignAmount,
|
||||||
'category' => $categoryName,
|
'foreign_amount' => $foreignAmount,
|
||||||
'tags' => $tags,
|
'native_amount' => $foreignAmount,
|
||||||
'interest_date' => $journal->getMeta('interest_date'),
|
'amount_currency_id_amount' => $transaction->foreign_currency_id ?? 0,
|
||||||
'book_date' => $journal->getMeta('book_date'),
|
'date' => $journal->date->format('Y-m-d'),
|
||||||
'process_date' => $journal->getMeta('process_date'),
|
'budget_id' => $budgetId,
|
||||||
'due_date' => $journal->getMeta('due_date'),
|
'category' => $categoryName,
|
||||||
'payment_date' => $journal->getMeta('payment_date'),
|
'tags' => $tags,
|
||||||
'invoice_date' => $journal->getMeta('invoice_date'),
|
'interest_date' => $journal->getMeta('interest_date'),
|
||||||
'internal_reference' => $journal->getMeta('internal_reference'),
|
'book_date' => $journal->getMeta('book_date'),
|
||||||
'notes' => $journal->getMeta('notes'),
|
'process_date' => $journal->getMeta('process_date'),
|
||||||
|
'due_date' => $journal->getMeta('due_date'),
|
||||||
|
'payment_date' => $journal->getMeta('payment_date'),
|
||||||
|
'invoice_date' => $journal->getMeta('invoice_date'),
|
||||||
|
'internal_reference' => $journal->getMeta('internal_reference'),
|
||||||
|
'notes' => $journal->getMeta('notes'),
|
||||||
];
|
];
|
||||||
Session::flash('preFilled', $preFilled);
|
Session::flash('preFilled', $preFilled);
|
||||||
|
|
||||||
@@ -161,7 +174,7 @@ class SingleController extends Controller
|
|||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return View
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||||
*/
|
*/
|
||||||
public function delete(TransactionJournal $journal)
|
public function delete(TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
@@ -191,7 +204,7 @@ class SingleController extends Controller
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
|
public function destroy(TransactionJournal $transactionJournal)
|
||||||
{
|
{
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
if ($this->isOpeningBalance($transactionJournal)) {
|
if ($this->isOpeningBalance($transactionJournal)) {
|
||||||
@@ -201,7 +214,7 @@ class SingleController extends Controller
|
|||||||
$type = $transactionJournal->transactionTypeStr();
|
$type = $transactionJournal->transactionTypeStr();
|
||||||
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
|
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
|
||||||
|
|
||||||
$repository->delete($transactionJournal);
|
$this->repository->delete($transactionJournal);
|
||||||
|
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
|
|
||||||
@@ -220,10 +233,7 @@ class SingleController extends Controller
|
|||||||
return $this->redirectToAccount($journal);
|
return $this->redirectToAccount($journal);
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
if ($this->isSplitJournal($journal)) {
|
||||||
$count = $journal->transactions()->count();
|
|
||||||
|
|
||||||
if ($count > 2) {
|
|
||||||
return redirect(route('transactions.split.edit', [$journal->id]));
|
return redirect(route('transactions.split.edit', [$journal->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +248,8 @@ class SingleController extends Controller
|
|||||||
$sourceAccounts = $journal->sourceAccountList();
|
$sourceAccounts = $journal->sourceAccountList();
|
||||||
$destinationAccounts = $journal->destinationAccountList();
|
$destinationAccounts = $journal->destinationAccountList();
|
||||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||||
|
$pTransaction = $journal->positiveTransaction();
|
||||||
|
$foreignCurrency = !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency;
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'date' => $journal->dateAsString(),
|
'date' => $journal->dateAsString(),
|
||||||
'interest_date' => $journal->dateAsString('interest_date'),
|
'interest_date' => $journal->dateAsString('interest_date'),
|
||||||
@@ -250,8 +262,6 @@ class SingleController extends Controller
|
|||||||
'source_account_name' => $sourceAccounts->first()->edit_name,
|
'source_account_name' => $sourceAccounts->first()->edit_name,
|
||||||
'destination_account_id' => $destinationAccounts->first()->id,
|
'destination_account_id' => $destinationAccounts->first()->id,
|
||||||
'destination_account_name' => $destinationAccounts->first()->edit_name,
|
'destination_account_name' => $destinationAccounts->first()->edit_name,
|
||||||
'amount' => $journal->amountPositive(),
|
|
||||||
'currency' => $journal->transactionCurrency,
|
|
||||||
|
|
||||||
// new custom fields:
|
// new custom fields:
|
||||||
'due_date' => $journal->dateAsString('due_date'),
|
'due_date' => $journal->dateAsString('due_date'),
|
||||||
@@ -260,30 +270,25 @@ class SingleController extends Controller
|
|||||||
'interal_reference' => $journal->getMeta('internal_reference'),
|
'interal_reference' => $journal->getMeta('internal_reference'),
|
||||||
'notes' => $journal->getMeta('notes'),
|
'notes' => $journal->getMeta('notes'),
|
||||||
|
|
||||||
// exchange rate fields
|
// amount fields
|
||||||
'native_amount' => $journal->amountPositive(),
|
'amount' => $pTransaction->amount,
|
||||||
'native_currency' => $journal->transactionCurrency,
|
'source_amount' => $pTransaction->amount,
|
||||||
|
'native_amount' => $pTransaction->amount,
|
||||||
|
'destination_amount' => $pTransaction->foreign_amount,
|
||||||
|
'currency' => $pTransaction->transactionCurrency,
|
||||||
|
'source_currency' => $pTransaction->transactionCurrency,
|
||||||
|
'native_currency' => $pTransaction->transactionCurrency,
|
||||||
|
'foreign_currency' => $foreignCurrency,
|
||||||
|
'destination_currency' => $foreignCurrency,
|
||||||
];
|
];
|
||||||
|
|
||||||
// if user has entered a foreign currency, update some fields
|
// amounts for withdrawals and deposits:
|
||||||
$foreignCurrencyId = intval($journal->getMeta('foreign_currency_id'));
|
// amount, native_amount, source_amount, destination_amount
|
||||||
if ($foreignCurrencyId > 0) {
|
if (($journal->isWithdrawal() || $journal->isDeposit()) && !is_null($pTransaction->foreign_amount)) {
|
||||||
// update some fields in pre-filled.
|
$preFilled['amount'] = $pTransaction->foreign_amount;
|
||||||
// @codeCoverageIgnoreStart
|
$preFilled['currency'] = $pTransaction->foreignCurrency;
|
||||||
$preFilled['amount'] = $journal->getMeta('foreign_amount');
|
|
||||||
$preFilled['currency'] = $this->currency->find(intval($journal->getMeta('foreign_currency_id')));
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
|
|
||||||
$preFilled['destination_account_name'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type == AccountType::CASH) {
|
|
||||||
$preFilled['source_account_name'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Session::flash('preFilled', $preFilled);
|
Session::flash('preFilled', $preFilled);
|
||||||
Session::flash('gaEventCategory', 'transactions');
|
Session::flash('gaEventCategory', 'transactions');
|
||||||
Session::flash('gaEventAction', 'edit-' . $what);
|
Session::flash('gaEventAction', 'edit-' . $what);
|
||||||
@@ -319,6 +324,7 @@ class SingleController extends Controller
|
|||||||
|
|
||||||
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array $files */
|
/** @var array $files */
|
||||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||||
$this->attachments->saveAttachmentsForModel($journal, $files);
|
$this->attachments->saveAttachmentsForModel($journal, $files);
|
||||||
@@ -401,4 +407,20 @@ class SingleController extends Controller
|
|||||||
// redirect to previous URL.
|
// redirect to previous URL.
|
||||||
return redirect($this->getPreviousUri('transactions.edit.uri'));
|
return redirect($this->getPreviousUri('transactions.edit.uri'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isSplitJournal(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
$count = $this->repository->countTransactions($journal);
|
||||||
|
|
||||||
|
if ($count > 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class SplitController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
||||||
$currencies = ExpandedForm::makeSelectList($this->currencies->get());
|
$currencies = $this->currencies->get();
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||||
@@ -130,7 +130,6 @@ class SplitController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->isOpeningBalance($journal)) {
|
if ($this->isOpeningBalance($journal)) {
|
||||||
return $this->redirectToAccount($journal);
|
return $this->redirectToAccount($journal);
|
||||||
}
|
}
|
||||||
@@ -179,7 +178,6 @@ class SplitController extends Controller
|
|||||||
'journal_source_account_id' => $request->get('journal_source_account_id'),
|
'journal_source_account_id' => $request->get('journal_source_account_id'),
|
||||||
'journal_source_account_name' => $request->get('journal_source_account_name'),
|
'journal_source_account_name' => $request->get('journal_source_account_name'),
|
||||||
'journal_destination_account_id' => $request->get('journal_destination_account_id'),
|
'journal_destination_account_id' => $request->get('journal_destination_account_id'),
|
||||||
'currency_id' => $request->get('currency_id'),
|
|
||||||
'what' => $request->get('what'),
|
'what' => $request->get('what'),
|
||||||
'date' => $request->get('date'),
|
'date' => $request->get('date'),
|
||||||
// all custom fields:
|
// all custom fields:
|
||||||
@@ -218,10 +216,9 @@ class SplitController extends Controller
|
|||||||
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
||||||
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
||||||
'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id),
|
'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id),
|
||||||
'currency_id' => $request->old('currency_id', $journal->transaction_currency_id),
|
|
||||||
'destinationAccounts' => $destinationAccounts,
|
'destinationAccounts' => $destinationAccounts,
|
||||||
'what' => strtolower($journal->transactionTypeStr()),
|
'what' => strtolower($journal->transactionTypeStr()),
|
||||||
'date' => $request->old('date', $journal->date),
|
'date' => $request->old('date', $journal->date->format('Y-m-d')),
|
||||||
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
||||||
|
|
||||||
// all custom fields:
|
// all custom fields:
|
||||||
@@ -253,14 +250,22 @@ class SplitController extends Controller
|
|||||||
/** @var array $transaction */
|
/** @var array $transaction */
|
||||||
foreach ($transactions as $index => $transaction) {
|
foreach ($transactions as $index => $transaction) {
|
||||||
$set = [
|
$set = [
|
||||||
'description' => $transaction['description'],
|
'description' => $transaction['description'],
|
||||||
'source_account_id' => $transaction['source_account_id'],
|
'source_account_id' => $transaction['source_account_id'],
|
||||||
'source_account_name' => $transaction['source_account_name'],
|
'source_account_name' => $transaction['source_account_name'],
|
||||||
'destination_account_id' => $transaction['destination_account_id'],
|
'destination_account_id' => $transaction['destination_account_id'],
|
||||||
'destination_account_name' => $transaction['destination_account_name'],
|
'destination_account_name' => $transaction['destination_account_name'],
|
||||||
'amount' => round($transaction['destination_amount'], 12),
|
'amount' => round($transaction['destination_amount'], 12),
|
||||||
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
|
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
|
||||||
'category' => $transaction['category'],
|
'category' => $transaction['category'],
|
||||||
|
'transaction_currency_id' => $transaction['transaction_currency_id'],
|
||||||
|
'transaction_currency_code' => $transaction['transaction_currency_code'],
|
||||||
|
'transaction_currency_symbol' => $transaction['transaction_currency_symbol'],
|
||||||
|
'foreign_amount' => round($transaction['foreign_destination_amount'], 12),
|
||||||
|
'foreign_currency_id' => $transaction['foreign_currency_id'],
|
||||||
|
'foreign_currency_code' => $transaction['foreign_currency_code'],
|
||||||
|
'foreign_currency_symbol' => $transaction['foreign_currency_symbol'],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// set initial category and/or budget:
|
// set initial category and/or budget:
|
||||||
@@ -294,8 +299,12 @@ class SplitController extends Controller
|
|||||||
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
|
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
|
||||||
'destination_account_name' => $transaction['destination_account_name'] ?? '',
|
'destination_account_name' => $transaction['destination_account_name'] ?? '',
|
||||||
'amount' => round($transaction['amount'] ?? 0, 12),
|
'amount' => round($transaction['amount'] ?? 0, 12),
|
||||||
|
'foreign_amount' => !isset($transaction['foreign_amount']) ? null : round($transaction['foreign_amount'] ?? 0, 12),
|
||||||
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
|
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
|
||||||
'category' => $transaction['category'] ?? '',
|
'category' => $transaction['category'] ?? '',
|
||||||
|
'transaction_currency_id' => intval($transaction['transaction_currency_id']),
|
||||||
|
'foreign_currency_id' => $transaction['foreign_currency_id'] ?? null,
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('Found %d splits in request data.', count($return)));
|
Log::debug(sprintf('Found %d splits in request data.', count($return)));
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
@@ -70,7 +70,7 @@ class TransactionController extends Controller
|
|||||||
// default values:
|
// default values:
|
||||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
||||||
$types = config('firefly.transactionTypesByWhat.' . $what);
|
$types = config('firefly.transactionTypesByWhat.' . $what);
|
||||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
@@ -78,6 +78,7 @@ class TransactionController extends Controller
|
|||||||
$start = null;
|
$start = null;
|
||||||
$end = null;
|
$end = null;
|
||||||
$periods = new Collection;
|
$periods = new Collection;
|
||||||
|
$path = '/transactions/' . $what;
|
||||||
|
|
||||||
// prep for "all" view.
|
// prep for "all" view.
|
||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
@@ -85,12 +86,14 @@ class TransactionController extends Controller
|
|||||||
$first = $repository->first();
|
$first = $repository->first();
|
||||||
$start = $first->date ?? new Carbon;
|
$start = $first->date ?? new Carbon;
|
||||||
$end = new Carbon;
|
$end = new Carbon;
|
||||||
|
$path = '/transactions/' . $what . '/all/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// prep for "specific date" view.
|
// prep for "specific date" view.
|
||||||
if (strlen($moment) > 0 && $moment !== 'all') {
|
if (strlen($moment) > 0 && $moment !== 'all') {
|
||||||
$start = new Carbon($moment);
|
$start = new Carbon($moment);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
|
$path = '/transactions/' . $what . '/' . $moment;
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.title_' . $what . '_between',
|
'firefly.title_' . $what . '_between',
|
||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
@@ -115,12 +118,12 @@ class TransactionController extends Controller
|
|||||||
Log::info('Count is zero, search for journals.');
|
Log::info('Count is zero, search for journals.');
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount();
|
||||||
->disableInternalFilter();
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$journals = $collector->getPaginatedJournals();
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('/budgets/list/no-budget');
|
$journals->setPath($path);
|
||||||
$count = $journals->getCollection()->count();
|
$count = $journals->getCollection()->count();
|
||||||
if ($count === 0) {
|
if ($count === 0 && $loop < 3) {
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfPeriod($start, $range);
|
$end = Navigation::endOfPeriod($start, $range);
|
||||||
@@ -128,7 +131,7 @@ class TransactionController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moment != 'all' && $loop > 1) {
|
if ($moment !== 'all' && $loop > 1) {
|
||||||
$subTitle = trans(
|
$subTitle = trans(
|
||||||
'firefly.title_' . $what . '_between',
|
'firefly.title_' . $what . '_between',
|
||||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||||
@@ -170,7 +173,7 @@ class TransactionController extends Controller
|
|||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param JournalTaskerInterface $tasker
|
* @param JournalTaskerInterface $tasker
|
||||||
*
|
*
|
||||||
* @return View
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||||
*/
|
*/
|
||||||
public function show(TransactionJournal $journal, JournalTaskerInterface $tasker)
|
public function show(TransactionJournal $journal, JournalTaskerInterface $tasker)
|
||||||
{
|
{
|
||||||
@@ -178,21 +181,12 @@ class TransactionController extends Controller
|
|||||||
return $this->redirectToAccount($journal);
|
return $this->redirectToAccount($journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = $tasker->getPiggyBankEvents($journal);
|
$events = $tasker->getPiggyBankEvents($journal);
|
||||||
$transactions = $tasker->getTransactionsOverview($journal);
|
$transactions = $tasker->getTransactionsOverview($journal);
|
||||||
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||||
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
|
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
|
||||||
$foreignCurrency = null;
|
|
||||||
|
|
||||||
if ($journal->hasMeta('foreign_currency_id')) {
|
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
/** @var CurrencyRepositoryInterface $repository */
|
|
||||||
$repository = app(CurrencyRepositoryInterface::class);
|
|
||||||
$foreignCurrency = $repository->find(intval($journal->getMeta('foreign_currency_id')));
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'foreignCurrency'));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -234,7 +228,8 @@ class TransactionController extends Controller
|
|||||||
// count journals without budget in this period:
|
// count journals without budget in this period:
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withOpposingAccount()->setTypes($types)->disableInternalFilter();
|
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withOpposingAccount()->setTypes($types);
|
||||||
|
$collector->removeFilter(InternalTransferFilter::class);
|
||||||
$set = $collector->getJournals();
|
$set = $collector->getJournals();
|
||||||
$sum = $set->sum('transaction_amount');
|
$sum = $set->sum('transaction_amount');
|
||||||
$journals = $set->count();
|
$journals = $set->count();
|
||||||
|
|||||||
@@ -38,19 +38,19 @@ class AccountFormRequest extends Request
|
|||||||
public function getAccountData(): array
|
public function getAccountData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->string('name'),
|
'name' => $this->string('name'),
|
||||||
'active' => $this->boolean('active'),
|
'active' => $this->boolean('active'),
|
||||||
'accountType' => $this->string('what'),
|
'accountType' => $this->string('what'),
|
||||||
'currency_id' => $this->integer('currency_id'),
|
'currency_id' => $this->integer('currency_id'),
|
||||||
'virtualBalance' => $this->float('virtualBalance'),
|
'virtualBalance' => $this->float('virtualBalance'),
|
||||||
'iban' => $this->string('iban'),
|
'iban' => $this->string('iban'),
|
||||||
'BIC' => $this->string('BIC'),
|
'BIC' => $this->string('BIC'),
|
||||||
'accountNumber' => $this->string('accountNumber'),
|
'accountNumber' => $this->string('accountNumber'),
|
||||||
'accountRole' => $this->string('accountRole'),
|
'accountRole' => $this->string('accountRole'),
|
||||||
'openingBalance' => $this->float('openingBalance'),
|
'openingBalance' => $this->float('openingBalance'),
|
||||||
'openingBalanceDate' => $this->date('openingBalanceDate'),
|
'openingBalanceDate' => $this->date('openingBalanceDate'),
|
||||||
'ccType' => $this->string('ccType'),
|
'ccType' => $this->string('ccType'),
|
||||||
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
|
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ class ImportUploadRequest extends Request
|
|||||||
$types = array_keys(config('firefly.import_formats'));
|
$types = array_keys(config('firefly.import_formats'));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'import_file' => 'required|file',
|
'import_file' => 'required|file',
|
||||||
'import_file_type' => 'required|in:' . join(',', $types),
|
'import_file_type' => 'required|in:' . join(',', $types),
|
||||||
|
'configuration_file' => 'file',
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class TagFormRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function collectTagData(): array
|
public function collectTagData(): array
|
||||||
{
|
{
|
||||||
if ($this->get('setTag') == 'true') {
|
if ($this->get('setTag') === 'true') {
|
||||||
$latitude = $this->string('latitude');
|
$latitude = $this->string('latitude');
|
||||||
$longitude = $this->string('longitude');
|
$longitude = $this->string('longitude');
|
||||||
$zoomLevel = $this->integer('zoomLevel');
|
$zoomLevel = $this->integer('zoomLevel');
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DaveJamesMiller\Breadcrumbs\Generator as BreadCrumbGenerator;
|
use DaveJamesMiller\Breadcrumbs\Generator as BreadCrumbGenerator;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
@@ -78,10 +79,10 @@ Breadcrumbs::register(
|
|||||||
$breadcrumbs->push(trans('firefly.everything'), route('accounts.show', [$account->id, 'all']));
|
$breadcrumbs->push(trans('firefly.everything'), route('accounts.show', [$account->id, 'all']));
|
||||||
}
|
}
|
||||||
// when is specific period or when empty:
|
// when is specific period or when empty:
|
||||||
if ($moment !== 'all') {
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
);
|
);
|
||||||
$breadcrumbs->push($title, route('accounts.show', [$account->id, $moment, $start, $end]));
|
$breadcrumbs->push($title, route('accounts.show', [$account->id, $moment, $start, $end]));
|
||||||
}
|
}
|
||||||
@@ -91,7 +92,7 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'accounts.delete', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
|
'accounts.delete', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
|
||||||
$breadcrumbs->parent('accounts.show', $account, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('accounts.show', $account, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('firefly.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id]));
|
$breadcrumbs->push(trans('firefly.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -99,7 +100,7 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'accounts.edit', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
|
'accounts.edit', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
|
||||||
$breadcrumbs->parent('accounts.show', $account, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('accounts.show', $account, '(nothing)', new Carbon, new Carbon);
|
||||||
$what = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
$what = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||||
|
|
||||||
$breadcrumbs->push(trans('firefly.edit_' . $what . '_account', ['name' => e($account->name)]), route('accounts.edit', [$account->id]));
|
$breadcrumbs->push(trans('firefly.edit_' . $what . '_account', ['name' => e($account->name)]), route('accounts.edit', [$account->id]));
|
||||||
@@ -257,8 +258,8 @@ Breadcrumbs::register(
|
|||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
$breadcrumbs->push(trans('firefly.everything'), route('budgets.no-budget', ['all']));
|
$breadcrumbs->push(trans('firefly.everything'), route('budgets.no-budget', ['all']));
|
||||||
}
|
}
|
||||||
// when is specific period:
|
// when is specific period or when empty:
|
||||||
if ($moment !== 'all') {
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
@@ -312,13 +313,13 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'categories.edit', function (BreadCrumbGenerator $breadcrumbs, Category $category) {
|
'categories.edit', function (BreadCrumbGenerator $breadcrumbs, Category $category) {
|
||||||
$breadcrumbs->parent('categories.show', $category, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('categories.show', $category, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('firefly.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id]));
|
$breadcrumbs->push(trans('firefly.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'categories.delete', function (BreadCrumbGenerator $breadcrumbs, Category $category) {
|
'categories.delete', function (BreadCrumbGenerator $breadcrumbs, Category $category) {
|
||||||
$breadcrumbs->parent('categories.show', $category, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('categories.show', $category, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('firefly.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id]));
|
$breadcrumbs->push(trans('firefly.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -333,8 +334,8 @@ Breadcrumbs::register(
|
|||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
$breadcrumbs->push(trans('firefly.everything'), route('categories.show', [$category->id, 'all']));
|
$breadcrumbs->push(trans('firefly.everything'), route('categories.show', [$category->id, 'all']));
|
||||||
}
|
}
|
||||||
// when is specific period:
|
// when is specific period or when empty:
|
||||||
if ($moment !== 'all') {
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
@@ -354,8 +355,8 @@ Breadcrumbs::register(
|
|||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
$breadcrumbs->push(trans('firefly.everything'), route('categories.no-category', ['all']));
|
$breadcrumbs->push(trans('firefly.everything'), route('categories.no-category', ['all']));
|
||||||
}
|
}
|
||||||
// when is specific period:
|
// when is specific period or when empty:
|
||||||
if ($moment !== 'all') {
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
@@ -469,26 +470,20 @@ Breadcrumbs::register(
|
|||||||
$breadcrumbs->push(trans('firefly.import'), route('import.index'));
|
$breadcrumbs->push(trans('firefly.import'), route('import.index'));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Breadcrumbs::register(
|
|
||||||
'import.complete', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
|
|
||||||
$breadcrumbs->parent('import.index');
|
|
||||||
$breadcrumbs->push(trans('firefly.bread_crumb_import_complete', ['key' => $job->key]), route('import.complete', [$job->key]));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'import.configure', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
|
'import.configure', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
|
||||||
$breadcrumbs->parent('import.index');
|
$breadcrumbs->parent('import.index');
|
||||||
$breadcrumbs->push(trans('firefly.bread_crumb_configure_import', ['key' => $job->key]), route('import.configure', [$job->key]));
|
$breadcrumbs->push(trans('firefly.import_config_sub_title', ['key' => $job->key]), route('import.configure', [$job->key]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'import.finished', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
|
'import.status', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
|
||||||
$breadcrumbs->parent('import.index');
|
$breadcrumbs->parent('import.index');
|
||||||
$breadcrumbs->push(trans('firefly.bread_crumb_import_finished', ['key' => $job->key]), route('import.finished', [$job->key]));
|
$breadcrumbs->push(trans('firefly.import_status_bread_crumb', ['key' => $job->key]), route('import.status', [$job->key]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PREFERENCES
|
* PREFERENCES
|
||||||
*/
|
*/
|
||||||
@@ -686,7 +681,7 @@ Breadcrumbs::register(
|
|||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'search.index', function (BreadCrumbGenerator $breadcrumbs, $query) {
|
'search.index', function (BreadCrumbGenerator $breadcrumbs, $query) {
|
||||||
$breadcrumbs->parent('home');
|
$breadcrumbs->parent('home');
|
||||||
$breadcrumbs->push(trans('breadcrumbs.searchResult', ['query' => e($query)]), route('search.index'));
|
$breadcrumbs->push(trans('breadcrumbs.search_result', ['query' => e($query)]), route('search.index'));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -710,14 +705,14 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'tags.edit', function (BreadCrumbGenerator $breadcrumbs, Tag $tag) {
|
'tags.edit', function (BreadCrumbGenerator $breadcrumbs, Tag $tag) {
|
||||||
$breadcrumbs->parent('tags.show', $tag, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('tags.show', $tag, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', [$tag->id]));
|
$breadcrumbs->push(trans('breadcrumbs.edit_tag', ['tag' => e($tag->tag)]), route('tags.edit', [$tag->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'tags.delete', function (BreadCrumbGenerator $breadcrumbs, Tag $tag) {
|
'tags.delete', function (BreadCrumbGenerator $breadcrumbs, Tag $tag) {
|
||||||
$breadcrumbs->parent('tags.show', $tag, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('tags.show', $tag, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id]));
|
$breadcrumbs->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -726,16 +721,17 @@ Breadcrumbs::register(
|
|||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'tags.show', function (BreadCrumbGenerator $breadcrumbs, Tag $tag, string $moment, Carbon $start, Carbon $end) {
|
'tags.show', function (BreadCrumbGenerator $breadcrumbs, Tag $tag, string $moment, Carbon $start, Carbon $end) {
|
||||||
$breadcrumbs->parent('tags.index');
|
$breadcrumbs->parent('tags.index');
|
||||||
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id], $moment));
|
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id, $moment]));
|
||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id], $moment));
|
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id, $moment]));
|
||||||
}
|
}
|
||||||
if ($moment !== 'all') {
|
// when is specific period or when empty:
|
||||||
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
);
|
);
|
||||||
$breadcrumbs->push($title, route('tags.show', [$tag->id], $moment));
|
$breadcrumbs->push($title, route('tags.show', [$tag->id, $moment]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -753,8 +749,8 @@ Breadcrumbs::register(
|
|||||||
$breadcrumbs->push(trans('firefly.everything'), route('transactions.index', [$what, 'all']));
|
$breadcrumbs->push(trans('firefly.everything'), route('transactions.index', [$what, 'all']));
|
||||||
}
|
}
|
||||||
|
|
||||||
// when is specific period:
|
// when is specific period or when empty:
|
||||||
if ($moment !== 'all') {
|
if ($moment !== 'all' && $moment !== '(nothing)') {
|
||||||
$title = trans(
|
$title = trans(
|
||||||
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
|
||||||
@@ -767,7 +763,7 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'transactions.create', function (BreadCrumbGenerator $breadcrumbs, string $what) {
|
'transactions.create', function (BreadCrumbGenerator $breadcrumbs, string $what) {
|
||||||
$breadcrumbs->parent('transactions.index', $what, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('transactions.index', $what, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what]));
|
$breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -789,7 +785,7 @@ Breadcrumbs::register(
|
|||||||
'transactions.show', function (BreadCrumbGenerator $breadcrumbs, TransactionJournal $journal) {
|
'transactions.show', function (BreadCrumbGenerator $breadcrumbs, TransactionJournal $journal) {
|
||||||
|
|
||||||
$what = strtolower($journal->transactionType->type);
|
$what = strtolower($journal->transactionType->type);
|
||||||
$breadcrumbs->parent('transactions.index', $what, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('transactions.index', $what, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push($journal->description, route('transactions.show', [$journal->id]));
|
$breadcrumbs->push($journal->description, route('transactions.show', [$journal->id]));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -814,7 +810,7 @@ Breadcrumbs::register(
|
|||||||
if ($journals->count() > 0) {
|
if ($journals->count() > 0) {
|
||||||
$journalIds = $journals->pluck('id')->toArray();
|
$journalIds = $journals->pluck('id')->toArray();
|
||||||
$what = strtolower($journals->first()->transactionType->type);
|
$what = strtolower($journals->first()->transactionType->type);
|
||||||
$breadcrumbs->parent('transactions.index', $what, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('transactions.index', $what, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
|
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -829,7 +825,7 @@ Breadcrumbs::register(
|
|||||||
|
|
||||||
$journalIds = $journals->pluck('id')->toArray();
|
$journalIds = $journals->pluck('id')->toArray();
|
||||||
$what = strtolower($journals->first()->transactionType->type);
|
$what = strtolower($journals->first()->transactionType->type);
|
||||||
$breadcrumbs->parent('transactions.index', $what, '', new Carbon, new Carbon);
|
$breadcrumbs->parent('transactions.index', $what, '(nothing)', new Carbon, new Carbon);
|
||||||
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.delete', $journalIds));
|
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.delete', $journalIds));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
65
app/Import/Configurator/ConfiguratorInterface.php
Normal file
65
app/Import/Configurator/ConfiguratorInterface.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ConfiguratorInterface.php
|
||||||
|
* Copyright (c) 2017 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\Import\Configurator;
|
||||||
|
|
||||||
|
use FireflyIII\Models\ImportJob;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface ConfiguratorInterface
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Import\Configurator
|
||||||
|
*/
|
||||||
|
interface ConfiguratorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* ConfiguratorInterface constructor.
|
||||||
|
*/
|
||||||
|
public function __construct();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store any data from the $data array into the job.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function configureJob(array $data): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the data required for the next step in the job configuration.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getNextData(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the view of the next step in the job configuration.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNextView(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when the initial configuration for this job is complete.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isJobConfigured(): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ImportJob $job
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setJob(ImportJob $job);
|
||||||
|
|
||||||
|
}
|
||||||
159
app/Import/Configurator/CsvConfigurator.php
Normal file
159
app/Import/Configurator/CsvConfigurator.php
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CsvConfigurator.php
|
||||||
|
* Copyright (c) 2017 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\Import\Configurator;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
|
||||||
|
use FireflyIII\Support\Import\Configuration\Csv\Initial;
|
||||||
|
use FireflyIII\Support\Import\Configuration\Csv\Map;
|
||||||
|
use FireflyIII\Support\Import\Configuration\Csv\Roles;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CsvConfigurator
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Import\Configurator
|
||||||
|
*/
|
||||||
|
class CsvConfigurator implements ConfiguratorInterface
|
||||||
|
{
|
||||||
|
private $job;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfiguratorInterface constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store any data from the $data array into the job.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function configureJob(array $data): bool
|
||||||
|
{
|
||||||
|
$class = $this->getConfigurationClass();
|
||||||
|
$job = $this->job;
|
||||||
|
/** @var ConfigurationInterface $object */
|
||||||
|
$object = new $class($this->job);
|
||||||
|
$object->setJob($job);
|
||||||
|
|
||||||
|
return $object->storeConfiguration($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the data required for the next step in the job configuration.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function getNextData(): array
|
||||||
|
{
|
||||||
|
$class = $this->getConfigurationClass();
|
||||||
|
$job = $this->job;
|
||||||
|
/** @var ConfigurationInterface $object */
|
||||||
|
$object = app($class);
|
||||||
|
$object->setJob($job);
|
||||||
|
|
||||||
|
return $object->getData();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function getNextView(): string
|
||||||
|
{
|
||||||
|
if (!$this->job->configuration['initial-config-complete']) {
|
||||||
|
return 'import.csv.initial';
|
||||||
|
}
|
||||||
|
if (!$this->job->configuration['column-roles-complete']) {
|
||||||
|
return 'import.csv.roles';
|
||||||
|
}
|
||||||
|
if (!$this->job->configuration['column-mapping-complete']) {
|
||||||
|
return 'import.csv.map';
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new FireflyException('No view for state');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isJobConfigured(): bool
|
||||||
|
{
|
||||||
|
$config = $this->job->configuration;
|
||||||
|
$config['initial-config-complete'] = $config['initial-config-complete'] ?? false;
|
||||||
|
$config['column-roles-complete'] = $config['column-roles-complete'] ?? false;
|
||||||
|
$config['column-mapping-complete'] = $config['column-mapping-complete'] ?? false;
|
||||||
|
$this->job->configuration = $config;
|
||||||
|
$this->job->save();
|
||||||
|
|
||||||
|
if ($this->job->configuration['initial-config-complete']
|
||||||
|
&& $this->job->configuration['column-roles-complete']
|
||||||
|
&& $this->job->configuration['column-mapping-complete']
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ImportJob $job
|
||||||
|
*/
|
||||||
|
public function setJob(ImportJob $job)
|
||||||
|
{
|
||||||
|
$this->job = $job;
|
||||||
|
if (is_null($this->job->configuration) || count($this->job->configuration) === 0) {
|
||||||
|
Log::debug(sprintf('Gave import job %s initial configuration.', $this->job->key));
|
||||||
|
$this->job->configuration = config('csv.default_config');
|
||||||
|
$this->job->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function getConfigurationClass(): string
|
||||||
|
{
|
||||||
|
$class = false;
|
||||||
|
switch (true) {
|
||||||
|
case (!$this->job->configuration['initial-config-complete']):
|
||||||
|
$class = Initial::class;
|
||||||
|
break;
|
||||||
|
case (!$this->job->configuration['column-roles-complete']):
|
||||||
|
$class = Roles::class;
|
||||||
|
break;
|
||||||
|
case (!$this->job->configuration['column-mapping-complete']):
|
||||||
|
$class = Map::class;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($class === false || strlen($class) === 0) {
|
||||||
|
throw new FireflyException('Cannot handle current job state in getConfigurationClass().');
|
||||||
|
}
|
||||||
|
if (!class_exists($class)) {
|
||||||
|
throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* AccountId.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class AccountId
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class AccountId extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = intval(trim($value));
|
|
||||||
Log::debug('Going to convert using AssetAccountId', ['value' => $value]);
|
|
||||||
if ($value === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$account = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by ID', ['id' => $account->id]);
|
|
||||||
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$account = $repository->find($value);// not mapped? Still try to find it first:
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
$this->setCertainty(90);
|
|
||||||
Log::debug('Found account by ID ', ['id' => $account->id]);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
$this->setCertainty(0); // should not really happen. If the ID does not match FF, what is FF supposed to do?
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
*
|
*
|
||||||
* @package FireflyIII\Import\Converter
|
* @package FireflyIII\Import\Converter
|
||||||
*/
|
*/
|
||||||
class Amount extends BasicConverter implements ConverterInterface
|
class Amount implements ConverterInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,18 +28,18 @@ class Amount extends BasicConverter implements ConverterInterface
|
|||||||
*
|
*
|
||||||
* @param $value
|
* @param $value
|
||||||
*
|
*
|
||||||
* @return float
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function convert($value): float
|
public function convert($value): string
|
||||||
{
|
{
|
||||||
$len = strlen($value);
|
$len = strlen($value);
|
||||||
$decimalPosition = $len - 3;
|
$decimalPosition = $len - 3;
|
||||||
$decimal = null;
|
$decimal = null;
|
||||||
|
|
||||||
if (($len > 2 && $value{$decimalPosition} == '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
||||||
$decimal = '.';
|
$decimal = '.';
|
||||||
}
|
}
|
||||||
if ($len > 2 && $value{$decimalPosition} == ',') {
|
if ($len > 2 && $value{$decimalPosition} === ',') {
|
||||||
$decimal = ',';
|
$decimal = ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,10 +59,7 @@ class Amount extends BasicConverter implements ConverterInterface
|
|||||||
$value = str_replace($search, '', $value);
|
$value = str_replace($search, '', $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setCertainty(90);
|
return strval(round(floatval($value), 12));
|
||||||
|
|
||||||
|
|
||||||
return round(floatval($value), 12);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* AssetAccountIban.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\AccountType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class AssetAccountIban
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function convert($value): Account
|
|
||||||
{
|
|
||||||
$value = trim($value);
|
|
||||||
Log::debug('Going to convert ', ['value' => $value]);
|
|
||||||
|
|
||||||
if (strlen($value) === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$account = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
$this->setCertainty(100);
|
|
||||||
Log::debug('Found account by ID', ['id' => $account->id]);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$account = $repository->findByIban($value, [AccountType::ASSET]);
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by IBAN', ['id' => $account->id]);
|
|
||||||
$this->setCertainty(50);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
|
||||||
['name' => 'Asset account with IBAN ' . $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
|
||||||
'active' => true, 'openingBalance' => 0]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (is_null($account->id)) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
Log::info('Could not store new asset account by IBAN', $account->getErrors()->toArray());
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* AssetAccountName.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\AccountType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class AssetAccountName
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class AssetAccountName extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = trim($value);
|
|
||||||
Log::debug('Going to convert using AssetAccountName', ['value' => $value]);
|
|
||||||
|
|
||||||
if (strlen($value) === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$account = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by ID', ['id' => $account->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$account = $repository->findByName($value, [AccountType::ASSET]);
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found asset account by name', ['value' => $value, 'id' => $account->id]);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
|
||||||
['name' => $value, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
|
||||||
'active' => true]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (is_null($account->id)) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
Log::info('Could not store new asset account by name', $account->getErrors()->toArray());
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
Log::debug('Created new asset account ', ['name' => $account->name, 'id' => $account->id]);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* AssetAccountNumber.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\AccountType;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class AssetAccountNumber
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = trim($value);
|
|
||||||
Log::debug('Going to convert using AssetAccountNumber', ['value' => $value]);
|
|
||||||
|
|
||||||
if (strlen($value) === 0) {
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$account = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by ID', ['id' => $account->id]);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$account = $repository->findByAccountNumber($value, [AccountType::ASSET]);
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
|
||||||
$this->setCertainty(50);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to find by the name we would give it:
|
|
||||||
$accountName = 'Asset account with number ' . e($value);
|
|
||||||
$account = $repository->findByName($accountName, [AccountType::ASSET]);
|
|
||||||
if (!is_null($account->id)) {
|
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
|
||||||
$this->setCertainty(50);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
|
||||||
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
|
||||||
'accountType' => 'asset',
|
|
||||||
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (is_null($account->id)) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
Log::info('Could not store new asset account by account number', $account->getErrors()->toArray());
|
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BasicConverter.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\User;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BasicConverter
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class BasicConverter
|
|
||||||
{
|
|
||||||
/** @var int */
|
|
||||||
public $certainty = 50;
|
|
||||||
/** @var array */
|
|
||||||
public $config;
|
|
||||||
/** @var bool */
|
|
||||||
public $doMap;
|
|
||||||
/** @var array */
|
|
||||||
public $mapping = [];
|
|
||||||
/** @var User */
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getCertainty(): int
|
|
||||||
{
|
|
||||||
return $this->certainty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $certainty
|
|
||||||
*/
|
|
||||||
protected function setCertainty(int $certainty)
|
|
||||||
{
|
|
||||||
$this->certainty = $certainty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $config
|
|
||||||
*/
|
|
||||||
public function setConfig(array $config)
|
|
||||||
{
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $doMap
|
|
||||||
*/
|
|
||||||
public function setDoMap(bool $doMap)
|
|
||||||
{
|
|
||||||
$this->doMap = $doMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $mapping
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setMapping(array $mapping)
|
|
||||||
{
|
|
||||||
$this->mapping = $mapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
public function setUser(User $user)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BillId.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Bill;
|
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BillId
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class BillId extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Bill
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = intval(trim($value));
|
|
||||||
Log::debug('Going to convert using BillId', ['value' => $value]);
|
|
||||||
|
|
||||||
if ($value === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var BillRepositoryInterface $repository */
|
|
||||||
$repository = app(BillRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found bill in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$bill = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($bill->id)) {
|
|
||||||
Log::debug('Found bill by ID', ['id' => $bill->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $bill;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$bill = $repository->find($value);
|
|
||||||
if (!is_null($bill->id)) {
|
|
||||||
Log::debug('Found bill by ID ', ['id' => $bill->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should not really happen. If the ID does not match FF, what is FF supposed to do?
|
|
||||||
Log::info(sprintf('Could not find bill with ID %d. Will return NULL', $value));
|
|
||||||
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Bill;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BillName.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Models\Bill;
|
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BillName
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class BillName extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Bill
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = trim($value);
|
|
||||||
Log::debug('Going to convert using BillName', ['value' => $value]);
|
|
||||||
|
|
||||||
if (strlen($value) === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var BillRepositoryInterface $repository */
|
|
||||||
$repository = app(BillRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found bill in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$bill = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($bill->id)) {
|
|
||||||
Log::debug('Found bill by ID', ['id' => $bill->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $bill;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$bill = $repository->findByName($value);
|
|
||||||
if (!is_null($bill->id)) {
|
|
||||||
Log::debug('Found bill by name ', ['id' => $bill->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new bill. Use a lot of made up values.
|
|
||||||
$bill = $repository->store(
|
|
||||||
[
|
|
||||||
'name' => $value,
|
|
||||||
'match' => $value,
|
|
||||||
'amount_min' => 1,
|
|
||||||
'user' => $this->user->id,
|
|
||||||
'amount_max' => 10,
|
|
||||||
'date' => date('Ymd'),
|
|
||||||
'repeat_freq' => 'monthly',
|
|
||||||
'skip' => 0,
|
|
||||||
'automatch' => 0,
|
|
||||||
'active' => 1,
|
|
||||||
|
|
||||||
]
|
|
||||||
);
|
|
||||||
if (is_null($bill->id)) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
Log::info('Could not store new bill by name', $bill->getErrors()->toArray());
|
|
||||||
|
|
||||||
return new Bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $bill;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BudgetId.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BudgetId
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class BudgetId extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Budget
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = intval(trim($value));
|
|
||||||
Log::debug('Going to convert using BudgetId', ['value' => $value]);
|
|
||||||
|
|
||||||
if ($value === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var BudgetRepositoryInterface $repository */
|
|
||||||
$repository = app(BudgetRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found budget in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$budget = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($budget->id)) {
|
|
||||||
Log::debug('Found budget by ID', ['id' => $budget->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $budget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$budget = $repository->find($value);
|
|
||||||
if (!is_null($budget->id)) {
|
|
||||||
Log::debug('Found budget by ID ', ['id' => $budget->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should not really happen. If the ID does not match FF, what is FF supposed to do?
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
Log::info(sprintf('Could not find budget with ID %d. Will return NULL', $value));
|
|
||||||
|
|
||||||
return new Budget;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BudgetName.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\Import\Converter;
|
|
||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BudgetName
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Import\Converter
|
|
||||||
*/
|
|
||||||
class BudgetName extends BasicConverter implements ConverterInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return Budget
|
|
||||||
*/
|
|
||||||
public function convert($value)
|
|
||||||
{
|
|
||||||
$value = trim($value);
|
|
||||||
Log::debug('Going to convert using BudgetName', ['value' => $value]);
|
|
||||||
|
|
||||||
if (strlen($value) === 0) {
|
|
||||||
$this->setCertainty(0);
|
|
||||||
|
|
||||||
return new Budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var BudgetRepositoryInterface $repository */
|
|
||||||
$repository = app(BudgetRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->user);
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
|
||||||
Log::debug('Found budget in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
|
||||||
$budget = $repository->find(intval($this->mapping[$value]));
|
|
||||||
if (!is_null($budget->id)) {
|
|
||||||
Log::debug('Found budget by ID', ['id' => $budget->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $budget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
|
||||||
$budget = $repository->findByName($value);
|
|
||||||
if (!is_null($budget->id)) {
|
|
||||||
Log::debug('Found budget by name ', ['id' => $budget->id]);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new budget. Use a lot of made up values.
|
|
||||||
$budget = $repository->store(
|
|
||||||
[
|
|
||||||
'name' => $value,
|
|
||||||
'user' => $this->user->id,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$this->setCertainty(100);
|
|
||||||
|
|
||||||
return $budget;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user