Skip to content

Commit

Permalink
Adding validation to the admin payments form to prevent using recentl…
Browse files Browse the repository at this point in the history
…y crated variable symbol in another payment.

remp/crm#1121
  • Loading branch information
lubos-michalik committed Mar 24, 2020
1 parent f92cdd8 commit a59a3e0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/forms/PaymentFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ public function create($paymentId, IRow $user = null)
'description',
Html::el('a', ['href' => '/api/v1/payments/variable-symbol', 'class' => 'variable_symbol_generate'])
->setHtml($this->translator->translate('payments.form.payment.variable_symbol.generate'))
);
)->addRule(function (TextInput $control) {
$paymentRow = $this->paymentsRepository->findLastByVS($control->getValue());
if ($paymentRow) {
return $paymentRow->created_at < new DateTime('-15 minutes');
}
return true;
}, 'payments.form.payment.variable_symbol.already_used');
}

$form->addText('amount', 'payments.form.payment.amount.label')
Expand Down
1 change: 1 addition & 0 deletions src/lang/payments.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ form:
required: Musí být zadaný variabilní symbol
placeholder: například 87239102385
generate: Vygeneruj
already_used: Variabilní symbol byl nedávno použit
amount:
label: Částka
required: Musí být zadána částka
Expand Down
1 change: 1 addition & 0 deletions src/lang/payments.en_US.neon
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ form:
required: Variable symbol is required
placeholder: e.g. 87239102385
generate: Generate
already_used: Variable symbol has been used recently
amount:
label: Amount
required: Amount is required
Expand Down
1 change: 1 addition & 0 deletions src/lang/payments.sk_SK.neon
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ form:
required: Musí byť zadaný variabilný symbol
placeholder: napríklad 87239102385
generate: Vygeneruj
already_used: Variabilný symbol bol nedávno použitý
amount:
label: Suma
required: Musí byť zadaná suma
Expand Down

0 comments on commit a59a3e0

Please sign in to comment.