From 244975702196095f52205837b9da3170a76a2086 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 13 Aug 2024 09:35:31 +1000 Subject: [PATCH] Update entity filters --- app/Filters/CreditFilters.php | 9 ++++++++- app/Filters/InvoiceFilters.php | 9 ++++++++- app/Filters/PurchaseOrderFilters.php | 9 ++++++++- app/Filters/QuoteFilters.php | 9 ++++++++- app/Filters/RecurringInvoiceFilters.php | 9 ++++++++- app/Models/Invoice.php | 2 +- app/Services/Invoice/AddGatewayFee.php | 7 ++++--- config/liap.php | 24 ++++++++++++++---------- 8 files changed, 59 insertions(+), 19 deletions(-) diff --git a/app/Filters/CreditFilters.php b/app/Filters/CreditFilters.php index 54ba0fb05c21..578a83ddcff0 100644 --- a/app/Filters/CreditFilters.php +++ b/app/Filters/CreditFilters.php @@ -98,7 +98,14 @@ class CreditFilters extends QueryFilters ->orWhere('last_name', 'like', '%'.$filter.'%') ->orWhere('email', 'like', '%'.$filter.'%'); }) - ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); + ->orWhereRaw(" + JSON_UNQUOTE(JSON_EXTRACT( + JSON_ARRAY( + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')), + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].product_key')) + ), '$[*]') + ) LIKE ?", ['%'.$filter.'%']); + // ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); }); } diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index de5a932fb76f..4685590b1cfa 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -125,7 +125,14 @@ class InvoiceFilters extends QueryFilters ->orWhere('last_name', 'like', '%'.$filter.'%') ->orWhere('email', 'like', '%'.$filter.'%'); }) - ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); + ->orWhereRaw(" + JSON_UNQUOTE(JSON_EXTRACT( + JSON_ARRAY( + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')), + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].product_key')) + ), '$[*]') + ) LIKE ?", ['%'.$filter.'%']); + // ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); }); } diff --git a/app/Filters/PurchaseOrderFilters.php b/app/Filters/PurchaseOrderFilters.php index 700335242fe4..82fe3f8aa907 100644 --- a/app/Filters/PurchaseOrderFilters.php +++ b/app/Filters/PurchaseOrderFilters.php @@ -96,7 +96,14 @@ class PurchaseOrderFilters extends QueryFilters ->orWhere('custom_value4', 'like', '%'.$filter.'%') ->orWhereHas('vendor', function ($q) use ($filter) { $q->where('name', 'like', '%'.$filter.'%'); - }); + }) + ->orWhereRaw(" + JSON_UNQUOTE(JSON_EXTRACT( + JSON_ARRAY( + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')), + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].product_key')) + ), '$[*]') + ) LIKE ?", ['%'.$filter.'%']); }); } diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 048669db927a..d2c5763187dc 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -46,7 +46,14 @@ class QuoteFilters extends QueryFilters ->orWhere('last_name', 'like', '%'.$filter.'%') ->orWhere('email', 'like', '%'.$filter.'%'); }) - ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); + ->orWhereRaw(" + JSON_UNQUOTE(JSON_EXTRACT( + JSON_ARRAY( + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')), + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].product_key')) + ), '$[*]') + ) LIKE ?", ['%'.$filter.'%']); + // ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); }); } diff --git a/app/Filters/RecurringInvoiceFilters.php b/app/Filters/RecurringInvoiceFilters.php index 983582cb9a4e..976739912b59 100644 --- a/app/Filters/RecurringInvoiceFilters.php +++ b/app/Filters/RecurringInvoiceFilters.php @@ -49,7 +49,14 @@ class RecurringInvoiceFilters extends QueryFilters ->orWhere('last_name', 'like', '%'.$filter.'%') ->orWhere('email', 'like', '%'.$filter.'%'); }) - ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); + ->orWhereRaw(" + JSON_UNQUOTE(JSON_EXTRACT( + JSON_ARRAY( + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')), + JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].product_key')) + ), '$[*]') + ) LIKE ?", ['%'.$filter.'%']); + //->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(line_items, '$[*].notes')) LIKE ?", ['%'.$filter.'%']); }); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index fe2b1222f391..4b98faa0c6c6 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -431,7 +431,7 @@ class Invoice extends BaseModel public function isPayable(): bool { - if($this->is_deleted) + if($this->is_deleted || $this->status_id == self::STATUS_PAID) return false; elseif ($this->status_id == self::STATUS_DRAFT && $this->is_deleted == false) { return true; diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index b95dd6841e90..9601d671f6b0 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -26,15 +26,16 @@ class AddGatewayFee extends AbstractService public function run() { + + // Removes existing stale gateway fees + $this->cleanPendingGatewayFees(); + $gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount, $this->gateway_type_id, $this->invoice->uses_inclusive_taxes), $this->invoice->client->currency()->precision); if (! $gateway_fee || $gateway_fee == 0) { return $this->invoice; } - // Removes existing stale gateway fees - $this->cleanPendingGatewayFees(); - // If a gateway fee is > 0 insert the line item if ($gateway_fee > 0) { return $this->processGatewayFee($gateway_fee); diff --git a/config/liap.php b/config/liap.php index 4483546d3ffa..a27e84334263 100644 --- a/config/liap.php +++ b/config/liap.php @@ -1,19 +1,22 @@ class_exists(\Modules\Admin\Listeners\Subscription\AppleSubscribed::class) ? [\Modules\Admin\Listeners\Subscription\AppleSubscribed::class] : [], DidRenew::class => class_exists(\Modules\Admin\Listeners\Subscription\AppleAutoRenew::class) ? [\Modules\Admin\Listeners\Subscription\AppleAutoRenew::class] : [], SubscriptionRenewed::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleAutoRenew::class) ? [\Modules\Admin\Listeners\Subscription\GoogleAutoRenew::class] : [], - DidChangeRenewalStatus::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleChangeRenewalStaus::class) ? [\Modules\Admin\Listeners\Subscription\GoogleChangeRenewalStaus::class] : [], + // DidChangeRenewalStatus::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleChangeRenewalStaus::class) ? [\Modules\Admin\Listeners\Subscription\GoogleChangeRenewalStaus::class] : [], DidFailToRenew::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleFailedToRenew::class) ? [\Modules\Admin\Listeners\Subscription\GoogleFailedToRenew::class] : [], Refund::class => class_exists(\Modules\Admin\Listeners\Subscription\AppleRefund::class) ? [\Modules\Admin\Listeners\Subscription\AppleRefund::class] : [], SubscriptionRecovered::class => class_exists(\Modules\Admin\Listeners\Subscription\GoogleSubscriptionRecovered::class) ? [\Modules\Admin\Listeners\Subscription\GoogleSubscriptionRecovered::class] : [],