Compare commits

..

119 Commits

Author SHA1 Message Date
James Cole
f090a9534f Merge branch 'release/4.8.0.3' 2019-08-23 14:25:17 +02:00
James Cole
ad289bc8cd Updated composer file. 2019-08-23 14:11:26 +02:00
James Cole
6f5b6e536d Updated version. 2019-08-23 14:11:18 +02:00
James Cole
c810bad97c New translations. 2019-08-23 14:11:10 +02:00
James Cole
a172c51495 Update changelog. 2019-08-23 13:54:51 +02:00
James Cole
633c776ebf Fix for #2438 2019-08-23 13:53:05 +02:00
James Cole
19bd295c71 Version update. 2019-08-23 13:52:36 +02:00
James Cole
3b39fb93e7 Fix tag overview. 2019-08-23 13:09:38 +02:00
James Cole
e3a338db0e Fix some view issues reported in #2436 2019-08-23 13:06:00 +02:00
James Cole
02df24bbc9 Possible fix for #2437 2019-08-23 09:41:31 +02:00
James Cole
4f6ba1e706 Re-order two columns #2437 2019-08-23 06:42:49 +02:00
James Cole
a1f57a0949 Fix #2467 2019-08-23 06:40:48 +02:00
James Cole
3d444eb833 Fix #2465 and #2463 2019-08-23 06:10:03 +02:00
James Cole
57b2a8d459 Add a note 2019-08-23 06:03:40 +02:00
James Cole
8a06507003 Fix #2459 2019-08-22 19:14:26 +02:00
James Cole
04d7137dff More code for #2457 2019-08-22 19:10:57 +02:00
James Cole
a2be71499f Add autocomplete #2457 2019-08-22 19:07:01 +02:00
James Cole
effba42ac2 Typo fix in budget helper and add debug info. #2451 2019-08-22 18:07:42 +02:00
James Cole
aea8603ca1 Typo fix in budget helper and add debug info. #2451 2019-08-22 18:07:33 +02:00
James Cole
fdb2abdf92 Some notes for future releases. #2443 2019-08-22 18:04:26 +02:00
James Cole
4b1d66bcf6 Merge pull request #2444 from GeoffreyFrogeye/availablebudgets
Fix wrong indexes in BudgetRepository
2019-08-22 18:03:34 +02:00
James Cole
248e393405 Merge pull request #2442 from GeoffreyFrogeye/currencycharlimit
Fix consistency in symbol character limit
2019-08-22 17:58:12 +02:00
James Cole
967ea6a181 Another fix for #2440 2019-08-22 17:56:48 +02:00
James Cole
a11f876c49 Fix return type #2440 2019-08-22 17:09:08 +02:00
James Cole
2a4051fe92 Fix for #2439 2019-08-22 17:06:43 +02:00
James Cole
10737d10a5 Merge pull request #2458 from jlauwers/patch-1
typo in readme
2019-08-22 04:43:42 +02:00
James Cole
6f75e0df3c Fix for #2451 2019-08-21 18:07:15 +02:00
James Cole
24a2238134 Fix #2456 2019-08-21 18:01:57 +02:00
James Cole
c7931f2b72 Fix for #2460 2019-08-21 17:27:59 +02:00
Jonathan
852584b6a8 typo in readme 2019-08-21 08:39:21 +02:00
James Cole
21a9e981a2 Fix for #2446 2019-08-21 05:15:47 +02:00
James Cole
ecc37b2ed3 Some undocumented changes for #2445 and #2447 2019-08-21 04:59:35 +02:00
James Cole
c0935e192d Fix #2448 2019-08-21 04:46:17 +02:00
James Cole
92a2404b61 Fix for invoice date #2449 2019-08-21 04:45:00 +02:00
James Cole
d9a2bd3e5f Update composer file with new command. 2019-08-21 04:37:27 +02:00
James Cole
22f110df8d Round the search time and make sure the count is shown #2453 2019-08-21 04:37:17 +02:00
James Cole
c76337926b Fix general docker file. 2019-08-21 04:18:37 +02:00
Geoffrey “Frogeye” Preud'homme
bf57dec07c Fix wrong indexes in BudgetRepository
Closes #2443
2019-08-18 17:58:42 +02:00
Geoffrey “Frogeye” Preud'homme
10d760a614 Fix consistency in symbol character limit
Closes #2441
2019-08-18 17:16:10 +02:00
James Cole
7b813065da Remove log debug things. 2019-08-18 13:01:47 +02:00
James Cole
c218a12af7 New command to make sure opening balance currency information is correct. 2019-08-18 13:01:38 +02:00
James Cole
98ae0efb16 SQL issue in piggy banks 2019-08-18 11:19:25 +02:00
James Cole
98cff18efa Fix email message for new transactions 2019-08-18 11:16:33 +02:00
James Cole
a7b2fbbf10 Budget box is back. 2019-08-18 09:07:08 +02:00
James Cole
ccc12171d6 Make sure all account meta data is deleted properly. 2019-08-18 09:00:15 +02:00
James Cole
525f69cf63 Inform user on currency disabling and where a currency may still be used. #2432 2019-08-18 08:46:36 +02:00
James Cole
4d2c5c1b58 Build both images using base image. 2019-08-18 08:10:30 +02:00
James Cole
450d07580e Push build from other base image. 2019-08-18 07:16:30 +02:00
James Cole
246100f2b7 Debug info for #2437 2019-08-17 21:02:02 +02:00
James Cole
9974e0229d Merge tag '4.8.0.2' into develop
4.8.0.2
2019-08-17 12:38:06 +02:00
James Cole
ad44f99dbf Merge branch 'release/4.8.0.2' 2019-08-17 12:38:04 +02:00
James Cole
12a64fefc8 Fix test. 2019-08-17 12:31:55 +02:00
James Cole
2ee8cbbae4 Update change logs and files for new version. 2019-08-17 12:27:15 +02:00
James Cole
34c19b145c Updated strings. 2019-08-17 12:24:16 +02:00
James Cole
c5e047ea02 Update copyright 2019-08-17 12:13:02 +02:00
James Cole
fc78c32fca Add newline to files 2019-08-17 12:09:03 +02:00
James Cole
b53cbbe469 Fix test coverage. 2019-08-17 12:08:09 +02:00
James Cole
1d4434698e Fix some tests. 2019-08-17 11:32:05 +02:00
James Cole
6d1bfd3956 Code cleanup 2019-08-17 10:54:16 +02:00
James Cole
1974d5f1e3 Code cleanup 2019-08-17 10:48:28 +02:00
James Cole
c235e42d6c Bill report URL must be set. 2019-08-17 10:48:09 +02:00
James Cole
342985d52a Code cleanup 2019-08-17 10:47:51 +02:00
James Cole
c2296c3ad5 Code cleanup 2019-08-17 10:47:29 +02:00
James Cole
23479790fe Code cleanup 2019-08-17 10:47:10 +02:00
James Cole
44823c6fec Code cleanup 2019-08-17 10:46:55 +02:00
James Cole
acfdf7dc90 Code cleanup 2019-08-17 10:46:40 +02:00
James Cole
6038a68ba9 Code cleanup 2019-08-17 10:46:32 +02:00
James Cole
79cf61b653 Fix #2434 2019-08-17 08:29:35 +02:00
James Cole
b97d3d3627 And fix sorting. 2019-08-17 08:04:41 +02:00
James Cole
7f887e294a Fix some charts. 2019-08-17 08:00:27 +02:00
James Cole
6f78735bc5 Fix some report issues. 2019-08-17 07:47:39 +02:00
James Cole
3e242aaca6 Clean up login controller. 2019-08-17 06:35:45 +02:00
James Cole
0796e422d4 Cleanup showLoginForm() 2019-08-17 06:24:49 +02:00
James Cole
fbd7c9ae07 Remove logout method (is the same) 2019-08-17 06:23:12 +02:00
James Cole
5cfb1b63dc Remove inspection warnings. 2019-08-17 06:22:42 +02:00
James Cole
f09d0e87e4 Remove inspection, add TODO's, make code a bit simpler. 2019-08-16 21:38:35 +02:00
James Cole
820358af73 Remove unused code. 2019-08-16 21:23:20 +02:00
James Cole
5a2998c80e Simplify bill overview. 2019-08-16 21:21:38 +02:00
James Cole
a32df0066e Fix form inconsistencies. 2019-08-16 19:08:20 +02:00
James Cole
02db333d46 Update for balance box in report. 2019-08-16 17:54:38 +02:00
James Cole
070f46c755 Budget box is multi-currency. 2019-08-16 08:27:08 +02:00
James Cole
b4a732bf77 Namespace errors, spotted by @davids3 #2392 2019-08-16 07:24:04 +02:00
James Cole
d8eb59736e Improve report boxes one by one #2428 2019-08-16 06:21:10 +02:00
James Cole
41c15b0cf8 Forgot auth in API 2019-08-16 06:20:16 +02:00
James Cole
fdf99400bc Some TODO's for the future. 2019-08-16 06:20:07 +02:00
James Cole
1ba45afeab Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2019-08-16 05:22:24 +02:00
James Cole
1819ece55d Merge pull request #2429 from GeoffreyFrogeye/emd_date
Fix typo in BudgetRepository (emd_date)
2019-08-16 05:15:50 +02:00
James Cole
78335210db Cleanup API middleware. 2019-08-16 05:08:56 +02:00
Geoffrey “Frogeye” Preud'homme
ca23bb6272 Fix typo in BudgetRepository (emd_date) 2019-08-15 23:23:06 +02:00
James Cole
eed84e18bb Fix #2423 2019-08-14 20:25:38 +02:00
James Cole
12641f96b1 Fix #2422 2019-08-14 20:23:11 +02:00
James Cole
1b97c4d58f Fix date for recurring transactions #2407 2019-08-14 20:06:16 +02:00
James Cole
ee3a2ef41c Fix report issues. 2019-08-14 19:51:46 +02:00
James Cole
084ceb0c4e Report fixes for #2418 2019-08-14 19:06:05 +02:00
James Cole
2497c4ee5c Fix #2426 2019-08-14 17:54:15 +02:00
James Cole
757a118f87 Change comment [skip ci] 2019-08-14 06:16:44 +02:00
James Cole
97908932e6 Fix #2393 2019-08-13 19:01:30 +02:00
James Cole
4c73ad8306 Fix #2402 2019-08-13 18:50:18 +02:00
James Cole
10a2078661 Fix #2404 2019-08-13 18:45:44 +02:00
James Cole
3fb09136cf Fix #2410 2019-08-13 18:38:15 +02:00
James Cole
843cced454 Fix #2405 2019-08-13 16:45:04 +02:00
James Cole
71a501868f Fix docker build back to original script. 2019-08-13 16:26:27 +02:00
James Cole
0a0ad8200a Fix #2414 2019-08-13 16:24:36 +02:00
James Cole
a9baf54b12 Fix #2416 2019-08-13 16:02:28 +02:00
James Cole
ed565136fc Fix #2415 2019-08-13 16:00:35 +02:00
James Cole
4719b87314 Try the ARM thing with my own version of the script. 2019-08-12 19:53:54 +02:00
James Cole
24b30af018 Install extension. 2019-08-12 19:31:42 +02:00
James Cole
e9f4695355 Fix ARM script. 2019-08-12 18:44:57 +02:00
James Cole
5b969fa014 Fix LDAP in ARM 2019-08-12 18:34:32 +02:00
James Cole
499e713683 Remove unused methods. 2019-08-12 18:24:33 +02:00
James Cole
5eadb51b78 Some refactoring. 2019-08-12 18:19:13 +02:00
James Cole
713a962005 Log errors instead of giving exceptions 2019-08-12 18:19:06 +02:00
James Cole
d96e77a3ec Use new methods from category repository 2019-08-12 18:18:51 +02:00
James Cole
bc68c367c8 Refactor earnedInperiod and spentInPeriod 2019-08-12 18:18:26 +02:00
James Cole
33e241d39a Remove initial balance accounts from auto-complete. 2019-08-12 18:17:43 +02:00
James Cole
e67812bf64 Method is no longer used. 2019-08-12 18:17:15 +02:00
James Cole
1090ce6597 Remove sum, make multi-currency 2019-08-12 18:16:28 +02:00
James Cole
e358f19548 Make method static 2019-08-12 18:16:12 +02:00
James Cole
eac406d62d Merge tag '4.8.0.1' into develop
4.8.0.1
2019-08-12 18:12:03 +02:00
753 changed files with 18098 additions and 17204 deletions

View File

@@ -70,7 +70,7 @@ php artisan firefly-iii:cc-liabilities
php artisan firefly-iii:back-to-journals
php artisan firefly-iii:rename-account-meta
# there are 13 verify commands
# there are 14 verify commands
php artisan firefly-iii:fix-piggies
php artisan firefly-iii:create-link-types
php artisan firefly-iii:create-access-tokens
@@ -80,10 +80,11 @@ php artisan firefly-iii:fix-transfer-budgets
php artisan firefly-iii:fix-uneven-amount
php artisan firefly-iii:delete-zero-amount
php artisan firefly-iii:delete-orphaned-transactions
php artisan firefly-iii:delete-empty-journals
php artisan firefly-iii:delete-empty-journals
php artisan firefly-iii:delete-empty-groups
php artisan firefly-iii:fix-account-types
php artisan firefly-iii:rename-meta-fields
php artisan firefly-iii:fix-ob-currencies
# report commands
php artisan firefly-iii:report-empty-objects

View File

@@ -40,6 +40,7 @@ APP_LOG_LEVEL=notice
# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III
# For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html
DB_CONNECTION=mysql
# If you use DOCKER COMPOSE, change this variable to "firefly_iii_db"
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead

View File

@@ -1,3 +1,48 @@
# 4.8.0.3 (API 0.10.1)
- #2438 Some balance issues when working with multiple currencies (a known issue)
- #2425 Transaction edit/create form is weird with the enter button
- #2424 auto complete tab doesn't work.
- #2441 Inconsistent character limit for currencies.
- #2443 500 error when submitting budgets
- #2446 Can't update current amount for piggy bank
- #2440 Errors when interacting with recurring transactions
- #2439 SQL error in API post new user
- Transaction report (after import, over email) is mostly empty
- Mass edit checkboxes doesn't work in a tag overview
- #2437 CPU issues when viewing accounts, probably run-away queries.
- #2432 Can't disable all currencies except one / can't disable EUR and switch to something else.
- Option to edit the budget is gone from edit transaction form.
- #2453 Search view things
- #2449 Can't add invoice date.
- #2448 Bad link in transaction overview
- #2447 Bad link in bill overview
- Improvements to various API end-points. Docs are updated.
# 4.8.0.2 (API 0.10.0)
- [Issue 2203](https://github.com/firefly-iii/firefly-iii/issues/2203) Reconciliation inconsistencies.
- [Issue 2392](https://github.com/firefly-iii/firefly-iii/issues/2392) Bad namespace leads to installation errors.
- [Issue 2393](https://github.com/firefly-iii/firefly-iii/issues/2393) Missing budget selector.
- [Issue 2402](https://github.com/firefly-iii/firefly-iii/issues/2402) bad amounts in default report
- [Issue 2405](https://github.com/firefly-iii/firefly-iii/issues/2405) Due date can't be edited.
- [Issue 2404](https://github.com/firefly-iii/firefly-iii/issues/2404) bad page indicator in the "no category" transaction overview.
- [Issue 2407](https://github.com/firefly-iii/firefly-iii/issues/2407) Fix recurring transaction dates
- [Issue 2410](https://github.com/firefly-iii/firefly-iii/issues/2410) Transaction links inconsistent
- [Issue 2414](https://github.com/firefly-iii/firefly-iii/issues/2414) Can't edit recurring transactions
- [Issue 2415](https://github.com/firefly-iii/firefly-iii/issues/2415) Return here + reset form results in empty transaction form
- [Issue 2416](https://github.com/firefly-iii/firefly-iii/issues/2416) Some form inconsistencies.
- [Issue 2418](https://github.com/firefly-iii/firefly-iii/issues/2418) Reports are inaccurate or broken.
- [Issue 2422](https://github.com/firefly-iii/firefly-iii/issues/2422) PHP error when matching transactions.
- [Issue 2423](https://github.com/firefly-iii/firefly-iii/issues/2423) Reports are inaccurate or broken.
- [Issue 2426](https://github.com/firefly-iii/firefly-iii/issues/2426) Inconsistent documentation and instructions.
- [Issue 2427](https://github.com/firefly-iii/firefly-iii/issues/2427) Deleted account and "initial balance" accounts may appear in dropdowns.
- [Issue 2428](https://github.com/firefly-iii/firefly-iii/issues/2428) Reports are inaccurate or broken.
- [Issue 2429](https://github.com/firefly-iii/firefly-iii/issues/2429) Typo leads to SQL errors in available budgets API
- [Issue 2431](https://github.com/firefly-iii/firefly-iii/issues/2431) Issues creating new recurring transactions.
- [Issue 2434](https://github.com/firefly-iii/firefly-iii/issues/2434) You can edit the initial balance transaction but it fails to save.
- ARM build should work now.
# 4.8.0.1 (API 0.10.0)
- The balance box on the dashboard shows only negative numbers, skewing the results.

View File

@@ -15,8 +15,8 @@ const pkgdef :Spk.PackageDefinition = (
manifest = (
appTitle = (defaultText = "Firefly III"),
appVersion = 33,
appMarketingVersion = (defaultText = "4.8.0.1"),
appVersion = 35,
appMarketingVersion = (defaultText = "4.8.0.3"),
actions = [
# Define your "new document" handlers here.

View File

@@ -1,7 +1,7 @@
sudo: required
language: bash
env:
- VERSION=4.8.0.1
- VERSION=4.8.0.3
dist: xenial
@@ -26,4 +26,4 @@ script:
# build everything
- .deploy/docker/build-amd64.sh
- .deploy/docker/build-arm.sh
- .deploy/docker/manifest.sh
- .deploy/docker/manifest.sh

View File

@@ -1,28 +1,10 @@
FROM php:7.2-apache
FROM jc5x/firefly-iii-base-image:latest
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
@@ -32,15 +14,6 @@ RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
# copy Apache config to correct spot.
COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Expose port 80
EXPOSE 80

View File

@@ -1,29 +1,10 @@
FROM php:7.2-apache
ARG ARCH
FROM jc5x/firefly-iii-base-image:latest
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# configure PHP
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 600/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 512M/' /usr/local/etc/php/php.ini
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
@@ -33,15 +14,6 @@ RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
# copy Apache config to correct spot.
COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Expose port 80
EXPOSE 80

View File

@@ -1,25 +1,10 @@
FROM arm32v7/php:7.2-apache-stretch
ARG ARCH
COPY tmp/qemu-arm-static /usr/bin/qemu-arm-static
FROM jc5x/firefly-iii-base-image:latest
ENV FIREFLY_PATH=/var/www/firefly-iii COMPOSER_ALLOW_SUPERUSER=1
LABEL version="1.5" maintainer="thegrumpydictator@gmail.com"
# Create volumes
VOLUME $FIREFLY_PATH/storage/export $FIREFLY_PATH/storage/upload
# Install stuff Firefly III runs with & depends on: php extensions, locales, dev headers and composer
RUN apt-get update && apt-get install -y locales unzip && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions --cleanup bcmath ldap gd pdo_pgsql pdo_sqlite pdo_mysql intl opcache memcached
RUN a2enmod rewrite && a2enmod ssl
RUN echo "hu_HU.UTF-8 UTF-8\nro_RO.UTF-8 UTF-8\nnb_NO.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\ncs_CZ.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\nes_ES.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8\nid_ID.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nnl_NL.UTF-8 UTF-8\npl_PL.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8\nru_RU.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\n\n" > /etc/locale.gen
RUN locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy in Firefly III source
WORKDIR $FIREFLY_PATH
ADD . $FIREFLY_PATH
@@ -29,15 +14,6 @@ RUN chown -R www-data:www-data /var/www && \
chmod -R 775 $FIREFLY_PATH/storage && \
composer install --prefer-dist --no-dev --no-scripts --no-suggest
# copy ca certs to correct location
COPY ./.deploy/docker/cacert.pem /usr/local/ssl/cert.pem
# copy Apache config to correct spot.
COPY ./.deploy/docker/apache2.conf /etc/apache2/apache2.conf
# Enable default site (Firefly III)
COPY ./.deploy/docker/apache-firefly.conf /etc/apache2/sites-available/000-default.conf
# Expose port 80
EXPOSE 80

View File

@@ -47,7 +47,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AccountController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AccountController extends Controller
{
@@ -234,8 +234,6 @@ class AccountController extends Controller
*
* @return JsonResponse
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function transactions(Request $request, Account $account): JsonResponse
{

View File

@@ -45,7 +45,7 @@ use function strlen;
/**
* Class AttachmentController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AttachmentController extends Controller
{

View File

@@ -42,7 +42,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AvailableBudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AvailableBudgetController extends Controller
{

View File

@@ -48,7 +48,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BillController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BillController extends Controller
{

View File

@@ -47,7 +47,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BudgetController extends Controller
{
@@ -79,8 +79,6 @@ class BudgetController extends Controller
/**
* Display a listing of the resource.
*
*
* @param Request $request
* @param Budget $budget
*

View File

@@ -46,7 +46,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BudgetLimitController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BudgetLimitController extends Controller
{

View File

@@ -44,7 +44,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CategoryController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class CategoryController extends Controller
{

View File

@@ -37,7 +37,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* Class Controller.
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.NumberOfChildren)
*
*/
class Controller extends BaseController
{

View File

@@ -66,7 +66,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CurrencyController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class CurrencyController extends Controller
{

View File

@@ -45,7 +45,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class LinkTypeController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class LinkTypeController extends Controller
{

View File

@@ -42,7 +42,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class PiggyBankController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class PiggyBankController extends Controller
{
@@ -226,7 +226,14 @@ class PiggyBankController extends Controller
*/
public function update(PiggyBankRequest $request, PiggyBank $piggyBank): JsonResponse
{
$piggyBank = $this->repository->update($piggyBank, $request->getAll());
$data = $request->getAll();
$piggyBank = $this->repository->update($piggyBank, $data);
if ('' !== $data['current_amount']) {
$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);
}
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));

View File

@@ -48,7 +48,7 @@ use Log;
/**
* Class RuleController
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class RuleController extends Controller
{

View File

@@ -231,7 +231,7 @@ class RuleGroupController extends Controller
*
* @return JsonResponse
* @throws FireflyException
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
public function testGroup(RuleGroupTestRequest $request, RuleGroup $group): JsonResponse
{

View File

@@ -24,7 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\UserRequest;
use FireflyIII\Api\V1\Requests\UserStoreRequest;
use FireflyIII\Api\V1\Requests\UserUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\UserTransformer;
@@ -42,7 +43,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class UserController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class UserController extends Controller
{
@@ -155,11 +156,11 @@ class UserController extends Controller
/**
* Store a new user.
*
* @param UserRequest $request
* @param UserStoreRequest $request
*
* @return JsonResponse
*/
public function store(UserRequest $request): JsonResponse
public function store(UserStoreRequest $request): JsonResponse
{
$data = $request->getAll();
$user = $this->repository->store($data);
@@ -183,12 +184,12 @@ class UserController extends Controller
/**
* Update a user.
*
* @param UserRequest $request
* @param UserUpdateRequest $request
* @param User $user
*
* @return JsonResponse
*/
public function update(UserRequest $request, User $user): JsonResponse
public function update(UserUpdateRequest $request, User $user): JsonResponse
{
$data = $request->getAll();
$user = $this->repository->update($user, $data);

View File

@@ -80,7 +80,7 @@ class CurrencyRequest extends Request
$rules = [
'name' => 'required|between:1,255|unique:transaction_currencies,name',
'code' => 'required|between:3,3|unique:transaction_currencies,code',
'symbol' => 'required|between:1,5|unique:transaction_currencies,symbol',
'symbol' => 'required|between:1,8|unique:transaction_currencies,symbol',
'decimal_places' => 'between:0,20|numeric|min:0|max:20',
'enabled' => [new IsBoolean()],
'default' => [new IsBoolean()],
@@ -94,8 +94,8 @@ class CurrencyRequest extends Request
case 'PATCH':
$currency = $this->route()->parameter('currency_code');
$rules['name'] = 'required|between:1,255|unique:transaction_currencies,name,' . $currency->id;
$rules['code'] = 'required|between:1,255|unique:transaction_currencies,code,' . $currency->id;
$rules['symbol'] = 'required|between:1,255|unique:transaction_currencies,symbol,' . $currency->id;
$rules['code'] = 'required|between:3,3|unique:transaction_currencies,code,' . $currency->id;
$rules['symbol'] = 'required|between:1,8|unique:transaction_currencies,symbol,' . $currency->id;
break;
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* DateRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -19,6 +20,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
@@ -65,4 +68,4 @@ class DateRequest extends Request
'end' => 'required|date|after:start',
];
}
}
}

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Rules\IsAssetAccountId;
use FireflyIII\Rules\LessThanPiggyTarget;
use FireflyIII\Rules\ZeroOrMore;
/**
@@ -53,14 +54,11 @@ class PiggyBankRequest extends Request
*/
public function getAll(): array
{
$current = $this->string('current_amount');
$current = '' === $current ? '0' : $current;
return [
'name' => $this->string('name'),
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('target_amount'),
'current_amount' => $current,
'current_amount' => $this->string('current_amount'),
'startdate' => $this->date('start_date'),
'targetdate' => $this->date('target_date'),
'notes' => $this->string('notes'),
@@ -76,8 +74,6 @@ class PiggyBankRequest extends Request
{
$rules = [
'name' => 'required|between:1,255|uniquePiggyBankForUser',
'account_id' => ['required', 'belongsToUser:accounts', new IsAssetAccountId],
'target_amount' => 'required|numeric|more:0',
'current_amount' => ['numeric', new ZeroOrMore, 'lte:target_amount'],
'start_date' => 'date|nullable',
'target_date' => 'date|nullable|after:start_date',
@@ -90,8 +86,11 @@ class PiggyBankRequest extends Request
case 'PUT':
case 'PATCH':
/** @var PiggyBank $piggyBank */
$piggyBank = $this->route()->parameter('piggyBank');
$rules['name'] = 'required|between:1,255|uniquePiggyBankForUser:' . $piggyBank->id;
$piggyBank = $this->route()->parameter('piggyBank');
$rules['name'] = 'between:1,255|uniquePiggyBankForUser:' . $piggyBank->id;
$rules['account_id'] = ['belongsToUser:accounts', new IsAssetAccountId];
$rules['target_amount'] = 'numeric|more:0';
$rules['current_amount'] = ['numeric', new ZeroOrMore, new LessThanPiggyTarget];
break;
}

View File

@@ -23,6 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Validation\RecurrenceValidation;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
@@ -52,7 +55,37 @@ class RecurrenceStoreRequest extends Request
*/
public function rules(): array
{
return $this->rulesRecurrence();
$today = Carbon::now()->addDay();
return [
'type' => 'required|in:withdrawal,transfer,deposit',
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
'description' => 'between:1,65000',
'first_date' => sprintf('required|date|after:%s', $today->format('Y-m-d')),
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
'nr_of_repetitions' => 'numeric|between:1,31',
'tags' => 'between:1,64000',
'piggy_bank_id' => 'numeric',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
}
/**

View File

@@ -23,6 +23,10 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Recurrence;
use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Validation\RecurrenceValidation;
use FireflyIII\Validation\TransactionValidation;
use Illuminate\Validation\Validator;
@@ -52,7 +56,40 @@ class RecurrenceUpdateRequest extends Request
*/
public function rules(): array
{
return $this->rulesRecurrence();
/** @var Recurrence $recurrence */
$recurrence = $this->route()->parameter('recurrence');
$first = clone $recurrence->first_date;
$first->subDay();
return [
'type' => 'required|in:withdrawal,transfer,deposit',
'title' => sprintf('required|between:1,255|uniqueObjectForUser:recurrences,title,%d', $recurrence->id),
'description' => 'between:1,65000',
'first_date' => sprintf('required|date|after:%s', $first->format('Y-m-d')),
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $first->format('Y-m-d')),
'nr_of_repetitions' => 'numeric|between:1,31',
'tags' => 'between:1,64000',
'piggy_bank_id' => 'numeric',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
}
/**

View File

@@ -121,48 +121,6 @@ class Request extends FireflyIIIRequest
return $return;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
protected function rulesRecurrence(): array
{
$today = Carbon::now()->addDay();
return [
'type' => 'required|in:withdrawal,transfer,deposit',
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
'description' => 'between:1,65000',
'first_date' => sprintf('required|date|after:%s', $today->format('Y-m-d')),
'apply_rules' => [new IsBoolean],
'active' => [new IsBoolean],
'repeat_until' => sprintf('date|after:%s', $today->format('Y-m-d')),
'nr_of_repetitions' => 'numeric|between:1,31',
'tags' => 'between:1,64000',
'piggy_bank_id' => 'numeric',
'repetitions.*.type' => 'required|in:daily,weekly,ndom,monthly,yearly',
'repetitions.*.moment' => 'between:0,10',
'repetitions.*.skip' => 'required|numeric|between:0,31',
'repetitions.*.weekend' => 'required|numeric|min:1|max:4',
'transactions.*.description' => 'required|between:1,255',
'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.foreign_amount' => 'numeric|more:0',
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
'transactions.*.category_name' => 'between:1,255|nullable',
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.source_name' => 'between:1,255|nullable',
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
'transactions.*.destination_name' => 'between:1,255|nullable',
];
}
/**
* Returns the repetition data as it is found in the submitted data.
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* RuleGroupTestRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -19,6 +20,9 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
@@ -141,4 +145,4 @@ class RuleGroupTestRequest extends Request
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* RuleGroupTriggerRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -19,6 +20,9 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
@@ -116,4 +120,4 @@ class RuleGroupTriggerRequest extends Request
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* RuleTestRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -19,6 +20,9 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
@@ -141,4 +145,4 @@ class RuleTestRequest extends Request
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* RuleTriggerRequest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -19,6 +20,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
@@ -116,4 +119,4 @@ class RuleTriggerRequest extends Request
return null !== $account && AccountType::ASSET === $account->accountType->type;
}
}
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* UserRequest.php
* UserStoreRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
@@ -30,11 +30,9 @@ use FireflyIII\User;
/**
* Class UserRequest
* @codeCoverageIgnore
* TODO AFTER 4.8,0: split this into two request classes.
* Class UserStoreRequest
*/
class UserRequest extends Request
class UserStoreRequest extends Request
{
/**
* Authorize logged in users.
@@ -68,7 +66,7 @@ class UserRequest extends Request
public function getAll(): array
{
$blocked = false;
if (null === $this->get('blocked')) {
if (null !== $this->get('blocked')) {
$blocked = $this->boolean('blocked');
}
$data = [
@@ -88,23 +86,12 @@ class UserRequest extends Request
*/
public function rules(): array
{
$rules = [
return [
'email' => 'required|email|unique:users,email,',
'blocked' => [new IsBoolean],
'blocked_code' => 'in:email_changed',
'role' => 'in:owner,demo',
];
switch ($this->method()) {
default:
break;
case 'PUT':
case 'PATCH':
$user = $this->route()->parameter('user');
$rules['email'] = 'required|email|unique:users,email,' . $user->id;
break;
}
return $rules;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* UserUpdateRequest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\User;
/**
* Class UserUpdateRequest
*/
class UserUpdateRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
$result = false;
// Only allow authenticated users
if (auth()->check()) {
/** @var User $user */
$user = auth()->user();
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole($user, 'owner')) {
$result = true; // @codeCoverageIgnore
}
}
return $result;
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
$blocked = false;
if (null !== $this->get('blocked')) {
$blocked = $this->boolean('blocked');
}
$data = [
'email' => $this->string('email'),
'blocked' => $blocked,
'blocked_code' => $this->string('blocked_code'),
'role' => $this->string('role'),
];
return $data;
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
$user = $this->route()->parameter('user');
$rules = [
'email' => sprintf('email|unique:users,email,%d', $user->id),
'blocked' => [new IsBoolean],
'blocked_code' => 'in:email_changed',
'role' => 'in:owner,demo,',
];
return $rules;
}
}

View File

@@ -70,6 +70,7 @@ class CorrectDatabase extends Command
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:rename-meta-fields',
'firefly-iii:fix-ob-currencies'
];
foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command));
@@ -80,4 +81,4 @@ class CorrectDatabase extends Command
return 0;
}
}
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* CorrectOpeningBalanceCurrencies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Console\Command;
use Log;
/**
* Class CorrectOpeningBalanceCurrencies
*/
class CorrectOpeningBalanceCurrencies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-ob-currencies';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// get all OB journals:
$set = TransactionJournal
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereNull('transaction_journals.deleted_at')
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);
$this->line(sprintf('Going to verify %d opening balance transactions.', $set->count()));
$count = 0;
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
$count += $this->correctJournal($journal);
}
if ($count > 0) {
$this->line(sprintf('Corrected %d opening balance transactions.', $count));
}
if (0 === $count) {
$this->info('There was nothing to fix in the opening balance transactions.');
}
return 0;
}
/**
* @param TransactionJournal $journal
*
* @return int
*/
private function correctJournal(TransactionJournal $journal): int
{
Log::debug(sprintf('Going to correct journal #%d', $journal->id));
// get the asset account for this opening balance:
$account = $this->getAccount($journal);
if (null === $account) {
$this->warn(sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id));
return 0;
}
Log::debug(sprintf('Found %s #%d "%s".', $account->accountType->type, $account->id, $account->name));
$currency = $this->getCurrency($account);
Log::debug(sprintf('Found currency #%d (%s)', $currency->id, $currency->code));
// update journal and all transactions:
$this->setCurrency($journal, $currency);
return 1;
}
/**
* @param TransactionJournal $journal
*
* @return Account|null
*/
private function getAccount(TransactionJournal $journal): ?Account
{
$excluded = [];
$transactions = $journal->transactions()->with(['account', 'account.accountType'])->get();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$account = $transaction->account;
if (null !== $account) {
if (AccountType::INITIAL_BALANCE !== $account->accountType->type) {
return $account;
}
}
}
return null;
}
/**
* @param Account $account
*
* @return TransactionCurrency
*/
private function getCurrency(Account $account): TransactionCurrency
{
/** @var AccountRepositoryInterface $repos */
$repos = app(AccountRepositoryInterface::class);
$repos->setUser($account->user);
return $repos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
}
/**
* @param TransactionJournal $journal
* @param TransactionCurrency $currency
*/
private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): void
{
$journal->transaction_currency_id = $currency->id;
$journal->save();
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$transaction->transaction_currency_id = $currency->id;
$transaction->save();
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* CreateAccessTokens.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* CreateLinkTypes.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* DeleteEmptyGroups.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* DeleteEmptyJournals.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* DeleteOrphanedTransactions.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* DeleteZeroAmount.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* EnableCurrencies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* FixAccountTypes.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* FixPiggies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* FixUnevenAmount.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* RemoveBills.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* RenameMetaFields.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* TransferBudgets.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* ReportEmptyObjects.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -70,4 +70,4 @@ class ReportIntegrity extends Command
return 0;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* ReportSum.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* AccountCurrencies.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* BackToJournals.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -116,4 +116,4 @@ class BudgetLimitCurrency extends Command
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
}
}

View File

@@ -115,4 +115,4 @@ class CCLiabilities extends Command
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
}
}

View File

@@ -125,4 +125,4 @@ class MigrateAttachments extends Command
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
}
}

View File

@@ -124,4 +124,4 @@ class MigrateJournalNotes extends Command
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* MigrateToGroups.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -236,7 +237,7 @@ class MigrateToGroups extends Command
* @param TransactionJournal $journal
*
* @throws Exception
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
private function makeMultiGroup(TransactionJournal $journal): void
{

View File

@@ -246,4 +246,4 @@ class MigrateToRules extends Command
$this->billRepository->update($bill, $newBillData);
$this->count++;
}
}
}

View File

@@ -125,6 +125,7 @@ class OtherCurrenciesCorrections extends Command
if (isset($this->accountCurrencies[$accountId]) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
return $this->accountCurrencies[$accountId]; // @codeCoverageIgnore
}
// TODO we can use getAccountCurrency() instead
$currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');
$result = $this->currencyRepos->findNull($currencyId);
if (null === $result) {
@@ -247,8 +248,8 @@ class OtherCurrenciesCorrections extends Command
* Gets the transaction that determines the transaction that "leads" and will determine
* the currency to be used by all transactions, and the journal itself.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @param TransactionJournal $journal
*
* @return Transaction|null
*/
private function getLeadTransaction(TransactionJournal $journal): ?Transaction
@@ -282,4 +283,4 @@ class OtherCurrenciesCorrections extends Command
return $lead;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* RenameAccountMeta.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* TransactionIdentifier.php
* Copyright (c) 2019 thegrumpydictator@gmail.com

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* TransferCurrenciesCorrections.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -147,6 +148,7 @@ class TransferCurrenciesCorrections extends Command
if (isset($this->accountCurrencies[$accountId]) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
return $this->accountCurrencies[$accountId]; // @codeCoverageIgnore
}
// TODO we can use getAccountCurrency() instead
$currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');
$result = $this->currencyRepos->findNull($currencyId);
if (null === $result) {
@@ -290,8 +292,6 @@ class TransferCurrenciesCorrections extends Command
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param TransactionJournal $transfer
*/
private function updateTransferCurrency(TransactionJournal $transfer): void
@@ -575,4 +575,4 @@ class TransferCurrenciesCorrections extends Command
return false;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* UpgradeDatabase.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -52,6 +53,7 @@ class UpgradeDatabase extends Command
*/
public function handle(): int
{
$this->callInitialCommands();
@@ -70,7 +72,7 @@ class UpgradeDatabase extends Command
'firefly-iii:back-to-journals',
'firefly-iii:rename-account-meta',
// there are 13 verify commands.
// there are 14 verify commands.
'firefly-iii:fix-piggies',
'firefly-iii:create-link-types',
'firefly-iii:create-access-tokens',
@@ -84,6 +86,7 @@ class UpgradeDatabase extends Command
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:rename-meta-fields',
'firefly-iii:fix-ob-currencies',
// two report commands
'firefly-iii:report-empty-objects',
@@ -102,8 +105,8 @@ class UpgradeDatabase extends Command
$result = Artisan::output();
echo $result;
}
// set new DB version.
app('fireflyconfig')->set('db_version', (int)config('firefly.db_version'));
// index will set FF3 version.
app('fireflyconfig')->set('ff3_version', (string)config('firefly.version'));
@@ -112,8 +115,21 @@ class UpgradeDatabase extends Command
private function callInitialCommands(): void
{
Artisan::call('migrate', ['--seed' => true]);
$this->line('Now seeding the database...');
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
$result = Artisan::output();
echo $result;
$this->line('Now decrypting the database (if necessary)...');
Artisan::call('firefly-iii:decrypt-all');
$result = Artisan::output();
echo $result;
$this->line('Now installing OAuth2 keys...');
Artisan::call('passport:install');
$result = Artisan::output();
echo $result;
$this->line('Done!');
}
}

View File

@@ -60,8 +60,8 @@ class RequestedReportOnJournals
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/** @var Collection The journals to report on. */
public $journals;
/** @var Collection The transaction groups to report on. */
public $groups;
/** @var int The ID of the user. */
public $userId;
@@ -69,13 +69,13 @@ class RequestedReportOnJournals
* Create a new event instance.
*
* @param int $userId
* @param Collection $journals
* @param Collection $groups
*/
public function __construct(int $userId, Collection $journals)
public function __construct(int $userId, Collection $groups)
{
Log::debug('In event RequestedReportOnJournals.');
$this->userId = $userId;
$this->journals = $journals;
$this->groups = $groups;
}
/**

View File

@@ -36,16 +36,15 @@ class StoredTransactionGroup extends Event
{
use SerializesModels;
public $applyRules;
/** @var TransactionGroup The group that was stored. */
public $transactionGroup;
public $applyRules;
/**
* Create a new event instance.
*
* @param TransactionGroup $transactionGroup
* @param bool $applyRules
* @param bool $applyRules
*/
public function __construct(TransactionGroup $transactionGroup, bool $applyRules = true)
{

View File

@@ -29,6 +29,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class UpdatedTransactionGroup.
*
* @codeCoverageIgnore
*
*/

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* GracefulNotFoundHandler.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
@@ -43,9 +44,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
*
* @param Request $request
* @param Exception $exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
* @return mixed
*/
@@ -225,4 +224,4 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
}
}

View File

@@ -48,9 +48,7 @@ class Handler extends ExceptionHandler
*
* @param Request $request
* @param Exception $exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
* @return mixed
*/
@@ -112,7 +110,7 @@ class Handler extends ExceptionHandler
*
* This is a great spot to send exceptions to Sentry etc.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five its fine.
* // it's five its fine.
*
* @param Exception $exception
*

View File

@@ -189,7 +189,7 @@ class AccountFactory
* @param null|string $accountType
*
* @return AccountType|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getAccountType(?int $accountTypeId, ?string $accountType): ?AccountType
{

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Budget;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
@@ -53,7 +52,7 @@ class BudgetFactory
* @param null|string $budgetName
*
* @return Budget|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function find(?int $budgetId, ?string $budgetName): ?Budget
{

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Category;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
@@ -63,7 +62,7 @@ class CategoryFactory
* @param null|string $categoryName
*
* @return Category|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
{

View File

@@ -53,7 +53,7 @@ class PiggyBankEventFactory
* @param PiggyBank|null $piggyBank
*
* @return PiggyBankEvent|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): ?PiggyBankEvent
{

View File

@@ -52,7 +52,7 @@ class PiggyBankFactory
* @param null|string $piggyBankName
*
* @return PiggyBank|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
{

View File

@@ -79,7 +79,7 @@ class TransactionCurrencyFactory
* @param null|string $currencyCode
*
* @return TransactionCurrency|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function find(?int $currencyId, ?string $currencyCode): ?TransactionCurrency
{

View File

@@ -23,9 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
/**
@@ -60,10 +58,8 @@ class TransactionGroupFactory
$collection = $this->journalFactory->create($data);
$title = $data['group_title'] ?? null;
$title = '' === $title ? null : $title;
/** @var TransactionJournal $first */
$first = $collection->first();
$group = new TransactionGroup;
$group->user()->associate($first->user);
$group = new TransactionGroup;
$group->user()->associate($this->user);
$group->title = $title;
$group->save();
@@ -81,4 +77,4 @@ class TransactionGroupFactory
{
$this->user = $user;
}
}
}

View File

@@ -143,6 +143,9 @@ class TransactionJournalFactory
if (null !== $journal) {
$collection->push($journal);
}
if(null === $journal) {
Log::error('The createJournal() method returned NULL. This may indicate an error.');
}
}
return $collection;
@@ -247,6 +250,7 @@ class TransactionJournalFactory
$destinationAccount = $this->getAccount($type->type, 'destination', (int)$row['destination_id'], $row['destination_name']);
// @codeCoverageIgnoreStart
} catch (FireflyException $e) {
Log::error('Could not validate source or destination.');
Log::error($e->getMessage());
return null;
@@ -293,9 +297,9 @@ class TransactionJournalFactory
$foreignCurrency = $this->getCurrency($foreignCurrency, $destinationAccount);
$sourceCurrency = $currency;
$destCurrency = $foreignCurrency;
$destCurrency = $currency;
$sourceForeignCurrency = $foreignCurrency;
$destForeignCurrency = $currency;
$destForeignCurrency = $foreignCurrency;
}
/** Create a basic journal. */

View File

@@ -49,8 +49,6 @@ class TransactionJournalMetaFactory
* @param array $data
*
* @return TransactionJournalMeta|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function updateOrCreate(array $data): ?TransactionJournalMeta
{

View File

@@ -109,7 +109,7 @@ class ChartJsGenerator implements GeneratorInterface
* ]
* ]
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five.
* // it's five.
*
* @param array $data
*

View File

@@ -60,7 +60,7 @@ interface GeneratorInterface
* ]
* ]
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five.
* // it's five.
*
* @param array $data
*

View File

@@ -24,7 +24,6 @@ namespace FireflyIII\Generator\Report\Standard;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use Illuminate\Support\Collection;
use Log;
use Throwable;
@@ -50,17 +49,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
public function generate(): string
{
/** @var ReportHelperInterface $helper */
$helper = app(ReportHelperInterface::class);
$bills = $helper->getBillReport($this->start, $this->end, $this->accounts);
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$reportType = 'default';
try {
return view(
'reports.default.month',
compact('bills', 'accountIds', 'reportType')
)->with('start', $this->start)->with('end', $this->end)->render();
return view('reports.default.month', compact('accountIds', 'reportType'))->with('start', $this->start)->with('end', $this->end)->render();
} catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.default.month: %s', $e->getMessage()));
$result = 'Could not render report view.';

View File

@@ -112,7 +112,7 @@ class Support
/**
* Summarize collection by earned and spent data.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
* // it's exactly five.
*
* @param array $spent
* @param array $earned

View File

@@ -55,10 +55,10 @@ class AutomationHandler
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$user = $repository->findNull($event->userId);
if (null !== $user && 0 !== $event->journals->count()) {
if (null !== $user && 0 !== $event->groups->count()) {
try {
Log::debug('Trying to mail...');
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->journals));
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->groups));
// @codeCoverageIgnoreStart
} catch (Exception $e) {
Log::debug('Send message failed! :(');

View File

@@ -43,9 +43,7 @@ class VersionCheckEventHandler
/**
* Checks with GitHub to see if there is a new version.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param RequestedVersionCheckStatus $event
*/
public function checkForUpdates(RequestedVersionCheckStatus $event): void

View File

@@ -98,7 +98,7 @@ class MetaPieChart implements MetaPieChartInterface
* @param string $group
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function generate(string $direction, string $group): array
{
@@ -181,8 +181,6 @@ class MetaPieChart implements MetaPieChartInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function groupByFields(array $array, array $fields): array
{

View File

@@ -1,97 +0,0 @@
<?php
/**
* Balance.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use Illuminate\Support\Collection;
/**
* Class Balance.
*
* @codeCoverageIgnore
*/
class Balance
{
/** @var BalanceHeader Header row. */
protected $balanceHeader;
/** @var Collection Collection of lines. */
protected $balanceLines;
/**
* Balance constructor.
*/
public function __construct()
{
$this->balanceLines = new Collection;
}
/**
* Add a line.
*
* @param BalanceLine $line
*/
public function addBalanceLine(BalanceLine $line): void
{
$this->balanceLines->push($line);
}
/**
* Get the header.
*
* @return BalanceHeader
*/
public function getBalanceHeader(): BalanceHeader
{
return $this->balanceHeader ?? new BalanceHeader;
}
/**
* Set the header.
*
* @param BalanceHeader $balanceHeader
*/
public function setBalanceHeader(BalanceHeader $balanceHeader): void
{
$this->balanceHeader = $balanceHeader;
}
/**
* Get all lines.
*
* @return Collection
*/
public function getBalanceLines(): Collection
{
return $this->balanceLines;
}
/**
* Set all lines.
*
* @param Collection $balanceLines
*/
public function setBalanceLines(Collection $balanceLines): void
{
$this->balanceLines = $balanceLines;
}
}

View File

@@ -1,100 +0,0 @@
<?php
/**
* BalanceEntry.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use FireflyIII\Models\Account as AccountModel;
/**
* Class BalanceEntry.
*
* @codeCoverageIgnore
*/
class BalanceEntry
{
/** @var AccountModel The account. */
protected $account;
/** @var string The amount left. */
protected $left = '0';
/** @var string The amount spent. */
protected $spent = '0';
/**
* Account getter.
*
* @return AccountModel
*/
public function getAccount(): AccountModel
{
return $this->account;
}
/**
* Account setter.
*
* @param AccountModel $account
*/
public function setAccount(AccountModel $account): void
{
$this->account = $account;
}
/**
* Get amount left.
*
* @return string
*/
public function getLeft(): string
{
return $this->left;
}
/**
* Set amount left.
*
* @param string $left
*/
public function setLeft(string $left): void
{
$this->left = $left;
}
/**
* Get amount spent.
*
* @return string
*/
public function getSpent(): string
{
return $this->spent;
}
/**
* Set amount spent.
*
* @param string $spent
*/
public function setSpent(string $spent): void
{
$this->spent = $spent;
}
}

View File

@@ -1,65 +0,0 @@
<?php
/**
* BalanceHeader.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use FireflyIII\Models\Account as AccountModel;
use Illuminate\Support\Collection;
/**
* Class BalanceHeader.
*
* @codeCoverageIgnore
*/
class BalanceHeader
{
/** @var Collection The accounts. */
protected $accounts;
/**
* BalanceHeader constructor.
*/
public function __construct()
{
$this->accounts = new Collection;
}
/**
* Add an account.
*
* @param AccountModel $account
*/
public function addAccount(AccountModel $account): void
{
$this->accounts->push($account);
}
/**
* Get them all.
*
* @return Collection
*/
public function getAccounts(): Collection
{
return $this->accounts;
}
}

View File

@@ -1,189 +0,0 @@
<?php
/**
* BalanceLine.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use Carbon\Carbon;
use FireflyIII\Models\Budget as BudgetModel;
use FireflyIII\Models\BudgetLimit;
use Illuminate\Support\Collection;
/**
* Class BalanceLine.
*
* @codeCoverageIgnore
*/
class BalanceLine
{
/**
*
*/
public const ROLE_DEFAULTROLE = 1;
/**
*
*/
public const ROLE_TAGROLE = 2;
/** @var Collection */
protected $balanceEntries;
/** @var BudgetModel */
protected $budget;
/** @var BudgetLimit */
protected $budgetLimit;
/** @var int */
protected $role = self::ROLE_DEFAULTROLE;
/**
*
*/
public function __construct()
{
$this->balanceEntries = new Collection;
}
/**
* @param BalanceEntry $balanceEntry
*/
public function addBalanceEntry(BalanceEntry $balanceEntry): void
{
$this->balanceEntries->push($balanceEntry);
}
/**
* @return Collection
*/
public function getBalanceEntries(): Collection
{
return $this->balanceEntries;
}
/**
* @param Collection $balanceEntries
*/
public function setBalanceEntries(Collection $balanceEntries): void
{
$this->balanceEntries = $balanceEntries;
}
/**
* @return BudgetModel
*/
public function getBudget(): BudgetModel
{
return $this->budget ?? new BudgetModel;
}
/**
* @param BudgetModel $budget
*/
public function setBudget(BudgetModel $budget): void
{
$this->budget = $budget;
}
/**
* @return BudgetLimit
*/
public function getBudgetLimit(): BudgetLimit
{
return $this->budgetLimit;
}
/**
* @param BudgetLimit $budgetLimit
*/
public function setBudgetLimit(BudgetLimit $budgetLimit): void
{
$this->budgetLimit = $budgetLimit;
}
/**
* @return Carbon
*/
public function getEndDate(): Carbon
{
return $this->budgetLimit->end_date ?? new Carbon;
}
/**
* @return int
*/
public function getRole(): int
{
return $this->role;
}
/**
* @param int $role
*/
public function setRole(int $role): void
{
$this->role = $role;
}
/**
* @return Carbon
*/
public function getStartDate(): Carbon
{
return $this->budgetLimit->start_date ?? new Carbon;
}
/**
* @return string
*/
public function getTitle(): string
{
$title = '';
if ($this->getBudget() instanceof BudgetModel && null !== $this->getBudget()->id) {
$title = $this->getBudget()->name;
}
if ('' === $title && self::ROLE_DEFAULTROLE === $this->getRole()) {
$title = (string)trans('firefly.no_budget');
}
if ('' === $title && self::ROLE_TAGROLE === $this->getRole()) {
$title = (string)trans('firefly.coveredWithTags');
}
return $title;
}
/**
* If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine
* should have a "spent" value, which is the amount of money that has been spent
* on the given budget/repetition. If you subtract all those amounts from the budget/repetition's
* total amount, this is returned:.
*
* @return string
*/
public function leftOfRepetition(): string
{
$start = $this->budgetLimit->amount ?? '0';
/** @var BalanceEntry $balanceEntry */
foreach ($this->getBalanceEntries() as $balanceEntry) {
$start = bcadd($balanceEntry->getSpent(), $start);
}
return $start;
}
}

View File

@@ -1,128 +0,0 @@
<?php
/**
* Bill.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use Carbon\Carbon;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
/**
* Class Bill.
*
* @codeCoverageIgnore
*/
class Bill
{
/** @var Collection The bills. */
private $bills;
/** @var Carbon End date of the collection. */
private $endDate;
/** @var Carbon Start date of the collection. */
private $startDate;
/**
* Bill constructor.
*/
public function __construct()
{
$this->bills = new Collection;
}
/**
* Add a bill line.
*
* @param BillLine $bill
*/
public function addBill(BillLine $bill): void
{
$this->bills->push($bill);
}
/**
* Filter the bills (yes how very descriptive).
*/
public function filterBills(): void
{
Log::debug('Now in filterBills()');
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$start = $this->startDate;
$end = $this->endDate;
$lines = $this->bills->filter(
function (BillLine $line) use ($repository, $start, $end) {
// next expected match?
$date = $start;
Log::debug(sprintf('Now at bill line for bill "%s"', $line->getBill()->name));
Log::debug(sprintf('Default date to use is start date: %s', $date->format('Y-m-d')));
if ($line->isHit()) {
$date = $line->getLastHitDate();
Log::debug(sprintf('Line was hit, see date: %s. Always include it.', $date->format('Y-m-d')));
return $line;
}
$expected = $repository->nextExpectedMatch($line->getBill(), $date);
Log::debug(sprintf('Next expected match is %s', $expected->format('Y-m-d')));
if ($expected <= $end && $expected >= $start) {
Log::debug('This date is inside report limits');
return $line;
}
Log::debug('This date is OUTSIDE report limits');
return false;
}
);
$this->bills = $lines;
}
/**
* Bills getter.
*
* @return Collection
*/
public function getBills(): Collection
{
return $this->bills;
}
/**
* End date setter.
*
* @param Carbon $endDate
*/
public function setEndDate(Carbon $endDate): void
{
$this->endDate = $endDate;
}
/**
* Start date setter.
*
* @param Carbon $startDate
*/
public function setStartDate(Carbon $startDate): void
{
$this->startDate = $startDate;
}
}

View File

@@ -1,270 +0,0 @@
<?php
/**
* BillLine.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use Carbon\Carbon;
use FireflyIII\Models\Bill as BillModel;
use FireflyIII\Models\TransactionCurrency;
/**
* Class BillLine.
*
* @codeCoverageIgnore
*/
class BillLine
{
/** @var string The amount */
protected $amount;
/** @var BillModel The bill. */
protected $bill;
/** @var bool Is it hit this period */
protected $hit;
/** @var string What was the max amount. */
protected $max;
/** @var string What was the min amount. */
protected $min;
/** @var TransactionCurrency The transaction currency */
private $currency;
/** @var Carbon Latest date that payment is expected. */
private $endOfPayDate;
/** @var Carbon Date of last hit */
private $lastHitDate;
/** @var Carbon Date of last payment */
private $payDate;
/** @var int Journal */
private $transactionJournalId;
/**
* BillLine constructor.
*/
public function __construct()
{
$this->lastHitDate = new Carbon;
}
/**
* Amount getter.
*
* @return string
*/
public function getAmount(): string
{
return $this->amount ?? '0';
}
/**
* Amount setter.
*
* @param string $amount
*/
public function setAmount(string $amount): void
{
$this->amount = $amount;
}
/**
* Bill getter.
*
* @return BillModel
*/
public function getBill(): BillModel
{
return $this->bill;
}
/**
* Bill setter.
*
* @param BillModel $bill
*/
public function setBill(BillModel $bill): void
{
$this->bill = $bill;
}
/**
* @return TransactionCurrency
*/
public function getCurrency(): TransactionCurrency
{
return $this->currency;
}
/**
* @param TransactionCurrency $currency
*/
public function setCurrency(TransactionCurrency $currency): void
{
$this->currency = $currency;
}
/**
* End of pay date getter.
*
* @return Carbon
*/
public function getEndOfPayDate(): Carbon
{
return $this->endOfPayDate;
}
/**
* End of pay date setter.
*
* @param Carbon $endOfPayDate
*/
public function setEndOfPayDate(Carbon $endOfPayDate): void
{
$this->endOfPayDate = $endOfPayDate;
}
/**
* Last hit date getter.
*
* @return Carbon
*/
public function getLastHitDate(): Carbon
{
return $this->lastHitDate;
}
/**
* Last hit date setter.
*
* @param Carbon $lastHitDate
*/
public function setLastHitDate(Carbon $lastHitDate): void
{
$this->lastHitDate = $lastHitDate;
}
/**
* Max getter.
*
* @return string
*/
public function getMax(): string
{
return $this->max;
}
/**
* Max setter.
*
* @param string $max
*/
public function setMax(string $max): void
{
$this->max = $max;
}
/**
* Min getter.
*
* @return string
*/
public function getMin(): string
{
return $this->min;
}
/**
* Min setter.
*
* @param string $min
*/
public function setMin(string $min): void
{
$this->min = $min;
}
/**
* Pay date getter.
*
* @return Carbon
*/
public function getPayDate(): Carbon
{
return $this->payDate;
}
/**
* Pay date setter.
*
* @param Carbon $payDate
*/
public function setPayDate(Carbon $payDate): void
{
$this->payDate = $payDate;
}
/**
* Journal ID getter.
*
* @return int
*/
public function getTransactionJournalId(): int
{
return $this->transactionJournalId ?? 0;
}
/**
* Journal ID setter.
*
* @param int $transactionJournalId
*/
public function setTransactionJournalId(int $transactionJournalId): void
{
$this->transactionJournalId = $transactionJournalId;
}
/**
* Is active.
*
* @return bool
*/
public function isActive(): bool
{
return 1 === (int)$this->bill->active;
}
/**
* Is hit.
*
* @return bool
*/
public function isHit(): bool
{
return $this->hit;
}
/**
* Set is hit.
*
* @param bool $hit
*/
public function setHit(bool $hit): void
{
$this->hit = $hit;
}
}

View File

@@ -1,97 +0,0 @@
<?php
/**
* Category.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Helpers\Collection;
use FireflyIII\Models\Category as CategoryModel;
use Illuminate\Support\Collection;
/**
* Class Category.
*
* @codeCoverageIgnore
*/
class Category
{
/** @var Collection The categories */
protected $categories;
/** @var string Total amount */
protected $total = '0';
/**
* Category constructor.
*/
public function __construct()
{
$this->categories = new Collection;
}
/**
* Add a category.
*
* @param CategoryModel $category
*/
public function addCategory(CategoryModel $category): void
{
// spent is minus zero for an expense report:
if ($category->spent < 0) {
$this->categories->push($category);
$this->addTotal((string)$category->spent);
}
}
/**
* Add to the total amount.
*
* @param string $add
*/
public function addTotal(string $add): void
{
$this->total = bcadd($this->total, $add);
}
/**
* Get all categories.
*
* @return Collection
*/
public function getCategories(): Collection
{
$set = $this->categories->sortBy(
static function (CategoryModel $category) {
return $category->spent;
}
);
return $set;
}
/**
* Get the total.
*
* @return string
*/
public function getTotal(): string
{
return $this->total;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,41 @@ interface GroupCollectorInterface
*/
public function getExtractedJournals(): array;
/**
* Set source accounts.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function setSourceAccounts(Collection $accounts): GroupCollectorInterface;
/**
* These accounts must not be source accounts.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function excludeSourceAccounts(Collection $accounts): GroupCollectorInterface;
/**
* Exclude destination accounts.
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function excludeDestinationAccounts(Collection $accounts): GroupCollectorInterface;
/**
* Set destination accounts.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function setDestinationAccounts(Collection $accounts): GroupCollectorInterface;
/**
* Return the sum of all journals.
*
@@ -341,4 +376,4 @@ interface GroupCollectorInterface
*/
public function withCategoryInformation(): GroupCollectorInterface;
}
}

View File

@@ -23,11 +23,10 @@ declare(strict_types=1);
namespace FireflyIII\Helpers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Collection\Balance;
use FireflyIII\Helpers\Collection\BalanceEntry;
use FireflyIII\Helpers\Collection\BalanceHeader;
use FireflyIII\Helpers\Collection\BalanceLine;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@@ -44,8 +43,6 @@ class BalanceReportHelper implements BalanceReportHelperInterface
/**
* ReportHelper constructor.
*
*
* @param BudgetRepositoryInterface $budgetRepository
*/
public function __construct(BudgetRepositoryInterface $budgetRepository)
@@ -65,126 +62,78 @@ class BalanceReportHelper implements BalanceReportHelperInterface
* @param Carbon $start
* @param Carbon $end
*
* @return Balance
* @return array
*/
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): Balance
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): array
{
Log::debug('Start of balance report');
$balance = new Balance;
$header = new BalanceHeader;
$budgetLimits = $this->budgetRepository->getAllBudgetLimits($start, $end);
$report = [
'budgets' => [],
'accounts' => [],
];
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Add account %s to headers.', $account->name));
$header->addAccount($account);
$report['accounts'][$account->id] = [
'id' => $account->id,
'name' => $account->name,
'iban' => $account->iban,
'sum' => '0',
];
}
/** @var BudgetLimit $budgetLimit */
foreach ($budgetLimits as $budgetLimit) {
if (null !== $budgetLimit->budget) {
$line = $this->createBalanceLine($budgetLimit, $accounts);
$balance->addBalanceLine($line);
$budgets = $this->budgetRepository->getBudgets();
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
$report['budgets'][$budgetId] = [
'budget_id' => $budgetId,
'budget_name' => $budget->name,
'spent' => [], // per account
'sums' => [], // per currency
];
$spent = [];
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
->getExtractedJournals();
/** @var array $journal */
foreach ($journals as $journal) {
$sourceAccount = $journal['source_account_id'];
$currencyId = $journal['currency_id'];
$spent[$sourceAccount] = $spent[$sourceAccount] ?? [
'source_account_id' => $sourceAccount,
'currency_id' => $journal['currency_id'],
'currency_code' => $journal['currency_code'],
'currency_name' => $journal['currency_name'],
'currency_symbol' => $journal['currency_symbol'],
'currency_decimal_places' => $journal['currency_decimal_places'],
'spent' => '0',
];
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
// also fix sum:
$report['sums'][$budgetId][$currencyId] = $report['sums'][$budgetId][$currencyId] ?? [
'sum' => '0',
'currency_id' => $journal['currency_id'],
'currency_code' => $journal['currency_code'],
'currency_name' => $journal['currency_name'],
'currency_symbol' => $journal['currency_symbol'],
'currency_decimal_places' => $journal['currency_decimal_places'],
];
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
// add currency info for account sum
$report['accounts'][$sourceAccount]['currency_id'] = $journal['currency_id'];
$report['accounts'][$sourceAccount]['currency_code'] = $journal['currency_code'];
$report['accounts'][$sourceAccount]['currency_name'] = $journal['currency_name'];
$report['accounts'][$sourceAccount]['currency_symbol'] = $journal['currency_symbol'];
$report['accounts'][$sourceAccount]['currency_decimal_places'] = $journal['currency_decimal_places'];
}
$report['budgets'][$budgetId]['spent'] = $spent;
// get transactions in budget
}
$noBudgetLine = $this->createNoBudgetLine($accounts, $start, $end);
$balance->addBalanceLine($noBudgetLine);
$balance->setBalanceHeader($header);
Log::debug('Clear unused budgets.');
// remove budgets without expenses from balance lines:
$balance = $this->removeUnusedBudgets($balance);
Log::debug('Return report.');
return $balance;
}
/**
* Create one balance line.
*
* @param BudgetLimit $budgetLimit
* @param Collection $accounts
*
* @return BalanceLine
*/
private function createBalanceLine(BudgetLimit $budgetLimit, Collection $accounts): BalanceLine
{
$line = new BalanceLine;
$line->setBudget($budgetLimit->budget);
$line->setBudgetLimit($budgetLimit);
// loop accounts:
foreach ($accounts as $account) {
$balanceEntry = new BalanceEntry;
$balanceEntry->setAccount($account);
$spent = $this->budgetRepository->spentInPeriod(
new Collection([$budgetLimit->budget]),
new Collection([$account]),
$budgetLimit->start_date,
$budgetLimit->end_date
);
$balanceEntry->setSpent($spent);
$line->addBalanceEntry($balanceEntry);
}
return $line;
}
/**
* Create a line for transactions without a budget.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return BalanceLine
*/
private function createNoBudgetLine(Collection $accounts, Carbon $start, Carbon $end): BalanceLine
{
$empty = new BalanceLine;
foreach ($accounts as $account) {
$spent = $this->budgetRepository->spentInPeriodWoBudget(new Collection([$account]), $start, $end);
// budget
$budgetEntry = new BalanceEntry;
$budgetEntry->setAccount($account);
$budgetEntry->setSpent($spent);
$empty->addBalanceEntry($budgetEntry);
}
return $empty;
}
/**
* Remove unused budgets from the report.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @param Balance $balance
*
* @return Balance
*/
private function removeUnusedBudgets(Balance $balance): Balance
{
$set = $balance->getBalanceLines();
$newSet = new Collection;
/** @var BalanceLine $entry */
foreach ($set as $entry) {
if (null !== $entry->getBudget()->id) {
$sum = '0';
/** @var BalanceEntry $balanceEntry */
foreach ($entry->getBalanceEntries() as $balanceEntry) {
$sum = bcadd($sum, $balanceEntry->getSpent());
}
if (bccomp($sum, '0') === -1) {
$newSet->push($entry);
}
continue;
}
$newSet->push($entry);
}
$balance->setBalanceLines($newSet);
return $balance;
return $report;
}
}

View File

@@ -38,7 +38,7 @@ interface BalanceReportHelperInterface
* @param Carbon $start
* @param Carbon $end
*
* @return Balance
* @return array
*/
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): Balance;
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): array;
}

View File

@@ -57,8 +57,8 @@ class BudgetReportHelper implements BudgetReportHelperInterface
/**
* Get the full budget report.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* TODO one big method is very complex.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
@@ -68,104 +68,147 @@ class BudgetReportHelper implements BudgetReportHelperInterface
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): array
{
$set = $this->repository->getBudgets();
$array = [];
$array = [
'budgets' => [],
'sums' => [],
];
/** @var Budget $budget */
foreach ($set as $budget) {
$budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end);
if (0 === $budgetLimits->count()) { // no budget limit(s) for this budget
$spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end); // spent for budget in time range
if (bccomp($spent, '0') === -1) {
$line = [
'type' => 'budget',
'id' => $budget->id,
'name' => $budget->name,
'budgeted' => '0',
'spent' => $spent,
'left' => '0',
'overspent' => '0',
$entry = [
'budget_id' => $budget->id,
'budget_name' => $budget->name,
'no_budget' => false,
'rows' => [],
];
// get multi currency expenses first:
$budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end);
$expenses = $this->repository->spentInPeriodMc(new Collection([$budget]), $accounts, $start, $end);
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($budget->user);
Log::debug(sprintf('Default currency for getBudgetReport is %s', $defaultCurrency->code));
if (0 === count($expenses)) {
// list the budget limits, basic amounts.
/** @var BudgetLimit $limit */
foreach ($budgetLimits as $limit) {
$currency = $limit->transactionCurrency ?? $defaultCurrency;
Log::debug(sprintf('Default currency for limit #%d is %s', $limit->id, $currency->code));
$row = [
'limit_id' => $limit->id,
'start_date' => $limit->start_date,
'end_date' => $limit->end_date,
'budgeted' => $limit->amount,
'spent' => '0',
'left' => $limit->amount,
'overspent' => null,
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
];
$array[] = $line;
$entry['rows'][] = $row;
}
continue;
}
/** @var BudgetLimit $budgetLimit */
foreach ($budgetLimits as $budgetLimit) { // one or more repetitions for budget
$data = $this->calculateExpenses($budget, $budgetLimit, $accounts);
$line = [
'type' => 'budget-line',
'start' => $budgetLimit->start_date,
'end' => $budgetLimit->end_date,
'limit' => $budgetLimit->id,
'id' => $budget->id,
'name' => $budget->name,
'budgeted' => (string)$budgetLimit->amount,
'spent' => $data['expenses'],
'left' => $data['left'],
'overspent' => $data['overspent'],
foreach ($expenses as $expense) {
$limit = $this->budgetLimitInCurrency($expense['currency_id'], $budgetLimits);
$row = [
'limit_id' => null,
'start_date' => null,
'end_date' => null,
'budgeted' => null,
'spent' => $expense['amount'],
'left' => null,
'overspent' => null,
'currency_id' => $expense['currency_id'],
'currency_code' => $expense['currency_name'],
'currency_name' => $expense['currency_name'],
'currency_symbol' => $expense['currency_symbol'],
'currency_decimal_places' => $expense['currency_decimal_places'],
];
$array[] = $line;
if (null !== $limit) {
// yes
$row['start_date'] = $limit->start_date;
$row['end_date'] = $limit->end_date;
$row['budgeted'] = $limit->amount;
$row['limit_id'] = $limit->id;
// less than zero? Set to 0.0
$row['left'] = -1 === bccomp(bcadd($limit->amount, $row['spent']), '0') ? '0' : bcadd($limit->amount, $row['spent']);
// spent > budgeted? then sum, otherwise other sum
$row['overspent'] = 1 === bccomp($row['spent'], $row['budgeted']) ? bcadd($row['spent'], $row['budgeted']) : '0';
}
$entry['rows'][] = $row;
}
$array['budgets'][] = $entry;
}
$noBudget = $this->repository->spentInPeriodWoBudget($accounts, $start, $end); // stuff outside of budgets
$line = [
'type' => 'no-budget',
'budgeted' => '0',
'spent' => $noBudget,
'left' => '0',
'overspent' => '0',
$noBudget = $this->repository->spentInPeriodWoBudgetMc($accounts, $start, $end);
$noBudgetEntry = [
'budget_id' => null,
'budget_name' => null,
'no_budget' => true,
'rows' => [],
];
$array[] = $line;
foreach ($noBudget as $row) {
$noBudgetEntry['rows'][] = [
'limit_id' => null,
'start_date' => null,
'end_date' => null,
'budgeted' => null,
'spent' => $row['amount'],
'left' => null,
'overspent' => null,
'currency_id' => $row['currency_id'],
'currency_code' => $row['currency_code'],
'currency_name' => $row['currency_name'],
'currency_symbol' => $row['currency_symbol'],
'currency_decimal_places' => $row['currency_decimal_places'],
];
}
$array['budgets'][] = $noBudgetEntry;
return $array;
}
/**
* Get all budgets and the expenses in these budgets.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Collection
*/
public function getBudgetsWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection
{
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$budgets = $repository->getActiveBudgets();
$set = new Collection;
/** @var Budget $budget */
foreach ($budgets as $budget) {
$total = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
if (bccomp($total, '0') === -1) {
$set->push($budget);
// fill sums:
/** @var array $budget */
foreach ($array['budgets'] as $budget) {
/** @var array $row */
foreach ($budget['rows'] as $row) {
$currencyId = $row['currency_id'];
$array['sums'][$currencyId] = $array['sums'][$currencyId] ?? [
'currency_id' => $row['currency_id'],
'currency_code' => $row['currency_code'],
'currency_name' => $row['currency_name'],
'currency_symbol' => $row['currency_symbol'],
'currency_decimal_places' => $row['currency_decimal_places'],
'budgeted' => '0',
'spent' => '0',
'left' => '0',
'overspent' => '0',
];
$array['sums'][$currencyId]['budgeted'] = bcadd($array['sums'][$currencyId]['budgeted'], $row['budgeted'] ?? '0');
$array['sums'][$currencyId]['spent'] = bcadd($array['sums'][$currencyId]['spent'], $row['spent'] ?? '0');
$array['sums'][$currencyId]['left'] = bcadd($array['sums'][$currencyId]['left'], $row['left'] ?? '0');
$array['sums'][$currencyId]['overspent'] = bcadd($array['sums'][$currencyId]['overspent'], $row['overspent'] ?? '0');
}
}
return $set;
return $array;
}
/**
* Calculate the expenses for a budget.
* Returns from the collection the budget limit with the indicated currency ID
*
* @param Budget $budget
* @param BudgetLimit $budgetLimit
* @param Collection $accounts
* @param int $currencyId
* @param Collection $budgetLimits
*
* @return array
* @return BudgetLimit|null
*/
private function calculateExpenses(Budget $budget, BudgetLimit $budgetLimit, Collection $accounts): array
private function budgetLimitInCurrency(int $currencyId, Collection $budgetLimits): ?BudgetLimit
{
$array = [];
$expenses = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $budgetLimit->start_date, $budgetLimit->end_date);
$array['left'] = 1 === bccomp(bcadd($budgetLimit->amount, $expenses), '0') ? bcadd($budgetLimit->amount, $expenses) : '0';
$array['spent'] = 1 === bccomp(bcadd($budgetLimit->amount, $expenses), '0') ? $expenses : '0';
$array['overspent'] = 1 === bccomp(bcadd($budgetLimit->amount, $expenses), '0') ? '0' : bcadd($expenses, $budgetLimit->amount);
$array['expenses'] = $expenses;
return $array;
return $budgetLimits->first(
static function (BudgetLimit $limit) use ($currencyId) {
return $limit->transaction_currency_id === $currencyId;
}
);
}
}

View File

@@ -40,15 +40,4 @@ interface BudgetReportHelperInterface
* @return array
*/
public function getBudgetReport(Carbon $start, Carbon $end, Collection $accounts): array;
/**
* Get budgets and the expenses in each budget.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return Collection
*/
public function getBudgetsWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection;
}

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