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') +
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 }} | +