<!--Notice: (c)2013 This page is part of the management program for Tlhomeso Timbers, Gaborone, 
and developed by Customized Software (Pty) Ltd, Gaborone, Botswana. 
Customized Software holds the copyright on the source code on this and all other pages in the 
management program. For more info contact Customized Software on email: info@bwcustomized.com-->


<head>

<?php	

$table_name = $_SESSION['db_prefix']."_pettycash";
$pettycash_query = "SELECT * FROM $table_name WHERE pettycash_id = '".$_SESSION['pettycash_id']."'  ";
//$pettycash_query = "SELECT * FROM $table_name WHERE emp_id = '".$_SESSION['emp_id']."'  ";                    

$pettycash_result = mySQL_query($pettycash_query);
$pettycash_num = mysql_num_rows($pettycash_result);
$a= mysql_result($pettycash_result, 0, "pettycash_id");  
$a0= mysql_result($pettycash_result, 0, "issue_date"); 
$a1= mysql_result($pettycash_result, 0, "use");
$a2= mysql_result($pettycash_result, 0, "amount");

echo "add=".$_SESSION['add'];	
require_once('../include/tc_calendar.php');
$return_date = strtotime($_SESSION['return_date']);
$d1 = date("d", $return_date ) ;
$m1 = date("m", $return_date ) ;
$y1 = date("Y", $return_date ) ;

if ($_SESSION['add']==1) {
$item= $_GET['item_text'];
$name= $_GET['name_text'];
$receipt_no= $_GET['receipt_no_text'];
$amount= $_GET['amount_text'];

$table_name = $_SESSION['db_prefix']."_pettycash_lines";
$line_query = "INSERT INTO $table_name  (`petty_cash_id`, `item`, `name`, `receipt_no`, `amount`) VALUES ('".$_SESSION['pettycash_id']."', '".$item."', '".$name."', '".$receipt_no."', '".$amount."') ";
execsql($line_query);

}

if ($_SESSION['add']==2) {
$cancel = $_GET['cancel'];
if ($cancel==0) {
$line_id = $_GET['line_id'];
$item= $_GET['item_text'];
$name= $_GET['name_text'];
$receipt_no= $_GET['receipt_no_text'];
$amount= $_GET['amount_text'];

$table_name = $_SESSION['db_prefix']."_pettycash_lines";
$update_line_query = "UPDATE $table_name SET item = '". $item ."', name = '". $name ."', receipt_no = '". $receipt_no ."', amount = '". $amount ."' WHERE line_id = '". $line_id  ."' ";
$update_line_result = mySQL_query($update_line_query);
}
}

if ($_SESSION['add']==3) {
$cancel = $_GET['cancel'];
if ($cancel==0) {
$line_id = $_GET['line_id'];
$table_name = $_SESSION['db_prefix']."_pettycash_lines";
$del_line_query = "DELETE FROM $table_name WHERE line_id = '". $line_id ."' ";
echo $del_line_query;
$del_line_result = mySQL_query($del_line_query);
}
}


$table_name = $_SESSION['db_prefix']."_pettycash_lines";
$pettycash_query = "SELECT  *   FROM $table_name WHERE petty_cash_id = '".$_SESSION['pettycash_id']."'  ";
$pettycash_result = mySQL_query($pettycash_query);
$pettycash_num = mysql_num_rows($pettycash_result);

   
?>


<script language="JavaScript" src="gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>  <!--form validation-->
<script type="text/javascript" src="../css/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script language="javascript" type="text/javascript" ></script>
<script language="javascript" src="../jscript/calendar.js"></script>

<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<link rel="stylesheet" href="../window/modal.css" type="text/css" />
<script type="text/javascript" src="../window/modal.js"></script>

<script type="text/javascript">
function addline(){
//Open a modal window with an iframe page inside, and assign the result to a global variable called "addproductwindow"
addlinewindow=dhtmlmodal.open('EmailBox', 'iframe', '../edit_windows/pettycash_line.php', 'Add line on petty cash', 'width=450px,height=250px,center=1,resize=0,scrolling=0')
needToConfirm = false;
addproductwindow.onclose=function(){return window}
}
</script>

<script type="text/javascript">
function editline(){
//Open a modal window with an iframe page inside, and assign the result to a global variable called "addproductwindow"
editlinewindow=dhtmlmodal.open(
}
</script>

<script language="JavaScript">
<!--
function confirmRefresh() {
var okToRefresh = confirm("Do you really want to cancel this entry?");
var url='hr_main.php?date='
if (okToRefresh)
	{
			window.location=url;
	}
}
// -->
</script>

<script language="JavaScript">
var needToConfirm = true;
  window.onbeforeunload = confirmExit;
   function confirmExit()
  {
    if (needToConfirm)
      return "You did not finish the wizard.\nIf you leave now your data will not be saved.";
  }
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
<link href="../css/main.css" rel="stylesheet" type="text/css" />


</head>

<body >
   
<form id="feedbackform" method="get" action="return_pettycashWizbase.php">
  <table id="tableMain" width="595">
    <!--begin of tableMain-->
    <tr>
      <td><!--center of tableMain-->
        <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
          <tr>
            <td width="525" valign="top" >
            
            
   <div class="wizard_frame">         
              <table width="948"  id="table_display_wizard">
                <tr>
                  <td width="135"  valign="middle"><label class="label_std">Date of return:</label>
&nbsp;&nbsp;
<label class="star">*</label></td>
                  <td width="639" valign="middle"><?php 
				  //instantiate class and set properties
		$myCalendar = new tc_calendar("return_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d1, $m1, $y1);
		$myCalendar->setYearInterval(2010, 2020);
		//output the calendar
		$myCalendar->writeScript();
?></td>
                  </tr>
                <tr>
                  <td height="47" valign="middle"><label class="label_std">Amount to return:</label>&nbsp;&nbsp;<label class="star">*</label></td>
                  <td valign="middle"><?php echo $a2 ?></td>
                  </tr>
                <tr>
                  <td colspan="2" align="left" valign="middle">
                    <table width="596"  id="table_list">
                      <?php 
				  $tot = 0;
				  $i=0;
				  while ($i<$pettycash_num) {
					$a =  mysql_result($pettycash_result, $i, "line_id"); 
                    $a0 = mysql_result($pettycash_result, $i, "item");
					$a1 = mysql_result($pettycash_result, $i, "name");
					$a2 = mysql_result($pettycash_result, $i, "receipt_no");
					$a3 = mysql_result($pettycash_result, $i, "amount");
					$tot = $tot + $a3;
				  ?>
                      <tr>
                        <td width="106"><?php echo $a0 ?></td>
                        <td width="129"><?php echo $a1 ?></td>
                        <td width="123"><?php echo $a2 ?></td>
                        <td width="122" align="right"><?php echo $a3 ?></td>
                        <td width="92"><span class="wizard">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="line_id" type="hidden" id="line_id" value="<?php echo $a ?>" >
                          <img src="../images/line_edit.png" style="cursor:pointer" width="16" height="16" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/edit_pettycash_line.php?line_id=<?php echo $a ?>', 'Edit petty cash line', 'width=450px,height=250px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false">&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/line_delete.png" style="cursor:pointer"  width="16" height="16" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/delete_pettycash_line.php?line_id=<?php echo $a ?>', 'Delete petty cash line', 'width=450px,height=250px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"></td>
                        </tr>
                      <?php 
					$i++;
				  }
				  ?>
                      <tr>
                        <td><span class="wizard">
                          
                          <img src="../images/line_add.png" width="16" height="16"  style="cursor:pointer" onClick="addline(); return false"> </td>
                        <td>&nbsp;</td>
                        <td>total:</td>
                        <td align="right"><?php echo number_format($tot , 2, '.', ',')  ?></td>
                        <td>&nbsp;</td>
                        </tr>
                    </table></td>
                </tr>
              </table>
            </div><br /><br /><br />
            <br />
<br /></td>
            <!--center of tableMain-->
          </tr>
          <tr>
            <td><!--center of tableMain-->
              <table width="675" 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; " /></td>
                  <td width="115">&nbsp;</td>
                  <td width="99">
                    <input name="p" type="hidden" id="p" value="3" />
                    <input name="s" type="hidden" id="s" value="3" />
                  </td>
                  <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; confirmRefresh();" value="Cancel" /></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; " /></td>
                </tr>
              </table></td>
          </tr>
        </table>
  </table>
  <!--end of tableMain-->
</form>
<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("amount_text","req","Please enter amount.");
  frmvalidator.addValidation("use_select","req","Please select reason.");
  
  </script>


	
 </body>