mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 22:04:35 -04:00
Refactor payment queries for improved efficiency
This commit is contained in:
parent
4e3f52a1ee
commit
2c8d25eeb3
@ -139,7 +139,8 @@ class PaymentRepository extends BaseRepository {
|
|||||||
|
|
||||||
//todo optimize this into a single query
|
//todo optimize this into a single query
|
||||||
foreach ($data['invoices'] as $paid_invoice) {
|
foreach ($data['invoices'] as $paid_invoice) {
|
||||||
$invoice = Invoice::withTrashed()->whereId($paid_invoice['invoice_id'])->first();
|
// $invoice = Invoice::withTrashed()->whereId($paid_invoice['invoice_id'])->first();
|
||||||
|
$invoice = $invoices->firstWhere('id', $paid_invoice['invoice_id']);
|
||||||
|
|
||||||
if ($invoice) {
|
if ($invoice) {
|
||||||
$invoice = $invoice->service()
|
$invoice = $invoice->service()
|
||||||
@ -165,8 +166,9 @@ class PaymentRepository extends BaseRepository {
|
|||||||
|
|
||||||
//todo optimize into a single query
|
//todo optimize into a single query
|
||||||
foreach ($data['credits'] as $paid_credit) {
|
foreach ($data['credits'] as $paid_credit) {
|
||||||
$credit = Credit::withTrashed()->find($paid_credit['credit_id']);
|
// $credit = Credit::withTrashed()->find($paid_credit['credit_id']);
|
||||||
|
$credit = $credits->firstWhere('id', $paid_credit['credit_id']);
|
||||||
|
|
||||||
if ($credit) {
|
if ($credit) {
|
||||||
$credit = $credit->service()->markSent()->save();
|
$credit = $credit->service()->markSent()->save();
|
||||||
(new ApplyCreditPayment($credit, $payment, $paid_credit['amount'], $credit->company))->handle();
|
(new ApplyCreditPayment($credit, $payment, $paid_credit['amount'], $credit->company))->handle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user