Some order processing

This commit is contained in:
Deon George 2018-08-23 15:17:26 +10:00
parent 90bcb7f5f1
commit 27fdb334d0
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
14 changed files with 333 additions and 27 deletions

View File

@ -5,11 +5,43 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Mail;
use App\Models\SiteDetails; use App\Mail\OrderRequestApprove;
use App\Models\{Service,SiteDetails};
class AdminHomeController extends Controller class AdminHomeController extends Controller
{ {
public function service(Service $o)
{
return View('a.service',['o'=>$o]);
}
public function service_update(Request $request, Service $o)
{
switch (strtolower($request->input('action')))
{
case 'approve':
// Send an email to the supplier.
// @todo Change to address to suppliers email address.
Mail::to('help@graytech.net.au')
->queue((new OrderRequestApprove($o,$request->input('order_notes') ?: 'NONE'))->onQueue('high'));
// Send an email to the client.
// @todo Your order has been submitted to supplier.
// Update the service to "ORDER-SENT"
$o->nextStatus();
break;
// No action specified.
default:
return $this->service($o);
}
return redirect(url('/a/service/',[$o->id]));
}
public function setup() public function setup()
{ {
return view('a.setup'); return view('a.setup');

View File

@ -3,7 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Models\Invoice; use App\Models\{Invoice,Service};
use App\User; use App\User;
use PDF; use PDF;
@ -14,16 +14,6 @@ class UserHomeController extends Controller
$this->middleware('auth'); $this->middleware('auth');
} }
public function invoice(Invoice $o)
{
return View('u.invoice',['o'=>$o]);
}
public function invoice_pdf(Invoice $o)
{
return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id));
}
public function home() public function home()
{ {
switch (Auth::user()->role()) { switch (Auth::user()->role()) {
@ -41,6 +31,16 @@ class UserHomeController extends Controller
} }
} }
public function invoice(Invoice $o)
{
return View('u.invoice',['o'=>$o]);
}
public function invoice_pdf(Invoice $o)
{
return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id));
}
/** /**
* Helper to redirect to the old site, when functions are not available in this one. * Helper to redirect to the old site, when functions are not available in this one.
* *
@ -55,6 +55,11 @@ class UserHomeController extends Controller
abort(307,sprintf('http://www.graytech.net.au/u/%s/%s/%s',$type,$action,$id)); abort(307,sprintf('http://www.graytech.net.au/u/%s/%s/%s',$type,$action,$id));
} }
public function service(Service $o)
{
return View('u.service',['o'=>$o]);
}
public function User(User $o) public function User(User $o)
{ {
// @todo Check authorised to see this account. // @todo Check authorised to see this account.

View File

@ -0,0 +1,42 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Service;
class OrderRequestApprove extends Mailable
{
use Queueable, SerializesModels;
public $service;
public $notes;
/**
* Create a new message instance.
*
* @param Service $o
* @param string $notes
*/
public function __construct(Service $o,$notes='')
{
$this->service = $o;
$this->notes = $notes;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->markdown('email.admin.order.approve')
->with(['site'=>config('SITE_SETUP')]);
}
}

View File

@ -22,6 +22,7 @@ class Service extends Model
protected $appends = [ protected $appends = [
'account_name', 'account_name',
'admin_service_id_url',
'category', 'category',
'name', 'name',
'next_invoice', 'next_invoice',
@ -33,6 +34,7 @@ class Service extends Model
protected $visible = [ protected $visible = [
'account_name', 'account_name',
'admin_service_id_url',
'active', 'active',
'category', 'category',
'data_orig', 'data_orig',
@ -99,6 +101,11 @@ class Service extends Model
return $this->account->company; return $this->account->company;
} }
public function getAdminServiceIdUrlAttribute()
{
return sprintf('<a href="/a/service/%s">%s</a>',$this->id,$this->service_id);
}
public function getCategoryAttribute() public function getCategoryAttribute()
{ {
return $this->product->category; return $this->product->category;
@ -162,6 +169,19 @@ class Service extends Model
return $this->active OR ($this->order_status AND ! in_array($this->order_status,$this->inactive_status)); return $this->active OR ($this->order_status AND ! in_array($this->order_status,$this->inactive_status));
} }
public function nextStatus() {
switch ($this->order_status)
{
case 'ORDER-REQUEST':
$this->order_status = 'ORDER-SENT';
$this->save();
return $this;
default:
abort(500,'Next Status not set up for:'.$this->order_status);
}
}
/** /**
* This function will return the associated service model for the product type * This function will return the associated service model for the product type
*/ */

View File

@ -226,6 +226,7 @@ class User extends Authenticatable
return $result->flatten(); return $result->flatten();
} }
public function all_clients($level=0) public function all_clients($level=0)
{ {
$result = collect(); $result = collect();
@ -286,6 +287,11 @@ class User extends Authenticatable
return in_array($this->role(),['wholesaler','reseller']); return in_array($this->role(),['wholesaler','reseller']);
} }
public function isWholesaler()
{
return in_array($this->role(),['wholesaler']);
}
public function role() public function role()
{ {
// If I have agents and no parent, I am the wholesaler // If I have agents and no parent, I am the wholesaler

View File

@ -0,0 +1,38 @@
@extends('adminlte::layouts.app')
@section('htmlheader_title')
Service #{{ $o->id }}
@endsection
@section('contentheader_title')
Service #
@endsection
@section('contentheader_description')
{{ $o->service_id }}
@endsection
@section('main-content')
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Service Information</h3>
</div>
<div class="box-body">
<div class="col-md-3">
@include('u.widgets.service_info')
</div>
@if($o->order_status == 'ORDER-REQUEST')
<div class="col-md-3">
@include('a.widgets.service_order-request')
</div>
@endif
</div>
<div class="box-footer">
<button type="submit" class="btn btn-info">Save</button>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,49 @@
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Service Order Information</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i></button>
</div>
</div>
<form role="form" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="box-body">
<table class="table table-condensed" width="100%">
<tr>
<th>Order Info</th>
<td>{{ $o->order_info ? join('|',$o->order_info) : '*NONE*' }}</td>
</tr>
<tr>
<th>Order Notes</th>
<td>{{ $o->order_notes ?: '*NONE*' }}</td>
</tr>
<tr>
<td colspan="2">
<div class="row">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_notes') ? 'has-error' : '' }}">
<span class="help-block">{{ $errors->first('product_options') }}</span>
</div>
<div class="control-group form-group col-sm-12 {{ $errors->has('order_notes') ? 'has-error' : '' }}">
<label for="order_notes">Notes To Supplier/Client</label>
<textarea name="order_notes" class="form-control" rows="4" placeholder="APPROVE goes to Supplier, REJECT goes to Client.">{{ old('order_notes') }}</textarea>
<span class="help-block">{{ $errors->first('order_notes') }}</span>
</div>
</div>
</td>
</tr>
</table>
</div>
<div class="box-footer">
<input class="btn btn-success" type="submit" name="action" value="Approve">
<input class="btn btn-danger" type="submit" name="action" value="Reject">
</div>
</form>
</div>

View File

@ -53,24 +53,30 @@
url: "/api/r/service_movements" url: "/api/r/service_movements"
}, },
columns: [ columns: [
{ data: "service_id_url" }, { data:
{ data: "account_name" }, @if($user->isWholesaler())
"admin_service_id_url"
@else
"service_id_url"
@endif
},
{ data: "account_name" },
{ data: "name" }, { data: "name" },
{ data: "status" }, { data: "status" },
{ data: "product_name" } { data: "product_name" }
], ],
language: { language: {
emptyTable: "No Active Clients" emptyTable: "No Active Clients"
}, },
order: [1, 'asc'], order: [1, 'asc'],
rowGroup: { rowGroup: {
dataSrc: 'product_name', dataSrc: 'account_name',
startRender: null, startRender: null,
endRender: function ( rows, group ) { endRender: function ( rows, group ) {
return rows.count()+' x ' + group; return rows.count()+' x ' + group;
}, },
}, },
orderFixed: [4, 'asc'] orderFixed: [4, 'asc']
}); });
$('#service_movements tbody').on('click','tr', function () { $('#service_movements tbody').on('click','tr', function () {

View File

@ -0,0 +1,46 @@
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Service Information</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<table class="table table-condensed" width="100%">
<tr>
<th>Account</th><td>{{ $o->account->company }}</td>
</tr>
<tr>
<th>Active</th><td>{{ $o->active }} ({{ $o->order_status }})</td>
</tr>
<tr>
<th>Billing Period</th><td>{{ $o->recur_schedule }}</td>
</tr>
<tr>
<th>Billing Amount</th><td>{{ $o->cost }}</td>
</tr>
<tr>
<th>Product</th><td>{{ $o->product->name }}</td>
</tr>
<tr>
<th>Last Invoice</th><td>{{ $o->date_last_invoice }}</td>
</tr>
<tr>
<th>Paid Until</th><td>{{ 'TBA' }}</td>
</tr>
<tr>
<th>Next Invoice</th><td>{{ $o->date_next_invoice }}</td>
</tr>
</table>
</div>
{{--
<div class="box-footer">
</div>
--}}
</div>

View File

@ -219,6 +219,35 @@
@endif @endif
</div> </div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Additional Notes -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Notes</h4>
</div>
<div class="panel-collapse margin-bottom-20">
<div class="panel-body">
<div class="col-md-12">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_notes') ? 'has-error' : '' }}">
<span class="help-block">{{ $errors->first('product_options') }}</span>
</div>
<div class="control-group form-group col-sm-12 {{ $errors->has('order_notes') ? 'has-error' : '' }}">
<label for="order_notes">Notes</label>
<textarea name="order_notes" class="form-control" rows="4" placeholder="Enter any special instructions...">{{ old('order_notes') }}</textarea>
<span class="help-block">{{ $errors->first('order_notes') }}</span>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div> <div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2 pull-right"><input type="submit" class="btn btn-block btn-primary" value="Submit Order"></div> <div class="col-sm-2 pull-right"><input type="submit" class="btn btn-block btn-primary" value="Submit Order"></div>

View File

@ -0,0 +1,30 @@
@component('mail::message',['site'=>$site])
# Please order the following service.
@component('mail::panel')
@component('mail::table')
| Service | Details |
| :---------- | :---------------- |
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) |
| Service ID | {!! $service->service_id_url !!} |
| Product | {{ $service->product_name }} |
@switch($service->category)
@case('ADSL')
| Address | {{ $service->service_adsl->service_address }} |
@break;
@case('VOIP')
| Address | {{ $service->service_voip->service_address }} |
| Supplier Details | {{ join(':',$service->order_info) }} |
@break;
@endswitch
@endcomponent
**NOTES:** {{ $notes }}
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent

View File

@ -4,4 +4,4 @@
<img class="pull-left" src="{{ $logo }}"> <div class="pull-right">{{ $slot }}</div> <img class="pull-left" src="{{ $logo }}"> <div class="pull-right">{{ $slot }}</div>
</a> </a>
</td> </td>
</tr> </tr>

View File

@ -1,8 +1,8 @@
@component('mail::layout') @component('mail::layout')
{{-- Header --}} {{-- Header --}}
@slot('header') @slot('header')
@component('mail::header', ['url' => config('app.url'),'logo'=>url($logo)]) @component('mail::header', ['url' => config('app.url'),'logo'=>url($site->site_logo)])
{{ $site_name }} {{ $site->site_name }}
@endcomponent @endcomponent
@endslot @endslot
@ -24,4 +24,4 @@
&copy; {{ date('Y') }} {{ config('app.name') }}. All rights reserved. &copy; {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
@endcomponent @endcomponent
@endslot @endslot
@endcomponent @endcomponent

View File

@ -21,6 +21,8 @@ Route::get('image/generic/{width}/{height}/{color}/{name?}','MediaController@ima
Route::group(['middleware'=>['theme:adminlte-be','auth','role:wholesaler'],'prefix'=>'a'], function() { Route::group(['middleware'=>['theme:adminlte-be','auth','role:wholesaler'],'prefix'=>'a'], function() {
Route::get('setup','AdminHomeController@setup'); Route::get('setup','AdminHomeController@setup');
Route::post('setup','AdminHomeController@setup_update'); Route::post('setup','AdminHomeController@setup_update');
Route::get('service/{o}', 'AdminHomeController@service');
Route::post('service/{o}', 'AdminHomeController@service_update');
//Route::get('accounting/connect', 'AccountingController@connect'); //Route::get('accounting/connect', 'AccountingController@connect');
}); });
@ -41,6 +43,7 @@ Route::group(['middleware'=>['theme:adminlte-be','auth'],'prefix'=>'u'], functio
Route::get('home', 'UserHomeController@home'); Route::get('home', 'UserHomeController@home');
Route::get('invoice/{o}', 'UserHomeController@invoice'); Route::get('invoice/{o}', 'UserHomeController@invoice');
Route::get('invoice/{o}/pdf','UserHomeController@invoice_pdf'); Route::get('invoice/{o}/pdf','UserHomeController@invoice_pdf');
Route::get('service/{o}', 'UserHomeController@service');
}); });
// Frontend Routes (Non-Authed Users) // Frontend Routes (Non-Authed Users)