2022-08-19 15:27:57 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-16 02:29:50 +00:00
|
|
|
namespace App\Jobs\Module\WorkOrder;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
2022-09-22 06:00:03 +00:00
|
|
|
use App\Events\UserEvent;
|
2022-11-06 11:28:22 +00:00
|
|
|
use App\Models\WorkOrder\WorkOrder as WorkOrderWorkOrder;
|
2022-08-19 15:27:57 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2022-08-19 15:27:57 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
2022-09-08 16:12:02 +00:00
|
|
|
// use Illuminate\Contracts\Queue\ShouldBeUnique;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
class WorkOrder implements ShouldQueue
|
|
|
|
{
|
2022-09-08 16:12:02 +00:00
|
|
|
use InteractsWithQueue, Queueable, SerializesModels;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
protected $workOrder, $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-11-16 05:16:56 +00:00
|
|
|
public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post')
|
2022-08-19 15:27:57 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
$this->workOrder = $workOrder;
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-08-29 17:11:19 +00:00
|
|
|
$this->workOrder->load(['module']);
|
2022-08-19 15:27:57 +00:00
|
|
|
|
2022-11-16 02:29:50 +00:00
|
|
|
$http = Http::module($this->workOrder->module->api_token, $this->workOrder->module->url);
|
2022-08-19 15:27:57 +00:00
|
|
|
if ($this->type == 'put') {
|
|
|
|
$response = $http->put('work-orders/' . $this->workOrder->id, $this->workOrder->toArray());
|
|
|
|
} else {
|
|
|
|
$response = $http->post('work-orders', $this->workOrder->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$response->successful()) {
|
2022-10-31 11:03:38 +00:00
|
|
|
$this->workOrder->update([
|
|
|
|
'status' => 'error'
|
|
|
|
]);
|
2022-09-22 06:00:03 +00:00
|
|
|
} else {
|
|
|
|
broadcast(new UserEvent($this->workOrder->user_id, 'work-order.updated', $this->workOrder));
|
2022-08-19 15:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|