Updates to Product Model, product updates, enable pricing update, improved formating of product services

This commit is contained in:
2023-05-04 22:17:42 +10:00
parent 95bb55aad8
commit 0f91ce4940
21 changed files with 491 additions and 138 deletions

View File

@@ -14,6 +14,12 @@
@endsection
@section('main-content')
<div class="row">
<div class="col-12">
@include('product.widget.selector')
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">

View File

@@ -16,46 +16,7 @@
@section('main-content')
<div class="row">
<div class="col-12">
<div class="card card-dark">
<div class="card-header">
<h1 class="card-title">Product Configuration</h1>
</div>
<div class="card-body">
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
@csrf
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_select',[
'label'=>'Product',
'icon'=>'fas fa-list',
'id'=>'product_id',
'old'=>'product_id',
'name'=>'product_id',
'groupby'=>'active',
'options'=>\App\Models\Product::get()->sortBy(function($item) { return ($item->active ? '0' : '1').$item->name; })->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name,'active'=>$item->active]; }),
'value'=>'',
])
</div>
</div>
</form>
</div>
</div>
@include('product.widget.selector')
</div>
</div>
@endsection
@section('page-scripts')
@css(select2)
@js(select2,autofocus)
<script type="text/javascript">
$(document).ready(function() {
$('#product_id').on('change',function(item) {
window.location.href = '{{ url('a/product/details') }}/'+item.target.value;
});
});
</script>
@append
@endsection

View File

@@ -53,64 +53,129 @@
</div>
<div class="row">
<!-- 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="col-12 col-md-3">
<div class="row">
<!-- Active -->
<div class="col-6">
@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">
<!-- Product Type -->
<div class="col-12">
@include('adminlte::widget.form_select',[
'label'=>'Product Type',
'icon'=>'fas fa-list',
'id'=>'model',
'old'=>'model',
'name'=>'model',
'options'=>\App\Models\Product::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 class="row">
<!-- Supplied Product -->
<div class="col-12" 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>
<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 class="row">
<!-- Accounting -->
<div class="col-12">
@include('adminlte::widget.form_text',[
'label'=>'Accounting',
'icon'=>'fas fa-calculator',
'id'=>'accounting',
'old'=>'accounting',
'name'=>'accounting',
'value'=>$o->accounting ?? '',
])
</div>
</div>
</div>
</div>
<div class="row">
<!-- Accounting -->
<div class="col-12 col-sm-9 col-md-12 col-xl-6">
@include('adminlte::widget.form_text',[
'label'=>'Accounting',
'icon'=>'fas fa-calculator',
'id'=>'accounting',
'old'=>'accounting',
'name'=>'accounting',
'value'=>$o->accounting ?? '',
])
<div class="col-12 offset-md-4 col-md-5">
<span class="h5">Pricing</span><small> Ex Taxes</small>
<hr>
<ul class="nav nav-pills w-100 pl-0 pt-2 pb-2">
@foreach(\App\Models\Group::pricing()->active()->get() as $go)
<li class="nav-item"><a class="nav-link @if(! $loop->index)active @endif" href="#pg_{{ $go->id }}" data-toggle="tab">{{ $go->name }}</a></li>
@endforeach
</ul>
<div class="tab-content">
@foreach(\App\Models\Group::pricing()->active()->get() as $go)
<div class="tab-pane fade @if(! $loop->index)show active @endif" id="pg_{{ $go->id }}" role="tabpanel">
@foreach(\App\Models\Invoice::billing_periods as $bp=>$detail)
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="{{ $x=sprintf('base_%d_%d',$bp,$go->id) }}">{{ $detail['name'] }} Reoccurring</label>
<div class="input-group has-validation">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa-fw fas fa-calculator"></i></span>
</div>
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][base]',$bp,$go->id) }}" {{ ($ca=$o->charge_available($bp,$go)) ? 'value' : 'placeholder' }}="{{ $c=$o->charge($bp,$go,'base') }}" @if(is_null($c) || ! $ca) disabled @endif>
<div class="input-group-append">
<div class="input-group-text">
<input type="checkbox" name="{{ sprintf('pricing[%d][show]',$bp) }}" @if($c && $ca)checked @endif>
</div>
</div>
<span class="invalid-feedback" role="alert">
@error($x)
{{ $message }}
@enderror
</span>
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="{{ $x=sprintf('setup_%d_%d',$bp,$go->id) }}">{{ $detail['name'] }} Reoccurring</label>
<div class="input-group has-validation">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa-fw fas fa-cog"></i></span>
</div>
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][setup]',$bp,$go->id) }}" {{ $ca ? 'value' : 'placeholder' }}="{{ $c=$o->charge($bp,$go,'setup') }}" @if(is_null($c) || ! $ca) disabled @endif>
<span class="invalid-feedback" role="alert">
@error($x)
{{ $message }}
@enderror
</span>
</div>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
</div>
</div>
</div>
@@ -183,6 +248,15 @@
$('#supplier_product').hide();
else
supplier_products($('#model').val(),$('#model_id'),{{ old('model_id',$o->model_id) }});
$('input[type=checkbox]').on('click',function(item) {
var input = $(this).parent().parent().parent().find('input[type="text"]');
input.prop('disabled',(i,v)=>!v);
// Find the setup input and toggle it
input = $('#'+input.attr('id').replace('base','setup')+'');
input.prop('disabled',(i,v)=>!v);
})
});
</script>
@append

View File

@@ -0,0 +1,40 @@
<!-- $o = Product::class -->
<div class="card card-dark">
<div class="card-header">
<h1 class="card-title">Product Configuration</h1>
</div>
<div class="card-body">
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
@csrf
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_select',[
'label'=>'Product',
'icon'=>'fas fa-list',
'id'=>'product_id',
'old'=>'product_id',
'name'=>'product_id',
'groupby'=>'active',
'options'=>\App\Models\Product::get()->sortBy(function($item) { return ($item->active ? '0' : '1').$item->name; })->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name,'active'=>$item->active]; }),
'value'=>isset($o) ? $o->id : NULL,
])
</div>
</div>
</form>
</div>
</div>
@section('page-scripts')
@css(select2)
@js(select2,autofocus)
<script type="text/javascript">
$(document).ready(function() {
$('#product_id').on('change',function(item) {
window.location.href = '{{ url('a/product/details') }}/'+item.target.value;
});
});
</script>
@append

View File

@@ -1,8 +1,8 @@
<!-- $o = Product::class -->
<div class="row">
@if(count($o->services))
<div class="col-6">
<table class="table table-hover">
<div class="col-7">
<table class="table table-hover w-100" id="table">
<thead>
<tr>
<th>ID</th>
@@ -10,7 +10,9 @@
<th>Date Stop</th>
<th>Data Invoiced</th>
<th>Active</th>
<th class="text-right">Charge</th>
<th class="text-right"><small>Normalized</small><br>Charge</th>
<th class="text-right"><small>Normalized</small><br>Cost</th>
<th>&nbsp;</th>
</tr>
</thead>
@@ -22,7 +24,9 @@
<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>
<td class="text-right">{{ $a=number_format($so->charge_normalized(),2) }}</td>
<td class="text-right">{{ $b=number_format($so->product->cost_normalized(),2) }}</td>
<td><button class="btn btn-sm @if($a<$b)btn-danger @else btn-success @endif"><small>@if($a<$b)<i class="fas fa-fw fa-exclamation"></i> @else <i class="fas fa-fw fa-check"></i> @endif</small></button></td>
</tr>
@endforeach
</tbody>
@@ -32,4 +36,70 @@
@else
<p>No services use this product.</p>
@endif
</div>
</div>
@section('page-scripts')
@css(datatables,bootstrap4|rowgroup|select|searchpanes|searchpanes-left)
@js(datatables,bootstrap4|rowgroup|select|searchpanes)
<style>
tr.odd td:first-child,
tr.even td:first-child {
padding-left: 3em;
}
table.dataTable tr.dtrg-group.dtrg-level-1 td {
background-color: #e0e0e0;
color: #4c110f;
}
</style>
<style>
.strike {
text-decoration: line-through;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
@if(count($o->services))
$('#table').DataTable({
paging: true,
pageLength: 25,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: false,
fixedHeader: true,
order: [[4,'desc'],[0,'asc']],
rowGroup: {
dataSrc: 4,
},
columnDefs: [
{
targets: [4],
visible: false,
}
],
language: {
searchPanes: {
clearMessage: 'Clear',
title: 'Filters: %d',
collapse: 'Filter',
}
},
searchPanes: {
cascadePanes: true,
viewTotal: true,
layout: 'columns-1',
dataLength: 20,
controls: false,
},
dom: '<"dtsp-verticalContainer"<"dtsp-verticalPanes"P><"dtsp-dataTable"Bfrtip>>',
});
$('tbody').on('click','tr', function () {
$(this).toggleClass('selected');
});
@endif
});
</script>
@append