Some product rework
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<!-- $o = Product::class -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h3>Product Details</h3>
|
||||
<hr>
|
||||
@if(session()->has('success'))
|
||||
<span class="ml-3 pt-0 pb-0 pr-1 pl-1 btn btn-outline-success"><small>{{ session()->get('success') }}</small></span>
|
||||
@endif
|
||||
|
||||
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
|
||||
@csrf
|
||||
|
||||
<div class="row">
|
||||
<!-- Product Name -->
|
||||
<div class="col-12 col-sm-9 col-md-12 col-xl-6">
|
||||
@include('adminlte::widget.form_text',[
|
||||
'label'=>'Product Name',
|
||||
'icon'=>'fas fa-atom',
|
||||
'id'=>'name',
|
||||
'old'=>'description.name',
|
||||
'name'=>'description[name]',
|
||||
'value'=>$o->name ?? '',
|
||||
])
|
||||
</div>
|
||||
|
||||
<!-- Active -->
|
||||
<div class="col-3">
|
||||
@include('adminlte::widget.form_toggle',[
|
||||
'label'=>'Active',
|
||||
'id'=>'active',
|
||||
'old'=>'active',
|
||||
'name'=>'active',
|
||||
'value'=>$o->active ?? '',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Product Type -->
|
||||
<div class="col-12 col-sm-9 col-md-12 col-xl-6">
|
||||
@include('adminlte::widget.form_select',[
|
||||
'label'=>'Product Type',
|
||||
'icon'=>'fas fa-list',
|
||||
'id'=>'model',
|
||||
'old'=>'model',
|
||||
'name'=>'model',
|
||||
'options'=>$o->availableTypes()->transform(function($item) { return ['id'=>$item,'value'=>$item]; }),
|
||||
'value'=>get_class($o->type) ?? '',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Supplied Product -->
|
||||
<div class="col-12 col-sm-9 col-md-12 col-xl-6" id="supplier_product">
|
||||
<div class="form-group">
|
||||
<label for="model_id">Supplied Product</label>
|
||||
<div class="input-group has-validation">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa-fw fas fa-shopping-cart"></i></span>
|
||||
</div>
|
||||
<select class="form-control @error('model_id') is-invalid @enderror" id="model_id" name="model_id"></select>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error('model_id')
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Buttons -->
|
||||
<div class="col-12">
|
||||
<a href="{{ url('/home') }}" class="btn btn-danger">Cancel</a>
|
||||
@can('wholesaler')
|
||||
<button type="submit" name="submit" class="btn btn-success mr-0 float-right">@if ($o->exists)Save @else Add @endif</button>
|
||||
@endcan
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section('page-scripts')
|
||||
@css(select2)
|
||||
@js(select2,autofocus)
|
||||
|
||||
<script type="text/javascript">
|
||||
// Get a list of supplier items matching this type to populate model_id
|
||||
function supplier_products(type,destination,selected) {
|
||||
destination.prop('disabled',true);
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
data: {type: type},
|
||||
cache: false,
|
||||
url: '{{ url('api/a/supplier_products') }}',
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
// @todo add a spinner
|
||||
//spinner.toggleClass('d-none').toggleClass('fa-spin');
|
||||
alert('Failed to submit');
|
||||
},
|
||||
success: function(data) {
|
||||
destination
|
||||
.empty()
|
||||
.append($('<option>'))
|
||||
.append(data.map(function(item,key) {
|
||||
return new Option(item.name,item.id,selected && selected==item.id,selected && selected==item.id);
|
||||
}))
|
||||
.prop('disabled',false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#model').on('change',function(item) {
|
||||
if ($(this).val()) {
|
||||
$('#supplier_product').show();
|
||||
supplier_products($(this).val(),$('#model_id'));
|
||||
|
||||
} else {
|
||||
$('#supplier_product').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#model_id').select2();
|
||||
|
||||
// After we render the page, hide the supplier_product if this product has no model.
|
||||
// We do this here, because adding d-none to the div results in the select2 input not presenting correctly
|
||||
if (! $('#model').val())
|
||||
$('#supplier_product').hide();
|
||||
else
|
||||
supplier_products($('#model').val(),$('#model_id'),{{ old('model_id',$o->model_id) }});
|
||||
});
|
||||
</script>
|
||||
@append
|
@@ -0,0 +1,35 @@
|
||||
<!-- $o = Product::class -->
|
||||
<div class="row">
|
||||
@if(count($o->services))
|
||||
<div class="col-6">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Date Start</th>
|
||||
<th>Date Stop</th>
|
||||
<th>Data Invoiced</th>
|
||||
<th>Active</th>
|
||||
<th class="text-right">Charge</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($o->services as $so)
|
||||
<tr>
|
||||
<td><a href="{{ url('u/service',[$so->id]) }}">{{ $so->sid }}</a></td>
|
||||
<td>{{ $so->start_at ? $so->start_at->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $so->stop_at ? $so->stop_at->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $so->invoice_to ? $so->invoice_to->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $so->active ? 'YES' : 'NO' }}</td>
|
||||
<td class="text-right">{{ number_format($so->billing_charge,2) }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@else
|
||||
<p>No services use this product.</p>
|
||||
@endif
|
||||
</div>
|
Reference in New Issue
Block a user