2022-08-19 15:27:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Remote\WorkOrder;
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
|
use App\Models\WorkOrder\Reply as WorkOrderReply;
|
2022-08-29 17:11:19 +00:00
|
|
|
use Log;
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
class Reply implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $reply;
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(WorkOrderReply $reply)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
$this->reply = $reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
//
|
2022-08-29 17:11:19 +00:00
|
|
|
$this->reply->load(['workOrder', 'user']);
|
|
|
|
$this->reply->workOrder->load(['module']);
|
|
|
|
|
2022-08-19 15:27:57 +00:00
|
|
|
$http = Http::remote($this->reply->workOrder->module->api_token, $this->reply->workOrder->module->url);
|
|
|
|
|
2022-08-29 17:11:19 +00:00
|
|
|
$reply = $this->reply->toArray();
|
|
|
|
|
|
|
|
$response = $http->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
|
2022-08-19 15:27:57 +00:00
|
|
|
|
|
|
|
if ($response->successful()) {
|
|
|
|
$this->reply->is_pending = false;
|
|
|
|
} else {
|
|
|
|
$this->reply->is_pending = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->reply->save();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|