Added approve action to order view

This commit is contained in:
Deon George 2019-01-24 17:16:51 +11:00
parent b19f01d7a4
commit 95bd89aa93
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
3 changed files with 23 additions and 17 deletions

View File

@ -19,7 +19,12 @@ class AdminHomeController extends Controller
public function service_update(Request $request, Service $o) public function service_update(Request $request, Service $o)
{ {
switch (strtolower($request->input('action'))) if (! $o->validStatus(strtolower($request->input('action'))))
return $this->service($o);
$action = strtolower($request->input('action'));
switch ($action)
{ {
case 'approve': case 'approve':
// Send an email to the supplier. // Send an email to the supplier.
@ -31,20 +36,17 @@ class AdminHomeController extends Controller
// @todo Your order has been submitted to supplier. // @todo Your order has been submitted to supplier.
// Update the service to "ORDER-SENT" // Update the service to "ORDER-SENT"
$o->nextStatus(); $o->nextStatus($action);
break; break;
case 'reject': case 'reject':
if (! $x=$o->validStatus(strtolower($request->input('action'))))
return $this->service($o);
$o->order_info = array_merge($o->order_info ? $o->order_info : [],['reason'=>$request->input('notes')]); $o->order_info = array_merge($o->order_info ? $o->order_info : [],['reason'=>$request->input('notes')]);
$o->order_status = $x;
$o->save();
// Send mail to user // Send mail to user
Mail::to($o->orderby->email)->queue((new OrderRequestReject($o,$request->input('notes')))->onQueue('email')); Mail::to($o->orderby->email)->queue((new OrderRequestReject($o,$request->input('notes')))->onQueue('email'));
$o->nextStatus($action);
break; break;
// No action specified. // No action specified.

View File

@ -56,7 +56,7 @@ class Service extends Model
]; ];
private $valid_status = [ private $valid_status = [
'ORDER-SUBMIT' => ['accept'=>'ORDER-SENT','reject'=>'ORDER-REJECTED'], 'ORDER-SUBMIT' => ['approve'=>'ORDER-SENT','reject'=>'ORDER-REJECTED'],
]; ];
public function account() public function account()
@ -167,9 +167,13 @@ class Service extends Model
/** /**
* This function will present the Order Info Details * This function will present the Order Info Details
*/ */
public function getOrderInfoDetailsAttribute() public function getOrderInfoDetailsAttribute(): string
{ {
if (! $this->order_info)
return '';
$result = ''; $result = '';
foreach ($this->order_info as $k=>$v) foreach ($this->order_info as $k=>$v)
$result .= sprintf('%s: <b>%s</b><br>',ucfirst($k),$v); $result .= sprintf('%s: <b>%s</b><br>',ucfirst($k),$v);
@ -222,17 +226,16 @@ 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() { public function nextStatus(string $status) {
switch ($this->order_status) if ($x=$this->validStatus($status))
{ {
case 'ORDER-REQUEST': $this->order_status = $x;
$this->order_status = 'ORDER-SENT'; $this->save();
$this->save();
return $this;
default: return $this;
abort(500,'Next Status not set up for:'.$this->order_status);
} }
abort(500,'Next Status not set up for:'.$this->order_status);
} }
/** /**

View File

@ -45,6 +45,7 @@
@switch($o->order_status) @switch($o->order_status)
@case('ORDER-SUBMIT') @case('ORDER-SUBMIT')
<button type="submit" class="btn btn-info btn-danger" name="action" value="reject">Reject</button> <button type="submit" class="btn btn-info btn-danger" name="action" value="reject">Reject</button>
<button type="submit" class="btn btn-info btn-warning" name="action" value="approve">Approve</button>
@break; @break;
@endswitch @endswitch