mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactors for Bank Transactions
This commit is contained in:
parent
dfca75229d
commit
e63c50f58f
@ -48,7 +48,8 @@ class StoreBankTransactionRuleRequest extends Request
|
|||||||
'rules.*.value' => 'bail|required|nullable',
|
'rules.*.value' => 'bail|required|nullable',
|
||||||
'auto_convert' => 'bail|sometimes|bool',
|
'auto_convert' => 'bail|sometimes|bool',
|
||||||
'matches_on_all' => 'bail|sometimes|bool',
|
'matches_on_all' => 'bail|sometimes|bool',
|
||||||
'applies_to' => 'bail|sometimes|string',
|
'applies_to' => 'bail|sometimes|string|in:CREDIT,DEBIT',
|
||||||
|
'on_credit_match' => 'bail|sometimes|in:create_payment,link_payment'
|
||||||
];
|
];
|
||||||
|
|
||||||
$rules['category_id'] = 'bail|sometimes|nullable|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
|
$rules['category_id'] = 'bail|sometimes|nullable|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
|
||||||
|
@ -85,12 +85,6 @@ class ProcessBankRules extends AbstractService
|
|||||||
foreach ($bank_transaction_rule['rules'] as $rule) {
|
foreach ($bank_transaction_rule['rules'] as $rule) {
|
||||||
$rule_count = count($bank_transaction_rule['rules']);
|
$rule_count = count($bank_transaction_rule['rules']);
|
||||||
|
|
||||||
$invoices = Invoice::query()
|
|
||||||
->withTrashed()
|
|
||||||
->where('company_id', $this->bank_transaction->company_id)
|
|
||||||
->whereIn('status_id', [1,2,3])
|
|
||||||
->where('is_deleted', 0)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$payments = Payment::query()
|
$payments = Payment::query()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
@ -100,34 +94,50 @@ class ProcessBankRules extends AbstractService
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
match($rule['search_key']){
|
match($rule['search_key']){
|
||||||
'$payment.amount' => $results = $this->searchPaymentResource('amount'),
|
'$payment.amount' => $results = $this->searchPaymentResource('amount', $rule),
|
||||||
'$payment.transaction_reference' => $results = $this->searchPaymentResource('transaction_reference'),
|
'$payment.transaction_reference' => $results = $this->searchPaymentResource('transaction_reference', $rule),
|
||||||
'$payment.custom1' => $results = $this->searchPaymentResource('custom1'),
|
'$payment.custom1' => $results = $this->searchPaymentResource('custom1', $rule),
|
||||||
'$payment.custom2' => $results = $this->searchPaymentResource('custom2'),
|
'$payment.custom2' => $results = $this->searchPaymentResource('custom2', $rule),
|
||||||
'$payment.custom3' => $results = $this->searchPaymentResource('custom3'),
|
'$payment.custom3' => $results = $this->searchPaymentResource('custom3', $rule),
|
||||||
'$payment.custom4' => $results = $this->searchPaymentResource('custom4'),
|
'$payment.custom4' => $results = $this->searchPaymentResource('custom4', $rule),
|
||||||
'$invoice.amount' => $results = $this->searchInvoiceResource('amount'),
|
'$invoice.amount' => $results = $this->searchInvoiceResource('amount', $rule),
|
||||||
'$invoice.number' => $results = $this->searchInvoiceResource('number'),
|
'$invoice.number' => $results = $this->searchInvoiceResource('number', $rule),
|
||||||
'$invoice.po_number' => $results = $this->searchInvoiceResource('po_number'),
|
'$invoice.po_number' => $results = $this->searchInvoiceResource('po_number', $rule),
|
||||||
'$invoice.custom1' => $results = $this->searchInvoiceResource('custom1'),
|
'$invoice.custom1' => $results = $this->searchInvoiceResource('custom1', $rule),
|
||||||
'$invoice.custom2' => $results = $this->searchInvoiceResource('custom2'),
|
'$invoice.custom2' => $results = $this->searchInvoiceResource('custom2', $rule),
|
||||||
'$invoice.custom3' => $results = $this->searchInvoiceResource('custom3'),
|
'$invoice.custom3' => $results = $this->searchInvoiceResource('custom3', $rule),
|
||||||
'$invoice.custom4' => $results = $this->searchInvoiceResource('custom4'),
|
'$invoice.custom4' => $results = $this->searchInvoiceResource('custom4', $rule),
|
||||||
'$client.id_number' => $results = $this->searchClientResource('id_number'),
|
'$client.id_number' => $results = $this->searchClientResource('id_number', $rule),
|
||||||
'$client.email' => $results = $this->searchClientResource('email'),
|
'$client.email' => $results = $this->searchClientResource('email', $rule),
|
||||||
'$client.custom1' => $results = $this->searchClientResource('custom1'),
|
'$client.custom1' => $results = $this->searchClientResource('custom1', $rule),
|
||||||
'$client.custom2' => $results = $this->searchClientResource('custom2'),
|
'$client.custom2' => $results = $this->searchClientResource('custom2', $rule),
|
||||||
'$client.custom3' => $results = $this->searchClientResource('custom3'),
|
'$client.custom3' => $results = $this->searchClientResource('custom3', $rule),
|
||||||
'$client.custom4' => $results = $this->searchClientResource('custom4'),
|
'$client.custom4' => $results = $this->searchClientResource('custom4', $rule),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function searchInvoiceResource()
|
private function searchInvoiceResource(string $column, array $rule)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
return Invoice::query()
|
||||||
|
->withTrashed()
|
||||||
|
->where('company_id', $this->bank_transaction->company_id)
|
||||||
|
->whereIn('status_id', [1,2,3])
|
||||||
|
->where('is_deleted', 0)
|
||||||
|
->when($rule['search_key'] == 'description', function ($q) use ($rule, $column){
|
||||||
|
return $q->cursor()->filter(function ($record) use ($rule, $column){
|
||||||
|
return $this->matchStringOperator($this->bank_transaction->description, $record->{$column}, $rule['operator']);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->when($rule['search_key'] == 'amount', function ($q) use($rule,$column){
|
||||||
|
return $q->cursor()->filter(function ($record) use ($rule, $column) {
|
||||||
|
return $this->matchNumberOperator($this->bank_transaction->amount, $record->{$column}, $rule['operator']);
|
||||||
|
});
|
||||||
|
})->pluck("id");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function searchPaymentResource()
|
private function searchPaymentResource()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user