<head>
<?php
$table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$line_query = "SELECT $table_name.store_item_id, $table_name2.store_item_id, $table_name.receive_line_id, $table_name.quantity, $table_name.price, $table_name2.unit FROM $table_name, $table_name2 WHERE  user =  '".$_SESSION['username']."' AND ($table_name.store_item_id = $table_name2.store_item_id) ORDER BY item_name "; 
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$table_name = $_SESSION['db_prefix']."_presets";
$rate_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Exchange rate'  ";
$rate_result = mySQL_query($rate_query);
$rate = mysql_result($rate_result, 0, "preset_value");
?>
</head>
<?php include('../include/wait.php') ?>
<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="page_middle_frame">
<form id="feedbackform" method="get" action="receivingPlatesWiz7.php" >
  <table width=595 border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" ><table width="595" id="table_resume_wizard" >
        <tr>
          <td width="111" align="left" valign="top">Received from:</td>
          <td colspan="3" align="left" valign="top"><?php echo $_SESSION['sup_name'] ?></td>
        </tr>
        <tr>
          <td align="left" valign="top">Date:</td>
          <td width="71" align="left" valign="top"><?php echo date("d-m-Y", strtotime($_SESSION['receive_date'] )) ?></td>
          <td colspan="2" align="left" valign="top">Delivery note:&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['del_note'] ?></td>
        </tr>
        <tr>
          <td colspan="2" align="left" valign="top">Total value of this delivery </td>
          <td width="176" align="left" valign="top">(SAR):&nbsp;<?php echo number_format($_SESSION['value'], 2, '.', ','); $_SESSION['value_tot']	= $_SESSION['value']/$rate; ?></td>
          <td width="217" align="left" valign="top">&nbsp;&nbsp;(BWP)<?php echo number_format($_SESSION['value_tot'], 2, '.', ',');?></td>
        </tr>
        <tr>
          <td colspan="2" align="left" valign="top">Total transport costs</td>
          <td align="left" valign="top">(SAR):&nbsp;<?php echo number_format($_SESSION['transport'], 2, '.', ','); $_SESSION['transport_tot']	= $_SESSION['transport']/$rate; ?></td>
          <td align="left" valign="top">&nbsp;&nbsp;(BWP)<?php echo number_format($_SESSION['transport_tot'], 2, '.', ',');?></td>
        </tr>
      </table>
        <br>
        <table width="592" id="table_resume_wizard" >
          <tr>
            <td height="26" align="left" valign="top">Item</td>
            <td width="86" align="left" valign="top">Quantity</td>
            <td width="131" align="left" valign="top">Unit Price (BWP)</td>
            <td width="114" align="left" valign="top">Total (BWP)</td>
          </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 FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					 $a7 = mysql_result($line_result, $i, "unit");
					$a5=$a2*$a3;
					$a6_total=$a6_total+$a5;
					 
				 ?>
          <tr>
            <td valign="top"><?php echo $a1a ?></td>
            <td valign="top"><?php echo $a2 ?>&nbsp;&nbsp;(<?php echo $a7 ?>)</td>
            <td align="right" valign="top"><?php echo number_format($a3, 4, '.', ',') ?></td>
            <td align="right" valign="top"><?php echo number_format($a5, 4, '.', ',')?></td>
          </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
        <tfoot>
        <tr>
        <td colspan="4" align="right" valign="top"><?php echo number_format($a6_total, 4, '.', ',')?></td>
        </tr>
        </tfoot>
        </table>
        <br />
        <div class="wizard_frame">
          <input name="s" type="hidden" id="s" value="4" />
          <input name="p" type="hidden" id="p" value="4" />
          <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
            Click 'New' to make a new entry or to finish the wizard click 'Finish'.</label>
        </div></td>
    
      </tr>
    
    <tr>
      <td><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','receivingPlatesWizbase.php?s=&p=3');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../store/store_main.php');;" value="Cancel" /></td>
            <td width="125"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
            <td width="110"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
          </tr>
        </table></td>
    </tr>
  </table>
  </table>
</form>
</div>
