<?session_start();
include("../opendb.php");



 $sql="create table eichersap (invno varchar(200),date date,orderdate date,delivery varchar(20),dano varchar(250),podate date,exeinv varchar(25),netamount double(10,2),fertcode varchar(250),configuration varchar(250),chasisno varchar(250),engno varchar(250),suplier varchar(250),entrydate date,status varchar(50),brcode varchar(10))";
 mysqli_query($db,$sql);

if($upd)
{
if($ff !="none")
{
   $fl=$HTTP_POST_FILES['ff']['name'];
   $file_dir=".";
  $tmp_name=$_FILES['ff']['tmp_name'];
print $fl;
   move_uploaded_file($tmp_name,"./$file_dir/$ff_name") or die(' err:could not copy file');
  print "=> File copied :".$fl."<br>";
 }
$fp=fopen("./$file_dir/$ff_name","r") or die("Cant open file");
$i=1;
//include("opendb.php");
$dt=date("Y-m-d");
while(!feof($fp))
{
 $line=fgets($fp,1024);
 $spline=explode("\t",$line);
 if(strlen($spline[0])>0)
 {
 if($spline[0]!='INV NO')

{
$fld = str_replace(".", "-", $spline[1]); 

$dt11=explode("-",$fld);
$dt2=$dt11[2].'-'.$dt11[1].'-'.$dt11[0];

$fld = str_replace(".", "-", $spline[2]); 

$dt11=explode("-",$fld);
$dt3=$dt11[2].'-'.$dt11[1].'-'.$dt11[0];

 $rr2=mysqli_query($db,"select invno from eichersap where invno='$spline[0]'");
  if(mysqli_num_rows($rr2)<=0)
  {

   $sql="insert into eichersap values('$spline[0]','".addslashes(trim($dt2))."','".addslashes(trim($dt3)).
"','".addslashes(trim($spline[3]))."','".addslashes(trim($spline[4]))."','".addslashes(trim($spline[5])).
"','".addslashes(trim($spline[6]))."','".addslashes(trim($spline[7]))."','".addslashes(trim($spline[8])).
"','".addslashes(trim($spline[9]))."','".addslashes(trim($spline[10]))."','".addslashes(trim($spline[11]))."','".addslashes(trim($spline[12]))."','$dt','Billed By Eicher','$brcode')";
print "<br>".$sql;
  mysqli_query($db,$sql) or die(mysqli_error());
} 
}
}
}
print "<script> alert('Done');</script>";
}

?>

<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<br><br><br><br><br><br>
<form action='upldeichersap.php' method='post' ENCTYPE="multipart/form-data">
<table border=1>
<tr><td>
<table>
<th colspan=2>Upload INS Data
<tr><td>File </td><td><input type=file name='ff'></td></tr>
<tr><td><input type=submit value='Upload' name='upd'></td></tr>
</table>
</td></tr>
</table>
</form>
