Some order processing

This commit is contained in:
Deon George
2018-08-23 15:17:26 +10:00
parent 90bcb7f5f1
commit 27fdb334d0
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\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');

View File

@@ -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.

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 = [
'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('<a href="/a/service/%s">%s</a>',$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
*/

View File

@@ -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