<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include ("../navigation/header.php");

$page_name = "Stores-main";
include ("../navigation/access.php");

require_once ('../include/tc_calendar.php');
$return_date = strtotime($today);
$d = date("d", $return_date );
$m = date("m", $return_date );
$y = date("Y", $return_date );

if ($permission_num==1) {

$show = $_GET['show'];


if ($show==0) {
$table_name = $_SESSION['db_prefix']."_customer";
$custQuery = "SELECT  cust_id, comp_name FROM $table_name ORDER BY comp_name ASC";
$custResult = execsql($custQuery);
$custNum = mysql_num_rows($custResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $custNum) {
		$arrId4[$w] = mysql_result($custResult, $w, 'cust_id');
		$arrName4[$w] = mysql_result($custResult, $w, 'comp_name');
		$w++;
	}
}


if ($show==1) {	
$cust_id = $_GET['cust_id'];

$table_name = $_SESSION['db_prefix']."_customer";
$comp_query = "SELECT comp_name, postal_place  FROM $table_name WHERE cust_id = '".$cust_id."' ";
$comp_result = mySQL_query($comp_query);
$comp_name = mysql_result($comp_result, 0, "comp_name");
$postal_place = mysql_result($comp_result, 0, "postal_place");

$table_name = $_SESSION['db_prefix']."_pallets_balance";
$outstanding_query = "SELECT SUM(del_qty) AS summed_del_qty, SUM(ret_qty) AS summed_ret_qty FROM $table_name WHERE cust_id = '".$cust_id."' GROUP BY cust_id ";
$outstanding_result = execsql($outstanding_query);
$outstanding_num = mysql_num_rows($outstanding_result);
if ($outstanding_num > 0) {
$outstanding = mysql_result($outstanding_result, 0, "summed_del_qty") - mysql_result($outstanding_result, 0, "summed_ret_qty");
}
else {
$outstanding = 0;
}

if ($outstanding<=0) {
$outstanding = 0;
}

}

include ("../navigation/store_sidebar.php");


?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  
       
</head>

<body>

<div class="main_frame">
<div class="page_head_frame">
    <label class="label_page_head">Pallets return</label>
</div>


<div class="page_middle_frame">


<div class="page_inside_frame">

<?php 
if ($show==0) { 
?>
<div style="float:left;">
<form name="form1" id="form1" action="" method="get">
Select  customer:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="customer_select" autofocus class="selectbox300" id="customer_select" onchange="window.location.href= this.form.customer_select.options[this.form.customer_select.selectedIndex].value">
  <option value="" selected="selected" ></option>
  <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
 ?>			
  <option value="return_pallets.php?cust_id=<?php echo $arrId4[$j] ?>&show=1"><?php echo $arrName4[$j] ?></option>	
 <?php }
     ?>
</select>
</form>
</div>
<?php } ?>

<?php 
if ($show==1) { 
?>
<div style="float:left;">
<form name="form2" id="form2" action="return_pallets_save" method="get">
<table width="600" id="table_display_wizard2">
  <tr>
    <td height="30">Returning pallets from:</td>
    <td><?php echo $comp_name.'&nbsp;&nbsp;--&nbsp;&nbsp;'.$postal_place ?><input name="cust_id_text" type="hidden" value="<?php echo $cust_id ?>"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="33">Return date:</td>
    <td><?php

		$myCalendar = new tc_calendar("return_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2015, 2090);
		//$myCalendar->dateAllow('2009-02-20', "", false);
		$myCalendar->writeScript();
?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="33">No of pallets returned:</td>
    <td><input type="text" name="return_qty_text" id="return_qty_text" class="text40" autocomplete="off" onkeypress="return numbersonly(this, event)" onfocus = "this.select();" style="text-align:right"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="38">Outstanding pallets:</td>
    <td><?php echo $outstanding ?></td>
    <td>&nbsp;</td>
  </tr>
</table>

<br>
<div style="float:left;">
<input type="button" name="select_button" id="select_button" value="Select other customer" class="imagebutton" onClick="window.location='return_pallets.php?show=0';">
</div>
<div style="float:right;">
<input type="submit" name="save_close_button" id="save_close_button" value="Save & Close" class="imagebutton">
</div>
<br>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form2");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("return_qty_text","req","- number of pallets to return.");
</script>
<br>
<br>
<br>
</div>
<?php } ?>
</div>
</div>
</div>




<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?branch=$date=";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

