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

$job_no = $_GET['job_no'];
$line_no = $_GET['line_no'];
$today=date("Y-m-d");

$table_name = $_SESSION['db_prefix']."_deliver_job";
$deliver_query = "INSERT INTO $table_name (job_no, add_no, date ) VALUES ('".$job_no."', '0', '".$today."' ) ";
execsql($deliver_query);

$table_name = $_SESSION['db_prefix']."_deliver_job";
$id_query = "SELECT deliver_job_id FROM $table_name ORDER BY deliver_job_id DESC LIMIT 1 ";
$id_result = mySQL_query($id_query);
$id = mysql_result($id_result, 0, "deliver_job_id");

$i=0;
while ($i<$line_no) {
	$quantity = $_GET['quantity'.$i];
	$product_id = $_GET['product_id'.$i];
	if ($quantity>0) {
	$table_name = $_SESSION['db_prefix']."_deliver_job_lines";
	$line_query = "INSERT INTO $table_name (deliver_job_id, job_no, product_id, quantity ) VALUES ('".$id."', '".$job_no."', '".$product_id."', '".$quantity."' ) ";
	execsql($line_query);
	}
	$i++;
}

?>

<script language="javascript" type="text/javascript">
          window.location="../production/deliver_job.php?job_no=<?php echo $job_no ?>";
</script>
