<?php
//die("hii");
set_time_limit(0);
ini_set('memory_limit','1024M');
ini_set('post_max_size','32M');
ini_set('upload_max_filesize ','32M');

$destdir  = "live-data-migration-csvs/";
$name     = "Suppier_parts_mapping.csv";
$destfile = $destdir.$name;  

$batch_size = 3000;
$table_name = "supplier_management";
$records_inserted = 0;
$records_updated = 0;  
                                   
$flag = true;
$fp = fopen($destfile, 'r');
while (!feof ($fp)){
  $buffer = fgetcsv($fp, 1000000, ',');  
  if($flag) { 
	  if($buffer){
			$variable_array = array("Supplier","Part_Number");
			foreach($variable_array as $key=>$val){		
				//${$val} = addslashes(trim(strtolower($buffer[$key])));
				${$val} = addslashes(trim($buffer[$key]));
			}
			if($Supplier == "Supplier"){
				continue;
			}
			
		
			
			$supplier_id = utility::getTableFieldById(
				"supplier_management",  
				"id",                     
				"supplier_code",          
				$Supplier           
			);
			$created_by					= $_SESSION['user_id'];
        	$created_on					= date("Y-m-d H:i:s");	
        	$updated_by					= $_SESSION['user_id'];
			
			$records_updated++;
			$sql = "UPDATE item_management 
					SET type_2 = '$supplier_id' 
					WHERE part_number = '$Part_Number'";

			mysqli_query($conn, $sql);
	  }
  }
}
?>
<?php 
if($records_inserted){    
  echo '<br><span style="font-family:calibri;color:red;">'.($records_inserted).' records has been inserted...</span>';
}?>
 <?php 
if($records_updated){    
  echo '<br><span style="font-family:calibri;color:red;">'.($records_updated).' records has been updated...</span>';
}?>