<?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;
margin: 3px; 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( $('#supp').val() === ''  ){ document.getElementById('valerr').value="Provider Cannot be Blank!";	}
else if( $('#proprem').val() === ''  ){ document.getElementById('valerr').value="Provider Premium Cannot be Blank!";	}
else if( $('#prorate').val() === ''  ){ document.getElementById('valerr').value="Provider Rate Cannot be Blank!";	}
else if( $('#proval').val() === ''  ){ document.getElementById('valerr').value="Provider Value Cannot be Blank!";	}
else if( $('#levy').val() === ''  ){ document.getElementById('valerr').value="Levy Cannot be Blank!";	}
else if( $('#sduty').val() === ''  ){ document.getElementById('valerr').value="Stamp Duty Cannot be Blank!";	}
else if( $('#wtax').val() === ''  ){ document.getElementById('valerr').value="Withholding Tax Cannot be Blank!";	}
else if( $('#comm').val() === ''  ){ document.getElementById('valerr').value="Commission Cannot be Blank!";	}
else if( $('#proam').val() === ''  ){ document.getElementById('valerr').value="Provider Due Amount Cannot be Blank!";	}
else if( $('#prorate').val() !== '' && $('#proam').val() !== '' && $('#proprem').val() !== '') {
		var savjcdet = $.post("savproinv.php?insno="+$('#insno').val()+"&proval="+$('#proval').val()+"&proprem="+$('#proprem').val()+"&prorate="+$('#prorate').val()+"&pno="+$('#poln').val()+"&expdate="+$('#expdate').val()+"&supp="+$('#supp').val()+
			"&iam="+$('#iam').val()+"&bam="+$('#bam').val()+"&cname="+$('#cname').val()+"&idate="+$('#idate').val()+"&plevy="+$('#plevy').val()+"&psduty="+$('#psduty').val()+"&pwtax="+$('#pwtax').val()++"&clevy="+$('#clevy').val()+"&csduty="+$('#csduty').val()+"&cwtax="+$('#cwtax').val()+"&comm="+$('#comm').val()+"&rmks="+$('#rmks').val(), function(data){
                                if(data.trim()==="OK") { window.location.replace("invinsprint.php?invno="+); } });
	 	}						
});

 
});
</script>
<?php 
	$insno = $_REQUEST['insno'];
	require_once 'includes/database.php';
	require_once 'includes/funcs.php';
	$db=new MySQLDatabase();
	$db->open_connection();
	$query = "SELECT * FROM insrecs WHERE insno = '$insno';";
	$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
	if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
		$cname = $row['cname'];
		$supp = $row['supp'];
		$idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'] ,0,4);
		$prorate = $row['prorate'];
		$proprem = $row['proprem'];
		$proam= $row['proam'];
		$proval= $row['proval'];
		$insurer = $row['insurer'];
		$insrate = $row['insrate'];
		$inam = $row['inam'];
		$insprem = $row['insprem'];
		$pllam = $row['pllam'];		$cexp = $row['cexp'];	$cexpr = $row['cexpr'];
		$pexp = $row['pexp'];	$pexpr = $row['pexpr'];
		$ppvt = $row['ppvt'];	$ppvtr = $row['ppvtr'];
		$cpvt = $row['cpvt'];	$cpvtr = $row['cpvtr'];
		$poln = $row['pno'];	$invno = $row['invno'];		$billno = $row['billno'];
		$instdate1 = substr($row['instdate1'],8,2)."-".substr($row['instdate1'],5,2)."-".substr($row['instdate1'] ,0,4);
		$instdate2 = substr($row['instdate2'],8,2)."-".substr($row['instdate2'],5,2)."-".substr($row['instdate2'] ,0,4);	
		$instdate3 = substr($row['instdate3'],8,2)."-".substr($row['instdate3'],5,2)."-".substr($row['instdate3'] ,0,4);
		$billdate1 = substr($row['billdate1'],8,2)."-".substr($row['billdate1'],5,2)."-".substr($row['billdate1'],0,4);	
		$billdate2 = substr($row['billdate2'],8,2)."-".substr($row['billdate2'],5,2)."-".substr($row['billdate2'],0,4);			
		$billdate3 = substr($row['billdate3'],8,2)."-".substr($row['billdate3'],5,2)."-".substr($row['billdate3'],0,4);	
		$clevy = $row['clevy'];	
		if($row['clevy']=='0'){ $clevy = round((floatval($insprem)+floatval($cexp)+floatval($cpvt)+floatval($pllam))*0.45/100,0); }
		$cwtax = $row['cwtax'];
		$csduty = $row['csduty'];
		if($row['csduty']=='0'){ $csduty = 40; }
		$plevy = $row['plevy'];	
		if($row['plevy']=='0'){ $plevy = round((floatval($proprem)+floatval($pexp)+floatval($ppvt)+floatval($pllam))*0.45/100,0); }
		$pwtax = $row['pwtax'];
		$psduty = $row['psduty'];
		if($row['psduty']=='0'){ $psduty = 40; }
		$plllab = $row['plllab'];	$pllam = intval($row['pllam']);
		$comm = $row['comm'];	if($row['comm']=='0'){ $comm = round((floatval($proprem)+floatval($pexp)+floatval($ppvt)+$pllam)*0.1,0); }
		$invno1 = $row['invno1'];		$invno2 = $row['invno2'];		$invno3 = $row['invno3'];
		$rmks = $row['rmks'];	$inst1 = $row['inst1'];		$inst2 = $row['inst2'];		$inst3 = $row['inst3'];
		$bill1 = $row['bill1'];		$bill2 = $row['bill2'];		$bill3 = $row['bill3'];
		$billno1 = $row['billno1'];		$billno2 = $row['billno2'];		$billno3 = $row['billno3'];
		$expdate = substr($row['expdate'],8,2)."-".substr($row['expdate'],5,2)."-".substr($row['expdate'] ,0,4);
		$bam = $row['proam'];	
		if($bam == '0'){ $bam = floatval($proprem) + floatval($pexp) + floatval($ppvt) + $plevy + $psduty + $pllam + floatval($pwtax) - $comm; }
		$iam = $row['amount'];	
		if($iam == '0'){ $iam = floatval($insprem) + floatval($cexp) + floatval($cpvt) + $clevy + $csduty + $pllam + floatval($cwtax); }
	}
	else { echo '<script type="text/javascript"> window.close();</script>';}

?>   
</head><body>
<p class="titletr"> Insurance Billing for Booking No. <?php echo $insno; 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="idate" name="idate" disabled="disabled" value="<?php echo $idate; ?>" size="20"/> </td>
                    </tr>
                    <tr><td align="left"><label for="cname">Dealer Name &nbsp; </label><input type="text" id="cname" name="cname" disabled="disabled" value= "<?php echo $cname; ?>" size="40"/> <input type="hidden" id="insno" name="insno" value= "<?php echo $insno; ?>"/></td>
                    </tr>
					<tr><td align="left"><label for="insurer"> Insurer &nbsp;</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="insurer" disabled="disabled" name="insurer" value="<?php echo $insurer; ?>" size="40"/> </td>
                    </tr>
					<tr><td align="left"><label for="supp"> Provider &nbsp;</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="suppn" name="suppn" disabled="disabled" value= "<?php echo getsupplier($supp); ?>" size="35"/> <input type="hidden" id="supp" name="supp" value="<?php echo $supp; ?>"/> </td>
                    </tr>
					
					<tr><td colspan="2" align="center">
						<table cellspacing="3px"><thead><th style="border: 1px solid #666; ">Customer</th> <th style="border: 1px solid #666; ">Provider</th></thead>
						<td><table cellspacing="3px" style="border: 1px solid #666; ">
						<tr><td align="left"><label for="inam"> Insured Value &nbsp;</label></td> <td><input type="text" id="inam" name="inam" disabled="disabled" value="<?php echo $inam; ?>" size="10" /> </td> <td></td></tr>
						<tr><td align="left"><label for="insrate"> Insurance Rate (%)&nbsp;</label></td> <td><input type="text" id="insrate" name="insrate" disabled="disabled" value="<?php echo $insrate; ?>" size="10"> </td> <td></td></tr>
						<tr><td align="left"><label for="insprem"> Premium Amount &nbsp;</label></td> <td><input type="text" id="insprem" name="insprem" disabled="disabled" value="<?php echo $insprem; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="cpll"> PLL &nbsp;</label></td> <td><input type="text" id="cpllam" name="cpllam" disabled="disabled" value="<?php echo $pllam; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="cpvt"> PVT &nbsp;</label></td> <td><input type="text" id="cpvt" name="cpvt" disabled="disabled" value="<?php echo $cpvt; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="cexp"> Excess Protector &nbsp;</label></td> <td><input type="text" id="cexp" name="cexp" disabled="disabled" value="<?php echo $cexp; ?>" size="10"/> </td> <td></td> </tr>
						
						<tr><td align="left"><label for="inst1"> 1st Installment &nbsp;</label><input type="text" id="instdate1" name="instdate1" value="<?php echo $instdate1; ?>" size="8"/>&nbsp;&nbsp; <input type="text" id="inst1" name="inst1" onchange="showprem()" value="<?php echo $inst1; ?>" size="6"/>&nbsp;&nbsp; <label for="invno1"> Inv. No. &nbsp;</label><input type="text" id="invno1" name="invno1" readonly="readonly" value="<?php echo $invno1; ?>" size="5"/> </td> 
							<td><?php if (intval($invno1) == 0) { echo '<input type="button" onclick="postdoc(1)" style="width:70px;font-weight:bold;" id="post1" name="post1" value="Invoice"/>'; }
									  else { echo '<input type="button" onclick="upddoc(1)" style="width:70px;font-weight:bold;" id="upd1" name="upd1" value="Update"/>'; }	?></td></tr>		 
						<tr><td align="left"><label for="inst2"> 2nd Installment &nbsp;</label><input type="text" id="instdate2" name="instdate2" value="<?php echo $instdate2; ?>" size="8"/>&nbsp;&nbsp; <input type="text" id="inst2" name="inst2" onchange="showprem()" value="<?php echo $inst2; ?>" size="6"/>&nbsp;&nbsp; <label for="invno2"> Inv. No. &nbsp;</label><input type="text" id="invno2" name="invno2" readonly="readonly" value="<?php echo $invno2; ?>" size="5"/> </td> 
							<td><?php if (intval($invno2) == 0) { echo '<input type="button" onclick="postdoc(2)" style="width:70px;font-weight:bold;" id="post2" name="post2" value="Invoice"/>'; } 
									   else { echo '<input type="button" onclick="upddoc(2)" style="width:70px;font-weight:bold;" id="upd2" name="upd2" value="Update"/>'; }?></td></tr>
						<tr><td align="left"><label for="inst3"> 3rd Installment &nbsp;</label><input type="text" id="instdate3" name="instdate3" value="<?php echo $instdate3; ?>" size="8"/>&nbsp;&nbsp; <input type="text" id="inst3" name="inst3" onchange="showprem()" value="<?php echo $inst3; ?>" size="6"/>&nbsp;&nbsp; <label for="invno3"> Inv. No. &nbsp;</label><input type="text" id="invno3" name="invno3" readonly="readonly" value="<?php echo $invno3; ?>" size="5"/> </td> 
							<td><?php if (intval($invno3) == 0) { echo '<input type="button" onclick="postdoc(3)" style="width:70px;font-weight:bold;" id="post3" name="post3" value="Invoice"/>'; } 
									  else { echo '<input type="button" onclick="upddoc(3)" style="width:70px;font-weight:bold;" id="upd3" name="upd3" value="Update"/>'; }?>
									  </td></tr>
						
						</table></td>
						<td><table cellspacing="3px" style="border: 1px solid #666; ">
						<tr><td align="left"><label for="proval"> Provider Value &nbsp;</label></td> <td><input type="text" id="proval" name="proval" disabled="disabled" onchange="recalprem();" value="<?php echo $proval; ?>" size="10" /> </td> <td></td></tr>
						<tr><td align="left"><label for="prorate"> Provider Rate (%)&nbsp;</label></td> <td><input type="text" id="prorate" name="prorate" disabled="disabled" onchange="recalprem();" value="<?php echo $prorate; ?>" size="10"> </td> <td></td></tr>
						<tr>  <td align="left"><label for="proprem"> Provider Premium &nbsp;</label></td> <td><input type="text" id="proprem" name="proprem" disabled="disabled" value="<?php echo $proprem; ?>" size="10"/> </td> <td></td></tr>
						<tr><td align="left"><label for="ppll"> PLL &nbsp;</label></td> <td><input type="text" id="pllam" name="pllam" disabled="disabled" value="<?php echo $pllam; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="ppvt"> PVT &nbsp;</label></td> <td><input type="text" id="ppvt" name="ppvt" disabled="disabled" value="<?php echo $ppvt; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="pexp"> Excess Protector &nbsp;</label></td> <td><input type="text" id="pexp" name="pexp" disabled="disabled" value="<?php echo $pexp; ?>" size="10"/> </td> <td></td> </tr>
						<tr><td align="left"><label for="billno1"> 1 Month Premium &nbsp;</label><input type="text" id="billdate1" name="billdate1" value="<?php echo $billdate1; ?>" size="8"/>&nbsp;&nbsp;<input type="text" id="bill1" name="bill1" onchange="showprem()" value="<?php echo $bill1; ?>" size="6"/>&nbsp;&nbsp; <label for="bill1"> Bill No. &nbsp;</label><input type="text" id="billno1" name="billno1" readonly="readonly" value="<?php echo $billno1; ?>" size="5"/> </td> 
							<td><?php if (intval($bill1) == 0) { echo '<input type="button" onclick="postdoc(4)" style="width:40px;font-weight:bold;" id="pbill1" name="pbill1" value="Bill"/>'; } 
									  else { echo '<input type="button" onclick="upddoc(4)" style="width:70px;font-weight:bold;" id="upd4" name="upd4" value="Update"/>'; }	?></td></tr>		 
						<tr><td align="left"><label for="billno2"> Additional Month &nbsp;</label><input type="text" id="billdate2" name="billdate2" value="<?php echo $billdate2; ?>" size="8"/>&nbsp;&nbsp;<input type="text" id="bill2" name="bill2" onchange="showprem()" value="<?php echo $bill2; ?>" size="6"/>&nbsp;&nbsp; <label for="bill2"> Bill No. &nbsp;</label><input type="text" id="billno2" name="billno2" readonly="readonly" value="<?php echo $billno2; ?>" size="5"/> </td> 
							<td><?php if (intval($bill2) == 0) { echo '<input type="button" onclick="postdoc(5)" style="width:40px;font-weight:bold;" id="pbill2" name="pbill2" value="Bill"/>'; } 
									  else { echo '<input type="button" onclick="upddoc(5)" style="width:70px;font-weight:bold;" id="upd5" name="upd5" value="Update"/>'; } ?></td></tr>
						<tr><td align="left"><label for="billno3"> Balance Premium &nbsp;</label><input type="text" id="billdate3" name="billdate3" value="<?php echo $billdate3; ?>" size="8"/>&nbsp;&nbsp;<input type="text" id="bill3" name="bill3" onchange="showprem()" value="<?php echo $bill3; ?>" size="6"/>&nbsp;&nbsp; <label for="bill3"> Bill No. &nbsp;</label><input type="text" id="billno3" name="billno3" readonly="readonly" value="<?php echo $billno3; ?>" size="5"/> </td> 
							<td><?php if (intval($bill3) == 0) { echo '<input type="button" onclick="postdoc(6)" style="width:40px;font-weight:bold;" id="pbill3" name="pbill3" value="Bill"/>'; } 
									  else { echo '<input type="button" onclick="upddoc(6)" style="width:70px;font-weight:bold;" id="upd6" name="upd6" value="Update"/>'; } ?></td></tr>
						</table></td>
						</table>
					</td></tr>
		
					<tr><td align="left"><label for="iam"> Customer Total Amount &nbsp;</label><input type="text" id="iam" name="iam" value="<?php echo $iam; ?>" size="8"/> <label for="finv"> Inv. No. &nbsp;</label> <input type="text" id="invno" name="invno" readonly="readonly" value="<?php echo $invno; ?>" size="5"/> 
							<?php if (intval($invno) == 0) { echo '<input type="button" onclick="postdoc(7)" style="width:90px;font-weight:bold;" id="cfbill" name="cfbill" value="Full Invoice"/>'; } 
								  else { echo '<input type="button" onclick="upddoc(7)" style="width:70px;font-weight:bold;" id="upd7" name="upd7" value="Update"/>'; } ?></td>
						<td align="left"><label for="bam"> Provider Bill Amount &nbsp;</label> <input type="text" id="bam" name="bam" value="<?php echo $bam; ?>" size="8"/> <label for="fbill"> Bill No. &nbsp;</label><input type="text" id="billno" name="billno" readonly="readonly" value="<?php echo $billno; ?>" size="5"/> 
							<?php if (intval($billno) == 0) { echo '<input type="button" onclick="postdoc(8)" style="width:80px;font-weight:bold;" id="pfbill" name="pfbill" value="Full Bill"/>'; } 
								  else { echo '<input type="button" onclick="upddoc(8)" style="width:70px;font-weight:bold;" id="upd8" name="upd8" value="Update"/>'; } ?></td>
					</tr>
					<tr><td align="left"><label for="clevy"> Levy &nbsp;&nbsp;</label> <input type="text" onchange="showprem();" id="clevy" name="clevy" value="<?php echo $clevy; ?>" size="5"/> &nbsp;&nbsp; <label for="csduty"> Stamp Duty &nbsp;</label> <input type="text" onchange="showprem();" id="csduty" name="csduty" value="<?php echo $csduty; ?>" size="5"/></td> 
						<td> <label for="plevy"> Levy &nbsp;&nbsp;</label> <input type="text" onchange="showprem();" id="plevy" name="plevy" value="<?php echo $plevy; ?>" size="5"/> &nbsp;&nbsp;<label for="psduty"> Stamp Duty &nbsp;</label> <input type="text" onchange="showprem();" id="psduty" name="psduty" value="<?php echo $psduty; ?>" size="5"/> </td></tr>
					<tr><td align="left"><label for="cwtax"> Witholding Tax &nbsp;</label> <input type="text" onchange="showprem();" id="cwtax" name="cwtax" value="<?php echo $cwtax; ?>" size="5"/> </td> 
					    <td><label for="pwtax"> Witholding Tax &nbsp;</label> <input type="text" onchange="showprem();" id="pwtax" name="pwtax" value="<?php echo $pwtax; ?>" size="5"/></td></tr>
						
					<tr><td></td> <td><label for="comm"> Commission &nbsp;</label> <input type="text" onchange="showprem();" id="comm" name="comm" value="<?php echo $comm; ?>" size="5"/> </td></tr>
					
                    <tr><td colspan=2> </td></tr><br />
                    <tr><td colspan=2 align="center">
					
                    </td></tr>
                    </table></center>
        </form>
</body>
</html>

<script type="text/javascript">  
$('#expdate').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});  
$('#instdate1').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"}); 
$('#instdate2').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});
$('#instdate3').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});
$('#billdate1').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});
$('#billdate2').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});
$('#billdate3').datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy"});
																			// computation of premium
function recalprem(){ 
 if(($('#proval').val() !== '') && ($('#prorate').val() !== '')){
	var imm = parseFloat(document.getElementById('proval').value);
	var imn = parseFloat(document.getElementById('prorate').value);
	document.getElementById('proprem').value = imm * imn/100; 
	showprem();
}	
}
																			// computation of provider total
function showprem(){  
var prorate = 0;
var proval = 0;
var proprem = 0;
var insam = 0;
var insrate = 0;
var insprem = 0;
var csduty = 0;
var cwtax = 0;
var clevy = 0;
var psduty = 0;
var pwtax = 0;
var plevy = 0;
var comm = 0;
if ($('#prorate').val() !== ''){ prorate = parseFloat($('#prorate').val()); }
if ($('#proval').val() !== ''){ proval = parseFloat($('#proval').val());	}
if ($('#proprem').val() !== ''){ proprem = parseFloat($('#proprem').val());	}
if ($('#insprem').val() !== ''){ insprem = parseFloat($('#insprem').val());	}
if ($('#csduty').val() !== ''){ csduty = parseFloat($('#csduty').val());	}
if ($('#clevy').val() !== ''){ clevy = parseFloat($('#clevy').val());	}
if ($('#cwtax').val() !== ''){ cwtax = parseFloat($('#cwtax').val());	}
if ($('#psduty').val() !== ''){ psduty = parseFloat($('#psduty').val());	}
if ($('#plevy').val() !== ''){ plevy = parseFloat($('#plevy').val());	}
if ($('#pwtax').val() !== ''){ pwtax = parseFloat($('#pwtax').val());	}
if ($('#comm').val() !== ''){ comm = parseFloat($('#comm').val());	}
if ($('#pllam').val() !== ''){ pllam = parseFloat($('#pllam').val()); }
document.getElementById('bam').value = proprem + plevy + psduty + pwtax + pllam - comm;
inst1 = 0;
inst2 = 0;
inst3 = 0;
if ($('#inst1').val() !== ''){ inst1 = parseFloat($('#inst1').val()); } 
if ($('#inst2').val() !== ''){ inst2 = parseFloat($('#inst2').val()); } 
if ($('#inst3').val() !== ''){ inst3 = parseFloat($('#inst3').val()); } 
document.getElementById('iam').value = insprem + clevy + csduty + pllam + cwtax; 
//if((inst1 + inst2 + inst3) > 0){ document.getElementById('iam').value = inst1 + inst2 + inst3 + clevy + csduty + cwtax; }
//else { document.getElementById('iam').value = insprem + clevy + csduty + cwtax; }
};
																			// posting of invoices/bills
function postdoc(n){  
if(n===1){ if(($('#instdate1').val() !== '0000-00-00') && ($('#inst1').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=1&u=0&doc=0&iam="+$('#inst1').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate1').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno1').value = data.trim();
														$('#post1').hide();
														window.open("invinsprint.php?i="+$('#invno1').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });	
					}
			}
else if(n===2){ if(($('#instdate2').val() !== '0000-00-00') && ($('#inst2').val() !== '')){ 
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=2&u=0&doc=0&iam="+$('#inst2').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate2').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno2').value = data.trim();
														$('#post2').hide();
														window.open("invinsprint.php?i="+$('#invno2').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });
					}
				}
else if(n===3){ if(($('#instdate3').val() !== '0000-00-00') && ($('#inst3').val() !== '')){ 
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=3&u=0&doc=0&iam="+$('#inst3').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate3').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno3').value = data.trim();
														$('#post3').hide();
														window.open("invinsprint.php?i="+$('#invno3').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });
					}									
			}			
else if(n===4){ if(($('#billdate1').val() !== '0000-00-00') && ($('#bill1').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=1&u=0&doc=0&iam="+$('#bill1').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate1').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno1').value = data.trim();
														$('#pbill1').hide();
														} });
					}									
			}	
else if(n===5){ if(($('#billdate2').val() !== '0000-00-00') && ($('#bill2').val() !== '')){ 
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=2&u=0&doc=0&iam="+$('#bill2').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate2').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno2').value = data.trim();
														$('#pbill2').hide();
														} });
					}									
			}	
else if(n===6){ if(($('#billdate3').val() !== '0000-00-00') && ($('#bill3').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=3&u=0&doc=0&iam="+$('#bill3').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate3').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno3').value = data.trim();
														$('#pbill3').hide();
														} });
					}									
			}	
else if(n===7){ if(($('#idate').val() !== '0000-00-00') && ($('#iam').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=7&u=0&doc=0&iam="+$('#iam').val()+"&cname="+$('#cname').val()+"&idate="+$('#idate').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno').value = data.trim();
														$('#cfbill').hide();
														} });
					}									
			}	
else if(n===8){ if(($('#idate').val() !== '0000-00-00') && ($('#bam').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=8&u=0&doc=0&iam="+$('#bam').val()+"&cname="+$('#cname').val()+"&idate="+$('#idate').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno').value = data.trim();
														$('#pfbill').hide();
														} });
					}									
			}			
};

function upddoc(n){  
if(n===1){ if(($('#instdate1').val() !== '0000-00-00') && ($('#inst1').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=1&u=1&doc="+$('#invno1').val()+"&iam="+$('#inst1').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate1').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno1').value = data.trim();
														window.open("invinsprint.php?i="+$('#invno1').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });
			}							
		}
else if(n===2){ if(($('#instdate2').val() !== '0000-00-00') && ($('#inst2').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=2&u=1&doc="+$('#invno2').val()+"&iam="+$('#inst2').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate2').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno2').value = data.trim();
														window.open("invinsprint.php?i="+$('#invno2').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });
					}															
			}
else if(n===3){ if(($('#instdate3').val() !== '0000-00-00') && ($('#inst3').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=3&u=1&doc="+$('#invno3').val()+"&iam="+$('#inst3').val()+"&cname="+$('#cname').val()+"&idate="+$('#instdate3').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno3').value = data.trim();
														window.open("invinsprint.php?i="+$('#invno3').val(),"Invoice","width=900px,height=800px;scrollbar=1");
														} });
					}	
			}		
else if(n===4){ if(($('#billdate1').val() !== '0000-00-00') && ($('#bill1').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=1&u=1&doc="+$('#billno1').val()+"&iam="+$('#bill1').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate1').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno1').value = data.trim();
														} });
					}									
			}			
else if(n===5){ if(($('#billdate2').val() !== '0000-00-00') && ($('#bill2').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=1&u=1&doc="+$('#billno2').val()+"&iam="+$('#bill2').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate2').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno2').value = data.trim();
														} });
					}
			}
else if(n===6){ if(($('#billdate3').val() !== '0000-00-00') && ($('#bill3').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=1&u=1&doc="+$('#billno3').val()+"&iam="+$('#bill3').val()+"&cname="+$('#cname').val()+"&idate="+$('#billdate3').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno3').value = data.trim();
														} });
					}									
			}
else if(n===7){ if(($('#idate').val() !== '0000-00-00') && ($('#iam').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=i&i=7&u=1&doc="+$('#invno').val()+"&iam="+$('#iam').val()+"&cname="+$('#cname').val()+"&idate="+$('#idate').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('invno').value = data.trim();
														} });
					}									
			}		
else if(n===8){ if(($('#idate').val() !== '0000-00-00') && ($('#bam').val() !== '')){
					var savjcdet = $.post("savinsdoc.php?insno="+$('#insno').val()+"&supp="+$('#supp').val()+"&ib=b&i=8&u=1&doc="+$('#billno').val()+"&iam="+$('#bam').val()+"&cname="+$('#cname').val()+"&idate="+$('#idate').val(), function(data){
                                if(data.trim()!=="0") { document.getElementById('billno').value = data.trim();
														} });
					}									
			}				
};
</script>



