<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--reference to main.css removed-->
<?php
include ("../navigation/header.php");
$page_name = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");


$del_note = $_GET['del_note'];
$supply_id = $_GET['supply_id'];
$pr_option = $_GET['pr_option'];

?>
<link rel="stylesheet" type="text/css" href="../css/main.css" />

</head>
<?php

$table_name = $_SESSION['db_prefix']."_permissions";
$print_permission_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'Stores-print-copy' ";
$print_permission_result = mySQL_query($print_permission_query);
$print_permission_num = mysql_num_rows($print_permission_result);
if ($print_permission_num==1) {
$print_permission = 'yes';
}
else {
	$print_permission = 'no';
}


$table_name = $_SESSION['db_prefix']."_supply_customer";
$deliver_query = "SELECT * FROM $table_name WHERE delivery_note = '".$del_note."'  ";
$deliver_result = mySQL_query($deliver_query);
$deliver_num = mysql_num_rows($deliver_result);
$a1 = mysql_result($deliver_result, 0, "job_no");
$a2 = mysql_result($deliver_result, 0, "cust_id");
$a3 = mysql_result($deliver_result, 0, "delivery_note");
$a4 = mysql_result($deliver_result, 0, "delivery_address");
$a5 = mysql_result($deliver_result, 0, "delivered_by");
$a6 = mysql_result($deliver_result, 0, "vehicle_reg");
$a7 = mysql_result($deliver_result, 0, "delivery_date");
$a8 = mysql_result($deliver_result, 0, "delivery_time");

$job_no = $a1;
$quote='';
$cust_id = $a2;

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$comp_name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$comp_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
	

$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$trusses_query = "SELECT job_no, truss_type, timber_type, quantity, user FROM $table_name WHERE supply_id = '".$supply_id."' AND timber_type = 'Trusses' ";
$trusses_result = mySQL_query($trusses_query);
$trusses_num = mysql_num_rows($trusses_result);

$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$summary_query = "SELECT * FROM $table_name WHERE supply_id = '".$supply_id."' AND truss_type = 'bracing'  ";
$summary_result = mySQL_query($summary_query);
$summary_num = mysql_num_rows($summary_result);
//echo '<br>'.$summary_query;


$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$summary2_query = "SELECT * FROM $table_name WHERE supply_id = '".$supply_id."' AND truss_type = 'sundries'  ";
$summary2_result = mySQL_query($summary2_query);
$summary2_num = mysql_num_rows($summary2_result);
//echo '<br>'.$summary_query;



$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$mitek_query = "SELECT job_no, truss_type, store_item_id, timber_type, quantity, user FROM $table_name WHERE supply_id = '".$supply_id."' AND truss_type = 'Mitek'";
//echo '<br>'.$mitek_query;
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);


$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$additional_query = "SELECT job_no, truss_type, store_item_id, timber_type, quantity, user FROM $table_name WHERE supply_id = '".$supply_id."' AND truss_type = 'Additional' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);


$table_name = $_SESSION['db_prefix']."_supply_customer_lines";
$cash_query = "SELECT * FROM $table_name WHERE supply_id = '".$supply_id."' AND truss_type = 'Cash'  ";
$cash_result = mySQL_query($cash_query);
$cash_num = mysql_num_rows($cash_result);



$table_name8 = $_SESSION['db_prefix']."_supply_customer";
$deliveries_query = "SELECT delivery_note, supply_id, type, job_no, cust_id, delivery_date FROM $table_name8 WHERE job_no = '".$job_no."' AND job_no!='0' ";
$deliveries_result = mySQL_query($deliveries_query);
$deliveries_num = mysql_num_rows($deliveries_result);


?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />


<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>

<script type="text/javascript">
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
</script>

<body onLoad="MM_changeProp('buttons_non_active','','display','none','DIV')">

<div class="main_frame">

<div class="page_head_frame">
          <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="525"><label class="label_page_head">Delivery note</label>
               <label class="label_page_head_2"> <?php echo $comp_name ?></label></td>
              <td width="141"><label style="font-size:24px; color:#FB6808;"><?php if ($job_no!=0) { echo "J".$job_no;} else { echo 'Cash sale'; } ?></label></td>
              <td width="143"><a href="customer_supplied_print_copy.php?supply_id=<?php echo $supply_id ?>" target="_blank"></a></td>
            </tr>
          </table>
</div> 
       
<div class="page_middle_frame">  

<div class="page_inside_frame"> Other deliveries on this job:     
 <?php if ($deliveries_num>1) { ?>     
        
          <?php 
$i=0;
while ($i<$deliveries_num) {
	$note_no = mysql_result($deliveries_result, $i, "delivery_note");
	$supply_id_1 = mysql_result($deliveries_result, $i, "supply_id");
	$type = mysql_result($deliveries_result, $i, "type");
	//$job_no = mysql_result($deliveries_result, $i, "job_no");
	$date = mysql_result($deliveries_result, $i, "delivery_date");
	$cust_id = mysql_result($deliveries_result, $i, "cust_id");
		$table_name = $_SESSION['db_prefix']."_customer";
		$name_query = "SELECT comp_name  FROM $table_name WHERE cust_id='".$cust_id."'  ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "comp_name");
	
	$deliveryTT="<label class=tip_text_label><table style=font-size:9px;><tr><td>Del note</td><td>".$note_no."</td></tr><tr><td>Name:</td><td>".$name."</td></tr><tr><td>Date:</td><td>".$date."</td></tr></table></label>";
	
	if ($supply_id<>$supply_id_1) {
		if ($type=='job') { ?>
          <a href="customer_supplied.php?del_note=<?php echo $note_no?>&supply_id=<?php echo $supply_id_1?>&pr_option=copy" onMouseover="ddrivetip('<label class=tip_text_label_bold>Delivery</label><br><?php echo $deliveryTT?><label class=tip_text_label_bold>Click for details</label>', 170)"; onMouseout="hideddrivetip()"><?php echo $note_no?></a>
          <?php } else { ?>
          <a href="cash_supplied.php?del_note=<?php echo $note_no?>&supply_id=<?php echo $supply_id_1?>&pr_option=copy" onMouseover="ddrivetip('<label class=tip_text_label_bold>Cash delivery</label><br><?php echo $deliveryTT?><label class=tip_text_label_bold>Click for details</label>', 170)"; onMouseout="hideddrivetip()"><?php echo $note_no?></a>
          <?php
	}
	}
	$i++;
}
}
?>
          <a href="customer_supplied_print.php?supply_id=<?php echo $supply_id ?>" target="_blank"></a>
          </div>
          
        <div class="page_inside_frame">
        <?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
        </div>
        
        <div class="page_inside_frame">
          <table width="646" align="left" id="table_details_display" >
            <tr>
              <td width="136" align="left" valign="top">Delivery note no:</td>
              <td align="left" valign="top"><?php echo $a3 ?></td>
              <td align="left" valign="top">Date:</td>
              <td align="left" valign="top"><?php echo date("d-m-Y", strtotime($a7)); ?></td>
            </tr>
            <tr>
              <td align="left" valign="top">Delivery address:</td>
              <td width="215" align="left" valign="top"><?php echo $a4 ?></td>
              <td width="92" align="left" valign="top">Time:</td>
              <td width="183" align="left" valign="top"><?php echo $a8; ?></td>
            </tr>
            <tr>
              <td align="left" valign="top">Vehicle:</td>
              <td align="left" valign="top"><?php echo $a6 ?></td>
              <td align="left" valign="top">Driver:</td>
              <td align="left" valign="top"><?php echo $a5 ?></td>
            </tr>
          </table>
          </div>
          
         <div class="page_inside_frame";>
          <table width="646" align="left" id="table_details_display_grey" >
            <tr >
              <td width="350" align="left" valign="top"><b>
                <label class="label_std">Item</label>
                </b></td>
              <td width="96" align="left" valign="top"><b>Deliver qty</b></td>
              <td width="184" align="left" valign="top">&nbsp;</td>
            </tr>
          </table>
        <br>
<br>

          <?php if ($trusses_num!=0) { ?>
          <table width="646" align="left" id="table_details_display" style="margin-top:10px;" >
            <tr style="border-bottom-style:double;">
              <td colspan="2" align="left" valign="top"><label class="label_std">Trusses:</label></td>
            </tr>
            <?php 
				  $i=0;
				  
				  while ($i<$trusses_num) {
				  		$f1 = mysql_result($trusses_result, $i, "truss_type");
						$f2 = mysql_result($trusses_result, $i, "quantity"); 			
				 ?>
            <tr>
              <td width="353"><?php echo $f1 ?></td>
              <td width="273"><?php echo $f2 ?>&nbsp;&nbsp;no</td>
            </tr>
            <?php
			  $i++;
             }
             ?>
          </table>
        <br>
<br>

        <?php }
 if ($summary_num!=0) { ?>
        
          <table width="646" align="left" id="table_details_display" style="margin-top:10px;" >
            <tr>
              <td colspan="3" align="left" valign="top" ><label class="label_std">Bracing timber:</label></td>
            </tr>
            <?php 
				  $k=0;
				  $temp_name='';
				  while ($k<$summary_num) { 
					    $c1 = mysql_result($summary_result, $k, "timber_type");
						$c2 = mysql_result($summary_result, $k, "store_item_id");
						$table_name = $_SESSION['db_prefix']."_store_items";
							$name_query = "SELECT length FROM $table_name WHERE  store_item_id = '".$c2."' ";
							$name_result = mySQL_query($name_query);
							$c2a = mysql_result($name_result, 0, "length");
						$c3 = mysql_result($summary_result, $k, "tot_length"); 
						$c4 = mysql_result($summary_result, $k, "quantity");  
						
				 ?>
            <tr <?php if ( $temp_name!=$c1) {?>style="border-top:double;"<?php } ?>>
              <td width="235"><?php if ($temp_name!=$c1) echo $c1; ?>
                <?php $temp_name=$c1;?></td>
              <td width="111"><?php echo number_format($c2a/1000, 2, '.', ',') ?> m</td>
              <td><?php echo $c4 ?> no</td>
            </tr>
            <?php
			  $k++;
             }
             ?>
          </table>
        <br>
<br>

        <?php }
 if ($summary2_num!=0) { ?>
        
          <table width="646" align="left" id="table_details_display"  style="margin-top:10px;" >
            <tr>
              <td colspan="3" align="left" valign="top"><label class="label_std">Sundries timber:</label></td>
            </tr>
            <?php 
				  $k=0;
				  $temp_name='';
				  while ($k<$summary2_num) { 
					    $c1 = mysql_result($summary2_result, $k, "timber_type");
						$c2 = mysql_result($summary2_result, $k, "store_item_id");
						$table_name = $_SESSION['db_prefix']."_store_items";
							$name_query = "SELECT length FROM $table_name WHERE  store_item_id = '".$c2."' ";
							$name_result = mySQL_query($name_query);
							$c2a = mysql_result($name_result, 0, "length");
						$c3 = mysql_result($summary2_result, $k, "tot_length"); 
						$c4 = mysql_result($summary2_result, $k, "quantity");  
						
				 ?>
            <tr <?php if ( $temp_name!=$c1) {?>style="border-top:double;"<?php } ?>>
              <td width="235"><?php if ($temp_name!=$c1) echo $c1; ?>
                <?php $temp_name=$c1;?></td>
              <td width="111"><?php echo number_format($c2a/1000, 2, '.', ',') ?> m</td>
              <td><?php echo $c4 ?> no</td>
            </tr>
            <?php
			  $k++;
             }
             ?>
          </table>
        <br>
<br>

        <?php }
 if ($mitek_num!=0) { ?>
        
          <table width="646" align="left" id="table_details_display"  style="margin-top:10px;" >
            <tr style="border-bottom-style:double;">
              <td colspan="2" align="left" valign="top"><label class="label_std">Mitek products:</label></td>
            </tr>
            <?php 
				  $j=0;
				  while ($j<$mitek_num) { 
					    $e1 = mysql_result($mitek_result, $j, "timber_type");
						$e2 = mysql_result($mitek_result, $j, "store_item_id");
						$table_name = $_SESSION['db_prefix']."_store_items";
							$name_query = "SELECT item_name, unit FROM $table_name WHERE  store_item_id = '".$e2."' ";
							$name_result = mySQL_query($name_query);
							$e2a = mysql_result($name_result, 0, "item_name");
							$e4 = mysql_result($name_result, 0, "unit");
						$e3 = mysql_result($mitek_result, $j, "quantity");  
						
				 ?>
            <tr>
              <td width="354"><?php echo $e2a ?></td>
              <td width="280"><?php echo $e3.'&nbsp;&nbsp;'.$e4 ?></td>
            </tr>
            <?php
				
			  $j++;
             }
             ?>
          </table>
        <br>
<br>
        <?php }
 if ($additional_num!=0) { ?>
        
          <table width="646" align="left" id="table_details_display" style="margin-top:10px;">
            <tr style="border-bottom-style:double;">
              <td colspan="2" align="left" valign="top"><label class="label_std">Additional sundries:</label></td>
            </tr>
            <?php 
				  $n=0;
				  while ($n<$additional_num) { 
					    $g1 = mysql_result($additional_result, $n, "timber_type");
						$g2 = mysql_result($additional_result, $n, "store_item_id");
						$table_name = $_SESSION['db_prefix']."_store_items";
							$name_query = "SELECT item_name, unit FROM $table_name WHERE  store_item_id = '".$g2."' ";
							$name_result = mySQL_query($name_query);
							$g2a = mysql_result($name_result, 0, "item_name");
							$g4 = mysql_result($name_result, 0, "unit");
						$g3 = mysql_result($additional_result, $n, "quantity");  
						
				 ?>
            <tr>
              <td width="354"><?php echo $g2a ?></td>
              <td width="280"><?php echo $g3.'&nbsp;&nbsp;'.$g4; ?></td>
            </tr>
            <?php
				
			  $n++;
             }
             ?>
          </table>
          
        
        <?php } 
		if ($cash_num!=0) { ?>
        
          <table width="646" align="left" id="table_details_display" >
            <?php 
				  $n=0;
				  while ($n<$cash_num) { 
					    $g1 = mysql_result($cash_result, $n, "timber_type");
						$g2 = mysql_result($cash_result, $n, "store_item_id");
						$table_name = $_SESSION['db_prefix']."_store_items";
							$name_query = "SELECT item_name, unit FROM $table_name WHERE  store_item_id = '".$g2."' ";
							$name_result = mySQL_query($name_query);
							$g2a = mysql_result($name_result, 0, "item_name");
							$g4 = mysql_result($name_result, 0, "unit");
						$g3 = mysql_result($cash_result, $n, "quantity");  
						
				 ?>
            <tr>
              <td width="354"><?php echo $g2a ?></td>
              <td width="280"><?php echo $g3.'&nbsp;&nbsp;'.$g4; ?></td>
            </tr>
            <?php
				
			  $n++;
             }
             ?>
          </table>
        
        <?php } ?>
        <br />
        <br />
        </div>
        
<div class="page_inside_frame">   
<?php 
if ($pr_option=='all') { ?>
<div align="right" >
<div id="buttons_active" style="display:block; margin-top:20px;">
<a href="customer_supplied_print_cod.php?supply_id=<?php echo $supply_id?>" target="_blank"><input name="del_1_button" type="button" class="imagebutton" id="del_1_button" onClick="MM_changeProp('buttons_active','','display','none','DIV');MM_changeProp('buttons_non_active','','display','block','DIV')"  value="Print for delivery" >
</a>
<a href="customer_supplied_print_co.php?supply_id=<?php echo $supply_id?>" target="_blank">
<input name="col_1_button" type="button" class="imagebutton" id="col_1_button" onClick="MM_changeProp('buttons_active','','display','none','DIV');MM_changeProp('buttons_non_active','','display','block','DIV')"  value="Print for collection" >
</a>
<a href="customer_supplied_print_cod.php?supply_id=<?php echo $supply_id?>" target="_blank"></a>
</div>
</div>


<div id="buttons_non_active" style=" display:block;  margin-top:20px; ">
<div align="right"><input name="del_2_button"  id="del_2_button" type="button" class="dis_imagebutton"  value="Print for delivery" >
<input name="del_2_button"  id="col_2_button" type="button" class="dis_imagebutton"  value="Print for collection" >
</div>
</div>
</div>
<?php }
else { ?>
<div align="right">
<?php if ($print_permission=='yes') {?><a href="customer_supplied_print_copy.php?supply_id=<?php echo $supply_id ?>" target="_blank"><input name="button" type="button" class="imagebutton" id="button" value="Print copy" > <?php } else { ?>  <input name="button" type="button" class="dis_imagebutton" id="button" value="Print copy" > <?php } ?>
</a></div>
<?php } ?>
</div>
</div>
</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else {
$_SESSION['denied_return'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
</html>