index.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. include_once "../include/DB.php";
  3. $UserID="";
  4. if (isset($_POST["UserID"]) && !empty($_POST["UserID"])) {
  5. $UserID=$_POST["UserID"];
  6. }
  7. $sql = "SELECT user.UserID,
  8. user.UserName,
  9. user.PhoneNumber,
  10. user.IsAdmin,
  11. user.CreatedAt AS UserCreatedAt,
  12. user.UpdatedAt AS UserUpdatedAt
  13. FROM user user
  14. WHERE user.UserID='$UserID'";
  15. $result = $conn->query($sql);
  16. if ($result!== false && $result->num_rows > 0) {
  17. $listArray = [];
  18. while($row = $result->fetch_assoc()) {
  19. //////////////////////////////////////////////////////////////////////////////////////////////
  20. $swapsql = "SELECT *,
  21. swap.CreatedAt AS SwapCreatedAt,
  22. swap.UpdatedAt AS SwapUpdatedAt
  23. FROM swap swap";
  24. $swapresult = $conn->query($swapsql);
  25. $swaplistArray= [];
  26. if ($swapresult!== false && $swapresult->num_rows > 0) {
  27. while($swaprow = $swapresult->fetch_assoc()) {
  28. $swapvalue = array(
  29. "SwapID"=>(int)$swaprow["SwapID"],
  30. "RiderID"=>$swaprow["RiderID"],
  31. "SwapReferID"=>$swaprow["SwapReferID"],
  32. "SwapRechargeID"=>$swaprow["SwapRechargeID"],
  33. "ReturnBatterID"=>$swaprow["ReturnBatterID"],
  34. "SwappedBatterID"=>$swaprow["SwappedBatterID"],
  35. "IsFreeSwap"=>$swaprow["IsFreeSwap"],
  36. "SwapCreatedAt"=>$swaprow["SwapCreatedAt"],
  37. "SwapUpdatedAt"=>$swaprow["SwapUpdatedAt"],
  38. );
  39. $swaplistArray[]= $swapvalue;
  40. }
  41. }
  42. $PaidSwapCount =array_count_values(array_column($swaplistArray, 'IsFreeSwap'))["0"]??0;
  43. $FreeSwapCount =array_count_values(array_column($swaplistArray, 'IsFreeSwap'))["1"]??0;
  44. $swapCount = count($swaplistArray);
  45. ///////////////////////////////////////////////////////////////////////////////////////////////
  46. $rechargesql = "SELECT *,
  47. recharge.CreatedAt AS RechargeCreatedAt,
  48. recharge.UpdatedAt AS RechargeUpdatedAt
  49. FROM rechargehistory recharge";
  50. $rechargeresult = $conn->query($rechargesql);
  51. $rechargelistArray= [];
  52. if ($rechargeresult!== false && $rechargeresult->num_rows > 0) {
  53. while($rechargerow = $rechargeresult->fetch_assoc()) {
  54. $rechargevalue = array(
  55. "RechargeID"=>(int)$rechargerow["RechargeHistoryID"],
  56. "RiderID"=>$rechargerow["RiderID"],
  57. "TransactionID"=>$rechargerow["TransactionID"],
  58. "PaymentTypeID"=>$rechargerow["PaymentTypeID"],
  59. "RechargeCreatedAt"=>$rechargerow["RechargeCreatedAt"],
  60. "RechargeUpdatedAt"=>$rechargerow["RechargeUpdatedAt"],
  61. );
  62. $rechargelistArray[]= $rechargevalue;
  63. }
  64. }
  65. $rechargeCount = count($rechargelistArray);
  66. /////////////////////////////////////////////////////////////////////////////////////////////////
  67. $servicehistorysql = "SELECT *,
  68. servicehistory.CreatedAt AS ServiceHistoryCreatedAt,
  69. servicehistory.UpdatedAt AS ServiceHistoryUpdatedAt
  70. FROM servicehistory servicehistory";
  71. $servicehistoryresult = $conn->query($servicehistorysql);
  72. $servicehistorylistArray= [];
  73. if ($servicehistoryresult!== false && $servicehistoryresult->num_rows > 0) {
  74. while($servicehistoryrow = $servicehistoryresult->fetch_assoc()) {
  75. $servicehistoryvalue = array(
  76. "ServiceHistoryID"=>(int)$servicehistoryrow["ServiceHistoryID"],
  77. "AssetID"=>$servicehistoryrow["AssetID"],
  78. "isServiced"=>(int)$servicehistoryrow["isServiced"],
  79. "InWard"=>$servicehistoryrow["InWard"],
  80. "outWard"=>$servicehistoryrow["outWard"],
  81. "ServiceHistoryCreatedAt"=>$servicehistoryrow["ServiceHistoryCreatedAt"],
  82. "ServiceHistoryUpdatedAt"=>$servicehistoryrow["ServiceHistoryUpdatedAt"],
  83. );
  84. $servicehistorylistArray[]= $servicehistoryvalue;
  85. }
  86. }
  87. $InCompletedServiceCount =array_count_values(array_column($servicehistorylistArray, 'isServiced'))["0"]??0;
  88. $servicehistoryCount = count($servicehistorylistArray);
  89. //////////////////////////////////////////////////////////////////////////////////////////////////
  90. $assetsql = "SELECT *,
  91. asset.CreatedAt AS AssetCreatedAt,
  92. asset.UpdatedAt AS AssetUpdatedAt,
  93. assetcategory.CreatedAt AS AssetCategoryCreatedAt,
  94. assetcategory.UpdatedAt AS AssetCategoryUpdatedAt
  95. FROM asset asset
  96. JOIN assetcategory assetcategory ON assetcategory.AssetCategoryID =asset.AssetCategoryID ";
  97. $assetresult = $conn->query($assetsql);
  98. $assetlistArray= [];
  99. if ($assetresult!== false && $assetresult->num_rows > 0) {
  100. while($sassetrow = $assetresult->fetch_assoc()) {
  101. $assetvalue = array(
  102. "AssetID"=>$sassetrow["AssetID"],
  103. "AssetName"=>$sassetrow["AssetName"],
  104. "AssetCategoryID"=>(int)$sassetrow["AssetCategoryID"],
  105. "AssetCategory"=>array(
  106. "AssetCategoryID"=>(int)$sassetrow["AssetCategoryID"],
  107. "AssetCategoryTitle"=>$sassetrow["AssetCategoryTitle"],
  108. "AssetCategoryCreatedAt"=>$sassetrow["AssetCategoryCreatedAt"],
  109. "AssetCategoryUpdatedAt"=>$sassetrow["AssetCategoryUpdatedAt"],
  110. ),
  111. "IsInServiceCenter"=>(int)$sassetrow["IsInServiceCenter"],
  112. "AssetCreatedAt"=>$sassetrow["AssetCreatedAt"],
  113. "AssetUpdatedAt"=>$sassetrow["AssetUpdatedAt"],
  114. );
  115. $assetlistArray[]= $assetvalue;
  116. }
  117. }
  118. $assetCount = count($assetlistArray);
  119. /////////////////////////////////////////////////////////////////////////////////////////////////////
  120. $value = array(
  121. "UserData"=>array(
  122. "UserID"=>(int)$row["UserID"],
  123. "UserName"=>$row["UserName"],
  124. "PhoneNumber"=>$row["PhoneNumber"],
  125. "IsAdmin"=>(int)$row["IsAdmin"],
  126. "UserCreatedAt"=>$row["UserCreatedAt"],
  127. "UserUpdatedAt"=>$row["UserUpdatedAt"],
  128. ),
  129. "SwapData"=>array(
  130. "HistoryData"=>array(
  131. "TotalCount"=>$swapCount,
  132. "FreeSwapCount"=>$FreeSwapCount,
  133. "PaidSwapCount"=>$PaidSwapCount,
  134. "History"=>$swaplistArray
  135. ),
  136. ),
  137. "RechargeData"=>array(
  138. "HistoryData"=>array(
  139. "TotalCount"=>$rechargeCount,
  140. "History"=>$rechargelistArray
  141. ),
  142. ),
  143. "ServiceData"=>array(
  144. "HistoryData"=>array(
  145. "TotalCount"=>$servicehistoryCount,
  146. "InCompletedServiceCount"=>$InCompletedServiceCount,
  147. "History"=>$servicehistorylistArray
  148. ),
  149. ),
  150. "AssetData"=>array(
  151. "HistoryData"=>array(
  152. "TotalCount"=>$assetCount,
  153. "History"=>$assetlistArray
  154. ),
  155. ),
  156. "Message"=>"Date successfully get"
  157. );
  158. $listArray[]= $value;
  159. }
  160. $count = count($listArray);
  161. if($count==1){
  162. // Use json_encode() function
  163. $json = json_encode($listArray[0]);
  164. }else {
  165. // Use json_encode() function
  166. $json = json_encode($listArray);
  167. }
  168. }else {
  169. http_response_code(404);
  170. $errorMesage= $conn->error;
  171. if ($errorMesage=="") {
  172. $errorMesage = "UserID not available";
  173. if (empty($_GET["UserID"])) {
  174. $errorMesage = "UserID is empty";
  175. }
  176. }
  177. // Declare an array with error message
  178. $value = array(
  179. "Message"=>"Failed to get data",
  180. "Error"=>$errorMesage
  181. );
  182. // Use json_encode() function
  183. $json = json_encode($value);
  184. }
  185. // Display the output
  186. echo($json);
  187. $conn->close();