mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
88 lines
3.2 KiB
PHP
88 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
|
|
|
class CreatesPerfexCRMTask
|
|
{
|
|
/**
|
|
* @param string $taskName
|
|
* @param string $taskDescription
|
|
* @param string $leadId
|
|
* @param string $milestoneId
|
|
* @param string $projectId
|
|
* @param string $reference
|
|
* @param string $on_task_completion
|
|
* @param string $department
|
|
* @param string $status
|
|
* @param string $priority
|
|
* @param string $duedate
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference, string $on_task_completion, string $department, string $status, string $priority, string $duedate) {
|
|
try{
|
|
$custom_fields = [];
|
|
if($department != ""){
|
|
$custom_fields = [
|
|
"tasks" => [
|
|
PerfexCRMCustomFields::TASKS_DEPARTMENT => $department
|
|
]
|
|
];
|
|
}
|
|
|
|
$data = [
|
|
'name' => $taskName,
|
|
'description' => $taskDescription,
|
|
'milestone' => $milestoneId,
|
|
'startdate' => date('Y-m-d'),
|
|
'rel_type' => 'project',
|
|
'rel_id' => $projectId,
|
|
'status' => $status,
|
|
'is_system_created' => 1,
|
|
'reference' => $reference,
|
|
'on_task_completion' => $on_task_completion,
|
|
'custom_fields' => $custom_fields,
|
|
'priority' => $priority,
|
|
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
|
];
|
|
|
|
if($leadId != '') {
|
|
$data = [
|
|
'name' => $taskName,
|
|
'description' => $taskDescription,
|
|
'milestone' => $milestoneId,
|
|
'startdate' => date('Y-m-d'),
|
|
'rel_type' => 'lead',
|
|
'rel_id' => $leadId,
|
|
'status' => $status,
|
|
'is_system_created' => 1,
|
|
'reference' => $reference,
|
|
'on_task_completion' => $on_task_completion,
|
|
'custom_fields' => $custom_fields,
|
|
'priority' => $priority,
|
|
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
|
];
|
|
}
|
|
|
|
$response = Http::asForm()->withHeaders([
|
|
'authtoken' => config('perfexcrm.api_key')])
|
|
->post(config('perfexcrm.base_url').'/api/tasks',$data);
|
|
|
|
if($response->successful()){
|
|
$data = $response->json();
|
|
return (object) $data;
|
|
}else{
|
|
Log::error($response);
|
|
return null;
|
|
}
|
|
}catch(\Exception $exception){
|
|
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage());
|
|
}
|
|
}
|
|
}
|