<?php
include 'dbConfig.php';
if(isset($_POST["Import"])){
//$sql = "UPDATE `update_tbl` SET `update_date_time`=NOW() WHERE `update_id` ='2021'";	

date_default_timezone_set("Asia/Riyadh");
//$date=date('Y-m-d H:i:s');

$emapData[11];

$date[11]=date_create("$emapData[11]");

//date_format($date,"d/m/Y H:i:s");
$date=date('d-m-Y H:i:s');

//mysqli_query($conn, "UPDATE `update_tbl` SET `update_date_time`='$date' WHERE `update_id` = '2021'") or die(mysqli_error());	


date_default_timezone_set("Asia/Riyadh");
$createdDate = date("Y-m-d h:i:sa");

$user_id = $_POST["user_id"];

echo $filename=$_FILES["file"]["tmp_name"];
		
if($_FILES["file"]["size"] > 0)		 
$file = fopen($filename, "r");
 while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
  {
	
	$d1=$emapData[5];
$date_convert=date("Y-m-d", strtotime($d1));
$time_convert=date("h:i:s", strtotime($d1));
//
$sql24="SELECT * FROM petrol_tbl where no='".$emapData[0]."' AND plate_number='".$emapData[1]."' AND price='".$emapData[2]."' and vat='".$emapData[3]."' and total='".$emapData[4]."' and date_time='".$emapData[5]."' and date='".$date_convert."' and time='".$time_convert."' and Add_Type='EXCEL' and invoice_copy='ex'";
  $result24 = $conn->query($sql24);
 if ($result24->num_rows > 0) {

 }else{
    $sql = "INSERT into petrol_tbl (`no`, `plate_number`,`price`,`vat`,`total`,`date_time`,`date`,`time`,`Add_Type`,`invoice_copy`,createdDate_time,user_id)    
	values('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$date_convert','$time_convert','EXCEL','ex','$createdDate','$user_id')";
    	 $result = mysqli_query( $conn, $sql );
        if(! $result)
        {
        
        }else{
            $i++;
        }
 }
 if($i>0)
 {
      echo "<script type=\"text/javascript\">
         alert(\"CSV File has been successfully Imported.\");
         window.location = \"Add_Petrol_Excel.php?lang=$lang&company_id=$company_idd\"
     </script>";
     
 
 
 }else{
         echo "<script type=\"text/javascript\">
             alert(\"Invalid File:Please Upload CSV File.\");
             window.location = \"Add_Petrol_Excel.php?lang=$lang&company_id=$company_idd\"
         </script>";
 }
//

	         }
	         fclose($file);
			 //close of connection
			mysqli_close($conn); 
				
		 	
			
		 }
		 
		 
		 
		 
		 
		 
	//}	 
?>		








 


