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->ordered_by = Auth::id();
$so->active = FALSE; $so->active = FALSE;
$so->model = $order ? get_class($order) : NULL; $so->model = $order ? get_class($order) : NULL;
$so->recur_schedule = $po->price_recur_default;
if ($order && $order->order_info) { if ($order && $order->order_info) {
$so->order_info = $order->order_info; $so->order_info = $order->order_info;

View File

@ -28,6 +28,14 @@ class ProductController extends Controller
->sortBy('name') ->sortBy('name')
->values(); ->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': case 'App\Models\Product\Email':
return Product\Email::select(['id','supplier_item_id']) return Product\Email::select(['id','supplier_item_id'])
->with(['supplied.supplier_detail.supplier']) ->with(['supplied.supplier_detail.supplier'])

View File

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

View File

@ -32,7 +32,7 @@ class ProductAddEdit extends FormRequest
'active' => 'sometimes|accepted', 'active' => 'sometimes|accepted',
'model' => 'sometimes|string', // @todo Check that it is a valid model type '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 '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'; 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 // The model that is referenced when this product is ordered
protected string $order_model = ServiceDomain::class; protected string $order_model = ServiceDomain::class;

View File

@ -800,7 +800,7 @@ class Service extends Model implements IDs
*/ */
public function getNameDetailAttribute() 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 [ return [
'domain_name' => 'nullable|string|min:2', 'domain_name' => 'nullable|string|min:2',
'tld_id' => 'required|exists:tlds,id', 'tld_id' => 'required|exists:tlds,id',
'expire_at' => 'required|date',
'domain_registrar_id' => 'required|exists:domain_registrars,id', 'domain_registrar_id' => 'required|exists:domain_registrars,id',
'registrar_account' => 'nullable|string', 'registrar_account' => 'nullable|string',
'registrar_ns' => 'nullable|string', 'registrar_ns' => 'nullable|string',
'registrar_username' => '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,6 +18,7 @@
<th>Domain Name</th> <th>Domain Name</th>
<td>{{ $o->service->name }}</td> <td>{{ $o->service->name }}</td>
</tr> </tr>
@if($o->registrar)
<tr> <tr>
<th>Registrar URL</th> <th>Registrar URL</th>
<td><a href="{{ $o->registrar->whitelabel_url }}" target="_blank" class="text-white">{{ $o->registrar->whitelabel_url }}</a></td> <td><a href="{{ $o->registrar->whitelabel_url }}" target="_blank" class="text-white">{{ $o->registrar->whitelabel_url }}</a></td>
@ -34,6 +35,7 @@
<th>Domain Auth</th> <th>Domain Auth</th>
<td>{{ $o->registrar_auth_password }}</td> <td>{{ $o->registrar_auth_password }}</td>
</tr> </tr>
@endif
@if($o->service_connect_date) @if($o->service_connect_date)
<tr> <tr>
<th>Connected</th> <th>Connected</th>
@ -41,10 +43,12 @@
</tr> </tr>
@endif @endif
@if ($o->active)
<tr> <tr>
<th>Expires</th> <th>Expires</th>
<td>{{ $o->expire_at->format('Y-m-d') }} <small>({{ $o->expire_at->diffInMonths() }} months) </small></td> <td>{{ $o->expire_at->format('Y-m-d') }} <small>({{ $o->expire_at->diffInMonths() }} months) </small></td>
</tr> </tr>
@endif
</table> </table>
</div> </div>
</div> </div>

View File

@ -95,6 +95,43 @@
</div> </div>
</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') @section('page-scripts')
@css(select2) @css(select2)
@js(select2,autofocus) @js(select2,autofocus)

View File

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