From 5b3155ea9ea695986779459a4330434f6dee9183 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 1 May 2025 15:40:54 +1000 Subject: [PATCH] Working on payment activities --- app/Models/Activity.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 89926051d6..d10bd3e6c8 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -517,7 +517,7 @@ class Activity extends StaticModel ':recurring_invoice' => $translation = [substr($variable, 1) => [ 'label' => $this?->recurring_invoice?->number ?? '', 'hashed_id' => $this->recurring_invoice->hashed_id ?? '']], ':recurring_expense' => $translation = [substr($variable, 1) => [ 'label' => $this?->recurring_expense?->number ?? '', 'hashed_id' => $this->recurring_expense->hashed_id ?? '']], ':payment_amount' => $translation = [substr($variable, 1) => [ 'label' => Number::formatMoney($this?->payment?->amount, $this?->payment?->client ?? $this->company) ?? '', 'hashed_id' => '']], - ':adjustment' => $translation = [substr($variable, 1) => [ 'label' => Number::formatMoney($this?->payment?->refunded, $this?->payment?->client ?? $this->company) ?? '', 'hashed_id' => '']], + ':adjustment' => $translation = [substr($variable, 1) => [ 'label' => $this->getPaymentAdjustment($this?->payment), 'hashed_id' => '']], ':ip' => $translation = [ 'ip' => $this->ip ?? ''], ':contact' => $translation = $this->resolveContact(), ':notes' => $translation = [ 'notes' => $this->notes ?? ''], @@ -528,6 +528,18 @@ class Activity extends StaticModel return $translation; } + private function getPaymentAdjustment(?\App\Models\Payment $payment): string + { + if(!$payment) + return ''; + + preg_match('/:\s*(\d+)\s*-/', $this->notes, $matches); + $amount = $matches[1] ?? null; + + return Number::formatMoney($amount ?? $payment->refunded, $payment?->client ?? $this->company); + + } + private function resolveContact(): array { $contact = $this->contact ? $this->contact : $this->vendor_contact;