Add cancellation request

This commit is contained in:
Deon George 2020-04-22 22:54:05 +10:00
parent 6480f40b22
commit 1934c6dfeb
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
6 changed files with 207 additions and 3 deletions

View File

@ -19,6 +19,26 @@ class ServiceController extends Controller
public function update(Request $request,Service $o)
{
switch ($o->order_status) {
case 'CANCEL-REQUEST':
if ($request->post()) {
if (! $request->post('date_end'))
return redirect()->back()->withErrors('Cancellation Date not provided');
$o->date_end = $request->post('date_end');
foreach (['cancel_notes'] as $key) {
if ($request->post($key))
$o->setOrderInfo($key,$request->post($key));
}
$o->order_status='CANCEL-PENDING';
$o->save();
return redirect()->to(url('u/service',$o->id))->with('updated','Service cancellation submitted.');
}
return $this->update_request_cancel($o);
case 'ORDER-SENT':
if ($request->post()) {
foreach (['reference','notes'] as $key) {
@ -43,6 +63,11 @@ class ServiceController extends Controller
}
}
private function update_request_cancel(Service $o)
{
return View('u.service.order.cancel',['o'=>$o]);
}
private function update_order_status(Service $o)
{
return View('r.service.order.sent',['o'=>$o]);

View File

@ -165,6 +165,34 @@ class Service extends Model
],
// Order Confirmed by Supplier
'ORDERED' => ['update_reference'=>'ORDER-SENT'],
'ACTIVE' => [
'fail'=>FALSE,
'next'=>[
'UPGRADE-REQUEST'=>['customer'],
'CANCEL-REQUEST'=>['customer'],
],
'system'=>FALSE,
'method'=>'action_active',
'title'=>'Service Active',
],
'UPGRADE-REQUEST' => [
'fail'=>FALSE,
'next'=>[
'UPGRADE-PENDING'=>[],
],
'system'=>FALSE,
'method'=>FALSE,
'title'=>'Upgrade Service',
],
'CANCEL-REQUEST' => [
'fail'=>FALSE,
'next'=>[
'CANCEL-PENDING'=>[],
],
'system'=>FALSE,
'method'=>'action_cancel_request',
'title'=>'Cancel Service',
],
];
/**
@ -467,6 +495,10 @@ class Service extends Model
default: throw new Exception('Unknown recur_schedule');
}
// If the invoice has an end date, our invoice period shouldnt be greater than that.
if ($this->date_end AND $date > $this->date_end)
$date = $this->date_end;
return $date;
}
@ -789,6 +821,28 @@ class Service extends Model
// The action methods will return: NULL for no progress|FALSE for a failed status|next stage name.
/**
* Action required before order can leave the ACTIVE status.
*
* @return bool
*/
private function action_active(): ?bool
{
// N/A
return TRUE;
}
/**
* Request cancellation for an order when status ACTIVE stage.
* This method should have the client confirm/accept the cancellation, if it was placed by a reseller/wholesaler.
*
* @return bool
*/
private function action_cancel_request(): ?bool
{
throw new HttpException(301,url('u/service/cancel',$this->id));
}
/**
* Process for an order when status ORDER-ACCEPT stage.
* This method should have the client confirm/accept the order, if it was placed by a reseller/wholesaler.
@ -962,7 +1016,7 @@ class Service extends Model
} else {
// Cant do anything, dont have a method to check if we can leave
$stage = NULL;
abort(500,'NO Method Cannot Proceed to leave this stage: '.$next['method']);
abort(500,'NO Method Cannot Proceed to leave this stage: '.$current['method']);
}
// If valid, call the method to start the next stage
@ -1092,9 +1146,13 @@ class Service extends Model
// If the service is active, there will be service charges
if ((! $this->invoice_items->filter(function($item) { return $item->item_type==0 AND ! $item->exists; })->count())
AND ($this->active OR $this->isPending())
AND ($future == TRUE OR ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)))))
AND (
($future == TRUE AND $this->invoice_next < $this->invoice_next_end) OR
($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30))))
))
{
do {
dump(['next'=>$this->invoice_next,'stop'=>$this->invoice_next_end]);
$o = new InvoiceItem;
$o->active = TRUE;
$o->service_id = $this->id;
@ -1111,7 +1169,7 @@ class Service extends Model
$o->addTaxes($this->account->country->taxes);
$this->invoice_items->push($o);
} while ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)));
} while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30))));
}
// Add additional charges

View File

@ -0,0 +1,12 @@
<!-- Errors -->
<div class="col-12">
<div class="alert alert-danger alert-dismissible mb-0">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<h5><i class="icon fa fa-ban"></i> Whoops!</h5>
<ul>
@foreach ($errors->all() as $error)
<li>{!! $error !!}</li>
@endforeach
</ul>
</div>
</div>

View File

@ -0,0 +1,100 @@
@extends('adminlte::layouts.app')
@section('htmlheader_title')
{{ $o->sid }}
@endsection
@section('page_title')
{{ $o->sid }}
@endsection
@section('contentheader_title')
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
@endsection
@section('main-content')
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header">
<div class="card-title">Cancelling Service</div>
</div>
<!-- Errors -->
@if ($errors->any())
@include('common.service.widget.error')
@endif
<form class="form-horizontal" method="post" action="{{ url('r/service/update',$o->id) }}">
{{ csrf_field() }}
<div class="card-body">
<div class="form-group row">
<label for="reference" class="col-sm-2 col-form-label text-right">Cancel Date</label>
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div>
<input type="text" class="form-control" id="datestop" name="date_end" value="{{ ($x=$o->date_end) && $x->format('Y-m-d') ?? '' }}">
</div>
</div>
</div>
{{--
@includeIf('u.service.widgets.'.$o->stype.'.order',['o'=>$o->type])
--}}
<div class="form-group row">
<label for="notes" class="col-sm-2 col-form-label text-right">Notes</label>
<div class="col-sm-10">
<textarea class="textarea" name="cancel_notes">{{ $o->order_info_notes ?? '' }}</textarea>
</div>
</div>
</div>
<div class="card-footer">
<button type="reset" class="btn btn-secondary mr-2" onclick="window.history.go(-1); return false;">Cancel</button>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@section('page-scripts')
@css('//cdnjs.cloudflare.com/ajax/libs/summernote/0.8.12/summernote-bs4.css','summernote-css')
@js('//cdnjs.cloudflare.com/ajax/libs/summernote/0.8.12/summernote-bs4.js','summernote-js')
@js('//cdn.jsdelivr.net/momentjs/latest/moment.min.js','moment-js')
@js('//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js','daterange-js')
@css('//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css','daterange-css')
<script>
$(document).ready(function() {
$('#datestop').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
minDate: moment().add(30,'days'),
locale: {
format: 'YYYY-MM-DD'
}
});
$('.textarea').summernote({
minHeight: 350,
toolbar: [
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['view', ['codeview', 'help']],
],
});
});
</script>
@append

View File

@ -21,6 +21,12 @@
<th>Status</th>
<td>{!! $o->status_html !!}</td>
</tr>
@if ($o->date_end)
<tr>
<th>Cancellation Date</th>
<td>{{ $o->date_end->format('Y-m-d') }}</td>
</tr>
@endif
@if (($o->active OR $o->isPending()) AND ! $o->external_billing)
<tr>
<th>Billed</th>

View File

@ -66,6 +66,9 @@ Route::group(['middleware'=>['theme:adminlte-be','auth'],'prefix'=>'u'],function
Route::get('service/{o}','UserHomeController@service')
->where('o','[0-9]+')
->middleware('can:view,o');
Route::get('service/cancel/{o}','ServiceController@update')
->where('o','[0-9]+')
->middleware('can:update,o');
Route::get('service/progress/{o}/{status}','UserHomeController@service_progress')
->where('o','[0-9]+')
->middleware('can:progress,o,status');