<?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;}
            #tenform {
            text-align: left;
            width:100%;
            padding-left:10px; padding-right:5px; 
            background: #55D4FF;
            box-shadow: 0px 0px 5px rgba(0,0,0,0.5); 
            font-family:Calibri, Arial, Helvetica, sans-serif;
            font-weight:bold;
            font-size:14px;
            color:#7A2525;
            }
        </style>
<script>        
 $(document).ready(function() { 

$("#btnaddbkjv").click(function(e) {
e.preventDefault();
   
if( $('#idate').val()===""  || $('#am').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 jdate = $("#idate").val();} else {  var jdate = "0000-00-00";}
    if($("#dacc").val()!== null) { var dacc = $("#dacc").val();} else {  var dacc = 0;}
    if($("#cacc").val()!== null) { var cacc = $("#cacc").val();} else {  var cacc = 0;} 
    var jqxhrposts = $.get("bankjvsav.php?newjv="+$('#jvno').val()+"&jdate="+jdate+"&am="+ramount+"&rmks="+vrmk+"&dacc="+dacc+"&cacc="+cacc, function(data) {
						if (data==="nothing"){ $(".validateTips3").html("<font size='2' color='red'><center>Error in creating Bank JV!</center></font>"); }
						else { if($('#jvno').val() ==='0') { alert('Saved wih JV No.'+data);  } }
						window.close();
                          } );
                          
    }                    
});
 });
</script>
<?php 
if($_REQUEST['e'] === "0"){
	$jdate = date("d-m-Y");
	$dacc = '';
	$cacc = '';
	$rmks = '';
	$amount = 0;
	$jvno = 0;
}
else {
	$jvno = $_REQUEST['jvno'];
	require_once 'includes/database.php';
	$db=new MySQLDatabase();
	$db->open_connection();
	$query = "SELECT * FROM bktrans WHERE jvno = '$jvno';";
	$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
	if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC )){
		$dacc = $row['dacc'];
		$cacc = $row['cacc'];
		$jdate = substr($row['jdate'],8,2)."-".substr($row['jdate'],5,2)."-".substr($row['jdate'] ,0,4);
		$rmks = $row['rmks'];
		$am= $row['amount'];
		$jvno = $row['jvno'];
	}
}
?>	
</head><body>
<p class="titletr"><?php echo ($_REQUEST['e'] === "0") ? 'New Bank JV' : 'Edit Bank JV';  echo str_repeat('&nbsp;', 90); ?><a href="#"><img src="images/close.png" onclick="window.close();"> </a></p>       
					<form id="tenform" method="post"  action="#" >
                    <center>
                    <p id="validatebkjv" 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 $jdate; } ?>" size="20"> <input type="hidden" id="jvno" name="jvno" value="<?php echo $jvno; ?>"/> </td>
                    </tr>     
                    <tr><td align="left"><label for="tid"> Debit Account &nbsp;</label></td>
                    <td><select id="dacc" name="dacc" style="width:240px; height:20px;" > <?php if($_REQUEST['e'] === "0"){ echo '<option value=""></option>'; } else { echo '<option value="'.$dacc.'">'.$dacc.'</option>'; }  echo selallbanks();?> </select> </td>
                    </tr>    

                    <tr><td align="left"><label for="rtype"> Credit Account &nbsp;</label></td>
                    <td><select id="cacc" name="cacc" style="width:240px; height:20px;"><?php if($_REQUEST['e'] === "0"){ echo '<option value=""></option>'; } else { echo '<option value="'.$cacc.'">'.$cacc.'</option>'; }  echo selallbanks();?></select></td>
                    </tr>

                    <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="btnaddbkjv" name="btnaddbkjv"  class="text ui-widget-content ui-corner-all" value=" Save JV " 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"});     

</script>



