<?php
	//Start session
	session_start();
	
	//Check whether the session variable SESS_MEMBER_ID is present or not
	if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
		header("location: index.html");
		exit();
	}
	
?>
<html>
<head>
<title>Insert</title>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1"/>
<script type="text/javascript" src="../javascript/jquery.js"></script>
<script type="text/javascript" src="../javascript/vch_entry_rel.js"></script>
<script type="text/javascript" src="../javascript/jquery.autocomplete.js"></script>
<script type="text/javascript" src="../javascript/jquery.form.js"></script>
<script type="text/javascript" src="../javascript/jquery.datepick.min.js"></script>
<script type="text/javascript" src="../javascript/jNotify.jquery.js"></script>
<script type="text/javascript" src="../javascript/common_rel.js"></script>
<script type="text/javascript" src="../javascript/picnet.table.filter.min.js"></script>
<script type="text/javascript" src="../javascript/jquery.php_excel.js"></script>
<script type="text/javascript" src="../tablesorter/js/jquery.tablesorter.js"></script>

<!-- tablesorter widgets (optional) -->
<script type="text/javascript" src="../tablesorter/js/jquery.tablesorter.widgets.js"></script>
<script type="text/javascript" src="../tablesorter/js/widgets/widget-scroller.js"></script>


<!-- choose a theme file -->
<link rel="stylesheet" href="../tablesorter/css/theme.default.css">
<link rel="stylesheet" href="../css/jNotify.jquery.css" type="text/css" />
<link rel="stylesheet" href="../css/redmond.datepick.css">
<link rel="stylesheet" href="../css/jquery.autocomplete.css" type="text/css" ></link>
<link rel="stylesheet" href="../css/stylereport.css"  type="text/css"></link>


<script type="text/javascript">
function myFunction()
{
jSuccess("Module not available in demo version");
}
</script>

<style type="text/css">
.dataTableContainer table tbody td input[type=text]{
height: 30px;	
}
.right-panel {
    background-repeat: no-repeat !important;
     width: auto !important; 
     float: left !important; 
	 padding: 0px 3px !important;
}
</style>
</head>

<body  id="dvr_adv">
<input  id="inline_edit" type="hidden" value="0"  />
<div id="transperent" style=" z-index:5" >
</div>
      <?php 
  include '../db_connect.php';
$vchno= $_GET['vchno'];
$vchtype = $_GET['mode'];
if(isset($vchtype)&&!empty($vchtype))
{
	if($vchtype=='PURCHASE' || $vchtype=='SALES') 
	$vchtable = "purcreg";	
	else
	$vchtable = "vchreg";
}

if(isset($vchno)&&!empty($vchno))
if($result = mysqli_query($con,"SELECT * FROM $vchtable where vchno='$vchno'"))
{
$row = mysqli_fetch_array($result);

foreach(array_keys($row) as $key)
{
  $row[$key] = mysqli_real_escape_string($con,$row[$key]);
}
}



function time_formatc($temp_time)
{
list($hour, $min, $sec) = explode(':', $temp_time);

return "$hour:$min";
}


function date_formatc($temp_date)
{
list($year, $month, $day) = explode('-', $temp_date);
return "$day/$month/$year";
}

?>
      
      
<div class="main">
  <div class="page">
 
    <div class="right-panel">
    <div id="formbox">
    <form id="vchreg_det">
		<table width="100%">
  <tr>
    <td colspan="2" align="left"><select name="vchtype" id="vchtype" >
        <option value="RECEIPT" >RECEIPT</option>
                 <option value="PAYMENT">PAYMENT</option>
                    <option value="SALES">SALES</option>
                    <option value="PURCHASE">PURCHASE</option>
                     <option value="JOURNAL">JOURNAL</option>
                      <option value="CONTRA">CONTRA</option>
                      <option value="CREDITNOTE">CREDITNOTE</option>
        </select>
      <input name="vchsource" id="vchsource" type="hidden" readonly placeholder="autofill" /></td>
    <td colspan="2" align="left"><input name="vchno" id="vchno" type="text" readonly  /></td>
    <td width="13%" align="left">&nbsp;</td>
    <td width="4%" align="right">&nbsp;</td>
    <td width="11%" align="right">Date:</td>
    <td colspan="3" align="right"><input name="vchdate" id="vchdate" type="text" value="<?php echo date('d/m/Y')?>" /></td>
    </tr>
  <tr>
    <td colspan="2" align="left">RefNo:</td>
    <td colspan="2" align="left"><input name="refno" id="refno" type="text" /></td>
     <?php if($_GET[mode]=='JOURNAL' || $_GET[mode]=='CONTRA') {?>
     <td>From: </td>
     <?php } else{ ?>
     <td>Company: </td>
     <?php } ?>
    <td colspan="5" align="left"><input name="comcode" id="comcode" type="text" style="width:100%" /></td>
    </tr>
     <tr>
     
    <td colspan="2" align="left" >INST/INVNO:</td>
    <td colspan="2" align="left" ><input name="bill_no" id="bill_no" type="text" /></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
  </tr>
<td colspan="2" align="left" >INV DATE:</td>
    <td colspan="2" align="left" ><input name="invdate" id="invdate" type="text"  /></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
  </tr>
    <?php if($_GET[mode]=='PURCHASE' || $_GET[mode]=='SALES') {?>
  
  <tr>
    <td colspan="2" align="left" >&nbsp;</td>
    <td colspan="2" align="left" >&nbsp;</td>
    <td colspan="3" align="right">Basic Amount:</td>
    <td align="left">&nbsp;</td>
    <td colspan="2"><!--<div style="float:right"><input name="vsurchg" id="vsurchg"  class="ser_tax" style="width:88px" type="text" /></div>--><div style="float:right"><input name="basic_amt" id="basic_amt" class="basic_amt" type="text" /></div></td>
    </tr>
    <tr style="display:none">
    <td colspan="2" align="left" >&nbsp;</td>
    <td colspan="2" align="left" >&nbsp;</td>
    <td  colspan="3" align="right">Toll Parking:</td>
    <td  align="left">&nbsp;</td>
    <td colspan="2"><!--<div style="float:right"><input name="vsurchg" id="vsurchg"  class="ser_tax" style="width:88px" type="text" /></div>--><div style="float:right"><input name="toll_park" id="toll_park" class="toll_park" type="text" /></div></td>
    </tr>
  
  <tr>
    <td colspan="2" align="left" >&nbsp;</td>
    <td align="left" ><input name="chargeable" type="checkbox" id="chargeable" value="1" <?php  echo "checked='checked'";?>  /></td>
    <td align="left" >Chargeable</td>
    <td align="left">&nbsp;</td>
    <td colspan="2" align="right">Service Tax:</td>
    <td><input name="ser_per" id="ser_per" size="5" type="text" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> /></td>
    <td colspan="2"><div style="float:right"><input name="ser_tax" id="ser_tax"  class="ser_tax" type="text" /></div></td>
    </tr>
    <tr>
      <td colspan="2" align="left" >&nbsp;</td>
      <td align="left" ><input name="taxontoll" type="checkbox" id="taxontoll" checked value="1" style="display:none"  /></td>
      <td align="left" ></td>
      <td colspan="3" align="right">S.B.Cess:</td>
      <td align="left"><input name="sbc" id="sbc"  class="sbc" size="5" type="text" /></td>
      <td colspan="2"><span style="float:right">
        <input name="vhecess" id="vhecess"  class="ser_tax" style="width:100%" type="text" />
      </span></td>
    </tr>
    <tr>
    <td colspan="2" align="left" >&nbsp;</td>
    <td colspan="2" align="left" >&nbsp;</td>
    <td colspan="3" align="right">K.K.Cess:</td>
    <td align="left"><input name="kkc" id="kkc"  class="sbc" size="5" type="text" /></td>
    <td colspan="2"><span style="float:right">
      <input name="vsurchg" id="vsurchg"  class="ser_tax" style="width:100%" type="text" />
    </span><!--<div style="float:right"><input name="vsurchg" id="vsurchg"  class="ser_tax" style="width:88px" type="text" /></div>--><div style="float:right"></div></td>
    </tr>
    
     <tr>
    <td colspan="2" align="left" >&nbsp;</td>
    <td align="left" >&nbsp;</td>
    <td align="left" >&nbsp;</td>
    <td colspan="3" align="right">Mis amount:</td>
    <td align="left"></td>
    <td colspan="2"><!--<div style="float:right"><input name="vsurchg" id="vsurchg"  class="ser_tax" style="width:88px" type="text" /></div>--><div style="float:right"><input name="misamt" id="misamt" class="amount" type="text" /></div></td>
    </tr>
    
 
  <?php } ?>

 
  <tr>
    <?php if($_GET[mode]=='JOURNAL' || $_GET[mode]=='CONTRA') {?>
     <td colspan="2" align="left" ><div >To:</div></td>
     <?php } else{ ?>
     <td colspan="2" align="left" ><div >Account:</div></td>
     <?php } ?>
    
    <td colspan="2" align="left" ><input name="account" id="account" type="text" /></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td>Amount:</td>
    <td colspan="3" ><div style="float:right"><input name="amount" id="amount" class="amount" type="text" /></div></td>
  </tr>
  <tr>
    <td colspan="2" align="left" class="srcbookings">Bank Name</td>
    <td colspan="3" align="left"><input class="srcbookings" name="bankname" id="bankname" type="text"  /></td>
    <td>&nbsp;</td>
    <td class="srcbookings"><span <?php if($_GET[mode]=='CONTRA'){ echo "style='display:none'";}?>><?php if($_GET[mode]=='JOURNAL'||$_GET[mode]=='CREDITNOTE') echo "Tax:"; else echo"Deduction:";?></span></td>
    <td colspan="3"><div style="float:right" class="srcbookings"><input <?php if($_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> name="sortpayment" id="sortpayment" type="text" /></div></td>
  </tr>
  <tr>
    <td colspan="2" align="left">Details</td>
    <td colspan="3" valign="top"><textarea name="details" id="details" style="width:100%; height:100%"></textarea></td>
    <td>&nbsp;</td>
    <td class="srcbookings" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?>>Sub Total:</td>
    <td >&nbsp;</td>
    <td colspan="2" class="srcbookings" ><div style="float:right" class="srcbookings"><input name="subtotal" id="subtotal" type="text" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> /></div></td>
  </tr>
  <tr>
    <td colspan="2" align="left">Agnst Ref</td>
    <td colspan="3" valign="middle"><span style="float:left">
      <input name="agnstref" id="agnstref" type="text" />
    </span>
      <span style="float:left;width:10%;"><input class="" id="vchledadd" type="button" value="+" style="width:100%" /></span></td>
    <td>&nbsp;</td>
    <td class="srcbookings" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?>>TDS:</td>
    <td width="3%" ><input name="tds" id="tds" size="5" type="text" class="srcbookings" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> /></td>
    <td colspan="2" ><div style="float:right" class="srcbookings"><input name="tdsamt" id="tdsamt" type="text" <?php if($_GET[mode]=='PAYMENT'||$_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> /></div></td>
  </tr>
  <tr>
    <td colspan="2" align="left">Narration:</td>
    <td colspan="3" valign="top"><textarea name="narration" id="narration" style="width:100%; height:100%"></textarea></td>
    <td colspan="2" <?php if($_GET[mode]=='CONTRA'){ echo "style='display:none'";}?>>Net Amount:</td>
    <td>&nbsp;</td>
    <td colspan="2" ><div style="float:right"><input name="totamount" id="totamount" type="text" <?php if($_GET[mode]=='CONTRA'){ echo "style='display:none'";}?> /></div></td>
  </tr>
  <tr>
    <td width="6%" align="left"><input name="CmpLogo" type="checkbox" id="CmpLogo" value="1" <?php if(isset($_SESSION['SESS_SHOWLOGO'])&&$_SESSION['SESS_SHOWLOGO']=='on') echo "checked='checked'";?>  />Logo      </td>
    <td width="10%" align="left"><input name="PrePrint" type="checkbox" id="PrePrint" value="" <?php if(isset($_SESSION['SESS_PREPRINT'])&&$_SESSION['SESS_PREPRINT']=='on') echo "checked='checked'";?>  />
Pre Print</td>
    <td colspan="3" valign="top">&nbsp;</td>
    <td colspan="7"><?php if($_GET[mode]=='PAYMENT'){ ?>
    <input name="chequep" type="button" class="button" id="chequep" value="Cheq Print" />
    <?php }?>
    <input name="new" type="button" class="button" id="new" value="NEW" />
      <input  type="button" name="save" id="vchsave" class="button"   value="SAVE"  />
      <input name="update" type="button" class="button" id="update"  value="UPDATE" style="display:none" />
      <input name="close" type="button" class="button" id="close"  value="CLOSE" />
      <input name="print" type="button" class="button" id="print"  value="PRINT" /></td>
  </tr>
  </table>
</form>
<form action="vchent_export_excel.php" method ="post" > 
<input type="hidden" name="csv_text" id="csv_text">
<input type="submit" value="Excel" id="ex_excel" class="ex_excel"  title="Export as Excel" onClick="getCSVData()" style="padding: 1px 6px;font-weight: bold;" />
</form>
 </div>
 <?php if($_GET[mode]=='PURCHASE'||$_GET[mode]=='CREDITNOTE'||$_GET[mode]=='SALES') 
 echo "<b>Book Details:</b>";
 else
 if($_GET[mode]=='JOURNAL') 
 echo "<b>Details:</b>";
 else
 if($_GET[mode]=='CONTRA') 
 echo " ";
 else	
 echo "<b>Bill Details:</b>";?>
 
<br/>

<table width="100%">
<tr>
  <td width="65%" rowspan="3" valign="top"><div id="vchdetails"  class="dataTableContainer vchdetails" style="height:400px; overflow-y:auto" ></div>
  <div id="vchdetails1"  class="dataTableContainer1" >

</div></td>
  <td><div id="chkamount" style="font-weight: bold;"></div></td>
</tr>
<tr>
  <td><div id="pedbilldetsearch" style="font-weight: bold;text-align: center;
color: rgb(131, 12, 12);display:none">Pending Details<input type="hidden" id="quickfind" size="5" /></div></td>
</tr>
<tr>
  <td valign="top"><div id="pedbilldet" style="font-weight: bold;height:250px; overflow-y:auto;text-align: center;
color: rgb(131, 12, 12);"></div></td>
</tr>
</table>
      
      <div id="message" style="text-align: center;font-weight: bold;color: #0064D1;" > </div>
    </div>
   
  </div>
</div>
<script type="text/javascript">
	<?php if(isset($_GET['vchno']))
	{?>
$('#vchtype').val('<?php echo $_GET['mode']?>');
$('#vchno').val('<?php echo $row[vchno]?>');
$('#vchdate').val('<?php echo date_formatc($row['vchdate'])?>');
$('#refno').val('<?php echo $row[refno]?>');
$('#account').val('<?php echo $row[account]?>');
$('#comcode').val('<?php echo $row[comcode]?>');
$('#narration').val('<?php echo $row[narration]?>');
$('#bankname').val('<?php echo $row[bankname]?>');
$('#details').val('<?php echo $row[details]?>');
$('#amount').val('<?php echo $row[dramount]; ?>');
$('#tdsamt').val('<?php echo $row[tdsamt]?>');
$('#chargeable').val('<?php echo $row[chargeable]?>');
$('#sortpayment').val('<?php echo $row[sortpayment]?>');
$('#tds').val('<?php echo $row[cramount]?>');
$('#totamount').val('<?php echo $row[totamount]?>');
$('#agnstref').val('<?php echo $row[agnstref]?>');
$('#basic_amt').val('<?php echo $row[basic_amt]?>');
$('#toll_park').val('<?php echo $row[toll_park]?>');
$('#ser_tax').val('<?php echo $row[ser_tax]?>');
$('#bill_no').val('<?php echo $row[bill_no]?>');
$('#vsurchg').val('<?php echo $row[seducess]?>');
$('#vhecess').val('<?php echo $row[educess]?>');
$('#ser_per').val('<?php echo $row[ser_per]?>');
$('#misamt').val('<?php echo $row[misamt]?>');
$('#invdate').val('<?php echo date_formatc($row['invdate'])?>');
$('#subtotal').val('<?php echo $row[subtotal]?>');
$('#vchsource').val('<?php echo $row[vchsource]?>');
$('#sbc').val(0.20);
$('#kkc').val(0.20);



	<?php } else{ 
	if($_GET['mode']=='PURCHASE' || $_GET['mode']=='SALES'){
		$stqry = mysqli_query($con,"SELECT `code` FROM master where `mstype`='STP' AND `desc` = 'ST RATE'");
		$strow = mysqli_fetch_assoc($stqry); ?>
	
		$('#ser_per').val('<?php echo $strow['code']?>');
		<?php 
		$stqry1 = mysqli_query($con,"SELECT `code` FROM master where `mstype`='STP' AND `desc` = 'SEC RATE'");
		$strow1 = mysqli_fetch_assoc($stqry1);
		
		$stqrykkc = mysqli_query($con,"SELECT `code` FROM master where `mstype`='STP' AND `desc` = 'KKC RATE'");
		$strowkkc = mysqli_fetch_assoc($stqrykkc); 
	
		
		
		 ?>
	
		$('#sbc').val('<?php echo $strow1['code']?>');
		$('#kkc').val('<?php echo $strowkkc['code']?>');
		
	<?php }	}
	
	?>
	
	

  function findValue(li) {
  	if( li == null ) return jSuccess("No match!");

  	// if coming from an AJAX call, let's use the CityId as the value
  	if( !!li.data ) var sValue = li.data[0];

  	// otherwise, let's just display the value in the text box
  	else var sValue = li.selectValue;
  }

  function selectItem(li) {
    	findValue(li);
  }

  function formatItem(row) {
    	return row[0];
  }
  
  $("#agnstref").autocomplete(
      "vehicleregno.php?mode=ccenter",
      {
  			delay:10,
  			minChars:0,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:function(row){
				vehnoblur(row.value);
				},
  			autoFill:false
  		}
    );
  
  if('<?php echo $_GET[mode]?>'=='CREDITNOTE'||'<?php echo $_GET[mode]?>'=='SALES')
  {
      
	  $("#comcode").autocomplete(
      "billedto.php?",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			mustMatch:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
            showResult:function(row,data) {
    	return row+"|"+data[0];

  },
  			autoFill:false
  		}
    );
	
	
	
	
  }
  

  else if('<?php echo $_GET[mode]?>'=='CONTRA')
	{
	$("#comcode").autocomplete(
      "account_fill.php?type=cashbank",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
  			autoFill:false
  		}
    );
	  }
	else if('<?php echo $_GET[mode]?>'=='PURCHASE'||'<?php echo $_GET[mode]?>'=='PAYMENT')
	{
	      $("#comcode").autocomplete(
      "billedto.php?mode=PA",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			mustMatch:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
            showResult:function(row,data) {
    	return row+"|"+data[0];

  },
  			autoFill:false
  		}
    );
	}
	else if('<?php echo $_GET[mode]?>'=='RECEIPT')
	{
	      $("#comcode").autocomplete(
      "billedto.php?mode=RE",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			mustMatch:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
            showResult:function(row,data) {
    	return row+"|"+data[0];

  },
  			autoFill:false
  		}
    );
	}
	else if('<?php echo $_GET[mode]?>'=='JOURNAL')
	{
	      $("#comcode").autocomplete(
      "billedto.php?mode=jv",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			mustMatch:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
             showResult:function(row,data) {
    	return row+"|"+data[0];

  },
  			autoFill:false
  		}
    );
	}
	
	 
	 if('<?php echo $_GET[mode]?>'=='PURCHASE')
  {
	
	      $("#account").autocomplete(
      "account_fill.php?type=puracc",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
           showResult:function(row,data) {
    	return row+"|"+data[0];

  },
  			autoFill:false
  		}
    );
  }
  else
   if('<?php echo $_GET[mode]?>'=='CREDITNOTE'||'<?php echo $_GET[mode]?>'=='SALES')
  {
	  $("#account").autocomplete(
      "account_fill.php?type=credacc",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
			
  			autoFill:false
  		}
    );
  }
  else
  if('<?php echo $_GET[mode]?>'=='JOURNAL')
  {
	
	  $("#account").autocomplete(
      "billedto.php?mode=jv",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:selectItem,
  			onFindValue:findValue,
  			formatItem:formatItem,
  			autoFill:false
  		}
    );
  }
  else
  {
	  $("#account").autocomplete(
      "account_fill.php?type=cashbank",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:function(row){
				//if (row.value=='CASH')
//				{
//					$("#refno").val('1');
//					}
//					else
//					{$("#refno").val(row.data[0]);
//					}
			},
  			onFindValue:findValue,
  			formatItem:formatItem,
  			autoFill:false
  		}
    );
	  }



		
	$('#comcode').blur(function(){	
	    $(".ptype").autocomplete({
		minChars:0,
		mustMatch:1,
        data: [
            ['Agnst Ref', 1],
            ['Advance', 2],
            ['New Ref', 3],
            ['TDS', 4],
            ['On Account', 5],
        ],
		onItemSelect:function(data){
		if(data.value=='Advance')
		{	
			 var row= $("*:focus").closest('tr');
			 var subtotal=0;
			 $( ".amt" ).each(function() {
		 		subtotal+=Number($(this).val());
	 		});
			var temp = (Number($('#amount').val())-Number(subtotal)).toFixed(2);
			row.find('.bno').val($('#vchno').val());
			row.find('.amt').val(temp);
			
			}
			else if(data.value=='Agnst Ref')
		{
			//if($('#vchsource').val()=='BOOKINGS')
			//{
			
				
			 var row= $("*:focus").closest('tr');
			 var subtotal=0;
			 $( ".amt" ).each(function() {
		 		subtotal+=Number($(this).val());
	 		});
			var temp = (Number($('#amount').val())-Number(subtotal)).toFixed(2);
			row.find('.bno').val($('#bill_no').val());
			row.find('.amt').val(temp);
		
				
				//}
		}
			
		}
		
    });
	  $(".angst_d").autocomplete(

      "misc_fill.php?",

      {

  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			onItemSelect:selectItem,               
  			onFindValue:findValue,
  			formatItem:formatItem,
  			autoFill:false

  		});
	
	 function findValue_bno(li) {
  	if( li == null ) return jSuccess("No match!");

  	// if coming from an AJAX call, let's use the CityId as the value
  	if( !!li.data ) var sValue = li.data[0];

  	// otherwise, let's just display the value in the text box
  	else var sValue = li.selectValue;
	var subtotal=0;
	
	 var row= $("*:focus").closest('tr');
	 row.find('.temp').val(sValue);
	 $('.amt').removeAttr('disabled');
	 $( ".amt" ).each(function() {
		// $(this).removeAttr('disabled');
		 subtotal+=Number($(this).val());
	 });
	 
	// $('.amt').attr('disabled','disabled');
	// row.find('.amt').removeAttr('disabled').css({'cursor':'auto'}).focus();
	// if('<?php //echo $_GET[mode]?>'=='RECEIPT')
	// {
	// 	var value=Number($('#amount').val()+$('#sortpayment').val()+$('#tdsamt').val())-Number(subtotal);
	// }
	// else
	// {
		var value=Number($('#amount').val())-Number(subtotal); 
		 
	// }
	 if(Number(sValue)>Number(value))
	 row.find('.amt').val(Number(value).toFixed(2));
	 else
	row.find('.amt').val(sValue);
  }
  
  	 function findValue_crbno(li) {
  	if( li == null ) return jSuccess("No match!");

  	// if coming from an AJAX call, let's use the CityId as the value
  	if( !!li.data ) var sValue = li.data[0];

  	// otherwise, let's just display the value in the text box
  	else var sValue = li.selectValue;
	var crsubtotal = 0;
	 var row= $("*:focus").closest('tr');
	 row.find('.temp').val(sValue);
	 $('.cramt').removeAttr('disabled');
	$( ".cramt" ).each(function() {
		// $(this).removeAttr('disabled');
		 crsubtotal+=Number($(this).val());
	 });
	var crvalue=Number($('#totamount').val())-Number(crsubtotal);
	 var row= $("*:focus").closest('tr');
	if(Number(sValue)>Number(crvalue))
	 row.find('.cramt').val(Number(crvalue).toFixed(2));
	 else
	row.find('.cramt').val(sValue);

  }
  
  
  function selectItem_bno(li) {
    	findValue_bno(li);
  }
  function selectItem_crbno(li) {
    	findValue_crbno(li);
  }
  

	
	 if('<?php echo $_GET[mode]?>'=='RECEIPT' || '<?php echo $_GET[mode]?>'=='JOURNAL' )
  {
	  $(".spl_autofill").remove();
	
	
	if( '<?php echo $_GET[mode]?>'=='JOURNAL')
	{
		$(".spl_autofill_jor").remove();
		 $(".crbno").autocomplete(
      "vchrefno_fill.php?comcode="+$('#account').val()+'&',
      {
		  resultsClass :'spl_autofill_jor',
  			delay:10,
  			minChars:0,
  			matchSubset:1,
  			mustMatch:0,
  			cacheLength:10,
  			onItemSelect:selectItem_crbno,
  			onFindValue:findValue_crbno,
			showResult:function(row,data){
				return row+"|"+data[0];
				},
  			autoFill:false
  		}
    );	
	}
  }
  else if('<?php echo $_GET[mode]?>'=='CREDITNOTE')
  {
	  $(".spl_autofill").remove();
	 $(".bno").autocomplete(
      "vchbno_fill.php?comcode="+$('#comcode').val()+'&',
      {
		  resultsClass :'spl_autofill',
  			delay:10,
  			minChars:0,
  			matchSubset:1,
  			mustMatch:0,
  			cacheLength:10,
  			onItemSelect:selectItem_bno,
  			onFindValue:findValue_bno,
  			showResult:function(row,data){
				return row+"|"+data[0];
				},
  			autoFill:false
  		}
    );
  }
  	else if('<?php echo $_GET[mode]?>'=='PURCHASE')
	{
		$(".spl_autofill").remove();
		 $(".bno").autocomplete(
      "vchbookid_fill.php?comcode="+$('#comcode').val()+'&',
      {
		  resultsClass :'spl_autofill',
  			delay:10,
  			minChars:0,
  			matchSubset:1,
  			mustMatch:0,
  			cacheLength:10,
  			onItemSelect:selectItem_bno,
  			onFindValue:findValue_bno,
			showResult:function(row,data){
				return row+"|"+data[0]+"|"+data[1]+"|"+data[2]+"|"+data[3]+"|"+data[4];
				},
  			autoFill:false
  		}
    );	
	}	
	else if('<?php echo $_GET[mode]?>'=='PAYMENT' )
	{
		$(".spl_autofill").remove();
		 $(".bno").autocomplete(
      "vchrefno_fill.php?comcode="+$('#comcode').val()+'&',
      {
		  resultsClass :'spl_autofill',
  			delay:10,
  			minChars:0,
  			matchSubset:1,
  			mustMatch:0,
  			cacheLength:10,
  			onItemSelect:selectItem_bno,
  			onFindValue:findValue_bno,
			showResult:function(row,data){
				return row+"|"+data[0];
				},
  			autoFill:false
  		}
    );	
	}	
	});
	
		

  $(window).load(function() {
	    $('#transperent').hide();
		if($('#vchsource').val()=='BOOKINGS')
		{
			$('.srcbookings').hide();	
		}
		
		
		
if($('#vchno').val()!='')
{
	$('#update').show();
	$('#save').hide();
	$('#new').hide();
	
	}
	$('#vchtype').val('<?php echo $_GET[mode]?>');
	$('#vchno').trigger('blur');
  });
  
  function  updatePendingBills(comCode)
  {
	 
  vchamount_chk($('#vchtype').val(),$('.amt:first'))
    $('#transperent').show();
  $.post('get_pendingbill.php?comcode='+comCode,  {}, function (result) {
				$('#pedbilldet').html(result);
				
				
			$('#pedbilldetsearch').show()
			 var options1 = {
				// additionalFilterTriggers: [$('#quickfind')],

			  enableCookies: false
	          };
	   $('#pedbilldet table').tableFilter(options1);
			
			  $('#pedbilldet table').tableFilterApplyFilterValues();
			  
               
                 
			
				
 $('#transperent').hide();
			});
			
  }
  
  $(window).load(function() {
	changeLinkSize();

    $('#transperent').hide();
  });

 $(window).resize(function() {
	changeLinkSize();
});
  
  function changeLinkSize()
  {
	  	var url = window.location.pathname;
		var str = url.split('/');
		var buttonfont=($('.left-panel').width());
		var buttonwidth=($('.left-panel').width());
		var buttonheight=($('.left-panel').width());
	  $('.button').css({'font-size':buttonfont,"width":buttonwidth,"height":buttonheight});
	  $('.left-content ul  a,.left-content ul  h3').css({'font-size':$('.left-panel').width()});
	  $('.left-content ul li span').css({'font-size':$('.left-panel').width()});
	  $('.left-content ul li a').css({'font-size':$('.left-panel').width()});
	  $(".left-content ul li a[href='"+str[2]+"']").css({'color':'#ffffff','font-size':$('.left-panel').width()});
	  
	  }
</script>

</body>
</html>