add_service.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. include_once "../../include/DB.php";
  3. $AssetID="";
  4. if (isset($_POST["AssetID"]) && !empty($_POST["AssetID"])) {
  5. $AssetID=$_POST["AssetID"];
  6. }
  7. $ServiceCheckSQL = "SELECT * FROM servicehistory servicehistory WHERE servicehistory.AssetID='$AssetID' AND servicehistory.isServiced='0'";
  8. $ServiceCheckResult = $conn->query($ServiceCheckSQL);
  9. if ($ServiceCheckResult!== false && $ServiceCheckResult->num_rows > 0) {
  10. while($ServiceCheckRow = $ServiceCheckResult->fetch_assoc()) {
  11. $ServiceHistoryID = $ServiceCheckRow["ServiceHistoryID"];
  12. $ServiceUpdateSQL = "UPDATE servicehistory servicehistory SET servicehistory.InWard='$currentDateTime',isServiced='1' WHERE servicehistory.ServiceHistoryID='$ServiceHistoryID'";
  13. $ServiceUpdateResult = $conn->query($ServiceUpdateSQL);
  14. if ($ServiceUpdateResult === TRUE) {
  15. $value = array(
  16. "Message"=>"Service updated successfully",
  17. );
  18. // Use json_encode() function
  19. $json = json_encode($value);
  20. }else {
  21. http_response_code(404);
  22. $errorMesage= $conn->error;
  23. // Declare an array with error message
  24. $value = array(
  25. "Message"=>"Something went wrong",
  26. "Error"=>$errorMesage
  27. );
  28. // Use json_encode() function
  29. $json = json_encode($value);
  30. }
  31. }
  32. }else {
  33. $ServiceInsertSQL = "INSERT INTO servicehistory(AssetID) VALUES ('$AssetID')";
  34. $ServiceInsertResult = $conn->query($ServiceInsertSQL);
  35. if ($ServiceInsertResult === TRUE) {
  36. $value = array(
  37. "Message"=>"Service insert successfully",
  38. );
  39. // Use json_encode() function
  40. $json = json_encode($value);
  41. }else {
  42. http_response_code(404);
  43. $errorMesage= $conn->error;
  44. // Declare an array with error message
  45. $value = array(
  46. "Message"=>"Something went wrong",
  47. "Error"=>$errorMesage
  48. );
  49. // Use json_encode() function
  50. $json = json_encode($value);
  51. }
  52. }
  53. // Display the output
  54. echo ($json);
  55. $conn->close();