From 27fdb334d0d7ad4969702a70cb2df974cc5a6afe Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 23 Aug 2018 15:17:26 +1000 Subject: [PATCH] Some order processing --- app/Http/Controllers/AdminHomeController.php | 34 ++++++++++++- app/Http/Controllers/UserHomeController.php | 27 +++++----- app/Mail/OrderRequestApprove.php | 42 ++++++++++++++++ app/Models/Service.php | 20 ++++++++ app/User.php | 6 +++ .../backend/adminlte/a/service.blade.php | 38 ++++++++++++++ .../a/widgets/service_order-request.blade.php | 49 +++++++++++++++++++ .../adminlte/r/service_movements.blade.php | 28 ++++++----- .../adminlte/u/widgets/service_Info.blade.php | 46 +++++++++++++++++ .../theme/frontend/metronic/order.blade.php | 29 +++++++++++ .../views/email/admin/order/approve.blade.php | 30 ++++++++++++ .../views/vendor/mail/html/header.blade.php | 2 +- .../views/vendor/mail/html/message.blade.php | 6 +-- routes/web.php | 3 ++ 14 files changed, 333 insertions(+), 27 deletions(-) create mode 100644 app/Mail/OrderRequestApprove.php create mode 100644 resources/theme/backend/adminlte/a/service.blade.php create mode 100644 resources/theme/backend/adminlte/a/widgets/service_order-request.blade.php create mode 100644 resources/theme/backend/adminlte/u/widgets/service_Info.blade.php create mode 100644 resources/views/email/admin/order/approve.blade.php diff --git a/app/Http/Controllers/AdminHomeController.php b/app/Http/Controllers/AdminHomeController.php index 0f521b8..8ddc671 100644 --- a/app/Http/Controllers/AdminHomeController.php +++ b/app/Http/Controllers/AdminHomeController.php @@ -5,11 +5,43 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; 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 { + 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() { return view('a.setup'); diff --git a/app/Http/Controllers/UserHomeController.php b/app/Http/Controllers/UserHomeController.php index 0367d79..74df1f4 100644 --- a/app/Http/Controllers/UserHomeController.php +++ b/app/Http/Controllers/UserHomeController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Support\Facades\Auth; -use App\Models\Invoice; +use App\Models\{Invoice,Service}; use App\User; use PDF; @@ -14,16 +14,6 @@ class UserHomeController extends Controller $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() { 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. * @@ -55,6 +55,11 @@ class UserHomeController extends Controller 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) { // @todo Check authorised to see this account. diff --git a/app/Mail/OrderRequestApprove.php b/app/Mail/OrderRequestApprove.php new file mode 100644 index 0000000..64818a4 --- /dev/null +++ b/app/Mail/OrderRequestApprove.php @@ -0,0 +1,42 @@ +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')]); + } +} \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index 3154c1f..ec03ee7 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -22,6 +22,7 @@ class Service extends Model protected $appends = [ 'account_name', + 'admin_service_id_url', 'category', 'name', 'next_invoice', @@ -33,6 +34,7 @@ class Service extends Model protected $visible = [ 'account_name', + 'admin_service_id_url', 'active', 'category', 'data_orig', @@ -99,6 +101,11 @@ class Service extends Model return $this->account->company; } + public function getAdminServiceIdUrlAttribute() + { + return sprintf('%s',$this->id,$this->service_id); + } + public function getCategoryAttribute() { 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)); } + 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 */ diff --git a/app/User.php b/app/User.php index d82e3fa..1842ede 100644 --- a/app/User.php +++ b/app/User.php @@ -226,6 +226,7 @@ class User extends Authenticatable return $result->flatten(); } + public function all_clients($level=0) { $result = collect(); @@ -286,6 +287,11 @@ class User extends Authenticatable return in_array($this->role(),['wholesaler','reseller']); } + public function isWholesaler() + { + return in_array($this->role(),['wholesaler']); + } + public function role() { // If I have agents and no parent, I am the wholesaler diff --git a/resources/theme/backend/adminlte/a/service.blade.php b/resources/theme/backend/adminlte/a/service.blade.php new file mode 100644 index 0000000..b8fe3c6 --- /dev/null +++ b/resources/theme/backend/adminlte/a/service.blade.php @@ -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') +
+
+
+

Service Information

+
+ +
+
+ @include('u.widgets.service_info') +
+ + @if($o->order_status == 'ORDER-REQUEST') +
+ @include('a.widgets.service_order-request') +
+ @endif +
+ + +
+
+@endsection \ No newline at end of file diff --git a/resources/theme/backend/adminlte/a/widgets/service_order-request.blade.php b/resources/theme/backend/adminlte/a/widgets/service_order-request.blade.php new file mode 100644 index 0000000..34457f0 --- /dev/null +++ b/resources/theme/backend/adminlte/a/widgets/service_order-request.blade.php @@ -0,0 +1,49 @@ +
+
+

Service Order Information

+
+ + +
+
+ +
+ {{ csrf_field() }} + +
+ + + + + + + + + + + + + +
Order Info{{ $o->order_info ? join('|',$o->order_info) : '*NONE*' }}
Order Notes{{ $o->order_notes ?: '*NONE*' }}
+
+
+ {{ $errors->first('product_options') }} +
+ +
+ + + {{ $errors->first('order_notes') }} +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/resources/theme/backend/adminlte/r/service_movements.blade.php b/resources/theme/backend/adminlte/r/service_movements.blade.php index 8e0604a..3814080 100644 --- a/resources/theme/backend/adminlte/r/service_movements.blade.php +++ b/resources/theme/backend/adminlte/r/service_movements.blade.php @@ -53,24 +53,30 @@ url: "/api/r/service_movements" }, columns: [ - { data: "service_id_url" }, - { data: "account_name" }, + { data: + @if($user->isWholesaler()) + "admin_service_id_url" + @else + "service_id_url" + @endif + }, + { data: "account_name" }, { data: "name" }, - { data: "status" }, + { data: "status" }, { data: "product_name" } ], language: { emptyTable: "No Active Clients" }, order: [1, 'asc'], - rowGroup: { - dataSrc: 'product_name', - startRender: null, - endRender: function ( rows, group ) { - return rows.count()+' x ' + group; - }, - }, - orderFixed: [4, 'asc'] + rowGroup: { + dataSrc: 'account_name', + startRender: null, + endRender: function ( rows, group ) { + return rows.count()+' x ' + group; + }, + }, + orderFixed: [4, 'asc'] }); $('#service_movements tbody').on('click','tr', function () { diff --git a/resources/theme/backend/adminlte/u/widgets/service_Info.blade.php b/resources/theme/backend/adminlte/u/widgets/service_Info.blade.php new file mode 100644 index 0000000..1c505e4 --- /dev/null +++ b/resources/theme/backend/adminlte/u/widgets/service_Info.blade.php @@ -0,0 +1,46 @@ +
+
+

Service Information

+
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Account{{ $o->account->company }}
Active{{ $o->active }} ({{ $o->order_status }})
Billing Period{{ $o->recur_schedule }}
Billing Amount{{ $o->cost }}
Product{{ $o->product->name }}
Last Invoice{{ $o->date_last_invoice }}
Paid Until{{ 'TBA' }}
Next Invoice{{ $o->date_next_invoice }}
+ +
+ + {{-- + + --}} +
\ No newline at end of file diff --git a/resources/theme/frontend/metronic/order.blade.php b/resources/theme/frontend/metronic/order.blade.php index 276a228..c0c0c44 100644 --- a/resources/theme/frontend/metronic/order.blade.php +++ b/resources/theme/frontend/metronic/order.blade.php @@ -219,6 +219,35 @@ @endif +
+
+
+
+ + + + + + +
+
+

Notes

+
+ +
+
+
+
+ {{ $errors->first('product_options') }} +
+ +
+ + + {{ $errors->first('order_notes') }} +
+
+
diff --git a/resources/views/email/admin/order/approve.blade.php b/resources/views/email/admin/order/approve.blade.php new file mode 100644 index 0000000..1cc1c78 --- /dev/null +++ b/resources/views/email/admin/order/approve.blade.php @@ -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,
+{{ config('app.name') }} +@endcomponent \ No newline at end of file diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.php index 3929217..1e8c69e 100644 --- a/resources/views/vendor/mail/html/header.blade.php +++ b/resources/views/vendor/mail/html/header.blade.php @@ -4,4 +4,4 @@
{{ $slot }}
- + \ No newline at end of file diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php index 725fd5c..2a39d34 100644 --- a/resources/views/vendor/mail/html/message.blade.php +++ b/resources/views/vendor/mail/html/message.blade.php @@ -1,8 +1,8 @@ @component('mail::layout') {{-- Header --}} @slot('header') - @component('mail::header', ['url' => config('app.url'),'logo'=>url($logo)]) - {{ $site_name }} + @component('mail::header', ['url' => config('app.url'),'logo'=>url($site->site_logo)]) + {{ $site->site_name }} @endcomponent @endslot @@ -24,4 +24,4 @@ © {{ date('Y') }} {{ config('app.name') }}. All rights reserved. @endcomponent @endslot -@endcomponent +@endcomponent \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index f1ab494..f50924c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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::get('setup','AdminHomeController@setup'); 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'); }); @@ -41,6 +43,7 @@ Route::group(['middleware'=>['theme:adminlte-be','auth'],'prefix'=>'u'], functio Route::get('home', 'UserHomeController@home'); Route::get('invoice/{o}', 'UserHomeController@invoice'); Route::get('invoice/{o}/pdf','UserHomeController@invoice_pdf'); + Route::get('service/{o}', 'UserHomeController@service'); }); // Frontend Routes (Non-Authed Users)