From f67959fb06d455d68412b457ca095a5a647a9322 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 1 Mar 2023 13:42:31 +1100 Subject: [PATCH 1/3] Working on subscriptions --- .../ClientPortal/SubscriptionPurchaseController.php | 5 +++++ app/Http/Livewire/SubscriptionsTable.php | 4 ++-- .../components/livewire/subscriptions-table.blade.php | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/SubscriptionPurchaseController.php b/app/Http/Controllers/ClientPortal/SubscriptionPurchaseController.php index b8d8f1fe395c..e5007a607d98 100644 --- a/app/Http/Controllers/ClientPortal/SubscriptionPurchaseController.php +++ b/app/Http/Controllers/ClientPortal/SubscriptionPurchaseController.php @@ -23,6 +23,8 @@ class SubscriptionPurchaseController extends Controller { public function index(Subscription $subscription, Request $request) { + App::setLocale($subscription->company->locale()); + /* Make sure the contact is logged into the correct company for this subscription */ if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) { auth()->guard('contact')->logout(); @@ -42,6 +44,9 @@ class SubscriptionPurchaseController extends Controller public function upgrade(Subscription $subscription, Request $request) { + + App::setLocale($subscription->company->locale()); + /* Make sure the contact is logged into the correct company for this subscription */ if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) { auth()->guard('contact')->logout(); diff --git a/app/Http/Livewire/SubscriptionsTable.php b/app/Http/Livewire/SubscriptionsTable.php index dc4744b250ab..f05c07f4b7df 100644 --- a/app/Http/Livewire/SubscriptionsTable.php +++ b/app/Http/Livewire/SubscriptionsTable.php @@ -39,9 +39,9 @@ class SubscriptionsTable extends Component ->where('company_id', $this->company->id) ->whereNotNull('subscription_id') ->where('is_deleted', false) - ->where('status_id', RecurringInvoice::STATUS_ACTIVE) - ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') + ->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_PAUSED]) ->withTrashed() + ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); return render('components.livewire.subscriptions-table', [ diff --git a/resources/views/portal/ninja2020/components/livewire/subscriptions-table.blade.php b/resources/views/portal/ninja2020/components/livewire/subscriptions-table.blade.php index 4602b8c102c8..58a52b03798f 100644 --- a/resources/views/portal/ninja2020/components/livewire/subscriptions-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/subscriptions-table.blade.php @@ -15,6 +15,11 @@ + @forelse($recurring_invoices as $recurring_invoice) + From 8247ff41e410ad18a0013a57b0171e5365703475 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 1 Mar 2023 14:47:04 +1100 Subject: [PATCH 2/3] Add validation to coupon code --- app/Http/Livewire/BillingPortalPurchasev2.php | 7 +++++++ lang/en/texts.php | 1 + .../livewire/billing-portal-purchasev2.blade.php | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index ae9c980d082c..f37475836c92 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -271,6 +271,10 @@ class BillingPortalPurchasev2 extends Component */ public function handleCoupon() { + + $this->resetErrorBag('coupon'); + $this->resetValidation('coupon'); + if ($this->coupon == $this->subscription->promo_code) { $this->valid_coupon = true; $this->buildBundle(); @@ -278,6 +282,9 @@ class BillingPortalPurchasev2 extends Component $this->discount = 0; $this->valid_coupon = false; $this->buildBundle(); + $errors = $this->getErrorBag(); + $errors->add('coupon', ctrans('texts.invalid_coupon')); + return $this; } } diff --git a/lang/en/texts.php b/lang/en/texts.php index 18fa7cc2195a..c9ec4d4daa47 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5010,6 +5010,7 @@ $LANG = array( 'change_plan_description' => 'Upgrade or downgrade your current plan.', 'add_company_logo' => 'Add Logo', 'add_stripe' => 'Add Stripe', + 'invalid_coupon' => 'Invalid Coupon', ); diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php index 2adb5cfcf1e4..81346b33798c 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php @@ -253,6 +253,14 @@ {{ ctrans('texts.apply') }} + @if($errors && $errors->has('coupon')) + @error("coupon") + + @enderror + @endif @endif @@ -347,7 +355,6 @@ @enderror - @endif From be88aa356a2ba8837042e83c666abcf7e41f2867 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 1 Mar 2023 16:32:47 +1100 Subject: [PATCH 3/3] Fixes for displaying negative numbers --- app/Services/PdfMaker/Design.php | 1 - app/Utils/Number.php | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 4487a381e6af..a2d4927a6ebd 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -13,7 +13,6 @@ namespace App\Services\PdfMaker; use App\Models\Credit; -use App\Models\Invoice; use App\Models\Quote; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 3451ab6dd0c5..76dccb6f0a34 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -201,6 +201,8 @@ class Number public static function formatMoneyNoRounding($value, $entity) :string { $currency = $entity->currency(); + + $_value = $value; $thousand = $currency->thousand_separator; $decimal = $currency->decimal_separator; @@ -247,6 +249,12 @@ class Number } elseif ($swapSymbol) { return "{$value} ".trim($symbol); } elseif ($entity->getSetting('show_currency_code') === false) { + + if ($_value < 0) { + $value = substr($value, 1); + $symbol = "-{$symbol}"; + } + return "{$symbol}{$value}"; } else { return self::formatValue($value, $currency);
+

+ {{ ctrans('texts.status') }} +

+

{{ ctrans('texts.subscription') }} @@ -47,6 +52,9 @@

+ {!! $recurring_invoice->badgeForStatus($recurring_invoice->status_id) !!} + {{ $recurring_invoice->subscription->name }}