<?php 
    require "connectionDb.php";
if (isset($_POST['find'])) {
	
$date = $_POST['selectDateToFind'];
$date = str_replace('-', '_', $date);
$shiftnum = $_POST['shiftNumber'];
$fuelgrade = $_POST['fuelGrade'];
$customers = $db->query("SELECT * FROM shift_pump_vw WHERE date='$date' AND number='$shiftnum' AND grade_name='$fuelgrade' ");

$json_data=[];

while ($row = $customers->fetchArray()) {

//print_r($row);
$openVolume = $row['open_volume'];
$closeVolume = $row['close_volume'];
$saleTotal =$closeVolume-$openVolume;
$price= $row['price'];
$moneyTotal = $saleTotal*$price;

$details = [
"Shift_Id" => $row['shift_id'],
"Date" => $row['date'],
"Number" => $row['number'],
"Open_Date" => date('Y-M-d h:i:s A',$row['open_date']),
"Close_Date" => date('Y-M-d h:i:s A',$row['close_date']),
"Fp_Id" => $row['fp_id'],
"Grade_Name" => $row['grade_name'],
"Open_Volume" => $row['open_volume'],
"Close_Volume" => $row['close_volume'],
"Price" => $row['price'],
"Sale_Total" => $saleTotal,
"Money_Total" => $moneyTotal,
];
//here pushing the values in to an array  
array_push($json_data,$details);  
}
$json_data_all = ["data" => $json_data];

$myfile = fopen("api/v1/ShiftPumpReport/shiftPumpData.txt", "w+") or die("Unable to open file!");;
fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
fclose($myfile);
}
 ?>