<?php 

$page = 'quote';

$table_name = $_SESSION['db_prefix']."_product_store";
$stock_item_query = "SELECT product_item_id, item_name, quantity FROM $table_name  WHERE subCategory = 'Sales product'  ORDER BY item_name ASC";
$stock_item_result = $con->query($stock_item_query);
$stock_item_num = mysqli_num_rows($stock_item_result);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while($row = $stock_item_result->fetch_assoc()) {
		$product_item_id = $row['product_item_id'];
		$item_name = $row['item_name'];
		$quantity = $row['quantity'];
					
		
		$arrId4[$w] = $product_item_id;
		$arrName4[$w] = str_pad($item_name, 40, ' ', STR_PAD_RIGHT).'&nbsp;&nbsp;&nbsp;&nbsp;available stock: '.$quantity;
		$w++;
	}
	

?>


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

<script>
function select_productA() {
	var e = document.getElementById('product_selectA');
	var product_item_id = e.options[e.selectedIndex].value; 
	var cash_sale_no = <?php echo $_SESSION['cash_sale_no'] ?>;
		
	window.dhtmlmodal.open('editBox', 'iframe', '../edit_windows/cash_deliver_products.php?product_item_id='+product_item_id+'&cash_sale_no='+cash_sale_no+'&line=A', 'Available products for cash sale', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	needToConfirm = false;
	editwindow.onclose=function(){return window}; 
	return false;	
}
</script> 

<script>
function select_productB() {
	var e = document.getElementById('product_selectB');
	var product_item_id = e.options[e.selectedIndex].value; 
	var cash_sale_no = <?php echo $_SESSION['cash_sale_no'] ?>;
		
	window.dhtmlmodal.open('editBox', 'iframe', '../edit_windows/cash_deliver_products.php?product_item_id='+product_item_id+'&cash_sale_no='+cash_sale_no+'&line=B', 'Available products for cash sale', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	needToConfirm = false;
	editwindow.onclose=function(){return window}; 
	return false;	
}
</script> 

<script>
function select_productC() {
	var e = document.getElementById('product_selectC');
	var product_item_id = e.options[e.selectedIndex].value; 
	var cash_sale_no = <?php echo $_SESSION['cash_sale_no'] ?>;
		
	window.dhtmlmodal.open('editBox', 'iframe', '../edit_windows/cash_deliver_products.php?product_item_id='+product_item_id+'&cash_sale_no='+cash_sale_no+'&line=C', 'Available products for cash sale', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	needToConfirm = false;
	editwindow.onclose=function(){return window}; 
	return false;	
}
</script> 

<script>
function select_productD() {
	var e = document.getElementById('product_selectD');
	var product_item_id = e.options[e.selectedIndex].value; 
	var cash_sale_no = <?php echo $_SESSION['cash_sale_no'] ?>;
		
	window.dhtmlmodal.open('editBox', 'iframe', '../edit_windows/cash_deliver_products.php?product_item_id='+product_item_id+'&cash_sale_no='+cash_sale_no+'&line=D', 'Available products for cash sale', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	needToConfirm = false;
	editwindow.onclose=function(){return window}; 
	return false;	
}
</script> 

<script>
function select_productE() {
	var e = document.getElementById('product_selectE');
	var product_item_id = e.options[e.selectedIndex].value; 
	var cash_sale_no = <?php echo $_SESSION['cash_sale_no'] ?>;
		
	window.dhtmlmodal.open('editBox', 'iframe', '../edit_windows/cash_deliver_products.php?product_item_id='+product_item_id+'&cash_sale_no='+cash_sale_no+'&line=E', 'Available products for cash sale', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	needToConfirm = false;
	editwindow.onclose=function(){return window}; 
	return false;	
}
</script> 

</head>

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide'); initCS(); " onFocus="MM_showHideLayers('wait','','hide');" >
<form id="form1" name="form1" method="GET" action="">
<div class="wizard_page_middle_frame">

<div class="wizard_frame">
<table width="670" border="1" cellpadding="2" style="border-collapse:collapse;">
  <tr>
    <td width="277">Product</td>
    <td width="353">Deliver qty&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Batch_code</td>
    </tr>
    <?php
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
	$quantity_query = "SELECT product_item_id, quantity, batch_code, product_store_line_id  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND product_item_id = '".$_SESSION['list_product_item_id_A']."' AND user_name = '".$_SESSION['username']."'"; 
	$quantity_result = $con->query($quantity_query);
	$quantity_num = mysqli_num_rows($quantity_result);
	
	if ($quantity_num>0) {
	$table_name = $_SESSION['db_prefix']."_product_store";
	$item_name_query = "SELECT  item_name FROM $table_name WHERE product_item_id = '".$_SESSION['list_product_item_id_A']."' ";
	$item_name_result = $con->query($item_name_query);
	$row = mysqli_fetch_assoc($item_name_result);
	$item_name = $row['item_name'];
	}
	else {
	$item_name = '';
	}

	?>
  <tr>
    <td><select name="product_selectA" autofocus class="selectbox300" id="product_selectA" onChange="select_productA();">
      <option value="<?php echo $item_name ?>" selected="selected" ><?php echo $item_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select></td>
    <td>
                
<?php 
$i=0;
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
$a10 = $row['product_store_line_id'];
?>							
<input name="quantity_textA<?php echo $i ?>" type="text" class="text60" id="quantity_textA<?php echo $i ?>"  value="<?php echo $a8 ?>" style="width:75px; font-weight:bold; border:hidden;" readonly  >&nbsp;&nbsp;&nbsp;<input name="batch_code_textA<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_textA<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" > 					
<br>			
<?php
$i++;
 } 
?>     
</td>
</tr>
  
    <?php
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
	$quantity_query = "SELECT product_item_id, quantity, batch_code  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND product_item_id = '".$_SESSION['list_product_item_id_B']."' AND user_name = '".$_SESSION['username']."'"; 
	$quantity_result = $con->query($quantity_query);
	$quantity_num = mysqli_num_rows($quantity_result);
	
	if ($quantity_num>0) {
	$table_name = $_SESSION['db_prefix']."_product_store";
	$item_name_query = "SELECT  item_name FROM $table_name WHERE product_item_id = '".$_SESSION['list_product_item_id_B']."' ";
	$item_name_result = $con->query($item_name_query);
	$row = mysqli_fetch_assoc($item_name_result);
	$item_name = $row['item_name'];
	}
	else {
	$item_name = '';
	}
	?>
  <tr>
    <td><select name="product_selectB" autofocus class="selectbox300" id="product_selectB" onChange="select_productB();">
      <option value="<?php echo $item_name ?>" selected="selected" ><?php echo $item_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select></td>
    <td>
    
<?php 
$i=0;
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
?>							
<input name="quantity_textB<?php echo $i ?>" type="text" class="text60" id="quantity_textB<?php echo $i ?>"  value="<?php echo $a8 ?>" style="width:75px; font-weight:bold; border:hidden;" readonly  >&nbsp;&nbsp;&nbsp;<input name="batch_code_textB<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_textB<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" >							
<br>			
<?php
$i++;
 } 
?>     
</td>
</tr>

<?php
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
	$quantity_query = "SELECT product_item_id, quantity, batch_code  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND product_item_id = '".$_SESSION['list_product_item_id_C']."' AND user_name = '".$_SESSION['username']."'"; 
	$quantity_result = $con->query($quantity_query);
	$quantity_num = mysqli_num_rows($quantity_result);
	
	if ($quantity_num>0) {
	$table_name = $_SESSION['db_prefix']."_product_store";
	$item_name_query = "SELECT  item_name FROM $table_name WHERE product_item_id = '".$_SESSION['list_product_item_id_C']."' ";
	$item_name_result = $con->query($item_name_query);
	$row = mysqli_fetch_assoc($item_name_result);
	$item_name = $row['item_name'];
	}
	else {
	$item_name = '';
	}
	?>
  <tr>
    <td><select name="product_selectC" autofocus class="selectbox300" id="product_selectC" onChange="select_productC();">
      <option value="<?php echo $item_name ?>" selected="selected" ><?php echo $item_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select></td>
    <td>
    
<?php 
$i=0;
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
?>							
<input name="quantity_textC<?php echo $i ?>" type="text" class="text60" id="quantity_textC<?php echo $i ?>"  value="<?php echo $a8 ?>" style="width:75px; font-weight:bold; border:hidden;" readonly  >&nbsp;&nbsp;&nbsp;<input name="batch_code_textC<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_textC<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" >							
<br>			
<?php
$i++;
 } 
?>     
</td>
</tr>

<?php
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
	$quantity_query = "SELECT product_item_id, quantity, batch_code  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND product_item_id = '".$_SESSION['list_product_item_id_D']."' AND user_name = '".$_SESSION['username']."'"; 
	$quantity_result = $con->query($quantity_query);
	$quantity_num = mysqli_num_rows($quantity_result);
	
	if ($quantity_num>0) {
	$table_name = $_SESSION['db_prefix']."_product_store";
	$item_name_query = "SELECT  item_name FROM $table_name WHERE product_item_id = '".$_SESSION['list_product_item_id_D']."' ";
	$item_name_result = $con->query($item_name_query);
	$row = mysqli_fetch_assoc($item_name_result);
	$item_name = $row['item_name'];
	}
	else {
	$item_name = '';
	}
	?>
  <tr>
    <td><select name="product_selectD" autofocus class="selectbox300" id="product_selectD" onChange="select_productD();">
      <option value="<?php echo $item_name ?>" selected="selected" ><?php echo $item_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select></td>
    <td>
    
<?php 
$i=0;
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
?>							
<input name="quantity_textD<?php echo $i ?>" type="text" class="text60" id="quantity_textD<?php echo $i ?>"  value="<?php echo $a8 ?>" style="width:75px; font-weight:bold; border:hidden;" readonly  >&nbsp;&nbsp;&nbsp;<input name="batch_code_textD<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_textD<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" >							
<br>			
<?php
$i++;
 } 
?>     
</td>
</tr>

<?php
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
	$quantity_query = "SELECT product_item_id, quantity, batch_code  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND product_item_id = '".$_SESSION['list_product_item_id_E']."' AND user_name = '".$_SESSION['username']."'"; 
	$quantity_result = $con->query($quantity_query);
	$quantity_num = mysqli_num_rows($quantity_result);
	
	if ($quantity_num>0) {
	$table_name = $_SESSION['db_prefix']."_product_store";
	$item_name_query = "SELECT  item_name FROM $table_name WHERE product_item_id = '".$_SESSION['list_product_item_id_E']."' ";
	$item_name_result = $con->query($item_name_query);
	$row = mysqli_fetch_assoc($item_name_result);
	$item_name = $row['item_name'];
	}
	else {
	$item_name = '';
	}
	?>
  <tr>
    <td><select name="product_selectE" autofocus class="selectbox300" id="product_selectE" onChange="select_productE();">
      <option value="<?php echo $item_name ?>" selected="selected" ><?php echo $item_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select></td>
    <td>
    
<?php 
$i=0;
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
?>							
<input name="quantity_textE<?php echo $i ?>" type="text" class="text60" id="quantity_textE<?php echo $i ?>"  value="<?php echo $a8 ?>" style="width:75px; font-weight:bold; border:hidden;" readonly  >&nbsp;&nbsp;&nbsp;<input name="batch_code_textE<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_textE<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" >							
<br>			
<?php
$i++;
 } 
?>     
</td>
</tr>
</table>
<div style="float:right;"><input name="clear_button" type="button" class="imagebutton" value="Clear list" onClick="needToConfirm = false; MM_goToURL('parent','newCashWizbase.php?s=3&p=3'); return document.MM_returnValue; ;return document.MM_returnValue"></div>
<br>
Pallets delivered: 
    <input name="pallets_text" type="text" class="text40" autocomplete="off" onKeyPress="return numbersonly(this, event)" style="text-align:right" onfocus = "this.select();"  value="<?php echo $_SESSION['pallets'] ?>">
</div>


 
<div class="wizard_frame">
  <table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','newCashWizbase.php?s=&amp;p=2&amp;e=0'); return document.MM_returnValue; ;return document.MM_returnValue"/></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="error" type="hidden" id="error" value="0" />
              <input name="p" type="hidden" id="p" value="3" />
              <input name="s" type="hidden" id="s" value="" />
            </span></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false;  cancel_confirmation(1, '../store/store_main.php?date=');" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
          </tr>
      </table>
    </div>
  </div>
</form>
</div>

<!--form validation-->


<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 50; i++) {
	frmvalidator.addValidation("product_item_id"+i,"req","- store item on store line "+(i+1)+".");
	frmvalidator.addValidation("quantity_text"+i,"req","- quantity  on store line "+(i+1)+".");
  }
  </script>

</body>

