
<?php 
$table_name = $_SESSION['db_prefix']."_employee";
$name_query = "SELECT emp_first_name, emp_last_name  FROM $table_name WHERE emp_id = '".$_SESSION['emp_id']."'  ";
$name_result = mySQL_query($name_query);
$name_num = mysql_num_rows($name_result);
$emp_first_name = mysql_result($name_result, 0, "emp_first_name");
$emp_last_name = mysql_result($name_result, 0, "emp_last_name");

$table_name = $_SESSION['db_prefix']."_pettycash_lines_temp WHERE pettycash_id = '".$_SESSION['pettycash_id']."' ";
$line_query = "SELECT * FROM $table_name ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$table_name = $_SESSION['db_prefix']."_pettycash_lines_temp ";
$total_query = "SELECT SUM(amount_debit) AS total_amount FROM $table_name WHERE pettycash_id = '".$_SESSION['pettycash_id']."' ";
$total_result = mySQL_query($total_query);
$total_amount = mysql_result($total_result, 0, "total_amount");

?>
<!--style sheets-->
<link href="../css/wait.css" rel="stylesheet" type="text/css">
</head>

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

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');">


<form id="feedbackform" method="get" action="pettycashReturnWiz6.php" >
<div class="wizard_page_middle_frame">
<div class="wizard_frame">
  <table width="640" align="center" id="table_resume_wizard" >
              <tr>
                <td align="left" valign="top">Petty cash amount:</td>
                <td colspan="2" align="left" valign="top"><?php echo number_format($_SESSION['amount'] , 2, '.', ',') ?></td>
                <td width="210" align="left" valign="top">&nbsp;</td>
              </tr>
              <tr>
                <td width="142" align="left" valign="top"><span class="wizard">Employee name:</span></td>
                <td colspan="2" align="left" valign="top"><strong><span class="wizard"><?php echo $emp_first_name." ".$emp_last_name ?></span></strong></td>
                <td align="left" valign="top">(<?php echo $_SESSION['emp_id'] ?>)</td>
              </tr>
              <tr>
                <td align="left" valign="top">Issued for:</td>
                <td width="168" align="left" valign="top"><?php echo $_SESSION['use'] ?></td>
                <td width="130" align="left" valign="top">&nbsp;</td>
                <td align="left" valign="top">&nbsp;</td>
              </tr>
              <tr>
                <td align="left" valign="top">Issue date:</td>
                <td align="left" valign="top"><?php echo date("d-m-Y", strtotime($_SESSION['issue_date'] )) ?></td>
                <td align="left" valign="top">Issued by:</td>
                <td align="left" valign="top"><?php echo $_SESSION['issued_by'] ?>&nbsp;</td>
              </tr>
              <tr>
                <td align="left" valign="top">Notes:</td>
                <td colspan="3" align="left" valign="top"><?php echo $_SESSION['notes']  ?></td>
              </tr>
            </table><br>
<br>

            <table width="640" align="center" id="table_resume_wizard">
  <thead>
  <tr>
    <td width="90">Date</td>
    <td width="266">Reference</td>
    <td width="176">Ref no</td>
    <td width="88">Amount</td>
  </tr>
  </thead>
  <?php
  $a4_tot = '';
  $i=0;
  while ($i<$line_num) {
	  $a1 = mysql_result($line_result, $i, "reference_date");
	  $a2 = mysql_result($line_result, $i, "reference");
	  $a3 = mysql_result($line_result, $i, "reference_no");
	  $a4 = mysql_result($line_result, $i, "amount_debit");
	  $a4_tot=$a4_tot+$a4;
  ?>
  <tr>
    <td><?php echo date("d-m-Y", strtotime($a1))?></td>
    <td><?php echo $a2?></td>
    <td><?php echo $a3?></td>
    <td align="right"><?php echo number_format($a4, 2, '.', ',')?></td>
  </tr>
  
  <?php
  $i++;
  }
  ?>
  <tfoot>
  <tr>
    <td colspan="3" align="right">Total: &nbsp;</td>
    <td align="right"><?php echo number_format($a4_tot, 2, '.', ',')?></td>
  </tr>
  </tfoot>
</table>
</div>
<div class="wizard_frame">
<?php $_SESSION['cash_balance'] = $_SESSION['amount'] - $_SESSION['returned_amount']- $total_amount;
if ($_SESSION['cash_balance'] != 0) { ?>
<img src="../images/exclamation_mark_green_small.png" width="20" height="32">&nbsp;&nbsp;There is a cash balance of <?php echo number_format($_SESSION['cash_balance'], 2, '.', ',')?>. Was this received back in cash? 
<input type="radio" name="received_selection" value="yes" id="received_selection_0">
    yes
    <input type="radio" name="received_selection" value="no" id="received_selection_1">
    no
<?php
}
else {
	?>
<img src="../images/check_mark_green.png" width="32" height="32">The voucher is in balance. <input type="radio" name="received_selection" value="balance" id="received_selection_2" checked="checked" >

<?php
}
?>
</div>
<div class="wizard_spacer_frame" style="height:10px;"></div>
<div class="wizard_frame">
              <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>
<div class="wizard_frame">
              <table width="675" 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','pettycashReturnWizbase.php?s=&p=3&pettycash_id=<?php echo $_SESSION['pettycash_id'] ?>'); return document.MM_returnValue; "/></td>
                  <td width="115">
                    <input name="s" type="hidden" id="s" value="5" />
                    <input name="p" type="hidden" id="p" value="5" />
                  </td>
                  <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="cancel_confirmation(1, '../hr_module/hr_main.php?date=0');" value="Cancel" /></td>
                  <td width="125" align="right"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
                  <td width="110" align="right"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false;  MM_showHideLayers('wait','','show');" /></td>
                </tr>
              </table>
</div>
</div> 
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  <?php
  if ($_SESSION['cash_balance'] != 0) { ?>
  frmvalidator.addValidation("received_selection","selone","- balance confirmation.");
  <?php } ?>
</script>

</body>

