mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -162,17 +162,17 @@ trait TransactionValidation
|
||||
app('log')->debug('Now in validateTransactionTypes()');
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
|
||||
$types = [];
|
||||
$types = [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$types[] = $transaction['type'] ?? 'invalid';
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
$first = $unique[0] ?? 'invalid';
|
||||
$first = $unique[0] ?? 'invalid';
|
||||
if ('invalid' === $first) {
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.invalid_transaction_type'));
|
||||
}
|
||||
@@ -189,9 +189,9 @@ trait TransactionValidation
|
||||
foreach ($transactions as $transaction) {
|
||||
$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;
|
||||
$types[] = $transaction['type'] ?? $originalType;
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
$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'));
|
||||
@@ -225,7 +225,7 @@ trait TransactionValidation
|
||||
app('log')->debug(sprintf('Now in validateSingleAccount(%d)', $index));
|
||||
|
||||
/** @var AccountValidator $accountValidator */
|
||||
$accountValidator = app(AccountValidator::class);
|
||||
$accountValidator = app(AccountValidator::class);
|
||||
|
||||
if (array_key_exists('user', $transaction) && null !== $transaction['user']) {
|
||||
$accountValidator->setUser($transaction['user']);
|
||||
@@ -234,21 +234,21 @@ trait TransactionValidation
|
||||
$accountValidator->setUserGroup($transaction['user_group']);
|
||||
}
|
||||
|
||||
$transactionType = $transaction['type'] ?? $transactionType;
|
||||
$transactionType = $transaction['type'] ?? $transactionType;
|
||||
$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;
|
||||
$source = [
|
||||
$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,
|
||||
'iban' => $sourceIban,
|
||||
'number' => $sourceNumber,
|
||||
];
|
||||
$validSource = $accountValidator->validateSource($source);
|
||||
$validSource = $accountValidator->validateSource($source);
|
||||
|
||||
// do something with result:
|
||||
if (false === $validSource) {
|
||||
@@ -423,8 +423,8 @@ trait TransactionValidation
|
||||
|
||||
return;
|
||||
}
|
||||
$source = $accountValidator->source;
|
||||
$destination = $accountValidator->destination;
|
||||
$source = $accountValidator->source;
|
||||
$destination = $accountValidator->destination;
|
||||
|
||||
app('log')->debug(sprintf('Source: #%d "%s (%s)"', $source->id, $source->name, $source->accountType->type));
|
||||
app('log')->debug(sprintf('Destination: #%d "%s" (%s)', $destination->id, $destination->name, $source->accountType->type));
|
||||
@@ -594,15 +594,15 @@ trait TransactionValidation
|
||||
if (count($transactions) < 2) {
|
||||
return;
|
||||
}
|
||||
$type = $transactions[0]['type'] ?? 'withdrawal';
|
||||
$sources = [];
|
||||
$dests = [];
|
||||
$type = $transactions[0]['type'] ?? 'withdrawal';
|
||||
$sources = [];
|
||||
$dests = [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$sources[] = sprintf('%d-%s', $transaction['source_id'] ?? 0, $transaction['source_name'] ?? '');
|
||||
$dests[] = sprintf('%d-%s', $transaction['destination_id'] ?? 0, $transaction['destination_name'] ?? '');
|
||||
}
|
||||
$sources = array_unique($sources);
|
||||
$dests = array_unique($dests);
|
||||
$sources = array_unique($sources);
|
||||
$dests = array_unique($dests);
|
||||
|
||||
switch ($type) {
|
||||
default:
|
||||
@@ -646,15 +646,15 @@ trait TransactionValidation
|
||||
|
||||
return;
|
||||
}
|
||||
$type = $this->getTransactionType($transactionGroup, $transactions);
|
||||
$type = $this->getTransactionType($transactionGroup, $transactions);
|
||||
|
||||
// compare source IDs, destination IDs, source names and destination names.
|
||||
// I think I can get away with one combination being equal, as long as the rest
|
||||
// of the code picks up on this as well.
|
||||
// either way all fields must be blank or all equal
|
||||
// but if IDs are equal don't bother with the names.
|
||||
$comparison = $this->collectComparisonData($transactions);
|
||||
$result = $this->compareAccountData($type, $comparison);
|
||||
$comparison = $this->collectComparisonData($transactions);
|
||||
$result = $this->compareAccountData($type, $comparison);
|
||||
if (false === $result) {
|
||||
if ('withdrawal' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
@@ -683,7 +683,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];
|
||||
@@ -695,7 +695,7 @@ trait TransactionValidation
|
||||
|
||||
private function getOriginalData(int $journalId): array
|
||||
{
|
||||
$return = [
|
||||
$return = [
|
||||
'source_id' => 0,
|
||||
'source_name' => '',
|
||||
'destination_id' => 0,
|
||||
@@ -706,7 +706,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/** @var null|Transaction $source */
|
||||
$source = Transaction::where('transaction_journal_id', $journalId)->where('amount', '<', 0)->with(['account'])->first();
|
||||
$source = Transaction::where('transaction_journal_id', $journalId)->where('amount', '<', 0)->with(['account'])->first();
|
||||
if (null !== $source) {
|
||||
$return['source_id'] = $source->account_id;
|
||||
$return['source_name'] = $source->account->name;
|
||||
|
Reference in New Issue
Block a user