mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-23 09:26:29 -06:00
Change rules for account requests
This commit is contained in:
parent
e07377af86
commit
f5af0350a4
@ -77,11 +77,11 @@ class StoreRequest extends FormRequest
|
||||
'interest' => $this->string('interest'),
|
||||
'interest_period' => $this->string('interest_period'),
|
||||
];
|
||||
// append Location information.
|
||||
// append location information.
|
||||
$data = $this->appendLocationData($data, null);
|
||||
|
||||
if ('liability' === $data['account_type_name'] || 'liabilities' === $data['account_type_name']) {
|
||||
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
|
||||
$data['opening_balance'] = app('steam')->negative($this->string('liability_amount'));
|
||||
$data['opening_balance_date'] = $this->date('liability_start_date');
|
||||
$data['account_type_name'] = $this->string('liability_type');
|
||||
$data['liability_direction'] = $this->string('liability_direction');
|
||||
@ -120,11 +120,11 @@ class StoreRequest extends FormRequest
|
||||
'credit_card_type' => sprintf('in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),
|
||||
'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',
|
||||
'liability_type' => 'required_if:type,liability|required_if:type,liabilities|in:loan,debt,mortgage',
|
||||
'liability_amount' => 'required_if:type,liability|required_if:type,liabilities|min:0|numeric',
|
||||
'liability_amount' => 'required_with:liability_start_date|min:0|numeric',
|
||||
'liability_start_date' => 'required_with:liability_amount|date',
|
||||
'liability_direction' => 'required_if:type,liability|required_if:type,liabilities|in:credit,debit',
|
||||
'liability_start_date' => 'required_if:type,liability|required_if:type,liabilities|date',
|
||||
'interest' => 'required_if:type,liability|required_if:type,liabilities|between:0,100|numeric',
|
||||
'interest_period' => 'required_if:type,liability|required_if:type,liabilities|in:daily,monthly,yearly',
|
||||
'interest' => 'between:0,100|numeric',
|
||||
'interest_period' => sprintf('in:%s', join(',', config('firefly.interest_periods'))),
|
||||
'notes' => 'min:0|max:65536',
|
||||
];
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\Account;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Rules\UniqueAccountNumber;
|
||||
@ -32,6 +33,7 @@ use FireflyIII\Support\Request\AppendsLocationData;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class UpdateRequest
|
||||
@ -68,16 +70,23 @@ class UpdateRequest extends FormRequest
|
||||
'order' => ['order', 'integer'],
|
||||
'currency_id' => ['currency_id', 'integer'],
|
||||
'currency_code' => ['currency_code', 'string'],
|
||||
'liability_direction' => ['liability_direction', 'string']
|
||||
'liability_direction' => ['liability_direction', 'string'],
|
||||
'liability_amount' => ['liability_amount', 'string'],
|
||||
'liability_start_date' => ['liability_start_date', 'date'],
|
||||
];
|
||||
/** @var Account $account */
|
||||
$account = $this->route()->parameter('account');
|
||||
$data = $this->getAllData($fields);
|
||||
$data = $this->appendLocationData($data, null);
|
||||
$valid = config('firefly.valid_liabilities');
|
||||
if (array_key_exists('liability_amount', $data) && in_array($account->accountType->type, $valid, true)) {
|
||||
$data['opening_balance'] = app('steam')->negative($data['liability_amount']);
|
||||
Log::debug(sprintf('Opening balance for liability is "%s".', $data['opening_balance']));
|
||||
}
|
||||
|
||||
if (array_key_exists('account_type_name', $data) && 'liability' === $data['account_type_name']) {
|
||||
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
|
||||
$data['opening_balance_date'] = $this->date('liability_start_date');
|
||||
$data['account_type_name'] = $this->string('liability_type');
|
||||
$data['account_type_id'] = null;
|
||||
if (array_key_exists('liability_start_date', $data) && in_array($account->accountType->type, $valid, true)) {
|
||||
$data['opening_balance_date'] = $data['liability_start_date'];
|
||||
Log::debug(sprintf('Opening balance date for liability is "%s".', $data['opening_balance_date']));
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
Loading…
Reference in New Issue
Block a user