Compare commits

...

210 Commits
4.4.3 ... 4.6.0

Author SHA1 Message Date
James Cole
63be574a14 Merge branch 'release/4.6.0' 2017-06-28 18:13:00 +02:00
James Cole
2414f998ba Update git ignore file. 2017-06-28 18:09:32 +02:00
James Cole
90e2ecad4f Merge pull request #683 from firefly-iii/l10n_develop
New Crowdin translations
2017-06-28 18:08:27 +02:00
James Cole
87a3f5c715 New translations firefly.php (Dutch) 2017-06-28 18:07:52 +02:00
James Cole
a4ef81ebd8 Improve test coverage. 2017-06-28 18:05:38 +02:00
James Cole
67fc810fc2 Ignore test database. 2017-06-28 18:05:04 +02:00
James Cole
e13a61645d New change log 2017-06-28 18:04:42 +02:00
James Cole
aae4a78fd4 Possible fix for #649 [skip ci] 2017-06-28 15:52:13 +02:00
James Cole
3947da5e27 Possible fix for #682 2017-06-28 15:45:28 +02:00
James Cole
4e4ce2f77c Remove test database from Firefly III thing. [skip ci] 2017-06-28 15:31:11 +02:00
James Cole
d9a2e081bd Update travis script. 2017-06-28 15:27:31 +02:00
James Cole
e60dde7ce5 Merge pull request #681 from firefly-iii/l10n_develop
New Crowdin translations
2017-06-28 15:18:59 +02:00
James Cole
699b138999 Small link fixes [skip ci] 2017-06-28 15:18:11 +02:00
James Cole
8f191b497f Updated read me and contributing guidelines. 2017-06-28 15:17:19 +02:00
James Cole
fd013d617c New translations firefly.php (Chinese Traditional) 2017-06-28 15:11:10 +02:00
James Cole
a8bda38035 New translations firefly.php (Dutch) 2017-06-28 15:11:07 +02:00
James Cole
411de9aa23 New translations firefly.php (French) 2017-06-28 15:11:05 +02:00
James Cole
f0abe497ef New translations firefly.php (German) 2017-06-28 15:11:02 +02:00
James Cole
9c8be83f5d New translations firefly.php (Polish) 2017-06-28 15:10:58 +02:00
James Cole
45335af8cf New translations firefly.php (Portuguese, Brazilian) 2017-06-28 15:10:56 +02:00
James Cole
945e433bb7 New translations firefly.php (Slovenian) 2017-06-28 15:10:51 +02:00
James Cole
70729fdb0c New translations firefly.php (Spanish) 2017-06-28 15:10:48 +02:00
James Cole
4a435e5701 Updated composer file. 2017-06-28 15:01:06 +02:00
James Cole
427747c6b8 Merge pull request #666 from firefly-iii/l10n_develop
New Crowdin translations
2017-06-28 15:00:48 +02:00
James Cole
be9407cb57 New translations csv.php (Dutch) 2017-06-28 15:00:19 +02:00
James Cole
c380d3d2a0 New translations firefly.php (Dutch) 2017-06-28 15:00:13 +02:00
James Cole
489b0eb12d New translations firefly.php (Dutch) 2017-06-28 14:50:13 +02:00
James Cole
7c73629962 Merge pull request #680 from Xeli/l10n_develop
Fix en_US translation: no_accounts_imperative_revenue.
2017-06-28 12:41:26 +02:00
richard@xeli.eu
ff619eca1c Fix en_US translation: no_accounts_imperative_revenue. Change Expense to Revenue 2017-06-28 12:12:31 +02:00
James Cole
134a39fd71 New translations firefly.php (German) 2017-06-27 13:50:38 +02:00
James Cole
506509b1b2 Fix #677 2017-06-26 18:29:45 +02:00
James Cole
02a36316be Forgot to remove a variable. 2017-06-26 18:24:44 +02:00
James Cole
8549c7c81b This should fix #677 2017-06-26 18:24:29 +02:00
James Cole
5a0be7d2ad Push new version number. 2017-06-24 13:05:12 +02:00
James Cole
c6f44c6398 Composer update. 2017-06-24 13:04:50 +02:00
James Cole
04a8a0e6a1 Code clean up 2017-06-24 13:04:41 +02:00
James Cole
8a175d147b Remove JS console log. 2017-06-24 13:03:09 +02:00
James Cole
5fbc319b20 This fixes the tests (must still upload test database). 2017-06-24 12:38:24 +02:00
James Cole
8e3ba7caf2 Fix various import bugs. 2017-06-24 08:37:09 +02:00
James Cole
182aaa7d27 New translations csv.php (Spanish) 2017-06-24 07:30:48 +02:00
James Cole
ec17d466f7 New translations firefly.php (Chinese Traditional) 2017-06-24 07:30:46 +02:00
James Cole
79c2445117 New translations firefly.php (Dutch) 2017-06-24 07:30:44 +02:00
James Cole
aa59db1609 New translations firefly.php (French) 2017-06-24 07:30:42 +02:00
James Cole
814b106be2 New translations csv.php (Slovenian) 2017-06-24 07:30:40 +02:00
James Cole
3901ea0fbe New translations csv.php (Portuguese, Brazilian) 2017-06-24 07:30:39 +02:00
James Cole
65133107be New translations csv.php (Dutch) 2017-06-24 07:30:38 +02:00
James Cole
08d15cfc5e New translations csv.php (French) 2017-06-24 07:30:37 +02:00
James Cole
3c89f9a5f1 New translations csv.php (German) 2017-06-24 07:30:36 +02:00
James Cole
dbc6bc8206 New translations csv.php (Polish) 2017-06-24 07:30:35 +02:00
James Cole
dc38291ef5 New translations firefly.php (German) 2017-06-24 07:30:34 +02:00
James Cole
3bb634ed5b New translations firefly.php (Polish) 2017-06-24 07:30:32 +02:00
James Cole
4bdcfe4d30 New translations firefly.php (Portuguese, Brazilian) 2017-06-24 07:30:28 +02:00
James Cole
3b74784486 New translations firefly.php (Slovenian) 2017-06-24 07:30:25 +02:00
James Cole
5226664a3d New translations firefly.php (Spanish) 2017-06-24 07:30:23 +02:00
James Cole
6d23823b63 New translations csv.php (Chinese Traditional) 2017-06-24 07:30:20 +02:00
James Cole
da3a56c144 Further improve import storage. 2017-06-24 07:30:05 +02:00
James Cole
58aa54d8cf Improving import storage. 2017-06-24 07:21:10 +02:00
James Cole
e525e673a8 Import routine cleanup. 2017-06-24 06:57:24 +02:00
James Cole
445dbf8779 More and improved code for the import routine. 2017-06-24 05:49:33 +02:00
James Cole
6a27bea2a3 New translations firefly.php (Chinese Traditional) 2017-06-22 22:01:08 +02:00
James Cole
13163f9c5c New translations firefly.php (Dutch) 2017-06-22 22:01:05 +02:00
James Cole
fde08f922b New translations firefly.php (French) 2017-06-22 22:01:02 +02:00
James Cole
266ce00872 New translations firefly.php (German) 2017-06-22 22:00:56 +02:00
James Cole
623a70a0d1 New translations firefly.php (Polish) 2017-06-22 22:00:52 +02:00
James Cole
1d7b738040 New translations firefly.php (Portuguese, Brazilian) 2017-06-22 22:00:46 +02:00
James Cole
edc8dd2601 New translations firefly.php (Slovenian) 2017-06-22 22:00:43 +02:00
James Cole
31dc932ca4 New translations firefly.php (Spanish) 2017-06-22 22:00:40 +02:00
James Cole
edb355941c More code for import routine. 2017-06-22 21:50:10 +02:00
James Cole
cddaccb7f7 Further improve import routine 2017-06-21 20:04:35 +02:00
James Cole
a905cce2c9 Expand import routine. 2017-06-20 21:04:25 +02:00
James Cole
b9f110ac2b Refactor and rename some import things. 2017-06-17 22:49:44 +02:00
James Cole
7cc24417b3 Expanded import routine. 2017-06-14 20:13:19 +02:00
James Cole
b304284d70 Fix report bug. 2017-06-14 19:15:30 +02:00
James Cole
c382fb1577 Add debug info for #671 2017-06-12 19:58:32 +02:00
James Cole
77244f4e2c Lots of new code for new importer routine. 2017-06-12 19:12:07 +02:00
James Cole
8beab5f5bc Fix #672 2017-06-12 17:21:31 +02:00
James Cole
902ae3f0cf Fix for #671 2017-06-12 17:07:29 +02:00
James Cole
519ef4e486 New translations csv.php (French) 2017-06-10 15:21:17 +02:00
James Cole
699e04f371 New translations firefly.php (French) 2017-06-10 15:21:16 +02:00
James Cole
d73de0e60d New translations csv.php (German) 2017-06-10 15:21:12 +02:00
James Cole
8e0b7d2a73 New translations firefly.php (German) 2017-06-10 15:21:10 +02:00
James Cole
04283cf2d6 New translations csv.php (Polish) 2017-06-10 15:21:06 +02:00
James Cole
d60b4aa56f New translations csv.php (Chinese Traditional) 2017-06-10 15:20:57 +02:00
James Cole
9cfeda1b0c New translations firefly.php (Chinese Traditional) 2017-06-10 15:20:55 +02:00
James Cole
5e1bd8e1eb New translations csv.php (Dutch) 2017-06-10 15:20:48 +02:00
James Cole
9b495d212b New translations firefly.php (Polish) 2017-06-10 15:20:47 +02:00
James Cole
b6fdd0070b New translations firefly.php (Slovenian) 2017-06-10 15:20:40 +02:00
James Cole
eea387ad0c New translations csv.php (Spanish) 2017-06-10 15:20:33 +02:00
James Cole
9cdb0f173a New translations csv.php (Slovenian) 2017-06-10 15:20:31 +02:00
James Cole
51063230d0 New translations firefly.php (Dutch) 2017-06-10 15:20:30 +02:00
James Cole
1111478b7f New translations firefly.php (Portuguese, Brazilian) 2017-06-10 15:20:25 +02:00
James Cole
c99c9b441f New translations csv.php (Portuguese, Brazilian) 2017-06-10 15:20:17 +02:00
James Cole
b5065a0276 New translations firefly.php (Spanish) 2017-06-10 15:20:11 +02:00
James Cole
c79a577060 Remove unused files in import. 2017-06-10 15:10:46 +02:00
James Cole
091596e80e Lots of new code for new importer routine. 2017-06-10 15:09:41 +02:00
James Cole
0b4efe4ae1 Small typo in chart. [skip ci] 2017-06-09 12:53:31 +02:00
James Cole
1f9b7faa60 Code for #660 2017-06-09 11:52:20 +02:00
James Cole
762d7bcc34 Fix database for postgresql 2017-06-09 11:51:59 +02:00
James Cole
a2145f6b49 Possible fix for #667 2017-06-08 10:54:15 +02:00
James Cole
b48de98865 Fix a bug where the balance routine forgot to account for accounts without a currency preference. 2017-06-08 10:35:02 +02:00
James Cole
a23179dd83 Merge branch 'release/4.5.0' 2017-06-07 12:30:09 +02:00
James Cole
5c18794122 Update lock file, and update database. 2017-06-07 12:22:59 +02:00
James Cole
f04011f6a7 New translations firefly.php (Dutch) 2017-06-07 12:20:13 +02:00
James Cole
893498238e Merge pull request #647 from firefly-iii/l10n_develop
New Crowdin translations
2017-06-07 12:11:28 +02:00
James Cole
474fa9dea0 New translations firefly.php (Dutch) 2017-06-07 12:10:10 +02:00
James Cole
d8a8574dda Prep for new release. 2017-06-07 12:08:32 +02:00
James Cole
935fb015d3 Live update budget amounts. 2017-06-07 11:58:04 +02:00
James Cole
8bbd3063ec Move code around for simplicity and fix tests. 2017-06-07 11:13:04 +02:00
James Cole
92c5cabd70 Try to untangle complex repositories 2017-06-07 08:18:42 +02:00
James Cole
e5db5a7b5c Various code clean up. 2017-06-07 07:38:58 +02:00
James Cole
28cf123da3 New translations firefly.php (French) 2017-06-06 20:41:24 +02:00
James Cole
5069367873 New translations firefly.php (German) 2017-06-06 20:41:16 +02:00
James Cole
234e656ff6 New translations firefly.php (Chinese Traditional) 2017-06-06 20:40:59 +02:00
James Cole
aeadfbdd6a New translations firefly.php (Polish) 2017-06-06 20:40:50 +02:00
James Cole
39288cfb0b New translations firefly.php (Slovenian) 2017-06-06 20:40:41 +02:00
James Cole
5e430968c1 New translations firefly.php (Dutch) 2017-06-06 20:40:34 +02:00
James Cole
154b74ce6f New translations firefly.php (Portuguese, Brazilian) 2017-06-06 20:40:26 +02:00
James Cole
2e26303b66 New translations firefly.php (Spanish) 2017-06-06 20:40:11 +02:00
James Cole
51ddcd9ee1 Plus not minus [skip ci] 2017-06-06 20:37:24 +02:00
James Cole
9d5d1c0a41 Updated budget view. 2017-06-06 20:35:39 +02:00
James Cole
6058ccff0d Merge pull request #664 from kressh/master
Add pgsql dependencies to Dockerfile
2017-06-06 20:01:43 +02:00
James Cole
a8ec4fe2fd New interface for budget overview. 2017-06-06 19:30:31 +02:00
James Cole
65ccb2d443 Fix error display #662 2017-06-06 19:29:10 +02:00
James Cole
0e929602a8 Verify currency data routine. 2017-06-06 07:23:54 +02:00
James Cole
5329e026dc Fixed various currency displays. 2017-06-06 07:18:09 +02:00
James Cole
a7412e43b3 Beter message for #662 2017-06-06 06:56:32 +02:00
Sergey Besedin
eeae24e058 Add pgsql dependencies 2017-06-06 01:22:09 +03:00
James Cole
17b6cc43d5 Fix display of foreign currencies in charts. 2017-06-05 22:11:54 +02:00
James Cole
b69a2ef0cd Can handle multi-currency balances better. 2017-06-05 15:09:17 +02:00
James Cole
6d1296094e Fixes a lot of issues in scrutinizer. 2017-06-05 11:20:38 +02:00
James Cole
c4039b53e6 Various code cleanup. 2017-06-05 11:12:50 +02:00
James Cole
64831b4c86 Code cleanup and refactoring. 2017-06-05 08:31:22 +02:00
James Cole
1dec270907 These changes fix the tests. 2017-06-05 07:37:53 +02:00
James Cole
f72f8b03df Catch empty currency preference 2017-06-05 07:03:32 +02:00
James Cole
0b47e5d05d Removed unnecessary variable. 2017-06-05 07:03:20 +02:00
James Cole
a487c7b4b2 Make sure amounts are formatted, and fixed some issues. 2017-06-04 23:39:26 +02:00
James Cole
3838b21459 New translations firefly.php (French) 2017-06-04 13:41:19 +02:00
James Cole
7801274d33 New translations firefly.php (German) 2017-06-04 13:41:15 +02:00
James Cole
a505406ee7 New translations firefly.php (Chinese Traditional) 2017-06-04 13:41:03 +02:00
James Cole
9487a95c13 New translations firefly.php (Polish) 2017-06-04 13:40:54 +02:00
James Cole
3b2fe13902 New translations firefly.php (Slovenian) 2017-06-04 13:40:47 +02:00
James Cole
db2898dfe5 New translations auth.php (Spanish) 2017-06-04 13:40:44 +02:00
James Cole
e08fd399d2 New translations csv.php (Spanish) 2017-06-04 13:40:40 +02:00
James Cole
e45ffba010 New translations passwords.php (Spanish) 2017-06-04 13:40:39 +02:00
James Cole
f7fde93ed2 New translations firefly.php (Dutch) 2017-06-04 13:40:37 +02:00
James Cole
3cf53604a1 New translations firefly.php (Portuguese, Brazilian) 2017-06-04 13:40:31 +02:00
James Cole
e041a5e037 New translations help.php (Spanish) 2017-06-04 13:40:19 +02:00
James Cole
6c8e10255b New translations form.php (Spanish) 2017-06-04 13:40:17 +02:00
James Cole
3464ab1527 New translations firefly.php (Spanish) 2017-06-04 13:40:13 +02:00
James Cole
82e74a2afd Big update to properly support multi currencies. 2017-06-04 13:39:16 +02:00
James Cole
771ebde295 Update journal collector so currency information is taken from the transaction. 2017-06-04 08:49:37 +02:00
James Cole
4ce4c3138c Update export routine so currency information is taken from the transaction. 2017-06-04 08:49:22 +02:00
James Cole
d37b46effc Database upgrade routine. 2017-06-04 08:48:54 +02:00
James Cole
0868aac750 Small update for 4.5.0 SQL update. 2017-06-04 08:48:40 +02:00
James Cole
4ff5f33966 Prep for solid multi-currency configuration. 2017-06-02 13:01:43 +02:00
James Cole
e1aebbe12b Remove non-existing charts. 2017-06-02 13:01:24 +02:00
James Cole
8273f467b6 Refactor some JS functions. 2017-06-02 13:00:43 +02:00
James Cole
74664afa68 Was not able to remove opening balance. 2017-06-02 13:00:24 +02:00
James Cole
c05f344371 Code clean up [skip ci] 2017-06-02 13:00:09 +02:00
James Cole
ec1507d644 Add some documentation [skip ci] 2017-06-02 12:59:27 +02:00
James Cole
8cdc1f0014 Rename several twig files. 2017-06-02 12:59:14 +02:00
James Cole
2b1ab5c6ef Fixed edit of multi currency transaction, ##651 2017-06-02 07:05:42 +02:00
James Cole
01fedc0bf8 Fix for #593, as inspired by @nhaarman. 2017-06-02 06:45:38 +02:00
James Cole
1bd82d71a2 New translations list.php (Spanish) 2017-05-25 16:50:09 +02:00
James Cole
1e9dacb6e4 New translations pagination.php (Spanish) 2017-05-25 16:40:16 +02:00
James Cole
94939ea3d3 New translations firefly.php (Portuguese, Brazilian) 2017-05-25 16:40:13 +02:00
James Cole
c3ff69d147 New translations list.php (Spanish) 2017-05-25 16:40:09 +02:00
James Cole
0fad9d4ac7 New translations validation.php (Spanish) 2017-05-25 16:40:07 +02:00
James Cole
70cd8ffb72 New translations validation.php (Spanish) 2017-05-25 16:30:10 +02:00
James Cole
61535bf4b8 New translations firefly.php (Spanish) 2017-05-25 16:30:08 +02:00
James Cole
4adcbf9e48 New translations demo.php (Spanish) 2017-05-25 16:20:11 +02:00
James Cole
3eba3167fd New translations firefly.php (Spanish) 2017-05-25 16:20:07 +02:00
James Cole
0608fd7732 New translations demo.php (Spanish) 2017-05-25 16:10:06 +02:00
James Cole
1f41f27e89 New translations breadcrumbs.php (Spanish) 2017-05-25 16:00:11 +02:00
James Cole
ded0df9303 New translations config.php (Spanish) 2017-05-25 16:00:06 +02:00
James Cole
2a7ba1893a New translations form.php (Slovenian) 2017-05-16 15:10:18 +02:00
James Cole
6b3b19632a New translations help.php (Slovenian) 2017-05-16 15:10:15 +02:00
James Cole
98bb0731df New translations list.php (Slovenian) 2017-05-16 15:10:12 +02:00
James Cole
a102f7044e New translations list.php (Slovenian) 2017-05-15 09:20:09 +02:00
James Cole
f1028dbaed New translations list.php (Slovenian) 2017-05-15 09:10:14 +02:00
James Cole
438ce5c3db New translations list.php (Slovenian) 2017-05-15 09:00:35 +02:00
James Cole
b995a1d091 New translations list.php (Slovenian) 2017-05-15 08:50:08 +02:00
James Cole
e072f83507 New translations list.php (Slovenian) 2017-05-14 10:10:08 +02:00
James Cole
79154bba25 New translations pagination.php (Slovenian) 2017-05-14 10:10:06 +02:00
James Cole
613eb7522c New translations pagination.php (Slovenian) 2017-05-14 10:00:10 +02:00
James Cole
0eb5653713 New translations csv.php (Slovenian) 2017-05-14 10:00:08 +02:00
James Cole
0d624f021b New translations csv.php (Slovenian) 2017-05-14 09:30:23 +02:00
James Cole
b263047f4e New translations csv.php (Slovenian) 2017-05-14 09:20:21 +02:00
James Cole
4410e1bbd7 New translations csv.php (Slovenian) 2017-05-14 09:10:12 +02:00
James Cole
8c3871e8de New translations csv.php (Slovenian) 2017-05-14 09:00:09 +02:00
James Cole
2eafd3cc15 Should fix #644 2017-05-14 08:57:43 +02:00
James Cole
368df66947 New translations validation.php (Slovenian) 2017-05-14 08:40:06 +02:00
James Cole
9f9a3ea8fd New translations breadcrumbs.php (Slovenian) 2017-05-14 01:20:08 +02:00
James Cole
f66286105f New translations validation.php (Slovenian) 2017-05-14 01:20:07 +02:00
James Cole
0f0f912370 Partial JS focus [skip ci] 2017-05-12 06:21:26 +02:00
James Cole
9fa0e37a5d Merge pull request #641 from firefly-iii/l10n_develop
New Crowdin translations
2017-05-12 06:20:05 +02:00
James Cole
a0cb51ff70 Merge branch 'develop' into l10n_develop 2017-05-12 06:19:56 +02:00
James Cole
a6305ddea4 New translations auth.php (Spanish) 2017-05-10 20:40:44 +02:00
James Cole
fb8638fe6a New translations breadcrumbs.php (Spanish) 2017-05-10 20:40:42 +02:00
James Cole
0009f1f865 New translations csv.php (Spanish) 2017-05-10 20:40:41 +02:00
James Cole
d449c35025 New translations passwords.php (Spanish) 2017-05-10 20:40:39 +02:00
James Cole
1893d1a2c2 New translations demo.php (Spanish) 2017-05-10 20:40:37 +02:00
James Cole
0c4539e4fa New translations validation.php (Spanish) 2017-05-10 20:40:31 +02:00
James Cole
feacddd1d7 Merge pull request #645 from elamperti/unfinished-translations-es_ES
Unfinished translations for Spanish language
2017-05-10 20:36:55 +02:00
Enrico Lamperti
0c44fe6ce0 Add translations for Spanish language 2017-05-07 21:24:07 -03:00
James Cole
17fb6983d8 Fix issue #637 with cash accounts. 2017-05-07 19:45:40 +02:00
James Cole
5fb73bdb01 Fix bug #642 2017-05-07 19:24:53 +02:00
James Cole
7f082ea389 Remove focus thing 2017-05-06 10:20:27 +02:00
James Cole
9856a1831a New translations firefly.php (Slovenian) 2017-05-04 17:40:13 +02:00
James Cole
dd17a20b60 New translations firefly.php (Slovenian) 2017-05-04 17:30:12 +02:00
255 changed files with 9509 additions and 7542 deletions

View File

@@ -4,20 +4,64 @@
## Feature requests
If you are requesting a new feature, please check out the list of [often requested features](https://firefly-iii.github.io/requested-features/).
I am always interested in expanding Firefly III's many features. If you are requesting a new feature, please check out the list of [often requested features](https://firefly-iii.github.io/requested-features/).
## Bugs
If you find a bug, please take the time and see if the [demo site](https://firefly-iii.nder.be/) is also suffering from this bug. Include as many log files and details as you think are necessary.
First of all: thank you for reporting a bug instead of ditching the tool altogether. If you find a bug, please take the time and see if the [demo site](https://firefly-iii.nder.be/) is also suffering from this bug. Include as many log files and details as you think are necessary. Bugs have a lot of priority!
## Installation problems
Take the time to read the [installation guide FAQ](https://firefly-iii.github.io/installation-guide-faq/) and make sure you search through closed issues for the problems other people have had. Your problem may be among them!
Please take the time to read the [installation guide FAQ](https://firefly-iii.github.io/installation-guide-faq/) and make sure you search through closed issues for the problems other people have had. Your problem may be among them! If not, open an issue and I will help where I can.
## Pull requests
I can only accept pull requests against the `develop` branch, never the `master` branch.
When contributing to Firefly III, please first discuss the change you wish to make via issue, email, or any other method. I can only accept pull requests against the `develop` branch, never the `master` branch.
## Translations :us: :fr: :de:
If you see a spelling error, grammatical error or a weird translation in your language, please join [our CrowdIn](https://crowdin.com/project/firefly-iii) project. There, you can submit your translations and fixes. The GitHub repository will download these automatically and they will be included in the next release.
If you see a spelling error, grammatical error or a weird translation in your language, please join [our CrowdIn](https://crowdin.com/project/firefly-iii) project. There, you can submit your translations and fixes. The GitHub repository will download these automatically and they will be included in the next release.
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at thegrumpydictator@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org/), version 1.4, available at [http://contributor-covenant.org/version/1/4](http://contributor-covenant.org/version/1/4).

View File

@@ -16,7 +16,7 @@ install:
- php artisan optimize
- php artisan env
- cp .env.testing .env
- mv storage/database/databasecopy.sqlite storage/database/database.sqlite
- wget -q https://github.com/firefly-iii/test-data/raw/master/storage/database.sqlite -O storage/database/database.sqlite
- mkdir -p build/logs
script:

View File

@@ -2,6 +2,36 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [4.6.0] - 2017-06-28
### Changed
- Revamped import routine. Will be buggy.
### Fixed
- Issue #667, postgresql reported by @skibbipl.
- Issue #680 by @Xeli
- Fixed #660
- Fixes #672, reported by @dzaikos
- Translation error fixed by
- Fix a bug where the balance routine forgot to account for accounts without a currency preference.
- Various other bugfixes.
### Security
- Initial release.
## [4.5.0] - 2017-06-07
### Added
- Better support for multi-currency transactions and display of transactions, accounts and everything. This requires a database overhaul (moving the currency information to specific transactions) so be careful when upgrading.
- Translations for Spanish and Slovenian.
- New interface for budget page, ~~stolen from~~ inspired by YNAB.
- Expanded Docker to work with postgresql as well, thanks to @kressh
### Fixed
- PostgreSQL support in database upgrade routine (#644, reported by @skibbipl)
- Frontpage budget chart was off, fix by @nhaarman
- Was not possible to remove opening balance.
## [4.4.3] - 2017-05-03
### Added
- Added support for Slovenian

View File

@@ -11,13 +11,14 @@ RUN apt-get update -y && \
libtidy-dev \
libxml2-dev \
libsqlite3-dev \
libpq-dev \
libbz2-dev \
gettext-base \
locales && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install -j$(nproc) curl gd intl json mcrypt readline tidy zip bcmath xml mbstring pdo_sqlite pdo_mysql bz2
RUN docker-php-ext-install -j$(nproc) curl gd intl json mcrypt readline tidy zip bcmath xml mbstring pdo_sqlite pdo_mysql bz2 pdo_pgsql
# Generate locales supported by firefly
RUN echo "en_US.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

View File

@@ -12,11 +12,9 @@
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/firefly-iii/firefly-iii/tree/master)
Firefly III can be run on Heroku. Register for a free Heroku account and instantly run Firefly III on your very own cloud instance.
Firefly III can be run on Heroku. Register for a free Heroku account and instantly run Firefly III on your very own cloud instance. There is also a [demo site](https://firefly-iii.nder.be) with an example financial administration already present.
There is also a [demo site](https://firefly-iii.nder.be) with an example financial administration already present.
## Installation
## Getting started
To install Firefly III, you'll need a web server (preferrably on Linux) and access to the command line. Then, please read the [installation guide](https://firefly-iii.github.io/using-installing.html).
@@ -26,7 +24,7 @@ Personal financial management is pretty difficult, and everybody has their own a
Firefly works on the principle that if you know where you're money is going, you can stop it from going there.
#### Some advantages of using Firefly
### Some advantages of using Firefly
- 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", its just somebody elses computer!
@@ -35,6 +33,25 @@ Firefly works on the principle that if you know where you're money is going, you
Firefly is pretty awesome. [You can read more about Firefly III, and its features, on the Github Pages](https://firefly-iii.github.io/).
### Contributing
Please read [CONTRIBUTING.md](https://github.com/firefly-iii/firefly-iii/blob/master/.github/CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests.
### Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see [the tags](https://github.com/firefly-iii/firefly-iii/tags) on this repository.
### Authors
* James Cole
* Over time, [many people have contributed to Firefly III](https://github.com/firefly-iii/firefly-iii/graphs/contributors).
### License
This work [is licensed](https://github.com/firefly-iii/firefly-iii/blob/master/LICENSE) under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).
### Other stuff
If you like Firefly and if it helps you save lots of money, why not send me [a dime for every dollar saved](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UKUT455HUFA) (this is a joke, although the Paypal form works just fine, try it!)
If you want to contact me, please open an issue or [email me](mailto:thegrumpydictator@gmail.com).

View File

@@ -88,7 +88,7 @@ class CreateImport extends Command
$this->line('Stored import data...');
$job->configuration = $configurationData;
$job->status = 'settings_complete';
$job->status = 'configured';
$job->save();
$this->line('Stored configuration...');

View File

@@ -13,12 +13,13 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use FireflyIII\Import\ImportProcedure;
use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Import\Routine\ImportRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
/**
@@ -75,15 +76,18 @@ class Import extends Command
$monolog = Log::getMonolog();
$handler = new CommandHandler($this);
$monolog->pushHandler($handler);
$importProcedure = new ImportProcedure;
$result = $importProcedure->runImport($job);
// display result to user:
$this->presentResults($result);
$this->line('The import has completed.');
/** @var ImportRoutine $routine */
$routine = app(ImportRoutine::class);
$routine->setJob($job);
$routine->run();
// get any errors from the importer:
$this->presentErrors($job);
/** @var MessageBag $error */
foreach ($routine->errors as $index => $error) {
$this->error(sprintf('Error importing line #%d: %s', $index, $error));
}
$this->line(sprintf('The import has finished. %d transactions have been imported out of %d records.', $routine->journals->count(), $routine->lines));
return;
}
@@ -96,12 +100,14 @@ class Import extends Command
private function isValid(ImportJob $job): bool
{
if (is_null($job)) {
Log::error('This job does not seem to exist.');
$this->error('This job does not seem to exist.');
return false;
}
if ($job->status != 'settings_complete') {
if ($job->status !== 'configured') {
Log::error(sprintf('This job is not ready to be imported (status is %s).', $job->status));
$this->error('This job is not ready to be imported.');
return false;
@@ -109,36 +115,4 @@ class Import extends Command
return true;
}
/**
* @param ImportJob $job
*/
private function presentErrors(ImportJob $job)
{
$extendedStatus = $job->extended_status;
if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
$this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
foreach ($extendedStatus['errors'] as $error) {
$this->error($error);
}
}
}
/**
* @param Collection $result
*/
private function presentResults(Collection $result)
{
/**
* @var int $index
* @var TransactionJournal $journal
*/
foreach ($result as $index => $journal) {
if (!is_null($journal->id)) {
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
continue;
}
$this->error(sprintf('Could not store line #%d', $index));
}
}
}

View File

@@ -32,6 +32,7 @@ use Illuminate\Database\QueryException;
use Log;
use Preferences;
use Schema;
use Steam;
/**
* Class UpgradeDatabase
@@ -72,9 +73,54 @@ class UpgradeDatabase extends Command
$this->repairPiggyBanks();
$this->updateAccountCurrencies();
$this->updateJournalCurrencies();
$this->currencyInfoToTransactions();
$this->verifyCurrencyInfo();
$this->info('Firefly III database is up to date.');
}
/**
* Moves the currency id info to the transaction instead of the journal.
*/
private function currencyInfoToTransactions()
{
$count = 0;
$set = TransactionJournal::with('transactions')->get();
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
if (is_null($transaction->transaction_currency_id)) {
$transaction->transaction_currency_id = $journal->transaction_currency_id;
$transaction->save();
$count++;
}
}
// read and use the foreign amounts when present.
if ($journal->hasMeta('foreign_amount')) {
$amount = Steam::positive($journal->getMeta('foreign_amount'));
// update both transactions:
foreach ($journal->transactions as $transaction) {
$transaction->foreign_amount = $amount;
if (bccomp($transaction->amount, '0') === -1) {
// update with negative amount:
$transaction->foreign_amount = bcmul($amount, '-1');
}
// set foreign currency id:
$transaction->foreign_currency_id = intval($journal->getMeta('foreign_currency_id'));
$transaction->save();
}
$journal->deleteMeta('foreign_amount');
$journal->deleteMeta('foreign_currency_id');
}
}
$this->line(sprintf('Updated currency information for %d transactions', $count));
}
/**
* Migrate budget repetitions to new format.
*/
@@ -269,9 +315,11 @@ class UpgradeDatabase extends Command
$repository = app(CurrencyRepositoryInterface::class);
$notification = '%s #%d uses %s but should use %s. It has been updated. Please verify this in Firefly III.';
$transfer = 'Transfer #%d has been updated to use the correct currencies. Please verify this in Firefly III.';
$driver = DB::connection()->getDriverName();
$pgsql = ['pgsql', 'postgresql'];
foreach ($types as $type => $operator) {
$set = TransactionJournal
$query = TransactionJournal
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->leftJoin(
'transactions', function (JoinClause $join) use ($operator) {
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', $operator, '0');
@@ -280,9 +328,15 @@ class UpgradeDatabase extends Command
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
->where('transaction_types.type', $type)
->where('account_meta.name', 'currency_id')
->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data'))
->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']);
->where('account_meta.name', 'currency_id');
if (in_array($driver, $pgsql)) {
$query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('cast(account_meta.data as int)'));
}
if (!in_array($driver, $pgsql)) {
$query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data'));
}
$set = $query->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']);
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
$expectedCurrency = $repository->find(intval($journal->expected_currency_id));
@@ -334,4 +388,25 @@ class UpgradeDatabase extends Command
}
}
}
/**
*
*/
private function verifyCurrencyInfo()
{
$count = 0;
$transactions = Transaction::get();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$currencyId = intval($transaction->transaction_currency_id);
$foreignId = intval($transaction->foreign_currency_id);
if ($currencyId === $foreignId) {
$transaction->foreign_currency_id = null;
$transaction->foreign_amount = null;
$transaction->save();
$count++;
}
}
$this->line(sprintf('Updated currency information for %d transactions', $count));
}
}

View File

@@ -26,9 +26,9 @@ class StoredTransactionJournal extends Event
use SerializesModels;
/** @var TransactionJournal */
/** @var TransactionJournal */
public $journal;
/** @var int */
/** @var int */
public $piggyBankId;
/**

View File

@@ -26,7 +26,7 @@ class UpdatedTransactionJournal extends Event
use SerializesModels;
/** @var TransactionJournal */
/** @var TransactionJournal */
public $journal;
/**

View File

@@ -303,7 +303,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('accounts AS opposing_accounts', 'opposing.account_id', '=', 'opposing_accounts.id')
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', 'transaction_types.id')
->leftJoin('transaction_currencies', 'transaction_journals.transaction_currency_id', '=', 'transaction_currencies.id')
->leftJoin('transaction_currencies', 'transactions.transaction_currency_id', '=', 'transaction_currencies.id')
->whereIn('transactions.account_id', $accountIds)
->where('transaction_journals.user_id', $this->job->user_id)
->where('transaction_journals.date', '>=', $this->start->format('Y-m-d'))
@@ -338,7 +338,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
'transaction_journals.encrypted as journal_encrypted',
'transaction_journals.transaction_type_id',
'transaction_types.type as transaction_type',
'transaction_journals.transaction_currency_id',
'transactions.transaction_currency_id',
'transaction_currencies.code AS transaction_currency_code',
]

View File

@@ -112,7 +112,7 @@ class ChartJsGenerator implements GeneratorInterface
// sort by value, keep keys.
asort($data);
$index = 0;
$index = 0;
foreach ($data as $key => $value) {
// make larger than 0

View File

@@ -22,10 +22,15 @@ interface GeneratorInterface
{
/**
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
* Will generate a Chart JS compatible array from the given input. Expects this format
*
* Will take labels for all from first set.
*
* 0: [
* 'label' => 'label of set',
* 'type' => bar or line, optional
* 'yAxisID' => ID of yAxis, optional, will not be included when unused.
* 'fill' => if to fill a line? optional, will not be included when unused.
* 'entries' =>
* [
* 'label-of-entry' => 'value'
@@ -33,12 +38,16 @@ interface GeneratorInterface
* ]
* 1: [
* 'label' => 'label of another set',
* 'type' => bar or line, optional
* 'yAxisID' => ID of yAxis, optional, will not be included when unused.
* 'fill' => if to fill a line? optional, will not be included when unused.
* 'entries' =>
* [
* 'label-of-entry' => 'value'
* ]
* ]
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five.
*
* @param array $data
*

View File

@@ -19,6 +19,7 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Steam;
@@ -147,6 +148,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
private function getAuditReport(Account $account, Carbon $date): array
{
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -155,15 +158,21 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals = $journals->reverse();
$dayBeforeBalance = Steam::balance($account, $date);
$startBalance = $dayBeforeBalance;
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
/** @var Transaction $journal */
foreach ($journals as $transaction) {
$transaction->before = $startBalance;
$transactionAmount = $transaction->transaction_amount;
$newBalance = bcadd($startBalance, $transactionAmount);
$transaction->after = $newBalance;
$startBalance = $newBalance;
$transactionAmount = $transaction->transaction_amount;
if ($currency->id === $transaction->foreign_currency_id) {
$transactionAmount = $transaction->transaction_foreign_amount;
}
$newBalance = bcadd($startBalance, $transactionAmount);
$transaction->after = $newBalance;
$startBalance = $newBalance;
$transaction->currency = $currency;
}
/*

View File

@@ -15,7 +15,6 @@ namespace FireflyIII\Generator\Report;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**

View File

@@ -14,6 +14,7 @@ namespace FireflyIII\Generator\Report\Tag;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
@@ -30,7 +31,7 @@ use Log;
*
* @package FireflyIII\Generator\Report\Tag
*/
class MonthReportGenerator implements ReportGeneratorInterface
class MonthReportGenerator extends Support implements ReportGeneratorInterface
{
/** @var Collection */

View File

@@ -42,6 +42,10 @@ class StoredJournalEventHandler
/**
* StoredJournalEventHandler constructor.
*
* @param PRI $repository
* @param JRI $journalRepository
* @param RGRI $ruleGroupRepository
*/
public function __construct(PRI $repository, JRI $journalRepository, RGRI $ruleGroupRepository)
{

View File

@@ -23,7 +23,7 @@ use FireflyIII\Support\Events\BillScanner;
/**
* @codeCoverageIgnore
*
*
* Class UpdatedJournalEventHandler
*
* @package FireflyIII\Handlers\Events
@@ -35,6 +35,8 @@ class UpdatedJournalEventHandler
/**
* StoredJournalEventHandler constructor.
*
* @param RuleGroupRepositoryInterface $ruleGroupRepository
*/
public function __construct(RuleGroupRepositoryInterface $ruleGroupRepository)
{
@@ -52,7 +54,7 @@ class UpdatedJournalEventHandler
{
// get all the user's rule groups, with the rules, order by 'order'.
$journal = $updatedJournalEvent->journal;
$groups = $this->repository->getActiveGroups($journal->user);
$groups = $this->repository->getActiveGroups($journal->user);
/** @var RuleGroup $group */
foreach ($groups as $group) {

View File

@@ -74,6 +74,7 @@ class UserEventHandler
} catch (Swift_TransportException $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
@@ -96,16 +97,17 @@ class UserEventHandler
}
// get the email address
$email = $event->user->email;
$address = route('index');
$uri = route('index');
$ipAddress = $event->ipAddress;
// send email.
try {
Mail::to($email)->send(new RegisteredUserMail($address, $ipAddress));
Mail::to($email)->send(new RegisteredUserMail($uri, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Swift_TransportException $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;

View File

@@ -18,9 +18,10 @@ use FireflyIII\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
use Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Log;
/**
* Class AttachmentHelper
*
@@ -157,11 +158,14 @@ class AttachmentHelper implements AttachmentHelperInterface
$attachment->size = $file->getSize();
$attachment->uploaded = 0;
$attachment->save();
Log::debug('Created attachment:', $attachment->toArray());
$fileObject = $file->openFile('r');
$fileObject->rewind();
$content = $fileObject->fread($file->getSize());
$encrypted = Crypt::encrypt($content);
Log::debug(sprintf('Full file length is %d and upload size is %d.', strlen($content), $file->getSize()));
Log::debug(sprintf('Encrypted content is %d', strlen($encrypted)));
// store it:
$this->uploadDisk->put($attachment->fileName(), $encrypted);
@@ -202,6 +206,7 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* @codeCoverageIgnore
*
* @param UploadedFile $file
*
* @return bool

View File

@@ -60,17 +60,30 @@ class JournalCollector implements JournalCollectorInterface
'transaction_journals.description',
'transaction_journals.date',
'transaction_journals.encrypted',
'transaction_currencies.code as transaction_currency_code',
'transaction_types.type as transaction_type_type',
'transaction_journals.bill_id',
'bills.name as bill_name',
'bills.name_encrypted as bill_name_encrypted',
'transactions.id as id',
'transactions.amount as transaction_amount',
'transactions.description as transaction_description',
'transactions.account_id',
'transactions.identifier',
'transactions.transaction_journal_id',
'transactions.amount as transaction_amount',
'transactions.transaction_currency_id as transaction_currency_id',
'transaction_currencies.code as transaction_currency_code',
'transaction_currencies.symbol as transaction_currency_symbol',
'transaction_currencies.decimal_places as transaction_currency_dp',
'transactions.foreign_amount as transaction_foreign_amount',
'transactions.foreign_currency_id as foreign_currency_id',
'foreign_currencies.code as foreign_currency_code',
'foreign_currencies.symbol as foreign_currency_symbol',
'foreign_currencies.decimal_places as foreign_currency_dp',
'accounts.name as account_name',
'accounts.encrypted as account_encrypted',
'account_types.type as account_type',
@@ -484,11 +497,12 @@ class JournalCollector implements JournalCollectorInterface
Log::debug('journalCollector::startQuery');
/** @var EloquentBuilder $query */
$query = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transaction_journals.transaction_currency_id')
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transactions.transaction_currency_id')
->leftJoin('transaction_currencies as foreign_currencies', 'foreign_currencies.id', 'transactions.foreign_currency_id')
->whereNull('transactions.deleted_at')
->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id)

View File

@@ -26,7 +26,7 @@ use Log;
*/
class InternalTransferFilter implements FilterInterface
{
/** @var array */
/** @var array */
private $accounts = [];
/**

View File

@@ -187,7 +187,7 @@ class PopupReport implements PopupReportInterface
$journals = $journals->filter(
function (Transaction $transaction) use ($report) {
// get the destinations:
$destinations = $transaction->destinationAccountList($transaction->transactionJournal)->pluck('id')->toArray();
$destinations = $transaction->transactionJournal->destinationAccountList()->pluck('id')->toArray();
// do these intersect with the current list?
return !empty(array_intersect($report, $destinations));

View File

@@ -219,8 +219,8 @@ class AccountController extends Controller
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$startBalances = Steam::balancesByAccounts($accounts, $start);
$endBalances = Steam::balancesByAccounts($accounts, $end);
$activities = Steam::getLastActivities($ids);
$accounts->each(
@@ -293,8 +293,8 @@ class AccountController extends Controller
$periods = $this->getPeriodOverview($account);
}
$count = 0;
$loop = 0;
$count = 0;
$loop = 0;
// grab journals, but be prepared to jump a period back to get the right ones:
Log::info('Now at loop start.');
while ($count === 0 && $loop < 3) {

View File

@@ -98,10 +98,14 @@ class AttachmentController extends Controller
*/
public function download(AttachmentRepositoryInterface $repository, Attachment $attachment)
{
if ($repository->exists($attachment)) {
$content = $repository->getContent($attachment);
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
/** @var LaravelResponse $response */
$response = response($content, 200);
$response
@@ -149,6 +153,7 @@ class AttachmentController extends Controller
{
$image = 'images/page_green.png';
if ($attachment->mime == 'application/pdf') {
$image = 'images/page_white_acrobat.png';
}

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
use Amount;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Http\Requests\BudgetFormRequest;
@@ -166,16 +167,38 @@ class BudgetController extends Controller
}
/**
* @param string|null $moment
*
* @return View
*/
public function index()
public function index(string $moment = null)
{
$range = Preferences::get('viewRange', '1M')->data;
$start = session('start', new Carbon);
$end = session('end', new Carbon);
// make date if present:
if (!is_null($moment) || strlen(strval($moment)) !== 0) {
try {
$start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range);
} catch (Exception $e) {
// start and end are already defined.
}
}
$next = clone $end;
$next->addDay();
$prev = clone $start;
$prev->subDay();
$prev = Navigation::startOfPeriod($prev, $range);
$this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets();
$inactive = $this->repository->getInactiveBudgets();
$start = session('start', new Carbon);
$end = session('end', new Carbon);
$periodStart = $start->formatLocalized($this->monthAndDayFormat);
$periodEnd = $end->formatLocalized($this->monthAndDayFormat);
$budgetInformation = $this->collectBudgetInformation($budgets, $start, $end);
@@ -184,9 +207,44 @@ class BudgetController extends Controller
$spent = array_sum(array_column($budgetInformation, 'spent'));
$budgeted = array_sum(array_column($budgetInformation, 'budgeted'));
// select thing for last 12 periods:
$previousLoop = [];
$previousDate = clone $start;
$count = 0;
while ($count < 12) {
$previousDate->subDay();
$previousDate = Navigation::startOfPeriod($previousDate, $range);
$format = $previousDate->format('Y-m-d');
$previousLoop[$format] = Navigation::periodShow($previousDate, $range);
$count++;
}
// select thing for next 12 periods:
$nextLoop = [];
$nextDate = clone $end;
$nextDate->addDay();
$count = 0;
while ($count < 12) {
$format = $nextDate->format('Y-m-d');
$nextLoop[$format] = Navigation::periodShow($nextDate, $range);
$nextDate = Navigation::endOfPeriod($nextDate, $range);
$count++;
$nextDate->addDay();
}
// display info
$currentMonth = Navigation::periodShow($start, $range);
$nextText = Navigation::periodShow($next, $range);
$prevText = Navigation::periodShow($prev, $range);
return view(
'budgets.index',
compact('available', 'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets', 'spent', 'budgeted')
compact(
'available', 'currentMonth', 'next', 'nextText', 'prev', 'prevText',
'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets',
'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start'
)
);
}

View File

@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
@@ -115,9 +114,8 @@ class AccountController extends Controller
$start->subDay();
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
$ids = $accounts->pluck('id')->toArray();
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$startBalances = Steam::balancesByAccounts($accounts, $start);
$endBalances = Steam::balancesByAccounts($accounts, $end);
$chartData = [];
foreach ($accounts as $account) {
@@ -129,6 +127,7 @@ class AccountController extends Controller
$chartData[$account->name] = $diff;
}
}
arsort($chartData);
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
$cache->store($data);
@@ -336,7 +335,7 @@ class AccountController extends Controller
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $start
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
@@ -411,9 +410,8 @@ class AccountController extends Controller
$accounts = $repository->getAccountsByType([AccountType::REVENUE]);
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$startBalances = Steam::balancesByAccounts($accounts, $start);
$endBalances = Steam::balancesByAccounts($accounts, $end);
foreach ($accounts as $account) {
$id = $account->id;
@@ -427,7 +425,7 @@ class AccountController extends Controller
}
arsort($chartData);
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $chartData);
$data = $this->generator->singleSet(strval(trans('firefly.earned')), $chartData);
$cache->store($data);
return Response::json($data);

View File

@@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
use Navigation;
use Preferences;
use Response;
use Steam;
/**
* Class BudgetController
@@ -320,12 +321,12 @@ class BudgetController extends Controller
['label' => strval(trans('firefly.overspent')), 'entries' => [], 'type' => 'bar',],
];
/** @var Budget $budget */
foreach ($budgets as $budget) {
// get relevant repetitions:
$limits = $this->repository->getBudgetLimits($budget, $start, $end);
$expenses = $this->getExpensesForBudget($limits, $budget, $start, $end);
foreach ($expenses as $name => $row) {
$chartData[0]['entries'][$name] = $row['spent'];
$chartData[1]['entries'][$name] = $row['left'];
@@ -529,9 +530,7 @@ class BudgetController extends Controller
$rows = $this->spentInPeriodMulti($budget, $limits);
foreach ($rows as $name => $row) {
if (bccomp($row['spent'], '0') !== 0 || bccomp($row['left'], '0') !== 0) {
$return[$name]['spent'] = bcmul($row['spent'], '-1');
$return[$name]['left'] = $row['left'];
$return[$name]['overspent'] = bcmul($row['overspent'], '-1');
$return[$name] = $row;
}
}
unset($rows, $row);
@@ -563,6 +562,7 @@ class BudgetController extends Controller
/** @var BudgetLimit $budgetLimit */
foreach ($limits as $budgetLimit) {
$expenses = $this->repository->spentInPeriod(new Collection([$budget]), new Collection, $budgetLimit->start_date, $budgetLimit->end_date);
$expenses = Steam::positive($expenses);
if ($limits->count() > 1) {
$name = $budget->name . ' ' . trans(
@@ -578,10 +578,14 @@ class BudgetController extends Controller
* left: amount of budget limit min spent, or 0 when < 0.
* spent: spent, or amount of budget limit when > amount
*/
$amount = $budgetLimit->amount;
$left = bccomp(bcadd($amount, $expenses), '0') < 1 ? '0' : bcadd($amount, $expenses);
$spent = bccomp($expenses, $amount) === 1 ? $expenses : bcmul($amount, '-1');
$overspent = bccomp(bcadd($amount, $expenses), '0') < 1 ? bcadd($amount, $expenses) : '0';
$amount = $budgetLimit->amount;
$leftInLimit = bcsub($amount, $expenses);
$hasOverspent = bccomp($leftInLimit, '0') === -1;
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
$spent = $hasOverspent ? $amount : $expenses;
$overspent = $hasOverspent ? Steam::positive($leftInLimit) : '0';
$return[$name] = [
'left' => $left,
'overspent' => $overspent,

View File

@@ -277,10 +277,10 @@ class CategoryController extends Controller
*/
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, Carbon $date)
{
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($date, $range);
$end = Navigation::endOfPeriod($date, $range);
$data = $this->makePeriodChart($repository, $category, $start, $end);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($date, $range);
$end = Navigation::endOfPeriod($date, $range);
$data = $this->makePeriodChart($repository, $category, $start, $end);
return Response::json($data);
}
@@ -336,9 +336,9 @@ class CategoryController extends Controller
$sum = bcadd($spent, $earned);
$label = trim(Navigation::periodShow($start, '1D'));
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'),12);
$chartData[1]['entries'][$label] = round($earned,12);
$chartData[2]['entries'][$label] = round($sum,12);
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12);
$chartData[2]['entries'][$label] = round($sum, 12);
$start->addDay();

View File

@@ -16,7 +16,6 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;

View File

@@ -67,11 +67,10 @@ class ReportController extends Controller
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$ids = $accounts->pluck('id')->toArray();
$current = clone $start;
$chartData = [];
while ($current < $end) {
$balances = Steam::balancesById($ids, $current);
$balances = Steam::balancesByAccounts($accounts, $current);
$sum = $this->arraySum($balances);
$label = $current->formatLocalized(strval(trans('config.month_and_day')));
$chartData[$label] = $sum;
@@ -104,7 +103,7 @@ class ReportController extends Controller
$cache->addProperty($accounts);
$cache->addProperty($end);
if ($cache->has()) {
//return Response::json($cache->get()); // @codeCoverageIgnore
return Response::json($cache->get()); // @codeCoverageIgnore
}
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
$format = Navigation::preferredCarbonLocalizedFormat($start, $end);
@@ -250,7 +249,7 @@ class ReportController extends Controller
$cache->addProperty($accounts);
$cache->addProperty($end);
if ($cache->has()) {
// return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
$currentStart = clone $start;

View File

@@ -12,32 +12,29 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Crypt;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\ImportUploadRequest;
use FireflyIII\Import\ImportProcedureInterface;
use FireflyIII\Import\Setup\SetupInterface;
use FireflyIII\Import\Configurator\ConfiguratorInterface;
use FireflyIII\Import\Routine\ImportRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Http\Response as LaravelResponse;
use Log;
use Response;
use Session;
use SplFileObject;
use Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use View;
/**
* Class ImportController
* Class ImportController.
*
* @package FireflyIII\Http\Controllers
*/
class ImportController extends Controller
{
/** @var ImportJobRepositoryInterface */
public $repository;
/**
*
*/
@@ -48,7 +45,8 @@ class ImportController extends Controller
$this->middleware(
function ($request, $next) {
View::share('mainTitleIcon', 'fa-archive');
View::share('title', trans('firefly.import_data_full'));
View::share('title', trans('firefly.import_index_title'));
$this->repository = app(ImportJobRepositoryInterface::class);
return $next($request);
}
@@ -56,28 +54,7 @@ class ImportController extends Controller
}
/**
* This is the last step before the import starts.
*
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function complete(ImportJob $job)
{
Log::debug('Now in complete()', ['job' => $job->key]);
if (!$this->jobInCorrectStep($job, 'complete')) {
return $this->redirectToCorrectStep($job);
}
$subTitle = trans('firefly.import_complete');
$subTitleIcon = 'fa-star';
return view('import.complete', compact('job', 'subTitle', 'subTitleIcon'));
}
/**
* This is step 3.
* This is the first step in configuring the job. It can only be executed
* when the job is set to "import_status_never_started".
* This is step 3. This repeats until the job is configured.
*
* @param ImportJob $job
*
@@ -86,37 +63,43 @@ class ImportController extends Controller
*/
public function configure(ImportJob $job)
{
Log::debug('Now at start of configure()');
if (!$this->jobInCorrectStep($job, 'configure')) {
return $this->redirectToCorrectStep($job);
}
// create configuration class:
$configurator = $this->makeConfigurator($job);
// actual code
$importer = $this->makeImporter($job);
$importer->configure();
$data = $importer->getConfigurationData();
$subTitle = trans('firefly.configure_import');
// is the job already configured?
if ($configurator->isJobConfigured()) {
$this->repository->updateStatus($job, 'configured');
return redirect(route('import.status', [$job->key]));
}
$view = $configurator->getNextView();
$data = $configurator->getNextData();
$subTitle = trans('firefly.import_config_bread_crumb');
$subTitleIcon = 'fa-wrench';
return view('import.' . $job->file_type . '.configure', compact('data', 'job', 'subTitle', 'subTitleIcon'));
return view($view, compact('data', 'job', 'subTitle', 'subTitleIcon'));
}
/**
* Generate a JSON file of the job's config and send it to the user.
* Generate a JSON file of the job's configuration and send it to the user.
*
* @param ImportJob $job
*
* @return mixed
* @return LaravelResponse
*/
public function download(ImportJob $job)
{
Log::debug('Now in download()', ['job' => $job->key]);
$config = $job->configuration;
$config = $job->configuration;
// TODO this is CSV import specific:
$config['column-roles-complete'] = false;
$config['column-mapping-complete'] = false;
$config['initial-config-complete'] = false;
$config['delimiter'] = $config['delimiter'] === "\t" ? 'tab' : $config['delimiter'];
$result = json_encode($config, JSON_PRETTY_PRINT);
$name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
$result = json_encode($config, JSON_PRETTY_PRINT);
$name = sprintf('"%s"', addcslashes('import-configuration-' . date('Y-m-d') . '.json', '"\\'));
/** @var LaravelResponse $response */
$response = response($result, 200);
@@ -134,26 +117,6 @@ class ImportController extends Controller
}
/**
* @param ImportJob $job
*
* @return View
*/
public function finished(ImportJob $job)
{
if (!$this->jobInCorrectStep($job, 'finished')) {
return $this->redirectToCorrectStep($job);
}
// if there is a tag (there might not be), we can link to it:
$tagId = $job->extended_status['importTag'] ?? 0;
$subTitle = trans('firefly.import_finished');
$subTitleIcon = 'fa-star';
return view('import.finished', compact('job', 'subTitle', 'subTitleIcon', 'tagId'));
}
/**
* This is step 1. Upload a file.
*
@@ -161,8 +124,7 @@ class ImportController extends Controller
*/
public function index()
{
Log::debug('Now at index');
$subTitle = trans('firefly.import_data_index');
$subTitle = trans('firefly.import_index_sub_title');
$subTitleIcon = 'fa-home';
$importFileTypes = [];
$defaultImportType = config('firefly.default_import_format');
@@ -175,42 +137,75 @@ class ImportController extends Controller
}
/**
* This is step 2. It creates an Import Job. Stores the import.
*
* @param ImportUploadRequest $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function initialize(ImportUploadRequest $request)
{
Log::debug('Now in initialize()');
// create import job:
$type = $request->get('import_file_type');
$job = $this->repository->create($type);
Log::debug('Created new job', ['key' => $job->key, 'id' => $job->id]);
// process file:
$this->repository->processFile($job, $request->files->get('import_file'));
// process config, if present:
if ($request->files->has('configuration_file')) {
$this->repository->processConfiguration($job, $request->files->get('configuration_file'));
}
$this->repository->updateStatus($job, 'initialized');
return redirect(route('import.configure', [$job->key]));
}
/**
*
* Show status of import job in JSON.
*
* @param ImportJob $job
*
* @return \Illuminate\Http\JsonResponse
*/
public function json(ImportJob $job)
{
$result = [
'showPercentage' => false,
'started' => false,
'finished' => false,
'running' => false,
'errors' => $job->extended_status['errors'],
'percentage' => 0,
'steps' => $job->extended_status['total_steps'],
'stepsDone' => $job->extended_status['steps_done'],
'statusText' => trans('firefly.import_status_' . $job->status),
'finishedText' => '',
$result = [
'started' => false,
'finished' => false,
'running' => false,
'errors' => array_values($job->extended_status['errors']),
'percentage' => 0,
'show_percentage' => false,
'steps' => $job->extended_status['steps'],
'done' => $job->extended_status['done'],
'statusText' => trans('firefly.import_status_job_' . $job->status),
'status' => $job->status,
'finishedText' => '',
];
$percentage = 0;
if ($job->extended_status['total_steps'] !== 0) {
$percentage = round(($job->extended_status['steps_done'] / $job->extended_status['total_steps']) * 100, 0);
if ($job->extended_status['steps'] !== 0) {
$result['percentage'] = round(($job->extended_status['done'] / $job->extended_status['steps']) * 100, 0);
$result['show_percentage'] = true;
}
if ($job->status === 'import_complete') {
$tagId = $job->extended_status['importTag'];
if ($job->status === 'finished') {
$tagId = $job->extended_status['tag'];
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$tag = $repository->find($tagId);
$result['finished'] = true;
$result['finishedText'] = trans('firefly.import_finished_link', ['link' => route('tags.show', [$tag->id]), 'tag' => $tag->tag]);
$result['finishedText'] = trans('firefly.import_status_finished_job', ['link' => route('tags.show', [$tag->id, 'all']), 'tag' => $tag->tag]);
}
if ($job->status === 'import_running') {
$result['started'] = true;
$result['running'] = true;
$result['showPercentage'] = true;
$result['percentage'] = $percentage;
if ($job->status === 'running') {
$result['started'] = true;
$result['running'] = true;
}
return Response::json($result);
@@ -219,286 +214,82 @@ class ImportController extends Controller
/**
* Step 4. Save the configuration.
*
* @param Request $request
* @param ImportJobRepositoryInterface $repository
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function postConfigure(Request $request, ImportJobRepositoryInterface $repository, ImportJob $job)
{
Log::debug('Now in postConfigure()', ['job' => $job->key]);
if (!$this->jobInCorrectStep($job, 'process')) {
return $this->redirectToCorrectStep($job);
}
Log::debug('Continue postConfigure()', ['job' => $job->key]);
// actual code
$importer = $this->makeImporter($job);
$data = $request->all();
$files = $request->files;
$importer->saveImportConfiguration($data, $files);
// update job:
$repository->updateStatus($job, 'import_configuration_saved');
// return redirect to settings.
// this could loop until the user is done.
return redirect(route('import.settings', [$job->key]));
}
/**
* This step 6. Depending on the importer, this will process the
* settings given and store them.
*
* @param Request $request
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws FireflyException
*/
public function postSettings(Request $request, ImportJob $job)
public function postConfigure(Request $request, ImportJob $job)
{
Log::debug('Now in postSettings()', ['job' => $job->key]);
if (!$this->jobInCorrectStep($job, 'store-settings')) {
return $this->redirectToCorrectStep($job);
}
$importer = $this->makeImporter($job);
$importer->storeSettings($request);
// return redirect to settings (for more settings perhaps)
return redirect(route('import.settings', [$job->key]));
}
/**
* Step 5. Depending on the importer, this will show the user settings to
* fill in.
*
* @param ImportJobRepositoryInterface $repository
* @param ImportJob $job
*
* @return View
*/
public function settings(ImportJobRepositoryInterface $repository, ImportJob $job)
{
Log::debug('Now in settings()', ['job' => $job->key]);
if (!$this->jobInCorrectStep($job, 'settings')) {
return $this->redirectToCorrectStep($job);
}
Log::debug('Continue in settings()');
$importer = $this->makeImporter($job);
$subTitle = trans('firefly.settings_for_import');
$subTitleIcon = 'fa-wrench';
// now show settings screen to user.
if ($importer->requireUserSettings()) {
Log::debug('Job requires user config.');
$data = $importer->getDataForSettings();
$view = $importer->getViewForSettings();
return view($view, compact('data', 'job', 'subTitle', 'subTitleIcon'));
}
Log::debug('Job does NOT require user config.');
$repository->updateStatus($job, 'settings_complete');
// if no more settings, save job and continue to process thing.
return redirect(route('import.complete', [$job->key]));
// ask the importer for the requested action.
// for example pick columns or map data.
// depends of course on the data in the job.
}
/**
* @param ImportProcedureInterface $importProcedure
* @param ImportJob $job
*/
public function start(ImportProcedureInterface $importProcedure, ImportJob $job)
{
set_time_limit(0);
if ($job->status == 'settings_complete') {
$importProcedure->runImport($job);
}
}
/**
* This is the last step before the import starts.
*
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function status(ImportJob $job)
{ //
Log::debug('Now in status()', ['job' => $job->key]);
if (!$this->jobInCorrectStep($job, 'status')) {
return $this->redirectToCorrectStep($job);
}
$subTitle = trans('firefly.import_status');
$subTitleIcon = 'fa-star';
return view('import.status', compact('job', 'subTitle', 'subTitleIcon'));
}
/**
* This is step 2. It creates an Import Job. Stores the import.
*
* @param ImportUploadRequest $request
* @param ImportJobRepositoryInterface $repository
* @param UserRepositoryInterface $userRepository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function upload(ImportUploadRequest $request, ImportJobRepositoryInterface $repository, UserRepositoryInterface $userRepository)
{
Log::debug('Now in upload()');
// create import job:
$type = $request->get('import_file_type');
$job = $repository->create($type);
Log::debug('Created new job', ['key' => $job->key, 'id' => $job->id]);
/** @var UploadedFile $upload */
$upload = $request->files->get('import_file');
$newName = $job->key . '.upload';
$uploaded = new SplFileObject($upload->getRealPath());
$content = $uploaded->fread($uploaded->getSize());
$contentEncrypted = Crypt::encrypt($content);
$disk = Storage::disk('upload');
// user is demo user, replace upload with prepared file.
if ($userRepository->hasRole(auth()->user(), 'demo')) {
$stubsDisk = Storage::disk('stubs');
$content = $stubsDisk->get('demo-import.csv');
$contentEncrypted = Crypt::encrypt($content);
$disk->put($newName, $contentEncrypted);
Log::debug('Replaced upload with demo file.');
// also set up prepared configuration.
$configuration = json_decode($stubsDisk->get('demo-configuration.json'), true);
$repository->setConfiguration($job, $configuration);
Log::debug('Set configuration for demo user', $configuration);
// also flash info
Session::flash('info', trans('demo.import-configure-security'));
}
if (!$userRepository->hasRole(auth()->user(), 'demo')) {
// user is not demo, process original upload:
$disk->put($newName, $contentEncrypted);
Log::debug('Uploaded file', ['name' => $upload->getClientOriginalName(), 'size' => $upload->getSize(), 'mime' => $upload->getClientMimeType()]);
}
// store configuration file's content into the job's configuration thing. Otherwise, leave it empty.
// demo user's configuration upload is ignored completely.
if ($request->files->has('configuration_file') && !auth()->user()->hasRole('demo')) {
/** @var UploadedFile $configFile */
$configFile = $request->files->get('configuration_file');
Log::debug(
'Uploaded configuration file',
['name' => $configFile->getClientOriginalName(), 'size' => $configFile->getSize(), 'mime' => $configFile->getClientMimeType()]
);
$configFileObject = new SplFileObject($configFile->getRealPath());
$configRaw = $configFileObject->fread($configFileObject->getSize());
$configuration = json_decode($configRaw, true);
// @codeCoverageIgnoreStart
if (!is_null($configuration) && is_array($configuration)) {
Log::debug('Found configuration', $configuration);
$repository->setConfiguration($job, $configuration);
}
// @codeCoverageIgnoreEnd
Log::debug('Now in postConfigure()', ['job' => $job->key]);
$configurator = $this->makeConfigurator($job);
// is the job already configured?
if ($configurator->isJobConfigured()) {
return redirect(route('import.status', [$job->key]));
}
$data = $request->all();
$configurator->configureJob($data);
// return to configure
return redirect(route('import.configure', [$job->key]));
}
/**
* @param ImportJob $job
* @param string $method
*
* @return bool
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
*/
private function jobInCorrectStep(ImportJob $job, string $method): bool
public function start(ImportJob $job)
{
Log::debug('Now in jobInCorrectStep()', ['job' => $job->key, 'method' => $method]);
switch ($method) {
case 'configure':
case 'process':
return $job->status === 'import_status_never_started';
case 'settings':
case 'store-settings':
Log::debug(sprintf('Job %d with key %s has status %s', $job->id, $job->key, $job->status));
return $job->status === 'import_configuration_saved';
case 'finished':
return $job->status === 'import_complete';
case 'complete':
return $job->status === 'settings_complete';
case 'status':
return ($job->status === 'settings_complete') || ($job->status === 'import_running');
/** @var ImportRoutine $routine */
$routine = app(ImportRoutine::class);
$routine->setJob($job);
$result = $routine->run();
if ($result) {
return Response::json(['run' => 'ok']);
}
return false; // @codeCoverageIgnore
throw new FireflyException('Job did not complete succesfully.');
}
/**
* @param ImportJob $job
*
* @return SetupInterface
* @throws FireflyException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
private function makeImporter(ImportJob $job): SetupInterface
public function status(ImportJob $job)
{
// create proper importer (depends on job)
$type = strtolower($job->file_type);
// validate type:
$validTypes = array_keys(config('firefly.import_formats'));
if (in_array($type, $validTypes)) {
/** @var SetupInterface $importer */
$importer = app('FireflyIII\Import\Setup\\' . ucfirst($type) . 'Setup');
$importer->setJob($job);
return $importer;
$statuses = ['configured', 'running', 'finished'];
if (!in_array($job->status, $statuses)) {
return redirect(route('import.configure', [$job->key]));
}
throw new FireflyException(sprintf('"%s" is not a valid file type', $type)); // @codeCoverageIgnore
$subTitle = trans('firefly.import_status_sub_title');
$subTitleIcon = 'fa-star';
return view('import.status', compact('job', 'subTitle', 'subTitleIcon'));
}
/**
* @param ImportJob $job
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return ConfiguratorInterface
* @throws FireflyException
*/
private function redirectToCorrectStep(ImportJob $job)
private function makeConfigurator(ImportJob $job): ConfiguratorInterface
{
Log::debug('Now in redirectToCorrectStep()', ['job' => $job->key]);
switch ($job->status) {
case 'import_status_never_started':
Log::debug('Will redirect to configure()');
return redirect(route('import.configure', [$job->key]));
case 'import_configuration_saved':
Log::debug('Will redirect to settings()');
return redirect(route('import.settings', [$job->key]));
case 'settings_complete':
Log::debug('Will redirect to complete()');
return redirect(route('import.complete', [$job->key]));
case 'import_complete':
Log::debug('Will redirect to finished()');
return redirect(route('import.finished', [$job->key]));
$type = $job->file_type;
$key = sprintf('firefly.import_configurators.%s', $type);
$className = config($key);
if (is_null($className)) {
throw new FireflyException('Cannot find configurator class for this job.'); // @codeCoverageIgnore
}
/** @var ConfiguratorInterface $configurator */
$configurator = app($className);
$configurator->setJob($job);
throw new FireflyException('Cannot redirect for job state ' . $job->status); // @codeCoverageIgnore
return $configurator;
}
}

View File

@@ -34,7 +34,7 @@ class JavascriptController extends Controller
* @param AccountRepositoryInterface $repository
* @param CurrencyRepositoryInterface $currencyRepository
*
* @return $this
* @return \Illuminate\Http\Response
*/
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
{
@@ -63,7 +63,7 @@ class JavascriptController extends Controller
/**
* @param CurrencyRepositoryInterface $repository
*
* @return $this
* @return \Illuminate\Http\Response
*/
public function currencies(CurrencyRepositoryInterface $repository)
{
@@ -71,8 +71,8 @@ class JavascriptController extends Controller
$data = ['currencies' => [],];
/** @var TransactionCurrency $currency */
foreach ($currencies as $currency) {
$currencyId = $currency->id;
$entry = ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol];
$currencyId = $currency->id;
$entry = ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol];
$data['currencies'][$currencyId] = $entry;
}

View File

@@ -41,7 +41,6 @@ class ExchangeController extends Controller
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$rate = $repository->getExchangeRate($fromCurrency, $toCurrency, $date);
$amount = null;
if (is_null($rate->id)) {
Log::debug(sprintf('No cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d')));
$preferred = env('EXCHANGE_RATE_SERVICE', config('firefly.preferred_exchange_service'));

View File

@@ -20,7 +20,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -116,10 +115,11 @@ class JsonController extends Controller
* Since both this method and the chart use the exact same data, we can suffice
* with calling the one method in the bill repository that will get this amount.
*/
$amount = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
$amount = bcmul($amount, '-1');
$amount = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
$amount = bcmul($amount, '-1');
$currency = Amount::getDefaultCurrency();
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$data = ['box' => 'bills-paid', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
return Response::json($data);
}
@@ -131,19 +131,19 @@ class JsonController extends Controller
*/
public function boxBillsUnpaid(BillRepositoryInterface $repository)
{
$start = session('start', Carbon::now()->startOfMonth());
$end = session('end', Carbon::now()->endOfMonth());
$amount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
$data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$start = session('start', Carbon::now()->startOfMonth());
$end = session('end', Carbon::now()->endOfMonth());
$amount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
$currency = Amount::getDefaultCurrency();
$data = ['box' => 'bills-unpaid', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
return Response::json($data);
}
/**
* @param AccountTaskerInterface $accountTasker
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
* @internal param AccountTaskerInterface $accountTasker
* @internal param AccountRepositoryInterface $repository
*
*/
public function boxIn()
@@ -167,18 +167,19 @@ class JsonController extends Controller
->setTypes([TransactionType::DEPOSIT])
->withOpposingAccount();
$amount = strval($collector->getJournals()->sum('transaction_amount'));
$data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$amount = strval($collector->getJournals()->sum('transaction_amount'));
$currency = Amount::getDefaultCurrency();
$data = ['box' => 'in', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
$cache->store($data);
return Response::json($data);
}
/**
* @param AccountTaskerInterface $accountTasker
* @param AccountRepositoryInterface $repository
*
* @return \Symfony\Component\HttpFoundation\Response
* @internal param AccountTaskerInterface $accountTasker
* @internal param AccountRepositoryInterface $repository
*
*/
public function boxOut()
{
@@ -200,9 +201,9 @@ class JsonController extends Controller
$collector->setAllAssetAccounts()->setRange($start, $end)
->setTypes([TransactionType::WITHDRAWAL])
->withOpposingAccount();
$amount = strval($collector->getJournals()->sum('transaction_amount'));
$data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$amount = strval($collector->getJournals()->sum('transaction_amount'));
$currency = Amount::getDefaultCurrency();
$data = ['box' => 'out', 'amount' => Amount::formatAnything($currency, $amount, false), 'amount_raw' => $amount];
$cache->store($data);
return Response::json($data);

View File

@@ -276,18 +276,29 @@ class PiggyBankController extends Controller
*/
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
$amount = $request->get('amount');
$amount = $request->get('amount');
$currency = Amount::getDefaultCurrency();
if ($repository->canAddAmount($piggyBank, $amount)) {
$repository->addAmount($piggyBank, $amount);
Session::flash('success', strval(trans('firefly.added_amount_to_piggy', ['amount' => Amount::format($amount, false), 'name' => $piggyBank->name])));
Session::flash(
'success', strval(
trans(
'firefly.added_amount_to_piggy',
['amount' => Amount::formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
)
)
);
Preferences::mark();
return redirect(route('piggy-banks.index'));
}
Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.');
Session::flash('error', strval(trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
Session::flash(
'error', strval(
trans('firefly.cannot_add_amount_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)])
)
);
return redirect(route('piggy-banks.index'));
}
@@ -301,11 +312,13 @@ class PiggyBankController extends Controller
*/
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
$amount = $request->get('amount');
$amount = $request->get('amount');
$currency = Amount::getDefaultCurrency();
if ($repository->canRemoveAmount($piggyBank, $amount)) {
$repository->removeAmount($piggyBank, $amount);
Session::flash(
'success', strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::format($amount, false), 'name' => $piggyBank->name]))
'success',
strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => $piggyBank->name]))
);
Preferences::mark();
@@ -314,7 +327,11 @@ class PiggyBankController extends Controller
$amount = strval(round($request->get('amount'), 12));
Session::flash('error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
Session::flash(
'error', strval(
trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)])
)
);
return redirect(route('piggy-banks.index'));
}

View File

@@ -120,7 +120,7 @@ class CategoryController extends Controller
foreach ($categories as $category) {
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
if (bccomp($spent, '0') !== 0) {
$report[$category->id] = ['name' => $category->name, 'spent' => $spent];
$report[$category->id] = ['name' => $category->name, 'spent' => $spent,'id' => $category->id];
}
}

View File

@@ -15,10 +15,7 @@ namespace FireflyIII\Http\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;

View File

@@ -306,7 +306,7 @@ class RuleController extends Controller
}
// Return json response
$view = view('list.journals-tiny-tasker', ['transactions' => $matchingTransactions])->render();
$view = view('list.journals-tiny', ['transactions' => $matchingTransactions])->render();
return Response::json(['html' => $view, 'warning' => $warning]);
}

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Http\Requests\TagFormRequest;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
@@ -245,6 +246,7 @@ class TagController extends Controller
$periods = new Collection;
$apiKey = env('GOOGLE_MAPS_API_KEY', '');
$sum = '0';
$path = 'tags/show/' . $tag->id;
// prep for "all" view.
@@ -253,6 +255,7 @@ class TagController extends Controller
$start = $repository->firstUseDate($tag);
$end = new Carbon;
$sum = $repository->sumOfTag($tag);
$path = 'tags/show/' . $tag->id . '/all';
}
// prep for "specific date" view.
@@ -282,13 +285,13 @@ class TagController extends Controller
Log::info('Now at tag loop start.');
while ($count === 0 && $loop < 3) {
$loop++;
Log::info('Count is zero, search for journals.');
Log::info(sprintf('Count is zero, search for journals between %s and %s (pagesize %d, page %d).', $start, $end, $pageSize, $page));
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
->setTag($tag)->withBudgetInformation()->withCategoryInformation();
->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id);
$journals->setPath($path);
$count = $journals->getCollection()->count();
if ($count === 0) {
$start->subDay();

View File

@@ -174,14 +174,23 @@ class ConvertController extends Controller
switch ($joined) {
default:
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
// one
$destination = $sourceAccount;
break;
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: // two
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
// two
$destination = $accountRepository->find(intval($data['destination_account_asset']));
break;
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
// three and five
if ($data['destination_account_expense'] === '') {
// destination is a cash account.
$destination = $accountRepository->getCashAccount();
return $destination;
}
$data = [
'name' => $data['destination_account_expense'],
'accountType' => 'expense',
@@ -191,8 +200,9 @@ class ConvertController extends Controller
];
$destination = $accountRepository->store($data);
break;
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: // four
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
// four and six
$destination = $destinationAccount;
break;
}
@@ -219,8 +229,16 @@ class ConvertController extends Controller
switch ($joined) {
default:
throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: // one
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: // six
case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT:
case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT:
if ($data['source_account_revenue'] === '') {
// destination is a cash account.
$destination = $accountRepository->getCashAccount();
return $destination;
}
$data = [
'name' => $data['source_account_revenue'],
'accountType' => 'revenue',
@@ -230,14 +248,14 @@ class ConvertController extends Controller
];
$source = $accountRepository->store($data);
break;
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: // two
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: // five
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
$source = $sourceAccount;
break;
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: // three
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
$source = $destinationAccount;
break;
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: // four
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
$source = $accountRepository->find(intval($data['source_account_asset']));
break;
}

View File

@@ -19,6 +19,7 @@ use FireflyIII\Http\Requests\MassDeleteJournalRequest;
use FireflyIII\Http\Requests\MassEditJournalRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -126,8 +127,7 @@ class MassController extends Controller
$budgetRepository = app(BudgetRepositoryInterface::class);
$budgets = $budgetRepository->getBudgets();
// skip transactions that have multiple destinations
// or multiple sources:
// skip transactions that have multiple destinations, multiple sources or are an opening balance.
$filtered = new Collection;
$messages = [];
/**
@@ -146,6 +146,10 @@ class MassController extends Controller
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
continue;
}
if ($journal->transactionType->type === TransactionType::OPENING_BALANCE) {
$messages[] = trans('firefly.cannot_edit_opening_balance');
continue;
}
$filtered->push($journal);
}
@@ -158,13 +162,21 @@ class MassController extends Controller
Session::flash('gaEventCategory', 'transactions');
Session::flash('gaEventAction', 'mass-edit');
// set some values to be used in the edit routine:
// collect some useful meta data for the mass edit:
$filtered->each(
function (TransactionJournal $journal) {
$journal->amount = $journal->amountPositive();
$sources = $journal->sourceAccountList();
$destinations = $journal->destinationAccountList();
$journal->transaction_count = $journal->transactions()->count();
$transaction = $journal->positiveTransaction();
$currency = $transaction->transactionCurrency;
$journal->amount = floatval($transaction->amount);
$sources = $journal->sourceAccountList();
$destinations = $journal->destinationAccountList();
$journal->transaction_count = $journal->transactions()->count();
$journal->currency_symbol = $currency->symbol;
$journal->transaction_type_type = $journal->transactionType->type;
$journal->foreign_amount = floatval($transaction->foreign_amount);
$journal->foreign_currency = $transaction->foreignCurrency;
if (!is_null($sources->first())) {
$journal->source_account_id = $sources->first()->id;
$journal->source_account_name = $sources->first()->editname;
@@ -208,6 +220,10 @@ class MassController extends Controller
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
$category = $request->get('category')[$journal->id];
$tags = $journal->tags->pluck('tag')->toArray();
$amount = round($request->get('amount')[$journal->id], 12);
$foreignAmount = isset($request->get('foreign_amount')[$journal->id]) ? round($request->get('foreign_amount')[$journal->id], 12) : null;
$foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?
intval($request->get('foreign_currency_id')[$journal->id]) : null;
// build data array
$data = [
@@ -218,16 +234,19 @@ class MassController extends Controller
'source_account_name' => $sourceAccountName,
'destination_account_id' => intval($destAccountId),
'destination_account_name' => $destAccountName,
'amount' => round($request->get('amount')[$journal->id], 12),
'currency_id' => $journal->transaction_currency_id,
'amount' => $foreignAmount,
'native_amount' => $amount,
'source_amount' => $amount,
'date' => new Carbon($request->get('date')[$journal->id]),
'interest_date' => $journal->interest_date,
'book_date' => $journal->book_date,
'process_date' => $journal->process_date,
'budget_id' => intval($budgetId),
'currency_id' => $foreignCurrencyId,
'foreign_amount' => $foreignAmount,
'destination_amount' => $foreignAmount,
'category' => $category,
'tags' => $tags,
];
// call repository update function.
$repository->update($journal, $data);
@@ -235,6 +254,7 @@ class MassController extends Controller
$count++;
}
}
}
Preferences::mark();
Session::flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count]));

View File

@@ -86,14 +86,16 @@ class SingleController extends Controller
public function cloneTransaction(TransactionJournal $journal)
{
$source = $journal->sourceAccountList()->first();
$destination = $journal->destinationAccountList()->first();
$budget = $journal->budgets()->first();
$budgetId = is_null($budget) ? 0 : $budget->id;
$category = $journal->categories()->first();
$categoryName = is_null($category) ? '' : $category->name;
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
$source = $journal->sourceAccountList()->first();
$destination = $journal->destinationAccountList()->first();
$budget = $journal->budgets()->first();
$budgetId = is_null($budget) ? 0 : $budget->id;
$category = $journal->categories()->first();
$categoryName = is_null($category) ? '' : $category->name;
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
$transaction = $journal->transactions()->first();
$amount = Steam::positive($transaction->amount);
$foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);
$preFilled = [
'description' => $journal->description,
@@ -101,7 +103,10 @@ class SingleController extends Controller
'source_account_name' => $source->name,
'destination_account_id' => $destination->id,
'destination_account_name' => $destination->name,
'amount' => $journal->amountPositive(),
'amount' => $amount,
'source_amount' => $amount,
'destination_amount' => $foreignAmount,
'foreign_amount' => $foreignAmount,
'date' => $journal->date->format('Y-m-d'),
'budget_id' => $budgetId,
'category' => $categoryName,
@@ -238,6 +243,7 @@ class SingleController extends Controller
$sourceAccounts = $journal->sourceAccountList();
$destinationAccounts = $journal->destinationAccountList();
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$pTransaction = $journal->positiveTransaction();
$preFilled = [
'date' => $journal->dateAsString(),
'interest_date' => $journal->dateAsString('interest_date'),
@@ -250,8 +256,6 @@ class SingleController extends Controller
'source_account_name' => $sourceAccounts->first()->edit_name,
'destination_account_id' => $destinationAccounts->first()->id,
'destination_account_name' => $destinationAccounts->first()->edit_name,
'amount' => $journal->amountPositive(),
'currency' => $journal->transactionCurrency,
// new custom fields:
'due_date' => $journal->dateAsString('due_date'),
@@ -260,26 +264,36 @@ class SingleController extends Controller
'interal_reference' => $journal->getMeta('internal_reference'),
'notes' => $journal->getMeta('notes'),
// exchange rate fields
'native_amount' => $journal->amountPositive(),
'native_currency' => $journal->transactionCurrency,
// amount fields
'amount' => $pTransaction->amount,
'source_amount' => $pTransaction->amount,
'native_amount' => $pTransaction->amount,
'destination_amount' => $pTransaction->foreign_amount,
'currency' => $pTransaction->transactionCurrency,
'source_currency' => $pTransaction->transactionCurrency,
'native_currency' => $pTransaction->transactionCurrency,
'foreign_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
'destination_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
];
// if user has entered a foreign currency, update some fields
$foreignCurrencyId = intval($journal->getMeta('foreign_currency_id'));
if ($foreignCurrencyId > 0) {
// update some fields in pre-filled.
// @codeCoverageIgnoreStart
$preFilled['amount'] = $journal->getMeta('foreign_amount');
$preFilled['currency'] = $this->currency->find(intval($journal->getMeta('foreign_currency_id')));
// @codeCoverageIgnoreEnd
// amounts for withdrawals and deposits:
// amount, native_amount, source_amount, destination_amount
if (($journal->isWithdrawal() || $journal->isDeposit()) && !is_null($pTransaction->foreign_amount)) {
$preFilled['amount'] = $pTransaction->foreign_amount;
$preFilled['currency'] = $pTransaction->foreignCurrency;
}
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
if ($journal->isTransfer() && !is_null($pTransaction->foreign_amount)) {
$preFilled['destination_amount'] = $pTransaction->foreign_amount;
$preFilled['destination_currency'] = $pTransaction->foreignCurrency;
}
// fixes for cash accounts:
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type === AccountType::CASH) {
$preFilled['destination_account_name'] = '';
}
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type == AccountType::CASH) {
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type === AccountType::CASH) {
$preFilled['source_account_name'] = '';
}
@@ -319,6 +333,7 @@ class SingleController extends Controller
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files);

View File

@@ -93,7 +93,7 @@ class SplitController extends Controller
}
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
$currencies = ExpandedForm::makeSelectList($this->currencies->get());
$currencies = $this->currencies->get();
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
@@ -130,7 +130,6 @@ class SplitController extends Controller
*/
public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
{
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal);
}
@@ -179,7 +178,6 @@ class SplitController extends Controller
'journal_source_account_id' => $request->get('journal_source_account_id'),
'journal_source_account_name' => $request->get('journal_source_account_name'),
'journal_destination_account_id' => $request->get('journal_destination_account_id'),
'currency_id' => $request->get('currency_id'),
'what' => $request->get('what'),
'date' => $request->get('date'),
// all custom fields:
@@ -218,10 +216,9 @@ class SplitController extends Controller
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id),
'currency_id' => $request->old('currency_id', $journal->transaction_currency_id),
'destinationAccounts' => $destinationAccounts,
'what' => strtolower($journal->transactionTypeStr()),
'date' => $request->old('date', $journal->date),
'date' => $request->old('date', $journal->date->format('Y-m-d')),
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
// all custom fields:
@@ -253,14 +250,22 @@ class SplitController extends Controller
/** @var array $transaction */
foreach ($transactions as $index => $transaction) {
$set = [
'description' => $transaction['description'],
'source_account_id' => $transaction['source_account_id'],
'source_account_name' => $transaction['source_account_name'],
'destination_account_id' => $transaction['destination_account_id'],
'destination_account_name' => $transaction['destination_account_name'],
'amount' => round($transaction['destination_amount'], 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'],
'description' => $transaction['description'],
'source_account_id' => $transaction['source_account_id'],
'source_account_name' => $transaction['source_account_name'],
'destination_account_id' => $transaction['destination_account_id'],
'destination_account_name' => $transaction['destination_account_name'],
'amount' => round($transaction['destination_amount'], 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'],
'transaction_currency_id' => $transaction['transaction_currency_id'],
'transaction_currency_code' => $transaction['transaction_currency_code'],
'transaction_currency_symbol' => $transaction['transaction_currency_symbol'],
'foreign_amount' => round($transaction['foreign_destination_amount'], 12),
'foreign_currency_id' => $transaction['foreign_currency_id'],
'foreign_currency_code' => $transaction['foreign_currency_code'],
'foreign_currency_symbol' => $transaction['foreign_currency_symbol'],
];
// set initial category and/or budget:
@@ -294,8 +299,12 @@ class SplitController extends Controller
'destination_account_id' => $transaction['destination_account_id'] ?? 0,
'destination_account_name' => $transaction['destination_account_name'] ?? '',
'amount' => round($transaction['amount'] ?? 0, 12),
'foreign_amount' => !isset($transaction['foreign_amount']) ? null : round($transaction['foreign_amount'] ?? 0, 12),
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0,
'category' => $transaction['category'] ?? '',
'transaction_currency_id' => intval($transaction['transaction_currency_id']),
'foreign_currency_id' => $transaction['foreign_currency_id'] ?? null,
];
}
Log::debug(sprintf('Found %d splits in request data.', count($return)));

View File

@@ -18,7 +18,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
use FireflyIII\Support\CacheProperties;
@@ -79,6 +78,7 @@ class TransactionController extends Controller
$start = null;
$end = null;
$periods = new Collection;
$path = '/transactions/' . $what;
// prep for "all" view.
if ($moment === 'all') {
@@ -86,6 +86,7 @@ class TransactionController extends Controller
$first = $repository->first();
$start = $first->date ?? new Carbon;
$end = new Carbon;
$path = '/transactions/'.$what.'/all/';
}
// prep for "specific date" view.
@@ -119,7 +120,7 @@ class TransactionController extends Controller
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount();
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('/budgets/list/no-budget');
$journals->setPath($path);
$count = $journals->getCollection()->count();
if ($count === 0) {
$start->subDay();
@@ -179,21 +180,12 @@ class TransactionController extends Controller
return $this->redirectToAccount($journal);
}
$events = $tasker->getPiggyBankEvents($journal);
$transactions = $tasker->getTransactionsOverview($journal);
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
$foreignCurrency = null;
$events = $tasker->getPiggyBankEvents($journal);
$transactions = $tasker->getTransactionsOverview($journal);
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
if ($journal->hasMeta('foreign_currency_id')) {
// @codeCoverageIgnoreStart
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$foreignCurrency = $repository->find(intval($journal->getMeta('foreign_currency_id')));
// @codeCoverageIgnoreEnd
}
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'foreignCurrency'));
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
}

View File

@@ -38,19 +38,19 @@ class AccountFormRequest extends Request
public function getAccountData(): array
{
return [
'name' => $this->string('name'),
'active' => $this->boolean('active'),
'accountType' => $this->string('what'),
'currency_id' => $this->integer('currency_id'),
'virtualBalance' => $this->float('virtualBalance'),
'iban' => $this->string('iban'),
'BIC' => $this->string('BIC'),
'accountNumber' => $this->string('accountNumber'),
'accountRole' => $this->string('accountRole'),
'openingBalance' => $this->float('openingBalance'),
'openingBalanceDate' => $this->date('openingBalanceDate'),
'ccType' => $this->string('ccType'),
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
'name' => $this->string('name'),
'active' => $this->boolean('active'),
'accountType' => $this->string('what'),
'currency_id' => $this->integer('currency_id'),
'virtualBalance' => $this->float('virtualBalance'),
'iban' => $this->string('iban'),
'BIC' => $this->string('BIC'),
'accountNumber' => $this->string('accountNumber'),
'accountRole' => $this->string('accountRole'),
'openingBalance' => $this->float('openingBalance'),
'openingBalanceDate' => $this->date('openingBalanceDate'),
'ccType' => $this->string('ccType'),
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
];
}

View File

@@ -38,8 +38,9 @@ class ImportUploadRequest extends Request
$types = array_keys(config('firefly.import_formats'));
return [
'import_file' => 'required|file',
'import_file_type' => 'required|in:' . join(',', $types),
'import_file' => 'required|file',
'import_file_type' => 'required|in:' . join(',', $types),
'configuration_file' => 'file',
];
}

View File

@@ -81,7 +81,7 @@ Breadcrumbs::register(
if ($moment !== 'all') {
$title = trans(
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
);
$breadcrumbs->push($title, route('accounts.show', [$account->id, $moment, $start, $end]));
}
@@ -469,26 +469,20 @@ Breadcrumbs::register(
$breadcrumbs->push(trans('firefly.import'), route('import.index'));
}
);
Breadcrumbs::register(
'import.complete', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
$breadcrumbs->parent('import.index');
$breadcrumbs->push(trans('firefly.bread_crumb_import_complete', ['key' => $job->key]), route('import.complete', [$job->key]));
}
);
Breadcrumbs::register(
'import.configure', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
$breadcrumbs->parent('import.index');
$breadcrumbs->push(trans('firefly.bread_crumb_configure_import', ['key' => $job->key]), route('import.configure', [$job->key]));
$breadcrumbs->push(trans('firefly.import_config_sub_title', ['key' => $job->key]), route('import.configure', [$job->key]));
}
);
Breadcrumbs::register(
'import.finished', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
'import.status', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) {
$breadcrumbs->parent('import.index');
$breadcrumbs->push(trans('firefly.bread_crumb_import_finished', ['key' => $job->key]), route('import.finished', [$job->key]));
$breadcrumbs->push(trans('firefly.import_status_bread_crumb', ['key' => $job->key]), route('import.status', [$job->key]));
}
);
/**
* PREFERENCES
*/
@@ -726,16 +720,16 @@ Breadcrumbs::register(
Breadcrumbs::register(
'tags.show', function (BreadCrumbGenerator $breadcrumbs, Tag $tag, string $moment, Carbon $start, Carbon $end) {
$breadcrumbs->parent('tags.index');
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id], $moment));
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id, $moment]));
if ($moment === 'all') {
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id], $moment));
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id, $moment]));
}
if ($moment !== 'all') {
$title = trans(
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
);
$breadcrumbs->push($title, route('tags.show', [$tag->id], $moment));
$breadcrumbs->push($title, route('tags.show', [$tag->id, $moment]));
}
}
);

View File

@@ -0,0 +1,65 @@
<?php
/**
* ConfiguratorInterface.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Configurator;
use FireflyIII\Models\ImportJob;
/**
* Interface ConfiguratorInterface
*
* @package FireflyIII\Import\Configurator
*/
interface ConfiguratorInterface
{
/**
* ConfiguratorInterface constructor.
*/
public function __construct();
/**
* Store any data from the $data array into the job.
*
* @param array $data
*
* @return bool
*/
public function configureJob(array $data): bool;
/**
* @param ImportJob $job
*
* @return void
*/
public function setJob(ImportJob $job);
/**
* Return the data required for the next step in the job configuration.
*
* @return array
*/
public function getNextData(): array;
/**
* Returns the view of the next step in the job configuration.
*
* @return string
*/
public function getNextView(): string;
/**
* Returns true when the initial configuration for this job is complete.
*
* @return bool
*/
public function isJobConfigured(): bool;
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* CsvConfigurator.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Configurator;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
use FireflyIII\Support\Import\Configuration\Csv\Initial;
use FireflyIII\Support\Import\Configuration\Csv\Map;
use FireflyIII\Support\Import\Configuration\Csv\Roles;
use Log;
/**
* Class CsvConfigurator
*
* @package FireflyIII\Import\Configurator
*/
class CsvConfigurator implements ConfiguratorInterface
{
private $job;
/**
* ConfiguratorInterface constructor.
*/
public function __construct()
{
}
/**
* Store any data from the $data array into the job.
*
* @param array $data
*
* @return bool
* @throws FireflyException
*/
public function configureJob(array $data): bool
{
$class = $this->getConfigurationClass();
$job = $this->job;
/** @var ConfigurationInterface $object */
$object = new $class($this->job);
$object->setJob($job);
return $object->storeConfiguration($data);
}
/**
* Return the data required for the next step in the job configuration.
*
* @return array
* @throws FireflyException
*/
public function getNextData(): array
{
$class = $this->getConfigurationClass();
$job = $this->job;
/** @var ConfigurationInterface $object */
$object = app($class);
$object->setJob($job);
return $object->getData();
}
/**
* @return string
* @throws FireflyException
*/
public function getNextView(): string
{
if (!$this->job->configuration['initial-config-complete']) {
return 'import.csv.initial';
}
if (!$this->job->configuration['column-roles-complete']) {
return 'import.csv.roles';
}
if (!$this->job->configuration['column-mapping-complete']) {
return 'import.csv.map';
}
throw new FireflyException('No view for state');
}
/**
* @return bool
*/
public function isJobConfigured(): bool
{
$config = $this->job->configuration;
$config['initial-config-complete'] = $config['initial-config-complete'] ?? false;
$config['column-roles-complete'] = $config['column-roles-complete'] ?? false;
$config['column-mapping-complete'] = $config['column-mapping-complete'] ?? false;
$this->job->configuration = $config;
$this->job->save();
if ($this->job->configuration['initial-config-complete']
&& $this->job->configuration['column-roles-complete']
&& $this->job->configuration['column-mapping-complete']
) {
return true;
}
return false;
}
/**
* @param ImportJob $job
*/
public function setJob(ImportJob $job)
{
$this->job = $job;
if (is_null($this->job->configuration) || count($this->job->configuration) === 0) {
Log::debug(sprintf('Gave import job %s initial configuration.', $this->job->key));
$this->job->configuration = config('csv.default_config');
$this->job->save();
}
}
/**
* @return string
* @throws FireflyException
*/
private function getConfigurationClass(): string
{
$class = false;
switch (true) {
case (!$this->job->configuration['initial-config-complete']):
$class = Initial::class;
break;
case (!$this->job->configuration['column-roles-complete']):
$class = Roles::class;
break;
case (!$this->job->configuration['column-mapping-complete']):
$class = Map::class;
break;
default:
break;
}
if ($class === false || strlen($class) === 0) {
throw new FireflyException('Cannot handle current job state in getConfigurationClass().');
}
if (!class_exists($class)) {
throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class));
}
return $class;
}
}

View File

@@ -1,69 +0,0 @@
<?php
/**
* AccountId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class AccountId
*
* @package FireflyIII\Import\Converter
*/
class AccountId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value)
{
$value = intval(trim($value));
Log::debug('Going to convert using AssetAccountId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
$account = $repository->find($value);// not mapped? Still try to find it first:
if (!is_null($account->id)) {
$this->setCertainty(90);
Log::debug('Found account by ID ', ['id' => $account->id]);
return $account;
}
$this->setCertainty(0); // should not really happen. If the ID does not match FF, what is FF supposed to do?
return new Account;
}
}

View File

@@ -18,7 +18,7 @@ namespace FireflyIII\Import\Converter;
*
* @package FireflyIII\Import\Converter
*/
class Amount extends BasicConverter implements ConverterInterface
class Amount implements ConverterInterface
{
/**
@@ -28,9 +28,9 @@ class Amount extends BasicConverter implements ConverterInterface
*
* @param $value
*
* @return float
* @return string
*/
public function convert($value): float
public function convert($value): string
{
$len = strlen($value);
$decimalPosition = $len - 3;
@@ -59,10 +59,7 @@ class Amount extends BasicConverter implements ConverterInterface
$value = str_replace($search, '', $value);
}
$this->setCertainty(90);
return round(floatval($value), 12);
return strval(round(floatval($value), 12));
}
}

View File

@@ -1,87 +0,0 @@
<?php
/**
* AssetAccountIban.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class AssetAccountIban
*
* @package FireflyIII\Import\Converter
*/
class AssetAccountIban extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value): Account
{
$value = trim($value);
Log::debug('Going to convert ', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
$this->setCertainty(100);
Log::debug('Found account by ID', ['id' => $account->id]);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByIban($value, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found account by IBAN', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
$account = $repository->store(
['name' => 'Asset account with IBAN ' . $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
'active' => true, 'openingBalance' => 0]
);
if (is_null($account->id)) {
$this->setCertainty(0);
Log::info('Could not store new asset account by IBAN', $account->getErrors()->toArray());
return new Account;
}
$this->setCertainty(100);
return $account;
}
}

View File

@@ -1,90 +0,0 @@
<?php
/**
* AssetAccountName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class AssetAccountName
*
* @package FireflyIII\Import\Converter
*/
class AssetAccountName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using AssetAccountName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByName($value, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found asset account by name', ['value' => $value, 'id' => $account->id]);
return $account;
}
$account = $repository->store(
['name' => $value, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
'active' => true]
);
if (is_null($account->id)) {
$this->setCertainty(0);
Log::info('Could not store new asset account by name', $account->getErrors()->toArray());
return new Account;
}
$this->setCertainty(100);
Log::debug('Created new asset account ', ['name' => $account->name, 'id' => $account->id]);
return $account;
}
}

View File

@@ -1,96 +0,0 @@
<?php
/**
* AssetAccountNumber.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class AssetAccountNumber
*
* @package FireflyIII\Import\Converter
*/
class AssetAccountNumber extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using AssetAccountNumber', ['value' => $value]);
if (strlen($value) === 0) {
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByAccountNumber($value, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found account by name', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
// try to find by the name we would give it:
$accountName = 'Asset account with number ' . e($value);
$account = $repository->findByName($accountName, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found account by name', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
$account = $repository->store(
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
'accountType' => 'asset',
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
);
if (is_null($account->id)) {
$this->setCertainty(0);
Log::info('Could not store new asset account by account number', $account->getErrors()->toArray());
return new Account;
}
$this->setCertainty(100);
return $account;
}
}

View File

@@ -1,85 +0,0 @@
<?php
/**
* BasicConverter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\User;
/**
* Class BasicConverter
*
* @package FireflyIII\Import\Converter
*/
class BasicConverter
{
/** @var int */
public $certainty = 50;
/** @var array */
public $config;
/** @var bool */
public $doMap;
/** @var array */
public $mapping = [];
/** @var User */
public $user;
/**
* @return int
*/
public function getCertainty(): int
{
return $this->certainty;
}
/**
* @param int $certainty
*/
protected function setCertainty(int $certainty)
{
$this->certainty = $certainty;
}
/**
* @param array $config
*/
public function setConfig(array $config)
{
$this->config = $config;
}
/**
* @param mixed $doMap
*/
public function setDoMap(bool $doMap)
{
$this->doMap = $doMap;
}
/**
* @param array $mapping
*
*/
public function setMapping(array $mapping)
{
$this->mapping = $mapping;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
* BillId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Log;
/**
* Class BillId
*
* @package FireflyIII\Import\Converter
*/
class BillId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Bill
*/
public function convert($value)
{
$value = intval(trim($value));
Log::debug('Going to convert using BillId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Bill;
}
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found bill in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$bill = $repository->find(intval($this->mapping[$value]));
if (!is_null($bill->id)) {
Log::debug('Found bill by ID', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
}
// not mapped? Still try to find it first:
$bill = $repository->find($value);
if (!is_null($bill->id)) {
Log::debug('Found bill by ID ', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
Log::info(sprintf('Could not find bill with ID %d. Will return NULL', $value));
$this->setCertainty(0);
return new Bill;
}
}

View File

@@ -1,99 +0,0 @@
<?php
/**
* BillName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Log;
/**
* Class BillName
*
* @package FireflyIII\Import\Converter
*/
class BillName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Bill
* @throws FireflyException
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using BillName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Bill;
}
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found bill in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$bill = $repository->find(intval($this->mapping[$value]));
if (!is_null($bill->id)) {
Log::debug('Found bill by ID', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
}
// not mapped? Still try to find it first:
$bill = $repository->findByName($value);
if (!is_null($bill->id)) {
Log::debug('Found bill by name ', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
// create new bill. Use a lot of made up values.
$bill = $repository->store(
[
'name' => $value,
'match' => $value,
'amount_min' => 1,
'user' => $this->user->id,
'amount_max' => 10,
'date' => date('Ymd'),
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 0,
'active' => 1,
]
);
if (is_null($bill->id)) {
$this->setCertainty(0);
Log::info('Could not store new bill by name', $bill->getErrors()->toArray());
return new Bill;
}
$this->setCertainty(100);
return $bill;
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
* BudgetId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
/**
* Class BudgetId
*
* @package FireflyIII\Import\Converter
*/
class BudgetId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Budget
*/
public function convert($value)
{
$value = intval(trim($value));
Log::debug('Going to convert using BudgetId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Budget;
}
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found budget in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$budget = $repository->find(intval($this->mapping[$value]));
if (!is_null($budget->id)) {
Log::debug('Found budget by ID', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
}
// not mapped? Still try to find it first:
$budget = $repository->find($value);
if (!is_null($budget->id)) {
Log::debug('Found budget by ID ', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
$this->setCertainty(0);
Log::info(sprintf('Could not find budget with ID %d. Will return NULL', $value));
return new Budget;
}
}

View File

@@ -1,80 +0,0 @@
<?php
/**
* BudgetName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
/**
* Class BudgetName
*
* @package FireflyIII\Import\Converter
*/
class BudgetName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Budget
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using BudgetName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Budget;
}
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found budget in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$budget = $repository->find(intval($this->mapping[$value]));
if (!is_null($budget->id)) {
Log::debug('Found budget by ID', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
}
// not mapped? Still try to find it first:
$budget = $repository->findByName($value);
if (!is_null($budget->id)) {
Log::debug('Found budget by name ', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
// create new budget. Use a lot of made up values.
$budget = $repository->store(
[
'name' => $value,
'user' => $this->user->id,
]
);
$this->setCertainty(100);
return $budget;
}
}

View File

@@ -1,76 +0,0 @@
<?php
/**
* CategoryId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Log;
/**
* Class CategoryId
*
* @package FireflyIII\Import\Converter
*/
class CategoryId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Category
*/
public function convert($value)
{
$value = intval(trim($value));
Log::debug('Going to convert using CategoryId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Category;
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found category in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$category = $repository->find(intval($this->mapping[$value]));
if (!is_null($category->id)) {
Log::debug('Found category by ID', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
}
// not mapped? Still try to find it first:
$category = $repository->find($value);
if (!is_null($category->id)) {
Log::debug('Found category by ID ', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
$this->setCertainty(0);
Log::info(sprintf('Could not find category with ID %d. Will return NULL', $value));
return new Category;
}
}

View File

@@ -1,80 +0,0 @@
<?php
/**
* CategoryName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Log;
/**
* Class CategoryName
*
* @package FireflyIII\Import\Converter
*/
class CategoryName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Category
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using CategoryName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Category;
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found category in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$category = $repository->find(intval($this->mapping[$value]));
if (!is_null($category->id)) {
Log::debug('Found category by ID', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
}
// not mapped? Still try to find it first:
$category = $repository->findByName($value);
if (!is_null($category->id)) {
Log::debug('Found category by name ', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
// create new category. Use a lot of made up values.
$category = $repository->store(
[
'name' => $value,
'user' => $this->user->id,
]
);
$this->setCertainty(100);
return $category;
}
}

View File

@@ -13,8 +13,6 @@ declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\User;
/**
* Interface ConverterInterface
*
@@ -27,30 +25,4 @@ interface ConverterInterface
*
*/
public function convert($value);
/**
* @return int
*/
public function getCertainty(): int;
/**
* @param array $config
*/
public function setConfig(array $config);
/**
* @param bool $doMap
*/
public function setDoMap(bool $doMap);
/**
* @param array $mapping
*
*/
public function setMapping(array $mapping);
/**
* @param User $user
*/
public function setUser(User $user);
}

View File

@@ -1,71 +0,0 @@
<?php
/**
* CurrencyCode.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
/**
* Class CurrencyCode
*
* @package FireflyIII\Import\Converter
*/
class CurrencyCode extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return TransactionCurrency
*/
public function convert($value): TransactionCurrency
{
Log::debug('Going to convert currency code', ['value' => $value]);
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found currency in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
// not mapped? Still try to find it first:
$currency = $repository->findByCode($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by code', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
$currency = $repository->store(
[
'name' => $value,
'code' => $value,
'symbol' => $value,
]
);
$this->setCertainty(100);
return $currency;
}
}

View File

@@ -1,75 +0,0 @@
<?php
/**
* CurrencyId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
/**
* Class CurrencyId
*
* @package FireflyIII\Import\Converter
*/
class CurrencyId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return TransactionCurrency
*/
public function convert($value)
{
$value = intval(trim($value));
Log::debug('Going to convert using CurrencyId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found currency in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
// not mapped? Still try to find it first:
$currency = $repository->find($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by ID ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
$this->setCertainty(0);
// should not really happen. If the ID does not match FF, what is FF supposed to do?
Log::info(sprintf('Could not find category with ID %d. Will return NULL', $value));
return new TransactionCurrency;
}
}

View File

@@ -1,81 +0,0 @@
<?php
/**
* CurrencyName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
/**
* Class CurrencyName
*
* @package FireflyIII\Import\Converter
*/
class CurrencyName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return TransactionCurrency
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using CurrencyName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found currency in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
// not mapped? Still try to find it first:
$currency = $repository->findByName($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by name ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
// create new currency
$currency = $repository->store(
[
'name' => $value,
'code' => strtoupper(substr($value, 0, 3)),
'symbol' => strtoupper(substr($value, 0, 1)),
]
);
$this->setCertainty(100);
return $currency;
}
}

View File

@@ -1,81 +0,0 @@
<?php
/**
* CurrencySymbol.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
/**
* Class CurrencySymbol
*
* @package FireflyIII\Import\Converter
*/
class CurrencySymbol extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return TransactionCurrency
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using CurrencySymbol', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found currency in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
// not mapped? Still try to find it first:
$currency = $repository->findBySymbol($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by symbol ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
// create new currency
$currency = $repository->store(
[
'name' => 'Currency ' . $value,
'code' => $value,
'symbol' => $value,
]
);
$this->setCertainty(100);
return $currency;
}
}

View File

@@ -1,53 +0,0 @@
<?php
/**
* Date.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use InvalidArgumentException;
use Log;
/**
* Class Date
*
* @package FireflyIII\Import\Converter
*/
class Date extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Carbon
* @throws FireflyException
*/
public function convert($value): Carbon
{
Log::debug('Going to convert date', ['value' => $value]);
Log::debug('Format: ', ['format' => $this->config['date-format']]);
try {
$date = Carbon::createFromFormat($this->config['date-format'], $value);
} catch (InvalidArgumentException $e) {
Log::info($e->getMessage());
Log::info('Cannot convert this string using the given format.', ['value' => $value, 'format' => $this->config['date-format']]);
$this->setCertainty(0);
return new Carbon;
}
Log::debug('Converted date', ['converted' => $date->toAtomString()]);
$this->setCertainty(100);
return $date;
}
}

View File

@@ -1,39 +0,0 @@
<?php
/**
* Description.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
/**
* Class Description
*
* @package FireflyIII\Import\Converter
*/
class Description extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return string
*/
public function convert($value): string
{
// this should replace all control characters
// but leave utf8 intact:
$value = preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', $value);
$this->setCertainty(100);
return strval($value);
}
}

View File

@@ -1,39 +0,0 @@
<?php
/**
* ExternalId.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
/**
* Class ExternalId
*
* @package FireflyIII\Import\Converter
*/
class ExternalId extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return string
*/
public function convert($value): string
{
// this should replace all control characters
// but leave utf8 intact:
$value = preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', $value);
$this->setCertainty(100);
return strval(trim($value));
}
}

View File

@@ -20,7 +20,7 @@ use Log;
*
* @package FireflyIII\Import\Converter
*/
class INGDebetCredit extends BasicConverter implements ConverterInterface
class INGDebetCredit implements ConverterInterface
{
/**
@@ -34,12 +34,10 @@ class INGDebetCredit extends BasicConverter implements ConverterInterface
if ($value === 'Af') {
Log::debug('Return -1');
$this->setCertainty(100);
return -1;
}
$this->setCertainty(100);
Log::debug('Return 1');
return 1;

View File

@@ -1,34 +0,0 @@
<?php
/**
* Ignore.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
/**
* Class Ignore
*
* @package FireflyIII\Import\Converter
*/
class Ignore extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return null
*/
public function convert($value)
{
return null;
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* OpposingAccountIban.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class OpposingAccountIban
*
* @package FireflyIII\Import\Converter
*/
class OpposingAccountIban extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value): Account
{
$value = trim($value);
Log::debug('Going to convert opposing IBAN', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByIban($value, []);
if (!is_null($account->id)) {
Log::debug('Found account by IBAN', ['id' => $account->id]);
Log::info(
'The match between IBAN and account is uncertain because the type of transactions may not have been determined.',
['id' => $account->id, 'iban' => $value]
);
$this->setCertainty(50);
return $account;
}
// the IBAN given may not be a valid IBAN. If not, we cannot store by
// iban and we have no opposing account. There should be some kind of fall back
// routine.
try {
$account = $repository->store(
['name' => $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
'openingBalance' => 0]
);
$this->setCertainty(100);
} catch (FireflyException $e) {
Log::error($e);
$account = new Account;
}
return $account;
}
}

View File

@@ -1,89 +0,0 @@
<?php
/**
* OpposingAccountName.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class OpposingAccountName
*
* @package FireflyIII\Import\Converter
*/
class OpposingAccountName extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value): Account
{
$value = trim($value);
Log::debug('Going to convert opposing account name', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByName($value, []);
if (!is_null($account->id)) {
Log::debug('Found opposing account by name', ['id' => $account->id]);
Log::info(
'The match between name and account is uncertain because the type of transactions may not have been determined.',
['id' => $account->id, 'name' => $value]
);
$this->setCertainty(50);
return $account;
}
$account = $repository->store(
['name' => $value, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
'openingBalance' => 0,
]
);
if (is_null($account->id)) {
$this->setCertainty(0);
return new Account;
}
$this->setCertainty(100);
Log::debug('Created new opposing account ', ['name' => $account->name, 'id' => $account->id]);
return $account;
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* OpposingAccountNumber.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class OpposingAccountNumber
*
* @package FireflyIII\Import\Converter
*/
class OpposingAccountNumber extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Account
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using OpposingAccountNumber', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (isset($this->mapping[$value])) {
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
// not mapped? Still try to find it first:
$account = $repository->findByAccountNumber($value, []);
if (!is_null($account->id)) {
Log::debug('Found account by number', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
// try to find by the name we would give it:
$accountName = 'Import account with number ' . e($value);
$account = $repository->findByName($accountName, [AccountType::IMPORT]);
if (!is_null($account->id)) {
Log::debug('Found account by name', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
$account = $repository->store(
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
'accountType' => 'import',
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
);
$this->setCertainty(100);
return $account;
}
}

View File

@@ -20,7 +20,7 @@ use Log;
*
* @package FireflyIII\Import\Converter
*/
class RabobankDebetCredit extends BasicConverter implements ConverterInterface
class RabobankDebetCredit implements ConverterInterface
{
/**
@@ -34,13 +34,11 @@ class RabobankDebetCredit extends BasicConverter implements ConverterInterface
if ($value === 'D') {
Log::debug('Return -1');
$this->setCertainty(100);
return -1;
}
Log::debug('Return 1');
$this->setCertainty(100);
return 1;
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* TagSplit.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class TagSplit
*
* @package FireflyIII\Import\Converter
*/
class TagSplit
{
/**
* @param User $user
* @param array $mapping
* @param array $parts
*
* @return Collection
*/
public static function createSetFromSplits(User $user, array $mapping, array $parts): Collection
{
$set = new Collection;
Log::debug('Exploded parts.', $parts);
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$repository->setUser($user);
/** @var string $part */
foreach ($parts as $part) {
if (isset($mapping[$part])) {
Log::debug('Found tag in mapping. Should exist.', ['value' => $part, 'map' => $mapping[$part]]);
$tag = $repository->find(intval($mapping[$part]));
if (!is_null($tag->id)) {
Log::debug('Found tag by ID', ['id' => $tag->id]);
$set->push($tag);
continue;
}
}
// not mapped? Still try to find it first:
$tag = $repository->findByTag($part);
if (!is_null($tag->id)) {
Log::debug('Found tag by name ', ['id' => $tag->id]);
$set->push($tag);
}
if (is_null($tag->id)) {
// create new tag
$tag = $repository->store(
[
'tag' => $part,
'date' => null,
'description' => $part,
'latitude' => null,
'longitude' => null,
'zoomLevel' => null,
'tagMode' => 'nothing',
]
);
Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
$set->push($tag);
}
}
return $set;
}
}

View File

@@ -1,48 +0,0 @@
<?php
/**
* TagsComma.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Illuminate\Support\Collection;
use Log;
/**
* Class TagsComma
*
* @package FireflyIII\Import\Converter
*/
class TagsComma extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Collection
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using TagsComma', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Collection;
}
$parts = array_unique(explode(',', $value));
$set = TagSplit::createSetFromSplits($this->user, $this->mapping, $parts);
$this->setCertainty(100);
return $set;
}
}

View File

@@ -1,49 +0,0 @@
<?php
/**
* TagsSpace.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Illuminate\Support\Collection;
use Log;
/**
* Class TagsSpace
*
* @package FireflyIII\Import\Converter
*/
class TagsSpace extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Collection
*/
public function convert($value)
{
$value = trim($value);
Log::debug('Going to convert using TagsSpace', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Collection;
}
$parts = array_unique(explode(' ', $value));
$set = TagSplit::createSetFromSplits($this->user, $this->mapping, $parts);
$this->setCertainty(100);
return $set;
}
}

View File

@@ -0,0 +1,235 @@
<?php
/**
* CsvProcessor.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\FileProcessor;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Object\ImportJournal;
use FireflyIII\Import\Specifics\SpecificInterface;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionJournalMeta;
use Illuminate\Support\Collection;
use Iterator;
use League\Csv\Reader;
use Log;
/**
* Class CsvProcessor, as the name suggests, goes over CSV file line by line and creates
* "ImportJournal" objects, which are used in another step to create new journals and transactions
* and what-not.
*
* @package FireflyIII\Import\FileProcessor
*/
class CsvProcessor implements FileProcessorInterface
{
/** @var ImportJob */
private $job;
/** @var Collection */
private $objects;
/** @var array */
private $validConverters = [];
/** @var array */
private $validSpecifics = [];
/**
* FileProcessorInterface constructor.
*/
public function __construct()
{
$this->objects = new Collection;
$this->validSpecifics = array_keys(config('csv.import_specifics'));
$this->validConverters = array_keys(config('csv.import_roles'));
}
/**
* @return Collection
*/
public function getObjects(): Collection
{
return $this->objects;
}
/**
* Does the actual job:
*
* @return bool
*/
public function run(): bool
{
Log::debug('Now in CsvProcessor run(). Job is now running...');
$entries = $this->getImportArray();
$index = 0;
Log::notice('Building importable objects from CSV file.');
foreach ($entries as $index => $row) {
// verify if not exists already:
if ($this->rowAlreadyImported($row)) {
$message = sprintf('Row #%d has already been imported.', $index);
$this->job->addError($index, $message);
$this->job->addStepsDone(5); // all steps.
Log::info($message);
continue;
}
$this->objects->push($this->importRow($index, $row));
$this->job->addStepsDone(1);
}
// if job has no step count, set it now:
$extended = $this->job->extended_status;
if ($extended['steps'] === 0) {
$extended['steps'] = $index * 5;
$this->job->extended_status = $extended;
$this->job->save();
}
return true;
}
/**
* @param ImportJob $job
*
* @return FileProcessorInterface
*/
public function setJob(ImportJob $job): FileProcessorInterface
{
$this->job = $job;
return $this;
}
/**
* Add meta data to the individual value and verify that it can be handled in a later stage.
*
* @param int $index
* @param string $value
*
* @return array
* @throws FireflyException
*/
private function annotateValue(int $index, string $value)
{
$value = trim($value);
$config = $this->job->configuration;
$role = $config['column-roles'][$index] ?? '_ignore';
$mapped = $config['column-mapping-config'][$index][$value] ?? null;
// throw error when not a valid converter.
if (!in_array($role, $this->validConverters)) {
throw new FireflyException(sprintf('"%s" is not a valid role.', $role));
}
$entry = [
'role' => $role,
'value' => $value,
'mapped' => $mapped,
];
return $entry;
}
/**
* @return Iterator
*/
private function getImportArray(): Iterator
{
$content = $this->job->uploadFileContents();
$config = $this->job->configuration;
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$start = $config['has-headers'] ? 1 : 0;
$results = $reader->setOffset($start)->fetch();
Log::debug(sprintf('Created a CSV reader starting at offset %d', $start));
return $results;
}
/**
* Take a row, build import journal by annotating each value and storing it in the import journal.
*
* @param int $index
* @param array $row
*
* @return ImportJournal
*/
private function importRow(int $index, array $row): ImportJournal
{
Log::debug(sprintf('Now at row %d', $index));
$row = $this->specifics($row);
$journal = new ImportJournal;
$journal->setUser($this->job->user);
$journal->setHash(hash('sha256', json_encode($row)));
foreach ($row as $rowIndex => $value) {
$value = trim($value);
if (strlen($value) > 0) {
$annotated = $this->annotateValue($rowIndex, $value);
Log::debug('Annotated value', $annotated);
$journal->setValue($annotated);
}
}
Log::debug('ImportJournal complete, returning.');
return $journal;
}
/**
* Checks if the row has not been imported before.
*
* @param array $array
*
* @return bool
*/
private function rowAlreadyImported(array $array): bool
{
$string = json_encode($array);
$hash = hash('sha256', json_encode($string));
$json = json_encode($hash);
$entry = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->where('data', $json)
->where('name', 'importHash')
->first();
if (!is_null($entry)) {
return true;
}
return false;
}
/**
* And this is the point where the specifix go to work.
*
* @param array $row
*
* @return array
* @throws FireflyException
*/
private function specifics(array $row): array
{
$config = $this->job->configuration;
//
foreach ($config['specifics'] as $name => $enabled) {
if (!in_array($name, $this->validSpecifics)) {
throw new FireflyException(sprintf('"%s" is not a valid class name', $name));
}
/** @var SpecificInterface $specific */
$specific = app('FireflyIII\Import\Specifics\\' . $name);
// it returns the row, possibly modified:
$row = $specific->run($row);
}
return $row;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* FileProcessorInterface.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\FileProcessor;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\Collection;
/**
* Interface FileProcessorInterface
*
* @package FireflyIII\Import\FileProcessor
*/
interface FileProcessorInterface
{
/**
* @return Collection
*/
public function getObjects(): Collection;
/**
* @return bool
*/
public function run(): bool;
/**
* @param ImportJob $job
*
* @return FileProcessorInterface
*/
public function setJob(ImportJob $job): FileProcessorInterface;
}

View File

@@ -1,274 +0,0 @@
<?php
/**
* ImportEntry.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class ImportEntry
*
* @package FireflyIII\Import
*/
class ImportEntry
{
/** @var array */
public $certain = [];
/** @var Collection */
public $errors;
/** @var string */
public $externalID;
/** @var array */
public $fields = [];
/** @var string */
public $hash;
/** @var User */
public $user;
/** @var bool */
public $valid = true;
/** @var int */
private $amountMultiplier = 0;
/** @var array */
private $validFields
= ['amount',
'date-transaction',
'date-interest',
'date-book',
'description',
'date-process',
'transaction-type',
'currency', 'asset-account', 'opposing-account', 'bill', 'budget', 'category', 'tags'];
/**
* ImportEntry constructor.
*/
public function __construct()
{
/** @var string $value */
foreach ($this->validFields as $value) {
$this->fields[$value] = null;
$this->certain[$value] = 0;
}
$this->errors = new Collection;
}
/**
* @param string $role
* @param int $certainty
* @param $convertedValue
*
* @throws FireflyException
*/
public function importValue(string $role, int $certainty, $convertedValue)
{
switch ($role) {
default:
Log::error('Import entry cannot handle object.', ['role' => $role]);
throw new FireflyException('Import entry cannot handle object of type "' . $role . '".');
case 'hash':
$this->hash = $convertedValue;
return;
case 'amount':
/*
* Easy enough.
*/
$this->setFloat('amount', $convertedValue, $certainty);
$this->applyMultiplier('amount'); // if present.
return;
case 'account-id':
case 'account-iban':
case 'account-name':
case 'account-number':
$this->setObject('asset-account', $convertedValue, $certainty);
break;
case 'opposing-number':
case 'opposing-iban':
case 'opposing-id':
case 'opposing-name':
$this->setObject('opposing-account', $convertedValue, $certainty);
break;
case 'bill-id':
case 'bill-name':
$this->setObject('bill', $convertedValue, $certainty);
break;
case 'budget-id':
case 'budget-name':
$this->setObject('budget', $convertedValue, $certainty);
break;
case 'category-id':
case 'category-name':
$this->setObject('category', $convertedValue, $certainty);
break;
case 'currency-code':
case 'currency-id':
case 'currency-name':
case 'currency-symbol':
$this->setObject('currency', $convertedValue, $certainty);
break;
case 'date-transaction':
$this->setDate('date-transaction', $convertedValue, $certainty);
break;
case 'date-interest':
$this->setDate('date-interest', $convertedValue, $certainty);
break;
case 'date-book':
$this->setDate('date-book', $convertedValue, $certainty);
break;
case 'date-process':
$this->setDate('date-process', $convertedValue, $certainty);
break;
case 'sepa-ct-id':
case 'sepa-db':
case 'sepa-ct-op':
case 'description':
$this->setAppendableString('description', $convertedValue);
break;
case '_ignore':
break;
case 'ing-debet-credit':
case 'rabo-debet-credit':
$this->manipulateFloat('amount', 'multiply', $convertedValue);
$this->applyMultiplier('amount'); // if present.
break;
case 'tags-comma':
case 'tags-space':
$this->appendCollection('tags', $convertedValue);
break;
case 'external-id':
$this->externalID = $convertedValue;
break;
}
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
}
/**
* @param string $field
* @param Collection $convertedValue
*/
private function appendCollection(string $field, Collection $convertedValue)
{
if (is_null($this->fields[$field])) {
$this->fields[$field] = new Collection;
}
$this->fields[$field] = $this->fields[$field]->merge($convertedValue);
}
/**
* @param string $field
*/
private function applyMultiplier(string $field)
{
if ($this->fields[$field] != 0 && $this->amountMultiplier != 0) {
$this->fields[$field] = $this->fields[$field] * $this->amountMultiplier;
}
}
/**
* @param string $field
* @param string $action
* @param $convertedValue
*
* @throws FireflyException
*/
private function manipulateFloat(string $field, string $action, $convertedValue)
{
switch ($action) {
default:
Log::error('Cannot handle manipulateFloat', ['field' => $field, 'action' => $action]);
throw new FireflyException('Cannot manipulateFloat with action ' . $action);
case 'multiply':
$this->amountMultiplier = $convertedValue;
break;
}
}
/**
* @param string $field
* @param string $value
*/
private function setAppendableString(string $field, string $value)
{
$value = trim($value);
$this->fields[$field] .= ' ' . $value;
}
/**
* @param string $field
* @param Carbon $date
* @param int $certainty
*/
private function setDate(string $field, Carbon $date, int $certainty)
{
if ($certainty > $this->certain[$field] && !is_null($date)) {
Log::debug(sprintf('ImportEntry: %s is now %s with certainty %d', $field, $date->format('Y-m-d'), $certainty));
$this->fields[$field] = $date;
$this->certain[$field] = $certainty;
return;
}
Log::info(sprintf('Will not set %s based on certainty %d (current certainty is %d) or NULL id.', $field, $certainty, $this->certain[$field]));
}
/**
* @param string $field
* @param float $value
* @param int $certainty
*/
private function setFloat(string $field, float $value, int $certainty)
{
if ($certainty > $this->certain[$field]) {
Log::debug(sprintf('ImportEntry: %s is now %f with certainty %d', $field, $value, $certainty));
$this->fields[$field] = $value;
$this->certain[$field] = $certainty;
return;
}
Log::info(sprintf('Will not set %s based on certainty %d (current certainty is %d).', $field, $certainty, $this->certain[$field]));
}
/**
* @param string $field
* @param $object
* @param int $certainty
*/
private function setObject(string $field, $object, int $certainty)
{
if ($certainty > $this->certain[$field] && !is_null($object->id)) {
Log::debug(sprintf('ImportEntry: %s ID is now %d with certainty %d', $field, $object->id, $certainty));
$this->fields[$field] = $object;
$this->certain[$field] = $certainty;
return;
}
Log::info(sprintf('Will not set %s based on certainty %d (current certainty is %d) or NULL id.', $field, $certainty, $this->certain[$field]));
}
}

View File

@@ -1,85 +0,0 @@
<?php
/**
* ImportProcedure.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import;
use FireflyIII\Import\Importer\ImporterInterface;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
/**
* Class ImportProcedure
*
* @package FireflyIII\Import
*/
class ImportProcedure implements ImportProcedureInterface
{
/**
* @param ImportJob $job
*
* @return Collection
*/
public function runImport(ImportJob $job): Collection
{
// update job to say we started.
$job->status = 'import_running';
$job->save();
// create Importer
$valid = array_keys(config('firefly.import_formats'));
$class = 'INVALID';
if (in_array($job->file_type, $valid)) {
$class = config('firefly.import_formats.' . $job->file_type);
}
/** @var ImporterInterface $importer */
$importer = app($class);
$importer->setJob($job);
// create import entries
$collection = $importer->createImportEntries();
// validate / clean collection:
$validator = new ImportValidator($collection);
$validator->setUser($job->user);
$validator->setJob($job);
if ($job->configuration['import-account'] != 0) {
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($job->user);
$validator->setDefaultImportAccount($repository->find($job->configuration['import-account']));
}
$cleaned = $validator->clean();
// then import collection:
$storage = new ImportStorage($job->user, $cleaned);
$storage->setJob($job);
// and run store routine:
$result = $storage->store();
// grab import tag:
$status = $job->extended_status;
$status['importTag'] = $storage->importTag->id;
$job->extended_status = $status;
$job->status = 'import_complete';
$job->save();
return $result;
}
}

View File

@@ -1,33 +0,0 @@
<?php
/**
* ImportProcedureInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\Collection;
/**
* Interface ImportProcedureInterface
*
* @package FireflyIII\Import
*/
interface ImportProcedureInterface
{
/**
* @param ImportJob $job
*
* @return Collection
*/
public function runImport(ImportJob $job): Collection;
}

View File

@@ -1,418 +0,0 @@
<?php
/**
* ImportStorage.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Rule;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Rules\Processor;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
use Steam;
/**
* Class ImportStorage
*
* @package FireflyIII\Import
*/
class ImportStorage
{
/** @var Collection */
public $entries;
/** @var Tag */
public $importTag;
/** @var ImportJob */
public $job;
/** @var User */
public $user;
/** @var Collection */
private $rules;
/**
* ImportStorage constructor.
*
* @param User $user
* @param Collection $entries
*/
public function __construct(User $user, Collection $entries)
{
$this->entries = $entries;
$this->user = $user;
$this->rules = $this->getUserRules();
}
/**
* @param ImportJob $job
*/
public function setJob(ImportJob $job)
{
$this->job = $job;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
}
/**
* @return Collection
*/
public function store(): Collection
{
// create a tag to join the transactions.
$this->importTag = $this->createImportTag();
$collection = new Collection;
Log::notice(sprintf('Started storing %d entry(ies).', $this->entries->count()));
foreach ($this->entries as $index => $entry) {
Log::debug(sprintf('--- import store start for row %d ---', $index));
// store entry:
$journal = $this->storeSingle($index, $entry);
$this->job->addStepsDone(1);
// apply rules:
$this->applyRules($journal);
$this->job->addStepsDone(1);
$collection->put($index, $journal);
}
Log::notice(sprintf('Finished storing %d entry(ies).', $collection->count()));
return $collection;
}
/**
* @param string $hash
*
* @return TransactionJournal
*/
private function alreadyImported(string $hash): TransactionJournal
{
$meta = TransactionJournalMeta
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->where('journal_meta.name', 'originalImportHash')
->where('transaction_journals.user_id', $this->user->id)
->where('journal_meta.data', json_encode($hash))->first(['journal_meta.*']);
if (!is_null($meta)) {
/** @var TransactionJournal $journal */
$journal = $meta->transactionjournal;
if (intval($journal->completed) === 1) {
return $journal;
}
}
return new TransactionJournal;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
private function applyRules(TransactionJournal $journal): bool
{
if ($this->rules->count() > 0) {
/** @var Rule $rule */
foreach ($this->rules as $rule) {
Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
$processor = Processor::make($rule);
$processor->handleTransactionJournal($journal);
if ($rule->stop_processing) {
return true;
}
}
}
return true;
}
/**
* @return Tag
*/
private function createImportTag(): Tag
{
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$repository->setUser($this->user);
$data = [
'tag' => trans('firefly.import_with_key', ['key' => $this->job->key]),
'date' => new Carbon,
'description' => null,
'latitude' => null,
'longitude' => null,
'zoomLevel' => null,
'tagMode' => 'nothing',
];
$tag = $repository->store($data);
return $tag;
}
/**
* @return Collection
*/
private function getUserRules(): Collection
{
$set = Rule::distinct()
->where('rules.user_id', $this->user->id)
->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_groups.active', 1)
->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'store-journal')
->where('rules.active', 1)
->orderBy('rule_groups.order', 'ASC')
->orderBy('rules.order', 'ASC')
->get(['rules.*', 'rule_groups.order']);
Log::debug(sprintf('Found %d user rules.', $set->count()));
return $set;
}
/**
* @param $entry
*
* @return array
* @throws FireflyException
*/
private function storeAccounts($entry): array
{
// then create transactions. Single ones, unfortunately.
switch ($entry->fields['transaction-type']->type) {
default:
throw new FireflyException('ImportStorage cannot handle ' . $entry->fields['transaction-type']->type);
case TransactionType::WITHDRAWAL:
$source = $entry->fields['asset-account'];
$destination = $entry->fields['opposing-account'];
// make amount positive, if it is not.
break;
case TransactionType::DEPOSIT:
$source = $entry->fields['opposing-account'];
$destination = $entry->fields['asset-account'];
break;
case TransactionType::TRANSFER:
// depends on amount:
if ($entry->fields['amount'] < 0) {
$source = $entry->fields['asset-account'];
$destination = $entry->fields['opposing-account'];
break;
}
$destination = $entry->fields['asset-account'];
$source = $entry->fields['opposing-account'];
break;
}
return [
'source' => $source,
'destination' => $destination,
];
}
/**
* @param TransactionJournal $journal
* @param ImportEntry $entry
*/
private function storeBill(TransactionJournal $journal, ImportEntry $entry)
{
if (!is_null($entry->fields['bill']) && !is_null($entry->fields['bill']->id)) {
$journal->bill()->associate($entry->fields['bill']);
Log::debug('Attached bill', ['id' => $entry->fields['bill']->id, 'name' => $entry->fields['bill']->name]);
$journal->save();
}
}
/**
* @param TransactionJournal $journal
* @param ImportEntry $entry
*/
private function storeBudget(TransactionJournal $journal, ImportEntry $entry)
{
if (!is_null($entry->fields['budget']) && !is_null($entry->fields['budget']->id)) {
$journal->budgets()->save($entry->fields['budget']);
Log::debug('Attached budget', ['id' => $entry->fields['budget']->id, 'name' => $entry->fields['budget']->name]);
$journal->save();
}
}
/**
* @param TransactionJournal $journal
* @param ImportEntry $entry
*/
private function storeCategory(TransactionJournal $journal, ImportEntry $entry)
{
if (!is_null($entry->fields['category']) && !is_null($entry->fields['category']->id)) {
$journal->categories()->save($entry->fields['category']);
Log::debug('Attached category', ['id' => $entry->fields['category']->id, 'name' => $entry->fields['category']->name]);
$journal->save();
}
}
/**
* @param $entry
*
* @return TransactionJournal
*/
private function storeJournal($entry): TransactionJournal
{
$billId = is_null($entry->fields['bill']) || intval($entry->fields['bill']->id) === 0 ? null : intval($entry->fields['bill']->id);
$journalData = [
'user_id' => $entry->user->id,
'transaction_type_id' => $entry->fields['transaction-type']->id,
'bill_id' => $billId,
'transaction_currency_id' => $entry->fields['currency']->id,
'description' => $entry->fields['description'],
'date' => $entry->fields['date-transaction'],
'interest_date' => $entry->fields['date-interest'],
'book_date' => $entry->fields['date-book'],
'process_date' => $entry->fields['date-process'],
'completed' => 0,
];
/** @var TransactionJournal $journal */
$journal = TransactionJournal::create($journalData);
foreach ($journal->getErrors()->all() as $err) {
Log::error('Error when storing journal: ' . $err);
}
Log::debug('Created journal', ['id' => $journal->id]);
// save hash as meta value:
$meta = new TransactionJournalMeta;
$meta->name = 'originalImportHash';
$meta->data = $entry->hash;
$meta->transactionJournal()->associate($journal);
$meta->save();
return $journal;
}
/**
* @param int $index
* @param ImportEntry $entry
*
* @return TransactionJournal
* @throws FireflyException
*/
private function storeSingle(int $index, ImportEntry $entry): TransactionJournal
{
if ($entry->valid === false) {
Log::warning(sprintf('Cannot import row %d, because the entry is not valid.', $index));
$errors = join(', ', $entry->errors->all());
$errorText = sprintf('Row #%d: ' . $errors, $index);
$extendedStatus = $this->job->extended_status;
$extendedStatus['errors'][] = $errorText;
$this->job->extended_status = $extendedStatus;
$this->job->save();
return new TransactionJournal;
}
$alreadyImported = $this->alreadyImported($entry->hash);
if (!is_null($alreadyImported->id)) {
Log::warning(sprintf('Cannot import row %d, because it has already been imported (journal #%d).', $index, $alreadyImported->id));
$errorText = trans(
'firefly.import_double',
['row' => $index, 'link' => route('transactions.show', [$alreadyImported->id]), 'description' => $alreadyImported->description]
);
$extendedStatus = $this->job->extended_status;
$extendedStatus['errors'][] = $errorText;
$this->job->extended_status = $extendedStatus;
$this->job->save();
return new TransactionJournal;
}
Log::debug(sprintf('Going to store row %d', $index));
$journal = $this->storeJournal($entry);
$amount = Steam::positive($entry->fields['amount']);
$accounts = $this->storeAccounts($entry);
// create new transactions. This is something that needs a rewrite for multiple/split transactions.
$sourceData = [
'account_id' => $accounts['source']->id,
'transaction_journal_id' => $journal->id,
'description' => null,
'amount' => bcmul($amount, '-1'),
];
$destinationData = [
'account_id' => $accounts['destination']->id,
'transaction_journal_id' => $journal->id,
'description' => null,
'amount' => $amount,
];
$one = Transaction::create($sourceData);
$two = Transaction::create($destinationData);
$error = false;
if (is_null($one->id)) {
Log::error('Could not create transaction 1.', $one->getErrors()->all());
$error = true;
}
if (is_null($two->id)) {
Log::error('Could not create transaction 1.', $two->getErrors()->all());
$error = true;
}
// respond to error
if ($error === true) {
$errorText = sprintf('Cannot import row %d, because an error occured when storing data.', $index);
Log::error($errorText);
$extendedStatus = $this->job->extended_status;
$extendedStatus['errors'][] = $errorText;
$this->job->extended_status = $extendedStatus;
$this->job->save();
return new TransactionJournal;
}
Log::debug('Created transaction 1', ['id' => $one->id, 'account' => $one->account_id, 'account_name' => $accounts['source']->name]);
Log::debug('Created transaction 2', ['id' => $two->id, 'account' => $two->account_id, 'account_name' => $accounts['destination']->name]);
$journal->completed = 1;
$journal->save();
// attach import tag.
$journal->tags()->save($this->importTag);
// now attach budget and so on.
$this->storeBudget($journal, $entry);
$this->storeCategory($journal, $entry);
$this->storeBill($journal, $entry);
return $journal;
}
}

View File

@@ -1,438 +0,0 @@
<?php
/**
* ImportValidator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
use Preferences;
/**
* Class ImportValidator
*
* @package FireflyIII\Import
*/
class ImportValidator
{
/** @var ImportJob */
public $job;
/** @var Account */
protected $defaultImportAccount;
/** @var Collection */
protected $entries;
/** @var User */
protected $user;
/**
* ImportValidator constructor.
*
* @param Collection $entries
*/
public function __construct(Collection $entries)
{
$this->entries = $entries;
}
/**
* Clean collection by filling in all the blanks.
*/
public function clean(): Collection
{
Log::notice(sprintf('Started validating %d entry(ies).', $this->entries->count()));
$newCollection = new Collection;
/** @var ImportEntry $entry */
foreach ($this->entries as $index => $entry) {
Log::debug(sprintf('--- import validator start for row %d ---', $index));
/*
* X Adds the date (today) if no date is present.
* X Determins the types of accounts involved (asset, expense, revenue).
* X Determins the type of transaction (withdrawal, deposit, transfer).
* - Determins the currency of the transaction.
* X Adds a default description if there isn't one present.
*/
$entry = $this->checkAmount($entry);
$entry = $this->setDate($entry);
$entry = $this->setAssetAccount($entry);
$entry = $this->setOpposingAccount($entry);
$entry = $this->cleanDescription($entry);
$entry = $this->setTransactionType($entry);
$entry = $this->setTransactionCurrency($entry);
$newCollection->put($index, $entry);
$this->job->addStepsDone(1);
}
Log::notice(sprintf('Finished validating %d entry(ies).', $newCollection->count()));
return $newCollection;
}
/**
* @param Account $defaultImportAccount
*/
public function setDefaultImportAccount(Account $defaultImportAccount)
{
$this->defaultImportAccount = $defaultImportAccount;
}
/**
* @param ImportJob $job
*/
public function setJob(ImportJob $job)
{
$this->job = $job;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function checkAmount(ImportEntry $entry): ImportEntry
{
if ($entry->fields['amount'] == 0) {
$entry->valid = false;
$entry->errors->push('Amount of transaction is zero, cannot handle.');
Log::warning('Amount of transaction is zero, cannot handle.');
return $entry;
}
Log::debug('Amount is OK.');
return $entry;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function cleanDescription(ImportEntry $entry): ImportEntry
{
if (!isset($entry->fields['description'])) {
Log::debug('Set empty transaction description because field was not set.');
$entry->fields['description'] = '(empty transaction description)';
return $entry;
}
if (is_null($entry->fields['description'])) {
Log::debug('Set empty transaction description because field was null.');
$entry->fields['description'] = '(empty transaction description)';
return $entry;
}
$entry->fields['description'] = trim($entry->fields['description']);
if (strlen($entry->fields['description']) == 0) {
Log::debug('Set empty transaction description because field was empty.');
$entry->fields['description'] = '(empty transaction description)';
return $entry;
}
Log::debug('Transaction description is OK.', ['description' => $entry->fields['description']]);
return $entry;
}
/**
* @param Account $account
* @param string $type
*
* @return Account
*/
private function convertAccount(Account $account, string $type): Account
{
$accountType = $account->accountType->type;
if ($accountType === $type) {
Log::debug(sprintf('Account %s already of type %s', $account->name, $type));
return $account;
}
// find it first by new type:
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$result = $repository->findByName($account->name, [$type]);
if (is_null($result->id)) {
// can convert account:
Log::debug(sprintf('No account named %s of type %s, create new account.', $account->name, $type));
$result = $repository->store(
[
'user' => $this->user->id,
'accountType' => config('firefly.shortNamesByFullName.' . $type),
'name' => $account->name,
'virtualBalance' => 0,
'active' => true,
'iban' => null,
'openingBalance' => 0,
]
);
}
Log::debug(
sprintf(
'Using another account named %s (#%d) of type %s, will use that one instead of %s (#%d)', $account->name, $result->id, $type, $account->name,
$account->id
)
);
return $result;
}
/**
* @return Account
*/
private function fallbackExpenseAccount(): Account
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$name = 'Unknown expense account';
$result = $repository->findByName($name, [AccountType::EXPENSE]);
if (is_null($result->id)) {
$result = $repository->store(
['name' => $name, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'expense', 'virtualBalance' => 0,
'active' => true]
);
}
return $result;
}
/**
* @return Account
*/
private function fallbackRevenueAccount(): Account
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$name = 'Unknown revenue account';
$result = $repository->findByName($name, [AccountType::REVENUE]);
if (is_null($result->id)) {
$result = $repository->store(
['name' => $name, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'revenue', 'virtualBalance' => 0,
'active' => true]
);
}
return $result;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function setAssetAccount(ImportEntry $entry): ImportEntry
{
if (is_null($entry->fields['asset-account'])) {
if (!is_null($this->defaultImportAccount)) {
Log::debug('Set asset account from default asset account');
$entry->fields['asset-account'] = $this->defaultImportAccount;
return $entry;
}
// default import is null? should not happen. Entry cannot be imported.
// set error message and block.
$entry->valid = false;
Log::warning('Cannot import entry. Asset account is NULL and import account is also NULL.');
return $entry;
}
Log::debug('Asset account is OK.', ['id' => $entry->fields['asset-account']->id, 'name' => $entry->fields['asset-account']->name]);
return $entry;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function setDate(ImportEntry $entry): ImportEntry
{
if (is_null($entry->fields['date-transaction']) || $entry->certain['date-transaction'] == 0) {
// empty date field? find alternative.
$alternatives = ['date-book', 'date-interest', 'date-process'];
foreach ($alternatives as $alternative) {
if (!is_null($entry->fields[$alternative])) {
Log::debug(sprintf('Copied date-transaction from %s.', $alternative));
$entry->fields['date-transaction'] = clone $entry->fields[$alternative];
return $entry;
}
}
// date is still null at this point
Log::debug('Set date-transaction to today.');
$entry->fields['date-transaction'] = new Carbon;
return $entry;
}
// confidence is zero?
Log::debug('Date-transaction is OK');
return $entry;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function setOpposingAccount(ImportEntry $entry): ImportEntry
{
// empty opposing account. Create one based on amount.
if (is_null($entry->fields['opposing-account'])) {
if ($entry->fields['amount'] < 0) {
// create or find general opposing expense account.
Log::debug('Created fallback expense account');
$entry->fields['opposing-account'] = $this->fallbackExpenseAccount();
return $entry;
}
Log::debug('Created fallback revenue account');
$entry->fields['opposing-account'] = $this->fallbackRevenueAccount();
return $entry;
}
// opposing is of type "import". Convert to correct type (by amount):
$type = $entry->fields['opposing-account']->accountType->type;
if ($type == AccountType::IMPORT && $entry->fields['amount'] < 0) {
$account = $this->convertAccount($entry->fields['opposing-account'], AccountType::EXPENSE);
$entry->fields['opposing-account'] = $account;
Log::debug('Converted import account to expense account');
return $entry;
}
if ($type == AccountType::IMPORT && $entry->fields['amount'] > 0) {
$account = $this->convertAccount($entry->fields['opposing-account'], AccountType::REVENUE);
$entry->fields['opposing-account'] = $account;
Log::debug('Converted import account to revenue account');
return $entry;
}
// amount < 0, but opposing is revenue
if ($type == AccountType::REVENUE && $entry->fields['amount'] < 0) {
$account = $this->convertAccount($entry->fields['opposing-account'], AccountType::EXPENSE);
$entry->fields['opposing-account'] = $account;
Log::debug('Converted revenue account to expense account');
return $entry;
}
// amount > 0, but opposing is expense
if ($type == AccountType::EXPENSE && $entry->fields['amount'] > 0) {
$account = $this->convertAccount($entry->fields['opposing-account'], AccountType::REVENUE);
$entry->fields['opposing-account'] = $account;
Log::debug('Converted expense account to revenue account');
return $entry;
}
// account type is OK
Log::debug('Opposing account is OK.');
return $entry;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function setTransactionCurrency(ImportEntry $entry): ImportEntry
{
if (is_null($entry->fields['currency'])) {
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($this->user);
// is the default currency for the user or the system
$defaultCode = Preferences::getForUser($this->user, 'currencyPreference', config('firefly.default_currency', 'EUR'))->data;
$entry->fields['currency'] = $repository->findByCode($defaultCode);
Log::debug(sprintf('Set currency to %s', $defaultCode));
return $entry;
}
Log::debug(sprintf('Currency is OK: %s', $entry->fields['currency']->code));
return $entry;
}
/**
* @param ImportEntry $entry
*
* @return ImportEntry
*/
private function setTransactionType(ImportEntry $entry): ImportEntry
{
Log::debug(sprintf('Opposing account is of type %s', $entry->fields['opposing-account']->accountType->type));
$type = $entry->fields['opposing-account']->accountType->type;
switch ($type) {
case AccountType::EXPENSE:
$entry->fields['transaction-type'] = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
Log::debug('Transaction type is now withdrawal.');
return $entry;
case AccountType::REVENUE:
$entry->fields['transaction-type'] = TransactionType::whereType(TransactionType::DEPOSIT)->first();
Log::debug('Transaction type is now deposit.');
return $entry;
case AccountType::DEFAULT:
case AccountType::ASSET:
$entry->fields['transaction-type'] = TransactionType::whereType(TransactionType::TRANSFER)->first();
Log::debug('Transaction type is now transfer.');
return $entry;
}
Log::warning(sprintf('Opposing account is of type %s, cannot handle this.', $type));
$entry->valid = false;
$entry->errors->push(sprintf('Opposing account is of type %s, cannot handle this.', $type));
return $entry;
}
}

View File

@@ -1,175 +0,0 @@
<?php
/**
* CsvImporter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Importer;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Converter\ConverterInterface;
use FireflyIII\Import\ImportEntry;
use FireflyIII\Import\Specifics\SpecificInterface;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\Collection;
use League\Csv\Reader;
use Log;
/**
* Class CsvImporter
*
* @package FireflyIII\Import\Importer
*/
class CsvImporter implements ImporterInterface
{
/** @var Collection */
public $collection;
/** @var ImportJob */
public $job;
public $validSpecifics = [];
/**
* CsvImporter constructor.
*/
public function __construct()
{
$this->collection = new Collection;
$this->validSpecifics = array_keys(config('csv.import_specifics'));
}
/**
* Run the actual import
*
* @return Collection
*/
public function createImportEntries(): Collection
{
$config = $this->job->configuration;
$content = $this->job->uploadFileContents();
// create CSV reader.
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$start = $config['has-headers'] ? 1 : 0;
$results = $reader->fetch();
Log::notice('Building importable objects from CSV file.');
foreach ($results as $index => $row) {
if ($index >= $start) {
$line = $index + 1;
Log::debug('----- import entry build start --');
Log::debug(sprintf('Now going to import row %d.', $index));
$importEntry = $this->importSingleRow($index, $row);
$this->collection->put($line, $importEntry);
/**
* 1. Build import entry.
* 2. Validate import entry.
* 3. Store journal.
* 4. Run rules.
*/
$this->job->addTotalSteps(4);
$this->job->addStepsDone(1);
}
}
Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
Log::notice(sprintf('Built %d importable object(s) from your CSV file.', $this->collection->count()));
return $this->collection;
}
/**
* @param ImportJob $job
*/
public function setJob(ImportJob $job)
{
$this->job = $job;
}
/**
* @param int $index
* @param array $row
*
* @return ImportEntry
* @throws FireflyException
*/
private function importSingleRow(int $index, array $row): ImportEntry
{
// create import object. This is where each entry ends up.
$object = new ImportEntry;
Log::debug(sprintf('Now at row %d', $index));
// set some vars:
$object->setUser($this->job->user);
$config = $this->job->configuration;
$json = json_encode($row);
if ($json === false) {
throw new FireflyException(sprintf('Could not process row #%d. Are you sure the uploaded file is encoded as "UTF-8"?', $index));
}
// hash the row:
$hash = hash('sha256', $json);
$object->importValue('hash', 100, $hash);
// and this is the point where the specifix go to work.
foreach ($config['specifics'] as $name => $enabled) {
if (!in_array($name, $this->validSpecifics)) {
throw new FireflyException(sprintf('"%s" is not a valid class name', $name));
}
/** @var SpecificInterface $specific */
$specific = app('FireflyIII\Import\Specifics\\' . $name);
// it returns the row, possibly modified:
$row = $specific->run($row);
}
foreach ($row as $rowIndex => $value) {
// find the role for this column:
$role = $config['column-roles'][$rowIndex] ?? '_ignore';
$doMap = $config['column-do-mapping'][$rowIndex] ?? false;
$validConverters = array_keys(config('csv.import_roles'));
// throw error when not a valid converter.
if (!in_array($role, $validConverters)) {
throw new FireflyException(sprintf('"%s" is not a valid role.', $role));
}
$converterClass = config('csv.import_roles.' . $role . '.converter');
$mapping = $config['column-mapping-config'][$rowIndex] ?? [];
$className = sprintf('FireflyIII\\Import\\Converter\\%s', $converterClass);
/** @var ConverterInterface $converter */
$converter = app($className);
// set some useful values for the converter:
$converter->setMapping($mapping);
$converter->setDoMap($doMap);
$converter->setUser($this->job->user);
$converter->setConfig($config);
// run the converter for this value:
$convertedValue = $converter->convert($value);
$certainty = $converter->getCertainty();
// log it.
Log::debug('Value ', ['index' => $rowIndex, 'value' => $value, 'role' => $role]);
// store in import entry:
Log::debug('Going to import', ['role' => $role, 'value' => $value, 'certainty' => $certainty]);
$object->importValue($role, $certainty, $convertedValue);
}
return $object;
}
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* ImporterInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Importer;
use FireflyIII\Models\ImportJob;
use Illuminate\Support\Collection;
/**
* Interface ImporterInterface
*
* @package FireflyIII\Import\Importer
*/
interface ImporterInterface
{
/**
* Run the actual import
*
* @return Collection
*/
public function createImportEntries(): Collection;
/**
* @param ImportJob $job
*
*/
public function setJob(ImportJob $job);
}

View File

@@ -50,7 +50,7 @@ class AssetAccountIbans implements MapperInterface
asort($list);
$list = $topList + $list;
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -47,7 +47,7 @@ class AssetAccounts implements MapperInterface
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -40,7 +40,7 @@ class Bills implements MapperInterface
}
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -41,7 +41,7 @@ class Budgets implements MapperInterface
}
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -41,7 +41,7 @@ class Categories implements MapperInterface
}
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -56,7 +56,7 @@ class OpposingAccountIbans implements MapperInterface
asort($list);
$list = $topList + $list;
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -53,7 +53,7 @@ class OpposingAccounts implements MapperInterface
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;
}

View File

@@ -40,7 +40,7 @@ class Tags implements MapperInterface
}
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -36,7 +36,7 @@ class TransactionCurrencies implements MapperInterface
asort($list);
$list = [0 => trans('csv.do_not_map')] + $list;
$list = [0 => trans('csv.map_do_not_map')] + $list;
return $list;

View File

@@ -0,0 +1,299 @@
<?php
/**
* ImportAccount.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Object;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class ImportAccount
*
* @package FireflyIII\Import\Object
*/
class ImportAccount
{
/** @var Account */
private $account;
/** @var array */
private $accountIban = [];
/** @var array */
private $accountId = [];
/** @var array */
private $accountName = [];
/** @var array */
private $accountNumber = [];
/** @var string */
private $expectedType = '';
/** @var AccountRepositoryInterface */
private $repository;
/** @var User */
private $user;
/**
* ImportAccount constructor.
*/
public function __construct()
{
$this->expectedType = AccountType::ASSET;
$this->account = new Account;
$this->repository = app(AccountRepositoryInterface::class);
Log::debug('Created ImportAccount.');
}
/**
* @return Account
*/
public function getAccount(): Account
{
if (is_null($this->account->id)) {
$this->store();
}
return $this->account;
}
/**
* @param array $accountIban
*/
public function setAccountIban(array $accountIban)
{
$this->accountIban = $accountIban;
}
/**
* @param array $value
*/
public function setAccountId(array $value)
{
$this->accountId = $value;
}
/**
* @param array $accountName
*/
public function setAccountName(array $accountName)
{
$this->accountName = $accountName;
}
/**
* @param array $accountNumber
*/
public function setAccountNumber(array $accountNumber)
{
$this->accountNumber = $accountNumber;
}
/**
* @param string $expectedType
*/
public function setExpectedType(string $expectedType)
{
$this->expectedType = $expectedType;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
$this->repository->setUser($user);
}
/**
* @return Account
*/
private function findExistingObject(): Account
{
Log::debug('In findExistingObject() for Account');
// 0: determin account type:
/** @var AccountType $accountType */
$accountType = AccountType::whereType($this->expectedType)->first();
// 1: find by ID, iban or name (and type)
if (count($this->accountId) === 3) {
Log::debug(sprintf('Finding account of type %d and ID %d', $accountType->id, $this->accountId['value']));
/** @var Account $account */
$account = $this->user->accounts()->where('account_type_id', $accountType->id)->where('id', $this->accountId['value'])->first();
if (!is_null($account)) {
Log::debug(sprintf('Found unmapped %s account by ID (#%d): %s', $this->expectedType, $account->id, $account->name));
return $account;
}
Log::debug('Found nothing.');
}
/** @var Collection $accounts */
$accounts = $this->repository->getAccountsByType([$accountType->type]);
// Two: find by IBAN (and type):
if (count($this->accountIban) === 3) {
$iban = $this->accountIban['value'];
Log::debug(sprintf('Finding account of type %d and IBAN %s', $accountType->id, $iban));
$filtered = $accounts->filter(
function (Account $account) use ($iban) {
if ($account->iban === $iban) {
Log::debug(
sprintf('Found unmapped %s account by IBAN (#%d): %s (%s)', $this->expectedType, $account->id, $account->name, $account->iban)
);
return $account;
}
return null;
}
);
if ($filtered->count() === 1) {
return $filtered->first();
}
Log::debug('Found nothing.');
}
// Three: find by name (and type):
if (count($this->accountName) === 3) {
$name = $this->accountName['value'];
Log::debug(sprintf('Finding account of type %d and name %s', $accountType->id, $name));
$filtered = $accounts->filter(
function (Account $account) use ($name) {
if ($account->name === $name) {
Log::debug(sprintf('Found unmapped %s account by name (#%d): %s', $this->expectedType, $account->id, $account->name));
return $account;
}
return null;
}
);
if ($filtered->count() === 1) {
return $filtered->first();
}
Log::debug('Found nothing.');
}
// 4: do not search by account number.
Log::debug('Found NO existing accounts.');
return new Account;
}
/**
* @return Account
*/
private function findMappedObject(): Account
{
Log::debug('In findMappedObject() for Account');
$fields = ['accountId', 'accountIban', 'accountNumber', 'accountName'];
foreach ($fields as $field) {
$array = $this->$field;
Log::debug(sprintf('Find mapped account based on field "%s" with value', $field), $array);
// check if a pre-mapped object exists.
$mapped = $this->getMappedObject($array);
if (!is_null($mapped->id)) {
Log::debug(sprintf('Found account #%d!', $mapped->id));
return $mapped;
}
}
Log::debug('Found no account on mapped data or no map present.');
return new Account;
}
/**
* @param array $array
*
* @return Account
*/
private function getMappedObject(array $array): Account
{
Log::debug('In getMappedObject() for Account');
if (count($array) === 0) {
Log::debug('Array is empty, nothing will come of this.');
return new Account;
}
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
return new Account;
}
Log::debug('Finding a mapped account based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
Log::debug(sprintf('Found account! #%d ("%s"). Return it', $account->id, $account->name));
return $account;
}
/**
* @return bool
*/
private function store(): bool
{
// 1: find mapped object:
$mapped = $this->findMappedObject();
if (!is_null($mapped->id)) {
$this->account = $mapped;
return true;
}
// 2: find existing by given values:
$found = $this->findExistingObject();
if (!is_null($found->id)) {
$this->account = $found;
return true;
}
// 3: if found nothing, retry the search with an asset account:
Log::debug('Will try to find an asset account just in case.');
$oldExpectedType = $this->expectedType;
$this->expectedType = AccountType::ASSET;
$found = $this->findExistingObject();
if (!is_null($found->id)) {
Log::debug('Found asset account!');
$this->account = $found;
return true;
}
$this->expectedType = $oldExpectedType;
Log::debug(sprintf('Found no account of type %s so must create one ourselves.', $this->expectedType));
$data = [
'accountType' => config('firefly.shortNamesByFullName.' . $this->expectedType),
'name' => $this->accountName['value'] ?? '(no name)',
'iban' => $this->accountIban['value'] ?? null,
'active' => true,
'virtualBalance' => null,
];
$this->account = $this->repository->store($data);
Log::debug(sprintf('Successfully stored new account #%d: %s', $this->account->id, $this->account->name));
return true;
}
}

View File

@@ -0,0 +1,228 @@
<?php
/**
* ImportBill.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Object;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class ImportBill
*
* @package FireflyIII\Import\Object
*/
class ImportBill
{
/** @var Bill */
private $bill;
/** @var array */
private $id = [];
/** @var array */
private $name = [];
/** @var BillRepositoryInterface */
private $repository;
/** @var User */
private $user;
/**
* ImportBill constructor.
*/
public function __construct()
{
$this->bill = new Bill;
$this->repository = app(BillRepositoryInterface::class);
Log::debug('Created ImportBill.');
}
/**
* @return Bill
*/
public function getBill(): Bill
{
if (is_null($this->bill->id)) {
$this->store();
}
return $this->bill;
}
/**
* @param array $id
*/
public function setId(array $id)
{
$this->id = $id;
}
/**
* @param array $name
*/
public function setName(array $name)
{
$this->name = $name;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
$this->repository->setUser($user);
}
/**
* @return Bill
*/
private function findExistingObject(): Bill
{
Log::debug('In findExistingObject() for Bill');
// 1: find by ID, or name
if (count($this->id) === 3) {
Log::debug(sprintf('Finding bill with ID #%d', $this->id['value']));
/** @var Bill $bill */
$bill = $this->repository->find(intval($this->id['value']));
if (!is_null($bill->id)) {
Log::debug(sprintf('Found unmapped bill by ID (#%d): %s', $bill->id, $bill->name));
return $bill;
}
Log::debug('Found nothing.');
}
// 2: find by name
if (count($this->name) === 3) {
/** @var Collection $bills */
$bills = $this->repository->getBills();
$name = $this->name['value'];
Log::debug(sprintf('Finding bill with name %s', $name));
$filtered = $bills->filter(
function (Bill $bill) use ($name) {
if ($bill->name === $name) {
Log::debug(sprintf('Found unmapped bill by name (#%d): %s', $bill->id, $bill->name));
return $bill;
}
return null;
}
);
if ($filtered->count() === 1) {
return $filtered->first();
}
Log::debug('Found nothing.');
}
// 4: do not search by account number.
Log::debug('Found NO existing bills.');
return new Bill;
}
/**
* @return Bill
*/
private function findMappedObject(): Bill
{
Log::debug('In findMappedObject() for Bill');
$fields = ['id', 'name'];
foreach ($fields as $field) {
$array = $this->$field;
Log::debug(sprintf('Find mapped bill based on field "%s" with value', $field), $array);
// check if a pre-mapped object exists.
$mapped = $this->getMappedObject($array);
if (!is_null($mapped->id)) {
Log::debug(sprintf('Found bill #%d!', $mapped->id));
return $mapped;
}
}
Log::debug('Found no bill on mapped data or no map present.');
return new Bill;
}
/**
* @param array $array
*
* @return Bill
*/
private function getMappedObject(array $array): Bill
{
Log::debug('In getMappedObject() for Bill');
if (count($array) === 0) {
Log::debug('Array is empty, nothing will come of this.');
return new Bill;
}
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
return new Bill;
}
Log::debug('Finding a mapped bill based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
Log::debug(sprintf('Found bill! #%d ("%s"). Return it', $account->id, $account->name));
return $account;
}
/**
* @return bool
*/
private function store(): bool
{
// 1: find mapped object:
$mapped = $this->findMappedObject();
if (!is_null($mapped->id)) {
$this->bill = $mapped;
return true;
}
// 2: find existing by given values:
$found = $this->findExistingObject();
if (!is_null($found->id)) {
$this->bill = $found;
return true;
}
$name = $this->name['value'] ?? '';
if (strlen($name) === 0) {
return true;
}
Log::debug('Found no bill so must create one ourselves.');
$data = [
'name' => $name,
];
$this->bill = $this->repository->store($data);
Log::debug(sprintf('Successfully stored new bill #%d: %s', $this->bill->id, $this->bill->name));
return true;
}
}

View File

@@ -0,0 +1,229 @@
<?php
/**
* ImportBudget.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Import\Object;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class ImportBudget
*
* @package FireflyIII\Import\Object
*/
class ImportBudget
{
/** @var Budget */
private $budget;
/** @var array */
private $id = [];
/** @var array */
private $name = [];
/** @var BudgetRepositoryInterface */
private $repository;
/** @var User */
private $user;
/**
* ImportBudget constructor.
*/
public function __construct()
{
$this->budget = new Budget;
$this->repository = app(BudgetRepositoryInterface::class);
Log::debug('Created ImportBudget.');
}
/**
* @return Budget
*/
public function getBudget(): Budget
{
if (is_null($this->budget->id)) {
$this->store();
}
return $this->budget;
}
/**
* @param array $id
*/
public function setId(array $id)
{
$this->id = $id;
}
/**
* @param array $name
*/
public function setName(array $name)
{
$this->name = $name;
}
/**
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
$this->repository->setUser($user);
}
/**
* @return Budget
*/
private function findExistingObject(): Budget
{
Log::debug('In findExistingObject() for Budget');
// 1: find by ID, or name
if (count($this->id) === 3) {
Log::debug(sprintf('Finding budget with ID #%d', $this->id['value']));
/** @var Budget $budget */
$budget = $this->repository->find(intval($this->id['value']));
if (!is_null($budget->id)) {
Log::debug(sprintf('Found unmapped budget by ID (#%d): %s', $budget->id, $budget->name));
return $budget;
}
Log::debug('Found nothing.');
}
// 2: find by name
if (count($this->name) === 3) {
/** @var Collection $budgets */
$budgets = $this->repository->getBudgets();
$name = $this->name['value'];
Log::debug(sprintf('Finding budget with name %s', $name));
$filtered = $budgets->filter(
function (Budget $budget) use ($name) {
if ($budget->name === $name) {
Log::debug(sprintf('Found unmapped budget by name (#%d): %s', $budget->id, $budget->name));
return $budget;
}
return null;
}
);
if ($filtered->count() === 1) {
return $filtered->first();
}
Log::debug('Found nothing.');
}
// 4: do not search by account number.
Log::debug('Found NO existing budgets.');
return new Budget;
}
/**
* @return Budget
*/
private function findMappedObject(): Budget
{
Log::debug('In findMappedObject() for Budget');
$fields = ['id', 'name'];
foreach ($fields as $field) {
$array = $this->$field;
Log::debug(sprintf('Find mapped budget based on field "%s" with value', $field), $array);
// check if a pre-mapped object exists.
$mapped = $this->getMappedObject($array);
if (!is_null($mapped->id)) {
Log::debug(sprintf('Found budget #%d!', $mapped->id));
return $mapped;
}
}
Log::debug('Found no budget on mapped data or no map present.');
return new Budget;
}
/**
* @param array $array
*
* @return Budget
*/
private function getMappedObject(array $array): Budget
{
Log::debug('In getMappedObject() for Budget');
if (count($array) === 0) {
Log::debug('Array is empty, nothing will come of this.');
return new Budget;
}
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
return new Budget;
}
Log::debug('Finding a mapped budget based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
Log::debug(sprintf('Found budget! #%d ("%s"). Return it', $account->id, $account->name));
return $account;
}
/**
* @return bool
*/
private function store(): bool
{
// 1: find mapped object:
$mapped = $this->findMappedObject();
if (!is_null($mapped->id)) {
$this->budget = $mapped;
return true;
}
// 2: find existing by given values:
$found = $this->findExistingObject();
if (!is_null($found->id)) {
$this->budget = $found;
return true;
}
$name = $this->name['value'] ?? '';
if (strlen($name) === 0) {
return true;
}
Log::debug('Found no budget so must create one ourselves.');
$data = [
'name' => $name,
];
$this->budget = $this->repository->store($data);
Log::debug(sprintf('Successfully stored new budget #%d: %s', $this->budget->id, $this->budget->name));
return true;
}
}

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