<?php
include 'connection.php';
$uploadedStatus = 0;

if ( isset($_POST["submit"]) ) {
if ( isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
if (file_exists($_FILES["file"]["name"])) {
unlink($_FILES["file"]["name"]);
}
$storagename = "discussdesk.xlsx";
move_uploaded_file($_FILES["file"]["tmp_name"],  $storagename);
$uploadedStatus = 1;
}
} else {
echo "No file selected <br />";
}
}

?>


						
     <?php
/************************ YOUR DATABASE CONNECTION START HERE   ****************************/

define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "threejne_crmuser"); // set database user
define ("DB_PASS","Se++$lf[b5,J"); // set database password
define ("DB_NAME","threejne_CRM"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

$databasetable = "job_registar";

/************************ YOUR DATABASE CONNECTION END HERE  ****************************/


set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';

// This is the file path to be uploaded.
$inputFileName = 'discussdesk.xlsx'; 

try {
	$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
	die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}


$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
echo $arrayCount = count($allDataInSheet);  // Here get total count of row in that Excel sheet

for($i=2;$i<=$arrayCount;$i++){
$Job_Dt = trim($allDataInSheet[$i]["A"]);
$Job_No = trim($allDataInSheet[$i]["B"]);
$Importer = trim($allDataInSheet[$i]["C"]);
$Supplier = trim($allDataInSheet[$i]["D"]);
$Invoice_No = trim($allDataInSheet[$i]["E"]);
$Invoice_Dt = trim($allDataInSheet[$i]["F"]);
$Commodity = trim($allDataInSheet[$i]["G"]);
$POL = trim($allDataInSheet[$i]["H"]);
$Country = trim($allDataInSheet[$i]["I"]);
$POD = trim($allDataInSheet[$i]["J"]);
$PKGS = trim($allDataInSheet[$i]["K"]);
$Net_WT = trim($allDataInSheet[$i]["L"]);
$Gr_WT = trim($allDataInSheet[$i]["M"]);
$No_Of_Cntr = trim($allDataInSheet[$i]["N"]);
$Size = trim($allDataInSheet[$i]["O"]);
$Cntr_no = trim($allDataInSheet[$i]["P"]);
$Fcl_Lcl = trim($allDataInSheet[$i]["Q"]);
$Load_Destuff = trim($allDataInSheet[$i]["R"]);
$Currency = trim($allDataInSheet[$i]["S"]);
$Terms_Of_Shipment = trim($allDataInSheet[$i]["T"]);
$Invoice_Value_In_FRN_Currency = trim($allDataInSheet[$i]["U"]);
$Invoice_Value_In_Rs = trim($allDataInSheet[$i]["V"]);
$CIF_IN_RS = trim($allDataInSheet[$i]["W"]);
$ASS_VAL_IN_RS = trim($allDataInSheet[$i]["X"]);
$SCHEME = trim($allDataInSheet[$i]["Y"]);
$DUTY = trim($allDataInSheet[$i]["Z"]);



$query = "SELECT Job_Dt FROM job_registar WHERE Job_No = '".$Job_No."' and Job_Dt = '".$Job_Dt."' and Importer = '".$Importer."'  and Supplier = '".$Supplier."'  and Invoice_No = '".$Invoice_No."'  and Invoice_Dt = '".$Invoice_Dt."'  and Commodity = '".$Commodity."'  and POL = '".$POL."'  and Country = '".$Country."'  and POD = '".$POD."'   and PKGS = '".$PKGS."'  and Net_WT = '".$Net_WT."'  and Gr_WT = '".$Gr_WT."'  and No_Of_Cntr = '".$No_Of_Cntr."'  and Size = '".$Size."'  and Cntr_no = '".$Cntr_no."'  and Fcl_Lcl = '".$Fcl_Lcl."'  and Load_Destuff = '".$Load_Destuff."'   and Currency = '".$Currency."'  and Terms_Of_Shipment = '".$Terms_Of_Shipment."' and Invoice_Value_In_FRN_Currency = '".$Invoice_Value_In_FRN_Currency."' and Invoice_Value_In_Rs = '".$Invoice_Value_In_Rs."' and CIF_IN_RS = '".$CIF_IN_RS."' and ASS_VAL_IN_RS = '".$ASS_VAL_IN_RS."' and SCHEME = '".$SCHEME."' and DUTY = '".$DUTY."'";
$sql = mysql_query($query);
echo $query;
$recResult = mysql_fetch_array($sql);
$existName = $recResult["Job_Dt"];
if($existName=="") {
$insertTable= mysql_query("insert into job_registar (Job_No, Job_Dt, Importer, Supplier, Invoice_No, Invoice_Dt, Commodity, POL, Country, POD, PKGS, Net_WT, Gr_WT, No_Of_Cntr, Size, Cntr_no, Fcl_Lcl,Load_Destuff,Currency,Terms_Of_Shipment,Invoice_Value_In_FRN_Currency,Invoice_Value_In_Rs,CIF_IN_RS,ASS_VAL_IN_RS,SCHEME,DUTY) values('".$Job_No."', '".$Job_Dt."', '".$Importer."', '".$Supplier."', '".$Invoice_No."', '".$Invoice_Dt."', '".$Commodity."', '".$POL."', '".$Country."', '".$POD."', '".$PKGS."', '".$Net_WT."', '".$Gr_WT."', '".$No_Of_Cntr."', '".$Size."', '".$Cntr_no."', '".$Fcl_Lcl."', '".$Load_Destuff."', '".$Currency."', '".$Terms_Of_Shipment."', '".$Invoice_Value_In_FRN_Currency."', '".$Invoice_Value_In_Rs."', '".$CIF_IN_RS."', '".$ASS_VAL_IN_RS."', '".$SCHEME."', '".$DUTY."');");


$msg = 'Record has been added. <div style="Padding:20px 0 0 0;"></div>';
} else {
$msg = 'Record already exist. <div style="Padding:20px 0 0 0;"></div>';
}
}
 

?>
               
         
		  
	<?php 	  echo $msg; ?>

		  


  <?php include 'footer.php';
  ?>
