<?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;}
#regform {
text-align: left;
width:90%;
margin: 5px; padding-left:5px; padding-right:5px;
border: 1px solid #666; 
background: #FFD47F;
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() { 

$("#btnaddcrinv").click(function(e) {
e.preventDefault();
var rtype = $("#rtype :selected").val();
   
if( $('#idate').val()===""  || $('#am').val()==="" || $('#rtype').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 = ".";}
    var jqxhrposts = $.post("crnsav.php?newdoc=true&idate="+$('#idate').val()+"&am="+ramount+"&rmks="+vrmk+"&rtype="+rtype+"&cname="+$('#cname').val(), function(data) {
						alert(data);
						if (data==="nothing"){ $(".validateTips3").html("<font size='2' color='red'><center>Error in creating Credit Note/Invoice!</center></font>"); }
						else { window.close(); }                         
                          } );
                          
    }                    
});
 });
</script>
   
    </head><body>
<p class="titletr">New Credit Note <?php echo str_repeat('&nbsp;', 120); ?><a href="#"><img src="images/close.png" onclick="window.close();"> </a></p>       
<form id="regform" method="post" onkeypress="return event.keyCode!=13" action="crnadd.php" >
                    <center>
                    <p id="validatecrinv" class="validateTips3">All fields are required</p>    
                    <table cellspacing="5px" id="lladdbox">
					
                    <tr><td align="left"><label for="rdate"> Doc. Date &nbsp;</label></td>
                    <td><input type="text" id="idate" name="idate" required="required" value="<?php echo date('d-m-Y'); ?>" size="20"/> </td>
                    </tr>   
					<tr><td align="left"><label for="rtype"> Type &nbsp;</label></td>
                    <td><select id="rtype" name="rtype" style="width:160px; height:20px;" required="required" ><option value="INSURANCE">INSURANCE</option> <option value="REPOSESSION">REPOSESSION</option> <option value="TRACKER">TRACKER</option> </select></td>
                    </tr>  
					<tr><td align="left"><label for="cname">Customer Name &nbsp; </label></td>
                    <td><select id="cname" name="cname"><?php echo selcus(); ?></select>  </td>
                    </tr> 
                    <tr><td align="left"><label for="am"> Amount &nbsp;</label></td>
                    <td><input type="text" id="am" name="am" value="0" size="20"> &nbsp;&nbsp; </td>
                    </tr>
                    <tr><td align="left"><label for="rmks"> Remarks &nbsp;</label></td>
                    <td><input type="text" id="rmks" name="rmks" value="" size="40"></td>
                    </tr>

                    <br />
                    <tr><td colspan=2 align="center"><input type="submit" id="btnaddcrinv" name="btnaddcrinv"  class="text ui-widget-content ui-corner-all" value=" Save Document " style="width:160px;font-weight:bold; "/></td>
                    </td></tr>
                    </table></center>
                    </form>
    </body>
</html>
<script type="text/javascript">
$("#idate").datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});    
                                                             
</script>



