CIM59 - Create partner when partner does not exists

This commit is contained in:
“VeLiTi”
2024-03-29 21:10:45 +01:00
parent b49e7b9a8d
commit ff5bb86f84
3 changed files with 50 additions and 7 deletions

View File

@@ -127,7 +127,7 @@ foreach ($account as $key => $value){
break; break;
} }
//Create partner and push to array account //Create partner and push to array account
$account[$key] = createPartner($partner->salesid,$partner->soldto,$value,$p_type); $account[$key] = createPartner($partner->salesid,$partner->soldto,$value,$p_type,$userkey);
} }
} }
} }

View File

@@ -72,7 +72,7 @@ else {
if ($permission == 3 || $permission == 4){ if ($permission == 3 || $permission == 4){
//ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD
$account = array( $account = array(
"salesid"=>$post_content['salesid'], "salesid"=>$partner->salesid,
"soldto"=>$post_content['soldto'] "soldto"=>$post_content['soldto']
); );
} else { } else {

View File

@@ -492,6 +492,49 @@ function ioServer($api_call, $data){
//Response //Response
return $resp; return $resp;
} }
//------------------------------------------
// API TO API
//------------------------------------------
function ioAPI($api_call, $data, $token){
include dirname(__FILE__,2).'/settings/settings.php';
$bearertoken = createCommunicationToken($token);
$url = $baseurl.$api_call;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Authorization: Bearer $bearertoken",
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
$resp = curl_exec($curl);
$http_status = curl_getinfo($curl) ?? '200';
curl_close($curl);
//Check If errorcode is returned
if($http_status['http_code'] == '403' || $http_status['http_code'] == '400') {$resp = generate_payload('NOK');}
if (debug){
$message = $date.';'.$api_call;
debuglog($message);
}
//Response
return $resp;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//get user profile||$profile=settings, $permision = userright() //get user profile||$profile=settings, $permision = userright()
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -1781,7 +1824,7 @@ exit;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Create Partner - when not exists // Create Partner - when not exists
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function createPartner($user_salesid,$user_soldto,$p_name,$p_type){ function createPartner($user_salesid,$user_soldto,$p_name,$p_type, $token){
$p_return = ''; $p_return = '';
@@ -1790,7 +1833,7 @@ function createPartner($user_salesid,$user_soldto,$p_name,$p_type){
//Secure data //Secure data
$payload = generate_payload($data); $payload = generate_payload($data);
//API call //API call
$responses = ioServer('/v1/partners', $payload); $responses = ioAPI('/v1/partners', $payload, $token);
if ($responses === 'NOK'){ if ($responses === 'NOK'){
// Do Nothing // Do Nothing
@@ -1798,13 +1841,13 @@ function createPartner($user_salesid,$user_soldto,$p_name,$p_type){
else { else {
//GET PARTNER DATA - CALL TO API WITH PARTNERNAME //GET PARTNER DATA - CALL TO API WITH PARTNERNAME
$api_url = '/v1/partners/partnername='.$p_name; $api_url = '/v1/partners/partnername='.$p_name;
$responses = ioServer($api_url,''); $responses = ioAPI($api_url,'',$token);
//Decode Payload //Decode Payload
if (!empty($responses)){ if (!empty($responses)){
//If response received, check END of array for latest partner details //If response received, check END of array for latest partner details
$responses = decode_payload($responses); $responses = decode_payload($responses);
$partner= end($responses); $p_responses = end($responses);
$p_return = $responses['partnerID'].'-'.$responses['partnername']; $p_return = $p_responses->partnerID.'-'.$p_responses->partnername;
} }
} }
return $p_return; return $p_return;