From d01814821fdcf641bb7b3a7fc630c431046e739c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 10 Apr 2021 08:02:10 +0200 Subject: [PATCH] Update forms and transformer. --- app/Transformers/AccountTransformer.php | 15 +++++++++------ frontend/src/components/accounts/Create.vue | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 97cccf7953..49e5aa6623 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Transformers; + use Carbon\Carbon; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; @@ -56,10 +57,11 @@ class AccountTransformer extends AbstractTransformer $this->repository->setUser($account->user); // get account type: - $fullType = $account->accountType->type; - $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); - $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); - $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); + $fullType = $account->accountType->type; + $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); + $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); + $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); + $liabilityDirection = $this->repository->getMetaValue($account, 'liability_direction'); // get account role (will only work if the type is asset. $accountRole = $this->getAccountRole($account, $accountType); @@ -114,6 +116,7 @@ class AccountTransformer extends AbstractTransformer 'opening_balance' => $openingBalance, 'opening_balance_date' => $openingBalanceDate, 'liability_type' => $liabilityType, + 'liability_direction' => $liabilityDirection, 'interest' => (float)$interest, 'interest_period' => $interestPeriod, 'include_net_worth' => $includeNetWorth, @@ -195,7 +198,7 @@ class AccountTransformer extends AbstractTransformer $creditCardType = $this->repository->getMetaValue($account, 'cc_type'); $monthlyPaymentDate = $this->repository->getMetaValue($account, 'cc_monthly_payment_date'); } - if(null !== $monthlyPaymentDate) { + if (null !== $monthlyPaymentDate) { $monthlyPaymentDate = Carbon::createFromFormat('!Y-m-d', $monthlyPaymentDate, config('app.timezone'))->toAtomString(); } @@ -219,7 +222,7 @@ class AccountTransformer extends AbstractTransformer $openingBalance = $amount; $openingBalanceDate = $this->repository->getOpeningBalanceDate($account); } - if(null !== $openingBalanceDate) { + if (null !== $openingBalanceDate) { $openingBalanceDate = Carbon::createFromFormat('!Y-m-d', $openingBalanceDate, config('app.timezone'))->toAtomString(); } diff --git a/frontend/src/components/accounts/Create.vue b/frontend/src/components/accounts/Create.vue index afcee2ff95..fa4b72a411 100644 --- a/frontend/src/components/accounts/Create.vue +++ b/frontend/src/components/accounts/Create.vue @@ -238,6 +238,7 @@ export default { axios.post(url, submission) .then(response => { + this.errors = lodashClonedeep(this.defaultErrors); console.log('success!'); this.returnedId = parseInt(response.data.data.id); this.returnedTitle = response.data.data.attributes.name; @@ -281,6 +282,9 @@ export default { if (errors.errors.hasOwnProperty(i)) { this.errors[i] = errors.errors[i]; } + if('liability_start_date' === i) { + this.errors.opening_balance_date = errors.errors[i]; + } } }, getSubmission: function () { @@ -302,13 +306,18 @@ export default { submission.liability_type = this.liability_type.toLowerCase(); submission.interest = this.interest; submission.interest_period = this.interest_period; - submission.opening_balance = this.liability_amount; - submission.opening_balance_date = this.liability_date; + submission.liability_amount = this.liability_amount; + submission.liability_start_date = this.liability_date; + submission.liability_direction = this.liability_direction; } - if (null !== this.opening_balance && null !== this.opening_balance_date && 'asset' === this.type) { + if ((null !== this.opening_balance || null !== this.opening_balance_date) && 'asset' === this.type) { submission.opening_balance = this.opening_balance; submission.opening_balance_date = this.opening_balance_date; } + if('' === submission.opening_balance) { + delete submission.opening_balance; + } + if ('asset' === this.type && 'ccAsset' === this.account_role) { submission.credit_card_type = 'monthlyFull'; submission.monthly_payment_date = '2021-01-01';