<?php
session_start();
require_once("config/configDB.php"); 
require "financial_year_calculation.php";

function validation_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $edit_id   = stripslashes($_POST['edit_id']);
    $invoice   = stripslashes($_POST['invoice']);
    
    $tdate_temp         = new DateTime(stripslashes($_POST['internalprodate']));
    $internalprodate 	= $tdate_temp->format('Y-m-d');
    $vhid          = stripslashes($_POST['vehicleno']);
	
	$driverid                = stripslashes($_POST['driverid']);
	$sql=mysqli_query($conn,"select * from employee_master where id='".$driverid."'");
	
	while($row1=mysqli_fetch_array($sql))
	{
		$drivername=$row1['ename'];
	}
	
	$sq=mysqli_query($conn,"select vehicleno as a from vehicle_master where id='".$vhid."'");
	
		while($row=mysqli_fetch_array($sq))
		{
		
	
    $vehicleno          = $row['a'];
	
		}
		
		
    $odometerkm           = stripslashes($_POST['odometerkm']);
    $odometerhours           = stripslashes($_POST['odometerhours']);
    $qty                = stripslashes($_POST['eqty']);
    
    $createdate  	= date("Y-m-d");
	$createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];

    $sql_update = "UPDATE internalunfillpro_diesel SET ";
    $sql_update .= "dieseldate='$internalprodate',";
	$sql_update .= "vehicleid='$vhid',";
    $sql_update .= "vehicleno='$vehicleno',";
	$sql_update .= "driverid='$driverid',";
	 $sql_update .= "drivername='$drivername',";
    $sql_update .= "intakekm='$odometerkm',";
    $sql_update .= "intakehrs='$odometerhours',";
    $sql_update .= "litres='$qty',";
    $sql_update .= "lastupdated='$createdate'";
    $sql_update .= "WHERE id='$edit_id' ";

    mysqli_query($conn,$sql_update);
	
	$sql_header2  = "update total_litres set dieseldate='".$internalprodate."',vehicleid='".$vhid."', vehicleno='".$vehicleno."',driverid='".$driverid."',drivername='".$drivername."',intakekm='".$odometerkm."',intakehrs='".$odometerhours."',litres='".$qty."',createdate='".$createdate."',createdby='".$createdby."',userID='".$userID."' WHERE invoice='".$invoice."' and filling_type='internalunfill'";
    
    mysqli_query($conn,$sql_header2);
	
	
	
    
    header("Location:inDieselunfillProDashboard.php");

}
?>
