mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-25 15:34:02 +00:00
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CreatesPerfexCRMTask
|
|
{
|
|
/**
|
|
* @param string $taskName
|
|
* @param string $milestoneId
|
|
* @param string $projectId
|
|
* @param string $status, default: 1
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(string $taskName, string $milestoneId, string $projectId, string $reference = '', string $status = "1") {
|
|
try{
|
|
$data = [
|
|
'name' => $taskName,
|
|
'milestone' => $milestoneId,
|
|
'startdate' => date('Y-m-d'),
|
|
'rel_type' => 'project',
|
|
'rel_id' => $projectId,
|
|
'status' => $status,
|
|
'is_system_created' => 1,
|
|
'reference' => $reference
|
|
];
|
|
|
|
$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());
|
|
}
|
|
}
|
|
}
|