<?php 
session_start();
require_once 'includes/database.php';
require_once 'includes/funcs.php';
if (!isset($_SESSION['reusername'])) { echo 'Sorry You Dont Have permissions to View this Page!'; exit();}
else {$user = $_SESSION['reusername'];}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.10.4.custom.js"></script>
        <link rel="stylesheet" href="css/allcss.css" type="text/css" />
        <link rel="stylesheet" href="css/jquery-ui-1.10.4.custom.css" type="text/css" />
        <style>
            html, body {margin:0; padding:0; height:100%; width:100%; min-width:100%; min-height:100%; overflow:scroll;}
			#exvform {
			text-align: left;
			width:90%;
			margin: 5px; padding-left:5px; padding-right:5px;
			border: 1px solid #666; 
			background: #D4D4FF;
			box-shadow: 0px 0px 5px rgba(0,0,0,0.5); 
			font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
			font-weight:bold;
			font-size:14px;
			color:#2C2C57; 
			z-index: 100;
			text-wrap: none;
}
        </style>
<script>        
 $(document).ready(function() { 
 
 $('#chks').hide();
 
$("#btnaddexpvch").click(function(e) {
e.preventDefault();
   
if( $('#idate').val()===""  || $('#am').val()===""  || $('#expacc').val()===""  || $('#bacc').val()==="" || $('#pmode').val()===""){
        $(".validateTips3").html("<font size='2' color='red'><center>All Fields Are Required!</center></font>");
        } 
else { 
    if($("#am").val()==="") { var ramount = 0;}  else {  var ramount = $("#am").val();}
    if($("#rmks").val()!== null) { var vrmk = $("#rmks").val();} else {  var vrmk = "";}
    if($("#idate").val()!== null) { var idate = $("#idate").val();} else {  var idate = "0000-00-00";}
    if($("#expacc").val()!== null) { var expacc = $("#expacc").val();} else {  var expacc = 0;}
    if($("#bacc").val()!== null) { var bacc = $("#bacc").val();} else {  var bacc = 0; } 	alert($('#dexpno').val());
    window.location.replace("dexpsav.php?dexpno="+$('#dexpno').val()+"&ddate="+$('#idate').val()+"&am="+ramount+"&rmks="+vrmk+"&expacc="+expacc+"&bacc="+bacc+"&pmode="+$('#pmode').val()+"&chqno="+$('#chqno').val());
	}
 });
 }); 
</script>

<?php 
if($_REQUEST['e'] === "0"){
	$idate = date("d-m-Y");
	$expacc = '';
	$bacc = '';
	$rmks = '';
	$am = 0;
	$dexpno = 0;
	$chqno = '';
	$pmode = '';
}
else {
	$dexpno = $_REQUEST['dexpno'];
	require_once 'includes/database.php';
	$db=new MySQLDatabase();
	$db->open_connection();
	$query = "SELECT * FROM dexptrans WHERE dexpno = '$dexpno';";
	$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
	if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
		$expacc = $row['expacc'];
		$bacc = $row['bacc'];
		$idate = substr($row['ddate'],8,2)."-".substr($row['ddate'],5,2)."-".substr($row['ddate'] ,0,4);
		$rmks = $row['rmks'];
		$am= $row['amount'];
		$dexpno = $row['dexpno'];
		$chqno = $row['chqno'];
		$pmode = $row['pmode'];
	}
}
?>	
   
    </head><body>
<p class="titletr">New Expense Voucher <?php echo str_repeat('&nbsp;', 120); ?><a href="#"><img src="images/close.png" onclick="window.close();"> </a></p>       
<form id="exvform" method="post" onkeypress="return event.keyCode!=13" action="#" >
                    <center>
                    <p id="validateexpvch" class="validateTips3">All fields are required</p>    
                    <table cellspacing="5px" id="lladdbox">
			
                    <tr><td align="left"><label for="rdate"> Date &nbsp;</label></td>
                    <td><input type="text" id="idate" class="dpicker" name="idate" value="<?php if($_REQUEST['e'] === "0"){ echo date('d-m-Y');} else { echo $idate;} ?>" size="20"> <input type="hidden" id="dexpno" name="dexpno" value="<?php echo $dexpno; ?>"/> </td>
                    </tr>  
					<tr><td align="left"><label for="pmode"> Payment Mode &nbsp;</label></td>
                    <td><select id="pmode" name="pmode" style="width:80px; height:20px;" onchange="getpaymoddet();"><?php if($_REQUEST['e'] !== "0"){ echo '<option value="'.$pmode.'" selected>'.$pmode.'</option>'; } ?> <option value="CASH">CASH</option><option value="CHEQUE">CHEQUE</option><option value="MPESA">MPESA</option></select> </td>
                    </tr>
					
                    <tr><td align="left"><label for="tid"> Debit Expense Account &nbsp;</label></td>
                    <td><select id="expacc" name="expacc" style="width:240px; height:20px;" > <?php if($_REQUEST['e'] === "0"){ echo '<option value=""></option>'; } else { echo '<option value="'.$expacc.'" selected>'.$expacc.'</option>'; } echo selallexpaccs();?> </select> </td>
                    </tr>    

                    <tr><td align="left"><label for="rtype"> Credit Bank Account &nbsp;</label></td>
                    <td><select id="bacc" name="bacc" style="width:240px; height:20px;"><?php if($_REQUEST['e'] === "0"){ echo '<option value=""></option>'; } else { echo '<option value="'.$bacc.'" selected>'.$bacc.'</option>'; }  echo selallbanks();?></select></td>
                    </tr>
					
                    <div  id="chks" >  
                    <tr><td align="left"><label for="chqno"> Cheque No. &nbsp;</label> &nbsp;</td>
						<td><input type="text" id="chqno" name="chqno" value="<?php if($_REQUEST['e'] === "0"){ echo ''; } else { echo $chqno; } ?>" size="10"/></td>
                    </tr> 
					</div>
                    <tr><td align="left"><label for="am"> Amount &nbsp;</label></td>
                    <td><input type="text" id="am" name="am" value="<?php if($_REQUEST['e'] === "0"){ echo ''; } else { echo $am; } ?>" size="10"></td>
                    </tr>
                    <tr><td align="left"><label for="rmks"> Remarks &nbsp;</label></td>
                    <td><input type="text" id="rmks" name="rmks" value="<?php if($_REQUEST['e'] === "0"){ echo ''; } else { echo $rmks; } ?>" size="40"></td>
                    </tr>

                    <br />
                    <tr><td colspan=2 align="center"><input type="submit" id="btnaddexpvch" name="btnaddexpvch"  class="text ui-widget-content ui-corner-all" value=" Save Expense " style="width:160px;font-weight:bold; "/></td>
                    </td></tr>
                    </table></center>
                    </form>
    </body>
</html>
<script type="text/javascript">
$(".dpicker").datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});     
                                                               // setting bank for cash
function getpaymoddet(){ 
 if($('#pmode').val()==="CASH") { alert("CCC");
     document.getElementById('bacc').value="CASH IN HAND"; 
     $('#chks').hide();
 }
 else {
    $('#chks').show();
    document.getElementById('bacc').selectedIndex=1;
    }
 };
 
</script>



