<?php
include("../include/session.php");
if( !$session->isAdmin() && !$session->isRadstoneReceptionUser() && !$session->isRadstoneStoreUser() ){
	//header("Location: ../Store/storeMenu.php");?>
	<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
	   <?php 
}else{
//	include("../include/db.php");
	
	
	include("../storeHeader.php");
	
	$delNo =  mysql_real_escape_string($_GET['DelNoText']);	
	
		
	$sel_query = "SELECT * FROM nam_sales WHERE delNote =  $delNo  ";
	$sel_result = execsql($sel_query);
	$sel_num = mysql_num_rows($sel_result);
	
	if ($sel_num==0) {
	  $d3a = "<font size=xsmall color=red><b>Delivery note $delNo not found, search again</b></font";
	  $delNo=0;
	}
	 else {
		$d3a="";
	 }  	
	    
	$displayQuery = "SELECT * FROM nam_sales WHERE delNote = '$delNo' ";		
	$displayQueryResult = mySQL_query($displayQuery) or die ("Error in query:   $Query . * ". mySQL_error());
	
	$i_d = 0;
	
	$num_d = mysql_num_rows($displayQueryResult);
	
	if ($num_d!=0) {
		$d0 = mysql_result($displayQueryResult, 0, "custNo");
		$d2 = mysql_result($displayQueryResult, 0, "date");
		$d5 = mysql_result($displayQueryResult, 0, "client"); 
		$d3 = mysql_result($displayQueryResult, 0, "delNote");
		$d4 = mysql_result($displayQueryResult, 0, "comments");
		$d6 = mysql_result($displayQueryResult, 0, "orderNo"); 
	}
	else {
		$d0 = "";
		$d2 = "";
		$d5 = "";
		$d3 = "";
		$d6 = "";
		$d16= "";
	}
	
	$delAddressQuery = "SELECT * FROM nam_delivered_address WHERE (delNoteNo ='$d3')";		
	$delAddressResult = mySQL_query($delAddressQuery) or die ("Error in query:   $Query . * ". mySQL_error());
	$delAddressNum = mysql_num_rows($delAddressResult);
	$d55a='';
	if ($delAddressNum!=0) {
	$d51 = mysql_result($delAddressResult, 0, "deliverTo");
	$d52 = mysql_result($delAddressResult, 0, "address");
	$d53 = mysql_result($delAddressResult, 0, "place");
	$d54 = mysql_result($delAddressResult, 0, "contact");
	$d57 = mysql_result($delAddressResult, 0, "transporter");
	$d56 = mysql_result($delAddressResult, 0, "regNo");
	$d55 = mysql_result($delAddressResult, 0, "delCol");
	
	if ($d55=='D') { $d55a="Delivered to:" ; }
	if ($d55=='C') { $d55a="Collected by:" ; }
	}
	else {
		$d51="";
		$d52="";
		$d53="";
		$d54="";
		$d55="";
		$d56="";
		$d57="";
		
		$delColText="";
	}
	
	 
	if ($d3 == "") {
	  $d3 = "";
	  }
	
	
	$clientQuery = "SELECT  CompanyName FROM nam_customer WHERE (custNo ='$d0') ";		
	$clientQueryResult = mySQL_query($clientQuery) or die ("Error in query:   $Query . * ". mySQL_error());
	$clientQueryNum = mysql_num_rows($clientQueryResult); 
	if ($clientQueryNum!=0) {
	    $d1 = mysql_result($clientQueryResult, 0, "CompanyName");
	}
	else { 
	  $d1='';
	}
	$productId='';
	$quantity='';
	
	
?>
<style type="text/css">
<!--
.style1 {
	color: #0066FF;
	font-weight: bold;
}
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; }
.style6 {font-size: small}
.style7 {font-weight: bold}
.style9 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	cursor: pointer;
}


-->
</style>
<script language="JavaScript" src="gen_validatorv4.js"
    type="text/javascript" xml:space="preserve"></script>

<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
	   <link href="../css/main.css" rel="stylesheet" type="text/css" />
	   <div class="headerbox2">View Delivery </div>
<br />

  <table width="590" id="tabledisplay_3">
    <tr>
      <td width="324"><?php if ($sel_num==0) { echo $d3a; } ?></td>
      <td width="254" align="right"><input name="button" type="button" class="linkbutton" id="button" onclick="MM_goToURL('parent','deliveries.php?date=0&search_select=0');return document.MM_returnValue" value="Delivery  List" /></td>
    </tr>
  </table>
<br />

	<table width="590" id="tablePlain">
	  <tr>
	    <td width="115">Delivery No.: </td>
	    <td width="154"><?php echo $d3 ?></td>
	    <td colspan="2"><?php echo $d55a ?></td>
      </tr>
	  <tr>
	    <td valign="top">Date:</td>
	    <td valign="top">
	      <?php if ($d2>'1980-01-01') {echo date("d-m-Y ", strtotime($d2)); } ?>
	    </td>
	    <td width="40" rowspan="4" valign="top">&nbsp;</td>
	    <td width="261" rowspan="4" valign="top"><b><?php echo $d51 ?><br />
        <b><?php echo $d52 ?><br />
        </b><b><?php echo $d53 ?><br />
        </b><b><?php echo $d54 ?><br />
        </b><b>
	      <?php  echo $d57 ?>
	      <br />
	    </b><b>
	    <?php  echo $d56 ?>
	    </b><br />
	    </b></p></td>
      </tr>
	  <tr>
	    <td valign="top">Customer No:</td>
	    <td valign="top">
	      <?php if ($d0==0) {
   echo "--"; }
   else { ?>
        <a href="customerDetails.php?custNo=<?php echo $d0 ?>" onmouseover="ddrivetip('click to view customer details for customer no<?php echo $d0 ?>','#FFFFCC', 180)" onmouseout="hideddrivetip()";><?php echo $d0 ?>
        <?php } ?>
        </a></td>
      </tr>
	  <tr>
	    <td valign="top">Company Name:</td>
	    <td valign="top">
	      <?php if ($d0==0) {
      echo $d5; }
	  else {
	   echo $d1; } ?>
	    </td>
      </tr>
	  <tr>
	    <td valign="top">Order No.:</td>
	    <td valign="top"><a href="viewOrders.php?OrderNoText=<?php echo $d6 ?>" onmouseover="ddrivetip('click to view order<?php echo $d6 ?>','#FFFFCC', 120)" onmouseout="hideddrivetip()";><?php echo $d6 ?></a></td>
      </tr>
	  <tr>
	    <td valign="top">Remarks:</td>
	    <td colspan="3" valign="top"><?php echo $d4 ?></td>
      </tr>
    </table>
<p>
  

<table id="tableList" >
  <thead>
    <tr>
      <th width="56"><span class="style9">Qty</span></th>
      <th width="226"><span class="style9">Item</span></th>
      <th width="147"><span class="style9">Batch code</span> </th>
      <th width="65"><span class="style9">Price</span></th>
      <th width="78"><span class="style9">Total</span></th>
    </tr>
  </thead>
  <tbody>
    <?php 
	
	$d12="0.00";
	if (($sel_num=="0"))
	  {  echo "<br><br><br><br><br><br>This delivery note is empty";
	  }
	  else
	  {
	  
	  while ($i_d < $num_d) {
	  	    
	    $d0 = mysql_result($displayQueryResult, $i_d, "productId");
		
		$cat = "Tiles and Accessories";
	    $productNameQuery = "SELECT productId, productName, price FROM nam_products WHERE productId = ". $d0  ;
		$nameResult = execsql($productNameQuery);
		
		$d5 = mysql_result($nameResult, 0, "productName");
		$d1 = mysql_result($displayQueryResult, $i_d, "quantity");
		$d7 = mysql_result($displayQueryResult, $i_d, "saleId");
		$d8 = mysql_result($displayQueryResult, $i_d, "price");
		$d9 = mysql_result($displayQueryResult, $i_d, "batchCodeOne");
	    $d10 = mysql_result($displayQueryResult, $i_d, "batchCodeTwo");
		
		$d14 = mysql_result($displayQueryResult, $i_d, "returnNo");
		$d15="";
		//if ($d14>0) {
		    //$d14a = "<a href='customerDetails.php?custNo= ".$d14." ' ". $d14." </a> " ;
		   // $d15 =   $d15.$d14a ; }
		//echo $d14a;
		//echo "<br>return note:".$d15;
		$d15 = $d15." ".$d14;
		
		if ($d15 > 0)  { $d16 = "There are returns on this delivery."; } else {$d16=""; }
	?>
    <tr class="">
      <td>
        <?php if ($d8>0) { echo "<font color=black>"; } else { echo "<font color=red>"; }  
	    echo $d1."</font>"?>
      </td>
      <td>
        <?php echo $d5?>
      </td>
      <td><?php echo $d9;
	            if ($d10!="") {echo " / " . $d10;} ?></td>
      <td><div align="right">
        <?php if ($d8>0) { 
		        echo number_format($d8, 2, '.', ',') ;
			  }
			  else {
			    echo "n/c";
			  }
				?>
      </div></td>
      <td><div align="right">
        <?php $d11=$d1*$d8; echo number_format($d11, 2, '.', ',')."</font>"; $d12=$d12+$d11; ?>
      </div></td>
    </tr>
    <?php 
	$i_d++;
	}
	}
	?>
    
    <tr class="">
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2">Sub Total:</td>
      <td><div align="right">
        <div align="right"><?php echo number_format($d12, 2, '.', ','); ?></div>
      </div></td>
      
    </tr>
    <tr class="">
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2">VAT @12% </td>
      <td><div align="right"><?php echo number_format($d12*0.12, 2, '.', ','); ?></div></td>
      
    </tr>
    <tr class="">
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2">Total</td>
      <td><div align="right"><?php echo number_format(($d12+($d12*0.12)), 2, '.', ','); ?></div></td>
      
    </tr>
  </tbody>
</table>
<br />
<font color="#FF0000" ><?php echo $d16 ?></font> <br />
<p><br />
    <?php
		include("../footer.php");

}

?>
</p>
<br /><br /><br />
<br />
 
  
   

<p>
  </td>
</p>
