Update forms and transformer.

This commit is contained in:
James Cole
2021-04-10 08:02:10 +02:00
parent 01234b52e3
commit d01814821f
2 changed files with 21 additions and 9 deletions

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace FireflyIII\Transformers; namespace FireflyIII\Transformers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -56,10 +57,11 @@ class AccountTransformer extends AbstractTransformer
$this->repository->setUser($account->user); $this->repository->setUser($account->user);
// get account type: // get account type:
$fullType = $account->accountType->type; $fullType = $account->accountType->type;
$accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $fullType));
$liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType));
$liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType);
$liabilityDirection = $this->repository->getMetaValue($account, 'liability_direction');
// get account role (will only work if the type is asset. // get account role (will only work if the type is asset.
$accountRole = $this->getAccountRole($account, $accountType); $accountRole = $this->getAccountRole($account, $accountType);
@@ -114,6 +116,7 @@ class AccountTransformer extends AbstractTransformer
'opening_balance' => $openingBalance, 'opening_balance' => $openingBalance,
'opening_balance_date' => $openingBalanceDate, 'opening_balance_date' => $openingBalanceDate,
'liability_type' => $liabilityType, 'liability_type' => $liabilityType,
'liability_direction' => $liabilityDirection,
'interest' => (float)$interest, 'interest' => (float)$interest,
'interest_period' => $interestPeriod, 'interest_period' => $interestPeriod,
'include_net_worth' => $includeNetWorth, 'include_net_worth' => $includeNetWorth,
@@ -195,7 +198,7 @@ class AccountTransformer extends AbstractTransformer
$creditCardType = $this->repository->getMetaValue($account, 'cc_type'); $creditCardType = $this->repository->getMetaValue($account, 'cc_type');
$monthlyPaymentDate = $this->repository->getMetaValue($account, 'cc_monthly_payment_date'); $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(); $monthlyPaymentDate = Carbon::createFromFormat('!Y-m-d', $monthlyPaymentDate, config('app.timezone'))->toAtomString();
} }
@@ -219,7 +222,7 @@ class AccountTransformer extends AbstractTransformer
$openingBalance = $amount; $openingBalance = $amount;
$openingBalanceDate = $this->repository->getOpeningBalanceDate($account); $openingBalanceDate = $this->repository->getOpeningBalanceDate($account);
} }
if(null !== $openingBalanceDate) { if (null !== $openingBalanceDate) {
$openingBalanceDate = Carbon::createFromFormat('!Y-m-d', $openingBalanceDate, config('app.timezone'))->toAtomString(); $openingBalanceDate = Carbon::createFromFormat('!Y-m-d', $openingBalanceDate, config('app.timezone'))->toAtomString();
} }

View File

@@ -238,6 +238,7 @@ export default {
axios.post(url, submission) axios.post(url, submission)
.then(response => { .then(response => {
this.errors = lodashClonedeep(this.defaultErrors);
console.log('success!'); console.log('success!');
this.returnedId = parseInt(response.data.data.id); this.returnedId = parseInt(response.data.data.id);
this.returnedTitle = response.data.data.attributes.name; this.returnedTitle = response.data.data.attributes.name;
@@ -281,6 +282,9 @@ export default {
if (errors.errors.hasOwnProperty(i)) { if (errors.errors.hasOwnProperty(i)) {
this.errors[i] = errors.errors[i]; this.errors[i] = errors.errors[i];
} }
if('liability_start_date' === i) {
this.errors.opening_balance_date = errors.errors[i];
}
} }
}, },
getSubmission: function () { getSubmission: function () {
@@ -302,13 +306,18 @@ export default {
submission.liability_type = this.liability_type.toLowerCase(); submission.liability_type = this.liability_type.toLowerCase();
submission.interest = this.interest; submission.interest = this.interest;
submission.interest_period = this.interest_period; submission.interest_period = this.interest_period;
submission.opening_balance = this.liability_amount; submission.liability_amount = this.liability_amount;
submission.opening_balance_date = this.liability_date; 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 = this.opening_balance;
submission.opening_balance_date = this.opening_balance_date; submission.opening_balance_date = this.opening_balance_date;
} }
if('' === submission.opening_balance) {
delete submission.opening_balance;
}
if ('asset' === this.type && 'ccAsset' === this.account_role) { if ('asset' === this.type && 'ccAsset' === this.account_role) {
submission.credit_card_type = 'monthlyFull'; submission.credit_card_type = 'monthlyFull';
submission.monthly_payment_date = '2021-01-01'; submission.monthly_payment_date = '2021-01-01';