<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<?php 
include('../include/session.php');

$job_no = $_GET['job_no'];
$bill_id = $_GET['bill_id'];

$store_item_id=$_GET['store_item_select'];

	
	$quantity = $_GET['quantity_text'];
	$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
	$table_name2 = $_SESSION['db_prefix']."_cutting_bill_lines_edit_temp";
		
	$check_query = "SELECT bill_line_id FROM $table_name WHERE type = 'timber' AND bill_id = '".$bill_id."' AND store_item_id='".$store_item_id."' UNION ALL SELECT bill_line_id FROM $table_name2 WHERE type = 'timber' AND bill_id = '".$bill_id."' AND store_item_id='".$store_item_id."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {	
		$truss_query = "INSERT INTO $table_name2 (job_no, bill_line_id, bill_id, type, store_item_id, quantity, user ) VALUES ('".$job_no."', '0', '".$bill_id."', 'timber', '".$store_item_id."', '".$quantity."', '".$_SESSION['username']."' ) ";
		execsql($truss_query);
		
	   }	
		else {
			?>
            <script>
			alert('This item is already in the list and will not be added to the list.\r\n\r\nIf you require additional quantity, you should edit the quantity in the list. ');
			</script>
            <?php 
		}

		
				   ?>
		<script language="javascript" type="text/javascript">
		 // window.location="../production/cutting_bill_edit.php?job_no=<?php echo $job_no ?>&screen=0&sub_category=&edit=1"; 
		 window.location="../production/cutting_bill_edit.php?job_no=<?php echo $job_no ?>&screen=0&sub_category=&edit=1";
      </script>


