Added command line send/reject for orders

This commit is contained in:
Deon George 2018-09-18 12:37:04 +10:00
parent cf46a2cf42
commit aeacb726dd
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
7 changed files with 202 additions and 4 deletions

View File

@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\OrderRequestReject;
use App\Models\Service;
class OrderReject extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order:reject {service : Service ID} {reason : Reason }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reject Order';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$so = Service::findOrFail($this->argument('service'));
Mail::to($so->orderby->email)->sendNow(new OrderRequestReject($so,$this->argument('reason')));
if (Mail::failures()) {
dump('Failure?');
dump(Mail::failures());
}
$so->order_status = 'ORDER-REJECTED';
$so->order_info = array_merge($so->order_info,['reason'=>$this->argument('reason')]);
$so->save();
}
}

View File

@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\OrderRequestApprove;
use App\Models\Service;
class OrderSend extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order:send {service : Service ID}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send an order to a supplier';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$so = Service::findOrFail($this->argument('service'));
// @todo TO get from DB
Mail::to('help@graytech.net.au')->sendNow(new OrderRequestApprove($so));
if (Mail::failures()) {
dump('Failure?');
dump(Mail::failures());
}
$so->order_status = 'ORDER-SENT';
$so->save();
}
}

View File

@ -50,6 +50,6 @@ class OrderRequestApprove extends Mailable
return $this
->markdown('email.admin.order.approve')
->subject($subject)
->with(['site'=>config('SITE_SETUP')]);
->with(['site'=>$this->service->site]);
}
}

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 OrderRequestReject extends Mailable
{
use Queueable, SerializesModels;
public $service;
public $reason;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Service $o,$reason)
{
$this->service = $o;
$this->reason = $reason;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->markdown('email.admin.order.reject')
->subject(sprintf('Your order: #%s was rejected',$this->service->id))
->with(['site'=>$this->service->site]);
}
}

View File

@ -56,6 +56,16 @@ class Service extends Model
return $this->belongsTo(Account::class);
}
public function orderby()
{
return $this->belongsTo(Account::class);
}
public function site()
{
return $this->belongsTo(Site::class);
}
public function service_adsl()
{
return $this->belongsTo(ServiceAdsl::class,'id','service_id');

View File

@ -68,7 +68,7 @@
language: {
emptyTable: "No Active Clients"
},
order: [1, 'asc'],
order: [3, 'asc'],
rowGroup: {
dataSrc: 'account_name',
startRender: null,
@ -76,7 +76,7 @@
return rows.count()+' x ' + group;
},
},
orderFixed: [4, 'asc']
orderFixed: [1, 'asc']
});
$('#service_movements tbody').on('click','tr', function () {
@ -84,4 +84,4 @@
});
});
</script>
@append
@append

View File

@ -0,0 +1,30 @@
@component('mail::message',['site'=>$site])
# Your order was rejected.
@component('mail::panel')
@component('mail::table')
| Service | Details |
| :---------- | :---------------- |
| Account | {{ $service->account_name }} ({!! $service->account->account_id_url !!}) |
| Service ID | {!! $service->service_id_url !!} |
| Product | {{ $service->product_name }} |
@switch($service->category)
@case('ADSL')
| Address | {{ $service->service_adsl->service_address }} |
@break;
@case('VOIP')
| Address | {{ $service->service_voip->service_address }} |
| Supplier Details | {{ join(':',$service->order_info) }} |
@break;
@endswitch
@endcomponent
**REASON:** {{ $reason }}
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent