mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 11:19:16 +00:00
chore: reformat code.
This commit is contained in:
@@ -51,8 +51,8 @@ services:
|
|||||||
# Looks for unused imports from other namespaces.
|
# Looks for unused imports from other namespaces.
|
||||||
Nette\CodingStandard\Sniffs\Namespaces\UnusedUsesSniff:
|
Nette\CodingStandard\Sniffs\Namespaces\UnusedUsesSniff:
|
||||||
searchAnnotations: yes
|
searchAnnotations: yes
|
||||||
ignoredAnnotationNames: ['@testCase']
|
ignoredAnnotationNames: [ '@testCase' ]
|
||||||
ignoredAnnotations: ['@internal']
|
ignoredAnnotations: [ '@internal' ]
|
||||||
|
|
||||||
# Language Construct (should be placed before some other fixers)
|
# Language Construct (should be placed before some other fixers)
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ services:
|
|||||||
|
|
||||||
# There MUST NOT be more than one property declared per statement.
|
# There MUST NOT be more than one property declared per statement.
|
||||||
PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer:
|
PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer:
|
||||||
elements: ['property']
|
elements: [ 'property' ]
|
||||||
|
|
||||||
# Methods - https://nette.org/en/coding-standard#toc-methods
|
# Methods - https://nette.org/en/coding-standard#toc-methods
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ services:
|
|||||||
PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer: ~
|
PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer: ~
|
||||||
# Single-line comments comments with only one line of actual content should use the `//` syntax.
|
# Single-line comments comments with only one line of actual content should use the `//` syntax.
|
||||||
PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer:
|
PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer:
|
||||||
comment_types: ['hash']
|
comment_types: [ 'hash' ]
|
||||||
# Require comments with single-line content to be written as one-liners
|
# Require comments with single-line content to be written as one-liners
|
||||||
SlevomatCodingStandard\Sniffs\Commenting\RequireOneLinePropertyDocCommentSniff: ~
|
SlevomatCodingStandard\Sniffs\Commenting\RequireOneLinePropertyDocCommentSniff: ~
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ services:
|
|||||||
PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer: ~
|
PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer: ~
|
||||||
|
|
||||||
Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer:
|
Nette\CodingStandard\Fixer\ClassNotation\ClassAndTraitVisibilityRequiredFixer:
|
||||||
elements: ['const', 'property', 'method']
|
elements: [ 'const', 'property', 'method' ]
|
||||||
|
|
||||||
# short list() syntax []
|
# short list() syntax []
|
||||||
PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer:
|
PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer:
|
||||||
|
@@ -22,12 +22,12 @@
|
|||||||
$current = __DIR__;
|
$current = __DIR__;
|
||||||
|
|
||||||
$paths = [
|
$paths = [
|
||||||
$current.'/../../app',
|
$current . '/../../app',
|
||||||
$current.'/../../config',
|
$current . '/../../config',
|
||||||
$current.'/../../database',
|
$current . '/../../database',
|
||||||
$current.'/../../routes',
|
$current . '/../../routes',
|
||||||
$current.'/../../tests',
|
$current . '/../../tests',
|
||||||
$current.'/../../resources/lang',
|
$current . '/../../resources/lang',
|
||||||
];
|
];
|
||||||
|
|
||||||
$finder = PhpCsFixer\Finder::create()
|
$finder = PhpCsFixer\Finder::create()
|
||||||
@@ -40,5 +40,5 @@ return $config->setRules([
|
|||||||
'declare_strict_types' => true,
|
'declare_strict_types' => true,
|
||||||
'strict_param' => true,
|
'strict_param' => true,
|
||||||
'array_syntax' => ['syntax' => 'short'],
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
])
|
])
|
||||||
->setFinder($finder);
|
->setFinder($finder);
|
||||||
|
@@ -30,12 +30,9 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|||||||
|
|
||||||
# clean up php code
|
# clean up php code
|
||||||
cd $SCRIPT_DIR/php-cs-fixer
|
cd $SCRIPT_DIR/php-cs-fixer
|
||||||
composer update
|
composer update --quiet
|
||||||
rm -f .php-cs-fixer.cache
|
rm -f .php-cs-fixer.cache
|
||||||
echo 'Removed cache...'
|
|
||||||
echo 'Running...'
|
|
||||||
PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php --allow-risky=yes
|
PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php --allow-risky=yes
|
||||||
echo 'Done!'
|
|
||||||
cd $SCRIPT_DIR/..
|
cd $SCRIPT_DIR/..
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
37
.ci/phpmd.sh
Normal file
37
.ci/phpmd.sh
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# phpmd.sh
|
||||||
|
# Copyright (c) 2023 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
|
cd $SCRIPT_DIR/phpmd
|
||||||
|
composer update --quiet
|
||||||
|
./vendor/bin/phpmd \
|
||||||
|
$SCRIPT_DIR/../app text phpmd.xml \
|
||||||
|
--exclude $SCRIPT_DIR/../app/resources/** \
|
||||||
|
--exclude $SCRIPT_DIR/../app/frontend/** \
|
||||||
|
--exclude $SCRIPT_DIR/../app/public/** \
|
||||||
|
--exclude $SCRIPT_DIR/../app/vendor/** \
|
||||||
|
|
||||||
|
cd $SCRIPT_DIR/..
|
||||||
|
|
||||||
|
exit 0
|
1
.ci/phpmd/.gitignore
vendored
Normal file
1
.ci/phpmd/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
vendor
|
5
.ci/phpmd/composer.json
Normal file
5
.ci/phpmd/composer.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"require-dev": {
|
||||||
|
"phpmd/phpmd": "^2.13"
|
||||||
|
}
|
||||||
|
}
|
1012
.ci/phpmd/composer.lock
generated
Normal file
1012
.ci/phpmd/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
52
.ci/phpmd/phpmd.xml
Normal file
52
.ci/phpmd/phpmd.xml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ruleset name="pcsg-generated-ruleset"
|
||||||
|
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||||
|
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||||
|
<description>Bla bla</description>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Commando vanuit firefly directory:
|
||||||
|
phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/report.html
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Import the entire controversial code rule set -->
|
||||||
|
<rule ref="rulesets/controversial.xml">
|
||||||
|
<exclude name="CamelCasePropertyName" />
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- clean code -->
|
||||||
|
<rule ref="rulesets/codesize.xml" />
|
||||||
|
<rule ref="rulesets/design.xml" />
|
||||||
|
<rule ref="rulesets/naming.xml" />
|
||||||
|
<rule ref="rulesets/unusedcode.xml" />
|
||||||
|
|
||||||
|
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
|
||||||
|
<properties>
|
||||||
|
<property name="reportLevel" value="5"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="rulesets/codesize.xml/NPathComplexity">
|
||||||
|
<properties>
|
||||||
|
<property name="minimum" value="128"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
|
||||||
|
<properties>
|
||||||
|
<property name="minimum" value="40"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
|
||||||
|
<properties>
|
||||||
|
<property name="minimum" value="5"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- include clean code manually -->
|
||||||
|
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
|
||||||
|
<rule ref="rulesets/cleancode.xml/ElseExpression" />
|
||||||
|
|
||||||
|
<!-- no this one -->
|
||||||
|
<!--<rule ref="rulesets/cleancode.xml/StaticAccess" />-->
|
||||||
|
</ruleset>
|
@@ -143,6 +143,7 @@ MAIL_FROM=changeme@example.com
|
|||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=null
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_SENDMAIL_COMMAND=
|
||||||
|
|
||||||
# Other mail drivers:
|
# Other mail drivers:
|
||||||
# If you use Docker or similar, you can set these variables from a file by appending them with _FILE
|
# If you use Docker or similar, you can set these variables from a file by appending them with _FILE
|
||||||
|
29
.github/code_of_conduct.md
vendored
29
.github/code_of_conduct.md
vendored
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
## Our Pledge
|
## Our Pledge
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making
|
||||||
|
participation in our project and our community a harassment-free experience for everyone, regardless of age, body size,
|
||||||
|
disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race,
|
||||||
|
religion, or sexual identity and orientation.
|
||||||
|
|
||||||
## Our Standards
|
## Our Standards
|
||||||
|
|
||||||
@@ -24,23 +27,35 @@ Examples of unacceptable behavior by participants include:
|
|||||||
|
|
||||||
## Our Responsibilities
|
## Our Responsibilities
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take
|
||||||
|
appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
|
||||||
|
issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any
|
||||||
|
contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
## Scope
|
## Scope
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the
|
||||||
|
project or its community. Examples of representing a project or community include using an official project e-mail
|
||||||
|
address, posting via an official social media account, or acting as an appointed representative at an online or offline
|
||||||
|
event. Representation of a project may be further defined and clarified by project maintainers.
|
||||||
|
|
||||||
## Enforcement
|
## Enforcement
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at james@firefly-iii.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at
|
||||||
|
james@firefly-iii.org. The project team will review and investigate all complaints, and will respond in a way that it
|
||||||
|
deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the
|
||||||
|
reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent
|
||||||
|
repercussions as determined by other members of the project's leadership.
|
||||||
|
|
||||||
## Attribution
|
## Attribution
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available
|
||||||
|
at [http://contributor-covenant.org/version/1/4][version]
|
||||||
|
|
||||||
[homepage]: http://contributor-covenant.org
|
[homepage]: http://contributor-covenant.org
|
||||||
|
|
||||||
[version]: http://contributor-covenant.org/version/1/4/
|
[version]: http://contributor-covenant.org/version/1/4/
|
||||||
|
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
@@ -5,7 +5,7 @@ updates:
|
|||||||
- package-ecosystem: "composer"
|
- package-ecosystem: "composer"
|
||||||
directory: "/" # Location of package manifests
|
directory: "/" # Location of package manifests
|
||||||
target-branch: develop
|
target-branch: develop
|
||||||
labels: ["bug"]
|
labels: [ "bug" ]
|
||||||
versioning-strategy: increase
|
versioning-strategy: increase
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
@@ -14,7 +14,7 @@ updates:
|
|||||||
- package-ecosystem: "npm"
|
- package-ecosystem: "npm"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
target-branch: develop
|
target-branch: develop
|
||||||
labels: ["bug"]
|
labels: [ "bug" ]
|
||||||
versioning-strategy: increase
|
versioning-strategy: increase
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
@@ -22,7 +22,7 @@ updates:
|
|||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: "github-actions"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
target-branch: develop
|
target-branch: develop
|
||||||
labels: ["bug"]
|
labels: [ "bug" ]
|
||||||
versioning-strategy: increase
|
versioning-strategy: increase
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
10
.github/its_you_not_me.md
vendored
10
.github/its_you_not_me.md
vendored
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
Sometimes bugs reported to Firefly III are configuration and system problems on the user's side.
|
Sometimes bugs reported to Firefly III are configuration and system problems on the user's side.
|
||||||
|
|
||||||
If you run into any of the following problems, there's a good chance it's not a Firefly III issue, but a configuration issue.
|
If you run into any of the following problems, there's a good chance it's not a Firefly III issue, but a configuration
|
||||||
|
issue.
|
||||||
|
|
||||||
- ⚠️ Firefly III can't connect to the database when starting or the password is wrong, even though you're sure it's correct.
|
- ⚠️ Firefly III can't connect to the database when starting or the password is wrong, even though you're sure it's
|
||||||
|
correct.
|
||||||
- ⚠️ Errors about a missing `APP_KEY` or other encryption/hash problems
|
- ⚠️ Errors about a missing `APP_KEY` or other encryption/hash problems
|
||||||
- ⚠️ You can't login due to `419` errors (page expired)
|
- ⚠️ You can't login due to `419` errors (page expired)
|
||||||
- ⚠️ Any `500` error when starting Firefly III
|
- ⚠️ Any `500` error when starting Firefly III
|
||||||
@@ -13,4 +15,6 @@ If you run into any of the following problems, there's a good chance it's not a
|
|||||||
- ⚠️ Firefly III does not work behind your reverse proxy
|
- ⚠️ Firefly III does not work behind your reverse proxy
|
||||||
- ⚠️ You can't connect to the Data Importer due to 404's or authentication issues.
|
- ⚠️ You can't connect to the Data Importer due to 404's or authentication issues.
|
||||||
|
|
||||||
If you run into an issue like this, please start a [discussion](https://github.com/firefly-iii/firefly-iii/discussions) or chat on [Gitter.im](https://gitter.im/firefly-iii/firefly-iii). There's a good chance it's not a bug but something we can fix rather quickly :+1:
|
If you run into an issue like this, please start a [discussion](https://github.com/firefly-iii/firefly-iii/discussions)
|
||||||
|
or chat on [Gitter.im](https://gitter.im/firefly-iii/firefly-iii). There's a good chance it's not a bug but something we
|
||||||
|
can fix rather quickly :+1:
|
||||||
|
6
.github/support.md
vendored
6
.github/support.md
vendored
@@ -9,7 +9,8 @@ First of all: thank you for reporting a bug instead of ditching the tool altoget
|
|||||||
1. Open bugs will have open issues, so search for one first.
|
1. Open bugs will have open issues, so search for one first.
|
||||||
2. If your feature request is already there, vote on it with :+1: or :-1: reactions.
|
2. If your feature request is already there, vote on it with :+1: or :-1: reactions.
|
||||||
3. Do NOT hijack old issues with the bug you found, open your own issue.
|
3. Do NOT hijack old issues with the bug you found, open your own issue.
|
||||||
4. If relevant, take the time and see if the [demo site](https://demo.firefly-iii.org/) is also suffering from your issue.
|
4. If relevant, take the time and see if the [demo site](https://demo.firefly-iii.org/) is also suffering from your
|
||||||
|
issue.
|
||||||
5. If relevant, read the [documentation](https://docs.firefly-iii.org/).
|
5. If relevant, read the [documentation](https://docs.firefly-iii.org/).
|
||||||
|
|
||||||
Please follow these guidelines when opening new issues:
|
Please follow these guidelines when opening new issues:
|
||||||
@@ -25,7 +26,8 @@ Only then [create a new issue](https://github.com/firefly-iii/firefly-iii/issues
|
|||||||
## Issue closure and abandonment policy
|
## Issue closure and abandonment policy
|
||||||
|
|
||||||
- Issues can be converted into discussions if it's not a bug or feature request.
|
- Issues can be converted into discussions if it's not a bug or feature request.
|
||||||
- Features that won't be implemented will be labelled "wontfix". [This isn't personal](https://docs.firefly-iii.org/firefly-iii/about-firefly-iii/what-its-not/).
|
- Features that won't be implemented will be labelled "
|
||||||
|
wontfix". [This isn't personal](https://docs.firefly-iii.org/firefly-iii/about-firefly-iii/what-its-not/).
|
||||||
- Issues can be closed if they're duplicates of other issues.
|
- Issues can be closed if they're duplicates of other issues.
|
||||||
- Issues can be closed if the answer is in the FAQ.
|
- Issues can be closed if the answer is in the FAQ.
|
||||||
- Issues will be closed automatically after 14 days.
|
- Issues will be closed automatically after 14 days.
|
||||||
|
3
.github/workflows/closed-issues.yml
vendored
3
.github/workflows/closed-issues.yml
vendored
@@ -7,8 +7,7 @@ jobs:
|
|||||||
auto_comment:
|
auto_comment:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- uses: aws-actions/closed-issue-message@v1
|
||||||
uses: aws-actions/closed-issue-message@v1
|
|
||||||
with:
|
with:
|
||||||
message: |
|
message: |
|
||||||
Hi there! This is an automatic reply. `Share and enjoy`
|
Hi there! This is an automatic reply. `Share and enjoy`
|
||||||
|
2
.github/workflows/depsreview.yaml
vendored
2
.github/workflows/depsreview.yaml
vendored
@@ -1,5 +1,5 @@
|
|||||||
name: 'Dependency Review'
|
name: 'Dependency Review'
|
||||||
on: [pull_request]
|
on: [ pull_request ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
@@ -74,42 +74,6 @@ abstract class Controller extends BaseController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to help build URL's.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
final protected function buildParams(): string
|
|
||||||
{
|
|
||||||
$return = '?';
|
|
||||||
$params = [];
|
|
||||||
foreach ($this->parameters as $key => $value) {
|
|
||||||
if ('page' === $key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($value instanceof Carbon) {
|
|
||||||
$params[$key] = $value->format('Y-m-d');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$params[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return.http_build_query($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Manager
|
|
||||||
*/
|
|
||||||
final protected function getManager(): Manager
|
|
||||||
{
|
|
||||||
// create some objects:
|
|
||||||
$manager = new Manager();
|
|
||||||
$baseUrl = request()->getSchemeAndHttpHost().'/api/v1';
|
|
||||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
|
||||||
|
|
||||||
return $manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to grab all parameters from the URL.
|
* Method to grab all parameters from the URL.
|
||||||
*
|
*
|
||||||
@@ -144,7 +108,7 @@ abstract class Controller extends BaseController
|
|||||||
if (null !== $date) {
|
if (null !== $date) {
|
||||||
try {
|
try {
|
||||||
$obj = Carbon::parse($date);
|
$obj = Carbon::parse($date);
|
||||||
} catch (InvalidDateException|InvalidFormatException $e) {
|
} catch (InvalidDateException | InvalidFormatException $e) {
|
||||||
// don't care
|
// don't care
|
||||||
app('log')->warning(
|
app('log')->warning(
|
||||||
sprintf(
|
sprintf(
|
||||||
@@ -211,4 +175,40 @@ abstract class Controller extends BaseController
|
|||||||
|
|
||||||
return $bag;
|
return $bag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to help build URL's.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
final protected function buildParams(): string
|
||||||
|
{
|
||||||
|
$return = '?';
|
||||||
|
$params = [];
|
||||||
|
foreach ($this->parameters as $key => $value) {
|
||||||
|
if ('page' === $key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($value instanceof Carbon) {
|
||||||
|
$params[$key] = $value->format('Y-m-d');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$params[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return . http_build_query($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Manager
|
||||||
|
*/
|
||||||
|
final protected function getManager(): Manager
|
||||||
|
{
|
||||||
|
// create some objects:
|
||||||
|
$manager = new Manager();
|
||||||
|
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v1';
|
||||||
|
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||||
|
|
||||||
|
return $manager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -201,6 +201,91 @@ class DestroyController extends Controller
|
|||||||
return response()->json([], 204);
|
return response()->json([], 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyBudgets(): void
|
||||||
|
{
|
||||||
|
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
||||||
|
$abRepository = app(AvailableBudgetRepositoryInterface::class);
|
||||||
|
$abRepository->destroyAll();
|
||||||
|
|
||||||
|
/** @var BudgetLimitRepositoryInterface $blRepository */
|
||||||
|
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$blRepository->destroyAll();
|
||||||
|
|
||||||
|
/** @var BudgetRepositoryInterface $budgetRepository */
|
||||||
|
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||||
|
$budgetRepository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyBills(): void
|
||||||
|
{
|
||||||
|
/** @var BillRepositoryInterface $repository */
|
||||||
|
$repository = app(BillRepositoryInterface::class);
|
||||||
|
$repository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyPiggyBanks(): void
|
||||||
|
{
|
||||||
|
/** @var PiggyBankRepositoryInterface $repository */
|
||||||
|
$repository = app(PiggyBankRepositoryInterface::class);
|
||||||
|
$repository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyRules(): void
|
||||||
|
{
|
||||||
|
/** @var RuleGroupRepositoryInterface $repository */
|
||||||
|
$repository = app(RuleGroupRepositoryInterface::class);
|
||||||
|
$repository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyRecurringTransactions(): void
|
||||||
|
{
|
||||||
|
/** @var RecurringRepositoryInterface $repository */
|
||||||
|
$repository = app(RecurringRepositoryInterface::class);
|
||||||
|
$repository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyCategories(): void
|
||||||
|
{
|
||||||
|
/** @var CategoryRepositoryInterface $categoryRepos */
|
||||||
|
$categoryRepos = app(CategoryRepositoryInterface::class);
|
||||||
|
$categoryRepos->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function destroyTags(): void
|
||||||
|
{
|
||||||
|
/** @var TagRepositoryInterface $tagRepository */
|
||||||
|
$tagRepository = app(TagRepositoryInterface::class);
|
||||||
|
$tagRepository->destroyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function destroyObjectGroups(): void
|
||||||
|
{
|
||||||
|
/** @var ObjectGroupRepositoryInterface $repository */
|
||||||
|
$repository = app(ObjectGroupRepositoryInterface::class);
|
||||||
|
$repository->deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $types
|
* @param array $types
|
||||||
*/
|
*/
|
||||||
@@ -226,91 +311,6 @@ class DestroyController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyBills(): void
|
|
||||||
{
|
|
||||||
/** @var BillRepositoryInterface $repository */
|
|
||||||
$repository = app(BillRepositoryInterface::class);
|
|
||||||
$repository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyBudgets(): void
|
|
||||||
{
|
|
||||||
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
|
||||||
$abRepository = app(AvailableBudgetRepositoryInterface::class);
|
|
||||||
$abRepository->destroyAll();
|
|
||||||
|
|
||||||
/** @var BudgetLimitRepositoryInterface $blRepository */
|
|
||||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
|
||||||
$blRepository->destroyAll();
|
|
||||||
|
|
||||||
/** @var BudgetRepositoryInterface $budgetRepository */
|
|
||||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
|
||||||
$budgetRepository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyCategories(): void
|
|
||||||
{
|
|
||||||
/** @var CategoryRepositoryInterface $categoryRepos */
|
|
||||||
$categoryRepos = app(CategoryRepositoryInterface::class);
|
|
||||||
$categoryRepos->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function destroyObjectGroups(): void
|
|
||||||
{
|
|
||||||
/** @var ObjectGroupRepositoryInterface $repository */
|
|
||||||
$repository = app(ObjectGroupRepositoryInterface::class);
|
|
||||||
$repository->deleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyPiggyBanks(): void
|
|
||||||
{
|
|
||||||
/** @var PiggyBankRepositoryInterface $repository */
|
|
||||||
$repository = app(PiggyBankRepositoryInterface::class);
|
|
||||||
$repository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyRecurringTransactions(): void
|
|
||||||
{
|
|
||||||
/** @var RecurringRepositoryInterface $repository */
|
|
||||||
$repository = app(RecurringRepositoryInterface::class);
|
|
||||||
$repository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyRules(): void
|
|
||||||
{
|
|
||||||
/** @var RuleGroupRepositoryInterface $repository */
|
|
||||||
$repository = app(RuleGroupRepositoryInterface::class);
|
|
||||||
$repository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function destroyTags(): void
|
|
||||||
{
|
|
||||||
/** @var TagRepositoryInterface $tagRepository */
|
|
||||||
$tagRepository = app(TagRepositoryInterface::class);
|
|
||||||
$tagRepository->destroyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $types
|
* @param array $types
|
||||||
*/
|
*/
|
||||||
|
@@ -69,6 +69,34 @@ class ExportController extends Controller
|
|||||||
return $this->returnExport('accounts');
|
return $this->returnExport('accounts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @return LaravelResponse
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function returnExport(string $key): LaravelResponse
|
||||||
|
{
|
||||||
|
$date = date('Y-m-d-H-i-s');
|
||||||
|
$fileName = sprintf('%s-export-%s.csv', $date, $key);
|
||||||
|
$data = $this->exporter->export();
|
||||||
|
|
||||||
|
/** @var LaravelResponse $response */
|
||||||
|
$response = response($data[$key]);
|
||||||
|
$response
|
||||||
|
->header('Content-Description', 'File Transfer')
|
||||||
|
->header('Content-Type', 'application/octet-stream')
|
||||||
|
->header('Content-Disposition', 'attachment; filename=' . $fileName)
|
||||||
|
->header('Content-Transfer-Encoding', 'binary')
|
||||||
|
->header('Connection', 'Keep-Alive')
|
||||||
|
->header('Expires', '0')
|
||||||
|
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
||||||
|
->header('Pragma', 'public')
|
||||||
|
->header('Content-Length', (string)strlen($data[$key]));
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportBills
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/data/exportBills
|
||||||
@@ -200,32 +228,4 @@ class ExportController extends Controller
|
|||||||
|
|
||||||
return $this->returnExport('transactions');
|
return $this->returnExport('transactions');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $key
|
|
||||||
*
|
|
||||||
* @return LaravelResponse
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function returnExport(string $key): LaravelResponse
|
|
||||||
{
|
|
||||||
$date = date('Y-m-d-H-i-s');
|
|
||||||
$fileName = sprintf('%s-export-%s.csv', $date, $key);
|
|
||||||
$data = $this->exporter->export();
|
|
||||||
|
|
||||||
/** @var LaravelResponse $response */
|
|
||||||
$response = response($data[$key]);
|
|
||||||
$response
|
|
||||||
->header('Content-Description', 'File Transfer')
|
|
||||||
->header('Content-Type', 'application/octet-stream')
|
|
||||||
->header('Content-Disposition', 'attachment; filename='.$fileName)
|
|
||||||
->header('Content-Transfer-Encoding', 'binary')
|
|
||||||
->header('Connection', 'Keep-Alive')
|
|
||||||
->header('Expires', '0')
|
|
||||||
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
|
|
||||||
->header('Pragma', 'public')
|
|
||||||
->header('Content-Length', (string)strlen($data[$key]));
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.accounts.attachments', [$account->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.accounts.attachments', [$account->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -125,7 +125,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.accounts.piggy-banks', [$account->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.accounts.piggy-banks', [$account->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var PiggyBankTransformer $transformer */
|
/** @var PiggyBankTransformer $transformer */
|
||||||
$transformer = app(PiggyBankTransformer::class);
|
$transformer = app(PiggyBankTransformer::class);
|
||||||
@@ -177,7 +177,7 @@ class ListController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.accounts.transactions', [$account->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.accounts.transactions', [$account->id]) . $this->buildParams());
|
||||||
$groups = $paginator->getCollection();
|
$groups = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -98,7 +98,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.accounts.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.accounts.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var AccountTransformer $transformer */
|
/** @var AccountTransformer $transformer */
|
||||||
$transformer = app(AccountTransformer::class);
|
$transformer = app(AccountTransformer::class);
|
||||||
|
@@ -75,7 +75,7 @@ class UpdateController extends Controller
|
|||||||
{
|
{
|
||||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||||
$data = $request->getUpdateData();
|
$data = $request->getUpdateData();
|
||||||
$data['type'] = config('firefly.shortNamesByFullName.'.$account->accountType->type);
|
$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||||
$account = $this->repository->update($account, $data);
|
$account = $this->repository->update($account, $data);
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
$account->refresh();
|
$account->refresh();
|
||||||
|
@@ -96,7 +96,7 @@ class ShowController extends Controller
|
|||||||
$response
|
$response
|
||||||
->header('Content-Description', 'File Transfer')
|
->header('Content-Description', 'File Transfer')
|
||||||
->header('Content-Type', 'application/octet-stream')
|
->header('Content-Type', 'application/octet-stream')
|
||||||
->header('Content-Disposition', 'attachment; filename='.$quoted)
|
->header('Content-Disposition', 'attachment; filename=' . $quoted)
|
||||||
->header('Content-Transfer-Encoding', 'binary')
|
->header('Content-Transfer-Encoding', 'binary')
|
||||||
->header('Connection', 'Keep-Alive')
|
->header('Connection', 'Keep-Alive')
|
||||||
->header('Expires', '0')
|
->header('Expires', '0')
|
||||||
@@ -132,7 +132,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.attachments.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.attachments.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
|
@@ -88,7 +88,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($availableBudgets, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($availableBudgets, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.available-budgets.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.available-budgets.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var AvailableBudgetTransformer $transformer */
|
/** @var AvailableBudgetTransformer $transformer */
|
||||||
$transformer = app(AvailableBudgetTransformer::class);
|
$transformer = app(AvailableBudgetTransformer::class);
|
||||||
|
@@ -88,7 +88,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.bills.attachments', [$bill->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.bills.attachments', [$bill->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -125,7 +125,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.bills.rules', [$bill->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.bills.rules', [$bill->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var RuleTransformer $transformer */
|
/** @var RuleTransformer $transformer */
|
||||||
$transformer = app(RuleTransformer::class);
|
$transformer = app(RuleTransformer::class);
|
||||||
@@ -184,7 +184,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// get paginator.
|
// get paginator.
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.bills.transactions', [$bill->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.bills.transactions', [$bill->id]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -90,7 +90,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.budgets.attachments', [$budget->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.attachments', [$budget->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -122,7 +122,7 @@ class ListController extends Controller
|
|||||||
$count = $collection->count();
|
$count = $collection->count();
|
||||||
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.budgets.budget-limits', [$budget->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.budget-limits', [$budget->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
@@ -186,7 +186,7 @@ class ListController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.budgets.transactions', [$budget->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.transactions', [$budget->id]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
@@ -249,7 +249,7 @@ class ListController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.budgets.without-budget').$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.without-budget') . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -86,7 +86,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($budgets, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($budgets, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.budgets.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var BudgetTransformer $transformer */
|
/** @var BudgetTransformer $transformer */
|
||||||
$transformer = app(BudgetTransformer::class);
|
$transformer = app(BudgetTransformer::class);
|
||||||
|
@@ -109,7 +109,7 @@ class ListController extends Controller
|
|||||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||||
$collector->setTypes($types);
|
$collector->setTypes($types);
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.budgets.limits.transactions', [$budget->id, $budgetLimit->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.limits.transactions', [$budget->id, $budgetLimit->id]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -90,7 +90,7 @@ class ShowController extends Controller
|
|||||||
$count = $collection->count();
|
$count = $collection->count();
|
||||||
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.budgets.limits.index', [$budget->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.budgets.limits.index', [$budget->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
@@ -122,7 +122,7 @@ class ShowController extends Controller
|
|||||||
$count = $collection->count();
|
$count = $collection->count();
|
||||||
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.budget-limits.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.budget-limits.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
|
@@ -85,7 +85,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.categories.attachments', [$category->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.categories.attachments', [$category->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -143,7 +143,7 @@ class ListController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.categories.transactions', [$category->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.categories.transactions', [$category->id]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -82,7 +82,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($categories, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($categories, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.categories.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.categories.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var CategoryTransformer $transformer */
|
/** @var CategoryTransformer $transformer */
|
||||||
$transformer = app(CategoryTransformer::class);
|
$transformer = app(CategoryTransformer::class);
|
||||||
|
@@ -85,7 +85,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.bills', [$objectGroup->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.bills', [$objectGroup->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var BillTransformer $transformer */
|
/** @var BillTransformer $transformer */
|
||||||
$transformer = app(BillTransformer::class);
|
$transformer = app(BillTransformer::class);
|
||||||
@@ -123,7 +123,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.object-groups.piggy-banks', [$objectGroup->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.object-groups.piggy-banks', [$objectGroup->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var PiggyBankTransformer $transformer */
|
/** @var PiggyBankTransformer $transformer */
|
||||||
$transformer = app(PiggyBankTransformer::class);
|
$transformer = app(PiggyBankTransformer::class);
|
||||||
|
@@ -88,7 +88,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($objectGroups, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($objectGroups, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.object-groups.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.object-groups.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var ObjectGroupTransformer $transformer */
|
/** @var ObjectGroupTransformer $transformer */
|
||||||
$transformer = app(ObjectGroupTransformer::class);
|
$transformer = app(ObjectGroupTransformer::class);
|
||||||
|
@@ -79,7 +79,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.piggy-banks.attachments', [$piggyBank->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.piggy-banks.attachments', [$piggyBank->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -114,7 +114,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.piggy-banks.events', [$piggyBank->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.piggy-banks.events', [$piggyBank->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var PiggyBankEventTransformer $transformer */
|
/** @var PiggyBankEventTransformer $transformer */
|
||||||
$transformer = app(PiggyBankEventTransformer::class);
|
$transformer = app(PiggyBankEventTransformer::class);
|
||||||
|
@@ -81,7 +81,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.piggy-banks.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.piggy-banks.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var PiggyBankTransformer $transformer */
|
/** @var PiggyBankTransformer $transformer */
|
||||||
$transformer = app(PiggyBankTransformer::class);
|
$transformer = app(PiggyBankTransformer::class);
|
||||||
|
@@ -109,7 +109,7 @@ class ListController extends Controller
|
|||||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
}
|
}
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.transactions.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -82,7 +82,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.recurrences.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.recurrences.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var RecurrenceTransformer $transformer */
|
/** @var RecurrenceTransformer $transformer */
|
||||||
$transformer = app(RecurrenceTransformer::class);
|
$transformer = app(RecurrenceTransformer::class);
|
||||||
|
@@ -86,7 +86,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rules.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.rules.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var RuleTransformer $transformer */
|
/** @var RuleTransformer $transformer */
|
||||||
$transformer = app(RuleTransformer::class);
|
$transformer = app(RuleTransformer::class);
|
||||||
|
@@ -102,7 +102,7 @@ class TriggerController extends Controller
|
|||||||
$count = $transactions->count();
|
$count = $transactions->count();
|
||||||
|
|
||||||
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rules.test', [$rule->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.rules.test', [$rule->id]) . $this->buildParams());
|
||||||
|
|
||||||
// resulting list is presented as JSON thing.
|
// resulting list is presented as JSON thing.
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
@@ -84,7 +84,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rule-groups.rules', [$group->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.rule-groups.rules', [$group->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var RuleTransformer $transformer */
|
/** @var RuleTransformer $transformer */
|
||||||
$transformer = app(RuleTransformer::class);
|
$transformer = app(RuleTransformer::class);
|
||||||
|
@@ -84,7 +84,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($ruleGroups, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($ruleGroups, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rule-groups.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.rule-groups.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var RuleGroupTransformer $transformer */
|
/** @var RuleGroupTransformer $transformer */
|
||||||
$transformer = app(RuleGroupTransformer::class);
|
$transformer = app(RuleGroupTransformer::class);
|
||||||
|
@@ -108,7 +108,7 @@ class TriggerController extends Controller
|
|||||||
$count = $transactions->count();
|
$count = $transactions->count();
|
||||||
|
|
||||||
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rule-groups.test', [$group->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.rule-groups.test', [$group->id]) . $this->buildParams());
|
||||||
|
|
||||||
// resulting list is presented as JSON thing.
|
// resulting list is presented as JSON thing.
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
@@ -88,7 +88,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.tags.attachments', [$tag->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.tags.attachments', [$tag->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -143,7 +143,7 @@ class ListController extends Controller
|
|||||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
}
|
}
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.tags.transactions', [$tag->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.tags.transactions', [$tag->id]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -85,7 +85,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.tags.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.tags.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var TagTransformer $transformer */
|
/** @var TagTransformer $transformer */
|
||||||
$transformer = app(TagTransformer::class);
|
$transformer = app(TagTransformer::class);
|
||||||
|
@@ -89,7 +89,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attachments, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.transactions.attachments', [$transactionGroup->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.transactions.attachments', [$transactionGroup->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AttachmentTransformer $transformer */
|
/** @var AttachmentTransformer $transformer */
|
||||||
$transformer = app(AttachmentTransformer::class);
|
$transformer = app(AttachmentTransformer::class);
|
||||||
@@ -122,7 +122,7 @@ class ListController extends Controller
|
|||||||
$events = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$events = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($events, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.transactions.piggy-bank-events', [$transactionGroup->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.transactions.piggy-bank-events', [$transactionGroup->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var PiggyBankEventTransformer $transformer */
|
/** @var PiggyBankEventTransformer $transformer */
|
||||||
$transformer = app(PiggyBankEventTransformer::class);
|
$transformer = app(PiggyBankEventTransformer::class);
|
||||||
@@ -158,7 +158,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($journalLinks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($journalLinks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.transaction-journals.transaction-links', [$transactionJournal->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.transaction-journals.transaction-links', [$transactionJournal->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var TransactionLinkTransformer $transformer */
|
/** @var TransactionLinkTransformer $transformer */
|
||||||
$transformer = app(TransactionLinkTransformer::class);
|
$transformer = app(TransactionLinkTransformer::class);
|
||||||
|
@@ -84,7 +84,7 @@ class ShowController extends Controller
|
|||||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
}
|
}
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.transactions.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
@@ -97,6 +97,21 @@ class ShowController extends Controller
|
|||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint is documented at:
|
||||||
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/transactions/getTransactionByJournal
|
||||||
|
*
|
||||||
|
* Show a single transaction, by transaction journal.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $transactionJournal
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function showJournal(TransactionJournal $transactionJournal): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->show($transactionJournal->transactionGroup);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/transactions/getTransaction
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/transactions/getTransaction
|
||||||
@@ -133,19 +148,4 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This endpoint is documented at:
|
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/transactions/getTransactionByJournal
|
|
||||||
*
|
|
||||||
* Show a single transaction, by transaction journal.
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $transactionJournal
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function showJournal(TransactionJournal $transactionJournal): JsonResponse
|
|
||||||
{
|
|
||||||
return $this->show($transactionJournal->transactionGroup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -127,7 +127,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.accounts', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.accounts', [$currency->code]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AccountTransformer $transformer */
|
/** @var AccountTransformer $transformer */
|
||||||
$transformer = app(AccountTransformer::class);
|
$transformer = app(AccountTransformer::class);
|
||||||
@@ -164,7 +164,7 @@ class ListController extends Controller
|
|||||||
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($availableBudgets, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($availableBudgets, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.available-budgets', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.available-budgets', [$currency->code]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var AvailableBudgetTransformer $transformer */
|
/** @var AvailableBudgetTransformer $transformer */
|
||||||
$transformer = app(AvailableBudgetTransformer::class);
|
$transformer = app(AvailableBudgetTransformer::class);
|
||||||
@@ -207,7 +207,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.bills', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.bills', [$currency->code]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var BillTransformer $transformer */
|
/** @var BillTransformer $transformer */
|
||||||
$transformer = app(BillTransformer::class);
|
$transformer = app(BillTransformer::class);
|
||||||
@@ -241,7 +241,7 @@ class ListController extends Controller
|
|||||||
$count = $collection->count();
|
$count = $collection->count();
|
||||||
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.budget-limits', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.budget-limits', [$currency->code]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
@@ -293,7 +293,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.recurrences', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.recurrences', [$currency->code]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var RecurrenceTransformer $transformer */
|
/** @var RecurrenceTransformer $transformer */
|
||||||
$transformer = app(RecurrenceTransformer::class);
|
$transformer = app(RecurrenceTransformer::class);
|
||||||
@@ -344,7 +344,7 @@ class ListController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.rules.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.rules.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var RuleTransformer $transformer */
|
/** @var RuleTransformer $transformer */
|
||||||
$transformer = app(RuleTransformer::class);
|
$transformer = app(RuleTransformer::class);
|
||||||
@@ -400,7 +400,7 @@ class ListController extends Controller
|
|||||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
}
|
}
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]).$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]) . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -84,7 +84,7 @@ class ShowController extends Controller
|
|||||||
// slice them:
|
// slice them:
|
||||||
$currencies = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$currencies = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
$paginator = new LengthAwarePaginator($currencies, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($currencies, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.currencies.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.currencies.index') . $this->buildParams());
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
$defaultCurrency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
||||||
$this->parameters->set('defaultCurrency', $defaultCurrency);
|
$this->parameters->set('defaultCurrency', $defaultCurrency);
|
||||||
|
@@ -97,35 +97,6 @@ class UpdateController extends Controller
|
|||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This endpoint is documented at:
|
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/enableCurrency
|
|
||||||
*
|
|
||||||
* Enable a currency.
|
|
||||||
*
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @throws FireflyException
|
|
||||||
* @throws JsonException
|
|
||||||
*/
|
|
||||||
public function enable(TransactionCurrency $currency): JsonResponse
|
|
||||||
{
|
|
||||||
$this->repository->enable($currency);
|
|
||||||
$manager = $this->getManager();
|
|
||||||
|
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
|
||||||
$this->parameters->set('defaultCurrency', $defaultCurrency);
|
|
||||||
|
|
||||||
/** @var CurrencyTransformer $transformer */
|
|
||||||
$transformer = app(CurrencyTransformer::class);
|
|
||||||
$transformer->setParameters($this->parameters);
|
|
||||||
|
|
||||||
$resource = new Item($currency, $transformer, 'currencies');
|
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/defaultCurrency
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/defaultCurrency
|
||||||
@@ -157,6 +128,35 @@ class UpdateController extends Controller
|
|||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This endpoint is documented at:
|
||||||
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/enableCurrency
|
||||||
|
*
|
||||||
|
* Enable a currency.
|
||||||
|
*
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws FireflyException
|
||||||
|
* @throws JsonException
|
||||||
|
*/
|
||||||
|
public function enable(TransactionCurrency $currency): JsonResponse
|
||||||
|
{
|
||||||
|
$this->repository->enable($currency);
|
||||||
|
$manager = $this->getManager();
|
||||||
|
|
||||||
|
$defaultCurrency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
||||||
|
$this->parameters->set('defaultCurrency', $defaultCurrency);
|
||||||
|
|
||||||
|
/** @var CurrencyTransformer $transformer */
|
||||||
|
$transformer = app(CurrencyTransformer::class);
|
||||||
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
|
$resource = new Item($currency, $transformer, 'currencies');
|
||||||
|
|
||||||
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/updateCurrency
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/updateCurrency
|
||||||
|
@@ -92,7 +92,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($journalLinks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($journalLinks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.transaction-links.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.transaction-links.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var TransactionLinkTransformer $transformer */
|
/** @var TransactionLinkTransformer $transformer */
|
||||||
$transformer = app(TransactionLinkTransformer::class);
|
$transformer = app(TransactionLinkTransformer::class);
|
||||||
|
@@ -110,7 +110,7 @@ class ListController extends Controller
|
|||||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
}
|
}
|
||||||
$paginator = $collector->getPaginatedGroups();
|
$paginator = $collector->getPaginatedGroups();
|
||||||
$paginator->setPath(route('api.v1.transactions.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
|
||||||
$transactions = $paginator->getCollection();
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
@@ -87,7 +87,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($linkTypes, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($linkTypes, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.link-types.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.link-types.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var LinkTypeTransformer $transformer */
|
/** @var LinkTypeTransformer $transformer */
|
||||||
$transformer = app(LinkTypeTransformer::class);
|
$transformer = app(LinkTypeTransformer::class);
|
||||||
|
@@ -33,7 +33,6 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use JsonException;
|
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
use League\Fractal\Resource\Collection as FractalCollection;
|
use League\Fractal\Resource\Collection as FractalCollection;
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ class AccountController extends Controller
|
|||||||
*
|
*
|
||||||
* @return JsonResponse|Response
|
* @return JsonResponse|Response
|
||||||
*/
|
*/
|
||||||
public function search(Request $request): JsonResponse|Response
|
public function search(Request $request): JsonResponse | Response
|
||||||
{
|
{
|
||||||
Log::debug('Now in account search()');
|
Log::debug('Now in account search()');
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
@@ -60,7 +60,7 @@ class TransactionController extends Controller
|
|||||||
$searcher->setLimit($pageSize);
|
$searcher->setLimit($pageSize);
|
||||||
$groups = $searcher->searchTransactions();
|
$groups = $searcher->searchTransactions();
|
||||||
$parameters = ['search' => $fullQuery];
|
$parameters = ['search' => $fullQuery];
|
||||||
$url = route('api.v1.search.transactions').'?'.http_build_query($parameters);
|
$url = route('api.v1.search.transactions') . '?' . http_build_query($parameters);
|
||||||
$groups->setPath($url);
|
$groups->setPath($url);
|
||||||
$transactions = $groups->getCollection();
|
$transactions = $groups->getCollection();
|
||||||
|
|
||||||
|
@@ -121,30 +121,6 @@ class BasicController extends Controller
|
|||||||
return response()->json($return);
|
return response()->json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if date is outside session range.
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
|
|
||||||
{
|
|
||||||
$result = false;
|
|
||||||
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
|
|
||||||
$result = true;
|
|
||||||
}
|
|
||||||
// start and end in the past? use $end
|
|
||||||
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
|
|
||||||
$result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
@@ -220,8 +196,8 @@ class BasicController extends Controller
|
|||||||
'currency_decimal_places' => $currency->decimal_places,
|
'currency_decimal_places' => $currency->decimal_places,
|
||||||
'value_parsed' => app('amount')->formatAnything($currency, $sums[$currencyId] ?? '0', false),
|
'value_parsed' => app('amount')->formatAnything($currency, $sums[$currencyId] ?? '0', false),
|
||||||
'local_icon' => 'balance-scale',
|
'local_icon' => 'balance-scale',
|
||||||
'sub_title' => app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false).
|
'sub_title' => app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false) .
|
||||||
' + '.app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false),
|
' + ' . app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false),
|
||||||
];
|
];
|
||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('spent-in-%s', $currency->code),
|
'key' => sprintf('spent-in-%s', $currency->code),
|
||||||
@@ -422,4 +398,28 @@ class BasicController extends Controller
|
|||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if date is outside session range.
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
|
||||||
|
{
|
||||||
|
$result = false;
|
||||||
|
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
// start and end in the past? use $end
|
||||||
|
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -94,6 +94,42 @@ class ConfigurationController extends Controller
|
|||||||
return response()->json($return);
|
return response()->json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all config values.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function getDynamicConfiguration(): array
|
||||||
|
{
|
||||||
|
$isDemoSite = app('fireflyconfig')->get('is_demo_site');
|
||||||
|
$updateCheck = app('fireflyconfig')->get('permission_update_check');
|
||||||
|
$lastCheck = app('fireflyconfig')->get('last_update_check');
|
||||||
|
$singleUser = app('fireflyconfig')->get('single_user_mode');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'is_demo_site' => $isDemoSite?->data,
|
||||||
|
'permission_update_check' => null === $updateCheck ? null : (int)$updateCheck->data,
|
||||||
|
'last_update_check' => null === $lastCheck ? null : (int)$lastCheck->data,
|
||||||
|
'single_user_mode' => $singleUser?->data,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getStaticConfiguration(): array
|
||||||
|
{
|
||||||
|
$list = EitherConfigKey::$static;
|
||||||
|
$return = [];
|
||||||
|
foreach ($list as $key) {
|
||||||
|
$return[$key] = config($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/configuration/getSingleConfiguration
|
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/configuration/getSingleConfiguration
|
||||||
@@ -164,40 +200,4 @@ class ConfigurationController extends Controller
|
|||||||
|
|
||||||
return response()->json(['data' => $data])->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json(['data' => $data])->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all config values.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
private function getDynamicConfiguration(): array
|
|
||||||
{
|
|
||||||
$isDemoSite = app('fireflyconfig')->get('is_demo_site');
|
|
||||||
$updateCheck = app('fireflyconfig')->get('permission_update_check');
|
|
||||||
$lastCheck = app('fireflyconfig')->get('last_update_check');
|
|
||||||
$singleUser = app('fireflyconfig')->get('single_user_mode');
|
|
||||||
|
|
||||||
return [
|
|
||||||
'is_demo_site' => $isDemoSite?->data,
|
|
||||||
'permission_update_check' => null === $updateCheck ? null : (int)$updateCheck->data,
|
|
||||||
'last_update_check' => null === $lastCheck ? null : (int)$lastCheck->data,
|
|
||||||
'single_user_mode' => $singleUser?->data,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getStaticConfiguration(): array
|
|
||||||
{
|
|
||||||
$list = EitherConfigKey::$static;
|
|
||||||
$return = [];
|
|
||||||
foreach ($list as $key) {
|
|
||||||
$return[$key] = config($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ class UserController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($users, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($users, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.users.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.users.index') . $this->buildParams());
|
||||||
|
|
||||||
// make resource
|
// make resource
|
||||||
/** @var UserTransformer $transformer */
|
/** @var UserTransformer $transformer */
|
||||||
|
@@ -63,7 +63,7 @@ class PreferencesController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($preferences, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($preferences, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.preferences.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.preferences.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var PreferenceTransformer $transformer */
|
/** @var PreferenceTransformer $transformer */
|
||||||
$transformer = app(PreferenceTransformer::class);
|
$transformer = app(PreferenceTransformer::class);
|
||||||
|
@@ -83,7 +83,7 @@ class AttemptController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($attempts, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($attempts, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.webhooks.attempts.index', [$webhook->id, $message->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.webhooks.attempts.index', [$webhook->id, $message->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var WebhookAttemptTransformer $transformer */
|
/** @var WebhookAttemptTransformer $transformer */
|
||||||
$transformer = app(WebhookAttemptTransformer::class);
|
$transformer = app(WebhookAttemptTransformer::class);
|
||||||
|
@@ -75,7 +75,7 @@ class MessageController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($messages, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($messages, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.webhooks.messages.index', [$webhook->id]).$this->buildParams());
|
$paginator->setPath(route('api.v1.webhooks.messages.index', [$webhook->id]) . $this->buildParams());
|
||||||
|
|
||||||
/** @var WebhookMessageTransformer $transformer */
|
/** @var WebhookMessageTransformer $transformer */
|
||||||
$transformer = app(WebhookMessageTransformer::class);
|
$transformer = app(WebhookMessageTransformer::class);
|
||||||
|
@@ -80,7 +80,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($webhooks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($webhooks, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.webhooks.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.webhooks.index') . $this->buildParams());
|
||||||
|
|
||||||
/** @var WebhookTransformer $transformer */
|
/** @var WebhookTransformer $transformer */
|
||||||
$transformer = app(WebhookTransformer::class);
|
$transformer = app(WebhookTransformer::class);
|
||||||
|
@@ -52,8 +52,8 @@ class DestroyRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups'.
|
$valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups' .
|
||||||
',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers'.
|
',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers' .
|
||||||
',not_assets_liabilities';
|
',not_assets_liabilities';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@@ -82,6 +82,28 @@ class GenericRequest extends FormRequest
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function parseAccounts(): void
|
||||||
|
{
|
||||||
|
if (0 !== $this->accounts->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
$repository->setUser(auth()->user());
|
||||||
|
$array = $this->get('accounts');
|
||||||
|
if (is_array($array)) {
|
||||||
|
foreach ($array as $accountId) {
|
||||||
|
$accountId = (int)$accountId;
|
||||||
|
$account = $repository->find($accountId);
|
||||||
|
if (null !== $account) {
|
||||||
|
$this->accounts->push($account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +114,28 @@ class GenericRequest extends FormRequest
|
|||||||
return $this->bills;
|
return $this->bills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function parseBills(): void
|
||||||
|
{
|
||||||
|
if (0 !== $this->bills->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$repository = app(BillRepositoryInterface::class);
|
||||||
|
$repository->setUser(auth()->user());
|
||||||
|
$array = $this->get('bills');
|
||||||
|
if (is_array($array)) {
|
||||||
|
foreach ($array as $billId) {
|
||||||
|
$billId = (int)$billId;
|
||||||
|
$bill = $repository->find($billId);
|
||||||
|
if (null !== $bill) {
|
||||||
|
$this->bills->push($bill);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +146,28 @@ class GenericRequest extends FormRequest
|
|||||||
return $this->budgets;
|
return $this->budgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function parseBudgets(): void
|
||||||
|
{
|
||||||
|
if (0 !== $this->budgets->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$repository = app(BudgetRepositoryInterface::class);
|
||||||
|
$repository->setUser(auth()->user());
|
||||||
|
$array = $this->get('budgets');
|
||||||
|
if (is_array($array)) {
|
||||||
|
foreach ($array as $budgetId) {
|
||||||
|
$budgetId = (int)$budgetId;
|
||||||
|
$budget = $repository->find($budgetId);
|
||||||
|
if (null !== $budget) {
|
||||||
|
$this->budgets->push($budget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@@ -112,6 +178,28 @@ class GenericRequest extends FormRequest
|
|||||||
return $this->categories;
|
return $this->categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function parseCategories(): void
|
||||||
|
{
|
||||||
|
if (0 !== $this->categories->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$repository = app(CategoryRepositoryInterface::class);
|
||||||
|
$repository->setUser(auth()->user());
|
||||||
|
$array = $this->get('categories');
|
||||||
|
if (is_array($array)) {
|
||||||
|
foreach ($array as $categoryId) {
|
||||||
|
$categoryId = (int)$categoryId;
|
||||||
|
$category = $repository->find($categoryId);
|
||||||
|
if (null !== $category) {
|
||||||
|
$this->categories->push($category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
*/
|
*/
|
||||||
@@ -180,114 +268,6 @@ class GenericRequest extends FormRequest
|
|||||||
return $this->tags;
|
return $this->tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The rules that the incoming request must be matched against.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
// this is cheating, but it works to initialize the collections.
|
|
||||||
$this->accounts = new Collection();
|
|
||||||
$this->budgets = new Collection();
|
|
||||||
$this->categories = new Collection();
|
|
||||||
$this->bills = new Collection();
|
|
||||||
$this->tags = new Collection();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'start' => 'required|date',
|
|
||||||
'end' => 'required|date|after_or_equal:start',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function parseAccounts(): void
|
|
||||||
{
|
|
||||||
if (0 !== $this->accounts->count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
$repository->setUser(auth()->user());
|
|
||||||
$array = $this->get('accounts');
|
|
||||||
if (is_array($array)) {
|
|
||||||
foreach ($array as $accountId) {
|
|
||||||
$accountId = (int)$accountId;
|
|
||||||
$account = $repository->find($accountId);
|
|
||||||
if (null !== $account) {
|
|
||||||
$this->accounts->push($account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function parseBills(): void
|
|
||||||
{
|
|
||||||
if (0 !== $this->bills->count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$repository = app(BillRepositoryInterface::class);
|
|
||||||
$repository->setUser(auth()->user());
|
|
||||||
$array = $this->get('bills');
|
|
||||||
if (is_array($array)) {
|
|
||||||
foreach ($array as $billId) {
|
|
||||||
$billId = (int)$billId;
|
|
||||||
$bill = $repository->find($billId);
|
|
||||||
if (null !== $bill) {
|
|
||||||
$this->bills->push($bill);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function parseBudgets(): void
|
|
||||||
{
|
|
||||||
if (0 !== $this->budgets->count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$repository = app(BudgetRepositoryInterface::class);
|
|
||||||
$repository->setUser(auth()->user());
|
|
||||||
$array = $this->get('budgets');
|
|
||||||
if (is_array($array)) {
|
|
||||||
foreach ($array as $budgetId) {
|
|
||||||
$budgetId = (int)$budgetId;
|
|
||||||
$budget = $repository->find($budgetId);
|
|
||||||
if (null !== $budget) {
|
|
||||||
$this->budgets->push($budget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function parseCategories(): void
|
|
||||||
{
|
|
||||||
if (0 !== $this->categories->count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$repository = app(CategoryRepositoryInterface::class);
|
|
||||||
$repository->setUser(auth()->user());
|
|
||||||
$array = $this->get('categories');
|
|
||||||
if (is_array($array)) {
|
|
||||||
foreach ($array as $categoryId) {
|
|
||||||
$categoryId = (int)$categoryId;
|
|
||||||
$category = $repository->find($categoryId);
|
|
||||||
if (null !== $category) {
|
|
||||||
$this->categories->push($category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -309,4 +289,24 @@ class GenericRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rules that the incoming request must be matched against.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
// this is cheating, but it works to initialize the collections.
|
||||||
|
$this->accounts = new Collection();
|
||||||
|
$this->budgets = new Collection();
|
||||||
|
$this->categories = new Collection();
|
||||||
|
$this->bills = new Collection();
|
||||||
|
$this->tags = new Collection();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'start' => 'required|date',
|
||||||
|
'end' => 'required|date|after_or_equal:start',
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,7 +104,7 @@ class StoreRequest extends FormRequest
|
|||||||
$type = $this->convertString('type');
|
$type = $this->convertString('type');
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|max:1024|min:1|uniqueAccountForUser',
|
'name' => 'required|max:1024|min:1|uniqueAccountForUser',
|
||||||
'type' => 'required|max:1024|min:1|'.sprintf('in:%s', $types),
|
'type' => 'required|max:1024|min:1|' . sprintf('in:%s', $types),
|
||||||
'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
|
'iban' => ['iban', 'nullable', new UniqueIban(null, $type)],
|
||||||
'bic' => 'bic|nullable',
|
'bic' => 'bic|nullable',
|
||||||
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber(null, $type)],
|
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber(null, $type)],
|
||||||
|
@@ -109,7 +109,7 @@ class UpdateRequest extends FormRequest
|
|||||||
'include_net_worth' => [new IsBoolean()],
|
'include_net_worth' => [new IsBoolean()],
|
||||||
'account_role' => sprintf('in:%s|nullable|required_if:type,asset', $accountRoles),
|
'account_role' => sprintf('in:%s|nullable|required_if:type,asset', $accountRoles),
|
||||||
'credit_card_type' => sprintf('in:%s|nullable|required_if:account_role,ccAsset', $ccPaymentTypes),
|
'credit_card_type' => sprintf('in:%s|nullable|required_if:account_role,ccAsset', $ccPaymentTypes),
|
||||||
'monthly_payment_date' => 'date'.'|nullable|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
|
'monthly_payment_date' => 'date' . '|nullable|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
|
||||||
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
|
'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',
|
||||||
'liability_direction' => 'required_if:type,liability|in:credit,debit',
|
'liability_direction' => 'required_if:type,liability|in:credit,debit',
|
||||||
'interest' => 'required_if:type,liability|between:0,100|numeric',
|
'interest' => 'required_if:type,liability|between:0,100|numeric',
|
||||||
|
@@ -74,7 +74,7 @@ class UpdateRequest extends FormRequest
|
|||||||
$piggyBank = $this->route()->parameter('piggyBank');
|
$piggyBank = $this->route()->parameter('piggyBank');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => 'between:1,255|uniquePiggyBankForUser:'.$piggyBank->id,
|
'name' => 'between:1,255|uniquePiggyBankForUser:' . $piggyBank->id,
|
||||||
'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget()],
|
'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget()],
|
||||||
'target_amount' => 'numeric|gte:0',
|
'target_amount' => 'numeric|gte:0',
|
||||||
'start_date' => 'date|nullable',
|
'start_date' => 'date|nullable',
|
||||||
|
@@ -73,6 +73,65 @@ class StoreRequest extends FormRequest
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
|
||||||
|
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getTransactionData(): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// transaction data:
|
||||||
|
/** @var array|null $transactions */
|
||||||
|
$transactions = $this->get('transactions');
|
||||||
|
if (null === $transactions) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
/** @var array $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$return[] = $this->getSingleTransactionData($transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the repetition data as it is found in the submitted data.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getRepetitionData(): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// repetition data:
|
||||||
|
/** @var array|null $repetitions */
|
||||||
|
$repetitions = $this->get('repetitions');
|
||||||
|
if (null === $repetitions) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
/** @var array $repetition */
|
||||||
|
foreach ($repetitions as $repetition) {
|
||||||
|
$current = [];
|
||||||
|
if (array_key_exists('type', $repetition)) {
|
||||||
|
$current['type'] = $repetition['type'];
|
||||||
|
}
|
||||||
|
if (array_key_exists('moment', $repetition)) {
|
||||||
|
$current['moment'] = $repetition['moment'];
|
||||||
|
}
|
||||||
|
if (array_key_exists('skip', $repetition)) {
|
||||||
|
$current['skip'] = (int)$repetition['skip'];
|
||||||
|
}
|
||||||
|
if (array_key_exists('weekend', $repetition)) {
|
||||||
|
$current['weekend'] = (int)$repetition['weekend'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$return[] = $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules that the incoming request must be matched against.
|
* The rules that the incoming request must be matched against.
|
||||||
*
|
*
|
||||||
@@ -139,63 +198,4 @@ class StoreRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the repetition data as it is found in the submitted data.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getRepetitionData(): array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
// repetition data:
|
|
||||||
/** @var array|null $repetitions */
|
|
||||||
$repetitions = $this->get('repetitions');
|
|
||||||
if (null === $repetitions) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
/** @var array $repetition */
|
|
||||||
foreach ($repetitions as $repetition) {
|
|
||||||
$current = [];
|
|
||||||
if (array_key_exists('type', $repetition)) {
|
|
||||||
$current['type'] = $repetition['type'];
|
|
||||||
}
|
|
||||||
if (array_key_exists('moment', $repetition)) {
|
|
||||||
$current['moment'] = $repetition['moment'];
|
|
||||||
}
|
|
||||||
if (array_key_exists('skip', $repetition)) {
|
|
||||||
$current['skip'] = (int)$repetition['skip'];
|
|
||||||
}
|
|
||||||
if (array_key_exists('weekend', $repetition)) {
|
|
||||||
$current['weekend'] = (int)$repetition['weekend'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$return[] = $current;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
|
|
||||||
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getTransactionData(): array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
// transaction data:
|
|
||||||
/** @var array|null $transactions */
|
|
||||||
$transactions = $this->get('transactions');
|
|
||||||
if (null === $transactions) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
/** @var array $transaction */
|
|
||||||
foreach ($transactions as $transaction) {
|
|
||||||
$return[] = $this->getSingleTransactionData($transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -80,6 +80,70 @@ class UpdateRequest extends FormRequest
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the repetition data as it is found in the submitted data.
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
private function getRepetitionData(): ?array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// repetition data:
|
||||||
|
/** @var array|null $repetitions */
|
||||||
|
$repetitions = $this->get('repetitions');
|
||||||
|
if (null === $repetitions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/** @var array $repetition */
|
||||||
|
foreach ($repetitions as $repetition) {
|
||||||
|
$current = [];
|
||||||
|
if (array_key_exists('type', $repetition)) {
|
||||||
|
$current['type'] = $repetition['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('moment', $repetition)) {
|
||||||
|
$current['moment'] = (string)$repetition['moment'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('skip', $repetition)) {
|
||||||
|
$current['skip'] = (int)$repetition['skip'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('weekend', $repetition)) {
|
||||||
|
$current['weekend'] = (int)$repetition['weekend'];
|
||||||
|
}
|
||||||
|
$return[] = $current;
|
||||||
|
}
|
||||||
|
if (0 === count($return)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
|
||||||
|
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
private function getTransactionData(): ?array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// transaction data:
|
||||||
|
/** @var array|null $transactions */
|
||||||
|
$transactions = $this->get('transactions');
|
||||||
|
if (null === $transactions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/** @var array $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$return[] = $this->getSingleTransactionData($transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules that the incoming request must be matched against.
|
* The rules that the incoming request must be matched against.
|
||||||
*
|
*
|
||||||
@@ -154,68 +218,4 @@ class UpdateRequest extends FormRequest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the repetition data as it is found in the submitted data.
|
|
||||||
*
|
|
||||||
* @return array|null
|
|
||||||
*/
|
|
||||||
private function getRepetitionData(): ?array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
// repetition data:
|
|
||||||
/** @var array|null $repetitions */
|
|
||||||
$repetitions = $this->get('repetitions');
|
|
||||||
if (null === $repetitions) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/** @var array $repetition */
|
|
||||||
foreach ($repetitions as $repetition) {
|
|
||||||
$current = [];
|
|
||||||
if (array_key_exists('type', $repetition)) {
|
|
||||||
$current['type'] = $repetition['type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists('moment', $repetition)) {
|
|
||||||
$current['moment'] = (string)$repetition['moment'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists('skip', $repetition)) {
|
|
||||||
$current['skip'] = (int)$repetition['skip'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists('weekend', $repetition)) {
|
|
||||||
$current['weekend'] = (int)$repetition['weekend'];
|
|
||||||
}
|
|
||||||
$return[] = $current;
|
|
||||||
}
|
|
||||||
if (0 === count($return)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
|
|
||||||
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
|
|
||||||
*
|
|
||||||
* @return array|null
|
|
||||||
*/
|
|
||||||
private function getTransactionData(): ?array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
// transaction data:
|
|
||||||
/** @var array|null $transactions */
|
|
||||||
$transactions = $this->get('transactions');
|
|
||||||
if (null === $transactions) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/** @var array $transaction */
|
|
||||||
foreach ($transactions as $transaction) {
|
|
||||||
$return[] = $this->getSingleTransactionData($transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,48 @@ class StoreRequest extends FormRequest
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getRuleTriggers(): array
|
||||||
|
{
|
||||||
|
$triggers = $this->get('triggers');
|
||||||
|
$return = [];
|
||||||
|
if (is_array($triggers)) {
|
||||||
|
foreach ($triggers as $trigger) {
|
||||||
|
$return[] = [
|
||||||
|
'type' => $trigger['type'],
|
||||||
|
'value' => $trigger['value'],
|
||||||
|
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'true')),
|
||||||
|
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getRuleActions(): array
|
||||||
|
{
|
||||||
|
$actions = $this->get('actions');
|
||||||
|
$return = [];
|
||||||
|
if (is_array($actions)) {
|
||||||
|
foreach ($actions as $action) {
|
||||||
|
$return[] = [
|
||||||
|
'type' => $action['type'],
|
||||||
|
'value' => $action['value'],
|
||||||
|
'active' => $this->convertBoolean((string)($action['active'] ?? 'true')),
|
||||||
|
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules that the incoming request must be matched against.
|
* The rules that the incoming request must be matched against.
|
||||||
*
|
*
|
||||||
@@ -87,12 +129,12 @@ class StoreRequest extends FormRequest
|
|||||||
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
|
'rule_group_id' => 'belongsToUser:rule_groups|required_without:rule_group_title',
|
||||||
'rule_group_title' => 'nullable|between:1,255|required_without:rule_group_id|belongsToUser:rule_groups,title',
|
'rule_group_title' => 'nullable|between:1,255|required_without:rule_group_id|belongsToUser:rule_groups,title',
|
||||||
'trigger' => 'required|in:store-journal,update-journal',
|
'trigger' => 'required|in:store-journal,update-journal',
|
||||||
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
|
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
|
||||||
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
|
'triggers.*.value' => 'required_if:actions.*.type,' . $contextTriggers . '|min:1|ruleTriggerValue|max:1024',
|
||||||
'triggers.*.stop_processing' => [new IsBoolean()],
|
'triggers.*.stop_processing' => [new IsBoolean()],
|
||||||
'triggers.*.active' => [new IsBoolean()],
|
'triggers.*.active' => [new IsBoolean()],
|
||||||
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
'actions.*.type' => 'required|in:' . implode(',', $validActions),
|
||||||
'actions.*.value' => 'required_if:actions.*.type,'.$contextActions.'|ruleActionValue',
|
'actions.*.value' => 'required_if:actions.*.type,' . $contextActions . '|ruleActionValue',
|
||||||
'actions.*.stop_processing' => [new IsBoolean()],
|
'actions.*.stop_processing' => [new IsBoolean()],
|
||||||
'actions.*.active' => [new IsBoolean()],
|
'actions.*.active' => [new IsBoolean()],
|
||||||
'strict' => [new IsBoolean()],
|
'strict' => [new IsBoolean()],
|
||||||
@@ -120,6 +162,21 @@ class StoreRequest extends FormRequest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an error to the validator when there are no triggers in the array of data.
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
|
*/
|
||||||
|
protected function atLeastOneTrigger(Validator $validator): void
|
||||||
|
{
|
||||||
|
$data = $validator->getData();
|
||||||
|
$triggers = $data['triggers'] ?? [];
|
||||||
|
// need at least one trigger
|
||||||
|
if (!is_countable($triggers) || 0 === count($triggers)) {
|
||||||
|
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
*
|
*
|
||||||
@@ -135,35 +192,6 @@ class StoreRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an error to the validator when there are no ACTIVE actions in the array of data.
|
|
||||||
*
|
|
||||||
* @param Validator $validator
|
|
||||||
*/
|
|
||||||
protected function atLeastOneActiveAction(Validator $validator): void
|
|
||||||
{
|
|
||||||
$data = $validator->getData();
|
|
||||||
$actions = $data['actions'] ?? [];
|
|
||||||
// need at least one trigger
|
|
||||||
if (!is_countable($actions) || 0 === count($actions)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$allInactive = true;
|
|
||||||
$inactiveIndex = 0;
|
|
||||||
foreach ($actions as $index => $action) {
|
|
||||||
$active = array_key_exists('active', $action) ? $action['active'] : true; // assume true
|
|
||||||
if (true === $active) {
|
|
||||||
$allInactive = false;
|
|
||||||
}
|
|
||||||
if (false === $active) {
|
|
||||||
$inactiveIndex = $index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (true === $allInactive) {
|
|
||||||
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no ACTIVE triggers in the array of data.
|
* Adds an error to the validator when there are no ACTIVE triggers in the array of data.
|
||||||
*
|
*
|
||||||
@@ -194,59 +222,31 @@ class StoreRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no triggers in the array of data.
|
* Adds an error to the validator when there are no ACTIVE actions in the array of data.
|
||||||
*
|
*
|
||||||
* @param Validator $validator
|
* @param Validator $validator
|
||||||
*/
|
*/
|
||||||
protected function atLeastOneTrigger(Validator $validator): void
|
protected function atLeastOneActiveAction(Validator $validator): void
|
||||||
{
|
{
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
$triggers = $data['triggers'] ?? [];
|
$actions = $data['actions'] ?? [];
|
||||||
// need at least one trigger
|
// need at least one trigger
|
||||||
if (!is_countable($triggers) || 0 === count($triggers)) {
|
if (!is_countable($actions) || 0 === count($actions)) {
|
||||||
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
|
return;
|
||||||
|
}
|
||||||
|
$allInactive = true;
|
||||||
|
$inactiveIndex = 0;
|
||||||
|
foreach ($actions as $index => $action) {
|
||||||
|
$active = array_key_exists('active', $action) ? $action['active'] : true; // assume true
|
||||||
|
if (true === $active) {
|
||||||
|
$allInactive = false;
|
||||||
|
}
|
||||||
|
if (false === $active) {
|
||||||
|
$inactiveIndex = $index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (true === $allInactive) {
|
||||||
/**
|
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getRuleActions(): array
|
|
||||||
{
|
|
||||||
$actions = $this->get('actions');
|
|
||||||
$return = [];
|
|
||||||
if (is_array($actions)) {
|
|
||||||
foreach ($actions as $action) {
|
|
||||||
$return[] = [
|
|
||||||
'type' => $action['type'],
|
|
||||||
'value' => $action['value'],
|
|
||||||
'active' => $this->convertBoolean((string)($action['active'] ?? 'true')),
|
|
||||||
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getRuleTriggers(): array
|
|
||||||
{
|
|
||||||
$triggers = $this->get('triggers');
|
|
||||||
$return = [];
|
|
||||||
if (is_array($triggers)) {
|
|
||||||
foreach ($triggers as $trigger) {
|
|
||||||
$return[] = [
|
|
||||||
'type' => $trigger['type'],
|
|
||||||
'value' => $trigger['value'],
|
|
||||||
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'true')),
|
|
||||||
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -52,24 +52,11 @@ class TestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getPage(): int
|
||||||
{
|
{
|
||||||
return [
|
return 0 === (int)$this->query('page') ? 1 : (int)$this->query('page');
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after_or_equal:start',
|
|
||||||
'accounts' => '',
|
|
||||||
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getAccounts(): array
|
|
||||||
{
|
|
||||||
return $this->get('accounts');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,10 +70,23 @@ class TestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getPage(): int
|
private function getAccounts(): array
|
||||||
{
|
{
|
||||||
return 0 === (int)$this->query('page') ? 1 : (int)$this->query('page');
|
return $this->get('accounts');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after_or_equal:start',
|
||||||
|
'accounts' => '',
|
||||||
|
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,16 +50,13 @@ class TriggerRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return Carbon|null
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getDate(string $field): ?Carbon
|
||||||
{
|
{
|
||||||
return [
|
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($this->query($field), 0, 10));
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after_or_equal:start',
|
|
||||||
'accounts' => '',
|
|
||||||
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,12 +68,15 @@ class TriggerRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @return array
|
||||||
*
|
|
||||||
* @return Carbon|null
|
|
||||||
*/
|
*/
|
||||||
private function getDate(string $field): ?Carbon
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($this->query($field), 0, 10));
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after_or_equal:start',
|
||||||
|
'accounts' => '',
|
||||||
|
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -73,6 +73,56 @@ class UpdateRequest extends FormRequest
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
private function getRuleTriggers(): ?array
|
||||||
|
{
|
||||||
|
if (!$this->has('triggers')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$triggers = $this->get('triggers');
|
||||||
|
$return = [];
|
||||||
|
if (is_array($triggers)) {
|
||||||
|
foreach ($triggers as $trigger) {
|
||||||
|
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
|
||||||
|
$stopProcessing = array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
|
||||||
|
$return[] = [
|
||||||
|
'type' => $trigger['type'],
|
||||||
|
'value' => $trigger['value'],
|
||||||
|
'active' => $active,
|
||||||
|
'stop_processing' => $stopProcessing,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
private function getRuleActions(): ?array
|
||||||
|
{
|
||||||
|
if (!$this->has('actions')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$actions = $this->get('actions');
|
||||||
|
$return = [];
|
||||||
|
if (is_array($actions)) {
|
||||||
|
foreach ($actions as $action) {
|
||||||
|
$return[] = [
|
||||||
|
'type' => $action['type'],
|
||||||
|
'value' => $action['value'],
|
||||||
|
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
|
||||||
|
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules that the incoming request must be matched against.
|
* The rules that the incoming request must be matched against.
|
||||||
*
|
*
|
||||||
@@ -96,12 +146,12 @@ class UpdateRequest extends FormRequest
|
|||||||
'rule_group_id' => 'belongsToUser:rule_groups',
|
'rule_group_id' => 'belongsToUser:rule_groups',
|
||||||
'rule_group_title' => 'nullable|between:1,255|belongsToUser:rule_groups,title',
|
'rule_group_title' => 'nullable|between:1,255|belongsToUser:rule_groups,title',
|
||||||
'trigger' => 'in:store-journal,update-journal',
|
'trigger' => 'in:store-journal,update-journal',
|
||||||
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
|
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
|
||||||
'triggers.*.value' => 'required_if:actions.*.type,'.$contextTriggers.'|min:1|ruleTriggerValue|max:1024',
|
'triggers.*.value' => 'required_if:actions.*.type,' . $contextTriggers . '|min:1|ruleTriggerValue|max:1024',
|
||||||
'triggers.*.stop_processing' => [new IsBoolean()],
|
'triggers.*.stop_processing' => [new IsBoolean()],
|
||||||
'triggers.*.active' => [new IsBoolean()],
|
'triggers.*.active' => [new IsBoolean()],
|
||||||
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
'actions.*.type' => 'required|in:' . implode(',', $validActions),
|
||||||
'actions.*.value' => 'required_if:actions.*.type,'.$contextActions.'|ruleActionValue',
|
'actions.*.value' => 'required_if:actions.*.type,' . $contextActions . '|ruleActionValue',
|
||||||
'actions.*.stop_processing' => [new IsBoolean()],
|
'actions.*.stop_processing' => [new IsBoolean()],
|
||||||
'actions.*.active' => [new IsBoolean()],
|
'actions.*.active' => [new IsBoolean()],
|
||||||
'strict' => [new IsBoolean()],
|
'strict' => [new IsBoolean()],
|
||||||
@@ -130,21 +180,6 @@ class UpdateRequest extends FormRequest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
|
||||||
*
|
|
||||||
* @param Validator $validator
|
|
||||||
*/
|
|
||||||
protected function atLeastOneAction(Validator $validator): void
|
|
||||||
{
|
|
||||||
$data = $validator->getData();
|
|
||||||
$actions = $data['actions'] ?? null;
|
|
||||||
// need at least one action
|
|
||||||
if (is_array($actions) && 0 === count($actions)) {
|
|
||||||
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
*
|
*
|
||||||
@@ -160,36 +195,6 @@ class UpdateRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
|
||||||
*
|
|
||||||
* @param Validator $validator
|
|
||||||
*/
|
|
||||||
protected function atLeastOneValidAction(Validator $validator): void
|
|
||||||
{
|
|
||||||
$data = $validator->getData();
|
|
||||||
$actions = $data['actions'] ?? [];
|
|
||||||
$allInactive = true;
|
|
||||||
$inactiveIndex = 0;
|
|
||||||
// need at least one action
|
|
||||||
if (is_array($actions) && 0 === count($actions)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($actions as $index => $action) {
|
|
||||||
$active = array_key_exists('active', $action) ? $action['active'] : true; // assume true
|
|
||||||
if (true === $active) {
|
|
||||||
$allInactive = false;
|
|
||||||
}
|
|
||||||
if (false === $active) {
|
|
||||||
$inactiveIndex = $index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (true === $allInactive) {
|
|
||||||
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
*
|
*
|
||||||
@@ -220,52 +225,47 @@ class UpdateRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
*/
|
*/
|
||||||
private function getRuleActions(): ?array
|
protected function atLeastOneAction(Validator $validator): void
|
||||||
{
|
{
|
||||||
if (!$this->has('actions')) {
|
$data = $validator->getData();
|
||||||
return null;
|
$actions = $data['actions'] ?? null;
|
||||||
|
// need at least one action
|
||||||
|
if (is_array($actions) && 0 === count($actions)) {
|
||||||
|
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
|
||||||
}
|
}
|
||||||
$actions = $this->get('actions');
|
|
||||||
$return = [];
|
|
||||||
if (is_array($actions)) {
|
|
||||||
foreach ($actions as $action) {
|
|
||||||
$return[] = [
|
|
||||||
'type' => $action['type'],
|
|
||||||
'value' => $action['value'],
|
|
||||||
'active' => $this->convertBoolean((string)($action['active'] ?? 'false')),
|
|
||||||
'stop_processing' => $this->convertBoolean((string)($action['stop_processing'] ?? 'false')),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
*/
|
*/
|
||||||
private function getRuleTriggers(): ?array
|
protected function atLeastOneValidAction(Validator $validator): void
|
||||||
{
|
{
|
||||||
if (!$this->has('triggers')) {
|
$data = $validator->getData();
|
||||||
return null;
|
$actions = $data['actions'] ?? [];
|
||||||
}
|
$allInactive = true;
|
||||||
$triggers = $this->get('triggers');
|
$inactiveIndex = 0;
|
||||||
$return = [];
|
// need at least one action
|
||||||
if (is_array($triggers)) {
|
if (is_array($actions) && 0 === count($actions)) {
|
||||||
foreach ($triggers as $trigger) {
|
return;
|
||||||
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
|
|
||||||
$stopProcessing = array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
|
|
||||||
$return[] = [
|
|
||||||
'type' => $trigger['type'],
|
|
||||||
'value' => $trigger['value'],
|
|
||||||
'active' => $active,
|
|
||||||
'stop_processing' => $stopProcessing,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
foreach ($actions as $index => $action) {
|
||||||
|
$active = array_key_exists('active', $action) ? $action['active'] : true; // assume true
|
||||||
|
if (true === $active) {
|
||||||
|
$allInactive = false;
|
||||||
|
}
|
||||||
|
if (false === $active) {
|
||||||
|
$inactiveIndex = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (true === $allInactive) {
|
||||||
|
$validator->errors()->add(sprintf('actions.%d.active', $inactiveIndex), (string)trans('validation.at_least_one_active_action'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,16 +50,13 @@ class TestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return Carbon|null
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getDate(string $field): ?Carbon
|
||||||
{
|
{
|
||||||
return [
|
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after_or_equal:start',
|
|
||||||
'accounts' => '',
|
|
||||||
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,12 +68,15 @@ class TestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @return array
|
||||||
*
|
|
||||||
* @return Carbon|null
|
|
||||||
*/
|
*/
|
||||||
private function getDate(string $field): ?Carbon
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after_or_equal:start',
|
||||||
|
'accounts' => '',
|
||||||
|
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,14 +50,13 @@ class TriggerRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return Carbon|null
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getDate(string $field): ?Carbon
|
||||||
{
|
{
|
||||||
return [
|
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after_or_equal:start',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,12 +68,13 @@ class TriggerRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @return array
|
||||||
*
|
|
||||||
* @return Carbon|null
|
|
||||||
*/
|
*/
|
||||||
private function getDate(string $field): ?Carbon
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after_or_equal:start',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,7 +66,7 @@ class UpdateRequest extends FormRequest
|
|||||||
$ruleGroup = $this->route()->parameter('ruleGroup');
|
$ruleGroup = $this->route()->parameter('ruleGroup');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => 'between:1,100|uniqueObjectForUser:rule_groups,title,'.$ruleGroup->id,
|
'title' => 'between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id,
|
||||||
'description' => 'between:1,5000|nullable',
|
'description' => 'between:1,5000|nullable',
|
||||||
'active' => [new IsBoolean()],
|
'active' => [new IsBoolean()],
|
||||||
];
|
];
|
||||||
|
@@ -71,7 +71,7 @@ class UpdateRequest extends FormRequest
|
|||||||
$tag = $this->route()->parameter('tagOrId');
|
$tag = $this->route()->parameter('tagOrId');
|
||||||
// TODO check if uniqueObjectForUser is obsolete
|
// TODO check if uniqueObjectForUser is obsolete
|
||||||
$rules = [
|
$rules = [
|
||||||
'tag' => 'min:1|max:1024|uniqueObjectForUser:tags,tag,'.$tag->id,
|
'tag' => 'min:1|max:1024|uniqueObjectForUser:tags,tag,' . $tag->id,
|
||||||
'description' => 'min:1|nullable|max:65536',
|
'description' => 'min:1|nullable|max:65536',
|
||||||
'date' => 'date|nullable',
|
'date' => 'date|nullable',
|
||||||
];
|
];
|
||||||
|
@@ -69,6 +69,103 @@ class StoreRequest extends FormRequest
|
|||||||
// TODO include location and ability to process it.
|
// TODO include location and ability to process it.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get transaction data.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getTransactionData(): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
/**
|
||||||
|
* @var array $transaction
|
||||||
|
*/
|
||||||
|
foreach ($this->get('transactions') as $transaction) {
|
||||||
|
$object = new NullArrayObject($transaction);
|
||||||
|
$return[] = [
|
||||||
|
'type' => $this->clearString($object['type'], false),
|
||||||
|
'date' => $this->dateFromValue($object['date']),
|
||||||
|
'order' => $this->integerFromValue((string)$object['order']),
|
||||||
|
|
||||||
|
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
|
||||||
|
'currency_code' => $this->clearString((string)$object['currency_code'], false),
|
||||||
|
|
||||||
|
// foreign currency info:
|
||||||
|
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
|
||||||
|
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
|
||||||
|
|
||||||
|
// amount and foreign amount. Cannot be 0.
|
||||||
|
'amount' => $this->clearString((string)$object['amount'], false),
|
||||||
|
'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
|
||||||
|
|
||||||
|
// description.
|
||||||
|
'description' => $this->clearString($object['description'], false),
|
||||||
|
|
||||||
|
// source of transaction. If everything is null, assume cash account.
|
||||||
|
'source_id' => $this->integerFromValue((string)$object['source_id']),
|
||||||
|
'source_name' => $this->clearString((string)$object['source_name'], false),
|
||||||
|
'source_iban' => $this->clearString((string)$object['source_iban'], false),
|
||||||
|
'source_number' => $this->clearString((string)$object['source_number'], false),
|
||||||
|
'source_bic' => $this->clearString((string)$object['source_bic'], false),
|
||||||
|
|
||||||
|
// destination of transaction. If everything is null, assume cash account.
|
||||||
|
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
|
||||||
|
'destination_name' => $this->clearString((string)$object['destination_name'], false),
|
||||||
|
'destination_iban' => $this->clearString((string)$object['destination_iban'], false),
|
||||||
|
'destination_number' => $this->clearString((string)$object['destination_number'], false),
|
||||||
|
'destination_bic' => $this->clearString((string)$object['destination_bic'], false),
|
||||||
|
|
||||||
|
// budget info
|
||||||
|
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
|
||||||
|
'budget_name' => $this->clearString((string)$object['budget_name'], false),
|
||||||
|
|
||||||
|
// category info
|
||||||
|
'category_id' => $this->integerFromValue((string)$object['category_id']),
|
||||||
|
'category_name' => $this->clearString((string)$object['category_name'], false),
|
||||||
|
|
||||||
|
// journal bill reference. Optional. Will only work for withdrawals
|
||||||
|
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
|
||||||
|
'bill_name' => $this->clearString((string)$object['bill_name'], false),
|
||||||
|
|
||||||
|
// piggy bank reference. Optional. Will only work for transfers
|
||||||
|
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
|
||||||
|
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
|
||||||
|
|
||||||
|
// some other interesting properties
|
||||||
|
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
|
||||||
|
'notes' => $this->clearString((string)$object['notes']),
|
||||||
|
'tags' => $this->arrayFromValue($object['tags']),
|
||||||
|
|
||||||
|
// all custom fields:
|
||||||
|
'internal_reference' => $this->clearString((string)$object['internal_reference'], false),
|
||||||
|
'external_id' => $this->clearString((string)$object['external_id'], false),
|
||||||
|
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
|
||||||
|
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
|
||||||
|
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'], false),
|
||||||
|
'external_url' => $this->clearString((string)$object['external_url'], false),
|
||||||
|
|
||||||
|
'sepa_cc' => $this->clearString((string)$object['sepa_cc'], false),
|
||||||
|
'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op'], false),
|
||||||
|
'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id'], false),
|
||||||
|
'sepa_db' => $this->clearString((string)$object['sepa_db'], false),
|
||||||
|
'sepa_country' => $this->clearString((string)$object['sepa_country'], false),
|
||||||
|
'sepa_ep' => $this->clearString((string)$object['sepa_ep'], false),
|
||||||
|
'sepa_ci' => $this->clearString((string)$object['sepa_ci'], false),
|
||||||
|
'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id'], false),
|
||||||
|
// custom date fields. Must be Carbon objects. Presence is optional.
|
||||||
|
'interest_date' => $this->dateFromValue($object['interest_date']),
|
||||||
|
'book_date' => $this->dateFromValue($object['book_date']),
|
||||||
|
'process_date' => $this->dateFromValue($object['process_date']),
|
||||||
|
'due_date' => $this->dateFromValue($object['due_date']),
|
||||||
|
'payment_date' => $this->dateFromValue($object['payment_date']),
|
||||||
|
'invoice_date' => $this->dateFromValue($object['invoice_date']),
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules that the incoming request must be matched against.
|
* The rules that the incoming request must be matched against.
|
||||||
*
|
*
|
||||||
@@ -197,101 +294,4 @@ class StoreRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get transaction data.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getTransactionData(): array
|
|
||||||
{
|
|
||||||
$return = [];
|
|
||||||
/**
|
|
||||||
* @var array $transaction
|
|
||||||
*/
|
|
||||||
foreach ($this->get('transactions') as $transaction) {
|
|
||||||
$object = new NullArrayObject($transaction);
|
|
||||||
$return[] = [
|
|
||||||
'type' => $this->clearString($object['type'], false),
|
|
||||||
'date' => $this->dateFromValue($object['date']),
|
|
||||||
'order' => $this->integerFromValue((string)$object['order']),
|
|
||||||
|
|
||||||
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
|
|
||||||
'currency_code' => $this->clearString((string)$object['currency_code'], false),
|
|
||||||
|
|
||||||
// foreign currency info:
|
|
||||||
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
|
|
||||||
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
|
|
||||||
|
|
||||||
// amount and foreign amount. Cannot be 0.
|
|
||||||
'amount' => $this->clearString((string)$object['amount'], false),
|
|
||||||
'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
|
|
||||||
|
|
||||||
// description.
|
|
||||||
'description' => $this->clearString($object['description'], false),
|
|
||||||
|
|
||||||
// source of transaction. If everything is null, assume cash account.
|
|
||||||
'source_id' => $this->integerFromValue((string)$object['source_id']),
|
|
||||||
'source_name' => $this->clearString((string)$object['source_name'], false),
|
|
||||||
'source_iban' => $this->clearString((string)$object['source_iban'], false),
|
|
||||||
'source_number' => $this->clearString((string)$object['source_number'], false),
|
|
||||||
'source_bic' => $this->clearString((string)$object['source_bic'], false),
|
|
||||||
|
|
||||||
// destination of transaction. If everything is null, assume cash account.
|
|
||||||
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
|
|
||||||
'destination_name' => $this->clearString((string)$object['destination_name'], false),
|
|
||||||
'destination_iban' => $this->clearString((string)$object['destination_iban'], false),
|
|
||||||
'destination_number' => $this->clearString((string)$object['destination_number'], false),
|
|
||||||
'destination_bic' => $this->clearString((string)$object['destination_bic'], false),
|
|
||||||
|
|
||||||
// budget info
|
|
||||||
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
|
|
||||||
'budget_name' => $this->clearString((string)$object['budget_name'], false),
|
|
||||||
|
|
||||||
// category info
|
|
||||||
'category_id' => $this->integerFromValue((string)$object['category_id']),
|
|
||||||
'category_name' => $this->clearString((string)$object['category_name'], false),
|
|
||||||
|
|
||||||
// journal bill reference. Optional. Will only work for withdrawals
|
|
||||||
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
|
|
||||||
'bill_name' => $this->clearString((string)$object['bill_name'], false),
|
|
||||||
|
|
||||||
// piggy bank reference. Optional. Will only work for transfers
|
|
||||||
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
|
|
||||||
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
|
|
||||||
|
|
||||||
// some other interesting properties
|
|
||||||
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
|
|
||||||
'notes' => $this->clearString((string)$object['notes']),
|
|
||||||
'tags' => $this->arrayFromValue($object['tags']),
|
|
||||||
|
|
||||||
// all custom fields:
|
|
||||||
'internal_reference' => $this->clearString((string)$object['internal_reference'], false),
|
|
||||||
'external_id' => $this->clearString((string)$object['external_id'], false),
|
|
||||||
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
|
|
||||||
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
|
|
||||||
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'], false),
|
|
||||||
'external_url' => $this->clearString((string)$object['external_url'], false),
|
|
||||||
|
|
||||||
'sepa_cc' => $this->clearString((string)$object['sepa_cc'], false),
|
|
||||||
'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op'], false),
|
|
||||||
'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id'], false),
|
|
||||||
'sepa_db' => $this->clearString((string)$object['sepa_db'], false),
|
|
||||||
'sepa_country' => $this->clearString((string)$object['sepa_country'], false),
|
|
||||||
'sepa_ep' => $this->clearString((string)$object['sepa_ep'], false),
|
|
||||||
'sepa_ci' => $this->clearString((string)$object['sepa_ci'], false),
|
|
||||||
'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id'], false),
|
|
||||||
// custom date fields. Must be Carbon objects. Presence is optional.
|
|
||||||
'interest_date' => $this->dateFromValue($object['interest_date']),
|
|
||||||
'book_date' => $this->dateFromValue($object['book_date']),
|
|
||||||
'process_date' => $this->dateFromValue($object['process_date']),
|
|
||||||
'due_date' => $this->dateFromValue($object['due_date']),
|
|
||||||
'payment_date' => $this->dateFromValue($object['payment_date']),
|
|
||||||
'invoice_date' => $this->dateFromValue($object['invoice_date']),
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,6 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Administration\Account\AccountRepositoryInterface as AdminAccountRepositoryInterface;
|
use FireflyIII\Repositories\Administration\Account\AccountRepositoryInterface as AdminAccountRepositoryInterface;
|
||||||
use FireflyIII\Support\Http\Api\AccountFilter;
|
use FireflyIII\Support\Http\Api\AccountFilter;
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
|
|
||||||
|
@@ -64,54 +64,6 @@ class Controller extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $key
|
|
||||||
* @param LengthAwarePaginator $paginator
|
|
||||||
* @param AbstractTransformer $transformer
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
|
|
||||||
{
|
|
||||||
$manager = new Manager();
|
|
||||||
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
|
|
||||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
|
||||||
|
|
||||||
$objects = $paginator->getCollection();
|
|
||||||
|
|
||||||
// the transformer, at this point, needs to collect information that ALL items in the collection
|
|
||||||
// require, like meta data and stuff like that, and save it for later.
|
|
||||||
$transformer->collectMetaData($objects);
|
|
||||||
|
|
||||||
$resource = new FractalCollection($objects, $transformer, $key);
|
|
||||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
|
||||||
|
|
||||||
return $manager->createData($resource)->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a JSON API object and returns it.
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param Model $object
|
|
||||||
* @param AbstractTransformer $transformer
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
final protected function jsonApiObject(string $key, Model $object, AbstractTransformer $transformer): array
|
|
||||||
{
|
|
||||||
// create some objects:
|
|
||||||
$manager = new Manager();
|
|
||||||
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
|
|
||||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
|
||||||
|
|
||||||
$transformer->collectMetaData(new Collection([$object]));
|
|
||||||
|
|
||||||
$resource = new Item($object, $transformer, $key);
|
|
||||||
|
|
||||||
return $manager->createData($resource)->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO duplicate from V1 controller
|
* TODO duplicate from V1 controller
|
||||||
* Method to grab all parameters from the URL.
|
* Method to grab all parameters from the URL.
|
||||||
@@ -123,7 +75,7 @@ class Controller extends BaseController
|
|||||||
$bag = new ParameterBag();
|
$bag = new ParameterBag();
|
||||||
try {
|
try {
|
||||||
$page = (int)request()->get('page');
|
$page = (int)request()->get('page');
|
||||||
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
|
||||||
$page = 1;
|
$page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +104,7 @@ class Controller extends BaseController
|
|||||||
if (null !== $date) {
|
if (null !== $date) {
|
||||||
try {
|
try {
|
||||||
$obj = Carbon::parse($date);
|
$obj = Carbon::parse($date);
|
||||||
} catch (InvalidDateException|InvalidFormatException $e) {
|
} catch (InvalidDateException | InvalidFormatException $e) {
|
||||||
// don't care
|
// don't care
|
||||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr($date, 0, 20), $e->getMessage()));
|
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr($date, 0, 20), $e->getMessage()));
|
||||||
}
|
}
|
||||||
@@ -179,4 +131,52 @@ class Controller extends BaseController
|
|||||||
|
|
||||||
return $bag;
|
return $bag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param LengthAwarePaginator $paginator
|
||||||
|
* @param AbstractTransformer $transformer
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
|
||||||
|
{
|
||||||
|
$manager = new Manager();
|
||||||
|
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
|
||||||
|
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||||
|
|
||||||
|
$objects = $paginator->getCollection();
|
||||||
|
|
||||||
|
// the transformer, at this point, needs to collect information that ALL items in the collection
|
||||||
|
// require, like meta data and stuff like that, and save it for later.
|
||||||
|
$transformer->collectMetaData($objects);
|
||||||
|
|
||||||
|
$resource = new FractalCollection($objects, $transformer, $key);
|
||||||
|
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||||
|
|
||||||
|
return $manager->createData($resource)->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a JSON API object and returns it.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param Model $object
|
||||||
|
* @param AbstractTransformer $transformer
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
final protected function jsonApiObject(string $key, Model $object, AbstractTransformer $transformer): array
|
||||||
|
{
|
||||||
|
// create some objects:
|
||||||
|
$manager = new Manager();
|
||||||
|
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
|
||||||
|
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||||
|
|
||||||
|
$transformer->collectMetaData(new Collection([$object]));
|
||||||
|
|
||||||
|
$resource = new Item($object, $transformer, $key);
|
||||||
|
|
||||||
|
return $manager->createData($resource)->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -174,6 +174,26 @@ class CorrectAmounts extends Command
|
|||||||
$this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count));
|
$this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function fixRepetitions(): void
|
||||||
|
{
|
||||||
|
$set = PiggyBankRepetition::where('currentamount', '<', 0)->get();
|
||||||
|
$count = $set->count();
|
||||||
|
if (0 === $count) {
|
||||||
|
$this->friendlyPositive('All piggy bank repetition amounts are positive.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/** @var PiggyBankRepetition $item */
|
||||||
|
foreach ($set as $item) {
|
||||||
|
$item->currentamount = app('steam')->positive((string)$item->currentamount);
|
||||||
|
$item->save();
|
||||||
|
}
|
||||||
|
$this->friendlyInfo(sprintf('Corrected %d piggy bank repetition amount(s).', $count));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -217,26 +237,6 @@ class CorrectAmounts extends Command
|
|||||||
$this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count));
|
$this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function fixRepetitions(): void
|
|
||||||
{
|
|
||||||
$set = PiggyBankRepetition::where('currentamount', '<', 0)->get();
|
|
||||||
$count = $set->count();
|
|
||||||
if (0 === $count) {
|
|
||||||
$this->friendlyPositive('All piggy bank repetition amounts are positive.');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/** @var PiggyBankRepetition $item */
|
|
||||||
foreach ($set as $item) {
|
|
||||||
$item->currentamount = app('steam')->positive((string)$item->currentamount);
|
|
||||||
$item->save();
|
|
||||||
}
|
|
||||||
$this->friendlyInfo(sprintf('Corrected %d piggy bank repetition amount(s).', $count));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@@ -71,6 +71,17 @@ class CorrectOpeningBalanceCurrencies extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
private function getJournals(): Collection
|
||||||
|
{
|
||||||
|
/** @var Collection */
|
||||||
|
return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
|
->whereNull('transaction_journals.deleted_at')
|
||||||
|
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
@@ -112,31 +123,6 @@ class CorrectOpeningBalanceCurrencies extends Command
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Account $account
|
|
||||||
*
|
|
||||||
* @return TransactionCurrency
|
|
||||||
*/
|
|
||||||
private function getCurrency(Account $account): TransactionCurrency
|
|
||||||
{
|
|
||||||
/** @var AccountRepositoryInterface $repos */
|
|
||||||
$repos = app(AccountRepositoryInterface::class);
|
|
||||||
$repos->setUser($account->user);
|
|
||||||
|
|
||||||
return $repos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function getJournals(): Collection
|
|
||||||
{
|
|
||||||
/** @var Collection */
|
|
||||||
return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
|
||||||
->whereNull('transaction_journals.deleted_at')
|
|
||||||
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
@@ -163,4 +149,18 @@ class CorrectOpeningBalanceCurrencies extends Command
|
|||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
*
|
||||||
|
* @return TransactionCurrency
|
||||||
|
*/
|
||||||
|
private function getCurrency(Account $account): TransactionCurrency
|
||||||
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repos */
|
||||||
|
$repos = app(AccountRepositoryInterface::class);
|
||||||
|
$repos->setUser($account->user);
|
||||||
|
|
||||||
|
return $repos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,30 +64,6 @@ class DeleteEmptyJournals extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function deleteEmptyJournals(): void
|
|
||||||
{
|
|
||||||
$count = 0;
|
|
||||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->groupBy('transaction_journals.id')
|
|
||||||
->whereNull('transactions.transaction_journal_id')
|
|
||||||
->get(['transaction_journals.id']);
|
|
||||||
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
try {
|
|
||||||
TransactionJournal::find($entry->id)->delete();
|
|
||||||
} catch (QueryException $e) {
|
|
||||||
Log::info(sprintf('Could not delete entry: %s', $e->getMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id));
|
|
||||||
++$count;
|
|
||||||
}
|
|
||||||
if (0 === $count) {
|
|
||||||
$this->friendlyPositive('No empty transaction journals.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete transactions and their journals if they have an uneven number of transactions.
|
* Delete transactions and their journals if they have an uneven number of transactions.
|
||||||
*/
|
*/
|
||||||
@@ -120,4 +96,28 @@ class DeleteEmptyJournals extends Command
|
|||||||
$this->friendlyPositive('No uneven transaction journals.');
|
$this->friendlyPositive('No uneven transaction journals.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function deleteEmptyJournals(): void
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->groupBy('transaction_journals.id')
|
||||||
|
->whereNull('transactions.transaction_journal_id')
|
||||||
|
->get(['transaction_journals.id']);
|
||||||
|
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
try {
|
||||||
|
TransactionJournal::find($entry->id)->delete();
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
Log::info(sprintf('Could not delete entry: %s', $e->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id));
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
|
if (0 === $count) {
|
||||||
|
$this->friendlyPositive('No empty transaction journals.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,38 +65,6 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function deleteFromOrphanedAccounts(): void
|
|
||||||
{
|
|
||||||
$set
|
|
||||||
= Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
|
||||||
->whereNotNull('accounts.deleted_at')
|
|
||||||
->get(['transactions.*']);
|
|
||||||
$count = 0;
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($set as $transaction) {
|
|
||||||
// delete journals
|
|
||||||
$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
|
|
||||||
if ($journal) {
|
|
||||||
$journal->delete();
|
|
||||||
}
|
|
||||||
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
|
|
||||||
$this->friendlyWarning(
|
|
||||||
sprintf(
|
|
||||||
'Deleted transaction journal #%d because account #%d was already deleted.',
|
|
||||||
$transaction->transaction_journal_id,
|
|
||||||
$transaction->account_id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
if (0 === $count) {
|
|
||||||
$this->friendlyPositive('No orphaned accounts.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function deleteOrphanedJournals(): void
|
private function deleteOrphanedJournals(): void
|
||||||
{
|
{
|
||||||
$set = TransactionJournal::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
$set = TransactionJournal::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||||
@@ -159,4 +127,36 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
$this->friendlyPositive('No orphaned transactions.');
|
$this->friendlyPositive('No orphaned transactions.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function deleteFromOrphanedAccounts(): void
|
||||||
|
{
|
||||||
|
$set
|
||||||
|
= Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||||
|
->whereNotNull('accounts.deleted_at')
|
||||||
|
->get(['transactions.*']);
|
||||||
|
$count = 0;
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($set as $transaction) {
|
||||||
|
// delete journals
|
||||||
|
$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
|
||||||
|
if ($journal) {
|
||||||
|
$journal->delete();
|
||||||
|
}
|
||||||
|
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
|
||||||
|
$this->friendlyWarning(
|
||||||
|
sprintf(
|
||||||
|
'Deleted transaction journal #%d because account #%d was already deleted.',
|
||||||
|
$transaction->transaction_journal_id,
|
||||||
|
$transaction->account_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
if (0 === $count) {
|
||||||
|
$this->friendlyPositive('No orphaned accounts.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EnableCurrencies
|
* Class EnableCurrencies
|
||||||
|
@@ -31,8 +31,8 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use JsonException;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use JsonException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FixAccountTypes
|
* Class FixAccountTypes
|
||||||
@@ -73,6 +73,79 @@ class FixAccountTypes extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
||||||
|
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
||||||
|
* be called from the handle method instead of using the constructor to initialize the command.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
private function stupidLaravel(): void
|
||||||
|
{
|
||||||
|
$this->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function inspectJournal(TransactionJournal $journal): void
|
||||||
|
{
|
||||||
|
$transactions = $journal->transactions()->count();
|
||||||
|
if (2 !== $transactions) {
|
||||||
|
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
|
||||||
|
$this->friendlyError(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$type = $journal->transactionType->type;
|
||||||
|
$sourceTransaction = $this->getSourceTransaction($journal);
|
||||||
|
$destTransaction = $this->getDestinationTransaction($journal);
|
||||||
|
$sourceAccount = $sourceTransaction->account;
|
||||||
|
$sourceAccountType = $sourceAccount->accountType->type;
|
||||||
|
$destAccount = $destTransaction->account;
|
||||||
|
$destAccountType = $destAccount->accountType->type;
|
||||||
|
|
||||||
|
if (!array_key_exists($type, $this->expected)) {
|
||||||
|
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
|
||||||
|
$this->friendlyError(sprintf('No source/destination info for transaction type %s.', $type));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
|
||||||
|
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
|
||||||
|
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$expectedTypes = $this->expected[$type][$sourceAccountType];
|
||||||
|
if (!in_array($destAccountType, $expectedTypes, true)) {
|
||||||
|
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
|
||||||
|
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return Transaction
|
||||||
|
*/
|
||||||
|
private function getSourceTransaction(TransactionJournal $journal): Transaction
|
||||||
|
{
|
||||||
|
return $journal->transactions->firstWhere('amount', '<', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return Transaction
|
||||||
|
*/
|
||||||
|
private function getDestinationTransaction(TransactionJournal $journal): Transaction
|
||||||
|
{
|
||||||
|
return $journal->transactions->firstWhere('amount', '>', 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param string $type
|
* @param string $type
|
||||||
@@ -167,77 +240,4 @@ class FixAccountTypes extends Command
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return Transaction
|
|
||||||
*/
|
|
||||||
private function getDestinationTransaction(TransactionJournal $journal): Transaction
|
|
||||||
{
|
|
||||||
return $journal->transactions->firstWhere('amount', '>', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @return Transaction
|
|
||||||
*/
|
|
||||||
private function getSourceTransaction(TransactionJournal $journal): Transaction
|
|
||||||
{
|
|
||||||
return $journal->transactions->firstWhere('amount', '<', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function inspectJournal(TransactionJournal $journal): void
|
|
||||||
{
|
|
||||||
$transactions = $journal->transactions()->count();
|
|
||||||
if (2 !== $transactions) {
|
|
||||||
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
|
|
||||||
$this->friendlyError(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$type = $journal->transactionType->type;
|
|
||||||
$sourceTransaction = $this->getSourceTransaction($journal);
|
|
||||||
$destTransaction = $this->getDestinationTransaction($journal);
|
|
||||||
$sourceAccount = $sourceTransaction->account;
|
|
||||||
$sourceAccountType = $sourceAccount->accountType->type;
|
|
||||||
$destAccount = $destTransaction->account;
|
|
||||||
$destAccountType = $destAccount->accountType->type;
|
|
||||||
|
|
||||||
if (!array_key_exists($type, $this->expected)) {
|
|
||||||
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
|
|
||||||
$this->friendlyError(sprintf('No source/destination info for transaction type %s.', $type));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
|
|
||||||
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
|
|
||||||
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$expectedTypes = $this->expected[$type][$sourceAccountType];
|
|
||||||
if (!in_array($destAccountType, $expectedTypes, true)) {
|
|
||||||
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
|
|
||||||
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
|
||||||
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
|
||||||
* be called from the handle method instead of using the constructor to initialize the command.
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
private function stupidLaravel(): void
|
|
||||||
{
|
|
||||||
$this->count = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -58,6 +58,28 @@ class FixIbans extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function filterIbans(Collection $accounts): void
|
||||||
|
{
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$iban = $account->iban;
|
||||||
|
if (str_contains($iban, ' ')) {
|
||||||
|
$iban = app('steam')->filterSpaces((string)$account->iban);
|
||||||
|
if ('' !== $iban) {
|
||||||
|
$account->iban = $iban;
|
||||||
|
$account->save();
|
||||||
|
$this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id));
|
||||||
|
$this->count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
*
|
*
|
||||||
@@ -105,26 +127,4 @@ class FixIbans extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $accounts
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function filterIbans(Collection $accounts): void
|
|
||||||
{
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$iban = $account->iban;
|
|
||||||
if (str_contains($iban, ' ')) {
|
|
||||||
$iban = app('steam')->filterSpaces((string)$account->iban);
|
|
||||||
if ('' !== $iban) {
|
|
||||||
$account->iban = $iban;
|
|
||||||
$account->save();
|
|
||||||
$this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id));
|
|
||||||
$this->count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -62,6 +62,19 @@ class FixRecurringTransactions extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
||||||
|
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
||||||
|
* be called from the handle method instead of using the constructor to initialize the command.
|
||||||
|
*
|
||||||
|
|
||||||
|
*/
|
||||||
|
private function stupidLaravel(): void
|
||||||
|
{
|
||||||
|
$this->recurringRepos = app(RecurringRepositoryInterface::class);
|
||||||
|
$this->userRepos = app(UserRepositoryInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -74,6 +87,19 @@ class FixRecurringTransactions extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
private function processUser(User $user): void
|
||||||
|
{
|
||||||
|
$this->recurringRepos->setUser($user);
|
||||||
|
$recurrences = $this->recurringRepos->get();
|
||||||
|
/** @var Recurrence $recurrence */
|
||||||
|
foreach ($recurrences as $recurrence) {
|
||||||
|
$this->processRecurrence($recurrence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Recurrence $recurrence
|
* @param Recurrence $recurrence
|
||||||
*/
|
*/
|
||||||
@@ -107,30 +133,4 @@ class FixRecurringTransactions extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
private function processUser(User $user): void
|
|
||||||
{
|
|
||||||
$this->recurringRepos->setUser($user);
|
|
||||||
$recurrences = $this->recurringRepos->get();
|
|
||||||
/** @var Recurrence $recurrence */
|
|
||||||
foreach ($recurrences as $recurrence) {
|
|
||||||
$this->processRecurrence($recurrence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
|
||||||
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
|
||||||
* be called from the handle method instead of using the constructor to initialize the command.
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
private function stupidLaravel(): void
|
|
||||||
{
|
|
||||||
$this->recurringRepos = app(RecurringRepositoryInterface::class);
|
|
||||||
$this->userRepos = app(UserRepositoryInterface::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -69,19 +69,6 @@ class FixTransactionTypes extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param TransactionJournal $journal
|
|
||||||
* @param string $expectedType
|
|
||||||
*/
|
|
||||||
private function changeJournal(TransactionJournal $journal, string $expectedType): void
|
|
||||||
{
|
|
||||||
$type = TransactionType::whereType($expectedType)->first();
|
|
||||||
if (null !== $type) {
|
|
||||||
$journal->transaction_type_id = $type->id;
|
|
||||||
$journal->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect all transaction journals.
|
* Collect all transaction journals.
|
||||||
*
|
*
|
||||||
@@ -129,6 +116,36 @@ class FixTransactionTypes extends Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return Account
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function getSourceAccount(TransactionJournal $journal): Account
|
||||||
|
{
|
||||||
|
$collection = $journal->transactions->filter(
|
||||||
|
static function (Transaction $transaction) {
|
||||||
|
return $transaction->amount < 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (0 === $collection->count()) {
|
||||||
|
throw new FireflyException(sprintf('300001: Journal #%d has no source transaction.', $journal->id));
|
||||||
|
}
|
||||||
|
if (1 !== $collection->count()) {
|
||||||
|
throw new FireflyException(sprintf('300002: Journal #%d has multiple source transactions.', $journal->id));
|
||||||
|
}
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
$transaction = $collection->first();
|
||||||
|
/** @var Account|null $account */
|
||||||
|
$account = $transaction->account;
|
||||||
|
if (null === $account) {
|
||||||
|
throw new FireflyException(sprintf('300003: Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
@@ -161,31 +178,14 @@ class FixTransactionTypes extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
* @param string $expectedType
|
||||||
* @return Account
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
private function getSourceAccount(TransactionJournal $journal): Account
|
private function changeJournal(TransactionJournal $journal, string $expectedType): void
|
||||||
{
|
{
|
||||||
$collection = $journal->transactions->filter(
|
$type = TransactionType::whereType($expectedType)->first();
|
||||||
static function (Transaction $transaction) {
|
if (null !== $type) {
|
||||||
return $transaction->amount < 0;
|
$journal->transaction_type_id = $type->id;
|
||||||
|
$journal->save();
|
||||||
}
|
}
|
||||||
);
|
|
||||||
if (0 === $collection->count()) {
|
|
||||||
throw new FireflyException(sprintf('300001: Journal #%d has no source transaction.', $journal->id));
|
|
||||||
}
|
|
||||||
if (1 !== $collection->count()) {
|
|
||||||
throw new FireflyException(sprintf('300002: Journal #%d has multiple source transactions.', $journal->id));
|
|
||||||
}
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
$transaction = $collection->first();
|
|
||||||
/** @var Account|null $account */
|
|
||||||
$account = $transaction->account;
|
|
||||||
if (null === $account) {
|
|
||||||
throw new FireflyException(sprintf('300003: Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,6 @@ namespace FireflyIII\Console\Commands\Correction;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
|
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CorrectionSkeleton
|
* Class CorrectionSkeleton
|
||||||
@@ -30,6 +29,16 @@ class TriggerCreditCalculation extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function processAccounts(): void
|
||||||
|
{
|
||||||
|
$accounts = Account::leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
||||||
|
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||||
|
->get(['accounts.*']);
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$this->processAccount($account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
@@ -42,14 +51,4 @@ class TriggerCreditCalculation extends Command
|
|||||||
$object->setAccount($account);
|
$object->setAccount($account);
|
||||||
$object->recalculate();
|
$object->recalculate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processAccounts(): void
|
|
||||||
{
|
|
||||||
$accounts = Account::leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
|
||||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
|
||||||
->get(['accounts.*']);
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$this->processAccount($account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -36,8 +36,8 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
|||||||
use FireflyIII\Support\Export\ExportDataGenerator;
|
use FireflyIII\Support\Export\ExportDataGenerator;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use InvalidArgumentException;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExportData
|
* Class ExportData
|
||||||
@@ -141,57 +141,48 @@ class ExportData extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $options
|
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
||||||
* @param array $data
|
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
||||||
|
* be called from the handle method instead of using the constructor to initialize the command.
|
||||||
*
|
*
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
private function exportData(array $options, array $data): void
|
private function stupidLaravel(): void
|
||||||
{
|
{
|
||||||
$date = date('Y_m_d');
|
$this->journalRepository = app(JournalRepositoryInterface::class);
|
||||||
foreach ($data as $key => $content) {
|
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key);
|
|
||||||
if (false === $options['force'] && file_exists($file)) {
|
|
||||||
throw new FireflyException(sprintf('File "%s" exists already. Use --force to overwrite.', $file));
|
|
||||||
}
|
|
||||||
if (true === $options['force'] && file_exists($file)) {
|
|
||||||
$this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file));
|
|
||||||
}
|
|
||||||
// continue to write to file.
|
|
||||||
file_put_contents($file, $content);
|
|
||||||
$this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return array
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function getAccountsParameter(): Collection
|
private function parseOptions(): array
|
||||||
{
|
{
|
||||||
$final = new Collection();
|
$start = $this->getDateParameter('start');
|
||||||
$accounts = new Collection();
|
$end = $this->getDateParameter('end');
|
||||||
$accountList = $this->option('accounts');
|
$accounts = $this->getAccountsParameter();
|
||||||
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
$export = $this->getExportDirectory();
|
||||||
if (null !== $accountList && '' !== (string)$accountList) {
|
|
||||||
$accountIds = explode(',', $accountList);
|
|
||||||
$accounts = $this->accountRepository->getAccountsById($accountIds);
|
|
||||||
}
|
|
||||||
if (null === $accountList) {
|
|
||||||
$accounts = $this->accountRepository->getAccountsByType($types);
|
|
||||||
}
|
|
||||||
// filter accounts,
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
if (in_array($account->accountType->type, $types, true)) {
|
|
||||||
$final->push($account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (0 === $final->count()) {
|
|
||||||
throw new FireflyException('300007: Ended up with zero valid accounts to export from.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $final;
|
return [
|
||||||
|
'export' => [
|
||||||
|
'transactions' => $this->option('export-transactions'),
|
||||||
|
'accounts' => $this->option('export-accounts'),
|
||||||
|
'budgets' => $this->option('export-budgets'),
|
||||||
|
'categories' => $this->option('export-categories'),
|
||||||
|
'tags' => $this->option('export-tags'),
|
||||||
|
'recurring' => $this->option('export-recurring'),
|
||||||
|
'rules' => $this->option('export-rules'),
|
||||||
|
'bills' => $this->option('export-bills'),
|
||||||
|
'piggies' => $this->option('export-piggies'),
|
||||||
|
],
|
||||||
|
'start' => $start,
|
||||||
|
'end' => $end,
|
||||||
|
'accounts' => $accounts,
|
||||||
|
'directory' => $export,
|
||||||
|
'force' => $this->option('force'),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,6 +226,37 @@ class ExportData extends Command
|
|||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function getAccountsParameter(): Collection
|
||||||
|
{
|
||||||
|
$final = new Collection();
|
||||||
|
$accounts = new Collection();
|
||||||
|
$accountList = $this->option('accounts');
|
||||||
|
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||||
|
if (null !== $accountList && '' !== (string)$accountList) {
|
||||||
|
$accountIds = explode(',', $accountList);
|
||||||
|
$accounts = $this->accountRepository->getAccountsById($accountIds);
|
||||||
|
}
|
||||||
|
if (null === $accountList) {
|
||||||
|
$accounts = $this->accountRepository->getAccountsByType($types);
|
||||||
|
}
|
||||||
|
// filter accounts,
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
if (in_array($account->accountType->type, $types, true)) {
|
||||||
|
$final->push($account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 === $final->count()) {
|
||||||
|
throw new FireflyException('300007: Ended up with zero valid accounts to export from.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $final;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@@ -254,47 +276,25 @@ class ExportData extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @param array $options
|
||||||
* @throws FireflyException
|
* @param array $data
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private function parseOptions(): array
|
|
||||||
{
|
|
||||||
$start = $this->getDateParameter('start');
|
|
||||||
$end = $this->getDateParameter('end');
|
|
||||||
$accounts = $this->getAccountsParameter();
|
|
||||||
$export = $this->getExportDirectory();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'export' => [
|
|
||||||
'transactions' => $this->option('export-transactions'),
|
|
||||||
'accounts' => $this->option('export-accounts'),
|
|
||||||
'budgets' => $this->option('export-budgets'),
|
|
||||||
'categories' => $this->option('export-categories'),
|
|
||||||
'tags' => $this->option('export-tags'),
|
|
||||||
'recurring' => $this->option('export-recurring'),
|
|
||||||
'rules' => $this->option('export-rules'),
|
|
||||||
'bills' => $this->option('export-bills'),
|
|
||||||
'piggies' => $this->option('export-piggies'),
|
|
||||||
],
|
|
||||||
'start' => $start,
|
|
||||||
'end' => $end,
|
|
||||||
'accounts' => $accounts,
|
|
||||||
'directory' => $export,
|
|
||||||
'force' => $this->option('force'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
|
||||||
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
|
||||||
* be called from the handle method instead of using the constructor to initialize the command.
|
|
||||||
*
|
*
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
private function stupidLaravel(): void
|
private function exportData(array $options, array $data): void
|
||||||
{
|
{
|
||||||
$this->journalRepository = app(JournalRepositoryInterface::class);
|
$date = date('Y_m_d');
|
||||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
foreach ($data as $key => $content) {
|
||||||
|
$file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key);
|
||||||
|
if (false === $options['force'] && file_exists($file)) {
|
||||||
|
throw new FireflyException(sprintf('File "%s" exists already. Use --force to overwrite.', $file));
|
||||||
|
}
|
||||||
|
if (true === $options['force'] && file_exists($file)) {
|
||||||
|
$this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file));
|
||||||
|
}
|
||||||
|
// continue to write to file.
|
||||||
|
file_put_contents($file, $content);
|
||||||
|
$this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@ use FireflyIII\Models\UserGroup;
|
|||||||
use FireflyIII\Models\UserRole;
|
use FireflyIII\Models\UserRole;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateGroupMemberships
|
* Class CreateGroupMemberships
|
||||||
@@ -44,6 +43,33 @@ class CreateGroupMemberships extends Command
|
|||||||
protected $description = 'Update group memberships';
|
protected $description = 'Update group memberships';
|
||||||
protected $signature = 'firefly-iii:create-group-memberships';
|
protected $signature = 'firefly-iii:create-group-memberships';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$this->createGroupMemberships();
|
||||||
|
$this->friendlyPositive('Validated group memberships');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function createGroupMemberships(): void
|
||||||
|
{
|
||||||
|
$users = User::get();
|
||||||
|
/** @var User $user */
|
||||||
|
foreach ($users as $user) {
|
||||||
|
self::createGroupMembership($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO move to helper.
|
* TODO move to helper.
|
||||||
*
|
*
|
||||||
@@ -81,31 +107,4 @@ class CreateGroupMemberships extends Command
|
|||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function handle(): int
|
|
||||||
{
|
|
||||||
$this->createGroupMemberships();
|
|
||||||
$this->friendlyPositive('Validated group memberships');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function createGroupMemberships(): void
|
|
||||||
{
|
|
||||||
$users = User::get();
|
|
||||||
/** @var User $user */
|
|
||||||
foreach ($users as $user) {
|
|
||||||
self::createGroupMembership($user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -67,51 +67,6 @@ class ReportEmptyObjects extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports on accounts with no transactions.
|
|
||||||
*/
|
|
||||||
private function reportAccounts(): void
|
|
||||||
{
|
|
||||||
$set = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
|
||||||
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
|
||||||
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
|
|
||||||
->whereNull('transactions.account_id')
|
|
||||||
->get(
|
|
||||||
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
|
|
||||||
);
|
|
||||||
|
|
||||||
/** @var stdClass $entry */
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
$line = 'User #%d (%s) has account #%d ("%s") which has no transactions.';
|
|
||||||
$line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $entry->name);
|
|
||||||
$this->friendlyWarning($line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports on budgets with no budget limits (which makes them pointless).
|
|
||||||
*/
|
|
||||||
private function reportBudgetLimits(): void
|
|
||||||
{
|
|
||||||
$set = Budget::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
|
||||||
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
|
||||||
->groupBy(['budgets.id', 'budgets.name', 'budgets.encrypted', 'budgets.user_id', 'users.email'])
|
|
||||||
->whereNull('budget_limits.id')
|
|
||||||
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'budgets.encrypted', 'users.email']);
|
|
||||||
|
|
||||||
/** @var Budget $entry */
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
$line = sprintf(
|
|
||||||
'User #%d (%s) has budget #%d ("%s") which has no budget limits.',
|
|
||||||
$entry->user_id,
|
|
||||||
$entry->email,
|
|
||||||
$entry->id,
|
|
||||||
$entry->name
|
|
||||||
);
|
|
||||||
$this->friendlyWarning($line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report on budgets with no transactions or journals.
|
* Report on budgets with no transactions or journals.
|
||||||
*/
|
*/
|
||||||
@@ -186,4 +141,49 @@ class ReportEmptyObjects extends Command
|
|||||||
$this->friendlyWarning($line);
|
$this->friendlyWarning($line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on accounts with no transactions.
|
||||||
|
*/
|
||||||
|
private function reportAccounts(): void
|
||||||
|
{
|
||||||
|
$set = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||||
|
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
||||||
|
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
|
||||||
|
->whereNull('transactions.account_id')
|
||||||
|
->get(
|
||||||
|
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
|
||||||
|
);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #%d (%s) has account #%d ("%s") which has no transactions.';
|
||||||
|
$line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $entry->name);
|
||||||
|
$this->friendlyWarning($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on budgets with no budget limits (which makes them pointless).
|
||||||
|
*/
|
||||||
|
private function reportBudgetLimits(): void
|
||||||
|
{
|
||||||
|
$set = Budget::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
||||||
|
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||||
|
->groupBy(['budgets.id', 'budgets.name', 'budgets.encrypted', 'budgets.user_id', 'users.email'])
|
||||||
|
->whereNull('budget_limits.id')
|
||||||
|
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'budgets.encrypted', 'users.email']);
|
||||||
|
|
||||||
|
/** @var Budget $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = sprintf(
|
||||||
|
'User #%d (%s) has budget #%d ("%s") which has no budget limits.',
|
||||||
|
$entry->user_id,
|
||||||
|
$entry->email,
|
||||||
|
$entry->id,
|
||||||
|
$entry->name
|
||||||
|
);
|
||||||
|
$this->friendlyWarning($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,38 +50,6 @@ class RestoreOAuthKeys extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function generateKeys(): void
|
|
||||||
{
|
|
||||||
OAuthKeys::generateKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function keysInDatabase(): bool
|
|
||||||
{
|
|
||||||
return OAuthKeys::keysInDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function keysOnDrive(): bool
|
|
||||||
{
|
|
||||||
return OAuthKeys::hasKeyFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function restoreKeysFromDB(): bool
|
|
||||||
{
|
|
||||||
return OAuthKeys::restoreKeysFromDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -116,6 +84,30 @@ class RestoreOAuthKeys extends Command
|
|||||||
$this->friendlyPositive('OAuth keys are OK');
|
$this->friendlyPositive('OAuth keys are OK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function keysInDatabase(): bool
|
||||||
|
{
|
||||||
|
return OAuthKeys::keysInDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function keysOnDrive(): bool
|
||||||
|
{
|
||||||
|
return OAuthKeys::hasKeyFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function generateKeys(): void
|
||||||
|
{
|
||||||
|
OAuthKeys::generateKeys();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -123,4 +115,12 @@ class RestoreOAuthKeys extends Command
|
|||||||
{
|
{
|
||||||
OAuthKeys::storeKeysInDB();
|
OAuthKeys::storeKeysInDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function restoreKeysFromDB(): bool
|
||||||
|
{
|
||||||
|
return OAuthKeys::restoreKeysFromDB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,18 +50,18 @@ trait ShowsFriendlyMessages
|
|||||||
* @param string $message
|
* @param string $message
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function friendlyLine(string $message): void
|
public function friendlyNeutral(string $message): void
|
||||||
{
|
{
|
||||||
$this->line(sprintf(' %s', trim($message)));
|
$this->line(sprintf(' [i] %s', trim($message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function friendlyNeutral(string $message): void
|
public function friendlyLine(string $message): void
|
||||||
{
|
{
|
||||||
$this->line(sprintf(' [i] %s', trim($message)));
|
$this->line(sprintf(' %s', trim($message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -110,52 +110,19 @@ class ForceDecimalSize extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function determineDatabaseType(): void
|
||||||
* This method loops over all accounts and validates the amounts.
|
|
||||||
*
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
* @param array $fields
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function correctAccountAmounts(TransactionCurrency $currency, array $fields): void
|
|
||||||
{
|
{
|
||||||
$operator = $this->operator;
|
// switch stuff based on database connection:
|
||||||
$cast = $this->cast;
|
$this->operator = 'REGEXP';
|
||||||
$regularExpression = $this->regularExpression;
|
$this->regularExpression = '\'\\\\.[\\\\d]{%d}[1-9]+\'';
|
||||||
|
$this->cast = 'CHAR';
|
||||||
/** @var Builder $query */
|
if ('pgsql' === config('database.default')) {
|
||||||
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
$this->operator = 'SIMILAR TO';
|
||||||
->where('account_meta.name', 'currency_id')
|
$this->regularExpression = '\'%%\.[\d]{%d}[1-9]+%%\'';
|
||||||
->where('account_meta.data', json_encode((string)$currency->id));
|
$this->cast = 'TEXT';
|
||||||
$query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression) {
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$q->orWhere(
|
|
||||||
DB::raw(sprintf('CAST(accounts.%s AS %s)', $field, $cast)),
|
|
||||||
$operator,
|
|
||||||
DB::raw(sprintf($regularExpression, $currency->decimal_places))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$result = $query->get(['accounts.*']);
|
|
||||||
if (0 === $result->count()) {
|
|
||||||
$this->friendlyPositive(sprintf('All accounts in %s are OK', $currency->code));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($result as $account) {
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$value = $account->$field;
|
|
||||||
if (null === $value) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// fix $field by rounding it down correctly.
|
|
||||||
$pow = pow(10, (int)$currency->decimal_places);
|
|
||||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
|
||||||
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
|
|
||||||
Account::find($account->id)->update([$field => $correct]);
|
|
||||||
}
|
}
|
||||||
|
if ('sqlite' === config('database.default')) {
|
||||||
|
$this->regularExpression = '"\\.[\d]{%d}[1-9]+"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,6 +216,55 @@ class ForceDecimalSize extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method loops over all accounts and validates the amounts.
|
||||||
|
*
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function correctAccountAmounts(TransactionCurrency $currency, array $fields): void
|
||||||
|
{
|
||||||
|
$operator = $this->operator;
|
||||||
|
$cast = $this->cast;
|
||||||
|
$regularExpression = $this->regularExpression;
|
||||||
|
|
||||||
|
/** @var Builder $query */
|
||||||
|
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||||
|
->where('account_meta.name', 'currency_id')
|
||||||
|
->where('account_meta.data', json_encode((string)$currency->id));
|
||||||
|
$query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$q->orWhere(
|
||||||
|
DB::raw(sprintf('CAST(accounts.%s AS %s)', $field, $cast)),
|
||||||
|
$operator,
|
||||||
|
DB::raw(sprintf($regularExpression, $currency->decimal_places))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$result = $query->get(['accounts.*']);
|
||||||
|
if (0 === $result->count()) {
|
||||||
|
$this->friendlyPositive(sprintf('All accounts in %s are OK', $currency->code));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($result as $account) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$value = $account->$field;
|
||||||
|
if (null === $value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// fix $field by rounding it down correctly.
|
||||||
|
$pow = pow(10, (int)$currency->decimal_places);
|
||||||
|
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||||
|
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
|
||||||
|
Account::find($account->id)->update([$field => $correct]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method fixes all auto budgets in currency $currency.
|
* This method fixes all auto budgets in currency $currency.
|
||||||
*
|
*
|
||||||
@@ -300,57 +316,6 @@ class ForceDecimalSize extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method fixes all piggy banks in currency $currency.
|
|
||||||
*
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
* @param array $fields
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function correctPiggyAmounts(TransactionCurrency $currency, array $fields): void
|
|
||||||
{
|
|
||||||
$operator = $this->operator;
|
|
||||||
$cast = $this->cast;
|
|
||||||
$regularExpression = $this->regularExpression;
|
|
||||||
|
|
||||||
/** @var Builder $query */
|
|
||||||
$query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
|
|
||||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
|
||||||
->where('account_meta.name', 'currency_id')
|
|
||||||
->where('account_meta.data', json_encode((string)$currency->id))
|
|
||||||
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression) {
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$q->orWhere(
|
|
||||||
DB::raw(sprintf('CAST(piggy_banks.%s AS %s)', $field, $cast)),
|
|
||||||
$operator,
|
|
||||||
DB::raw(sprintf($regularExpression, $currency->decimal_places))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$result = $query->get(['piggy_banks.*']);
|
|
||||||
if (0 === $result->count()) {
|
|
||||||
$this->friendlyPositive(sprintf('All piggy banks in %s are OK', $currency->code));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/** @var PiggyBank $item */
|
|
||||||
foreach ($result as $item) {
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$value = $item->$field;
|
|
||||||
if (null === $value) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// fix $field by rounding it down correctly.
|
|
||||||
$pow = pow(10, (int)$currency->decimal_places);
|
|
||||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
|
||||||
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
|
|
||||||
PiggyBank::find($item->id)->update([$field => $correct]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method fixes all piggy bank events in currency $currency.
|
* This method fixes all piggy bank events in currency $currency.
|
||||||
*
|
*
|
||||||
@@ -459,6 +424,57 @@ class ForceDecimalSize extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method fixes all piggy banks in currency $currency.
|
||||||
|
*
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function correctPiggyAmounts(TransactionCurrency $currency, array $fields): void
|
||||||
|
{
|
||||||
|
$operator = $this->operator;
|
||||||
|
$cast = $this->cast;
|
||||||
|
$regularExpression = $this->regularExpression;
|
||||||
|
|
||||||
|
/** @var Builder $query */
|
||||||
|
$query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
|
||||||
|
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||||
|
->where('account_meta.name', 'currency_id')
|
||||||
|
->where('account_meta.data', json_encode((string)$currency->id))
|
||||||
|
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$q->orWhere(
|
||||||
|
DB::raw(sprintf('CAST(piggy_banks.%s AS %s)', $field, $cast)),
|
||||||
|
$operator,
|
||||||
|
DB::raw(sprintf($regularExpression, $currency->decimal_places))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = $query->get(['piggy_banks.*']);
|
||||||
|
if (0 === $result->count()) {
|
||||||
|
$this->friendlyPositive(sprintf('All piggy banks in %s are OK', $currency->code));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/** @var PiggyBank $item */
|
||||||
|
foreach ($result as $item) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$value = $item->$field;
|
||||||
|
if (null === $value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// fix $field by rounding it down correctly.
|
||||||
|
$pow = pow(10, (int)$currency->decimal_places);
|
||||||
|
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||||
|
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
|
||||||
|
PiggyBank::find($item->id)->update([$field => $correct]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method fixes all transactions in currency $currency.
|
* This method fixes all transactions in currency $currency.
|
||||||
*
|
*
|
||||||
@@ -524,22 +540,6 @@ class ForceDecimalSize extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function determineDatabaseType(): void
|
|
||||||
{
|
|
||||||
// switch stuff based on database connection:
|
|
||||||
$this->operator = 'REGEXP';
|
|
||||||
$this->regularExpression = '\'\\\\.[\\\\d]{%d}[1-9]+\'';
|
|
||||||
$this->cast = 'CHAR';
|
|
||||||
if ('pgsql' === config('database.default')) {
|
|
||||||
$this->operator = 'SIMILAR TO';
|
|
||||||
$this->regularExpression = '\'%%\.[\d]{%d}[1-9]+%%\'';
|
|
||||||
$this->cast = 'TEXT';
|
|
||||||
}
|
|
||||||
if ('sqlite' === config('database.default')) {
|
|
||||||
$this->regularExpression = '"\\.[\d]{%d}[1-9]+"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@@ -66,6 +66,93 @@ class UpgradeFireflyInstructions extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render upgrade instructions.
|
||||||
|
*/
|
||||||
|
private function updateInstructions(): void
|
||||||
|
{
|
||||||
|
/** @var string $version */
|
||||||
|
$version = config('firefly.version');
|
||||||
|
$config = config('upgrade.text.upgrade');
|
||||||
|
$text = '';
|
||||||
|
foreach (array_keys($config) as $compare) {
|
||||||
|
// if string starts with:
|
||||||
|
if (\str_starts_with($version, $compare)) {
|
||||||
|
$text = $config[$compare];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->newLine();
|
||||||
|
$this->showLogo();
|
||||||
|
$this->newLine();
|
||||||
|
$this->showLine();
|
||||||
|
|
||||||
|
$this->boxed('');
|
||||||
|
if (null === $text || '' === $text) {
|
||||||
|
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s', $version));
|
||||||
|
$this->boxedInfo('There are no extra upgrade instructions.');
|
||||||
|
$this->boxed('Firefly III should be ready for use.');
|
||||||
|
$this->boxed('');
|
||||||
|
$this->showLine();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s!', $version));
|
||||||
|
$this->boxedInfo($text);
|
||||||
|
$this->boxed('');
|
||||||
|
$this->showLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logo takes up 8 lines of code. So 8 colors can be used.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function showLogo(): void
|
||||||
|
{
|
||||||
|
$today = date('m-d');
|
||||||
|
$month = date('m');
|
||||||
|
// variation in colors and effects just because I can!
|
||||||
|
// default is Ukraine flag:
|
||||||
|
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
|
||||||
|
|
||||||
|
// 5th of May is Dutch liberation day and 29th of April is Dutch King's Day and September 17 is my birthday.
|
||||||
|
if ('05-01' === $today || '04-29' === $today || '09-17' === $today) {
|
||||||
|
$colors = ['red', 'red', 'red', 'white', 'white', 'blue', 'blue', 'blue'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// National Coming Out Day, International Day Against Homophobia, Biphobia and Transphobia and Pride Month
|
||||||
|
if ('10-11' === $today || '05-17' === $today || '06' === $month) {
|
||||||
|
$colors = ['red', 'bright-red', 'yellow', 'green', 'blue', 'magenta', 'default', 'default'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// International Transgender Day of Visibility
|
||||||
|
if ('03-31' === $today) {
|
||||||
|
$colors = ['bright-blue', 'bright-red', 'white', 'white', 'bright-red', 'bright-blue', 'default', 'default'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->line(sprintf('<fg=%s> ______ _ __ _ _____ _____ _____ </>', $colors[0]));
|
||||||
|
$this->line(sprintf('<fg=%s> | ____(_) / _| | |_ _|_ _|_ _| </>', $colors[1]));
|
||||||
|
$this->line(sprintf('<fg=%s> | |__ _ _ __ ___| |_| |_ _ | | | | | | </>', $colors[2]));
|
||||||
|
$this->line(sprintf('<fg=%s> | __| | | \'__/ _ \ _| | | | | | | | | | | </>', $colors[3]));
|
||||||
|
$this->line(sprintf('<fg=%s> | | | | | | __/ | | | |_| | _| |_ _| |_ _| |_ </>', $colors[4]));
|
||||||
|
$this->line(sprintf('<fg=%s> |_| |_|_| \___|_| |_|\__, | |_____|_____|_____| </>', $colors[5]));
|
||||||
|
$this->line(sprintf('<fg=%s> __/ | </>', $colors[6]));
|
||||||
|
$this->line(sprintf('<fg=%s> |___/ </>', $colors[7]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a line.
|
||||||
|
*/
|
||||||
|
private function showLine(): void
|
||||||
|
{
|
||||||
|
$line = '+';
|
||||||
|
$line .= str_repeat('-', 78);
|
||||||
|
$line .= '+';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a nice box.
|
* Show a nice box.
|
||||||
*
|
*
|
||||||
@@ -75,7 +162,7 @@ class UpgradeFireflyInstructions extends Command
|
|||||||
{
|
{
|
||||||
$parts = explode("\n", wordwrap($text));
|
$parts = explode("\n", wordwrap($text));
|
||||||
foreach ($parts as $string) {
|
foreach ($parts as $string) {
|
||||||
$this->line('| '.sprintf('%-77s', $string).'|');
|
$this->line('| ' . sprintf('%-77s', $string) . '|');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +175,7 @@ class UpgradeFireflyInstructions extends Command
|
|||||||
{
|
{
|
||||||
$parts = explode("\n", wordwrap($text));
|
$parts = explode("\n", wordwrap($text));
|
||||||
foreach ($parts as $string) {
|
foreach ($parts as $string) {
|
||||||
$this->info('| '.sprintf('%-77s', $string).'|');
|
$this->info('| ' . sprintf('%-77s', $string) . '|');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,90 +214,4 @@ class UpgradeFireflyInstructions extends Command
|
|||||||
$this->boxed('');
|
$this->boxed('');
|
||||||
$this->showLine();
|
$this->showLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a line.
|
|
||||||
*/
|
|
||||||
private function showLine(): void
|
|
||||||
{
|
|
||||||
$line = '+';
|
|
||||||
$line .= str_repeat('-', 78);
|
|
||||||
$line .= '+';
|
|
||||||
$this->line($line);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The logo takes up 8 lines of code. So 8 colors can be used.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function showLogo(): void
|
|
||||||
{
|
|
||||||
$today = date('m-d');
|
|
||||||
$month = date('m');
|
|
||||||
// variation in colors and effects just because I can!
|
|
||||||
// default is Ukraine flag:
|
|
||||||
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
|
|
||||||
|
|
||||||
// 5th of May is Dutch liberation day and 29th of April is Dutch King's Day and September 17 is my birthday.
|
|
||||||
if ('05-01' === $today || '04-29' === $today || '09-17' === $today) {
|
|
||||||
$colors = ['red', 'red', 'red', 'white', 'white', 'blue', 'blue', 'blue'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// National Coming Out Day, International Day Against Homophobia, Biphobia and Transphobia and Pride Month
|
|
||||||
if ('10-11' === $today || '05-17' === $today || '06' === $month) {
|
|
||||||
$colors = ['red', 'bright-red', 'yellow', 'green', 'blue', 'magenta', 'default', 'default'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// International Transgender Day of Visibility
|
|
||||||
if ('03-31' === $today) {
|
|
||||||
$colors = ['bright-blue', 'bright-red', 'white', 'white', 'bright-red', 'bright-blue', 'default', 'default'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->line(sprintf('<fg=%s> ______ _ __ _ _____ _____ _____ </>', $colors[0]));
|
|
||||||
$this->line(sprintf('<fg=%s> | ____(_) / _| | |_ _|_ _|_ _| </>', $colors[1]));
|
|
||||||
$this->line(sprintf('<fg=%s> | |__ _ _ __ ___| |_| |_ _ | | | | | | </>', $colors[2]));
|
|
||||||
$this->line(sprintf('<fg=%s> | __| | | \'__/ _ \ _| | | | | | | | | | | </>', $colors[3]));
|
|
||||||
$this->line(sprintf('<fg=%s> | | | | | | __/ | | | |_| | _| |_ _| |_ _| |_ </>', $colors[4]));
|
|
||||||
$this->line(sprintf('<fg=%s> |_| |_|_| \___|_| |_|\__, | |_____|_____|_____| </>', $colors[5]));
|
|
||||||
$this->line(sprintf('<fg=%s> __/ | </>', $colors[6]));
|
|
||||||
$this->line(sprintf('<fg=%s> |___/ </>', $colors[7]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render upgrade instructions.
|
|
||||||
*/
|
|
||||||
private function updateInstructions(): void
|
|
||||||
{
|
|
||||||
/** @var string $version */
|
|
||||||
$version = config('firefly.version');
|
|
||||||
$config = config('upgrade.text.upgrade');
|
|
||||||
$text = '';
|
|
||||||
foreach (array_keys($config) as $compare) {
|
|
||||||
// if string starts with:
|
|
||||||
if (\str_starts_with($version, $compare)) {
|
|
||||||
$text = $config[$compare];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->newLine();
|
|
||||||
$this->showLogo();
|
|
||||||
$this->newLine();
|
|
||||||
$this->showLine();
|
|
||||||
|
|
||||||
$this->boxed('');
|
|
||||||
if (null === $text || '' === $text) {
|
|
||||||
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s', $version));
|
|
||||||
$this->boxedInfo('There are no extra upgrade instructions.');
|
|
||||||
$this->boxed('Firefly III should be ready for use.');
|
|
||||||
$this->boxed('');
|
|
||||||
$this->showLine();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s!', $version));
|
|
||||||
$this->boxedInfo($text);
|
|
||||||
$this->boxed('');
|
|
||||||
$this->showLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -153,49 +153,6 @@ class ApplyRules extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function getRulesToApply(): Collection
|
|
||||||
{
|
|
||||||
$rulesToApply = new Collection();
|
|
||||||
/** @var RuleGroup $group */
|
|
||||||
foreach ($this->groups as $group) {
|
|
||||||
$rules = $this->ruleGroupRepository->getActiveStoreRules($group);
|
|
||||||
/** @var Rule $rule */
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
// if in rule selection, or group in selection or all rules, it's included.
|
|
||||||
$test = $this->includeRule($rule, $group);
|
|
||||||
if (true === $test) {
|
|
||||||
Log::debug(sprintf('Will include rule #%d "%s"', $rule->id, $rule->title));
|
|
||||||
$rulesToApply->push($rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rulesToApply;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
private function grabAllRules(): void
|
|
||||||
{
|
|
||||||
$this->groups = $this->ruleGroupRepository->getActiveGroups();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Rule $rule
|
|
||||||
* @param RuleGroup $group
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function includeRule(Rule $rule, RuleGroup $group): bool
|
|
||||||
{
|
|
||||||
return in_array($group->id, $this->ruleGroupSelection, true)
|
|
||||||
|| in_array($rule->id, $this->ruleSelection, true)
|
|
||||||
|| $this->allRules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
||||||
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
||||||
@@ -274,42 +231,6 @@ class ApplyRules extends Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function verifyInputDates(): void
|
|
||||||
{
|
|
||||||
// parse start date.
|
|
||||||
$inputStart = today(config('app.timezone'))->startOfMonth();
|
|
||||||
$startString = $this->option('start_date');
|
|
||||||
if (null === $startString) {
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
|
||||||
$repository->setUser($this->getUser());
|
|
||||||
$first = $repository->firstNull();
|
|
||||||
if (null !== $first) {
|
|
||||||
$inputStart = $first->date;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (null !== $startString && '' !== $startString) {
|
|
||||||
$inputStart = Carbon::createFromFormat('Y-m-d', $startString);
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse end date
|
|
||||||
$inputEnd = today(config('app.timezone'));
|
|
||||||
$endString = $this->option('end_date');
|
|
||||||
if (null !== $endString && '' !== $endString) {
|
|
||||||
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($inputStart > $inputEnd) {
|
|
||||||
[$inputEnd, $inputStart] = [$inputStart, $inputEnd];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->startDate = $inputStart;
|
|
||||||
$this->endDate = $inputEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@@ -356,4 +277,83 @@ class ApplyRules extends Command
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function verifyInputDates(): void
|
||||||
|
{
|
||||||
|
// parse start date.
|
||||||
|
$inputStart = today(config('app.timezone'))->startOfMonth();
|
||||||
|
$startString = $this->option('start_date');
|
||||||
|
if (null === $startString) {
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$repository->setUser($this->getUser());
|
||||||
|
$first = $repository->firstNull();
|
||||||
|
if (null !== $first) {
|
||||||
|
$inputStart = $first->date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null !== $startString && '' !== $startString) {
|
||||||
|
$inputStart = Carbon::createFromFormat('Y-m-d', $startString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse end date
|
||||||
|
$inputEnd = today(config('app.timezone'));
|
||||||
|
$endString = $this->option('end_date');
|
||||||
|
if (null !== $endString && '' !== $endString) {
|
||||||
|
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($inputStart > $inputEnd) {
|
||||||
|
[$inputEnd, $inputStart] = [$inputStart, $inputEnd];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->startDate = $inputStart;
|
||||||
|
$this->endDate = $inputEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
private function grabAllRules(): void
|
||||||
|
{
|
||||||
|
$this->groups = $this->ruleGroupRepository->getActiveGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
private function getRulesToApply(): Collection
|
||||||
|
{
|
||||||
|
$rulesToApply = new Collection();
|
||||||
|
/** @var RuleGroup $group */
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$rules = $this->ruleGroupRepository->getActiveStoreRules($group);
|
||||||
|
/** @var Rule $rule */
|
||||||
|
foreach ($rules as $rule) {
|
||||||
|
// if in rule selection, or group in selection or all rules, it's included.
|
||||||
|
$test = $this->includeRule($rule, $group);
|
||||||
|
if (true === $test) {
|
||||||
|
Log::debug(sprintf('Will include rule #%d "%s"', $rule->id, $rule->title));
|
||||||
|
$rulesToApply->push($rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rulesToApply;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Rule $rule
|
||||||
|
* @param RuleGroup $group
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function includeRule(Rule $rule, RuleGroup $group): bool
|
||||||
|
{
|
||||||
|
return in_array($group->id, $this->ruleGroupSelection, true)
|
||||||
|
|| in_array($rule->id, $this->ruleSelection, true)
|
||||||
|
|| $this->allRules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -126,6 +126,62 @@ class Cron extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $force
|
||||||
|
* @param Carbon|null $date
|
||||||
|
*/
|
||||||
|
private function exchangeRatesCronJob(bool $force, ?Carbon $date): void
|
||||||
|
{
|
||||||
|
$exchangeRates = new ExchangeRatesCronjob();
|
||||||
|
$exchangeRates->setForce($force);
|
||||||
|
// set date in cron job:
|
||||||
|
if (null !== $date) {
|
||||||
|
$exchangeRates->setDate($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$exchangeRates->fire();
|
||||||
|
|
||||||
|
if ($exchangeRates->jobErrored) {
|
||||||
|
$this->friendlyError(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message));
|
||||||
|
}
|
||||||
|
if ($exchangeRates->jobFired) {
|
||||||
|
$this->friendlyInfo(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message));
|
||||||
|
}
|
||||||
|
if ($exchangeRates->jobSucceeded) {
|
||||||
|
$this->friendlyPositive(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $force
|
||||||
|
* @param Carbon|null $date
|
||||||
|
*
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws FireflyException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function recurringCronJob(bool $force, ?Carbon $date): void
|
||||||
|
{
|
||||||
|
$recurring = new RecurringCronjob();
|
||||||
|
$recurring->setForce($force);
|
||||||
|
|
||||||
|
// set date in cron job:
|
||||||
|
if (null !== $date) {
|
||||||
|
$recurring->setDate($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$recurring->fire();
|
||||||
|
if ($recurring->jobErrored) {
|
||||||
|
$this->friendlyError(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
|
||||||
|
}
|
||||||
|
if ($recurring->jobFired) {
|
||||||
|
$this->friendlyInfo(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
|
||||||
|
}
|
||||||
|
if ($recurring->jobSucceeded) {
|
||||||
|
$this->friendlyPositive(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
* @param Carbon|null $date
|
* @param Carbon|null $date
|
||||||
@@ -182,60 +238,4 @@ class Cron extends Command
|
|||||||
$this->friendlyPositive(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
|
$this->friendlyPositive(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $force
|
|
||||||
* @param Carbon|null $date
|
|
||||||
*/
|
|
||||||
private function exchangeRatesCronJob(bool $force, ?Carbon $date): void
|
|
||||||
{
|
|
||||||
$exchangeRates = new ExchangeRatesCronjob();
|
|
||||||
$exchangeRates->setForce($force);
|
|
||||||
// set date in cron job:
|
|
||||||
if (null !== $date) {
|
|
||||||
$exchangeRates->setDate($date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$exchangeRates->fire();
|
|
||||||
|
|
||||||
if ($exchangeRates->jobErrored) {
|
|
||||||
$this->friendlyError(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message));
|
|
||||||
}
|
|
||||||
if ($exchangeRates->jobFired) {
|
|
||||||
$this->friendlyInfo(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message));
|
|
||||||
}
|
|
||||||
if ($exchangeRates->jobSucceeded) {
|
|
||||||
$this->friendlyPositive(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $force
|
|
||||||
* @param Carbon|null $date
|
|
||||||
*
|
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws FireflyException
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
private function recurringCronJob(bool $force, ?Carbon $date): void
|
|
||||||
{
|
|
||||||
$recurring = new RecurringCronjob();
|
|
||||||
$recurring->setForce($force);
|
|
||||||
|
|
||||||
// set date in cron job:
|
|
||||||
if (null !== $date) {
|
|
||||||
$recurring->setDate($date);
|
|
||||||
}
|
|
||||||
|
|
||||||
$recurring->fire();
|
|
||||||
if ($recurring->jobErrored) {
|
|
||||||
$this->friendlyError(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
|
|
||||||
}
|
|
||||||
if ($recurring->jobFired) {
|
|
||||||
$this->friendlyInfo(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
|
|
||||||
}
|
|
||||||
if ($recurring->jobSucceeded) {
|
|
||||||
$this->friendlyPositive(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -35,8 +35,6 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountCurrencies
|
* Class AccountCurrencies
|
||||||
@@ -54,7 +52,8 @@ class AccountCurrencies extends Command
|
|||||||
private UserRepositoryInterface $userRepos;
|
private UserRepositoryInterface $userRepos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's forced upon the account.
|
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's
|
||||||
|
* forced upon the account.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
@@ -80,6 +79,19 @@ class AccountCurrencies extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
||||||
|
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
||||||
|
* be called from the handle method instead of using the constructor to initialize the command.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function stupidLaravel(): void
|
||||||
|
{
|
||||||
|
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||||
|
$this->userRepos = app(UserRepositoryInterface::class);
|
||||||
|
$this->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@@ -92,22 +104,46 @@ class AccountCurrencies extends Command
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function markAsExecuted(): void
|
private function updateAccountCurrencies(): void
|
||||||
{
|
{
|
||||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
$users = $this->userRepos->all();
|
||||||
|
$defaultCurrencyCode = (string)config('firefly.default_currency', 'EUR');
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$this->updateCurrenciesForUser($user, $defaultCurrencyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
|
* @param User $user
|
||||||
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
|
* @param string $systemCurrencyCode
|
||||||
* be called from the handle method instead of using the constructor to initialize the command.
|
|
||||||
*
|
*
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
private function stupidLaravel(): void
|
private function updateCurrenciesForUser(User $user, string $systemCurrencyCode): void
|
||||||
{
|
{
|
||||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
$this->accountRepos->setUser($user);
|
||||||
$this->userRepos = app(UserRepositoryInterface::class);
|
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||||
$this->count = 0;
|
|
||||||
|
// get user's currency preference:
|
||||||
|
$defaultCurrencyCode = app('preferences')->getForUser($user, 'currencyPreference', $systemCurrencyCode)->data;
|
||||||
|
if (!is_string($defaultCurrencyCode)) {
|
||||||
|
$defaultCurrencyCode = $systemCurrencyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var TransactionCurrency|null $defaultCurrency */
|
||||||
|
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
||||||
|
|
||||||
|
if (null === $defaultCurrency) {
|
||||||
|
Log::error(sprintf('Users currency pref "%s" does not exist!', $defaultCurrencyCode));
|
||||||
|
$this->friendlyError(sprintf('User has a preference for "%s", but this currency does not exist.', $defaultCurrencyCode));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$this->updateAccount($account, $defaultCurrency);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,45 +194,8 @@ class AccountCurrencies extends Command
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function updateAccountCurrencies(): void
|
private function markAsExecuted(): void
|
||||||
{
|
{
|
||||||
$users = $this->userRepos->all();
|
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||||
$defaultCurrencyCode = (string)config('firefly.default_currency', 'EUR');
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$this->updateCurrenciesForUser($user, $defaultCurrencyCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
* @param string $systemCurrencyCode
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function updateCurrenciesForUser(User $user, string $systemCurrencyCode): void
|
|
||||||
{
|
|
||||||
$this->accountRepos->setUser($user);
|
|
||||||
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
|
||||||
|
|
||||||
// get user's currency preference:
|
|
||||||
$defaultCurrencyCode = app('preferences')->getForUser($user, 'currencyPreference', $systemCurrencyCode)->data;
|
|
||||||
if (!is_string($defaultCurrencyCode)) {
|
|
||||||
$defaultCurrencyCode = $systemCurrencyCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var TransactionCurrency|null $defaultCurrency */
|
|
||||||
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
|
||||||
|
|
||||||
if (null === $defaultCurrency) {
|
|
||||||
Log::error(sprintf('Users currency pref "%s" does not exist!', $defaultCurrencyCode));
|
|
||||||
$this->friendlyError(sprintf('User has a preference for "%s", but this currency does not exist.', $defaultCurrencyCode));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$this->updateAccount($account, $defaultCurrency);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,6 +71,30 @@ class AppendBudgetLimitPeriods extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function isExecuted(): bool
|
||||||
|
{
|
||||||
|
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||||
|
|
||||||
|
return (bool)$configVar->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function theresNoLimit(): void
|
||||||
|
{
|
||||||
|
$limits = BudgetLimit::whereNull('period')->get();
|
||||||
|
/** @var BudgetLimit $limit */
|
||||||
|
foreach ($limits as $limit) {
|
||||||
|
$this->fixLimit($limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BudgetLimit $limit
|
* @param BudgetLimit $limit
|
||||||
*/
|
*/
|
||||||
@@ -156,18 +180,6 @@ class AppendBudgetLimitPeriods extends Command
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
private function isExecuted(): bool
|
|
||||||
{
|
|
||||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
|
||||||
|
|
||||||
return (bool)$configVar->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -175,16 +187,4 @@ class AppendBudgetLimitPeriods extends Command
|
|||||||
{
|
{
|
||||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private function theresNoLimit(): void
|
|
||||||
{
|
|
||||||
$limits = BudgetLimit::whereNull('period')->get();
|
|
||||||
/** @var BudgetLimit $limit */
|
|
||||||
foreach ($limits as $limit) {
|
|
||||||
$this->fixLimit($limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,6 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
@@ -87,54 +86,6 @@ class BackToJournals extends Command
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getIdsForBudgets(): array
|
|
||||||
{
|
|
||||||
$transactions = DB::table('budget_transaction')->distinct()->pluck('transaction_id')->toArray();
|
|
||||||
$array = [];
|
|
||||||
$chunks = array_chunk($transactions, 500);
|
|
||||||
|
|
||||||
foreach ($chunks as $chunk) {
|
|
||||||
$set = DB::table('transactions')->whereIn('transactions.id', $chunk)->pluck('transaction_journal_id')->toArray();
|
|
||||||
$array = array_merge($array, $set);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getIdsForCategories(): array
|
|
||||||
{
|
|
||||||
$transactions = DB::table('category_transaction')->distinct()->pluck('transaction_id')->toArray();
|
|
||||||
$array = [];
|
|
||||||
$chunks = array_chunk($transactions, 500);
|
|
||||||
|
|
||||||
foreach ($chunks as $chunk) {
|
|
||||||
$set = DB::table('transactions')
|
|
||||||
->whereIn('transactions.id', $chunk)
|
|
||||||
->pluck('transaction_journal_id')->toArray();
|
|
||||||
$array = array_merge($array, $set);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
* @throws ContainerExceptionInterface
|
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
|
||||||
private function isExecuted(): bool
|
|
||||||
{
|
|
||||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
|
||||||
|
|
||||||
return (bool)$configVar->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
@@ -148,11 +99,15 @@ class BackToJournals extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return bool
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
private function markAsExecuted(): void
|
private function isExecuted(): bool
|
||||||
{
|
{
|
||||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||||
|
|
||||||
|
return (bool)$configVar->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,6 +141,23 @@ class BackToJournals extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getIdsForBudgets(): array
|
||||||
|
{
|
||||||
|
$transactions = DB::table('budget_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||||
|
$array = [];
|
||||||
|
$chunks = array_chunk($transactions, 500);
|
||||||
|
|
||||||
|
foreach ($chunks as $chunk) {
|
||||||
|
$set = DB::table('transactions')->whereIn('transactions.id', $chunk)->pluck('transaction_journal_id')->toArray();
|
||||||
|
$array = array_merge($array, $set);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*/
|
*/
|
||||||
@@ -239,6 +211,25 @@ class BackToJournals extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getIdsForCategories(): array
|
||||||
|
{
|
||||||
|
$transactions = DB::table('category_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||||
|
$array = [];
|
||||||
|
$chunks = array_chunk($transactions, 500);
|
||||||
|
|
||||||
|
foreach ($chunks as $chunk) {
|
||||||
|
$set = DB::table('transactions')
|
||||||
|
->whereIn('transactions.id', $chunk)
|
||||||
|
->pluck('transaction_journal_id')->toArray();
|
||||||
|
$array = array_merge($array, $set);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*/
|
*/
|
||||||
@@ -268,4 +259,12 @@ class BackToJournals extends Command
|
|||||||
$journal->categories()->sync([(int)$category->id]);
|
$journal->categories()->sync([(int)$category->id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function markAsExecuted(): void
|
||||||
|
{
|
||||||
|
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user