���� ������������������������������������ setSearchPreferences(false, 20); $code=$_GET['code']; if (strpos($code, '^') !== false) { $code = str_replace('^', ' ', $code); } $emailSearchField = new SearchStringField(); $emailSearchField->operator = "contains"; $emailSearchField->searchValue = $code; $search = new ItemSearchBasic(); $search->itemId = $emailSearchField; $request = new SearchRequest(); $request->searchRecord = $search; $searchResponse = $service->search($request); if ($searchResponse->searchResult->totalRecords == 0) { $response = [ 'status' => 'error', 'message' => 'Sales order item not found!', 'data'=>[] ]; } else { // $internalId=$searchResponse->searchResult->recordList->record[0]->internalId; $internalId=''; foreach($searchResponse->searchResult->recordList->record as $record){ if($record->itemId==$code){ $internalId=$record->internalId; } } $response = [ 'status' => 'success', 'message' => 'Sales order item found!', 'data'=>[ 'id'=>$internalId ] ]; } } else { $response = [ 'status' => 'error', 'message' => 'Please provide item code!' ]; } header('Content-Type: application/json'); echo json_encode($response); exit; } if ($_SERVER['REQUEST_METHOD'] === 'GET' && $_GET['action'] === 'getSalesOrder') { if ($_GET['id']) { $service->setSearchPreferences(false, 20); $request = new GetRequest(); $request->baseRef = new RecordRef(); $request->baseRef->internalId = $_GET['id']; $request->baseRef->type = "salesOrder"; $getResponse = $service->get($request); if (!$getResponse->readResponse->status->isSuccess) { $response = [ 'status' => 'error', 'message' => 'Sales order not found!' ]; } else { $response = [ 'status' => 'success', 'message' => 'Sales order found!', 'data'=>array( 'OrderNo'=>$getResponse->readResponse->record->tranId ) ]; } } else { $response = [ 'status' => 'error', 'message' => 'Please provide sales order Id!' ]; } header('Content-Type: application/json'); echo json_encode($response); exit; } // Endpoint to update a sales order item if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_GET['action'] === 'updateSalesOrderItem') { $exchangeRate=$_GET['exchangeRate']? $_GET['exchangeRate'] :0.00; $documentLink=$_GET['documentLink']? $_GET['documentLink'] :"https://lifefitness.clientpoint.net/"; $requestData = json_decode(file_get_contents('php://input'), true); $postField = " ".$account." ".$consumerKey." ".$token." ".$nonce." ".$timestamp." ".$signature." true "; foreach($requestData as $data) { // fwrite($file, $data['trade_in'] . PHP_EOL); $price = str_replace(',', '', $data['price']); $price = (float)$price; $price1 = number_format($price, 2); // Convert to two decimal places $rate=$price / $data['quantity']; $rate = number_format($rate, 2); // Convert to two decimal places $price1 = (float)str_replace(',', '', $price1); $rate = (float)str_replace(',', '', $rate); if (!empty($data['trade_in'])) { $trade_in = (int) $data['trade_in']; } else { $trade_in = 0; } $postField .= " ".$data['quantity']." ".htmlspecialchars($data['description'])." ".$rate." ".$price1." 00.Vic-Product ".$trade_in." "; } $postField .= " ".$exchangeRate." ".$documentLink." "; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://4661993.suitetalk.api.netsuite.com/services/NetSuitePort_2023_1', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>$postField, CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'SOAPAction: update' ), )); $response = curl_exec($curl); curl_close($curl); if ($file = fopen($logFile, 'a')) { // Optionally, you can add a timestamp to each log entry fwrite($file, $postField); } else { // Handle file open error } if ($file = fopen($logFile, 'a')) { // Optionally, you can add a timestamp to each log entry fwrite($file, $response); } else { // Handle file open error } echo $response; exit; $response = [ 'status' => 'success', 'response' => $error, ]; // header('Content-Type: application/json'); echo json_encode($response); exit; } // If no matching endpoint is found, return a 404 response http_response_code(404); header('Content-Type: application/json'); echo json_encode([ 'status' => 'error', 'message' => 'API not found!', ]);