| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- include_once "../../include/DB.php";
- $RiderID="";
- $ReturnBatteryID="";
- $SwapBatteryID="";
- $SwapRechargeID="";
- $TotalRechargedSwapCount="";
- $UsedRechargedSwapCount="";
- $AvailableRechargedSwapCount="";
- if (isset($_POST["RiderID"]) && !empty($_POST["RiderID"])) {
- $RiderID=$_POST["RiderID"];
- }
- if (isset($_POST["ReturnBatteryID"]) && !empty($_POST["ReturnBatteryID"])) {
- $ReturnBatteryID=$_POST["ReturnBatteryID"];
- }
- if (isset($_POST["SwapBatteryID"]) && !empty($_POST["SwapBatteryID"])) {
- $SwapBatteryID=$_POST["SwapBatteryID"];
- }
- if (isset($_POST["SwapRechargeID"]) && !empty($_POST["SwapRechargeID"])) {
- $SwapRechargeID=$_POST["SwapRechargeID"];
- }
- if (isset($_POST["TotalRechargedSwapCount"]) && !empty($_POST["TotalRechargedSwapCount"])) {
- $TotalRechargedSwapCount=$_POST["TotalRechargedSwapCount"];
- }
- if (isset($_POST["UsedRechargedSwapCount"]) && !empty($_POST["UsedRechargedSwapCount"])) {
- $UsedRechargedSwapCount=$_POST["UsedRechargedSwapCount"];
- }
- if (isset($_POST["AvailableRechargedSwapCount"]) && !empty($_POST["AvailableRechargedSwapCount"])) {
- $AvailableRechargedSwapCount=$_POST["AvailableRechargedSwapCount"];
- }
- $SwapInsertSql = "INSERT INTO swap(RiderID, SwapRechargeID, ReturnBatterID, SwappedBatterID,IsFreeSwap) VALUES ('$RiderID','$SwapRechargeID','$ReturnBatteryID','$SwapBatteryID','0')";
- $SwapInsertresult = $conn->query($SwapInsertSql);
- if ($SwapInsertresult === TRUE) {
- $RechargePostData = array(
- 'SwapRechargeID' => $SwapRechargeID,
- 'TotalRechargedSwapCount' => $TotalRechargedSwapCount,
- 'UsedRechargedSwapCount' => $UsedRechargedSwapCount,
- 'AvailableRechargedSwapCount' => $AvailableRechargedSwapCount,
- );
- $RechargeURL = "http://localhost/cygnusa/batterySwap/api/Admin/Recharge/";
- $RechargeCURL = curl_init($RechargeURL);
- curl_setopt($RechargeCURL, CURLOPT_HEADER, false);
- curl_setopt($RechargeCURL, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($RechargeCURL, CURLOPT_POST, true);
- curl_setopt($RechargeCURL, CURLOPT_POSTFIELDS, $RechargePostData);
- $RechargeJsonResponse = curl_exec($RechargeCURL);
- $value = array(
- "RiderID"=>$RiderID,
- "ReturnBatteryID"=>$ReturnBatteryID,
- "SwapBatteryID"=>$SwapBatteryID,
- "Recharge"=>$RechargeJsonResponse,
- "Message"=>"Swap Data saved successfully",
- );
- // Use json_encode() function
- $json = json_encode($value);
- }else {
- http_response_code(404);
- $errorMesage= $conn->error;
- // Declare an array with error message
- $value = array(
- "Message"=>"Something went wrong",
- "Error"=>$errorMesage
- );
- // Use json_encode() function
- $json = json_encode($value);
- }
- // Display the output
- echo ($json);
- $conn->close();
|