<?php
include('../include/session.php');
date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$production_no = $_GET['production_no_text'];
$line_num = $_GET['line_num'];

$i=0;
while ($i<$line_num) {
	$plan_line_id = $_GET['plan_line_id'.$i];
	$saved_quantity = $_GET['saved_quantity'.$i];
	$quantity = $_GET['count_text'.$i];
	$count_date = $_GET['count_date'.$i];
	
	if ($quantity!='') {
	  
	   $table_name = $_SESSION['db_prefix']."_production_plan_lines";		
	   $skip_update_query = "UPDATE $table_name SET quantity = '".$quantity."' WHERE plan_line_id = '".$plan_line_id."' ";
	   execsql($skip_update_query);
	   	  	   
	   $table_name = $_SESSION['db_prefix']."_tracking_production";
	   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '83', '".$production_no."' ,'".$count_date."','".$saved_quantity."','".$quantity."' )";
	   execsql($trackingQuery);
}
$i++;
}

?>
       <script>
	 	   window.location="../production/production_plan.php?production_no=<?php echo $production_no?>";
		</script>
