Fix invoices not being generated when price is null, service update rendering updates

This commit is contained in:
Deon George 2022-10-18 17:24:53 +11:00
parent a87560ff96
commit bfd17b0686
6 changed files with 95 additions and 50 deletions

View File

@ -421,6 +421,12 @@ class ServiceController extends Controller
if ($request->post('recur_schedule')) if ($request->post('recur_schedule'))
$o->recur_schedule = $request->recur_schedule; $o->recur_schedule = $request->recur_schedule;
$o->suspend_billing = ($request->suspend_billing == 'on');
$o->external_billing = ($request->external_billing == 'on');
// @todo Cant have both price and price_override - show an exception. (price_override shows a discount, whereas price shows the price)
$o->price = $request->price ?: NULL;
$o->price_override = $request->price_override ?: NULL;
// 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

@ -1190,7 +1190,7 @@ class Service extends Model implements IDs
*/ */
public function isBilled(): bool public function isBilled(): bool
{ {
return ! ($this->external_billing || $this->suspend_billing || ($this->price == 0)); return ! ($this->external_billing || $this->suspend_billing || ($this->price === 0));
} }
/** /**

View File

@ -54,6 +54,7 @@
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Connect Date', 'label'=>'Connect Date',
'icon'=>'fas fa-calendar',
'id'=>'connect_at', 'id'=>'connect_at',
'old'=>'broadband.connect_at', 'old'=>'broadband.connect_at',
'name'=>'broadband[connect_at]', 'name'=>'broadband[connect_at]',
@ -61,21 +62,10 @@
]) ])
</div> </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>
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Contract End', 'label'=>'Contract End',
'icon'=>'fas fa-calendar',
'id'=>'expire_at', 'id'=>'expire_at',
'old'=>'broadband.expire_at', 'old'=>'broadband.expire_at',
'name'=>'broadband[expire_at]', 'name'=>'broadband[expire_at]',

View File

@ -33,6 +33,7 @@
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Expiry', 'label'=>'Expiry',
'icon'=>'fas fa-calendar',
'id'=>'expire_at', 'id'=>'expire_at',
'old'=>'domain.expire_at', 'old'=>'domain.expire_at',
'name'=>'domain[expire_at]', 'name'=>'domain[expire_at]',
@ -102,34 +103,15 @@
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Registered 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', 'icon'=>'fas fa-calendar',
'id'=>'recur_schedule', 'id'=>'start_at',
'old'=>'recur_schedule', 'old'=>'start_at',
'name'=>'recur_schedule', 'name'=>'start_at',
'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->start_at ? $o->service->start_at->format('Y-m-d') : '',
'value'=>$o->service->recur_schedule ?? '',
]) ])
</div> </div>
</div> </div>
@section('page-scripts') @section('page-scripts')

View File

@ -54,6 +54,7 @@
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Connect Date', 'label'=>'Connect Date',
'icon'=>'fas fa-calendar',
'id'=>'connect_at', 'id'=>'connect_at',
'old'=>'phone.connect_at', 'old'=>'phone.connect_at',
'name'=>'phone[connect_at]', 'name'=>'phone[connect_at]',
@ -61,21 +62,10 @@
]) ])
</div> </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>
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[ @include('adminlte::widget.form_date',[
'label'=>'Contract End', 'label'=>'Contract End',
'icon'=>'fas fa-calendar',
'id'=>'expire_at', 'id'=>'expire_at',
'old'=>'phone.expire_at', 'old'=>'phone.expire_at',
'name'=>'phone[expire_at]', 'name'=>'phone[expire_at]',

View File

@ -7,6 +7,83 @@
@csrf @csrf
<div class="row">
<!-- External Billing -->
<div class="col-2">
@include('adminlte::widget.form_toggle',[
'label'=>'External Billing',
'id'=>'external_billing',
'old'=>'external_billing',
'name'=>'external_billing',
'value'=>$o->external_billing ?? '',
])
<!-- Suspend Billing -->
@include('adminlte::widget.form_toggle',[
'label'=>'Suspend Billing',
'id'=>'suspend_billing',
'old'=>'suspend_billing',
'name'=>'suspend_billing',
'value'=>$o->suspend_billing ?? '',
])
</div>
<div class="col-1"></div>
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_date',[
'label'=>'Billing Start Date',
'icon'=>'fas fa-calendar',
'id'=>'invoice_next_at',
'old'=>'invoice_next_at',
'name'=>'invoice_next_at',
'value'=>$o->invoice_next_at ? $o->invoice_next_at->format('Y-m-d') : ($o->connect_at ? $o->connect_at->format('Y-m-d') : ''),
])
</div>
<!-- Price -->
<div class="col-12 col-sm-9 col-md-12 col-xl-3">
@include('adminlte::widget.form_text',[
'label'=>'Price',
'icon'=>'fas fa-dollar-sign',
'id'=>'price',
'old'=>'price',
'name'=>'price',
'value'=>$o->price ?? '',
])
</div>
</div>
<div class="row">
<div class="col-3"></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-redo',
'id'=>'recur_schedule',
'old'=>'recur_schedule',
'name'=>'recur_schedule',
'options'=>collect(\App\Models\Invoice::billing_periods)->transform(function($item,$key) { return ['id'=>$key,'value'=>$item['name']]; }),
'value'=>$o->recur_schedule ?? '',
])
</div>
<!-- Price Override -->
<div class="col-12 col-sm-9 col-md-12 col-xl-3">
@include('adminlte::widget.form_text',[
'label'=>'Override Price',
'icon'=>'fas fa-dollar-sign',
'id'=>'price_override',
'old'=>'price_override',
'name'=>'price_override',
'value'=>$o->price_override ?? '',
])
</div>
</div>
<hr>
@includeIf('service.widget.'.$o->product->category.'.update',['o'=>$o->type]) @includeIf('service.widget.'.$o->product->category.'.update',['o'=>$o->type])
<div class="row"> <div class="row">