Minor updates to order process
This commit is contained in:
@@ -52,7 +52,7 @@ class OrderReject extends Command
|
||||
}
|
||||
|
||||
$so->order_status = 'ORDER-REJECTED';
|
||||
$so->order_info = array_merge($so->order_info,['reason'=>$this->argument('reason')]);
|
||||
$so->order_info = array_merge($so->order_info ? $so->order_info : [],['reason'=>$this->argument('reason')]);
|
||||
$so->save();
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use App\Mail\OrderRequestApprove;
|
||||
use App\Mail\{OrderRequestApprove,OrderRequestReject};
|
||||
use App\Models\{Service,SiteDetails};
|
||||
|
||||
class AdminHomeController extends Controller
|
||||
@@ -34,6 +34,19 @@ class AdminHomeController extends Controller
|
||||
$o->nextStatus();
|
||||
break;
|
||||
|
||||
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_status = $x;
|
||||
$o->save();
|
||||
|
||||
// Send mail to user
|
||||
Mail::to($o->orderby->email)->queue((new OrderRequestReject($o,$request->input('notes')))->onQueue('email'));
|
||||
|
||||
break;
|
||||
|
||||
// No action specified.
|
||||
default:
|
||||
return $this->service($o);
|
||||
|
@@ -5,9 +5,11 @@ namespace App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use Igaster\LaravelTheme\Facades\Theme;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Mail\OrderRequest;
|
||||
use App\Models\{Account,Product,Service};
|
||||
use App\User;
|
||||
|
||||
@@ -115,6 +117,7 @@ class OrderController extends Controller
|
||||
$options->save();
|
||||
}
|
||||
|
||||
Mail::to('deon@graytech.net.au')->queue((new OrderRequest($so))->onQueue('email')); //@todo Get email from DB.
|
||||
return view('order_received',['o'=>$so]);
|
||||
}
|
||||
}
|
55
app/Mail/OrderRequest.php
Normal file
55
app/Mail/OrderRequest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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 OrderRequest 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()
|
||||
{
|
||||
switch ($this->service->category)
|
||||
{
|
||||
case 'ADSL': $subject = sprintf('%s: %s',$this->service->category,$this->service->service_adsl->service_address);
|
||||
break;
|
||||
|
||||
case 'VOIP': $subject = sprintf('%s: %s',$this->service->category,$this->service->service_voip->service_number);
|
||||
break;
|
||||
|
||||
default:
|
||||
$subject = 'New Order Request';
|
||||
}
|
||||
|
||||
return $this
|
||||
->markdown('email.admin.order.approve')
|
||||
->subject($subject)
|
||||
->with(['site'=>$this->service->site]);
|
||||
}
|
||||
}
|
@@ -50,8 +50,13 @@ class Service extends Model
|
||||
];
|
||||
|
||||
private $inactive_status = [
|
||||
'CANCELLED',
|
||||
'CANCELLED', // @todo Check if these should be changed to ORDER-CANCELLED
|
||||
'ORDER-REJECTED',
|
||||
'ORDER-CANCELLED',
|
||||
];
|
||||
|
||||
private $valid_status = [
|
||||
'ORDER-SUBMIT' => ['accept'=>'ORDER-SENT','reject'=>'ORDER-REJECTED'],
|
||||
];
|
||||
|
||||
public function account()
|
||||
@@ -159,6 +164,18 @@ class Service extends Model
|
||||
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will present the Order Info Details
|
||||
*/
|
||||
public function getOrderInfoDetailsAttribute()
|
||||
{
|
||||
$result = '';
|
||||
foreach ($this->order_info as $k=>$v)
|
||||
$result .= sprintf('%s: <b>%s</b><br>',ucfirst($k),$v);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getProductNameAttribute()
|
||||
{
|
||||
// @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product.
|
||||
@@ -238,4 +255,15 @@ class Service extends Model
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the proposed status is valid.
|
||||
*
|
||||
* @param string $status
|
||||
* @return string | NULL
|
||||
*/
|
||||
public function validStatus(string $status)
|
||||
{
|
||||
return array_get(array_get($this->valid_status,$this->order_status,[]),$status,NULL);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user