<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);

$table_name = $_SESSION['db_prefix']."_presets";
$exchange_query = "SELECT  preset_value FROM $table_name WHERE preset_name='Exchange rate' ";
$exchange_result = mySQL_query($exchange_query);
$exchange_num = mysql_num_rows($exchange_result);
$exchange = mysql_result($exchange_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="receivingWiz6.php" >
  <table width=695 border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" ><table width="670" id="table_resume_wizard" >
          <tr>
            <td width="99" align="left" valign="top">Received from:</td>
            <td width="258" align="left" valign="top"><?php echo $_SESSION['sup_name'] ?></td>
            <td width="80" align="left" valign="top">Date:</td>
            <td width="213" align="left" valign="top"><?php echo $_SESSION['receive_date'] ?></td>
          </tr>
          <tr>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">Delivery note:</td>
            <td align="left" valign="top"><?php echo $_SESSION['del_note'] ?></td>
          </tr>
          <tr>
            <td colspan="4" align="left" valign="top"><?php if ($_SESSION['currency']=='BWP') {echo 'BWP';} else {echo 'SAR Exchange rate:'.$exchange;} ?></td>
          </tr>
        </table>
        <table width="670" id="table_resume_wizard" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="70" align="left" valign="top">quantity</td>
            <td width="77" align="left" valign="top">price <?php if ($_SESSION['currency']=='BWP') {echo 'BWP';} else {echo 'SAR';} ?> </td>
            <td width="96" align="left" valign="top">total <?php if ($_SESSION['currency']=='BWP') {echo 'BWP';} else {echo 'SAR';} ?></td>
            <td width="126" 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, 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 colspan="2" 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"><?php if ($_SESSION['currency']=='BWP') {echo number_format($a5, 2, '.', ',');} else {echo number_format($a5/$exchange, 2, '.', ',');} ?>&nbsp;</td>
          </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
          <tr>
            <td colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">Total:</td>
            <td align="right" valign="top"><?php echo number_format($_SESSION['total'], 2, '.', ',') ?>&nbsp;</td>
            <td align="right" valign="top"><?php if ($_SESSION['currency']=='BWP') {echo number_format($_SESSION['total'], 2, '.', ',');} else {echo number_format(($_SESSION['total']/$exchange), 2, '.', ',');} ?></td>
          </tr>
          </table><br>

          <table width="670" id="table_resume_wizard">
          <tr>
            <td align="left" valign="top">Total value of receival:</td>
            <td width="191" align="right" valign="top"><?php echo number_format($_SESSION['value'], 2, '.', ',') ?></td>
            <td width="127" align="right" valign="top"><?php if ($_SESSION['currency']=='BWP') {$_SESSION['value_tot']=$_SESSION['value'];} else {$_SESSION['value_tot']=$_SESSION['value']/$exchange;} echo number_format($_SESSION['value_tot'], 2, '.', ',') ?></td>
          </tr>
          <tr>
            <td align="left" valign="top">Transport costs:</td>
            <td align="right" valign="top"><?php if ($_SESSION['transport']!='') { echo number_format($_SESSION['transport'], 2, '.', ',');}?></td>
            <td align="right" valign="top"><?php if ($_SESSION['transport']!='') { if ($_SESSION['currency']=='BWP') {$_SESSION['transport_tot']=$_SESSION['transport'];} else {$_SESSION['transport_tot']=$_SESSION['transport']/$exchange;} echo number_format($_SESSION['transport_tot'], 2, '.', ',');} ?></td>
          </tr>
        </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','receivingWizbase.php?s=2&p=2');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:cancel_confirmation(1, '../store/store_main.php'); needToConfirm = false;" 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>