| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- include_once "../include/DB.php";
- $UserID="";
- if (isset($_POST["UserID"]) && !empty($_POST["UserID"])) {
- $UserID=$_POST["UserID"];
- }
- $sql = "SELECT user.UserID,
- user.UserName,
- user.PhoneNumber,
- user.IsAdmin,
- user.CreatedAt AS UserCreatedAt,
- user.UpdatedAt AS UserUpdatedAt
- FROM user user
- WHERE user.UserID='$UserID'";
- $result = $conn->query($sql);
- if ($result!== false && $result->num_rows > 0) {
- $listArray = [];
- while($row = $result->fetch_assoc()) {
- //////////////////////////////////////////////////////////////////////////////////////////////
- $swapsql = "SELECT *,
- swap.CreatedAt AS SwapCreatedAt,
- swap.UpdatedAt AS SwapUpdatedAt
- FROM swap swap";
- $swapresult = $conn->query($swapsql);
-
- $swaplistArray= [];
- if ($swapresult!== false && $swapresult->num_rows > 0) {
- while($swaprow = $swapresult->fetch_assoc()) {
-
- $swapvalue = array(
- "SwapID"=>(int)$swaprow["SwapID"],
- "RiderID"=>$swaprow["RiderID"],
- "SwapReferID"=>$swaprow["SwapReferID"],
- "SwapRechargeID"=>$swaprow["SwapRechargeID"],
- "ReturnBatterID"=>$swaprow["ReturnBatterID"],
- "SwappedBatterID"=>$swaprow["SwappedBatterID"],
- "IsFreeSwap"=>$swaprow["IsFreeSwap"],
- "SwapCreatedAt"=>$swaprow["SwapCreatedAt"],
- "SwapUpdatedAt"=>$swaprow["SwapUpdatedAt"],
- );
- $swaplistArray[]= $swapvalue;
- }
- }
-
- $PaidSwapCount =array_count_values(array_column($swaplistArray, 'IsFreeSwap'))["0"]??0;
- $FreeSwapCount =array_count_values(array_column($swaplistArray, 'IsFreeSwap'))["1"]??0;
- $swapCount = count($swaplistArray);
- ///////////////////////////////////////////////////////////////////////////////////////////////
- $rechargesql = "SELECT *,
- recharge.CreatedAt AS RechargeCreatedAt,
- recharge.UpdatedAt AS RechargeUpdatedAt
- FROM rechargehistory recharge";
- $rechargeresult = $conn->query($rechargesql);
-
- $rechargelistArray= [];
- if ($rechargeresult!== false && $rechargeresult->num_rows > 0) {
- while($rechargerow = $rechargeresult->fetch_assoc()) {
- $rechargevalue = array(
- "RechargeID"=>(int)$rechargerow["RechargeHistoryID"],
- "RiderID"=>$rechargerow["RiderID"],
- "TransactionID"=>$rechargerow["TransactionID"],
- "PaymentTypeID"=>$rechargerow["PaymentTypeID"],
- "RechargeCreatedAt"=>$rechargerow["RechargeCreatedAt"],
- "RechargeUpdatedAt"=>$rechargerow["RechargeUpdatedAt"],
- );
- $rechargelistArray[]= $rechargevalue;
- }
- }
- $rechargeCount = count($rechargelistArray);
- /////////////////////////////////////////////////////////////////////////////////////////////////
- $servicehistorysql = "SELECT *,
- servicehistory.CreatedAt AS ServiceHistoryCreatedAt,
- servicehistory.UpdatedAt AS ServiceHistoryUpdatedAt
- FROM servicehistory servicehistory";
- $servicehistoryresult = $conn->query($servicehistorysql);
-
- $servicehistorylistArray= [];
- if ($servicehistoryresult!== false && $servicehistoryresult->num_rows > 0) {
- while($servicehistoryrow = $servicehistoryresult->fetch_assoc()) {
- $servicehistoryvalue = array(
- "ServiceHistoryID"=>(int)$servicehistoryrow["ServiceHistoryID"],
- "AssetID"=>$servicehistoryrow["AssetID"],
- "isServiced"=>(int)$servicehistoryrow["isServiced"],
- "InWard"=>$servicehistoryrow["InWard"],
- "outWard"=>$servicehistoryrow["outWard"],
- "ServiceHistoryCreatedAt"=>$servicehistoryrow["ServiceHistoryCreatedAt"],
- "ServiceHistoryUpdatedAt"=>$servicehistoryrow["ServiceHistoryUpdatedAt"],
- );
- $servicehistorylistArray[]= $servicehistoryvalue;
- }
- }
- $InCompletedServiceCount =array_count_values(array_column($servicehistorylistArray, 'isServiced'))["0"]??0;
- $servicehistoryCount = count($servicehistorylistArray);
- //////////////////////////////////////////////////////////////////////////////////////////////////
- $assetsql = "SELECT *,
- asset.CreatedAt AS AssetCreatedAt,
- asset.UpdatedAt AS AssetUpdatedAt,
- assetcategory.CreatedAt AS AssetCategoryCreatedAt,
- assetcategory.UpdatedAt AS AssetCategoryUpdatedAt
- FROM asset asset
- JOIN assetcategory assetcategory ON assetcategory.AssetCategoryID =asset.AssetCategoryID ";
- $assetresult = $conn->query($assetsql);
-
- $assetlistArray= [];
- if ($assetresult!== false && $assetresult->num_rows > 0) {
- while($sassetrow = $assetresult->fetch_assoc()) {
- $assetvalue = array(
- "AssetID"=>$sassetrow["AssetID"],
- "AssetName"=>$sassetrow["AssetName"],
- "AssetCategoryID"=>(int)$sassetrow["AssetCategoryID"],
- "AssetCategory"=>array(
- "AssetCategoryID"=>(int)$sassetrow["AssetCategoryID"],
- "AssetCategoryTitle"=>$sassetrow["AssetCategoryTitle"],
- "AssetCategoryCreatedAt"=>$sassetrow["AssetCategoryCreatedAt"],
- "AssetCategoryUpdatedAt"=>$sassetrow["AssetCategoryUpdatedAt"],
- ),
- "IsInServiceCenter"=>(int)$sassetrow["IsInServiceCenter"],
- "AssetCreatedAt"=>$sassetrow["AssetCreatedAt"],
- "AssetUpdatedAt"=>$sassetrow["AssetUpdatedAt"],
- );
- $assetlistArray[]= $assetvalue;
- }
- }
- $assetCount = count($assetlistArray);
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- $value = array(
- "UserData"=>array(
- "UserID"=>(int)$row["UserID"],
- "UserName"=>$row["UserName"],
- "PhoneNumber"=>$row["PhoneNumber"],
- "IsAdmin"=>(int)$row["IsAdmin"],
- "UserCreatedAt"=>$row["UserCreatedAt"],
- "UserUpdatedAt"=>$row["UserUpdatedAt"],
- ),
- "SwapData"=>array(
- "HistoryData"=>array(
- "TotalCount"=>$swapCount,
- "FreeSwapCount"=>$FreeSwapCount,
- "PaidSwapCount"=>$PaidSwapCount,
- "History"=>$swaplistArray
- ),
- ),
- "RechargeData"=>array(
- "HistoryData"=>array(
- "TotalCount"=>$rechargeCount,
- "History"=>$rechargelistArray
- ),
- ),
- "ServiceData"=>array(
- "HistoryData"=>array(
- "TotalCount"=>$servicehistoryCount,
- "InCompletedServiceCount"=>$InCompletedServiceCount,
- "History"=>$servicehistorylistArray
- ),
- ),
- "AssetData"=>array(
- "HistoryData"=>array(
- "TotalCount"=>$assetCount,
- "History"=>$assetlistArray
- ),
- ),
-
- "Message"=>"Date successfully get"
- );
- $listArray[]= $value;
- }
- $count = count($listArray);
- if($count==1){
- // Use json_encode() function
- $json = json_encode($listArray[0]);
- }else {
- // Use json_encode() function
- $json = json_encode($listArray);
- }
- }else {
- http_response_code(404);
- $errorMesage= $conn->error;
- if ($errorMesage=="") {
- $errorMesage = "UserID not available";
- if (empty($_GET["UserID"])) {
- $errorMesage = "UserID is empty";
- }
- }
- // Declare an array with error message
- $value = array(
- "Message"=>"Failed to get data",
- "Error"=>$errorMesage
- );
- // Use json_encode() function
- $json = json_encode($value);
- }
- // Display the output
- echo($json);
- $conn->close();
|