shiftTankData.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require "connectionDb.php";
  3. if (isset($_POST['find'])) {
  4. $date = $_POST['selectDateToFind'];
  5. $date = str_replace('-', '_', $date);
  6. $shiftnum = $_POST['shiftNumber'];
  7. if ($_POST['fuelGrade']=='ALL') {
  8. $customers = $db->query("SELECT * FROM shift_tank_vw WHERE date='$date' AND number='$shiftnum' ");
  9. }else {
  10. $fuelgrade = $_POST['fuelGrade'];
  11. $customers = $db->query("SELECT * FROM shift_tank_vw WHERE date='$date' AND number='$shiftnum' AND product_text='$fuelgrade' ");
  12. }
  13. $json_data=[];
  14. while ($row = $customers->fetchArray()) {
  15. //print_r($row);
  16. $details = [
  17. "Shift_Id" => $row['shift_id'],
  18. "Date" => $row['date'],
  19. "Number" => $row['number'],
  20. "Open_Date" => date('Y-M-d h:i:s A',$row['open_date']),
  21. "Close_Date" => date('Y-M-d h:i:s A',$row['close_date']),
  22. "Tank_Id" => $row['tank_id'],
  23. "Product_Text" => $row['product_text'],
  24. "Open_Vol" => $row['open_vol'],
  25. "Close_Vol" => $row['close_vol'],
  26. "Open_Water_Vol" => $row['open_water_vol'],
  27. "Close_Water_Vol" => $row['close_water_vol'],
  28. "Open_Level" => $row['open_level'],
  29. "Close_Level" => $row['close_level'],
  30. ];
  31. //here pushing the values in to an array
  32. array_push($json_data,$details);
  33. }
  34. $json_data_all = ["data" => $json_data];
  35. $myfile = fopen("api/v1/ShiftTankReport/shiftTankData.txt", "w+") or die("Unable to open file!");;
  36. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  37. fclose($myfile);
  38. }
  39. ?>