Enforce registration for subscriptions if configured

This commit is contained in:
David Bomba 2022-12-20 15:50:02 +11:00
parent 2b4c3b799d
commit 971787161c
8 changed files with 63 additions and 11 deletions

View File

@ -93,6 +93,10 @@ class ClientRegistrationFields
'key' => 'vat_number',
'required' => false,
],
[
'key' => 'currency_id',
'required' => false,
],
];
return $data;

View File

@ -58,7 +58,7 @@ class ContactRegisterController extends Controller
Auth::guard('contact')->loginUsingId($client_contact->id, true);
return redirect()->route('client.dashboard');
return redirect()->intended('client.dashboard');
}
private function getClient(array $data)
@ -66,7 +66,15 @@ class ContactRegisterController extends Controller
$client = ClientFactory::create($data['company']->id, $data['company']->owner()->id);
$client->fill($data);
$client->save();
if(isset($data['currency_id'])) {
$settings = $client->settings;
$settings->currency_id = isset($data['currency_id']) ? $data['currency_id'] : $data['company']->settings->currency_id;
$client->settings = $settings;
}
$client->number = $this->getNextClientNumber($client);
$client->save();

View File

@ -53,6 +53,16 @@ class SubscriptionPurchaseController extends Controller
$this->setLocale($request->query('locale'));
}
if(!auth()->guard('contact')->check() && $subscription->registration_required && $subscription->company->client_can_register) {
session()->put('url.intended', route('client.subscription.upgrade',['subscription' => $subscription->hashed_id]));
return redirect()->route('client.register', ['company_key' => $subscription->company->company_key]);
}
elseif(!auth()->guard('contact')->check() && $subscription->registration_required && ! $subscription->company->client_can_register) {
return render('generic.subscription_blocked', ['account' => $subscription->company->account, 'company' => $subscription->company]);
}
return view('billing-portal.purchasev2', [
'subscription' => $subscription,
'hash' => Str::uuid()->toString(),

View File

@ -158,6 +158,13 @@ class BillingPortalPurchasev2 extends Component
{
MultiDB::setDb($this->company->db);
if(auth()->guard('contact')->check()){
$this->email = auth()->guard('contact')->user()->email;
$this->contact = auth()->guard('contact')->user();
$this->authenticated = true;
$this->payment_started = true;
}
$this->discount = 0;
$this->sub_total = 0;
$this->float_amount_total = 0;

View File

@ -29,14 +29,8 @@ class ProductFactory extends Factory
'cost' => $this->faker->numberBetween(1, 1000),
'price' => $this->faker->numberBetween(1, 1000),
'quantity' => $this->faker->numberBetween(1, 100),
// 'tax_name1' => 'GST',
// 'tax_rate1' => 10,
// 'tax_name2' => 'VAT',
// 'tax_rate2' => 17.5,
// 'tax_name3' => 'THIRDTAX',
// 'tax_rate3' => 5,
'custom_value1' => $this->faker->text(20),
'custom_value2' => $this->faker->text(20),
'custom_value1' => 'https://picsum.photos/200',
'custom_value2' => rand(0,100),
'custom_value3' => $this->faker->text(20),
'custom_value4' => $this->faker->text(20),
'is_deleted' => false,

View File

@ -4910,6 +4910,8 @@ $LANG = array(
'notification_purchase_order_created_subject' => 'Purchase Order :purchase_order was created for :vendor',
'notification_purchase_order_sent_subject' => 'Purchase Order :purchase_order was sent to :vendor',
'notification_purchase_order_sent' => 'The following vendor :vendor was emailed Purchase Order :purchase_order for :amount.',
'subscription_blocked' => 'This product is a restricted item, please contact the vendor for further information.',
'subscription_blocked_title' => 'Product not available.',
);
return $LANG;

View File

@ -5,9 +5,17 @@
<div class="grid lg:grid-cols-12 py-8">
<div class="col-span-12 lg:col-span-8 lg:col-start-3 xl:col-span-6 xl:col-start-4 px-6">
@if($register_company->account && !$register_company->account->isPaid())
<div class="flex justify-center">
<img class="h-32 w-auto" src="{{ $register_company->present()->logo() }}" alt="{{ ctrans('texts.logo') }}">
</div>
<img src="{{ asset('images/invoiceninja-black-logo-2.png') }}"
class="border-b border-gray-100 h-18 pb-4" alt="Invoice Ninja logo">
</div>
@elseif(isset($register_company) && !is_null($register_company))
<div class="flex justify-center">
<img src="{{ $register_company->present()->logo() }}"
class="mx-auto border-b border-gray-100 h-18 pb-4" alt="{{ $register_company->present()->name() }} logo">
</div>
@endif
<h1 class="text-center text-3xl mt-8">{{ ctrans('texts.register') }}</h1>
<p class="block text-center text-gray-600">{{ ctrans('texts.register_label') }}</p>
@ -54,6 +62,18 @@
type="password"
name="{{ $field['key'] }}"
/>
@elseif($field['key'] === 'currency_id')
<select
id="currency_id"
class="input w-full form-select bg-white"
name="currency_id">
@foreach(App\Utils\TranslationHelper::getCurrencies() as $currency)
<option
{{ $currency->id == $register_company->settings->currency_id ? 'selected' : null }} value="{{ $currency->id }}">
{{ $currency->name }}
</option>
@endforeach
</select>
@elseif($field['key'] === 'country_id')
<select
id="shipping_country"

View File

@ -196,6 +196,13 @@
</li>
@endforeach
@endif
@if(auth()->guard('contact')->check())
<li class="flex py-6">
<div class="flex w-full text-left mt-8">
<a href="{{route('client.dashboard')}}" class="button-link text-primary">{{ ctrans('texts.go_back') }}</a>
</div>
</li>
@endif
</ul>
</div>
</div>