<?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');
    
    $vehicleid          = stripslashes($_POST['vehicleid']);
	
	 $driverid          = stripslashes($_POST['driverid']);
    $inchargeid           = stripslashes($_POST['inchargeid']);
    $previouskms           = stripslashes($_POST['previouskms']);
    $previoushrs           = stripslashes($_POST['previoushrs']);
	$preiousqty           = stripslashes($_POST['preiousqty']);
   
	
	
    $intakekm           = stripslashes($_POST['intakekm']);
    $intakehrs           = stripslashes($_POST['intakehrs']);
    $qty                = stripslashes($_POST['eqty']);
	$mileage                = stripslashes($_POST['mileage']);
	$hmileage                = stripslashes($_POST['hmileage']);
	$remarks                = stripslashes($_POST['remarks']);
	
	
	
	$sql=mysqli_query($conn,"select * from employee_master where id='".$driverid."'");
	
	while($row=mysqli_fetch_array($sql))
	{
		$drivername=$row['ename'];
	}
	
	$sql1=mysqli_query($conn,"select * from employee_master where id='".$inchargeid."'");
	
	while($row1=mysqli_fetch_array($sql1))
	{
		$inchargename=$row1['ename'];
	}
	
	
	$sqlv=mysqli_query($conn,"select * from vehicle_master where id='".$vehicleid."'");
	
	while($rowv=mysqli_fetch_array($sqlv))
	{
		$vehicleno=$rowv['vehicleno'];
	}
    
    $accountyear    = $financialYearStart."-".$financialYearEnd;
    $createdate  	= date("Y-m-d");
    $createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];
    
    

    $sql_update = "UPDATE internalpro_diesel SET dieseldate='".$internalprodate."',vehicleid='".$vehicleid."',vehicleno='".$vehicleno."',driverid='".$driverid."',drivername='".$drivername."',inchargeid='".$inchargeid."',inchargename='".$inchargename."',previouskms='".$previouskms."',previoushrs='".$previoushrs."',preiousqty='".$preiousqty."',intakekm='".$intakekm."',intakehrs='".$intakehrs."',litres='".$qty."',mileage='".$mileage."',hmileage='".$hmileage."',remarks='".$remarks."',lastupdated='".$createdate."' WHERE invoice='".$invoice."'";

    mysqli_query($conn,$sql_update);
	
	$sql_header1  = "update fill_diesel set dieseldate='".$internalprodate."',vehicleid='".$vehicleid."', vehicleno='".$vehicleno."',driverid='".$driverid."',drivername='".$drivername."',intakekm='".$intakekm."',intakehrs='".$intakehrs."',litres='".$qty."',accountyear='".$accountyear."',createdate='".$createdate."',createdby='".$createdby."',userID='".$userID."' WHERE invoice='".$invoice."' and filling_type='internalfill'";
    
    mysqli_query($conn,$sql_header1);
	
		$sql_header2  = "update total_litres set dieseldate='".$internalprodate."',vehicleid='".$vehicleid."', vehicleno='".$vehicleno."',driverid='".$driverid."',drivername='".$drivername."',intakekm='".$intakekm."',intakehrs='".$intakehrs."',litres='".$qty."',accountyear='".$accountyear."',createdate='".$createdate."',createdby='".$createdby."',userID='".$userID."' WHERE invoice='".$invoice."' and filling_type='internalfill'  ";
    
    mysqli_query($conn,$sql_header2);
    
    header("Location:inDieselProDashboard.php");

}
?>
