Compare commits

...

262 Commits
3.10 ... 4.0.2

Author SHA1 Message Date
James Cole
399db47826 Merge branch 'release/4.0.2' 2016-10-14 17:15:47 +02:00
James Cole
148956a60d Some code reformatting. 2016-10-14 17:14:54 +02:00
James Cole
3670053a58 Some code reformatting [skip ci] 2016-10-14 17:14:28 +02:00
James Cole
e8e2b9704f New translations. 2016-10-14 17:14:04 +02:00
James Cole
fcdeebcc06 Some last minute updated texts. 2016-10-14 16:51:38 +02:00
James Cole
586ed82e88 New changelog. 2016-10-14 16:26:05 +02:00
James Cole
cc400d1e2e Merge pull request #356 from telyn/require-intl
Require PHP intl extension
2016-10-12 10:32:28 +02:00
Telyn
6edbfb27aa Add ext-intl to dependencies 2016-10-12 09:22:21 +01:00
James Cole
8fc9251b93 Fix name of language. [skip ci] 2016-10-10 19:08:09 +02:00
James Cole
10af888a97 Expand view [skip ci] 2016-10-10 13:27:35 +02:00
James Cole
89f2328846 Forgot include [skip ci] 2016-10-10 13:25:27 +02:00
James Cole
48e8cd20b4 Removed unused Twig methods. 2016-10-10 13:08:02 +02:00
James Cole
394ef23eda New local names [skip ci] 2016-10-10 08:27:08 +02:00
James Cole
62aa1eb487 Updated translations [skip ci] 2016-10-10 08:19:00 +02:00
James Cole
1500018ccc A new language arrives! [skip ci] 2016-10-10 08:13:27 +02:00
James Cole
23fad62d46 Completely removed account crud class. 2016-10-10 08:03:03 +02:00
James Cole
3cbf00734f Remove storeMeta 2016-10-10 07:53:25 +02:00
James Cole
1dc17dd59d Move getActiveAccountsByType 2016-10-10 07:53:12 +02:00
James Cole
f8935c92ea Unrelated code cleanup. 2016-10-10 07:49:55 +02:00
James Cole
de6f838413 Moved getAccountsByType 2016-10-10 07:49:39 +02:00
James Cole
e8a095e543 Moved getAccountsById 2016-10-10 07:25:27 +02:00
James Cole
717c1d080e Copied (not yet removed) findByName 2016-10-10 07:20:49 +02:00
James Cole
0ae9afd325 Move findByIban 2016-10-10 07:16:05 +02:00
James Cole
d1b56c2afa Moved findByAccountNumber 2016-10-10 07:14:01 +02:00
James Cole
8ef7c5ac33 Moved find() method to new class. 2016-10-10 07:12:39 +02:00
James Cole
7180a40cd8 Refactored some methods surrounding the opening balance of an account. 2016-10-10 07:01:14 +02:00
James Cole
71804af624 Updated some model code. 2016-10-10 06:50:24 +02:00
James Cole
85dc7f3643 Moved another method. 2016-10-10 06:49:50 +02:00
James Cole
a866d13b75 Forgot to add argument 2016-10-10 06:49:39 +02:00
James Cole
fcb5e4eabc Moved leftOnAccount() 2016-10-10 06:47:42 +02:00
James Cole
ade1cf9c19 Fixed wrong listing. 2016-10-10 06:40:50 +02:00
James Cole
0f1ec7d003 Removed double method. 2016-10-09 21:49:31 +02:00
James Cole
7e038afece Must be unsigned 2016-10-09 21:36:22 +02:00
James Cole
9bb8e182fa Forgot a translation 2016-10-09 21:36:15 +02:00
James Cole
e94ae126fd Refactored accountRepository::getJournals > accountTasker > getJournals 2016-10-09 21:36:03 +02:00
James Cole
5bb8c6a366 This should fix #355 2016-10-09 20:18:46 +02:00
James Cole
30844df5d4 Merge branch 'develop' of https://github.com/JC5/firefly-iii into develop
* 'develop' of https://github.com/JC5/firefly-iii:
  Fixed issue causing all imported transactions to have unknown opposing account with ABN AMRO specific
2016-10-09 20:18:14 +02:00
James Cole
63e4a410a7 Merge pull request #354 from roberthorlings/bugfix/abn-amro-specific
Bugfix for issue with ABN AMRO specific
2016-10-09 20:00:48 +02:00
Robert Horlings
ee9a5d91e2 Merge branch 'develop' into bugfix/abn-amro-specific 2016-10-09 19:53:11 +02:00
Robert Horlings
171ab8a4c3 Fixed issue causing all imported transactions to have unknown opposing account with ABN AMRO specific 2016-10-09 17:19:00 +02:00
James Cole
96740aaac4 Extend transaction model for #351 2016-10-09 17:06:52 +02:00
James Cole
2017720096 Experimental new getJournals method. 2016-10-09 16:22:08 +02:00
James Cole
b77ea6d316 Add some phpdoc 2016-10-09 11:21:41 +02:00
James Cole
f5adb4047f Remove methods no longer used. 2016-10-09 10:59:28 +02:00
James Cole
b082858866 Removed unused blocks from the front page. Savings and piggy banks. 2016-10-09 10:58:54 +02:00
James Cole
a8a014189d Removed method that was already there under another name. 2016-10-09 10:57:06 +02:00
James Cole
39ea9e85a7 Various code cleanup and refactoring. Restored cache. 2016-10-09 10:53:37 +02:00
James Cole
a4d2ed74fc Make sure all journals are included. 2016-10-09 09:41:03 +02:00
James Cole
90f2e27f1f Refactoring income and expense reports. 2016-10-09 09:32:12 +02:00
James Cole
a3359ba47a Moved destroy() method from CRUD to Account repos. 2016-10-09 08:20:29 +02:00
James Cole
1d2d3523d6 Move CRUD method count() to account repository 2016-10-09 08:18:47 +02:00
James Cole
3f40751a1a Forgot to exclude a method. 2016-10-09 08:06:49 +02:00
James Cole
b5b55e862c Clean up code. 2016-10-09 07:59:14 +02:00
James Cole
c64771b76b Move some methods around, refactoring. 2016-10-09 07:58:27 +02:00
James Cole
ea7ee7ee9a Moved a report out of the controller. 2016-10-08 16:24:07 +02:00
James Cole
a1f797c4d1 Moved a method around. 2016-10-08 16:04:05 +02:00
James Cole
d0c92a2244 Clean up account report helper. 2016-10-08 15:59:58 +02:00
James Cole
6e90c033b1 Start of some remodelling. 2016-10-08 14:54:32 +02:00
James Cole
24f62b8fce Some minor refactoring. 2016-10-08 10:02:33 +02:00
James Cole
d43936155c Removed some unused code. 2016-10-07 16:33:17 +02:00
James Cole
39dab4fdd9 Remove unused class. 2016-10-07 12:28:14 +02:00
James Cole
c0fdf44ad2 Small cleaning up. 2016-10-07 11:40:03 +02:00
James Cole
4d91f7d23a This fixes #344 2016-10-07 09:40:50 +02:00
James Cole
49af6522a8 Some code cleanup. 2016-10-07 05:44:21 +02:00
James Cole
3c5f9487a8 Prep change log for next version [skip ci] 2016-10-07 05:43:47 +02:00
James Cole
f5cb87f5c3 Merge pull request #348 from SanderKleykens/feature/postgres-compatibility
PostgreSQL compatibility
2016-10-07 05:32:10 +02:00
Sander Kleykens
cf543613c9 Fix the CSV importer failing when using PostgreSQL
Add ordered column to the list of columns that are selected so PostgreSQL doesn't throw an error
2016-10-06 23:49:33 +02:00
Sander Kleykens
5c239c91db Convert raw XORs to a construct compatible with Laravel's query builder 2016-10-06 22:27:10 +02:00
James Cole
9920504232 Fixes #346 2016-10-06 05:26:38 +02:00
James Cole
5540697dbd Removed a method no longer necessary. 2016-10-05 16:09:37 +02:00
James Cole
b355c18e0c Some code cleanup and copyright cleanup. [skip ci] 2016-10-05 06:52:15 +02:00
James Cole
1e90485c5f Merge branch 'master' into develop
* master:
  added some comments
  removed some debug commands
  Better descriptions for ING accounts
2016-10-05 06:31:47 +02:00
James Cole
dc784c53b5 Fix for #343 2016-10-04 21:51:46 +02:00
James Cole
5a47391a64 Merge branch 'release/4.0.1' 2016-10-04 20:13:50 +02:00
James Cole
8a106bd16a Merge branch 'release/4.0.1' into develop 2016-10-04 20:13:50 +02:00
James Cole
a31ac79173 New version. 2016-10-04 20:13:40 +02:00
James Cole
0d0a604254 Changelog for 4.0.1 [skip ci] 2016-10-04 20:13:09 +02:00
James Cole
724d25f2c2 Merge branch 'develop'
* develop:
  Fixed some rare bugs.
  Extra clear button to reapply rules #307
  Fix trim when null [skip ci]
  Fixed a bug where incoming transactions would not be properly filtered in several reports.
  Removed for #334
  Fix #337 [skip ci]
  Fix #335
  Remove account extra text #336 [skip ci]
  Fixes bug #338
  Refer to correct page [skip ci]
  Catch unset row.
2016-10-04 20:08:35 +02:00
James Cole
8ed22d452d Merge pull request #342 from tomwerf/master
ING Import
2016-10-04 20:02:34 +02:00
Tom van der Werf
d7fef45a56 added some comments 2016-10-04 17:50:01 +00:00
Tom van der Werf
dc22802dec removed some debug commands 2016-10-04 17:30:49 +00:00
Tom van der Werf
ce5af7b1d9 Better descriptions for ING accounts 2016-10-03 17:08:24 +00:00
James Cole
0a147e5c9c Fixed some rare bugs. 2016-10-02 15:09:43 +02:00
James Cole
7d21255f7f Extra clear button to reapply rules #307 2016-10-02 08:14:11 +02:00
James Cole
13f952f182 Fix trim when null [skip ci] 2016-10-01 09:41:16 +02:00
James Cole
b494be228b Fixed a bug where incoming transactions would not be properly filtered in several reports. 2016-10-01 09:37:18 +02:00
James Cole
0fdaac53d0 Removed for #334 2016-10-01 08:49:33 +02:00
James Cole
e1b3a08878 Fix #337 [skip ci] 2016-10-01 08:49:02 +02:00
James Cole
dc893588b0 Fix #335 2016-10-01 08:48:13 +02:00
James Cole
b9fcc443ec Remove account extra text #336 [skip ci] 2016-10-01 08:45:14 +02:00
James Cole
d8586c8043 Fixes bug #338 2016-09-29 19:17:24 +02:00
James Cole
4252a3e53b Refer to correct page [skip ci] 2016-09-29 07:04:58 +02:00
James Cole
dbb5cdb9cf Catch unset row. 2016-09-29 07:02:47 +02:00
James Cole
9bdfecbfdc Merge branch 'release/4.0.0' 2016-09-26 18:37:33 +02:00
James Cole
3ec8a8c375 Merge branch 'release/4.0.0' into develop 2016-09-26 18:37:33 +02:00
James Cole
f85e4a24e5 New license information. 2016-09-26 18:37:20 +02:00
James Cole
0dda87c78e New license. 2016-09-26 18:34:31 +02:00
James Cole
2fc09ff9d7 Fix empty pop-ups in report. 2016-09-25 14:47:55 +02:00
James Cole
e4e0e21293 Smaller method. 2016-09-25 08:59:27 +02:00
James Cole
15089f0d7e Some issues fixed for scrutiniser. 2016-09-25 08:50:12 +02:00
James Cole
7232c1d7bb partial fix for #307 2016-09-25 08:46:57 +02:00
James Cole
9a53d8c21c Some array_keys fixes. 2016-09-25 08:46:42 +02:00
James Cole
0d198193db Some issues fixed for scrutiniser. 2016-09-25 08:36:35 +02:00
James Cole
45bc23b8af Some issues fixed for scrutiniser. 2016-09-25 08:32:53 +02:00
James Cole
3323c31765 Some issues fixed for scrutiniser. 2016-09-25 08:24:03 +02:00
James Cole
bb7c26b77c Some issues fixed for scrutiniser. 2016-09-25 08:20:17 +02:00
James Cole
9101d6a2c0 Add lines to configuration on wiki. [skip ci] 2016-09-24 19:32:00 +02:00
James Cole
ad2b254be0 Fix for issue #328. Turns out the import routine converts accounts back and forth instead of creating new entries. 2016-09-24 18:59:31 +02:00
James Cole
abc4f856ce Fix nullable fields. 2016-09-24 17:22:42 +02:00
James Cole
b3b66a8f92 Merge pull request #329 from niekvanderkooy/develop
Fix assignment of array variables
2016-09-24 17:04:32 +02:00
Niek van der Kooy
2f7cf9b916 Fix assignment of array variables 2016-09-24 17:01:41 +02:00
James Cole
b822e0c6e7 Upgrade stuff for 4.0.0 2016-09-24 15:30:08 +02:00
James Cole
6fef9ee72b #315 2016-09-24 10:58:48 +02:00
James Cole
ab6dd0a1ec #314 2016-09-24 10:55:13 +02:00
James Cole
9deef5ac92 #325 2016-09-24 10:53:39 +02:00
James Cole
577187babe Fix #324 [skip ci] 2016-09-24 10:52:13 +02:00
James Cole
577290e813 add strtolower [skip ci] 2016-09-24 09:14:47 +02:00
James Cole
f3b9798216 Fix some rule things. 2016-09-24 09:12:17 +02:00
James Cole
4dcaa96d16 Fix group error. I hope. 2016-09-24 08:59:29 +02:00
James Cole
0dcbf451d6 Add verify command to composer.json 2016-09-24 08:59:14 +02:00
James Cole
e87f6ca40e Fix some possible NULL values. 2016-09-24 08:55:01 +02:00
James Cole
1f34e33d8c Update composer, improve verify routine. 2016-09-23 22:31:01 +02:00
James Cole
258e87e127 Merge pull request #323 from Mortalife/master
Adding GBP to Seed
2016-09-22 07:58:21 +02:00
Matthew Peck
3ec8efcfc1 Adding GBP to Seed 2016-09-21 20:45:36 +01:00
James Cole
70ea227bd0 Add logging to processor #322 2016-09-21 21:01:10 +02:00
James Cole
27c832ed58 Logging for rule triggers #322 2016-09-21 20:58:12 +02:00
James Cole
a31b4ccf01 Basic logging for willMatchEverything #322 2016-09-21 20:30:09 +02:00
James Cole
d221ea68d0 Gave all rule actions some logging. #322 2016-09-21 20:12:04 +02:00
James Cole
dc9fe58536 Fix tags input width. 2016-09-21 19:23:50 +02:00
James Cole
f871e29bdb Quick fix for broken attachments. 2016-09-21 19:16:47 +02:00
James Cole
1357352276 Merge pull request #320 from Mortalife/master
Decimal place fix on import
2016-09-20 20:21:02 +02:00
James Cole
e169754693 Fix display bug for attachments 2016-09-20 17:23:12 +02:00
James Cole
1cfe4f40ba Fix display bug for attachments 2016-09-20 17:22:07 +02:00
James Cole
5545d1c1ba Fix display bug for attachments 2016-09-20 17:21:26 +02:00
James Cole
e5f7228fa9 Fix future query problems (current users not affected either way) [skip ci] 2016-09-20 09:32:58 +02:00
James Cole
11385494eb Fix for income entry. 2016-09-20 08:57:08 +02:00
James Cole
ae328de469 Fix bug in year report. 2016-09-20 08:26:42 +02:00
James Cole
0574a706c8 Error in decrypt error (yes) 2016-09-20 07:57:04 +02:00
Matthew Peck
70bb85a75b Cleanup 2016-09-20 00:00:11 +01:00
Matthew Peck
8cd901b57b Added support for multiple decimal places 2016-09-19 23:53:51 +01:00
James Cole
8b9818c48e This will fix #316 2016-09-18 20:00:13 +02:00
James Cole
a95099fa46 Update FF configuration. 2016-09-18 19:57:21 +02:00
James Cole
221e4b7fc0 Fix some migrations [skip ci] 2016-09-18 18:14:07 +02:00
James Cole
6cff3eb61e Fix some migrations [skip ci] 2016-09-18 17:52:31 +02:00
James Cole
e4fd97ae77 Some code fixes. [skip ci] 2016-09-17 09:52:28 +02:00
James Cole
5ca9099654 Some code fixes. 2016-09-17 09:50:40 +02:00
James Cole
6e33e26ddf Update copyright notices, update German language. 2016-09-17 07:57:32 +02:00
James Cole
04461a4ab8 Updated composer.lock [skip ci] 2016-09-17 07:22:39 +02:00
James Cole
a4b9bbff54 Update AdminLTE template. 2016-09-17 07:19:09 +02:00
James Cole
4ad4252a77 Extend exclude path. Trigger a new inspection. 2016-09-17 07:10:29 +02:00
James Cole
aac0c9ab98 Various layout updates and tiny upgrade fixes [skip ci] 2016-09-16 13:29:56 +02:00
James Cole
c123e1044a Expand config so people won't get errors here [skip ci] 2016-09-16 12:19:29 +02:00
James Cole
d25d0454fc Code clean up 2016-09-16 12:15:58 +02:00
James Cole
f38984398d Code clean up [skip ci] 2016-09-16 12:07:45 +02:00
James Cole
a07799cfa4 MySQL 5.7 compatible query fixing. [skip ci] 2016-09-16 11:16:31 +02:00
James Cole
7c52f297ee MySQL 5.7 compatible query fixing. [skip ci] 2016-09-16 11:06:21 +02:00
James Cole
50a3279b30 MySQL 5.7 compatible query fixing. [skip ci] 2016-09-16 11:04:24 +02:00
James Cole
0ea14eb987 MySQL 5.7 compatible grouping. [skip ci] 2016-09-16 11:01:35 +02:00
James Cole
cf1b98e569 MySQL 5.7 compatible grouping. 2016-09-16 10:55:26 +02:00
James Cole
63fb435002 Expand code. 2016-09-16 10:50:19 +02:00
James Cole
2f8263f53a Possible fix for reports [skip ci] 2016-09-16 09:36:08 +02:00
James Cole
fb649779d6 Do not need to sort. Fix MySQL 5.7 compatibility. 2016-09-16 09:31:40 +02:00
James Cole
bb58f605f7 Some new login / logout routes 2016-09-16 09:21:36 +02:00
James Cole
fccdf56c5d Fixed some query things. 2016-09-16 09:09:54 +02:00
James Cole
bd53410c71 Some changes in login routes for 5.3 2016-09-16 09:02:35 +02:00
James Cole
7d63f124c4 Fixing some login routes 2016-09-16 07:22:57 +02:00
James Cole
9ffc5d857c Fixed some db bugs. These will only pop up when developing. 2016-09-16 07:16:09 +02:00
James Cole
2f93784acd More code for 5.3 2016-09-16 07:05:34 +02:00
James Cole
d00fbe4eb3 More code for 5.3 2016-09-16 06:48:38 +02:00
James Cole
51d9f041ae Changes for login routes. 2016-09-16 06:43:13 +02:00
James Cole
b872ab8b86 New code and new routes for 5.3 2016-09-16 06:40:45 +02:00
James Cole
3d25fd79ca First set of upgrade to 5.3 stuff. 2016-09-16 06:19:40 +02:00
James Cole
3aad78e6ef Lots of updated libraries.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-15 19:14:55 +02:00
James Cole
7d5bb72b0c Fix for #312
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-15 19:14:22 +02:00
James Cole
46e5aae8bb Fix changelog. [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-15 19:00:22 +02:00
James Cole
b9e2ee7af3 Merge branch 'release/3.10.4' 2016-09-14 20:40:52 +02:00
James Cole
c1a2892788 New changelog.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-14 20:40:12 +02:00
James Cole
2078183e0d Update version and composer file. 2016-09-14 20:37:12 +02:00
James Cole
fab1d53714 Simplified upgrade instructions. 2016-09-14 20:35:45 +02:00
James Cole
3fe831c7d8 Bit of code cleanup courtesy of PHPStorm. 2016-09-13 19:20:09 +02:00
James Cole
6958f71cfd @fuf discovered a bug where FF3 will fall back to the hard-coded system default currency and not the set default currency. See #307 2016-09-13 19:19:58 +02:00
James Cole
a7351f348d Fixed a bug mentioned by @vissert and added some logging for @sandermulders
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-12 18:43:10 +02:00
James Cole
5379e03447 Merge pull request #311 from sandermulders/fix/nullable-values
add migration that correctly sets nullable for description fields on rules and rule_groups
2016-09-12 16:52:14 +02:00
Sander Mulders
539058e32d Fix for #310: add migration that correctly sets nullable for description fields on rules and rule_groups 2016-09-12 14:24:01 +02:00
James Cole
11b6b5a63c Merge branch 'release/3.10.3' into develop 2016-09-11 08:17:42 +02:00
James Cole
1155096226 Merge branch 'release/3.10.3' 2016-09-11 08:17:41 +02:00
James Cole
2920dd356e Updated translations.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-11 08:17:35 +02:00
James Cole
9c3dac8170 Config for new version.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-11 08:13:22 +02:00
James Cole
49f9909b15 New changelog.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-11 08:13:14 +02:00
James Cole
e4fef6dfc3 Fixed an import bug where a new transaction validation rule would break storing of the transaction, while the import would not notice this error happening. The importer will now also correctly set a date on the "import tag" and will not tag an incomplete journal as already imported.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-11 08:08:01 +02:00
James Cole
2da087401e Extend audit report
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-10 18:37:16 +02:00
James Cole
629baf9de5 Added invoice date
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-10 18:36:52 +02:00
James Cole
29a930dae5 Updated translations.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 11:36:19 +02:00
James Cole
d920537dd2 Updated translations.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 11:29:19 +02:00
James Cole
106b04a5da Update composer.lock [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 11:19:50 +02:00
James Cole
176752e219 Code for optional fields #301
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 11:19:40 +02:00
James Cole
8d19f60091 Various translation updates.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 11:19:19 +02:00
James Cole
e937aa2f74 Fix a bug in piggy bank display [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-09 06:17:50 +02:00
James Cole
c3ccc4ccdf This should fix #308
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-08 21:10:24 +02:00
James Cole
6c5cd705c0 Some code for new optional fields, see #301
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-04 16:21:51 +02:00
James Cole
ce003f217b Removed unused "budget maximum" preference 2016-09-03 21:13:08 +02:00
James Cole
8c7ef49eb6 New code by @vissert that allows category edit (see #282)
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-03 05:01:48 +02:00
James Cole
29af4bd1b9 This fixes #303 2016-09-03 04:54:57 +02:00
James Cole
2ce5142b06 Small fix for #303
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-01 19:01:08 +02:00
James Cole
f3a8a25872 Fixed #303
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-09-01 18:31:39 +02:00
James Cole
598e97d028 Forgot to escape things, which causes havoc in the Dutch translation.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-31 18:50:46 +02:00
James Cole
fa110279de Merge branch 'release/3.10.2' 2016-08-29 19:32:49 +02:00
James Cole
8fdeaf73cc Update composer.lock [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-29 19:32:03 +02:00
James Cole
a7ffdf062a Update changelog. [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-29 19:26:31 +02:00
James Cole
3bad92dd6d Upgrade instructions and new version.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-29 19:25:21 +02:00
James Cole
2e88024bca Close #290
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-29 19:21:40 +02:00
James Cole
ca2301959c Merge pull request #298 from Bonno/develop
Fixed wrong conversion to revenue account
2016-08-29 14:49:46 +02:00
Bonno Nachtegaal-Karels
3285fae7f0 Fixed wrong conversion to revenue account 2016-08-29 14:39:43 +02:00
James Cole
312079657b Include files from new import routine in export routine. 2016-08-28 07:05:42 +02:00
James Cole
18c183afd6 Remove form tags in favour of raw html.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 09:38:58 +02:00
James Cole
f424d9cf20 Update change log
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 04:37:04 +02:00
James Cole
5c3da9fd9e New language files.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 04:34:59 +02:00
James Cole
1f321fadd4 Removed some form-tags in favour of plain HTML
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 04:18:02 +02:00
James Cole
65f5d27b12 New pages for administration. More settings will be web-based.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 04:00:48 +02:00
James Cole
cdb591de7f Remove unnecessary setting.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 04:00:19 +02:00
James Cole
a0ea3882e1 Various code cleanup.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-27 03:50:35 +02:00
James Cole
a9444ac702 Code cleanup.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 09:30:52 +02:00
James Cole
d0c6afc3a9 Various code clean up. [skip ci] 2016-08-26 08:21:31 +02:00
James Cole
e7a0a5937c Extend git ignore. [skip ci]
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:41:13 +02:00
James Cole
08992b5298 Extend test-import data set to contain some rules.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:38:00 +02:00
James Cole
6490a4240d Remove references to ImportResult. Add the application of user rules.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:37:47 +02:00
James Cole
43a7544dd7 Catch empty (null) descriptions. Which never happens.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:37:27 +02:00
James Cole
0fe70dae17 Referring to Auth::user will not work from the command line.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:37:09 +02:00
James Cole
7079e76886 Remove some commented code.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:36:33 +02:00
James Cole
0ec021c375 No need to grab journals we don't need.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:36:26 +02:00
James Cole
ff3396e286 Removed the ImportResult class because it was lame.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-26 07:36:13 +02:00
James Cole
78912903ce Change signature of importstorage. 2016-08-26 06:47:12 +02:00
James Cole
4c015e2d12 Re-arrange code. No changes. 2016-08-26 06:44:24 +02:00
James Cole
172634a55a Add some comments. 2016-08-26 06:43:38 +02:00
James Cole
58ca7d551a Rename import procedure method name 2016-08-26 06:43:23 +02:00
James Cole
fd8ed4c9aa Fixed a bug in strict typing.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-25 19:19:12 +02:00
James Cole
c03f5f5ff0 Merge branch 'release/3.10.1' 2016-08-25 11:20:39 +02:00
James Cole
6775fc58c8 Change log and updated config.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-25 11:20:13 +02:00
James Cole
9f250fc61b Renamed migration. 2016-08-25 11:16:17 +02:00
James Cole
94609f1419 Clean up some code. 2016-08-25 06:44:48 +02:00
James Cole
53402aa5e2 Update composer file. 2016-08-25 06:44:41 +02:00
James Cole
5aadb29905 Add some forgotten code to the mobile piggy bank controller things.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-24 20:06:45 +02:00
James Cole
d4f8c41d80 This should fix a bug in the verification routine.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-24 19:36:09 +02:00
James Cole
a2e14f8b8d Various code clean up.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
2016-08-24 19:33:58 +02:00
James Cole
98c4ac955a Finetune user feedback during import and add a tag to collect transactions. 2016-08-14 11:31:09 +02:00
James Cole
70b63e1736 Better report for finished import. 2016-08-14 10:11:49 +02:00
James Cole
106665a468 Better reporting for double imported rows. See also #164 2016-08-14 09:49:04 +02:00
James Cole
da5e48d769 More language lines. Add a check for double lines. 2016-08-14 09:10:47 +02:00
James Cole
85f484e73c Divide by zero. 2016-08-14 09:10:08 +02:00
James Cole
d287ae97f8 Prep for translations in JS. 2016-08-14 08:34:59 +02:00
James Cole
117bb602dc Extend ImportObject with row hash. 2016-08-14 08:34:51 +02:00
James Cole
e440d55034 Finetune import status page. 2016-08-14 08:10:42 +02:00
James Cole
7f5b94fe43 Fixed a bug in the verify routine. 2016-08-13 23:31:42 +02:00
James Cole
c58eea6654 Fine-tuning the import routine. 2016-08-13 23:28:01 +02:00
James Cole
bbed5d0701 First version of a web-based import status thing. 2016-08-13 21:51:01 +02:00
James Cole
2775690fc8 Extend model to allow for more data during the import. 2016-08-13 18:53:16 +02:00
James Cole
1fd9f6e724 First user interface elements and routes for web import. 2016-08-13 16:38:58 +02:00
James Cole
3d63903128 Make sure import errors end up where the user can read them. 2016-08-13 16:29:24 +02:00
James Cole
ef876a165a Some better feedback in the import process. 2016-08-13 14:22:40 +02:00
James Cole
c4d6aaeef3 Extend scrutinizer config. 2016-08-12 16:06:27 +02:00
James Cole
37b735c2e3 Remove code climate config 2016-08-12 16:06:17 +02:00
James Cole
62d30c7b0e Fix migration (call to empty table name) 2016-08-12 16:06:11 +02:00
661 changed files with 17911 additions and 10313 deletions

View File

@@ -1,50 +0,0 @@
---
engines:
csslint:
enabled: true
duplication:
enabled: true
config:
languages:
- ruby
- javascript
- python
- php
eslint:
enabled: true
fixme:
enabled: true
phpmd:
enabled: true
ratings:
paths:
- "**.css"
- "**.inc"
- "**.js"
- "**.jsx"
- "**.module"
- "**.php"
- "**.py"
- "**.rb"
exclude_paths:
- gulpfile.js
- public/packages/maximebf/php-debugbar/debugbar.js
- public/packages/maximebf/php-debugbar/widgets.js
- public/packages/maximebf/php-debugbar/openhandler.js
- public/packages/maximebf/php-debugbar/widgets/sqlqueries/widget.js
- public/js/bootstrap3-typeahead.min.js
- public/js/bootstrap-sortable.js
- public/js/bootstrap-tagsinput.min.js
- public/js/bootstrap-tagsinput.min.js.map
- public/js/daterangepicker.js
- public/js/jquery-2.1.3.min.js
- public/js/jquery-2.1.3.min.js.map
- public/js/jquery-ui.min.js
- public/js/metisMenu.js
- public/js/moment.min.js
- public/js/sb-admin-2.js
- public/bootstrap/*
- resources/lang/*
- tests/*
- database/*
- storage/*

View File

@@ -1,15 +1,19 @@
APP_ENV=production
APP_DEBUG=false
APP_FORCE_SSL=false
APP_FORCE_ROOT=
APP_KEY=SomeRandomStringOf32CharsExactly
LOG_LEVEL=warning
APP_LOG_LEVEL=warning
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
@@ -18,17 +22,14 @@ COOKIE_PATH="/"
COOKIE_DOMAIN=
COOKIE_SECURE=false
DEFAULT_CURRENCY=EUR
DEFAULT_LANGUAGE=en_US
REDIS_HOST=localhost
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_FROM=enter_your_email_here
MAIL_FROM=changeme@example.com
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
@@ -37,8 +38,10 @@ SEND_REGISTRATION_MAIL=true
MUST_CONFIRM_ACCOUNT=false
SHOW_INCOMPLETE_TRANSLATIONS=false
SHOW_DEMO_WARNING=false
ANALYTICS_ID=
RUNCLEANUP=true
SITE_OWNER=mail@example.com
PUSHER_KEY=
PUSHER_SECRET=
PUSHER_APP_ID=

View File

@@ -1,38 +0,0 @@
APP_ENV=testing
APP_DEBUG=true
APP_FORCE_SSL=false
APP_KEY=SomeRandomStringOf32CharsExactly
LOG_LEVEL=debug
DB_CONNECTION=sqlite
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=array
DEFAULT_CURRENCY=EUR
DEFAULT_LANGUAGE=en_US
REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_FROM=your_address_here@example.com
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
SHOW_INCOMPLETE_TRANSLATIONS=false
ANALYTICS_ID=abcde
RUNCLEANUP=false
SITE_OWNER=your_address_here@example.com
BLOCKED_DOMAINS=

2
.gitattributes vendored
View File

@@ -1,3 +1,3 @@
* text=auto
*.css linguist-vendored
*.less linguist-vendored
*.scss linguist-vendored

7
.gitignore vendored Normal file → Executable file
View File

@@ -1,8 +1,13 @@
/vendor
/node_modules
/public/storage
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
_development
.env.local
result.html
test-import.sh
test-import-report.txt
public/google*.html

View File

@@ -4,3 +4,5 @@ tools:
filter:
excluded_paths:
- app/Support/Migration/*
- app/database/migrations/*
- database/migrations/*

View File

@@ -2,8 +2,131 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
- No unreleased changes yet.
## [4.0.2] - 2016-10-14
### Added
- Added ``intl`` dependency to composer file to ease installation (thanks @telyn)
- Added support for Croatian.
### Changed
- Updated all copyright notices to refer to the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/)
- Fixed #344
- Fixed #346, thanks to @SanderKleykens
- #351
- Did some internal remodelling.
### Fixed
- PostgreSQL compatibility thanks to @SanderKleykens
- @RobertHorlings fixed a bug in the ABN Amro import specific.
## [4.0.1] - 2016-10-04
### Added
- New ING import specific by @tomwerf
- New Presidents Choice specific to fix #307
- Added some trimming (#335)
### Changed
- Initial release.
### Deprecated
- Initial release.
### Removed
- Initial release.
### Fixed
- Fixed a bug where incoming transactions would not be properly filtered in several reports.
- #334 by @cyberkov
- #337
- #336
- #338 found by @roberthorlings
### Security
- Initial release.
## [4.0.0] - 2015-09-26
### Added
- Upgraded to Laravel 5.3, most other libraries upgraded as well.
- Added GBP as currency, thanks to @Mortalife
### Changed
- Jump to version 4.0.0.
- Firefly III is now subject to a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/) license. Previous versions of this software are still MIT licensed.
### Fixed
- Support for specific decimal places, thanks to @Mortalife
- Various CSS fixes
- Various bugs, thanks to @fuf, @sandermulders and @vissert
- Various queries optimized for MySQL 5.7
## [3.10.4] - 2015-09-14
### Fixed
- Migration fix by @sandermulders
- Tricky import bug fix thanks to @vissert
- Currency preference will be correctly pulled from user settings, thanks to @fuf
- Simplified code for upgrade instructions.
## [3.10.3] - 2016-08-29
### Added
- More fields for mass-edit, thanks to @Vissert (#282)
- First start of German translation
### Changed
- More optional fields for transactions and the ability to filter them.
### Removed
- Preference for budget maximum.
### Fixed
- A bug in the translation routine broke the import.
- It was possible to destroy your Firefly installation by removing all currencies. Thanks @mondjef
- Translation bugs.
- Import bug.
### Security
- Firefly will not accept registrations beyond the first one, by default.
## [3.10.2] - 2016-08-29
### Added
- New Chinese translations. Set Firefly III to show incomplete translations to follow the progress. Want to translate Firefly III in Chinese, or in any other language? Then check out [the Crowdin project](https://crowdin.com/project/firefly-iii).
- Added more admin pages. They do nothing yet.
### Changed
- Import routine will now also apply user rules.
- Various code cleanup.
- Some small HTML changes.
### Fixed
- Bug in the mass edit routines.
- Firefly III over a proxy will now work (see [issue #290](https://github.com/JC5/firefly-iii/issues/290)), thanks @dfiel for reporting.
- Sneaky bug in the import routine, fixed by @Bonno
## [3.10.1] - 2016-08-25
### Added
- More feedback in the import procedure.
- Extended model for import job.
- Web bases import procedure.
### Changed
- Scrutinizer configuration
- Various code clean up.
### Removed
- Code climate YAML file.
### Fixed
- Fixed a bug where a migration would check an empty table name.
- Fixed various bugs in the import routine.
- Fixed various bugs in the piggy banks pages.
- Fixed a bug in the ``firefly:verify`` routine
## [3.10] - 2015-05-25
### Added
@@ -18,13 +141,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- The date picker now supports more ranges and periods.
- Rewrote all migrations. #272
### Deprecated
- Initial release.
### Removed
- Initial release.
### Fixed
- Issue #264
- Issue #265
@@ -39,10 +155,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Bulk update problems, #280, thanks @stickgrinder
- Fixed various problems with amount reporting of split transactions.
### Security
- Initial release.
[3.9.1]
### Fixed
- Fixed a bug where removing money from a piggy bank would not work. See issue #265 and #269

View File

@@ -1,7 +1,7 @@
Copyright (C) 2016 thegrumpydictator@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
https://creativecommons.org/licenses/by-sa/4.0/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -3,8 +3,10 @@
* ConfigureLogging.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -22,24 +24,40 @@ use Illuminate\Log\Writer;
*/
class ConfigureLogging extends IlluminateConfigureLogging
{
/**
* @param Application $app
* @param Writer $log
* Configure the Monolog handlers for the application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Log\Writer $log
*
* @return void
*/
protected function configureDailyHandler(Application $app, Writer $log)
{
$config = $app->make('config');
$maxFiles = $config->get('app.log_max_files');
$log->useDailyFiles(
$app->storagePath() . '/logs/firefly-iii.log',
$app->make('config')->get('app.log_max_files', 5)
$app->storagePath() . '/logs/firefly-iii.log', is_null($maxFiles) ? 5 : $maxFiles,
$config->get('app.log_level', 'debug')
);
}
/**
* @param Application $app
* @param Writer $log
* Configure the Monolog handlers for the application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Log\Writer $log
*
* @return void
*/
protected function configureSingleHandler(Application $app, Writer $log)
{
$log->useFiles($app->storagePath() . '/logs/firefly-iii.log');
$log->useFiles(
$app->storagePath() . '/logs/firefly-iii.log',
$app->make('config')->get('app.log_level', 'debug')
);
}
}

View File

@@ -3,8 +3,10 @@
* EncryptFile.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -46,8 +48,6 @@ class EncryptFile extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
@@ -64,6 +64,5 @@ class EncryptFile extends Command
$path = storage_path('upload') . '/' . $newName;
file_put_contents($path, $content);
$this->line(sprintf('Encrypted "%s" and put it in "%s"', $file, $path));
}
}

View File

@@ -3,20 +3,20 @@
* Import.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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\Console\Commands;
use FireflyIII\Crud\Account\AccountCrud;
use FireflyIII\Import\Importer\ImporterInterface;
use FireflyIII\Import\ImportStorage;
use FireflyIII\Import\ImportValidator;
use FireflyIII\Import\ImportProcedure;
use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Log;
@@ -59,55 +59,64 @@ class Import extends Command
{
$jobKey = $this->argument('key');
$job = ImportJob::whereKey($jobKey)->first();
if (!$this->isValid($job)) {
return;
}
$this->line('Going to import job with key "' . $job->key . '" of type ' . $job->file_type);
$monolog = Log::getMonolog();
$handler = new CommandHandler($this);
$monolog->pushHandler($handler);
$result = ImportProcedure::runImport($job);
/**
* @var int $index
* @var TransactionJournal $journal
*/
foreach ($result as $index => $journal) {
if (!is_null($journal->id)) {
$this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
continue;
}
$this->error(sprintf('Could not store line #%d', $index));
}
$this->line('The import has completed.');
// get any errors from the importer:
$extendedStatus = $job->extended_status;
if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
$this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
foreach ($extendedStatus['errors'] as $error) {
$this->error($error);
}
}
return;
}
/**
* @param ImportJob $job
*
* @return bool
*/
private function isValid(ImportJob $job): bool
{
if (is_null($job)) {
$this->error('This job does not seem to exist.');
return;
return false;
}
if ($job->status != 'settings_complete') {
$this->error('This job is not ready to be imported.');
return;
return false;
}
$this->line('Going to import job with key "' . $job->key . '" of type ' . $job->file_type);
$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);
// intercept logging by importer.
$monolog = Log::getMonolog();
$handler = new CommandHandler($this);
$monolog->pushHandler($handler);
// create import entries
$collection = $importer->createImportEntries();
// validate / clean collection:
$validator = new ImportValidator($collection);
$validator->setUser($job->user);
if ($job->configuration['import-account'] != 0) {
$repository = app(AccountCrud::class, [$job->user]);
$validator->setDefaultImportAccount($repository->find($job->configuration['import-account']));
}
$cleaned = $validator->clean();
// then import collection:
$storage = new ImportStorage($cleaned);
$storage->setUser($job->user);
// and run store routine:
$storage->store();
$this->line('Something something import: ' . $jobKey);
return true;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* ScanAttachments.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\Console\Commands;
use Crypt;
use FireflyIII\Models\Attachment;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Storage;
/**
* Class ScanAttachments
*
* @package FireflyIII\Console\Commands
*/
class ScanAttachments extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Rescan all attachments and re-set the MD5 hash and mime.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly:scan-attachments';
/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$attachments = Attachment::get();
$disk = Storage::disk('upload');
/** @var Attachment $attachment */
foreach ($attachments as $attachment) {
$fileName = $attachment->fileName();
// try to grab file content:
try {
$content = $disk->get($fileName);
} catch (FileNotFoundException $e) {
$this->error(sprintf('Could not find data for attachment #%d', $attachment->id));
continue;
}
// try to decrypt content.
try {
$decrypted = Crypt::decrypt($content);
} catch (DecryptException $e) {
$this->error(sprintf('Could not decrypt data of attachment #%d', $attachment->id));
continue;
}
// make temp file:
$tmpfname = tempnam(sys_get_temp_dir(), 'FireflyIII');
// store content in temp file:
file_put_contents($tmpfname, $decrypted);
// get md5 and mime
$md5 = md5_file($tmpfname);
$mime = mime_content_type($tmpfname);
// update attachment:
$attachment->md5 = $md5;
$attachment->mime = $mime;
$attachment->save();
$this->line(sprintf('Fixed attachment #%d', $attachment->id));
// find file:
}
}
}

View File

@@ -3,8 +3,10 @@
* UpgradeFireflyInstructions.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -44,8 +46,6 @@ class UpgradeFireflyInstructions extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
@@ -53,15 +53,22 @@ class UpgradeFireflyInstructions extends Command
/** @var string $version */
$version = config('firefly.version');
$config = config('upgrade.text');
$text = $config[$version] ?? null;
$text = null;
foreach (array_keys($config) as $compare) {
// if string starts with:
$len = strlen($compare);
if (substr($version, 0, $len) === $compare) {
$text = $config[$compare];
}
}
$this->line('+------------------------------------------------------------------------------+');
$this->line('');
if (is_null($text)) {
$this->line('Thank you for installing Firefly III, v' . $version);
$this->line('If you are upgrading from a previous version,');
$this->info('there are no extra upgrade instructions.');
$this->info('There are no extra upgrade instructions.');
$this->line('Firefly III should be ready for use.');
} else {
$this->line('Thank you for installing Firefly III, v' . $version);

View File

@@ -3,8 +3,10 @@
* VerifyDatabase.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -12,13 +14,13 @@ declare(strict_types = 1);
namespace FireflyIII\Console\Commands;
use Crypt;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Console\Command;
@@ -55,8 +57,6 @@ class VerifyDatabase extends Command
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
@@ -81,6 +81,9 @@ class VerifyDatabase extends Command
// report on journals with no transactions at all.
$this->reportNoTransactions();
// transfers with budgets.
$this->reportTransfersBudgets();
}
/**
@@ -91,14 +94,17 @@ class VerifyDatabase extends Command
$set = Account
::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
->groupBy('accounts.id')
->having('transaction_count', '=', 0)
->get(['accounts.id', 'accounts.name', 'accounts.user_id', 'users.email', DB::raw('COUNT(`transactions`.`id`) AS `transaction_count`')]);
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
->whereNull('transactions.account_id')
->get(
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
);
/** @var stdClass $entry */
foreach ($set as $entry) {
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has account #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
. '") which has no transactions.';
$name = $entry->name;
$line = 'User #%d (%s) has account #%d ("%s") which has no transactions.';
$line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $name);
$this->line($line);
}
}
@@ -111,9 +117,9 @@ class VerifyDatabase extends Command
$set = Budget
::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
->groupBy('budgets.id')
->having('budget_limit_count', '=', 0)
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email', DB::raw('COUNT(`budget_limits`.`id`) AS `budget_limit_count`')]);
->groupBy(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email'])
->whereNull('budget_limits.id')
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']);
/** @var stdClass $entry */
foreach ($set as $entry) {
@@ -191,7 +197,7 @@ class VerifyDatabase extends Command
$date = is_null($entry->transaction_deleted_at) ? $entry->journal_deleted_at : $entry->transaction_deleted_at;
$this->error(
'Error: Account #' . $entry->account_id . ' should have been deleted, but has not.' .
' Find it in the table called `accounts` and change the `deleted_at` field to: "' . $date . '"'
' Find it in the table called "accounts" and change the "deleted_at" field to: "' . $date . '"'
);
}
}
@@ -218,28 +224,25 @@ class VerifyDatabase extends Command
foreach ($set as $entry) {
$this->error(
'Error: Transaction #' . $entry->transaction_id . ' should have been deleted, but has not.' .
' Find it in the table called `transactions` and change the `deleted_at` field to: "' . $entry->journal_deleted . '"'
' Find it in the table called "transactions" and change the "deleted_at" field to: "' . $entry->journal_deleted . '"'
);
}
}
/**
*
*/
private function reportNoTransactions()
{
/*
* select transaction_journals.id, count(transactions.id) as transaction_count from transaction_journals
left join transactions ON transaction_journals.id = transactions.transaction_journal_id
group by transaction_journals.id
having transaction_count = 0
*/
$set = TransactionJournal
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->having('transaction_count', '=', 0)
->get(['transaction_journals.id', DB::raw('COUNT(`transactions`.`id`) as `transaction_count`')]);
->whereNull('transactions.transaction_journal_id')
->get(['transaction_journals.id']);
foreach ($set as $entry) {
$this->error(
'Error: Journal #' . $entry->id . ' has zero transactions. Open table `transaction_journals` and delete the entry with id #' . $entry->id
'Error: Journal #' . $entry->id . ' has zero transactions. Open table "transaction_journals" and delete the entry with id #' . $entry->id
);
}
@@ -300,8 +303,33 @@ having transaction_count = 0
foreach ($set as $entry) {
$this->error(
'Error: Transaction journal #' . $entry->journal_id . ' should have been deleted, but has not.' .
' Find it in the table called `transaction_journals` and change the `deleted_at` field to: "' . $entry->transaction_deleted . '"'
' Find it in the table called "transaction_journals" and change the "deleted_at" field to: "' . $entry->transaction_deleted . '"'
);
}
}
/**
*
*/
private function reportTransfersBudgets()
{
$set = TransactionJournal
::distinct()
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
->where('transaction_types.type', TransactionType::TRANSFER)
->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.id']);
/** @var TransactionJournal $entry */
foreach ($set as $entry) {
$this->error(
sprintf(
'Error: Transaction journal #%d is a transfer, but has a budget. Edit it without changing anything, so the budget will be removed.',
$entry->id
)
);
}
}
}

34
app/Console/Kernel.php Normal file → Executable file
View File

@@ -3,8 +3,10 @@
* Kernel.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -13,8 +15,10 @@ namespace FireflyIII\Console;
use FireflyIII\Console\Commands\EncryptFile;
use FireflyIII\Console\Commands\Import;
use FireflyIII\Console\Commands\ScanAttachments;
use FireflyIII\Console\Commands\UpgradeFireflyInstructions;
use FireflyIII\Console\Commands\VerifyDatabase;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
/**
@@ -24,11 +28,10 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
*/
class Kernel extends ConsoleKernel
{
/**
* The bootstrap classes for the application.
*
* This needs to be for with the next upgrade.
* Next upgrade verify these are the same.
*
* @var array
*/
@@ -55,5 +58,28 @@ class Kernel extends ConsoleKernel
VerifyDatabase::class,
Import::class,
EncryptFile::class,
ScanAttachments::class,
];
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule)
{
}
}

View File

@@ -1,541 +0,0 @@
<?php
/**
* AccountCrud.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Crud\Account;
use Carbon\Carbon;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use Log;
/**
* Class AccountCrud
*
* @package FireflyIII\Crud\Account
*/
class AccountCrud implements AccountCrudInterface
{
/** @var User */
private $user;
/** @var array */
private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber'];
/**
* AccountCrud constructor.
*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* @param Account $account
* @param Account $moveTo
*
* @return bool
*/
public function destroy(Account $account, Account $moveTo): bool
{
if (!is_null($moveTo->id)) {
// update all transactions:
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
}
if (!is_null($account)) {
Log::debug('Now trigger account delete #' . $account->id);
$account->delete();
}
return true;
}
/**
* @param $accountId
*
* @return Account
*/
public function find(int $accountId): Account
{
Log::debug('Searching for user ', ['user' => $this->user->id]);
$account = $this->user->accounts()->find($accountId);
if (is_null($account)) {
return new Account;
}
return $account;
}
/**
* @param string $number
* @param array $types
*
* @return Account
*/
public function findByAccountNumber(string $number, array $types): Account
{
$query = $this->user->accounts()
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
->where('account_meta.name', 'accountNumber')
->where('account_meta.data', json_encode($number));
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Collection $accounts */
$accounts = $query->get(['accounts.*']);
if ($accounts->count() > 0) {
return $accounts->first();
}
return new Account;
}
/**
* @param string $iban
* @param array $types
*
* @return Account
*/
public function findByIban(string $iban, array $types): Account
{
$query = $this->user->accounts()->where('iban', '!=', '');
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->iban === $iban) {
return $account;
}
}
return new Account;
}
/**
* @param string $name
* @param array $types
*
* @return Account
*/
public function findByName(string $name, array $types): Account
{
$query = $this->user->accounts();
Log::debug('Now in findByName()', ['name' => $name, 'types' => $types]);
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
$accounts = $query->get(['accounts.*']);
Log::debug(sprintf('Total set count is %d ', $accounts->count()));
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name) {
Log::debug('Account name is an exact match. ', ['db' => $account->name, 'source' => $name, 'id' => $account->id]);
return $account;
}
}
Log::debug('Found nothing in findByName()', ['name' => $name, 'types' => $types]);
return new Account;
}
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection
{
/** @var Collection $result */
$query = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
);
if (count($accountIds) > 0) {
$query->whereIn('accounts.id', $accountIds);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
);
if (count($types) > 0) {
$query->accountTypeIn($types);
}
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @param array $data
*
* @return Account
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function store(array $data): Account
{
$newAccount = $this->storeAccount($data);
if (!is_null($newAccount->id)) {
$this->storeMetadata($newAccount, $data);
}
if ($data['openingBalance'] != 0) {
$this->storeInitialBalance($newAccount, $data);
}
return $newAccount;
}
/**
* @param $account
* @param $name
* @param $value
*
* @return AccountMeta
*/
public function storeMeta(Account $account, string $name, $value): AccountMeta
{
return AccountMeta::create(['name' => $name, 'data' => $value, 'account_id' => $account->id,]);
}
/**
* @param Account $account
* @param array $data
*
* @return Account
*/
public function update(Account $account, array $data): Account
{
// update the account:
$account->name = $data['name'];
$account->active = $data['active'] == '1' ? true : false;
$account->virtual_balance = $data['virtualBalance'];
$account->iban = $data['iban'];
$account->save();
$this->updateMetadata($account, $data);
$this->updateInitialBalance($account, $data);
return $account;
}
/**
* @param Account $account
* @param string $type
*
* @return Account
*/
public function updateAccountType(Account $account, string $type): Account
{
$type = AccountType::whereType($type)->first();
if (!is_null($type)) {
$account->accountType()->associate($type);
$account->save();
}
return $this->find($account->id);
}
/**
* @param array $data
*
* @return Account
*/
protected function storeAccount(array $data): Account
{
$type = config('firefly.accountTypeByIdentifier.' . $data['accountType']);
$accountType = AccountType::whereType($type)->first();
$newAccount = new Account(
[
'user_id' => $data['user'],
'account_type_id' => $accountType->id,
'name' => $data['name'],
'virtual_balance' => $data['virtualBalance'],
'active' => $data['active'] === true ? true : false,
'iban' => $data['iban'],
]
);
if (!$newAccount->isValid()) {
// does the account already exist?
$searchData = [
'user_id' => $data['user'],
'account_type_id' => $accountType->id,
'virtual_balance' => $data['virtualBalance'],
'name' => $data['name'],
'iban' => $data['iban'],
];
$existingAccount = Account::firstOrNullEncrypted($searchData);
if (!$existingAccount) {
Log::error('Account create error', $newAccount->getErrors()->toArray());
return new Account;
}
$newAccount = $existingAccount;
}
$newAccount->save();
return $newAccount;
}
/**
* @param Account $account
* @param array $data
*
* @return TransactionJournal
*/
protected function storeInitialBalance(Account $account, array $data): TransactionJournal
{
$amount = $data['openingBalance'];
$user = $data['user'];
$name = $data['name'];
$opposing = $this->storeOpposingAccount($amount, $user, $name);
$transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
$journal = TransactionJournal::create(
[
'user_id' => $data['user'],
'transaction_type_id' => $transactionType->id,
'transaction_currency_id' => $data['openingBalanceCurrency'],
'description' => 'Initial balance for "' . $account->name . '"',
'completed' => true,
'date' => $data['openingBalanceDate'],
'encrypted' => true,
]
);
$firstAccount = $account;
$secondAccount = $opposing;
$firstAmount = $amount;
$secondAmount = $amount * -1;
if ($data['openingBalance'] < 0) {
$firstAccount = $opposing;
$secondAccount = $account;
$firstAmount = $amount * -1;
$secondAmount = $amount;
}
$one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]);
$one->save();// first transaction: from
$two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]);
$two->save(); // second transaction: to
return $journal;
}
/**
* @param Account $account
* @param array $data
*/
protected function storeMetadata(Account $account, array $data)
{
foreach ($this->validFields as $field) {
if (isset($data[$field])) {
$metaData = new AccountMeta(
[
'account_id' => $account->id,
'name' => $field,
'data' => $data[$field],
]
);
$metaData->save();
}
}
}
/**
* @param Account $account
* @param array $data
*
* @return bool
*/
protected function updateInitialBalance(Account $account, array $data): bool
{
$openingBalance = $this->openingBalanceTransaction($account);
if ($data['openingBalance'] != 0) {
if (!is_null($openingBalance->id)) {
$date = $data['openingBalanceDate'];
$amount = $data['openingBalance'];
return $this->updateJournal($account, $openingBalance, $date, $amount);
}
$this->storeInitialBalance($account, $data);
return true;
}
// else, delete it:
if ($openingBalance) { // opening balance is zero, should we delete it?
$openingBalance->delete(); // delete existing opening balance.
}
return true;
}
/**
* @param Account $account
* @param array $data
*
*/
protected function updateMetadata(Account $account, array $data)
{
foreach ($this->validFields as $field) {
$entry = $account->accountMeta()->where('name', $field)->first();
if (isset($data[$field])) {
// update if new data is present:
if (!is_null($entry)) {
$entry->data = $data[$field];
$entry->save();
continue;
}
$metaData = new AccountMeta(
[
'account_id' => $account->id,
'name' => $field,
'data' => $data[$field],
]
);
$metaData->save();
}
}
}
/**
* @param Account $account
*
* @return TransactionJournal|null
*/
private function openingBalanceTransaction(Account $account): TransactionJournal
{
$journal = TransactionJournal
::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
return new TransactionJournal;
}
return $journal;
}
/**
* @param float $amount
* @param int $user
* @param string $name
*
* @return Account
*/
private function storeOpposingAccount(float $amount, int $user, string $name):Account
{
$type = $amount < 0 ? 'expense' : 'revenue';
$opposingData = [
'user' => $user,
'accountType' => $type,
'name' => $name . ' initial balance',
'active' => false,
'iban' => '',
'virtualBalance' => 0,
];
return $this->storeAccount($opposingData);
}
/**
* @param Account $account
* @param TransactionJournal $journal
* @param Carbon $date
* @param float $amount
*
* @return bool
*/
private function updateJournal(Account $account, TransactionJournal $journal, Carbon $date, float $amount): bool
{
// update date:
$journal->date = $date;
$journal->save();
// update transactions:
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if ($account->id == $transaction->account_id) {
$transaction->amount = $amount;
$transaction->save();
}
if ($account->id != $transaction->account_id) {
$transaction->amount = $amount * -1;
$transaction->save();
}
}
return true;
}
}

View File

@@ -1,109 +0,0 @@
<?php
/**
* AccountCrudInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Crud\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use Illuminate\Support\Collection;
/**
* Interface AccountCrudInterface
*
* @package FireflyIII\Crud\Account
*/
interface AccountCrudInterface
{
/**
* @param Account $account
* @param Account $moveTo
*
* @return bool
*/
public function destroy(Account $account, Account $moveTo): bool;
/**
* @param int $accountId
*
* @return Account
*/
public function find(int $accountId): Account;
/**
* @param string $number
* @param array $types
*
* @return Account
*/
public function findByAccountNumber(string $number, array $types): Account;
/**
* @param string $iban
* @param array $types
*
* @return Account
*/
public function findByIban(string $iban, array $types): Account;
/**
* @param string $name
* @param array $types
*
* @return Account
*/
public function findByName(string $name, array $types): Account;
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection;
/**
* @param array $types
*
* @return Collection
*/
public function getAccountsByType(array $types): Collection;
/**
* @param array $data
*
* @return Account
*/
public function store(array $data) : Account;
/**
* @param $account
* @param $name
* @param $value
*
* @return AccountMeta
*/
public function storeMeta(Account $account, string $name, $value): AccountMeta;
/**
* @param Account $account
* @param array $data
*
* @return Account
*/
public function update(Account $account, array $data): Account;
/**
* @param Account $account
* @param string $type
*
* @return Account
*/
public function updateAccountType(Account $account, string $type): Account;
}

View File

@@ -3,8 +3,10 @@
* Journal.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -59,10 +61,11 @@ class Journal implements JournalInterface
/**
* @param TransactionJournal $journal
* @param array $transaction
* @param int $identifier
*
* @return Collection
*/
public function storeTransaction(TransactionJournal $journal, array $transaction): Collection
public function storeTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection
{
// store accounts (depends on type)
list($sourceAccount, $destinationAccount) = $this->storeAccounts($journal->transactionType->type, $transaction);
@@ -71,11 +74,11 @@ class Journal implements JournalInterface
/** @var Transaction $one */
$one = Transaction::create(
['account_id' => $sourceAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'] * -1,
'description' => $transaction['description']]
'description' => $transaction['description'], 'identifier' => $identifier]
);
$two = Transaction::create(
['account_id' => $destinationAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'],
'description' => $transaction['description']]
'description' => $transaction['description'], 'identifier' => $identifier]
);
if (strlen($transaction['category']) > 0) {
@@ -116,8 +119,10 @@ class Journal implements JournalInterface
// delete original transactions, and recreate them.
$journal->transactions()->delete();
$identifier = 0;
foreach ($data['transactions'] as $transaction) {
$this->storeTransaction($journal, $transaction);
$this->storeTransaction($journal, $transaction, $identifier);
$identifier++;
}
$journal->completed = true;

View File

@@ -3,8 +3,10 @@
* JournalInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -32,10 +34,11 @@ interface JournalInterface
/**
* @param TransactionJournal $journal
* @param array $transaction
* @param int $identifier
*
* @return Collection
*/
public function storeTransaction(TransactionJournal $journal, array $transaction): Collection;
public function storeTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection;
/**
* @param TransactionJournal $journal

View File

@@ -3,8 +3,10 @@
* BudgetLimitStored.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BudgetLimitUpdated.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Event.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ResendConfirmation.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* TransactionJournalStored.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* TransactionJournalUpdated.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* TransactionStored.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UserIsConfirmed.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UserIsDeleted.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UserRegistration.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* FireflyException.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

40
app/Exceptions/Handler.php Normal file → Executable file
View File

@@ -3,21 +3,24 @@
* Handler.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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\Exceptions;
use Auth;
use ErrorException;
use Exception;
use FireflyIII\Jobs\MailError;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Request;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException as ValException;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
@@ -34,9 +37,12 @@ class Handler extends ExceptionHandler
*/
protected $dontReport
= [
AuthenticationException::class,
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
TokenMismatchException::class,
ValException::class,
];
/**
@@ -71,15 +77,14 @@ class Handler extends ExceptionHandler
*/
public function report(Exception $exception)
{
if ($exception instanceof FireflyException || $exception instanceof ErrorException) {
$userData = [
'id' => 0,
'email' => 'unknown@example.com',
];
if (Auth::check()) {
$userData['id'] = Auth::user()->id;
$userData['email'] = Auth::user()->email;
if (auth()->check()) {
$userData['id'] = auth()->user()->id;
$userData['email'] = auth()->user()->email;
}
$data = [
'class' => get_class($exception),
@@ -92,10 +97,27 @@ class Handler extends ExceptionHandler
];
// create job that will mail.
$job = new MailError($userData, env('SITE_OWNER'), Request::ip(), $data);
$ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
$job = new MailError($userData, env('SITE_OWNER', ''), $ip, $data);
dispatch($job);
}
parent::report($exception);
}
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest('login');
}
}

View File

@@ -3,8 +3,10 @@
* NotImplementedException.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ValidationException.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* AttachmentCollector.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -92,6 +94,7 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
'amount' => Amount::formatJournal($journal, false),
];
$string = trans('firefly.attachment_explanation', $args) . "\n";
Log::debug('Appended explanation string', ['string' => $string]);
$this->explanationString .= $string;
}

View File

@@ -3,8 +3,10 @@
* BasicCollector.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* CollectorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,15 +3,16 @@
* UploadCollector.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Export\Collector;
use Auth;
use Crypt;
use FireflyIII\Models\ExportJob;
use Illuminate\Contracts\Encryption\DecryptException;
@@ -29,6 +30,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface
private $expected;
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
private $exportDisk;
private $importKeys = [];
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
private $uploadDisk;
@@ -42,10 +44,17 @@ class UploadCollector extends BasicCollector implements CollectorInterface
{
parent::__construct($job);
Log::debug('Going to collect attachments', ['key' => $job->key]);
// make storage:
$this->uploadDisk = Storage::disk('upload');
$this->exportDisk = Storage::disk('export');
$this->expected = 'csv-upload-' . Auth::user()->id . '-';
// file names associated with the old import routine.
$this->expected = 'csv-upload-' . auth()->user()->id . '-';
// for the new import routine:
$this->getImportKeys();
}
/**
@@ -57,12 +66,26 @@ class UploadCollector extends BasicCollector implements CollectorInterface
$files = $this->uploadDisk->files();
foreach ($files as $entry) {
$this->processOldUpload($entry);
$this->processUpload($entry);
}
return true;
}
/**
*
*/
private function getImportKeys()
{
$set = auth()->user()->importJobs()->where('status', 'import_complete')->get(['import_jobs.*']);
if ($set->count() > 0) {
$keys = $set->pluck('key')->toArray();
$this->importKeys = $keys;
}
Log::debug('Valid import keys are ', $this->importKeys);
}
/**
* @param string $entry
*
@@ -83,9 +106,28 @@ class UploadCollector extends BasicCollector implements CollectorInterface
*
* @return bool
*/
private function isValidFile(string $entry): bool
private function isImportFile(string $entry): bool
{
$name = str_replace('.upload', '', $entry);
if (in_array($name, $this->importKeys)) {
Log::debug(sprintf('Import file "%s" is in array', $name), $this->importKeys);
return true;
}
Log::debug(sprintf('Import file "%s" is NOT in array', $name), $this->importKeys);
return false;
}
/**
* @param string $entry
*
* @return bool
*/
private function isOldImport(string $entry): bool
{
$len = strlen($this->expected);
// file is part of the old import routine:
if (substr($entry, 0, $len) === $this->expected) {
return true;
@@ -97,23 +139,63 @@ class UploadCollector extends BasicCollector implements CollectorInterface
/**
* @param $entry
*/
private function processOldUpload(string $entry)
private function processUpload(string $entry)
{
// file is old import:
if ($this->isOldImport($entry)) {
$this->saveOldImportFile($entry);
}
// file is current import.
if ($this->isImportFile($entry)) {
$this->saveImportFile($entry);
}
}
/**
* @param string $entry
*/
private function saveImportFile(string $entry)
{
// find job associated with import file:
$name = str_replace('.upload', '', $entry);
$job = auth()->user()->importJobs()->where('key', $name)->first();
$content = '';
try {
$content = Crypt::decrypt($this->uploadDisk->get($entry));
} catch (DecryptException $e) {
Log::error('Could not decrypt old import file ' . $entry . '. Skipped because ' . $e->getMessage());
}
if (!is_null($job) && strlen($content) > 0) {
// add to export disk.
$date = $job->created_at->format('Y-m-d');
$file = sprintf('%s-Old %s import dated %s.%s', $this->job->key, strtoupper($job->file_type), $date, $job->file_type);
$this->exportDisk->put($file, $content);
$this->getFiles()->push($file);
}
}
/**
* @param string $entry
*/
private function saveOldImportFile(string $entry)
{
$content = '';
if ($this->isValidFile($entry)) {
try {
$content = Crypt::decrypt($this->uploadDisk->get($entry));
} catch (DecryptException $e) {
Log::error('Could not decrypt old CSV import file ' . $entry . '. Skipped because ' . $e->getMessage());
}
}
if (strlen($content) > 0) {
// continue with file:
// add to export disk.
$date = $this->getOriginalUploadDate($entry);
$file = $this->job->key . '-Old CSV import dated ' . $date . '.csv';
$file = $this->job->key . '-Old import dated ' . $date . '.csv';
$this->exportDisk->put($file, $content);
$this->getFiles()->push($file);
}
}
}

View File

@@ -3,8 +3,10 @@
* ConfigurationFile.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Entry.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* EntryAccount.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* EntryBill.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* EntryBudget.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* EntryCategory.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BasicExporter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* CsvExporter.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ExporterInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Processor.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* AccountChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsAccountChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BillChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsBillChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BudgetChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsBudgetChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* CategoryChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsCategoryChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsPiggyBankChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* PiggyBankChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ChartJsReportChartGenerator.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ReportChartGeneratorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* AttachUserRole.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BudgetLimitEventHandler.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,15 +3,16 @@
* ConnectJournalToPiggyBank.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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\Handlers\Events;
use Auth;
use FireflyIII\Events\TransactionJournalStored;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
@@ -39,7 +40,7 @@ class ConnectJournalToPiggyBank
$piggyBankId = $event->piggyBankId;
/** @var PiggyBank $piggyBank */
$piggyBank = Auth::user()->piggybanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
$piggyBank = auth()->user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
if (is_null($piggyBank)) {
return true;

View File

@@ -3,8 +3,10 @@
* ConnectTransactionToPiggyBank.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* FireRulesForStore.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -17,7 +19,6 @@ use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Rules\Processor;
use FireflyIII\User;
use Illuminate\Support\Facades\Auth;
/**
* Class FireRulesForStore
@@ -38,7 +39,7 @@ class FireRulesForStore
{
// get all the user's rule groups, with the rules, order by 'order'.
/** @var User $user */
$user = Auth::user();
$user = auth()->user();
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
//
/** @var RuleGroup $group */

View File

@@ -3,15 +3,16 @@
* FireRulesForUpdate.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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\Handlers\Events;
use Auth;
use FireflyIII\Events\TransactionJournalUpdated;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
@@ -36,7 +37,7 @@ class FireRulesForUpdate
{
// get all the user's rule groups, with the rules, order by 'order'.
/** @var User $user */
$user = Auth::user();
$user = auth()->user();
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
//
/** @var RuleGroup $group */

View File

@@ -3,8 +3,10 @@
* ScanForBillsAfterStore.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ScanForBillsAfterUpdate.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* SendRegistrationMail.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UpdateJournalConnection.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -27,6 +29,7 @@ class UpdateJournalConnection
* Handle the event.
*
* @param TransactionJournalUpdated $event
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
*
* @return bool
*/
@@ -46,7 +49,7 @@ class UpdateJournalConnection
}
$piggyBank = $event->piggyBank()->first();
$repetition = null;
if ($piggyBank) {
if (!is_null($piggyBank)) {
/** @var PiggyBankRepetition $repetition */
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
}

View File

@@ -3,8 +3,10 @@
* UserConfirmation.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UserEventListener.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* UserSaveIpAddress.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -13,7 +15,6 @@ namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\UserIsConfirmed;
use FireflyIII\Events\UserRegistration;
use FireflyIII\User;
use Preferences;
/**
@@ -32,20 +33,6 @@ class UserSaveIpAddress
//
}
/**
* Handle the event.
*
* @param UserRegistration $event
*
* @return bool
*/
public function saveFromRegistration(UserRegistration $event): bool
{
Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress);
return true;
}
/**
* Handle the event.
*
@@ -59,4 +46,18 @@ class UserSaveIpAddress
return true;
}
/**
* Handle the event.
*
* @param UserRegistration $event
*
* @return bool
*/
public function saveFromRegistration(UserRegistration $event): bool
{
Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress);
return true;
}
}

View File

@@ -3,14 +3,15 @@
* AttachmentHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Attachments;
use Auth;
use Crypt;
use FireflyIII\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
@@ -60,7 +61,7 @@ class AttachmentHelper implements AttachmentHelperInterface
*/
public function getAttachmentLocation(Attachment $attachment): string
{
$path = storage_path('upload') . DIRECTORY_SEPARATOR . 'at-' . $attachment->id . '.data';
$path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, intval($attachment->id));
return $path;
}
@@ -112,7 +113,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$md5 = md5_file($file->getRealPath());
$name = $file->getClientOriginalName();
$class = get_class($model);
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
$count = auth()->user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
if ($count > 0) {
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
@@ -139,7 +140,7 @@ class AttachmentHelper implements AttachmentHelperInterface
}
$attachment = new Attachment; // create Attachment object.
$attachment->user()->associate(Auth::user());
$attachment->user()->associate(auth()->user());
$attachment->attachable()->associate($model);
$attachment->md5 = md5_file($file->getRealPath());
$attachment->filename = $file->getClientOriginalName();
@@ -250,6 +251,8 @@ class AttachmentHelper implements AttachmentHelperInterface
/**
* @param array $files
*
* @param Model $model
*
* @return bool
*/
private function processFiles(array $files, Model $model): bool

View File

@@ -3,8 +3,10 @@
* AttachmentHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Account.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Balance.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BalanceEntry.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BalanceHeader.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BalanceLine.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -32,14 +34,12 @@ class BalanceLine
/** @var BudgetModel */
protected $budget;
/** @var Carbon */
protected $startDate;
/** @var Carbon */
protected $endDate;
/** @var int */
protected $role = self::ROLE_DEFAULTROLE;
/** @var Carbon */
protected $startDate;
/**
*
@@ -90,6 +90,22 @@ class BalanceLine
$this->budget = $budget;
}
/**
* @return Carbon
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* @param Carbon $endDate
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
}
/**
* @return int
*/
@@ -106,6 +122,22 @@ class BalanceLine
$this->role = $role;
}
/**
* @return Carbon
*/
public function getStartDate()
{
return $this->startDate;
}
/**
* @param Carbon $startDate
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
}
/**
* @return string
*/
@@ -127,39 +159,6 @@ class BalanceLine
return '';
}
/**
* @return Carbon
*/
public function getStartDate()
{
return $this->startDate;
}
/**
* @param Carbon $startDate
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
}
/**
* @return Carbon
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* @param Carbon $endDate
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
}
/**
* If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine
* should have a "spent" value, which is the amount of money that has been spent

View File

@@ -3,8 +3,10 @@
* Bill.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BillLine.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Budget.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -41,46 +43,66 @@ class Budget
/**
* @param BudgetLine $budgetLine
*
* @return Budget
*/
public function addBudgetLine(BudgetLine $budgetLine)
public function addBudgetLine(BudgetLine $budgetLine): Budget
{
$this->budgetLines->push($budgetLine);
return $this;
}
/**
* @param string $add
*
* @return Budget
*/
public function addBudgeted(string $add)
public function addBudgeted(string $add): Budget
{
$add = strval(round($add, 2));
$this->budgeted = bcadd($this->budgeted, $add);
return $this;
}
/**
* @param string $add
*
* @return Budget
*/
public function addLeft(string $add)
public function addLeft(string $add): Budget
{
$add = strval(round($add, 2));
$this->left = bcadd($this->left, $add);
return $this;
}
/**
* @param string $add
*
* @return Budget
*/
public function addOverspent(string $add)
public function addOverspent(string $add): Budget
{
$add = strval(round($add, 2));
$this->overspent = bcadd($this->overspent, $add);
return $this;
}
/**
* @param string $add
*
* @return Budget
*/
public function addSpent(string $add)
public function addSpent(string $add): Budget
{
$add = strval(round($add, 2));
$this->spent = bcadd($this->spent, $add);
return $this;
}
/**
@@ -101,10 +123,14 @@ class Budget
/**
* @param string $budgeted
*
* @return Budget
*/
public function setBudgeted(string $budgeted)
public function setBudgeted(string $budgeted): Budget
{
$this->budgeted = $budgeted;
return $this;
}
/**
@@ -117,10 +143,14 @@ class Budget
/**
* @param string $left
*
* @return Budget
*/
public function setLeft(string $left)
public function setLeft(string $left): Budget
{
$this->left = $left;
return $this;
}
/**
@@ -133,10 +163,14 @@ class Budget
/**
* @param string $overspent
*
* @return Budget
*/
public function setOverspent(string $overspent)
public function setOverspent(string $overspent): Budget
{
$this->overspent = strval(round($overspent, 2));
return $this;
}
/**
@@ -149,10 +183,14 @@ class Budget
/**
* @param string $spent
*
* @return Budget
*/
public function setSpent(string $spent)
public function setSpent(string $spent): Budget
{
$this->spent = strval(round($spent, 2));
return $this;
}

View File

@@ -3,8 +3,10 @@
* BudgetLine.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -45,10 +47,14 @@ class BudgetLine
/**
* @param BudgetModel $budget
*
* @return BudgetLine
*/
public function setBudget(BudgetModel $budget)
public function setBudget(BudgetModel $budget): BudgetLine
{
$this->budget = $budget;
return $this;
}
/**
@@ -61,10 +67,14 @@ class BudgetLine
/**
* @param string $budgeted
*
* @return BudgetLine
*/
public function setBudgeted(string $budgeted)
public function setBudgeted(string $budgeted): BudgetLine
{
$this->budgeted = $budgeted;
return $this;
}
/**
@@ -77,10 +87,14 @@ class BudgetLine
/**
* @param string $left
*
* @return BudgetLine
*/
public function setLeft(string $left)
public function setLeft(string $left): BudgetLine
{
$this->left = $left;
return $this;
}
/**
@@ -93,10 +107,14 @@ class BudgetLine
/**
* @param string $overspent
*
* @return BudgetLine
*/
public function setOverspent(string $overspent)
public function setOverspent(string $overspent): BudgetLine
{
$this->overspent = $overspent;
return $this;
}
/**
@@ -109,10 +127,14 @@ class BudgetLine
/**
* @param LimitRepetition $repetition
*
* @return BudgetLine
*/
public function setRepetition(LimitRepetition $repetition)
public function setRepetition(LimitRepetition $repetition): BudgetLine
{
$this->repetition = $repetition;
return $this;
}
/**
@@ -125,10 +147,14 @@ class BudgetLine
/**
* @param string $spent
*
* @return BudgetLine
*/
public function setSpent(string $spent)
public function setSpent(string $spent): BudgetLine
{
$this->spent = $spent;
return $this;
}

View File

@@ -3,8 +3,10 @@
* Category.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,14 +3,15 @@
* Expense.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Collection;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
use stdClass;
@@ -36,36 +37,11 @@ class Expense
}
/**
* @param TransactionJournal $entry
* @param stdClass $entry
*/
public function addOrCreateExpense(TransactionJournal $entry)
public function addOrCreateExpense(stdClass $entry)
{
// add each account individually:
$destinations = TransactionJournal::destinationTransactionList($entry);
foreach ($destinations as $transaction) {
$amount = strval($transaction->amount);
$account = $transaction->account;
if (bccomp('0', $amount) === -1) {
$amount = bcmul($amount, '-1');
}
$object = new stdClass;
$object->amount = $amount;
$object->name = $account->name;
$object->count = 1;
$object->id = $account->id;
// overrule some properties:
if ($this->expenses->has($account->id)) {
$object = $this->expenses->get($account->id);
$object->amount = bcadd($object->amount, $amount);
$object->count++;
}
$this->expenses->put($account->id, $object);
}
$this->expenses->put($entry->id, $entry);
}
/**

View File

@@ -3,14 +3,15 @@
* Income.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Collection;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
use stdClass;
@@ -37,32 +38,11 @@ class Income
}
/**
* @param TransactionJournal $entry
* @param stdClass $entry
*/
public function addOrCreateIncome(TransactionJournal $entry)
public function addOrCreateIncome(stdClass $entry)
{
// add each account individually:
$sources = TransactionJournal::sourceTransactionList($entry);
foreach ($sources as $transaction) {
$amount = strval($transaction->amount);
$account = $transaction->account;
$amount = bcmul($amount, '-1');
$object = new stdClass;
$object->amount = $amount;
$object->name = $account->name;
$object->count = 1;
$object->id = $account->id;
// overrule some properties:
if ($this->incomes->has($account->id)) {
$object = $this->incomes->get($account->id);
$object->amount = bcadd($object->amount, $amount);
$object->count++;
}
$this->incomes->put($account->id, $object);
}
$this->incomes->put($entry->id, $entry);
}

View File

@@ -1,385 +0,0 @@
<?php
/**
* Importer.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv;
use Auth;
use FireflyIII\Events\TransactionJournalStored;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Csv\Converter\ConverterInterface;
use FireflyIII\Helpers\Csv\PostProcessing\PostProcessorInterface;
use FireflyIII\Helpers\Csv\Specifix\SpecifixInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
/**
* Class Importer
*
* @package FireflyIII\Helpers\Csv
*/
class Importer
{
/** @var Data */
protected $data;
/** @var array */
protected $errors = [];
/** @var array */
protected $importData;
/** @var array */
protected $importRow;
/** @var int */
protected $imported = 0;
/** @var Collection */
protected $journals;
/** @var array */
protected $map;
/** @var array */
protected $mapped;
/** @var array */
protected $roles;
/** @var int */
protected $rows = 0;
/** @var array */
protected $specifix = [];
/**
* Used by CsvController.
*
* @return array
*/
public function getErrors(): array
{
return $this->errors;
}
/**
* Used by CsvController
*
* @return int
*/
public function getImported(): int
{
return $this->imported;
}
/**
* @return Collection
*/
public function getJournals(): Collection
{
return $this->journals;
}
/**
* Used by CsvController
*
* @return int
*/
public function getRows(): int
{
return $this->rows;
}
/**
* @return array
*/
public function getSpecifix(): array
{
return is_array($this->specifix) ? $this->specifix : [];
}
/**
* @throws FireflyException
*/
public function run()
{
set_time_limit(0);
$this->journals = new Collection;
$this->map = $this->data->getMap();
$this->roles = $this->data->getRoles();
$this->mapped = $this->data->getMapped();
$this->specifix = $this->data->getSpecifix();
foreach ($this->data->getReader() as $index => $row) {
if ($this->parseRow($index)) {
$this->rows++;
$result = $this->importRow($row);
if (!($result instanceof TransactionJournal)) {
Log::error('Caught error at row #' . $index . ': ' . $result);
$this->errors[$index] = $result;
} else {
$this->imported++;
$this->journals->push($result);
event(new TransactionJournalStored($result, 0));
}
}
}
}
/**
* @param Data $data
*/
public function setData(Data $data)
{
$this->data = $data;
}
/**
* @return TransactionJournal|string
*/
protected function createTransactionJournal()
{
$date = $this->importData['date'];
if (is_null($this->importData['date'])) {
$date = $this->importData['date-rent'];
}
$transactionType = $this->getTransactionType(); // defaults to deposit
$errors = new MessageBag;
$journal = TransactionJournal::create(
[
'user_id' => Auth::user()->id,
'transaction_type_id' => $transactionType->id,
'transaction_currency_id' => $this->importData['currency']->id,
'description' => $this->importData['description'],
'completed' => 0,
'date' => $date,
'bill_id' => $this->importData['bill-id'],
]
);
if ($journal->getErrors()->count() == 0) {
// first transaction
$accountId = $this->importData['asset-account-object']->id; // create first transaction:
$amount = $this->importData['amount'];
$transaction = Transaction::create(['transaction_journal_id' => $journal->id, 'account_id' => $accountId, 'amount' => $amount]);
$errors = $transaction->getErrors();
// second transaction
$accountId = $this->importData['opposing-account-object']->id; // create second transaction:
$amount = bcmul($this->importData['amount'], '-1');
$transaction = Transaction::create(['transaction_journal_id' => $journal->id, 'account_id' => $accountId, 'amount' => $amount]);
$errors = $transaction->getErrors()->merge($errors);
}
if ($errors->count() == 0) {
$journal->completed = 1;
$journal->save();
} else {
$text = join(',', $errors->all());
return $text;
}
$this->saveBudget($journal);
$this->saveCategory($journal);
$this->saveTags($journal);
// some debug info:
$journalId = $journal->id;
$type = $journal->transaction_type_type ?? $journal->transactionType->type;
/** @var Account $asset */
$asset = $this->importData['asset-account-object'];
/** @var Account $opposing */
$opposing = $this->importData['opposing-account-object'];
Log::info('Created journal #' . $journalId . ' of type ' . $type . '!');
Log::info('Asset account #' . $asset->id . ' lost/gained: ' . $this->importData['amount']);
Log::info($opposing->accountType->type . ' #' . $opposing->id . ' lost/gained: ' . bcmul($this->importData['amount'], '-1'));
return $journal;
}
/**
* @return TransactionType
*/
protected function getTransactionType()
{
$transactionType = TransactionType::where('type', TransactionType::DEPOSIT)->first();
if ($this->importData['amount'] < 0) {
$transactionType = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
}
if (in_array($this->importData['opposing-account-object']->accountType->type, ['Asset account', 'Default account'])) {
$transactionType = TransactionType::where('type', TransactionType::TRANSFER)->first();
}
return $transactionType;
}
/**
* @param array $row
*
* @throws FireflyException
* @return string|bool
*/
protected function importRow(array $row)
{
$data = $this->getFiller(); // These fields are necessary to create a new transaction journal. Some are optional
foreach ($row as $index => $value) {
$role = $this->roles[$index] ?? '_ignore';
$class = config('csv.roles.' . $role . '.converter');
$field = config('csv.roles.' . $role . '.field');
// here would be the place where preprocessors would fire.
/** @var ConverterInterface $converter */
$converter = app('FireflyIII\Helpers\Csv\Converter\\' . $class);
$converter->setData($data); // the complete array so far.
$converter->setField($field);
$converter->setIndex($index);
$converter->setMapped($this->mapped);
$converter->setValue($value);
$data[$field] = $converter->convert();
}
// move to class vars.
$this->importData = $data;
$this->importRow = $row;
unset($data, $row);
// post processing and validating.
$this->postProcess();
$result = $this->validateData();
if (!($result === true)) {
return $result; // return error.
}
$journal = $this->createTransactionJournal();
return $journal;
}
/**
* @param int $index
*
* @return bool
*/
protected function parseRow(int $index)
{
return (($this->data->hasHeaders() && $index >= 1) || !$this->data->hasHeaders());
}
/**
* Row denotes the original data.
*
* @return void
*/
protected function postProcess()
{
// do bank specific fixes (must be enabled but now all of them.
foreach ($this->getSpecifix() as $className) {
/** @var SpecifixInterface $specifix */
$specifix = app('FireflyIII\Helpers\Csv\Specifix\\' . $className);
if ($specifix->getProcessorType() == SpecifixInterface::POST_PROCESSOR) {
$specifix->setData($this->importData);
$specifix->setRow($this->importRow);
$this->importData = $specifix->fix();
}
}
$set = config('csv.post_processors');
foreach ($set as $className) {
/** @var PostProcessorInterface $postProcessor */
$postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className);
$array = $this->importData ?? [];
$postProcessor->setData($array);
$this->importData = $postProcessor->process();
}
}
/**
* @param TransactionJournal $journal
*/
protected function saveBudget(TransactionJournal $journal)
{
// add budget:
if (!is_null($this->importData['budget'])) {
$journal->budgets()->save($this->importData['budget']);
}
}
/**
* @param TransactionJournal $journal
*/
protected function saveCategory(TransactionJournal $journal)
{
// add category:
if (!is_null($this->importData['category'])) {
$journal->categories()->save($this->importData['category']);
}
}
/**
* @param TransactionJournal $journal
*/
protected function saveTags(TransactionJournal $journal)
{
if (!is_null($this->importData['tags'])) {
foreach ($this->importData['tags'] as $tag) {
$journal->tags()->save($tag);
}
}
}
/**
*
* @return bool|string
*/
protected function validateData()
{
$date = $this->importData['date'] ?? null;
$rentDate = $this->importData['date-rent'] ?? null;
if (is_null($date) && is_null($rentDate)) {
return 'No date value for this row.';
}
if (is_null($this->importData['opposing-account-object'])) {
return 'Opposing account is null';
}
if (!($this->importData['asset-account-object'] instanceof Account)) {
return 'No asset account to import into.';
}
return true;
}
/**
* @return array
*/
private function getFiller()
{
$filler = [];
foreach (config('csv.roles') as $role) {
if (isset($role['field'])) {
$fieldName = $role['field'];
$filler[$fieldName] = null;
}
}
// some extra's:
$filler['bill-id'] = null;
$filler['opposing-account-object'] = null;
$filler['asset-account-object'] = null;
$filler['amount-modifier'] = '1';
return $filler;
}
}

View File

@@ -3,8 +3,10 @@
* FiscalHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* FiscalHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* Help.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* HelpInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -1,142 +0,0 @@
<?php
/**
* AccountReportHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Report;
use Carbon\Carbon;
use DB;
use FireflyIII\Helpers\Collection\Account as AccountCollection;
use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
/**
* Class AccountReportHelper
*
* @package FireflyIII\Helpers\Report
*/
class AccountReportHelper implements AccountReportHelperInterface
{
/**
* @param Account $account
* @param Collection $startSet
* @param Collection $endSet
* @param Collection $backupSet
*
* @return Account
*/
public static function reportFilter(Account $account, Collection $startSet, Collection $endSet, Collection $backupSet)
{
// The balance for today always incorporates transactions made on today. So to get todays "start" balance, we sub one day.
$account->startBalance = '0';
$account->endBalance = '0';
$currentStart = $startSet->filter(
function (Account $entry) use ($account) {
return $account->id == $entry->id;
}
);
$currentBackup = $backupSet->filter( // grab entry from current backup as well:
function (Account $entry) use ($account) {
return $account->id == $entry->id;
}
);
// first try to set from backup
if (!is_null($currentBackup->first())) {
$account->startBalance = $currentBackup->first()->balance;
}
// overrule with data from start
if (!is_null($currentStart->first())) {
$account->startBalance = $currentStart->first()->balance;
}
$currentEnd = $endSet->filter(
function (Account $entry) use ($account) {
return $account->id == $entry->id;
}
);
if (!is_null($currentEnd->first())) {
$account->endBalance = $currentEnd->first()->balance;
}
return $account;
}
/**
* This method generates a full report for the given period on all
* given accounts.
*
* a special consideration for accounts that did exist on this exact day.
* we also grab the balance from today just in case, to see if that changes things.
* it's a fall back for users who (rightly so) start keeping score at the first of
* the month and find the first report lacking / broken.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return AccountCollection
*/
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection
{
$startAmount = '0';
$endAmount = '0';
$diff = '0';
$ids = $accounts->pluck('id')->toArray();
$yesterday = clone $start;
$yesterday->subDay();
$startSet = $this->getSet($ids, $yesterday); // get balances for start.
$backupSet = $this->getSet($ids, $start);
$endSet = $this->getSet($ids, $end);
$accounts->each(
function (Account $account) use ($startSet, $endSet, $backupSet) {
return self::reportFilter($account, $startSet, $endSet, $backupSet);
}
);
// summarize:
foreach ($accounts as $account) {
$startAmount = bcadd($startAmount, $account->startBalance);
$endAmount = bcadd($endAmount, $account->endBalance);
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
}
$object = new AccountCollection;
$object->setStart($startAmount);
$object->setEnd($endAmount);
$object->setDifference($diff);
$object->setAccounts($accounts);
return $object;
}
/**
* @param array $ids
* @param Carbon $date
*
* @return Collection
*/
private function getSet(array $ids, Carbon $date): Collection
{
return Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->whereIn('accounts.id', $ids)
->whereNull('transaction_journals.deleted_at')
->whereNull('transactions.deleted_at')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->groupBy('accounts.id')
->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);
}
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* AccountReportHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Collection\Account as AccountCollection;
use Illuminate\Support\Collection;
/**
* Interface AccountReportHelperInterface
*
* @package FireflyIII\Helpers\Report
*/
interface AccountReportHelperInterface
{
/**
* This method generates a full report for the given period on all
* given accounts
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return AccountCollection
*/
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection;
}

View File

@@ -3,15 +3,16 @@
* BalanceReportHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Report;
use Auth;
use Carbon\Carbon;
use DB;
use FireflyIII\Helpers\Collection\Balance;
@@ -102,7 +103,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
private function allCoveredByBalancingActs(Collection $accounts, Carbon $start, Carbon $end): Collection
{
$ids = $accounts->pluck('id')->toArray();
$set = Auth::user()->tags()
$set = auth()->user()->tags()
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
@@ -127,7 +128,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
->get(
[
't_destination.account_id',
DB::raw('SUM(`t_destination`.`amount`) as `sum`'),
DB::raw('SUM(t_destination.amount) AS sum'),
]
);
@@ -261,6 +262,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface
/**
* @param Balance $balance
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
*
* @return Balance
*/

View File

@@ -3,8 +3,10 @@
* BalanceReportHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* BudgetReportHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -42,6 +44,9 @@ class BudgetReportHelper implements BudgetReportHelperInterface
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // at 43, its ok.
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
@@ -60,37 +65,21 @@ class BudgetReportHelper implements BudgetReportHelperInterface
return $cache->get();
}
$headers = [];
$current = clone $start;
$return = new Collection;
$set = $this->repository->getBudgets();
$budgets = [];
$spent = [];
while ($current < $end) {
$short = $current->format('m-Y');
$headers[$short] = $current->formatLocalized((string)trans('config.month'));
$current->addMonth();
}
$headers = $this->createYearHeaders($current, $end);
/** @var Budget $budget */
foreach ($set as $budget) {
$id = $budget->id;
$budgets[$id] = $budget->name;
$spent[$id] = [];
$current = clone $start;
$sum = '0';
while ($current < $end) {
$currentEnd = clone $current;
$currentEnd->endOfMonth();
$format = $current->format('m-Y');
$budgetSpent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $current, $currentEnd);
$spent[$id][$format] = $budgetSpent;
$sum = bcadd($sum, $budgetSpent);
$current->addMonth();
}
$budgetData = $this->getBudgetSpentData($current, $end, $budget, $accounts);
$sum = $budgetData['sum'];
$spent[$id] = $budgetData['spent'];
if (bccomp('0', $sum) === 0) {
// not spent anything.
@@ -131,10 +120,8 @@ class BudgetReportHelper implements BudgetReportHelperInterface
if ($spent > 0) {
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);
$budgetLine->setOverspent($spent);
$object->addOverspent($spent);
$object->addBudgetLine($budgetLine);
$budgetLine->setBudget($budget)->setOverspent($spent);
$object->addOverspent($spent)->addBudgetLine($budgetLine);
}
continue;
}
@@ -144,18 +131,12 @@ class BudgetReportHelper implements BudgetReportHelperInterface
$data = $this->calculateExpenses($budget, $repetition, $accounts);
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);
$budgetLine->setRepetition($repetition);
$budgetLine->setLeft($data['left']);
$budgetLine->setSpent($data['expenses']);
$budgetLine->setOverspent($data['overspent']);
$budgetLine->setBudgeted($repetition->amount);
$budgetLine->setBudget($budget)->setRepetition($repetition)
->setLeft($data['left'])->setSpent($data['expenses'])->setOverspent($data['overspent'])
->setBudgeted(strval($repetition->amount));
$object->addBudgeted($repetition->amount);
$object->addSpent($data['spent']);
$object->addLeft($data['left']);
$object->addOverspent($data['overspent']);
$object->addBudgetLine($budgetLine);
$object->addBudgeted(strval($repetition->amount))->addSpent($data['spent'])
->addLeft($data['left'])->addOverspent($data['overspent'])->addBudgetLine($budgetLine);
}
@@ -165,10 +146,8 @@ class BudgetReportHelper implements BudgetReportHelperInterface
$noBudget = $this->repository->spentInPeriodWithoutBudget($accounts, $start, $end);
$budgetLine = new BudgetLine;
$budgetLine->setOverspent($noBudget);
$budgetLine->setSpent($noBudget);
$object->addOverspent($noBudget);
$object->addBudgetLine($budgetLine);
$budgetLine->setOverspent($noBudget)->setSpent($noBudget);
$object->addOverspent($noBudget)->addBudgetLine($budgetLine);
return $object;
}
@@ -249,4 +228,50 @@ class BudgetReportHelper implements BudgetReportHelperInterface
return $array;
}
/**
* @param Carbon $current
* @param Carbon $end
*
* @return array
*/
private function createYearHeaders(Carbon $current, Carbon $end): array
{
$headers = [];
while ($current < $end) {
$short = $current->format('m-Y');
$headers[$short] = $current->formatLocalized((string)trans('config.month'));
$current->addMonth();
}
return $headers;
}
/**
* @param Carbon $current
* @param Carbon $end
* @param Budget $budget
* @param Collection $accounts
*
* @return array
*/
private function getBudgetSpentData(Carbon $current, Carbon $end, Budget $budget, Collection $accounts): array
{
$sum = '0';
$spent = [];
while ($current < $end) {
$currentEnd = clone $current;
$currentEnd->endOfMonth();
$format = $current->format('m-Y');
$budgetSpent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $current, $currentEnd);
$spent[$format] = $budgetSpent;
$sum = bcadd($sum, $budgetSpent);
$current->addMonth();
}
return [
'spent' => $spent,
'sum' => $sum,
];
}
}

View File

@@ -3,8 +3,10 @@
* BudgetReportHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,8 +3,10 @@
* ReportHelper.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);
@@ -22,7 +24,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
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;
@@ -30,6 +32,7 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use stdClass;
/**
* Class ReportHelper
@@ -82,8 +85,8 @@ class ReportHelper implements ReportHelperInterface
$billLine = new BillLine;
$billLine->setBill($bill);
$billLine->setActive(intval($bill->active) === 1);
$billLine->setMin($bill->amount_min);
$billLine->setMax($bill->amount_max);
$billLine->setMin(strval($bill->amount_min));
$billLine->setMax(strval($bill->amount_max));
$billLine->setHit(false);
// is hit in period?
@@ -144,14 +147,14 @@ class ReportHelper implements ReportHelperInterface
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): Expense
{
$object = new Expense;
/** @var AccountRepositoryInterface $repos */
$repos = app(AccountRepositoryInterface::class);
$journals = $repos->expensesInPeriod($accounts, $start, $end);
/** @var TransactionJournal $entry */
foreach ($journals as $entry) {
$amount = TransactionJournal::amount($entry);
$object->addToTotal($amount);
/** @var AccountTaskerInterface $tasker */
$tasker = app(AccountTaskerInterface::class);
$collection = $tasker->expenseReport($accounts, $accounts, $start, $end);
/** @var stdClass $entry */
foreach ($collection as $entry) {
$object->addToTotal($entry->amount);
$object->addOrCreateExpense($entry);
}
@@ -170,13 +173,13 @@ class ReportHelper implements ReportHelperInterface
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): Income
{
$object = new Income;
/** @var AccountRepositoryInterface $repos */
$repos = app(AccountRepositoryInterface::class);
$journals = $repos->incomesInPeriod($accounts, $start, $end);
/** @var AccountTaskerInterface $tasker */
$tasker = app(AccountTaskerInterface::class);
$collection = $tasker->incomeReport($accounts, $accounts, $start, $end);
foreach ($journals as $entry) {
$amount = TransactionJournal::amount($entry);
$object->addToTotal($amount);
/** @var stdClass $entry */
foreach ($collection as $entry) {
$object->addToTotal($entry->amount);
$object->addOrCreateIncome($entry);
}
@@ -255,9 +258,19 @@ class ReportHelper implements ReportHelperInterface
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->where(
function (Builder $q) use ($ids) {
$q->whereIn('source.account_id', $ids)
->whereIn('destination.account_id', $ids, 'xor');
// source.account_id in accountIds XOR destination.account_id in accountIds
function (Builder $query) use ($ids) {
$query->where(
function (Builder $q1) use ($ids) {
$q1->whereIn('source.account_id', $ids)
->whereNotIn('destination.account_id', $ids);
}
)->orWhere(
function (Builder $q2) use ($ids) {
$q2->whereIn('destination.account_id', $ids)
->whereNotIn('source.account_id', $ids);
}
);
}
)
->get(['tags.id', 'tags.tag', 'transaction_journals.id as journal_id', 'destination.amount']);

View File

@@ -3,8 +3,10 @@
* ReportHelperInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* 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);

View File

@@ -3,22 +3,23 @@
* AccountController.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Http\Controllers;
use Auth;
use Carbon\Carbon;
use ExpandedForm;
use FireflyIII\Crud\Account\AccountCrudInterface;
use FireflyIII\Http\Requests\AccountFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -50,7 +51,7 @@ class AccountController extends Controller
/**
* @param string $what
*
* @return \Illuminate\View\View
* @return View
*/
public function create(string $what = 'asset')
{
@@ -71,16 +72,16 @@ class AccountController extends Controller
}
/**
* @param AccountCrudInterface $crud
* @param ARI $repository
* @param Account $account
*
* @return View
*/
public function delete(AccountCrudInterface $crud, Account $account)
public function delete(ARI $repository, Account $account)
{
$typeName = config('firefly.shortNamesByFullName.' . $account->accountType->type);
$subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]);
$accountList = ExpandedForm::makeSelectListWithEmpty($crud->getAccountsByType([$account->accountType->type]));
$accountList = ExpandedForm::makeSelectListWithEmpty($repository->getAccountsByType([$account->accountType->type]));
unset($accountList[$account->id]);
// put previous url in session
@@ -92,19 +93,19 @@ class AccountController extends Controller
}
/**
* @param AccountCrudInterface $crud
* @param ARI $repository
* @param Account $account
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy(AccountCrudInterface $crud, Account $account)
public function destroy(ARI $repository, Account $account)
{
$type = $account->accountType->type;
$typeName = config('firefly.shortNamesByFullName.' . $type);
$name = $account->name;
$moveTo = $crud->find(intval(Input::get('move_account_before_delete')));
$moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
$crud->destroy($account, $moveTo);
$repository->destroy($account, $moveTo);
Session::flash('success', strval(trans('firefly.' . $typeName . '_deleted', ['name' => $name])));
Preferences::mark();
@@ -116,7 +117,7 @@ class AccountController extends Controller
* @param ARI $repository
* @param Account $account
*
* @return \Illuminate\View\View
* @return View
*/
public function edit(ARI $repository, Account $account)
{
@@ -124,7 +125,6 @@ class AccountController extends Controller
$what = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$openingBalance = $repository->openingBalanceTransaction($account);
// put previous url in session if not redirect from store (not "return_to_edit").
if (session('accounts.edit.fromUpdate') !== true) {
@@ -135,19 +135,17 @@ class AccountController extends Controller
// pre fill some useful values.
// the opening balance is tricky:
$openingBalanceAmount = null;
if ($openingBalance->id) {
$transaction = $repository->getFirstTransaction($openingBalance, $account);
$openingBalanceAmount = $transaction->amount;
}
$openingBalanceAmount = $account->getOpeningBalanceAmount();
$openingBalanceAmount = $account->getOpeningBalanceAmount() === '0' ? '' : $openingBalanceAmount;
$openingBalanceDate = $account->getOpeningBalanceDate();
$openingBalanceDate = $openingBalanceDate->year === 1900 ? null : $openingBalanceDate->format('Y-m-d');
$preFilled = [
'accountNumber' => $account->getMeta('accountNumber'),
'accountRole' => $account->getMeta('accountRole'),
'ccType' => $account->getMeta('ccType'),
'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'),
'openingBalanceDate' => $openingBalance->id ? $openingBalance->date->format('Y-m-d') : null,
'openingBalanceDate' => $openingBalanceDate,
'openingBalance' => $openingBalanceAmount,
'virtualBalance' => round($account->virtual_balance, 2),
];
@@ -159,20 +157,22 @@ class AccountController extends Controller
}
/**
* @param AccountCrudInterface $crud
* @param ARI $repository
* @param string $what
*
* @return View
*/
public function index(AccountCrudInterface $crud, string $what)
public function index(ARI $repository, string $what)
{
$what = $what ?? 'asset';
$subTitle = trans('firefly.' . $what . '_accounts');
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$types = config('firefly.accountTypesByIdentifier.' . $what);
$accounts = $crud->getAccountsByType($types);
$accounts = $repository->getAccountsByType($types);
/** @var Carbon $start */
$start = clone session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', Carbon::now()->endOfMonth());
$start->subDay();
@@ -193,23 +193,26 @@ class AccountController extends Controller
}
/**
* @param AccountTaskerInterface $tasker
* @param ARI $repository
* @param Account $account
*
* @return \Illuminate\View\View
* @return View
*/
public function show(ARI $repository, Account $account)
public function show(AccountTaskerInterface $tasker, ARI $repository, Account $account)
{
// show journals from current period only:
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
$subTitle = $account->name;
$range = Preferences::get('viewRange', '1M')->data;
/** @var Carbon $start */
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
/** @var Carbon $end */
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
$page = intval(Input::get('page'));
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$offset = ($page - 1) * $pageSize;
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
$count = $set->count();
$subSet = $set->splice($offset, $pageSize);
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
@@ -217,10 +220,7 @@ class AccountController extends Controller
// grouped other months thing:
// oldest transaction in account:
$start = $repository->firstUseDate($account);
if ($start->year == 1900) {
$start = new Carbon;
}
$start = $repository->oldestJournalDate($account);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range);
@@ -240,11 +240,17 @@ class AccountController extends Controller
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
}
// only include asset accounts when this account is an asset:
$assets = new Collection;
if (in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEFAULT])) {
$assets = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
}
while ($end >= $start) {
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
$spent = $this->spentInPeriod($account, $end, $currentEnd);
$earned = $this->earnedInPeriod($account, $end, $currentEnd);
$spent = $tasker->amountOutInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
$earned = $tasker->amountInInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
$entries->push([$dateStr, $dateName, $spent, $earned]);
@@ -257,13 +263,13 @@ class AccountController extends Controller
}
/**
* @param ARI $repository
* @param AccountTaskerInterface $tasker
* @param Account $account
* @param string $date
*
* @return View
*/
public function showWithDate(ARI $repository, Account $account, string $date)
public function showWithDate(AccountTaskerInterface $tasker, Account $account, string $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
@@ -274,7 +280,7 @@ class AccountController extends Controller
$page = $page === 0 ? 1 : $page;
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$offset = ($page - 1) * $pageSize;
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
$count = $set->count();
$subSet = $set->splice($offset, $pageSize);
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
@@ -285,21 +291,22 @@ class AccountController extends Controller
/**
* @param AccountFormRequest $request
* @param AccountCrudInterface $crud
* @param ARI $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(AccountFormRequest $request, AccountCrudInterface $crud)
public function store(AccountFormRequest $request, ARI $repository)
{
$accountData = [
'name' => $request->input('name'),
'name' => trim($request->input('name')),
'accountType' => $request->input('what'),
'virtualBalance' => round($request->input('virtualBalance'), 2),
'virtualBalanceCurrency' => intval($request->input('amount_currency_id_virtualBalance')),
'active' => true,
'user' => Auth::user()->id,
'iban' => $request->input('iban'),
'accountNumber' => $request->input('accountNumber'),
'user' => auth()->user()->id,
'iban' => trim($request->input('iban')),
'accountNumber' => trim($request->input('accountNumber')),
'accountRole' => $request->input('accountRole'),
'openingBalance' => round($request->input('openingBalance'), 2),
'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')),
@@ -307,7 +314,7 @@ class AccountController extends Controller
];
$account = $crud->store($accountData);
$account = $repository->store($accountData);
Session::flash('success', strval(trans('firefly.stored_new_account', ['name' => $account->name])));
Preferences::mark();
@@ -332,18 +339,18 @@ class AccountController extends Controller
/**
* @param AccountFormRequest $request
* @param AccountCrudInterface $crud
* @param ARI $repository
* @param Account $account
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(AccountFormRequest $request, AccountCrudInterface $crud, Account $account)
public function update(AccountFormRequest $request, ARI $repository, Account $account)
{
$accountData = [
'name' => $request->input('name'),
'active' => $request->input('active'),
'user' => Auth::user()->id,
'user' => auth()->user()->id,
'iban' => $request->input('iban'),
'accountNumber' => $request->input('accountNumber'),
'accountRole' => $request->input('accountRole'),
@@ -354,7 +361,7 @@ class AccountController extends Controller
'ccType' => $request->input('ccType'),
'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'),
];
$crud->update($account, $accountData);
$repository->update($account, $accountData);
Session::flash('success', strval(trans('firefly.updated_account', ['name' => $account->name])));
Preferences::mark();
@@ -386,69 +393,4 @@ class AccountController extends Controller
return '';
}
/**
* Asset accounts actually earn money by being the destination of a deposit or the destination
* of a transfer. The money moves to them.
*
* A revenue account doesn't really earn money itself. Money is earned "from" the revenue account.
* So, the call to find out how many money has been earned by/from a revenue account is slightly different.
*
*
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
private function earnedInPeriod(Account $account, Carbon $start, Carbon $end)
{
/** @var ARI $repository */
$repository = app(ARI::class);
$collection = new Collection([$account]);
$type = $account->accountType->type;
switch ($type) {
case AccountType::DEFAULT:
case AccountType::ASSET:
return $repository->earnedInPeriod($collection, $start, $end);
case AccountType::REVENUE:
return $repository->earnedFromInPeriod($collection, $start, $end);
default:
return '0';
}
}
/**
* Asset accounts actually spend money by being the source of a withdrawal or the source
* of a transfer. The money moves away from them.
*
* An expense account doesn't really spend money itself. Money is spent "at" the expense account.
* So, the call to find out how many money has been spent on/at an expense account is slightly different.
*
*
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
private function spentInPeriod(Account $account, Carbon $start, Carbon $end): string
{
/** @var ARI $repository */
$repository = app(ARI::class);
$collection = new Collection([$account]);
$type = $account->accountType->type;
switch ($type) {
case AccountType::DEFAULT:
case AccountType::ASSET:
return $repository->spentInPeriod($collection, $start, $end);
case AccountType::EXPENSE:
return $repository->spentAtInPeriod($collection, $start, $end);
default:
return '0';
}
}
}

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