mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-08-17 03:14:34 +00:00
Compare commits
451 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d357142075 | ||
|
2e7d339d7e | ||
|
6303b172b1 | ||
|
636ae193a7 | ||
|
aff8493204 | ||
|
8f2d4494d5 | ||
|
7a2bb4eb96 | ||
|
4916c06797 | ||
|
a818ab0942 | ||
|
9aa89393c0 | ||
|
216b304fe1 | ||
|
cf8a687b4d | ||
|
d1d6ba4114 | ||
|
a5ac713310 | ||
|
6fa8c33672 | ||
|
dd2b019d3c | ||
|
3a12ad192f | ||
|
d669b75352 | ||
|
746d50d459 | ||
|
f741552d91 | ||
|
c38e4b86b4 | ||
|
b044d85e90 | ||
|
24d111f026 | ||
|
f50058e3c2 | ||
|
ce9445168c | ||
|
27b8b4b35a | ||
|
9ccb67db8a | ||
|
3d82afd4e6 | ||
|
5f9cb61160 | ||
|
7f54b70c24 | ||
|
a156dce281 | ||
|
c0b0e58720 | ||
|
170ffbae04 | ||
|
6755ec7eb0 | ||
|
c8bc9a096a | ||
|
dc7f5a562b | ||
|
3b5b51578d | ||
|
41188a1bd6 | ||
|
d9bafe34eb | ||
|
43dbba5378 | ||
|
168ed5ac56 | ||
|
e5b4a55d8e | ||
|
167c057e8a | ||
|
71bf054ab1 | ||
|
111fcd77c4 | ||
|
287c1c4ffa | ||
|
3d69dc786d | ||
|
57a3f20c13 | ||
|
eab2c57594 | ||
|
b019962f34 | ||
|
5c59c819b6 | ||
|
93b97b8d72 | ||
|
f1f922031a | ||
|
390cace775 | ||
|
28fdad9426 | ||
|
9155c13e08 | ||
|
e8776d44c5 | ||
|
5ee8d04800 | ||
|
eb31934fb7 | ||
|
000f86d318 | ||
|
d9b3ebc82f | ||
|
91b3ca047a | ||
|
08131e42af | ||
|
a013553a6c | ||
|
7b2fe8eb4a | ||
|
610f782054 | ||
|
94700f4064 | ||
|
0f12ebb31c | ||
|
00a8a9ac0e | ||
|
92616c6ae3 | ||
|
97db618cd8 | ||
|
2832d308f1 | ||
|
a7ecdf715f | ||
|
935dc3ff9f | ||
|
99d14e8cbe | ||
|
664fde2344 | ||
|
27c45eface | ||
|
f83bc3c8b3 | ||
|
0d5efb8d27 | ||
|
bf9c1c1875 | ||
|
049d866f62 | ||
|
d672f0c2ad | ||
|
7b040e8583 | ||
|
e1cf285272 | ||
|
53f7f13362 | ||
|
f710677cdc | ||
|
b5fbc8b632 | ||
|
1fdc0a196c | ||
|
559f429f5e | ||
|
ae4b198d3d | ||
|
e088ecbbad | ||
|
f6b7bd5b44 | ||
|
f5a21f64c0 | ||
|
f5cbed7c0c | ||
|
59fff8928b | ||
|
8743b49a17 | ||
|
19dc91937e | ||
|
4846cb7b14 | ||
|
54e0ac816b | ||
|
9ce960b3d7 | ||
|
cc9d1c4bfd | ||
|
d211555beb | ||
|
9350557d10 | ||
|
ea6c54cad0 | ||
|
81287602d7 | ||
|
441ba79ec7 | ||
|
c9e4a09da6 | ||
|
c84f4e2bc0 | ||
|
6938f8ab89 | ||
|
4fdd2c851f | ||
|
78b56712fc | ||
|
6dcdb0f9a0 | ||
|
cfab837b96 | ||
|
b8461cdeb6 | ||
|
e07d65ef6b | ||
|
80cbc35c89 | ||
|
2faf84780f | ||
|
ebdb1a8836 | ||
|
2dfa51652a | ||
|
1cf1ea230f | ||
|
86e127ebff | ||
|
a313265785 | ||
|
37693ad08d | ||
|
e8180d252b | ||
|
9957c95c68 | ||
|
3354d53a48 | ||
|
ddaa53b940 | ||
|
c2e04a11bf | ||
|
00d059b8df | ||
|
f3fff6f1c5 | ||
|
9360eb6a70 | ||
|
26fb03e6c8 | ||
|
eed3d021d9 | ||
|
48728e8418 | ||
|
f39f25760a | ||
|
10ea60daaf | ||
|
f2fa5e140b | ||
|
be5ff35b13 | ||
|
bd5d73d1e6 | ||
|
cc712b0c75 | ||
|
a5ac84e1b9 | ||
|
cbe1f762ca | ||
|
e6db49c20c | ||
|
4909fcc8b4 | ||
|
68cdfd00b0 | ||
|
323c16ebe1 | ||
|
c20a38b7b0 | ||
|
20993342a2 | ||
|
1b3198c143 | ||
|
173d0290ea | ||
|
ae4cd8da12 | ||
|
a494398332 | ||
|
c82bdd1f5a | ||
|
e6ac3ccfad | ||
|
b13b58a2b2 | ||
|
2b6790f83f | ||
|
fe30850568 | ||
|
493c71b89e | ||
|
deaebc373c | ||
|
e834489206 | ||
|
1b316e462e | ||
|
7bf75128a8 | ||
|
3857e8d49f | ||
|
b16149b842 | ||
|
32ed8a4d8d | ||
|
f949d2476b | ||
|
0620830b10 | ||
|
7ee25693aa | ||
|
7cb86add64 | ||
|
fbc9720f7a | ||
|
ffdd37ddd5 | ||
|
51062bc80b | ||
|
31533b5ef8 | ||
|
3649b595df | ||
|
83b7c9aa32 | ||
|
4e3c59a2da | ||
|
dcbfe90cf7 | ||
|
f69be86c74 | ||
|
820722f44e | ||
|
2ff806dedc | ||
|
a755badd5f | ||
|
4df1e5393b | ||
|
8c55bd179f | ||
|
ccfc5ece66 | ||
|
6c12f1bc86 | ||
|
88839e9610 | ||
|
4f6a733238 | ||
|
dc9083a764 | ||
|
6f231b840b | ||
|
61a703e605 | ||
|
8e0e9734a5 | ||
|
2afb455bac | ||
|
01792f91e2 | ||
|
651dff0750 | ||
|
9cbfbd41dc | ||
|
168d6f403c | ||
|
41f200e630 | ||
|
0809cfdc6d | ||
|
466d739da8 | ||
|
daf65cb387 | ||
|
2605f60983 | ||
|
fcf6cdb134 | ||
|
209258b507 | ||
|
f80bc214f9 | ||
|
f76990bb9b | ||
|
eef68c9b31 | ||
|
006c2ae186 | ||
|
8b66ff6afe | ||
|
4cc6d57e6e | ||
|
af1c6b22bb | ||
|
5958990ed5 | ||
|
cd4cbdc197 | ||
|
1f538be16e | ||
|
9703439a4c | ||
|
42203ba872 | ||
|
cd60b852a1 | ||
|
5b1d9e1a0d | ||
|
e02657a7c7 | ||
|
c352eb0c74 | ||
|
81b9d5da09 | ||
|
b9b0413510 | ||
|
97770da619 | ||
|
521623797e | ||
|
15d3414443 | ||
|
245f06c93a | ||
|
33899f0e2f | ||
|
4697fbdeef | ||
|
06174d6afb | ||
|
b2bb16c1e0 | ||
|
27aae279e6 | ||
|
e9ee93beb7 | ||
|
20941dedd3 | ||
|
5ac88623ed | ||
|
768508dd4b | ||
|
668633e764 | ||
|
3dbb1f034d | ||
|
1270e5d15c | ||
|
afec8480fb | ||
|
8720511046 | ||
|
a7a00ecf40 | ||
|
88bbafd3e8 | ||
|
ae3258b449 | ||
|
cf4d7cfeef | ||
|
46ee2a0568 | ||
|
ce250c85fc | ||
|
1087b9f5df | ||
|
0dc74d9d14 | ||
|
98b272383f | ||
|
e722daafd0 | ||
|
670ab059d1 | ||
|
09f826ceba | ||
|
df5e3c9be9 | ||
|
31c336b3b1 | ||
|
b3a419b2f3 | ||
|
11f63fa6ce | ||
|
4b35059140 | ||
|
7836feba63 | ||
|
1e54366f1f | ||
|
d039bb0e03 | ||
|
166d32f073 | ||
|
321890992e | ||
|
d644403d8a | ||
|
44e76f9518 | ||
|
f9703eca4c | ||
|
48551e8bf5 | ||
|
74b538805b | ||
|
35f493beff | ||
|
06d11c9133 | ||
|
da7eb615db | ||
|
5da5024ad3 | ||
|
c1346d4c86 | ||
|
c38a4a15ff | ||
|
bdec94ead6 | ||
|
69bebf202f | ||
|
38895afea6 | ||
|
70ed4188b6 | ||
|
d889094863 | ||
|
c96eb8753e | ||
|
5a7607f6c6 | ||
|
71bb88529a | ||
|
b26164a168 | ||
|
19444551e4 | ||
|
e0b2a6e627 | ||
|
2973765866 | ||
|
2a08a25064 | ||
|
a55e291908 | ||
|
2003d37a9a | ||
|
29145bf6cf | ||
|
caa1ff120a | ||
|
ef4e964c94 | ||
|
1f263f60a7 | ||
|
5fc7cafcbe | ||
|
397c4926eb | ||
|
a14544398b | ||
|
d439dceac1 | ||
|
af29b31ea8 | ||
|
b311ef70bc | ||
|
9f9d744406 | ||
|
e094871bc9 | ||
|
dfc95cee45 | ||
|
fdca234721 | ||
|
cf5cc626d7 | ||
|
358d9aac7d | ||
|
681bc580c4 | ||
|
4a2768f8d1 | ||
|
05f8773fa0 | ||
|
5e5fdfdd51 | ||
|
5e744390c0 | ||
|
cb5fa401cb | ||
|
2980860377 | ||
|
9ff0b282f3 | ||
|
4bc1c032bd | ||
|
9fcb00f10b | ||
|
723e461559 | ||
|
9b24e6d448 | ||
|
e622774775 | ||
|
84ce9bc94b | ||
|
a3a1bc30b1 | ||
|
b4c9a7698e | ||
|
8b2d7fc32f | ||
|
90e66cbd94 | ||
|
fd9a7080ea | ||
|
c0fad106f0 | ||
|
78c8243184 | ||
|
780abecd53 | ||
|
ea6896816d | ||
|
95a456860a | ||
|
b1b2fda155 | ||
|
5847f534c3 | ||
|
e8e8163fa7 | ||
|
6a21d82dcf | ||
|
d6b47656bc | ||
|
8c37ef3a95 | ||
|
35deed1d10 | ||
|
ba32a665f1 | ||
|
bbd19be554 | ||
|
c360cc6db6 | ||
|
7e4b9af315 | ||
|
9b03e6b124 | ||
|
013e16e15f | ||
|
180ec52798 | ||
|
c7b47b4453 | ||
|
4b00db7662 | ||
|
78a7b995d2 | ||
|
f7c50a123a | ||
|
9617d17aca | ||
|
d9884ddf73 | ||
|
8157f0a958 | ||
|
b7580a5f83 | ||
|
66703b30b3 | ||
|
53677e3c64 | ||
|
feef6a1756 | ||
|
5f299b895b | ||
|
4e1bb5fbac | ||
|
47ccc513ad | ||
|
cce1a01936 | ||
|
6f2b1a6a76 | ||
|
8526907f50 | ||
|
bc192a8e54 | ||
|
9ff6f8fc52 | ||
|
6573bd6b4b | ||
|
9dc3f614af | ||
|
3888b8cceb | ||
|
294df4a2b3 | ||
|
265dd37212 | ||
|
eb7c79ad27 | ||
|
de111c7100 | ||
|
e892c9a824 | ||
|
5eb0e18cae | ||
|
27cabb398e | ||
|
64dbb14241 | ||
|
bb4e2be9eb | ||
|
7d1de0da17 | ||
|
bf16c9a42b | ||
|
1a7b1ce499 | ||
|
efc9bc71a7 | ||
|
fc5b315af0 | ||
|
7a4a78628d | ||
|
d16fb30a62 | ||
|
2d177e660e | ||
|
2f131dc170 | ||
|
94810e371a | ||
|
59731878f6 | ||
|
54ede8aa18 | ||
|
b415b6b043 | ||
|
70c922cdc5 | ||
|
068fc32cb2 | ||
|
3dcdacc3b8 | ||
|
a6594358d8 | ||
|
f98921da46 | ||
|
25747fbcf2 | ||
|
aac5c2b13c | ||
|
cc810a5b6f | ||
|
1b3592d959 | ||
|
d75614e9a7 | ||
|
08703e282f | ||
|
2904baf44e | ||
|
f99e46bf75 | ||
|
9f87890ead | ||
|
638184cf66 | ||
|
03babfe75c | ||
|
238ed3c788 | ||
|
6a9d931ba3 | ||
|
a3d2a9e00b | ||
|
39b88e8207 | ||
|
449c6dfde5 | ||
|
7cc47ca0b1 | ||
|
95f4a83f41 | ||
|
35154dc7a3 | ||
|
0fd0d7d080 | ||
|
658265c938 | ||
|
38fe9e7e1c | ||
|
77056dcf8d | ||
|
026683a8e1 | ||
|
6ab6dd6ac3 | ||
|
83de3482ce | ||
|
919a35aed3 | ||
|
ad3defb071 | ||
|
9c929ecd1b | ||
|
f79c9f7cf1 | ||
|
8e75c345d9 | ||
|
44886d9aad | ||
|
c2d444347d | ||
|
5cb497596d | ||
|
1857469d2f | ||
|
ea71b4843d | ||
|
97727e2e3d | ||
|
f81e7da8bb | ||
|
8e827bf83b | ||
|
9e1fa284ca | ||
|
3bf800be6e | ||
|
635b9f9dba | ||
|
52a0d7cf7b | ||
|
a34516932b | ||
|
929a2a30a2 | ||
|
ffa88eeb08 | ||
|
51b45b4ed4 | ||
|
f263844793 | ||
|
18c46df9aa | ||
|
15846e157b | ||
|
bc59f2db0d | ||
|
cd2be8c1a4 | ||
|
f958115c50 | ||
|
e7d677bfb6 | ||
|
3e80ffc52b | ||
|
d0c7a5c076 | ||
|
f3f4e6b354 | ||
|
5a45b25614 | ||
|
0b5ee1edfc | ||
|
da3dc599f9 | ||
|
5f6975a113 |
@@ -3,6 +3,7 @@ languages:
|
||||
JavaScript: true
|
||||
PHP: true
|
||||
exclude_paths:
|
||||
- "gulpfile.js"
|
||||
- "public/packages/maximebf/php-debugbar/debugbar.js"
|
||||
- "public/packages/maximebf/php-debugbar/widgets.js"
|
||||
- "public/packages/maximebf/php-debugbar/openhandler.js"
|
||||
|
20
.env.example
Normal file → Executable file
20
.env.example
Normal file → Executable file
@@ -11,15 +11,22 @@ DB_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
|
||||
DEFAULT_CURRENCY=EUR
|
||||
DEFAULT_LANGUAGE=en_US
|
||||
|
||||
EMAIL_SMTP=
|
||||
EMAIL_DRIVER=smtp
|
||||
EMAIL_USERNAME=
|
||||
EMAIL_PASSWORD=
|
||||
EMAIL_PRETEND=false
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_FROM=enter_your_email_here
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
|
||||
@@ -27,7 +34,4 @@ ANALYTICS_ID=
|
||||
RUNCLEANUP=true
|
||||
SITE_OWNER=mail@example.com
|
||||
|
||||
SENDGRID_USERNAME=
|
||||
SENDGRID_PASSWORD=
|
||||
|
||||
BLOCKED_DOMAINS=
|
31
.env.testing
Normal file → Executable file
31
.env.testing
Normal file → Executable file
@@ -1,6 +1,7 @@
|
||||
APP_ENV=testing
|
||||
APP_DEBUG=true
|
||||
APP_KEY=SomeRandomString
|
||||
APP_KEY=SomeRandomStringOf32CharsExactly
|
||||
|
||||
|
||||
DB_CONNECTION=sqlite
|
||||
DB_HOST=localhost
|
||||
@@ -10,9 +11,27 @@ DB_PASSWORD=secret
|
||||
|
||||
CACHE_DRIVER=array
|
||||
SESSION_DRIVER=array
|
||||
QUEUE_DRIVER=array
|
||||
|
||||
EMAIL_SMTP=
|
||||
EMAIL_USERNAME=
|
||||
EMAIL_PASSWORD=
|
||||
ANALYTICS_ID=ABC
|
||||
EMAIL_PRETEND=true
|
||||
DEFAULT_CURRENCY=EUR
|
||||
DEFAULT_LANGUAGE=en_US
|
||||
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=log
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_FROM=your_address_here@example.com
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
|
||||
ANALYTICS_ID=abcde
|
||||
RUNCLEANUP=false
|
||||
SITE_OWNER=your_address_here@example.com
|
||||
|
||||
BLOCKED_DOMAINS=
|
2
.gitattributes
vendored
Normal file → Executable file
2
.gitattributes
vendored
Normal file → Executable file
@@ -1 +1,3 @@
|
||||
* text=auto
|
||||
*.css linguist-vendored
|
||||
*.less linguist-vendored
|
||||
|
45
.gitignore
vendored
45
.gitignore
vendored
@@ -1,36 +1,17 @@
|
||||
/bootstrap/compiled.php
|
||||
/vendor
|
||||
composer.phar
|
||||
Thumbs.db
|
||||
.idea/
|
||||
tests/_output/*
|
||||
_ide_helper.php
|
||||
/build/logs
|
||||
index.html*
|
||||
app/storage/firefly-export*
|
||||
.vagrant
|
||||
firefly-iii-import-*.json
|
||||
tests/_output/*
|
||||
testing.sqlite
|
||||
_ide_helper_models.php
|
||||
clean.sqlite
|
||||
tests/acceptance/AcceptanceTester.php
|
||||
tests/functional/FunctionalTester.php
|
||||
tests/unit/UnitTester.php
|
||||
pi.php
|
||||
tests/_data/db.sqlite
|
||||
tests/_data/dump.sql
|
||||
db.sqlite_snapshot
|
||||
c3.php
|
||||
db.sqlite-journal
|
||||
tests/_output/*
|
||||
/node_modules
|
||||
Homestead.yaml
|
||||
Homestead.json
|
||||
.env
|
||||
clover.xml
|
||||
node_modules/
|
||||
addNewLines.php
|
||||
_ide_helper.php
|
||||
_ide_helper_models.php
|
||||
.phpstorm.meta.php
|
||||
.env.backup
|
||||
.env.local
|
||||
|
||||
tests/_output/*
|
||||
tests/_output/*
|
||||
storage/
|
||||
|
||||
# Eclipse project files
|
||||
.buildpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
.env.local
|
||||
|
10
.travis.yml
10
.travis.yml
@@ -3,16 +3,20 @@ sudo: false
|
||||
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7
|
||||
|
||||
install:
|
||||
- composer selfupdate
|
||||
- composer install --no-dev
|
||||
- composer update
|
||||
- php artisan env
|
||||
- mv -v .env.testing .env
|
||||
- php artisan env
|
||||
- touch storage/upload/at-1.data
|
||||
- touch storage/upload/at-2.data
|
||||
- touch storage/database/testing.db
|
||||
- php artisan migrate --env=testing
|
||||
- php artisan migrate --seed --env=testing
|
||||
- php artisan migrate --seed
|
||||
|
||||
script:
|
||||
- phpunit
|
||||
|
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (C) 2016 Sander Dorigo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
120
README.md
120
README.md
@@ -2,126 +2,26 @@
|
||||
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
|
||||
[](https://scrutinizer-ci.com/g/JC5/firefly-iii/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/JC5/firefly-iii/build-status/master)
|
||||
[](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102)
|
||||
[](https://codeclimate.com/github/JC5/firefly-iii)
|
||||
[](http://stillmaintained.com/JC5/firefly-iii)
|
||||
|
||||
## About
|
||||
|
||||
"Firefly III" is a financial manager. It can help you keep track of expenses, income, budgets and everything in between. It even supports credit cards, shared
|
||||
household accounts and savings accounts! It's pretty fancy. You should use it to save and organise money.
|
||||
|
||||
_Firefly is a system you'll have install yourself on webhosting of your choosing._
|
||||
|
||||
Personal financial management is pretty difficult, and everybody has their own approach to it. Some people
|
||||
make budgets, other people limit their cashflow by throwing away their credit cards, others try to increase
|
||||
their current cashflow. There are tons of ways to save and earn money.
|
||||
Personal financial management is pretty difficult, and everybody has their own approach to it. Some people make budgets, other people limit their cashflow by throwing away their credit cards, others try to increase their current cashflow. There are tons of ways to save and earn money.
|
||||
|
||||
Firefly works on the principle that if you know where you're money is going, you can stop it from going there.
|
||||
|
||||
To get to know Firefly, and to see if it fits you, check out these resources:
|
||||
#### Some advantages of using Firefly
|
||||
|
||||
- The screenshots below on this very page.
|
||||
- The featurelist below, also on this very page.
|
||||
- The [full description](https://github.com/JC5/firefly-iii/wiki/full-description), which will tell you how Firefly works,
|
||||
and the philosophy behind it.
|
||||
- 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 has lots of features without becoming fancy or bloated.
|
||||
- If you feel you're missing something you can just ask me and I'll add it!
|
||||
|
||||
|
||||
#### About the name (should you care)
|
||||
|
||||
It's III, or 3, because [version 2](https://github.com/JC5/Firefly) and version 1 (not online) preceded it. It has been growing steadily ever since.
|
||||
|
||||
## Current features
|
||||
|
||||
- [A double-entry bookkeeping system](https://en.wikipedia.org/wiki/Double-entry_bookkeeping_system);
|
||||
- You can store, edit and remove [withdrawals, deposits and transfers](https://en.wikipedia.org/wiki/Financial_transaction). This allows you full financial management;
|
||||
- You can manage different types of accounts;
|
||||
- [Asset](https://en.wikipedia.org/wiki/Asset) accounts
|
||||
- Shared [asset accounts](https://en.wikipedia.org/wiki/Asset) ([household accounts](https://en.wikipedia.org/wiki/Household))
|
||||
- Saving accounts
|
||||
- Credit cards
|
||||
- It's possible to create, change and manage money using _[budgets](https://en.wikipedia.org/wiki/Envelope_system)_;
|
||||
- Organize transactions using categories;
|
||||
- Save towards a goal using [piggy banks](https://en.wikipedia.org/wiki/Piggy_bank);
|
||||
- Predict and anticipate [bills](https://en.wikipedia.org/wiki/Invoice);
|
||||
- View income / expense [reports](https://en.wikipedia.org/wiki/Financial_statement);
|
||||
- Organize expenses using tags;
|
||||
- Lots of help text in case you don't get it.
|
||||
|
||||
Everything is organised:
|
||||
|
||||
- Clear views that should show you how you're doing;
|
||||
- Easy navigation through your records;
|
||||
- Browse back and forth to see previous months or even years;
|
||||
- Lots of charts because we all love them;
|
||||
- Financial reporting showing you how well you are doing.
|
||||
|
||||
## Screenshots
|
||||
|
||||
_Please note that everything in these screenshots is fictional and may not be realistic._
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Running and installing
|
||||
|
||||
If you're still interested please read [the installation guide](https://github.com/JC5/firefly-iii/wiki/Installation),
|
||||
[the upgrade guide](https://github.com/JC5/firefly-iii/wiki/Upgrade-instructions) (if applicable)
|
||||
and the **[first use guide](https://github.com/JC5/firefly-iii/wiki/First-use)**.
|
||||
|
||||
If you want to try out Firefly III, you can do so on [this dedicated website](https://geld.nder.be/).
|
||||
This site always runs the latest version of Firefly III. If you want to use it, please read the [privacy considerations](https://github.com/JC5/firefly-iii/wiki/Privacy-on-demo-site) for this demo-site. Accounts on the demo sites will stop working after one month. It's a trial.
|
||||
|
||||
## Security
|
||||
|
||||
You should always run Firefly III on a site with TLS enabled (https://). Please note that although some parts of the
|
||||
database are encrypted (transaction descriptions, names, etc.) some parts are _not_ (amounts, dates, etc). If you need
|
||||
more security, you must enable transparent database encryption or a comparable technology. Please remember that this
|
||||
is open source software under active development, and it is in no way guaranteed to be safe or secure.
|
||||
|
||||
## Translations
|
||||
|
||||
Firefly III is currently available in Dutch and English. Support for other languages is being worked on. I can use
|
||||
your help. Checkout [Crowdin](https://crowdin.com/project/firefly-iii) for more information.
|
||||
|
||||
## Credits
|
||||
|
||||
Firefly III uses the following libraries and tools:
|
||||
|
||||
* The AdminLTE template by [Almsaseed Studio](https://almsaeedstudio.com/)
|
||||
* The [Google charts](https://developers.google.com/chart/) library.
|
||||
* [Chart.js](http://www.chartjs.org/)
|
||||
* [Bootstrap](http://getbootstrap.com/)
|
||||
* [Laravel](http://laravel.com/)
|
||||
* [Twig](http://twig.sensiolabs.org/)
|
||||
* For development, some of the excellent tools made by [Barry van den Heuvel](https://github.com/barryvdh)
|
||||
* [Bootstrap sortable](https://github.com/drvic10k/bootstrap-sortable) by [Matúš Brliť](https://github.com/drvic10k).
|
||||
* [Date range picker](https://github.com/dangrossman/bootstrap-daterangepicker/) by [Dan Grossman](https://github.com/dangrossman)
|
||||
* The [real favicon generator](http://realfavicongenerator.net/)
|
||||
* Various other open source components (see [composer.json](https://github.com/JC5/firefly-iii/blob/master/composer.json))
|
||||
|
||||
|
||||
## Current state
|
||||
|
||||
Firefly III is pretty much all grown up. Full test coverage (nerd alert!) is coming. Translations are a work in progress.
|
||||
|
||||
Questions, ideas, bugs or other things to contribute? [Let me know](https://github.com/JC5/firefly-iii/issues/new)!
|
||||
|
||||
If you like this tool, feel free to [donate me some beer money](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2ZMV952UUSCLU&lc=NL&item_name=Development%20of%20Firefly¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted).
|
||||
|
||||
[](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102)
|
||||
[](https://codeclimate.com/github/JC5/firefly-iii)
|
||||
[](http://stillmaintained.com/JC5/firefly-iii)
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||

|
||||
Firefly is pretty awesome. [You can read more about Firefly III, and its features, on the Github Pages](https://jc5.github.io/firefly-iii/).
|
||||
|
27
_development/codesniffer/ruleset.xml
Normal file
27
_development/codesniffer/ruleset.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="JamesStandard">
|
||||
<rule ref="Zend">
|
||||
<exclude name="Zend.NamingConventions.ValidVariableName" />
|
||||
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace" />
|
||||
<!--<exclude name="PEAR.Whitespace.ScopeIndent"/>-->
|
||||
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace"/>
|
||||
<exclude name="Generic.Formatting.MultipleStatementAlignment.Incorrect" />
|
||||
<exclude name="PEAR.Functions.FunctionCallSignature" />
|
||||
|
||||
</rule>
|
||||
<!--
|
||||
Here we change two messages from the same sniff. Note how the
|
||||
codes are slightly different because the sniff developer has
|
||||
defined both a MaxExceeded message and a TooLong message. In the
|
||||
case of this sniff, one is used for warnings and one is used
|
||||
for errors.
|
||||
-->
|
||||
<rule ref="Generic.Files.LineLength">
|
||||
<properties>
|
||||
<property name="lineLimit" value="160"/>
|
||||
<property name="absoluteLineLimit" value="160"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
322
_development/codestyle.xml
Normal file
322
_development/codestyle.xml
Normal file
@@ -0,0 +1,322 @@
|
||||
<code_scheme name="Use This One">
|
||||
<option name="RIGHT_MARGIN" value="160" />
|
||||
<CoffeeScriptCodeStyleSettings>
|
||||
<option name="SPACE_BEFORE_PROPERTY_COLON" value="true" />
|
||||
</CoffeeScriptCodeStyleSettings>
|
||||
<JSCodeStyleSettings>
|
||||
<option name="ALIGN_MULTILINE_VAR_DECLARATION" value="true" />
|
||||
</JSCodeStyleSettings>
|
||||
<PHPCodeStyleSettings>
|
||||
<option name="ALIGN_KEY_VALUE_PAIRS" value="true" />
|
||||
<option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" />
|
||||
<option name="ALIGN_PHPDOC_COMMENTS" value="true" />
|
||||
<option name="ALIGN_ASSIGNMENTS" value="true" />
|
||||
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
|
||||
<option name="PHPDOC_BLANK_LINE_BEFORE_TAGS" value="true" />
|
||||
<option name="PHPDOC_BLANK_LINES_AROUND_PARAMETERS" value="true" />
|
||||
<option name="PHPDOC_WRAP_LONG_LINES" value="true" />
|
||||
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
|
||||
<option name="LOWER_CASE_NULL_CONST" value="true" />
|
||||
<option name="BLANK_LINE_BEFORE_RETURN_STATEMENT" value="true" />
|
||||
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
|
||||
<option name="ALIGN_CLASS_CONSTANTS" value="true" />
|
||||
<option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" />
|
||||
</PHPCodeStyleSettings>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="CoffeeScript">
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JavaScript">
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="PHP">
|
||||
<option name="RIGHT_MARGIN" value="160" />
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
|
||||
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
|
||||
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
|
||||
<option name="ALIGN_GROUP_FIELD_DECLARATIONS" value="true" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="1" />
|
||||
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="1" />
|
||||
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="EXTENDS_LIST_WRAP" value="1" />
|
||||
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
|
||||
<option name="BINARY_OPERATION_WRAP" value="1" />
|
||||
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="1" />
|
||||
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
||||
<option name="FOR_STATEMENT_WRAP" value="1" />
|
||||
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
|
||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||
<option name="PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE" value="true" />
|
||||
<option name="IF_BRACE_FORCE" value="3" />
|
||||
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||
<option name="WHILE_BRACE_FORCE" value="3" />
|
||||
<option name="FOR_BRACE_FORCE" value="3" />
|
||||
<arrangement>
|
||||
<tokens>
|
||||
<token id="modifiers" name="modifiers">
|
||||
<rules>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<PUBLIC>true</PUBLIC>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<PROTECTED>true</PROTECTED>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<PRIVATE>true</PRIVATE>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<PUBLIC>true</PUBLIC>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<PROTECTED>true</PROTECTED>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<PRIVATE>true</PRIVATE>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</rules>
|
||||
</token>
|
||||
<token id="visibility" name="visibility">
|
||||
<rules>
|
||||
<rule>
|
||||
<match>
|
||||
<PUBLIC>true</PUBLIC>
|
||||
</match>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<PROTECTED>true</PROTECTED>
|
||||
</match>
|
||||
</rule>
|
||||
<rule>
|
||||
<match>
|
||||
<PRIVATE>true</PRIVATE>
|
||||
</match>
|
||||
</rule>
|
||||
</rules>
|
||||
</token>
|
||||
</tokens>
|
||||
<groups>
|
||||
<group>
|
||||
<type>GETTERS_AND_SETTERS</type>
|
||||
<order>KEEP</order>
|
||||
</group>
|
||||
</groups>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<CONST />
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PUBLIC />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PROTECTED />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PRIVATE />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PUBLIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PROTECTED />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD />
|
||||
<PRIVATE />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<CONSTRUCTOR />
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PUBLIC />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PROTECTED />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PRIVATE />
|
||||
<STATIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PUBLIC />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PROTECTED />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD />
|
||||
<PRIVATE />
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<TRAIT />
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<INTERFACE />
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<CLASS />
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
36
_development/phpmd/phpmd.xml
Normal file
36
_development/phpmd/phpmd.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset name="pcsg-generated-ruleset"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<description>Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/
|
||||
</description>
|
||||
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
|
||||
<properties>
|
||||
<property name="reportLevel" value="5"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/NPathComplexity">
|
||||
<properties>
|
||||
<property name="minimum" value="128"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
|
||||
<properties>
|
||||
<property name="minimum" value="40"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
|
||||
<properties>
|
||||
<property name="minimum" value="5"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Import rule set and exclude rules -->
|
||||
<rule ref="rulesets/controversial.xml">
|
||||
<exclude name="CamelCasePropertyName" />
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
1
_development/readme.txt
Normal file
1
_development/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
These are some of the files I use for code formatting, PHPMD and PHPCS.
|
@@ -1,12 +0,0 @@
|
||||
<?php namespace FireflyIII\Commands;
|
||||
/**
|
||||
* Class Command
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Commands
|
||||
*/
|
||||
abstract class Command
|
||||
{
|
||||
|
||||
|
||||
}
|
67
app/Console/Commands/UpgradeFireflyInstructions.php
Normal file
67
app/Console/Commands/UpgradeFireflyInstructions.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class UpgradeFireflyInstructions
|
||||
*
|
||||
* @package FireflyIII\Console\Commands
|
||||
*/
|
||||
class UpgradeFireflyInstructions extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly:upgrade-instructions';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
$version = Config::get('firefly.version');
|
||||
$config = Config::get('upgrade.text');
|
||||
$text = isset($config[$version]) ? $config[$version] : null;
|
||||
|
||||
$this->line('+------------------------------------------------------------------------------+');
|
||||
$this->line('');
|
||||
|
||||
if (is_null($text)) {
|
||||
$this->line('Thank you for installing Firefly III, v' . $version);
|
||||
$this->line('If you are upgrading from a previous version,');
|
||||
$this->info('there are no extra upgrade instructions.');
|
||||
$this->line('Firefly III should be ready for use.');
|
||||
} else {
|
||||
$this->line('Thank you for installing Firefly III, v' . $version);
|
||||
$this->line('If you are upgrading from a previous version,');
|
||||
$this->line('please follow these upgrade instructions carefully:');
|
||||
$this->info(wordwrap($text));
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
$this->line('+------------------------------------------------------------------------------+');
|
||||
}
|
||||
}
|
@@ -1,17 +1,25 @@
|
||||
<?php namespace FireflyIII\Console;
|
||||
<?php
|
||||
/**
|
||||
* Kernel.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Console;
|
||||
|
||||
use FireflyIII\Console\Commands\UpgradeFireflyInstructions;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
/**
|
||||
* Class Kernel
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Console
|
||||
*/
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
@@ -19,6 +27,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected $commands
|
||||
= [
|
||||
UpgradeFireflyInstructions::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -26,12 +35,11 @@ class Kernel extends ConsoleKernel
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameters)
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,13 @@
|
||||
<?php namespace FireflyIII\Events;
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
abstract class Event
|
||||
{
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?php namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class JournalDeleted
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalDeleted extends Event
|
||||
{
|
||||
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
@@ -1,15 +1,24 @@
|
||||
<?php namespace FireflyIII\Events;
|
||||
<?php
|
||||
/**
|
||||
* TransactionJournalStored.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class JournalCreated
|
||||
* Class TransactionJournalStored
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalCreated extends Event
|
||||
class TransactionJournalStored extends Event
|
||||
{
|
||||
|
||||
use SerializesModels;
|
@@ -4,12 +4,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class JournalSaved
|
||||
* Class TransactionJournalUpdated
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class JournalSaved extends Event
|
||||
class TransactionJournalUpdated extends Event
|
||||
{
|
||||
|
||||
use SerializesModels;
|
@@ -1,18 +1,20 @@
|
||||
<?php namespace FireflyIII\Exceptions;
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
/**
|
||||
* Class Handler
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Exceptions
|
||||
*/
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
@@ -20,40 +22,35 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
protected $dontReport
|
||||
= [
|
||||
'Symfony\Component\HttpKernel\Exception\HttpException'
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $e
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @param \Exception $exception
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
if ($e instanceof HttpException) {
|
||||
return $this->renderHttpException($e);
|
||||
} else {
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @param Exception $exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $e)
|
||||
public function report(Exception $exception)
|
||||
{
|
||||
parent::report($e);
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Account;
|
||||
|
||||
@@ -7,13 +14,22 @@ use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface AccountChartGenerator
|
||||
* Interface AccountChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Account
|
||||
*/
|
||||
interface AccountChartGenerator
|
||||
interface AccountChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
@@ -31,13 +47,4 @@ interface AccountChartGenerator
|
||||
* @return array
|
||||
*/
|
||||
public function single(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end);
|
||||
}
|
@@ -12,7 +12,7 @@ use Steam;
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Account
|
||||
*/
|
||||
class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
class ChartJsAccountChartGenerator implements AccountChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -62,22 +62,6 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @param $entryId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function isInArray($array, $entryId)
|
||||
{
|
||||
if (isset($array[$entryId])) {
|
||||
return $array[$entryId];
|
||||
}
|
||||
|
||||
return '0';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
@@ -88,19 +72,14 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
public function frontpage(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month_and_day');
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
$format = (string)trans('config.month_and_day');
|
||||
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
|
||||
$current = clone $start;
|
||||
while ($current <= $end) {
|
||||
$data['labels'][] = $current->formatLocalized($format);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$set = [
|
||||
'label' => $account->name,
|
||||
@@ -113,11 +92,11 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
'data' => [],
|
||||
];
|
||||
$current = clone $start;
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$previous = array_values($range)[0];
|
||||
$range = Steam::balanceInRange($account, $start, clone $end);
|
||||
$previous = round(array_values($range)[0], 2);
|
||||
while ($current <= $end) {
|
||||
$format = $current->format('Y-m-d');
|
||||
$balance = isset($range[$format]) ? $range[$format] : $previous;
|
||||
$balance = isset($range[$format]) ? round($range[$format], 2) : $previous;
|
||||
|
||||
$set['data'][] = $balance;
|
||||
$previous = $balance;
|
||||
@@ -140,24 +119,29 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
public function single(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month_and_day');
|
||||
$format = (string)trans('config.month_and_day');
|
||||
|
||||
$data = [
|
||||
$data = [
|
||||
'count' => 1,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $account->name,
|
||||
'data' => []
|
||||
]
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$current = clone $start;
|
||||
$range = Steam::balanceInRange($account, $start, $end);
|
||||
$current = clone $start;
|
||||
$previous = array_values($range)[0];
|
||||
|
||||
while ($end >= $current) {
|
||||
$theDate = $current->format('Y-m-d');
|
||||
$balance = isset($range[$theDate]) ? $range[$theDate] : $previous;
|
||||
|
||||
$data['labels'][] = $current->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = Steam::balance($account, $current);
|
||||
$data['datasets'][0]['data'][] = $balance;
|
||||
$previous = $balance;
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
@@ -179,4 +163,19 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
||||
return array_unique($ids);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @param $entryId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function isInArray($array, $entryId)
|
||||
{
|
||||
if (isset($array[$entryId])) {
|
||||
return $array[$entryId];
|
||||
}
|
||||
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* BillChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Bill;
|
||||
|
||||
|
||||
@@ -6,20 +14,20 @@ use FireflyIII\Models\Bill;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface BillChartGenerator
|
||||
* Interface BillChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Bill
|
||||
*/
|
||||
interface BillChartGenerator
|
||||
interface BillChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $paid
|
||||
* @param Collection $unpaid
|
||||
* @param string $paid
|
||||
* @param string $unpaid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $paid, Collection $unpaid);
|
||||
public function frontpage($paid, $unpaid);
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
@@ -1,62 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* ChartJsBillChartGenerator.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Bill;
|
||||
|
||||
use Config;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class ChartJsBillChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Bill
|
||||
*/
|
||||
class ChartJsBillChartGenerator implements BillChartGenerator
|
||||
class ChartJsBillChartGenerator implements BillChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $paid
|
||||
* @param Collection $unpaid
|
||||
* @param string $paid
|
||||
* @param string $unpaid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function frontpage(Collection $paid, Collection $unpaid)
|
||||
public function frontpage($paid, $unpaid)
|
||||
{
|
||||
$paidDescriptions = [];
|
||||
$paidAmount = 0;
|
||||
$unpaidDescriptions = [];
|
||||
$unpaidAmount = 0;
|
||||
bcscale(2);
|
||||
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($paid as $entry) { // loop paid and create single entry:
|
||||
$paidDescriptions[] = $entry->description;
|
||||
$paidAmount = bcadd($paidAmount, $entry->amount_positive);
|
||||
}
|
||||
/** @var Bill $entry */
|
||||
foreach ($unpaid as $entry) { // loop unpaid:
|
||||
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
||||
$amount = bcdiv(bcadd($entry[0]->amount_max, $entry[0]->amount_min), 2);
|
||||
$unpaidDescriptions[] = $description;
|
||||
$unpaidAmount = bcadd($unpaidAmount, $amount);
|
||||
unset($amount, $description);
|
||||
}
|
||||
|
||||
$data = [
|
||||
[
|
||||
'value' => $unpaidAmount,
|
||||
'value' => round($unpaid, 2),
|
||||
'color' => 'rgba(53, 124, 165,0.7)',
|
||||
'highlight' => 'rgba(53, 124, 165,0.9)',
|
||||
'label' => trans('firefly.unpaid'),
|
||||
],
|
||||
[
|
||||
'value' => $paidAmount,
|
||||
'value' => round($paid * -1, 2), // paid is negative, must be positive.
|
||||
'color' => 'rgba(0, 141, 76, 0.7)',
|
||||
'highlight' => 'rgba(0, 141, 76, 0.9)',
|
||||
'label' => trans('firefly.paid'),
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
@@ -70,27 +56,24 @@ class ChartJsBillChartGenerator implements BillChartGenerator
|
||||
*/
|
||||
public function single(Bill $bill, Collection $entries)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
|
||||
$data = [
|
||||
$format = (string)trans('config.month');
|
||||
$data = [
|
||||
'count' => 3,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
// dataset: max amount
|
||||
// dataset: min amount
|
||||
// dataset: actual amount
|
||||
|
||||
$minAmount = [];
|
||||
$maxAmount = [];
|
||||
$actualAmount = [];
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry->date->formatLocalized($format);
|
||||
$minAmount[] = round($bill->amount_min, 2);
|
||||
$maxAmount[] = round($bill->amount_max, 2);
|
||||
$actualAmount[] = round(($entry->amount * -1), 2);
|
||||
/*
|
||||
* journalAmount has been collected in BillRepository::getJournals
|
||||
*/
|
||||
$actualAmount[] = round(($entry->journalAmount * -1), 2);
|
||||
}
|
||||
|
||||
$data['datasets'][] = [
|
||||
|
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Budget;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface BudgetChartGenerator
|
||||
* Interface BudgetChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Budget
|
||||
*/
|
||||
interface BudgetChartGenerator
|
||||
interface BudgetChartGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $entries
|
@@ -12,7 +12,7 @@ use Preferences;
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Budget
|
||||
*/
|
||||
class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -68,24 +68,24 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
*/
|
||||
public function frontpage(Collection $entries)
|
||||
{
|
||||
$data = [
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// dataset: left
|
||||
// dataset: spent
|
||||
// dataset: overspent
|
||||
$left = [];
|
||||
$spent = [];
|
||||
$overspent = [];
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0) {
|
||||
$data['labels'][] = $entry[0];
|
||||
$left[] = round($entry[1], 2);
|
||||
$spent[] = round($entry[2], 2);
|
||||
$overspent[] = round($entry[3], 2);
|
||||
$filtered = $entries->filter(
|
||||
function ($entry) {
|
||||
return ($entry[1] != 0 || $entry[2] != 0 || $entry[3] != 0);
|
||||
}
|
||||
);
|
||||
foreach ($filtered as $entry) {
|
||||
$data['labels'][] = $entry[0];
|
||||
$left[] = round($entry[1], 2);
|
||||
$spent[] = round($entry[2] * -1, 2); // spent is coming in negative, must be positive
|
||||
$overspent[] = round($entry[3] * -1, 2); // same
|
||||
}
|
||||
|
||||
$data['datasets'][] = [
|
||||
@@ -106,6 +106,40 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYear(Collection $entries)
|
||||
{
|
||||
// dataset:
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// get labels from one of the budgets (assuming there's at least one):
|
||||
$first = $entries->first();
|
||||
$keys = array_keys($first['budgeted']);
|
||||
foreach ($keys as $year) {
|
||||
$data['labels'][] = strval($year);
|
||||
}
|
||||
|
||||
// then, loop all entries and create datasets:
|
||||
foreach ($entries as $entry) {
|
||||
$name = $entry['name'];
|
||||
$spent = $entry['spent'];
|
||||
$budgeted = $entry['budgeted'];
|
||||
$data['datasets'][] = ['label' => 'Spent on ' . $name, 'data' => array_values($spent)];
|
||||
$data['datasets'][] = ['label' => 'Budgeted for ' . $name, 'data' => array_values($budgeted)];
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $entries
|
||||
@@ -115,7 +149,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
public function year(Collection $budgets, Collection $entries)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'labels' => [],
|
||||
@@ -140,37 +174,4 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYear(Collection $entries)
|
||||
{
|
||||
// dataset:
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// get labels from one of the budgets (assuming there's at least one):
|
||||
$first = $entries->first();
|
||||
foreach ($first['budgeted'] as $year => $noInterest) {
|
||||
$data['labels'][] = strval($year);
|
||||
}
|
||||
|
||||
// then, loop all entries and create datasets:
|
||||
foreach ($entries as $entry) {
|
||||
$name = $entry['name'];
|
||||
$spent = $entry['spent'];
|
||||
$budgeted = $entry['budgeted'];
|
||||
$data['datasets'][] = ['label' => 'Spent on ' . $name, 'data' => array_values($spent)];
|
||||
$data['datasets'][] = ['label' => 'Budgeted for ' . $name, 'data' => array_values($budgeted)];
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* CategoryChartGeneratorInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Category;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface CategoryChartGenerator
|
||||
* Interface CategoryChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Category
|
||||
*/
|
||||
interface CategoryChartGenerator
|
||||
interface CategoryChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -54,5 +61,5 @@ interface CategoryChartGenerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInYear(Collection $categories, Collection $entries);
|
||||
public function spentInPeriod(Collection $categories, Collection $entries);
|
||||
}
|
@@ -10,7 +10,7 @@ use Illuminate\Support\Collection;
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Category
|
||||
*/
|
||||
class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -28,12 +28,12 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => []
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.earned'),
|
||||
'data' => []
|
||||
]
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -49,6 +49,39 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriod(Collection $categories, Collection $entries)
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$data['labels'][] = $category->name;
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$date = $entry[0]->formatLocalized($format);
|
||||
array_shift($entry);
|
||||
$data['count']++;
|
||||
$data['datasets'][] = ['label' => $date, 'data' => $entry];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
@@ -62,20 +95,58 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.spent'),
|
||||
'data' => []
|
||||
]
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry['sum'] != 0) {
|
||||
$data['labels'][] = $entry['name'];
|
||||
$data['datasets'][0]['data'][] = round(($entry['sum'] * -1), 2);
|
||||
if ($entry->spent != 0) {
|
||||
$data['labels'][] = $entry->name;
|
||||
$data['datasets'][0]['data'][] = round(($entry->spent * -1), 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYear(Collection $entries)
|
||||
{
|
||||
// dataset:
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// get labels from one of the categories (assuming there's at least one):
|
||||
$first = $entries->first();
|
||||
$keys = array_keys($first['spent']);
|
||||
foreach ($keys as $year) {
|
||||
$data['labels'][] = strval($year);
|
||||
}
|
||||
|
||||
// then, loop all entries and create datasets:
|
||||
foreach ($entries as $entry) {
|
||||
$name = $entry['name'];
|
||||
$spent = $entry['spent'];
|
||||
$earned = $entry['earned'];
|
||||
if (array_sum(array_values($spent)) != 0) {
|
||||
$data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
|
||||
}
|
||||
if (array_sum(array_values($earned)) != 0) {
|
||||
$data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
|
||||
}
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
@@ -89,72 +160,6 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInYear(Collection $categories, Collection $entries)
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$data['labels'][] = $category->name;
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$date = $entry[0]->formatLocalized($format);
|
||||
array_shift($entry);
|
||||
$data['count']++;
|
||||
$data['datasets'][] = ['label' => $date, 'data' => $entry];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriod(Collection $categories, Collection $entries)
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$data['labels'][] = $category->name;
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$date = $entry[0]->formatLocalized($format);
|
||||
array_shift($entry);
|
||||
$data['count']++;
|
||||
$data['datasets'][] = ['label' => $date, 'data' => $entry];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $entries
|
||||
@@ -165,7 +170,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 0,
|
||||
@@ -187,41 +192,4 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYear(Collection $entries)
|
||||
{
|
||||
// dataset:
|
||||
$data = [
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
// get labels from one of the categories (assuming there's at least one):
|
||||
$first = $entries->first();
|
||||
foreach ($first['spent'] as $year => $noInterest) {
|
||||
$data['labels'][] = strval($year);
|
||||
}
|
||||
|
||||
// then, loop all entries and create datasets:
|
||||
foreach ($entries as $entry) {
|
||||
$name = $entry['name'];
|
||||
$spent = $entry['spent'];
|
||||
$earned = $entry['earned'];
|
||||
if (array_sum(array_values($spent)) != 0) {
|
||||
$data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
|
||||
}
|
||||
if (array_sum(array_values($earned)) != 0) {
|
||||
$data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
|
||||
}
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,7 @@
|
||||
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,7 +11,7 @@ use Preferences;
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||
*/
|
||||
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
|
||||
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -25,7 +23,7 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
|
||||
{
|
||||
|
||||
// language:
|
||||
$format = trans('config.month_and_day');
|
||||
$format = (string)trans('config.month_and_day');
|
||||
|
||||
$data = [
|
||||
'count' => 1,
|
||||
@@ -33,8 +31,8 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Diff',
|
||||
'data' => []
|
||||
]
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
$sum = '0';
|
||||
|
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface PiggyBankChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||
*/
|
||||
interface PiggyBankChartGenerator
|
||||
{
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function history(Collection $set);
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* PiggyBankChartGenerator.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface PiggyBankChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\PiggyBank
|
||||
*/
|
||||
interface PiggyBankChartGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $set
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function history(Collection $set);
|
||||
}
|
@@ -2,52 +2,16 @@
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Report;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class ChartJsReportChartGenerator
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Report
|
||||
*/
|
||||
class ChartJsReportChartGenerator implements ReportChartGenerator
|
||||
class ChartJsReportChartGenerator implements ReportChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOut(Collection $entries)
|
||||
{
|
||||
// language:
|
||||
$format = trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => []
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => []
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[0]->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
||||
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above but other translations.
|
||||
*
|
||||
@@ -63,12 +27,12 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => []
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => []
|
||||
]
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -81,6 +45,71 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOutSummarized($income, $expense, $count)
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
$data['datasets'][0]['data'][] = round($income, 2);
|
||||
$data['datasets'][1]['data'][] = round($expense, 2);
|
||||
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
||||
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function yearInOut(Collection $entries)
|
||||
{
|
||||
// language:
|
||||
$format = (string)trans('config.month');
|
||||
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$data['labels'][] = $entry[0]->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
||||
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
@@ -97,43 +126,12 @@ class ChartJsReportChartGenerator implements ReportChartGenerator
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => []
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => []
|
||||
]
|
||||
],
|
||||
];
|
||||
$data['datasets'][0]['data'][] = round($income, 2);
|
||||
$data['datasets'][1]['data'][] = round($expense, 2);
|
||||
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
||||
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $income
|
||||
* @param string $expense
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiYearInOutSummarized($income, $expense, $count)
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => trans('firefly.income'),
|
||||
'data' => []
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'label' => trans('firefly.expenses'),
|
||||
'data' => []
|
||||
]
|
||||
],
|
||||
];
|
||||
$data['datasets'][0]['data'][] = round($income, 2);
|
||||
|
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* ReportChartGenerator.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Generator\Chart\Report;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ReportChartGenerator
|
||||
* Interface ReportChartGeneratorInterface
|
||||
*
|
||||
* @package FireflyIII\Generator\Chart\Report
|
||||
*/
|
||||
interface ReportChartGenerator
|
||||
interface ReportChartGeneratorInterface
|
||||
{
|
||||
|
||||
/**
|
@@ -1,7 +1,7 @@
|
||||
<?php namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\JournalCreated;
|
||||
use FireflyIII\Events\TransactionJournalStored;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -26,15 +26,13 @@ class ConnectJournalToPiggyBank
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event when journal is saved.
|
||||
* Connect a new transaction journal to any related piggy banks.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @param JournalCreated $event
|
||||
* @param TransactionJournalStored $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle(JournalCreated $event)
|
||||
public function handle(TransactionJournalStored $event)
|
||||
{
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $event->journal;
|
||||
@@ -44,12 +42,12 @@ class ConnectJournalToPiggyBank
|
||||
$piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||
|
||||
if (is_null($piggyBank)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// update piggy bank rep for date of transaction journal.
|
||||
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
|
||||
if (is_null($repetition)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bcscale(2);
|
||||
|
||||
|
77
app/Handlers/Events/FireRulesForStore.php
Normal file
77
app/Handlers/Events/FireRulesForStore.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* FireRulesForStore.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
|
||||
use FireflyIII\Events\TransactionJournalStored;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FireRulesForStore
|
||||
*
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class FireRulesForStore
|
||||
{
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect a new transaction journal to any related piggy banks.
|
||||
*
|
||||
* @param TransactionJournalStored $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle(TransactionJournalStored $event)
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
Log::debug('Now processing group "' . $group->title . '".');
|
||||
$rules = $group->rules()
|
||||
->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 */
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = new Processor($rule, $event->journal);
|
||||
|
||||
// get some return out of this?
|
||||
$processor->handle();
|
||||
|
||||
if ($rule->stop_processing) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
app/Handlers/Events/FireRulesForUpdate.php
Normal file
74
app/Handlers/Events/FireRulesForUpdate.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* FireRulesForUpdate.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Events\TransactionJournalUpdated;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FireRulesForUpdate
|
||||
*
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class FireRulesForUpdate
|
||||
{
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param TransactionJournalUpdated $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(TransactionJournalUpdated $event)
|
||||
{
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
Log::debug('Now processing group "' . $group->title . '".');
|
||||
$rules = $group->rules()
|
||||
->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 */
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = new Processor($rule, $event->journal);
|
||||
|
||||
// get some return out of this?
|
||||
$processor->handle();
|
||||
|
||||
if ($rule->stop_processing) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
<?php namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RescanJournal
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class RescanJournal
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param JournalSaved $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(JournalSaved $event)
|
||||
{
|
||||
$journal = $event->journal;
|
||||
|
||||
Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
|
||||
|
||||
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||
$list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
|
||||
|
||||
Log::debug('Found ' . $list->count() . ' bills to check.');
|
||||
|
||||
/** @var \FireflyIII\Models\Bill $bill */
|
||||
foreach ($list as $bill) {
|
||||
Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
|
||||
$repository->scan($bill, $journal);
|
||||
}
|
||||
|
||||
Log::debug('Done!');
|
||||
}
|
||||
|
||||
}
|
47
app/Handlers/Events/ScanForBillsAfterStore.php
Normal file
47
app/Handlers/Events/ScanForBillsAfterStore.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* RescanJournalAfterStore.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\TransactionJournalStored;
|
||||
use FireflyIII\Support\Events\BillScanner;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RescanJournal
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class ScanForBillsAfterStore
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a transaction journal for possible links to bills, right after storing.
|
||||
*
|
||||
* @param TransactionJournalStored $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(TransactionJournalStored $event)
|
||||
{
|
||||
$journal = $event->journal;
|
||||
BillScanner::scan($journal);
|
||||
}
|
||||
|
||||
}
|
47
app/Handlers/Events/ScanForBillsAfterUpdate.php
Normal file
47
app/Handlers/Events/ScanForBillsAfterUpdate.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* ScanForBillsAfterUpdate.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\TransactionJournalUpdated;
|
||||
use FireflyIII\Support\Events\BillScanner;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RescanJournal
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class ScanForBillsAfterUpdate
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a transaction journal for possibly related bills after it has been updated.
|
||||
*
|
||||
* @param TransactionJournalUpdated $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(TransactionJournalUpdated $event)
|
||||
{
|
||||
$journal = $event->journal;
|
||||
BillScanner::scan($journal);
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
<?php namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
use FireflyIII\Events\TransactionJournalUpdated;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
|
||||
@@ -25,11 +25,11 @@ class UpdateJournalConnection
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param JournalSaved $event
|
||||
* @param TransactionJournalUpdated $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(JournalSaved $event)
|
||||
public function handle(TransactionJournalUpdated $event)
|
||||
{
|
||||
$journal = $event->journal;
|
||||
|
||||
|
@@ -19,14 +19,14 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
class AttachmentHelper implements AttachmentHelperInterface
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
protected $maxUploadSize;
|
||||
/** @var array */
|
||||
protected $allowedMimes;
|
||||
/** @var MessageBag */
|
||||
public $errors;
|
||||
/** @var MessageBag */
|
||||
public $messages;
|
||||
/** @var array */
|
||||
protected $allowedMimes;
|
||||
/** @var int */
|
||||
protected $maxUploadSize;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -51,6 +51,22 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
*
|
||||
@@ -67,7 +83,9 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->processFile($files, $model);
|
||||
if (!is_null($files)) {
|
||||
$this->processFile($files, $model);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -87,7 +105,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
|
||||
|
||||
if ($count > 0) {
|
||||
$msg = trans('validation.file_already_attached', ['name' => $name]);
|
||||
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
|
||||
return true;
|
||||
@@ -96,27 +114,6 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UploadedFile $file
|
||||
* @param Model $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateUpload(UploadedFile $file, Model $model)
|
||||
{
|
||||
if (!$this->validMime($file)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->validSize($file)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->hasFile($file, $model)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UploadedFile $file
|
||||
* @param Model $model
|
||||
@@ -154,7 +151,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$attachment->save();
|
||||
|
||||
$name = e($file->getClientOriginalName()); // add message:
|
||||
$msg = trans('validation.file_attached', ['name' => $name]);
|
||||
$msg = (string)trans('validation.file_attached', ['name' => $name]);
|
||||
$this->messages->add('attachments', $msg);
|
||||
|
||||
// return it.
|
||||
@@ -174,7 +171,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$name = e($file->getClientOriginalName());
|
||||
|
||||
if (!in_array($mime, $this->allowedMimes)) {
|
||||
$msg = trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
|
||||
$msg = (string)trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
|
||||
return false;
|
||||
@@ -193,7 +190,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$size = $file->getSize();
|
||||
$name = e($file->getClientOriginalName());
|
||||
if ($size > $this->maxUploadSize) {
|
||||
$msg = trans('validation.file_too_large', ['name' => $name]);
|
||||
$msg = (string)trans('validation.file_too_large', ['name' => $name]);
|
||||
$this->errors->add('attachments', $msg);
|
||||
|
||||
return false;
|
||||
@@ -203,19 +200,24 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MessageBag
|
||||
* @param UploadedFile $file
|
||||
* @param Model $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getErrors()
|
||||
protected function validateUpload(UploadedFile $file, Model $model)
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
if (!$this->validMime($file)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->validSize($file)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->hasFile($file, $model)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MessageBag
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -15,11 +15,11 @@ interface AttachmentHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveAttachmentsForModel(Model $model);
|
||||
public function getAttachmentLocation(Attachment $attachment);
|
||||
|
||||
/**
|
||||
* @return MessageBag
|
||||
@@ -32,10 +32,10 @@ interface AttachmentHelperInterface
|
||||
public function getMessages();
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Model $model
|
||||
*
|
||||
* @return mixed
|
||||
* @return bool
|
||||
*/
|
||||
public function getAttachmentLocation(Attachment $attachment);
|
||||
public function saveAttachmentsForModel(Model $model);
|
||||
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use FireflyIII\Models\Budget as BudgetModel;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -26,9 +25,6 @@ class BalanceLine
|
||||
/** @var BudgetModel */
|
||||
protected $budget;
|
||||
|
||||
/** @var LimitRepetition */
|
||||
protected $repetition;
|
||||
|
||||
protected $role = self::ROLE_DEFAULTROLE;
|
||||
|
||||
/**
|
||||
@@ -48,24 +44,19 @@ class BalanceLine
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTitle()
|
||||
public function getBalanceEntries()
|
||||
{
|
||||
if ($this->getBudget() instanceof BudgetModel) {
|
||||
return $this->getBudget()->name;
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DEFAULTROLE) {
|
||||
return trans('firefly.noBudget');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_TAGROLE) {
|
||||
return trans('firefly.coveredWithTags');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DIFFROLE) {
|
||||
return trans('firefly.leftUnbalanced');
|
||||
}
|
||||
return $this->balanceEntries;
|
||||
}
|
||||
|
||||
return '';
|
||||
/**
|
||||
* @param Collection $balanceEntries
|
||||
*/
|
||||
public function setBalanceEntries($balanceEntries)
|
||||
{
|
||||
$this->balanceEntries = $balanceEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,6 +91,27 @@ class BalanceLine
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if ($this->getBudget() instanceof BudgetModel) {
|
||||
return $this->getBudget()->name;
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DEFAULTROLE) {
|
||||
return trans('firefly.noBudget');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_TAGROLE) {
|
||||
return trans('firefly.coveredWithTags');
|
||||
}
|
||||
if ($this->getRole() == self::ROLE_DIFFROLE) {
|
||||
return trans('firefly.leftUnbalanced');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine
|
||||
* should have a "spent" value, which is the amount of money that has been spent
|
||||
@@ -110,7 +122,7 @@ class BalanceLine
|
||||
*/
|
||||
public function leftOfRepetition()
|
||||
{
|
||||
$start = $this->getRepetition() ? $this->getRepetition()->amount : 0;
|
||||
$start = isset($this->budget->amount) ? $this->budget->amount : 0;
|
||||
/** @var BalanceEntry $balanceEntry */
|
||||
foreach ($this->getBalanceEntries() as $balanceEntry) {
|
||||
$start += $balanceEntry->getSpent();
|
||||
@@ -118,36 +130,4 @@ class BalanceLine
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LimitRepetition
|
||||
*/
|
||||
public function getRepetition()
|
||||
{
|
||||
return $this->repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LimitRepetition $repetition
|
||||
*/
|
||||
public function setRepetition($repetition)
|
||||
{
|
||||
$this->repetition = $repetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBalanceEntries()
|
||||
{
|
||||
return $this->balanceEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $balanceEntries
|
||||
*/
|
||||
public function setBalanceEntries($balanceEntries)
|
||||
{
|
||||
$this->balanceEntries = $balanceEntries;
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use Crypt;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
use stdClass;
|
||||
@@ -36,7 +37,7 @@ class Expense
|
||||
bcscale(2);
|
||||
|
||||
$accountId = $entry->account_id;
|
||||
$amount = strval(round($entry->amount, 2));
|
||||
$amount = strval(round($entry->journalAmount, 2));
|
||||
if (bccomp('0', $amount) === -1) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
@@ -44,7 +45,7 @@ class Expense
|
||||
if (!$this->expenses->has($accountId)) {
|
||||
$newObject = new stdClass;
|
||||
$newObject->amount = $amount;
|
||||
$newObject->name = $entry->name;
|
||||
$newObject->name = Crypt::decrypt($entry->account_name);
|
||||
$newObject->count = 1;
|
||||
$newObject->id = $accountId;
|
||||
$this->expenses->put($accountId, $newObject);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace FireflyIII\Helpers\Collection;
|
||||
|
||||
use Crypt;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
use stdClass;
|
||||
@@ -38,15 +39,15 @@ class Income
|
||||
$accountId = $entry->account_id;
|
||||
if (!$this->incomes->has($accountId)) {
|
||||
$newObject = new stdClass;
|
||||
$newObject->amount = strval(round($entry->amount_positive, 2));
|
||||
$newObject->name = $entry->name;
|
||||
$newObject->amount = strval(round($entry->journalAmount, 2));
|
||||
$newObject->name = Crypt::decrypt($entry->account_name);
|
||||
$newObject->count = 1;
|
||||
$newObject->id = $accountId;
|
||||
$this->incomes->put($accountId, $newObject);
|
||||
} else {
|
||||
bcscale(2);
|
||||
$existing = $this->incomes->get($accountId);
|
||||
$existing->amount = bcadd($existing->amount, $entry->amount_positive);
|
||||
$existing->amount = bcadd($existing->amount, $entry->journalAmount);
|
||||
$existing->count++;
|
||||
$this->incomes->put($accountId, $existing);
|
||||
}
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
@@ -13,7 +11,7 @@ class Amount extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Account|null
|
||||
* @return string|int
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
28
app/Helpers/Csv/Converter/AmountComma.php
Normal file
28
app/Helpers/Csv/Converter/AmountComma.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
/**
|
||||
* Class AmountComma
|
||||
*
|
||||
* Parses the input as the amount with a comma as decimal separator
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Converter
|
||||
*/
|
||||
class AmountComma extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
$value = str_replace(',', '.', $this->value);
|
||||
|
||||
if (is_numeric($value)) {
|
||||
return floatval($value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -18,8 +18,6 @@ class BasicConverter
|
||||
/** @var array */
|
||||
protected $mapped;
|
||||
/** @var string */
|
||||
protected $role;
|
||||
/** @var string */
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
@@ -86,22 +84,6 @@ class BasicConverter
|
||||
$this->mapped = $mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRole()
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*/
|
||||
public function setRole($role)
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -5,7 +5,7 @@ use Auth;
|
||||
use FireflyIII\Models\Budget;
|
||||
|
||||
/**
|
||||
* Class AccountId
|
||||
* Class BudgetId
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Converter
|
||||
*/
|
||||
|
@@ -24,7 +24,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
|
||||
$category = Category::firstOrCreateEncrypted(
|
||||
[
|
||||
'name' => $this->value,
|
||||
'user_id' => Auth::user()->id
|
||||
'user_id' => Auth::user()->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@@ -36,11 +36,6 @@ interface ConverterInterface
|
||||
*/
|
||||
public function setMapped($mapped);
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*/
|
||||
public function setRole($role);
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
|
@@ -13,7 +13,7 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed|static
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ class CurrencyId extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed|static
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ class CurrencyName extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed|static
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed|static
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -18,6 +18,7 @@ class Date extends BasicConverter implements ConverterInterface
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -12,7 +12,7 @@ class Description extends BasicConverter implements ConverterInterface
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
@@ -13,7 +11,7 @@ class Ignore extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Account|null
|
||||
* @return null
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -6,7 +6,7 @@ use Auth;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class OpposingName
|
||||
* Class OpposingAccountId
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Converter
|
||||
*/
|
||||
|
@@ -6,7 +6,7 @@ use Auth;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class OpposingName
|
||||
* Class OpposingAccountName
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Converter
|
||||
*/
|
||||
|
@@ -13,7 +13,7 @@ class RabobankDebetCredit extends BasicConverter implements ConverterInterface
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return int
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -3,7 +3,6 @@
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Tag;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -16,7 +15,7 @@ class TagsComma extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Bill
|
||||
* @return Collection
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -3,7 +3,6 @@
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Tag;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -16,7 +15,7 @@ class TagsSpace extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Bill
|
||||
* @return Collection
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers\Csv;
|
||||
|
||||
use Crypt;
|
||||
@@ -16,14 +15,16 @@ class Data
|
||||
|
||||
/** @var string */
|
||||
protected $csvFileContent;
|
||||
|
||||
/** @var string */
|
||||
protected $csvFileLocation;
|
||||
/** @var string */
|
||||
protected $dateFormat;
|
||||
/** @var string */
|
||||
protected $delimiter;
|
||||
/** @var bool */
|
||||
protected $hasHeaders;
|
||||
|
||||
/** @var int */
|
||||
protected $importAccount = 0;
|
||||
/** @var array */
|
||||
protected $map = [];
|
||||
/** @var array */
|
||||
@@ -32,15 +33,10 @@ class Data
|
||||
protected $reader;
|
||||
/** @var array */
|
||||
protected $roles = [];
|
||||
|
||||
/** @var array */
|
||||
protected $specifix = [];
|
||||
|
||||
/** @var int */
|
||||
protected $importAccount = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -52,6 +48,234 @@ class Data
|
||||
$this->sessionMapped();
|
||||
$this->sessionSpecifix();
|
||||
$this->sessionImportAccount();
|
||||
$this->sessionDelimiter();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCsvFileContent()
|
||||
{
|
||||
return $this->csvFileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $csvFileContent
|
||||
*/
|
||||
public function setCsvFileContent($csvFileContent)
|
||||
{
|
||||
$this->csvFileContent = $csvFileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCsvFileLocation()
|
||||
{
|
||||
return $this->csvFileLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $csvFileLocation
|
||||
*/
|
||||
public function setCsvFileLocation($csvFileLocation)
|
||||
{
|
||||
Session::put('csv-file', $csvFileLocation);
|
||||
$this->csvFileLocation = $csvFileLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFormat()
|
||||
{
|
||||
return $this->dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed $dateFormat
|
||||
*/
|
||||
public function setDateFormat($dateFormat)
|
||||
{
|
||||
Session::put('csv-date-format', $dateFormat);
|
||||
$this->dateFormat = $dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDelimiter()
|
||||
{
|
||||
return $this->delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $delimiter
|
||||
*/
|
||||
public function setDelimiter($delimiter)
|
||||
{
|
||||
Session::put('csv-delimiter', $delimiter);
|
||||
$this->delimiter = $delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMap()
|
||||
{
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $map
|
||||
*/
|
||||
public function setMap(array $map)
|
||||
{
|
||||
Session::put('csv-map', $map);
|
||||
$this->map = $map;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMapped()
|
||||
{
|
||||
return $this->mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $mapped
|
||||
*/
|
||||
public function setMapped(array $mapped)
|
||||
{
|
||||
Session::put('csv-mapped', $mapped);
|
||||
$this->mapped = $mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Reader
|
||||
*/
|
||||
public function getReader()
|
||||
{
|
||||
if (strlen($this->csvFileContent) === 0) {
|
||||
$this->loadCsvFile();
|
||||
}
|
||||
|
||||
if (is_null($this->reader)) {
|
||||
$this->reader = Reader::createFromString($this->getCsvFileContent());
|
||||
$this->reader->setDelimiter($this->delimiter);
|
||||
}
|
||||
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->roles;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $roles
|
||||
*/
|
||||
public function setRoles(array $roles)
|
||||
{
|
||||
Session::put('csv-roles', $roles);
|
||||
$this->roles = $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifix()
|
||||
{
|
||||
return is_array($this->specifix) ? $this->specifix : [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $specifix
|
||||
*/
|
||||
public function setSpecifix(array $specifix)
|
||||
{
|
||||
Session::put('csv-specifix', $specifix);
|
||||
$this->specifix = $specifix;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasHeaders()
|
||||
{
|
||||
return $this->hasHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bool $hasHeaders
|
||||
*/
|
||||
public function setHasHeaders($hasHeaders)
|
||||
{
|
||||
Session::put('csv-has-headers', $hasHeaders);
|
||||
$this->hasHeaders = $hasHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $importAccount
|
||||
*/
|
||||
public function setImportAccount($importAccount)
|
||||
{
|
||||
Session::put('csv-import-account', $importAccount);
|
||||
$this->importAccount = $importAccount;
|
||||
}
|
||||
|
||||
protected function loadCsvFile()
|
||||
{
|
||||
$file = $this->getCsvFileLocation();
|
||||
$content = file_get_contents($file);
|
||||
$contentDecrypted = Crypt::decrypt($content);
|
||||
$this->setCsvFileContent($contentDecrypted);
|
||||
}
|
||||
|
||||
protected function sessionCsvFileLocation()
|
||||
{
|
||||
if (Session::has('csv-file')) {
|
||||
$this->csvFileLocation = (string)Session::get('csv-file');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionDateFormat()
|
||||
{
|
||||
if (Session::has('csv-date-format')) {
|
||||
$this->dateFormat = (string)Session::get('csv-date-format');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionDelimiter()
|
||||
{
|
||||
if (Session::has('csv-delimiter')) {
|
||||
$this->delimiter = Session::get('csv-delimiter');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionHasHeaders()
|
||||
@@ -68,20 +292,6 @@ class Data
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionDateFormat()
|
||||
{
|
||||
if (Session::has('csv-date-format')) {
|
||||
$this->dateFormat = (string)Session::get('csv-date-format');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionCsvFileLocation()
|
||||
{
|
||||
if (Session::has('csv-file')) {
|
||||
$this->csvFileLocation = (string)Session::get('csv-file');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionMap()
|
||||
{
|
||||
if (Session::has('csv-map')) {
|
||||
@@ -89,13 +299,6 @@ class Data
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionRoles()
|
||||
{
|
||||
if (Session::has('csv-roles')) {
|
||||
$this->roles = (array)Session::get('csv-roles');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionMapped()
|
||||
{
|
||||
if (Session::has('csv-mapped')) {
|
||||
@@ -103,181 +306,17 @@ class Data
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionRoles()
|
||||
{
|
||||
if (Session::has('csv-roles')) {
|
||||
$this->roles = (array)Session::get('csv-roles');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sessionSpecifix()
|
||||
{
|
||||
if (Session::has('csv-specifix')) {
|
||||
$this->specifix = (array)Session::get('csv-specifix');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFormat()
|
||||
{
|
||||
return $this->dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $dateFormat
|
||||
*/
|
||||
public function setDateFormat($dateFormat)
|
||||
{
|
||||
Session::put('csv-date-format', $dateFormat);
|
||||
$this->dateFormat = $dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $importAccount
|
||||
*/
|
||||
public function setImportAccount($importAccount)
|
||||
{
|
||||
Session::put('csv-import-account', $importAccount);
|
||||
$this->importAccount = $importAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasHeaders()
|
||||
{
|
||||
return $this->hasHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $hasHeaders
|
||||
*/
|
||||
public function setHasHeaders($hasHeaders)
|
||||
{
|
||||
Session::put('csv-has-headers', $hasHeaders);
|
||||
$this->hasHeaders = $hasHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMap()
|
||||
{
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $map
|
||||
*/
|
||||
public function setMap(array $map)
|
||||
{
|
||||
Session::put('csv-map', $map);
|
||||
$this->map = $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMapped()
|
||||
{
|
||||
return $this->mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $mapped
|
||||
*/
|
||||
public function setMapped(array $mapped)
|
||||
{
|
||||
Session::put('csv-mapped', $mapped);
|
||||
$this->mapped = $mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Reader
|
||||
*/
|
||||
public function getReader()
|
||||
{
|
||||
|
||||
if (strlen($this->csvFileContent) === 0) {
|
||||
$this->loadCsvFile();
|
||||
}
|
||||
|
||||
if (is_null($this->reader)) {
|
||||
$this->reader = Reader::createFromString($this->getCsvFileContent());
|
||||
}
|
||||
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
protected function loadCsvFile()
|
||||
{
|
||||
$file = $this->getCsvFileLocation();
|
||||
$content = file_get_contents($file);
|
||||
$contentDecrypted = Crypt::decrypt($content);
|
||||
$this->setCsvFileContent($contentDecrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCsvFileLocation()
|
||||
{
|
||||
return $this->csvFileLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $csvFileLocation
|
||||
*/
|
||||
public function setCsvFileLocation($csvFileLocation)
|
||||
{
|
||||
Session::put('csv-file', $csvFileLocation);
|
||||
$this->csvFileLocation = $csvFileLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCsvFileContent()
|
||||
{
|
||||
return $this->csvFileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $csvFileContent
|
||||
*/
|
||||
public function setCsvFileContent($csvFileContent)
|
||||
{
|
||||
$this->csvFileContent = $csvFileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $roles
|
||||
*/
|
||||
public function setRoles(array $roles)
|
||||
{
|
||||
Session::put('csv-roles', $roles);
|
||||
$this->roles = $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifix()
|
||||
{
|
||||
return is_array($this->specifix) ? $this->specifix : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $specifix
|
||||
*/
|
||||
public function setSpecifix($specifix)
|
||||
{
|
||||
Session::put('csv-specifix', $specifix);
|
||||
$this->specifix = $specifix;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -9,9 +9,14 @@ use FireflyIII\Helpers\Csv\Converter\ConverterInterface;
|
||||
use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface;
|
||||
use FireflyIII\Helpers\Csv\Specifix\SpecifixInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Rules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
@@ -34,6 +39,8 @@ class Importer
|
||||
protected $importRow;
|
||||
/** @var int */
|
||||
protected $imported = 0;
|
||||
/** @var Collection */
|
||||
protected $journals;
|
||||
/** @var array */
|
||||
protected $map;
|
||||
/** @var array */
|
||||
@@ -45,9 +52,6 @@ class Importer
|
||||
/** @var array */
|
||||
protected $specifix = [];
|
||||
|
||||
/** @var Collection */
|
||||
protected $journals;
|
||||
|
||||
/**
|
||||
* Used by CsvController.
|
||||
*
|
||||
@@ -68,6 +72,14 @@ class Importer
|
||||
return $this->imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournals()
|
||||
{
|
||||
return $this->journals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by CsvController
|
||||
*
|
||||
@@ -79,14 +91,13 @@ class Importer
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function getJournals()
|
||||
public function getSpecifix()
|
||||
{
|
||||
return $this->journals;
|
||||
return is_array($this->specifix) ? $this->specifix : [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -115,139 +126,19 @@ class Importer
|
||||
Log::debug('---');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseRow($index)
|
||||
{
|
||||
return (($this->data->hasHeaders() && $index >= 1) || !$this->data->hasHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function importRow($row)
|
||||
{
|
||||
|
||||
$data = $this->getFiller(); // These fields are necessary to create a new transaction journal. Some are optional
|
||||
foreach ($row as $index => $value) {
|
||||
$role = isset($this->roles[$index]) ? $this->roles[$index] : '_ignore';
|
||||
$class = Config::get('csv.roles.' . $role . '.converter');
|
||||
$field = Config::get('csv.roles.' . $role . '.field');
|
||||
|
||||
Log::debug('Column #' . $index . ' (role: ' . $role . ') : converter ' . $class . ' stores its data into field ' . $field . ':');
|
||||
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app('FireflyIII\Helpers\Csv\Converter\\' . $class);
|
||||
$converter->setData($data); // the complete array so far.
|
||||
$converter->setField($field);
|
||||
$converter->setIndex($index);
|
||||
$converter->setMapped($this->mapped);
|
||||
$converter->setValue($value);
|
||||
$converter->setRole($role);
|
||||
$data[$field] = $converter->convert();
|
||||
}
|
||||
// move to class vars.
|
||||
$this->importData = $data;
|
||||
$this->importRow = $row;
|
||||
unset($data, $row);
|
||||
// post processing and validating.
|
||||
$this->postProcess();
|
||||
$result = $this->validateData();
|
||||
|
||||
if (!($result === true)) {
|
||||
return $result; // return error.
|
||||
}
|
||||
$journal = $this->createTransactionJournal();
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getFiller()
|
||||
{
|
||||
$filler = [];
|
||||
foreach (Config::get('csv.roles') as $role) {
|
||||
if (isset($role['field'])) {
|
||||
$fieldName = $role['field'];
|
||||
$filler[$fieldName] = null;
|
||||
}
|
||||
}
|
||||
// some extra's:
|
||||
$filler['bill-id'] = null;
|
||||
$filler['opposing-account-object'] = null;
|
||||
$filler['asset-account-object'] = null;
|
||||
$filler['amount-modifier'] = '1';
|
||||
|
||||
return $filler;
|
||||
// once all journals have been imported (or not)
|
||||
// fire the rules.
|
||||
$this->fireRules();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Row denotes the original data.
|
||||
*
|
||||
* @return void
|
||||
* @param Data $data
|
||||
*/
|
||||
protected function postProcess()
|
||||
public function setData($data)
|
||||
{
|
||||
// do bank specific fixes (must be enabled but now all of them.
|
||||
|
||||
foreach ($this->getSpecifix() as $className) {
|
||||
/** @var SpecifixInterface $specifix */
|
||||
$specifix = app('FireflyIII\Helpers\Csv\Specifix\\' . $className);
|
||||
$specifix->setData($this->importData);
|
||||
$specifix->setRow($this->importRow);
|
||||
Log::debug('Now post-process specifix named ' . $className . ':');
|
||||
$this->importData = $specifix->fix();
|
||||
}
|
||||
|
||||
|
||||
$set = Config::get('csv.post_processors');
|
||||
foreach ($set as $className) {
|
||||
/** @var PostProcessorInterface $postProcessor */
|
||||
$postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className);
|
||||
$postProcessor->setData($this->importData);
|
||||
Log::debug('Now post-process processor named ' . $className . ':');
|
||||
$this->importData = $postProcessor->process();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifix()
|
||||
{
|
||||
return is_array($this->specifix) ? $this->specifix : [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function validateData()
|
||||
{
|
||||
if (is_null($this->importData['date']) && is_null($this->importData['date-rent'])) {
|
||||
return 'No date value for this row.';
|
||||
}
|
||||
if (is_null($this->importData['opposing-account-object'])) {
|
||||
return 'Opposing account is null';
|
||||
}
|
||||
|
||||
if (!($this->importData['asset-account-object'] instanceof Account)) {
|
||||
return 'No asset account to import into.';
|
||||
}
|
||||
|
||||
return true;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,8 +194,8 @@ class Importer
|
||||
$opposing = $this->importData['opposing-account-object'];
|
||||
|
||||
Log::info('Created journal #' . $journalId . ' of type ' . $type . '!');
|
||||
Log::info('Asset account ****** (#' . $asset->id . ') lost/gained: ' . $this->importData['amount']);
|
||||
Log::info($opposing->accountType->type . ' ****** (#' . $opposing->id . ') lost/gained: ' . bcmul($this->importData['amount'], -1));
|
||||
Log::info('Asset account #' . $asset->id . ' lost/gained: ' . $this->importData['amount']);
|
||||
Log::info($opposing->accountType->type . ' #' . $opposing->id . ' lost/gained: ' . bcmul($this->importData['amount'], -1));
|
||||
|
||||
return $journal;
|
||||
}
|
||||
@@ -326,6 +217,92 @@ class Importer
|
||||
return $transactionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function importRow($row)
|
||||
{
|
||||
|
||||
$data = $this->getFiller(); // These fields are necessary to create a new transaction journal. Some are optional
|
||||
foreach ($row as $index => $value) {
|
||||
$role = isset($this->roles[$index]) ? $this->roles[$index] : '_ignore';
|
||||
$class = Config::get('csv.roles.' . $role . '.converter');
|
||||
$field = Config::get('csv.roles.' . $role . '.field');
|
||||
|
||||
Log::debug('Column #' . $index . ' (role: ' . $role . ') : converter ' . $class . ' stores its data into field ' . $field . ':');
|
||||
|
||||
// here would be the place where preprocessors would fire.
|
||||
|
||||
/** @var ConverterInterface $converter */
|
||||
$converter = app('FireflyIII\Helpers\Csv\Converter\\' . $class);
|
||||
$converter->setData($data); // the complete array so far.
|
||||
$converter->setField($field);
|
||||
$converter->setIndex($index);
|
||||
$converter->setMapped($this->mapped);
|
||||
$converter->setValue($value);
|
||||
$data[$field] = $converter->convert();
|
||||
}
|
||||
// move to class vars.
|
||||
$this->importData = $data;
|
||||
$this->importRow = $row;
|
||||
unset($data, $row);
|
||||
// post processing and validating.
|
||||
$this->postProcess();
|
||||
$result = $this->validateData();
|
||||
|
||||
if (!($result === true)) {
|
||||
return $result; // return error.
|
||||
}
|
||||
$journal = $this->createTransactionJournal();
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseRow($index)
|
||||
{
|
||||
return (($this->data->hasHeaders() && $index >= 1) || !$this->data->hasHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* Row denotes the original data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function postProcess()
|
||||
{
|
||||
// do bank specific fixes (must be enabled but now all of them.
|
||||
|
||||
foreach ($this->getSpecifix() as $className) {
|
||||
/** @var SpecifixInterface $specifix */
|
||||
$specifix = app('FireflyIII\Helpers\Csv\Specifix\\' . $className);
|
||||
if ($specifix->getProcessorType() == SpecifixInterface::POST_PROCESSOR) {
|
||||
$specifix->setData($this->importData);
|
||||
$specifix->setRow($this->importRow);
|
||||
Log::debug('Now post-process specifix named ' . $className . ':');
|
||||
$this->importData = $specifix->fix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$set = Config::get('csv.post_processors');
|
||||
foreach ($set as $className) {
|
||||
/** @var PostProcessorInterface $postProcessor */
|
||||
$postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className);
|
||||
$postProcessor->setData($this->importData);
|
||||
Log::debug('Now post-process processor named ' . $className . ':');
|
||||
$this->importData = $postProcessor->process();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
@@ -361,11 +338,94 @@ class Importer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Data $data
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function setData($data)
|
||||
protected function validateData()
|
||||
{
|
||||
$this->data = $data;
|
||||
if (is_null($this->importData['date']) && is_null($this->importData['date-rent'])) {
|
||||
return 'No date value for this row.';
|
||||
}
|
||||
if (is_null($this->importData['opposing-account-object'])) {
|
||||
return 'Opposing account is null';
|
||||
}
|
||||
|
||||
if (!($this->importData['asset-account-object'] instanceof Account)) {
|
||||
return 'No asset account to import into.';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $groups
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
private function fireRule(Collection $groups, TransactionJournal $journal)
|
||||
{
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($group->rules as $rule) {
|
||||
$processor = new Processor($rule, $journal);
|
||||
$processor->handle();
|
||||
if ($rule->stop_processing) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function fireRules()
|
||||
{
|
||||
// get all users rules.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$groups = $user
|
||||
->ruleGroups()
|
||||
->where('rule_groups.active', 1)
|
||||
->orderBy('order', 'ASC')
|
||||
->with(
|
||||
[
|
||||
'rules' => function (HasMany $q) {
|
||||
$q->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)
|
||||
->orderBy('rules.order', 'ASC');
|
||||
},
|
||||
]
|
||||
)
|
||||
->get();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($this->journals as $journal) {
|
||||
$this->fireRule($groups, $journal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getFiller()
|
||||
{
|
||||
$filler = [];
|
||||
foreach (Config::get('csv.roles') as $role) {
|
||||
if (isset($role['field'])) {
|
||||
$fieldName = $role['field'];
|
||||
$filler[$fieldName] = null;
|
||||
}
|
||||
}
|
||||
// some extra's:
|
||||
$filler['bill-id'] = null;
|
||||
$filler['opposing-account-object'] = null;
|
||||
$filler['asset-account-object'] = null;
|
||||
$filler['amount-modifier'] = '1';
|
||||
|
||||
return $filler;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 05/07/15
|
||||
* Time: 19:20
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\PostProcessing;
|
||||
|
||||
|
185
app/Helpers/Csv/Specifix/AbnAmroDescription.php
Normal file
185
app/Helpers/Csv/Specifix/AbnAmroDescription.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\Specifix;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Parses the description from txt files for ABN AMRO bank accounts.
|
||||
*
|
||||
* Based on the logic as described in the following Gist:
|
||||
* https://gist.github.com/vDorst/68d555a6a90f62fec004
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Specifix
|
||||
*/
|
||||
class AbnAmroDescription extends Specifix implements SpecifixInterface
|
||||
{
|
||||
/** @var array */
|
||||
protected $data;
|
||||
|
||||
/** @var array */
|
||||
protected $row;
|
||||
|
||||
/**
|
||||
* AbnAmroDescription constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProcessorType(self::POST_PROCESSOR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fix()
|
||||
{
|
||||
// Try to parse the description in known formats.
|
||||
$parsed = $this->parseSepaDescription() || $this->parseTRTPDescription() || $this->parseGEABEADescription() || $this->parseABNAMRODescription();
|
||||
|
||||
// If the description could not be parsed, specify an unknown opposing
|
||||
// account, as an opposing account is required
|
||||
if (!$parsed) {
|
||||
$this->data['opposing-account-name'] = trans('firefly.unknown');
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row
|
||||
*/
|
||||
public function setRow($row)
|
||||
{
|
||||
$this->row = $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description with costs from ABN AMRO itself
|
||||
*
|
||||
* @return boolean true if the description is GEA/BEA-format, false otherwise
|
||||
*/
|
||||
protected function parseABNAMRODescription()
|
||||
{
|
||||
// See if the current description is formatted in ABN AMRO format
|
||||
if (preg_match('/ABN AMRO.{24} (.*)/', $this->data['description'], $matches)) {
|
||||
Log::debug('AbnAmroSpecifix: Description is structured as costs from ABN AMRO itself.');
|
||||
|
||||
$this->data['opposing-account-name'] = 'ABN AMRO';
|
||||
$this->data['description'] = $matches[1];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in GEA/BEA format
|
||||
*
|
||||
* @return boolean true if the description is GEA/BEAformat, false otherwise
|
||||
*/
|
||||
protected function parseGEABEADescription()
|
||||
{
|
||||
// See if the current description is formatted in GEA/BEA format
|
||||
if (preg_match('/([BG]EA) +(NR:[a-zA-Z:0-9]+) +([0-9.\/]+) +([^,]*)/', $this->data['description'], $matches)) {
|
||||
Log::debug('AbnAmroSpecifix: Description is structured as GEA or BEA format.');
|
||||
|
||||
// description and opposing account will be the same.
|
||||
$this->data['opposing-account-name'] = $matches[4];
|
||||
$this->data['description'] = $matches[4];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in SEPA format
|
||||
*
|
||||
* @return boolean true if the description is SEPA format, false otherwise
|
||||
*/
|
||||
protected function parseSepaDescription()
|
||||
{
|
||||
// See if the current description is formatted as a SEPA plain description
|
||||
if (preg_match('/^SEPA(.{28})/', $this->data['description'], $matches)) {
|
||||
Log::debug('AbnAmroSpecifix: Description is structured as SEPA plain description.');
|
||||
|
||||
// SEPA plain descriptions contain several key-value pairs, split by a colon
|
||||
preg_match_all('/([A-Za-z]+(?=:\s)):\s([A-Za-z 0-9._#-]+(?=\s))/', $this->data['description'], $matches, PREG_SET_ORDER);
|
||||
|
||||
if (is_array($matches)) {
|
||||
foreach ($matches as $match) {
|
||||
$key = $match[1];
|
||||
$value = trim($match[2]);
|
||||
|
||||
switch (strtoupper($key)) {
|
||||
case 'OMSCHRIJVING':
|
||||
$this->data['description'] = $value;
|
||||
break;
|
||||
case 'NAAM':
|
||||
$this->data['opposing-account-name'] = $value;
|
||||
break;
|
||||
case 'IBAN':
|
||||
$this->data['opposing-account-iban'] = $value;
|
||||
break;
|
||||
default:
|
||||
// Ignore the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in TRTP format
|
||||
*
|
||||
* @return boolean true if the description is TRTP format, false otherwise
|
||||
*/
|
||||
protected function parseTRTPDescription()
|
||||
{
|
||||
// See if the current description is formatted in TRTP format
|
||||
if (preg_match_all('!\/([A-Z]{3,4})\/([^/]*)!', $this->data['description'], $matches, PREG_SET_ORDER)) {
|
||||
Log::debug('AbnAmroSpecifix: Description is structured as TRTP format.');
|
||||
|
||||
if (is_array($matches)) {
|
||||
foreach ($matches as $match) {
|
||||
$key = $match[1];
|
||||
$value = trim($match[2]);
|
||||
|
||||
switch (strtoupper($key)) {
|
||||
case 'NAME':
|
||||
$this->data['opposing-account-name'] = $value;
|
||||
break;
|
||||
case 'REMI':
|
||||
$this->data['description'] = $value;
|
||||
break;
|
||||
case 'IBAN':
|
||||
$this->data['opposing-account-iban'] = $value;
|
||||
break;
|
||||
default:
|
||||
// Ignore the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -7,7 +7,7 @@ namespace FireflyIII\Helpers\Csv\Specifix;
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Specifix
|
||||
*/
|
||||
class Dummy
|
||||
class Dummy extends Specifix implements SpecifixInterface
|
||||
{
|
||||
/** @var array */
|
||||
protected $data;
|
||||
@@ -15,6 +15,13 @@ class Dummy
|
||||
/** @var array */
|
||||
protected $row;
|
||||
|
||||
/**
|
||||
* Dummy constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProcessorType(self::POST_PROCESSOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@@ -9,7 +9,7 @@ use Log;
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Specifix
|
||||
*/
|
||||
class RabobankDescription
|
||||
class RabobankDescription extends Specifix implements SpecifixInterface
|
||||
{
|
||||
/** @var array */
|
||||
protected $data;
|
||||
@@ -17,6 +17,14 @@ class RabobankDescription
|
||||
/** @var array */
|
||||
protected $row;
|
||||
|
||||
/**
|
||||
* RabobankDescription constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProcessorType(self::POST_PROCESSOR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -29,23 +37,6 @@ class RabobankDescription
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes Rabobank specific thing.
|
||||
*/
|
||||
protected function rabobankFixEmptyOpposing()
|
||||
{
|
||||
Log::debug('RaboSpecifix: Opposing account name is "******".');
|
||||
if (is_string($this->data['opposing-account-name']) && strlen($this->data['opposing-account-name']) == 0) {
|
||||
Log::debug('RaboSpecifix: opp-name is zero length, changed to: "******"');
|
||||
$this->data['opposing-account-name'] = $this->row[10];
|
||||
|
||||
Log::debug('Description was: "******".');
|
||||
$this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description']));
|
||||
Log::debug('Description is now: "******".');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
@@ -62,5 +53,22 @@ class RabobankDescription
|
||||
$this->row = $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes Rabobank specific thing.
|
||||
*/
|
||||
protected function rabobankFixEmptyOpposing()
|
||||
{
|
||||
Log::debug('RaboSpecifix: Opposing account name is "******".');
|
||||
if (is_string($this->data['opposing-account-name']) && strlen($this->data['opposing-account-name']) == 0) {
|
||||
Log::debug('RaboSpecifix: opp-name is zero length, changed to: "******"');
|
||||
$this->data['opposing-account-name'] = $this->row[10];
|
||||
|
||||
Log::debug('Description was: "******".');
|
||||
$this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description']));
|
||||
Log::debug('Description is now: "******".');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
44
app/Helpers/Csv/Specifix/Specifix.php
Normal file
44
app/Helpers/Csv/Specifix/Specifix.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Specifix.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Csv\Specifix;
|
||||
|
||||
/**
|
||||
* Class Specifix
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv\Specifix
|
||||
*/
|
||||
class Specifix
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
protected $processorType;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getProcessorType()
|
||||
{
|
||||
return $this->processorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $processorType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProcessorType($processorType)
|
||||
{
|
||||
$this->processorType = $processorType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -8,16 +8,30 @@ namespace FireflyIII\Helpers\Csv\Specifix;
|
||||
*/
|
||||
interface SpecifixInterface
|
||||
{
|
||||
const PRE_PROCESSOR = 1;
|
||||
const POST_PROCESSOR = 2;
|
||||
/**
|
||||
* Implement bank and locale related fixes.
|
||||
*/
|
||||
public function fix();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getProcessorType();
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function setData($data);
|
||||
|
||||
/**
|
||||
* @param int $processorType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProcessorType($processorType);
|
||||
|
||||
/**
|
||||
* @param array $row
|
||||
*/
|
||||
|
@@ -63,7 +63,8 @@ class Wizard implements WizardInterface
|
||||
|
||||
|
||||
if (is_array($map)) {
|
||||
foreach ($map as $index => $field) {
|
||||
$keys = array_keys($map);
|
||||
foreach ($keys as $index) {
|
||||
if (isset($roles[$index])) {
|
||||
$name = $roles[$index];
|
||||
if ($configRoles[$name]['mappable']) {
|
||||
@@ -167,17 +168,6 @@ class Wizard implements WizardInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $hasHeaders
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function useRow($hasHeaders, $index)
|
||||
{
|
||||
return ($hasHeaders && $index > 1) || !$hasHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
@@ -191,4 +181,15 @@ class Wizard implements WizardInterface
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $hasHeaders
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function useRow($hasHeaders, $index)
|
||||
{
|
||||
return ($hasHeaders && $index > 1) || !$hasHeaders;
|
||||
}
|
||||
}
|
||||
|
78
app/Helpers/FiscalHelper.php
Normal file
78
app/Helpers/FiscalHelper.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class FiscalHelper
|
||||
*
|
||||
* @package FireflyIII\Helpers
|
||||
*/
|
||||
class FiscalHelper implements FiscalHelperInterface
|
||||
{
|
||||
|
||||
/** @var bool */
|
||||
protected $useCustomFiscalYear;
|
||||
|
||||
/**
|
||||
* FiscalHelper constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (Preferences::get('customFiscalYear', 0)->data) {
|
||||
$this->useCustomFiscalYear = true;
|
||||
} else {
|
||||
$this->useCustomFiscalYear = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon date object
|
||||
*/
|
||||
public function startOfFiscalYear(Carbon $date)
|
||||
{
|
||||
// get start mm-dd. Then create a start date in the year passed.
|
||||
$startDate = clone $date;
|
||||
if ($this->useCustomFiscalYear === true) {
|
||||
$prefStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
||||
list($mth, $day) = explode('-', $prefStartStr);
|
||||
$startDate->month(intval($mth))->day(intval($day));
|
||||
|
||||
// if start date is after passed date, sub 1 year.
|
||||
if ($startDate > $date) {
|
||||
$startDate->subYear();
|
||||
}
|
||||
} else {
|
||||
$startDate->startOfYear();
|
||||
}
|
||||
return $startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon date object
|
||||
*/
|
||||
public function endOfFiscalYear(Carbon $date)
|
||||
{
|
||||
// get start of fiscal year for passed date
|
||||
$endDate = $this->startOfFiscalYear($date);
|
||||
if ($this->useCustomFiscalYear === true) {
|
||||
// add 1 year and sub 1 day
|
||||
$endDate->addYear();
|
||||
$endDate->subDay();
|
||||
} else {
|
||||
$endDate->endOfYear();
|
||||
}
|
||||
|
||||
|
||||
return $endDate;
|
||||
}
|
||||
}
|
35
app/Helpers/FiscalHelperInterface.php
Normal file
35
app/Helpers/FiscalHelperInterface.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Interface FiscalHelperInterface
|
||||
*
|
||||
* @package FireflyIII\Helpers
|
||||
*/
|
||||
interface FiscalHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* This method produces a clone of the Carbon date object passed, checks preferences
|
||||
* and calculates the first day of the fiscal year.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon date object
|
||||
*/
|
||||
public function startOfFiscalYear(Carbon $date);
|
||||
|
||||
/**
|
||||
* This method produces a clone of the Carbon date object passed, checks preferences
|
||||
* and calculates the last day of the fiscal year.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon date object
|
||||
*/
|
||||
public function endOfFiscalYear(Carbon $date);
|
||||
|
||||
}
|
113
app/Helpers/Report/AccountReportHelper.php
Normal file
113
app/Helpers/Report/AccountReportHelper.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountReportHelper.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Helpers\Collection\Account as AccountCollection;
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Class AccountReportHelper
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
class AccountReportHelper implements AccountReportHelperInterface
|
||||
{
|
||||
/**
|
||||
* This method generates a full report for the given period on all
|
||||
* given accounts
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return AccountCollection
|
||||
*/
|
||||
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$startAmount = '0';
|
||||
$endAmount = '0';
|
||||
$diff = '0';
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
|
||||
$yesterday = clone $start;
|
||||
$yesterday->subDay();
|
||||
|
||||
bcscale(2);
|
||||
|
||||
// get balances for start.
|
||||
$startSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->whereIn('accounts.id', $ids)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->where('transaction_journals.date', '<=', $yesterday->format('Y-m-d'))
|
||||
->groupBy('accounts.id')
|
||||
->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
|
||||
|
||||
// and end:
|
||||
$endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->whereIn('accounts.id', $ids)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->groupBy('accounts.id')
|
||||
->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
|
||||
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($startSet, $endSet) {
|
||||
/**
|
||||
* The balance for today always incorporates transactions
|
||||
* made on today. So to get todays "start" balance, we sub one
|
||||
* day.
|
||||
*/
|
||||
//
|
||||
$currentStart = $startSet->filter(
|
||||
function (Account $entry) use ($account) {
|
||||
return $account->id == $entry->id;
|
||||
}
|
||||
);
|
||||
if ($currentStart->first()) {
|
||||
$account->startBalance = $currentStart->first()->balance;
|
||||
}
|
||||
|
||||
$currentEnd = $endSet->filter(
|
||||
function (Account $entry) use ($account) {
|
||||
return $account->id == $entry->id;
|
||||
}
|
||||
);
|
||||
if ($currentEnd->first()) {
|
||||
$account->endBalance = $currentEnd->first()->balance;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// summarize:
|
||||
foreach ($accounts as $account) {
|
||||
$startAmount = bcadd($startAmount, $account->startBalance);
|
||||
$endAmount = bcadd($endAmount, $account->endBalance);
|
||||
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
|
||||
}
|
||||
|
||||
$object = new AccountCollection;
|
||||
$object->setStart($startAmount);
|
||||
$object->setEnd($endAmount);
|
||||
$object->setDifference($diff);
|
||||
$object->setAccounts($accounts);
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
36
app/Helpers/Report/AccountReportHelperInterface.php
Normal file
36
app/Helpers/Report/AccountReportHelperInterface.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountReportHelperInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Account as AccountCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Interface AccountReportHelperInterface
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
interface AccountReportHelperInterface
|
||||
{
|
||||
/**
|
||||
* This method generates a full report for the given period on all
|
||||
* given accounts
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return AccountCollection
|
||||
*/
|
||||
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
}
|
241
app/Helpers/Report/BalanceReportHelper.php
Normal file
241
app/Helpers/Report/BalanceReportHelper.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* BalanceReportHelper.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Balance;
|
||||
use FireflyIII\Helpers\Collection\BalanceEntry;
|
||||
use FireflyIII\Helpers\Collection\BalanceHeader;
|
||||
use FireflyIII\Helpers\Collection\BalanceLine;
|
||||
use FireflyIII\Models\Budget as BudgetModel;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Class BalanceReportHelper
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
class BalanceReportHelper implements BalanceReportHelperInterface
|
||||
{
|
||||
|
||||
/** @var BudgetRepositoryInterface */
|
||||
protected $budgetRepository;
|
||||
/** @var TagRepositoryInterface */
|
||||
protected $tagRepository;
|
||||
|
||||
/**
|
||||
* ReportHelper constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param BudgetRepositoryInterface $budgetRepository
|
||||
* @param TagRepositoryInterface $tagRepository
|
||||
*/
|
||||
public function __construct(BudgetRepositoryInterface $budgetRepository, TagRepositoryInterface $tagRepository)
|
||||
{
|
||||
$this->budgetRepository = $budgetRepository;
|
||||
$this->tagRepository = $tagRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$balance = new Balance;
|
||||
|
||||
// build a balance header:
|
||||
$header = new BalanceHeader;
|
||||
$budgets = $this->budgetRepository->getBudgetsAndLimitsInRange($start, $end);
|
||||
$spentData = $this->budgetRepository->spentPerBudgetPerAccount($budgets, $accounts, $start, $end);
|
||||
foreach ($accounts as $account) {
|
||||
$header->addAccount($account);
|
||||
}
|
||||
|
||||
/** @var BudgetModel $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$balance->addBalanceLine($this->createBalanceLine($budget, $accounts, $spentData));
|
||||
}
|
||||
|
||||
$balance->addBalanceLine($this->createEmptyBalanceLine($accounts, $spentData));
|
||||
$balance->addBalanceLine($this->createTagsBalanceLine($accounts, $start, $end));
|
||||
$balance->addBalanceLine($this->createDifferenceBalanceLine($accounts, $spentData, $start, $end));
|
||||
|
||||
$balance->setBalanceHeader($header);
|
||||
|
||||
return $balance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Collection $accounts
|
||||
* @param Collection $spentData
|
||||
*
|
||||
* @return BalanceLine
|
||||
*/
|
||||
private function createBalanceLine(BudgetModel $budget, Collection $accounts, Collection $spentData)
|
||||
{
|
||||
$line = new BalanceLine;
|
||||
$line->setBudget($budget);
|
||||
|
||||
// loop accounts:
|
||||
foreach ($accounts as $account) {
|
||||
$balanceEntry = new BalanceEntry;
|
||||
$balanceEntry->setAccount($account);
|
||||
|
||||
// get spent:
|
||||
$entry = $spentData->filter(
|
||||
function (TransactionJournal $model) use ($budget, $account) {
|
||||
return $model->account_id == $account->id && $model->budget_id == $budget->id;
|
||||
}
|
||||
);
|
||||
$spent = 0;
|
||||
if (!is_null($entry->first())) {
|
||||
$spent = $entry->first()->spent;
|
||||
}
|
||||
$balanceEntry->setSpent($spent);
|
||||
$line->addBalanceEntry($balanceEntry);
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $spentData
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @return BalanceLine
|
||||
*/
|
||||
private function createDifferenceBalanceLine(Collection $accounts, Collection $spentData, Carbon $start, Carbon $end)
|
||||
{
|
||||
$diff = new BalanceLine;
|
||||
$tagsLeft = $this->tagRepository->allCoveredByBalancingActs($accounts, $start, $end);
|
||||
|
||||
$diff->setRole(BalanceLine::ROLE_DIFFROLE);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$entry = $spentData->filter(
|
||||
function (TransactionJournal $model) use ($account) {
|
||||
return $model->account_id == $account->id && is_null($model->budget_id);
|
||||
}
|
||||
);
|
||||
$spent = 0;
|
||||
if (!is_null($entry->first())) {
|
||||
$spent = $entry->first()->spent;
|
||||
}
|
||||
$leftEntry = $tagsLeft->filter(
|
||||
function (Tag $tag) use ($account) {
|
||||
return $tag->account_id == $account->id;
|
||||
}
|
||||
);
|
||||
$left = 0;
|
||||
if (!is_null($leftEntry->first())) {
|
||||
$left = $leftEntry->first()->sum;
|
||||
}
|
||||
bcscale(2);
|
||||
$diffValue = bcadd($spent, $left);
|
||||
|
||||
// difference:
|
||||
$diffEntry = new BalanceEntry;
|
||||
$diffEntry->setAccount($account);
|
||||
$diffEntry->setSpent($diffValue);
|
||||
$diff->addBalanceEntry($diffEntry);
|
||||
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $spentData
|
||||
*
|
||||
* @return BalanceLine
|
||||
*/
|
||||
private function createEmptyBalanceLine(Collection $accounts, Collection $spentData)
|
||||
{
|
||||
$empty = new BalanceLine;
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$entry = $spentData->filter(
|
||||
function (TransactionJournal $model) use ($account) {
|
||||
return $model->account_id == $account->id && is_null($model->budget_id);
|
||||
}
|
||||
);
|
||||
$spent = 0;
|
||||
if (!is_null($entry->first())) {
|
||||
$spent = $entry->first()->spent;
|
||||
}
|
||||
|
||||
// budget
|
||||
$budgetEntry = new BalanceEntry;
|
||||
$budgetEntry->setAccount($account);
|
||||
$budgetEntry->setSpent($spent);
|
||||
$empty->addBalanceEntry($budgetEntry);
|
||||
|
||||
}
|
||||
|
||||
return $empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return BalanceLine
|
||||
*/
|
||||
private function createTagsBalanceLine(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$tags = new BalanceLine;
|
||||
$tagsLeft = $this->tagRepository->allCoveredByBalancingActs($accounts, $start, $end);
|
||||
|
||||
$tags->setRole(BalanceLine::ROLE_TAGROLE);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$leftEntry = $tagsLeft->filter(
|
||||
function (Tag $tag) use ($account) {
|
||||
return $tag->account_id == $account->id;
|
||||
}
|
||||
);
|
||||
$left = 0;
|
||||
if (!is_null($leftEntry->first())) {
|
||||
$left = $leftEntry->first()->sum;
|
||||
}
|
||||
bcscale(2);
|
||||
|
||||
// balanced by tags
|
||||
$tagEntry = new BalanceEntry;
|
||||
$tagEntry->setAccount($account);
|
||||
$tagEntry->setLeft($left);
|
||||
$tags->addBalanceEntry($tagEntry);
|
||||
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
}
|
32
app/Helpers/Report/BalanceReportHelperInterface.php
Normal file
32
app/Helpers/Report/BalanceReportHelperInterface.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* BalanceReportHelperInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Balance;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Interface BalanceReportHelperInterface
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
interface BalanceReportHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
}
|
133
app/Helpers/Report/BudgetReportHelper.php
Normal file
133
app/Helpers/Report/BudgetReportHelper.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetReportHelper.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
|
||||
use FireflyIII\Helpers\Collection\BudgetLine;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class BudgetReportHelper
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return BudgetCollection
|
||||
*/
|
||||
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$object = new BudgetCollection;
|
||||
/** @var \FireflyIII\Repositories\Budget\BudgetRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$set = $repository->getBudgets();
|
||||
$allRepetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
$allTotalSpent = $repository->spentAllPerDayForAccounts($accounts, $start, $end);
|
||||
bcscale(2);
|
||||
|
||||
foreach ($set as $budget) {
|
||||
|
||||
$repetitions = $allRepetitions->filter(
|
||||
function (LimitRepetition $rep) use ($budget) {
|
||||
return $rep->budget_id == $budget->id;
|
||||
}
|
||||
);
|
||||
$totalSpent = isset($allTotalSpent[$budget->id]) ? $allTotalSpent[$budget->id] : [];
|
||||
|
||||
// no repetition(s) for this budget:
|
||||
if ($repetitions->count() == 0) {
|
||||
$spent = array_sum($totalSpent);
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setBudget($budget);
|
||||
$budgetLine->setOverspent($spent);
|
||||
$object->addOverspent($spent);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
continue;
|
||||
}
|
||||
|
||||
// one or more repetitions for budget:
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setBudget($budget);
|
||||
$budgetLine->setRepetition($repetition);
|
||||
$expenses = $this->getSumOfRange($start, $end, $totalSpent);
|
||||
|
||||
// 200 en -100 is 100, vergeleken met 0 === 1
|
||||
// 200 en -200 is 0, vergeleken met 0 === 0
|
||||
// 200 en -300 is -100, vergeleken met 0 === -1
|
||||
|
||||
$left = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? bcadd($repetition->amount, $expenses) : 0;
|
||||
$spent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? $expenses : '0';
|
||||
$overspent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? '0' : bcadd($expenses, $repetition->amount);
|
||||
|
||||
$budgetLine->setLeft($left);
|
||||
$budgetLine->setSpent($expenses);
|
||||
$budgetLine->setOverspent($overspent);
|
||||
$budgetLine->setBudgeted($repetition->amount);
|
||||
|
||||
$object->addBudgeted($repetition->amount);
|
||||
$object->addSpent($spent);
|
||||
$object->addLeft($left);
|
||||
$object->addOverspent($overspent);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// stuff outside of budgets:
|
||||
$noBudget = $repository->getWithoutBudgetSum($start, $end);
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setOverspent($noBudget);
|
||||
$budgetLine->setSpent($noBudget);
|
||||
$object->addOverspent($noBudget);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
|
||||
{
|
||||
bcscale(2);
|
||||
$sum = '0';
|
||||
$currentStart = clone $start; // to not mess with the original one
|
||||
$currentEnd = clone $end; // to not mess with the original one
|
||||
|
||||
while ($currentStart <= $currentEnd) {
|
||||
$date = $currentStart->format('Y-m-d');
|
||||
if (isset($array[$date])) {
|
||||
$sum = bcadd($sum, $array[$date]);
|
||||
}
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
32
app/Helpers/Report/BudgetReportHelperInterface.php
Normal file
32
app/Helpers/Report/BudgetReportHelperInterface.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetReportHelperInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface BudgetReportHelperInterface
|
||||
*
|
||||
* @package FireflyIII\Helpers\Report
|
||||
*/
|
||||
interface BudgetReportHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return BudgetCollection
|
||||
*/
|
||||
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
}
|
@@ -3,24 +3,17 @@
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Account as AccountCollection;
|
||||
use FireflyIII\Helpers\Collection\Balance;
|
||||
use FireflyIII\Helpers\Collection\BalanceEntry;
|
||||
use FireflyIII\Helpers\Collection\BalanceHeader;
|
||||
use FireflyIII\Helpers\Collection\BalanceLine;
|
||||
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
||||
use FireflyIII\Helpers\Collection\BillLine;
|
||||
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
|
||||
use FireflyIII\Helpers\Collection\BudgetLine;
|
||||
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
|
||||
use FireflyIII\Helpers\Collection\Expense;
|
||||
use FireflyIII\Helpers\Collection\Income;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Helpers\FiscalHelperInterface;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Budget as BudgetModel;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* Class ReportHelper
|
||||
@@ -30,337 +23,27 @@ use Steam;
|
||||
class ReportHelper implements ReportHelperInterface
|
||||
{
|
||||
|
||||
/** @var BudgetRepositoryInterface */
|
||||
protected $budgetRepository;
|
||||
/** @var ReportQueryInterface */
|
||||
protected $query;
|
||||
/** @var TagRepositoryInterface */
|
||||
protected $tagRepository;
|
||||
|
||||
/**
|
||||
* ReportHelper constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ReportQueryInterface $query
|
||||
*
|
||||
* @param ReportQueryInterface $query
|
||||
* @param BudgetRepositoryInterface $budgetRepository
|
||||
* @param TagRepositoryInterface $tagRepository
|
||||
*/
|
||||
public function __construct(ReportQueryInterface $query)
|
||||
public function __construct(ReportQueryInterface $query, BudgetRepositoryInterface $budgetRepository, TagRepositoryInterface $tagRepository)
|
||||
{
|
||||
$this->query = $query;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return CategoryCollection
|
||||
*/
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$object = new CategoryCollection;
|
||||
|
||||
/**
|
||||
* GET CATEGORIES:
|
||||
*/
|
||||
/** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||
$set = $repository->getCategories();
|
||||
foreach ($set as $category) {
|
||||
$spent = $repository->balanceInPeriod($category, $start, $end, $accounts);
|
||||
$category->spent = $spent;
|
||||
$object->addCategory($category);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listOfMonths(Carbon $date)
|
||||
{
|
||||
|
||||
$start = clone $date;
|
||||
$end = Carbon::now();
|
||||
$months = [];
|
||||
while ($start <= $end) {
|
||||
$year = $start->year;
|
||||
|
||||
if (!isset($months[$year])) {
|
||||
$months[$year] = [
|
||||
'start' => Carbon::createFromDate($year, 1, 1)->format('Y-m-d'),
|
||||
'end' => Carbon::createFromDate($year, 12, 31)->format('Y-m-d'),
|
||||
'months' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$currentEnd = clone $start;
|
||||
$currentEnd->endOfMonth();
|
||||
$months[$year]['months'][] = [
|
||||
'formatted' => $start->formatLocalized('%B %Y'),
|
||||
'start' => $start->format('Y-m-d'),
|
||||
'end' => $currentEnd->format('Y-m-d'),
|
||||
'month' => $start->month,
|
||||
'year' => $year,
|
||||
];
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method generates a full report for the given period on all
|
||||
* given accounts
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return AccountCollection
|
||||
*/
|
||||
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$startAmount = '0';
|
||||
$endAmount = '0';
|
||||
$diff = '0';
|
||||
bcscale(2);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($start, $end) {
|
||||
/**
|
||||
* The balance for today always incorporates transactions
|
||||
* made on today. So to get todays "start" balance, we sub one
|
||||
* day.
|
||||
*/
|
||||
$yesterday = clone $start;
|
||||
$yesterday->subDay();
|
||||
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$account->startBalance = Steam::balance($account, $yesterday);
|
||||
$account->endBalance = Steam::balance($account, $end);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// summarize:
|
||||
foreach ($accounts as $account) {
|
||||
$startAmount = bcadd($startAmount, $account->startBalance);
|
||||
$endAmount = bcadd($endAmount, $account->endBalance);
|
||||
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
|
||||
}
|
||||
|
||||
$object = new AccountCollection;
|
||||
$object->setStart($startAmount);
|
||||
$object->setEnd($endAmount);
|
||||
$object->setDifference($diff);
|
||||
$object->setAccounts($accounts);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users incomes during the period for the given accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Income
|
||||
*/
|
||||
public function getIncomeReport($start, $end, Collection $accounts)
|
||||
{
|
||||
$object = new Income;
|
||||
$set = $this->query->incomeInPeriod($start, $end, $accounts);
|
||||
foreach ($set as $entry) {
|
||||
$object->addToTotal($entry->amount_positive);
|
||||
$object->addOrCreateIncome($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users expenses during the period for a list of accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
public function getExpenseReport($start, $end, Collection $accounts)
|
||||
{
|
||||
$object = new Expense;
|
||||
$set = $this->query->expenseInPeriod($start, $end, $accounts);
|
||||
foreach ($set as $entry) {
|
||||
$object->addToTotal($entry->amount); // can be positive, if it's a transfer
|
||||
$object->addOrCreateExpense($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return BudgetCollection
|
||||
*/
|
||||
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$object = new BudgetCollection;
|
||||
/** @var \FireflyIII\Repositories\Budget\BudgetRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$set = $repository->getBudgets();
|
||||
|
||||
bcscale(2);
|
||||
|
||||
foreach ($set as $budget) {
|
||||
|
||||
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
|
||||
|
||||
// no repetition(s) for this budget:
|
||||
if ($repetitions->count() == 0) {
|
||||
$spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setBudget($budget);
|
||||
$budgetLine->setOverspent($spent);
|
||||
$object->addOverspent($spent);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
continue;
|
||||
}
|
||||
|
||||
// one or more repetitions for budget:
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setBudget($budget);
|
||||
$budgetLine->setRepetition($repetition);
|
||||
$expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts);
|
||||
|
||||
// 200 en -100 is 100, vergeleken met 0 === 1
|
||||
// 200 en -200 is 0, vergeleken met 0 === 0
|
||||
// 200 en -300 is -100, vergeleken met 0 === -1
|
||||
|
||||
$left = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? bcadd($repetition->amount, $expenses) : 0;
|
||||
$spent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? $expenses : '0';
|
||||
$overspent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? '0' : bcadd($expenses, $repetition->amount);
|
||||
|
||||
$budgetLine->setLeft($left);
|
||||
$budgetLine->setSpent($spent);
|
||||
$budgetLine->setOverspent($overspent);
|
||||
$budgetLine->setBudgeted($repetition->amount);
|
||||
|
||||
$object->addBudgeted($repetition->amount);
|
||||
$object->addSpent($spent);
|
||||
$object->addLeft($left);
|
||||
$object->addOverspent($overspent);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// stuff outside of budgets:
|
||||
$noBudget = $repository->getWithoutBudgetSum($start, $end);
|
||||
$budgetLine = new BudgetLine;
|
||||
$budgetLine->setOverspent($noBudget);
|
||||
$budgetLine->setSpent($noBudget);
|
||||
$object->addOverspent($noBudget);
|
||||
$object->addBudgetLine($budgetLine);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||
$tagRepository = app('FireflyIII\Repositories\Tag\TagRepositoryInterface');
|
||||
$balance = new Balance;
|
||||
|
||||
// build a balance header:
|
||||
$header = new BalanceHeader;
|
||||
$budgets = $repository->getBudgets();
|
||||
foreach ($accounts as $account) {
|
||||
$header->addAccount($account);
|
||||
}
|
||||
|
||||
/** @var BudgetModel $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$line = new BalanceLine;
|
||||
$line->setBudget($budget);
|
||||
|
||||
// get budget amount for current period:
|
||||
$rep = $repository->getCurrentRepetition($budget, $start, $end);
|
||||
// could be null?
|
||||
$line->setRepetition($rep);
|
||||
|
||||
// loop accounts:
|
||||
foreach ($accounts as $account) {
|
||||
$balanceEntry = new BalanceEntry;
|
||||
$balanceEntry->setAccount($account);
|
||||
|
||||
// get spent:
|
||||
$spent = $this->query->spentInBudget($account, $budget, $start, $end); // I think shared is irrelevant.
|
||||
|
||||
$balanceEntry->setSpent($spent);
|
||||
$line->addBalanceEntry($balanceEntry);
|
||||
}
|
||||
// add line to balance:
|
||||
$balance->addBalanceLine($line);
|
||||
}
|
||||
|
||||
// then a new line for without budget.
|
||||
// and one for the tags:
|
||||
// and one for "left unbalanced".
|
||||
$empty = new BalanceLine;
|
||||
$tags = new BalanceLine;
|
||||
$diffLine = new BalanceLine;
|
||||
|
||||
$tags->setRole(BalanceLine::ROLE_TAGROLE);
|
||||
$diffLine->setRole(BalanceLine::ROLE_DIFFROLE);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$spent = $this->query->spentNoBudget($account, $start, $end);
|
||||
$left = $tagRepository->coveredByBalancingActs($account, $start, $end);
|
||||
bcscale(2);
|
||||
$diff = bcadd($spent, $left);
|
||||
|
||||
// budget
|
||||
$budgetEntry = new BalanceEntry;
|
||||
$budgetEntry->setAccount($account);
|
||||
$budgetEntry->setSpent($spent);
|
||||
$empty->addBalanceEntry($budgetEntry);
|
||||
|
||||
// balanced by tags
|
||||
$tagEntry = new BalanceEntry;
|
||||
$tagEntry->setAccount($account);
|
||||
$tagEntry->setLeft($left);
|
||||
$tags->addBalanceEntry($tagEntry);
|
||||
|
||||
// difference:
|
||||
$diffEntry = new BalanceEntry;
|
||||
$diffEntry->setAccount($account);
|
||||
$diffEntry->setSpent($diff);
|
||||
$diffLine->addBalanceEntry($diffEntry);
|
||||
|
||||
}
|
||||
|
||||
$balance->addBalanceLine($empty);
|
||||
$balance->addBalanceLine($tags);
|
||||
$balance->addBalanceLine($diffLine);
|
||||
|
||||
$balance->setBalanceHeader($header);
|
||||
|
||||
return $balance;
|
||||
$this->query = $query;
|
||||
$this->budgetRepository = $budgetRepository;
|
||||
$this->tagRepository = $tagRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,6 +63,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||
$bills = $repository->getBillsForAccounts($accounts);
|
||||
$journals = $repository->getAllJournalsInRange($bills, $start, $end);
|
||||
$collection = new BillCollection;
|
||||
|
||||
/** @var Bill $bill */
|
||||
@@ -392,16 +76,17 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
// is hit in period?
|
||||
bcscale(2);
|
||||
$set = $repository->getJournalsInRange($bill, $start, $end);
|
||||
if ($set->count() == 0) {
|
||||
$billLine->setHit(false);
|
||||
} else {
|
||||
$billLine->setHit(true);
|
||||
$amount = '0';
|
||||
foreach ($set as $entry) {
|
||||
$amount = bcadd($amount, $entry->amount);
|
||||
|
||||
$entry = $journals->filter(
|
||||
function (TransactionJournal $journal) use ($bill) {
|
||||
return $journal->bill_id == $bill->id;
|
||||
}
|
||||
$billLine->setAmount($amount);
|
||||
);
|
||||
if (!is_null($entry->first())) {
|
||||
$billLine->setAmount($entry->first()->journalAmount);
|
||||
$billLine->setHit(true);
|
||||
} else {
|
||||
$billLine->setHit(false);
|
||||
}
|
||||
|
||||
$collection->addBill($billLine);
|
||||
@@ -410,4 +95,142 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return CategoryCollection
|
||||
*/
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$object = new CategoryCollection;
|
||||
|
||||
/**
|
||||
* GET CATEGORIES:
|
||||
*/
|
||||
/** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||
|
||||
$set = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
||||
foreach ($set as $category) {
|
||||
$object->addCategory($category);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users expenses during the period for a list of accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Expense
|
||||
*/
|
||||
public function getExpenseReport($start, $end, Collection $accounts)
|
||||
{
|
||||
$object = new Expense;
|
||||
$set = $this->query->expense($accounts, $start, $end);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$object->addToTotal($entry->journalAmount); // can be positive, if it's a transfer
|
||||
$object->addOrCreateExpense($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full report on the users incomes during the period for the given accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Income
|
||||
*/
|
||||
public function getIncomeReport($start, $end, Collection $accounts)
|
||||
{
|
||||
$object = new Income;
|
||||
$set = $this->query->income($accounts, $start, $end);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$object->addToTotal($entry->journalAmount);
|
||||
$object->addOrCreateIncome($entry);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listOfMonths(Carbon $date)
|
||||
{
|
||||
/** @var FiscalHelperInterface $fiscalHelper */
|
||||
$fiscalHelper = app('FireflyIII\Helpers\FiscalHelperInterface');
|
||||
$start = clone $date;
|
||||
$end = Carbon::now();
|
||||
$months = [];
|
||||
|
||||
while ($start <= $end) {
|
||||
$year = $fiscalHelper->endOfFiscalYear($start)->year;
|
||||
|
||||
if (!isset($months[$year])) {
|
||||
$months[$year] = [
|
||||
'fiscal_start' => $fiscalHelper->startOfFiscalYear($start)->format('Y-m-d'),
|
||||
'fiscal_end' => $fiscalHelper->endOfFiscalYear($start)->format('Y-m-d'),
|
||||
'start' => Carbon::createFromDate($year, 1, 1)->format('Y-m-d'),
|
||||
'end' => Carbon::createFromDate($year, 12, 31)->format('Y-m-d'),
|
||||
'months' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$currentEnd = clone $start;
|
||||
$currentEnd->endOfMonth();
|
||||
$months[$year]['months'][] = [
|
||||
'formatted' => $start->formatLocalized('%B %Y'),
|
||||
'start' => $start->format('Y-m-d'),
|
||||
'end' => $currentEnd->format('Y-m-d'),
|
||||
'month' => $start->month,
|
||||
'year' => $year,
|
||||
];
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
|
||||
{
|
||||
bcscale(2);
|
||||
$sum = '0';
|
||||
$currentStart = clone $start; // to not mess with the original one
|
||||
$currentEnd = clone $end; // to not mess with the original one
|
||||
|
||||
while ($currentStart <= $currentEnd) {
|
||||
$date = $currentStart->format('Y-m-d');
|
||||
if (isset($array[$date])) {
|
||||
$sum = bcadd($sum, $array[$date]);
|
||||
}
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,7 @@
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collection\Account as AccountCollection;
|
||||
use FireflyIII\Helpers\Collection\Balance;
|
||||
use FireflyIII\Helpers\Collection\Bill as BillCollection;
|
||||
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
|
||||
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
|
||||
use FireflyIII\Helpers\Collection\Expense;
|
||||
use FireflyIII\Helpers\Collection\Income;
|
||||
@@ -20,18 +17,6 @@ use Illuminate\Support\Collection;
|
||||
interface ReportHelperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* This method generates a full report for the given period on all
|
||||
* given accounts
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return AccountCollection
|
||||
*/
|
||||
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* This method generates a full report for the given period on all
|
||||
* the users bills and their payments.
|
||||
@@ -46,24 +31,6 @@ interface ReportHelperInterface
|
||||
*/
|
||||
public function getBillReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return BudgetCollection
|
||||
*/
|
||||
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
|
@@ -4,12 +4,8 @@ namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use DB;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -20,224 +16,163 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class ReportQuery implements ReportQueryInterface
|
||||
{
|
||||
/**
|
||||
* Covers tags
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end)
|
||||
{
|
||||
|
||||
return Auth::user()->transactionjournals()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->where('transactions.account_id', $account->id)
|
||||
/**
|
||||
* Returns an array of the amount of money spent in the given accounts (on withdrawals, opening balances and transfers)
|
||||
* grouped by month like so: "2015-01" => '123.45'
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedPerMonth(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$query = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
'transactions AS t_from', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_from.transaction_journal_id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS t_to', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_to.transaction_journal_id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->whereIn('t_to.account_id', $ids)
|
||||
->whereNotIn('t_from.account_id', $ids)
|
||||
->after($start)
|
||||
->before($end)
|
||||
->transactionTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])
|
||||
->groupBy('dateFormatted')
|
||||
->get(
|
||||
[
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
|
||||
DB::Raw('SUM(`t_to`.`amount`) AS `sum`'),
|
||||
]
|
||||
);
|
||||
$array = [];
|
||||
foreach ($query as $result) {
|
||||
$array[$result->dateFormatted] = $result->sum;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns all the "out" transaction journals for the given account and given period. The amount
|
||||
* is stored in "journalAmount".
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function expense(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$set = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
'transactions as t_from', function (JoinClause $join) {
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions as t_to', function (JoinClause $join) {
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts', 't_to.account_id', '=', 'accounts.id')
|
||||
->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])
|
||||
->before($end)
|
||||
->after($start)
|
||||
->where('budget_transaction_journal.budget_id', $budget->id)
|
||||
->get(['transaction_journals.*'])->sum('amount');
|
||||
->whereIn('t_from.account_id', $ids)
|
||||
->whereNotIn('t_to.account_id', $ids)
|
||||
->get(['transaction_journals.*', 't_from.amount as journalAmount', 'accounts.id as account_id', 'accounts.name as account_name']);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function spentNoBudget(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
return
|
||||
Auth::user()->transactionjournals()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->where('transactions.account_id', $account->id)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->whereNull('budget_transaction_journal.budget_id')->get(['transaction_journals.*'])->sum('amount');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
protected function queryJournalsWithTransactions(Carbon $start, Carbon $end)
|
||||
{
|
||||
$query = TransactionJournal::
|
||||
leftJoin(
|
||||
'transactions as t_from', function (JoinClause $join) {
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_from', 't_from.account_id', '=', 'ac_from.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_from', function (JoinClause $join) {
|
||||
$join->on('ac_from.id', '=', 'acm_from.account_id')->where('acm_from.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions as t_to', function (JoinClause $join) {
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as ac_to', 't_to.account_id', '=', 'ac_to.id')
|
||||
->leftJoin(
|
||||
'account_meta as acm_to', function (JoinClause $join) {
|
||||
$join->on('ac_to.id', '=', 'acm_to.account_id')->where('acm_to.name', '=', 'accountRole');
|
||||
}
|
||||
)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
||||
$query->before($end)->after($start)->where('transaction_journals.user_id', Auth::user()->id);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results
|
||||
* will simply list the transaction journals only. This should allow any follow up counting to be accurate with
|
||||
* regards to tags. It will only get the incomes to the specified accounts.
|
||||
* This method returns all the "in" transaction journals for the given account and given period. The amount
|
||||
* is stored in "journalAmount".
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function incomeInPeriod(Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function income(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$query = $this->queryJournalsWithTransactions($start, $end);
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$set = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
'transactions as t_from', function (JoinClause $join) {
|
||||
$join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions as t_to', function (JoinClause $join) {
|
||||
$join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts', 't_from.account_id', '=', 'accounts.id')
|
||||
->transactionTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])
|
||||
->before($end)
|
||||
->after($start)
|
||||
->whereIn('t_to.account_id', $ids)
|
||||
->whereNotIn('t_from.account_id', $ids)
|
||||
->get(['transaction_journals.*', 't_to.amount as journalAmount', 'accounts.id as account_id', 'accounts.name as account_name']);
|
||||
|
||||
$ids = [];
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$ids[] = $account->id;
|
||||
}
|
||||
|
||||
// OR is a deposit
|
||||
// OR any transfer TO the accounts in $accounts, not FROM any of the accounts in $accounts.
|
||||
$query->where(
|
||||
function (Builder $query) use ($ids) {
|
||||
$query->where(
|
||||
function (Builder $q) {
|
||||
$q->where('transaction_types.type', TransactionType::DEPOSIT);
|
||||
}
|
||||
);
|
||||
$query->orWhere(
|
||||
function (Builder $q) use ($ids) {
|
||||
$q->where('transaction_types.type', TransactionType::TRANSFER);
|
||||
$q->whereNotIn('ac_from.id', $ids);
|
||||
$q->whereIn('ac_to.id', $ids);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// only include selected accounts.
|
||||
$query->whereIn('ac_to.id', $ids);
|
||||
$query->orderBy('transaction_journals.date');
|
||||
|
||||
// get everything
|
||||
$data = $query->get(
|
||||
['transaction_journals.*',
|
||||
'transaction_types.type', 'ac_from.name as name',
|
||||
't_from.amount as from_amount',
|
||||
't_to.amount as to_amount',
|
||||
'ac_from.id as account_id', 'ac_from.encrypted as account_encrypted']
|
||||
);
|
||||
|
||||
$data->each(
|
||||
function (TransactionJournal $journal) {
|
||||
if (intval($journal->account_encrypted) == 1) {
|
||||
$journal->name = Crypt::decrypt($journal->name);
|
||||
}
|
||||
}
|
||||
);
|
||||
// $data = $data->filter(
|
||||
// function (TransactionJournal $journal) {
|
||||
// if ($journal->amount != 0) {
|
||||
// return $journal;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
// );
|
||||
|
||||
return $data;
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* See ReportQueryInterface::incomeInPeriod
|
||||
*
|
||||
* This method returns all "expense" journals in a certain period, which are both transfers to a shared account
|
||||
* and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
|
||||
* not group and returns different fields.
|
||||
* Returns an array of the amount of money spent in the given accounts (on withdrawals, opening balances and transfers)
|
||||
* grouped by month like so: "2015-01" => '123.45'
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseInPeriod(Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function spentPerMonth(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$ids[] = $account->id;
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$query = Auth::user()->transactionjournals()
|
||||
->leftJoin(
|
||||
'transactions AS t_from', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_from.transaction_journal_id')->where('t_from.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS t_to', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 't_to.transaction_journal_id')->where('t_to.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->whereIn('t_from.account_id', $ids)
|
||||
->whereNotIn('t_to.account_id', $ids)
|
||||
->after($start)
|
||||
->before($end)
|
||||
->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])
|
||||
->groupBy('dateFormatted')
|
||||
->get(
|
||||
[
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") AS `dateFormatted`'),
|
||||
DB::Raw('SUM(`t_from`.`amount`) AS `sum`'),
|
||||
]
|
||||
);
|
||||
$array = [];
|
||||
foreach ($query as $result) {
|
||||
$array[$result->dateFormatted] = $result->sum;
|
||||
}
|
||||
|
||||
$query = $this->queryJournalsWithTransactions($start, $end);
|
||||
return $array;
|
||||
|
||||
// withdrawals from any account are an expense.
|
||||
// transfers away, from an account in the list, to an account not in the list, are an expense.
|
||||
|
||||
$query->where(
|
||||
function (Builder $query) use ($ids) {
|
||||
$query->where(
|
||||
function (Builder $q) {
|
||||
$q->where('transaction_types.type', TransactionType::WITHDRAWAL);
|
||||
}
|
||||
);
|
||||
$query->orWhere(
|
||||
function (Builder $q) use ($ids) {
|
||||
$q->where('transaction_types.type', TransactionType::TRANSFER);
|
||||
$q->whereIn('ac_from.id', $ids);
|
||||
$q->whereNotIn('ac_to.id', $ids);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// expense goes from the selected accounts:
|
||||
$query->whereIn('ac_from.id', $ids);
|
||||
|
||||
$query->orderBy('transaction_journals.date');
|
||||
$data = $query->get( // get everything
|
||||
['transaction_journals.*', 'transaction_types.type',
|
||||
't_from.amount as from_amount',
|
||||
't_to.amount as to_amount',
|
||||
'ac_to.name as name', 'ac_to.id as account_id', 'ac_to.encrypted as account_encrypted']
|
||||
);
|
||||
|
||||
$data->each(
|
||||
function (TransactionJournal $journal) {
|
||||
if (intval($journal->account_encrypted) == 1) {
|
||||
$journal->name = Crypt::decrypt($journal->name);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,6 @@
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Budget;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -16,54 +14,52 @@ interface ReportQueryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* See ReportQueryInterface::incomeInPeriod
|
||||
*
|
||||
* This method returns all "expense" journals in a certain period, which are both transfers to a shared account
|
||||
* and "ordinary" withdrawals. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does
|
||||
* not group and returns different fields.
|
||||
* Returns an array of the amount of money spent in the given accounts (on withdrawals, opening balances and transfers)
|
||||
* grouped by month like so: "2015-01" => '123.45'
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseInPeriod(Carbon $start, Carbon $end, Collection $accounts);
|
||||
public function earnedPerMonth(Collection $accounts, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* This method works the same way as ReportQueryInterface::incomeInPeriod does, but instead of returning results
|
||||
* will simply list the transaction journals only. This should allow any follow up counting to be accurate with
|
||||
* regards to tags. It will only get the incomes to the specified accounts.
|
||||
* This method returns all the "out" transaction journals for the given account and given period. The amount
|
||||
* is stored in "journalAmount".
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function incomeInPeriod(Carbon $start, Carbon $end, Collection $accounts);
|
||||
public function expense(Collection $accounts, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* Covers tags as well.
|
||||
* This method returns all the "in" transaction journals for the given account and given period. The amount
|
||||
* is stored in "journalAmount".
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return float
|
||||
* @return Collection
|
||||
*/
|
||||
public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end);
|
||||
public function income(Collection $accounts, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* Returns an array of the amount of money spent in the given accounts (on withdrawals, opening balances and transfers)
|
||||
* grouped by month like so: "2015-01" => '123.45'
|
||||
*
|
||||
* @return string
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentNoBudget(Account $account, Carbon $start, Carbon $end);
|
||||
public function spentPerMonth(Collection $accounts, Carbon $start, Carbon $end);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use Config;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Session;
|
||||
@@ -56,11 +56,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function delete(AccountRepositoryInterface $repository, Account $account)
|
||||
public function delete(ARI $repository, Account $account)
|
||||
{
|
||||
$typeName = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||
$subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]);
|
||||
@@ -76,12 +77,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(AccountRepositoryInterface $repository, Account $account)
|
||||
public function destroy(ARI $repository, Account $account)
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$typeName = Config::get('firefly.shortNamesByFullName.' . $type);
|
||||
@@ -97,12 +98,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(AccountRepositoryInterface $repository, Account $account)
|
||||
public function edit(ARI $repository, Account $account)
|
||||
{
|
||||
|
||||
$what = Config::get('firefly.shortNamesByFullName')[$account->accountType->type];
|
||||
@@ -132,7 +133,7 @@ class AccountController extends Controller
|
||||
'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'),
|
||||
'openingBalanceDate' => $openingBalance ? $openingBalance->date->format('Y-m-d') : null,
|
||||
'openingBalance' => $openingBalanceAmount,
|
||||
'virtualBalance' => round($account->virtual_balance, 2)
|
||||
'virtualBalance' => round($account->virtual_balance, 2),
|
||||
];
|
||||
Session::flash('preFilled', $preFilled);
|
||||
Session::flash('gaEventCategory', 'accounts');
|
||||
@@ -142,40 +143,31 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param ARI $repository
|
||||
* @param $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository, $what)
|
||||
public function index(ARI $repository, $what)
|
||||
{
|
||||
$subTitle = trans('firefly.' . $what . '_accounts');
|
||||
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = Config::get('firefly.accountTypesByIdentifier.' . $what);
|
||||
$accounts = $repository->getAccounts($types);
|
||||
// last activity:
|
||||
/**
|
||||
* HERE WE ARE
|
||||
*/
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
// start balances:
|
||||
$ids = [];
|
||||
foreach ($accounts as $account) {
|
||||
$ids[] = $account->id;
|
||||
}
|
||||
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$startBalances = Steam::balancesById($ids, $start);
|
||||
$endBalances = Steam::balancesById($ids, $end);
|
||||
$activities = Steam::getLastActivities($ids);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
$account->lastActivityDate = isset($activities[$account->id]) ? $activities[$account->id] : null;
|
||||
$account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
|
||||
$account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -183,12 +175,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(AccountRepositoryInterface $repository, Account $account)
|
||||
public function show(ARI $repository, Account $account)
|
||||
{
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$subTitleIcon = Config::get('firefly.subTitlesByIdentifier.' . $account->accountType->type);
|
||||
@@ -202,12 +194,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param AccountFormRequest $request
|
||||
* @param ARI $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(AccountFormRequest $request, AccountRepositoryInterface $repository)
|
||||
public function store(AccountFormRequest $request, ARI $repository)
|
||||
{
|
||||
$accountData = [
|
||||
'name' => $request->input('name'),
|
||||
@@ -241,13 +233,13 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param AccountFormRequest $request
|
||||
* @param ARI $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(AccountFormRequest $request, AccountRepositoryInterface $repository, Account $account)
|
||||
public function update(AccountFormRequest $request, ARI $repository, Account $account)
|
||||
{
|
||||
|
||||
$accountData = [
|
||||
@@ -259,12 +251,10 @@ class AccountController extends Controller
|
||||
'virtualBalance' => round($request->input('virtualBalance'), 2),
|
||||
'openingBalance' => round($request->input('openingBalance'), 2),
|
||||
'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')),
|
||||
'openingBalanceCurrency' => intval($request->input('balance_currency_id')),
|
||||
'openingBalanceCurrency' => intval($request->input('amount_currency_id_openingBalance')),
|
||||
'ccType' => $request->input('ccType'),
|
||||
'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'),
|
||||
];
|
||||
|
||||
|
||||
$repository->update($account, $accountData);
|
||||
|
||||
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
||||
@@ -282,4 +272,20 @@ class AccountController extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, $entryId)
|
||||
{
|
||||
if (isset($array[$entryId])) {
|
||||
return $array[$entryId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
|
||||
use Crypt;
|
||||
use File;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
@@ -25,7 +24,7 @@ class AttachmentController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -34,26 +33,6 @@ class AttachmentController extends Controller
|
||||
View::share('title', trans('firefly.attachments'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(Attachment $attachment)
|
||||
{
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$subTitle = trans('firefly.edit_attachment', ['name' => $attachment->filename]);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('attachments.edit.fromUpdate') !== true) {
|
||||
Session::put('attachments.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('attachments.edit.fromUpdate');
|
||||
|
||||
return view('attachments.edit', compact('attachment', 'subTitleIcon', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
@@ -90,7 +69,10 @@ class AttachmentController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
* @param AttachmentHelperInterface $helper
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function download(Attachment $attachment, AttachmentHelperInterface $helper)
|
||||
{
|
||||
@@ -100,23 +82,42 @@ class AttachmentController extends Controller
|
||||
|
||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename=' . $quoted);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . $attachment->size);
|
||||
|
||||
echo Crypt::decrypt(file_get_contents($file));
|
||||
return response(Crypt::decrypt(file_get_contents($file)), 200)
|
||||
->header('Content-Description', 'File Transfer')
|
||||
->header('Content-Type', 'application/octet-stream')
|
||||
->header('Content-Disposition', 'attachment; filename=' . $quoted)
|
||||
->header('Content-Transfer-Encoding', 'binary')
|
||||
->header('Connection', 'Keep-Alive')
|
||||
->header('Expires', '0')
|
||||
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
||||
->header('Pragma', 'public')
|
||||
->header('Content-Length', $attachment->size);
|
||||
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(Attachment $attachment)
|
||||
{
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$subTitle = trans('firefly.edit_attachment', ['name' => $attachment->filename]);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (Session::get('attachments.edit.fromUpdate') !== true) {
|
||||
Session::put('attachments.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('attachments.edit.fromUpdate');
|
||||
|
||||
return view('attachments.edit', compact('attachment', 'subTitleIcon', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php namespace FireflyIII\Http\Controllers\Auth;
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use Config;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\User;
|
||||
@@ -9,13 +10,14 @@ use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Request as Rq;
|
||||
use Session;
|
||||
use Twig;
|
||||
use Validator;
|
||||
|
||||
|
||||
/**
|
||||
* Class AuthController
|
||||
*
|
||||
@@ -26,27 +28,20 @@ class AuthController extends Controller
|
||||
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
|
||||
|
||||
/**
|
||||
* Log the user out of the application.
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @var string
|
||||
*/
|
||||
public function getLogout()
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
return redirect('/auth/login');
|
||||
}
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Show the application registration form.
|
||||
* Create a new authentication controller instance.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getRegister()
|
||||
public function __construct()
|
||||
{
|
||||
$host = Rq::getHttpHost();
|
||||
|
||||
return view('auth.register', compact('host'));
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,17 +51,9 @@ class AuthController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postLogin(Request $request)
|
||||
public function login(Request $request)
|
||||
{
|
||||
$this->validate(
|
||||
$request, [
|
||||
$this->loginUsername() => 'required', 'password' => 'required',
|
||||
]
|
||||
);
|
||||
|
||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||
// the login attempts for this application. We'll key this by the username and
|
||||
// the IP address of the client making these requests into this application.
|
||||
$this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required',]);
|
||||
$throttles = $this->isUsingThrottlesLoginsTrait();
|
||||
|
||||
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
|
||||
@@ -76,79 +63,40 @@ class AuthController extends Controller
|
||||
$credentials = $this->getCredentials($request);
|
||||
$credentials['blocked'] = 0; // most not be blocked.
|
||||
|
||||
if (Auth::attempt($credentials, $request->has('remember'))) {
|
||||
if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
|
||||
|
||||
return $this->handleUserWasAuthenticated($request, $throttles);
|
||||
}
|
||||
|
||||
// default error message:
|
||||
$message = $this->getFailedLoginMessage();
|
||||
|
||||
// try to find a blocked user with this email address.
|
||||
// check if user is blocked:
|
||||
$message = '';
|
||||
/** @var User $foundUser */
|
||||
$foundUser = User::where('email', $credentials['email'])->where('blocked', 1)->first();
|
||||
if (!is_null($foundUser)) {
|
||||
// if it exists, show message:
|
||||
$code = $foundUser->blocked_code;
|
||||
|
||||
if (strlen($code) == 0) {
|
||||
$code = 'general_blocked';
|
||||
}
|
||||
$message = trans('firefly.' . $code . '_error', ['email' => $credentials['email']]);
|
||||
}
|
||||
|
||||
// try
|
||||
|
||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||
// to login and redirect the user back to the login form. Of course, when this
|
||||
// user surpasses their maximum number of attempts they will get locked out.
|
||||
if ($throttles) {
|
||||
$this->incrementLoginAttempts($request);
|
||||
}
|
||||
|
||||
return redirect($this->loginPath())
|
||||
->withInput($request->only($this->loginUsername(), 'remember'))
|
||||
->withErrors(
|
||||
[
|
||||
$this->loginUsername() => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public $redirectTo = '/';
|
||||
|
||||
/**
|
||||
* Create a new authentication controller instance.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware('guest', ['except' => 'getLogout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application login form.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*/
|
||||
public function getLogin()
|
||||
{
|
||||
return Twig::render('auth.login');
|
||||
return $this->sendFailedLoginResponse($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postRegister(Request $request)
|
||||
public function register(Request $request)
|
||||
{
|
||||
$validator = $this->validator($request->all());
|
||||
|
||||
@@ -156,23 +104,21 @@ class AuthController extends Controller
|
||||
$this->throwValidationException(
|
||||
$request, $validator
|
||||
);
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
// is user email domain blocked?
|
||||
if ($this->isBlockedDomain($data['email'])) {
|
||||
$validator->getMessageBag()->add('email', trans('validation.invalid_domain'));
|
||||
$validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain'));
|
||||
$this->throwValidationException(
|
||||
$request, $validator
|
||||
);
|
||||
}
|
||||
|
||||
Auth::login($this->create($data));
|
||||
|
||||
Auth::login($this->create($request->all()));
|
||||
|
||||
// get the email address
|
||||
if (Auth::user() instanceof User) {
|
||||
@@ -207,8 +153,37 @@ class AuthController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
abort(500, 'Not a user!');
|
||||
|
||||
return redirect('/');
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application registration form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
$host = Rq::getHttpHost();
|
||||
|
||||
return view('auth.register', compact('host'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create(
|
||||
[
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +191,7 @@ class AuthController extends Controller
|
||||
*/
|
||||
protected function getBlockedDomains()
|
||||
{
|
||||
$set = Config::get('mail.blocked_domains');
|
||||
$set = explode(',', env('BLOCKED_DOMAINS', ''));
|
||||
$domains = [];
|
||||
foreach ($set as $entry) {
|
||||
$domain = trim($entry);
|
||||
@@ -228,6 +203,29 @@ class AuthController extends Controller
|
||||
return $domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login message.
|
||||
*
|
||||
* @param $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFailedLoginMessage($message)
|
||||
{
|
||||
if (strlen($message) > 0) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
return Lang::has('auth.failed')
|
||||
? Lang::get('auth.failed')
|
||||
: 'These credentials do not match our records.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBlockedDomain($email)
|
||||
{
|
||||
$parts = explode('@', $email);
|
||||
@@ -240,6 +238,26 @@ class AuthController extends Controller
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @param $message
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request, $message)
|
||||
{
|
||||
return redirect()->back()
|
||||
->withInput($request->only($this->loginUsername(), 'remember'))
|
||||
->withErrors(
|
||||
[
|
||||
$this->loginUsername() => $this->getFailedLoginMessage($message),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
@@ -247,7 +265,7 @@ class AuthController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
public function validator(array $data)
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make(
|
||||
$data, [
|
||||
@@ -256,21 +274,4 @@ class AuthController extends Controller
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
return User::create(
|
||||
[
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php namespace FireflyIII\Http\Controllers\Auth;
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\User;
|
||||
@@ -7,15 +9,14 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
|
||||
|
||||
/**
|
||||
* Class PasswordController
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Controllers\Auth
|
||||
*/
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
@@ -29,14 +30,9 @@ class PasswordController extends Controller
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
|
||||
protected $redirectPath = '/';
|
||||
|
||||
/**
|
||||
* Create a new password controller instance.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -52,7 +48,7 @@ class PasswordController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postEmail(Request $request)
|
||||
public function sendResetLinkEmail(Request $request)
|
||||
{
|
||||
$this->validate($request, ['email' => 'required|email']);
|
||||
|
||||
@@ -70,12 +66,12 @@ class PasswordController extends Controller
|
||||
|
||||
switch ($response) {
|
||||
case Password::RESET_LINK_SENT:
|
||||
return redirect()->back()->with('status', trans($response));
|
||||
return $this->getSendResetLinkEmailSuccessResponse($response);
|
||||
|
||||
case Password::INVALID_USER:
|
||||
case 'passwords.blocked':
|
||||
return redirect()->back()->withErrors(['email' => trans($response)]);
|
||||
|
||||
default:
|
||||
return $this->getSendResetLinkEmailFailureResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,8 +6,9 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
@@ -20,7 +21,6 @@ use View;
|
||||
* Class BudgetController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
* @SuppressWarnings(PHPMD.TooManyMethods)
|
||||
*/
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
@@ -68,7 +68,7 @@ class BudgetController extends Controller
|
||||
Session::forget('budgets.create.fromStore');
|
||||
Session::flash('gaEventCategory', 'budgets');
|
||||
Session::flash('gaEventAction', 'create');
|
||||
$subTitle = trans('firefly.create_new_budget');
|
||||
$subTitle = (string)trans('firefly.create_new_budget');
|
||||
|
||||
return view('budgets.create', compact('subTitle'));
|
||||
}
|
||||
@@ -134,9 +134,11 @@ class BudgetController extends Controller
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @param ARI $accountRepository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
|
||||
public function index(BudgetRepositoryInterface $repository, ARI $accountRepository)
|
||||
{
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$inactive = $repository->getInactiveBudgets();
|
||||
@@ -230,13 +232,26 @@ class BudgetController extends Controller
|
||||
$journals = $repository->getJournals($budget, $repetition);
|
||||
|
||||
if (is_null($repetition->id)) {
|
||||
$limits = $repository->getBudgetLimits($budget);
|
||||
$start = $repository->firstActivity($budget);
|
||||
$end = new Carbon;
|
||||
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
|
||||
$subTitle = e($budget->name);
|
||||
} else {
|
||||
$limits = [$repetition->budgetLimit];
|
||||
$start = $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
$set = new Collection([$repetition]);
|
||||
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);
|
||||
}
|
||||
|
||||
$spentArray = $repository->spentPerDay($budget, $start, $end);
|
||||
$limits = new Collection();
|
||||
|
||||
/** @var LimitRepetition $entry */
|
||||
foreach ($set as $entry) {
|
||||
$entry->spent = $this->getSumOfRange($entry->startdate, $entry->enddate, $spentArray);
|
||||
$limits->push($entry);
|
||||
}
|
||||
|
||||
$journals->setPath('/budgets/show/' . $budget->id);
|
||||
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
|
||||
|
@@ -4,7 +4,8 @@ use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface as SCRI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -68,12 +69,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(CategoryRepositoryInterface $repository, Category $category)
|
||||
public function destroy(SCRI $repository, Category $category)
|
||||
{
|
||||
|
||||
$name = $category->name;
|
||||
@@ -107,17 +108,18 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param CRI $repository
|
||||
* @param SCRI $singleRepository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(CategoryRepositoryInterface $repository)
|
||||
public function index(CRI $repository, SCRI $singleRepository)
|
||||
{
|
||||
$categories = $repository->getCategories();
|
||||
$categories = $repository->listCategories();
|
||||
|
||||
$categories->each(
|
||||
function (Category $category) use ($repository) {
|
||||
$category->lastActivity = $repository->getLatestActivity($category);
|
||||
function (Category $category) use ($singleRepository) {
|
||||
$category->lastActivity = $singleRepository->getLatestActivity($category);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -125,15 +127,15 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function noCategory(CategoryRepositoryInterface $repository)
|
||||
public function noCategory(CRI $repository)
|
||||
{
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->startOfMonth());
|
||||
$list = $repository->getWithoutCategory($start, $end);
|
||||
$list = $repository->listNoCategory($start, $end);
|
||||
$subTitle = trans(
|
||||
'firefly.without_category_between',
|
||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||
@@ -143,37 +145,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showWithDate(CategoryRepositoryInterface $repository, Category $category, $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $category->name;
|
||||
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
|
||||
$set = $repository->getJournalsInRange($category, $page, $start, $end);
|
||||
$count = $repository->countJournalsInRange($category, $start, $end);
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$journals->setPath('categories/show/' . $category->id . '/' . $date);
|
||||
|
||||
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(CategoryRepositoryInterface $repository, Category $category)
|
||||
public function show(SCRI $repository, Category $category)
|
||||
{
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
@@ -198,6 +175,12 @@ class CategoryController extends Controller
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category-show');
|
||||
$cache->addProperty($category->id);
|
||||
|
||||
// get all spent and earned data:
|
||||
// get amount earned in period, grouped by day.
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
|
||||
if ($cache->has()) {
|
||||
$entries = $cache->get();
|
||||
} else {
|
||||
@@ -206,9 +189,9 @@ class CategoryController extends Controller
|
||||
$end = Navigation::startOfPeriod($end, $range);
|
||||
$currentEnd = Navigation::endOfPeriod($end, $range);
|
||||
|
||||
// here do something.
|
||||
$spent = $repository->spentInPeriod($category, $end, $currentEnd);
|
||||
$earned = $repository->earnedInPeriod($category, $end, $currentEnd);
|
||||
// get data from spentArray:
|
||||
$spent = $this->getSumOfRange($end, $currentEnd, $spentArray);
|
||||
$earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
$entries->push([$dateStr, $dateName, $spent, $earned]);
|
||||
@@ -223,12 +206,39 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryFormRequest $request
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param $date
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showWithDate(SCRI $repository, Category $category, $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $category->name;
|
||||
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
|
||||
$set = $repository->getJournalsInRange($category, $page, $start, $end);
|
||||
$count = $repository->countJournalsInRange($category, $start, $end);
|
||||
$journals = new LengthAwarePaginator($set, $count, 50, $page);
|
||||
$journals->setPath('categories/show/' . $category->id . '/' . $date);
|
||||
|
||||
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryFormRequest $request
|
||||
* @param SCRI $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(CategoryFormRequest $request, CategoryRepositoryInterface $repository)
|
||||
public function store(CategoryFormRequest $request, SCRI $repository)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
@@ -250,13 +260,13 @@ class CategoryController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* @param CategoryFormRequest $request
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
* @param CategoryFormRequest $request
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category)
|
||||
public function update(CategoryFormRequest $request, SCRI $repository, Category $category)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
|
@@ -5,7 +5,7 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
@@ -20,7 +20,7 @@ use Session;
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Account\AccountChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -30,22 +30,21 @@ class AccountController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Account\AccountChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the balances for a given set of dates and accounts.
|
||||
*
|
||||
* TODO fix parameters.
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function report($report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function report($reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
@@ -54,13 +53,14 @@ class AccountController extends Controller
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('accounts');
|
||||
$cache->addProperty('default');
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// make chart:
|
||||
$data = $this->generator->all($accounts, $start, $end);
|
||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
@@ -69,11 +69,11 @@ class AccountController extends Controller
|
||||
/**
|
||||
* Shows the balances for all the user's expense accounts.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param ARI $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function expenseAccounts(AccountRepositoryInterface $repository)
|
||||
public function expenseAccounts(ARI $repository)
|
||||
{
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = clone Session::get('end', Carbon::now()->endOfMonth());
|
||||
@@ -99,11 +99,11 @@ class AccountController extends Controller
|
||||
/**
|
||||
* Shows the balances for all the user's frontpage accounts.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param ARI $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function frontpage(AccountRepositoryInterface $repository)
|
||||
public function frontpage(ARI $repository)
|
||||
{
|
||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
|
@@ -19,7 +19,7 @@ use Session;
|
||||
class BillController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Bill\BillChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -29,11 +29,11 @@ class BillController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Bill\BillChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows all bills and whether or not theyve been paid this month (pie chart).
|
||||
* Shows all bills and whether or not they've been paid this month (pie chart).
|
||||
*
|
||||
* @param BillRepositoryInterface $repository
|
||||
*
|
||||
@@ -41,28 +41,24 @@ class BillController extends Controller
|
||||
*/
|
||||
public function frontpage(BillRepositoryInterface $repository)
|
||||
{
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$cache = new CacheProperties(); // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('bills');
|
||||
$cache->addProperty('frontpage');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||
$creditCardDue = $repository->getCreditCardBill($start, $end);
|
||||
|
||||
if ($creditCardDue < 0) {
|
||||
// expenses are negative (bill not yet paid),
|
||||
$creditCardDue = bcmul($creditCardDue, '-1');
|
||||
$unpaid = bcadd($unpaid, $creditCardDue);
|
||||
} else {
|
||||
// if more than zero, the bill has been paid: (transfer = positive).
|
||||
// amount must be negative to be added to $paid:
|
||||
$paid = bcadd($paid, $creditCardDue);
|
||||
}
|
||||
|
||||
$set = $repository->getBillsForChart($start, $end);
|
||||
|
||||
// optionally expand this set with credit card data
|
||||
$set = $repository->getCreditCardInfoForChart($set, $start, $end);
|
||||
$paid = $set->get('paid');
|
||||
$unpaid = $set->get('unpaid');
|
||||
|
||||
|
||||
// build chart:
|
||||
$data = $this->generator->frontpage($paid, $unpaid);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -23,7 +23,7 @@ use Session;
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Budget\BudgetChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -33,22 +33,27 @@ class BudgetController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Budget\BudgetChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param $report_type
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function multiYear(BudgetRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
|
||||
public function multiYear(BudgetRepositoryInterface $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
@@ -59,41 +64,43 @@ class BudgetController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* budget
|
||||
* year:
|
||||
* spent: x
|
||||
* budgeted: x
|
||||
* year
|
||||
* spent: x
|
||||
* budgeted: x
|
||||
/*
|
||||
* Get the budgeted amounts for each budgets in each year.
|
||||
*/
|
||||
$budgetedSet = $repository->getBudgetedPerYear($budgets, $start, $end);
|
||||
$budgetedArray = [];
|
||||
/** @var Budget $entry */
|
||||
foreach ($budgetedSet as $entry) {
|
||||
$budgetedArray[$entry->id][$entry->dateFormatted] = $entry->budgeted;
|
||||
}
|
||||
|
||||
$set = $repository->getBudgetsAndExpensesPerYear($budgets, $accounts, $start, $end);
|
||||
$entries = new Collection;
|
||||
// go by budget, not by year.
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$entry = ['name' => '', 'spent' => [], 'budgeted' => []];
|
||||
|
||||
$entry = ['name' => '', 'spent' => [], 'budgeted' => []];
|
||||
$id = $budget->id;
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart < $end) {
|
||||
// fix the date:
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd->endOfYear();
|
||||
|
||||
// get data:
|
||||
if (is_null($budget->id)) {
|
||||
$name = trans('firefly.noBudget');
|
||||
$sum = $repository->getWithoutBudgetSum($currentStart, $currentEnd);
|
||||
$budgeted = 0;
|
||||
} else {
|
||||
$name = $budget->name;
|
||||
$sum = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
|
||||
$budgeted = $repository->getBudgetLimitRepetitions($budget, $currentStart, $currentEnd)->sum('amount');
|
||||
// save to array:
|
||||
$year = $currentStart->year;
|
||||
$entry['name'] = $budget->name;
|
||||
$spent = 0;
|
||||
$budgeted = 0;
|
||||
if (isset($set[$id]['entries'][$year])) {
|
||||
$spent = $set[$id]['entries'][$year] * -1;
|
||||
}
|
||||
|
||||
// save to array:
|
||||
$year = $currentStart->year;
|
||||
$entry['name'] = $name;
|
||||
$entry['spent'][$year] = ($sum * -1);
|
||||
if (isset($budgetedArray[$id][$year])) {
|
||||
$budgeted = round($budgetedArray[$id][$year], 2);
|
||||
}
|
||||
|
||||
$entry['spent'][$year] = $spent;
|
||||
$entry['budgeted'][$year] = $budgeted;
|
||||
|
||||
// jump to next year.
|
||||
@@ -104,6 +111,7 @@ class BudgetController extends Controller
|
||||
}
|
||||
// generate chart with data:
|
||||
$data = $this->generator->multiYear($entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
@@ -115,18 +123,13 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budget(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository, Budget $budget)
|
||||
public function budget(BudgetRepositoryInterface $repository, Budget $budget)
|
||||
{
|
||||
|
||||
// dates and times
|
||||
$first = $repository->getFirstBudgetLimitDate($budget);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$last = Session::get('end', new Carbon);
|
||||
$final = clone $last;
|
||||
$final->addYears(2);
|
||||
$last = Navigation::endOfX($last, $range, $final);
|
||||
$accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
|
||||
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
@@ -134,18 +137,29 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($last);
|
||||
$cache->addProperty('budget');
|
||||
if ($cache->has()) {
|
||||
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$final = clone $last;
|
||||
$final->addYears(2);
|
||||
$last = Navigation::endOfX($last, $range, $final);
|
||||
$entries = new Collection;
|
||||
// get all expenses:
|
||||
$set = $repository->getExpensesPerMonth($budget, $first, $last);
|
||||
|
||||
while ($first < $last) {
|
||||
$end = Navigation::addPeriod($first, $range, 0);
|
||||
$end->subDay();
|
||||
$chartDate = clone $end;
|
||||
$chartDate->startOfMonth();
|
||||
$spent = $repository->balanceInPeriod($budget, $first, $end, $accounts) * -1;
|
||||
$entries->push([$chartDate, $spent]);
|
||||
$monthFormatted = $first->format('Y-m');
|
||||
|
||||
$filtered = $set->filter(
|
||||
function (Budget $obj) use ($monthFormatted) {
|
||||
return $obj->dateFormatted == $monthFormatted;
|
||||
}
|
||||
);
|
||||
$spent = is_null($filtered->first()) ? '0' : $filtered->first()->monthlyAmount;
|
||||
|
||||
$entries->push([$first, round(($spent * -1), 2)]);
|
||||
|
||||
$first = Navigation::addPeriod($first, $range, 0);
|
||||
}
|
||||
|
||||
@@ -182,15 +196,24 @@ class BudgetController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$set = $repository->getExpensesPerDay($budget, $start, $end);
|
||||
$entries = new Collection;
|
||||
$amount = $repetition->amount;
|
||||
|
||||
// get sum (har har)!
|
||||
while ($start <= $end) {
|
||||
$formatted = $start->format('Y-m-d');
|
||||
$filtered = $set->filter(
|
||||
function (Budget $obj) use ($formatted) {
|
||||
return $obj->date == $formatted;
|
||||
}
|
||||
);
|
||||
$sum = is_null($filtered->first()) ? '0' : $filtered->first()->dailyAmount;
|
||||
|
||||
/*
|
||||
* Sum of expenses on this day:
|
||||
*/
|
||||
$sum = $repository->expensesOnDay($budget, $start);
|
||||
$amount = bcadd($amount, $sum);
|
||||
$amount = round(bcadd($amount, $sum), 2);
|
||||
$entries->push([clone $start, $amount]);
|
||||
$start->addDay();
|
||||
}
|
||||
@@ -207,15 +230,14 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
*
|
||||
* @param ARI $accountRepository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function frontpage(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
|
||||
public function frontpage(BudgetRepositoryInterface $repository, ARI $accountRepository)
|
||||
{
|
||||
$budgets = $repository->getBudgets();
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$allEntries = new Collection;
|
||||
$accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
@@ -227,63 +249,66 @@ class BudgetController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$budgets = $repository->getBudgetsAndLimitsInRange($start, $end);
|
||||
$allEntries = new Collection;
|
||||
$accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
|
||||
|
||||
|
||||
bcscale(2);
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
|
||||
if ($repetitions->count() == 0) {
|
||||
$expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts) * -1;
|
||||
$allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]);
|
||||
continue;
|
||||
// we already have amount, startdate and enddate.
|
||||
// if this "is" a limit repetition (as opposed to a budget without one entirely)
|
||||
// depends on whether startdate and enddate are null.
|
||||
$name = $budget->name;
|
||||
if (is_null($budget->startdate) && is_null($budget->enddate)) {
|
||||
$currentStart = clone $start;
|
||||
$currentEnd = clone $end;
|
||||
$expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
|
||||
$amount = 0;
|
||||
$left = 0;
|
||||
$spent = $expenses;
|
||||
$overspent = 0;
|
||||
} else {
|
||||
$currentStart = clone $budget->startdate;
|
||||
$currentEnd = clone $budget->enddate;
|
||||
$expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
|
||||
$amount = $budget->amount;
|
||||
// smaller than 1 means spent MORE than budget allows.
|
||||
$left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? 0 : bcadd($budget->amount, $expenses);
|
||||
$spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? ($amount * -1) : $expenses;
|
||||
$overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : 0;
|
||||
}
|
||||
/** @var LimitRepetition $repetition */
|
||||
foreach ($repetitions as $repetition) {
|
||||
$expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, $accounts) * -1;
|
||||
// $left can be less than zero.
|
||||
// $overspent can be more than zero ( = overspending)
|
||||
|
||||
$left = max(bcsub($repetition->amount, $expenses), 0); // limited at zero.
|
||||
$overspent = max(bcsub($expenses, $repetition->amount), 0); // limited at zero.
|
||||
$name = $budget->name;
|
||||
|
||||
// $spent is maxed to the repetition amount:
|
||||
$spent = $expenses > $repetition->amount ? $repetition->amount : $expenses;
|
||||
|
||||
|
||||
$allEntries->push([$name, $left, $spent, $overspent, $repetition->amount, $expenses]);
|
||||
}
|
||||
$allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]);
|
||||
}
|
||||
|
||||
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end) * -1;
|
||||
$noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end);
|
||||
$allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses, 0, 0]);
|
||||
|
||||
$data = $this->generator->frontpage($allEntries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a yearly overview for a budget.
|
||||
*
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param $year
|
||||
* @param bool $shared
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function year(BudgetRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function year(BudgetRepositoryInterface $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$allBudgets = $repository->getBudgets();
|
||||
$budgets = new Collection;
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('year');
|
||||
@@ -291,26 +316,30 @@ class BudgetController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// filter empty budgets:
|
||||
foreach ($allBudgets as $budget) {
|
||||
$spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
|
||||
if ($spent != 0) {
|
||||
$budgets->push($budget);
|
||||
}
|
||||
}
|
||||
$budgetInformation = $repository->getBudgetsAndExpensesPerMonth($accounts, $start, $end);
|
||||
$budgets = new Collection;
|
||||
$entries = new Collection;
|
||||
|
||||
$entries = new Collection;
|
||||
/** @var array $row */
|
||||
foreach ($budgetInformation as $row) {
|
||||
$budgets->push($row['budget']);
|
||||
}
|
||||
|
||||
while ($start < $end) {
|
||||
// month is the current end of the period:
|
||||
$month = clone $start;
|
||||
$month->endOfMonth();
|
||||
$row = [clone $start];
|
||||
$row = [clone $start];
|
||||
$dateFormatted = $start->format('Y-m');
|
||||
|
||||
// each budget, fill the row:
|
||||
foreach ($budgets as $budget) {
|
||||
$spent = $repository->balanceInPeriod($budget, $start, $month, $accounts);
|
||||
$row[] = $spent * -1;
|
||||
// each budget, check if there is an entry for this month:
|
||||
/** @var array $row */
|
||||
foreach ($budgetInformation as $budgetRow) {
|
||||
$spent = 0; // nothing spent.
|
||||
if (isset($budgetRow['entries'][$dateFormatted])) {
|
||||
$spent = $budgetRow['entries'][$dateFormatted] * -1; // to fit array
|
||||
}
|
||||
$row[] = $spent;
|
||||
}
|
||||
$entries->push($row);
|
||||
$start->endOfMonth()->addDay();
|
||||
|
@@ -6,13 +6,15 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface as SCRI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use Session;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class CategoryController
|
||||
@@ -21,7 +23,7 @@ use Session;
|
||||
*/
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/** @var \FireflyIII\Generator\Chart\Category\CategoryChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -31,19 +33,21 @@ class CategoryController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Category\CategoryChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show an overview for a category for all time, per month/week/year.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function all(CategoryRepositoryInterface $repository, Category $category)
|
||||
public function all(SCRI $repository, Category $category)
|
||||
{
|
||||
// oldest transaction in category:
|
||||
$start = $repository->getFirstActivityDate($category);
|
||||
@@ -51,8 +55,6 @@ class CategoryController extends Controller
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = new Carbon;
|
||||
$entries = new Collection;
|
||||
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
@@ -62,36 +64,116 @@ class CategoryController extends Controller
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
|
||||
while ($start <= $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||
$spent = $repository->spentInPeriod($category, $start, $currentEnd);
|
||||
$earned = $repository->earnedInPeriod($category, $start, $currentEnd);
|
||||
$spent = $this->getSumOfRange($start, $currentEnd, $spentArray);
|
||||
$earned = $this->getSumOfRange($start, $currentEnd, $earnedArray);
|
||||
$date = Navigation::periodShow($start, $range);
|
||||
$entries->push([clone $start, $date, $spent, $earned]);
|
||||
$start = Navigation::addPeriod($start, $range, 0);
|
||||
}
|
||||
// limit the set to the last 40:
|
||||
$entries = $entries->reverse();
|
||||
$entries = $entries->slice(0, 48);
|
||||
$entries = $entries->reverse();
|
||||
|
||||
$data = $this->generator->all($entries);
|
||||
$data = $this->generator->all($entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function currentPeriod(SCRI $repository, Category $category)
|
||||
{
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$data = $this->makePeriodChart($repository, $category, $start, $end);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a chart of what has been earned in this period in each category
|
||||
* grouped by month.
|
||||
*
|
||||
* @param CRI $repository
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // cant avoid it.
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // it's long but ok.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function earnedInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('earned-in-period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$set = $repository->earnedForAccountsPerMonth($accounts, $start, $end);
|
||||
$categories = $set->unique('id')->sortBy(
|
||||
function (Category $category) {
|
||||
return $category->name;
|
||||
}
|
||||
);
|
||||
$entries = new Collection;
|
||||
|
||||
while ($start < $end) { // filter the set:
|
||||
$row = [clone $start];
|
||||
$currentSet = $set->filter( // get possibly relevant entries from the big $set
|
||||
function (Category $category) use ($start) {
|
||||
return $category->dateFormatted == $start->format('Y-m');
|
||||
}
|
||||
);
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) { // check for each category if its in the current set.
|
||||
$entry = $currentSet->filter( // if its in there, use the value.
|
||||
function (Category $cat) use ($category) {
|
||||
return ($cat->id == $category->id);
|
||||
}
|
||||
)->first();
|
||||
if (!is_null($entry)) {
|
||||
$row[] = round($entry->earned, 2);
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
}
|
||||
$entries->push($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
$data = $this->generator->earnedInPeriod($categories, $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show this month's category overview.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function frontpage(CategoryRepositoryInterface $repository)
|
||||
public function frontpage(CRI $repository)
|
||||
{
|
||||
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
@@ -107,40 +189,41 @@ class CategoryController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$array = $repository->getCategoriesAndExpenses($start, $end);
|
||||
// sort by callback:
|
||||
uasort(
|
||||
$array,
|
||||
function ($left, $right) {
|
||||
if ($left['sum'] == $right['sum']) {
|
||||
return 0;
|
||||
}
|
||||
// get data for categories (and "no category"):
|
||||
$set = $repository->spentForAccountsPerMonth(new Collection, $start, $end);
|
||||
$outside = $repository->sumSpentNoCategory(new Collection, $start, $end);
|
||||
|
||||
return ($left['sum'] < $right['sum']) ? -1 : 1;
|
||||
}
|
||||
);
|
||||
$set = new Collection($array);
|
||||
// this is a "fake" entry for the "no category" entry.
|
||||
$entry = new stdClass();
|
||||
$entry->name = trans('firefly.no_category');
|
||||
$entry->spent = $outside;
|
||||
$set->push($entry);
|
||||
|
||||
$set = $set->sortBy('spent');
|
||||
$data = $this->generator->frontpage($set);
|
||||
$cache->store($data);
|
||||
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param $report_type
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function multiYear(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
|
||||
public function multiYear($reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
|
||||
{
|
||||
/** @var CRI $repository */
|
||||
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
@@ -151,17 +234,9 @@ class CategoryController extends Controller
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* category
|
||||
* year:
|
||||
* spent: x
|
||||
* earned: x
|
||||
* year
|
||||
* spent: x
|
||||
* earned: x
|
||||
*/
|
||||
$entries = new Collection;
|
||||
// go by budget, not by year.
|
||||
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$entry = ['name' => '', 'spent' => [], 'earned' => []];
|
||||
@@ -169,22 +244,35 @@ class CategoryController extends Controller
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart < $end) {
|
||||
// fix the date:
|
||||
$year = $currentStart->year;
|
||||
$currentEnd = clone $currentStart;
|
||||
$currentEnd->endOfYear();
|
||||
|
||||
|
||||
// get data:
|
||||
if (is_null($category->id)) {
|
||||
$name = trans('firefly.noCategory');
|
||||
$spent = $repository->spentNoCategoryForAccounts($accounts, $currentStart, $currentEnd);
|
||||
$earned = $repository->earnedNoCategoryForAccounts($accounts, $currentStart, $currentEnd);
|
||||
$spent = $repository->sumSpentNoCategory($accounts, $currentStart, $currentEnd);
|
||||
$earned = $repository->sumEarnedNoCategory($accounts, $currentStart, $currentEnd);
|
||||
} else {
|
||||
// get from set:
|
||||
$entrySpent = $set->filter(
|
||||
function (Category $cat) use ($year, $category) {
|
||||
return ($cat->type == 'Withdrawal' && $cat->dateFormatted == $year && $cat->id == $category->id);
|
||||
}
|
||||
)->first();
|
||||
$entryEarned = $set->filter(
|
||||
function (Category $cat) use ($year, $category) {
|
||||
return ($cat->type == 'Deposit' && $cat->dateFormatted == $year && $cat->id == $category->id);
|
||||
}
|
||||
)->first();
|
||||
|
||||
$name = $category->name;
|
||||
$spent = $repository->spentInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
|
||||
$earned = $repository->earnedInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
|
||||
$spent = !is_null($entrySpent) ? $entrySpent->sum : 0;
|
||||
$earned = !is_null($entryEarned) ? $entryEarned->sum : 0;
|
||||
}
|
||||
|
||||
// save to array:
|
||||
$year = $currentStart->year;
|
||||
$entry['name'] = $name;
|
||||
$entry['spent'][$year] = ($spent * -1);
|
||||
$entry['earned'][$year] = $earned;
|
||||
@@ -199,38 +287,127 @@ class CategoryController extends Controller
|
||||
$data = $this->generator->multiYear($entries);
|
||||
$cache->store($data);
|
||||
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param $date
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function currentPeriod(CategoryRepositoryInterface $repository, Category $category)
|
||||
public function specificPeriod(SCRI $repository, Category $category, $date)
|
||||
{
|
||||
$start = clone Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$data = $this->makePeriodChart($repository, $category, $start, $end);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a chart of what has been spent in this period in each category
|
||||
* grouped by month.
|
||||
*
|
||||
* @param CRI $repository
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
|
||||
* @SuppressWarnings(PHPMD.ExcessuveMethodLength) // need the length
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function spentInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('spent-in-period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$set = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
||||
$categories = $set->unique('id')->sortBy(
|
||||
function (Category $category) {
|
||||
return $category->name;
|
||||
}
|
||||
);
|
||||
$entries = new Collection;
|
||||
|
||||
while ($start < $end) { // filter the set:
|
||||
$row = [clone $start];
|
||||
$currentSet = $set->filter(// get possibly relevant entries from the big $set
|
||||
function (Category $category) use ($start) {
|
||||
return $category->dateFormatted == $start->format('Y-m');
|
||||
}
|
||||
);
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {// check for each category if its in the current set.
|
||||
$entry = $currentSet->filter(// if its in there, use the value.
|
||||
function (Category $cat) use ($category) {
|
||||
return ($cat->id == $category->id);
|
||||
}
|
||||
)->first();
|
||||
if (!is_null($entry)) {
|
||||
$row[] = round(($entry->spent * -1), 2);
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$entries->push($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
$data = $this->generator->spentInPeriod($categories, $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makePeriodChart(SCRI $repository, Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('currentPeriod');
|
||||
$cache->addProperty('specific-period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
$entries = new Collection;
|
||||
|
||||
// get amount earned in period, grouped by day.
|
||||
// get amount spent in period, grouped by day.
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
|
||||
while ($start <= $end) {
|
||||
$spent = $repository->spentOnDaySum($category, $start);
|
||||
$earned = $repository->earnedOnDaySum($category, $start);
|
||||
$str = $start->format('Y-m-d');
|
||||
$spent = isset($spentArray[$str]) ? $spentArray[$str] : 0;
|
||||
$earned = isset($earnedArray[$str]) ? $earnedArray[$str] : 0;
|
||||
$date = Navigation::periodShow($start, '1D');
|
||||
$entries->push([clone $start, $date, $spent, $earned]);
|
||||
$start->addDay();
|
||||
@@ -239,303 +416,8 @@ class CategoryController extends Controller
|
||||
$data = $this->generator->period($entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($category->id);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('specificPeriod');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
$entries = new Collection;
|
||||
|
||||
|
||||
while ($start <= $end) {
|
||||
$spent = $repository->spentOnDaySum($category, $start);
|
||||
$earned = $repository->earnedOnDaySum($category, $start);
|
||||
$theDate = Navigation::periodShow($start, '1D');
|
||||
$entries->push([clone $start, $theDate, $spent, $earned]);
|
||||
$start->addDay();
|
||||
}
|
||||
|
||||
$data = $this->generator->period($entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This chart will only show expenses.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param $report_type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function spentInYear(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('spent-in-year');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$allCategories = $repository->getCategories();
|
||||
$entries = new Collection;
|
||||
$categories = $allCategories->filter(
|
||||
function (Category $category) use ($repository, $start, $end, $accounts) {
|
||||
$spent = $repository->balanceInPeriod($category, $start, $end, $accounts);
|
||||
if ($spent < 0) {
|
||||
return $category;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
while ($start < $end) {
|
||||
$month = clone $start; // month is the current end of the period
|
||||
$month->endOfMonth();
|
||||
$row = [clone $start]; // make a row:
|
||||
|
||||
foreach ($categories as $category) { // each budget, fill the row
|
||||
$spent = $repository->balanceInPeriod($category, $start, $month, $accounts);
|
||||
if ($spent < 0) {
|
||||
$row[] = $spent * -1;
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
}
|
||||
$entries->push($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
$data = $this->generator->spentInYear($categories, $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a chart of what has been earned in this period in each category
|
||||
* grouped by month.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param $report_type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function earnedInPeriod(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$original = clone $start;
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('earned-in-period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
$categories = new Collection;
|
||||
$sets = new Collection;
|
||||
$entries = new Collection;
|
||||
|
||||
// run a very special query each month:
|
||||
$start = clone $original;
|
||||
while ($start < $end) {
|
||||
$currentEnd = clone $start;
|
||||
$currentStart = clone $start;
|
||||
$currentStart->startOfMonth();
|
||||
$currentEnd->endOfMonth();
|
||||
// get a list of categories, and what the user has earned for that category
|
||||
// (if the user has earned anything)
|
||||
$set = $repository->earnedForAccounts($accounts, $currentStart, $currentEnd);
|
||||
$categories = $categories->merge($set);
|
||||
// save the set combined with the data that is in it:
|
||||
// for example:
|
||||
// [december 2015, salary:1000, bonus:200]
|
||||
$sets->push([$currentStart, $set]);
|
||||
$start->addMonth();
|
||||
}
|
||||
// filter categories into a single bunch. Useful later on.
|
||||
// $categories contains all the categories the user has earned money
|
||||
// in in this period.
|
||||
$categories = $categories->unique('id');
|
||||
$categories = $categories->sortBy(
|
||||
function (Category $category) {
|
||||
return $category->name;
|
||||
}
|
||||
);
|
||||
|
||||
// start looping the time again, this time processing the
|
||||
// data for each month.
|
||||
$start = clone $original;
|
||||
while ($start < $end) {
|
||||
$currentEnd = clone $start;
|
||||
$currentStart = clone $start;
|
||||
$currentStart->startOfMonth();
|
||||
$currentEnd->endOfMonth();
|
||||
|
||||
// in $sets we have saved all the sets of data for each month
|
||||
// so now we need to retrieve the corrent one.
|
||||
// match is on date of course.
|
||||
$currentSet = $sets->first(
|
||||
function ($key, $value) use ($currentStart) {
|
||||
// set for this date.
|
||||
return ($value[0] == $currentStart);
|
||||
}
|
||||
);
|
||||
// create a row used later on.
|
||||
$row = [clone $currentStart];
|
||||
|
||||
// loop all categories:
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
// if entry is not null, we've earned money in this period for this category.
|
||||
$entry = $currentSet[1]->first(
|
||||
function ($key, $value) use ($category) {
|
||||
return $value->id == $category->id;
|
||||
}
|
||||
);
|
||||
// save amount
|
||||
if (!is_null($entry)) {
|
||||
$row[] = $entry->earned;
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
}
|
||||
$entries->push($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->earnedInPeriod($categories, $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a chart of what has been spent in this period in each category
|
||||
* grouped by month.
|
||||
*
|
||||
* @param CategoryRepositoryInterface $repository
|
||||
* @param $report_type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function spentInPeriod(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$original = clone $start;
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($report_type);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('spent-in-period');
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
$categories = new Collection;
|
||||
$sets = new Collection;
|
||||
$entries = new Collection;
|
||||
|
||||
// run a very special query each month:
|
||||
$start = clone $original;
|
||||
while ($start < $end) {
|
||||
$currentEnd = clone $start;
|
||||
$currentStart = clone $start;
|
||||
$currentStart->startOfMonth();
|
||||
$currentEnd->endOfMonth();
|
||||
$set = $repository->spentForAccounts($accounts, $currentStart, $currentEnd);
|
||||
$categories = $categories->merge($set);
|
||||
$sets->push([$currentStart, $set]);
|
||||
$start->addMonth();
|
||||
}
|
||||
$categories = $categories->unique('id');
|
||||
$categories = $categories->sortBy(
|
||||
function (Category $category) {
|
||||
return $category->name;
|
||||
}
|
||||
);
|
||||
|
||||
$start = clone $original;
|
||||
while ($start < $end) {
|
||||
$currentEnd = clone $start;
|
||||
$currentStart = clone $start;
|
||||
$currentStart->startOfMonth();
|
||||
$currentEnd->endOfMonth();
|
||||
$currentSet = $sets->first(
|
||||
function ($key, $value) use ($currentStart) {
|
||||
// set for this date.
|
||||
return ($value[0] == $currentStart);
|
||||
}
|
||||
);
|
||||
$row = [clone $currentStart];
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
/** @var Category $entry */
|
||||
$entry = $currentSet[1]->first(
|
||||
function ($key, $value) use ($category) {
|
||||
return $value->id == $category->id;
|
||||
}
|
||||
);
|
||||
if (!is_null($entry)) {
|
||||
$row[] = $entry->spent;
|
||||
} else {
|
||||
$row[] = 0;
|
||||
}
|
||||
}
|
||||
$entries->push($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->spentInPeriod($categories, $entries);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ use Response;
|
||||
class PiggyBankController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ class PiggyBankController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGeneratorInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,7 +18,7 @@ use Response;
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Report\ReportChartGenerator */
|
||||
/** @var \FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface */
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ class ReportController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
// create chart generator:
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Report\ReportChartGenerator');
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface');
|
||||
}
|
||||
|
||||
|
||||
@@ -36,66 +36,42 @@ class ReportController extends Controller
|
||||
* Summarizes all income and expenses, per month, for a given year.
|
||||
*
|
||||
* @param ReportQueryInterface $query
|
||||
* @param $report_type
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // cant avoid it.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInOut(ReportQueryInterface $query, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function yearInOut(ReportQueryInterface $query, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('yearInOut');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// spent per month, and earned per month. For a specific set of accounts
|
||||
// grouped by month
|
||||
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||
|
||||
// per year?
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
$startOfYear = clone $start;
|
||||
$startOfYear->startOfYear();
|
||||
$endOfYear = clone $startOfYear;
|
||||
$endOfYear->endOfYear();
|
||||
|
||||
// total income and total expenses:
|
||||
$incomeSum = $query->incomeInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
||||
$expenseSum = $query->expenseInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOut($entries);
|
||||
$cache->store($data);
|
||||
// data = method X
|
||||
$data = $this->multiYearInOut($earnedArray, $spentArray, $start, $end);
|
||||
} else {
|
||||
// per month:
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
$month = clone $start;
|
||||
$month->endOfMonth();
|
||||
// total income and total expenses:
|
||||
$incomeSum = $query->incomeInPeriod($start, $month, $accounts)->sum('amount_positive');
|
||||
$expenseSum = $query->expenseInPeriod($start, $month, $accounts)->sum('amount_positive');
|
||||
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOut($entries);
|
||||
$cache->store($data);
|
||||
// data = method Y
|
||||
$data = $this->singleYearInOut($earnedArray, $spentArray, $start, $end);
|
||||
}
|
||||
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
@@ -105,14 +81,14 @@ class ReportController extends Controller
|
||||
* Summarizes all income and expenses for a given year. Gives a total and an average.
|
||||
*
|
||||
* @param ReportQueryInterface $query
|
||||
* @param $report_type
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInOutSummarized(ReportQueryInterface $query, $report_type, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function yearInOutSummarized(ReportQueryInterface $query, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
|
||||
// chart properties for cache:
|
||||
@@ -120,58 +96,155 @@ class ReportController extends Controller
|
||||
$cache->addProperty('yearInOutSummarized');
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
// spent per month, and earned per month. For a specific set of accounts
|
||||
// grouped by month
|
||||
$spentArray = $query->spentPerMonth($accounts, $start, $end);
|
||||
$earnedArray = $query->earnedPerMonth($accounts, $start, $end);
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
// per year
|
||||
$data = $this->multiYearInOutSummarized($earnedArray, $spentArray, $start, $end);
|
||||
} else {
|
||||
// per month!
|
||||
$data = $this->singleYearInOutSummarized($earnedArray, $spentArray, $start, $end);
|
||||
}
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
$date = $start->format('Y-m');
|
||||
$currentIncome = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$currentExpense = isset($spent[$date]) ? ($spent[$date] * -1) : 0;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
bcscale(2);
|
||||
|
||||
if ($start->diffInMonths($end) > 12) {
|
||||
// per year
|
||||
while ($start < $end) {
|
||||
$startOfYear = clone $start;
|
||||
$startOfYear->startOfYear();
|
||||
$endOfYear = clone $startOfYear;
|
||||
$endOfYear->endOfYear();
|
||||
|
||||
// total income and total expenses:
|
||||
$currentIncome = $query->incomeInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
||||
$currentExpense = $query->expenseInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOutSummarized($income, $expense, $count);
|
||||
$cache->store($data);
|
||||
} else {
|
||||
// per month!
|
||||
while ($start < $end) {
|
||||
$month = clone $start;
|
||||
$month->endOfMonth();
|
||||
// total income and total expenses:
|
||||
$currentIncome = $query->incomeInPeriod($start, $month, $accounts)->sum('amount_positive');
|
||||
$currentExpense = $query->expenseInPeriod($start, $month, $accounts)->sum('amount_positive');
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||
$cache->store($data);
|
||||
$count++;
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return Response::json($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOutSummarized(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$income = '0';
|
||||
$expense = '0';
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
|
||||
$currentIncome = $this->pluckFromArray($start->year, $earned);
|
||||
$currentExpense = $this->pluckFromArray($start->year, $spent) * -1;
|
||||
$income = bcadd($income, $currentIncome);
|
||||
$expense = bcadd($expense, $currentExpense);
|
||||
|
||||
$count++;
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOutSummarized($income, $expense, $count);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function multiYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
|
||||
$incomeSum = $this->pluckFromArray($start->year, $earned);
|
||||
$expenseSum = $this->pluckFromArray($start->year, $spent) * -1;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addYear();
|
||||
}
|
||||
|
||||
$data = $this->generator->multiYearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $earned
|
||||
* @param array $spent
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function singleYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
|
||||
{
|
||||
// per month? simply use each month.
|
||||
|
||||
$entries = new Collection;
|
||||
while ($start < $end) {
|
||||
// total income and total expenses:
|
||||
$date = $start->format('Y-m');
|
||||
$incomeSum = isset($earned[$date]) ? $earned[$date] : 0;
|
||||
$expenseSum = isset($spent[$date]) ? ($spent[$date] * -1) : 0;
|
||||
|
||||
$entries->push([clone $start, $incomeSum, $expenseSum]);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
$data = $this->generator->yearInOut($entries);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @param array $set
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function pluckFromArray($year, array $set)
|
||||
{
|
||||
bcscale(2);
|
||||
$sum = '0';
|
||||
foreach ($set as $date => $amount) {
|
||||
if (substr($date, 0, 4) == $year) {
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
}
|
||||
|
||||
return $sum;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,15 @@
|
||||
<?php namespace FireflyIII\Http\Controllers;
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use Config;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use NumberFormatter;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
@@ -13,10 +18,9 @@ use View;
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
*/
|
||||
abstract class Controller extends BaseController
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
||||
use DispatchesJobs, ValidatesRequests;
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/** @var string */
|
||||
protected $monthAndDayFormat;
|
||||
@@ -24,7 +28,7 @@ abstract class Controller extends BaseController
|
||||
protected $monthFormat;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Controller constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -36,13 +40,58 @@ abstract class Controller extends BaseController
|
||||
if (Auth::check()) {
|
||||
$pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
|
||||
$lang = $pref->data;
|
||||
$this->monthFormat = trans('config.month');
|
||||
$this->monthAndDayFormat = trans('config.month_and_day');
|
||||
$this->monthFormat = (string)trans('config.month');
|
||||
$this->monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
|
||||
App::setLocale($lang);
|
||||
Carbon::setLocale(substr($lang, 0, 2));
|
||||
$locale = explode(',', trans('config.locale'));
|
||||
$locale = array_map('trim', $locale);
|
||||
|
||||
setlocale(LC_TIME, $locale);
|
||||
setlocale(LC_MONETARY, $locale);
|
||||
|
||||
// change localeconv to a new array:
|
||||
$numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);
|
||||
$localeconv = [
|
||||
'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),
|
||||
'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),
|
||||
'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),
|
||||
];
|
||||
View::share('monthFormat', $this->monthFormat);
|
||||
View::share('monthAndDayFormat', $this->monthAndDayFormat);
|
||||
View::share('language', $lang);
|
||||
View::share('localeconv', localeconv());
|
||||
View::share('localeconv', $localeconv);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSumOfRange(Carbon $start, Carbon $end, array $array)
|
||||
{
|
||||
bcscale(2);
|
||||
$sum = '0';
|
||||
$currentStart = clone $start; // to not mess with the original one
|
||||
$currentEnd = clone $end; // to not mess with the original one
|
||||
|
||||
while ($currentStart <= $currentEnd) {
|
||||
$date = $currentStart->format('Y-m-d');
|
||||
if (isset($array[$date])) {
|
||||
$sum = bcadd($sum, $array[$date]);
|
||||
}
|
||||
$currentStart->addDay();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
* Class WebhookController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
*/
|
||||
class CronController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Firefly doesn't have anything that should be in the a cron job, except maybe this one, and it's fairly exceptional.
|
||||
*
|
||||
* If you use SendGrid like I do, you can detect bounces and thereby check if users gave an invalid address. If they did,
|
||||
* it's easy to block them and change their password. Optionally, you could notify yourself about it and send them a message.
|
||||
*
|
||||
* But thats something not supported right now.
|
||||
*/
|
||||
public function sendgrid()
|
||||
{
|
||||
|
||||
if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) {
|
||||
|
||||
$set = [
|
||||
'blocks' => 'https://api.sendgrid.com/api/blocks.get.json',
|
||||
'bounces' => 'https://api.sendgrid.com/api/bounces.get.json',
|
||||
'invalids' => 'https://api.sendgrid.com/api/invalidemails.get.json',
|
||||
|
||||
];
|
||||
echo '<pre>';
|
||||
foreach ($set as $name => $URL) {
|
||||
|
||||
|
||||
$parameters = [
|
||||
'api_user' => env('SENDGRID_USERNAME'),
|
||||
'api_key' => env('SENDGRID_PASSWORD'),
|
||||
'date' => 1,
|
||||
'days' => 7
|
||||
];
|
||||
$fullURL = $URL . '?' . http_build_query($parameters);
|
||||
$data = json_decode(file_get_contents($fullURL));
|
||||
|
||||
/*
|
||||
* Loop the result, if any.
|
||||
*/
|
||||
if (is_array($data)) {
|
||||
echo 'Found ' . count($data) . ' entries in the SendGrid ' . $name . ' list.' . "\n";
|
||||
foreach ($data as $entry) {
|
||||
$address = $entry->email;
|
||||
$user = User::where('email', $address)->where('blocked', 0)->first();
|
||||
if (!is_null($user)) {
|
||||
echo 'Found a user: ' . $address . ', who is now blocked.' . "\n";
|
||||
$user->blocked = 1;
|
||||
$user->blocked_code = 'bounced';
|
||||
$user->password = 'bounced';
|
||||
$user->save();
|
||||
} else {
|
||||
echo 'Found no user: ' . $address . ', did nothing.' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'Done!' . "\n";
|
||||
} else {
|
||||
echo 'Please fill in SendGrid details.';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -8,11 +8,12 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Csv\Data;
|
||||
use FireflyIII\Helpers\Csv\Importer;
|
||||
use FireflyIII\Helpers\Csv\WizardInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use Illuminate\Http\Request;
|
||||
use Input;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Request as RequestFacade;
|
||||
use Session;
|
||||
use View;
|
||||
|
||||
@@ -30,7 +31,7 @@ class CsvController extends Controller
|
||||
protected $wizard;
|
||||
|
||||
/**
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -57,8 +58,9 @@ class CsvController extends Controller
|
||||
public function columnRoles()
|
||||
{
|
||||
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account'];
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account', 'csv-specifix', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Log::error('Could not recover upload.');
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
return redirect(route('csv.index'));
|
||||
@@ -79,9 +81,9 @@ class CsvController extends Controller
|
||||
if ($this->data->hasHeaders()) {
|
||||
$headers = $firstRow;
|
||||
}
|
||||
|
||||
foreach (Config::get('csv.roles') as $name => $role) {
|
||||
$availableRoles[$name] = trans('firefly.csv_column_' . $name);//$role['name'];
|
||||
$keys = array_keys(Config::get('csv.roles'));
|
||||
foreach ($keys as $name) {
|
||||
$availableRoles[$name] = trans('firefly.csv_column_' . $name);
|
||||
}
|
||||
ksort($availableRoles);
|
||||
|
||||
@@ -97,7 +99,7 @@ class CsvController extends Controller
|
||||
*/
|
||||
public function downloadConfig()
|
||||
{
|
||||
$fields = ['csv-date-format', 'csv-has-headers'];
|
||||
$fields = ['csv-date-format', 'csv-has-headers', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
@@ -105,7 +107,7 @@ class CsvController extends Controller
|
||||
}
|
||||
$data = [
|
||||
'date-format' => Session::get('csv-date-format'),
|
||||
'has-headers' => Session::get('csv-has-headers')
|
||||
'has-headers' => Session::get('csv-has-headers'),
|
||||
];
|
||||
if (Session::has('csv-map')) {
|
||||
$data['map'] = Session::get('csv-map');
|
||||
@@ -122,13 +124,18 @@ class CsvController extends Controller
|
||||
}
|
||||
|
||||
$result = json_encode($data, JSON_PRETTY_PRINT);
|
||||
$name = 'csv-configuration-' . date('Y-m-d') . '.json';
|
||||
$name = sprintf('"%s"', addcslashes('csv-configuration-' . date('Y-m-d') . '.json', '"\\'));
|
||||
|
||||
header('Content-disposition: attachment; filename=' . $name);
|
||||
header('Content-type: application/json');
|
||||
echo $result;
|
||||
RequestFacade::header('Content-disposition: attachment; filename=' . $name);
|
||||
RequestFacade::header('Content-Type: application/json');
|
||||
RequestFacade::header('Content-Description: File Transfer');
|
||||
RequestFacade::header('Connection: Keep-Alive');
|
||||
RequestFacade::header('Expires: 0');
|
||||
RequestFacade::header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
RequestFacade::header('Pragma: public');
|
||||
RequestFacade::header('Content-Length: ' . strlen($result));
|
||||
|
||||
return '';
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +143,13 @@ class CsvController extends Controller
|
||||
*/
|
||||
public function downloadConfigPage()
|
||||
{
|
||||
$fields = ['csv-date-format', 'csv-has-headers', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
return redirect(route('csv.index'));
|
||||
}
|
||||
|
||||
$subTitle = trans('firefly.csv_download_config_title');
|
||||
|
||||
return view('csv.download-config', compact('subTitle'));
|
||||
@@ -146,9 +160,11 @@ class CsvController extends Controller
|
||||
*
|
||||
* STEP ONE
|
||||
*
|
||||
* @param ARI $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
public function index(ARI $repository)
|
||||
{
|
||||
$subTitle = trans('firefly.csv_import');
|
||||
|
||||
@@ -160,6 +176,7 @@ class CsvController extends Controller
|
||||
Session::forget('csv-roles');
|
||||
Session::forget('csv-mapped');
|
||||
Session::forget('csv-specifix');
|
||||
Session::forget('csv-delimiter');
|
||||
|
||||
// get list of supported specifix
|
||||
$specifix = [];
|
||||
@@ -167,6 +184,13 @@ class CsvController extends Controller
|
||||
$specifix[$entry] = trans('firefly.csv_specifix_' . $entry);
|
||||
}
|
||||
|
||||
// get a list of delimiters:
|
||||
$delimiters = [
|
||||
',' => trans('form.csv_comma'),
|
||||
';' => trans('form.csv_semicolon'),
|
||||
'tab' => trans('form.csv_tab'),
|
||||
];
|
||||
|
||||
// get a list of asset accounts:
|
||||
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Asset account', 'Default account']));
|
||||
|
||||
@@ -174,7 +198,7 @@ class CsvController extends Controller
|
||||
$uploadPossible = is_writable(storage_path('upload'));
|
||||
$path = storage_path('upload');
|
||||
|
||||
return view('csv.index', compact('subTitle', 'uploadPossible', 'path', 'specifix', 'accounts'));
|
||||
return view('csv.index', compact('subTitle', 'uploadPossible', 'path', 'specifix', 'accounts', 'delimiters'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +210,7 @@ class CsvController extends Controller
|
||||
*/
|
||||
public function initialParse()
|
||||
{
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers'];
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
@@ -236,7 +260,7 @@ class CsvController extends Controller
|
||||
{
|
||||
|
||||
// Make sure all fields we need are accounted for.
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles'];
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
@@ -256,6 +280,8 @@ class CsvController extends Controller
|
||||
try {
|
||||
$options = $this->wizard->showOptions($this->data->getMap());
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return view('error', ['message' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
@@ -284,7 +310,7 @@ class CsvController extends Controller
|
||||
/*
|
||||
* Make sure all fields we need are accounted for.
|
||||
*/
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles', 'csv-mapped'];
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles', 'csv-mapped', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
@@ -321,6 +347,8 @@ class CsvController extends Controller
|
||||
*
|
||||
* STEP SIX
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) it's 6, but it's allright.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function saveMapping()
|
||||
@@ -328,7 +356,7 @@ class CsvController extends Controller
|
||||
/*
|
||||
* Make sure all fields we need are accounted for.
|
||||
*/
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles'];
|
||||
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles', 'csv-delimiter'];
|
||||
if (!$this->wizard->sessionHasValues($fields)) {
|
||||
Session::flash('warning', 'Could not recover upload.');
|
||||
|
||||
@@ -365,6 +393,9 @@ class CsvController extends Controller
|
||||
*
|
||||
* STEP TWO
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // need the length.
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly 5, its ok
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
@@ -381,11 +412,19 @@ class CsvController extends Controller
|
||||
$settings = [];
|
||||
$settings['date-format'] = Input::get('date_format');
|
||||
$settings['has-headers'] = intval(Input::get('has_headers')) === 1;
|
||||
$settings['specifix'] = Input::get('specifix');
|
||||
$settings['specifix'] = is_array(Input::get('specifix')) ? Input::get('specifix') : [];
|
||||
$settings['import-account'] = intval(Input::get('csv_import_account'));
|
||||
$settings['map'] = [];
|
||||
$settings['mapped'] = [];
|
||||
$settings['roles'] = [];
|
||||
$settings['delimiter'] = Input::get('csv_delimiter', ',');
|
||||
|
||||
// A tab character cannot be used itself as option value in HTML
|
||||
// See http://stackoverflow.com/questions/6064135/valid-characters-in-option-value
|
||||
if ($settings['delimiter'] == 'tab') {
|
||||
$settings['delimiter'] = "\t";
|
||||
}
|
||||
|
||||
$settings['map'] = [];
|
||||
$settings['mapped'] = [];
|
||||
$settings['roles'] = [];
|
||||
|
||||
if ($request->hasFile('csv_config')) { // Process config file if present.
|
||||
$data = file_get_contents($request->file('csv_config')->getRealPath());
|
||||
@@ -403,6 +442,7 @@ class CsvController extends Controller
|
||||
$this->data->setRoles($settings['roles']);
|
||||
$this->data->setSpecifix($settings['specifix']);
|
||||
$this->data->setImportAccount($settings['import-account']);
|
||||
$this->data->setDelimiter($settings['delimiter']);
|
||||
|
||||
return redirect(route('csv.column-roles'));
|
||||
|
||||
|
@@ -6,6 +6,7 @@ use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Input;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use URL;
|
||||
@@ -60,7 +61,7 @@ class CurrencyController extends Controller
|
||||
Preferences::set('currencyPreference', $currency->code);
|
||||
Preferences::mark();
|
||||
|
||||
Session::flash('success', $currency->name . ' is now the default currency.');
|
||||
Session::flash('success', trans('firefly.new_default_currency', ['name' => $currency->name]));
|
||||
Cache::forget('FFCURRENCYSYMBOL');
|
||||
Cache::forget('FFCURRENCYCODE');
|
||||
|
||||
@@ -78,7 +79,7 @@ class CurrencyController extends Controller
|
||||
{
|
||||
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
Session::flash('error', 'Cannot delete ' . e($currency->name) . ' because there are still transactions attached to it.');
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
}
|
||||
@@ -103,12 +104,12 @@ class CurrencyController extends Controller
|
||||
public function destroy(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
{
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
Session::flash('error', 'Cannot destroy ' . e($currency->name) . ' because there are still transactions attached to it.');
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
}
|
||||
|
||||
Session::flash('success', 'Currency "' . e($currency->name) . '" deleted');
|
||||
Session::flash('success', trans('firefly.deleted_currency', ['name' => $currency->name]));
|
||||
if (Auth::user()->hasRole('owner')) {
|
||||
$currency->delete();
|
||||
}
|
||||
@@ -151,7 +152,7 @@ class CurrencyController extends Controller
|
||||
|
||||
|
||||
if (!Auth::user()->hasRole('owner')) {
|
||||
Session::flash('warning', 'Please ask ' . env('SITE_OWNER') . ' to add, remove or edit currencies.');
|
||||
Session::flash('warning', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')]));
|
||||
}
|
||||
|
||||
|
||||
@@ -170,8 +171,9 @@ class CurrencyController extends Controller
|
||||
$data = $request->getCurrencyData();
|
||||
if (Auth::user()->hasRole('owner')) {
|
||||
$currency = $repository->store($data);
|
||||
Session::flash('success', 'Currency "' . $currency->name . '" created');
|
||||
|
||||
Session::flash('success', trans('firefly.created_currency', ['name' => $currency->name]));
|
||||
} else {
|
||||
Log::error('User ' . Auth::user()->id . ' is not admin, but tried to store a currency.');
|
||||
}
|
||||
|
||||
if (intval(Input::get('create_another')) === 1) {
|
||||
@@ -199,7 +201,7 @@ class CurrencyController extends Controller
|
||||
if (Auth::user()->hasRole('owner')) {
|
||||
$currency = $repository->update($currency, $data);
|
||||
}
|
||||
Session::flash('success', 'Currency "' . e($currency->name) . '" updated.');
|
||||
Session::flash('success', trans('firefly.updated_currency', ['name' => $currency->name]));
|
||||
Preferences::mark();
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user