mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Can now create auto budget over API
This commit is contained in:
@@ -50,7 +50,7 @@ class BudgetFormStoreRequest extends Request
|
||||
return [
|
||||
'name' => $this->string('name'),
|
||||
'active' => $this->boolean('active'),
|
||||
'auto_budget_option' => $this->integer('auto_budget_option'),
|
||||
'auto_budget_type' => $this->integer('auto_budget_type'),
|
||||
'transaction_currency_id' => $this->integer('transaction_currency_id'),
|
||||
'auto_budget_amount' => $this->string('auto_budget_amount'),
|
||||
'auto_budget_period' => $this->string('auto_budget_period'),
|
||||
|
@@ -387,17 +387,27 @@ class Request extends FormRequest
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function validateAutoBudgetAmount(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$option = (int)$data['auto_budget_option'];
|
||||
$amount = $data['auto_budget_amount'] ?? '';
|
||||
switch ($option) {
|
||||
$data = $validator->getData();
|
||||
$type = $data['auto_budget_type'] ?? '';
|
||||
$amount = $data['auto_budget_amount'] ?? '';
|
||||
$period = (string)($data['auto_budget_period'] ?? '');
|
||||
$currencyId = $data['auto_budget_currency_id'] ?? '';
|
||||
$currencyCode = $data['auto_budget_currency_code'] ?? '';
|
||||
if (is_numeric($type)) {
|
||||
$type = (int)$type;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case AutoBudget::AUTO_BUDGET_RESET:
|
||||
case AutoBudget::AUTO_BUDGET_ROLLOVER:
|
||||
case 'reset':
|
||||
case 'rollover':
|
||||
// basic float check:
|
||||
if ('' === $amount) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
@@ -405,8 +415,16 @@ class Request extends FormRequest
|
||||
if (1 !== bccomp((string)$amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
||||
}
|
||||
if ('' === $period) {
|
||||
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if('' === $currencyCode && '' === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user