diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 7fab7943fbd1..09412bab11fd 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -122,7 +122,7 @@ class PaymentMigrationRepository extends BaseRepository $invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get(); - $payment->invoices()->saveMany($invoices); + $payment->invoices()->saveMany($invoices); // 1:1 relationship so this is ok $payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals, $payment) { if ($payment->status_id != Payment::STATUS_CANCELLED || ! $payment->is_deleted) { diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 6b47aae2e624..0b4be3c46880 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -139,7 +139,7 @@ class PaymentRepository extends BaseRepository $invoices = Invoice::withTrashed()->whereIn('id', array_column($data['invoices'], 'invoice_id'))->get(); - // $payment->invoices()->saveMany($invoices); + // $payment->invoices()->saveMany($invoices); //25-06-2023 //todo optimize this into a single query foreach ($data['invoices'] as $paid_invoice) { @@ -148,6 +148,8 @@ class PaymentRepository extends BaseRepository if ($invoice) { + //25-06-2023 + $paymentable = new Paymentable(); $paymentable->payment_id = $payment->id; $paymentable->paymentable_id = $invoice->id; @@ -162,9 +164,7 @@ class PaymentRepository extends BaseRepository } } } else { - //payment is made, but not to any invoice, therefore we are applying the payment to the clients paid_to_date only - //01-07-2020 i think we were duplicating the paid to date here. - //$payment->client->service()->updatePaidToDate($payment->amount)->save(); + } if (array_key_exists('credits', $data) && is_array($data['credits'])) { @@ -176,7 +176,7 @@ class PaymentRepository extends BaseRepository //todo optimize into a single query foreach ($data['credits'] as $paid_credit) { - // $credit = Credit::withTrashed()->find($paid_credit['credit_id']); + $credit = $credits->firstWhere('id', $paid_credit['credit_id']); if ($credit) { diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index b556b2261425..542e871876b4 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -86,7 +86,7 @@ class ApplyPayment extends AbstractService if ($inv->id == $this->invoice->id) { // $inv->pivot->amount = ($amount_paid * -1); // $inv->pivot->save(); - + //25-06-2023 $inv->paid_to_date += floatval($amount_paid * -1); $inv->save(); }