<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'];
$sub_category=$_GET['sub_category'];
echo $sub_category;
if ($sub_category=='Trusses') {
	$type1=$_GET['type_1_text'];
	$type2=$_GET['type_2_text'];
	$type3=$_GET['type_3_text'];
	$truss_type=$type1.$type2.$type3;
	$quantity = $_GET['qty_text'];
	$press_points = $_GET['press_points_text'];
	$span = $_GET['span_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 truss_type = '".$truss_type."' AND job_no = '".$job_no."' UNION ALL SELECT bill_line_id FROM $table_name WHERE truss_type = '".$truss_type."' AND job_no = '".$job_no."'";
		$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, truss_type, quantity, span, press_points, user ) VALUES ('".$job_no."', '0', '".$bill_id."', 'truss', '".$truss_type."', '".$quantity."', '".$span."', '".$press_points."', '".$_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&edit=1&sub_category=";
</script>

