diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 4a1c5e52d2f4..f09dad17504e 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -167,7 +167,7 @@ class CreditService } public function adjustBalance($adjustment) - { + {nlog("adjusting by {$adjustment}"); $this->credit->balance += $adjustment; return $this; diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index f16576c0d11f..edacc89e6594 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -69,16 +69,6 @@ class RefundPayment EmailRefundPayment::dispatch($this->payment, $this->payment->company, $contact); } - $transaction = [ - 'invoice' => [], - 'payment' => $this->payment->transaction_event(), - 'client' => $this->payment->client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $this->payment->company->db); - $notes = ctrans('texts.refunded') . " : {$this->total_refund} - " . ctrans('texts.gateway_refund') . " : "; $notes .= $this->refund_data['gateway_refund'] !== false ? ctrans('texts.yes') : ctrans('texts.no'); @@ -210,6 +200,7 @@ class RefundPayment if ($this->payment->credits()->exists()) { //Adjust credits first!!! foreach ($this->payment->credits as $paymentable_credit) { + $available_credit = $paymentable_credit->pivot->amount - $paymentable_credit->pivot->refunded; if ($available_credit > $this->total_refund) { @@ -221,18 +212,18 @@ class RefundPayment ->updateBalance($this->total_refund) ->updatePaidToDate($this->total_refund * -1) ->save(); + $this->total_refund = 0; } else { $paymentable_credit->pivot->refunded += $available_credit; $paymentable_credit->pivot->save(); - $paymentable_credit->balance += $available_credit; $paymentable_credit->service() - ->setStatus(Credit::STATUS_SENT) + ->setStatus(Credit::STATUS_SENT) ->adjustBalance($available_credit) ->updatePaidToDate($available_credit * -1) - ->save(); + ->save(); $this->total_refund -= $available_credit; } @@ -288,16 +279,6 @@ class RefundPayment ->updateBalance($refunded_invoice['amount']) ->save(); - $transaction = [ - 'invoice' => $invoice->transaction_event(), - 'payment' => [], - 'client' => $client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $invoice->company->db); - if ($invoice->is_deleted) { $invoice->delete(); } @@ -311,15 +292,6 @@ class RefundPayment $client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save(); - $transaction = [ - 'invoice' => [], - 'payment' => [], - 'client' => $client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $client->company->db); } else { //if we are refunding and no payments have been tagged, then we need to decrement the client->paid_to_date by the total refund amount. @@ -331,15 +303,6 @@ class RefundPayment $client->service()->updatePaidToDate(-1 * $this->total_refund)->save(); - $transaction = [ - 'invoice' => [], - 'payment' => [], - 'client' => $client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $client->company->db); } return $this; diff --git a/app/Utils/Traits/Pdf/PDF.php b/app/Utils/Traits/Pdf/PDF.php index a3f0727f714f..7021fc8c3be8 100644 --- a/app/Utils/Traits/Pdf/PDF.php +++ b/app/Utils/Traits/Pdf/PDF.php @@ -19,7 +19,7 @@ class PDF extends FPDI public function Footer() { - $this->SetXY(0, -5); + $this->SetXY(0, -6); $this->SetFont('Arial', 'I', 9); $this->SetTextColor(135, 135, 135);