Fix broadband plan change update

This commit is contained in:
2023-05-03 18:09:29 +10:00
parent fd110f5c6f
commit 4f19da5987
7 changed files with 67 additions and 26 deletions

View File

@@ -17,7 +17,7 @@
<!-- $o = App\Models\Service::class -->
@section('main-content')
<div class="row">
<div class="col-8">
<div class="col-4">
<form role="form" method="POST" enctype="multipart/form-data">
<div class="card card-dark">
{{ csrf_field() }}
@@ -55,8 +55,8 @@
<select class="form-control @error('broadband.product_id') is-invalid @enderror" id="product_id" name="broadband[product_id]" required>
<!-- @todo TO DO LIMIT THIS TO OF THE SAME OFFERING TYPE AND SORT BY NAME -->
@foreach (\App\Models\Product::get() as $po)
@if ($po->category !== $o->product->category) @continue @endif
<option value="{{ $po->id }}" {{ $po->id == old('broadband.product_id',$po->exists ? \Illuminate\Support\Arr::get($o->order_info,'change_product_id') : NULL) ? 'selected' : '' }}>{{ $po->name }}</option>
@if (! $po->category || ($po->category !== $o->product->category)) @continue @endif
<option value="{{ $po->id }}" {{ $po->id == old('broadband.product_id',$po->exists ? Arr::get($o->order_info,'change_product_id') : NULL) ? 'selected' : '' }}>{{ $po->name }}</option>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@@ -112,6 +112,24 @@
</div>
</div>
</div>
<div class="col-6">
<!-- NEW PRICE -->
<div class="form-group has-validation">
<label for="price" class="col-form-label text-right">New Price <small>(Override)</small></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
</div>
<input type="text" class="form-control @error('broadband.price_override') is-invalid @enderror" id="price" name="broadband[price]" value="{{ $o->price }}">
<span class="invalid-feedback" role="alert">
@error('broadband.price')
{{ $message }}
@enderror
</span>
</div>
</div>
</div>
</div>
<div class="row">
@@ -126,8 +144,31 @@
</div>
</form>
</div>
<!-- Current Plan -->
<div class="col-4">
@include('service.widget.internal')
<div class="card card-dark">
<div class="card-body">
<div class="card-header">
<h3 class="card-title">Current Plan</h3>
</div>
@include('service.widget.internal',['o'=>$o,'p'=>$o->product])
</div>
</div>
</div>
<!-- Proposed Plan -->
<div class="col-4">
<div class="card card-dark">
<div class="card-body">
<div class="card-header">
<h3 class="card-title">Proposed Plan</h3>
</div>
@include('service.widget.internal',['o'=>$o,'p'=>\App\Models\Product::where('id',Arr::get($o->order_info,'change_product_id'))->singleOrFail()])
</div>
</div>
</div>
</div>
<div id="transactions"></div>

View File

@@ -89,7 +89,7 @@
</div>
@can('wholesaler')
<div class="tab-pane fade" id="internal" role="tabpanel">
@include('service.widget.internal')
@include('service.widget.internal',['o'=>$o,'p'=>$o->product])
</div>
<div class="tab-pane fade {{ session()->pull('service_update') ? 'active show' : '' }}" id="update" role="tabpanel">

View File

@@ -1,4 +1,4 @@
<!-- $o = Service::class -->
<!-- $o = Service::class, $p = Product::class -->
<table class="table table-sm">
<thead>
<tr>
@@ -19,16 +19,16 @@
@if ($s->exists)
<td>#{{ $s->id }}: {{ $s->name }}</td>
@endif
<td>#{{ $o->product->id }}: {{ $o->product->name }}</td>
<td>#{{ $p->id }}: {{ $p->name }}</td>
@if ($s->exists)
<td>{{ $o->product->category_name }}</td>
<td>{{ $p->category_name }}</td>
@endif
</tr>
<tr>
<th>Setup</th>
@if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->setup_cost,$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->setup_charge,$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($p->setup_charge,$o->account->taxes),2) }}</td>
<td>{!! markup($a,$b) !!}</td>
@else
<td>-</td>
@@ -47,7 +47,7 @@
<tr>
<th>Billing Price</th>
@if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$o->product->billing_interval),$o->account->taxes),2) }}</td>
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,$p->billing_interval),$o->account->taxes),2) }}</td>
@endif
<td>${{ number_format($b=$o->billing_charge,2) }}</td>
@if ($s->exists)
@@ -59,7 +59,7 @@
@if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->base_cost*\App\Models\Invoice::billing_change($s->billing_interval,1),$o->account->taxes),2) }}</td>
@endif
<td>${{ number_format($b=$o->billing_monthly_price,2) }}</td>
<td @if($x=$o->isChargeOverriden()) class="text-danger" @endif>${{ number_format($b=($x ? $p->base_charge_taxable : $o->billing_monthly_price),2) }}</td>
@if ($s->exists)
<td>{!! markup($a,$b) !!}</td>
@endif
@@ -69,7 +69,7 @@
@if ($s->exists)
<td>{{ $s->contract_term }} months</td>
@endif
<td>{{ $o->contract_term }} months</td>
<td>{{ $p->contract_term }} months</td>
@if ($s->exists)
<td>&nbsp;</td>
@endif
@@ -78,19 +78,11 @@
<th>Min Price</th>
@if ($s->exists)
<td>${{ number_format($a=\App\Models\Tax::tax_calc($s->min_cost,$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($o->product->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }}</td>
<td>${{ number_format($b=\App\Models\Tax::tax_calc($p->getMinChargeAttribute($o->billing_interval),$o->account->taxes),2) }}</td>
<td>{!! markup($a,$b) !!}</td>
@else
<td>-</td>
@endif
</tr>
</tbody>
</table>
@php
function markup($a,$b) {
return ($a > $b)
? sprintf('<span class="badge bg-danger>">(%3.1f%%)</span>',$a ? ($b-$a)/($b ?: 1)*100 : 100)
: sprintf('<span class="badge">%3.1f%%</span>',$a ? ($b-$a)/($b ?: 1)*100 : ($b ? 100: 0));
}
@endphp
</table>