
<?php
$_SESSION['pettycash_id'] = $_GET['pettycash_id'];

$table_name = $_SESSION['db_prefix']."_pettycash";
$amount_query = "SELECT amount, returned_amount FROM $table_name WHERE pettycash_id = '".$_SESSION['pettycash_id']."' ";
$amount_result = mySQL_query($amount_query);
$_SESSION['amount'] = mysql_result($amount_result, 0, "amount");
$_SESSION['returned_amount'] = mysql_result($amount_result, 0, "returned_amount");


$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);
$today = date("d-m-Y");

?>
<!--style sheets-->
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
<link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/upper_case.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
<script type="text/javascript" src="../jscript/datepicker.js"></script>
<script language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
			var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            element1.name="line_checkbox"+line_no;
			element1.id="line_checkbox"+line_no;
			/*element1.checked="checked";*/
            cell1.appendChild(element1);
			 
            var cell2 = row.insertCell(1);
            var element5 = document.createElement("input");
            element5.type = "text";
			element5.value = "<?php echo $today?>";
            element5.name = "inputDate"+line_no;
			element5.id = "inputDate"+line_no;
			var date_var = $("#inputDate1");
			element5.className = "inputDate";
			cell2.appendChild(element5);
			
			
			var element7 = document.createElement("script");
			element7.setAttribute('type', 'text/javascript');
            /*element7.type = "text/script";*/
            element7.innerHTML='$("#'+element5.id+'").DatePicker({format:"d-m-Y",date: $("#'+element5.id+'").val(),current: $("#'+element5.id+'").val(),starts: 1,	position: "r",onBeforeShow: function(){$("#'+element5.id+'").DatePickerSetDate($("#'+element5.id+'").val(), true);},onChange: function(formated, dates){$("#'+element5.id+'").val(formated);$("#'+element5.id+'").DatePickerHide();}});' ;
			/*element7.appendChild(document.createTextNode("alert('yes')" ) );*/
			document.getElementsByTagName('head').item(0).appendChild(element7);
			/*element7.text = document.writeln('this is it');*/
			/*cell2.appendChild(element7);*/
			
						
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            element2.name = "reference_text"+line_no;
			element2.className = "text200";
			element2.value = "";
			element2.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
			cell3.appendChild(element2);
			
			var cell4 = row.insertCell(3);
            var element3 = document.createElement("input");
            element3.type = "text";
            element3.name = "ref_no_text"+line_no;
			element3.className = "text100";
			element3.onkeyup = function() {ToUpper(this)};
            cell4.appendChild(element3);
			
			var cell5 = row.insertCell(4);
			var element6 = document.createElement("input");
            element6.type = "text";
            element6.name = "amount_text"+line_no;
			element6.className = "text60";
			element6.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if (charCode != 46 && charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element6.onchange = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element6.style = "text-align:right";		

            var element4 = document.createElement("input");
            element4.type = "hidden";
            element4.name = "line_num";
			element4.value = rowCount;
            						
			cell5.appendChild(element6);
            cell5.appendChild(element4);
			
			var element8 = document.createElement("script");
			element8.setAttribute('type', 'text/javascript');
			element8.innerHTML="var frmvalidator  = new Validator('feedbackform');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('reference_text'+i,'req','- reference on line '+(i+1)+'.');frmvalidator.addValidation('ref_no_text'+i,'req','- reference number on line '+(i+1)+'.');frmvalidator.addValidation('amount_text'+i,'req','- amount on line '+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element8);
			
			
			element1.onmouseup = function() {
				 if (document.getElementById('line_checkbox'+line_no).checked) {
                         element2.style.background = '#F0F0F0';
						 element3.style.background = '#F0F0F0';
						 element6.style.background = '#F0F0F0';
						 element2.value = '-----';
						 element3.value = '-----';
						 element6.value = '0';
						 element2.disabled = true;
						 element3.disabled = true;
						 element6.disabled = true;
						 
                } else {
                        element2.style.background = '#FFF';
						element3.style.background = '#FFF';
						element6.style.background = '#FFF';
						element2.value = '';
						element3.value = '';
						element6.value = '';
						element2.disabled = false;
						element3.disabled = false;
						element6.disabled = false;
						 
                }
				};
			
}

</script>
<link href="../css/wizard.css" rel="stylesheet" type="text/css">
<link href="../css/main.css" rel="stylesheet" type="text/css">
<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');" >

   

<div class="wizard_page_middle_frame">
<form id="feedbackform" method="get" action="pettycashReturnWizbase.php">
<div class="wizard_frame">
  Enter receipts for petty cash voucher no <?php echo $_SESSION['pettycash_id'] ?>:<br>
Outstanding amount on this voucher: P<?php echo $_SESSION['amount']?><br><br>


    <table id="dataTable" width="628" border="1" style="border-collapse:collapse;">
    <?php
	
	   if ($line_num==0) {
	       $a0=$today;
		   $a1='';
		   $a2='';
		   $a3='';
	   }
	   else {
		   $a0 = mysql_result($line_result, 0, "reference_date");
		   $a1 = mysql_result($line_result, 0, "reference");
		   $a2 = mysql_result($line_result, 0, "reference_no");
		   $a3 = mysql_result($line_result, 0, "amount_debit");
	   }
		?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td>Date</TD>
          <td>Reference</td>
          <td>Reference no</td>
          <td>Amount</td>
        </tr>
        </thead>
        <script>
			 function check_it() {
				 if (document.getElementById('line_checkbox0').checked) {
                         document.getElementById('reference_text0').style.background = '#F0F0F0';
						 document.getElementById('ref_no_text0').style.background = '#F0F0F0';
						 document.getElementById('amount_text0').style.background = '#F0F0F0';
						 document.getElementById('reference_text0').value = '-----';
						 document.getElementById('ref_no_text0').value = '-----';
						 document.getElementById('amount_text0').value = '0';
						 document.getElementById('reference_text0').disabled = true;
						 document.getElementById('ref_no_text0').disabled = true;
						 document.getElementById('amount_text0').disabled = true;
						 
                } else {
                        document.getElementById('reference_text0').style.background = '#FFF';
						 document.getElementById('ref_no_text0').style.background = '#FFF';
						 document.getElementById('amount_text0').style.background = '#FFF';
						 document.getElementById('reference_text0').value = '';
						 document.getElementById('ref_no_text0').value = '';
						 document.getElementById('amount_text0').value = '';
						 document.getElementById('reference_text0').disabled = false;
						 document.getElementById('ref_no_text0').disabled = false;
						 document.getElementById('amount_text0').disabled = false;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0" onMouseUp="check_it()" <?php if ($a1!='') { ?> checked="checked" <?php } ?> /></td>
          <td width="116"><input class="inputDate" name="inputDate0" id="inputDate0" value="<?php echo date("d-m-Y", strtotime($a0 ))?>" />
					<label id="closeOnSelect"><!--<input type="checkbox" /> Close on selection--></label>
<script>

$('#inputDate0').DatePicker({
	format:'d-m-Y',
	date: $('#inputDate0').val(),
	current: $('#inputDate0').val(),
	starts: 1,
	position: 'r',
	onBeforeShow: function(){
		$('#inputDate0').DatePickerSetDate($('#inputDate0').val(), true);
	},
	onChange: function(formated, dates){
		$('#inputDate0').val(formated);
		/*if ($('#closeOnSelect input').attr('checked')) {*/
			$('#inputDate0').DatePickerHide();
		/*}*/
	}
});
</script>
</td>
            <td width="276"> <input name="reference_text0" type="text" class="text200" id="reference_text0"  value="<?php echo $a1 ?>" autofocus onChange="document.getElementById('line_checkbox0').checked = 'checked';"/> </td>
            <td width="102"><input  name="ref_no_text0" type="text" class="text100" id="ref_no_text0" value="<?php echo $a2 ?>" onKeyUp="ToUpper(this)"/></td>
            <td width="80"><input  name="amount_text0" type="text" class="text60" id="amount_text0" value="<?php if ($a3!=0) {echo number_format($a3, 2, '.', ',');} ?>" onKeyPress="return isNumberKey(event)" onChange=" this.value = this.value.replace (/(\...).*/, '$1')" style="text-align:right"/><input type="hidden" name="line_num" id="line_num" value="1" >
        
            

        </td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line_num) {
		$a0 = mysql_result($line_result, $i, "reference_date");
		$a1 = mysql_result($line_result, $i, "reference");
		$a2 = mysql_result($line_result, $i, "reference_no");
		$a3 = mysql_result($line_result, $i, "amount_debit");
		?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox<?php echo $i ?>" id="line_checkbox<?php echo $i ?>"  <?php if ($a1!='') { ?> checked="checked" <?php } ?> onMouseUp="{
				 if (document.getElementById('line_checkbox<?php echo $i ?>').checked) {
                         document.getElementById('reference_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('ref_no_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('amount_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('reference_text<?php echo $i ?>').value = '-----';
						 document.getElementById('ref_no_text<?php echo $i ?>').value = '-----';
						 document.getElementById('amount_text<?php echo $i ?>').value = '0';
						 document.getElementById('reference_text<?php echo $i ?>').disabled = true;
						 document.getElementById('ref_no_text<?php echo $i ?>').disabled = true;
						 document.getElementById('amount_text<?php echo $i ?>').disabled = true;
                } else {
                        document.getElementById('reference_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('ref_no_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('amount_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('reference_text<?php echo $i ?>').value = '';
						 document.getElementById('ref_no_text<?php echo $i ?>').value = '';
						 document.getElementById('amount_text<?php echo $i ?>').value = '';
						 document.getElementById('reference_text<?php echo $i ?>').disabled = false;
						 document.getElementById('ref_no_text<?php echo $i ?>').disabled = false;
						 document.getElementById('amount_text<?php echo $i ?>').disabled = false;
                }
				}
                "/></td>
          <td width="116"><input class="inputDate" name="inputDate<?php echo $i ?>" id="inputDate<?php echo $i ?>" value="<?php echo date("d-m-Y", strtotime($a0))?>" />
					<label id="closeOnSelect"><!--<input type="checkbox" /> Close on selection--></label> 
            <script>
$('#inputDate<?php echo $i ?>').DatePicker({
	format:'d-m-Y',
	date: $('#inputDate<?php echo $i ?>').val(),
	current: $('#inputDate<?php echo $i ?>').val(),
	starts: 1,
	position: 'r',
	onBeforeShow: function(){
		$('#inputDate<?php echo $i ?>').DatePickerSetDate($('#inputDate<?php echo $i ?>').val(), true);
	},
	onChange: function(formated, dates){
		$('#inputDate<?php echo $i ?>').val(formated);
		if ($('#closeOnSelect input').attr('checked')) {
			$('#inputDate<?php echo $i ?>').DatePickerHide();
		}
	}
});
</script>
</td>
            <td width="276"> <input name="reference_text<?php echo $i ?>" type="text" class="text200" id="reference_text<?php echo $i ?>" value="<?php echo $a1 ?>" onChange="document.getElementById('line_checkbox'<?php echo $i ?>).checked = 'checked';"/> </td>
            <td width="102"><input  name="ref_no_text<?php echo $i ?>" type="text" class="text100" id="ref_no_text<?php echo $i ?>" value="<?php echo $a2 ?>"/></td>
            <td width="80"><input  name="amount_text<?php echo $i ?>" type="text" class="text60" id="amount_text<?php echo $i ?>" value="<?php echo number_format($a3, 2, '.', ',') ?>" onKeyPress="return isNumberKey(event)" onChange=" this.value = this.value.replace (/(\...).*/, '$1')" style="text-align:right"/>              <input type="hidden" name="line_num" id="line_num" value="<?php echo $line_num?>"></td>
        </tr>
        <?php
		$i++;
		}
		?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow('dataTable')" value="Add line" />
    <input name="save_button" type="submit" class="imagebutton" id="save_button" value="Temp Save" onClick="needToConfirm = false; form.action='pettycashReturnWiz3_save.php';">
  <div align="right"><label class="label_small">To delete a line: uncheck line box and click Temp Save.</label></div>
  
					
				
  </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=2');return document.MM_returnValue; "/></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="cancel_confirmation(1, '../hr_module/hr_main.php?date=0');" value="Cancel" /></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); " /></td>
                </tr>
              </table>

<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("reference_text0","req","- reference on line 1.");
  frmvalidator.addValidation("ref_no_text0","req","- reference number  on line 1.");
  frmvalidator.addValidation("amount_text0","req","- amount  on line 1.");
  
  for (i = 0; i < 10; i++) {
	frmvalidator.addValidation("reference_text"+i,"req","- reference on line "+(i+1)+".");
  	frmvalidator.addValidation("ref_no_text"+i,"req","- reference number  on line "+(i+1)+".");
  	frmvalidator.addValidation("amount_text"+i,"req","- amount on line "+(i+1)+".");
}
  </script>
</div>
</form>
</div>
</body>