<?php 
session_start();
require_once 'includes/database.php';
include '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;z-index: 100;}  
#proform {
text-align: left;
width:90%;
margin: 5px; padding-left:5px; padding-right:5px;
border: 1px solid #666; 
background: #A3CEA3;
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 type="text/javascript">       
$(document).ready(function() {  

$("#btnmodins").click(function(e) {
e.preventDefault();
if( $('#cname').val() === ''  ){ document.getElementById('valerr').value="Customer Name Cannot be Blank!";	} 
else if( $('#insurer').val() === ''  ){ document.getElementById('valerr').value="Insurer Name Cannot be Blank!";	}
else if( $('#idate').val() === ''  ){ document.getElementById('valerr').value="Date Cannot be Blank!";	}
else if( $('#icat').val() === ''  ){ document.getElementById('valerr').value="Category Cannot be Blank!";	}
else if( $('#insprem').val() === ''  ){ document.getElementById('valerr').value="Premium Value Cannot be Blank!";	}
else if( $('#chasis').val() === ''  ){ document.getElementById('valerr').value="Chasis Cannot be Blank!";	}
else if( $('#inam').val() === ''  ){ document.getElementById('valerr').value="Insured Value Cannot be Blank!";	}
else if( $('#cname').val() !== '' && $('#idate').val() !== '' && $('#chasis').val() !== '' && $('#insurer').val() !== '' && $('#invno').val() !== '') {
		var savjcdet = $.post("savinsinv.php?e=1&cname="+$('#cname').val()+"&invno="+$('#invno').val()+"&idate="+$('#idate').val()+"&vehmod="+$('#vehmod').val()+"&chasis="+$('#chasis').val()+
		"&regno="+$('#regno').val()+"&vcolor="+$('#vcolor').val()+"&insurer="+$('#insurer').val()+"&instel="+$('#instel').val()+"&inam="+$('#inam').val()+"&insprem="+
		$('#insprem').val()+"&rmks="+$('#rmks').val()+"&insrate="+$('#insrate').val()+"&icat="+$('#icat').val(), function(data){
                                if(data.trim()==="OK") { window.close(); } });
	 	}						
});

 
});
</script>
<?php 

	$invno = $_REQUEST['invno'];
	require_once 'includes/database.php';
	$db=new MySQLDatabase();
	$db->open_connection();
	$query = "SELECT cname, idate, vehmod, regno, chasis, vcolor, insurer, insrate, inam, icat, insprem, instel, rmks FROM insinvoices WHERE invno = '$invno';";
	$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
	if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
		$cname = $row['cname'];
		$idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'] ,0,4);
		$vehmod = $row['vehmod'];
		$regno = $row['regno'];
		$chasis = $row['chasis'];
		$vcolor =$row['vcolor'];
		$insurer = $row['insurer'];
		$insrate = $row['insrate'];
		$instel = $row['instel'];
		$inam = $row['inam'];
		$icat = $row['icat'];
		$insprem = $row['insprem'];
		$rmks = $row['rmks'];
	}
	else { echo '<script type="text/javascript"> window.close();</script>';}

?>   
</head><body>
<p class="titletr"> Provider Details<?php echo str_repeat('&nbsp;', 8); ?> <input type="text" id="valerr" name="valerr" value="" size="30"> <?php echo str_repeat('&nbsp;', 10); ?> <a href="#"><img src="images/close.png" onclick="window.close();"> </a>  </p>       
<form id="proform" method="post" onkeypress="return event.keyCode!=13" enctype="multipart/form-data" action="#" >
                    <center>
                    <table cellspacing="5px" id="regaddbox">
					<tr><td align="left"><label for="idate"> Date &nbsp;</label></td>
                    <td><input type="text" id="idate" name="idate" value="<?php echo $idate; ?>" size="20"/> </td>
                    </tr>
                    <tr><td align="left"><label for="cname">Dealer Name &nbsp; </label></td>
                    <td><input type="text" id="cname" name="cname" value= "<?php echo $cname; ?>" size="40"/> <input type="hidden" id="invno" name="invno" value= "<?php echo $invno; ?>"> </td>
                    </tr>
					<tr><td align="left"><label for="insurer"> Insurer &nbsp;</label></td>
                    <td><input type="text" id="insurer" name="insurer" value="<?php echo $insurer; ?>" size="40"/> </td>
                    </tr>
					<tr><td align="left"><label for="instel"> Insurer Phone No. &nbsp;</label></td>
                    <td><input type="text" id="instel" name="instel" value="<?php echo $instel; ?>" size="20"/> </td>
                    </tr>
					<tr><td align="left"><label for="icat"> Category &nbsp;</label></td>
                    <td><select id="icat" name="icat" style="width:120px;"><?php echo '<option value="'.$icat.'"></option>';?> <option value="COMMERCIAL">COMMERCIAL</option> <option value="PRIVATE">PRIVATE</option> <option value="THIRD PARTY">THIRD PARTY</option></select> </td>
                    </tr>
                    <tr><td align="left"><label for="vehmod"> Vehicle Model &nbsp;</label></td>
                    <td><input type="text" id="vehmod" name="vehmod" value="<?php echo $vehmod; ?>" size="40"/> </td>
                    </tr>
                    <tr><td align="left"><label for="chasis"> Chassis No. &nbsp;</label></td>
                    <td><input type="text" id="chasis" name="chasis" value="<?php echo $chasis; ?>" size="20"/> </td>
                    </tr>
                    <tr><td align="left"><label for="regno"> Reg. No. &nbsp;</label></td>
                    <td><input type="text" id="regno" name="regno" value="<?php echo $regno; ?>" size="10"/> </td>
                    </tr>
					<tr><td align="left"><label for="vcolor"> Vehicle Colour &nbsp;</label></td>
                    <td><input type="text" id="vcolor" name="vcolor" value="<?php echo $vcolor; ?>" size="20"/> </td>
                    </tr>
					<tr><td align="left"><label for="inam"> Insured Value &nbsp;</label></td>
                    <td><input type="text" id="inam" name="inam" onchange="showprem();" value="<?php echo $inam; ?>" size="20" /> </td>
                    </tr>
					<tr><td align="left"><label for="insrate"> Insurance Rate (%)&nbsp;</label></td>
                    <td><input type="text" id="insrate" name="insrate" onchange="showprem();" value="<?php echo $insrate; ?>" size="20"> </td>
                    </tr>
					<tr><td align="left"><label for="insprem"> Premium Amount &nbsp;</label></td>
                    <td><input type="text" id="insprem" name="insprem" required="requirred" value="<?php echo $insprem; ?>" size="20"/> </td>
                    </tr>				
					<tr><td align="left"><label for="rmks"> Remarks &nbsp;</label></td>
                    <td><input type="text" id="rmks" name="rmks" value="<?php echo $rmks; ?>" size="40"> </td>
                    </tr>
                    <tr><td colspan=2> </td></tr><br />
                    <tr><td colspan=2 align="center">
					<input type="button" class="text ui-widget-content ui-corner-all" style="width:160px;font-weight:bold;" id="btnmodins" name="btnmodins" value=" Save Details "/>
                    </td></tr>
                    </table></center>
        </form>
</body>
</html>

<script type="text/javascript">   
$('#cname').autocomplete({ source: <?php echo allcustomers(); ?>, minLength: 2  });                                                             
$('#idate').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"}); 

																			// computation of premium
function showprem(){  
 if($('#inam').val() !== '' && $('#insrate').val() !== ''){
	var imm = parseFloat(document.getElementById('inam').value);
	var imn = parseFloat(document.getElementById('insrate').value);
	document.getElementById('insprem').value = imm * imn/100;                    
	}
else { document.getElementById('insprem').value = 0;}	
};
</script>



