| Server IP : 138.197.176.125 / Your IP : 216.73.217.54 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/soltelcocrm/modules/NewNumber/ |
Upload File : |
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
function handleAddSubscribers($entityData){
$adb = PearDatabase::getInstance();
$moduleName = $entityData->getModuleName();
$wsId = $entityData->getId();
$parts = explode('x', $wsId);
$recordId = $parts[1];
$entityResult = $entityData->data;
if($recordId){
//get simgenerate id using record id
$numberRecordModel = Vtiger_Record_Model::getInstanceById($recordId,'NewNumber');
$simgenerateid = $numberRecordModel->get('packagesimnumber');
/*$relatedSimGenerate = $entityResult['packagesimnumber'];
$simgenerateids = explode('x', $relatedSimGenerate);
$simgenerateid = $simgenerateids[1];*/
//get simnumber from simgenerate id
$simgenerateRecordModel = Vtiger_Record_Model::getInstanceById($simgenerateid, 'SimGenerate');
$sellingsim_isdn = $simgenerateRecordModel->get('simcard_number');
$sellingsim_imsi = $entityResult['simimsino'];
$inventoryModuleModel = new SellingInventory_Module_Model();
$loginCredentials = $inventoryModuleModel->getAPISettingsDetails();
$apiurl = $loginCredentials['hlr_apiurl'];
$username = $loginCredentials['hlr_username'];
$password = $loginCredentials['hlr_password'];
//call HLR login API
$curl = curl_init();
$crmapirequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<LGI>
<OPNAME>'.$username.'</OPNAME>
<PWD>'.$password.'</PWD>
</LGI>
</soapenv:Body>
</soapenv:Envelope>';
curl_setopt_array($curl, array(
CURLOPT_URL => $apiurl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$crmapirequest,
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain',
'User-Agent: Jakarta Commons-HttpClient/3.1'
),
));
$response = curl_exec($curl);
//if log enable save api log
$logStaus = $inventoryModuleModel->checkApiLogEnabled();
if($logStaus){
$loginsertid = $inventoryModuleModel->insertRecordInApiModule($apiurl, $crmapirequest,$response);
}
$headerlocation = '';
if (strpos($response, 'Location') !== false) {
$arrresponse = explode("Location:", $response);
$arrresponse1 = explode("Server:", $arrresponse[1]);
$headerlocation = $arrresponse1[0];
}
$loginResponse = trim($headerlocation);
if(!empty($loginResponse)){
$apiurl = $loginResponse;
$crmapirequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ADD_TPLSUB>
<HLRSN>2</HLRSN>
<IMSI>'.$sellingsim_imsi.'</IMSI>
<ISDN>'.$sellingsim_isdn.'</ISDN>
<TPLID>600</TPLID>
</ADD_TPLSUB>
</soapenv:Body>
</soapenv:Envelope>';
curl_setopt_array($curl, array(
CURLOPT_URL => $apiurl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$crmapirequest,
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain',
'User-Agent: Jakarta Commons-HttpClient/3.1'
),
));
$response1 = curl_exec($curl);
$soap = simplexml_load_string($response1);
$arrresponse = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children();
$xmlresponse = $arrresponse->ADD_TPLSUBResponse->Result->ResultCode;
curl_close($curl);
//if log enable save api log
$logStaus = $inventoryModuleModel->checkApiLogEnabled();
if($logStaus){
$loginsertid = $inventoryModuleModel->insertRecordInApiModule($apiurl, $crmapirequest,$response1);
if($loginsertid > 0){
//update status and number record id
$recordModel = Vtiger_Record_Model::getInstanceById($loginsertid, 'APILog');
$recordModel->set('mode','edit');
$recordModel->set('relatednumber',$recordId);
if($xmlresponse == 0){
$recordModel->set('apistatus','Success');
}else{
$recordModel->set('apistatus','Fail');
}
$recordModel->save();
}
}
$related_simgenerate = $simgenerateid;
$recordSimGenerateModel = Vtiger_Record_Model::getInstanceById($related_simgenerate,'SimGenerate');
// $simdivision = $recordSimGenerateModel->get('simtype');
$simcarddistributeid = $recordSimGenerateModel->get('related_simcarddistribute');
$currentuserid = $_SESSION['authenticated_user_id'];
$userRecordModel = Vtiger_Record_Model::getInstanceById($currentuserid,'Users');
$first_name = $userRecordModel->get('first_name');
$last_name = $userRecordModel->get('last_name');
$currentUserName = $first_name." ".$last_name;
if($xmlresponse == 0){
//update sim distribute balance when simcard sell
$simDistributeModel = Vtiger_Record_Model::getInstanceById($simcarddistributeid,'SimcardDistribute');
$distribute_balance = $simDistributeModel->get('distribute_balance');
$newdistribute_balance = $distribute_balance - 1;
$simDistributeModel->set('mode', 'edit');
$simDistributeModel->set('distribute_balance', $newdistribute_balance);
$simDistributeModel->save();
//update status of sim generate when subscriber generate
$adb->pquery("UPDATE vtiger_simgenerate SET simgenerate_status=?, assignedstatus=? WHERE simcard_imsino= ?", array('Activate', 'Activate', $sellingsim_imsi));
}else{
//$adb->pquery("UPDATE vtiger_simgenerate SET simgenerate_status=?, assignedstatus=? WHERE simcard_imsino=?", array('Fail', 'Fail', $sellingsim_imsi));
}
}
}
}