mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -46,7 +46,7 @@ trait DepositValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a deposit can't be created.
|
||||
$this->destError = (string)trans('validation.deposit_dest_need_data');
|
||||
$this->destError = (string) trans('validation.deposit_dest_need_data');
|
||||
app('log')->error('Both values are NULL, cant create deposit destination.');
|
||||
$result = false;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ trait DepositValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
app('log')->debug('findExistingAccount() returned NULL, so the result is false.');
|
||||
$this->destError = (string)trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string) trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$result = false;
|
||||
}
|
||||
if (null !== $search) {
|
||||
@@ -107,7 +107,7 @@ trait DepositValidation
|
||||
// if both values are NULL return false,
|
||||
// because the source of a deposit can't be created.
|
||||
// (this never happens).
|
||||
$this->sourceError = (string)trans('validation.deposit_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.deposit_source_need_data');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ trait DepositValidation
|
||||
app('log')->debug('Check if there is not already another account with this IBAN');
|
||||
$existing = $this->findExistingAccount($validTypes, ['iban' => $accountIban], true);
|
||||
if (null !== $existing) {
|
||||
$this->sourceError = (string)trans('validation.deposit_src_iban_exists');
|
||||
$this->sourceError = (string) trans('validation.deposit_src_iban_exists');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ trait OBValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a deposit can't be created.
|
||||
$this->destError = (string)trans('validation.ob_dest_need_data');
|
||||
$this->destError = (string) trans('validation.ob_dest_need_data');
|
||||
app('log')->error('Both values are NULL, cant create OB destination.');
|
||||
$result = false;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ trait OBValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
app('log')->debug('findExistingAccount() returned NULL, so the result is false.', $validTypes);
|
||||
$this->destError = (string)trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string) trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$result = false;
|
||||
}
|
||||
if (null !== $search) {
|
||||
@@ -92,7 +92,7 @@ trait OBValidation
|
||||
// if both values are NULL return false,
|
||||
// because the source of a deposit can't be created.
|
||||
// (this never happens).
|
||||
$this->sourceError = (string)trans('validation.ob_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.ob_source_need_data');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ trait ReconciliationValidation
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
@@ -88,7 +88,7 @@ trait ReconciliationValidation
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -42,7 +42,7 @@ trait TransferValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a transfer can't be created.
|
||||
$this->destError = (string)trans('validation.transfer_dest_need_data');
|
||||
$this->destError = (string) trans('validation.transfer_dest_need_data');
|
||||
app('log')->error('Both values are NULL, cant create transfer destination.');
|
||||
|
||||
return false;
|
||||
@@ -51,7 +51,7 @@ trait TransferValidation
|
||||
// or try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->destError = (string)trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string) trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ trait TransferValidation
|
||||
&& false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the source of a withdrawal can't be created.
|
||||
$this->sourceError = (string)trans('validation.transfer_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.transfer_source_need_data');
|
||||
app('log')->warning('Not a valid source, need more data.');
|
||||
|
||||
return false;
|
||||
@@ -95,7 +95,7 @@ trait TransferValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string)trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string) trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source, cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -43,7 +43,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return TRUE
|
||||
// because we assume the user doesn't want to submit / change anything.
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_need_data');
|
||||
app('log')->warning('[a] Not a valid source. Need more data.');
|
||||
|
||||
return false;
|
||||
@@ -52,7 +52,7 @@ trait WithdrawalValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
@@ -80,7 +80,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && null === $accountNumber && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL return false,
|
||||
// because the destination of a withdrawal can never be created automatically.
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_need_data');
|
||||
$this->destError = (string) trans('validation.withdrawal_dest_need_data');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ trait WithdrawalValidation
|
||||
return true;
|
||||
}
|
||||
// todo explain error in log message.
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string) trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ trait WithdrawalValidation
|
||||
// the inverse flag reverses the search, searching for everything that is NOT a valid type.
|
||||
$existing = $this->findExistingAccount($validTypes, ['iban' => $accountIban], true);
|
||||
if (null !== $existing) {
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_iban_exists');
|
||||
$this->destError = (string) trans('validation.withdrawal_dest_iban_exists');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && null === $accountNumber && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the source of a withdrawal can't be created.
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_need_data');
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_need_data');
|
||||
app('log')->warning('[b] Not a valid source. Need more data.');
|
||||
|
||||
return false;
|
||||
@@ -140,7 +140,7 @@ trait WithdrawalValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -277,7 +277,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by iban
|
||||
if (null !== $accountIban && '' !== (string)$accountIban) {
|
||||
if (null !== $accountIban && '' !== (string) $accountIban) {
|
||||
$first = $this->getRepository()->findByIbanNull($accountIban, $validTypes);
|
||||
$accountType = null === $first ? 'invalid' : $first->accountType->type;
|
||||
$check = in_array($accountType, $validTypes, true);
|
||||
@@ -290,7 +290,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by number
|
||||
if (null !== $accountNumber && '' !== (string)$accountNumber) {
|
||||
if (null !== $accountNumber && '' !== (string) $accountNumber) {
|
||||
$first = $this->getRepository()->findByAccountNumber($accountNumber, $validTypes);
|
||||
$accountType = null === $first ? 'invalid' : $first->accountType->type;
|
||||
$check = in_array($accountType, $validTypes, true);
|
||||
@@ -303,7 +303,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by name:
|
||||
if ('' !== (string)$accountName) {
|
||||
if ('' !== (string) $accountName) {
|
||||
$first = $this->getRepository()->findByName($accountName, $validTypes);
|
||||
if (null !== $first) {
|
||||
app('log')->debug(sprintf('Name: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban'));
|
||||
|
@@ -41,20 +41,20 @@ trait ValidatesBulkTransactionQuery
|
||||
// find both accounts, must be same type.
|
||||
// already validated: belongs to this user.
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$source = $repository->find((int)$json['where']['account_id']);
|
||||
$dest = $repository->find((int)$json['update']['account_id']);
|
||||
$source = $repository->find((int) $json['where']['account_id']);
|
||||
$dest = $repository->find((int) $json['update']['account_id']);
|
||||
if (null === $source) {
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'where', 'account_id'));
|
||||
$validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'where', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (null === $dest) {
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'update', 'account_id'));
|
||||
$validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'update', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
if ($source->accountType->type !== $dest->accountType->type) {
|
||||
$validator->errors()->add('query', (string)trans('validation.invalid_query_account_type'));
|
||||
$validator->errors()->add('query', (string) trans('validation.invalid_query_account_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ trait ValidatesBulkTransactionQuery
|
||||
&& null !== $destCurrency
|
||||
&& $sourceCurrency->id !== $destCurrency->id
|
||||
) {
|
||||
$validator->errors()->add('query', (string)trans('validation.invalid_query_currency'));
|
||||
$validator->errors()->add('query', (string) trans('validation.invalid_query_currency'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,38 +42,38 @@ trait ValidatesAutoBudgetRequest
|
||||
/** @var null|float|int|string $amount */
|
||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
||||
$period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int)$data['auto_budget_currency_id'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null;
|
||||
$currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null;
|
||||
if (is_numeric($type)) {
|
||||
$type = (int)$type;
|
||||
$type = (int) $type;
|
||||
}
|
||||
if ('' === $type || 0 === $type) {
|
||||
return;
|
||||
}
|
||||
// TODO lots of duplicates with number validator.
|
||||
// TODO should be present at more places, stop scientific notification
|
||||
if (str_contains(strtoupper((string)$amount), 'E')) {
|
||||
if (str_contains(strtoupper((string) $amount), 'E')) {
|
||||
$amount = '';
|
||||
}
|
||||
// basic float check:
|
||||
if (!is_numeric($amount)) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (1 !== bccomp((string)$amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
||||
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'));
|
||||
$validator->errors()->add('auto_budget_period', (string) trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if (null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.require_currency_info'));
|
||||
}
|
||||
// too big amount
|
||||
if ((int)$amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
if ((int) $amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ trait CurrencyValidation
|
||||
|
||||
continue;
|
||||
}
|
||||
$foreignAmount = (string)($transaction['foreign_amount'] ?? '');
|
||||
$foreignAmount = (string) ($transaction['foreign_amount'] ?? '');
|
||||
$foreignId = $transaction['foreign_currency_id'] ?? null;
|
||||
$foreignCode = $transaction['foreign_currency_code'] ?? null;
|
||||
if ('' === $foreignAmount) {
|
||||
@@ -66,9 +66,9 @@ trait CurrencyValidation
|
||||
(array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
|
||||
&& (null !== $foreignId || null !== $foreignCode)
|
||||
) {
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_id', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_code', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string) trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_id', (string) trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_code', (string) trans('validation.require_currency_amount'));
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -79,14 +79,14 @@ trait CurrencyValidation
|
||||
Log::debug('validateForeignCurrencyInformation: array contains foreign amount info.');
|
||||
if (!array_key_exists('foreign_currency_id', $transaction) && !array_key_exists('foreign_currency_code', $transaction)) {
|
||||
Log::debug('validateForeignCurrencyInformation: array contains NO foreign currency info.');
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string)trans('validation.require_currency_info'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string) trans('validation.require_currency_info'));
|
||||
}
|
||||
}
|
||||
if (0 === $compare && ('' !== (string)$foreignId || '' !== (string)$foreignCode)) {
|
||||
if (0 === $compare && ('' !== (string) $foreignId || '' !== (string) $foreignCode)) {
|
||||
Log::debug('validateForeignCurrencyInformation: array contains foreign currency info, but zero amount.');
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_id', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_code', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string)trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_id', (string) trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_currency_code', (string) trans('validation.require_currency_amount'));
|
||||
$validator->errors()->add('transactions.'.$index.'.foreign_amount', (string) trans('validation.require_currency_amount'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -79,22 +79,6 @@ class FireflyValidator extends Validator
|
||||
return (bool) \Google2FA::verifyKey((string) $secret, $value);
|
||||
}
|
||||
|
||||
public function validateExistingMfaCode($attribute, $value): bool
|
||||
{
|
||||
if (!is_string($value) || 6 !== strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
$user = auth()->user();
|
||||
if (null === $user) {
|
||||
app('log')->error('No user during validate2faCode');
|
||||
|
||||
return false;
|
||||
}
|
||||
$secret = (string)$user->mfa_secret;
|
||||
|
||||
return (bool) \Google2FA::verifyKey($secret, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
@@ -131,6 +115,22 @@ class FireflyValidator extends Validator
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validateExistingMfaCode($attribute, $value): bool
|
||||
{
|
||||
if (!is_string($value) || 6 !== strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
$user = auth()->user();
|
||||
if (null === $user) {
|
||||
app('log')->error('No user during validate2faCode');
|
||||
|
||||
return false;
|
||||
}
|
||||
$secret = (string) $user->mfa_secret;
|
||||
|
||||
return (bool) \Google2FA::verifyKey($secret, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
|
@@ -66,7 +66,7 @@ trait GroupValidation
|
||||
$hasAccountInfo = false;
|
||||
$hasJournalId = array_key_exists('transaction_journal_id', $transaction);
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $transaction) && '' !== (string)$transaction[$key]) {
|
||||
if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) {
|
||||
$hasAccountInfo = true;
|
||||
}
|
||||
}
|
||||
@@ -74,11 +74,11 @@ trait GroupValidation
|
||||
if (false === $hasAccountInfo && !$hasJournalId) {
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.source_id', $index),
|
||||
(string)trans('validation.generic_no_source')
|
||||
(string) trans('validation.generic_no_source')
|
||||
);
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.destination_id', $index),
|
||||
(string)trans('validation.generic_no_destination')
|
||||
(string) trans('validation.generic_no_destination')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ trait GroupValidation
|
||||
if (array_key_exists($key, $row)) {
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.%s', $index, $key),
|
||||
(string)trans('validation.reconciled_forbidden_field', ['field' => $key])
|
||||
(string) trans('validation.reconciled_forbidden_field', ['field' => $key])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ trait GroupValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$validDescriptions = 0;
|
||||
foreach ($transactions as $transaction) {
|
||||
if ('' !== (string)($transaction['description'] ?? null)) {
|
||||
if ('' !== (string) ($transaction['description'] ?? null)) {
|
||||
++$validDescriptions;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ trait GroupValidation
|
||||
if (0 === $validDescriptions) {
|
||||
$validator->errors()->add(
|
||||
'transactions.0.description',
|
||||
(string)trans('validation.filled', ['attribute' => (string)trans('validation.attributes.description')])
|
||||
(string) trans('validation.filled', ['attribute' => (string) trans('validation.attributes.description')])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ trait GroupValidation
|
||||
|
||||
$groupTitle = $data['group_title'] ?? '';
|
||||
if ('' === $groupTitle && count($transactions) > 1) {
|
||||
$validator->errors()->add('group_title', (string)trans('validation.group_title_mandatory'));
|
||||
$validator->errors()->add('group_title', (string) trans('validation.group_title_mandatory'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,12 +210,12 @@ trait GroupValidation
|
||||
|
||||
return;
|
||||
}
|
||||
$journalId = (int)$journalId;
|
||||
$journalId = (int) $journalId;
|
||||
$count = $transactionGroup->transactionJournals()->where('transaction_journals.id', $journalId)->count();
|
||||
if (0 === $journalId || 0 === $count) {
|
||||
app('log')->warning(sprintf('Transaction group #%d has %d journals with ID %d', $transactionGroup->id, $count, $journalId));
|
||||
app('log')->warning('Invalid submission: Each split must have transaction_journal_id (either valid ID or 0).');
|
||||
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string)trans('validation.need_id_in_edit'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string) trans('validation.need_id_in_edit'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -89,7 +89,7 @@ trait RecurrenceValidation
|
||||
continue;
|
||||
}
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
||||
|
||||
@@ -101,7 +101,7 @@ trait RecurrenceValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$validDestination = $accountValidator->validateDestination(['id' => $destinationId, 'name' => $destinationName]);
|
||||
// do something with result:
|
||||
@@ -123,7 +123,7 @@ trait RecurrenceValidation
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (!is_countable($repetitions) || 0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ trait RecurrenceValidation
|
||||
}
|
||||
// need at least one transaction
|
||||
if (0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,15 +154,15 @@ trait RecurrenceValidation
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('repeat_until', (string) trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string) trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateRecurringConfig(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int)$data['nr_of_repetitions'] : null;
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int) $data['nr_of_repetitions'] : null;
|
||||
$repeatUntil = array_key_exists('repeat_until', $data) ? new Carbon($data['repeat_until']) : null;
|
||||
|
||||
if (null === $reps && null === $repeatUntil) {
|
||||
@@ -182,7 +182,7 @@ trait RecurrenceValidation
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
if (!is_array($repetitions)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -201,32 +201,32 @@ trait RecurrenceValidation
|
||||
|
||||
switch ($repetition['type'] ?? 'empty') {
|
||||
default:
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
|
||||
case 'daily':
|
||||
$this->validateDaily($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateDaily($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
$this->validateMonthly($validator, $index, (int)$repetition['moment']);
|
||||
$this->validateMonthly($validator, $index, (int) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'ndom':
|
||||
$this->validateNdom($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateNdom($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
$this->validateWeekly($validator, $index, (int)$repetition['moment']);
|
||||
$this->validateWeekly($validator, $index, (int) $repetition['moment']);
|
||||
|
||||
break;
|
||||
|
||||
case 'yearly':
|
||||
$this->validateYearly($validator, $index, (string)$repetition['moment']);
|
||||
$this->validateYearly($validator, $index, (string) $repetition['moment']);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ trait RecurrenceValidation
|
||||
protected function validateDaily(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
if ('' !== $moment) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ trait RecurrenceValidation
|
||||
protected function validateMonthly(Validator $validator, int $index, int $dayOfMonth): void
|
||||
{
|
||||
if ($dayOfMonth < 1 || $dayOfMonth > 31) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,19 +261,19 @@ trait RecurrenceValidation
|
||||
{
|
||||
$parameters = explode(',', $moment);
|
||||
if (2 !== count($parameters)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
$nthDay = (int)($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int)($parameters[1] ?? 0.0);
|
||||
$nthDay = (int) ($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int) ($parameters[1] ?? 0.0);
|
||||
if ($nthDay < 1 || $nthDay > 5) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ trait RecurrenceValidation
|
||||
protected function validateWeekly(Validator $validator, int $index, int $dayOfWeek): void
|
||||
{
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ trait RecurrenceValidation
|
||||
Carbon::createFromFormat('Y-m-d', $moment);
|
||||
} catch (\InvalidArgumentException $e) { // @phpstan-ignore-line
|
||||
app('log')->debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ trait RecurrenceValidation
|
||||
|
||||
if (0 === $submittedTrCount) {
|
||||
app('log')->warning('[b] User submitted no transactions.');
|
||||
$validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -324,16 +324,16 @@ trait RecurrenceValidation
|
||||
return; // home safe!
|
||||
}
|
||||
$id = $first['id'];
|
||||
if ('' === (string)$id) {
|
||||
if ('' === (string) $id) {
|
||||
app('log')->debug('Single count and empty ID, done.');
|
||||
|
||||
return; // home safe!
|
||||
}
|
||||
$integer = (int)$id;
|
||||
$integer = (int) $id;
|
||||
$secondCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', $integer)->count();
|
||||
app('log')->debug(sprintf('Result of ID count: %d', $secondCount));
|
||||
if (0 === $secondCount) {
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.id_does_not_match', ['id' => $integer]));
|
||||
$validator->errors()->add('transactions.0.id', (string) trans('validation.id_does_not_match', ['id' => $integer]));
|
||||
}
|
||||
app('log')->debug('Single ID validation done.');
|
||||
|
||||
@@ -364,19 +364,19 @@ trait RecurrenceValidation
|
||||
app('log')->debug(sprintf('Now at %d/%d', $index + 1, $submittedTrCount));
|
||||
if (!is_array($transaction)) {
|
||||
app('log')->warning('Not an array. Give error.');
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.at_least_one_transaction'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (!array_key_exists('id', $transaction) && $idsMandatory) {
|
||||
app('log')->warning('ID is mandatory but array has no ID.');
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.need_id_to_match'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string) trans('validation.need_id_to_match'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('id', $transaction)) { // don't matter if $idsMandatory
|
||||
app('log')->debug('Array has ID.');
|
||||
$idCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', (int)$transaction['id'])->count();
|
||||
$idCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', (int) $transaction['id'])->count();
|
||||
if (0 === $idCount) {
|
||||
app('log')->debug('ID does not exist or no match. Count another unmatched ID.');
|
||||
++$unmatchedIds;
|
||||
@@ -392,7 +392,7 @@ trait RecurrenceValidation
|
||||
app('log')->debug(sprintf('Submitted: %d. Original: %d. User can submit %d unmatched transactions.', $submittedTrCount, $originalTrCount, $maxUnmatched));
|
||||
if ($unmatchedIds > $maxUnmatched) {
|
||||
app('log')->warning(sprintf('Too many unmatched transactions (%d).', $unmatchedIds));
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.too_many_unmatched'));
|
||||
$validator->errors()->add('transactions.0.id', (string) trans('validation.too_many_unmatched'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -109,10 +109,10 @@ trait TransactionValidation
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string)$transaction['source_number'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string) $transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string) $transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string) $transaction['source_number'] : null;
|
||||
$source = [
|
||||
'id' => $sourceId,
|
||||
'name' => $sourceName,
|
||||
@@ -129,10 +129,10 @@ trait TransactionValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string)$transaction['destination_number'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string) $transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string) $transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string) $transaction['destination_number'] : null;
|
||||
$destination = [
|
||||
'id' => $destinationId,
|
||||
'name' => $destinationName,
|
||||
@@ -244,17 +244,17 @@ trait TransactionValidation
|
||||
|
||||
// no foreign currency information is present:
|
||||
if (!$this->hasForeignCurrencyInfo($transaction)) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_currency'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// wrong currency information is present
|
||||
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
|
||||
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
|
||||
$foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0);
|
||||
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
|
||||
if ($foreignCurrencyCode !== $sourceCurrency->code && $foreignCurrencyId !== $sourceCurrency->id) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string)trans('validation.require_foreign_src'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string) trans('validation.require_foreign_src'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -271,19 +271,19 @@ trait TransactionValidation
|
||||
|
||||
// no foreign currency information is present:
|
||||
if (!$this->hasForeignCurrencyInfo($transaction)) {
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_currency'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_currency'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// wrong currency information is present
|
||||
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
|
||||
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
|
||||
$foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0);
|
||||
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
|
||||
if ($foreignCurrencyCode !== $destinationCurrency->code && $foreignCurrencyId !== $destinationCurrency->id) {
|
||||
app('log')->debug(sprintf('No match on code, "%s" vs "%s"', $foreignCurrencyCode, $destinationCurrency->code));
|
||||
app('log')->debug(sprintf('No match on ID, #%d vs #%d', $foreignCurrencyId, $destinationCurrency->id));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_dest'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string) trans('validation.require_foreign_dest'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ trait TransactionValidation
|
||||
if ('' === $transaction['foreign_amount']) {
|
||||
return false;
|
||||
}
|
||||
if (0 === bccomp('0', (string)$transaction['foreign_amount'])) {
|
||||
if (0 === bccomp('0', (string) $transaction['foreign_amount'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ trait TransactionValidation
|
||||
|| array_key_exists('source_number', $transaction)
|
||||
) {
|
||||
app('log')->debug('Will try to validate source account information.');
|
||||
$sourceId = (int)($transaction['source_id'] ?? 0);
|
||||
$sourceId = (int) ($transaction['source_id'] ?? 0);
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$sourceIban = $transaction['source_iban'] ?? null;
|
||||
$sourceNumber = $transaction['source_number'] ?? null;
|
||||
@@ -425,7 +425,7 @@ trait TransactionValidation
|
||||
$accountValidator->source = $source;
|
||||
}
|
||||
}
|
||||
$destinationId = (int)($transaction['destination_id'] ?? 0);
|
||||
$destinationId = (int) ($transaction['destination_id'] ?? 0);
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$destinationIban = $transaction['destination_iban'] ?? null;
|
||||
$destinationNumber = $transaction['destination_number'] ?? null;
|
||||
@@ -444,7 +444,7 @@ trait TransactionValidation
|
||||
|
||||
private function getTransactionType(TransactionGroup $group, array $transactions): string
|
||||
{
|
||||
return $transactions[0]['type'] ?? strtolower((string)$group->transactionJournals()->first()?->transactionType->type);
|
||||
return $transactions[0]['type'] ?? strtolower((string) $group->transactionJournals()->first()?->transactionType->type);
|
||||
}
|
||||
|
||||
private function getOriginalSource(array $transaction, TransactionGroup $transactionGroup): ?Account
|
||||
@@ -457,7 +457,7 @@ trait TransactionValidation
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
||||
$journalId = (int) ($transaction['transaction_journal_id'] ?? 0);
|
||||
if ($journal->id === $journalId) {
|
||||
return $journal->transactions()->where('amount', '<', 0)->first()?->account;
|
||||
}
|
||||
@@ -476,7 +476,7 @@ trait TransactionValidation
|
||||
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
app('log')->debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -510,7 +510,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
foreach (array_keys($transactions) as $key) {
|
||||
if (!is_int($key)) {
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
app('log')->debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -535,13 +535,13 @@ trait TransactionValidation
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
$first = $unique[0] ?? 'invalid';
|
||||
if ('invalid' === $first) {
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.invalid_transaction_type'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.invalid_transaction_type'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,14 +554,14 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$types = [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$originalType = $this->getOriginalType((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalType = $this->getOriginalType((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
// if type is not set, fall back to the type of the journal, if one is given.
|
||||
$types[] = $transaction['type'] ?? $originalType;
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
app('log')->warning('Add error for mismatch transaction types.');
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -609,22 +609,22 @@ trait TransactionValidation
|
||||
default:
|
||||
case 'withdrawal':
|
||||
if (count($sources) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'deposit':
|
||||
if (count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'transfer':
|
||||
if (count($sources) > 1 || count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -658,14 +658,14 @@ trait TransactionValidation
|
||||
$result = $this->compareAccountData($type, $comparison);
|
||||
if (false === $result) {
|
||||
if ('withdrawal' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('deposit' === $type) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('transfer' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
}
|
||||
app('log')->warning('Add error about equal accounts.');
|
||||
|
||||
@@ -684,7 +684,7 @@ trait TransactionValidation
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// source or destination may be omitted. If this is the case, use the original source / destination name + ID.
|
||||
$originalData = $this->getOriginalData((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalData = $this->getOriginalData((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
|
||||
// get field.
|
||||
$comparison[$field][] = $transaction[$field] ?? $originalData[$field];
|
||||
|
Reference in New Issue
Block a user