Compare commits

...

98 Commits

Author SHA1 Message Date
github-actions[bot]
dcf20a472a Merge pull request #10772 from firefly-iii/release-1755424214
🤖 Automatically merge the PR into the develop branch.
2025-08-17 11:50:24 +02:00
JC5
7bd528defe 🤖 Auto commit for release 'develop' on 2025-08-17 2025-08-17 11:50:14 +02:00
James Cole
9e6d123165 Fix #10771 2025-08-17 11:46:03 +02:00
James Cole
c592f51c83 Fix bad call. 2025-08-17 11:37:58 +02:00
James Cole
fbb6f30366 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2025-08-17 11:37:07 +02:00
James Cole
4546c721fb Merge branch 'main' into develop 2025-08-17 11:37:01 +02:00
github-actions[bot]
3a659c9a81 Merge pull request #10770 from firefly-iii/release-1755423290
🤖 Automatically merge the PR into the develop branch.
2025-08-17 11:34:58 +02:00
JC5
e28a988eb3 🤖 Auto commit for release 'develop' on 2025-08-17 2025-08-17 11:34:50 +02:00
James Cole
a29742fe1f Never mind lol. 2025-08-17 11:31:03 +02:00
James Cole
dd06838eec Reshuffle dependencies. 2025-08-17 11:27:36 +02:00
James Cole
5eb828bff8 Force order. But I think steps need dependencies, not jobs. 2025-08-17 11:24:16 +02:00
James Cole
c7f3701053 Add command to see where we end up. 2025-08-17 11:22:51 +02:00
James Cole
ab6799442c Fix job again. 2025-08-17 11:19:20 +02:00
James Cole
1fe9bf7d76 Clean up job. 2025-08-17 11:18:48 +02:00
James Cole
bd14797da6 Fix dependencies. 2025-08-17 11:16:55 +02:00
James Cole
93b4e6a8d0 Update build job. 2025-08-17 11:15:18 +02:00
github-actions[bot]
5566671971 Merge pull request #10769 from firefly-iii/release-1755421680
🤖 Automatically merge the PR into the develop branch.
2025-08-17 11:08:07 +02:00
JC5
defcc7a00c 🤖 Auto commit for release 'develop' on 2025-08-17 2025-08-17 11:08:00 +02:00
James Cole
5183de634b Fix #10768 2025-08-17 11:03:20 +02:00
James Cole
7771b0311c Expand webhook options, allow for budgets. 2025-08-17 07:40:19 +02:00
github-actions[bot]
52abe3bbc2 Merge pull request #10765 from firefly-iii/develop
🤖 Automatically merge the PR into the main branch.
2025-08-16 19:54:36 +02:00
github-actions[bot]
34db9f41c2 Merge pull request #10764 from firefly-iii/release-1755366862
🤖 Automatically merge the PR into the develop branch.
2025-08-16 19:54:31 +02:00
JC5
72c31fbe6a 🤖 Auto commit for release 'v6.3.0' on 2025-08-16 2025-08-16 19:54:22 +02:00
github-actions[bot]
1d8dd41564 Merge pull request #10763 from firefly-iii/release-1755365805
🤖 Automatically merge the PR into the develop branch.
2025-08-16 19:36:56 +02:00
JC5
3409240a19 🤖 Auto commit for release 'develop' on 2025-08-16 2025-08-16 19:36:45 +02:00
James Cole
eccc58e75a Add piggy bank tests. 2025-08-16 19:31:59 +02:00
James Cole
24098f35bb Fix some commands. 2025-08-16 15:04:15 +02:00
James Cole
e7d9dc57d8 Add some tests. 2025-08-16 14:52:29 +02:00
James Cole
f04ed5b8f0 Restore and fix API tests 2025-08-16 14:10:24 +02:00
James Cole
8bd44f429b Merge pull request #10762 from firefly-iii/JC5-patch-1
Update lock.yml
2025-08-16 10:26:21 +02:00
James Cole
fb7866b165 Update lock.yml
Signed-off-by: James Cole <james@firefly-iii.org>
2025-08-16 10:26:09 +02:00
James Cole
98db6db1eb Fix references to charts. 2025-08-16 08:28:10 +02:00
James Cole
0a235ec523 Optimize category chart. 2025-08-16 06:34:28 +02:00
github-actions[bot]
cb4f7ad0a8 Merge pull request #10761 from firefly-iii/release-1755317595
🤖 Automatically merge the PR into the develop branch.
2025-08-16 06:13:25 +02:00
JC5
91ce1d3b88 🤖 Auto commit for release 'develop' on 2025-08-16 2025-08-16 06:13:15 +02:00
James Cole
8f9ab150ee Add command to reset rate limit for error emails. 2025-08-16 06:08:01 +02:00
James Cole
8d52f83b4f Fix nulls. 2025-08-16 06:02:26 +02:00
James Cole
fb19739b54 Fix missing enrichment. 2025-08-16 05:58:58 +02:00
James Cole
acd4f28ae3 Restore "default" API endpoint so data importer does not fail. 2025-08-15 21:37:49 +02:00
James Cole
e4d443db50 Remove some unused comments. 2025-08-15 21:10:30 +02:00
James Cole
fe9d36cd27 Clean up a variety of end points. 2025-08-15 20:06:28 +02:00
James Cole
a916cc7e78 Rename command. 2025-08-15 20:00:29 +02:00
James Cole
77d15f884b Extend acceptedRoles to chart controllers. 2025-08-15 19:57:32 +02:00
James Cole
ab773c9052 Extend acceptedRoles array in AC controllers. 2025-08-15 19:50:12 +02:00
James Cole
87d292ca27 Rename method from default to primary. 2025-08-15 14:33:14 +02:00
James Cole
946e272d1c Update changelog and templates. 2025-08-15 13:46:41 +02:00
github-actions[bot]
ffe2e310aa Merge pull request #10760 from firefly-iii/develop
🤖 Automatically merge the PR into the main branch.
2025-08-15 13:43:40 +02:00
github-actions[bot]
9fc6af0f2d Merge pull request #10759 from firefly-iii/release-1755258209
🤖 Automatically merge the PR into the develop branch.
2025-08-15 13:43:35 +02:00
JC5
71807b67fc 🤖 Auto commit for release 'v6.3.0-beta.2' on 2025-08-15 2025-08-15 13:43:29 +02:00
github-actions[bot]
ab61d0ce21 Merge pull request #10758 from firefly-iii/release-1755257846
🤖 Automatically merge the PR into the develop branch.
2025-08-15 13:37:34 +02:00
JC5
f2dc0d234b 🤖 Auto commit for release 'develop' on 2025-08-15 2025-08-15 13:37:27 +02:00
James Cole
4885dbc78e Fix currency exchange rate UI. 2025-08-15 13:33:22 +02:00
James Cole
0e29e282df Fix translations. 2025-08-15 11:38:25 +02:00
James Cole
0b3fd335ad Fix other endpoint. 2025-08-15 11:35:16 +02:00
James Cole
9b2263c7bb Match exchange rate API with API docs. 2025-08-15 11:28:23 +02:00
James Cole
1305fafd38 Add multi-currency for budget chart 2025-08-15 07:50:13 +02:00
James Cole
844b8d48c4 Update category overview to be multi-currency aware. 2025-08-15 07:44:14 +02:00
James Cole
fc9ef290f1 Clean up API endpoints. 2025-08-15 07:11:34 +02:00
James Cole
020c8ad933 Clean up and expand templates. 2025-08-13 10:15:36 +02:00
James Cole
33ea27b411 Fix template 2025-08-13 08:03:59 +02:00
James Cole
b39e3e5965 Expand template. 2025-08-13 07:56:31 +02:00
James Cole
ba7e504f12 Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2025-08-13 07:54:53 +02:00
James Cole
a732ce2a20 Merge branch 'main' into develop
# Conflicts:
#	.github/workflows/release.yml
2025-08-13 07:54:44 +02:00
James Cole
2b76c4801f Remove steps no longer necessary. 2025-08-13 07:54:15 +02:00
github-actions[bot]
dd09dd59e9 Merge pull request #10752 from firefly-iii/release-1755064372
🤖 Automatically merge the PR into the develop branch.
2025-08-13 07:53:05 +02:00
JC5
d56088d086 🤖 Auto commit for release 'develop' on 2025-08-13 2025-08-13 07:52:52 +02:00
James Cole
f27f00cfa0 Change command. 2025-08-13 07:48:29 +02:00
James Cole
d762136e0b Clean up action. 2025-08-13 07:46:02 +02:00
James Cole
536cd78e29 Templates for new releases. 2025-08-13 07:43:11 +02:00
James Cole
5ef0889f50 Lol lets remove this file. 2025-08-12 20:45:42 +02:00
James Cole
c2ffedb506 Remove link. 2025-08-12 20:44:58 +02:00
github-actions[bot]
fe702a3030 Merge pull request #10751 from firefly-iii/develop
🤖 Automatically merge the PR into the main branch.
2025-08-12 20:27:03 +02:00
github-actions[bot]
2244d366bd Merge pull request #10750 from firefly-iii/release-1755023209
🤖 Automatically merge the PR into the develop branch.
2025-08-12 20:26:57 +02:00
JC5
ac16e0294e 🤖 Auto commit for release 'v6.3.0-beta.1' on 2025-08-12 2025-08-12 20:26:49 +02:00
github-actions[bot]
bf1b0ee3c2 Merge pull request #10749 from firefly-iii/release-1755022724
🤖 Automatically merge the PR into the develop branch.
2025-08-12 20:18:52 +02:00
JC5
ffec4bbfba 🤖 Auto commit for release 'develop' on 2025-08-12 2025-08-12 20:18:44 +02:00
James Cole
ae6e103c09 Fix translation. 2025-08-12 20:13:48 +02:00
James Cole
99d4471f75 Merge branch 'main' into develop 2025-08-11 19:19:22 +02:00
James Cole
7f1fb72298 Merge pull request #10744 from firefly-iii/dependabot/github_actions/github/command-2.0.2
Bump github/command from 2.0.1 to 2.0.2
2025-08-11 09:43:28 +02:00
dependabot[bot]
009c2ed5d9 Bump github/command from 2.0.1 to 2.0.2
Bumps [github/command](https://github.com/github/command) from 2.0.1 to 2.0.2.
- [Release notes](https://github.com/github/command/releases)
- [Commits](https://github.com/github/command/compare/v2.0.1...v2.0.2)

---
updated-dependencies:
- dependency-name: github/command
  dependency-version: 2.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-11 05:23:27 +00:00
github-actions[bot]
44fc00299c Merge pull request #10742 from firefly-iii/release-1754883400
🤖 Automatically merge the PR into the develop branch.
2025-08-11 05:36:47 +02:00
JC5
774fc4281c 🤖 Auto commit for release 'develop' on 2025-08-11 2025-08-11 05:36:40 +02:00
github-actions[bot]
c47955c069 Merge pull request #10741 from firefly-iii/release-1754821000
🤖 Automatically merge the PR into the develop branch.
2025-08-10 12:16:47 +02:00
JC5
e7569644f7 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 12:16:41 +02:00
James Cole
c567474043 Optimize balance collection. 2025-08-10 12:12:30 +02:00
github-actions[bot]
9f394e92fe Merge pull request #10740 from firefly-iii/release-1754804137
🤖 Automatically merge the PR into the develop branch.
2025-08-10 07:35:46 +02:00
JC5
66befc7e44 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 07:35:37 +02:00
James Cole
c3a28fc698 Fix three years ago. 2025-08-10 07:31:10 +02:00
github-actions[bot]
ef317d5b3c Merge pull request #10739 from firefly-iii/release-1754802161
🤖 Automatically merge the PR into the develop branch.
2025-08-10 07:02:58 +02:00
JC5
152301f9ee 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 07:02:41 +02:00
James Cole
645e9ba1f7 Go back 3 years max. 2025-08-10 06:58:06 +02:00
James Cole
56487c3a33 Fix equation. 2025-08-10 06:54:04 +02:00
James Cole
b8062a915c Fix equation. 2025-08-10 06:53:21 +02:00
James Cole
5780c9512a Optimize convert all balances. 2025-08-10 06:53:08 +02:00
github-actions[bot]
71d39707d9 Merge pull request #10738 from firefly-iii/release-1754800979
🤖 Automatically merge the PR into the develop branch.
2025-08-10 06:43:10 +02:00
JC5
9ccb8ae692 🤖 Auto commit for release 'develop' on 2025-08-10 2025-08-10 06:42:59 +02:00
James Cole
8cd50bb5bd Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop 2025-08-10 06:38:34 +02:00
James Cole
ae9e1278e5 Expand some timers, fix reports. 2025-08-10 06:38:23 +02:00
179 changed files with 5683 additions and 4547 deletions

View File

@@ -345,16 +345,16 @@
},
{
"name": "fidry/cpu-core-counter",
"version": "1.2.0",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/theofidry/cpu-core-counter.git",
"reference": "8520451a140d3f46ac33042715115e290cf5785f"
"reference": "db9508f7b1474469d9d3c53b86f817e344732678"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f",
"reference": "8520451a140d3f46ac33042715115e290cf5785f",
"url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678",
"reference": "db9508f7b1474469d9d3c53b86f817e344732678",
"shasum": ""
},
"require": {
@@ -364,10 +364,10 @@
"fidry/makefile": "^0.2.0",
"fidry/php-cs-fixer-config": "^1.1.2",
"phpstan/extension-installer": "^1.2.0",
"phpstan/phpstan": "^1.9.2",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.2.2",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^8.5.31 || ^9.5.26",
"webmozarts/strict-phpunit": "^7.5"
},
@@ -394,7 +394,7 @@
],
"support": {
"issues": "https://github.com/theofidry/cpu-core-counter/issues",
"source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0"
"source": "https://github.com/theofidry/cpu-core-counter/tree/1.3.0"
},
"funding": [
{
@@ -402,20 +402,20 @@
"type": "github"
}
],
"time": "2024-08-06T10:04:20+00:00"
"time": "2025-08-14T07:29:31+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v3.85.1",
"version": "v3.86.0",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "2fb6d7f6c3398dca5786a1635b27405d73a417ba"
"reference": "4a952bd19dc97879b0620f495552ef09b55f7d36"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/2fb6d7f6c3398dca5786a1635b27405d73a417ba",
"reference": "2fb6d7f6c3398dca5786a1635b27405d73a417ba",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/4a952bd19dc97879b0620f495552ef09b55f7d36",
"reference": "4a952bd19dc97879b0620f495552ef09b55f7d36",
"shasum": ""
},
"require": {
@@ -499,7 +499,7 @@
],
"support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.85.1"
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.86.0"
},
"funding": [
{
@@ -507,7 +507,7 @@
"type": "github"
}
],
"time": "2025-07-29T22:22:50+00:00"
"time": "2025-08-13T22:36:21+00:00"
},
{
"name": "psr/container",

View File

@@ -1,6 +1,6 @@
parameters:
scanFiles:
- ../_ide_helper
- ../_ide_helper.php
paths:
- ../app
- ../database

21
.github/release-notes/alpha.md vendored Normal file
View File

@@ -0,0 +1,21 @@
Welcome to release %version of Firefly III. This **alpha** release contains the latest fixes, translations and features. It is probably buggy and may not work as expected. You can download the release below, and adventurous Docker users can find this release under the `alpha` tag.
> [!WARNING]
> Please be careful with this alpha release, as it may not work as expected.
Alpha releases are created to test new features and fixes before they are included in a stable release. They are not recommended for production use. This release was created on %date and may contain unexpected bugs. Data loss is rare but possible.
## Changelog (not final)
%changelog
## Installation and upgrade instructions
* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/).
* Alternatively, read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)
The release files are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/).
## Support Firefly III
Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. Please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information. Thank you for your consideration.

21
.github/release-notes/beta.md vendored Normal file
View File

@@ -0,0 +1,21 @@
Welcome to release %version of Firefly III. This **beta** release contains the latest fixes, translations and features. It may be buggy, nor work as expected. You can download the release below, and adventurous Docker users can find this release under the `beta` tag.
> [!WARNING]
> Please be careful with this beta release, as it may not work as expected.
Alpha releases are created to test new features and fixes before they are included in a stable release. They are not recommended for production use. This release was created on %date and may contain unexpected bugs. Data loss is rare but possible.
## Changelog (not final)
%changelog
## Installation and upgrade instructions
* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/).
* Alternatively, read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)
The release files are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/).
## Support Firefly III
Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. Please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information. Thank you for your consideration.

21
.github/release-notes/branch.md vendored Normal file
View File

@@ -0,0 +1,21 @@
Welcome to release %version of Firefly III. This branch-related release contains the latest fixes, translations and features. It is probably buggy and may not work as expected. You can download the release below, and adventurous Docker users can find this release under the `branch-*` tag.
> [!WARNING]
> Please be careful with this branch release, as it may not work as expected.
Branch releases are created to test large new features that are developed alongside the normal release flow. They are not recommended for production use. This release was created on %date and may contain unexpected bugs. Data loss is rare but possible.
## Changelog
There is no changelog for this release, as it is not final. However, [changelog.md](https://github.com/firefly-iii/firefly-iii/blob/develop/changelog.md) may already contain entries for the future release that this branch will be a part of.
## Installation and upgrade instructions
* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/).
* Alternatively, read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)
The release files are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/).
## Support Firefly III
Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. Please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information. Thank you for your consideration.

21
.github/release-notes/develop.md vendored Normal file
View File

@@ -0,0 +1,21 @@
Welcome to the latest development release of Firefly III. This test release contains the absolute latest fixes, translations and features. It is probably buggy and may not work as expected. You can download the release below, and adventurous Docker users can find this release under the `develop` tag.
> [!WARNING]
> Please be careful with this pre-release, as it may not work as expected.
This release was created on %date and may contain unexpected bugs. Data loss is rare but possible.
## Changelog
The changelog for this release may not be up-to-date, so it is not included. However, [changelog.md](https://github.com/firefly-iii/firefly-iii/blob/develop/changelog.md) may already contain entries for the future release.
## Installation and upgrade instructions
* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/).
* Alternatively, read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)
The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/).
## Support Firefly III
Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. Please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information. Thank you for your consideration.

16
.github/release-notes/release.md vendored Normal file
View File

@@ -0,0 +1,16 @@
Welcome to release %version of Firefly III. It contains the latest fixes, translations and features. Docker users can find this release under the `latest` tag.
## Changelog
%changelog
## Installation and upgrade instructions
* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/).
* Alternatively, read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)
The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/).
## Support Firefly III
Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. Please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information. Thank you for your consideration.

View File

@@ -13,7 +13,7 @@ jobs:
close_duplicates:
runs-on: ubuntu-latest
steps:
- uses: github/command@v2.0.1
- uses: github/command@v2.0.2
id: command
with:
allowed_contexts: "issue"

View File

@@ -21,7 +21,7 @@ jobs:
discussions: write
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v5
- uses: JC5/lock-threads@v6.0.2
with:
issue-inactive-days: 21
pr-inactive-days: 21

View File

@@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Import GPG key
@@ -233,122 +233,15 @@ jobs:
git push
env:
version: ${{ github.event_name == 'schedule' && 'develop' || github.event.inputs.version }}
- name: Extract changelog
id: extract-changelog
- name: Generate release description
id: release-description
uses: JC5/firefly-iii-dev@main
with:
action: 'ff3:extract-changelog'
action: "ff3:generate-release-notes firefly-iii ${{ github.event.inputs.version }}"
output: 'output'
env:
FIREFLY_III_ROOT: /github/workspace
GH_TOKEN: ""
- name: Describe new release
run: |
# describe the development release.
if [[ "develop" == "$version" ]]; then
echo 'Describe the latest develop release'
rm -f output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Weekly development release of Firefly III with the latest fixes, translations and features. Docker users can find this release under the \`develop\` tag." >> output.txt
echo "" >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d %H:%M')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo "" >> output.txt
echo "* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "" >> output.txt
echo ":warning: Please be careful with this pre-release, as it may not work as expected." >> output.txt
# donations!
echo '' >> output.txt
echo '### Support Firefly III' >> output.txt
echo 'Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. For more information, please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information.' >> output.txt
echo '' >> output.txt
fi
# describe a branch release
if [[ "$version" == branch* ]]; then
echo 'Describe a branch release'
rm -f output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Irregular BRANCH release of Firefly III. This release contains specific features or changes. Docker users can find this release under the \`$version\` tag." >> output.txt
echo "" >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d %H:%M')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo "" >> output.txt
echo "* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "" >> output.txt
echo ":warning: Please be careful with this branch pre-release, as it may not work as expected." >> output.txt
fi
# describe the main release
if [[ "develop" != "$version" ]] && [[ "$version" != branch* ]] && [[ "$version" != *alpha* ]] && [[ "$version" != *beta* ]]; then
echo 'Describe the latest release'
sudo chown -R runner:docker output.txt
# the changelog is in output.txt
mv output.txt output2.txt
touch output.txt
echo '' >> output.txt
echo "Welcome to release $version of Firefly III. It contains the the latest fixes, translations and features. Docker users can find this release under the \`latest\` tag." >> output.txt
echo '' >> output.txt
# add changelog to file.
cat output2.txt >> output.txt
echo '' >> output.txt
rm -f output2.txt
echo '### Instructions' >> output.txt
echo '' >> output.txt
echo "* Installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "* The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
# donations!
echo '' >> output.txt
echo '### Support Firefly III' >> output.txt
echo 'Did you know you can support the development of Firefly III? You can donate in many ways, like GitHub Sponsors or Patreon. For more information, please [follow this link](https://bit.ly/donate-to-Firefly-III) for more information.' >> output.txt
echo '' >> output.txt
fi
# describe alpha release
if [[ "$version" == *alpha* ]]; then
echo 'Describe an ALPHA release'
rm -f output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Very early ALPHA release of Firefly III. This release contains specific features or changes. Docker users can find this release under the \`$version\` tag." >> output.txt
echo '' >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d %H:%M')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo '' >> output.txt
echo '### Instructions' >> output.txt
echo '' >> output.txt
echo "* Installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "* The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
fi
# describe beta release
if [[ "$version" == *beta* ]]; then
echo 'Describe a BETA release'
rm -f output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Very early BETA release of Firefly III. This release contains specific features or changes. Docker users can find this release under the \`$version\` tag." >> output.txt
echo '' >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d %H:%M')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo '' >> output.txt
echo '### Instructions' >> output.txt
echo '' >> output.txt
echo "* Installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "* The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
fi
env:
version: ${{ github.event_name == 'schedule' && 'develop' || github.event.inputs.version }}
- name: Merge all into working branch
run: |
MERGE_INTO=develop

View File

@@ -27,6 +27,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -34,7 +35,6 @@ use FireflyIII\Support\Debug\Timer;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
@@ -46,7 +46,8 @@ class AccountController extends Controller
use AccountFilter;
// this array only exists to test if the constructor will use it properly.
protected array $accepts = ['application/json', 'application/vnd.api+json'];
protected array $accepts = ['application/json', 'application/vnd.api+json'];
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/** @var array<int, string> */
private array $balanceTypes;
@@ -60,10 +61,10 @@ class AccountController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}
@@ -85,7 +86,8 @@ class AccountController extends Controller
$query = $data['query'];
$date = $data['date'] ?? today(config('app.timezone'));
$return = [];
Timer::start(sprintf('AC accounts "%s"', $query));
$timer = Timer::getInstance();
$timer->start(sprintf('AC accounts "%s"', $query));
$result = $this->repository->searchAccount((string) $query, $types, $this->parameters->get('limit'));
// set date to subday + end-of-day for account balance. so it is at $date 23:59:59
@@ -137,7 +139,7 @@ class AccountController extends Controller
return $posA - $posB;
}
);
Timer::stop(sprintf('AC accounts "%s"', $query));
$timer->stop(sprintf('AC accounts "%s"', $query));
return response()->api($return);
}

View File

@@ -26,9 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -37,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class BillController extends Controller
{
private BillRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_SUBSCRIPTIONS];
/**
* BillController constructor.
@@ -46,10 +47,10 @@ class BillController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}

View File

@@ -26,9 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -37,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class BudgetController extends Controller
{
private BudgetRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_BUDGETS];
/**
* BudgetController constructor.
@@ -46,10 +47,10 @@ class BudgetController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(BudgetRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}

View File

@@ -26,9 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -37,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class CategoryController extends Controller
{
private CategoryRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* CategoryController constructor.
@@ -46,10 +47,10 @@ class CategoryController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}

View File

@@ -27,9 +27,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use Deprecated;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -38,6 +38,7 @@ use Illuminate\Http\JsonResponse;
class CurrencyController extends Controller
{
private CurrencyRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* CurrencyController constructor.
@@ -47,10 +48,10 @@ class CurrencyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(CurrencyRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}

View File

@@ -26,9 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -37,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class ObjectGroupController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* CurrencyController constructor.
@@ -46,10 +47,10 @@ class ObjectGroupController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(ObjectGroupRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}

View File

@@ -26,10 +26,10 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -39,6 +39,7 @@ class PiggyBankController extends Controller
{
private AccountRepositoryInterface $accountRepository;
private PiggyBankRepositoryInterface $piggyRepository;
protected array $acceptedRoles = [UserRoleEnum::READ_PIGGY_BANKS];
/**
* PiggyBankController constructor.
@@ -48,22 +49,19 @@ class PiggyBankController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->piggyRepository = app(PiggyBankRepositoryInterface::class);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->piggyRepository->setUser($user);
$this->accountRepository->setUser($user);
$this->piggyRepository->setUser($this->user);
$this->piggyRepository->setUserGroup($this->userGroup);
$this->accountRepository->setUser($this->user);
$this->accountRepository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getPiggiesAC
*/
public function piggyBanks(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
@@ -90,10 +88,6 @@ class PiggyBankController extends Controller
return response()->api($response);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getPiggiesBalanceAC
*/
public function piggyBanksWithBalance(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Http\JsonResponse;
@@ -36,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class RecurrenceController extends Controller
{
private RecurringRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_RECURRING];
/**
* RecurrenceController constructor.
@@ -45,19 +47,16 @@ class RecurrenceController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser(auth()->user());
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getRecurringAC
*/
public function recurring(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use Illuminate\Http\JsonResponse;
@@ -36,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class RuleController extends Controller
{
private RuleRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_RULES];
/**
* RuleController constructor.
@@ -45,18 +47,16 @@ class RuleController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(RuleRepositoryInterface::class);
$this->repository->setUser(auth()->user());
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getRulesAC
*/
public function rules(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use Illuminate\Http\JsonResponse;
@@ -36,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class RuleGroupController extends Controller
{
private RuleGroupRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_RULES];
/**
* RuleGroupController constructor.
@@ -45,18 +47,16 @@ class RuleGroupController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(RuleGroupRepositoryInterface::class);
$this->repository->setUser(auth()->user());
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getRuleGroupsAC
*/
public function ruleGroups(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -26,9 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -37,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class TagController extends Controller
{
private TagRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* TagController constructor.
@@ -46,20 +47,16 @@ class TagController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->validateUserGroup($request);
$this->repository = app(TagRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getTagAC
*/
public function tags(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -31,7 +31,6 @@ use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
@@ -52,24 +51,19 @@ class TransactionController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$userGroup = $this->validateUserGroup($request);
$this->validateUserGroup($request);
$this->repository = app(JournalRepositoryInterface::class);
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
$this->repository->setUser($user);
$this->groupRepository->setUser($user);
$this->groupRepository->setUserGroup($userGroup);
$this->repository->setUser($this->user);
$this->repository->setUserGroup($this->userGroup);
$this->groupRepository->setUser($this->user);
$this->groupRepository->setUserGroup($this->userGroup);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getTransactionsAC
*/
public function transactions(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
@@ -92,10 +86,6 @@ class TransactionController extends Controller
return response()->api($array);
}
/**
* This endpoint is documented at:
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getTransactionsIDAC
*/
public function transactionsWithID(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
use Illuminate\Http\JsonResponse;
@@ -36,6 +37,7 @@ use Illuminate\Http\JsonResponse;
class TransactionTypeController extends Controller
{
private TransactionTypeRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* TransactionTypeController constructor.
@@ -45,6 +47,7 @@ class TransactionTypeController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(TransactionTypeRepositoryInterface::class);
return $next($request);
@@ -52,10 +55,6 @@ class TransactionTypeController extends Controller
);
}
/**
* This endpoint is documented at
* * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/autocomplete/getTransactionTypesAC
*/
public function transactionTypes(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();

View File

@@ -24,23 +24,17 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Chart\ChartRequest;
use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Exceptions\ValidationException;
use FireflyIII\Models\Account;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Chart\ChartData;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Api\ApiSupport;
use FireflyIII\Support\Http\Api\CleansChartData;
use FireflyIII\Support\Http\Api\CollectsAccountsFromFilter;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
@@ -50,9 +44,12 @@ use Illuminate\Support\Facades\Log;
class AccountController extends Controller
{
use ApiSupport;
use CleansChartData;
use CollectsAccountsFromFilter;
private ChartData $chartData;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
private array $chartData = [];
private AccountRepositoryInterface $repository;
/**
@@ -63,11 +60,10 @@ class AccountController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->chartData = new ChartData();
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser($user);
$this->validateUserGroup($request);
$this->repository->setUserGroup($this->userGroup);
$this->repository->setUser($this->user);
return $next($request);
}
@@ -75,11 +71,9 @@ class AccountController extends Controller
}
/**
* TODO fix documentation
*
* @throws FireflyException
*/
public function dashboard(ChartRequest $request): JsonResponse
public function overview(ChartRequest $request): JsonResponse
{
$queryParameters = $request->getParameters();
$accounts = $this->getAccountList($queryParameters);
@@ -87,7 +81,7 @@ class AccountController extends Controller
// move date to end of day
$queryParameters['start']->startOfDay();
$queryParameters['end']->endOfDay();
Log::debug(sprintf('dashboard(), convert to primary: %s', var_export($this->convertToPrimary, true)));
// Log::debug(sprintf('dashboard(), convert to primary: %s', var_export($this->convertToPrimary, true)));
// loop each account, and collect info:
/** @var Account $account */
@@ -96,7 +90,7 @@ class AccountController extends Controller
$this->renderAccountData($queryParameters, $account);
}
return response()->json($this->chartData->render());
return response()->json($this->clean($this->chartData));
}
/**
@@ -105,29 +99,35 @@ class AccountController extends Controller
private function renderAccountData(array $params, Account $account): void
{
Log::debug(sprintf('Now in %s(array, #%d)', __METHOD__, $account->id));
$currency = $this->repository->getAccountCurrency($account);
$currentStart = clone $params['start'];
$range = Steam::finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToPrimary);
$currency = $this->repository->getAccountCurrency($account);
$currentStart = clone $params['start'];
$range = Steam::finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToPrimary);
$previous = array_values($range)[0]['balance'];
$pcPrevious = null;
$previous = array_values($range)[0]['balance'];
$pcPrevious = null;
if (!$currency instanceof TransactionCurrency) {
$currency = $this->default;
$currency = $this->primaryCurrency;
}
$currentSet = [
$currentSet = [
'label' => $account->name,
// the currency that belongs to the account.
'currency_id' => (string)$currency->id,
'currency_name' => $currency->name,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
// the primary currency
'primary_currency_id' => (string)$this->primaryCurrency->id,
// the default currency of the user (could be the same!)
'date' => $params['start']->toAtomString(),
'start' => $params['start']->toAtomString(),
'end' => $params['end']->toAtomString(),
'start_date' => $params['start']->toAtomString(),
'end_date' => $params['end']->toAtomString(),
'type' => 'line',
'yAxisID' => 0,
'period' => '1D',
'entries' => [],
];
@@ -159,106 +159,6 @@ class AccountController extends Controller
$currentStart->addDay();
}
$this->chartData->add($currentSet);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/charts/getChartAccountOverview
*
* @throws ValidationException
*/
public function overview(DateRequest $request): JsonResponse
{
// parameters for chart:
$dates = $request->getAll();
/** @var Carbon $start */
$start = $dates['start'];
/** @var Carbon $end */
$end = $dates['end'];
// set dates to end of day + start of day:
$start->startOfDay();
$end->endOfDay();
$frontPageIds = $this->getFrontPageAccountIds();
$accounts = $this->repository->getAccountsById($frontPageIds);
$chartData = [];
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Rendering chart data for account %s (%d)', $account->name, $account->id));
$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;
$currentStart = clone $start;
$range = Steam::finalAccountBalanceInRange($account, $start, clone $end, $this->convertToPrimary);
$previous = array_values($range)[0]['balance'];
$pcPrevious = null;
$currentSet = [
'label' => $account->name,
'currency_id' => (string)$currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'start_date' => $start->toAtomString(),
'end_date' => $end->toAtomString(),
'type' => 'line', // line, area or bar
'yAxisID' => 0, // 0, 1, 2
'entries' => [],
];
// add "pc_entries" if convertToPrimary is true:
if ($this->convertToPrimary) {
$currentSet['pc_entries'] = [];
$currentSet['primary_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['primary_currency_code'] = $this->primaryCurrency->code;
$currentSet['primary_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['primary_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$pcPrevious = array_values($range)[0]['pc_balance'];
}
// also get the primary balance if convertToPrimary is true:
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->toAtomString();
// balance is based on "balance" from the $range variable.
$balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
$previous = $balance;
$currentSet['entries'][$label] = $balance;
// do the same for the primary balance, if relevant:
$pcBalance = null;
if ($this->convertToPrimary) {
$pcBalance = array_key_exists($format, $range) ? $range[$format]['pc_balance'] : $pcPrevious;
$pcPrevious = $pcBalance;
$currentSet['pc_entries'][$label] = $pcBalance;
}
$currentStart->addDay();
}
$chartData[] = $currentSet;
}
return response()->json($chartData);
}
private function getFrontPageAccountIds(): array
{
$defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
/** @var Preference $frontpage */
$frontpage = Preferences::get('frontpageAccounts', $defaultSet);
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
$frontpage->data = $defaultSet;
$frontpage->save();
}
return $frontpage->data ?? $defaultSet;
$this->chartData[] = $currentSet;
}
}

View File

@@ -7,11 +7,11 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Chart\ChartRequest;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Chart\ChartData;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Http\Api\AccountBalanceGrouped;
use FireflyIII\Support\Http\Api\CleansChartData;
@@ -25,8 +25,9 @@ class BalanceController extends Controller
{
use CleansChartData;
use CollectsAccountsFromFilter;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
private ChartData $chartData;
private array $chartData = [];
private GroupCollectorInterface $collector;
private AccountRepositoryInterface $repository;
@@ -37,13 +38,13 @@ class BalanceController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(AccountRepositoryInterface::class);
$this->collector = app(GroupCollectorInterface::class);
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
$this->collector->setUserGroup($userGroup);
$this->chartData = new ChartData();
// $this->default = app('amount')->getPrimaryCurrency();
$this->repository->setUserGroup($this->userGroup);
$this->collector->setUserGroup($this->userGroup);
$this->repository->setUser($this->user);
$this->collector->setUser($this->user);
return $next($request);
}
@@ -66,10 +67,6 @@ class BalanceController extends Controller
$queryParameters = $request->getParameters();
$accounts = $this->getAccountList($queryParameters);
// prepare for currency conversion and data collection:
/** @var TransactionCurrency $primary */
$primary = Amount::getPrimaryCurrency();
// get journals for entire period:
$this->collector->setRange($queryParameters['start'], $queryParameters['end'])
@@ -81,7 +78,7 @@ class BalanceController extends Controller
$object = new AccountBalanceGrouped();
$object->setPreferredRange($queryParameters['period']);
$object->setPrimary($primary);
$object->setPrimary($this->primaryCurrency);
$object->setAccounts($accounts);
$object->setJournals($journals);
$object->setStart($queryParameters['start']);
@@ -89,9 +86,10 @@ class BalanceController extends Controller
$object->groupByCurrencyAndPeriod();
$data = $object->convertToChartData();
foreach ($data as $entry) {
$this->chartData->add($entry);
$this->chartData[] = $entry;
}
$this->chartData = $this->clean($this->chartData);
return response()->json($this->chartData->render());
return response()->json($this->chartData);
}
}

View File

@@ -26,7 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Api\V1\Requests\Data\SameDateRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
@@ -63,13 +63,16 @@ class BudgetController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
$this->opsRepository->setUserGroup($userGroup);
$this->blRepository->setUserGroup($userGroup);
$this->repository->setUserGroup($this->userGroup);
$this->opsRepository->setUserGroup($this->userGroup);
$this->blRepository->setUserGroup($this->userGroup);
$this->repository->setUser($this->user);
$this->opsRepository->setUser($this->user);
$this->blRepository->setUser($this->user);
return $next($request);
}
@@ -81,7 +84,7 @@ class BudgetController extends Controller
*
* @throws FireflyException
*/
public function dashboard(DateRequest $request): JsonResponse
public function overview(SameDateRequest $request): JsonResponse
{
$params = $request->getAll();
@@ -110,10 +113,12 @@ class BudgetController extends Controller
private function processBudget(Budget $budget, Carbon $start, Carbon $end): array
{
// get all limits:
$limits = $this->blRepository->getBudgetLimits($budget, $start, $end);
$rows = [];
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
$expenses = $this->processExpenses($budget->id, $spent, $start, $end);
$limits = $this->blRepository->getBudgetLimits($budget, $start, $end);
$rows = [];
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
$expenses = $this->processExpenses($budget->id, $spent, $start, $end);
$converter = new ExchangeRateConverter();
$currencies = [$this->primaryCurrency->id => $this->primaryCurrency];
/**
* @var int $currencyId
@@ -121,7 +126,14 @@ class BudgetController extends Controller
*/
foreach ($expenses as $currencyId => $row) {
// budgeted, left and overspent are now 0.
$limit = $this->filterLimit($currencyId, $limits);
$limit = $this->filterLimit($currencyId, $limits);
// primary currency entries
$row['pc_budgeted'] = '0';
$row['pc_spent'] = '0';
$row['pc_left'] = '0';
$row['pc_overspent'] = '0';
if (null !== $limit) {
$row['budgeted'] = $limit->amount;
$row['left'] = bcsub($row['budgeted'], bcmul($row['spent'], '-1'));
@@ -129,34 +141,59 @@ class BudgetController extends Controller
$row['left'] = 1 === bccomp($row['left'], '0') ? $row['left'] : '0';
$row['overspent'] = 1 === bccomp($row['overspent'], '0') ? $row['overspent'] : '0';
}
$rows[] = $row;
// convert data if necessary.
if (true === $this->convertToPrimary && $currencyId !== $this->primaryCurrency->id) {
$currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
$row['pc_budgeted'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['budgeted']);
$row['pc_spent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['spent']);
$row['pc_left'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['left']);
$row['pc_overspent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['overspent']);
}
if (true === $this->convertToPrimary && $currencyId === $this->primaryCurrency->id) {
$row['pc_budgeted'] = $row['budgeted'];
$row['pc_spent'] = $row['spent'];
$row['pc_left'] = $row['left'];
$row['pc_overspent'] = $row['overspent'];
}
$rows[] = $row;
}
// if no limits
// if (0 === $limits->count()) {
// return as a single item in an array
// $rows = $this->noBudgetLimits($budget, $start, $end);
// }
// is always an array
$return = [];
$return = [];
foreach ($rows as $row) {
$current = [
'label' => $budget->name,
'currency_id' => (string)$row['currency_id'],
'currency_code' => $row['currency_code'],
'currency_name' => $row['currency_name'],
'currency_decimal_places' => $row['currency_decimal_places'],
'period' => null,
'start' => $row['start'],
'end' => $row['end'],
'entries' => [
'label' => $budget->name,
'currency_id' => (string)$row['currency_id'],
'currency_name' => $row['currency_name'],
'currency_code' => $row['currency_code'],
'currency_decimal_places' => $row['currency_decimal_places'],
'primary_currency_id' => (string)$this->primaryCurrency->id,
'primary_currency_name' => $this->primaryCurrency->name,
'primary_currency_code' => $this->primaryCurrency->code,
'primary_currency_symbol' => $this->primaryCurrency->symbol,
'primary_currency_decimal_places' => $this->primaryCurrency->decimal_places,
'period' => null,
'date' => $row['start'],
'start_date' => $row['start'],
'end_date' => $row['end'],
'yAxisID' => 0,
'type' => 'bar',
'entries' => [
'budgeted' => $row['budgeted'],
'spent' => $row['spent'],
'left' => $row['left'],
'overspent' => $row['overspent'],
],
'pc_entries' => [
'budgeted' => $row['pc_budgeted'],
'spent' => $row['pc_spent'],
'left' => $row['pc_left'],
'overspent' => $row['pc_overspent'],
],
];
$return[] = $current;
}

View File

@@ -26,7 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Api\V1\Requests\Data\SameDateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Enums\UserRoleEnum;
@@ -34,6 +34,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Api\CleansChartData;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
@@ -58,11 +59,13 @@ class CategoryController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$userGroup = $this->validateUserGroup($request);
$this->accountRepos->setUserGroup($userGroup);
$this->currencyRepos->setUserGroup($userGroup);
$this->accountRepos->setUserGroup($this->userGroup);
$this->currencyRepos->setUserGroup($this->userGroup);
$this->accountRepos->setUser($this->user);
$this->currencyRepos->setUser($this->user);
return $next($request);
}
@@ -77,7 +80,7 @@ class CategoryController extends Controller
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
public function dashboard(DateRequest $request): JsonResponse
public function overview(SameDateRequest $request): JsonResponse
{
/** @var Carbon $start */
$start = $this->parameters->get('start');
@@ -100,52 +103,70 @@ class CategoryController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
// find journal:
$journalCurrencyId = (int)$journal['currency_id'];
$currency = $currencies[$journalCurrencyId] ?? $this->currencyRepos->find($journalCurrencyId);
$currencies[$journalCurrencyId] = $currency;
$currencyId = (int)$currency->id;
$currencyName = (string)$currency->name;
$currencyCode = (string)$currency->code;
$currencySymbol = (string)$currency->symbol;
$currencyDecimalPlaces = (int)$currency->decimal_places;
$amount = app('steam')->positive($journal['amount']);
$journalCurrencyId = (int)$journal['currency_id'];
$currency = $currencies[$journalCurrencyId] ?? $this->currencyRepos->find($journalCurrencyId);
$currencies[$journalCurrencyId] = $currency;
$currencyId = (int)$currency->id;
$currencyName = (string)$currency->name;
$currencyCode = (string)$currency->code;
$currencySymbol = (string)$currency->symbol;
$currencyDecimalPlaces = (int)$currency->decimal_places;
$amount = Steam::positive($journal['amount']);
$pcAmount = null;
// overrule if necessary:
if ($this->convertToPrimary && $journalCurrencyId === $this->primaryCurrency->id) {
$pcAmount = $amount;
}
if ($this->convertToPrimary && $journalCurrencyId !== $this->primaryCurrency->id) {
$currencyId = (int)$this->primaryCurrency->id;
$currencyName = (string)$this->primaryCurrency->name;
$currencyCode = (string)$this->primaryCurrency->code;
$currencySymbol = (string)$this->primaryCurrency->symbol;
$currencyDecimalPlaces = (int)$this->primaryCurrency->decimal_places;
$convertedAmount = $converter->convert($currency, $this->primaryCurrency, $journal['date'], $amount);
Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->primaryCurrency->code, $convertedAmount));
$amount = $convertedAmount;
$pcAmount = $converter->convert($currency, $this->primaryCurrency, $journal['date'], $amount);
Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->primaryCurrency->code, $pcAmount));
}
$categoryName = $journal['category_name'] ?? (string)trans('firefly.no_category');
$key = sprintf('%s-%s', $categoryName, $currencyCode);
$categoryName = $journal['category_name'] ?? (string)trans('firefly.no_category');
$key = sprintf('%s-%s', $categoryName, $currencyCode);
// create arrays
$return[$key] ??= [
'label' => $categoryName,
'currency_id' => (string)$currencyId,
'currency_code' => $currencyCode,
'currency_name' => $currencyName,
'currency_symbol' => $currencySymbol,
'currency_decimal_places' => $currencyDecimalPlaces,
'period' => null,
'start' => $start->toAtomString(),
'end' => $end->toAtomString(),
'amount' => '0',
'label' => $categoryName,
'currency_id' => (string)$currencyId,
'currency_name' => $currencyName,
'currency_code' => $currencyCode,
'currency_symbol' => $currencySymbol,
'currency_decimal_places' => $currencyDecimalPlaces,
'primary_currency_id' => (string)$this->primaryCurrency->id,
'primary_currency_name' => (string)$this->primaryCurrency->name,
'primary_currency_code' => (string)$this->primaryCurrency->code,
'primary_currency_symbol' => (string)$this->primaryCurrency->symbol,
'primary_currency_decimal_places' => (int)$this->primaryCurrency->decimal_places,
'period' => null,
'start_date' => $start->toAtomString(),
'end_date' => $end->toAtomString(),
'yAxisID' => 0,
'type' => 'bar',
'entries' => [
'spent' => '0',
],
'pc_entries' => [
'spent' => '0',
],
];
// add monies
$return[$key]['amount'] = bcadd($return[$key]['amount'], (string)$amount);
$return[$key]['entries']['spent'] = bcadd($return[$key]['entries']['spent'], (string)$amount);
if (null !== $pcAmount) {
$return[$key]['pc_entries']['spent'] = bcadd($return[$key]['pc_entries']['spent'], (string)$pcAmount);
}
}
$return = array_values($return);
// order by amount
usort($return, static fn (array $a, array $b) => (float)$a['amount'] < (float)$b['amount'] ? 1 : -1);
usort($return, static fn (array $a, array $b) => (float)$a['entries']['spent'] < (float)$b['entries']['spent'] ? 1 : -1);
return response()->json($this->clean($return));
}

View File

@@ -64,7 +64,7 @@ abstract class Controller extends BaseController
protected const string CONTENT_TYPE = 'application/vnd.api+json';
protected const string JSON_CONTENT_TYPE = 'application/json';
protected array $accepts = ['application/json', 'application/vnd.api+json'];
protected array $accepts = ['application/json', 'application/vnd.api+json'];
/** @var array<int, string> */
protected array $allowedSort;
@@ -107,7 +107,7 @@ abstract class Controller extends BaseController
private function getParameters(): ParameterBag
{
$bag = new ParameterBag();
$page = (int) request()->get('page');
$page = (int)request()->get('page');
if ($page < 1) {
$page = 1;
}
@@ -131,13 +131,13 @@ abstract class Controller extends BaseController
$obj = null;
if (null !== $date) {
try {
$obj = Carbon::parse((string) $date);
$obj = Carbon::parse((string)$date);
} catch (InvalidFormatException $e) {
// don't care
Log::warning(
sprintf(
'Ignored invalid date "%s" in API controller parameter check: %s',
substr((string) $date, 0, 20),
substr((string)$date, 0, 20),
$e->getMessage()
)
);
@@ -158,7 +158,7 @@ abstract class Controller extends BaseController
$value = null;
}
if (null !== $value) {
$value = (int) $value;
$value = (int)$value;
if ($value < 1) {
$value = 1;
}
@@ -176,7 +176,7 @@ abstract class Controller extends BaseController
$user = auth()->user();
/** @var Preference $pageSize */
$pageSize = (int) app('preferences')->getForUser($user, 'listPageSize', 50)->data;
$pageSize = (int)app('preferences')->getForUser($user, 'listPageSize', 50)->data;
$bag->set($integer, $pageSize);
}
}
@@ -190,7 +190,7 @@ abstract class Controller extends BaseController
$sortParameters = [];
try {
$param = (string) request()->query->get('sort');
$param = (string)request()->query->get('sort');
} catch (BadRequestException $e) {
Log::error('Request field "sort" contains a non-scalar value. Value set to NULL.');
Log::error($e->getMessage());

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Data\Bulk;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\Bulk\TransactionRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use Illuminate\Http\JsonResponse;
@@ -44,23 +45,23 @@ class TransactionController extends Controller
{
private AccountRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::MANAGE_TRANSACTIONS];
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->repository = app(AccountRepositoryInterface::class);
$this->repository->setUser(auth()->user());
$this->repository->setUserGroup($this->userGroup);
$this->repository->setUser($this->user);
return $next($request);
}
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/bulkUpdateTransactions
*/
public function update(TransactionRequest $request): JsonResponse
{
$query = $request->getAll();

View File

@@ -28,6 +28,7 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DestroyRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
@@ -55,12 +56,20 @@ class DestroyController extends Controller
{
private bool $unused;
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/destroyData
*
* @throws FireflyException
*/
protected array $acceptedRoles = [UserRoleEnum::FULL];
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
return $next($request);
}
);
}
public function destroy(DestroyRequest $request): JsonResponse
{
$objects = $request->getObjects();

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Data\Export;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\Export\ExportRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Export\ExportDataGenerator;
use Illuminate\Http\Response as LaravelResponse;
@@ -39,6 +40,7 @@ use function Safe\date;
class ExportController extends Controller
{
private ExportDataGenerator $exporter;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
/**
* ExportController constructor.
@@ -48,8 +50,10 @@ class ExportController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
$this->exporter = app(ExportDataGenerator::class);
$this->exporter->setUser(auth()->user());
$this->exporter->setUserGroup($this->userGroup);
$this->exporter->setUser($this->user);
return $next($request);
}
@@ -57,9 +61,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportAccounts
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -99,9 +100,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportBills
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -114,9 +112,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportBudgets
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -129,9 +124,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportCategories
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -144,9 +136,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportPiggies
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -159,9 +148,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportRecurring
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -174,9 +160,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportRules
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -189,9 +172,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportTags
*
* @throws FireflyException
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -204,9 +184,6 @@ class ExportController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportTransactions
*
* @throws FireflyException
*/
public function transactions(ExportRequest $request): LaravelResponse

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Data;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
@@ -44,10 +45,22 @@ use Illuminate\Http\JsonResponse;
*/
class PurgeController extends Controller
{
protected array $acceptedRoles = [UserRoleEnum::FULL];
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->validateUserGroup($request);
return $next($request);
}
);
}
/**
* TODO cleanup and use repositories.
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/purgeData
*/
public function purge(): JsonResponse
{
@@ -66,14 +79,6 @@ class PurgeController extends Controller
$repository = app(PiggyBankRepositoryInterface::class);
$repository->setUser($user);
$repository->purgeAll();
// $set = PiggyBank::leftJoin('accounts', 'accounts.id', 'piggy_banks.account_id')
// ->where('accounts.user_id', $user->id)->onlyTrashed()->get(['piggy_banks.*'])
// ;
//
// /** @var PiggyBank $piggy */
// foreach ($set as $piggy) {
// $piggy->forceDelete();
// }
// rule group
RuleGroup::whereUserId($user->id)->onlyTrashed()->forceDelete();

View File

@@ -64,10 +64,6 @@ class AccountController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseAsset
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -91,10 +87,6 @@ class AccountController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseExpense
*/
public function expense(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -58,9 +58,6 @@ class BillController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseBill
*
* Expenses per bill, possibly filtered by bill and account.
*/
public function bill(GenericRequest $request): JsonResponse
@@ -122,9 +119,6 @@ class BillController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseNoBill
*
* Expenses for no bill filtered by account.
*/
public function noBill(GenericRequest $request): JsonResponse

View File

@@ -63,10 +63,6 @@ class BudgetController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseBudget
*/
public function budget(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -98,10 +94,6 @@ class BudgetController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseNoBudget
*/
public function noBudget(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -63,10 +63,6 @@ class CategoryController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferCategory
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -98,10 +94,6 @@ class CategoryController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferNoCategory
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -37,10 +37,6 @@ use Illuminate\Support\Facades\Log;
*/
class PeriodController extends Controller
{
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseTotal
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();

View File

@@ -57,9 +57,6 @@ class TagController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseNoTag
*
* Expenses for no tag filtered by account.
*/
public function noTag(GenericRequest $request): JsonResponse
@@ -115,9 +112,6 @@ class TagController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightExpenseTag
*
* Expenses per tag, possibly filtered by tag and account.
*/
public function tag(GenericRequest $request): JsonResponse

View File

@@ -64,10 +64,6 @@ class AccountController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeAsset
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -92,10 +88,6 @@ class AccountController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeRevenue
*/
public function revenue(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -63,10 +63,6 @@ class CategoryController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeCategory
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -98,10 +94,6 @@ class CategoryController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeNoCategory
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -36,10 +36,6 @@ use Illuminate\Http\JsonResponse;
*/
class PeriodController extends Controller
{
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeTotal
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();

View File

@@ -57,9 +57,6 @@ class TagController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeTag
*
* Expenses for no tag filtered by account.
*/
public function noTag(GenericRequest $request): JsonResponse
@@ -109,9 +106,6 @@ class TagController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightIncomeNoTag
*
* Expenses per tag, possibly filtered by tag and account.
*/
public function tag(GenericRequest $request): JsonResponse

View File

@@ -56,10 +56,6 @@ class AccountController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransfers
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -63,10 +63,6 @@ class CategoryController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferCategory
*/
public function category(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
@@ -98,10 +94,6 @@ class CategoryController extends Controller
return response()->json($result);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferNoCategory
*/
public function noCategory(GenericRequest $request): JsonResponse
{
$start = $request->getStart();

View File

@@ -36,10 +36,6 @@ use Illuminate\Http\JsonResponse;
*/
class PeriodController extends Controller
{
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferTotal
*/
public function total(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();

View File

@@ -56,10 +56,6 @@ class TagController extends Controller
);
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferNoTag
*/
public function noTag(GenericRequest $request): JsonResponse
{
$accounts = $request->getAssetAccounts();
@@ -108,9 +104,6 @@ class TagController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/insight/insightTransferTag
*
* Transfers per tag, possibly filtered by tag and account.
*/
public function tag(GenericRequest $request): JsonResponse

View File

@@ -55,9 +55,6 @@ class DestroyController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/accounts/deleteAccount
*
* Remove the specified resource from storage.
*/
public function destroy(Account $account): JsonResponse

View File

@@ -71,9 +71,6 @@ class ListController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/accounts/listAttachmentByAccount
*
* @throws FireflyException
*/
public function attachments(Account $account): JsonResponse
@@ -100,9 +97,6 @@ class ListController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/accounts/listPiggyBankByAccount
*
* @throws FireflyException
*/
public function piggyBanks(Account $account): JsonResponse
@@ -140,9 +134,6 @@ class ListController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/accounts/listTransactionByAccount
*
* Show all transaction groups related to the account.
*
* @throws FireflyException

View File

@@ -67,9 +67,6 @@ class ShowController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/accounts/listAccount
*
* Display a listing of the resource.
*
* @throws FireflyException

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\JsonApi\Enrichments\BudgetEnrichment;
use FireflyIII\Support\JsonApi\Enrichments\BudgetLimitEnrichment;
use FireflyIII\Transformers\BudgetLimitTransformer;
use FireflyIII\User;
@@ -76,6 +77,16 @@ class ShowController extends Controller
*/
public function index(Budget $budget): JsonResponse
{
/** @var User $admin */
$admin = auth()->user();
// enrich budget:
$enrichment = new BudgetEnrichment();
$enrichment->setUser($admin);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$budget = $enrichment->enrichSingle($budget);
$manager = $this->getManager();
$manager->parseIncludes('budget');
$pageSize = $this->parameters->get('limit');
@@ -87,8 +98,6 @@ class ShowController extends Controller
// enrich
/** @var User $admin */
$admin = auth()->user();
$enrichment = new BudgetLimitEnrichment();
$enrichment->setUser($admin);
$budgetLimits = $enrichment->enrich($budgetLimits);

View File

@@ -28,13 +28,11 @@ use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\DestroyRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\ValidationException;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DestroyController extends Controller
{
@@ -59,23 +57,25 @@ class DestroyController extends Controller
public function destroy(DestroyRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse
{
$date = $request->getDate();
if (!$date instanceof Carbon) {
throw new ValidationException('Date is required');
}
$rate = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (!$rate instanceof CurrencyExchangeRate) {
throw new NotFoundHttpException();
}
$this->repository->deleteRate($rate);
$this->repository->deleteRates($from, $to);
return response()->json([], 204);
}
public function destroySingle(CurrencyExchangeRate $exchangeRate): JsonResponse
public function destroySingleById(CurrencyExchangeRate $exchangeRate): JsonResponse
{
$this->repository->deleteRate($exchangeRate);
return response()->json([], 204);
}
public function destroySingleByDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): JsonResponse
{
$exchangeRate = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null !== $exchangeRate) {
$this->repository->deleteRate($exchangeRate);
}
return response()->json([], 204);
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\CurrencyExchangeRate;
@@ -33,6 +34,7 @@ use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ShowController
@@ -76,7 +78,7 @@ class ShowController extends Controller
;
}
public function showSingle(CurrencyExchangeRate $exchangeRate): JsonResponse
public function showSingleById(CurrencyExchangeRate $exchangeRate): JsonResponse
{
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters);
@@ -86,4 +88,20 @@ class ShowController extends Controller
->header('Content-Type', self::CONTENT_TYPE)
;
}
public function showSingleByDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): JsonResponse
{
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters);
$exchangeRate = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null === $exchangeRate) {
throw new NotFoundHttpException();
}
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $exchangeRate, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -24,21 +24,27 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreByCurrenciesRequest;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreByDateRequest;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreRequest;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
class StoreController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
protected array $acceptedRoles = [UserRoleEnum::OWNER];
public const string RESOURCE_KEY = 'exchange-rates';
protected array $acceptedRoles = [UserRoleEnum::OWNER];
private ExchangeRateRepositoryInterface $repository;
public function __construct()
@@ -54,6 +60,71 @@ class StoreController extends Controller
);
}
public function storeByCurrencies(StoreByCurrenciesRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse
{
$data = $request->getAll();
$collection = new Collection();
foreach ($data as $date => $rate) {
$date = Carbon::createFromFormat('Y-m-d', $date);
$existing = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null !== $existing) {
// update existing rate.
$existing = $this->repository->updateExchangeRate($existing, $rate);
$collection->push($existing);
continue;
}
$new = $this->repository->storeExchangeRate($from, $to, $rate, $date);
$collection->push($new);
}
$count = $collection->count();
$paginator = new LengthAwarePaginator($collection, $count, $count, 1);
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
public function storeByDate(StoreByDateRequest $request, Carbon $date): JsonResponse
{
$data = $request->getAll();
$from = $request->getFromCurrency();
$collection = new Collection();
foreach ($data['rates'] as $key => $rate) {
$to = TransactionCurrency::where('code', $key)->first();
if (null === $to) {
continue; // should not happen.
}
$existing = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null !== $existing) {
// update existing rate.
$existing = $this->repository->updateExchangeRate($existing, $rate);
$collection->push($existing);
continue;
}
$new = $this->repository->storeExchangeRate($from, $to, $rate, $date);
$collection->push($new);
}
$count = $collection->count();
$paginator = new LengthAwarePaginator($collection, $count, $count, 1);
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
public function store(StoreRequest $request): JsonResponse
{
$date = $request->getDate();

View File

@@ -24,21 +24,24 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\UpdateRequest;
use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\UpdateRequest;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
use FireflyIII\Transformers\ExchangeRateTransformer;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UpdateController extends Controller
{
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
protected array $acceptedRoles = [UserRoleEnum::OWNER];
public const string RESOURCE_KEY = 'exchange-rates';
protected array $acceptedRoles = [UserRoleEnum::OWNER];
private ExchangeRateRepositoryInterface $repository;
public function __construct()
@@ -54,7 +57,7 @@ class UpdateController extends Controller
);
}
public function update(UpdateRequest $request, CurrencyExchangeRate $exchangeRate): JsonResponse
public function updateById(UpdateRequest $request, CurrencyExchangeRate $exchangeRate): JsonResponse
{
$date = $request->getDate();
$rate = $request->getRate();
@@ -67,4 +70,23 @@ class UpdateController extends Controller
->header('Content-Type', self::CONTENT_TYPE)
;
}
public function updateByDate(UpdateRequest $request, TransactionCurrency $from, TransactionCurrency $to, Carbon $date): JsonResponse
{
$exchangeRate = $this->repository->getSpecificRateOnDate($from, $to, $date);
if (null === $exchangeRate) {
throw new NotFoundHttpException();
}
$date = $request->getDate();
$rate = $request->getRate();
$exchangeRate = $this->repository->updateExchangeRate($exchangeRate, $rate, $date);
$transformer = new ExchangeRateTransformer();
$transformer->setParameters($this->parameters);
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $exchangeRate, $transformer))
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -126,7 +126,7 @@ class ShowController extends Controller
*
* @throws FireflyException
*/
public function showDefault(): JsonResponse
public function showPrimary(): JsonResponse
{
/** @var User $user */
$user = auth()->user();

View File

@@ -73,7 +73,7 @@ class StoreController extends Controller
{
$currency = $this->repository->store($request->getAll());
if (true === $request->boolean('default')) {
$this->repository->makeDefault($currency);
$this->repository->makePrimary($currency);
app('preferences')->mark();
}
$manager = $this->getManager();

View File

@@ -101,12 +101,12 @@ class UpdateController extends Controller
/**
* @throws FireflyException
*/
public function makeDefault(TransactionCurrency $currency): JsonResponse
public function makePrimary(TransactionCurrency $currency): JsonResponse
{
/** @var User $user */
$user = auth()->user();
$this->repository->enable($currency);
$this->repository->makeDefault($currency);
$this->repository->makePrimary($currency);
app('preferences')->mark();

View File

@@ -24,15 +24,18 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\System;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\System\UpdateRequest;
use FireflyIII\Enums\WebhookDelivery;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Binder\EitherConfigKey;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
/**
@@ -107,8 +110,8 @@ class ConfigurationController extends Controller
return [
'is_demo_site' => $isDemoSite?->data,
'permission_update_check' => null === $updateCheck ? null : (int) $updateCheck->data,
'last_update_check' => null === $lastCheck ? null : (int) $lastCheck->data,
'permission_update_check' => null === $updateCheck ? null : (int)$updateCheck->data,
'last_update_check' => null === $lastCheck ? null : (int)$lastCheck->data,
'single_user_mode' => $singleUser?->data,
];
}
@@ -139,7 +142,20 @@ class ConfigurationController extends Controller
'value' => $dynamic[$shortKey],
'editable' => true,
];
return response()->api(['data' => $data])->header('Content-Type', self::JSON_CONTENT_TYPE);
}
if (str_starts_with($configKey, 'webhook.')) {
$data = [
'title' => $configKey,
'value' => $this->getWebhookConfiguration($configKey),
'editable' => false,
];
return response()->api(['data' => $data])->header('Content-Type', self::JSON_CONTENT_TYPE);
}
// fallback
if (!str_starts_with($configKey, 'configuration.')) {
$data = [
'title' => $configKey,
@@ -182,4 +198,39 @@ class ConfigurationController extends Controller
return response()->api(['data' => $data])->header('Content-Type', self::CONTENT_TYPE);
}
private function getWebhookConfiguration(string $configKey): array
{
switch ($configKey) {
case 'webhook.triggers':
$cases = WebhookTrigger::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
case 'webhook.responses':
$cases = WebhookResponse::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
case 'webhook.deliveries':
$cases = WebhookDelivery::cases();
$data = [];
foreach ($cases as $c) {
$data[$c->name] = $c->value;
}
return $data;
default:
throw new FireflyException(sprintf('Unknown webhook configuration key "%s".', $configKey));
}
}
}

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Webhook;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Events\RequestedSendWebhookMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
@@ -146,7 +147,7 @@ class ShowController extends Controller
$engine->setUser(auth()->user());
// tell the generator which trigger it should look for
$engine->setTrigger($webhook->trigger);
$engine->setTrigger(WebhookTrigger::tryFrom($webhook->trigger));
// tell the generator which objects to process
$engine->setObjects(new Collection([$group]));
// set the webhook to trigger

View File

@@ -45,7 +45,7 @@ class DestroyRequest extends FormRequest
public function rules(): array
{
return [
'date' => 'required|date|after:1970-01-02|before:2038-01-17',
// 'date' => 'required|date|after:1970-01-02|before:2038-01-17',
];
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*
* StoreRequest.php
* Copyright (c) 2025 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
class StoreByCurrenciesRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
public function getAll(): array
{
return $this->all();
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'*' => 'required|numeric|min:0.0000000001',
];
}
public function withValidator(Validator $validator): void
{
$validator->after(
static function (Validator $validator): void {
$data = $validator->getData() ?? [];
foreach ($data as $date => $rate) {
try {
$date = Carbon::createFromFormat('Y-m-d', $date);
} catch (InvalidFormatException $e) {
$validator->errors()->add('date', trans('validation.date', ['attribute' => 'date']));
return;
}
if (!is_numeric($rate)) {
$validator->errors()->add('rate', trans('validation.number', ['attribute' => 'rate']));
return;
}
}
}
);
}
}

View File

@@ -0,0 +1,90 @@
<?php
/*
* StoreRequest.php
* Copyright (c) 2025 james@firefly-iii.org.
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
class StoreByDateRequest extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
public function getAll(): array
{
return [
'from' => $this->get('from'),
'rates' => $this->get('rates', []),
];
}
public function getFromCurrency(): TransactionCurrency
{
return TransactionCurrency::where('code', $this->get('from'))->first();
}
/**
* The rules that the incoming request must be matched against.
*/
public function rules(): array
{
return [
'from' => 'required|exists:transaction_currencies,code',
'rates' => 'required|array',
'rates.*' => 'required|numeric|min:0.0000000001',
];
}
public function withValidator(Validator $validator): void
{
$from = $this->getFromCurrency();
$validator->after(
static function (Validator $validator) use ($from): void {
$data = $validator->getData();
$rates = $data['rates'] ?? [];
if (0 === count($rates)) {
$validator->errors()->add('rates', 'No rates given.');
return;
}
foreach ($rates as $key => $entry) {
if ($key === $from->code) {
$validator->errors()->add(sprintf('rates.%s', $key), trans('validation.convert_to_itself', ['code' => $key]));
continue;
}
$to = TransactionCurrency::where('code', $key)->first();
if (null === $to) {
$validator->errors()->add(sprintf('rates.%s', $key), trans('validation.invalid_currency_code', ['code' => $key]));
}
}
}
);
}
}

View File

@@ -52,6 +52,8 @@ class UpdateRequest extends FormRequest
return [
'date' => 'date|after:1970-01-02|before:2038-01-17',
'rate' => 'required|numeric|gt:0',
'from' => 'nullable|exists:transaction_currencies,code',
'to' => 'nullable|exists:transaction_currencies,code',
];
}
}

View File

@@ -24,11 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Models\Webhook;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
/**
* Class CreateRequest
@@ -55,9 +59,9 @@ class CreateRequest extends FormRequest
// this is the way.
$return = $this->getAllData($fields);
$return['trigger'] = $triggers[$return['trigger']] ?? (int) $return['trigger'];
$return['response'] = $responses[$return['response']] ?? (int) $return['response'];
$return['delivery'] = $deliveries[$return['delivery']] ?? (int) $return['delivery'];
$return['trigger'] = $triggers[$return['trigger']] ?? (int)$return['trigger'];
$return['response'] = $responses[$return['response']] ?? (int)$return['response'];
$return['delivery'] = $deliveries[$return['delivery']] ?? (int)$return['delivery'];
return $return;
}
@@ -81,4 +85,45 @@ class CreateRequest extends FormRequest
'url' => ['required', sprintf('url:%s', $validProtocols), 'uniqueWebhook'],
];
}
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator): void {
Log::debug('Validating webhook');
$data = $validator->getData();
$trigger = $data['trigger'] ?? null;
$response = $data['response'] ?? null;
if (null === $trigger || null === $response) {
Log::debug('No trigger or response, return.');
return;
}
$triggers = array_keys(Webhook::getTriggersForValidation());
$responses = array_keys(Webhook::getResponsesForValidation());
if (!in_array($trigger, $triggers, true) || !in_array($response, $responses, true)) {
return;
}
// cannot deliver budget info.
if (is_int($trigger)) {
Log::debug(sprintf('Trigger was integer (%d).', $trigger));
$trigger = WebhookTrigger::from($trigger)->name;
}
if (is_int($response)) {
Log::debug(sprintf('Response was integer (%d).', $response));
$response = WebhookResponse::from($response)->name;
}
Log::debug(sprintf('Trigger is %s, response is %s', $trigger, $response));
if (str_contains($trigger, 'TRANSACTION') && str_contains($response, 'BUDGET')) {
$validator->errors()->add('response', trans('validation.webhook_budget_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'ACCOUNT')) {
$validator->errors()->add('response', trans('validation.webhook_account_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'TRANSACTION')) {
$validator->errors()->add('response', trans('validation.webhook_transaction_info'));
}
}
);
}
}

View File

@@ -24,11 +24,15 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\Webhook;
use FireflyIII\Enums\WebhookResponse;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Models\Webhook;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Log;
/**
* Class UpdateRequest
@@ -94,4 +98,45 @@ class UpdateRequest extends FormRequest
'url' => [sprintf('url:%s', $validProtocols), sprintf('uniqueExistingWebhook:%d', $webhook->id)],
];
}
public function withValidator(Validator $validator): void
{
$validator->after(
function (Validator $validator): void {
Log::debug('Validating webhook');
$data = $validator->getData();
$trigger = $data['trigger'] ?? null;
$response = $data['response'] ?? null;
if (null === $trigger || null === $response) {
Log::debug('No trigger or response, return.');
return;
}
$triggers = array_keys(Webhook::getTriggersForValidation());
$responses = array_keys(Webhook::getResponsesForValidation());
if (!in_array($trigger, $triggers, true) || !in_array($response, $responses, true)) {
return;
}
// cannot deliver budget info.
if (is_int($trigger)) {
Log::debug(sprintf('Trigger was integer (%d).', $trigger));
$trigger = WebhookTrigger::from($trigger)->name;
}
if (is_int($response)) {
Log::debug(sprintf('Response was integer (%d).', $response));
$response = WebhookResponse::from($response)->name;
}
Log::debug(sprintf('Trigger is %s, response is %s', $trigger, $response));
if (str_contains($trigger, 'TRANSACTION') && str_contains($response, 'BUDGET')) {
$validator->errors()->add('response', trans('validation.webhook_budget_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'ACCOUNT')) {
$validator->errors()->add('response', trans('validation.webhook_account_info'));
}
if (str_contains($trigger, 'BUDGET') && str_contains($response, 'TRANSACTION')) {
$validator->errors()->add('response', trans('validation.webhook_transaction_info'));
}
}
);
}
}

View File

@@ -49,14 +49,23 @@ class ValidatesEnvironmentVariables extends Command
*/
public function handle(): int
{
$this->validateLanguage();
$this->validateGuard();
$this->validateStaticToken();
$result = $this->validateLanguage();
if (false === $result) {
return Command::FAILURE;
}
$result = $this->validateGuard();
if (false === $result) {
return Command::FAILURE;
}
$result = $this->validateStaticToken();
if (false === $result) {
return Command::FAILURE;
}
return Command::SUCCESS;
}
private function validateLanguage(): void
private function validateLanguage(): bool
{
$language = config('firefly.default_language');
$locale = config('firefly.default_locale');
@@ -67,7 +76,7 @@ class ValidatesEnvironmentVariables extends Command
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options)));
exit(1);
return false;
}
$options[] = 'equal';
if (!in_array($locale, $options, true)) {
@@ -75,11 +84,13 @@ class ValidatesEnvironmentVariables extends Command
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options)));
exit(1);
return false;
}
return true;
}
private function validateGuard(): void
private function validateGuard(): bool
{
$guard = config('auth.defaults.guard');
if ('web' !== $guard && 'remote_user_guard' !== $guard) {
@@ -87,18 +98,22 @@ class ValidatesEnvironmentVariables extends Command
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError('Valid guards are: web, remote_user_guard');
exit(1);
return false;
}
return true;
}
private function validateStaticToken(): void
private function validateStaticToken(): bool
{
$token = (string) config('firefly.static_cron_token');
$token = (string)config('firefly.static_cron_token');
if ('' !== $token && 32 !== strlen($token)) {
$this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.');
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
exit(1);
return false;
}
return true;
}
}

View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ResetsErrorMailLimit extends Command
{
use ShowsFriendlyMessages;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:reset-error-mail-limit';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Resets the number of error mails sent.';
/**
* Execute the console command.
*/
public function handle(): int
{
$file = storage_path('framework/cache/error-count.json');
$directory = storage_path('framework/cache');
$limits = [];
if (!is_writable($directory)) {
$this->friendlyError(sprintf('Cannot write to directory "%s", cannot rate limit errors.', $directory));
return CommandAlias::FAILURE;
}
if (!file_exists($file)) {
$this->friendlyInfo(sprintf('Created new limits file at "%s"', $file));
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
return CommandAlias::SUCCESS;
}
if (!is_writable($file)) {
$this->friendlyError(sprintf('Cannot write to "%s", cannot rate limit errors.', $file));
return CommandAlias::FAILURE;
}
$this->friendlyInfo(sprintf('Successfully reset the error rate-limits file located at "%s"', $file));
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
return CommandAlias::SUCCESS;
}
}

View File

@@ -29,12 +29,16 @@ use FireflyIII\Models\Attachment;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Safe\Exceptions\FileinfoException;
use Safe\Exceptions\FilesystemException;
use Safe\Exceptions\StringsException;
use function Safe\tempnam;
use function Safe\file_put_contents;
use function Safe\md5_file;
use function Safe\mime_content_type;
use function Safe\tempnam;
class ScansAttachments extends Command
{
@@ -46,6 +50,10 @@ class ScansAttachments extends Command
/**
* Execute the console command.
*
* @throws FilesystemException
* @throws StringsException
* @throws FileinfoException
*/
public function handle(): int
{
@@ -57,7 +65,7 @@ class ScansAttachments extends Command
$fileName = $attachment->fileName();
$encryptedContent = $disk->get($fileName);
if (null === $encryptedContent) {
app('log')->error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName));
Log::error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName));
continue;
}
@@ -65,18 +73,13 @@ class ScansAttachments extends Command
try {
$decryptedContent = Crypt::decrypt($encryptedContent); // verified
} catch (DecryptException $e) {
app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
$decryptedContent = $encryptedContent;
}
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
if (false === $tempFileName) {
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
exit(1);
}
file_put_contents($tempFileName, $decryptedContent);
$attachment->md5 = (string) md5_file($tempFileName);
$attachment->mime = (string) mime_content_type($tempFileName);
$attachment->md5 = (string)md5_file($tempFileName);
$attachment->mime = (string)mime_content_type($tempFileName);
$attachment->save();
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
}

View File

@@ -50,7 +50,7 @@ class Cron extends Command
{--download-cer : Download exchange rates. Other tasks will be skipped unless also requested.}
{--create-recurring : Create recurring transactions. Other tasks will be skipped unless also requested.}
{--create-auto-budgets : Create auto budgets. Other tasks will be skipped unless also requested.}
{--send-bill-warnings : Send bill warnings. Other tasks will be skipped unless also requested.}
{--send-subscription-warnings : Send subscription warnings. Other tasks will be skipped unless also requested.}
{--send-webhook-messages : Sends any stray webhook messages (with a maximum of 5).}
';
@@ -59,7 +59,7 @@ class Cron extends Command
$doAll = !$this->option('download-cer')
&& !$this->option('create-recurring')
&& !$this->option('create-auto-budgets')
&& !$this->option('send-bill-warnings')
&& !$this->option('send-subscription-warnings')
&& !$this->option('check-version')
&& !$this->option('send-webhook-messages');
$date = null;
@@ -116,9 +116,9 @@ class Cron extends Command
}
// Fire bill warning cron job
if ($doAll || $this->option('send-bill-warnings')) {
if ($doAll || $this->option('send-subscription-warnings')) {
try {
$this->billWarningCronJob($force, $date);
$this->subscriptionWarningCronJob($force, $date);
} catch (FireflyException $e) {
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
@@ -231,25 +231,25 @@ class Cron extends Command
/**
* @throws FireflyException
*/
private function billWarningCronJob(bool $force, ?Carbon $date): void
private function subscriptionWarningCronJob(bool $force, ?Carbon $date): void
{
$autoBudget = new BillWarningCronjob();
$autoBudget->setForce($force);
$subscriptionWarningJob = new BillWarningCronjob();
$subscriptionWarningJob->setForce($force);
// set date in cron job:
if ($date instanceof Carbon) {
$autoBudget->setDate($date);
$subscriptionWarningJob->setDate($date);
}
$autoBudget->fire();
$subscriptionWarningJob->fire();
if ($autoBudget->jobErrored) {
$this->friendlyError(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message));
if ($subscriptionWarningJob->jobErrored) {
$this->friendlyError(sprintf('Error in "subscription warnings" cron: %s', $subscriptionWarningJob->message));
}
if ($autoBudget->jobFired) {
$this->friendlyInfo(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message));
if ($subscriptionWarningJob->jobFired) {
$this->friendlyInfo(sprintf('"Send subscription warnings" cron fired: %s', $subscriptionWarningJob->message));
}
if ($autoBudget->jobSucceeded) {
$this->friendlyPositive(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
if ($subscriptionWarningJob->jobSucceeded) {
$this->friendlyPositive(sprintf('"Send subscription warnings" cron ran with success: %s', $subscriptionWarningJob->message));
}
}

View File

@@ -31,5 +31,6 @@ enum WebhookResponse: int
{
case TRANSACTIONS = 200;
case ACCOUNTS = 210;
case BUDGET = 230;
case NONE = 220;
}

View File

@@ -29,10 +29,11 @@ namespace FireflyIII\Enums;
*/
enum WebhookTrigger: int
{
case STORE_TRANSACTION = 100;
// case BEFORE_STORE_TRANSACTION = 101;
case UPDATE_TRANSACTION = 110;
// case BEFORE_UPDATE_TRANSACTION = 111;
case DESTROY_TRANSACTION = 120;
// case BEFORE_DESTROY_TRANSACTION = 121;
case STORE_TRANSACTION = 100;
case UPDATE_TRANSACTION = 110;
case DESTROY_TRANSACTION = 120;
case STORE_BUDGET = 200;
case UPDATE_BUDGET = 210;
case DESTROY_BUDGET = 220;
case STORE_UPDATE_BUDGET_LIMIT = 230;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Generator\Webhook;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -38,7 +39,7 @@ interface MessageGeneratorInterface
public function setObjects(Collection $objects): void;
public function setTrigger(int $trigger): void;
public function setTrigger(WebhookTrigger $trigger): void;
public function setUser(User $user): void;

View File

@@ -47,11 +47,11 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
class StandardMessageGenerator implements MessageGeneratorInterface
{
private Collection $objects;
private int $trigger;
private User $user;
private int $version = 0;
private Collection $webhooks;
private Collection $objects;
private WebhookTrigger $trigger;
private User $user;
private int $version = 0;
private Collection $webhooks;
public function __construct()
{
@@ -68,9 +68,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
}
// do some debugging
Log::debug(
sprintf('StandardMessageGenerator will generate messages for %d object(s) and %d webhook(s).', $this->objects->count(), $this->webhooks->count())
);
Log::debug(sprintf('StandardMessageGenerator will generate messages for %d object(s) and %d webhook(s).', $this->objects->count(), $this->webhooks->count()));
$this->run();
}
@@ -79,6 +77,9 @@ class StandardMessageGenerator implements MessageGeneratorInterface
return $this->user->webhooks()->where('active', true)->where('trigger', $this->trigger)->get(['webhooks.*']);
}
/**
* @throws FireflyException
*/
private function run(): void
{
Log::debug('Now in StandardMessageGenerator::run');
@@ -114,28 +115,28 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$uuid = Uuid::uuid4();
$basicMessage = [
'uuid' => $uuid->toString(),
'user_id' => 0,
'trigger' => WebhookTrigger::from($webhook->trigger)->name,
'response' => WebhookResponse::from($webhook->response)->name,
'url' => $webhook->url,
'version' => sprintf('v%d', $this->getVersion()),
'content' => [],
'uuid' => $uuid->toString(),
'user_id' => 0,
'user_group_id' => 0,
'trigger' => $webhook->trigger->name,
'response' => WebhookResponse::from($webhook->response)->name,
'url' => $webhook->url,
'version' => sprintf('v%d', $this->getVersion()),
'content' => [],
];
// depends on the model how user_id is set:
switch ($class) {
default:
// Line is ignored because all of Firefly III's Models have an id property.
Log::error(
sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id)
);
Log::error(sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id));
return;
case TransactionGroup::class:
/** @var TransactionGroup $model */
$basicMessage['user_id'] = $model->user->id;
$basicMessage['user_id'] = $model->user_id;
$basicMessage['user_group_id'] = $model->user_group_id;
break;
}
@@ -143,9 +144,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
// then depends on the response what to put in the message:
switch ($webhook->response) {
default:
Log::error(
sprintf('The response code for webhook #%d is "%d" and the message generator cant handle it. Soft fail.', $webhook->id, $webhook->response)
);
Log::error(sprintf('The response code for webhook #%d is "%d" and the message generator cant handle it. Soft fail.', $webhook->id, $webhook->response));
return;
@@ -224,7 +223,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$this->objects = $objects;
}
public function setTrigger(int $trigger): void
public function setTrigger(WebhookTrigger $trigger): void
{
$this->trigger = $trigger;
}

View File

@@ -53,7 +53,7 @@ class DestroyedGroupEventHandler
$engine = app(MessageGeneratorInterface::class);
$engine->setUser($user);
$engine->setObjects(new Collection([$group]));
$engine->setTrigger(WebhookTrigger::DESTROY_TRANSACTION->value);
$engine->setTrigger(WebhookTrigger::DESTROY_TRANSACTION);
$engine->generateMessages();
event(new RequestedSendWebhookMessages());

View File

@@ -32,6 +32,7 @@ use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/**
* Class StoredGroupEventHandler
@@ -51,11 +52,11 @@ class StoredGroupEventHandler
private function processRules(StoredTransactionGroup $storedGroupEvent): void
{
if (false === $storedGroupEvent->applyRules) {
app('log')->info(sprintf('Will not run rules on group #%d', $storedGroupEvent->transactionGroup->id));
Log::info(sprintf('Will not run rules on group #%d', $storedGroupEvent->transactionGroup->id));
return;
}
app('log')->debug('Now in StoredGroupEventHandler::processRules()');
Log::debug('Now in StoredGroupEventHandler::processRules()');
$journals = $storedGroupEvent->transactionGroup->transactionJournals;
$array = [];
@@ -65,7 +66,7 @@ class StoredGroupEventHandler
$array[] = $journal->id;
}
$journalIds = implode(',', $array);
app('log')->debug(sprintf('Add local operator for journal(s): %s', $journalIds));
Log::debug(sprintf('Add local operator for journal(s): %s', $journalIds));
// collect rules:
$ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
@@ -98,10 +99,10 @@ class StoredGroupEventHandler
*/
private function triggerWebhooks(StoredTransactionGroup $storedGroupEvent): void
{
app('log')->debug(__METHOD__);
Log::debug(__METHOD__);
$group = $storedGroupEvent->transactionGroup;
if (false === $storedGroupEvent->fireWebhooks) {
app('log')->info(sprintf('Will not fire webhooks for transaction group #%d', $group->id));
Log::info(sprintf('Will not fire webhooks for transaction group #%d', $group->id));
return;
}
@@ -113,7 +114,7 @@ class StoredGroupEventHandler
$engine->setUser($user);
// tell the generator which trigger it should look for
$engine->setTrigger(WebhookTrigger::STORE_TRANSACTION->value);
$engine->setTrigger(WebhookTrigger::STORE_TRANSACTION);
// tell the generator which objects to process
$engine->setObjects(new Collection([$group]));
// tell the generator to generate the messages

View File

@@ -164,7 +164,7 @@ class UpdatedGroupEventHandler
$engine = app(MessageGeneratorInterface::class);
$engine->setUser($user);
$engine->setObjects(new Collection([$group]));
$engine->setTrigger(WebhookTrigger::UPDATE_TRANSACTION->value);
$engine->setTrigger(WebhookTrigger::UPDATE_TRANSACTION);
$engine->generateMessages();
event(new RequestedSendWebhookMessages());

View File

@@ -839,7 +839,7 @@ class GroupCollector implements GroupCollectorInterface
return 'zzz';
}
exit('here we are 2');
return 'zzz';
});
}

View File

@@ -40,6 +40,7 @@ use Illuminate\Routing\Redirector;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ShowController
@@ -81,7 +82,9 @@ class ShowController extends Controller
* */
public function show(Request $request, Account $account, ?Carbon $start = null, ?Carbon $end = null)
{
if (0 === $account->id) {
throw new NotFoundHttpException();
}
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
if (!$this->isEditableAccount($account)) {
@@ -115,19 +118,27 @@ class ShowController extends Controller
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
// go back max 3 years.
$threeYearsAgo = clone $start;
$threeYearsAgo->startOfYear()->subYears(3);
if ($firstTransaction->lt($threeYearsAgo)) {
$firstTransaction = clone $threeYearsAgo;
}
Log::debug('Start period overview');
Timer::start('period-overview');
$timer = Timer::getInstance();
$timer->start('period-overview');
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
Log::debug('End period overview');
Timer::stop('period-overview');
$timer->stop('period-overview');
// if layout = v2, overrule the page title.
if ('v1' !== config('view.layout')) {
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
}
Log::debug('Collect transactions');
Timer::start('collection');
$timer->start('collection');
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -146,7 +157,7 @@ class ShowController extends Controller
Log::debug('End collect transactions');
Timer::stop('collection');
$timer->stop('collection');
// enrich data in arrays.

View File

@@ -36,6 +36,7 @@ use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
use Psr\Container\ContainerExceptionInterface;
@@ -94,7 +95,7 @@ class RegisterController extends Controller
$this->validator($request->all())->validate();
$user = $this->createUser($request->all());
app('log')->info(sprintf('Registered new user %s', $user->email));
Log::info(sprintf('Registered new user %s', $user->email));
$owner = new OwnerNotifiable();
event(new RegisteredUser($owner, $user));

View File

@@ -118,7 +118,7 @@ class AccountController extends Controller
Log::debug(sprintf('expenseAccounts: accountsBalancesOptimized("%s")', $end->format('Y-m-d H:i:s')));
$startBalances = Steam::accountsBalancesOptimized($accounts, $start, $this->primaryCurrency, $this->convertToPrimary);
$endBalances = Steam::accountsBalancesOptimized($accounts, $end, $this->primaryCurrency, $this->convertToPrimary);
Log::debug('Done collecting balances');
// loop the accounts, then check for balance and currency info.
foreach ($accounts as $account) {
// Log::debug(sprintf('[a] Now in account #%d ("%s")', $account->id, $account->name));

View File

@@ -112,7 +112,7 @@ class NewUserController extends Controller
$this->createCashWalletAccount($currency, $language); // create cash wallet account
// store currency preference:
$currencyRepository->makeDefault($currency);
$currencyRepository->makePrimary($currency);
// store frontpage preferences:
$accounts = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();

View File

@@ -188,16 +188,7 @@ class ReportController extends Controller
$start->endOfDay(); // end of day so the final balance is at the end of that day.
$end->endOfDay();
app('view')->share(
'subTitle',
trans(
'firefly.report_default',
[
'start' => $start->isoFormat($this->monthAndDayFormat),
'end' => $end->isoFormat($this->monthAndDayFormat),
]
)
);
app('view')->share('subTitle', trans('firefly.report_default', ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]));
$generator = ReportGeneratorFactory::reportGenerator('Standard', $start, $end);
$generator->setAccounts($accounts);
@@ -222,16 +213,7 @@ class ReportController extends Controller
$start->endOfDay(); // end of day so the final balance is at the end of that day.
$end->endOfDay();
app('view')->share(
'subTitle',
trans(
'firefly.report_double',
[
'start' => $start->isoFormat($this->monthAndDayFormat),
'end' => $end->isoFormat($this->monthAndDayFormat),
]
)
);
app('view')->share('subTitle', trans('firefly.report_double', ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]));
$generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end);
$generator->setAccounts($accounts);

View File

@@ -417,7 +417,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
// currency must be made default.
if (true === $default) {
$this->makeDefault($currency);
$this->makePrimary($currency);
}
/** @var CurrencyUpdateService $service */
@@ -426,7 +426,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return $service->update($currency, $data);
}
public function makeDefault(TransactionCurrency $currency): void
public function makePrimary(TransactionCurrency $currency): void
{
$current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup);
Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));

View File

@@ -102,7 +102,7 @@ interface CurrencyRepositoryInterface
public function isFallbackCurrency(TransactionCurrency $currency): bool;
public function makeDefault(TransactionCurrency $currency): void;
public function makePrimary(TransactionCurrency $currency): void;
public function searchCurrency(string $search, int $limit): Collection;

View File

@@ -112,4 +112,13 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
return $object;
}
public function deleteRates(TransactionCurrency $from, TransactionCurrency $to): void
{
$this->userGroup->currencyExchangeRates()
->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id)
->delete()
;
}
}

View File

@@ -47,6 +47,8 @@ interface ExchangeRateRepositoryInterface
{
public function deleteRate(CurrencyExchangeRate $rate): void;
public function deleteRates(TransactionCurrency $from, TransactionCurrency $to): void;
public function getAll(): Collection;
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection;

View File

@@ -209,7 +209,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
$currency = $repository->find((int) $data['primary_currency_id']);
}
if (null !== $currency) {
$repository->makeDefault($currency);
$repository->makePrimary($currency);
}

View File

@@ -365,7 +365,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
// currency must be made default.
if (true === $default) {
$this->makeDefault($currency);
$this->makePrimary($currency);
}
/** @var CurrencyUpdateService $service */
@@ -374,7 +374,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $service->update($currency, $data);
}
public function makeDefault(TransactionCurrency $currency): void
public function makePrimary(TransactionCurrency $currency): void
{
$current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup);
Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));

View File

@@ -89,7 +89,7 @@ interface CurrencyRepositoryInterface
public function isFallbackCurrency(TransactionCurrency $currency): bool;
public function makeDefault(TransactionCurrency $currency): void;
public function makePrimary(TransactionCurrency $currency): void;
public function searchCurrency(string $search, int $limit): Collection;

View File

@@ -57,6 +57,11 @@ class EitherConfigKey
'firefly.rule-actions',
'firefly.context-rule-actions',
'search.operators',
// webhooks
'webhook.triggers',
'webhook.responses',
'webhook.deliveries',
];
/**

View File

@@ -65,55 +65,27 @@ class FrontpageChartGenerator
public function generate(): array
{
Log::debug('Now in generate()');
Log::debug(sprintf('Now in %s', __METHOD__));
$categories = $this->repository->getCategories();
$accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value]);
// get expenses + income per category:
$collection = [];
/** @var Category $category */
foreach ($categories as $category) {
// get expenses
$collection[] = $this->collectExpenses($category, $accounts);
}
$collection = $this->collectExpensesAll($categories, $accounts);
// collect for no-category:
$collection[] = $this->collectNoCatExpenses($accounts);
$tempData = array_merge(...$collection);
$noCategory = $this->collectNoCatExpenses($accounts);
$collection = array_merge($collection, $noCategory);
// sort temp array by amount.
$amounts = array_column($tempData, 'sum_float');
array_multisort($amounts, SORT_ASC, $tempData);
$amounts = array_column($collection, 'sum_float');
array_multisort($amounts, SORT_ASC, $collection);
$currencyData = $this->createCurrencyGroups($tempData);
$currencyData = $this->createCurrencyGroups($collection);
return $this->insertValues($currencyData, $tempData);
}
private function collectExpenses(Category $category, Collection $accounts): array
{
Log::debug(sprintf('Collect expenses for category #%d ("%s")', $category->id, $category->name));
$spent = $this->opsRepos->sumExpenses($this->start, $this->end, $accounts, new Collection([$category]));
$tempData = [];
foreach ($spent as $currency) {
Log::debug(sprintf('Spent %s %s', $currency['currency_code'], $currency['sum']));
$this->addCurrency($currency);
$tempData[] = [
'name' => $category->name,
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int) $currency['currency_id'],
];
}
return $tempData;
return $this->insertValues($currencyData, $collection);
}
private function addCurrency(array $currency): void
{
$currencyId = (int) $currency['currency_id'];
$currencyId = (int)$currency['currency_id'];
$this->currencies[$currencyId] ??= [
'currency_id' => $currencyId,
@@ -133,8 +105,8 @@ class FrontpageChartGenerator
$tempData[] = [
'name' => trans('firefly.no_category'),
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float
'currency_id' => (int) $currency['currency_id'],
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float
'currency_id' => (int)$currency['currency_id'],
];
}
@@ -152,7 +124,7 @@ class FrontpageChartGenerator
foreach ($this->currencies as $currencyId => $currency) {
$key = sprintf('spent-%d', $currencyId);
$return[$key] = [
'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currency['currency_name']),
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currency['currency_name']),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
'entries' => $names,
@@ -175,4 +147,28 @@ class FrontpageChartGenerator
return $currencyData;
}
private function collectExpensesAll(Collection $categories, Collection $accounts): array
{
Log::debug(sprintf('Collect expenses for %d category(ies).', count($categories)));
$spent = $this->opsRepos->collectExpenses($this->start, $this->end, $accounts, $categories);
$tempData = [];
foreach ($categories as $category) {
$sums = $this->opsRepos->sumCollectedTransactionsByCategory($spent, $category, 'negative', $this->convertToPrimary);
if (0 === count($sums)) {
continue;
}
foreach ($sums as $currency) {
$this->addCurrency($currency);
$tempData[] = [
'name' => $category->name,
'sum' => $currency['sum'],
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int)$currency['currency_id'],
];
}
}
return $tempData;
}
}

View File

@@ -26,6 +26,9 @@ namespace FireflyIII\Support\Chart;
use FireflyIII\Exceptions\FireflyException;
/**
* @deprecated
*/
class ChartData
{
private array $series;

View File

@@ -28,19 +28,34 @@ use Illuminate\Support\Facades\Log;
class Timer
{
private static array $times = [];
private array $times = [];
private static ?Timer $instance = null;
public static function start(string $title): void
private function __construct()
{
self::$times[$title] = microtime(true);
// Private constructor to prevent direct instantiation.
}
public static function stop(string $title): void
public static function getInstance(): self
{
$start = self::$times[$title] ?? 0;
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function start(string $title): void
{
$this->times[$title] = microtime(true);
}
public function stop(string $title): void
{
$start = $this->times[$title] ?? 0;
$end = microtime(true);
$diff = $end - $start;
unset(self::$times[$title]);
unset($this->times[$title]);
Log::debug(sprintf('Timer "%s" took %f seconds', $title, $diff));
}
}

View File

@@ -42,6 +42,7 @@ use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\Tag;
use FireflyIII\Models\UserGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
@@ -84,6 +85,7 @@ class ExportDataGenerator
private bool $exportTransactions;
private Carbon $start;
private User $user;
private UserGroup $userGroup;
public function __construct()
{
@@ -906,4 +908,9 @@ class ExportDataGenerator
{
$this->start = $start;
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
}

View File

@@ -28,6 +28,8 @@ use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Navigation;
use FireflyIII\Support\Facades\Steam;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
@@ -66,34 +68,38 @@ class AccountBalanceGrouped
// income and expense array prepped:
$income = [
'label' => 'earned',
'currency_id' => (string) $currency['currency_id'],
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'primary_currency_id' => (string) $currency['primary_currency_id'],
'primary_currency_id' => (string)$currency['primary_currency_id'],
'primary_currency_symbol' => $currency['primary_currency_symbol'],
'primary_currency_code' => $currency['primary_currency_code'],
'primary_currency_decimal_places' => $currency['primary_currency_decimal_places'],
'date' => $this->start->toAtomString(),
'start' => $this->start->toAtomString(),
'end' => $this->end->toAtomString(),
'start_date' => $this->start->toAtomString(),
'end_date' => $this->end->toAtomString(),
'yAxisID' => 0,
'type' => 'line',
'period' => $this->preferredRange,
'entries' => [],
'primary_entries' => [],
'pc_entries' => [],
];
$expense = [
'label' => 'spent',
'currency_id' => (string) $currency['currency_id'],
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'primary_currency_id' => (string) $currency['primary_currency_id'],
'primary_currency_id' => (string)$currency['primary_currency_id'],
'primary_currency_symbol' => $currency['primary_currency_symbol'],
'primary_currency_code' => $currency['primary_currency_code'],
'primary_currency_decimal_places' => $currency['primary_currency_decimal_places'],
'date' => $this->start->toAtomString(),
'start' => $this->start->toAtomString(),
'end' => $this->end->toAtomString(),
'start_date' => $this->start->toAtomString(),
'end_date' => $this->end->toAtomString(),
'type' => 'line',
'yAxisID' => 0,
'period' => $this->preferredRange,
'entries' => [],
'pc_entries' => [],
@@ -104,15 +110,15 @@ class AccountBalanceGrouped
$key = $currentStart->format($this->carbonFormat);
$label = $currentStart->toAtomString();
// normal entries
$income['entries'][$label] = app('steam')->bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = app('steam')->bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
$income['entries'][$label] = Steam::bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = Steam::bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
// converted entries
$income['pc_entries'][$label] = app('steam')->bcround($currency[$key]['pc_earned'] ?? '0', $currency['primary_currency_decimal_places']);
$expense['pc_entries'][$label] = app('steam')->bcround($currency[$key]['pc_spent'] ?? '0', $currency['primary_currency_decimal_places']);
$income['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_earned'] ?? '0', $currency['primary_currency_decimal_places']);
$expense['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_spent'] ?? '0', $currency['primary_currency_decimal_places']);
// next loop
$currentStart = app('navigation')->addPeriod($currentStart, $this->preferredRange, 0);
$currentStart = Navigation::addPeriod($currentStart, $this->preferredRange, 0);
}
$chartData[] = $income;
@@ -143,7 +149,7 @@ class AccountBalanceGrouped
{
// format the date according to the period
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int) $journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
$currency = $this->findCurrency($currencyId);
// set the array with monetary info, if it does not exist.
@@ -153,24 +159,24 @@ class AccountBalanceGrouped
// is this journal's amount in- our outgoing?
$key = $this->getDataKey($journal);
$amount = 'spent' === $key ? app('steam')->negative($journal['amount']) : app('steam')->positive($journal['amount']);
$amount = 'spent' === $key ? Steam::negative($journal['amount']) : Steam::positive($journal['amount']);
// get conversion rate
$rate = $this->getRate($currency, $journal['date']);
$amountConverted = bcmul((string) $amount, $rate);
$amountConverted = bcmul((string)$amount, $rate);
// perhaps transaction already has the foreign amount in the primary currency.
if ((int) $journal['foreign_currency_id'] === $this->primary->id) {
if ((int)$journal['foreign_currency_id'] === $this->primary->id) {
$amountConverted = $journal['foreign_amount'] ?? '0';
$amountConverted = 'earned' === $key ? app('steam')->positive($amountConverted) : app('steam')->negative($amountConverted);
$amountConverted = 'earned' === $key ? Steam::positive($amountConverted) : Steam::negative($amountConverted);
}
// add normal entry
$this->data[$currencyId][$period][$key] = bcadd((string) $this->data[$currencyId][$period][$key], (string) $amount);
$this->data[$currencyId][$period][$key] = bcadd((string)$this->data[$currencyId][$period][$key], (string)$amount);
// add converted entry
$convertedKey = sprintf('pc_%s', $key);
$this->data[$currencyId][$period][$convertedKey] = bcadd((string) $this->data[$currencyId][$period][$convertedKey], (string) $amountConverted);
$this->data[$currencyId][$period][$convertedKey] = bcadd((string)$this->data[$currencyId][$period][$convertedKey], (string)$amountConverted);
}
private function findCurrency(int $currencyId): TransactionCurrency
@@ -185,15 +191,15 @@ class AccountBalanceGrouped
private function createDefaultDataEntry(array $journal): void
{
$currencyId = (int) $journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
$this->data[$currencyId] ??= [
'currency_id' => (string) $currencyId,
'currency_id' => (string)$currencyId,
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
'currency_name' => $journal['currency_name'],
'currency_decimal_places' => $journal['currency_decimal_places'],
// primary currency info (could be the same)
'primary_currency_id' => (string) $this->primary->id,
'primary_currency_id' => (string)$this->primary->id,
'primary_currency_code' => $this->primary->code,
'primary_currency_symbol' => $this->primary->symbol,
'primary_currency_decimal_places' => $this->primary->decimal_places,
@@ -202,14 +208,14 @@ class AccountBalanceGrouped
private function createDefaultPeriodEntry(array $journal): void
{
$currencyId = (int) $journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
$period = $journal['date']->format($this->carbonFormat);
$this->data[$currencyId][$period] ??= [
'period' => $period,
'spent' => '0',
'earned' => '0',
'pc_spent' => '0',
'pc_earned' => '0',
'period' => $period,
'spent' => '0',
'earned' => '0',
'pc_spent' => '0',
'pc_earned' => '0',
];
}
@@ -258,12 +264,12 @@ class AccountBalanceGrouped
$primaryCurrencyId = $primary->id;
$this->currencies = [$primary->id => $primary]; // currency cache
$this->data[$primaryCurrencyId] = [
'currency_id' => (string) $primaryCurrencyId,
'currency_id' => (string)$primaryCurrencyId,
'currency_symbol' => $primary->symbol,
'currency_code' => $primary->code,
'currency_name' => $primary->name,
'currency_decimal_places' => $primary->decimal_places,
'primary_currency_id' => (string) $primaryCurrencyId,
'primary_currency_id' => (string)$primaryCurrencyId,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_code' => $primary->code,
'primary_currency_name' => $primary->name,
@@ -284,7 +290,7 @@ class AccountBalanceGrouped
public function setPreferredRange(string $preferredRange): void
{
$this->preferredRange = $preferredRange;
$this->carbonFormat = app('navigation')->preferredCarbonFormatByPeriod($preferredRange);
$this->carbonFormat = Navigation::preferredCarbonFormatByPeriod($preferredRange);
}
public function setStart(Carbon $start): void

View File

@@ -47,24 +47,31 @@ trait CleansChartData
* @var array $array
*/
foreach ($data as $index => $array) {
if (array_key_exists('currency_id', $array)) {
$array['currency_id'] = (string) $array['currency_id'];
}
if (array_key_exists('primary_currency_id', $array)) {
$array['primary_currency_id'] = (string) $array['primary_currency_id'];
}
if (!array_key_exists('start', $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "start"-variable.', $index));
}
if (!array_key_exists('end', $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "end"-variable.', $index));
}
if (!array_key_exists('period', $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "period"-variable.', $index));
}
$array = $this->cleanSingleArray($index, $array);
$return[] = $array;
}
return $return;
}
private function cleanSingleArray(mixed $index, array $array): array
{
if (array_key_exists('currency_id', $array)) {
$array['currency_id'] = (string)$array['currency_id'];
}
if (array_key_exists('primary_currency_id', $array)) {
$array['primary_currency_id'] = (string)$array['primary_currency_id'];
}
$required = [
'start_date', 'end_date', 'period', 'yAxisID', 'type', 'entries', 'pc_entries',
'currency_id', 'primary_currency_id',
];
foreach ($required as $field) {
if (!array_key_exists($field, $array)) {
throw new FireflyException(sprintf('Data-set "%s" is missing the "%s"-variable.', $index, $field));
}
}
return $array;
}
}

View File

@@ -67,7 +67,7 @@ trait CollectsAccountsFromFilter
if ('all' === $queryParameters['preselected']) {
return $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
}
if ('assets' === $queryParameters['preselected']) {
if ('assets' === $queryParameters['preselected'] || 'Asset account' === $queryParameters['preselected']) {
return $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value]);
}
if ('liabilities' === $queryParameters['preselected']) {

View File

@@ -39,6 +39,7 @@ use Illuminate\Support\Facades\Log;
trait ValidatesUserGroupTrait
{
protected ?UserGroup $userGroup = null;
protected ?User $user = null;
/**
* An "undocumented" filter
@@ -101,6 +102,7 @@ trait ValidatesUserGroupTrait
if ($user->hasRoleInGroupOrOwner($group, $role)) {
Log::debug(sprintf('validateUserGroup: User has role "%s" in group #%d, return the group.', $role->value, $groupId));
$this->userGroup = $group;
$this->user = $user;
return $group;
}

View File

@@ -80,7 +80,8 @@ trait PeriodOverview
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array
{
Log::debug('Now in getAccountPeriodOverview()');
Timer::start('account-period-total');
$timer = Timer::getInstance();
$timer->start('account-period-total');
$this->accountRepository = app(AccountRepositoryInterface::class);
$range = Navigation::getViewRange(true);
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
@@ -102,14 +103,14 @@ trait PeriodOverview
$entries = [];
// run a custom query because doing this with the collector is MEGA slow.
Timer::start('account-period-collect');
$timer->start('account-period-collect');
$transactions = $this->accountRepository->periodCollection($account, $start, $end);
Timer::stop('account-period-collect');
$timer->stop('account-period-collect');
// loop dates
Log::debug(sprintf('Count of loops: %d', count($dates)));
$loops = 0;
// stop after 10 loops for memory reasons.
Timer::start('account-period-loop');
$timer->start('account-period-loop');
foreach ($dates as $currentDate) {
$title = Navigation::periodShow($currentDate['start'], $currentDate['period']);
[$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']);
@@ -128,9 +129,9 @@ trait PeriodOverview
];
++$loops;
}
Timer::stop('account-period-loop');
$timer->stop('account-period-loop');
$cache->store($entries);
Timer::stop('account-period-total');
$timer->stop('account-period-total');
Log::debug('End of getAccountPeriodOverview()');
return $entries;

View File

@@ -73,10 +73,12 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
public function enrich(Collection $collection): Collection
{
$this->collection = $collection;
$this->collectIds();
$this->collectCurrencies();
$this->collectSpentInfo();
$this->appendCollectedData();
if ($this->collection->count() > 0) {
$this->collectIds();
$this->collectCurrencies();
$this->collectSpentInfo();
$this->appendCollectedData();
}
return $this->collection;
}
@@ -85,7 +87,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
public function enrichSingle(array|Model $model): array|Model
{
Log::debug(__METHOD__);
$collection = new Collection([$model]);
$collection = new Collection()->push($model);
$collection = $this->enrich($collection);
return $collection->first();
@@ -119,8 +121,8 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
private function collectSpentInfo(): void
{
$start = $this->collection->min('start_date');
$end = $this->collection->max('end_date');
$start = $this->collection->min('start_date') ?? Carbon::now()->startOfMonth();
$end = $this->collection->max('end_date') ?? Carbon::now()->endOfMonth();
$allActive = $this->repository->getActiveBudgets();
$spentInBudgets = $this->opsRepository->collectExpenses($start, $end, null, $allActive, null);
$spentOutsideBudgets = $this->noBudgetRepository->collectExpenses($start, $end, null, null, null);
@@ -139,14 +141,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
$this->pcSpentInBudgets[$id] = array_values($pcFilteredSpentInBudgets);
$this->pcSpentOutsideBudgets[$id] = array_values($pcFilteredSpentOutsideBudgets);
}
// filter arrays on date.
// send them to sumCollection thing.
// save.
}
// first collect, then filter and append.
}
private function appendCollectedData(): void

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