shiftPumpData.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_pump_vw WHERE date='$date' AND number='$shiftnum' ");
  9. }else {
  10. $fuelgrade = $_POST['fuelGrade'];
  11. $customers = $db->query("SELECT * FROM shift_pump_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. $openVolume = $row['open_volume'];
  17. $closeVolume = $row['close_volume'];
  18. $saleTotal =$closeVolume-$openVolume;
  19. $price= $row['price'];
  20. $moneyTotal = $saleTotal*$price;
  21. $details = [
  22. "Shift_Id" => $row['shift_id'],
  23. "Date" => $row['date'],
  24. "Number" => $row['number'],
  25. "Open_Date" => date('Y-M-d h:i:s A',$row['open_date']),
  26. "Close_Date" => date('Y-M-d h:i:s A',$row['close_date']),
  27. "Fp_Id" => $row['fp_id'],
  28. "Grade_Name" => $row['grade_name'],
  29. "Open_Volume" => $row['open_volume'],
  30. "Close_Volume" => $row['close_volume'],
  31. "Price" => $row['price'],
  32. "Sale_Total" => $saleTotal,
  33. "Money_Total" => $moneyTotal,
  34. ];
  35. //here pushing the values in to an array
  36. array_push($json_data,$details);
  37. }
  38. $json_data_all = ["data" => $json_data];
  39. $myfile = fopen("api/v1/ShiftPumpReport/shiftPumpData.txt", "w+") or die("Unable to open file!");;
  40. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  41. fclose($myfile);
  42. }
  43. ?>