<head>
<?php
$table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
$line_query = "SELECT *  FROM $table_name WHERE user =  '".$_SESSION['username']."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);
?>
<!--style sheets-->
<link href="../css/tooltip.css" rel="stylesheet" type="text/css">
<link href="../window/dhtmlwindow.css" rel="stylesheet" type="text/css">
<link href="../window/modal.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../window/dhtmlwindow.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../window/modal.js"  type="text/javascript"></script>  
</head>

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

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');" onBlur="<?php if ($_SESSION['s']=='10') { ?> needToConfirm = false; <?php } ?> ">

<div class="page_middle_frame">
<form id="form1" name="form1" method="get" action="receivingWizbase.php">
  <table width=595 border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" height="277" valign="top" ><div class="wizard_frame">
        <label class="label_std">Click <img src="../images/plus.png" alt="" width="16" height="16" /> to add line, <img src="../images/line_edit.png" alt="" width="16" height="16" /> to edit, <img src="../images/delete.png" alt="" width="16" height="16" /> to delete.</label>
        <br />
        <br />
        <table width="641" border="0">
          <tr>
            <th width="22">&nbsp;</th>
            <th width="34">Line</th>
            <th width="224" align="left">Item</th>
            <th width="77" align="left">Quantity</th>
            <th width="105" align="center">Unit price <?php if ($_SESSION['currency']=='BWP') {echo 'BWP';} else {echo 'SAR';} ?></th>
            <th width="130" align="center">Total</th>
            <th width="19" align="center">&nbsp;</th>
          </tr>
          <?php
				$i=0;
				$sub_tot=0;
				$a6_total=0;
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "receive_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit 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");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					$a5=$a2*$a3;
					$a6_total=$a6_total+$a5;
					 
				 ?>
          <tr>
            <td valign="top"><a href="" onMouseOver="ddrivetip('Click to edit this line', 110)"; onMouseOut="hideddrivetip()" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/receival_add_edit.php?receive_line_id=<?php echo $a0 ?>', 'Edit quantity / price.', 'width=500px,height=200px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><img src="../images/line_edit.png" alt="" width="16" height="16" /></a></td>
            <td valign="top"><?php echo $i+1 ?></td>
            <td valign="top"><?php echo $a1a ?></td>
            <td valign="top"><?php echo $a2 ?></td>
            <td align="right" valign="top"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
            <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',')?></td>
            <td align="right" valign="top"><a href="receivingWizbase.php?p=2&s=12&receive_line_id=<?php echo $a0?>" onMouseOver="ddrivetip('Click to delete this line', 110)"; onMouseOut="hideddrivetip()"><img src="../images/delete.png" alt="" width="16" height="16" onClick="needToConfirm = false;" /></a></td>
          </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
          <tr>
            <td height="34" valign="bottom"><a href="" onMouseOver="ddrivetip('Click to add a line', 100)"; onMouseOut="hideddrivetip()" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/receival_add.php?category=&sub_category=', 'Add received item', 'width=500px,height=250px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><img src="../images/plus.png" alt="" width="16" height="16" /></a></td>
            <td valign="bottom">&nbsp;</td>
            <td valign="bottom">&nbsp;</td>
            <td colspan="2" align="right" valign="bottom"><label class="label_std">Totals:</label></td>
            <td align="right" valign="bottom"><?php echo number_format($a6_total, 2, '.', ','); $_SESSION['total']=$a6_total;?></td>
            <td align="right" valign="bottom">&nbsp;</td>
          </tr>
        </table>
      </div></td>
    </tr>
    <tr>
      <td><table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="submit" name="prev_button" id="prev_button" class="imagebutton" value="Prev" onClick=" needToConfirm = false; MM_showHideLayers('wait','','show');" /></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="2" />
              <input name="s" type="hidden" id="s" value="2" />
            </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');;" 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></td>
    </tr>
  </table>
</form>
</div>
<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("store_item_select","req","Please select a product.");
  frmvalidator.addValidation("quantityText","req","Please enter the quantity.");
  frmvalidator.addValidation("priceText","req","Please enter the price.");
  </script>
</body>