From ccda36a7451ba665670f51fad581c99ff8d04901 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Nov 2021 16:18:16 +1100 Subject: [PATCH 1/7] wepay fixes --- app/PaymentDrivers/WePayPaymentDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 73b8d7573949..a0009fb6cd4b 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -208,7 +208,7 @@ class WePayPaymentDriver extends BaseDriver return 'Processed successfully'; } elseif ($objectType == 'account') { - if ($accountId !== $objectId) { + if ($accountId != $objectId) { throw new \Exception('Unknown account ' . $accountId . ' does not equal '.$objectId); } From a505f2531b035c9e5b0328a5d309c9ddd55e0063 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Nov 2021 21:39:43 +1100 Subject: [PATCH 2/7] Dedicated ninja plan controller --- .../ClientPortal/NinjaPlanController.php | 46 +++++++++++++++++++ app/Http/ViewComposers/PortalComposer.php | 5 ++ resources/lang/en/texts.php | 1 + routes/client.php | 2 + 4 files changed, 54 insertions(+) diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index 739f573f3556..a534340ba539 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -18,10 +18,13 @@ use App\Libraries\MultiDB; use App\Models\Account; use App\Models\ClientContact; use App\Models\Company; +use App\Models\Invoice; +use App\Models\Subscription; use App\Utils\Ninja; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Auth; class NinjaPlanController extends Controller @@ -57,4 +60,47 @@ class NinjaPlanController extends Controller return redirect()->route('client.catchall'); } + + public function plan() + { + //harvest the current plan + $data = []; + + if(MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) + { + $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); + + if($account && $account->isPaidHostedClient()) + { + + if(Carbon::parse($account->plan_expires).lt(now())){ + //expired get the most recent invoice for payment + + $late_invoice = Invoice::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('client_id', Auth::guard('contact')->user()->client->id) + ->where('status_id', Invoice::STATUS_SENT) + ->orderBy('id', DESC) + ->first(); + + if($late_invoice) + $data['late_invoice'] = $late_invoice; + + } + + //build list of upgrades. + + $data['monthly_plans'] = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 6) + ->get(); + + $data['yearly_plans'] = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 31) + ->get(); + } + } + + } } diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 3f589c759ef1..32034c05dfbd 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -115,6 +115,11 @@ class PortalComposer $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download']; $data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar']; + + if(Ninja::isHosted() && auth('contact')->user()->company->id == config('ninja.ninja_default_company_id')) + $data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card']; + + if (auth('contact')->user()->client->getSetting('enable_client_portal_tasks')) { $data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock']; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3afda95c0172..7e273e7ff56e 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4340,6 +4340,7 @@ $LANG = array( 'no_available_methods' => 'We can\'t find any credit cards on your device. Read more about this.', 'gocardless_mandate_not_ready' => 'Payment mandate is not ready. Please try again later.', 'payment_type_instant_bank_pay' => 'Instant Bank Pay', + ); return $LANG; diff --git a/routes/client.php b/routes/client.php index 31478e3c6712..cd8860c6f960 100644 --- a/routes/client.php +++ b/routes/client.php @@ -31,6 +31,8 @@ Route::get('client/ninja/{contact_key}/{company_key}', 'ClientPortal\NinjaPlanCo Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence','domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () { Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit + Route::get('plan', 'ClientPortal\NinjaPlanController@plan')->name('plan'); // name = (dashboard. index / create / show / update / destroy / edit + Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index')->middleware('portal_enabled'); Route::post('invoices/payment', 'ClientPortal\InvoiceController@bulk')->name('invoices.bulk'); Route::get('invoices/{invoice}', 'ClientPortal\InvoiceController@show')->name('invoice.show'); From b249077420e2a81c6044709ad8fd16e1da35aa11 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 04:27:45 +1100 Subject: [PATCH 3/7] fixes for Stripe ACH description --- app/PaymentDrivers/Stripe/ACH.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index a0568cb8f6ec..cac64514a20c 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -231,12 +231,24 @@ class ACH $this->stripe->payment_hash->data = array_merge((array)$this->stripe->payment_hash->data, $state); $this->stripe->payment_hash->save(); + $amount = array_sum(array_column($this->stripe->payment_hash->invoices(), 'amount')) + $this->stripe->payment_hash->fee_total; + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->stripe->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if ($invoice) { + $description = "Invoice {$invoice->number} for {$amount} for client {$this->stripe->client->present()->name()}"; + } else { + $description = "Payment with no invoice for amount {$amount} for client {$this->stripe->client->present()->name()}"; + } + try { $state['charge'] = \Stripe\Charge::create([ 'amount' => $state['amount'], 'currency' => $state['currency'], 'customer' => $state['customer'], 'source' => $state['source'], + 'description' => $description, ], $this->stripe->stripe_connect_auth); $state = array_merge($state, $request->all()); From 3c8651ad6fc19e98e1e03fbfd0cb0aa7b496a9d1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 04:39:29 +1100 Subject: [PATCH 4/7] Ensure braintree error is parsed correctly --- app/PaymentDrivers/Braintree/CreditCard.php | 5 ++++- app/PaymentDrivers/MolliePaymentDriver.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index a00dd398a7f9..0613dfe8ab0f 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -136,7 +136,10 @@ class CreditCard return $this->processSuccessfulPayment($result); } - return $this->processUnsuccessfulPayment($result); + $error = $result ?: 'Undefined gateway error'; + + return $this->processUnsuccessfulPayment($error); + } private function getPaymentToken(array $data, $customerId): ?string diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index e05fe4972924..b256fbdecf83 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -294,7 +294,7 @@ class MolliePaymentDriver extends BaseDriver } $this->init(); - + $codes = [ 'open' => Payment::STATUS_PENDING, 'canceled' => Payment::STATUS_CANCELLED, @@ -312,6 +312,9 @@ class MolliePaymentDriver extends BaseDriver $client = $record->client; } else{ + nlog("mollie webhook"); + nlog($payment); + $client = Client::withTrashed()->find($this->decodePrimaryKey($payment->metadata->client_id)); } From 7e9afd7849d45b16ff1b8998ea5b402ca0a5c7c9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 08:57:24 +1100 Subject: [PATCH 5/7] Ninja plan --- .../ClientPortal/NinjaPlanController.php | 60 +++++++++- app/Http/ViewComposers/PortalComposer.php | 9 +- .../portal/ninja2020/plan/index.blade.php | 103 ++++++++++++++++++ 3 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 resources/views/portal/ninja2020/plan/index.blade.php diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index a534340ba539..c2a4a1d6bd9c 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -19,8 +19,10 @@ use App\Models\Account; use App\Models\ClientContact; use App\Models\Company; use App\Models\Invoice; +use App\Models\RecurringInvoice; use App\Models\Subscription; use App\Utils\Ninja; +use App\Utils\Traits\MakesHash; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -29,6 +31,7 @@ use Illuminate\Support\Facades\Auth; class NinjaPlanController extends Controller { + use MakesHash; public function index(string $contact_key, string $account_or_company_key) { @@ -66,6 +69,7 @@ class NinjaPlanController extends Controller //harvest the current plan $data = []; + if(MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); @@ -73,14 +77,17 @@ class NinjaPlanController extends Controller if($account && $account->isPaidHostedClient()) { - if(Carbon::parse($account->plan_expires).lt(now())){ + $data['account'] = $account; + + if(Carbon::parse($account->plan_expires)->lt(now())){ //expired get the most recent invoice for payment $late_invoice = Invoice::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('client_id', Auth::guard('contact')->user()->client->id) ->where('status_id', Invoice::STATUS_SENT) - ->orderBy('id', DESC) + ->whereNotNull('subscription_id') + ->orderBy('id', 'DESC') ->first(); if($late_invoice) @@ -90,17 +97,62 @@ class NinjaPlanController extends Controller //build list of upgrades. - $data['monthly_plans'] = Subscription::on('db-ninja-01') + $monthly_plans = Subscription::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('group_id', 6) ->get(); - $data['yearly_plans'] = Subscription::on('db-ninja-01') + $yearly_plans = Subscription::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('group_id', 31) ->get(); + + $monthly_plans->merge($yearly_plans); } } + $recurring_invoice = RecurringInvoice::query() + ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->whereNotNull('subscription_id') + ->where('status_id', RecurringInvoice::STATUS_ACTIVE) + ->orderBy('id', 'desc') + ->first(); + + + $data['late_invoice'] = Invoice::first(); + + $monthly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + // ->where('group_id', 6) + ->orderBy('promo_price', 'ASC') + ->get(); + + $yearly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 31) + ->orderBy('promo_price', 'ASC') + ->get(); + + $monthly_plans->merge($yearly_plans); + + $current_subscription_id = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->subscription_id) : false; + + //remove existing subscription + if($current_subscription_id){ + + $monthly_plans = $monthly_plans->filter(function ($plan) use($current_subscription_id){ + return (string)$plan->hashed_id != (string)$current_subscription_id; + }); + + } + + $data['account'] = Account::first(); + $data['client'] = Auth::guard('contact')->user()->client; + $data['plans'] = $monthly_plans; + $data['current_subscription_id'] = $current_subscription_id; + $data['current_recurring_id'] = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->hashed_id) : false; + + return $this->render('plan.index', $data); } } diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 32034c05dfbd..ca8472aaa496 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -115,17 +115,16 @@ class PortalComposer $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download']; $data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar']; - - if(Ninja::isHosted() && auth('contact')->user()->company->id == config('ninja.ninja_default_company_id')) - $data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card']; - - if (auth('contact')->user()->client->getSetting('enable_client_portal_tasks')) { $data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock']; } $data[] = ['title' => ctrans('texts.statement'), 'url' => 'client.statement', 'icon' => 'activity']; + if(Ninja::isHosted() && auth('contact')->user()->company->id == config('ninja.ninja_default_company_id')) + $data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card']; + + return $data; } } diff --git a/resources/views/portal/ninja2020/plan/index.blade.php b/resources/views/portal/ninja2020/plan/index.blade.php new file mode 100644 index 000000000000..ce62369f8488 --- /dev/null +++ b/resources/views/portal/ninja2020/plan/index.blade.php @@ -0,0 +1,103 @@ +@extends('portal.ninja2020.layout.app') +@section('meta_title', ctrans('texts.pro_plan_call_to_action')) + +@section('body') + + +
+
+

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

+

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

+
+
+
+
+
+ {{ ctrans('texts.plan') }} +
+
+ {{ $account->plan ? ucfirst($account->plan) : 'Free' }} +
+
+ @if($account->plan) + +
+
+ {{ ctrans('texts.expires') }} +
+
+ {{ $client->formatDate($account->plan_expires, $client->date_format()) }} +
+
+ + @if($account->plan == 'enterprise') + +
+
+ {{ ctrans('texts.users')}} +
+
+ {{ $account->num_users }} +
+
+ + @endif + + @endif + +
+
+ {{ ctrans('texts.plan_change') }} +
+
+
+ + + @if($current_recurring_id) + + @else + + @endif + +
+
+ +
+
+
+ +@endsection + +@push('footer') + + +@endpush \ No newline at end of file From 9edd8c6de5fe894ce78dcdd2e7a7ef27489790e0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 14:31:05 +1100 Subject: [PATCH 6/7] Ninja plan --- .../ClientPortal/NinjaPlanController.php | 102 ++++++++---------- app/Http/Livewire/RequiredClientInfo.php | 8 +- .../SubscriptionRecurringInvoicesTable.php | 1 + app/PaymentDrivers/Braintree/CreditCard.php | 2 +- .../Subscription/SubscriptionService.php | 7 +- .../portal/ninja2020/plan/index.blade.php | 39 +++++-- 6 files changed, 85 insertions(+), 74 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index c2a4a1d6bd9c..e41fb872a6ef 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -69,16 +69,13 @@ class NinjaPlanController extends Controller //harvest the current plan $data = []; - if(MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); - if($account && $account->isPaidHostedClient()) + if($account) { - $data['account'] = $account; - if(Carbon::parse($account->plan_expires)->lt(now())){ //expired get the most recent invoice for payment @@ -90,69 +87,58 @@ class NinjaPlanController extends Controller ->orderBy('id', 'DESC') ->first(); - if($late_invoice) + //account status means user cannot perform upgrades until they pay their account. $data['late_invoice'] = $late_invoice; } - //build list of upgrades. + $recurring_invoice = RecurringInvoice::on('db-ninja-01') + ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->whereNotNull('subscription_id') + ->where('status_id', RecurringInvoice::STATUS_ACTIVE) + ->orderBy('id', 'desc') + ->first(); - $monthly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 6) - ->get(); + $monthly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 6) + ->orderBy('promo_price', 'ASC') + ->get(); - $yearly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 31) - ->get(); + $yearly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 31) + ->orderBy('promo_price', 'ASC') + ->get(); + + $monthly_plans = $monthly_plans->merge($yearly_plans); + + $current_subscription_id = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->subscription_id) : false; + + //remove existing subscription + if($current_subscription_id){ + + $monthly_plans = $monthly_plans->filter(function ($plan) use($current_subscription_id){ + return (string)$plan->hashed_id != (string)$current_subscription_id; + }); + + } + + $data['account'] = $account; + $data['client'] = Auth::guard('contact')->user()->client; + $data['plans'] = $monthly_plans; + $data['current_subscription_id'] = $current_subscription_id; + $data['current_recurring_id'] = $recurring_invoice ? $recurring_invoice->hashed_id : false; + + return $this->render('plan.index', $data); - $monthly_plans->merge($yearly_plans); } + } + else + return redirect()->route('client.catchall'); - $recurring_invoice = RecurringInvoice::query() - ->where('client_id', auth('contact')->user()->client->id) - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->whereNotNull('subscription_id') - ->where('status_id', RecurringInvoice::STATUS_ACTIVE) - ->orderBy('id', 'desc') - ->first(); - - - $data['late_invoice'] = Invoice::first(); - - $monthly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - // ->where('group_id', 6) - ->orderBy('promo_price', 'ASC') - ->get(); - - $yearly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 31) - ->orderBy('promo_price', 'ASC') - ->get(); - - $monthly_plans->merge($yearly_plans); - - $current_subscription_id = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->subscription_id) : false; - - //remove existing subscription - if($current_subscription_id){ - - $monthly_plans = $monthly_plans->filter(function ($plan) use($current_subscription_id){ - return (string)$plan->hashed_id != (string)$current_subscription_id; - }); - - } - - $data['account'] = Account::first(); - $data['client'] = Auth::guard('contact')->user()->client; - $data['plans'] = $monthly_plans; - $data['current_subscription_id'] = $current_subscription_id; - $data['current_recurring_id'] = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->hashed_id) : false; - - return $this->render('plan.index', $data); + } } diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php index 35372358efc1..71f0ac4f5733 100644 --- a/app/Http/Livewire/RequiredClientInfo.php +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -60,8 +60,8 @@ class RequiredClientInfo extends Component 'contact_first_name' => 'first_name', 'contact_last_name' => 'last_name', - 'contact_email' => 'email', - 'contact_phone' => 'phone', + // 'contact_email' => 'email', + // 'contact_phone' => 'phone', ]; public $show_form = false; @@ -141,7 +141,7 @@ class RequiredClientInfo extends Component $_field = $this->mappings[$field['name']]; if (Str::startsWith($field['name'], 'client_')) { - if (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field}) || $this->contact->client->{$_field} = 840) { + if (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field}) || $this->contact->client->{$_field} == 840) { $this->show_form = true; } else { $this->fields[$index]['filled'] = true; @@ -149,7 +149,7 @@ class RequiredClientInfo extends Component } if (Str::startsWith($field['name'], 'contact_')) { - if ((empty($this->contact->{$_field}) || is_null($this->contact->{$_field})) || $this->contact->client->{$_field} = 840) { + if ((empty($this->contact->{$_field}) || is_null($this->contact->{$_field})) || $this->contact->client->{$_field} == 840) { $this->show_form = true; } else { $this->fields[$index]['filled'] = true; diff --git a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php index f5ae39999f45..3568ff8cf502 100644 --- a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php +++ b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php @@ -38,6 +38,7 @@ class SubscriptionRecurringInvoicesTable extends Component ->where('client_id', auth('contact')->user()->client->id) ->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') ->withTrashed() diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 0613dfe8ab0f..f66304b52c2d 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -136,7 +136,7 @@ class CreditCard return $this->processSuccessfulPayment($result); } - $error = $result ?: 'Undefined gateway error'; + $error = 'Undefined gateway error'; return $this->processUnsuccessfulPayment($error); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index ba7da5f28670..dad9c094b8c2 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -18,6 +18,7 @@ use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Factory\RecurringInvoiceFactory; use App\Jobs\Util\SubscriptionWebhookHandler; use App\Jobs\Util\SystemLogger; +use App\Libraries\MultiDB; use App\Models\Client; use App\Models\ClientContact; use App\Models\Credit; @@ -240,10 +241,10 @@ class SubscriptionService elseif ($outstanding->count() > 1) { //user is changing plan mid frequency cycle //we cannot handle this if there are more than one invoice outstanding. - return null; + return $target->price; } - return null; + return $target->price; } @@ -439,7 +440,7 @@ class SubscriptionService $credit = false; /* Only generate a credit if the previous invoice was paid in full. */ - if($last_invoice->balance == 0) + if($last_invoice && $last_invoice->balance == 0) $credit = $this->createCredit($last_invoice, $target_subscription, $is_credit); $new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice); diff --git a/resources/views/portal/ninja2020/plan/index.blade.php b/resources/views/portal/ninja2020/plan/index.blade.php index ce62369f8488..4ab6008db659 100644 --- a/resources/views/portal/ninja2020/plan/index.blade.php +++ b/resources/views/portal/ninja2020/plan/index.blade.php @@ -1,5 +1,5 @@ @extends('portal.ninja2020.layout.app') -@section('meta_title', ctrans('texts.pro_plan_call_to_action')) +@section('meta_title', ctrans('texts.account_management')) @section('body') @@ -7,11 +7,8 @@

- {{ ctrans('texts.account_management') }} -

-

{{ ctrans('texts.plan_status') }} -

+
@@ -49,6 +46,29 @@ @endif + @if($late_invoice) + +
+

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

+

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

+
+
+
+
+ {{ ctrans('texts.invoice') }} +
+
+ {{ $late_invoice->number }} - {{ \App\Utils\Number::formatMoney($late_invoice->balance, $client) }} {{ ctrans('texts.pay_now')}} +
+
+
+ + @else +
{{ ctrans('texts.plan_change') }} @@ -71,10 +91,11 @@ {{ ctrans('texts.plan_upgrade') }} @endif -
+ @endif +
@@ -88,13 +109,15 @@ @if($current_recurring_id) document.getElementById('handlePlanChange').addEventListener('click', function() { - location.href = 'http://ninja.test:8000/client/subscriptions/{{ $current_recurring_id }}/plan_switch/' + document.getElementById("newPlan").value + ''; + if(document.getElementById("newPlan").value.length > 1) + location.href = 'https://invoiceninja.invoicing.co/client/subscriptions/{{ $current_recurring_id }}/plan_switch/' + document.getElementById("newPlan").value + ''; }); @else document.getElementById('handleNewPlan').addEventListener('click', function() { - location.href = 'http://ninja.test:8000/client/subscriptions/' + document.getElementById("newPlan").value + '/purchase'; + if(document.getElementById("newPlan").value.length > 1) + location.href = 'https://invoiceninja.invoicing.co/client/subscriptions/' + document.getElementById("newPlan").value + '/purchase'; }); @endif From 602bc327c8a5efece61974bffd955d5df48bcd0d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 17:47:21 +1100 Subject: [PATCH 7/7] Fixes for modern design --- app/Jobs/Entity/CreateRawPdf.php | 4 ++-- resources/views/pdf-designs/modern.html | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index 585deb9dbe35..c2c28b0c23f1 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -188,9 +188,9 @@ class CreateRawPdf implements ShouldQueue nlog(print_r($e->getMessage(), 1)); } - if (config('ninja.log_pdf_html')) { + // if (config('ninja.log_pdf_html')) { info($maker->getCompiledHTML()); - } + // } if ($pdf) return $pdf; diff --git a/resources/views/pdf-designs/modern.html b/resources/views/pdf-designs/modern.html index 608380e11fb4..906237dfe47b 100644 --- a/resources/views/pdf-designs/modern.html +++ b/resources/views/pdf-designs/modern.html @@ -2,8 +2,8 @@ @import url($font_url); :root { - --primary-color: #298aab; - --secondary-color: #7081e0; + --primary-color: $primary_color; + --secondary-color: $secondary_color; } body { @@ -149,13 +149,13 @@ #footer, #footer-spacer { height: 220px; - padding: 1rem 3rem; + padding: 1rem 1.5rem; margin-top: 1rem; } .footer-content { display: flex; - gap: 20px; + gap: 10px; width: 100%; /* grid-template-columns: 1fr 1fr 1fr; */ color: #fff4e9; @@ -165,8 +165,8 @@ .footer-company-details-address-wrapper { display: flex; - gap: 25px; - margin-right: 150px; + gap: 5px; + margin-right: 60px; } #company-address, @@ -348,7 +348,7 @@ $entity_images