Enable creation of domains and domain service editing

This commit is contained in:
Deon George 2022-10-18 14:17:50 +11:00
parent 0b4e3a9341
commit c96d264c8f
12 changed files with 143 additions and 25 deletions

View File

@ -108,6 +108,7 @@ class OrderController extends Controller
$so->ordered_by = Auth::id();
$so->active = FALSE;
$so->model = $order ? get_class($order) : NULL;
$so->recur_schedule = $po->price_recur_default;
if ($order && $order->order_info) {
$so->order_info = $order->order_info;

View File

@ -28,6 +28,14 @@ class ProductController extends Controller
->sortBy('name')
->values();
case 'App\Models\Product\Domain':
return Product\Domain::select(['id','supplier_item_id'])
->with(['supplied.supplier_detail.supplier'])
->get()
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier_detail->supplier->name,$item->supplied->name)]; })
->sortBy('name')
->values();
case 'App\Models\Product\Email':
return Product\Email::select(['id','supplier_item_id'])
->with(['supplied.supplier_detail.supplier'])

View File

@ -415,10 +415,12 @@ class ServiceController extends Controller
$o->type->save();
// @todo create a validator for service
if ($request->post('invoice_next_at'))
$o->invoice_next_at = $request->invoice_next_at;
if ($request->post('recur_schedule'))
$o->recur_schedule = $request->recur_schedule;
// Also update our service start_at date.
// @todo We may want to make start_at/stop_at dynamic values calculated by the type records
if ($request->post('start_at'))

View File

@ -32,7 +32,7 @@ class ProductAddEdit extends FormRequest
'active' => 'sometimes|accepted',
'model' => 'sometimes|string', // @todo Check that it is a valid model type
'model_id' => 'sometimes|int', // @todo Check that it is a valid model type
'accounting' => 'sometimes|string',
'accounting' => 'nullable|string',
];
}
}

View File

@ -12,6 +12,22 @@ final class Domain extends Type implements ProductItem
{
protected $table = 'product_domain';
// Information required during the order process
protected array $order_attributes = [
'options.domain'=>[
'request'=>'options.domain',
'key'=>'domain_name',
'validation'=>'required|min:3',
'validation_message'=>'Domain Name is a required field.',
],
'options.tld_id'=>[
'request'=>'options.tld_id',
'key'=>'tld_id',
'validation'=>'required|exists:tlds,id',
'validation_message'=>'Domain TLD is a required field.',
],
];
// The model that is referenced when this product is ordered
protected string $order_model = ServiceDomain::class;

View File

@ -800,7 +800,7 @@ class Service extends Model implements IDs
*/
public function getNameDetailAttribute()
{
return ($this->type && $this->type->getServiceDescriptionAttribute()) ? $this->type->getServiceDescriptionAttribute() : 'No Description';
return ($this->type && ($this->type->getServiceDescriptionAttribute() !== NULL)) ? $this->type->getServiceDescriptionAttribute() : 'No Description';
}
/**

View File

@ -28,11 +28,14 @@ class Domain extends Type
return [
'domain_name' => 'nullable|string|min:2',
'tld_id' => 'required|exists:tlds,id',
'expire_at' => 'required|date',
'domain_registrar_id' => 'required|exists:domain_registrars,id',
'registrar_account' => 'nullable|string',
'registrar_ns' => 'nullable|string',
'registrar_username' => 'nullable|string',
'connect_at' => 'nullable|date',
'start_at' => 'nullable|date',
'expire_at' => 'nullable|date|after:start_at',
'recur_schedule' => 'nullable|int', // @todo insure value is at least 1 yr and not higher than Invoice::billing_periods
];
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE service_domain MODIFY domain_registrar_id INT UNSIGNED DEFAULT NULL');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('ALTER TABLE service_domain MODIFY domain_registrar_id INT UNSIGNED NOT NULL');
}
};

View File

@ -18,22 +18,24 @@
<th>Domain Name</th>
<td>{{ $o->service->name }}</td>
</tr>
<tr>
<th>Registrar URL</th>
<td><a href="{{ $o->registrar->whitelabel_url }}" target="_blank" class="text-white">{{ $o->registrar->whitelabel_url }}</a></td>
</tr>
<tr>
<th>Registrar Username</th>
<td>{{ $o->registrar_username }}</td>
</tr>
<tr>
<th>Registrar Password</th>
<td>{{ $o->registrar_password }}</td>
</tr>
<tr>
<th>Domain Auth</th>
<td>{{ $o->registrar_auth_password }}</td>
</tr>
@if($o->registrar)
<tr>
<th>Registrar URL</th>
<td><a href="{{ $o->registrar->whitelabel_url }}" target="_blank" class="text-white">{{ $o->registrar->whitelabel_url }}</a></td>
</tr>
<tr>
<th>Registrar Username</th>
<td>{{ $o->registrar_username }}</td>
</tr>
<tr>
<th>Registrar Password</th>
<td>{{ $o->registrar_password }}</td>
</tr>
<tr>
<th>Domain Auth</th>
<td>{{ $o->registrar_auth_password }}</td>
</tr>
@endif
@if($o->service_connect_date)
<tr>
<th>Connected</th>
@ -41,10 +43,12 @@
</tr>
@endif
<tr>
<th>Expires</th>
<td>{{ $o->expire_at->format('Y-m-d') }} <small>({{ $o->expire_at->diffInMonths() }} months) </small></td>
</tr>
@if ($o->active)
<tr>
<th>Expires</th>
<td>{{ $o->expire_at->format('Y-m-d') }} <small>({{ $o->expire_at->diffInMonths() }} months) </small></td>
</tr>
@endif
</table>
</div>
</div>

View File

@ -95,6 +95,43 @@
</div>
</div>
<hr>
<p class="h6">Service Dates</p>
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[
'label'=>'Registered Date',
'id'=>'connect_at',
'old'=>'phone.connect_at',
'name'=>'phone[connect_at]',
'value'=>$o->connect_at ? $o->connect_at->format('Y-m-d') : '',
])
</div>
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[
'label'=>'Billing Start Date',
'id'=>'invoice_next_at',
'old'=>'invoice_next_at',
'name'=>'invoice_next_at',
'value'=>$o->service->invoice_next_at ? $o->service->invoice_next_at->format('Y-m-d') : ($o->connect_at ? $o->connect_at->format('Y-m-d') : ''),
])
</div>
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_select',[
'label'=>'Renew Term',
'icon'=>'fas fa-calendar',
'id'=>'recur_schedule',
'old'=>'recur_schedule',
'name'=>'recur_schedule',
'options'=>collect(\App\Models\Invoice::billing_periods)->filter(function ($item) { return $item['interval'] >= 12; })->transform(function($item,$key) { return ['id'=>$key,'value'=>$item['name']]; }),
'value'=>$o->service->recur_schedule ?? '',
])
</div>
</div>
@section('page-scripts')
@css(select2)
@js(select2,autofocus)

View File

@ -43,7 +43,7 @@
@if (($o->active OR $o->isPending()) AND ! $o->external_billing)
<tr>
<th>Billed</th>
<td>{{ $o->billing_period }}</td>
<td>{{ $o->billing_interval_string }}</td>
</tr>
@if($o->active AND $o->invoice_to)
<tr>

View File

@ -0,0 +1,19 @@
<fieldset class="form-group">
<label class="col-md-12">DOMAIN</label>
<div class="form-group col-sm-6 {{ $errors->has('options.domain') ? 'has-error' : '' }}">
<label for="options.domain">Domain Name</label>
<input type="text" class="form-control" id="options.domain" name="options[domain]" placeholder="Domain Name" value="{{ old('options.domain') }}">
<span class="help-block">{{ $errors->first('options.domain') }}</span>
</div>
<div class="form-group col-sm-6 {{ $errors->has('options.tld_id') ? 'has-error' : '' }}">
<label for="options.tld_id">Domain TLD</label>
<select style="width:25%;" class="form-control @error('options.tld_id') is-invalid @enderror" id="options.tld_id" name="options[tld_id]">
@foreach(\App\Models\TLD::orderBy('name')->get() as $oo)
<option value="{{ $oo->id }}" @if($oo->id == old('options.tld_id',$o->tld_id))selected @endif>{{ $oo->name }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('options.tld') }}</span>
</div>
</fieldset>