Minor updates to order process

This commit is contained in:
Deon George 2019-01-24 14:40:33 +11:00
parent a9f545412b
commit b19f01d7a4
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
9 changed files with 217 additions and 20 deletions

View File

@ -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();
}
}

View File

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

View File

@ -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
View 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]);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

View File

@ -14,13 +14,24 @@
@section('main-content')
<div class="col-md-12">
<div class="box box-primary">
<form role="form" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="box-header with-border">
<h3 class="box-title">Service Information</h3>
</div>
<div class="box-body">
<div class="col-md-3">
@switch($o->order_status)
@case('ORDER-SUBMIT')
@include('a.widgets.service.order.submit')
@break
@default
@include('u.widgets.service_info')
@endswitch
</div>
@if($o->order_status == 'ORDER-REQUEST')
@ -31,8 +42,15 @@
</div>
<div class="box-footer">
<button type="submit" class="btn btn-info">Save</button>
@switch($o->order_status)
@case('ORDER-SUBMIT')
<button type="submit" class="btn btn-info btn-danger" name="action" value="reject">Reject</button>
@break;
@endswitch
<button type="submit" class="btn btn-info" name="action" value="save">Save</button>
</div>
</form>
</div>
</div>
@endsection

View File

@ -0,0 +1,44 @@
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">New Order</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<table class="table table-condensed" width="100%">
<tr>
<th>Account</th><td>{{ $o->account->company }}</td>
</tr>
<tr>
<th>Product</th><td>{{ $o->product->name }}</td>
</tr>
@if($o->date_last_invoice)
<tr>
<th>Last Invoice</th><td>{{ $o->date_last_invoice }}</td>
</tr>
<tr>
<th>Paid Until</th><td>{{ 'TBA' }}</td>
</tr>
<tr>
<th>Next Invoice</th><td>{{ $o->date_next_invoice }}</td>
</tr>
@endif
<tr>
<th>Order Details</th><td>{!! $o->order_info_details !!}</td>
</tr>
<tr>
<th>Save/Reject Note:</th><td><input type="text" name="notes" class=""></td>
</th>
</table>
</div>
{{--
<div class="box-footer">
</div>
--}}
</div>

View File

@ -11,10 +11,10 @@
| Product | {{ $service->product_name }} |
@switch($service->category)
@case('ADSL')
| Address | {{ $service->service_adsl->service_address }} |
| Address | {{ is_object($service->service_voip) ? $service->service_voip->service_address : 'Not Supplied' }} |
@break;
@case('VOIP')
| Address | {{ $service->service_voip->service_address }} |
| Address | {{ is_object($service->service_voip) ? $service->service_voip->service_address : 'Not Supplied' }} |
| Supplier Details | {{ join(':',$service->order_info) }} |
@break;
@endswitch