Compare commits

...

185 Commits
4.4.1 ... 4.5.0

Author SHA1 Message Date
James Cole
a23179dd83 Merge branch 'release/4.5.0' 2017-06-07 12:30:09 +02:00
James Cole
5c18794122 Update lock file, and update database. 2017-06-07 12:22:59 +02:00
James Cole
893498238e Merge pull request #647 from firefly-iii/l10n_develop
New Crowdin translations
2017-06-07 12:11:28 +02:00
James Cole
474fa9dea0 New translations firefly.php (Dutch) 2017-06-07 12:10:10 +02:00
James Cole
d8a8574dda Prep for new release. 2017-06-07 12:08:32 +02:00
James Cole
935fb015d3 Live update budget amounts. 2017-06-07 11:58:04 +02:00
James Cole
8bbd3063ec Move code around for simplicity and fix tests. 2017-06-07 11:13:04 +02:00
James Cole
92c5cabd70 Try to untangle complex repositories 2017-06-07 08:18:42 +02:00
James Cole
e5db5a7b5c Various code clean up. 2017-06-07 07:38:58 +02:00
James Cole
28cf123da3 New translations firefly.php (French) 2017-06-06 20:41:24 +02:00
James Cole
5069367873 New translations firefly.php (German) 2017-06-06 20:41:16 +02:00
James Cole
234e656ff6 New translations firefly.php (Chinese Traditional) 2017-06-06 20:40:59 +02:00
James Cole
aeadfbdd6a New translations firefly.php (Polish) 2017-06-06 20:40:50 +02:00
James Cole
39288cfb0b New translations firefly.php (Slovenian) 2017-06-06 20:40:41 +02:00
James Cole
5e430968c1 New translations firefly.php (Dutch) 2017-06-06 20:40:34 +02:00
James Cole
154b74ce6f New translations firefly.php (Portuguese, Brazilian) 2017-06-06 20:40:26 +02:00
James Cole
2e26303b66 New translations firefly.php (Spanish) 2017-06-06 20:40:11 +02:00
James Cole
51ddcd9ee1 Plus not minus [skip ci] 2017-06-06 20:37:24 +02:00
James Cole
9d5d1c0a41 Updated budget view. 2017-06-06 20:35:39 +02:00
James Cole
6058ccff0d Merge pull request #664 from kressh/master
Add pgsql dependencies to Dockerfile
2017-06-06 20:01:43 +02:00
James Cole
a8ec4fe2fd New interface for budget overview. 2017-06-06 19:30:31 +02:00
James Cole
65ccb2d443 Fix error display #662 2017-06-06 19:29:10 +02:00
James Cole
0e929602a8 Verify currency data routine. 2017-06-06 07:23:54 +02:00
James Cole
5329e026dc Fixed various currency displays. 2017-06-06 07:18:09 +02:00
James Cole
a7412e43b3 Beter message for #662 2017-06-06 06:56:32 +02:00
Sergey Besedin
eeae24e058 Add pgsql dependencies 2017-06-06 01:22:09 +03:00
James Cole
17b6cc43d5 Fix display of foreign currencies in charts. 2017-06-05 22:11:54 +02:00
James Cole
b69a2ef0cd Can handle multi-currency balances better. 2017-06-05 15:09:17 +02:00
James Cole
6d1296094e Fixes a lot of issues in scrutinizer. 2017-06-05 11:20:38 +02:00
James Cole
c4039b53e6 Various code cleanup. 2017-06-05 11:12:50 +02:00
James Cole
64831b4c86 Code cleanup and refactoring. 2017-06-05 08:31:22 +02:00
James Cole
1dec270907 These changes fix the tests. 2017-06-05 07:37:53 +02:00
James Cole
f72f8b03df Catch empty currency preference 2017-06-05 07:03:32 +02:00
James Cole
0b47e5d05d Removed unnecessary variable. 2017-06-05 07:03:20 +02:00
James Cole
a487c7b4b2 Make sure amounts are formatted, and fixed some issues. 2017-06-04 23:39:26 +02:00
James Cole
3838b21459 New translations firefly.php (French) 2017-06-04 13:41:19 +02:00
James Cole
7801274d33 New translations firefly.php (German) 2017-06-04 13:41:15 +02:00
James Cole
a505406ee7 New translations firefly.php (Chinese Traditional) 2017-06-04 13:41:03 +02:00
James Cole
9487a95c13 New translations firefly.php (Polish) 2017-06-04 13:40:54 +02:00
James Cole
3b2fe13902 New translations firefly.php (Slovenian) 2017-06-04 13:40:47 +02:00
James Cole
db2898dfe5 New translations auth.php (Spanish) 2017-06-04 13:40:44 +02:00
James Cole
e08fd399d2 New translations csv.php (Spanish) 2017-06-04 13:40:40 +02:00
James Cole
e45ffba010 New translations passwords.php (Spanish) 2017-06-04 13:40:39 +02:00
James Cole
f7fde93ed2 New translations firefly.php (Dutch) 2017-06-04 13:40:37 +02:00
James Cole
3cf53604a1 New translations firefly.php (Portuguese, Brazilian) 2017-06-04 13:40:31 +02:00
James Cole
e041a5e037 New translations help.php (Spanish) 2017-06-04 13:40:19 +02:00
James Cole
6c8e10255b New translations form.php (Spanish) 2017-06-04 13:40:17 +02:00
James Cole
3464ab1527 New translations firefly.php (Spanish) 2017-06-04 13:40:13 +02:00
James Cole
82e74a2afd Big update to properly support multi currencies. 2017-06-04 13:39:16 +02:00
James Cole
771ebde295 Update journal collector so currency information is taken from the transaction. 2017-06-04 08:49:37 +02:00
James Cole
4ce4c3138c Update export routine so currency information is taken from the transaction. 2017-06-04 08:49:22 +02:00
James Cole
d37b46effc Database upgrade routine. 2017-06-04 08:48:54 +02:00
James Cole
0868aac750 Small update for 4.5.0 SQL update. 2017-06-04 08:48:40 +02:00
James Cole
4ff5f33966 Prep for solid multi-currency configuration. 2017-06-02 13:01:43 +02:00
James Cole
e1aebbe12b Remove non-existing charts. 2017-06-02 13:01:24 +02:00
James Cole
8273f467b6 Refactor some JS functions. 2017-06-02 13:00:43 +02:00
James Cole
74664afa68 Was not able to remove opening balance. 2017-06-02 13:00:24 +02:00
James Cole
c05f344371 Code clean up [skip ci] 2017-06-02 13:00:09 +02:00
James Cole
ec1507d644 Add some documentation [skip ci] 2017-06-02 12:59:27 +02:00
James Cole
8cdc1f0014 Rename several twig files. 2017-06-02 12:59:14 +02:00
James Cole
2b1ab5c6ef Fixed edit of multi currency transaction, ##651 2017-06-02 07:05:42 +02:00
James Cole
01fedc0bf8 Fix for #593, as inspired by @nhaarman. 2017-06-02 06:45:38 +02:00
James Cole
1bd82d71a2 New translations list.php (Spanish) 2017-05-25 16:50:09 +02:00
James Cole
1e9dacb6e4 New translations pagination.php (Spanish) 2017-05-25 16:40:16 +02:00
James Cole
94939ea3d3 New translations firefly.php (Portuguese, Brazilian) 2017-05-25 16:40:13 +02:00
James Cole
c3ff69d147 New translations list.php (Spanish) 2017-05-25 16:40:09 +02:00
James Cole
0fad9d4ac7 New translations validation.php (Spanish) 2017-05-25 16:40:07 +02:00
James Cole
70cd8ffb72 New translations validation.php (Spanish) 2017-05-25 16:30:10 +02:00
James Cole
61535bf4b8 New translations firefly.php (Spanish) 2017-05-25 16:30:08 +02:00
James Cole
4adcbf9e48 New translations demo.php (Spanish) 2017-05-25 16:20:11 +02:00
James Cole
3eba3167fd New translations firefly.php (Spanish) 2017-05-25 16:20:07 +02:00
James Cole
0608fd7732 New translations demo.php (Spanish) 2017-05-25 16:10:06 +02:00
James Cole
1f41f27e89 New translations breadcrumbs.php (Spanish) 2017-05-25 16:00:11 +02:00
James Cole
ded0df9303 New translations config.php (Spanish) 2017-05-25 16:00:06 +02:00
James Cole
2a7ba1893a New translations form.php (Slovenian) 2017-05-16 15:10:18 +02:00
James Cole
6b3b19632a New translations help.php (Slovenian) 2017-05-16 15:10:15 +02:00
James Cole
98bb0731df New translations list.php (Slovenian) 2017-05-16 15:10:12 +02:00
James Cole
a102f7044e New translations list.php (Slovenian) 2017-05-15 09:20:09 +02:00
James Cole
f1028dbaed New translations list.php (Slovenian) 2017-05-15 09:10:14 +02:00
James Cole
438ce5c3db New translations list.php (Slovenian) 2017-05-15 09:00:35 +02:00
James Cole
b995a1d091 New translations list.php (Slovenian) 2017-05-15 08:50:08 +02:00
James Cole
e072f83507 New translations list.php (Slovenian) 2017-05-14 10:10:08 +02:00
James Cole
79154bba25 New translations pagination.php (Slovenian) 2017-05-14 10:10:06 +02:00
James Cole
613eb7522c New translations pagination.php (Slovenian) 2017-05-14 10:00:10 +02:00
James Cole
0eb5653713 New translations csv.php (Slovenian) 2017-05-14 10:00:08 +02:00
James Cole
0d624f021b New translations csv.php (Slovenian) 2017-05-14 09:30:23 +02:00
James Cole
b263047f4e New translations csv.php (Slovenian) 2017-05-14 09:20:21 +02:00
James Cole
4410e1bbd7 New translations csv.php (Slovenian) 2017-05-14 09:10:12 +02:00
James Cole
8c3871e8de New translations csv.php (Slovenian) 2017-05-14 09:00:09 +02:00
James Cole
2eafd3cc15 Should fix #644 2017-05-14 08:57:43 +02:00
James Cole
368df66947 New translations validation.php (Slovenian) 2017-05-14 08:40:06 +02:00
James Cole
9f9a3ea8fd New translations breadcrumbs.php (Slovenian) 2017-05-14 01:20:08 +02:00
James Cole
f66286105f New translations validation.php (Slovenian) 2017-05-14 01:20:07 +02:00
James Cole
0f0f912370 Partial JS focus [skip ci] 2017-05-12 06:21:26 +02:00
James Cole
9fa0e37a5d Merge pull request #641 from firefly-iii/l10n_develop
New Crowdin translations
2017-05-12 06:20:05 +02:00
James Cole
a0cb51ff70 Merge branch 'develop' into l10n_develop 2017-05-12 06:19:56 +02:00
James Cole
a6305ddea4 New translations auth.php (Spanish) 2017-05-10 20:40:44 +02:00
James Cole
fb8638fe6a New translations breadcrumbs.php (Spanish) 2017-05-10 20:40:42 +02:00
James Cole
0009f1f865 New translations csv.php (Spanish) 2017-05-10 20:40:41 +02:00
James Cole
d449c35025 New translations passwords.php (Spanish) 2017-05-10 20:40:39 +02:00
James Cole
1893d1a2c2 New translations demo.php (Spanish) 2017-05-10 20:40:37 +02:00
James Cole
0c4539e4fa New translations validation.php (Spanish) 2017-05-10 20:40:31 +02:00
James Cole
feacddd1d7 Merge pull request #645 from elamperti/unfinished-translations-es_ES
Unfinished translations for Spanish language
2017-05-10 20:36:55 +02:00
Enrico Lamperti
0c44fe6ce0 Add translations for Spanish language 2017-05-07 21:24:07 -03:00
James Cole
17fb6983d8 Fix issue #637 with cash accounts. 2017-05-07 19:45:40 +02:00
James Cole
5fb73bdb01 Fix bug #642 2017-05-07 19:24:53 +02:00
James Cole
7f082ea389 Remove focus thing 2017-05-06 10:20:27 +02:00
James Cole
9856a1831a New translations firefly.php (Slovenian) 2017-05-04 17:40:13 +02:00
James Cole
dd17a20b60 New translations firefly.php (Slovenian) 2017-05-04 17:30:12 +02:00
James Cole
665a52b106 Merge branch 'release/4.4.3' 2017-05-03 21:25:44 +02:00
James Cole
f68d33870b Composer lock file and version update. 2017-05-03 21:25:13 +02:00
James Cole
49d13b12a5 No code coverage. 2017-05-03 21:22:01 +02:00
James Cole
674ab7e41f Merge branch 'develop' of https://github.com/firefly-iii/firefly-iii into develop
* 'develop' of https://github.com/firefly-iii/firefly-iii: (45 commits)
  New translations validation.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations passwords.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations csv.php (Slovenian)
  New translations config.php (Slovenian)
  New translations breadcrumbs.php (Slovenian)
  New translations breadcrumbs.php (Slovenian)
  New translations auth.php (Slovenian)
  New translations firefly.php (Slovenian)
  New translations breadcrumbs.php (Slovenian)
  New translations demo.php (Slovenian)
  New translations firefly.php (Slovenian)
  New translations firefly.php (Slovenian)
  New translations firefly.php (Slovenian)
  New translations firefly.php (Slovenian)
  New translations form.php (Slovenian)
  ...
2017-05-03 21:21:03 +02:00
James Cole
5b3eb3ba82 Merge pull request #639 from firefly-iii/l10n_develop
New Crowdin translations
2017-05-03 21:20:36 +02:00
James Cole
e28d3f3b5a Remove unused languages. 2017-05-03 21:14:37 +02:00
James Cole
870d8b5008 No prefix key, issue #624 2017-05-03 21:12:49 +02:00
James Cole
6aa240e9a3 Update version and changelog. 2017-05-03 21:12:19 +02:00
James Cole
b55a4047d0 New translations validation.php (Slovenian) 2017-05-03 17:50:07 +02:00
James Cole
a07d87318c New translations csv.php (Slovenian) 2017-05-03 17:40:08 +02:00
James Cole
dd6555c903 New translations csv.php (Slovenian) 2017-05-03 17:30:12 +02:00
James Cole
e8c40b6044 New translations csv.php (Slovenian) 2017-05-03 17:21:14 +02:00
James Cole
91c17a0b2a New translations csv.php (Slovenian) 2017-05-03 09:40:10 +02:00
James Cole
2ed0ea0243 New translations passwords.php (Slovenian) 2017-05-03 09:00:11 +02:00
James Cole
df2f92433a New translations csv.php (Slovenian) 2017-05-03 01:10:06 +02:00
James Cole
68b3fc72bf New translations csv.php (Slovenian) 2017-05-03 01:00:11 +02:00
James Cole
df5bb14758 New translations config.php (Slovenian) 2017-05-03 01:00:08 +02:00
James Cole
e24199bbbe New translations breadcrumbs.php (Slovenian) 2017-05-03 00:40:06 +02:00
James Cole
2c6099556b New translations breadcrumbs.php (Slovenian) 2017-05-03 00:30:13 +02:00
James Cole
f98215a5da New translations auth.php (Slovenian) 2017-05-03 00:30:11 +02:00
James Cole
b6b6888493 New translations firefly.php (Slovenian) 2017-05-03 00:30:09 +02:00
James Cole
f8e5b9be43 New translations breadcrumbs.php (Slovenian) 2017-05-03 00:20:10 +02:00
James Cole
692210214f New translations demo.php (Slovenian) 2017-05-03 00:20:08 +02:00
James Cole
cff2546c0c New translations firefly.php (Slovenian) 2017-05-03 00:10:14 +02:00
James Cole
f0cc1200f3 New translations firefly.php (Slovenian) 2017-05-03 00:00:14 +02:00
James Cole
e83a9af455 New translations firefly.php (Slovenian) 2017-05-02 23:50:09 +02:00
James Cole
fb84f9d9cf New translations firefly.php (Slovenian) 2017-05-02 23:40:12 +02:00
James Cole
118a2515e1 New translations form.php (Slovenian) 2017-05-02 23:40:09 +02:00
James Cole
63e891b0f7 New translations firefly.php (Slovenian) 2017-05-02 23:30:11 +02:00
James Cole
9891080b57 New translations firefly.php (Slovenian) 2017-05-02 23:20:10 +02:00
James Cole
bc7a7e55af New translations firefly.php (Slovenian) 2017-05-02 23:00:13 +02:00
James Cole
9b8a029de1 New translations demo.php (Slovenian) 2017-05-02 22:40:10 +02:00
James Cole
11b5575422 New translations csv.php (Slovenian) 2017-05-02 22:40:09 +02:00
James Cole
06336aa580 New translations form.php (Slovenian) 2017-05-02 22:40:07 +02:00
James Cole
aa8c1d6e9c New translations demo.php (Slovenian) 2017-05-02 22:30:08 +02:00
James Cole
9a4d5d8abf New translations firefly.php (Slovenian) 2017-05-02 22:20:11 +02:00
James Cole
3c5631bca3 New translations firefly.php (Slovenian) 2017-05-02 22:10:17 +02:00
James Cole
84f85f87b2 New translations firefly.php (Slovenian) 2017-05-02 22:00:13 +02:00
James Cole
c35db5976f New translations form.php (Slovenian) 2017-05-02 22:00:10 +02:00
James Cole
8d1fcf988c New translations firefly.php (Slovenian) 2017-05-02 21:50:11 +02:00
James Cole
bbf8f2dd69 New translations form.php (Slovenian) 2017-05-02 21:50:07 +02:00
James Cole
2f6436e34f New translations list.php (Slovenian) 2017-05-02 21:10:34 +02:00
James Cole
9cbb03107d New translations help.php (Slovenian) 2017-05-02 21:10:33 +02:00
James Cole
ee44d7fb2e New translations pagination.php (Slovenian) 2017-05-02 21:10:31 +02:00
James Cole
6a0fcd9cf0 New translations passwords.php (Slovenian) 2017-05-02 21:10:30 +02:00
James Cole
43cfe3b858 New translations demo.php (Slovenian) 2017-05-02 21:10:29 +02:00
James Cole
dba83c1c03 New translations validation.php (Slovenian) 2017-05-02 21:10:28 +02:00
James Cole
053e139d00 New translations form.php (Slovenian) 2017-05-02 21:10:26 +02:00
James Cole
04f791a839 New translations firefly.php (Slovenian) 2017-05-02 21:10:24 +02:00
James Cole
a4029c9490 New translations auth.php (Slovenian) 2017-05-02 21:10:20 +02:00
James Cole
d471dfec43 New translations csv.php (Slovenian) 2017-05-02 21:10:19 +02:00
James Cole
494bbd46d0 New translations config.php (Slovenian) 2017-05-02 21:10:17 +02:00
James Cole
1525b9ad06 New translations breadcrumbs.php (Slovenian) 2017-05-02 21:10:16 +02:00
James Cole
19847ee80b Change log update and added Slovenian. 2017-05-02 21:08:29 +02:00
James Cole
fddf1f146c Pie chart tests. 2017-05-02 20:54:49 +02:00
James Cole
5f19cb1c0c Fix canvas things. 2017-04-29 08:56:08 +02:00
James Cole
aaeae992e1 Reinstate support class. 2017-04-29 08:55:50 +02:00
James Cole
a0e7be9d45 Fix binding. 2017-04-29 08:55:37 +02:00
James Cole
78faf7e14c Forgot call to sprintf. [skip ci] 2017-04-29 08:33:32 +02:00
James Cole
98f84c2c37 Introducing filters to the journal collector. 2017-04-29 08:22:56 +02:00
James Cole
278805043e Update gitignore file. 2017-04-28 20:18:07 +02:00
James Cole
dc5215e41e Update tests. 2017-04-28 20:17:10 +02:00
James Cole
7e11691ea4 Update code to work with filters. 2017-04-28 20:08:25 +02:00
James Cole
c83dfc44d6 Update internal filters. 2017-04-28 20:08:04 +02:00
James Cole
68a01b1735 More text about Heroku. 2017-04-28 20:07:26 +02:00
James Cole
0307b58d17 Small changes to make code more testable. 2017-04-28 18:04:57 +02:00
James Cole
9d1508049e Add comment [skip ci] 2017-04-28 18:03:27 +02:00
James Cole
42322055f9 New filters to clean up the journal collector. 2017-04-28 18:02:54 +02:00
James Cole
5de8fce156 Make event handlers easier to test (and then ignore them). 2017-04-28 10:34:11 +02:00
James Cole
29ff92f833 Clean up event related code. 2017-04-28 07:51:43 +02:00
James Cole
359007c5bf Clean up event related code. 2017-04-28 07:51:09 +02:00
James Cole
bbe40518e4 Can now also test event code. 2017-04-27 08:26:58 +02:00
James Cole
b26f3c0cc6 User registration is now a Mailable. See #636 2017-04-27 08:03:15 +02:00
James Cole
552b4b67a6 Merge branch 'release/4.4.2' 2017-04-27 07:45:50 +02:00
James Cole
7fbf359efd New version [skip ci] 2017-04-27 07:45:15 +02:00
James Cole
052b804855 Fixed a bug where the opening balance could not be stored. 2017-04-27 07:44:35 +02:00
221 changed files with 5048 additions and 6444 deletions

View File

@@ -26,7 +26,7 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_FROM=changeme@example.com

View File

@@ -20,10 +20,10 @@ install:
- mkdir -p build/logs
script:
- phpunit -c phpunit.coverage.xml
- phpunit -c phpunit.xml
after_success:
- travis_retry php vendor/bin/coveralls -x storage/build/clover.xml
#after_success:
# - travis_retry php vendor/bin/coveralls -x storage/build/clover.xml
# safelist
branches:

View File

@@ -2,6 +2,38 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [4.5.0] - 2017-07-07
### Added
- Better support for multi-currency transactions and display of transactions, accounts and everything. This requires a database overhaul (moving the currency information to specific transactions) so be careful when upgrading.
- Translations for Spanish and Slovenian.
- New interface for budget page, ~~stolen from~~ inspired by YNAB.
- Expanded Docker to work with postgresql as well, thanks to @kressh
### Fixed
- PostgreSQL support in database upgrade routine (#644, reported by @)
- Frontpage budget chart was off, fix by @nhaarman
- Was not possible to remove opening balance.
## [4.4.3] - 2017-05-03
### Added
- Added support for Slovenian
- Removed support for Spanish. No translations whatsoever by the guy who requested it.
- Removed support for Russian. Same thing.
- Removed support for Croatian. Same thing.
- Removed support for Chinese Traditional, Hong Kong. Same thing.
### Changed
- The journal collector, an internal piece of code to collect transactions, now uses a slightly different method of collecting journals. This may cause problems.
### Fixed
- Issue #638 as reported by [worldworm](https://github.com/worldworm).
- Possible fix for #624
## [4.4.2] - 2017-04-27
### Fixed
- Fixed a bug where the opening balance could not be stored.
## [4.4.1] - 2017-04-27
### Added

View File

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

View File

@@ -12,6 +12,10 @@
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/firefly-iii/firefly-iii/tree/master)
Firefly III can be run on Heroku. Register for a free Heroku account and instantly run Firefly III on your very own cloud instance.
There is also a [demo site](https://firefly-iii.nder.be) with an example financial administration already present.
## Installation
To install Firefly III, you'll need a web server (preferrably on Linux) and access to the command line. Then, please read the [installation guide](https://firefly-iii.github.io/using-installing.html).

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,6 +18,9 @@ use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
@@ -156,11 +159,13 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::WITHDRAWAL])
->setBudgets($this->budgets)->withOpposingAccount()->disableFilter();
->setBudgets($this->budgets)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$accountIds = $this->accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$transactions = self::filterExpenses($transactions, $accountIds);
$this->expenses = $transactions;
return $transactions;

View File

@@ -18,6 +18,10 @@ use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
@@ -166,11 +170,13 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setCategories($this->categories)->withOpposingAccount()->disableFilter();
->setCategories($this->categories)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$accountIds = $this->accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$transactions = self::filterExpenses($transactions, $accountIds);
$this->expenses = $transactions;
return $transactions;
@@ -190,9 +196,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setCategories($this->categories)->withOpposingAccount();
$accountIds = $this->accounts->pluck('id')->toArray();
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(NegativeAmountFilter::class);
$transactions = $collector->getJournals();
$transactions = self::filterIncome($transactions, $accountIds);
$this->income = $transactions;
return $transactions;

View File

@@ -15,7 +15,6 @@ namespace FireflyIII\Generator\Report;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
@@ -25,61 +24,6 @@ use Log;
*/
class Support
{
/**
* @param Collection $collection
* @param array $accounts
*
* @return Collection
*/
public static function filterExpenses(Collection $collection, array $accounts): Collection
{
return self::filterTransactions($collection, $accounts, 1);
}
/**
* @param Collection $collection
* @param array $accounts
*
* @return Collection
*/
public static function filterIncome(Collection $collection, array $accounts): Collection
{
return self::filterTransactions($collection, $accounts, -1);
}
/**
* @param Collection $collection
* @param array $accounts
* @param int $modifier
*
* @return Collection
*/
public static function filterTransactions(Collection $collection, array $accounts, int $modifier): Collection
{
$result = $collection->filter(
function (Transaction $transaction) use ($accounts, $modifier) {
$opposing = $transaction->opposing_account_id;
// remove internal transfer
if (in_array($opposing, $accounts)) {
Log::debug(sprintf('Filtered #%d because its opposite is in accounts.', $transaction->id));
return null;
}
// remove positive amount
if (bccomp($transaction->transaction_amount, '0') === $modifier) {
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
return null;
}
return $transaction;
}
);
return $result;
}
/**
* @return Collection
*/

View File

@@ -14,8 +14,11 @@ namespace FireflyIII\Generator\Report\Tag;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
@@ -27,7 +30,7 @@ use Log;
*
* @package FireflyIII\Generator\Report\Tag
*/
class MonthReportGenerator extends Support implements ReportGeneratorInterface
class MonthReportGenerator implements ReportGeneratorInterface
{
/** @var Collection */
@@ -162,11 +165,14 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setTags($this->tags)->withOpposingAccount()->disableFilter();
->setTags($this->tags)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$transactions = $collector->getJournals();
$accountIds = $this->accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$transactions = self::filterExpenses($transactions, $accountIds);
$this->expenses = $transactions;
return $transactions;
@@ -186,9 +192,11 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setTags($this->tags)->withOpposingAccount();
$accountIds = $this->accounts->pluck('id')->toArray();
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(NegativeAmountFilter::class);
$transactions = $collector->getJournals();
$transactions = self::filterIncome($transactions, $accountIds);
$this->income = $transactions;
return $transactions;

View File

@@ -14,76 +14,95 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface as JRI;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface as PRI;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface as RGRI;
use FireflyIII\Rules\Processor;
use FireflyIII\Support\Events\BillScanner;
use Log;
/**
* @codeCoverageIgnore
*
* Class StoredJournalEventHandler
*
* @package FireflyIII\Handlers\Events
*/
class StoredJournalEventHandler
{
/** @var JRI */
public $journalRepository;
/** @var PRI */
public $repository;
/** @var RGRI */
public $ruleGroupRepository;
/**
* StoredJournalEventHandler constructor.
*
* @param PRI $repository
* @param JRI $journalRepository
* @param RGRI $ruleGroupRepository
*/
public function __construct(PRI $repository, JRI $journalRepository, RGRI $ruleGroupRepository)
{
$this->repository = $repository;
$this->journalRepository = $journalRepository;
$this->ruleGroupRepository = $ruleGroupRepository;
}
/**
* This method connects a new transfer to a piggy bank.
*
*
*
* @param StoredTransactionJournal $event
*
* @return bool
*/
public function connectToPiggyBank(StoredTransactionJournal $event): bool
{
/** @var TransactionJournal $journal */
$journal = $event->journal;
$piggyBankId = $event->piggyBankId;
Log::debug(sprintf('Trying to connect journal %d to piggy bank %d.', $journal->id, $piggyBankId));
$piggyBank = $this->repository->find($piggyBankId);
/*
* Will only continue when journal is a transfer.
*/
Log::debug(sprintf('Journal transaction type is %s', $journal->transactionType->type));
if ($journal->transactionType->type !== TransactionType::TRANSFER) {
// is a transfer?
if (!$this->journalRepository->isTransfer($journal)) {
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
return true;
}
/*
* Verify existence of piggy bank:
*/
if (!$this->verifyExistence($event)) {
Log::error(sprintf('No such piggy bank or no repetition on %s', $journal->date->format('Y-m-d')));
// piggy exists?
if (is_null($piggyBank->id)) {
Log::error(sprintf('There is no piggy bank with ID #%d', $piggyBankId));
return true;
}
/*
* Get relevant data:
*/
$piggyBank = $journal->user->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
$amount = $this->getExactAmount($journal, $piggyBank, $repetition);
// repetition exists?
$repetition = $this->repository->getRepetition($piggyBank, $journal->date);
if (is_null($repetition->id)) {
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
return true;
}
// get the amount
$amount = $this->repository->getExactAmount($piggyBank, $repetition, $journal);
if (bccomp($amount, '0') === 0) {
Log::debug('Amount is zero, will not create event.');
return true;
}
$repetition->currentamount = bcadd($repetition->currentamount, $amount);
$repetition->save();
// update amount
$this->repository->addAmountToRepetition($repetition, $amount);
$event = $this->repository->createEventWithJournal($piggyBank, $amount, $journal);
/** @var PiggyBankEvent $event */
$event = PiggyBankEvent::create(
['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]
);
Log::debug(sprintf('Created piggy bank event #%d', $event->id));
return true;
@@ -100,16 +119,11 @@ class StoredJournalEventHandler
{
// get all the user's rule groups, with the rules, order by 'order'.
$journal = $storedJournalEvent->journal;
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
//
$groups = $this->ruleGroupRepository->getActiveGroups($journal->user);
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $group->rules()
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'store-journal')
->where('rules.active', 1)
->get(['rules.*']);
$rules = $this->ruleGroupRepository->getActiveStoreRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
@@ -117,9 +131,8 @@ class StoredJournalEventHandler
$processor->handleTransactionJournal($journal);
if ($rule->stop_processing) {
return true;
break;
}
}
}
@@ -140,81 +153,4 @@ class StoredJournalEventHandler
return true;
}
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 6 but I can live with it.
* @param TransactionJournal $journal
* @param PiggyBank $piggyBank
* @param PiggyBankRepetition $repetition
*
* @return string
*/
private function getExactAmount(TransactionJournal $journal, PiggyBank $piggyBank, PiggyBankRepetition $repetition): string
{
$amount = $journal->amountPositive();
$sources = $journal->sourceAccountList()->pluck('id')->toArray();
$room = bcsub(strval($piggyBank->targetamount), strval($repetition->currentamount));
$compare = bcmul($repetition->currentamount, '-1');
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
// if piggy account matches source account, the amount is positive
if (in_array($piggyBank->account_id, $sources)) {
$amount = bcmul($amount, '-1');
Log::debug(sprintf('Account #%d is the source, so will remove amount from piggy bank.', $piggyBank->account_id));
}
// if the amount is positive, make sure it fits in piggy bank:
if (bccomp($amount, '0') === 1 && bccomp($room, $amount) === -1) {
// amount is positive and $room is smaller than $amount
Log::debug(sprintf('Room in piggy bank for extra money is %f', $room));
Log::debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
Log::debug(sprintf('New amount is %f', $room));
return $room;
}
// amount is negative and $currentamount is smaller than $amount
if (bccomp($amount, '0') === -1 && bccomp($compare, $amount) === 1) {
Log::debug(sprintf('Max amount to remove is %f', $repetition->currentamount));
Log::debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
Log::debug(sprintf('New amount is %f', $compare));
return $compare;
}
return $amount;
}
/**
* @param StoredTransactionJournal $event
*
* @return bool
*/
private function verifyExistence(StoredTransactionJournal $event): bool
{
/** @var TransactionJournal $journal */
$journal = $event->journal;
$piggyBankId = $event->piggyBankId;
/** @var PiggyBank $piggyBank */
$piggyBank = $journal->user->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
if (is_null($piggyBank)) {
Log::error('No such piggy bank!');
return false;
}
Log::debug(sprintf('Found piggy bank #%d: "%s"', $piggyBank->id, $piggyBank->name));
// update piggy bank rep for date of transaction journal.
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();
if (is_null($repetition)) {
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
return false;
}
return true;
}
}

View File

@@ -17,16 +17,31 @@ namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Rules\Processor;
use FireflyIII\Support\Events\BillScanner;
/**
* @codeCoverageIgnore
*
* Class UpdatedJournalEventHandler
*
* @package FireflyIII\Handlers\Events
*/
class UpdatedJournalEventHandler
{
/** @var RuleGroupRepositoryInterface */
public $repository;
/**
* StoredJournalEventHandler constructor.
*
* @param RuleGroupRepositoryInterface $ruleGroupRepository
*/
public function __construct(RuleGroupRepositoryInterface $ruleGroupRepository)
{
$this->repository = $ruleGroupRepository;
}
/**
* This method will check all the rules when a journal is updated.
@@ -39,16 +54,11 @@ class UpdatedJournalEventHandler
{
// get all the user's rule groups, with the rules, order by 'order'.
$journal = $updatedJournalEvent->journal;
$groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
//
$groups = $this->repository->getActiveGroups($journal->user);
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $group->rules()
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'update-journal')
->where('rules.active', 1)
->get(['rules.*']);
$rules = $this->repository->getActiveUpdateRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
$processor = Processor::make($rule);

View File

@@ -15,8 +15,9 @@ namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\RegisteredUser;
use FireflyIII\Events\RequestedNewPassword;
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Mail\Message;
use Log;
use Mail;
use Swift_TransportException;
@@ -68,15 +69,14 @@ class UserEventHandler
// send email.
try {
Mail::send(
['emails.password-html', 'emails.password-text'], ['url' => $url, 'ip' => $ipAddress], function (Message $message) use ($email) {
$message->to($email, $email)->subject('Your password reset request');
}
);
Mail::to($email)->send(new RequestedNewPasswordMail($url, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Swift_TransportException $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}
@@ -93,23 +93,23 @@ class UserEventHandler
$sendMail = env('SEND_REGISTRATION_MAIL', true);
if (!$sendMail) {
return true;
return true; // @codeCoverageIgnore
}
// get the email address
$email = $event->user->email;
$address = route('index');
$uri = route('index');
$ipAddress = $event->ipAddress;
// send email.
try {
Mail::send(
['emails.registered-html', 'emails.registered-text'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) {
$message->to($email, $email)->subject('Welcome to Firefly III!');
}
);
Mail::to($email)->send(new RegisteredUserMail($uri, $ipAddress));
// @codeCoverageIgnoreStart
} catch (Swift_TransportException $e) {
Log::error($e->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}
}

View File

@@ -16,6 +16,7 @@ namespace FireflyIII\Helpers\Attachments;
use Crypt;
use FireflyIII\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -28,6 +29,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
class AttachmentHelper implements AttachmentHelperInterface
{
/** @var Collection */
public $attachments;
/** @var MessageBag */
public $errors;
/** @var MessageBag */
@@ -49,6 +52,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$this->allowedMimes = (array)config('firefly.allowedMimes');
$this->errors = new MessageBag;
$this->messages = new MessageBag;
$this->attachments = new Collection;
$this->uploadDisk = Storage::disk('upload');
}
@@ -64,6 +68,14 @@ class AttachmentHelper implements AttachmentHelperInterface
return $path;
}
/**
* @return Collection
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
/**
* @return MessageBag
*/
@@ -110,7 +122,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 = $model->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]);
@@ -137,7 +149,7 @@ class AttachmentHelper implements AttachmentHelperInterface
}
$attachment = new Attachment; // create Attachment object.
$attachment->user()->associate(auth()->user());
$attachment->user()->associate($model->user);
$attachment->attachable()->associate($model);
$attachment->md5 = md5_file($file->getRealPath());
$attachment->filename = $file->getClientOriginalName();
@@ -156,6 +168,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$attachment->uploaded = 1; // update attachment
$attachment->save();
$this->attachments->push($attachment);
$name = e($file->getClientOriginalName()); // add message:
$msg = (string)trans('validation.file_attached', ['name' => $name]);
@@ -188,6 +201,8 @@ class AttachmentHelper implements AttachmentHelperInterface
}
/**
* @codeCoverageIgnore
*
* @param UploadedFile $file
*
* @return bool
@@ -218,7 +233,7 @@ class AttachmentHelper implements AttachmentHelperInterface
return false;
}
if (!$this->validSize($file)) {
return false;
return false; // @codeCoverageIgnore
}
if ($this->hasFile($file, $model)) {
return false;

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Helpers\Attachments;
use FireflyIII\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
/**
@@ -32,6 +33,11 @@ interface AttachmentHelperInterface
*/
public function getAttachmentLocation(Attachment $attachment): string;
/**
* @return Collection
*/
public function getAttachments(): Collection;
/**
* @return MessageBag
*/

View File

@@ -12,8 +12,11 @@ declare(strict_types=1);
namespace FireflyIII\Helpers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
@@ -91,6 +94,7 @@ class MetaPieChart implements MetaPieChartInterface
if ($this->collectOtherObjects && $direction === 'expense') {
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
$journals = $collector->getJournals();
$sum = strval($journals->sum('transaction_amount'));
@@ -102,6 +106,7 @@ class MetaPieChart implements MetaPieChartInterface
if ($this->collectOtherObjects && $direction === 'income') {
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
$journals = $collector->getJournals();
$sum = strval($journals->sum('transaction_amount'));
@@ -114,6 +119,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Collection $accounts
*
* @return MetaPieChartInterface
@@ -126,6 +133,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Collection $budgets
*
* @return MetaPieChartInterface
@@ -138,6 +147,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Collection $categories
*
* @return MetaPieChartInterface
@@ -150,6 +161,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param bool $collectOtherObjects
*
* @return MetaPieChartInterface
@@ -162,6 +175,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Carbon $end
*
* @return MetaPieChartInterface
@@ -174,6 +189,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Carbon $start
*
* @return MetaPieChartInterface
@@ -186,6 +203,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param Collection $tags
*
* @return MetaPieChartInterface
@@ -198,6 +217,8 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @codeCoverageIgnore
*
* @param User $user
*
* @return MetaPieChartInterface
@@ -209,23 +230,32 @@ class MetaPieChart implements MetaPieChartInterface
return $this;
}
protected function getTransactions(string $direction)
/**
* @param string $direction
*
* @return Collection
*/
protected function getTransactions(string $direction): Collection
{
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
$modifier = -1;
if ($direction === 'expense') {
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
$modifier = 1;
}
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
$collector->addFilter(NegativeAmountFilter::class);
if ($direction === 'expense') {
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
$collector->addFilter(PositiveAmountFilter::class);
$collector->removeFilter(NegativeAmountFilter::class);
}
$collector->setUser($this->user);
$collector->setAccounts($this->accounts);
$collector->setRange($this->start, $this->end);
$collector->setTypes($types);
$collector->withOpposingAccount();
$collector->addFilter(OpposingAccountFilter::class);
if ($direction === 'income') {
$collector->disableFilter();
$collector->removeFilter(TransferFilter::class);
}
if ($this->budgets->count() > 0) {
@@ -240,11 +270,7 @@ class MetaPieChart implements MetaPieChartInterface
$collector->withBudgetInformation();
}
$accountIds = $this->accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = Support::filterTransactions($transactions, $accountIds, $modifier);
return $set;
return $collector->getJournals();
}
/**
@@ -286,6 +312,7 @@ class MetaPieChart implements MetaPieChartInterface
$chartData = [];
$names = [];
$repository = app($this->repositories[$type]);
$repository->setUser($this->user);
foreach ($array as $objectId => $amount) {
if (!isset($names[$objectId])) {
$object = $repository->find(intval($objectId));
@@ -300,6 +327,11 @@ class MetaPieChart implements MetaPieChartInterface
}
/**
* @param Collection $set
*
* @return array
*/
private function groupByTag(Collection $set): array
{
$grouped = [];

View File

@@ -18,12 +18,17 @@ use Carbon\Carbon;
use Crypt;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Filter\FilterInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User;
use Illuminate\Contracts\Encryption\DecryptException;
@@ -55,17 +60,30 @@ class JournalCollector implements JournalCollectorInterface
'transaction_journals.description',
'transaction_journals.date',
'transaction_journals.encrypted',
'transaction_currencies.code as transaction_currency_code',
'transaction_types.type as transaction_type_type',
'transaction_journals.bill_id',
'bills.name as bill_name',
'bills.name_encrypted as bill_name_encrypted',
'transactions.id as id',
'transactions.amount as transaction_amount',
'transactions.description as transaction_description',
'transactions.account_id',
'transactions.identifier',
'transactions.transaction_journal_id',
'transactions.amount as transaction_amount',
'transactions.transaction_currency_id as transaction_currency_id',
'transaction_currencies.code as transaction_currency_code',
'transaction_currencies.symbol as transaction_currency_symbol',
'transaction_currencies.decimal_places as transaction_currency_dp',
'transactions.foreign_amount as transaction_foreign_amount',
'transactions.foreign_currency_id as foreign_currency_id',
'foreign_currencies.code as foreign_currency_code',
'foreign_currencies.symbol as foreign_currency_symbol',
'foreign_currencies.decimal_places as foreign_currency_dp',
'accounts.name as account_name',
'accounts.encrypted as account_encrypted',
'account_types.type as account_type',
@@ -74,6 +92,9 @@ class JournalCollector implements JournalCollectorInterface
private $filterInternalTransfers;
/** @var bool */
private $filterTransfers = false;
/** @var array */
private $filters = [InternalTransferFilter::class];
/** @var bool */
private $joinedBudget = false;
/** @var bool */
@@ -95,6 +116,22 @@ class JournalCollector implements JournalCollectorInterface
/** @var User */
private $user;
/**
* @param string $filter
*
* @return JournalCollectorInterface
*/
public function addFilter(string $filter): JournalCollectorInterface
{
$interfaces = class_implements($filter);
if (in_array(FilterInterface::class, $interfaces)) {
Log::debug(sprintf('Enabled filter %s', $filter));
$this->filters[] = $filter;
}
return $this;
}
/**
* @return int
* @throws FireflyException
@@ -119,36 +156,6 @@ class JournalCollector implements JournalCollectorInterface
return $this->count;
}
/**
* @return JournalCollectorInterface
*/
public function disableFilter(): JournalCollectorInterface
{
$this->filterTransfers = false;
return $this;
}
/**
* @return JournalCollectorInterface
*/
public function disableInternalFilter(): JournalCollectorInterface
{
$this->filterInternalTransfers = false;
return $this;
}
/**
* @return JournalCollectorInterface
*/
public function enableInternalFilter(): JournalCollectorInterface
{
$this->filterInternalTransfers = true;
return $this;
}
/**
* @return Collection
*/
@@ -157,14 +164,9 @@ class JournalCollector implements JournalCollectorInterface
$this->run = true;
/** @var Collection $set */
$set = $this->query->get(array_values($this->fields));
Log::debug(sprintf('Count of set is %d', $set->count()));
$set = $this->filterTransfers($set);
Log::debug(sprintf('Count of set after filterTransfers() is %d', $set->count()));
// possibly filter "internal" transfers:
$set = $this->filterInternalTransfers($set);
Log::debug(sprintf('Count of set after filterInternalTransfers() is %d', $set->count()));
// run all filters:
$set = $this->filter($set);
// loop for decryption.
$set->each(
@@ -204,6 +206,22 @@ class JournalCollector implements JournalCollectorInterface
return $journals;
}
/**
* @param string $filter
*
* @return JournalCollectorInterface
*/
public function removeFilter(string $filter): JournalCollectorInterface
{
$key = array_search($filter, $this->filters, true);
if (!($key === false)) {
Log::debug(sprintf('Removed filter %s', $filter));
unset($this->filters[$key]);
}
return $this;
}
/**
* @param Collection $accounts
*
@@ -219,6 +237,7 @@ class JournalCollector implements JournalCollectorInterface
}
if ($accounts->count() > 1) {
$this->addFilter(TransferFilter::class);
$this->filterTransfers = true;
}
@@ -242,6 +261,7 @@ class JournalCollector implements JournalCollectorInterface
}
if ($accounts->count() > 1) {
$this->addFilter(TransferFilter::class);
$this->filterTransfers = true;
}
@@ -464,7 +484,9 @@ class JournalCollector implements JournalCollectorInterface
*/
public function setUser(User $user)
{
Log::debug(sprintf('Journal collector now collecting for user #%d', $user->id));
$this->user = $user;
$this->startQuery();
}
/**
@@ -472,13 +494,15 @@ class JournalCollector implements JournalCollectorInterface
*/
public function startQuery()
{
Log::debug('journalCollector::startQuery');
/** @var EloquentBuilder $query */
$query = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transaction_journals.transaction_currency_id')
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transactions.transaction_currency_id')
->leftJoin('transaction_currencies as foreign_currencies', 'foreign_currencies.id', 'transactions.foreign_currency_id')
->whereNull('transactions.deleted_at')
->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id)
@@ -560,79 +584,23 @@ class JournalCollector implements JournalCollectorInterface
*
* @return Collection
*/
private function filterInternalTransfers(Collection $set): Collection
private function filter(Collection $set): Collection
{
if ($this->filterInternalTransfers === false) {
Log::debug('Did NO filtering for internal transfers on given set.');
return $set;
}
if ($this->joinedOpposing === false) {
Log::info('Cannot filter internal transfers because no opposing information is present.');
return $set;
}
$accountIds = $this->accountIds;
$set = $set->filter(
function (Transaction $transaction) use ($accountIds) {
// both id's in $accountids?
if (in_array($transaction->account_id, $accountIds) && in_array($transaction->opposing_account_id, $accountIds)) {
Log::debug(
sprintf(
'Transaction #%d has #%d and #%d in set, so removed',
$transaction->id, $transaction->account_id, $transaction->opposing_account_id
), $accountIds
);
return false;
}
return $transaction;
// create all possible filters:
$filters = [
InternalTransferFilter::class => new InternalTransferFilter($this->accountIds),
OpposingAccountFilter::class => new OpposingAccountFilter($this->accountIds),
TransferFilter::class => new TransferFilter,
PositiveAmountFilter::class => new PositiveAmountFilter,
NegativeAmountFilter::class => new NegativeAmountFilter,
];
Log::debug(sprintf('Will run %d filters on the set.', count($this->filters)));
foreach ($this->filters as $enabled) {
if (isset($filters[$enabled])) {
Log::debug(sprintf('Before filter %s: %d', $enabled, $set->count()));
$set = $filters[$enabled]->filter($set);
Log::debug(sprintf('After filter %s: %d', $enabled, $set->count()));
}
);
return $set;
}
/**
* If the set of accounts used by the collector includes more than one asset
* account, chances are the set include double entries: transfers get selected
* on both the source, and then again on the destination account.
*
* This method filters them out by removing transfers that have been selected twice.
*
* @param Collection $set
*
* @return Collection
*/
private function filterTransfers(Collection $set): Collection
{
if ($this->filterTransfers) {
$count = [];
$new = new Collection;
/** @var Transaction $transaction */
foreach ($set as $transaction) {
if ($transaction->transaction_type_type !== TransactionType::TRANSFER) {
$new->push($transaction);
continue;
}
// make property string:
$journalId = $transaction->transaction_journal_id;
$amount = Steam::positive($transaction->transaction_amount);
$accountIds = [intval($transaction->account_id), intval($transaction->opposing_account_id)];
sort($accountIds);
$key = $journalId . '-' . join(',', $accountIds) . '-' . $amount;
Log::debug(sprintf('Key is %s', $key));
if (!isset($count[$key])) {
// not yet counted? add to new set and count it:
$new->push($transaction);
$count[$key] = 1;
}
}
return $new;
}
return $set;

View File

@@ -28,26 +28,18 @@ use Illuminate\Support\Collection;
*/
interface JournalCollectorInterface
{
/**
* @param string $filter
*
* @return JournalCollectorInterface
*/
public function addFilter(string $filter): JournalCollectorInterface;
/**
* @return int
*/
public function count(): int;
/**
* @return JournalCollectorInterface
*/
public function disableFilter(): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function disableInternalFilter(): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function enableInternalFilter(): JournalCollectorInterface;
/**
* @return Collection
*/
@@ -58,6 +50,13 @@ interface JournalCollectorInterface
*/
public function getPaginatedJournals(): LengthAwarePaginator;
/**
* @param string $filter
*
* @return JournalCollectorInterface
*/
public function removeFilter(string $filter): JournalCollectorInterface;
/**
* @param Collection $accounts
*

View File

@@ -0,0 +1,56 @@
<?php
/**
* AmountFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
* Class AmountFilter
*
* This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount
* ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.
*
* @package FireflyIII\Helpers\Filter
*/
class AmountFilter implements FilterInterface
{
/** @var int */
private $modifier = 0;
public function __construct(int $modifier)
{
$this->modifier = $modifier;
}
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
// remove by amount
if (bccomp($transaction->transaction_amount, '0') === $this->modifier) {
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
return null;
}
return $transaction;
}
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* EmptyFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use Illuminate\Support\Collection;
/**
* Class EmptyFilter
*
* @package FireflyIII\Helpers\Filter
*/
class EmptyFilter implements FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* FilterInterface.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use Illuminate\Support\Collection;
interface FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection;
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* InternalTransferFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
* Class InternalTransferFilter
*
* This filter removes any filters that are from A to B or from B to A given a set of
* account id's (in $parameters) where A and B are mentioned. So transfers between the mentioned
* accounts will be removed.
*
* @package FireflyIII\Helpers\Filter
*/
class InternalTransferFilter implements FilterInterface
{
/** @var array */
private $accounts = [];
/**
* InternalTransferFilter constructor.
*
* @param array $accounts
*/
public function __construct(array $accounts)
{
$this->accounts = $accounts;
}
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
if (is_null($transaction->opposing_account_id)) {
return $transaction;
}
// both id's in $parameters?
if (in_array($transaction->account_id, $this->accounts) && in_array($transaction->opposing_account_id, $this->accounts)) {
Log::debug(
sprintf(
'Transaction #%d has #%d and #%d in set, so removed',
$transaction->id, $transaction->account_id, $transaction->opposing_account_id
), $this->accounts
);
return false;
}
return $transaction;
}
);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* NegativeAmountFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
* Class NegativeAmountFilter
*
* This filter removes entries with a negative amount (the original modifier is -1).
*
* @package FireflyIII\Helpers\Filter
*/
class NegativeAmountFilter implements FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
// remove by amount
if (bccomp($transaction->transaction_amount, '0') === -1) {
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
return null;
}
return $transaction;
}
);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* OpposingAccountFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
* Class OpposingAccountFilter
*
* This filter is similar to the internal transfer filter but only removes transactions when the opposing account is
* amongst $parameters (list of account ID's).
*
* @package FireflyIII\Helpers\Filter
*/
class OpposingAccountFilter implements FilterInterface
{
/** @var array */
private $accounts = [];
/**
* InternalTransferFilter constructor.
*
* @param array $accounts
*/
public function __construct(array $accounts)
{
$this->accounts = $accounts;
}
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
$opposing = $transaction->opposing_account_id;
// remove internal transfer
if (in_array($opposing, $this->accounts)) {
Log::debug(sprintf('Filtered #%d because its opposite is in accounts.', $transaction->id), $this->accounts);
return null;
}
return $transaction;
}
);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* PositiveAmountFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
use Log;
/**
* Class PositiveAmountFilter
*
* This filter removes entries with a negative amount (the original modifier is -1).
*
* This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount
* ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.
*
* @package FireflyIII\Helpers\Filter
*/
class PositiveAmountFilter implements FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
// remove by amount
if (bccomp($transaction->transaction_amount, '0') === 1) {
Log::debug(sprintf('Filtered #%d because amount is %f.', $transaction->id, $transaction->transaction_amount));
return null;
}
return $transaction;
}
);
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* TransferFilter.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Filter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Steam;
/**
* Class TransferFilter
*
* This filter removes any transfers that are in the collection twice (from A to B and from B to A).
*
* @package FireflyIII\Helpers\Filter
*/
class TransferFilter implements FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
$count = [];
$new = new Collection;
/** @var Transaction $transaction */
foreach ($set as $transaction) {
if ($transaction->transaction_type_type !== TransactionType::TRANSFER) {
$new->push($transaction);
continue;
}
// make property string:
$journalId = $transaction->transaction_journal_id;
$amount = Steam::positive($transaction->transaction_amount);
$accountIds = [intval($transaction->account_id), intval($transaction->opposing_account_id)];
sort($accountIds);
$key = $journalId . '-' . join(',', $accountIds) . '-' . $amount;
if (!isset($count[$key])) {
// not yet counted? add to new set and count it:
$new->push($transaction);
$count[$key] = 1;
}
}
return $new;
}
}

View File

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

View File

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

View File

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

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Http\Requests\CategoryFormRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
@@ -211,7 +212,7 @@ class CategoryController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount();
$collector->disableInternalFilter();
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('/categories/list/no-category');
$count = $journals->getCollection()->count();
@@ -294,7 +295,8 @@ class CategoryController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
->setCategory($category)->withBudgetInformation()->withCategoryInformation()->disableInternalFilter();
->setCategory($category)->withBudgetInformation()->withCategoryInformation();
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('categories/show/' . $category->id);
$count = $journals->getCollection()->count();
@@ -402,14 +404,17 @@ class CategoryController extends Controller
// count journals without budget in this period:
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()->withOpposingAccount()->disableInternalFilter();
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()
->withOpposingAccount();
$collector->removeFilter(InternalTransferFilter::class);
$count = $collector->getJournals()->count();
// amount transferred
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutCategory()
->withOpposingAccount()->setTypes([TransactionType::TRANSFER])->disableInternalFilter();
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
$collector->removeFilter(InternalTransferFilter::class);
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
// amount spent
@@ -488,7 +493,8 @@ class CategoryController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->setCategory($category)
->withOpposingAccount()->setTypes([TransactionType::TRANSFER])->disableInternalFilter();
->withOpposingAccount()->setTypes([TransactionType::TRANSFER]);
$collector->removeFilter(InternalTransferFilter::class);
$transferred = Steam::positive($collector->getJournals()->sum('transaction_amount'));
$entries->push(

View File

@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
@@ -115,9 +114,8 @@ class AccountController extends Controller
$start->subDay();
$accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
$ids = $accounts->pluck('id')->toArray();
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$startBalances = Steam::balancesByAccounts($accounts, $start);
$endBalances = Steam::balancesByAccounts($accounts, $end);
$chartData = [];
foreach ($accounts as $account) {
@@ -336,7 +334,7 @@ class AccountController extends Controller
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $start
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
@@ -411,9 +409,8 @@ class AccountController extends Controller
$accounts = $repository->getAccountsByType([AccountType::REVENUE]);
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
$startBalances = Steam::balancesByAccounts($accounts, $start);
$endBalances = Steam::balancesByAccounts($accounts, $end);
foreach ($accounts as $account) {
$id = $account->id;

View File

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

View File

@@ -16,9 +16,11 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
@@ -234,12 +236,15 @@ class BudgetReportController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setBudgets($budgets)->withOpposingAccount()->disableFilter();
$accountIds = $accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = Support::filterExpenses($transactions, $accountIds);
->setBudgets($budgets)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
return $set;
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$transactions = $collector->getJournals();
return $transactions;
}
/**

View File

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

View File

@@ -16,9 +16,12 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Report\Category\MonthReportGenerator;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;
@@ -271,12 +274,15 @@ class CategoryReportController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setCategories($categories)->withOpposingAccount()->disableFilter();
$accountIds = $accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = MonthReportGenerator::filterExpenses($transactions, $accountIds);
->setCategories($categories)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
return $set;
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$transactions = $collector->getJournals();
return $transactions;
}
/**
@@ -293,11 +299,13 @@ class CategoryReportController extends Controller
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setCategories($categories)->withOpposingAccount();
$accountIds = $accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = MonthReportGenerator::filterIncome($transactions, $accountIds);
return $set;
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(NegativeAmountFilter::class);
$transactions = $collector->getJournals();
return $transactions;
}
/**

View File

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

View File

@@ -14,9 +14,12 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Generator\Report\Tag\MonthReportGenerator;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
@@ -303,12 +306,15 @@ class TagReportController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setTags($tags)->withOpposingAccount()->disableFilter();
$accountIds = $accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = MonthReportGenerator::filterExpenses($transactions, $accountIds);
->setTags($tags)->withOpposingAccount();
$collector->removeFilter(TransferFilter::class);
return $set;
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(PositiveAmountFilter::class);
$transactions = $collector->getJournals();
return $transactions;
}
/**
@@ -325,11 +331,13 @@ class TagReportController extends Controller
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setTags($tags)->withOpposingAccount();
$accountIds = $accounts->pluck('id')->toArray();
$transactions = $collector->getJournals();
$set = MonthReportGenerator::filterIncome($transactions, $accountIds);
return $set;
$collector->addFilter(OpposingAccountFilter::class);
$collector->addFilter(NegativeAmountFilter::class);
$transactions = $collector->getJournals();
return $transactions;
}
/**

View File

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

View File

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

View File

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

View File

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

View File

@@ -56,12 +56,8 @@ class PreferencesController extends Controller
*/
public function code(Google2FA $google2fa)
{
$domain = $this->getDomain();
$secretKey = 'FIREFLYIII';
$secretKey = str_pad($secretKey, intval(pow(2, ceil(log(strlen($secretKey), 2)))), 'X');
/** @noinspection PhpMethodParametersCountMismatchInspection */
$secret = $google2fa->generateSecretKey(16, $secretKey);
$domain = $this->getDomain();
$secret = $google2fa->generateSecretKey(16);
Session::flash('two-factor-secret', $secret);
$image = $google2fa->getQRCodeInline('Firefly III at ' . $domain, auth()->user()->email, $secret, 150);

View File

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

View File

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

View File

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

View File

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

View File

@@ -238,6 +238,7 @@ class SingleController extends Controller
$sourceAccounts = $journal->sourceAccountList();
$destinationAccounts = $journal->destinationAccountList();
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$pTransaction = $journal->positiveTransaction();
$preFilled = [
'date' => $journal->dateAsString(),
'interest_date' => $journal->dateAsString('interest_date'),
@@ -250,8 +251,6 @@ class SingleController extends Controller
'source_account_name' => $sourceAccounts->first()->edit_name,
'destination_account_id' => $destinationAccounts->first()->id,
'destination_account_name' => $destinationAccounts->first()->edit_name,
'amount' => $journal->amountPositive(),
'currency' => $journal->transactionCurrency,
// new custom fields:
'due_date' => $journal->dateAsString('due_date'),
@@ -260,26 +259,36 @@ class SingleController extends Controller
'interal_reference' => $journal->getMeta('internal_reference'),
'notes' => $journal->getMeta('notes'),
// exchange rate fields
'native_amount' => $journal->amountPositive(),
'native_currency' => $journal->transactionCurrency,
// amount fields
'amount' => $pTransaction->amount,
'source_amount' => $pTransaction->amount,
'native_amount' => $pTransaction->amount,
'destination_amount' => $pTransaction->foreign_amount,
'currency' => $pTransaction->transactionCurrency,
'source_currency' => $pTransaction->transactionCurrency,
'native_currency' => $pTransaction->transactionCurrency,
'foreign_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
'destination_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
];
// if user has entered a foreign currency, update some fields
$foreignCurrencyId = intval($journal->getMeta('foreign_currency_id'));
if ($foreignCurrencyId > 0) {
// update some fields in pre-filled.
// @codeCoverageIgnoreStart
$preFilled['amount'] = $journal->getMeta('foreign_amount');
$preFilled['currency'] = $this->currency->find(intval($journal->getMeta('foreign_currency_id')));
// @codeCoverageIgnoreEnd
// amounts for withdrawals and deposits:
// amount, native_amount, source_amount, destination_amount
if (($journal->isWithdrawal() || $journal->isDeposit()) && !is_null($pTransaction->foreign_amount)) {
$preFilled['amount'] = $pTransaction->foreign_amount;
$preFilled['currency'] = $pTransaction->foreignCurrency;
}
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type == AccountType::CASH) {
if ($journal->isTransfer() && !is_null($pTransaction->foreign_amount)) {
$preFilled['destination_amount'] = $pTransaction->foreign_amount;
$preFilled['destination_currency'] = $pTransaction->foreignCurrency;
}
// fixes for cash accounts:
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type === AccountType::CASH) {
$preFilled['destination_account_name'] = '';
}
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type == AccountType::CASH) {
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type === AccountType::CASH) {
$preFilled['source_account_name'] = '';
}
@@ -319,6 +328,7 @@ class SingleController extends Controller
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files);

View File

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

View File

@@ -16,8 +16,8 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
use FireflyIII\Support\CacheProperties;
@@ -115,10 +115,10 @@ class TransactionController extends Controller
Log::info('Count is zero, search for journals.');
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
->disableInternalFilter();
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount();
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('/budgets/list/no-budget');
$journals->setPath('/transactions/' . $what);
$count = $journals->getCollection()->count();
if ($count === 0) {
$start->subDay();
@@ -178,21 +178,12 @@ class TransactionController extends Controller
return $this->redirectToAccount($journal);
}
$events = $tasker->getPiggyBankEvents($journal);
$transactions = $tasker->getTransactionsOverview($journal);
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
$foreignCurrency = null;
$events = $tasker->getPiggyBankEvents($journal);
$transactions = $tasker->getTransactionsOverview($journal);
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $what) . ' "' . e($journal->description) . '"';
if ($journal->hasMeta('foreign_currency_id')) {
// @codeCoverageIgnoreStart
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$foreignCurrency = $repository->find(intval($journal->getMeta('foreign_currency_id')));
// @codeCoverageIgnoreEnd
}
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'foreignCurrency'));
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions'));
}
@@ -234,7 +225,8 @@ class TransactionController extends Controller
// count journals without budget in this period:
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withOpposingAccount()->setTypes($types)->disableInternalFilter();
$collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withOpposingAccount()->setTypes($types);
$collector->removeFilter(InternalTransferFilter::class);
$set = $collector->getJournals();
$sum = $set->sum('transaction_amount');
$journals = $set->count();

View File

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

View File

@@ -81,7 +81,7 @@ Breadcrumbs::register(
if ($moment !== 'all') {
$title = trans(
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
);
$breadcrumbs->push($title, route('accounts.show', [$account->id, $moment, $start, $end]));
}
@@ -726,16 +726,16 @@ Breadcrumbs::register(
Breadcrumbs::register(
'tags.show', function (BreadCrumbGenerator $breadcrumbs, Tag $tag, string $moment, Carbon $start, Carbon $end) {
$breadcrumbs->parent('tags.index');
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id], $moment));
$breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id, $moment]));
if ($moment === 'all') {
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id], $moment));
$breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id, $moment]));
}
if ($moment !== 'all') {
$title = trans(
'firefly.between_dates_breadcrumb', ['start' => $start->formatLocalized(strval(trans('config.month_and_day'))),
'end' => $end->formatLocalized(strval(trans('config.month_and_day')))]
);
$breadcrumbs->push($title, route('tags.show', [$tag->id], $moment));
$breadcrumbs->push($title, route('tags.show', [$tag->id, $moment]));
}
}
);

View File

@@ -16,15 +16,12 @@ namespace FireflyIII\Import\Setup;
use ExpandedForm;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Mapper\MapperInterface;
use FireflyIII\Import\MapperPreProcess\PreProcessorInterface;
use FireflyIII\Import\Specifics\SpecificInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Import\CsvImportSupportTrait;
use Illuminate\Http\Request;
use League\Csv\Reader;
use Log;
use Symfony\Component\HttpFoundation\FileBag;
@@ -35,6 +32,7 @@ use Symfony\Component\HttpFoundation\FileBag;
*/
class CsvSetup implements SetupInterface
{
use CsvImportSupportTrait;
/** @var Account */
public $defaultImportAccount;
/** @var ImportJob */
@@ -286,220 +284,4 @@ class CsvSetup implements SetupInterface
$this->job->save();
}
}
/**
* @return bool
*/
private function doColumnMapping(): bool
{
$mapArray = $this->job->configuration['column-do-mapping'] ?? [];
$doMap = false;
foreach ($mapArray as $value) {
if ($value === true) {
$doMap = true;
break;
}
}
return $this->job->configuration['column-mapping-complete'] === false && $doMap;
}
/**
* @return bool
*/
private function doColumnRoles(): bool
{
return $this->job->configuration['column-roles-complete'] === false;
}
/**
* @return array
* @throws FireflyException
*/
private function getDataForColumnMapping(): array
{
$config = $this->job->configuration;
$data = [];
$indexes = [];
foreach ($config['column-do-mapping'] as $index => $mustBeMapped) {
if ($mustBeMapped) {
$column = $config['column-roles'][$index] ?? '_ignore';
// is valid column?
$validColumns = array_keys(config('csv.import_roles'));
if (!in_array($column, $validColumns)) {
throw new FireflyException(sprintf('"%s" is not a valid column.', $column));
}
$canBeMapped = config('csv.import_roles.' . $column . '.mappable');
$preProcessMap = config('csv.import_roles.' . $column . '.pre-process-map');
if ($canBeMapped) {
$mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass);
/** @var MapperInterface $mapper */
$mapper = new $mapperName;
$indexes[] = $index;
$data[$index] = [
'name' => $column,
'mapper' => $mapperName,
'index' => $index,
'options' => $mapper->getMap(),
'preProcessMap' => null,
'values' => [],
];
if ($preProcessMap) {
$preClass = sprintf(
'\\FireflyIII\\Import\\MapperPreProcess\\%s',
config('csv.import_roles.' . $column . '.pre-process-mapper')
);
$data[$index]['preProcessMap'] = $preClass;
}
}
}
}
// in order to actually map we also need all possible values from the CSV file.
$content = $this->job->uploadFileContents();
/** @var Reader $reader */
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$results = $reader->fetch();
$validSpecifics = array_keys(config('csv.import_specifics'));
foreach ($results as $rowIndex => $row) {
// skip first row?
if ($rowIndex === 0 && $config['has-headers']) {
continue;
}
// run specifics here:
// and this is the point where the specifix go to work.
foreach ($config['specifics'] as $name => $enabled) {
if (!in_array($name, $validSpecifics)) {
throw new FireflyException(sprintf('"%s" is not a valid class name', $name));
}
$class = config('csv.import_specifics.' . $name);
/** @var SpecificInterface $specific */
$specific = app($class);
// it returns the row, possibly modified:
$row = $specific->run($row);
}
//do something here
foreach ($indexes as $index) { // this is simply 1, 2, 3, etc.
if (!isset($row[$index])) {
// don't really know how to handle this. Just skip, for now.
continue;
}
$value = $row[$index];
if (strlen($value) > 0) {
// we can do some preprocessing here,
// which is exclusively to fix the tags:
if (!is_null($data[$index]['preProcessMap'])) {
/** @var PreProcessorInterface $preProcessor */
$preProcessor = app($data[$index]['preProcessMap']);
$result = $preProcessor->run($value);
$data[$index]['values'] = array_merge($data[$index]['values'], $result);
Log::debug($rowIndex . ':' . $index . 'Value before preprocessor', ['value' => $value]);
Log::debug($rowIndex . ':' . $index . 'Value after preprocessor', ['value-new' => $result]);
Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $data[$index]['values']]);
continue;
}
$data[$index]['values'][] = $value;
}
}
}
foreach ($data as $index => $entry) {
$data[$index]['values'] = array_unique($data[$index]['values']);
}
return $data;
}
/**
* This method collects the data that will enable a user to choose column content.
*
* @return array
*/
private function getDataForColumnRoles(): array
{
Log::debug('Now in getDataForColumnRoles()');
$config = $this->job->configuration;
$data = [
'columns' => [],
'columnCount' => 0,
'columnHeaders' => [],
];
// show user column role configuration.
$content = $this->job->uploadFileContents();
// create CSV reader.
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$start = $config['has-headers'] ? 1 : 0;
$end = $start + config('csv.example_rows');
$header = [];
if ($config['has-headers']) {
$header = $reader->fetchOne(0);
}
// collect example data in $data['columns']
Log::debug(sprintf('While %s is smaller than %d', $start, $end));
while ($start < $end) {
$row = $reader->fetchOne($start);
Log::debug(sprintf('Row %d has %d columns', $start, count($row)));
// run specifics here:
// and this is the point where the specifix go to work.
foreach ($config['specifics'] as $name => $enabled) {
/** @var SpecificInterface $specific */
$specific = app('FireflyIII\Import\Specifics\\' . $name);
Log::debug(sprintf('Will now apply specific "%s" to row %d.', $name, $start));
// it returns the row, possibly modified:
$row = $specific->run($row);
}
foreach ($row as $index => $value) {
$value = trim($value);
$data['columnHeaders'][$index] = $header[$index] ?? '';
if (strlen($value) > 0) {
$data['columns'][$index][] = $value;
}
}
$start++;
$data['columnCount'] = count($row) > $data['columnCount'] ? count($row) : $data['columnCount'];
}
// make unique example data
foreach ($data['columns'] as $index => $values) {
$data['columns'][$index] = array_unique($values);
}
$data['set_roles'] = [];
// collect possible column roles:
$data['available_roles'] = [];
foreach (array_keys(config('csv.import_roles')) as $role) {
$data['available_roles'][$role] = trans('csv.column_' . $role);
}
$config['column-count'] = $data['columnCount'];
$this->job->configuration = $config;
$this->job->save();
return $data;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace FireflyIII\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class RegisteredUser extends Mailable
{
use Queueable, SerializesModels;
/** @var string */
public $address;
/** @var string */
public $ipAddress;
/**
* Create a new message instance.
*
* @param string $address
* @param string $ipAddress
*/
public function __construct(string $address, string $ipAddress)
{
$this->address = $address;
$this->ipAddress = $ipAddress;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.registered-html')->text('emails.registered-text')->subject('Welcome to Firefly III!');
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace FireflyIII\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class RequestedNewPassword extends Mailable
{
use Queueable, SerializesModels;
/** @var string */
public $ipAddress;
/** @var string */
public $url;
/**
* RequestedNewPassword constructor.
*
* @param string $url
* @param string $ipAddress
*/
public function __construct(string $url, string $ipAddress)
{
$this->url = $url;
$this->ipAddress = $ipAddress;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.password-html')->text('emails.password-text')->subject('Your password reset request');
}
}

View File

@@ -26,14 +26,13 @@ use Watson\Validating\ValidatingTrait;
*/
class Transaction extends Model
{
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts
= [
= [
'created_at' => 'date',
'updated_at' => 'date',
'deleted_at' => 'date',
@@ -41,17 +40,19 @@ class Transaction extends Model
'encrypted' => 'boolean', // model does not have these fields though
'bill_name_encrypted' => 'boolean',
];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount', 'identifier'];
protected $hidden = ['encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable
= ['account_id', 'transaction_journal_id', 'description', 'amount', 'identifier', 'transaction_currency_id', 'foreign_currency_id',
'foreign_amount'];
protected $hidden = ['encrypted'];
protected $rules
= [
'account_id' => 'required|exists:accounts,id',
'transaction_journal_id' => 'required|exists:transaction_journals,id',
'description' => 'between:0,1024',
'amount' => 'required|numeric',
= [
'account_id' => 'required|exists:accounts,id',
'transaction_journal_id' => 'required|exists:transaction_journals,id',
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'description' => 'between:0,1024',
'amount' => 'required|numeric',
];
use SoftDeletes, ValidatingTrait;
/**
* @param Builder $query
@@ -74,6 +75,8 @@ class Transaction extends Model
return false;
}
use SoftDeletes, ValidatingTrait;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
@@ -98,6 +101,14 @@ class Transaction extends Model
return $this->belongsToMany('FireflyIII\Models\Category');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function foreignCurrency()
{
return $this->belongsTo('FireflyIII\Models\TransactionCurrency', 'foreign_currency_id');
}
/**
* @param $value
*
@@ -160,6 +171,14 @@ class Transaction extends Model
$this->attributes['amount'] = strval(round($value, 12));
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function transactionCurrency()
{
return $this->belongsTo('FireflyIII\Models\TransactionCurrency');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/

View File

@@ -19,6 +19,7 @@ use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Models\TransactionJournalTrait;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Log;
@@ -66,13 +67,12 @@ class TransactionJournal extends Model
/** @var array */
protected $rules
= [
'user_id' => 'required|exists:users,id',
'transaction_type_id' => 'required|exists:transaction_types,id',
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'description' => 'required|between:1,1024',
'completed' => 'required|boolean',
'date' => 'required|date',
'encrypted' => 'required|boolean',
'user_id' => 'required|exists:users,id',
'transaction_type_id' => 'required|exists:transaction_types,id',
'description' => 'required|between:1,1024',
'completed' => 'required|boolean',
'date' => 'required|date',
'encrypted' => 'required|boolean',
];
/**
@@ -115,7 +115,7 @@ class TransactionJournal extends Model
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function budgets()
public function budgets(): BelongsToMany
{
return $this->belongsToMany('FireflyIII\Models\Budget');
}
@@ -123,7 +123,7 @@ class TransactionJournal extends Model
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function categories()
public function categories(): BelongsToMany
{
return $this->belongsToMany('FireflyIII\Models\Category');
}
@@ -204,7 +204,7 @@ class TransactionJournal extends Model
/**
* @return bool
*/
public function isDeposit()
public function isDeposit(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type == TransactionType::DEPOSIT;
@@ -217,7 +217,7 @@ class TransactionJournal extends Model
*
* @return bool
*/
public function isOpeningBalance()
public function isOpeningBalance(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type == TransactionType::OPENING_BALANCE;
@@ -230,7 +230,7 @@ class TransactionJournal extends Model
*
* @return bool
*/
public function isTransfer()
public function isTransfer(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type == TransactionType::TRANSFER;
@@ -243,7 +243,7 @@ class TransactionJournal extends Model
*
* @return bool
*/
public function isWithdrawal()
public function isWithdrawal(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type == TransactionType::WITHDRAWAL;
@@ -255,7 +255,7 @@ class TransactionJournal extends Model
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggyBankEvents()
public function piggyBankEvents(): HasMany
{
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
}
@@ -267,7 +267,7 @@ class TransactionJournal extends Model
*
* @return bool
*/
public function save(array $options = [])
public function save(array $options = []): bool
{
$count = $this->tags()->count();
$this->tag_count = $count;
@@ -299,46 +299,6 @@ class TransactionJournal extends Model
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00'));
}
/**
* @param EloquentBuilder $query
*/
public function scopeExpanded(EloquentBuilder $query)
{
// left join transaction type:
if (!self::isJoined($query, 'transaction_types')) {
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
}
// left join transaction currency:
$query->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id');
// extend group by:
$query->groupBy(
[
'transaction_journals.id',
'transaction_journals.created_at',
'transaction_journals.updated_at',
'transaction_journals.deleted_at',
'transaction_journals.user_id',
'transaction_journals.transaction_type_id',
'transaction_journals.bill_id',
'transaction_journals.transaction_currency_id',
'transaction_journals.description',
'transaction_journals.date',
'transaction_journals.interest_date',
'transaction_journals.book_date',
'transaction_journals.process_date',
'transaction_journals.order',
'transaction_journals.tag_count',
'transaction_journals.encrypted',
'transaction_journals.completed',
'transaction_types.type',
'transaction_currencies.code',
]
);
$query->with(['categories', 'budgets', 'attachments', 'bill', 'transactions']);
}
/**
* @param EloquentBuilder $query
*/
@@ -445,9 +405,9 @@ class TransactionJournal extends Model
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* @return HasMany
*/
public function transactions()
public function transactions(): HasMany
{
return $this->hasMany('FireflyIII\Models\Transaction');
}

View File

@@ -44,6 +44,7 @@ use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
use FireflyIII\Support\Twig\Account;
use FireflyIII\Support\Twig\AmountFormat;
use FireflyIII\Support\Twig\General;
use FireflyIII\Support\Twig\Journal;
use FireflyIII\Support\Twig\PiggyBank;
@@ -51,6 +52,7 @@ use FireflyIII\Support\Twig\Rule;
use FireflyIII\Support\Twig\Transaction;
use FireflyIII\Support\Twig\Translation;
use FireflyIII\Validation\FireflyValidator;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Twig;
use TwigBridge\Extension\Loader\Functions;
@@ -78,7 +80,7 @@ class FireflyServiceProvider extends ServiceProvider
Twig::addExtension(new Translation);
Twig::addExtension(new Transaction);
Twig::addExtension(new Rule);
Twig::addExtension(new Account);
Twig::addExtension(new AmountFormat);
}
/**
@@ -123,7 +125,18 @@ class FireflyServiceProvider extends ServiceProvider
$this->app->bind(GeneratorInterface::class, ChartJsGenerator::class);
// chart builder
$this->app->bind(MetaPieChartInterface::class, MetaPieChart::class);
$this->app->bind(
MetaPieChartInterface::class,
function (Application $app) {
/** @var MetaPieChart $chart */
$chart = app(MetaPieChart::class);
if ($app->auth->check()) {
$chart->setUser(auth()->user());
}
return $chart;
}
);
// other generators
$this->app->bind(ProcessorInterface::class, Processor::class);

View File

@@ -52,6 +52,9 @@ class JournalServiceProvider extends ServiceProvider
$this->registerCollector();
}
/**
*
*/
private function registerCollector()
{
$this->app->bind(
@@ -62,13 +65,16 @@ class JournalServiceProvider extends ServiceProvider
if ($app->auth->check()) {
$collector->setUser(auth()->user());
}
$collector->startQuery();
return $collector;
}
);
}
/**
*
*/
private function registerRepository()
{
$this->app->bind(
@@ -86,6 +92,9 @@ class JournalServiceProvider extends ServiceProvider
);
}
/**
*
*/
private function registerTasker()
{
$this->app->bind(
@@ -102,4 +111,5 @@ class JournalServiceProvider extends ServiceProvider
}
);
}
}

View File

@@ -24,8 +24,6 @@ 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;
@@ -37,6 +35,7 @@ use Log;
*/
class AccountRepository implements AccountRepositoryInterface
{
use FindAccountsTrait;
/** @var User */
private $user;
@@ -77,179 +76,6 @@ class AccountRepository implements AccountRepositoryInterface
return true;
}
/**
* @param $accountId
*
* @return Account
*/
public function find(int $accountId): Account
{
$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', '!=', '')->whereNotNull('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();
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named %s of the following type(s)', $name), ['types' => $types]);
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name) {
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account;
}
}
Log::debug('Found nothing.');
return new Account;
}
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
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();
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 $types
*
* @return Collection
*/
public function getActiveAccountsByType(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);
}
$query->where('active', 1);
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* Returns the date of the very last transaction in this account.
*
@@ -453,7 +279,12 @@ class AccountRepository implements AccountRepositoryInterface
*/
protected function storeInitialBalance(Account $account, array $data): TransactionJournal
{
$amount = $data['openingBalance'];
$amount = strval($data['openingBalance']);
if (bccomp($amount, '0') === 0) {
return new TransactionJournal;
}
$name = $data['name'];
$currencyId = $data['currency_id'];
$opposing = $this->storeOpposingAccount($name);
@@ -474,18 +305,32 @@ class AccountRepository implements AccountRepositoryInterface
$firstAccount = $account;
$secondAccount = $opposing;
$firstAmount = $amount;
$secondAmount = $amount * -1;
$secondAmount = bcmul($amount, '-1');
if ($data['openingBalance'] < 0) {
$firstAccount = $opposing;
$secondAccount = $account;
$firstAmount = $amount * -1;
$firstAmount = bcmul($amount, '-1');
$secondAmount = $amount;
}
$one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]);
$one = new Transaction(
[
'account_id' => $firstAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $firstAmount,
'transaction_currency_id' => $currencyId,
]
);
$one->save();// first transaction: from
$two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]);
$two = new Transaction(
[
'account_id' => $secondAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $secondAmount,
'transaction_currency_id' => $currencyId,]
);
$two->save(); // second transaction: to
Log::debug(sprintf('Stored two transactions, #%d and #%d', $one->id, $two->id));
@@ -593,9 +438,15 @@ class AccountRepository implements AccountRepositoryInterface
protected function updateOpeningBalanceJournal(Account $account, TransactionJournal $journal, array $data): bool
{
$date = $data['openingBalanceDate'];
$amount = $data['openingBalance'];
$amount = strval($data['openingBalance']);
$currencyId = intval($data['currency_id']);
if (bccomp($amount, '0') === 0) {
$journal->delete();
return true;
}
// update date:
$journal->date = $date;
$journal->transaction_currency_id = $currencyId;
@@ -604,11 +455,13 @@ class AccountRepository implements AccountRepositoryInterface
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if ($account->id == $transaction->account_id) {
$transaction->amount = $amount;
$transaction->amount = $amount;
$transaction->transaction_currency_id = $currencyId;
$transaction->save();
}
if ($account->id != $transaction->account_id) {
$transaction->amount = $amount * -1;
$transaction->amount = bcmul($amount, '-1');
$transaction->transaction_currency_id = $currencyId;
$transaction->save();
}
}
@@ -618,6 +471,7 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
* @param array $data
*
@@ -625,11 +479,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
protected function validOpeningBalanceData(array $data): bool
{
if (isset($data['openingBalance'])
&& isset($data['openingBalanceDate'])
&& isset($data['openingBalanceCurrency'])
&& bccomp(strval($data['openingBalance']), '0') !== 0
) {
if (isset($data['openingBalance']) && isset($data['openingBalanceDate'])) {
Log::debug('Array has valid opening balance data.');
return true;

View File

@@ -98,6 +98,11 @@ interface AccountRepositoryInterface
*/
public function getActiveAccountsByType(array $types): Collection;
/**
* @return Account
*/
public function getCashAccount(): Account;
/**
* Returns the date of the very last transaction in this account.
*

View File

@@ -41,11 +41,10 @@ class AccountTasker implements AccountTaskerInterface
*/
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array
{
$ids = $accounts->pluck('id')->toArray();
$yesterday = clone $start;
$yesterday->subDay();
$startSet = Steam::balancesById($ids, $yesterday);
$endSet = Steam::balancesById($ids, $end);
$startSet = Steam::balancesByAccounts($accounts, $yesterday);
$endSet = Steam::balancesByAccounts($accounts, $end);
Log::debug('Start of accountreport');
@@ -106,8 +105,7 @@ class AccountTasker implements AccountTaskerInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end);
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->withOpposingAccount()
->enableInternalFilter();
->withOpposingAccount();
$transactions = $collector->getJournals();
$transactions = $transactions->filter(
function (Transaction $transaction) {
@@ -149,8 +147,7 @@ class AccountTasker implements AccountTaskerInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end);
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->withOpposingAccount()
->enableInternalFilter();
->withOpposingAccount();
$transactions = $collector->getJournals();
$transactions = $transactions->filter(
function (Transaction $transaction) {

View File

@@ -0,0 +1,212 @@
<?php
/**
* FindAccountsTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use Log;
/**
* Trait FindAccountsTrait
*
* @package FireflyIII\Repositories\Account
*/
trait FindAccountsTrait
{
/**
* @param $accountId
*
* @return Account
*/
public function find(int $accountId): Account
{
$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', '!=', '')->whereNotNull('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();
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
Log::debug(sprintf('Searching for account named %s of the following type(s)', $name), ['types' => $types]);
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name) {
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
return $account;
}
}
Log::debug('Found nothing.');
return new Account;
}
/**
* @param array $accountIds
*
* @return Collection
*/
public function getAccountsById(array $accountIds): Collection
{
/** @var Collection $result */
$query = $this->user->accounts();
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();
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 $types
*
* @return Collection
*/
public function getActiveAccountsByType(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);
}
$query->where('active', 1);
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* @return Account
*/
public function getCashAccount(): Account
{
$type = AccountType::where('type', AccountType::CASH)->first();
$account = Account::firstOrCreateEncrypted(
['user_id' => $this->user->id, 'account_type_id' => $type->id, 'name' => 'Cash account', 'active' => 1]
);
return $account;
}
}

View File

@@ -228,8 +228,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end);
$collector->setCategories($categories)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->withOpposingAccount()
->enableInternalFilter();
->withOpposingAccount();
$transactions = $collector->getJournals();
// loop transactions:
@@ -260,7 +259,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->enableInternalFilter();
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
$collector->withoutCategory();
$transactions = $collector->getJournals();
$result = [
@@ -312,8 +311,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end);
$collector->setCategories($categories)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->withOpposingAccount()
->enableInternalFilter();
->withOpposingAccount();
$transactions = $collector->getJournals();
// loop transactions:
@@ -345,7 +343,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])->enableInternalFilter();
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER]);
$collector->withoutCategory();
$transactions = $collector->getJournals();
$result = [

View File

@@ -0,0 +1,186 @@
<?php
/**
* CreateJournalsTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
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\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Trait CreateJournalsTrait
*
* @package FireflyIII\Repositories\Journal
*/
trait CreateJournalsTrait
{
/**
*
* * Remember: a balancingAct takes at most one expense and one transfer.
* an advancePayment takes at most one expense, infinite deposits and NO transfers.
*
* @param TransactionJournal $journal
* @param array $array
*
* @return bool
*/
protected function saveTags(TransactionJournal $journal, array $array): bool
{
/** @var TagRepositoryInterface $tagRepository */
$tagRepository = app(TagRepositoryInterface::class);
foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
if (!is_null($tag)) {
Log::debug(sprintf('Will try to connect tag #%d to journal #%d.', $tag->id, $journal->id));
$tagRepository->connect($journal, $tag);
}
}
}
return true;
}
/**
* @param Transaction $transaction
* @param int $budgetId
*/
protected function storeBudgetWithTransaction(Transaction $transaction, int $budgetId)
{
if (intval($budgetId) > 0 && $transaction->transactionJournal->transactionType->type !== TransactionType::TRANSFER) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($budgetId);
$transaction->budgets()->save($budget);
}
}
/**
* @param Transaction $transaction
* @param string $category
*/
protected function storeCategoryWithTransaction(Transaction $transaction, string $category)
{
if (strlen($category) > 0) {
$category = Category::firstOrCreateEncrypted(['name' => $category, 'user_id' => $transaction->transactionJournal->user_id]);
$transaction->categories()->save($category);
}
}
/**
* The reference to storeAccounts() in this function is an indication of spagetti code but alas,
* I leave it as it is.
*
* @param TransactionJournal $journal
* @param array $transaction
* @param int $identifier
*
* @return Collection
*/
protected function storeSplitTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection
{
// store source and destination accounts (depends on type)
$accounts = $this->storeAccounts($this->user, $journal->transactionType, $transaction);
// store transaction one way:
$amount = bcmul(strval($transaction['amount']), '-1');
$foreignAmount = is_null($transaction['foreign_amount']) ? null : bcmul(strval($transaction['foreign_amount']), '-1');
$one = $this->storeTransaction(
[
'journal' => $journal,
'account' => $accounts['source'],
'amount' => $amount,
'transaction_currency_id' => $transaction['transaction_currency_id'],
'foreign_amount' => $foreignAmount,
'foreign_currency_id' => $transaction['foreign_currency_id'],
'description' => $transaction['description'],
'category' => null,
'budget' => null,
'identifier' => $identifier,
]
);
$this->storeCategoryWithTransaction($one, $transaction['category']);
$this->storeBudgetWithTransaction($one, $transaction['budget_id']);
// and the other way:
$amount = strval($transaction['amount']);
$foreignAmount = is_null($transaction['foreign_amount']) ? null : strval($transaction['foreign_amount']);
$two = $this->storeTransaction(
[
'journal' => $journal,
'account' => $accounts['destination'],
'amount' => $amount,
'transaction_currency_id' => $transaction['transaction_currency_id'],
'foreign_amount' => $foreignAmount,
'foreign_currency_id' => $transaction['foreign_currency_id'],
'description' => $transaction['description'],
'category' => null,
'budget' => null,
'identifier' => $identifier,
]
);
$this->storeCategoryWithTransaction($two, $transaction['category']);
$this->storeBudgetWithTransaction($two, $transaction['budget_id']);
return new Collection([$one, $two]);
}
/**
* @param array $data
*
* @return Transaction
*/
protected function storeTransaction(array $data): Transaction
{
$fields = [
'transaction_journal_id' => $data['journal']->id,
'account_id' => $data['account']->id,
'amount' => $data['amount'],
'foreign_amount' => $data['foreign_amount'],
'transaction_currency_id' => $data['transaction_currency_id'],
'foreign_currency_id' => $data['foreign_currency_id'],
'description' => $data['description'],
'identifier' => $data['identifier'],
];
if (is_null($data['foreign_currency_id'])) {
unset($fields['foreign_currency_id']);
}
if (is_null($data['foreign_amount'])) {
unset($fields['foreign_amount']);
}
/** @var Transaction $transaction */
$transaction = Transaction::create($fields);
Log::debug(sprintf('Transaction stored with ID: %s', $transaction->id));
if (!is_null($data['category'])) {
$transaction->categories()->save($data['category']);
}
if (!is_null($data['budget'])) {
$transaction->categories()->save($data['budget']);
}
return $transaction;
}
}

View File

@@ -13,17 +13,9 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
@@ -37,14 +29,12 @@ use Preferences;
*/
class JournalRepository implements JournalRepositoryInterface
{
use CreateJournalsTrait, UpdateJournalsTrait, SupportJournalsTrait;
/** @var User */
private $user;
/** @var array */
private $validMetaFields
= ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes', 'foreign_amount',
'foreign_currency_id',
];
private $validMetaFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes'];
/**
* @param TransactionJournal $journal
@@ -138,6 +128,16 @@ class JournalRepository implements JournalRepositoryInterface
return TransactionType::orderBy('type', 'ASC')->get();
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function isTransfer(TransactionJournal $journal): bool
{
return $journal->transactionType->type === TransactionType::TRANSFER;
}
/**
* @param TransactionJournal $journal
* @param int $order
@@ -170,15 +170,14 @@ class JournalRepository implements JournalRepositoryInterface
// find transaction type.
/** @var TransactionType $transactionType */
$transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
$accounts = $this->storeAccounts($transactionType, $data);
$accounts = $this->storeAccounts($this->user, $transactionType, $data);
$data = $this->verifyNativeAmount($data, $accounts);
$currencyId = $data['currency_id'];
$amount = strval($data['amount']);
$journal = new TransactionJournal(
[
'user_id' => $this->user->id,
'transaction_type_id' => $transactionType->id,
'transaction_currency_id' => $currencyId,
'transaction_currency_id' => $data['currency_id'], // no longer used.
'description' => $data['description'],
'completed' => 0,
'date' => $data['date'],
@@ -190,27 +189,32 @@ class JournalRepository implements JournalRepositoryInterface
$this->storeCategoryWithJournal($journal, $data['category']);
$this->storeBudgetWithJournal($journal, $data['budget_id']);
// store two transactions:
$one = [
'journal' => $journal,
'account' => $accounts['source'],
'amount' => bcmul($amount, '-1'),
'description' => null,
'category' => null,
'budget' => null,
'identifier' => 0,
'journal' => $journal,
'account' => $accounts['source'],
'amount' => bcmul($amount, '-1'),
'transaction_currency_id' => $data['currency_id'],
'foreign_amount' => is_null($data['foreign_amount']) ? null : bcmul(strval($data['foreign_amount']), '-1'),
'foreign_currency_id' => $data['foreign_currency_id'],
'description' => null,
'category' => null,
'budget' => null,
'identifier' => 0,
];
$this->storeTransaction($one);
$two = [
'journal' => $journal,
'account' => $accounts['destination'],
'amount' => $amount,
'description' => null,
'category' => null,
'budget' => null,
'identifier' => 0,
'journal' => $journal,
'account' => $accounts['destination'],
'amount' => $amount,
'transaction_currency_id' => $data['currency_id'],
'foreign_amount' => $data['foreign_amount'],
'foreign_currency_id' => $data['foreign_currency_id'],
'description' => null,
'category' => null,
'budget' => null,
'identifier' => 0,
];
$this->storeTransaction($two);
@@ -246,20 +250,12 @@ class JournalRepository implements JournalRepositoryInterface
{
// update actual journal:
$journal->description = $data['description'];
$journal->date = $data['date'];
$accounts = $this->storeAccounts($journal->transactionType, $data);
$amount = strval($data['amount']);
if ($data['currency_id'] !== $journal->transaction_currency_id) {
// user has entered amount in foreign currency.
// amount in "our" currency is $data['exchanged_amount']:
$amount = strval($data['exchanged_amount']);
// other values must be stored as well:
$data['original_amount'] = $data['amount'];
$data['original_currency_id'] = $data['currency_id'];
}
$journal->description = $data['description'];
$journal->date = $data['date'];
$accounts = $this->storeAccounts($this->user, $journal->transactionType, $data);
$data = $this->verifyNativeAmount($data, $accounts);
$data['amount'] = strval($data['amount']);
$data['foreign_amount'] = is_null($data['foreign_amount']) ? null : strval($data['foreign_amount']);
// unlink all categories, recreate them:
$journal->categories()->detach();
@@ -268,9 +264,11 @@ class JournalRepository implements JournalRepositoryInterface
$this->storeCategoryWithJournal($journal, $data['category']);
$this->storeBudgetWithJournal($journal, $data['budget_id']);
// negative because source loses money.
$this->updateSourceTransaction($journal, $accounts['source'], $data);
$this->updateSourceTransaction($journal, $accounts['source'], bcmul($amount, '-1')); // negative because source loses money.
$this->updateDestinationTransaction($journal, $accounts['destination'], $amount); // positive because destination gets money.
// positive because destination gets money.
$this->updateDestinationTransaction($journal, $accounts['destination'], $data);
$journal->save();
@@ -307,9 +305,8 @@ class JournalRepository implements JournalRepositoryInterface
public function updateSplitJournal(TransactionJournal $journal, array $data): TransactionJournal
{
// update actual journal:
$journal->transaction_currency_id = $data['currency_id'];
$journal->description = $data['journal_description'];
$journal->date = $data['date'];
$journal->description = $data['journal_description'];
$journal->date = $data['date'];
$journal->save();
Log::debug(sprintf('Updated split journal #%d', $journal->id));
@@ -329,7 +326,6 @@ class JournalRepository implements JournalRepositoryInterface
}
}
// update tags:
if (isset($data['tags']) && is_array($data['tags'])) {
$this->updateTags($journal, $data['tags']);
@@ -341,6 +337,7 @@ class JournalRepository implements JournalRepositoryInterface
// store each transaction.
$identifier = 0;
Log::debug(sprintf('Count %d transactions in updateSplitJournal()', count($data['transactions'])));
foreach ($data['transactions'] as $transaction) {
Log::debug(sprintf('Split journal update split transaction %d', $identifier));
$transaction = $this->appendTransactionData($transaction, $data);
@@ -352,466 +349,4 @@ class JournalRepository implements JournalRepositoryInterface
return $journal;
}
/**
* When the user edits a split journal, each line is missing crucial data:
*
* - Withdrawal lines are missing the source account ID
* - Deposit lines are missing the destination account ID
* - Transfers are missing both.
*
* We need to append the array.
*
* @param array $transaction
* @param array $data
*
* @return array
*/
private function appendTransactionData(array $transaction, array $data): array
{
switch ($data['what']) {
case strtolower(TransactionType::TRANSFER):
case strtolower(TransactionType::WITHDRAWAL):
$transaction['source_account_id'] = intval($data['journal_source_account_id']);
break;
}
switch ($data['what']) {
case strtolower(TransactionType::TRANSFER):
case strtolower(TransactionType::DEPOSIT):
$transaction['destination_account_id'] = intval($data['journal_destination_account_id']);
break;
}
return $transaction;
}
/**
*
* * Remember: a balancingAct takes at most one expense and one transfer.
* an advancePayment takes at most one expense, infinite deposits and NO transfers.
*
* @param TransactionJournal $journal
* @param array $array
*
* @return bool
*/
private function saveTags(TransactionJournal $journal, array $array): bool
{
/** @var TagRepositoryInterface $tagRepository */
$tagRepository = app(TagRepositoryInterface::class);
foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
if (!is_null($tag)) {
Log::debug(sprintf('Will try to connect tag #%d to journal #%d.', $tag->id, $journal->id));
$tagRepository->connect($journal, $tag);
}
}
}
return true;
}
/**
* @param TransactionType $type
* @param array $data
*
* @return array
* @throws FireflyException
*/
private function storeAccounts(TransactionType $type, array $data): array
{
$accounts = [
'source' => null,
'destination' => null,
];
Log::debug(sprintf('Going to store accounts for type %s', $type->type));
switch ($type->type) {
case TransactionType::WITHDRAWAL:
$accounts = $this->storeWithdrawalAccounts($data);
break;
case TransactionType::DEPOSIT:
$accounts = $this->storeDepositAccounts($data);
break;
case TransactionType::TRANSFER:
$accounts['source'] = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first();
$accounts['destination'] = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first();
break;
default:
throw new FireflyException(sprintf('Did not recognise transaction type "%s".', $type->type));
}
if (is_null($accounts['source'])) {
Log::error('"source"-account is null, so we cannot continue!', ['data' => $data]);
throw new FireflyException('"source"-account is null, so we cannot continue!');
}
if (is_null($accounts['destination'])) {
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
throw new FireflyException('"destination"-account is null, so we cannot continue!');
}
return $accounts;
}
/**
* @param TransactionJournal $journal
* @param int $budgetId
*/
private function storeBudgetWithJournal(TransactionJournal $journal, int $budgetId)
{
if (intval($budgetId) > 0 && $journal->transactionType->type === TransactionType::WITHDRAWAL) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($budgetId);
$journal->budgets()->save($budget);
}
}
/**
* @param Transaction $transaction
* @param int $budgetId
*/
private function storeBudgetWithTransaction(Transaction $transaction, int $budgetId)
{
if (intval($budgetId) > 0 && $transaction->transactionJournal->transactionType->type !== TransactionType::TRANSFER) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($budgetId);
$transaction->budgets()->save($budget);
}
}
/**
* @param TransactionJournal $journal
* @param string $category
*/
private function storeCategoryWithJournal(TransactionJournal $journal, string $category)
{
if (strlen($category) > 0) {
$category = Category::firstOrCreateEncrypted(['name' => $category, 'user_id' => $journal->user_id]);
$journal->categories()->save($category);
}
}
/**
* @param Transaction $transaction
* @param string $category
*/
private function storeCategoryWithTransaction(Transaction $transaction, string $category)
{
if (strlen($category) > 0) {
$category = Category::firstOrCreateEncrypted(['name' => $category, 'user_id' => $transaction->transactionJournal->user_id]);
$transaction->categories()->save($category);
}
}
/**
* @param array $data
*
* @return array
*/
private function storeDepositAccounts(array $data): array
{
Log::debug('Now in storeDepositAccounts().');
$destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
Log::debug(sprintf('Destination account is #%d ("%s")', $destinationAccount->id, $destinationAccount->name));
if (strlen($data['source_account_name']) > 0) {
$sourceType = AccountType::where('type', 'Revenue account')->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1]
);
Log::debug(sprintf('source account name is "%s", account is %d', $data['source_account_name'], $sourceAccount->id));
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
Log::debug('source_account_name is empty, so default to cash account!');
$sourceType = AccountType::where('type', AccountType::CASH)->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account', 'active' => 1]
);
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
/**
* @param TransactionJournal $journal
* @param array $transaction
* @param int $identifier
*
* @return Collection
*/
private function storeSplitTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection
{
// store source and destination accounts (depends on type)
$accounts = $this->storeAccounts($journal->transactionType, $transaction);
// store transaction one way:
$one = $this->storeTransaction(
[
'journal' => $journal,
'account' => $accounts['source'],
'amount' => bcmul(strval($transaction['amount']), '-1'),
'description' => $transaction['description'],
'category' => null,
'budget' => null,
'identifier' => $identifier,
]
);
$this->storeCategoryWithTransaction($one, $transaction['category']);
$this->storeBudgetWithTransaction($one, $transaction['budget_id']);
// and the other way:
$two = $this->storeTransaction(
[
'journal' => $journal,
'account' => $accounts['destination'],
'amount' => strval($transaction['amount']),
'description' => $transaction['description'],
'category' => null,
'budget' => null,
'identifier' => $identifier,
]
);
$this->storeCategoryWithTransaction($two, $transaction['category']);
$this->storeBudgetWithTransaction($two, $transaction['budget_id']);
return new Collection([$one, $two]);
}
/**
* @param array $data
*
* @return Transaction
*/
private function storeTransaction(array $data): Transaction
{
/** @var Transaction $transaction */
$transaction = Transaction::create(
[
'transaction_journal_id' => $data['journal']->id,
'account_id' => $data['account']->id,
'amount' => $data['amount'],
'description' => $data['description'],
'identifier' => $data['identifier'],
]
);
Log::debug(sprintf('Transaction stored with ID: %s', $transaction->id));
if (!is_null($data['category'])) {
$transaction->categories()->save($data['category']);
}
if (!is_null($data['budget'])) {
$transaction->categories()->save($data['budget']);
}
return $transaction;
}
/**
* @param array $data
*
* @return array
*/
private function storeWithdrawalAccounts(array $data): array
{
Log::debug('Now in storeWithdrawalAccounts().');
$sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
Log::debug(sprintf('Source account is #%d ("%s")', $sourceAccount->id, $sourceAccount->name));
if (strlen($data['destination_account_name']) > 0) {
$destinationType = AccountType::where('type', AccountType::EXPENSE)->first();
$destinationAccount = Account::firstOrCreateEncrypted(
[
'user_id' => $this->user->id,
'account_type_id' => $destinationType->id,
'name' => $data['destination_account_name'],
'active' => 1,
]
);
Log::debug(sprintf('destination account name is "%s", account is %d', $data['destination_account_name'], $destinationAccount->id));
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
Log::debug('destination_account_name is empty, so default to cash account!');
$destinationType = AccountType::where('type', AccountType::CASH)->first();
$destinationAccount = Account::firstOrCreateEncrypted(
['user_id' => $this->user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1]
);
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
/**
* @param TransactionJournal $journal
* @param Account $account
* @param string $amount
*
* @throws FireflyException
*/
private function updateDestinationTransaction(TransactionJournal $journal, Account $account, string $amount)
{
// should be one:
$set = $journal->transactions()->where('amount', '>', 0)->get();
if ($set->count() != 1) {
throw new FireflyException(
sprintf('Journal #%d has an unexpected (%d) amount of transactions with an amount more than zero.', $journal->id, $set->count())
);
}
/** @var Transaction $transaction */
$transaction = $set->first();
$transaction->amount = $amount;
$transaction->account_id = $account->id;
$transaction->save();
}
/**
* @param TransactionJournal $journal
* @param Account $account
* @param string $amount
*
* @throws FireflyException
*/
private function updateSourceTransaction(TransactionJournal $journal, Account $account, string $amount)
{
// should be one:
$set = $journal->transactions()->where('amount', '<', 0)->get();
if ($set->count() != 1) {
throw new FireflyException(
sprintf('Journal #%d has an unexpected (%d) amount of transactions with an amount less than zero.', $journal->id, $set->count())
);
}
/** @var Transaction $transaction */
$transaction = $set->first();
$transaction->amount = $amount;
$transaction->account_id = $account->id;
$transaction->save();
}
/**
* @param TransactionJournal $journal
* @param array $array
*
* @return bool
*/
private function updateTags(TransactionJournal $journal, array $array): bool
{
// create tag repository
/** @var TagRepositoryInterface $tagRepository */
$tagRepository = app(TagRepositoryInterface::class);
// find or create all tags:
$tags = [];
$ids = [];
foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
$tags[] = $tag;
$ids[] = $tag->id;
}
}
// delete all tags connected to journal not in this array:
if (count($ids) > 0) {
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->whereNotIn('tag_id', $ids)->delete();
}
// if count is zero, delete them all:
if (count($ids) == 0) {
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->delete();
}
// connect each tag to journal (if not yet connected):
/** @var Tag $tag */
foreach ($tags as $tag) {
Log::debug(sprintf('Will try to connect tag #%d to journal #%d.', $tag->id, $journal->id));
$tagRepository->connect($journal, $tag);
}
return true;
}
/**
* This method checks the data array and the given accounts to verify that the native amount, currency
* and possible the foreign currency and amount are properly saved.
*
* @param array $data
* @param array $accounts
*
* @return array
* @throws FireflyException
*/
private function verifyNativeAmount(array $data, array $accounts): array
{
/** @var TransactionType $transactionType */
$transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
$submittedCurrencyId = $data['currency_id'];
// which account to check for what the native currency is?
$check = 'source';
if ($transactionType->type === TransactionType::DEPOSIT) {
$check = 'destination';
}
switch ($transactionType->type) {
case TransactionType::DEPOSIT:
case TransactionType::WITHDRAWAL:
// continue:
$nativeCurrencyId = intval($accounts[$check]->getMeta('currency_id'));
// does not match? Then user has submitted amount in a foreign currency:
if ($nativeCurrencyId !== $submittedCurrencyId) {
// store amount and submitted currency in "foreign currency" fields:
$data['foreign_amount'] = $data['amount'];
$data['foreign_currency_id'] = $submittedCurrencyId;
// overrule the amount and currency ID fields to be the original again:
$data['amount'] = strval($data['native_amount']);
$data['currency_id'] = $nativeCurrencyId;
}
break;
case TransactionType::TRANSFER:
// source gets the original amount.
$data['amount'] = strval($data['source_amount']);
$data['currency_id'] = intval($accounts['source']->getMeta('currency_id'));
$data['foreign_amount'] = strval($data['destination_amount']);
$data['foreign_currency_id'] = intval($accounts['destination']->getMeta('currency_id'));
break;
default:
throw new FireflyException(sprintf('Cannot handle %s in verifyNativeAmount()', $transactionType->type));
}
return $data;
}
}

View File

@@ -27,6 +27,7 @@ use Illuminate\Support\MessageBag;
*/
interface JournalRepositoryInterface
{
/**
* @param TransactionJournal $journal
* @param TransactionType $type
@@ -67,6 +68,13 @@ interface JournalRepositoryInterface
*/
public function getTransactionTypes(): Collection;
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function isTransfer(TransactionJournal $journal): bool;
/**
* @param TransactionJournal $journal
* @param int $order

View File

@@ -81,6 +81,8 @@ class JournalTasker implements JournalTaskerInterface
->leftJoin('account_types as source_account_types', 'source_accounts.account_type_id', '=', 'source_account_types.id')
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
->leftJoin('account_types as destination_account_types', 'destination_accounts.account_type_id', '=', 'destination_account_types.id')
->leftJoin('transaction_currencies as native_currencies', 'transactions.transaction_currency_id', '=', 'native_currencies.id')
->leftJoin('transaction_currencies as foreign_currencies', 'transactions.foreign_currency_id', '=', 'foreign_currencies.id')
->where('transactions.amount', '<', 0)
->whereNull('transactions.deleted_at')
->get(
@@ -91,12 +93,23 @@ class JournalTasker implements JournalTaskerInterface
'source_accounts.encrypted as account_encrypted',
'source_account_types.type as account_type',
'transactions.amount',
'transactions.foreign_amount',
'transactions.description',
'destination.id as destination_id',
'destination.account_id as destination_account_id',
'destination_accounts.name as destination_account_name',
'destination_accounts.encrypted as destination_account_encrypted',
'destination_account_types.type as destination_account_type',
'native_currencies.id as transaction_currency_id',
'native_currencies.decimal_places as transaction_currency_dp',
'native_currencies.code as transaction_currency_code',
'native_currencies.symbol as transaction_currency_symbol',
'foreign_currencies.id as foreign_currency_id',
'foreign_currencies.decimal_places as foreign_currency_dp',
'foreign_currencies.code as foreign_currency_code',
'foreign_currencies.symbol as foreign_currency_symbol',
]
);
@@ -109,23 +122,33 @@ class JournalTasker implements JournalTaskerInterface
$budget = $entry->budgets->first();
$category = $entry->categories->first();
$transaction = [
'source_id' => $entry->id,
'source_amount' => $entry->amount,
'description' => $entry->description,
'source_account_id' => $entry->account_id,
'source_account_name' => Steam::decrypt(intval($entry->account_encrypted), $entry->account_name),
'source_account_type' => $entry->account_type,
'source_account_before' => $sourceBalance,
'source_account_after' => bcadd($sourceBalance, $entry->amount),
'destination_id' => $entry->destination_id,
'destination_amount' => bcmul($entry->amount, '-1'),
'destination_account_id' => $entry->destination_account_id,
'destination_account_type' => $entry->destination_account_type,
'destination_account_name' => Steam::decrypt(intval($entry->destination_account_encrypted), $entry->destination_account_name),
'destination_account_before' => $destinationBalance,
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
'budget_id' => is_null($budget) ? 0 : $budget->id,
'category' => is_null($category) ? '' : $category->name,
'source_id' => $entry->id,
'source_amount' => $entry->amount,
'foreign_source_amount' => $entry->foreign_amount,
'description' => $entry->description,
'source_account_id' => $entry->account_id,
'source_account_name' => Steam::decrypt(intval($entry->account_encrypted), $entry->account_name),
'source_account_type' => $entry->account_type,
'source_account_before' => $sourceBalance,
'source_account_after' => bcadd($sourceBalance, $entry->amount),
'destination_id' => $entry->destination_id,
'destination_amount' => bcmul($entry->amount, '-1'),
'foreign_destination_amount' => is_null($entry->foreign_amount) ? null : bcmul($entry->foreign_amount, '-1'),
'destination_account_id' => $entry->destination_account_id,
'destination_account_type' => $entry->destination_account_type,
'destination_account_name' => Steam::decrypt(intval($entry->destination_account_encrypted), $entry->destination_account_name),
'destination_account_before' => $destinationBalance,
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
'budget_id' => is_null($budget) ? 0 : $budget->id,
'category' => is_null($category) ? '' : $category->name,
'transaction_currency_id' => $entry->transaction_currency_id,
'transaction_currency_code' => $entry->transaction_currency_code,
'transaction_currency_symbol' => $entry->transaction_currency_symbol,
'transaction_currency_dp' => $entry->transaction_currency_dp,
'foreign_currency_id' => $entry->foreign_currency_id,
'foreign_currency_code' => $entry->foreign_currency_code,
'foreign_currency_symbol' => $entry->foreign_currency_symbol,
'foreign_currency_dp' => $entry->foreign_currency_dp,
];
if ($entry->destination_account_type === AccountType::CASH) {
$transaction['destination_account_name'] = '';

View File

@@ -0,0 +1,246 @@
<?php
/**
* SupportJournalsTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
use Log;
/**
* Trait SupportJournalsTrait
*
* @package FireflyIII\Repositories\Journal
*/
trait SupportJournalsTrait
{
/**
* @param User $user
* @param TransactionType $type
* @param array $data
*
* @return array
* @throws FireflyException
*/
protected function storeAccounts(User $user, TransactionType $type, array $data): array
{
$accounts = [
'source' => null,
'destination' => null,
];
Log::debug(sprintf('Going to store accounts for type %s', $type->type));
switch ($type->type) {
case TransactionType::WITHDRAWAL:
$accounts = $this->storeWithdrawalAccounts($user, $data);
break;
case TransactionType::DEPOSIT:
$accounts = $this->storeDepositAccounts($user, $data);
break;
case TransactionType::TRANSFER:
$accounts['source'] = Account::where('user_id', $user->id)->where('id', $data['source_account_id'])->first();
$accounts['destination'] = Account::where('user_id', $user->id)->where('id', $data['destination_account_id'])->first();
break;
default:
throw new FireflyException(sprintf('Did not recognise transaction type "%s".', $type->type));
}
if (is_null($accounts['source'])) {
Log::error('"source"-account is null, so we cannot continue!', ['data' => $data]);
throw new FireflyException('"source"-account is null, so we cannot continue!');
}
if (is_null($accounts['destination'])) {
Log::error('"destination"-account is null, so we cannot continue!', ['data' => $data]);
throw new FireflyException('"destination"-account is null, so we cannot continue!');
}
return $accounts;
}
/**
* @param TransactionJournal $journal
* @param int $budgetId
*/
protected function storeBudgetWithJournal(TransactionJournal $journal, int $budgetId)
{
if (intval($budgetId) > 0 && $journal->transactionType->type === TransactionType::WITHDRAWAL) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($budgetId);
$journal->budgets()->save($budget);
}
}
/**
* @param TransactionJournal $journal
* @param string $category
*/
protected function storeCategoryWithJournal(TransactionJournal $journal, string $category)
{
if (strlen($category) > 0) {
$category = Category::firstOrCreateEncrypted(['name' => $category, 'user_id' => $journal->user_id]);
$journal->categories()->save($category);
}
}
/**
* @param User $user
* @param array $data
*
* @return array
*/
protected function storeDepositAccounts(User $user, array $data): array
{
Log::debug('Now in storeDepositAccounts().');
$destinationAccount = Account::where('user_id', $user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
Log::debug(sprintf('Destination account is #%d ("%s")', $destinationAccount->id, $destinationAccount->name));
if (strlen($data['source_account_name']) > 0) {
$sourceType = AccountType::where('type', 'Revenue account')->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1]
);
Log::debug(sprintf('source account name is "%s", account is %d', $data['source_account_name'], $sourceAccount->id));
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
Log::debug('source_account_name is empty, so default to cash account!');
$sourceType = AccountType::where('type', AccountType::CASH)->first();
$sourceAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account', 'active' => 1]
);
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
/**
* @param User $user
* @param array $data
*
* @return array
*/
protected function storeWithdrawalAccounts(User $user, array $data): array
{
Log::debug('Now in storeWithdrawalAccounts().');
$sourceAccount = Account::where('user_id', $user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
Log::debug(sprintf('Source account is #%d ("%s")', $sourceAccount->id, $sourceAccount->name));
if (strlen($data['destination_account_name']) > 0) {
$destinationType = AccountType::where('type', AccountType::EXPENSE)->first();
$destinationAccount = Account::firstOrCreateEncrypted(
[
'user_id' => $user->id,
'account_type_id' => $destinationType->id,
'name' => $data['destination_account_name'],
'active' => 1,
]
);
Log::debug(sprintf('destination account name is "%s", account is %d', $data['destination_account_name'], $destinationAccount->id));
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
Log::debug('destination_account_name is empty, so default to cash account!');
$destinationType = AccountType::where('type', AccountType::CASH)->first();
$destinationAccount = Account::firstOrCreateEncrypted(
['user_id' => $user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1]
);
return [
'source' => $sourceAccount,
'destination' => $destinationAccount,
];
}
/**
* This method checks the data array and the given accounts to verify that the native amount, currency
* and possible the foreign currency and amount are properly saved.
*
* @param array $data
* @param array $accounts
*
* @return array
* @throws FireflyException
*/
protected function verifyNativeAmount(array $data, array $accounts): array
{
/** @var TransactionType $transactionType */
$transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
$submittedCurrencyId = $data['currency_id'];
$data['foreign_amount'] = null;
$data['foreign_currency_id'] = null;
// which account to check for what the native currency is?
$check = 'source';
if ($transactionType->type === TransactionType::DEPOSIT) {
$check = 'destination';
}
switch ($transactionType->type) {
case TransactionType::DEPOSIT:
case TransactionType::WITHDRAWAL:
// continue:
$nativeCurrencyId = intval($accounts[$check]->getMeta('currency_id'));
// does not match? Then user has submitted amount in a foreign currency:
if ($nativeCurrencyId !== $submittedCurrencyId) {
// store amount and submitted currency in "foreign currency" fields:
$data['foreign_amount'] = $data['amount'];
$data['foreign_currency_id'] = $submittedCurrencyId;
// overrule the amount and currency ID fields to be the original again:
$data['amount'] = strval($data['native_amount']);
$data['currency_id'] = $nativeCurrencyId;
}
break;
case TransactionType::TRANSFER:
$sourceCurrencyId = intval($accounts['source']->getMeta('currency_id'));
$destinationCurrencyId = intval($accounts['destination']->getMeta('currency_id'));
$data['amount'] = strval($data['source_amount']);
$data['currency_id'] = intval($accounts['source']->getMeta('currency_id'));
if ($sourceCurrencyId !== $destinationCurrencyId) {
// accounts have different id's, save this info:
$data['foreign_amount'] = strval($data['destination_amount']);
$data['foreign_currency_id'] = $destinationCurrencyId;
}
break;
default:
throw new FireflyException(sprintf('Cannot handle %s in verifyNativeAmount()', $transactionType->type));
}
return $data;
}
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* UpdateJournalsTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Log;
/**
* Trait UpdateJournalsTrait
*
* @package FireflyIII\Repositories\Journal
*/
trait UpdateJournalsTrait
{
/**
* When the user edits a split journal, each line is missing crucial data:
*
* - Withdrawal lines are missing the source account ID
* - Deposit lines are missing the destination account ID
* - Transfers are missing both.
*
* We need to append the array.
*
* @param array $transaction
* @param array $data
*
* @return array
*/
protected function appendTransactionData(array $transaction, array $data): array
{
switch ($data['what']) {
case strtolower(TransactionType::TRANSFER):
case strtolower(TransactionType::WITHDRAWAL):
$transaction['source_account_id'] = intval($data['journal_source_account_id']);
break;
}
switch ($data['what']) {
case strtolower(TransactionType::TRANSFER):
case strtolower(TransactionType::DEPOSIT):
$transaction['destination_account_id'] = intval($data['journal_destination_account_id']);
break;
}
return $transaction;
}
/**
* @param TransactionJournal $journal
* @param Account $account
* @param array $data
*
* @throws FireflyException
*/
protected function updateDestinationTransaction(TransactionJournal $journal, Account $account, array $data)
{
$set = $journal->transactions()->where('amount', '>', 0)->get();
if ($set->count() != 1) {
throw new FireflyException(sprintf('Journal #%d has %d transactions with an amount more than zero.', $journal->id, $set->count()));
}
/** @var Transaction $transaction */
$transaction = $set->first();
$transaction->amount = app('steam')->positive($data['amount']);
$transaction->transaction_currency_id = $data['currency_id'];
$transaction->foreign_amount = is_null($data['foreign_amount']) ? null : app('steam')->positive($data['foreign_amount']);
$transaction->foreign_currency_id = $data['foreign_currency_id'];
$transaction->account_id = $account->id;
$transaction->save();
}
/**
* @param TransactionJournal $journal
* @param Account $account
* @param array $data
*
* @throws FireflyException
*/
protected function updateSourceTransaction(TransactionJournal $journal, Account $account, array $data)
{
// should be one:
$set = $journal->transactions()->where('amount', '<', 0)->get();
if ($set->count() != 1) {
throw new FireflyException(sprintf('Journal #%d has %d transactions with an amount more than zero.', $journal->id, $set->count()));
}
/** @var Transaction $transaction */
$transaction = $set->first();
$transaction->amount = bcmul(app('steam')->positive($data['amount']), '-1');
$transaction->transaction_currency_id = $data['currency_id'];
$transaction->foreign_amount = is_null($data['foreign_amount']) ? null : bcmul(app('steam')->positive($data['foreign_amount']), '-1');
$transaction->foreign_currency_id = $data['foreign_currency_id'];
$transaction->account_id = $account->id;
$transaction->save();
}
/**
* @param TransactionJournal $journal
* @param array $array
*
* @return bool
*/
protected function updateTags(TransactionJournal $journal, array $array): bool
{
// create tag repository
/** @var TagRepositoryInterface $tagRepository */
$tagRepository = app(TagRepositoryInterface::class);
// find or create all tags:
$tags = [];
$ids = [];
foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
$tags[] = $tag;
$ids[] = $tag->id;
}
}
// delete all tags connected to journal not in this array:
if (count($ids) > 0) {
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->whereNotIn('tag_id', $ids)->delete();
}
// if count is zero, delete them all:
if (count($ids) == 0) {
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal->id)->delete();
}
// connect each tag to journal (if not yet connected):
/** @var Tag $tag */
foreach ($tags as $tag) {
Log::debug(sprintf('Will try to connect tag #%d to journal #%d.', $tag->id, $journal->id));
$tagRepository->connect($journal, $tag);
}
return true;
}
}

View File

@@ -18,8 +18,11 @@ use Carbon\Carbon;
use FireflyIII\Models\Note;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class PiggyBankRepository
@@ -51,6 +54,21 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return true;
}
/**
* @param PiggyBankRepetition $repetition
* @param string $amount
*
* @return string
*/
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount): string
{
$newAmount = bcadd($repetition->currentamount, $amount);
$repetition->currentamount = $newAmount;
$repetition->save();
return $newAmount;
}
/**
* @param PiggyBank $piggyBank
* @param string $amount
@@ -94,6 +112,23 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $event;
}
/**
* @param PiggyBank $piggyBank
* @param string $amount
* @param TransactionJournal $journal
*
* @return PiggyBankEvent
*/
public function createEventWithJournal(PiggyBank $piggyBank, string $amount, TransactionJournal $journal): PiggyBankEvent
{
/** @var PiggyBankEvent $event */
$event = PiggyBankEvent::create(
['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]
);
return $event;
}
/**
* @param PiggyBank $piggyBank
*
@@ -132,6 +167,53 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $piggyBank->piggyBankEvents()->orderBy('date', 'DESC')->orderBy('id', 'DESC')->get();
}
/**
* Used for connecting to a piggy bank.
*
* @param PiggyBank $piggyBank
* @param PiggyBankRepetition $repetition
* @param TransactionJournal $journal
*
* @return string
*/
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
{
$amount = $journal->amountPositive();
$sources = $journal->sourceAccountList()->pluck('id')->toArray();
$room = bcsub(strval($piggyBank->targetamount), strval($repetition->currentamount));
$compare = bcmul($repetition->currentamount, '-1');
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
// if piggy account matches source account, the amount is positive
if (in_array($piggyBank->account_id, $sources)) {
$amount = bcmul($amount, '-1');
Log::debug(sprintf('Account #%d is the source, so will remove amount from piggy bank.', $piggyBank->account_id));
}
// if the amount is positive, make sure it fits in piggy bank:
if (bccomp($amount, '0') === 1 && bccomp($room, $amount) === -1) {
// amount is positive and $room is smaller than $amount
Log::debug(sprintf('Room in piggy bank for extra money is %f', $room));
Log::debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
Log::debug(sprintf('New amount is %f', $room));
return $room;
}
// amount is negative and $currentamount is smaller than $amount
if (bccomp($amount, '0') === -1 && bccomp($compare, $amount) === 1) {
Log::debug(sprintf('Max amount to remove is %f', $repetition->currentamount));
Log::debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
Log::debug(sprintf('New amount is %f', $compare));
return $compare;
}
return $amount;
}
/**
* @return int
*/
@@ -158,15 +240,33 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
public function getPiggyBanksWithAmount(): Collection
{
$set = $this->getPiggyBanks();
$currency = Amount::getDefaultCurrency();
$set = $this->getPiggyBanks();
foreach ($set as $piggy) {
$currentAmount = $piggy->currentRelevantRep()->currentamount ?? '0';
$piggy->name = $piggy->name . ' (' . Amount::format($currentAmount, false) . ')';
$piggy->name = $piggy->name . ' (' . Amount::formatAnything($currency, $currentAmount, false) . ')';
}
return $set;
}
/**
* @param PiggyBank $piggyBank
* @param Carbon $date
*
* @return PiggyBankRepetition
*/
public function getRepetition(PiggyBank $piggyBank, Carbon $date): PiggyBankRepetition
{
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($date)->first();
if (is_null($repetition)) {
return new PiggyBankRepetition;
}
return $repetition;
}
/**
* @param PiggyBank $piggyBank
* @param string $amount

View File

@@ -13,8 +13,11 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\PiggyBank;
use Carbon\Carbon;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -25,7 +28,6 @@ use Illuminate\Support\Collection;
*/
interface PiggyBankRepositoryInterface
{
/**
* @param PiggyBank $piggyBank
* @param string $amount
@@ -34,6 +36,14 @@ interface PiggyBankRepositoryInterface
*/
public function addAmount(PiggyBank $piggyBank, string $amount): bool;
/**
* @param PiggyBankRepetition $repetition
* @param string $amount
*
* @return string
*/
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount): string;
/**
* @param PiggyBank $piggyBank
* @param string $amount
@@ -60,6 +70,15 @@ interface PiggyBankRepositoryInterface
*/
public function createEvent(PiggyBank $piggyBank, string $amount): PiggyBankEvent;
/**
* @param PiggyBank $piggyBank
* @param string $amount
* @param TransactionJournal $journal
*
* @return PiggyBankEvent
*/
public function createEventWithJournal(PiggyBank $piggyBank, string $amount, TransactionJournal $journal): PiggyBankEvent;
/**
* Destroy piggy bank.
*
@@ -85,6 +104,17 @@ interface PiggyBankRepositoryInterface
*/
public function getEvents(PiggyBank $piggyBank): Collection;
/**
* Used for connecting to a piggy bank.
*
* @param PiggyBank $piggyBank
* @param PiggyBankRepetition $repetition
* @param TransactionJournal $journal
*
* @return string
*/
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string;
/**
* Highest order of all piggy banks.
*
@@ -106,6 +136,14 @@ interface PiggyBankRepositoryInterface
*/
public function getPiggyBanksWithAmount(): Collection;
/**
* @param PiggyBank $piggyBank
* @param Carbon $date
*
* @return PiggyBankRepetition
*/
public function getRepetition(PiggyBank $piggyBank, Carbon $date): PiggyBankRepetition;
/**
* @param PiggyBank $piggyBank
* @param string $amount

View File

@@ -92,6 +92,46 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
return $this->user->ruleGroups()->orderBy('order', 'ASC')->get();
}
/**
* @param User $user
*
* @return Collection
*/
public function getActiveGroups(User $user): Collection
{
return $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(['rule_groups.*']);
}
/**
* @param RuleGroup $group
*
* @return Collection
*/
public function getActiveStoreRules(RuleGroup $group): Collection
{
return $group->rules()
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'store-journal')
->where('rules.active', 1)
->get(['rules.*']);
}
/**
* @param RuleGroup $group
*
* @return Collection
*/
public function getActiveUpdateRules(RuleGroup $group): Collection
{
return $group->rules()
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'update-journal')
->where('rules.active', 1)
->get(['rules.*']);
}
/**
* @return int
*/

View File

@@ -53,6 +53,27 @@ interface RuleGroupRepositoryInterface
*/
public function get(): Collection;
/**
* @param User $user
*
* @return Collection
*/
public function getActiveGroups(User $user): Collection;
/**
* @param RuleGroup $group
*
* @return Collection
*/
public function getActiveStoreRules(RuleGroup $group): Collection;
/**
* @param RuleGroup $group
*
* @return Collection
*/
public function getActiveUpdateRules(RuleGroup $group): Collection;
/**
* @return int
*/

View File

@@ -47,7 +47,7 @@ class TagRepository implements TagRepositoryInterface
* Already connected:
*/
if ($journal->tags()->find($tag->id)) {
Log::error(sprintf('Cannot find tag #%d', $tag->id));
Log::info(sprintf('Tag #%d is already connected to journal #%d.', $tag->id, $journal->id));
return false;
}

View File

@@ -61,6 +61,8 @@ class FixerIO implements ExchangeRateInterface
/**
* @param User $user
*
* @return mixed|void
*/
public function setUser(User $user)
{

View File

@@ -14,9 +14,10 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Preferences as Prefs;
@@ -27,6 +28,7 @@ use Preferences as Prefs;
*/
class Amount
{
/**
* bool $sepBySpace is $localeconv['n_sep_by_space']
* int $signPosn = $localeconv['n_sign_posn']
@@ -101,17 +103,6 @@ class Amount
return $format;
}
/**
* @param string $amount
* @param bool $coloured
*
* @return string
*/
public function format(string $amount, bool $coloured = true): string
{
return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);
}
/**
* This method will properly format the given number, in color or "black and white",
* as a currency, given two things: the currency required and the current locale.
@@ -159,49 +150,6 @@ class Amount
return $result;
}
/**
* Used in many places (unfortunately).
*
* @param string $currencyCode
* @param string $amount
* @param bool $coloured
*
* @return string
*/
public function formatByCode(string $currencyCode, string $amount, bool $coloured = true): string
{
$currency = TransactionCurrency::where('code', $currencyCode)->first();
return $this->formatAnything($currency, $amount, $coloured);
}
/**
*
* @param \FireflyIII\Models\TransactionJournal $journal
* @param bool $coloured
*
* @return string
*/
public function formatJournal(TransactionJournal $journal, bool $coloured = true): string
{
$currency = $journal->transactionCurrency;
return $this->formatAnything($currency, $journal->amount(), $coloured);
}
/**
* @param Transaction $transaction
* @param bool $coloured
*
* @return string
*/
public function formatTransaction(Transaction $transaction, bool $coloured = true)
{
$currency = $transaction->transactionJournal->transactionCurrency;
return $this->formatAnything($currency, strval($transaction->amount), $coloured);
}
/**
* @return Collection
*/
@@ -256,7 +204,7 @@ class Amount
}
/**
* @return TransactionCurrency
* @return \FireflyIII\Models\TransactionCurrency
* @throws FireflyException
*/
public function getDefaultCurrency(): TransactionCurrency
@@ -295,4 +243,81 @@ class Amount
'zero' => $positive,
];
}
/**
* @param TransactionJournal $journal
* @param bool $coloured
*
* @return string
*/
public function journalAmount(TransactionJournal $journal, bool $coloured = true): string
{
$amounts = [];
$transactions = $journal->transactions()->where('amount', '>', 0)->get();
/** @var TransactionModel $transaction */
foreach ($transactions as $transaction) {
// model some fields to fit "transactionAmount()":
$transaction->transaction_amount = $transaction->amount;
$transaction->transaction_foreign_amount = $transaction->foreign_amount;
$transaction->transaction_type_type = $journal->transactionType->type;
$transaction->transaction_currency_symbol = $transaction->transactionCurrency->symbol;
$transaction->transaction_currency_dp = $transaction->transactionCurrency->decimal_places;
if (!is_null($transaction->foreign_currency_id)) {
$transaction->foreign_currency_symbol = $transaction->foreignCurrency->symbol;
$transaction->foreign_currency_dp = $transaction->foreignCurrency->decimal_places;
}
$amounts[] = $this->transactionAmount($transaction, $coloured);
}
return join(' / ', $amounts);
}
/**
* This formats a transaction, IF that transaction has been "collected" using the JournalCollector.
*
* @param TransactionModel $transaction
* @param bool $coloured
*
* @return string
*/
public function transactionAmount(TransactionModel $transaction, bool $coloured = true): string
{
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1');
$format = '%s';
if ($transaction->transaction_type_type === TransactionType::DEPOSIT) {
$amount = bcmul($amount, '-1');
}
if ($transaction->transaction_type_type === TransactionType::TRANSFER) {
$amount = app('steam')->positive($amount);
$coloured = false;
$format = '<span class="text-info">%s</span>';
}
$currency = new TransactionCurrency;
$currency->symbol = $transaction->transaction_currency_symbol;
$currency->decimal_places = $transaction->transaction_currency_dp;
$str = sprintf($format, $this->formatAnything($currency, $amount, $coloured));
if (!is_null($transaction->transaction_foreign_amount)) {
$amount = strval($transaction->transaction_foreign_amount);
if ($transaction->transaction_type_type === TransactionType::TRANSFER) {
$amount = app('steam')->positive($amount);
$coloured = false;
$format = '<span class="text-info">%s</span>';
}
$currency = new TransactionCurrency;
$currency->symbol = $transaction->foreign_currency_symbol;
$currency->decimal_places = $transaction->foreign_currency_dp;
$str .= ' (' . sprintf($format, $this->formatAnything($currency, $amount, $coloured)) . ')';
}
return $str;
}
}

View File

@@ -37,15 +37,8 @@ class JournalList implements BinderInterface
$ids = explode(',', $value);
/** @var \Illuminate\Support\Collection $object */
$object = TransactionJournal::whereIn('transaction_journals.id', $ids)
->expanded()
->where('transaction_journals.user_id', auth()->user()->id)
->get(
[
'transaction_journals.*',
'transaction_types.type AS transaction_type_type',
'transaction_currencies.code AS transaction_currency_code',
]
);
->get(['transaction_journals.*',]);
if ($object->count() > 0) {
return $object;

View File

@@ -0,0 +1,242 @@
<?php
/**
* CsvImportSupportTrait.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Import;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Mapper\MapperInterface;
use FireflyIII\Import\MapperPreProcess\PreProcessorInterface;
use FireflyIII\Import\Specifics\SpecificInterface;
use League\Csv\Reader;
use Log;
/**
* Trait CsvImportSupportTrait
*
* @package FireflyIII\Support\Import
*/
trait CsvImportSupportTrait
{
/**
* @return bool
*/
protected function doColumnMapping(): bool
{
$mapArray = $this->job->configuration['column-do-mapping'] ?? [];
$doMap = false;
foreach ($mapArray as $value) {
if ($value === true) {
$doMap = true;
break;
}
}
return $this->job->configuration['column-mapping-complete'] === false && $doMap;
}
/**
* @return bool
*/
protected function doColumnRoles(): bool
{
return $this->job->configuration['column-roles-complete'] === false;
}
/**
* @return array
* @throws FireflyException
*/
protected function getDataForColumnMapping(): array
{
$config = $this->job->configuration;
$data = [];
$indexes = [];
foreach ($config['column-do-mapping'] as $index => $mustBeMapped) {
if ($mustBeMapped) {
$column = $config['column-roles'][$index] ?? '_ignore';
// is valid column?
$validColumns = array_keys(config('csv.import_roles'));
if (!in_array($column, $validColumns)) {
throw new FireflyException(sprintf('"%s" is not a valid column.', $column));
}
$canBeMapped = config('csv.import_roles.' . $column . '.mappable');
$preProcessMap = config('csv.import_roles.' . $column . '.pre-process-map');
if ($canBeMapped) {
$mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass);
/** @var MapperInterface $mapper */
$mapper = new $mapperName;
$indexes[] = $index;
$data[$index] = [
'name' => $column,
'mapper' => $mapperName,
'index' => $index,
'options' => $mapper->getMap(),
'preProcessMap' => null,
'values' => [],
];
if ($preProcessMap) {
$preClass = sprintf(
'\\FireflyIII\\Import\\MapperPreProcess\\%s',
config('csv.import_roles.' . $column . '.pre-process-mapper')
);
$data[$index]['preProcessMap'] = $preClass;
}
}
}
}
// in order to actually map we also need all possible values from the CSV file.
$content = $this->job->uploadFileContents();
/** @var Reader $reader */
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$results = $reader->fetch();
$validSpecifics = array_keys(config('csv.import_specifics'));
foreach ($results as $rowIndex => $row) {
// skip first row?
if ($rowIndex === 0 && $config['has-headers']) {
continue;
}
// run specifics here:
// and this is the point where the specifix go to work.
foreach ($config['specifics'] as $name => $enabled) {
if (!in_array($name, $validSpecifics)) {
throw new FireflyException(sprintf('"%s" is not a valid class name', $name));
}
$class = config('csv.import_specifics.' . $name);
/** @var SpecificInterface $specific */
$specific = app($class);
// it returns the row, possibly modified:
$row = $specific->run($row);
}
//do something here
foreach ($indexes as $index) { // this is simply 1, 2, 3, etc.
if (!isset($row[$index])) {
// don't really know how to handle this. Just skip, for now.
continue;
}
$value = $row[$index];
if (strlen($value) > 0) {
// we can do some preprocessing here,
// which is exclusively to fix the tags:
if (!is_null($data[$index]['preProcessMap'])) {
/** @var PreProcessorInterface $preProcessor */
$preProcessor = app($data[$index]['preProcessMap']);
$result = $preProcessor->run($value);
$data[$index]['values'] = array_merge($data[$index]['values'], $result);
Log::debug($rowIndex . ':' . $index . 'Value before preprocessor', ['value' => $value]);
Log::debug($rowIndex . ':' . $index . 'Value after preprocessor', ['value-new' => $result]);
Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $data[$index]['values']]);
continue;
}
$data[$index]['values'][] = $value;
}
}
}
foreach ($data as $index => $entry) {
$data[$index]['values'] = array_unique($data[$index]['values']);
}
return $data;
}
/**
* This method collects the data that will enable a user to choose column content.
*
* @return array
*/
protected function getDataForColumnRoles(): array
{
Log::debug('Now in getDataForColumnRoles()');
$config = $this->job->configuration;
$data = [
'columns' => [],
'columnCount' => 0,
'columnHeaders' => [],
];
// show user column role configuration.
$content = $this->job->uploadFileContents();
// create CSV reader.
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$start = $config['has-headers'] ? 1 : 0;
$end = $start + config('csv.example_rows');
$header = [];
if ($config['has-headers']) {
$header = $reader->fetchOne(0);
}
// collect example data in $data['columns']
Log::debug(sprintf('While %s is smaller than %d', $start, $end));
while ($start < $end) {
$row = $reader->fetchOne($start);
Log::debug(sprintf('Row %d has %d columns', $start, count($row)));
// run specifics here:
// and this is the point where the specifix go to work.
foreach ($config['specifics'] as $name => $enabled) {
/** @var SpecificInterface $specific */
$specific = app('FireflyIII\Import\Specifics\\' . $name);
Log::debug(sprintf('Will now apply specific "%s" to row %d.', $name, $start));
// it returns the row, possibly modified:
$row = $specific->run($row);
}
foreach ($row as $index => $value) {
$value = trim($value);
$data['columnHeaders'][$index] = $header[$index] ?? '';
if (strlen($value) > 0) {
$data['columns'][$index][] = $value;
}
}
$start++;
$data['columnCount'] = count($row) > $data['columnCount'] ? count($row) : $data['columnCount'];
}
// make unique example data
foreach ($data['columns'] as $index => $values) {
$data['columns'][$index] = array_unique($values);
}
$data['set_roles'] = [];
// collect possible column roles:
$data['available_roles'] = [];
foreach (array_keys(config('csv.import_roles')) as $role) {
$data['available_roles'][$role] = trans('csv.column_' . $role);
}
$config['column-count'] = $data['columnCount'];
$this->job->configuration = $config;
$this->job->save();
return $data;
}
}

View File

@@ -15,16 +15,21 @@ namespace FireflyIII\Support\Models;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
/**
* Class TransactionJournalTrait
*
* @property int $id
* @method Collection transactions()
* @method bool isWithdrawal()
* @property int $id
* @property Carbon $date
* @property string $transaction_type_type
* @property TransactionType $transactionType
*
* @package FireflyIII\Support\Models
*/
@@ -91,6 +96,16 @@ trait TransactionJournalTrait
return 0;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
abstract public function budgets(): BelongsToMany;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
abstract public function categories(): BelongsToMany;
/**
* @return string
*/
@@ -180,6 +195,19 @@ trait TransactionJournalTrait
return $list;
}
/**
*
* @param string $name
*
* @return string
*/
abstract public function getMeta(string $name);
/**
* @return bool
*/
abstract public function isDeposit(): bool;
/**
* @param Builder $query
* @param string $table
@@ -201,6 +229,29 @@ trait TransactionJournalTrait
return false;
}
/**
*
* @return bool
*/
abstract public function isOpeningBalance(): bool;
/**
*
* @return bool
*/
abstract public function isTransfer(): bool;
/**
*
* @return bool
*/
abstract public function isWithdrawal(): bool;
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
abstract public function piggyBankEvents(): HasMany;
/**
* @return int
*/
@@ -213,6 +264,31 @@ trait TransactionJournalTrait
return 0;
}
/**
* @return Transaction
*/
public function positiveTransaction(): Transaction
{
return $this->transactions()->where('amount', '>', 0)->first();
}
/**
* Save the model to the database.
*
* @param array $options
*
* @return bool
*/
abstract public function save(array $options = []): bool;
/**
* @param string $name
* @param $value
*
* @return TransactionJournalMeta
*/
abstract public function setMeta(string $name, $value): TransactionJournalMeta;
/**
* @return Collection
*/
@@ -273,4 +349,9 @@ trait TransactionJournalTrait
return $typeStr;
}
/**
* @return HasMany
*/
abstract public function transactions(): HasMany;
}

View File

@@ -16,6 +16,7 @@ namespace FireflyIII\Support\Search;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
@@ -52,7 +53,7 @@ class Search implements SearchInterface
public function __construct()
{
$this->modifiers = new Collection;
$this->validModifiers = config('firefly.search_modifiers');
$this->validModifiers = (array) config('firefly.search_modifiers');
}
/**
@@ -207,7 +208,7 @@ class Search implements SearchInterface
if ($this->hasModifiers()) {
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
}
$collector->disableInternalFilter();
$collector->removeFilter(InternalTransferFilter::class);
$set = $collector->getPaginatedJournals()->getCollection();
$words = $this->words;

View File

@@ -18,6 +18,7 @@ use Crypt;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
/**
* Class Steam
@@ -45,14 +46,27 @@ class Steam
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$balance = strval(
$account->transactions()->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
$currencyId = intval($account->getMeta('currency_id'));
// first part: get all balances in own currency:
$nativeBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount')
);
$virtual = is_null($account->virtual_balance) ? '0' : strval($account->virtual_balance);
$balance = bcadd($balance, $virtual);
// get all balances in foreign currency:
$foreignBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);
$virtual = is_null($account->virtual_balance) ? '0' : strval($account->virtual_balance);
$balance = bcadd($balance, $virtual);
$cache->store($balance);
return $balance;
@@ -76,13 +90,26 @@ class Steam
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$currencyId = intval($account->getMeta('currency_id'));
$balance = strval(
$account->transactions()->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
$nativeBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount')
);
// get all balances in foreign currency:
$foreignBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance);
$cache->store($balance);
return $balance;
@@ -111,27 +138,55 @@ class Steam
return $cache->get(); // @codeCoverageIgnore
}
$balances = [];
$start->subDay();
$end->addDay();
$startBalance = $this->balance($account, $start);
$balances[$start->format('Y-m-d')] = $startBalance;
$balances = [];
$formatted = $start->format('Y-m-d');
$startBalance = $this->balance($account, $start);
$balances[$formatted] = $startBalance;
$currencyId = intval($account->getMeta('currency_id'));
$start->addDay();
// query!
$set = $account->transactions()
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->groupBy('transaction_journals.date')
->orderBy('transaction_journals.date', 'ASC')
->whereNull('transaction_journals.deleted_at')
->get(['transaction_journals.date', DB::raw('SUM(transactions.amount) AS modified')]);
$set = $account->transactions()
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->groupBy('transaction_journals.date')
->groupBy('transactions.transaction_currency_id')
->groupBy('transactions.foreign_currency_id')
->orderBy('transaction_journals.date', 'ASC')
->whereNull('transaction_journals.deleted_at')
->get(
[
'transaction_journals.date',
'transactions.transaction_currency_id',
DB::raw('SUM(transactions.amount) AS modified'),
'transactions.foreign_currency_id',
DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
]
);
$currentBalance = $startBalance;
/** @var Transaction $entry */
foreach ($set as $entry) {
$modified = is_null($entry->modified) ? '0' : strval($entry->modified);
$currentBalance = bcadd($currentBalance, $modified);
$balances[$entry->date] = $currentBalance;
// normal amount and foreign amount
$modified = is_null($entry->modified) ? '0' : strval($entry->modified);
$foreignModified = is_null($entry->modified_foreign) ? '0' : strval($entry->modified_foreign);
$amount = '0';
if ($currencyId === $entry->transaction_currency_id) {
// use normal amount:
$amount = $modified;
}
if ($currencyId === $entry->foreign_currency_id) {
// use normal amount:
$amount = $foreignModified;
}
$currentBalance = bcadd($currentBalance, $amount);
$carbon = new Carbon($entry->date);
$date = $carbon->format('Y-m-d');
$balances[$date] = $currentBalance;
}
$cache->store($balances);
@@ -144,14 +199,14 @@ class Steam
/**
* This method always ignores the virtual balance.
*
* @param array $ids
* @param \Carbon\Carbon $date
* @param \Illuminate\Support\Collection $accounts
* @param \Carbon\Carbon $date
*
* @return array
*/
public function balancesById(array $ids, Carbon $date): array
public function balancesByAccounts(Collection $accounts, Carbon $date): array
{
$ids = $accounts->pluck('id')->toArray();
// cache this property.
$cache = new CacheProperties;
$cache->addProperty($ids);
@@ -161,21 +216,13 @@ class Steam
return $cache->get(); // @codeCoverageIgnore
}
$balances = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->groupBy('transactions.account_id')
->whereIn('transactions.account_id', $ids)
->whereNull('transaction_journals.deleted_at')
->get(['transactions.account_id', DB::raw('sum(transactions.amount) AS aggregate')]);
// need to do this per account.
$result = [];
foreach ($balances as $entry) {
$accountId = intval($entry->account_id);
$balance = $entry->aggregate;
$result[$accountId] = $balance;
/** @var Account $account */
foreach ($accounts as $account) {
$result[$account->id] = $this->balance($account, $date);
}
$cache->store($result);
return $result;

View File

@@ -1,63 +0,0 @@
<?php
/**
* Account.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use FireflyIII\Models\Account as AccountModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Amount as AmountFacade;
use Twig_Extension;
use Twig_SimpleFunction;
/**
* Class Account
*
* @package FireflyIII\Support\Twig
*/
class Account extends Twig_Extension
{
/**
* {@inheritDoc}
*/
public function getFunctions(): array
{
return [
$this->formatAmountByAccount(),
];
}
/**
* Will return "active" when a part of the route matches the argument.
* ie. "accounts" will match "accounts.index".
*
* @return Twig_SimpleFunction
*/
protected function formatAmountByAccount(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatAmountByAccount', function (AccountModel $account, string $amount, bool $coloured = true): string {
$currencyId = intval($account->getMeta('currency_id'));
if ($currencyId === 0) {
// Format using default currency:
return AmountFacade::format($amount, $coloured);
}
$currency = TransactionCurrency::find($currencyId);
return AmountFacade::formatAnything($currency, $amount, $coloured);
}, ['is_safe' => ['html']]
);
}
}

View File

@@ -0,0 +1,268 @@
<?php
/**
* AmountFormat.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use FireflyIII\Models\Account as AccountModel;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
/**
* Contains all amount formatting routines.
*
* @package FireflyIII\Support\Twig
*/
class AmountFormat extends Twig_Extension
{
/**
* {@inheritDoc}
*/
public function getFilters(): array
{
return [
$this->formatAmount(),
$this->formatAmountPlain(),
];
}
/**
* {@inheritDoc}
*/
public function getFunctions(): array
{
return [
$this->formatAmountByAccount(),
$this->transactionAmount(),
$this->journalAmount(),
$this->formatDestinationAfter(),
$this->formatDestinationBefore(),
$this->formatSourceAfter(),
$this->formatSourceBefore(),
$this->formatAmountByCurrency(),
];
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName(): string
{
return 'FireflyIII\Support\Twig\AmountFormat';
}
/**
*
* @return Twig_SimpleFilter
*/
protected function formatAmount(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
'formatAmount', function (string $string): string {
$currency = app('amount')->getDefaultCurrency();
return app('amount')->formatAnything($currency, $string, true);
}, ['is_safe' => ['html']]
);
}
/**
* Will format the amount by the currency related to the given account.
*
* @return Twig_SimpleFunction
*/
protected function formatAmountByAccount(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatAmountByAccount', function (AccountModel $account, string $amount, bool $coloured = true): string {
$currencyId = intval($account->getMeta('currency_id'));
if ($currencyId !== 0) {
$currency = TransactionCurrency::find($currencyId);
return app('amount')->formatAnything($currency, $amount, $coloured);
}
$currency = app('amount')->getDefaultCurrency();
return app('amount')->formatAnything($currency, $amount, $coloured);
}, ['is_safe' => ['html']]
);
}
/**
* Will format the amount by the currency related to the given account.
*
* @return Twig_SimpleFunction
*/
protected function formatAmountByCurrency(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatAmountByCurrency', function (TransactionCurrency $currency, string $amount, bool $coloured = true): string {
return app('amount')->formatAnything($currency, $amount, $coloured);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFilter
*/
protected function formatAmountPlain(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
'formatAmountPlain', function (string $string): string {
$currency = app('amount')->getDefaultCurrency();
return app('amount')->formatAnything($currency, $string, false);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function formatDestinationAfter(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatDestinationAfter', function (array $transaction): string {
// build fake currency for main amount.
$format = new TransactionCurrency;
$format->decimal_places = $transaction['transaction_currency_dp'];
$format->symbol = $transaction['transaction_currency_symbol'];
$string = app('amount')->formatAnything($format, $transaction['destination_account_after'], true);
// also append foreign amount for clarity:
if (!is_null($transaction['foreign_destination_amount'])) {
// build fake currency for foreign amount
$format = new TransactionCurrency;
$format->decimal_places = $transaction['foreign_currency_dp'];
$format->symbol = $transaction['foreign_currency_symbol'];
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_destination_amount'], true) . ')';
}
return $string;
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function formatDestinationBefore(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatDestinationBefore', function (array $transaction): string {
// build fake currency for main amount.
$format = new TransactionCurrency;
$format->decimal_places = $transaction['transaction_currency_dp'];
$format->symbol = $transaction['transaction_currency_symbol'];
return app('amount')->formatAnything($format, $transaction['destination_account_before'], true);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function formatSourceAfter(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatSourceAfter', function (array $transaction): string {
// build fake currency for main amount.
$format = new TransactionCurrency;
$format->decimal_places = $transaction['transaction_currency_dp'];
$format->symbol = $transaction['transaction_currency_symbol'];
$string = app('amount')->formatAnything($format, $transaction['source_account_after'], true);
// also append foreign amount for clarity:
if (!is_null($transaction['foreign_source_amount'])) {
// build fake currency for foreign amount
$format = new TransactionCurrency;
$format->decimal_places = $transaction['foreign_currency_dp'];
$format->symbol = $transaction['foreign_currency_symbol'];
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_source_amount'], true) . ')';
}
return $string;
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function formatSourceBefore(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatSourceBefore', function (array $transaction): string {
// build fake currency for main amount.
$format = new TransactionCurrency;
$format->decimal_places = $transaction['transaction_currency_dp'];
$format->symbol = $transaction['transaction_currency_symbol'];
return app('amount')->formatAnything($format, $transaction['source_account_before'], true);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function journalAmount(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'journalAmount', function (TransactionJournal $journal): string {
return app('amount')->journalAmount($journal, true);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
protected function transactionAmount(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'transactionAmount', function (TransactionModel $transaction): string {
return app('amount')->transactionAmount($transaction, true);
}, ['is_safe' => ['html']]
);
}
}

View File

@@ -38,9 +38,6 @@ class General extends Twig_Extension
public function getFilters(): array
{
return [
$this->formatAmount(),
$this->formatAmountPlain(),
$this->formatJournal(),
$this->balance(),
$this->formatFilesize(),
$this->mimeIcon(),
@@ -173,33 +170,6 @@ class General extends Twig_Extension
);
}
/**
*
* @return Twig_SimpleFilter
*/
protected function formatAmount(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
'formatAmount', function (string $string): string {
return app('amount')->format($string);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFilter
*/
protected function formatAmountPlain(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
'formatAmountPlain', function (string $string): string {
return app('amount')->format($string, false);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFilter
*/
@@ -223,17 +193,6 @@ class General extends Twig_Extension
);
}
/**
* @return Twig_SimpleFilter
*/
protected function formatJournal(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
'formatJournal', function (TransactionJournal $journal): string {
return app('amount')->formatJournal($journal);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction

View File

@@ -13,10 +13,8 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use Amount;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use Steam;
use Twig_Extension;
@@ -30,49 +28,6 @@ use Twig_SimpleFunction;
*/
class Transaction extends Twig_Extension
{
/**
* @return Twig_SimpleFunction
*/
public function formatAnything(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatAnything', function (TransactionCurrency $currency, string $amount): string {
return Amount::formatAnything($currency, $amount, true);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
public function formatAnythingPlain(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatAnythingPlain', function (TransactionCurrency $currency, string $amount): string {
return Amount::formatAnything($currency, $amount, false);
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/
public function formatByCode(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatByCode', function (string $currencyCode, string $amount): string {
return Amount::formatByCode($currencyCode, $amount, true);
}, ['is_safe' => ['html']]
);
}
/**
* @return array
*/
@@ -91,17 +46,13 @@ class Transaction extends Twig_Extension
public function getFunctions(): array
{
$functions = [
$this->formatAnything(),
$this->formatAnythingPlain(),
$this->transactionSourceAccount(),
$this->transactionDestinationAccount(),
$this->optionalJournalAmount(),
$this->transactionBudgets(),
$this->transactionIdBudgets(),
$this->transactionCategories(),
$this->transactionIdCategories(),
$this->splitJournalIndicator(),
$this->formatByCode(),
];
return $functions;
@@ -117,33 +68,6 @@ class Transaction extends Twig_Extension
return 'transaction';
}
/**
* @return Twig_SimpleFunction
*/
public function optionalJournalAmount(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'optionalJournalAmount', function (int $journalId, string $transactionAmount, string $code, string $type): string {
// get amount of journal:
$amount = strval(TransactionModel::where('transaction_journal_id', $journalId)->whereNull('deleted_at')->where('amount', '<', 0)->sum('amount'));
// display deposit and transfer positive
if ($type === TransactionType::DEPOSIT || $type === TransactionType::TRANSFER) {
$amount = bcmul($amount, '-1');
}
// not equal to transaction amount?
if (bccomp($amount, $transactionAmount) !== 0 && bccomp($amount, bcmul($transactionAmount, '-1')) !== 0) {
//$currency =
return sprintf(' (%s)', Amount::formatByCode($code, $amount, true));
}
return '';
}, ['is_safe' => ['html']]
);
}
/**
* @return Twig_SimpleFunction
*/

View File

@@ -214,9 +214,9 @@ class User extends Authenticatable
*/
public function sendPasswordResetNotification($token)
{
$ip = Request::ip();
$ipAddress = Request::ip();
event(new RequestedNewPassword($this, $token, $ip));
event(new RequestedNewPassword($this, $token, $ipAddress));
}
/**

314
composer.lock generated
View File

@@ -665,16 +665,16 @@
},
{
"name": "laravel/framework",
"version": "v5.4.19",
"version": "v5.4.24",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "02444b7450350db17a7607c8a52f7268ebdb0dad"
"reference": "ec8548db26c1b147570f661128649e98f3ac0f29"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/02444b7450350db17a7607c8a52f7268ebdb0dad",
"reference": "02444b7450350db17a7607c8a52f7268ebdb0dad",
"url": "https://api.github.com/repos/laravel/framework/zipball/ec8548db26c1b147570f661128649e98f3ac0f29",
"reference": "ec8548db26c1b147570f661128649e98f3ac0f29",
"shasum": ""
},
"require": {
@@ -790,20 +790,20 @@
"framework",
"laravel"
],
"time": "2017-04-16T13:33:34+00:00"
"time": "2017-05-30T12:44:32+00:00"
},
{
"name": "laravelcollective/html",
"version": "v5.4.1",
"version": "v5.4.8",
"source": {
"type": "git",
"url": "https://github.com/LaravelCollective/html.git",
"reference": "7570f25d58a00fd6909c0563808590f9cdb14d47"
"reference": "9b8f51e7a2368911c896f5d42757886bae0717b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/7570f25d58a00fd6909c0563808590f9cdb14d47",
"reference": "7570f25d58a00fd6909c0563808590f9cdb14d47",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/9b8f51e7a2368911c896f5d42757886bae0717b5",
"reference": "9b8f51e7a2368911c896f5d42757886bae0717b5",
"shasum": ""
},
"require": {
@@ -844,20 +844,20 @@
],
"description": "HTML and Form Builders for the Laravel Framework",
"homepage": "http://laravelcollective.com",
"time": "2017-01-26T19:27:05+00:00"
"time": "2017-05-22T06:35:07+00:00"
},
{
"name": "league/commonmark",
"version": "0.15.3",
"version": "0.15.4",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "c8b43ee5821362216f8e9ac684f0f59de164edcc"
"reference": "c4c8e6bf99e62d9568875d9fc3ef473fe3e18e0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c8b43ee5821362216f8e9ac684f0f59de164edcc",
"reference": "c8b43ee5821362216f8e9ac684f0f59de164edcc",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c4c8e6bf99e62d9568875d9fc3ef473fe3e18e0c",
"reference": "c4c8e6bf99e62d9568875d9fc3ef473fe3e18e0c",
"shasum": ""
},
"require": {
@@ -913,7 +913,7 @@
"markdown",
"parser"
],
"time": "2016-12-19T00:11:43+00:00"
"time": "2017-05-09T12:47:53+00:00"
},
{
"name": "league/csv",
@@ -974,16 +974,16 @@
},
{
"name": "league/flysystem",
"version": "1.0.38",
"version": "1.0.40",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "4ba6e13f5116204b21c3afdf400ecf2b9eb1c482"
"reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4ba6e13f5116204b21c3afdf400ecf2b9eb1c482",
"reference": "4ba6e13f5116204b21c3afdf400ecf2b9eb1c482",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/3828f0b24e2c1918bb362d57a53205d6dc8fde61",
"reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61",
"shasum": ""
},
"require": {
@@ -1053,7 +1053,7 @@
"sftp",
"storage"
],
"time": "2017-04-22T18:59:19+00:00"
"time": "2017-04-28T10:15:08+00:00"
},
{
"name": "monolog/monolog",
@@ -1583,16 +1583,16 @@
},
{
"name": "swiftmailer/swiftmailer",
"version": "v5.4.7",
"version": "v5.4.8",
"source": {
"type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4"
"reference": "9a06dc570a0367850280eefd3f1dc2da45aef517"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4",
"reference": "56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/9a06dc570a0367850280eefd3f1dc2da45aef517",
"reference": "9a06dc570a0367850280eefd3f1dc2da45aef517",
"shasum": ""
},
"require": {
@@ -1633,20 +1633,20 @@
"mail",
"mailer"
],
"time": "2017-04-20T17:32:18+00:00"
"time": "2017-05-01T15:54:03+00:00"
},
{
"name": "symfony/console",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "c30243cc51f726812be3551316b109a2f5deaf8d"
"reference": "70d2a29b2911cbdc91a7e268046c395278238b2e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/c30243cc51f726812be3551316b109a2f5deaf8d",
"reference": "c30243cc51f726812be3551316b109a2f5deaf8d",
"url": "https://api.github.com/repos/symfony/console/zipball/70d2a29b2911cbdc91a7e268046c395278238b2e",
"reference": "70d2a29b2911cbdc91a7e268046c395278238b2e",
"shasum": ""
},
"require": {
@@ -1654,10 +1654,16 @@
"symfony/debug": "~2.8|~3.0",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/dependency-injection": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.3",
"symfony/dependency-injection": "~3.3",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/filesystem": "~2.8|~3.0",
"symfony/http-kernel": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0"
},
"suggest": {
@@ -1669,7 +1675,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -1696,7 +1702,7 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2017-04-04T14:33:42+00:00"
"time": "2017-06-02T19:24:58+00:00"
},
{
"name": "symfony/css-selector",
@@ -1753,16 +1759,16 @@
},
{
"name": "symfony/debug",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "56f613406446a4a0a031475cfd0a01751de22659"
"reference": "e9c50482841ef696e8fa1470d950a79c8921f45d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/56f613406446a4a0a031475cfd0a01751de22659",
"reference": "56f613406446a4a0a031475cfd0a01751de22659",
"url": "https://api.github.com/repos/symfony/debug/zipball/e9c50482841ef696e8fa1470d950a79c8921f45d",
"reference": "e9c50482841ef696e8fa1470d950a79c8921f45d",
"shasum": ""
},
"require": {
@@ -1773,13 +1779,12 @@
"symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
},
"require-dev": {
"symfony/class-loader": "~2.8|~3.0",
"symfony/http-kernel": "~2.8|~3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -1806,20 +1811,20 @@
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2017-03-28T21:38:24+00:00"
"time": "2017-06-01T21:01:25+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.8.19",
"version": "v2.8.21",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "88b65f0ac25355090e524aba4ceb066025df8bd2"
"reference": "7fc8e2b4118ff316550596357325dfd92a51f531"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/88b65f0ac25355090e524aba4ceb066025df8bd2",
"reference": "88b65f0ac25355090e524aba4ceb066025df8bd2",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7fc8e2b4118ff316550596357325dfd92a51f531",
"reference": "7fc8e2b4118ff316550596357325dfd92a51f531",
"shasum": ""
},
"require": {
@@ -1866,20 +1871,20 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-04-03T20:37:06+00:00"
"time": "2017-04-26T16:56:54+00:00"
},
{
"name": "symfony/finder",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "b20900ce5ea164cd9314af52725b0bb5a758217a"
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/b20900ce5ea164cd9314af52725b0bb5a758217a",
"reference": "b20900ce5ea164cd9314af52725b0bb5a758217a",
"url": "https://api.github.com/repos/symfony/finder/zipball/baea7f66d30854ad32988c11a09d7ffd485810c4",
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4",
"shasum": ""
},
"require": {
@@ -1888,7 +1893,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -1915,20 +1920,20 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2017-03-20T09:32:19+00:00"
"time": "2017-06-01T21:01:25+00:00"
},
{
"name": "symfony/http-foundation",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-foundation.git",
"reference": "cb0b6418f588952c9290b3df4ca650f1b7ab570a"
"reference": "80eb5a1f968448b77da9e8b2c0827f6e8d767846"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/cb0b6418f588952c9290b3df4ca650f1b7ab570a",
"reference": "cb0b6418f588952c9290b3df4ca650f1b7ab570a",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/80eb5a1f968448b77da9e8b2c0827f6e8d767846",
"reference": "80eb5a1f968448b77da9e8b2c0827f6e8d767846",
"shasum": ""
},
"require": {
@@ -1941,7 +1946,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -1968,20 +1973,20 @@
],
"description": "Symfony HttpFoundation Component",
"homepage": "https://symfony.com",
"time": "2017-04-04T15:30:56+00:00"
"time": "2017-06-05T13:06:51+00:00"
},
{
"name": "symfony/http-kernel",
"version": "v3.2.7",
"version": "v3.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-kernel.git",
"reference": "8285ab5faf1306b1a5ebcf287fe91c231a6de88e"
"reference": "4ad34a0d20a5848c0fcbf6ff6a2ff1cd9cf4b9ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/8285ab5faf1306b1a5ebcf287fe91c231a6de88e",
"reference": "8285ab5faf1306b1a5ebcf287fe91c231a6de88e",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/4ad34a0d20a5848c0fcbf6ff6a2ff1cd9cf4b9ed",
"reference": "4ad34a0d20a5848c0fcbf6ff6a2ff1cd9cf4b9ed",
"shasum": ""
},
"require": {
@@ -1989,18 +1994,21 @@
"psr/log": "~1.0",
"symfony/debug": "~2.8|~3.0",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/http-foundation": "~2.8.13|~3.1.6|~3.2"
"symfony/http-foundation": "~3.3"
},
"conflict": {
"symfony/config": "<2.8"
"symfony/config": "<2.8",
"symfony/dependency-injection": "<3.3",
"symfony/var-dumper": "<3.3"
},
"require-dev": {
"psr/cache": "~1.0",
"symfony/browser-kit": "~2.8|~3.0",
"symfony/class-loader": "~2.8|~3.0",
"symfony/config": "~2.8|~3.0",
"symfony/console": "~2.8|~3.0",
"symfony/css-selector": "~2.8|~3.0",
"symfony/dependency-injection": "~2.8|~3.0",
"symfony/dependency-injection": "~3.3",
"symfony/dom-crawler": "~2.8|~3.0",
"symfony/expression-language": "~2.8|~3.0",
"symfony/finder": "~2.8|~3.0",
@@ -2009,7 +2017,7 @@
"symfony/stopwatch": "~2.8|~3.0",
"symfony/templating": "~2.8|~3.0",
"symfony/translation": "~2.8|~3.0",
"symfony/var-dumper": "~3.2"
"symfony/var-dumper": "~3.3"
},
"suggest": {
"symfony/browser-kit": "",
@@ -2023,7 +2031,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -2050,7 +2058,7 @@
],
"description": "Symfony HttpKernel Component",
"homepage": "https://symfony.com",
"time": "2017-04-05T12:52:03+00:00"
"time": "2017-05-29T21:02:12+00:00"
},
{
"name": "symfony/polyfill-mbstring",
@@ -2221,16 +2229,16 @@
},
{
"name": "symfony/process",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "57fdaa55827ae14d617550ebe71a820f0a5e2282"
"reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/57fdaa55827ae14d617550ebe71a820f0a5e2282",
"reference": "57fdaa55827ae14d617550ebe71a820f0a5e2282",
"url": "https://api.github.com/repos/symfony/process/zipball/8e30690c67aafb6c7992d6d8eb0d707807dd3eaf",
"reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf",
"shasum": ""
},
"require": {
@@ -2239,7 +2247,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -2266,36 +2274,39 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2017-03-27T18:07:02+00:00"
"time": "2017-05-22T12:32:03+00:00"
},
{
"name": "symfony/routing",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/routing.git",
"reference": "d6605f9a5767bc5bc4895e1c762ba93964608aee"
"reference": "39804eeafea5cca851946e1eed122eb94459fdb4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/routing/zipball/d6605f9a5767bc5bc4895e1c762ba93964608aee",
"reference": "d6605f9a5767bc5bc4895e1c762ba93964608aee",
"url": "https://api.github.com/repos/symfony/routing/zipball/39804eeafea5cca851946e1eed122eb94459fdb4",
"reference": "39804eeafea5cca851946e1eed122eb94459fdb4",
"shasum": ""
},
"require": {
"php": ">=5.5.9"
},
"conflict": {
"symfony/config": "<2.8"
"symfony/config": "<2.8",
"symfony/dependency-injection": "<3.3",
"symfony/yaml": "<3.3"
},
"require-dev": {
"doctrine/annotations": "~1.0",
"doctrine/common": "~2.2",
"psr/log": "~1.0",
"symfony/config": "~2.8|~3.0",
"symfony/dependency-injection": "~3.3",
"symfony/expression-language": "~2.8|~3.0",
"symfony/http-foundation": "~2.8|~3.0",
"symfony/yaml": "~2.8|~3.0"
"symfony/yaml": "~3.3"
},
"suggest": {
"doctrine/annotations": "For using the annotation loader",
@@ -2308,7 +2319,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -2341,20 +2352,20 @@
"uri",
"url"
],
"time": "2017-03-02T15:58:09+00:00"
"time": "2017-06-02T09:51:43+00:00"
},
{
"name": "symfony/translation",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13"
"reference": "dc3b2a0c6cfff60327ba1c043a82092735397543"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/c740eee70783d2af4d3d6b70d5146f209e6b4d13",
"reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13",
"url": "https://api.github.com/repos/symfony/translation/zipball/dc3b2a0c6cfff60327ba1c043a82092735397543",
"reference": "dc3b2a0c6cfff60327ba1c043a82092735397543",
"shasum": ""
},
"require": {
@@ -2362,13 +2373,14 @@
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/config": "<2.8"
"symfony/config": "<2.8",
"symfony/yaml": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.8|~3.0",
"symfony/intl": "^2.8.18|^3.2.5",
"symfony/yaml": "~2.8|~3.0"
"symfony/yaml": "~3.3"
},
"suggest": {
"psr/log": "To use logging capability in translator",
@@ -2378,7 +2390,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -2405,20 +2417,20 @@
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
"time": "2017-03-21T21:44:32+00:00"
"time": "2017-05-22T07:42:36+00:00"
},
{
"name": "symfony/var-dumper",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-dumper.git",
"reference": "81dce20f69a8b40427e1f4e6462178df87cafc03"
"reference": "347c4247a3e40018810b476fcd5dec36d46d08dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/81dce20f69a8b40427e1f4e6462178df87cafc03",
"reference": "81dce20f69a8b40427e1f4e6462178df87cafc03",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/347c4247a3e40018810b476fcd5dec36d46d08dc",
"reference": "347c4247a3e40018810b476fcd5dec36d46d08dc",
"shasum": ""
},
"require": {
@@ -2429,15 +2441,17 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
},
"require-dev": {
"twig/twig": "~1.20|~2.0"
"ext-iconv": "*",
"twig/twig": "~1.34|~2.4"
},
"suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
"ext-symfony_debug": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -2471,7 +2485,7 @@
"debug",
"dump"
],
"time": "2017-03-12T16:07:05+00:00"
"time": "2017-06-02T09:10:29+00:00"
},
{
"name": "tijsverkoyen/css-to-inline-styles",
@@ -2685,20 +2699,20 @@
"packages-dev": [
{
"name": "barryvdh/laravel-debugbar",
"version": "v2.3.2",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
"reference": "24e4f0261e352d3fd86d0447791b56ae49398674"
"reference": "de15d00a74696db62e1b4782474c27ed0c4fc763"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/24e4f0261e352d3fd86d0447791b56ae49398674",
"reference": "24e4f0261e352d3fd86d0447791b56ae49398674",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/de15d00a74696db62e1b4782474c27ed0c4fc763",
"reference": "de15d00a74696db62e1b4782474c27ed0c4fc763",
"shasum": ""
},
"require": {
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
"maximebf/debugbar": "~1.13.0",
"php": ">=5.5.9",
"symfony/finder": "~2.7|~3.0"
@@ -2706,7 +2720,15 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "2.4-dev"
},
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facade"
}
}
},
"autoload": {
@@ -2735,7 +2757,7 @@
"profiler",
"webprofiler"
],
"time": "2017-01-19T08:19:49+00:00"
"time": "2017-06-01T17:46:08+00:00"
},
{
"name": "barryvdh/laravel-ide-helper",
@@ -3723,16 +3745,16 @@
},
{
"name": "phpunit/phpunit",
"version": "5.7.19",
"version": "5.7.20",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "69c4f49ff376af2692bad9cebd883d17ebaa98a1"
"reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/69c4f49ff376af2692bad9cebd883d17ebaa98a1",
"reference": "69c4f49ff376af2692bad9cebd883d17ebaa98a1",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3cb94a5f8c07a03c8b7527ed7468a2926203f58b",
"reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b",
"shasum": ""
},
"require": {
@@ -3750,7 +3772,7 @@
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "^3.2",
"sebastian/comparator": "^1.2.4",
"sebastian/diff": "~1.2",
"sebastian/diff": "^1.4.3",
"sebastian/environment": "^1.3.4 || ^2.0",
"sebastian/exporter": "~2.0",
"sebastian/global-state": "^1.1",
@@ -3801,7 +3823,7 @@
"testing",
"xunit"
],
"time": "2017-04-03T02:22:27+00:00"
"time": "2017-05-22T07:42:55+00:00"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -4031,23 +4053,23 @@
},
{
"name": "sebastian/diff",
"version": "1.4.1",
"version": "1.4.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "13edfd8706462032c2f52b4b862974dd46b71c9e"
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e",
"reference": "13edfd8706462032c2f52b4b862974dd46b71c9e",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
},
"type": "library",
"extra": {
@@ -4079,7 +4101,7 @@
"keywords": [
"diff"
],
"time": "2015-12-08T07:14:41+00:00"
"time": "2017-05-22T07:24:03+00:00"
},
{
"name": "sebastian/environment",
@@ -4435,16 +4457,16 @@
},
{
"name": "symfony/class-loader",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/class-loader.git",
"reference": "c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9"
"reference": "386a294d621576302e7cc36965d6ed53b8c73c4f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/class-loader/zipball/c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9",
"reference": "c29a5bc6ca14cfff1f5e3d7781ed74b6e898d2b9",
"url": "https://api.github.com/repos/symfony/class-loader/zipball/386a294d621576302e7cc36965d6ed53b8c73c4f",
"reference": "386a294d621576302e7cc36965d6ed53b8c73c4f",
"shasum": ""
},
"require": {
@@ -4460,7 +4482,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4487,27 +4509,31 @@
],
"description": "Symfony ClassLoader Component",
"homepage": "https://symfony.com",
"time": "2017-02-18T17:28:00+00:00"
"time": "2017-06-02T09:51:43+00:00"
},
{
"name": "symfony/config",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "8444bde28e3c2a33e571e6f180c2d78bfdc4480d"
"reference": "35716d4904e0506a7a5a9bcf23f854aeb5719bca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/8444bde28e3c2a33e571e6f180c2d78bfdc4480d",
"reference": "8444bde28e3c2a33e571e6f180c2d78bfdc4480d",
"url": "https://api.github.com/repos/symfony/config/zipball/35716d4904e0506a7a5a9bcf23f854aeb5719bca",
"reference": "35716d4904e0506a7a5a9bcf23f854aeb5719bca",
"shasum": ""
},
"require": {
"php": ">=5.5.9",
"symfony/filesystem": "~2.8|~3.0"
},
"conflict": {
"symfony/dependency-injection": "<3.3"
},
"require-dev": {
"symfony/dependency-injection": "~3.3",
"symfony/yaml": "~3.0"
},
"suggest": {
@@ -4516,7 +4542,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4543,7 +4569,7 @@
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
"time": "2017-04-04T15:30:56+00:00"
"time": "2017-06-02T18:07:20+00:00"
},
{
"name": "symfony/dom-crawler",
@@ -4603,16 +4629,16 @@
},
{
"name": "symfony/filesystem",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "64421e6479c4a8e60d790fb666bd520992861b66"
"reference": "c709670bf64721202ddbe4162846f250735842c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/64421e6479c4a8e60d790fb666bd520992861b66",
"reference": "64421e6479c4a8e60d790fb666bd520992861b66",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/c709670bf64721202ddbe4162846f250735842c0",
"reference": "c709670bf64721202ddbe4162846f250735842c0",
"shasum": ""
},
"require": {
@@ -4621,7 +4647,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4648,20 +4674,20 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2017-03-26T15:47:15+00:00"
"time": "2017-05-28T14:08:56+00:00"
},
{
"name": "symfony/stopwatch",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "c5ee0f8650c84b4d36a5f76b3b504233feaabf75"
"reference": "602a15299dc01556013b07167d4f5d3a60e90d15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/c5ee0f8650c84b4d36a5f76b3b504233feaabf75",
"reference": "c5ee0f8650c84b4d36a5f76b3b504233feaabf75",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/602a15299dc01556013b07167d4f5d3a60e90d15",
"reference": "602a15299dc01556013b07167d4f5d3a60e90d15",
"shasum": ""
},
"require": {
@@ -4670,7 +4696,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4697,20 +4723,20 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2017-02-18T17:28:00+00:00"
"time": "2017-04-12T14:14:56+00:00"
},
{
"name": "symfony/yaml",
"version": "v3.2.7",
"version": "v3.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "62b4cdb99d52cb1ff253c465eb1532a80cebb621"
"reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/62b4cdb99d52cb1ff253c465eb1532a80cebb621",
"reference": "62b4cdb99d52cb1ff253c465eb1532a80cebb621",
"url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063",
"reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063",
"shasum": ""
},
"require": {
@@ -4725,7 +4751,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4752,7 +4778,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-03-20T09:45:15+00:00"
"time": "2017-06-02T22:05:06+00:00"
},
{
"name": "webmozart/assert",

View File

@@ -23,7 +23,7 @@ return [
'is_demo_site' => false,
],
'encryption' => (is_null(env('USE_ENCRYPTION')) || env('USE_ENCRYPTION') === true),
'version' => '4.4.1',
'version' => '4.5.0',
'maxUploadSize' => 5242880,
'allowedMimes' => ['image/png', 'image/jpeg', 'application/pdf'],
'list_length' => 10,
@@ -99,14 +99,11 @@ return [
'languages' => [
'de_DE' => ['name_locale' => 'Deutsch', 'name_english' => 'German', 'complete' => true],
'en_US' => ['name_locale' => 'English', 'name_english' => 'English', 'complete' => true],
'es_ES' => ['name_locale' => 'Español', 'name_english' => 'Spanish', 'complete' => false],
'fr_FR' => ['name_locale' => 'Français', 'name_english' => 'French', 'complete' => false],
'hr_HR' => ['name_locale' => 'hrvatski', 'name_english' => 'Croatian', 'complete' => false],
'nl_NL' => ['name_locale' => 'Nederlands', 'name_english' => 'Dutch', 'complete' => true],
'pl_PL' => ['name_locale' => 'Polski', 'name_english' => 'Polish ', 'complete' => false],
'pt_BR' => ['name_locale' => 'Português do Brasil', 'name_english' => 'Portuguese (Brazil)', 'complete' => true],
'ru-RU' => ['name_locale' => 'Russian', 'name_english' => 'Russian', 'complete' => false],
'zh-HK' => ['name_locale' => '繁體中文(香港)', 'name_english' => 'Chinese Traditional, Hong Kong', 'complete' => false],
'sl-SI' => ['name_locale' => 'Slovenščina', 'name_english' => 'Slovenian', 'complete' => false],
'zh-TW' => ['name_locale' => '正體中文', 'name_english' => 'Chinese Traditional', 'complete' => false],
],
'transactionTypesByWhat' => [
@@ -176,7 +173,7 @@ return [
'category_is' => 'FireflyIII\Rules\Triggers\CategoryIs',
'budget_is' => 'FireflyIII\Rules\Triggers\BudgetIs',
'tag_is' => 'FireflyIII\Rules\Triggers\TagIs',
'has_attachments' => 'FireflyIII\Rules\Triggers\HasAttachment',
'has_attachments' => 'FireflyIII\Rules\Triggers\HasAttachment',
],
'rule-actions' => [
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',

View File

@@ -85,10 +85,11 @@ $factory->define(
$factory->define(
FireflyIII\Models\TransactionJournal::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'id' => $faker->unique()->numberBetween(1000, 10000),
'user_id' => 1,
'transaction_type_id' => 1,
'bill_id' => null,
// TODO update this transaction currency reference.
'transaction_currency_id' => 1,
'description' => $faker->words(3, true),
'date' => '2017-01-01',
@@ -122,6 +123,18 @@ $factory->define(
}
);
$factory->define(
FireflyIII\Models\PiggyBankRepetition::class, function (Faker\Generator $faker) {
return [
'id' => $faker->unique()->numberBetween(100, 10000),
'piggy_bank_id' => $faker->numberBetween(1, 10),
'startdate' => '2017-01-01',
'targetdate' => '2020-01-01',
'currentamount' => 10,
];
}
);
$factory->define(
FireflyIII\Models\PiggyBank::class, function (Faker\Generator $faker) {
return [
@@ -194,8 +207,9 @@ $factory->define(
$factory->define(
FireflyIII\Models\Account::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'name' => $faker->words(3, true),
'id' => $faker->unique()->numberBetween(1000, 10000),
'name' => $faker->words(3, true),
'account_type_id' => 1,
];
}
);
@@ -203,25 +217,31 @@ $factory->define(
$factory->define(
FireflyIII\Models\Transaction::class, function (Faker\Generator $faker) {
return [
'transaction_amount' => strval($faker->randomFloat(2, -100, 100)),
'destination_amount' => strval($faker->randomFloat(2, -100, 100)),
'opposing_account_id' => $faker->numberBetween(1, 10),
'source_account_id' => $faker->numberBetween(1, 10),
'opposing_account_name' => $faker->words(3, true),
'description' => $faker->words(3, true),
'source_account_name' => $faker->words(3, true),
'destination_account_id' => $faker->numberBetween(1, 10),
'date' => new Carbon,
'destination_account_name' => $faker->words(3, true),
'amount' => strval($faker->randomFloat(2, -100, 100)),
'budget_id' => 0,
'category' => $faker->words(3, true),
'transaction_journal_id' => $faker->numberBetween(1, 10),
'journal_id' => $faker->numberBetween(1, 10),
'transaction_currency_code' => 'EUR',
'transaction_type_type' => 'Withdrawal',
'account_encrypted' => 0,
'account_name' => 'Some name',
'transaction_amount' => strval($faker->randomFloat(2, -100, 100)),
'destination_amount' => strval($faker->randomFloat(2, -100, 100)),
'opposing_account_id' => $faker->numberBetween(1, 10),
'source_account_id' => $faker->numberBetween(1, 10),
'opposing_account_name' => $faker->words(3, true),
'description' => $faker->words(3, true),
'source_account_name' => $faker->words(3, true),
'destination_account_id' => $faker->numberBetween(1, 10),
'date' => new Carbon,
'destination_account_name' => $faker->words(3, true),
'amount' => strval($faker->randomFloat(2, -100, 100)),
'budget_id' => 0,
'category' => $faker->words(3, true),
'transaction_journal_id' => $faker->numberBetween(1, 10),
'journal_id' => $faker->numberBetween(1, 10),
'transaction_currency_code' => 'EUR',
'transaction_type_type' => 'Withdrawal',
'account_encrypted' => 0,
'account_name' => 'Some name',
'transaction_currency_id' => 1,
'transaction_currency_symbol' => '€',
'foreign_destination_amount' => null,
'foreign_currency_id' => null,
'foreign_currency_code' => null,
'foreign_currency_symbol' => null,
];
}
);

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* Class ChangesForV450
*/
class ChangesForV450 extends Migration
{
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// add "foreign_amount" to transactions
Schema::table(
'transactions', function (Blueprint $table) {
$table->decimal('foreign_amount', 22, 12)->nullable()->after('amount');
}
);
// add foreign transaction currency id to transactions (is nullable):
Schema::table(
'transactions', function (Blueprint $table) {
$table->integer('foreign_currency_id', false, true)->default(null)->after('foreign_amount')->nullable();
$table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
}
);
}
}

View File

@@ -8,7 +8,7 @@
* See the LICENSE file for details.
*/
/** global: spent, budgeted, available, currencySymbol */
/** global: spent, budgeted, available, currencySymbol, budgetIndexURI */
function drawSpentBar() {
"use strict";
@@ -59,9 +59,26 @@ function updateBudgetedAmounts(e) {
"use strict";
var target = $(e.target);
var id = target.data('id');
var value = target.val();
var original = target.data('original');
var difference = value - original;
var spentCell = $('td[class="spent"][data-id="' + id + '"]');
var leftCell = $('td[class="left"][data-id="' + id + '"]');
var spentAmount = parseFloat(spentCell.data('spent'));
var newAmountLeft = spentAmount + parseFloat(value);
var amountLeftString = accounting.formatMoney(newAmountLeft);
if(newAmountLeft < 0) {
leftCell.html('<span class="text-danger">' + amountLeftString + '</span>');
}
if(newAmountLeft > 0) {
leftCell.html('<span class="text-success">' + amountLeftString + '</span>');
}
if(newAmountLeft === 0.0) {
leftCell.html('<span style="color:#999">' + amountLeftString + '</span>');
}
if (difference !== 0) {
// add difference to 'budgeted' var
budgeted = budgeted + difference;
@@ -99,6 +116,15 @@ $(function () {
*/
$('input[type="number"]').on('input', updateBudgetedAmounts);
//
$('.selectPeriod').change(function (e) {
var sel = $(e.target).val();
if (sel !== "x") {
var newURI = budgetIndexURI.replace("REPLACE", sel);
window.location.assign(newURI);
}
});
});
function updateIncome() {

View File

@@ -8,7 +8,7 @@
* See the LICENSE file for details.
*/
/** global: budgetChartUri,budgetLimitID */
/** global: budgetChartUri, expenseCategoryUri, expenseAssetUri, expenseExpenseUri, budgetLimitID */
$(function () {
"use strict";

View File

@@ -13,10 +13,7 @@
$(function () {
"use strict";
console.log('Getting charts');
columnChart(everything, 'category-everything');
console.log('Specific: ' + specific);
columnChart(specific, 'specific-period');
});

View File

@@ -75,7 +75,7 @@ function lineChart(URI, container) {
"use strict";
var colorData = true;
var options = defaultChartOptions;
var options = $.extend(true, {}, defaultChartOptions);
var chartType = 'line';
drawAChart(URI, container, chartType, options, colorData);
@@ -186,9 +186,8 @@ function doubleYNonStackedChart(URI, container) {
*/
function columnChart(URI, container) {
"use strict";
console.log('Going to draw column chart for ' + URI + ' in ' + container);
var colorData = true;
var options = defaultChartOptions;
var options = $.extend(true, {}, defaultChartOptions);
var chartType = 'bar';
drawAChart(URI, container, chartType, options, colorData);
@@ -224,7 +223,7 @@ function pieChart(URI, container) {
"use strict";
var colorData = false;
var options = defaultPieOptions;
var options = $.extend(true, {}, defaultPieOptions);
var chartType = 'pie';
drawAChart(URI, container, chartType, options, colorData);

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