<?php
include("../include/session.php");

$userId = $_SESSION['username'];
date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s"); 




$i=0;
while ($i<$_SESSION['line_num']) {	
$table_name = $_SESSION['db_prefix']."_mworks_job_components";
$update_query = "UPDATE $table_name SET produced_quantity = produced_quantity + '".$_SESSION['new_produced'.$i]."' WHERE job_card_no = '".$_SESSION['job_card_no']."' AND  component = '".$_SESSION['component'.$i]."' ";
execsql($update_query);

$table_name = $_SESSION['db_prefix']."_mworks_job_components";
$check_query = "SELECT job_card_no FROM $table_name WHERE job_card_no = '".$_SESSION['job_card_no']."' AND (quantity-produced_quantity) > 0 ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);

if ($check_num>0) {
	$done ='part';
}
else {
	$done = 'yes';
}

$i++;
}


//if ($_SESSION['mworks']=='only') { $delivered='no';} else {$delivered='';}

$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$update_query = "UPDATE $table_name SET  production='".$done."'  WHERE job_card_no = '".$_SESSION['job_card_no']."' ";
execsql($update_query);


$table_name = $_SESSION['db_prefix']."_mworks_production_report";
$inspection_query = "INSERT INTO $table_name (job_card_no, cust_id, production_date, inspected_by, job_approved ) VALUES ('".$_SESSION['job_card_no']."', '".$_SESSION['cust_id']."', '".$_SESSION['inspection_date']."', '".$_SESSION['inspect']."', '".$_SESSION['approved']."' ) ";
execsql($inspection_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']."', '102', '".$_SESSION['job_card_no']."', '".$_SESSION['project']."' ,'".$_SESSION['inspect']."','' )";
$trackingResult = mySQL_query($trackingQuery);

include('../include/m_production_alert.php');
	
	
$job_card_no = $_SESSION['job_card_no'];
 
	 	$_SESSION['job_card_no']='';
	 	$_SESSION['name']="";
	 	$_SESSION['deliver_date']='';
	 	$_SESSION['cust_id']='';
	 
	 	$_SESSION['quote_note'] = '';
		$_SESSION['inspect']='';
		$_SESSION['cust_id']='';
		$_SESSION['order_date']='';
		$_SESSION['project_description'] = '';
		$_SESSION['project'] = '';
		$_SESSION['project_no'] = '';
		$_SESSION['project_place'] = '';
		$_SESSION['project_area'] = '';
		$_SESSION['deliver_date'] = '';
		$_SESSION['work_days'] = '';
		$_SESSION['value'] = '';
		$_SESSION['deliver_date']= '';

      $_SESSION['forman']='';
		$_SESSION['forman_name']='';
	 	
		
?>

<script language="javascript" type="text/javascript">
        
		  window.location="production_report.php?job_card_no=<?php echo $job_card_no ?>" ;
        
       </script>

