<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Orders-order cancel";
include ("../navigation/access.php");

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

require_once ('../include/tc_calendar.php');
	

$order_reference = $_GET['order_reference'];


	
$table_name2 = $_SESSION['db_prefix']."_orders";
$order_query = "SELECT * FROM $table_name2 WHERE order_reference ='".$order_reference."' ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);
$order_no  = mysql_result($order_result, 0, "order_no");
$cust_id  = mysql_result($order_result, 0, "cust_id");
$order_date  = mysql_result($order_result, 0, "order_date");
$delivery_date  = mysql_result($order_result, 0, "delivery_date");
$delivery_contact  = mysql_result($order_result, 0, "delivery_contact");
$delivery_phone  = mysql_result($order_result, 0, "delivery_phone");
$project_no  = mysql_result($order_result, 0, "project_no");
$project_place  = mysql_result($order_result, 0, "project_place");
$pallets  = mysql_result($order_result, 0, "pallets");
$del_col  = mysql_result($order_result, 0, "del_col");
$additional_info  = mysql_result($order_result, 0, "additional_info");
$ordered  = mysql_result($order_result, 0, "ordered");
$del_pallets  = mysql_result($order_result, 0, "del_pallets");
$delivered  = mysql_result($order_result, 0, "delivered");


$require_date = strtotime($delivery_date);
$d = date("d", $require_date );
$m = date("m", $require_date );
$y = date("Y", $require_date );


$table_name3 = $_SESSION['db_prefix']."_customer";
$account_query = "SELECT cust_id, comp_name, bag_box, box_no, postal_place, phone, contact_1, email_1, cell_1 FROM $table_name3 WHERE cust_id = '".$cust_id."' ";
$account_result = mySQL_query($account_query);
$c0 = mysql_result($account_result, 0, "cust_id");
$c1 = mysql_result($account_result, 0, "comp_name");  
$c2 = mysql_result($account_result, 0, "bag_box");
$c3 = mysql_result($account_result, 0, "box_no");
$c4 = mysql_result($account_result, 0, "postal_place");
$c5 = mysql_result($account_result, 0, "phone");
$c6 = mysql_result($account_result, 0, "contact_1");
$c7 = mysql_result($account_result, 0, "email_1");
//$c8 = mysql_result($account_result, 0, "status");
$c9 = mysql_result($account_result, 0, "cell_1");

$accountTT = "<label class=tip_text_label>".$c1."<br>".$c2."<br>".$c4."<br>".$c5."<br>".$c6."<br><label class=tip_click_label>Click for details</label>";



$table_name = $_SESSION['db_prefix']."_permissions";
$permission_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'Orders-order cancel' ";
$permission_result = mySQL_query($permission_query);
$permission_num = mysql_num_rows($permission_result);
if ($permission_num>0) { 
		$cancel = 'yes'; 
}
else {
	$cancel = 'no'; 
}

$message_text='';
if ($ordered=='no') { $message_text = 'This order is cancelled.'; }
if (($ordered=="part") AND ($delivered=="part") ) { $message_text = 'This order is cancelled.'; }
if (($ordered=="yes") AND ($delivered=="part") ) { $message_text = 'This order is partly delivered. Canceling the order, will cancel the remainder outstanding.'; }

?>

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

<!--jscript-->
<script language="javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 

</head>

<body onload="<?php if ($message_text!='') {?>alertMessage(1, '', '<?php echo $message_text; ?>')<?php } ?>; ">
<div class="main_frame" style="height:auto; min-height:555px;">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="493"><label class="label_page_head">
              Cancel order</label>
              </td>
              <td width="197"><label style="font-size:18px; "><?php echo $order_no ?></label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />
<form action="edit_order_save.php" method="get" name="form1" id="form1">
      <div class="page_middle_frame">
       <?php if ($message_text!='') { echo '<img src=../images/exclamation_mark_red_small.png width=10 height=16 /><font color=#FF0000>&nbsp;&nbsp;'.$message_text.'</font>'; } ?>
       <div class="page_inside_frame"> Order for:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($order_date)) ?>  
              <?php 
		include ('../include/customer_block.php');
		echo' <br>';
		?>
         
          <table width="642" id="table_display" >
            <tr>
              <td width="128" valign="top"><?php echo $del_col ?>
              </td>
              <td colspan="3" valign="top"><?php

		echo $delivery_date; ?></td>
            </tr>
            
            <tr>
              <td><?php if ($del_col=='deliver') {echo 'Delivery address:'; } ?></td>
              <td colspan="3"><?php echo $project_no ?>
              <?php echo $project_place; ?>
             </td>
            </tr>
            <tr>
              <td>Contact:</td>
              <td width="176">
              <?php echo $delivery_contact ?></td>
              <td width="86">Cell/phone:</td>
              <td width="232" align="left" valign="top">
              <?php echo $delivery_phone ?></td>
            </tr>
            <tr>
              <td>Notes:</td>
              <td colspan="3"><?php echo $additional_info ?></td>
            </tr>
          </table>
          <br />
          Cancel order:<br />
            
            <?php

$table_name = $_SESSION['db_prefix']."_order_lines";
$line_query = "SELECT *  FROM $table_name WHERE  order_no =  '".$order_no."'";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

				  ?>
            
            <input name="order_no" type="hidden" value="<?php echo $order_no ?>" />   
          </p>
          <table width="642" id="table_display" >
            <tr>
                  <td width="266" height="26" align="left" valign="top">Item</td>
                  <td width="170" align="left" valign="top">Group</td>
                  <td width="84" align="center" valign="top">Ordered</td>
                  <td width="102" align="center" valign="top">Delivered</td>
                </tr>
                <?php
				$i=0;
				while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "delivered");
					 
					 
								 
				 ?>
                <tr>
                  <td colspan="2" valign="middle">
              
                    <?php echo $a1a ?>
                    <input name="store_item_id<?php echo $i ?>" id="store_item_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>" />
                  
                    </td>
                  <td align="right" valign="middle"><?php echo number_format($a2, 0, '.', '') ?>
                  </td>
                  <td align="right" valign="middle">
                  <?php echo $a3; ?></td>
                </tr>
                <?php 
			   
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="2"> Pallets</td>
                  <td align="right"><?php echo $pallets ?></td>
                  <td align="right"><?php echo $del_pallets; ?></td>
                </tr>
              </table>
              </div>
              <br />
              <div class="page_inside_frame">
      <table width="600" border="0">
    <tr>
      <td width="189">
      
	 
       <!--<a href="uncancel_order_save.php?order_reference=<?php echo $order_reference ?>"><input type="button" name="cancel_button" id="cancel_button" value="Undo cancelation" class="imagebutton" /></a>-->
</td>
      <td width="401" align="right"><input type="hidden" name="order_reference" id="order_reference" value="<?php echo $order_reference ?>" />
       <a href="../store/store_main.php?date="><input name="button2" type="button" class="imagebutton" id="button2" value="Close"/></a>
        
        
        <?php if ($ordered=='yes') { ?>
        <a href="cancel_order_save.php?order_reference=<?php echo $order_reference ?>&amp;delivered=<?php echo $delivered ?>">
        <input type="button" name="cancel_button2" id="cancel_button2" value="Cancel order" class="imagebutton" />
        </a>
        <?php ;} 
		else { ?>
        <input type="button" name="cancel_button3" id="cancel_button3" value="Cancel order" class="dis_imagebutton" />
        <?php } ?>     
        
        </td>
    </tr>
  </table>
</div>
  
 <br />
  </div>
  </form>
  <!--end of tableMain--> 
  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "store/store_main.php?date=";	
include ("../navigation/store_sidebar.php");?>
<body onload="accessdenied(); return false">
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php }
?>
</html>