Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code cleanup [skip ci]
James Coleb8774a7af3f6
diff --git a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php b/app/Api/V1/Controllers/Autocomplete/CurrencyController.phpindex 1e8f67827d..5f17ca3bb2 100644--- a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php+++ b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php@@ -89,7 +89,7 @@ class CurrencyController extends Controller*/public function currencies(AutocompleteRequest $request): JsonResponse{- $data = $request->getData();+ $data = $request->getData();$collection = $this->repository->searchCurrency($data['query'], $data['limit']);$result = [];diff --git a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.phpindex 47ef2259c9..fc2c682a91 100644--- a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php+++ b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php@@ -76,7 +76,7 @@ class PiggyBankController extends Controller/** @var PiggyBank $piggy */foreach ($piggies as $piggy) {- $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;+ $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;$response[] = ['id' => $piggy->id,'name' => $piggy->name,@@ -103,9 +103,9 @@ class PiggyBankController extends Controller$response = [];/** @var PiggyBank $piggy */foreach ($piggies as $piggy) {- $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;- $currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';- $response[] = [+ $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;+ $currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';+ $response[] = ['id' => $piggy->id,'name' => $piggy->name,'name_with_balance' => sprintf(diff --git a/app/Api/V1/Controllers/Chart/AvailableBudgetController.php b/app/Api/V1/Controllers/Chart/AvailableBudgetController.phpindex dc05304d6e..e299a504f4 100644--- a/app/Api/V1/Controllers/Chart/AvailableBudgetController.php+++ b/app/Api/V1/Controllers/Chart/AvailableBudgetController.php@@ -31,7 +31,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;use FireflyIII\User;use Illuminate\Http\JsonResponse;-use Illuminate\Support\Collection;/*** Class AvailableBudgetControllerdiff --git a/app/Api/V1/Controllers/Chart/BudgetController.php b/app/Api/V1/Controllers/Chart/BudgetController.phpindex 2dd4a953f2..4e153e0161 100644--- a/app/Api/V1/Controllers/Chart/BudgetController.php+++ b/app/Api/V1/Controllers/Chart/BudgetController.php@@ -131,93 +131,6 @@ class BudgetController extends Controllerreturn $arr;}- /**- * @param array $budgetNames- * @param array $currencyNames- *- * @return array- */- private function createSets(array $budgetNames, array $currencyNames): array- {- $return = [];- foreach ($currencyNames as $currencyName) {- $entries = [];- foreach ($budgetNames as $budgetName) {- $label = sprintf('%s (%s)', $budgetName, $currencyName);- $entries[$label] = '0';- }-- // left- $return['left'] = [- 'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName),- 'data_type' => 'left',- 'currency_name' => $currencyName,- 'type' => 'bar',- 'yAxisID' => 0, // 0, 1, 2- 'entries' => $entries,- ];-- // spent_capped- $return['spent_capped'] = [- 'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName),- 'data_type' => 'spent_capped',- 'currency_name' => $currencyName,- 'type' => 'bar',- 'yAxisID' => 0, // 0, 1, 2- 'entries' => $entries,- ];-- // overspent- $return['overspent'] = [- 'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName),- 'data_type' => 'overspent',- 'currency_name' => $currencyName,- 'type' => 'bar',- 'yAxisID' => 0, // 0, 1, 2- 'entries' => $entries,- ];-- }-- return $return;- }-- /**- * @param array $basic- * @param array $sets- *- * @return array- */- private function fillSets(array $basic, array $sets): array- {- foreach ($sets as $set) {- $label = $set['label'];- $basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];- $basic['left']['entries'][$label] = $set['entries']['left'];- $basic['overspent']['entries'][$label] = $set['entries']['overspent'];- }-- return $basic;- }-- /**- * @param array $expenses- *- * @return array- */- private function filterNulls(array $expenses): array- {- $return = [];- /** @var array|null $arr */- foreach ($expenses as $arr) {- if ([] !== $arr) {- $return[] = $arr;- }- }-- return $return;- }-/*** @param Budget $budget* @param Carbon $start@@ -288,10 +201,97 @@ class BudgetController extends Controller$return['entries']['spent'] = $sumSpent;$return['entries']['amount'] = $limit->amount;$return['entries']['spent_capped'] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent;- $return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left+ $return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left$return['entries']['overspent'] = 1 === bccomp($limit->amount, $sumSpent) ? '0' : bcmul(bcadd($set['sum'], $limit->amount), '-1'); // overspentreturn $return;}+ /**+ * @param array $expenses+ *+ * @return array+ */+ private function filterNulls(array $expenses): array+ {+ $return = [];+ /** @var array|null $arr */+ foreach ($expenses as $arr) {+ if ([] !== $arr) {+ $return[] = $arr;+ }+ }++ return $return;+ }++ /**+ * @param array $budgetNames+ * @param array $currencyNames+ *+ * @return array+ */+ private function createSets(array $budgetNames, array $currencyNames): array+ {+ $return = [];+ foreach ($currencyNames as $currencyName) {+ $entries = [];+ foreach ($budgetNames as $budgetName) {+ $label = sprintf('%s (%s)', $budgetName, $currencyName);+ $entries[$label] = '0';+ }++ // left+ $return['left'] = [+ 'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName),+ 'data_type' => 'left',+ 'currency_name' => $currencyName,+ 'type' => 'bar',+ 'yAxisID' => 0, // 0, 1, 2+ 'entries' => $entries,+ ];++ // spent_capped+ $return['spent_capped'] = [+ 'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName),+ 'data_type' => 'spent_capped',+ 'currency_name' => $currencyName,+ 'type' => 'bar',+ 'yAxisID' => 0, // 0, 1, 2+ 'entries' => $entries,+ ];++ // overspent+ $return['overspent'] = [+ 'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName),+ 'data_type' => 'overspent',+ 'currency_name' => $currencyName,+ 'type' => 'bar',+ 'yAxisID' => 0, // 0, 1, 2+ 'entries' => $entries,+ ];++ }++ return $return;+ }++ /**+ * @param array $basic+ * @param array $sets+ *+ * @return array+ */+ private function fillSets(array $basic, array $sets): array+ {+ foreach ($sets as $set) {+ $label = $set['label'];+ $basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];+ $basic['left']['entries'][$label] = $set['entries']['left'];+ $basic['overspent']['entries'][$label] = $set['entries']['overspent'];+ }++ return $basic;+ }+}diff --git a/app/Api/V1/Controllers/Chart/CategoryController.php b/app/Api/V1/Controllers/Chart/CategoryController.phpindex 6b88eb1ad6..bb789bd0cc 100644--- a/app/Api/V1/Controllers/Chart/CategoryController.php+++ b/app/Api/V1/Controllers/Chart/CategoryController.php@@ -88,17 +88,17 @@ class CategoryController extends Controller$end = $dates['end'];- $tempData = [];- $spentWith = $this->opsRepository->listExpenses($start, $end);- $spentWithout = $this->noCatRepository->listExpenses($start, $end);- $categories = [];+ $tempData = [];+ $spentWith = $this->opsRepository->listExpenses($start, $end);+ $spentWithout = $this->noCatRepository->listExpenses($start, $end);+ $categories = [];- foreach ([$spentWith, $spentWithout, ] as $set) {+ foreach ([$spentWith, $spentWithout,] as $set) {foreach ($set as $currency) {foreach ($currency['categories'] as $category) {- $categories[] = $category['name'];- $outKey = sprintf('%d-e', $currency['currency_id']);+ $categories[] = $category['name'];+ $outKey = sprintf('%d-e', $currency['currency_id']);$tempData[$outKey] = $tempData[$outKey] ?? ['currency_id' => $currency['currency_id'],'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),diff --git a/app/Api/V1/Controllers/Data/DestroyController.php b/app/Api/V1/Controllers/Data/DestroyController.phpindex 98bbfabc50..830cda1dc4 100644--- a/app/Api/V1/Controllers/Data/DestroyController.php+++ b/app/Api/V1/Controllers/Data/DestroyController.php@@ -160,31 +160,6 @@ class DestroyController extends Controllerreturn response()->json([], 204);}- /**- * @param array $types- */- private function destroyAccounts(array $types): void- {- /** @var AccountRepositoryInterface $repository */- $repository = app(AccountRepositoryInterface::class);- $collection = $repository->getAccountsByType($types);- $service = app(AccountDestroyService::class);- /** @var Account $account */- foreach ($collection as $account) {- $service->destroy($account, null);- }- }-- /**- *- */- private function destroyBills(): void- {- /** @var BillRepositoryInterface $repository */- $repository = app(BillRepositoryInterface::class);- $repository->destroyAll();- }-/****/@@ -206,18 +181,11 @@ class DestroyController extends Controller/****/- private function destroyCategories(): void- {- /** @var CategoryRepositoryInterface $categoryRepos */- $categoryRepos = app(CategoryRepositoryInterface::class);- $categoryRepos->destroyAll();- }-- private function destroyObjectGroups(): void+ private function destroyBills(): void{- /** @var ObjectGroupRepositoryInterface $repository */- $repository = app(ObjectGroupRepositoryInterface::class);- $repository->deleteAll();+ /** @var BillRepositoryInterface $repository */+ $repository = app(BillRepositoryInterface::class);+ $repository->destroyAll();}/**@@ -230,6 +198,16 @@ class DestroyController extends Controller$repository->destroyAll();}+ /**+ *+ */+ private function destroyRules(): void+ {+ /** @var RuleGroupRepositoryInterface $repository */+ $repository = app(RuleGroupRepositoryInterface::class);+ $repository->destroyAll();+ }+/****/@@ -243,11 +221,11 @@ class DestroyController extends Controller/****/- private function destroyRules(): void+ private function destroyCategories(): void{- /** @var RuleGroupRepositoryInterface $repository */- $repository = app(RuleGroupRepositoryInterface::class);- $repository->destroyAll();+ /** @var CategoryRepositoryInterface $categoryRepos */+ $categoryRepos = app(CategoryRepositoryInterface::class);+ $categoryRepos->destroyAll();}/**@@ -260,6 +238,28 @@ class DestroyController extends Controller$tagRepository->destroyAll();}+ private function destroyObjectGroups(): void+ {+ /** @var ObjectGroupRepositoryInterface $repository */+ $repository = app(ObjectGroupRepositoryInterface::class);+ $repository->deleteAll();+ }++ /**+ * @param array $types+ */+ private function destroyAccounts(array $types): void+ {+ /** @var AccountRepositoryInterface $repository */+ $repository = app(AccountRepositoryInterface::class);+ $collection = $repository->getAccountsByType($types);+ $service = app(AccountDestroyService::class);+ /** @var Account $account */+ foreach ($collection as $account) {+ $service->destroy($account, null);+ }+ }+/*** @param array $types*/@@ -267,10 +267,10 @@ class DestroyController extends Controller{/** @var JournalRepositoryInterface $repository */$repository = app(JournalRepositoryInterface::class);- $journals = $repository->findByType($types);- $service = app(JournalDestroyService::class);+ $journals = $repository->findByType($types);+ $service = app(JournalDestroyService::class);/** @var TransactionJournal $journal */- foreach($journals as $journal) {+ foreach ($journals as $journal) {$service->destroy($journal);}}diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/Search/TransactionController.phpindex 6db862591e..58766005b7 100644--- a/app/Api/V1/Controllers/Search/TransactionController.php+++ b/app/Api/V1/Controllers/Search/TransactionController.php@@ -45,7 +45,7 @@ class TransactionController extends Controller*/public function search(Request $request, SearchInterface $searcher): JsonResponse{- $manager = $this->getManager();+ $manager = $this->getManager();$fullQuery = (string) $request->get('query');$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');diff --git a/app/Api/V1/Middleware/ApiDemoUser.php b/app/Api/V1/Middleware/ApiDemoUser.phpindex 14fc2ac314..fd3b1e35b6 100644--- a/app/Api/V1/Middleware/ApiDemoUser.php+++ b/app/Api/V1/Middleware/ApiDemoUser.php@@ -23,7 +23,6 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Middleware;use Closure;-use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\User;use Illuminate\Http\Request;diff --git a/app/Api/V1/Requests/AccountUpdateRequest.php b/app/Api/V1/Requests/AccountUpdateRequest.phpindex c0976a5f38..af8b807c76 100644--- a/app/Api/V1/Requests/AccountUpdateRequest.php+++ b/app/Api/V1/Requests/AccountUpdateRequest.php@@ -38,6 +38,7 @@ use Illuminate\Foundation\Http\FormRequest;class AccountUpdateRequest extends FormRequest{use ConvertsDataTypes, AppendsLocationData;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/AttachmentStoreRequest.php b/app/Api/V1/Requests/AttachmentStoreRequest.phpindex 7b0b901daf..d92ad40e40 100644--- a/app/Api/V1/Requests/AttachmentStoreRequest.php+++ b/app/Api/V1/Requests/AttachmentStoreRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class AttachmentStoreRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/AttachmentUpdateRequest.php b/app/Api/V1/Requests/AttachmentUpdateRequest.phpindex 910d07d53d..ff09081edd 100644--- a/app/Api/V1/Requests/AttachmentUpdateRequest.php+++ b/app/Api/V1/Requests/AttachmentUpdateRequest.php@@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;class AttachmentUpdateRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/AvailableBudgetRequest.php b/app/Api/V1/Requests/AvailableBudgetRequest.phpindex 01b09cd798..328abf0f3c 100644--- a/app/Api/V1/Requests/AvailableBudgetRequest.php+++ b/app/Api/V1/Requests/AvailableBudgetRequest.php@@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;class AvailableBudgetRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.phpindex 79d4d89548..e0a97bc9e8 100644--- a/app/Api/V1/Requests/BillRequest.php+++ b/app/Api/V1/Requests/BillRequest.php@@ -39,6 +39,7 @@ use Illuminate\Validation\Validator;class BillRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/BudgetStoreRequest.php b/app/Api/V1/Requests/BudgetStoreRequest.phpindex 812d7f4f8e..b41ff703ca 100644--- a/app/Api/V1/Requests/BudgetStoreRequest.php+++ b/app/Api/V1/Requests/BudgetStoreRequest.php@@ -37,6 +37,7 @@ use Illuminate\Validation\Validator;class BudgetStoreRequest extends FormRequest{use ConvertsDataTypes, ValidatesAutoBudgetRequest;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/BudgetUpdateRequest.php b/app/Api/V1/Requests/BudgetUpdateRequest.phpindex e7bf86c17f..6ccdd9681c 100644--- a/app/Api/V1/Requests/BudgetUpdateRequest.php+++ b/app/Api/V1/Requests/BudgetUpdateRequest.php@@ -37,6 +37,7 @@ use Illuminate\Validation\Validator;class BudgetUpdateRequest extends FormRequest{use ConvertsDataTypes, ValidatesAutoBudgetRequest;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/CategoryRequest.php b/app/Api/V1/Requests/CategoryRequest.phpindex ebeae6a766..6360ddc152 100644--- a/app/Api/V1/Requests/CategoryRequest.php+++ b/app/Api/V1/Requests/CategoryRequest.php@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;class CategoryRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/ConfigurationRequest.php b/app/Api/V1/Requests/ConfigurationRequest.phpindex 93f68c2598..2d86a1bfbc 100644--- a/app/Api/V1/Requests/ConfigurationRequest.php+++ b/app/Api/V1/Requests/ConfigurationRequest.php@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;class ConfigurationRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/CurrencyRequest.php b/app/Api/V1/Requests/CurrencyRequest.phpindex 7d50a94ed7..1b694114f8 100644--- a/app/Api/V1/Requests/CurrencyRequest.php+++ b/app/Api/V1/Requests/CurrencyRequest.php@@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest;class CurrencyRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/DataDestroyRequest.php b/app/Api/V1/Requests/DataDestroyRequest.phpindex 8513099869..f55a645917 100644--- a/app/Api/V1/Requests/DataDestroyRequest.php+++ b/app/Api/V1/Requests/DataDestroyRequest.php@@ -32,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;class DataDestroyRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/DateRequest.php b/app/Api/V1/Requests/DateRequest.phpindex 63cd80b69c..a329ae9a18 100644--- a/app/Api/V1/Requests/DateRequest.php+++ b/app/Api/V1/Requests/DateRequest.php@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;class DateRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/LinkTypeRequest.php b/app/Api/V1/Requests/LinkTypeRequest.phpindex c0d42b3e74..ba55cc964f 100644--- a/app/Api/V1/Requests/LinkTypeRequest.php+++ b/app/Api/V1/Requests/LinkTypeRequest.php@@ -37,6 +37,7 @@ use Illuminate\Validation\Rule;class LinkTypeRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/ObjectGroupUpdateRequest.php b/app/Api/V1/Requests/ObjectGroupUpdateRequest.phpindex cc306ed14e..16ee295312 100644--- a/app/Api/V1/Requests/ObjectGroupUpdateRequest.php+++ b/app/Api/V1/Requests/ObjectGroupUpdateRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class ObjectGroupUpdateRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/PiggyBankStoreRequest.php b/app/Api/V1/Requests/PiggyBankStoreRequest.phpindex a6d627cccc..9cdf005d94 100644--- a/app/Api/V1/Requests/PiggyBankStoreRequest.php+++ b/app/Api/V1/Requests/PiggyBankStoreRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class PiggyBankStoreRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.phpindex 40da7f863b..01e6d9b344 100644--- a/app/Api/V1/Requests/RecurrenceStoreRequest.php+++ b/app/Api/V1/Requests/RecurrenceStoreRequest.php@@ -40,6 +40,7 @@ use Illuminate\Validation\Validator;class RecurrenceStoreRequest extends FormRequest{use ConvertsDataTypes, RecurrenceValidation, TransactionValidation, CurrencyValidation, GetRecurrenceData;+/*** Authorize logged in users.*@@ -83,6 +84,56 @@ class RecurrenceStoreRequest 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 $transactions */+ $transactions = $this->get('transactions');+ if (null === $transactions) {+ return [];+ }+ /** @var array $transaction */+ foreach ($transactions as $transaction) {+ $return[] = $this->getSingleRecurrenceData($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 $repetitions */+ $repetitions = $this->get('repetitions');+ if (null === $repetitions) {+ return [];+ }+ /** @var array $repetition */+ foreach ($repetitions as $repetition) {+ $return[] = [+ 'type' => $repetition['type'],+ 'moment' => $repetition['moment'],+ 'skip' => (int) $repetition['skip'],+ 'weekend' => (int) $repetition['weekend'],+ ];+ }++ return $return;+ }+/*** The rules that the incoming request must be matched against.*@@ -150,54 +201,4 @@ class RecurrenceStoreRequest 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 $repetitions */- $repetitions = $this->get('repetitions');- if (null === $repetitions) {- return [];- }- /** @var array $repetition */- foreach ($repetitions as $repetition) {- $return[] = [- 'type' => $repetition['type'],- 'moment' => $repetition['moment'],- 'skip' => (int) $repetition['skip'],- 'weekend' => (int) $repetition['weekend'],- ];- }-- 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 $transactions */- $transactions = $this->get('transactions');- if (null === $transactions) {- return [];- }- /** @var array $transaction */- foreach ($transactions as $transaction) {- $return[] = $this->getSingleRecurrenceData($transaction);- }-- return $return;- }}diff --git a/app/Api/V1/Requests/RecurrenceUpdateRequest.php b/app/Api/V1/Requests/RecurrenceUpdateRequest.phpindex b39f9718fe..bfcccbffdc 100644--- a/app/Api/V1/Requests/RecurrenceUpdateRequest.php+++ b/app/Api/V1/Requests/RecurrenceUpdateRequest.php@@ -85,6 +85,56 @@ class RecurrenceUpdateRequest 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 $transactions */+ $transactions = $this->get('transactions');+ if (null === $transactions) {+ return [];+ }+ /** @var array $transaction */+ foreach ($transactions as $transaction) {+ $return[] = $this->getSingleRecurrenceData($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 $repetitions */+ $repetitions = $this->get('repetitions');+ if (null === $repetitions) {+ return [];+ }+ /** @var array $repetition */+ foreach ($repetitions as $repetition) {+ $return[] = [+ 'type' => $repetition['type'],+ 'moment' => $repetition['moment'],+ 'skip' => (int) $repetition['skip'],+ 'weekend' => (int) $repetition['weekend'],+ ];+ }++ return $return;+ }+/*** The rules that the incoming request must be matched against.*@@ -153,54 +203,4 @@ class RecurrenceUpdateRequest 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 $repetitions */- $repetitions = $this->get('repetitions');- if (null === $repetitions) {- return [];- }- /** @var array $repetition */- foreach ($repetitions as $repetition) {- $return[] = [- 'type' => $repetition['type'],- 'moment' => $repetition['moment'],- 'skip' => (int) $repetition['skip'],- 'weekend' => (int) $repetition['weekend'],- ];- }-- 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 $transactions */- $transactions = $this->get('transactions');- if (null === $transactions) {- return [];- }- /** @var array $transaction */- foreach ($transactions as $transaction) {- $return[] = $this->getSingleRecurrenceData($transaction);- }-- return $return;- }}diff --git a/app/Api/V1/Requests/RuleGroupRequest.php b/app/Api/V1/Requests/RuleGroupRequest.phpindex 53374a6a88..b55de2194a 100644--- a/app/Api/V1/Requests/RuleGroupRequest.php+++ b/app/Api/V1/Requests/RuleGroupRequest.php@@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest;class RuleGroupRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/RuleGroupTestRequest.php b/app/Api/V1/Requests/RuleGroupTestRequest.phpindex bc9f0edf94..25853aa49f 100644--- a/app/Api/V1/Requests/RuleGroupTestRequest.php+++ b/app/Api/V1/Requests/RuleGroupTestRequest.php@@ -26,13 +26,9 @@ namespace FireflyIII\Api\V1\Requests;use Carbon\Carbon;-use FireflyIII\Models\Account;-use FireflyIII\Models\AccountType;-use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Support\Request\ConvertsDataTypes;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Support\Collection;-use Log;/*** Class RuleGroupTestRequest@@ -65,16 +61,16 @@ class RuleGroupTestRequest extends FormRequest}/**- * @return array+ * @param string $field+ *+ * @return Carbon|null*/- public function rules(): array+ private function getDate(string $field): ?Carbon{- return [- 'start' => 'date',- 'end' => 'date|after:start',- 'accounts' => '',- 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',- ];+ /** @var Carbon $result */+ $result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));++ return $result;}/**@@ -86,16 +82,16 @@ class RuleGroupTestRequest extends FormRequest}/**- * @param string $field- *- * @return Carbon|null+ * @return array*/- private function getDate(string $field): ?Carbon+ public function rules(): array{- /** @var Carbon $result */- $result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));-- return $result;+ return [+ 'start' => 'date',+ 'end' => 'date|after:start',+ 'accounts' => '',+ 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',+ ];}}diff --git a/app/Api/V1/Requests/RuleGroupTriggerRequest.php b/app/Api/V1/Requests/RuleGroupTriggerRequest.phpindex 6c2f2b75ea..c14e353ee6 100644--- a/app/Api/V1/Requests/RuleGroupTriggerRequest.php+++ b/app/Api/V1/Requests/RuleGroupTriggerRequest.php@@ -26,13 +26,8 @@ namespace FireflyIII\Api\V1\Requests;use Carbon\Carbon;-use FireflyIII\Models\Account;-use FireflyIII\Models\AccountType;-use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Support\Request\ConvertsDataTypes;use Illuminate\Foundation\Http\FormRequest;-use Illuminate\Support\Collection;-use Log;/*** Class RuleGroupTriggerRequest@@ -65,14 +60,14 @@ class RuleGroupTriggerRequest extends FormRequest}/**- * @return array+ * @param string $field+ *+ * @return Carbon|null*/- public function rules(): array+ private function getDate(string $field): ?Carbon{- return [- 'start' => 'date',- 'end' => 'date|after:start',- ];+ /** @var Carbon $result */+ return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));}/**@@ -84,14 +79,14 @@ class RuleGroupTriggerRequest extends FormRequest}/**- * @param string $field- *- * @return Carbon|null+ * @return array*/- private function getDate(string $field): ?Carbon+ public function rules(): array{- /** @var Carbon $result */- return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));+ return [+ 'start' => 'date',+ 'end' => 'date|after:start',+ ];}}diff --git a/app/Api/V1/Requests/RuleStoreRequest.php b/app/Api/V1/Requests/RuleStoreRequest.phpindex 7a1a06c4a9..fff904c06f 100644--- a/app/Api/V1/Requests/RuleStoreRequest.php+++ b/app/Api/V1/Requests/RuleStoreRequest.php@@ -83,6 +83,48 @@ class RuleStoreRequest extends FormRequest];}+ /**+ * @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'] ?? 'false')),+ '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'] ?? 'false')),+ 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),+ ];+ }+ }++ return $return;+ }+/*** The rules that the incoming request must be matched against.*@@ -134,21 +176,6 @@ class RuleStoreRequest 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'] ?? [];- // need at least one trigger- if (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.*@@ -165,44 +192,17 @@ class RuleStoreRequest extends FormRequest}/**- * @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'] ?? 'false')),- 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),- ];- }- }-- return $return;- }-- /**- * @return array+ * 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 atLeastOneAction(Validator $validator): void{- $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'] ?? 'false')),- 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),- ];- }+ $data = $validator->getData();+ $actions = $data['actions'] ?? [];+ // need at least one trigger+ if (0 === count($actions)) {+ $validator->errors()->add('title', (string) trans('validation.at_least_one_action'));}-- return $return;}}diff --git a/app/Api/V1/Requests/RuleTestRequest.php b/app/Api/V1/Requests/RuleTestRequest.phpindex c823b35585..e2b6c9de2c 100644--- a/app/Api/V1/Requests/RuleTestRequest.php+++ b/app/Api/V1/Requests/RuleTestRequest.php@@ -62,24 +62,12 @@ class RuleTestRequest extends FormRequest}/**- * @return array+ * @return int*/- public function rules(): array+ private function getPage(): int{- return [- 'start' => 'date',- 'end' => 'date|after:start',- 'accounts' => '',- 'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',- ];- }+ return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');- /**- * @return string- */- private function getAccounts(): string- {- return (string) $this->query('accounts');}/**@@ -96,12 +84,24 @@ class RuleTestRequest extends FormRequest}/**- * @return int+ * @return string*/- private function getPage(): int+ private function getAccounts(): string{- return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');+ return (string) $this->query('accounts');+ }+ /**+ * @return array+ */+ public function rules(): array+ {+ return [+ 'start' => 'date',+ 'end' => 'date|after:start',+ 'accounts' => '',+ 'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',+ ];}}diff --git a/app/Api/V1/Requests/RuleTriggerRequest.php b/app/Api/V1/Requests/RuleTriggerRequest.phpindex 407d9de810..cbb30c53ab 100644--- a/app/Api/V1/Requests/RuleTriggerRequest.php+++ b/app/Api/V1/Requests/RuleTriggerRequest.php@@ -60,16 +60,13 @@ class RuleTriggerRequest extends FormRequest}/**- * @return array+ * @param string $field+ *+ * @return Carbon|null*/- public function rules(): array+ private function getDate(string $field): ?Carbon{- return [- 'start' => 'date',- 'end' => 'date|after:start',- 'accounts' => '',- 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',- ];+ return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));}/**@@ -81,13 +78,16 @@ class RuleTriggerRequest extends FormRequest}/**- * @param string $field- *- * @return Carbon|null+ * @return array*/- 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:start',+ 'accounts' => '',+ 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',+ ];}}diff --git a/app/Api/V1/Requests/RuleUpdateRequest.php b/app/Api/V1/Requests/RuleUpdateRequest.phpindex 4e6aeec134..b275b7d52b 100644--- a/app/Api/V1/Requests/RuleUpdateRequest.php+++ b/app/Api/V1/Requests/RuleUpdateRequest.php@@ -37,6 +37,7 @@ use function is_array;class RuleUpdateRequest extends FormRequest{use ConvertsDataTypes, GetRuleConfiguration;+/*** Authorize logged in users.*@@ -82,6 +83,54 @@ class RuleUpdateRequest extends FormRequest];}+ /**+ * @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) {+ $return[] = [+ 'type' => $trigger['type'],+ 'value' => $trigger['value'],+ 'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),+ 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),+ ];+ }+ }++ 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.*@@ -134,21 +183,6 @@ class RuleUpdateRequest 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.*@@ -165,50 +199,17 @@ class RuleUpdateRequest extends FormRequest}/**- * @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;- }-- /**- * @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 atLeastOneAction(Validator $validator): void{- if (!$this->has('triggers')) {- return null;- }- $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'] ?? 'false')),- 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),- ];- }+ $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'));}-- return $return;}}diff --git a/app/Api/V1/Requests/TagStoreRequest.php b/app/Api/V1/Requests/TagStoreRequest.phpindex c269357078..724ffa052b 100644--- a/app/Api/V1/Requests/TagStoreRequest.php+++ b/app/Api/V1/Requests/TagStoreRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class TagStoreRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/TagUpdateRequest.php b/app/Api/V1/Requests/TagUpdateRequest.phpindex 08d87d5261..4798a0dfd0 100644--- a/app/Api/V1/Requests/TagUpdateRequest.php+++ b/app/Api/V1/Requests/TagUpdateRequest.php@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;class TagUpdateRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/TransactionLinkRequest.php b/app/Api/V1/Requests/TransactionLinkRequest.phpindex 02f260e8e9..c52b9902be 100644--- a/app/Api/V1/Requests/TransactionLinkRequest.php+++ b/app/Api/V1/Requests/TransactionLinkRequest.php@@ -36,6 +36,7 @@ use Illuminate\Validation\Validator;class TransactionLinkRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/TransactionStoreRequest.php b/app/Api/V1/Requests/TransactionStoreRequest.phpindex 2ed203bc07..5f57465c5e 100644--- a/app/Api/V1/Requests/TransactionStoreRequest.php+++ b/app/Api/V1/Requests/TransactionStoreRequest.php@@ -73,6 +73,106 @@ class TransactionStoreRequest extends FormRequest];}+ /**+ * Get transaction data.+ *+ * @return array+ */+ private function getTransactionData(): array+ {+ $return = [];+ /**+ * @var int $index+ * @var array $transaction+ */+ foreach ($this->get('transactions') as $index => $transaction) {+ $object = new NullArrayObject($transaction);+ $return[] = [+ 'type' => $this->stringFromValue($object['type']),+ 'date' => $this->dateFromValue($object['date']),+ 'order' => $this->integerFromValue((string) $object['order']),++ 'currency_id' => $this->integerFromValue((string) $object['currency_id']),+ 'currency_code' => $this->stringFromValue($object['currency_code']),++ // foreign currency info:+ 'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']),+ 'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']),++ // amount and foreign amount. Cannot be 0.+ 'amount' => $this->stringFromValue((string) $object['amount']),+ 'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']),++ // description.+ 'description' => $this->stringFromValue($object['description']),++ // source of transaction. If everything is null, assume cash account.+ 'source_id' => $this->integerFromValue((string) $object['source_id']),+ 'source_name' => $this->stringFromValue((string) $object['source_name']),+ 'source_iban' => $this->stringFromValue((string) $object['source_iban']),+ 'source_number' => $this->stringFromValue((string) $object['source_number']),+ 'source_bic' => $this->stringFromValue((string) $object['source_bic']),++ // destination of transaction. If everything is null, assume cash account.+ 'destination_id' => $this->integerFromValue((string) $object['destination_id']),+ 'destination_name' => $this->stringFromValue((string) $object['destination_name']),+ 'destination_iban' => $this->stringFromValue((string) $object['destination_iban']),+ 'destination_number' => $this->stringFromValue((string) $object['destination_number']),+ 'destination_bic' => $this->stringFromValue((string) $object['destination_bic']),++ // budget info+ 'budget_id' => $this->integerFromValue((string) $object['budget_id']),+ 'budget_name' => $this->stringFromValue((string) $object['budget_name']),++ // category info+ 'category_id' => $this->integerFromValue((string) $object['category_id']),+ 'category_name' => $this->stringFromValue((string) $object['category_name']),++ // journal bill reference. Optional. Will only work for withdrawals+ 'bill_id' => $this->integerFromValue((string) $object['bill_id']),+ 'bill_name' => $this->stringFromValue((string) $object['bill_name']),++ // piggy bank reference. Optional. Will only work for transfers+ 'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']),+ 'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']),++ // some other interesting properties+ 'reconciled' => $this->convertBoolean((string) $object['reconciled']),+ 'notes' => $this->nlStringFromValue((string) $object['notes']),+ 'tags' => $this->arrayFromValue($object['tags']),++ // all custom fields:+ 'internal_reference' => $this->stringFromValue((string) $object['internal_reference']),+ 'external_id' => $this->stringFromValue((string) $object['external_id']),+ '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->stringFromValue((string) $object['bunq_payment_id']),+ 'external_uri' => $this->stringFromValue((string) $object['external_uri']),++ 'sepa_cc' => $this->stringFromValue($object['sepa_cc']),+ 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),+ 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),+ 'sepa_db' => $this->stringFromValue($object['sepa_db']),+ 'sepa_country' => $this->stringFromValue($object['sepa_country']),+ 'sepa_ep' => $this->stringFromValue($object['sepa_ep']),+ 'sepa_ci' => $this->stringFromValue($object['sepa_ci']),+ 'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),+++ // 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.*@@ -199,104 +299,4 @@ class TransactionStoreRequest extends FormRequest});}-- /**- * Get transaction data.- *- * @return array- */- private function getTransactionData(): array- {- $return = [];- /**- * @var int $index- * @var array $transaction- */- foreach ($this->get('transactions') as $index => $transaction) {- $object = new NullArrayObject($transaction);- $return[] = [- 'type' => $this->stringFromValue($object['type']),- 'date' => $this->dateFromValue($object['date']),- 'order' => $this->integerFromValue((string) $object['order']),-- 'currency_id' => $this->integerFromValue((string) $object['currency_id']),- 'currency_code' => $this->stringFromValue($object['currency_code']),-- // foreign currency info:- 'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']),- 'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']),-- // amount and foreign amount. Cannot be 0.- 'amount' => $this->stringFromValue((string) $object['amount']),- 'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']),-- // description.- 'description' => $this->stringFromValue($object['description']),-- // source of transaction. If everything is null, assume cash account.- 'source_id' => $this->integerFromValue((string) $object['source_id']),- 'source_name' => $this->stringFromValue((string) $object['source_name']),- 'source_iban' => $this->stringFromValue((string) $object['source_iban']),- 'source_number' => $this->stringFromValue((string) $object['source_number']),- 'source_bic' => $this->stringFromValue((string) $object['source_bic']),-- // destination of transaction. If everything is null, assume cash account.- 'destination_id' => $this->integerFromValue((string) $object['destination_id']),- 'destination_name' => $this->stringFromValue((string) $object['destination_name']),- 'destination_iban' => $this->stringFromValue((string) $object['destination_iban']),- 'destination_number' => $this->stringFromValue((string) $object['destination_number']),- 'destination_bic' => $this->stringFromValue((string) $object['destination_bic']),-- // budget info- 'budget_id' => $this->integerFromValue((string) $object['budget_id']),- 'budget_name' => $this->stringFromValue((string) $object['budget_name']),-- // category info- 'category_id' => $this->integerFromValue((string) $object['category_id']),- 'category_name' => $this->stringFromValue((string) $object['category_name']),-- // journal bill reference. Optional. Will only work for withdrawals- 'bill_id' => $this->integerFromValue((string) $object['bill_id']),- 'bill_name' => $this->stringFromValue((string) $object['bill_name']),-- // piggy bank reference. Optional. Will only work for transfers- 'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']),- 'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']),-- // some other interesting properties- 'reconciled' => $this->convertBoolean((string) $object['reconciled']),- 'notes' => $this->nlStringFromValue((string) $object['notes']),- 'tags' => $this->arrayFromValue($object['tags']),-- // all custom fields:- 'internal_reference' => $this->stringFromValue((string) $object['internal_reference']),- 'external_id' => $this->stringFromValue((string) $object['external_id']),- '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->stringFromValue((string) $object['bunq_payment_id']),- 'external_uri' => $this->stringFromValue((string) $object['external_uri']),-- 'sepa_cc' => $this->stringFromValue($object['sepa_cc']),- 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),- 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),- 'sepa_db' => $this->stringFromValue($object['sepa_db']),- 'sepa_country' => $this->stringFromValue($object['sepa_country']),- 'sepa_ep' => $this->stringFromValue($object['sepa_ep']),- 'sepa_ci' => $this->stringFromValue($object['sepa_ci']),- 'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),--- // 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;- }}diff --git a/app/Api/V1/Requests/TransactionUpdateRequest.php b/app/Api/V1/Requests/TransactionUpdateRequest.phpindex 1cc70a88ea..7e2e94a0cd 100644--- a/app/Api/V1/Requests/TransactionUpdateRequest.php+++ b/app/Api/V1/Requests/TransactionUpdateRequest.php@@ -146,6 +146,139 @@ class TransactionUpdateRequest extends FormRequestreturn $data;}+ /**+ * Get transaction data.+ *+ * @return array+ */+ private function getTransactionData(): array+ {+ Log::debug('Now in getTransactionData()');+ $return = [];+ /**+ * @var int $index+ * @var array $transaction+ */+ foreach ($this->get('transactions') as $transaction) {+ // default response is to update nothing in the transaction:+ $current = [];+ $current = $this->getIntegerData($current, $transaction);+ $current = $this->getStringData($current, $transaction);+ $current = $this->getNlStringData($current, $transaction);+ $current = $this->getDateData($current, $transaction);+ $current = $this->getBooleanData($current, $transaction);+ $current = $this->getArrayData($current, $transaction);+ $return[] = $current;+ }++ return $return;+ }++ /**+ * For each field, add it to the array if a reference is present in the request:+ *+ * @param array $current+ *+ * @return array+ */+ private function getIntegerData(array $current, array $transaction): array+ {+ foreach ($this->integerFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);+ }+ }++ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getStringData(array $current, array $transaction): array+ {+ foreach ($this->stringFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);+ }+ }++ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getNlStringData(array $current, array $transaction): array+ {+ foreach ($this->textareaFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);+ }+ }++ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getDateData(array $current, array $transaction): array+ {+ foreach ($this->dateFields as $fieldName) {+ Log::debug(sprintf('Now at date field %s', $fieldName));+ if (array_key_exists($fieldName, $transaction)) {+ Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));+ $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);+ }+ }++ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getBooleanData(array $current, array $transaction): array+ {+ foreach ($this->booleanFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);+ }+ }++ return $current;+ }++ /**+ * @param array $current+ * @param array $transaction+ *+ * @return array+ */+ private function getArrayData(array $current, array $transaction): array+ {+ foreach ($this->arrayFields as $fieldName) {+ if (array_key_exists($fieldName, $transaction)) {+ $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);+ }+ }++ return $current;+ }+/*** The rules that the incoming request must be matched against.*@@ -272,137 +405,4 @@ class TransactionUpdateRequest extends FormRequest});}-- /**- * @param array $current- * @param array $transaction- *- * @return array- */- private function getArrayData(array $current, array $transaction): array- {- foreach ($this->arrayFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);- }- }-- return $current;- }-- /**- * @param array $current- * @param array $transaction- *- * @return array- */- private function getBooleanData(array $current, array $transaction): array- {- foreach ($this->booleanFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);- }- }-- return $current;- }-- /**- * @param array $current- * @param array $transaction- *- * @return array- */- private function getDateData(array $current, array $transaction): array- {- foreach ($this->dateFields as $fieldName) {- Log::debug(sprintf('Now at date field %s', $fieldName));- if (array_key_exists($fieldName, $transaction)) {- Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));- $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);- }- }-- return $current;- }-- /**- * For each field, add it to the array if a reference is present in the request:- *- * @param array $current- *- * @return array- */- private function getIntegerData(array $current, array $transaction): array- {- foreach ($this->integerFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);- }- }-- return $current;- }-- /**- * @param array $current- * @param array $transaction- *- * @return array- */- private function getNlStringData(array $current, array $transaction): array- {- foreach ($this->textareaFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);- }- }-- return $current;- }-- /**- * @param array $current- * @param array $transaction- *- * @return array- */- private function getStringData(array $current, array $transaction): array- {- foreach ($this->stringFields as $fieldName) {- if (array_key_exists($fieldName, $transaction)) {- $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);- }- }-- return $current;- }-- /**- * Get transaction data.- *- * @return array- */- private function getTransactionData(): array- {- Log::debug('Now in getTransactionData()');- $return = [];- /**- * @var int $index- * @var array $transaction- */- foreach ($this->get('transactions') as $transaction) {- // default response is to update nothing in the transaction:- $current = [];- $current = $this->getIntegerData($current, $transaction);- $current = $this->getStringData($current, $transaction);- $current = $this->getNlStringData($current, $transaction);- $current = $this->getDateData($current, $transaction);- $current = $this->getBooleanData($current, $transaction);- $current = $this->getArrayData($current, $transaction);- $return[] = $current;- }-- return $return;- }}diff --git a/app/Api/V1/Requests/UserStoreRequest.php b/app/Api/V1/Requests/UserStoreRequest.phpindex cff3d97e47..c68558ce05 100644--- a/app/Api/V1/Requests/UserStoreRequest.php+++ b/app/Api/V1/Requests/UserStoreRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class UserStoreRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*diff --git a/app/Api/V1/Requests/UserUpdateRequest.php b/app/Api/V1/Requests/UserUpdateRequest.phpindex 5fee8f3e24..8e4a0d6eef 100644--- a/app/Api/V1/Requests/UserUpdateRequest.php+++ b/app/Api/V1/Requests/UserUpdateRequest.php@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;class UserUpdateRequest extends FormRequest{use ConvertsDataTypes;+/*** Authorize logged in users.*