diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 0307d177d132..4ea1e65340e3 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -185,7 +185,7 @@ class PaymentRepository extends BaseRepository { * @param $payment * @return */ - private function processExchangeRates($data, $payment) + public function processExchangeRates($data, $payment) { if(array_key_exists('exchange_rate', $data) && isset($data['exchange_rate'])) diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 9a867284afa3..22bd94a56448 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -16,6 +16,7 @@ use App\Jobs\Util\UnlinkFile; use App\Models\Credit; use App\Models\Payment; use App\Models\PaymentType; +use App\Repositories\CreditRepository; use App\Repositories\PaymentRepository; use App\Services\Credit\CreateInvitations; use App\Services\Credit\TriggeredActions; @@ -97,7 +98,7 @@ class CreditService if($this->credit->balance > 0) return $this; - $payment_repo = new PaymentRepository(); + $payment_repo = new PaymentRepository(new CreditRepository()); //set credit balance to zero $adjustment = $this->credit->balance; @@ -129,6 +130,7 @@ class CreditService //reduce client paid_to_date by $this->credit->balance amount $this->credit ->client + ->service() ->updatePaidToDate($adjustment) ->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index ae84ea16462a..f1ea59aefc8d 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -130,7 +130,7 @@ class AutoBillInvoice extends AbstractService info("Auto Bill payment captured for ".$this->invoice->number); } - return $this->invoice; + return $this->invoice->fresh(); } /** diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 626327f803a7..58222c6e75d1 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -139,8 +139,13 @@ class DeletePayment if ($this->payment->credits()->exists()) { $this->payment->credits()->each(function ($paymentable_credit) { + $multiplier = 1; + + if($paymentable_credit->pivot->amount < 0) + $multiplier = -1; + $paymentable_credit->service() - ->updateBalance($paymentable_credit->pivot->amount) + ->updateBalance($paymentable_credit->pivot->amount*$multiplier) ->updatePaidToDate($paymentable_credit->pivot->amount*-1) ->setStatus(Credit::STATUS_SENT) ->save();