From 69786492e0be3d10552941f5e286b9f4d942791f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 31 Jul 2023 18:22:34 +1000 Subject: [PATCH] Minor update --- app/Http/Requests/Invoice/UpdateInvoiceRequest.php | 2 +- .../ValidationRules/Payment/ValidRefundableRequest.php | 2 +- app/Models/Payment.php | 8 +++++++- app/Models/Product.php | 2 +- app/Services/Payment/DeletePayment.php | 9 +++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index 971de8712cd3..db055d17c4cf 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -71,7 +71,7 @@ class UpdateInvoiceRequest extends Request $rules['tax_name1'] = 'bail|sometimes|string|nullable'; $rules['tax_name2'] = 'bail|sometimes|string|nullable'; $rules['tax_name3'] = 'bail|sometimes|string|nullable'; - $rules['status_id'] = 'bail|sometimes|not_in:5'; //do not all cancelled invoices to be modfified. + $rules['status_id'] = 'bail|sometimes|not_in:5'; //do not allow cancelled invoices to be modfified. $rules['exchange_rate'] = 'bail|sometimes|gt:0'; // not needed. diff --git a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php index 3ae582e772a8..29b6a7230d58 100644 --- a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php +++ b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php @@ -106,7 +106,7 @@ class ValidRefundableRequest implements Rule if ($payment->credits()->exists()) { $paymentable_credit = $payment->credits->where('id', $credit->id)->first(); - if (! $paymentable_invoice) { + if (! $paymentable_credit) { $this->error_msg = ctrans('texts.credit_not_related_to_payment', ['credit' => $credit->hashed_id]); return false; diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 4502b389a405..cbcbc1171f76 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -15,12 +15,13 @@ use App\Events\Payment\PaymentWasRefunded; use App\Events\Payment\PaymentWasVoided; use App\Services\Ledger\LedgerService; use App\Services\Payment\PaymentService; -use App\Utils\Ninja; +use App\Utils\Ninja; use App\Utils\Number; use App\Utils\Traits\Inviteable; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; use App\Utils\Traits\Payment\Refundable; +use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -251,6 +252,11 @@ class Payment extends BaseModel return $this->belongsTo(Currency::class); } + public function transaction(): BelongsTo + { + return $this->belongsTo(BankTransaction::class); + } + public function exchange_currency() { return $this->belongsTo(Currency::class, 'exchange_currency_id', 'id'); diff --git a/app/Models/Product.php b/app/Models/Product.php index cff15a798e69..c3e8724ebc46 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -198,7 +198,7 @@ class Product extends BaseModel ], ]); - return $converter->convert($this->notes); + return $converter->convert($this->notes ?? ''); } public function portalUrl($use_react_url): string diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 38002a9057be..6c99757ea25e 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -54,13 +54,14 @@ class DeletePayment /** @return $this */ private function cleanupPayment() { + $this->payment->is_deleted = true; $this->payment->delete(); - // BankTransaction::where('payment_id', $this->payment->id)->cursor()->each(function ($bt){ - // $bt->payment_id = null; - // $bt->save(); - // }); + BankTransaction::where('payment_id', $this->payment->id)->cursor()->each(function ($bt){ + $bt->payment_id = null; + $bt->save(); + }); return $this; }