<!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('../include/session.php');

?>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  

<style>
input.imagebutton{
	background-color:#E1E1E1;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:1px;
	border-color:#39A751;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:0px 0px 0px #CCC;
	-webkit-box-shadow:0px 0px 0px #CCC;
	box-shadow:0px 0px 0px #CCC;
}

input.imagebutton:hover{
	background-color:#E4E4E4;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:2px;
	border-color:#39A751;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:5px 5px 5px #666;
	-webkit-box-shadow:5px 5px 5px #666;
	box-shadow:5px 5px 5px #666;
}

label.label_std{
	margin-left:5px;
    line-height:20px;
	padding-top:6px;
    color:#000;
    text-shadow:1px 1px 1px #fff;
    font:bold 12px Arial;
}

#table_display {
	font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
	color:#000;
	font-size:12px;
	font-weight:normal;
	
}

</style>

<?php

//include('../include/db.php');

$product_item_id = $_GET['product_item_id'];
$cash_sale_no = $_GET['cash_sale_no'];
$line = $_GET['line'];

$table_name = $_SESSION['db_prefix']."_product_store";
$name_query = "SELECT item_name, item_type, price FROM $table_name WHERE product_item_id = '".$product_item_id."'  ";
$name_result = $con->query($name_query);
$row = mysqli_fetch_assoc($name_result);
$item_name = $row['item_name'];
$item_type = $row['item_type'];
$product_price = $row['price'];


$table_name = $_SESSION['db_prefix']."_product_store_lines";
$stock_query = "SELECT product_store_line_id, batch_code, (quantity_in-quantity_out) AS balance  FROM $table_name WHERE product_item_id = '".$product_item_id."' AND (quantity_in-quantity_out) > 0 ";
$stock_result = $con->query($stock_query);
$stock_num = mysqli_num_rows($stock_result);

?>

<script>
function qty_check(i) {
	
	var balance = parseInt(document.getElementById('balance_text'+i).value);
	var del_qty = parseInt(document.getElementById('del_qty_text'+i).value);
		
	if (del_qty > balance) {
		    document.getElementById('del_qty_text'+i).value='';
			alert('The quantity of '+del_qty+' is more than available.\n Available quantity is '+balance+'\n\n Please select a lower quantity.');
	}
}
</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]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>
<body onload="document.getElementById('password_text').value='';">

<label class="label_std">Select quantity to deliver <?php echo $item_name ?><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<?php echo $item_type ?>)<br /></label>
<br />
<form action='../edit_windows/cash_deliver_products_save.php' method="GET" name="form2" target="_top" id="form2">
  <table id="table_display">
    <tr>
      <td width="153" align="center">Batch code</td>
      <td width="75" align="center">Stock qty</td>
      <td width="62" align="center">Deliver</td>
    </tr>
    <?php
	$k=0;
	while($row = $stock_result->fetch_assoc()) {
			$product_store_line_id = $row["product_store_line_id"];
			$batch_code = $row["batch_code"];
		    $balance = $row["balance"];
	?>
    <tr>
       <script>recycle_id=[];</script>
      <td align="center"><?php echo $batch_code ?><input name="batch_code_text<?php echo $k ?>" type="hidden" value="<?php echo $batch_code ?>" />
      </td>
      <td align="center"><?php echo $balance ?></td><input name="balance_text<?php echo $k ?>" id="balance_text<?php echo $k ?>" type="hidden" value="<?php echo $balance ?>" />
      <td align="center"><input type="text" name="del_qty_text<?php echo $k ?>" id="del_qty_text<?php echo $k ?>" onkeypress="return numbersonly(this, event)" onfocus = "this.select();" style="width:50px;" onkeyup="qty_check(<?php echo $k ?>); tot_check(<?php echo $k ?>);"/><input name="product_store_line_id_text<?php echo $k ?>" type="hidden" value="<?php echo $product_store_line_id ?>" /></td>
    </tr>
    <?php
	$k++;
	}
	?>
    <tr>
      <td height="45" align="center">
        <input name="show" type="hidden" value="1" />
        <input name="line_num" type="hidden" value="<?php echo $stock_num ?>" />
        <input name="product_item_id_text" type="hidden" value="<?php echo $product_item_id ?>" />
        <input name="item_type_text" type="hidden" value="<?php echo $item_type ?>" />
        <input name="product_price" type="hidden" value="<?php echo $product_price ?>" />
        <input name="cash_sale_no_text" type="hidden" value="<?php echo $cash_sale_no ?>" />
        <input name="line" type="hidden" value="<?php echo $line ?>" />
      <input name="input" type="submit" value="Add selected" class="imagebutton"  /></td>
      <td colspan="2" align="center"><div style="float:left;"><img src="../images/exclamation_mark_red_small.png" width="20" height="32" /></div><div ><label style="color:#F00; font-weight:bold">Earlier entered quantities will be overridden.</label></div></td>
    </tr>
  </table>
</form>

</body>
</html>