From 5d459aaa2f2709a4bc242e19c312e50b7150e0fc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Jan 2023 14:32:53 +1100 Subject: [PATCH] Fixes for credit creation after downgrading a subscription service --- app/Repositories/PaymentRepository.php | 3 +-- app/Services/Credit/ApplyPayment.php | 4 ++-- app/Services/Subscription/SubscriptionService.php | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 5c912539b573..7d6cad5386a5 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -83,9 +83,8 @@ class PaymentRepository extends BaseRepository { if ($data['amount'] == '') { $data['amount'] = array_sum(array_column($data['invoices'], 'amount')); } - + $client->service()->updatePaidToDate($data['amount'])->save(); - // $client->paid_to_date += $data['amount']; $client->save(); } diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index b5df4be9e60f..f6e49faac3e9 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -105,8 +105,8 @@ class ApplyPayment private function addPaymentToLedger() { - $this->payment->amount += $this->amount_applied; - $this->payment->applied += $this->amount_applied; + // $this->payment->amount += $this->amount_applied; + // $this->payment->applied += $this->amount_applied; $this->payment->status_id = Payment::STATUS_COMPLETED; $this->payment->currency_id = $this->credit->client->getSetting('currency_id'); $this->payment->save(); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 4b2d7d1cfc48..f4439c922e59 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -416,7 +416,7 @@ else foreach($invoice->line_items as $item) { - if($item->product_key != ctrans('texts.refund')) + if($item->product_key != ctrans('texts.refund') && ($item->type_id == "1" || $item->type_id == "2")) { $item->cost = ($item->cost*$ratio*$multiplier);