mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 19:49:54 +00:00
Code cleanup
This commit is contained in:
@@ -27,7 +27,6 @@ namespace FireflyIII\Validation;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
@@ -38,44 +37,6 @@ use Illuminate\Validation\Validator;
|
||||
*/
|
||||
trait GroupValidation
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function preventUpdateReconciled(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
|
||||
$count = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_groups', 'transaction_groups.id', 'transaction_journals.transaction_group_id')
|
||||
->where('transaction_journals.transaction_group_id', $transactionGroup->id)
|
||||
->where('transactions.reconciled', 1)->where('transactions.amount', '<', 0)->count(['transactions.id']);
|
||||
if (0 === $count) {
|
||||
app('log')->debug(sprintf('Transaction is not reconciled, done with %s', __METHOD__));
|
||||
return;
|
||||
}
|
||||
$data = $validator->getData();
|
||||
$forbidden = ['amount','foreign_amount','currency_code','currency_id','foreign_currency_code','foreign_currency_id',
|
||||
'source_id','source_name','source_number','source_iban',
|
||||
'destination_id','destination_name','destination_number','destination_iban',
|
||||
];
|
||||
foreach($data['transactions'] as $index => $row) {
|
||||
foreach($forbidden as $key) {
|
||||
if(array_key_exists($key, $row)) {
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.%s', $index, $key),
|
||||
(string)trans('validation.reconciled_forbidden_field', ['field' => $key])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Done with %s', __METHOD__));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A catch when users submit splits with no source or destination info at all.
|
||||
*
|
||||
@@ -133,6 +94,43 @@ trait GroupValidation
|
||||
*/
|
||||
abstract protected function getTransactionsArray(Validator $validator): array;
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function preventUpdateReconciled(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
|
||||
$count = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_groups', 'transaction_groups.id', 'transaction_journals.transaction_group_id')
|
||||
->where('transaction_journals.transaction_group_id', $transactionGroup->id)
|
||||
->where('transactions.reconciled', 1)->where('transactions.amount', '<', 0)->count(['transactions.id']);
|
||||
if (0 === $count) {
|
||||
app('log')->debug(sprintf('Transaction is not reconciled, done with %s', __METHOD__));
|
||||
return;
|
||||
}
|
||||
$data = $validator->getData();
|
||||
$forbidden = ['amount', 'foreign_amount', 'currency_code', 'currency_id', 'foreign_currency_code', 'foreign_currency_id',
|
||||
'source_id', 'source_name', 'source_number', 'source_iban',
|
||||
'destination_id', 'destination_name', 'destination_number', 'destination_iban',
|
||||
];
|
||||
foreach ($data['transactions'] as $index => $row) {
|
||||
foreach ($forbidden as $key) {
|
||||
if (array_key_exists($key, $row)) {
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.%s', $index, $key),
|
||||
(string)trans('validation.reconciled_forbidden_field', ['field' => $key])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Done with %s', __METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the "description" field when the user has submitted no descriptions and no
|
||||
* journal description.
|
||||
|
Reference in New Issue
Block a user