<?php 
date_default_timezone_set('Asia/Calcutta');
include('./includes/Class_Branch.php');
include('./includes/AccountGroupMaster_Class.php');
//$lcrdata=array('8','10','11','12','14','15');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$VPrefix=$_REQUEST['VPrefix'];
$debit_side=array('6','4','8','11','12','14','15');
$lcrdata=array('5','3','11','8','13','12','15');

if($_REQUEST['id']!='')
{
 $sql=DB_query("select * from account_book where id='".$_REQUEST['id']."'",$db);
 $row1=DB_fetch_array($sql);
 extract($row1);
$currency_sec=$s->getField('account_book_details','account_bookid',$_REQUEST['id'],'conv_currency');

}
?>
<input type="hidden" id="Voucherprefixtype" name="Vprefixtype" id="Vprefixtype" value="<?php echo $VPrefix; ?>" />
<?php 
$conv_check=$s->getField('account_multi_currency','CompanyId',$_SESSION['ACGCompanyId'],'multicurrency');
echo '<input type="hidden" id="conv_check" value="'.$conv_check.'">';
$ChkVoucher_Numtype=($s->getField('voucher_master','VoucherType',$VPrefix,'voucher_num')==1?'Auto':'Manual');
$BillBookType=$s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'VPrefix');
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
if($_REQUEST['Debit_note'] =='Update')
$rurl="&modid=".$modid."&frmid=".$frmid."&action=".$action."&id=".$_REQUEST['id'].'&VPrefix='.$VPrefix;
else
$rurl="&modid=".$modid."&frmid=".$frmid."&VPrefix=".$VPrefix;
$targetpage="index.php?route=Account/ACBillbookPayment".$rurl;
$msgErr=array();;
if($_REQUEST['action'] )
 $rurl.="&action=".$_REQUEST['action'];
 //echo $BillBookType;
	 switch($BillBookType)
	 {
	   	case 'CP':
	             $LDR="not in('cash','bank','P&L','tds')";
	            // array('ASSET','INCOME','EXPENSE','LIABILITIES');
				 $LCR="in('cash','tds')";
				 $CRbillstatus=1;
				 $DRbillstatus=0;
				
				 break;
		case 'CR':
			     $CRbillstatus=0;
				 $DRbillstatus=1;
	             $LDR="in('cash','tds')";
	             //array('cash');
				  $LCR="not in('cash','bank','P&L','tds')";
				 //array('ASSET','INCOME','EXPENSE','LIABILITIES');
				 
				 break;
   		case 'BP':
   			     $CRbillstatus=1;
				 $DRbillstatus=0;
	             $LDR="not in('cash','bank','P&L','tds')";
	             //array('ASSET','INCOME','EXPENSE','LIABILITIES');
				 //$LCR=array('bank','duty and taxes','TDS payable');
				 $LCR="in('bank')";
				 //array('bank');
				
				 break;
   		case 'BR':
	             $LDR="in('bank','tds')";
	             //array('bank');
				 $LCR="not in('cash','bank','P&L','tds')";
				 //array('ASSET','INCOME','EXPENSE','LIABILITIES');
				 $CRbillstatus=0;
				 $DRbillstatus=1;
				
				 break;		
 		case 'JV':
	             $LDR="not in('bank','cash')";
				 $LCR="not in('bank','cash')";  
				 $CRbillstatus=0;
				 $DRbillstatus=0;
				
				 break;
 		case 'CON':
	            $LDR="in('bank','cash')";
	            //array('cash','bank'); 
				$LCR="in('bank','cash')";
				//array('cash','bank'); 
				$CRbillstatus=0;
				$DRbillstatus=0;
				
				break;

 		case 'CDN':
	            $LCR="in('client','vendor')";
	            //array('client','vender');
				$LDR="not in('client','vendor')";
				$CRbillstatus=0;
				$DRbillstatus=0;				
				break;

 		case 'DBN':
	          
				$LCR="not in('client','vendor')";
			    $LDR="in('client','vendor')";
				$CRbillstatus=0;
				$DRbillstatus=0;
				break;

		case 'VatTax':
	       		$LDR="in('salestax')"; 
				$LCR="in('bank','cash')";
				//array('cash','bank');
				$CRbillstatus=0;
				$DRbillstatus=0;
				
				break;

		case 'ExDV':
	       		$LDR="in('excisetax','cess','servicetax','scess')"; 
				$LCR="in('bank','cash')";
				//array('cash','bank');
				$CRbillstatus=0;
				$DRbillstatus=0;
				
				break;
						
  		default: 				
       			$LDR='';
				$LCR='';
				$CRbillstatus=0;
				$DRbillstatus=0;
				
		break; 				 				 		 
	 }
	// $_SESSION['ACGGroupid']=array();
	function CategoryShow($pcode, $PcateID, $dashVal)
	{
	    global $db;
		static $i=0;
		//$arr1=array();
		 print_r($arr1);
 	    $sqlCate = "select * from accountgroupmaster  where  MainGroupId = '".$PcateID."' or NatureOfGroup='".$PcateID."'";
 		$rsCate  = DB_query($sqlCate,$db);	
 		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate = DB_fetch_array($rsCate))
			{ 
                 
  				  //$arr1[]=$rowCate['GroupId'];
  				$_SESSION['ACGGroupid'][]=$rowCate['GroupId'];		
  				   CategoryShow($pcode,$rowCate['GroupId'], $dashVal);
  				
  				  // $result = array_merge($result, showCombinations(...));
 				   //CategoryShow($pcode,$rowCate['GroupId'], $dashVal,$arr1);
 			}
 		}
 		
	       //print_r($arr1);
			return(array_unique($_SESSION['ACGGroupid']));
	}

?>
<script src="js/function-ajax.js" language="javascript"></script>
<script language="javascript">

	function validate_date(str)
	{
		 var ExpiryDate = document.getElementById(str).value;   
		 
    if (isDate(ExpiryDate)) { 
    	return true;
      }
      else{
      	alert("invalid date format");
         document.getElementById(str).value='';
         document.getElementById(str).focus='';
         return false;
         } 

	}

  function isDate(txtDate, separator) {
    var aoDate,           // needed for creating array and object
        ms,               // date in milliseconds
        month, day, year; // (integer) month, day and year
    // if separator is not defined then set '/'
    if (separator === undefined) {
        separator = '/';
    }
    // split input date to month, day and year
    aoDate = txtDate.split(separator);
    // array length should be exactly 3 (no more no less)
    if (aoDate.length !== 3) {
        return false;
    }
    // define month, day and year from array (expected format is m/d/yyyy)
    // subtraction will cast variables to integer implicitly
    month = aoDate[1] - 1; // because months in JS start from 0
    day = aoDate[0] - 0;
    year = aoDate[2] - 0;
    // test year range
    if (year < 1000 || year > 3000) {
        return false;
    }
    // convert input date to milliseconds
    ms = (new Date(year, month, day)).getTime();
    // initialize Date() object from milliseconds (reuse aoDate variable)
    aoDate = new Date();
    aoDate.setTime(ms);
    // compare input date and parts from Date() object
    // if difference exists then input date is not valid
    if (aoDate.getFullYear() !== year ||
        aoDate.getMonth() !== month ||
        aoDate.getDate() !== day) {
        return false;
    }
    // date is OK, return true
    return true;
}

function isNumberKey1(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
         // alert(charCode);
          if (charCode != 46 && charCode != 47 && charCode > 31 
            && (charCode < 47 || charCode > 57))
             return false;

          return true;
       } 
function retCNP(i,str,id)
{
var n=id.split("_");
var j=n[1];

if(j==undefined){
x=document.getElementById(i).value;
t=0;

}
else
{
var k=i+'_'+j;
x=document.getElementById(k).value;
t=j;
}
if(x==000)
{
 alert('Please Select Ledger');
   return false;
}
else
{
	var seq=0;
var site=document.getElementById("Branch").value;	
window.open("ACBillBookDetails.php?cnp="+x+'&VPrefix='+str+'&seq='+seq+'&rowid='+t+'&site='+site,'', 'height=500,width=1200');
}
 }
 // FOR CR (To get Data From Invoice)
 function retCNP1(i,str,id)
{

var n=id.split("_");
var j=n[1];

if(j==undefined){
x=document.getElementById(i).value;
t=0;
}
else
{
var k=i+'_'+j;
x=document.getElementById(k).value;
t=j;
}
if(x==000)
{
 alert('Please Select Ledger');
   return false;
}else
{
var site=document.getElementById("Branch").value;	
	window.open("ACInvoiceDetails.php?cnp="+x+'&VPrefix='+str+'&rowid='+t+'&site='+site,'', 'height=500,width=1050');
}
 }
 
 function addRow2(tableID) 
 { 

	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount1").value=='')
	r =rowCount+1;
	else
	{
	var t=0;
	var t1=document.getElementById("hiditemcount1").value;
	r=parseInt(t1)+parseInt(t)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount1").value=r;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
	newcell.style.background='#fff';
	//newcell.className='tabledata1';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	//newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("AccType_"+r).value='DR';
}

 function addRow(tableID) 
  {
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount").value=='')
	r =rowCount+1;
	else
	{
	var t=0;
	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1)+parseInt(t)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=r;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
	newcell.style.background='#fff';
	//newcell.className='tabledata1';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("AccType_"+r).value='DR';
}
 
 

function addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount1").value=='')
	r =rowCount+1;
	else
	{
	var t=0;
	var t1=document.getElementById("hiditemcount1").value;
	r=parseInt(t1)+parseInt(t)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount1").value=r;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
	newcell.style.background='#fff';
	newcell.className='tabledata1';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("AccType1_"+r).value='CR';
}

function deleteRowOrder(tableID) 
{
    if($('#'+tableID).find('input[type="checkbox"]:checked').length == 0)
    { alert('Please select at least one row to delete.');
      return false;
    }

	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				
				
				var chkbox = row.cells[0].childNodes[0];
				
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
					//alert(i);
				table.deleteRow(i);
				rowCount--;
				i--;
			//	alert(rowCount);
			//document.getElementById("hiditemcount").value=rowCount;
				//alert(id);
				
				}
				
			}
	//document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		

	}
	catch(e) 
	{
		alert(e);
	}

 if(document.getElementById("convrate"))
    {
    	var convrate=document.getElementById("convrate");

calculate_conversion(convrate);
    }
    else
    {
     var convrate='';
 calculate_conversion(convrate);
    }
}

function deleteRowOrder1(tableID) 
{

    if($('#'+tableID).find('input[type="checkbox"]:checked').length == 0)
    { alert('Please select at least one row to delete.');
      return false;
    }
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
			//alert(rowCount);
	//document.getElementById("hiditemcount1").value=parseInt(rowCount);		

	}
	catch(e) 
	{
		alert(e);
	}
	 if(document.getElementById("convrate"))
    {
    	var convrate=document.getElementById("convrate");

calculate_conversion(convrate);
    }
    else
    {
     var convrate='';
 calculate_conversion(convrate);
    }
}
</script>

<?php 
/***********************************INSERT HERE*******START HERE******************AMIt***********************************/
if(isset($_POST['Debit_note']))
{

	$dataArray['document_type']         =$_REQUEST['document_type'];
	$dataArray['Dates']                 =ConvertSQLDate($_REQUEST['Dates']);	
	$dataArray['Ref_no']                =$_REQUEST['Ref_no'];
	 $dataArray['tds_appli']=$_REQUEST['tds_app'];
    $dataArray['service_appli']=$_REQUEST['service_app'];
	$dataArray['transation_type']       =$_REQUEST['transation_type'];
	$dataArray['banks_checkno']         =$_REQUEST['banks_checkno'];
	$dataArray['banks_checkdate']       =FormatDateForSQL($_REQUEST['banks_checkdate']);
	$dataArray['banks_receivedfrom']    =$_REQUEST['banks_receivedfrom'];
	$dataArray['favouring_name']        =$_REQUEST['favouring_name'];
	$dataArray['cross_inst']            =$_REQUEST['cross_inst'];
	$dataArray['total_cramount']        =$_REQUEST['total_cramount'];	
	$dataArray['total_dramount']        =$_REQUEST['total_dramount'];
	$dataArray['total_cramount_conv']   =$_REQUEST['total_convercramount'];	
	$dataArray['total_dramount_conv']   =$_REQUEST['total_convertdramount'];
	$dataArray['narration']             =trim($_REQUEST['narration']);
	$dataArray['modified_date']         =date('Y-m-d');
	$dataArray['modified_by']           =$_SESSION['UserID'];
	$dataArray['deposit_vouchertype']   =$_REQUEST['deposit_vouchertype'];	
	$dataArray['dcrno']                 =$_REQUEST['dcrno'];
	$dataArray['deposit_voucherdate']   =trim(FormatDateForSQL($_REQUEST['deposit_voucherdate']));
	$dataArray['depositedby']           =trim( $_REQUEST['depositedby']);
   	$cond="id='".$_REQUEST['id']."'";
   	//echo "<pre>";print_r($dataArray);exit;
	$s->RecordEdit('account_book', $dataArray,$cond);
	$getlastid=$_REQUEST['id'];

	$DELPrevdata=DB_query("DELETE FROM account_book_details WHERE account_bookid='".$_REQUEST['id']."'",$db);
	for($i=0;$i<count($_REQUEST['Acc_Type']);$i++)
	{
		if(isset($_REQUEST['convrate']))
		{
			if($_REQUEST['convrate']=='')
			{
				$_REQUEST['convrate']=1;
			}
					if($_REQUEST['Acc_Type'][$i]=='DR')
					{
						$data['account_bookid']=$getlastid;
						$data['ledgerid']=$_REQUEST['ledger'][$i];
						$data['amount']=$_REQUEST['totalconvPrice'][$i];
						$data['converted_amount']=$_REQUEST['totalconvPrice'][$i]*$_REQUEST['convrate'];
						$data['currency']=$_REQUEST['drcurrency'][$i];
						$data['conv_currency']=$_REQUEST['drcurrency_conv'][$i];
						$data['amount_type']='DR';
					}
					else
					{
						$data['account_bookid']=$getlastid;
						$data['ledgerid']=$_REQUEST['ledger'][$i];
						$data['amount']=$_REQUEST['totalconvPrice'][$i];
						$data['converted_amount']=$_REQUEST['totalconvPrice'][$i]*$_REQUEST['convrate'];
						$data['currency']=$_REQUEST['drcurrency'][$i];
						$data['conv_currency']=$_REQUEST['drcurrency_conv'][$i];
						$data['amount_type']='CR';
					}
			$s->RecordInsert('account_book_details', $data);
			//$lst=DB_Last_Insert_ID($db,'account_book_details', 'id');
		}
		else if(!isset($_REQUEST['convrate']))
		{
			if($_REQUEST['Acc_Type'][$i]=='DR')
			{
				$data['account_bookid']=$getlastid;
				$data['ledgerid']=$_REQUEST['ledger'][$i];
				$data['amount']=$_REQUEST['totalconvPrice'][$i];
			 //	$data['converted_amount']=$_REQUEST['totalconvPrice'][$i]*$_REQUEST['convrate'];
				$data['currency']=$_REQUEST['drcurrency'][$i];
				$data['conv_currency']=$_REQUEST['drcurrency_conv'][$i];
				$data['amount_type']='DR';
			}
			else
			{
				$data['account_bookid']=$getlastid;
				$data['ledgerid']=$_REQUEST['ledger'][$i];
				$data['amount']=$_REQUEST['totalconvPrice'][$i];
			//	$data['converted_amount']=$_REQUEST['totalconvPrice'][$i]*$_REQUEST['convrate'];
				$data['currency']=$_REQUEST['drcurrency'][$i];
				$data['conv_currency']=$_REQUEST['drcurrency_conv'][$i];
				$data['amount_type']='CR';
			}
		$s->RecordInsert('account_book_details', $data);
		//$lst=DB_Last_Insert_ID($db,'account_book_details', 'id');
		}

	}
   
   if(!empty($_SESSION['sql1']))
	{
   $sql1=explode("#",$_SESSION['sql1']);
	for($i=0;$i<count($sql1);$i++)
	{
	if($sql1[$i]!='')
  // echo "<br>".str_replace("\","",$sql1[$i]);
   
	DB_query(stripslashes($sql1[$i]),$db);
	}
	}
	if(!empty($_SESSION['sql2']))
	{
	$sql2=explode("#",$_SESSION['sql2']);

	for($i=0;$i<count($sql2);$i++)
	{
	if($sql2[$i]!='')
    
	DB_query(stripslashes($sql2[$i]),$db);
	}
	}
	unset($_SESSION['sql1']);
	unset($_SESSION['sql2']);
    unset($_SESSION['adjamt']);
    unset($_SESSION['ACGGroupid']);
    unset($_SESSION['adjamt1']);
   
$s->pageLocation($targetpage.'&daction=view'); 

}	
?>
<div id="PickedItems" style="display:none">
</div>

<div id="div_id" style="display:none"></div>
<style type="text/css">
.modal22 {
	display: none;
	position: fixed;
	z-index: 1000;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	background: rgba( 105, 105, 105, .4 )50% 50%no-repeat;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
	<div class="modal22"><center><div style="font-size:50px;margin-top:200px;">Loading...</div></center></div>
<div class="tab_div">
<h1><?php echo $fromtitle=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'GroupName');?></h1>
<!--<p align="right" style="float:right;"><A HREF="javascript:history.go(-1)" class="search">Go Back</A></p>-->
<?php if($daction=='view')
{ 	
	unset($_SESSION['Acgvoucher_no']);
	unset($_SESSION['AcgBranch']);
	unset($_SESSION['ACGLedgerId']);
	unset($_SESSION['Amount']);
	unset($_SESSION['Amount_type']);
	unset($_SESSION['Currency']);
	unset($_SESSION['AcgDates']);
	unset($_SESSION['AcgRef_no']);
	unset($_SESSION['Acgnarration']);
	unset($_SESSION['AcgDocument']);
			

?>
<?php
 if($_SESSION['frmAdd']=='1') { ?>
<p align="left">
<a href="<?php echo $targetpage;?>&action=addnew&VPrefix=<?php echo $VPrefix;?>"><input name="Add New" type="button" value="Add New" class="search" /></a>
</p>
<?php } ?>
<!---------------------------------SEARCH PART START HERE----------------START HERE---------------------------------------->
<form method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td width="13%" align="right">Type of Info</td>
    <td width="20%"><select name="Type_of_info" >
		<option value="0">Select</option>
		<option value="voucher"<?php echo($_REQUEST['Type_of_info']=='voucher'?'selected':'')?>>voucher</option>
	</select>
	</td>
    <td width="13%" align="right">Having</td>
    <td width="20%"><select name="having" >
		<option value="0">Select</option>
		<option value="voucherno" <?php echo($_REQUEST['having']=='voucherno'?'selected':'')?>>Voucher no</option>
		<option value="vouchertype"<?php echo($_REQUEST['having']=='vouchertype'?'selected':'')?>>Voucher type</option>
		<option value="narration"<?php echo($_REQUEST['having']=='narration'?'selected':'')?>>Narration</option>
		<option value="instrumentno"<?php echo($_REQUEST['having']=='instrumentno'?'selected':'')?>>Instrument no</option>
		<!--<option value="searchledger"<?php echo($_REQUEST['having']=='ledger'?'selected':'')?>>Ledger</option>-->
		<!--<option value="amount"<?php echo($_REQUEST['having']=='amount'?'selected':'')?>>Amount</option>-->
	</select>
	</td>
    <td width="13%" align="right">Range of Info</td>
    <td><select name="range_of_info" >
		<option  value="0">Select</option>
		<option value="containing"<?php echo($_REQUEST['range_of_info']=='containing'?'selected':'')?>>Containing</option>
		<option value="equalto"<?php echo($_REQUEST['range_of_info']=='equalto'?'selected':'')?>>Equal to</option>
		<option value="startingwith"<?php echo($_REQUEST['range_of_info']=='startingwith'?'selected':'')?>>starting with</option>
	</select>
	</td>
</tr>
<tr class="row1">
    <td align="right">Text</td>
    <td><input type="text" value="<?php echo $_REQUEST['searchtext']; ?>" name="searchtext" /></td>
	<td align="right">From Date</td>
    <td><input type="text" name="from" id="from" value="<?php echo $_REQUEST['from']; ?>" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)"  class="datepicker" /></td>
	<td align="right">To Date</td>
    <td><input type="text" name="to" id="to" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)" value="<?php echo $_REQUEST['to']; ?>"  class="datepicker"  /></td>
</tr>
<tr class="row1">
	<td align="right">Transcation</td>
    <td style="padding-left:15px;">Debit</strong> <input type="radio" name="typeofamount" id="typeofamount" value="DR"  
	<?php if($_REQUEST['typeofamount']=='DR' || $_REQUEST['typeofamount']=='' ){ ?> checked="checked" <?php  } ?> />&nbsp;
	Credit</strong><input type="radio" name="typeofamount" id="typeofamount" value="CR" 
	<?php if($_REQUEST['typeofamount']=='CR'){ ?> checked="checked"<?php  } ?>/></td>
	<td align="right">Document Type</td>
	<td><select name="documenttype" id="documenttype" >
      <option value=''>Select</option>
      	<option value="EB"<?php if($_REQUEST['documenttype']=='EB') { ?> selected<?php } ?>>Expence Bill</option>
      </select>
	</td>
	<td></td>
	<td></td>
</tr>
<tr class="row1">
	<td colspan="6" style="text-align:center;"><input type="submit" class="search" name="filter" value="Search" /></td>
</tr>
</table>
</form>

<br />
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
<tr>
 	<th>Branch</th>
	<th width="12%">Voucher No.</th>
	<th width="8%">Date</th>
	<th width="8%">Ref. No.</th>
	<th width="12%">Ledger</th>
	<?php if(!isset($_REQUEST['typeofamount'])) { ?>
	<th width="8%">DR Amount</th>
	<?php } else { ?>
	<th width="8%"><?php echo $_REQUEST['typeofamount']; ?> Amount</th>
	<?php } ?>
	<th width="12%">Narration</th>
	<?php if($_SESSION['frmView']=='1'){?><th width="5%" style="text-align:center;">View</th><?php } ?>
	<?php if($_SESSION['frmEdit']=='1'){?><th width="5%" style="text-align:center;">Edit</th><?php } ?>
	<th width="5%" style="text-align:center;">Print</th>
	<th width="5%" style="text-align:center;">Cancel</th>
	<?php if($_REQUEST['VPrefix']==4) { ?>
	<th width="5%" style="text-align:center;">Cheque Print</th>
	<th width="5%" style="text-align:center;">RTGS Print</th>
	<?php } ?>
</tr>
  <?php  
if($_REQUEST['filter'])
{
$Typeofinfo=$_REQUEST['Type_of_info'];
	  	$having=$_REQUEST['having'];
		$range=$_REQUEST['range_of_info'];
		$searchtext=$_REQUEST['searchtext'];
		$filter=array();$filter2='';
		$amount_type=$_REQUEST['typeofamount'];		
		
 		switch($having)
		{
		  case 'voucherno':
		  					if($range=='equalto')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.Voucher_NO ='".$searchtext."' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.Voucher_NO ='".$searchtext."'";
							}
							if($range=='containing')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.Voucher_NO  like'%".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";		
							}
							else
							{
							$filter=" A.Voucher_NO  like'%".$searchtext."%'";		
							}			
							if($range=='startingwith')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter="  A.Voucher_NO  like'".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";	
							}
							else
							{
							$filter=" A.Voucher_NO  like'".$searchtext."%'";	
							}						
							
		  					break;
		                case 'vouchertype':
		  
					   $Vprefixval1= $s->getField('voucher_master','VPrefix',$searchtext,'VoucherType');
		 					 if($range=='equalto')
							 if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.VPrefix ='".$Vprefixval1."' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.VPrefix ='".$Vprefixval1."'";
							}
							if($range=='containing')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.VPrefix  like'%".$Vprefixval1."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";		
							}
							else
							{
							$filter=" A.VPrefix  like'%".$Vprefixval1."%'";		
							}			
							if($range=='startingwith')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.VPrefix  like'".$Vprefixval1."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";	
							}
							else
							{
							$filter=" A.VPrefix  like'".$Vprefixval1."%'";	
							}
		  
		  					break;
		                     case 'narration':
		  					 if($range=='equalto')
							 if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.narration ='".$searchtext."' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.narration ='".$searchtext."'";
							}
							if($range=='containing')
							 if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.narration  like'%".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.narration  like'%".$searchtext."%'";
							}					
							if($range=='startingwith')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter="A.narration  like'".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";	
							}
							else
							{
							$filter="A.narration  like'".$searchtext."%'";	
							}
							break;	
																				
		                     case 'instrumentno':		  
		  					if($range=='equalto')
		  						

							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.banks_checkno ='".$searchtext."' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.banks_checkno ='".$searchtext."'";
							}
							if($range=='containing')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.banks_checkno  like'%".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' 
		  					and '".FormatDateForSQL($_REQUEST['to'])."'";
							}
							else
							{
							$filter=" A.banks_checkno  like'%".$searchtext."%'";
							}					
							if($range=='startingwith')
							if($_REQUEST['from']!='' && $_REQUEST['to']!=''){
		  					$filter=" A.banks_checkno  like'".$searchtext."%' and A.Dates between '".FormatDateForSQL($_REQUEST['from'])."' 
		  					and '".FormatDateForSQL($_REQUEST['to'])."'";	
							}
							else
							{
							$filter=" A.banks_checkno  like'".$searchtext."%'";	
							}							
							break;																			
		}

		if($_REQUEST['documenttype']!='')
		 	$filter="  A.document_type ='".$_REQUEST['documenttype']."' ";
		
			if($amount_type=='' && !empty($filter))		
			$WithoutFSQL="select A.id as Pid,B.* ,A.* from account_book A,account_book_details B where A.VPrefix='".$VPrefix."' 
			and A.AccountBookType='voucher' and A.Branch in('".$_SESSION['AssignedBranch']."')   and  A.id=B.account_bookid and  $filter  group by A.id";
			else if($amount_type!='' && empty($filter)) 
			$WithoutFSQL="select A.id as Pid,B.* ,A.* from account_book A,account_book_details B where A.VPrefix='".$VPrefix."'  and A.AccountBookType='voucher'  and  A.id=B.account_bookid and  B.amount_type='".$amount_type."' and  A.Branch in('".$_SESSION['AssignedBranch']."') and 
			A.Dates between '".$_SESSION['financialYrStart']."' 
			and '".$_SESSION['financialYrEnd']."' group by A.id  ";
			else if($amount_type!='' && !empty($filter)) 
			$WithoutFSQL="select A.id as Pid,B.* ,A.* from account_book A,account_book_details B where A.VPrefix='".$VPrefix."' and  $filter and A.AccountBookType='voucher'  and  A.id=B.account_bookid and  B.amount_type='".$amount_type."' and  A.Branch in('".$_SESSION['AssignedBranch']."') and 
			A.Dates between '".$_SESSION['financialYrStart']."' 
			and '".$_SESSION['financialYrEnd']."' group by A.id";
			else
			$WithoutFSQL="select A.id as Pid,B.* ,A.* from account_book A,account_book_details B where A.VPrefix='".$VPrefix."'  
			and A.AccountBookType='voucher'  and  A.id=B.account_bookid and   A.Branch in('".$_SESSION['AssignedBranch']."') and
			A.Dates between '".$_SESSION['financialYrStart']."' 
			and '".$_SESSION['financialYrEnd']."' group by A.id";
}

else
{
	$WithoutFSQL="select A.id as Pid,B.* ,A.* from account_book A,account_book_details B where  A.created_date='".date('Y-m-d')."'
	 and A.VPrefix='".$VPrefix."'  and A.AccountBookType='voucher'  and  A.id=B.account_bookid  and B.amount_type='DR' 
     and  A.id=B.account_bookid and   A.Branch in('".$_SESSION['AssignedBranch']."') 
     and  A.Dates between '".$_SESSION['financialYrStart']."'  and '".$_SESSION['financialYrEnd']."'  group by A.id      ";
}

$ResultData=DB_query($WithoutFSQL,$db);
while($RowData = DB_fetch_array($ResultData))
{
$drAmtAk='';
$CrAmtAk='';
$amt='';

$chkAdrcrSQL=DB_query("select * from account_book_details where account_bookid='".$RowData['account_bookid']."'",$db);
while($chkDrCr=DB_fetch_array($chkAdrcrSQL))
{
	if($chkDrCr['amount_type']=='DR')
	{
	
		$drAmtAk=$drAmtAk+$chkDrCr['amount'];
		$amt=$chkDrCr['amount'];
	}
	else
	{
		$CrAmtAk=$CrAmtAk+$chkDrCr['amount'];
		$amt=$chkDrCr['amount'];
	}
}
if(trim($drAmtAk)!=trim($CrAmtAk))
{
	$bgcolor=1;
}
else
{
	$bgcolor=0;
}
if($_REQUEST['typeofamount']=='CR')
$amount1=$CrAmtAk;
else 
$amount1=$drAmtAk;

//echo $_REQUEST['typeofamount'];
?>
 
<tr <?php if($bgcolor==1) { ?> style="color:#FF0000" <?php } else { ?> style="background:#fff;" <?php } ?>  >	
	<td><?php echo $s->getField('locations','loccode',$RowData['Branch'],'locationname') ?></td>
	<td><?php echo $RowData['Voucher_NO'] ?></td>	
	<td><?php echo ConvertSQLDate($RowData['Dates']); ?></td>
	<td><?php echo $RowData['Ref_no']; ?></td>
	<td><?php echo  $s->getField('accountledger','AccountsID',$RowData['ledgerid'],'AccountName'); ?></td>
	<td><?php echo $amount1; ?></td>
	<td><?php echo $RowData['narration']; ?></td>
    <!--<td><a href="#" onclick='popup("address_book.php?id=<?php  echo $RowData['Pid'].$rurl?>&VPrefix=<?php echo $VPrefix;?>",600,600)'>View</a></td>-->
   <?php $slipno=explode(":",$RowData['narration']); ?>
	<?php if($_SESSION['frmView']=='1'){?><td style="text-align:center;"><a href="index.php?route=Account/address_book&id=<?php  echo $RowData['Pid'].$rurl?>" ><img src="images/search.gif" height="15" width="15" title="View" /></a></td><?php } ?>
	<?php if($_SESSION['frmEdit']=='1' && $RowData['bill_status']=='Pending' and $slipno[1]=='' ){?><td style="text-align:center;"><a href="index.php?route=Account/ACBillbookPayment_Edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Edit&id=<?php  echo $RowData['Pid'];?>&VPrefix=<?php echo $VPrefix; ?>"><img src="images/icon-edit.png" height="15" width="15" title="Edit" /></a></td><?php } else { ?><td style="text-align:center;"><img src="images/icon-edit.png" height="15" width="15" title="No Permission" style="opacity:0.5;" /></td><?php } ?>
	 <td style="text-align:center;"><?php if($_SESSION['frmView']==1 ) { 
     if($_REQUEST['VPrefix']==6) { $address_print="address_book_print1.php"; } else {$address_print="address_book_print.php"; }	?>      
      <a href="<?php echo $address_print; ?>?id=<?php echo $RowData['Pid'];?>&VPrefix=<?php echo $_REQUEST['VPrefix'];?>&type=view" target="_blank"><img src="images/print.png" height="15" width="15" title="Print" /></a><?php } else { ?><img src="images/print.png" height="15" width="15" title="No Permission" style="opacity:0.5;" /><?php } ?></td>      
      <td style="text-align:center;"><?php if($RowData['cancel_status']==1) { ?><img src="images/icon_cancel1.png" width="15" height="15" title="Cancelled" />
	  <input type="button" name="reason" class="search"  value="Reason" onclick="javascript:popup('voucher_Cancelled_reason.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $RowData['Pid'];?>&VPrefix=<?php echo $_REQUEST['VPrefix'];?>',200,220)"> <?php } else { ?>
			 <a onclick="popup('VoucherCancel.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $RowData['Pid'];?>&VPrefix=<?php echo $_REQUEST['VPrefix'];?>',600,200)" href="#"><img src="images/icon_cancel.png" width="15" height="15" title="Cancel" /></a><?php } ?></td>
	<?php if($_REQUEST['VPrefix']==4) { ?>
	<td style="text-align:center;"><a href="cheque_printing.php?id=<?php echo $RowData['Pid'].$rurl?>"><img src="images/cheque_book.png" width="20" height="15" title="Cheque" /></a></td>
	<td style="text-align:center;"><a href="RTGSPayment.php?id=<?php  echo $RowData['Pid'].$rurl?>" >RTGS</a></td>
	<?php } ?>
  </tr>
  <?php } ?>
</table>

<?php 
}
else
{?>

<form action="" method="post">
<?php   // $BillBookType;
  if($BillBookType=='CR' || $BillBookType=='BR' )  
     $credit_amount= $_REQUEST['amount']; 
     else 
     $dr_amount= $_REQUEST['amount']; 
     $ledger_dr=$_REQUEST['cnp'];
 ?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php if(count($msgErr)>0){?>
<tr class="row1">
	<td colspan="6">
	<div class='error'><?php
	   for($i=0;$i<count($msgErr);$i++)
	   {
		 echo "".$msgErr[$i].'<br>';
	   }?>
	</div>
</td>
</tr>
   <?php } ?>
<tr class="row1">
	<td width="13%" align="right">Branch</td>
    <td width="20%"><?php $sql_state=DB_query("SELECT loccode,locationname FROM  locations 
					WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND loccode in('".$Branch."')",$db);	?>
			<select name="Branch" id="Branch"  onchange="getLedgerName(this.value,'<?php echo $BillBookType;?>');"> 
				<?php 
					while($row_branch=DB_fetch_array($sql_state))
					{
					  
					  echo "<option value='".$row_branch['loccode']."' $p >".$row_branch['locationname']."</option>";
					}?>
	</select>	
	</td>
    <td width="13%" align="right">Voucher No.</td>
    <td width="20%"><input name="voucher_no" id="voucher_no" type="text" value="<?php echo $Voucher_NO;?>" readonly  /></td>
    <td width="13%" align="right">Date</td>
    <td><input name="Dates" readonly id="Dates" type="text"  class="datepicker"  value="<?php echo ConvertSQLDate($Dates);?>"   onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)"  placeholder="dd/mm/yyyy"/></td>
</tr>
<tr class="row1">
    <td align="right">Ref. No.</td>
    <td><input name="Ref_no" id="Ref_no" type="text" value="<?php echo $Ref_no;?>" /></td>
    <td align="right">Ref. Date</td>
    <td><input name="ref_date"  id="ref_date" type="text"   value="<?php echo ConvertSQLDate($Ref_date);?>" class="datepicker" placeholder="dd/mm/yyyy" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)" /></td>	
 <?php  
 if($BillBookType=='JV' or $BillBookType=='BR')
  {
  	 if($BillBookType!='JV')
  	 {
  $arr_doc=array(""=>'None',"EB"=>'Expence Bill',"SW"=>"Solid Waste","CC"=>"Capital Cost","MF"=>"Membership Fees","SEP"=>"Supplementary","TB1"=>"Table-1","TB2"=>"Table-2","FC"=>"Facco","TC"=>"Treatment Charges","CA"=>"CMEE and Analysis");
      }
      else
     $arr_doc=array(""=>'None',"EB"=>'Expence Bill');
  
  ?>
    <td align="right">Document</td>
    <td><select name="document_type" >		
	<?php //$arr_doc=array(""=>'None',"EB"=>'Expence Bill');
 
   //array('Vat Voucher','TDS Voucher','Service Tax Voucher');
	foreach($arr_doc as $key=>$value)
   {	
	echo "<option value='".$key."'>".$value."</option>";
	}
	 ?></select>
	 </td>
    <?php } else {?>    
<td></td>
<td></td>
<?php } ?>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php if($BillBookType=='JV')
  {
  ?>
<tr class="row1">
 <td colspan="6">Applicable TDS &nbsp;<input type="checkbox" name="tds_app" value="Y" <?php echo ($tds_appli=="Y")?"checked":""; ?>> &nbsp;Applicable Service Tax &nbsp;<input type="checkbox" name="service_app" value="Y" <?php echo ($service_appli=="Y")?"checked":""; ?>></td>
</tr> 
<?php } ?>	
	<?php if($conv_check==1) { ?>
<tr class="row1">
    <td width="13%" align="right">Currency</td>
    <td width="20%"><select id="currency"  onchange="showcurrency1(this.value)" >
		<?php
	    $sql_currency1=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'
		  and abbreviation='INR'",$db);
	while($row_currency1=DB_fetch_array($sql_currency1))
	{
	?>	
     <option value="<?php echo $row_currency1['id'] ; ?>"><?php echo $row_currency1['abbreviation']; ?></option>
	<?php  } ?>
       </select>
	</td>
    <td width="13%" align="right">Currency Conv.</td>
    <td width="20%"><select  id="convcurrency" onchange="showcurrency(this.value)" >
		<?php
	       $sql_currency1=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'
		  and id='".$currency_sec."'",$db);
	while($row_currency1=DB_fetch_array($sql_currency1))
	{
	?>	
     <option value="<?php echo $row_currency1['id'] ; ?>"><?php echo $row_currency1['abbreviation']; ?></option>
	<?php  } ?>
       </select></td>
	<td width="13%" align="right">Conv. Rate</td>
    <td><input type="text" name="convrate" id="convrate" value="<?php echo $conv_rate; ?>" onkeypress="return isNumberKey(event)"  maxlength='11' onblur='javascript:validate_floating(this.value,this.id)' readonly  /></td>
</tr>
<?php } ?>
</table>
<p align="left">
    <?php $drfl=0;  if(in_array($_REQUEST['VPrefix'], $debit_side)) { $drfl=1; ?>
     <?php if($_REQUEST['action']=="Edit"){?>
	<input type="button" onclick="addRow('dataTable')" value="Add Rows" class="search" /> 
		<input type="button" class="search"   onclick="deleteRowOrder('dataTable');getSumT()" value="Delete" />
		<input type="hidden" id="multipledr" value="true" > 	
	<?php } ?>
		<?php } ?>
</p>	
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">		
	<tr>	
		<th width="4%">S. No.</th>
		<th width="15%">Search</th>
		<th width="1"></th>
    	<th>Dr. Ledger Name</th>
        <th width="1"></th>
		<th width="8%">Debit</th>
    	<th width="8%">Curr.</th>
		<?php if($conv_check==1) { ?>
		<th width="10%">Curr. Cov.</th>
		<th width="10%">Conv.Amount.</th>
		<?php } ?>
		<th width="8%"></th>
	</tr>
		
	<tbody id="dataTable">
		<?php
         $d=1;
		 $sql_debit=DB_query("select * from account_book_details where account_bookid='".$id."' and amount_type='DR'",$db);
		 if(DB_num_rows($sql_debit)>0)
		 {
		      while($row_sql_dr=DB_fetch_array($sql_debit))
		      {
		 ?>	
	<tr>
		<td><input name="delitem[]" type="checkbox" /></td>
    	<td><input type="text" name="ledgername" id="ledgername_<?php echo $d; ?>"  onkeyup="getledgernameDR(this.value,this.id,event)" /></td><!-- onkeyup="legend(this);"-->
		<td><input type="hidden" name="Acc_Type[]" id="AccType_<?php echo $d; ?>" value="DR" /></td>
		<td><select name="ledger[]" id="ledgerdr_<?php echo $d; ?>"   onchange="validatebank(this.id)" class="form-control input-sm debitledger">
        <!--onchange="ShowDiv(this.value,'hid-Bankdetails','ACBillbookBankDetails.php')"-->
		<option value="0">Please select Ledger</option>		
		<?php   
         if($LDR!='')
         $undergroup=$LDR;
         else
         $undergroup='';	        
		$AccountMaster-> AccountLeger_edit($ledger_dr,'ledger_dr[]','ledgerdrID',$undergroup,$row_sql_dr['ledgerid'],$Branch);?>
        </select></td>
		<td><input type="hidden" name="tot_bil_no" id="tot_bil_no_<?php echo $d; ?>" ><input type="hidden" name="undergroup" id="undergroup" value="<?php echo $undergroup; ?>"/><input type="hidden" name="undergroup1" id="undergroup1" value="<?php echo urlencode($undergroup);?>"></td>
		<td><input style='width:98%;' type='text' name='totalconvPrice[]' id='totaldrconvPrice_<?php echo $d; ?>' <?php if(in_array($_REQUEST['VPrefix'], $debit_side) or $_REQUEST['VPrefix']==10) {  ?> onkeyup="javascript:all_calculation(this,event);" onfocus="javascript:all_calculation(this,event);"  <?php }else { echo "readonly";} ?> maxlength='11' onblur='javascript:validate_floating(this.value,this.id)'    dramt="dramt" onkeypress="return isNumberKey(event)" value="<?php echo $row_sql_dr['amount']; ?>" />
		<!--onkeyup="adddebitamount1(this.value,this.id)" onfocus="adddebitamount1(this.value,this.id)"--></td>
		<td><select name="drcurrency[]" id="drcurrency_<?php echo $d; ?>"  curr="curr" >
		          <?php
			     $sql_currency1=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'
				  and abbreviation='INR' and id='".$row_sql_dr['currency']."'",$db);
			while($row_currency1=DB_fetch_array($sql_currency1))
			{
			?>
          <option value="<?php echo $row_currency1['id'] ; ?>"><?php echo $row_currency1['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>
	    <?php if($conv_check==1) { ?>
	    <td><select name="drcurrency_conv[]" id="drcurrencyconv_<?php echo $d; ?>"  curr1="curr1" >
          <?php
	     $sql_currency=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$row_sql_dr['conv_currency']."'",$db);
	     while($row_currency=DB_fetch_array($sql_currency))
	     {
	    ?>
        <option value="<?php echo $row_currency['id'] ; ?>"><?php echo $row_currency['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>	 
	    <td><input name="dramount[]"  type="text" id="debitamount_<?php echo $d; ?>" value="<?php echo $row_sql_dr['converted_amount']; ?>"  readonly='true' /></td><!--onkeyup="adddebitamount(this.value,this.id)"-->
	    <?php } ?>
    	<td><?php if($CRbillstatus==1){ ?>
    	 <?php if($_REQUEST['action']=="Edit"){?>
    	<input type="button" id="billDR_<?php echo $d; ?>" class="search" onclick="retCNP('ledgerdr',<?php echo $VPrefix; ?>,this.id)" value="Bill wise Adj"/>
    	<?php } ?>
	 	<?php } ?>
      	</td>
  	</tr>
  		<?php $d++; }
  	}
  	else{?>
  	<tr>
		<td><input name="delitem[]" type="checkbox"  /></td>
    	<td><input type="text" name="ledgername" id="ledgername_<?php echo $d; ?>"  onkeyup="getledgernameDR(this.value,this.id,event)" /></td><!-- onkeyup="legend(this);"-->
		<td><input type="hidden" name="Acc_Type[]" id="AccType_<?php echo $d; ?>" value="DR" /></td>
		<td><select name="ledger[]" id="ledgerdr_<?php echo $d; ?>"   onchange="validatebank(this.id)" class="form-control input-sm debitledger">
        <!--onchange="ShowDiv(this.value,'hid-Bankdetails','ACBillbookBankDetails.php')"-->
		<option value="0">Please select Ledger</option>		
		<?php   
         if($LDR!='')
         $undergroup=$LDR;
         else
         $undergroup='';	        
		$AccountMaster-> AccountLeger_edit($ledger_dr,'ledger_dr[]','ledgerdrID',$undergroup,$row_sql_dr['ledgerid'],$Branch);?>
        </select></td>
		<td><input type="hidden" name="tot_bil_no" id="tot_bil_no_<?php echo $d; ?>" ><input type="hidden" name="undergroup" id="undergroup" value="<?php echo $undergroup; ?>"/><input type="hidden" name="undergroup1" id="undergroup1" value="<?php echo urlencode($undergroup);?>"></td>
		<td><input style='width:98%;' type='text' name='totalconvPrice[]' id='totaldrconvPrice_<?php echo $d; ?>' <?php if(in_array($_REQUEST['VPrefix'], $debit_side) or $_REQUEST['VPrefix']==10) {  ?> onkeyup="javascript:all_calculation(this,event);" onfocus="javascript:all_calculation(this,event);"  <?php }else { echo "readonly";} ?> maxlength='11' onblur='javascript:validate_floating(this.value,this.id)'    dramt="dramt" onkeypress="return isNumberKey(event)" value="<?php echo $row_sql_dr['amount']; ?>" />
		<!--onkeyup="adddebitamount1(this.value,this.id)"
		  onfocus="adddebitamount1(this.value,this.id)"-->
		</td>
		<td><select name="drcurrency[]" id="drcurrency_<?php echo $d; ?>"  curr="curr" >
		          <?php
			     $sql_currency1=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'
				  and abbreviation='INR' and id='".$row_sql_dr['currency']."'",$db);
			while($row_currency1=DB_fetch_array($sql_currency1))
			{
			?>
          <option value="<?php echo $row_currency1['id'] ; ?>"><?php echo $row_currency1['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>
	    <?php if($conv_check==1) { ?>
	    <td><select name="drcurrency_conv[]" id="drcurrencyconv_<?php echo $d; ?>"  curr1="curr1" >
          <?php
	     $sql_currency=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$row_sql_dr['conv_currency']."'",$db);
	     while($row_currency=DB_fetch_array($sql_currency))
	     {
	    ?>
        <option value="<?php echo $row_currency['id'] ; ?>"><?php echo $row_currency['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>	 
	    <td><input name="dramount[]"  type="text" id="debitamount_<?php echo $d; ?>" value="<?php echo $row_sql_dr['converted_amount']; ?>"  readonly='true' /></td><!--onkeyup="adddebitamount(this.value,this.id)"-->
	    <?php } ?>
    	<td><?php if($CRbillstatus==1){ ?>
    	 <?php if($_REQUEST['action']=="Edit"){?>
    	<input type="button" id="billDR_<?php echo $d; ?>" class="search" onclick="retCNP('ledgerdr',<?php echo $VPrefix; ?>,this.id)" value="Bill wise Adj"/>
    	<?php } ?>
	 	<?php } ?>
      	</td>
  	</tr>
  	<?php }

  		 ?>
	</tbody>
</table>

<p align="left">
		 <?php if($_REQUEST['action']=="Edit"){?>

		<?php $red=1;  if(in_array($_REQUEST['VPrefix'],$lcrdata))	{ $red='0';?>
		<input type="button" onclick="addRow2('dataTable1')" value="Add Rows" class="search" />
		<input type="button" class="search"   onclick="deleteRowOrder1('dataTable1');getSumT1()" value="Delete" />
		<input type="hidden" id="multiplecr" value="true" >
		<?php }?>

		<?php } ?>
</p>

<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
	<tr>
		<th width="4%">S. No.</th>
		<th width="15%">Search</th>
		<th width="1"></th>
    	<th>Cr. Ledger Name</th>
        <th width="1"></th>
    	<th width="8%">Credit</th>
    	<th width="8%">Curr.</th>
		<th width="10%"></th>
		<th width="10%"></th>
		<th width="8%"></th>
	</tr>
	<tbody id="dataTable1">
			<?php
         $c=1;
		 $sql_credit=DB_query("select * from account_book_details where account_bookid='".$id."' and amount_type='CR'",$db);
		      while($row_sql_cr=DB_fetch_array($sql_credit))
		      {
		      	
		 ?>	
	<tr>
		<td><?php if(in_array($_REQUEST['VPrefix'],$lcrdata)){?><input name="delitem1[]" type="checkbox" /><?php }?></td>
		<td><input type="text" name="ledgername1" id="ledgername1_<?php echo $c;?>"  onkeyup="getledgernameCR(this.value,this.id,event)" /></td>
		<td><input type="hidden" name="Acc_Type[]" id="AccType1_<?php echo $c;?>" value="CR" /></td>
		<td><select name="ledger[]" id="ledgercrID_<?php echo $c;?>" onchange="GetBankDetals(this.value,this.id)"  class="form-control input-sm creditledger">
		<option value="0">Please select Ledger</option>
	    <?php		
	 
	     if($LCR!='')
         $undergroup1=$LCR;
         else
         $undergroup1=$LCR;
	     if(isset($_REQUEST['cnp']) ){
		 $AccountMaster-> AccountLeger_edit($_REQUEST['cnp'],'ledger_cr[]','ledgercrID',$undergroup1,$row_sql_cr['ledgerid'],$Branch);}
 	    else  { $AccountMaster-> AccountLeger_edit($ledger_cr,'ledger_cr[]','ledgercrID',$undergroup1,$row_sql_cr['ledgerid'],$Branch); }	?>
         </select>   
	    <!--<input type="hidden" name="undergroupCR" id="undergroupCR" value="<?php //echo $undergroup1; ?>"	 />-->	
	    </td>
        <td><input type="hidden" name="undergroup1CR" id="undergroup1CR" value="<?php echo $undergroup1; ?>"	 />
          <input type="hidden" name="undergroup2" id="undergroup2" value="<?php echo urlencode($undergroup1);?>">
        </td>  				
		<td><input style='width:98%;' type='text' name='totalconvPrice[]' cramt="cramt" id='totalcrconvPrice_<?php echo $c;?>' onkeypress="return isNumberKey(event)" maxlength='11' onblur='javascript:validate_floating(this.value,this.id)' <?php if(in_array($_REQUEST['VPrefix'],$lcrdata) or $_REQUEST['VPrefix']==10){ ?>  onkeyup="all_calculation(this,event)" onfocus="javascript:all_calculation(this,event);" onblur='javascript:validate_floating(this.value,this.id)' maxlength='11' <?php }else { echo "readonly";} ?>  value="<?php echo  $row_sql_cr['amount']; ?>" /><!--onkeyup="addcreditamount1(this.value,this.id)"--></td>		
    	<td><select name="drcurrency[]" id="crcurrency_<?php echo $c;?>"  curr1="curr1" >
          <?php
	     $sql_currency1=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'
		  and abbreviation='INR' and id='".$row_sql_cr['currency']."'",$db);
	     while($row_currency1=DB_fetch_array($sql_currency1))
	    {
	     ?>
          <option value="<?php echo $row_currency1['id'] ; ?>"><?php echo $row_currency1['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>
	    <?php if($conv_check==1) { ?>
	    <td><select name="drcurrency_conv[]" id="crcurrencyconv_<?php echo $c;?>"  curr2="curr2" >
          <?php
	     $sql_currency=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$row_sql_cr['conv_currency']."'",$db);
	    while($row_currency=DB_fetch_array($sql_currency))
	    {
	    ?>
          <option value="<?php echo $row_currency['id'] ; ?>"><?php echo $row_currency['abbreviation']; ?></option>
          <?php  } ?>
        </select></td>	
	    <td><input name="cramount[]" id="creditamount_<?php echo $c;?>"  type="text"   readonly='true' value="<?php echo  $row_sql_cr['converted_amount']; ?>" /></td>
        <!--onkeyup="addcreditamount(this.value,this.id)"-->
	    <?php }else { ?>
	    <td colspan="2"></td>
	    <?php } ?>
    	<td><?php if($DRbillstatus==1){?>
    	<?php if($_REQUEST['action']=="Edit"){?>
    	<input type="button" id="billcr_<?php echo $c;?>" class="search" onclick="retCNP1('ledgercrID',<?php echo $VPrefix; ?>,this.id)" value="Bill wise Adj"/>
    	<?php } ?>
	 	<?php } ?> <!--<input type="button" name="AddCRLedger" onclick="addcreditlist()" value="Add" class="search" />-->
		</td>
  		</tr>
  		<?php $c++; } ?>
		</tbody>
</table>
<br>
<div id="dis_crdr" style="z-index:-9999;"></div>

	 <?php  //echo $BillBookType;
		if( $BillBookType!='CP' && $BillBookType!='CR' && $BillBookType!='JV'){
		
		
			if($BillBookType=='CON'){
			$favouring_name=$_SESSION['CompanyRecord']['CompanyName'];
			$cross_inst='A/C PAYEE';
			}
			
	?>
	<!--<div id='hid-Bankdetails'>-->
<h3>Bank Cheque Details</h3>
<table width="100%" cellpadding="3" cellspacing="0" border="0">	 
<tr class="row1">
	<td width="13%" align="right">Transation Type</td>
    <td width="20%"><select  name="transation_type" id="transation_type" >
    	<option value="0">Please select</option>
               <?php  
               $resultGp=DB_query("select * from conf_bank_master",$db);
               while($rowGP=DB_fetch_array($resultGp))
               {?>
                <option value="<?php echo $rowGP['id']; ?>" <?php if($transation_type==$rowGP['id']) { ?> selected<?php } ?>><?php echo $rowGP['bank_name']; ?></option>
               <?php }

               ?>
	</select></td>	
    <td width="13%" align="right">Cheque No.</td>
    <td width="20%" id="INSNO"><input type="text" name="banks_checkno"   id='banks_checkno' value="<?php echo $banks_checkno; ?>"   /></td>
    <td width="13%" align="right">Cheque Date</td>
    <td><input type="text" name="banks_checkdate"  id="banks_checkdate" class="datepicker" value="<?php echo ConvertSQLDate($banks_checkdate);?>" placeholder="dd/mm/yyyy" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)" /></td>   
  </tr>
<tr class="row1">
<?php if($VPrefix=='4')
{ ?>
	<td align="right">Bank Payee Name</td>
	<?php } else { ?> <td>Bank Name</strong></td> <?php } ?>
    <td><input type="text" name="banks_receivedfrom" id="banks_receivedfrom"  value="<?php echo $banks_receivedfrom; ?>"></td> 	
	<td align="right">Bank Branch Name</td>
	<td><input type="text" name="favouring_name" id="favouring_name"  value="<?php echo $favouring_name; ?>" /></td>
	<td align="right">Cross Inst.</td>
	<td><input type="text" name="cross_inst" id="cross_inst"   value="<?php echo $cross_inst; ?>" <?php if($BillBookType!='CON') {?>maxlength='11' onblur='javascript:validate_floating(this.value,this.id)' onkeypress='javascript:return isNumberKey(event)'  <?php } ?> /></td>
</tr>
</table>
	<!--</div>-->
  <?php } ?>
  
   <?php  
	if( $BillBookType=='VatTax' && $BillBookType!='ExDV' && $BillBookType!='JV'  && $BillBookType!='CON'){
	?>	
<h3>Deposit Voucher Type</h3>
<table width="100%" cellspacing="0" cellpadding="3" border="0">		 
<tr class="row1">
	<td width="13%" align="right">Voucher Type</td>
	<td width="20%"><input type="text" name="deposit_vouchertype" id='deposit_vouchertype' value="<?php echo $deposit_vouchertype; ?>"  /></td>
	<td width="13%" align="right">DCR No.</td>
	<td width="20%"><input type="text" name="dcrno" id="dcrno" value="<?php echo $dcrno; ?>"  /></td>  
	<td width="13%"></td>
	<td></td> 
	</tr>
	<tr class="row1">
	<td align="right">Date</td>
	<td><input type="text" name="deposit_voucherdate" id="deposit_voucherdate" class="datepicker" value="<?php echo $deposit_voucherdate; ?>" placeholder="dd/mm/yyyy" onchange="validate_date(this.id)" onkeypress="return isNumberKey1(event)"  /></td>
	<td align="right">Deposited By</td>
	<td><input type="text" name="depositedby" id="depositedby"  value="<?php echo $depositedby; ?>"  /></td> 
	<td></td>
	<td></td> 
</tr>
</table>
  <?php } ?>
	<?php if($conv_check==1) { ?>
<table width="100%" cellspacing="0" cellpadding="3" border="0">	
<tr class="row1">
    <td width="13%" align="right">Total Converted Credit Amt.</td>
    <td width="20%"><input type="text" name="total_convercramount" id='total_convercramount'  value="<?php echo $total_dramount_conv; ?>"  readonly="true"  /></td>
    <td width="13%" align="right">Total Converted Debit Amt.</td>
    <td width="20%"><input type="text" name="total_convertdramount" id="total_convertdramount"  value="<?php echo $total_cramount_conv; ?>"  readonly="true" /></td>
    <td width="13%" align="right">Converted Difference Amt.</td>
    <td><?php 
//$diff=	array_sum($total_cr)-array_sum($total_dr);
	?>
	<!--onfocus="cladifferenceamt()"-->
	<input type="text" name="convertdiff_amount" id="convertdiff_amount"   value="<?php echo ($total_dramount_conv-$total_cramount_conv); ?>"  readonly="true" /></td>
  </tr>
</table>
<br>
  <?php } ?>
<table width="100%" cellpadding="3" cellspacing="0" border="0">
  <tr class="row1">
    <td width="13%" align="right">Total Credit Amt.</td>
    <td width="20%"><input type="text" name="total_cramount" id='total_cramount'  value="<?php echo $total_dramount; ?>"  readonly="true"    /></td>
    <td width="13%" align="right">Total  Debit Amt.</td>
    <td width="20%"><input type="text" name="total_dramount" id="total_dramount" value="<?php echo $total_cramount; ?>"  readonly="true" /></td>
    <td width="13%" align="right">Difference Amt.</td>
    <td><?php 
//$diff=	array_sum($total_cr)-array_sum($total_dr);
	?>
	<input type="text" name="diff_amount"  id="credit2" readonly="true" value="<?php echo ($total_dramount-$total_cramount); ?>" /></td>
  </tr>
<tr class="row1">
    <td align="right">Narration</td>
    <td colspan="5"><textarea name="narration" id="narration" cols="95" rows="5" style="width:99%; height:50px;" ><?php echo ($narration!=''?trim($narration):'');?></textarea></td>
    </tr>
	<!--<tr class="row1">
    <td colspan="6">	<input type="button" name="profile_popup" value="Add New Ledger" class="search" id="profile_popup"/>
</td>
    </tr>-->
        </table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $d; ?>" />
<input type="hidden" name="" value="<?php echo $d; ?>" id="edit_cnt" />
<input type="hidden" name="hiditemcount1" id="hiditemcount1" value="<?php echo $c; ?>" />
<input type="hidden" name="" value="<?php echo $c; ?>" id="edit_cnt1" />
<p style="text-align:center;">
  <?php if($_REQUEST['action']=="Edit"){?>
	<input type="submit" name="Debit_note" value="Save" class="search" onclick="return validateForm();"/>
<?php } ?>
</p>
<?php 

 //if(array_sum($total_cr)==array_sum($total_dr)  && (array_sum($total_cr)!=0 && array_sum($total_dr)!=0)) {?>
  
 <?php //}?>
</form>


<?php } ?>

</div>
</div>

<script language="javascript" type="text/javascript">
function getSumT(){
	var cdsum=0;
	$("input[id^='totaldrconvPrice']").each(function(){
		cdsum += parseFloat(this.value);
	});
	
	if(isNaN(cdsum))
	{
		var cdsum=0;
	}
	$("#total_dramount").val(cdsum);
	if($("input[id^='totalcrconvPrice']").length==1)
	{
		$("input[id^='totalcrconvPrice']").val(cdsum);
		$("#total_cramount").val(cdsum);
	}
	var cdsumconv=0;
	$("input[id^='debitamount']").each(function(){
		cdsumconv += parseFloat(this.value);
	});
	if(isNaN(cdsumconv))
	{
		var cdsumconv=0;
	}
	if($("input[id^='creditamount']").length==1)
	{
		$("input[id^='creditamount']").val(cdsumconv);
		$("#total_convercramount").val(cdsumconv);
	}
	var totdr=$("#total_dramount").val();
	var totcr=$("#total_cramount").val();
	if(parseFloat(totdr)>parseFloat(totcr)){
		var diffdr=parseFloat(totdr)-parseFloat(totcr);
	}else{
		var diffdr=parseFloat(totcr)-parseFloat(totdr);
	}
	var totdrconv=$("#total_convertdramount").val();
	var totcrconv=$("#total_convercramount").val();
	if(parseFloat(totdrconv)>parseFloat(totcrconv)){
		var diffdrconv=parseFloat(totdrconv)-parseFloat(totcrconv);
	}else{
		var diffdrconv=parseFloat(totcrconv)-parseFloat(totdrconv);
	}
	$("#credit2").val(diffdr);
	$("#convertdiff_amount").val(diffdrconv);
	
	
}
function getSumT1(){
	var cdsum=0;
	$("input[id^='totalcrconvPrice']").each(function(){
		cdsum += parseFloat(this.value);
	});
	if(isNaN(cdsum))
	{
		var cdsum=0;
	}
	$("#total_cramount").val(cdsum);
	if($("input[id^='totaldrconvPrice']").length==1)
	{
		$("input[id^='totaldrconvPrice']").val(cdsum);
		$("#total_dramount").val(cdsum);
	}
	var cdsumconv=0;
	$("input[id^='creditamount']").each(function(){
		cdsumconv += parseFloat(this.value);
	});
	if(isNaN(cdsumconv))
	{
		var cdsumconv=0;
	}
	if($("input[id^='debitamount']").length==1)
	{
		$("input[id^='debitamount']").val(cdsumconv);
		$("#total_convertdramount").val(cdsumconv);
	}
	var totdr=$("#total_dramount").val();
	var totcr=$("#total_cramount").val();
	if(parseFloat(totdr)>parseFloat(totcr)){
		var diffcr=parseFloat(totdr)-parseFloat(totcr);
	}else{
		var diffcr=parseFloat(totcr)-parseFloat(totdr);
	}
	var totdrconv=$("#total_convertdramount").val();
	var totcrconv=$("#total_convercramount").val();
	if(parseFloat(totdrconv)>parseFloat(totcrconv)){
		var diffcrconv=parseFloat(totdrconv)-parseFloat(totcrconv);
	}else{
		var diffcrconv=parseFloat(totcrconv)-parseFloat(totdrconv);
	}
	$("#credit2").val(diffcr);
	$("#convertdiff_amount").val(diffcrconv);
	
	
}
function chkdteformat(obj){
var pattern =/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
  var input=$(obj).val();
  if(!pattern.test(input))
  {
      alert("Date should be in dd/mm/yyyy Format");
      $(obj).val("");
  }
}
function legend(str)
{ 
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert(xmlhttp.responseText);
		document.getElementById("ledgerdr"+str.id.substr(10)).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","ajax_leger.php?q="+str.value,true);
	xmlhttp.send();
}



function chkglobaldate(val,id)
{
	var finstyear=document.getElementById("Startfinyear").value;
	var finenyear=document.getElementById("Endfinyear").value;
	var stdate=finstyear.split("-");
	var stakdate=(stdate[2] + "/" + stdate[1] + "/" + stdate[0]);
	var enddate=finenyear.split("-");
	var Endakdate=(enddate[2] + "/" + enddate[1] + "/" + enddate[0]);
	
	
	
	var dt1  = parseInt(val.substring(0,2),10);
    var mon1 = parseInt(val.substring(3,5),10);
    var yr1  = parseInt(val.substring(6,10),10);
	
	
	var sdt1  = parseInt(stakdate.substring(0,2),10);
    var smon1 = parseInt(stakdate.substring(3,5),10);
    var syr1  = parseInt(stakdate.substring(6,10),10);
	
	
	var edt1  = parseInt(Endakdate.substring(0,2),10);
    var emon1 = parseInt(Endakdate.substring(3,5),10);
    var eyr1  = parseInt(Endakdate.substring(6,10),10);
	
	
	var stamitdate = new Date(syr1,smon1,sdt1);
	
	var endamitdate = new Date(eyr1,emon1,edt1);
	
	var requesteddate = new Date(yr1, mon1, dt1);
	
	if((requesteddate < stamitdate) || (requesteddate > endamitdate))
	{
		alert("Please Take Date Between Financial Year");
		document.getElementById(id).value='';
		document.getElementById(id).focus();
		return false;
	}

	
	//var datedat=(curr_date2 + "/" + curr_month2 + "/" + curr_year);
}



function validateForm()
{ //Please set validation
	

	//alert(document.getElementById("Voucherprefixtype").value)

	if(document.getElementById("Branch").value=='')
	{
		alert("Please select Branch First.");
		return false;
	}
	
	
	if(document.getElementById("Dates").value=="")
	{
		alert("Please enter date.");
		return false;
	}
	if(document.getElementById("Voucherprefixtype").value=='4' && document.getElementById('banks_receivedfrom').value=='')
	{
	alert("Please fill Payee name");
	document.getElementById('banks_receivedfrom').focus();
		return false;	
	}
	

  
	
	
	
	var coun=document.getElementById("hiditemcount").value;

	if(coun!='')
	{
		for(var j=1;j<=coun;j++)
		{
			if(document.getElementById("ledgerdr_"+j))
			{
			if(document.getElementById("ledgerdr_"+j).value=='0')
			{
				alert("Please Select The Debit Ledger First");
				document.getElementById("ledgerdr_"+j).focus();
				return false;
			}
			}
			if(document.getElementById("totaldrconvPrice_"+j))
			if(document.getElementById("totalcrconvPrice_"+j))
			{
				if(document.getElementById("totalcrconvPrice_"+j).value=='')
				{
					alert("Please Enter The Credit Amount First");
					document.getElementById("totalcrconvPrice_"+j).focus();
					return false;
				}
			}	
		}
	}
	
	
	
	
	
	
	
	
	var coun1=document.getElementById("hiditemcount1").value;
	if(coun1!='')
	{
		for(var j=1;j<=coun1;j++)
		{
			if(document.getElementById("ledgercrID_"+j))
			{
			if(document.getElementById("ledgercrID_"+j).value=='0')
		{
			alert("Please Select The Credit Ledger First");
			document.getElementById("ledgercrID_"+j).focus();
			return false;
		}
		}
		if(document.getElementById("creditamount_"+j))
		{
		if(document.getElementById("creditamount_"+j).value=='')
		{
			alert("Please Enter The Credit Amount First");
			document.getElementById("creditamount_"+j).focus();
			return false;
		}
		}	
		}
	}
	
	
	
	if(document.getElementById("credit2").value!=0)
	{
		alert("Sorry! Total credit is not equal to total debit");
		return false;
	}

	 if(document.getElementById("narration").value.trim()=="")
	{
		alert("Narration Required");
		return false;
	}
	
	return true;
}

function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 
function checkUpdateValidate()
{
	/*var count=document.getElementById("count_entries").value;
	alert(count);
	var dr_amt=0;
	var cr_amt=0;
	for(var i=0; i<count;i++)
	{
		var amount=document.getElementById("amount_"+i).value;
		var amount_type=document.getElementById("amount_type_"+i).value;
		alert(amount+"--"+amount_type);
		if(amount_type=='CR'){cr_amt=parseFloat(cr_amt)+parseFloat(amount);}
		else if(amount_type=='DR'){dr_amt=parseFloat(dr_amt)+parseFloat(amount);}
	}*/
	
if(parseFloat(document.getElementById("total_cramount").value)!=parseFloat(document.getElementById("total_dramount").value))
{
	alert("Sorry! Total credit is not equal to total debit");
	return false;
	}
	return true;
}

function calculateTotalCrDr()
{
	if(document.getElementById("debitamount").value!='')
	var obj1=document.getElementById("debitamount").value;
	else var obj1=0;
	
	if(document.getElementById("creditamount").value!='')
	var obj2=document.getElementById("creditamount").value;
	else
	var obj2=0;
	
	
	var count=document.getElementById("count_entries").value;
	var dr_amt=0;
	var cr_amt=0;
	for(var i=0; i<count;i++)
	{
	var amount=document.getElementById("amount_"+i).value;
	var amount_type=document.getElementById("amount_type_"+i).value;
	if(amount_type=='CR'){cr_amt=parseFloat(cr_amt)+parseFloat(amount);}
	else if(amount_type=='DR'){dr_amt=parseFloat(dr_amt)+parseFloat(amount);}
	}
	var dr_amt=parseFloat(obj1)+dr_amt;
	var cr_amt=parseFloat(obj2)+cr_amt;
	
	document.getElementById("total_cramount").value=cr_amt.toFixed(2);
	document.getElementById("total_dramount").value=dr_amt.toFixed(2);
	
	if(cr_amt>dr_amt){var diff=parseFloat(cr_amt)-parseFloat(dr_amt);}
	else if(dr_amt>cr_amt){var diff=parseFloat(dr_amt)-parseFloat(cr_amt);}else{var diff=0;}
	document.getElementById("credit2").value=diff.toFixed(2);
}




/************************************************************************************************************************/
function calcurrencyamtdr(val,id)
{  
	var n=id.split("_");
	var i=n[1];
	
	if(i==undefined)
	{
	if(document.getElementById("debitamount").value!='')
	var str=parseFloat(document.getElementById("debitamount").value);
	else
	var str=0;
	var currency1=document.getElementById("drcurrency").value;
	var currency2=document.getElementById("drcurrencyconv").value;
	
	if(currency1==currency2)
	{ 
	document.getElementById("totaldrconvPrice").value=str.toFixed(2);
	}
	else
	{ 
	var totalconverted_rate=(str*val);
	document.getElementById("totaldrconvPrice").value=totalconverted_rate.toFixed(2);
	
	
	}
	
	
	}
	else
	{
	if(document.getElementById("debitamount_"+i))
		{
		if(document.getElementById("debitamount_"+i).value!='')
		var str=parseFloat(document.getElementById("debitamount_"+i).value);
		else var str=0;
		
	var currency1=document.getElementById("drcurrency_"+i).value;
	var currency2=document.getElementById("drcurrencyconv_"+i).value;
	
			if(currency1==currency2)
			{	document.getElementById("totaldrconvPrice_"+i).value=str.toFixed(2);	}
			else	{ 	var totalconverted_rate=(str*val);
			document.getElementById("totaldrconvPrice_"+i).value=totalconverted_rate.toFixed(2);}
				
		
		
		
			}
	
	}	
}
function calcurrencyamtdr1(val,id)
{
	var n=id.split("_");
	var i=n[1];
	
	if(i==undefined)
	{
	
	if(document.getElementById("totaldrconvPrice").value!='')
	var str=parseFloat(document.getElementById("totaldrconvPrice").value);
	else
	var str=0;
	var currency1=document.getElementById("drcurrency").value;
	var currency2=document.getElementById("drcurrencyconv").value;
	
	if(currency1==currency2)
	{ 
	document.getElementById("debitamount").value=str.toFixed(2);
	}
	else
	{ 
	var totalconverted_rate=(str*val);
	document.getElementById("debitamount").value=totalconverted_rate.toFixed(2);
	
	
	}
	
	
	}
	else
	{
	if(document.getElementById("totaldrconvPrice_"+i))
		{
		if(document.getElementById("totaldrconvPrice_"+i).value!='')
		var str=parseFloat(document.getElementById("totaldrconvPrice_"+i).value);
		else var str=0;
		
	var currency1=document.getElementById("drcurrency_"+i).value;
	var currency2=document.getElementById("drcurrencyconv_"+i).value;
	
			if(currency1==currency2)
			{	document.getElementById("debitamount_"+i).value=str.toFixed(2);	}
			else	{ 	var totalconverted_rate=(str*val);
			document.getElementById("debitamount_"+i).value=totalconverted_rate.toFixed(2);}
				
		
		
		
			}
	
	}
	
	
	
}
function calcurrencyamtcr(val,id)
{
	var n=id.split("_");
	var i=n[1];
	
	if(i==undefined)
	{
	if(document.getElementById("creditamount").value!='')
	var str=parseFloat(document.getElementById("creditamount").value);
	else
	var str=0;
	var currency1=document.getElementById("crcurrency").value;
	var currency2=document.getElementById("crcurrencyconv").value;
	
	
	if(currency1==currency2)
	{
	document.getElementById("totalcrconvPrice").value=str.toFixed(2);
	}
	else
	{
	var totalconverted_rate=(str*val);
	document.getElementById("totalcrconvPrice").value=totalconverted_rate.toFixed(2);
	
	
	}
	
	
	}
	else
	{
	if(document.getElementById("creditamount_"+i))
		{
		if(document.getElementById("creditamount_"+i).value!='')
		var str=parseFloat(document.getElementById("creditamount_"+i).value);
		else var str=0;
		
	var currency1=document.getElementById("crcurrency_"+i).value;
	var currency2=document.getElementById("crcurrencyconv_"+i).value;
	
			if(currency1==currency2)
			{	document.getElementById("totalcrconvPrice_"+i).value=str.toFixed(2);	}
			else	{ 	var totalconverted_rate=(str*val);
			document.getElementById("totalcrconvPrice_"+i).value=totalconverted_rate.toFixed(2);
                    }		
		
	 }
	
	}
	
	
	
}

function calcurrencyamtcr1(val,id)
{
	var n=id.split("_");
	var i=n[1];
	
	if(i==undefined)
	{
	if(document.getElementById("totalcrconvPrice").value!='')
	var str=parseFloat(document.getElementById("totalcrconvPrice").value);
	else
	var str=0;
	var currency1=document.getElementById("crcurrency").value;
	var currency2=document.getElementById("crcurrencyconv").value;
	
	
	if(currency1==currency2)
	{
	document.getElementById("creditamount").value=str.toFixed(2);
	}
	else
	{
	var totalconverted_rate=(str*val);
	document.getElementById("creditamount").value=totalconverted_rate.toFixed(2);
	
	
	}
	
	
	}
	else
	{
	if(document.getElementById("totalcrconvPrice_"+i))
		{
		if(document.getElementById("totalcrconvPrice_"+i).value!='')
		var str=parseFloat(document.getElementById("totalcrconvPrice_"+i).value);
		else var str=0;
		
	var currency1=document.getElementById("crcurrency_"+i).value;
	var currency2=document.getElementById("crcurrencyconv_"+i).value;
	
			if(currency1==currency2)
			{	document.getElementById("creditamount_"+i).value=str.toFixed(2);	}
			else	{ 	var totalconverted_rate=(str*val);
			document.getElementById("creditamount_"+i).value=totalconverted_rate.toFixed(2);}
				
		
		
		
			}
	
	}
	
	
	
}



/*************************************************************************************************************************/


function adddebitamount(val,id)
{
	var n=id.split("_");
	var i=n[1];
   // var firstrowdebit=0;
	var t=0;
	
	var count=document.getElementById("hiditemcount").value;
	//alert(count);
			if(count=='')
			{

			if(document.getElementById("debitamount_1").value!='')
			var firstrowdebit=parseFloat(document.getElementById("debitamount_1").value);
			else
			var firstrowdebit=0;
				//var dramt=0;

			}
	

	else
	{
		var firstrowdebit=0;
	}

	for(var j=1;j<=count;j++)
	{
		if(document.getElementById("debitamount_"+j))
		{
		if(document.getElementById("debitamount_"+j).value!='')
		{
		 t=t+parseFloat(document.getElementById("debitamount_"+j).value);
		}
		else
		{
		t=t+0;
		}
		}
		
	}
	var str=t+firstrowdebit;
	

	//var str=document.getElementById("debitamount").value;
	
	
	
	
	document.getElementById("total_convertdramount").value=str.toFixed(2);
	document.getElementById("creditamount_1").value=str.toFixed(2);
	document.getElementById("total_convercramount").value=str.toFixed(2);
	var cr_amt=dramt.toFixed(2);
	//var data=addcreditamount(cr_amt,'creditamount');
	var cramt = document.getElementById("total_convercramount").value;
	var diff=parseFloat(dramt)-parseFloat(cramt)
    var data1=cladifferenceamt();
	document.getElementById("credit2").value=diff.toFixed(2);	
	
}










function addcreditamount(val,id)
{
	var n=id.split("_");
	var i=n[1];
   // var firstrowdebit=0;
	var t=0;
	var count=document.getElementById("hiditemcount1").value;
	//alert(count);
	if(count=='')
	{
	var str=parseFloat(document.getElementById("creditamount").value);
		
	}
	else
	{
	if(document.getElementById("creditamount"))
	{
	var firstrowdebit=parseFloat(document.getElementById("creditamount").value);
	}
	else
	{
	var firstrowdebit=0;	
	}
	for(var j=1;j<=count;j++)
	{	
		if(document.getElementById("creditamount_"+j))
		{
		if(document.getElementById("creditamount_"+j).value!='')
		{
		 t=t+parseFloat(document.getElementById("creditamount_"+j).value);
		}
		else
		{
		t=t+0;
		}
		}
	}
	var str=t+firstrowdebit;
	
	}
	//var cramt=0;
	var dramt = document.getElementById("total_dramount").value;
	var cramt = document.getElementById("total_cramount1").value;
	
	cramt=parseFloat(cramt)+parseFloat(str);
	//alert(cramt);
	document.getElementById("total_cramount").value=cramt.toFixed(2);
	document.getElementById("total_dramount").value=cramt.toFixed(2);
	document.getElementById("debitamount").value=cramt.toFixed(2);
	var diff=parseFloat(cramt)-parseFloat(cramt)
	document.getElementById("credit2").value=diff.toFixed(2);
	if(document.getElementById("convrate").value!='')
	var val=document.getElementById("convrate").value;
	else
	var val=1;
	var amtconvertedcr=(dramt*val);
	var amtconverteddr=(dramt*val);
	document.getElementById("total_convercramount").value=amtconverteddr.toFixed(2);
	document.getElementById("total_convertdramount").value=amtconvertedcr.toFixed(2);
	var diff1=parseFloat(amtconverteddr)-parseFloat(amtconvertedcr)
	document.getElementById("convertdiff_amount").value=diff1.toFixed(2);
	var data1=calcurrencyamtdr(val,id);
	var data2=calcurrencyamtcr(val,id);
	
}




function adddebitamount1(val,id)
{
	var n=id.split("_");
	var i=n[1];
   // var firstrowdebit=0;
	var t=0;
	
	var count=document.getElementById("hiditemcount").value;
	
	if(count=='')
	{
	if(document.getElementById("totaldrconvPrice").value!='')
	var str=parseFloat(document.getElementById("totaldrconvPrice").value);
	else
	var str=0;
		//var dramt=0;
	}
	else
	{
	if(document.getElementById("totaldrconvPrice"))
	{
	if(document.getElementById("totaldrconvPrice").value!='')
	var firstrowdebit=parseFloat(document.getElementById("totaldrconvPrice").value);
	else
	var firstrowdebit=0;
	}
	else
	{
		var firstrowdebit=0;
	}
	for(var j=1;j<=count;j++)
	{
		if(document.getElementById("totaldrconvPrice_"+j))
		{
		if(document.getElementById("totaldrconvPrice_"+j).value!='')
		{
		 t=parseFloat(t)+parseFloat(document.getElementById("totaldrconvPrice_"+j).value);
		}
		else
		{
		t=parseFloat(t)+0;
		}
		}
		
	}
	var str=parseFloat(t)+parseFloat(firstrowdebit);
	
	}
	
	//var str=document.getElementById("debitamount").value;
	
	
	
	if(str!='')
	var dramt=parseFloat(str);
	else
	var dramt=0;
	
	document.getElementById("total_convertdramount").value=dramt.toFixed(2);
	document.getElementById("totalcrconvPrice").value=dramt.toFixed(2);
	
	var cr_amt=dramt.toFixed(2);
	var data=addcreditamount1(cr_amt,'creditamount');
	var cramt = document.getElementById("total_convercramount").value;
	var diff=parseFloat(dramt)-parseFloat(cramt)
    var data1=cladifferenceamt();
	document.getElementById("convertdiff_amount").value=diff.toFixed(2);
	if(document.getElementById("convrate").value!='')
	var val=document.getElementById("convrate").value;
	else
	var val=1;
	var amtconvertedcr=(dramt*val);
	var amtconverteddr=(dramt*val);
	document.getElementById("total_cramount").value=amtconverteddr.toFixed(2);
	document.getElementById("total_dramount").value=amtconvertedcr.toFixed(2);
	var diff1=parseFloat(amtconverteddr)-parseFloat(amtconvertedcr)
	document.getElementById("credit2").value=diff1.toFixed(2);
	var data1=calcurrencyamtdr1(val,id);
	var data2=calcurrencyamtcr1(val,id);
	
}





function addcreditamount1(val,id)
{
	var n=id.split("_");
	var i=n[1];
	
   // var firstrowdebit=0;
	var t=0;
	var count=document.getElementById("hiditemcount1").value;
	//alert(count);
	if(count=='')
	{
	var str=parseFloat(document.getElementById("totalcrconvPrice").value);
		
	}
	else
	{
	if(document.getElementById("totalcrconvPrice"))
	{
	var firstrowdebit=parseFloat(document.getElementById("totalcrconvPrice").value);
	}
	else
	{
	var firstrowdebit=0;	
	}
	for(var j=1;j<=count;j++)
	{	
		if(document.getElementById("totalcrconvPrice_"+j))
		{
		if(document.getElementById("totalcrconvPrice_"+j).value!='')
		{
		 t=t+parseFloat(document.getElementById("totalcrconvPrice_"+j).value);
		}
		else
		{
		t=t+0;
		}
		}
	}
	var str=t+firstrowdebit;
	
	}
	//var cramt=0;
	var dramt = document.getElementById("total_convertdramount").value;
	var cramt = document.getElementById("total_convercramount").value;
	
	 var cramt=parseFloat(str);	
	document.getElementById("total_convercramount").value=cramt.toFixed(2);
	var diff=parseFloat(cramt)-parseFloat(dramt)
	document.getElementById("convertdiff_amount").value=diff.toFixed(2);
	if(document.getElementById("convrate").value!='')
	var val=document.getElementById("convrate").value;
	else
	var val=1;
	var amtconvertedcr=(dramt*val);
	var amtconverteddr=(dramt*val);
	document.getElementById("total_cramount").value=amtconverteddr.toFixed(2);
	document.getElementById("total_dramount").value=amtconvertedcr.toFixed(2);
	var diff1=parseFloat(amtconverteddr)-parseFloat(amtconvertedcr)
	document.getElementById("credit2").value=diff1.toFixed(2);
	var data1=calcurrencyamtdr1(val,id);
	var data2=calcurrencyamtcr1(val,id);
	
}

function getledgernameDR(str,id,event)
{
	if(event.keyCode!=9)
	{
   
	var id1=id.split("_");
	var i=id1[1];	
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		//alert(xmlhttp.responseText);
	if(i==undefined)
	{
	document.getElementById("ledgerdr").innerHTML=xmlhttp.responseText;
	}
	else
	{
	document.getElementById("ledgerdr_"+i).innerHTML=xmlhttp.responseText;
	}
	}
	}
	//var undergroup1=document.getElementById("undergroup1").value;
	var undergroup=document.getElementById("undergroup1").value;
	var site=document.getElementById("Branch").value;
	//alert(undergroup);
	xmlhttp.open("GET","searchledgerName.php?searchWord="+str+"&undergroup="+undergroup+"&site="+site,true);
	xmlhttp.send();
 
}
}


function getledgernameCR(str,id,event)
{
	if(event.keyCode!=9)
	{
	/*if(str!='')
	{*/
	var id1=id.split("_");
	var i=id1[1];	

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		//alert(xmlhttp.responseText);
	if(i==undefined)
	{
	document.getElementById("ledgercrID").innerHTML=xmlhttp.responseText;
	}
	else
	{
	document.getElementById("ledgercrID_"+i).innerHTML=xmlhttp.responseText;
	}
	}
	}
	var undergroup1=document.getElementById("undergroup2").value;
	var site=document.getElementById("Branch").value;

	xmlhttp.open("GET","searchledgerNameCR.php?searchWord="+str+"&undergroup1="+undergroup1+"&site="+site,true);
	xmlhttp.send();
  //}
  }
}

function validatebank(id)
{
	if(document.getElementById("Branch").value=='')
	{
	  alert("Please Select Branch ");
	  document.getElementById("Branch").focus();	
      document.getElementById(id).selectedIndex=0;
	}
}

function GetBankDetals(str,id)
{
	if(document.getElementById("Branch").value=='')
	{
	  alert("Please Select Branch ");
	  document.getElementById("Branch").focus();	
      document.getElementById(id).selectedIndex=0;
	}
	else
	{
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("INSNO").innerHTML=xmlhttp.responseText;
			}
		}
		var Vprefixtype=document.getElementById("Vprefixtype").value;
		xmlhttp.open("GET","ACBillbookBankDetails.php?q="+str+"&VPREFIXTYPE="+Vprefixtype,true);
		xmlhttp.send();
  }
}


function chkvoucherno(str)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("autogennos").innerHTML=xmlhttp.responseText;
	}
	}
	
	var Vprefixtype=document.getElementById("Vprefixtype").value;
	var branch=document.getElementById("Branch").value;
	xmlhttp.open("GET","chkvouno.php?Vno="+str+"&VPREFIXTYPE="+Vprefixtype+"&branch="+branch,true);
	xmlhttp.send();
}



function clacreaditamt()
{
	if(document.getElementById("creditamount"))
	{
	var firstrow=document.getElementById("creditamount").value;
	if(firstrow==''){firstrow=0;}
	}
	else
	{
	var firstrow=0;
	}
	var hidcount=document.getElementById("hiditemcount1").value;
	var total=0;
	for(var j=1;j<=hidcount;j++)
	{
		if(document.getElementById("creditamount_"+j))
		{
			var total=parseFloat(total)+parseFloat(document.getElementById("creditamount_"+j).value);
		}
	}
	var fintotal=parseFloat(total)+parseFloat(firstrow);
	document.getElementById("total_cramount").value=fintotal;
}

function cladebitamt()
{
	if(document.getElementById("debitamount"))
	{
	var firstrow=document.getElementById("debitamount").value;
	if(firstrow==''){firstrow=0;}
	}
	else
	{
	var firstrow=0;
	}
	//alert(document.getElementById("hiditemcount").value);
	var hidcount1=document.getElementById("hiditemcount").value;
	var total=0;
	
	for(var j=1;j<=hidcount1;j++)
	{
		if(document.getElementById("debitamount_"+j))
		{
			var total=parseFloat(total)+parseFloat(document.getElementById("debitamount_"+j).value);
		}
	}
	var fintotal=parseFloat(total)+parseFloat(firstrow);
	document.getElementById("total_dramount").value=fintotal;
	document.getElementById("creditamount").value=fintotal;
	document.getElementById("total_cramount").value=fintotal;
}


function cladifferenceamt()
{
	var dramt=document.getElementById("total_dramount").value;
	
	var cramt=document.getElementById("total_cramount").value;
	
	if(dramt==''){dramt=0;}
	if(cramt==''){cramt=0;}
	
	var diff=parseFloat(cramt)-parseFloat(dramt);
	document.getElementById("credit2").value=diff;
}

</script>
<script type="text/javascript" language="javascript">
//$.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		
		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#PickedItems").dialog({
				title:'Ledger Selection Popup ',
				modal: true,
				resizable: false,
				width:400,
				height:200,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO();
		});
	});
	
	
	function GetitemListForDirectPO()
    {
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","show_ledger_item.php",true);
	xmlhttp.send();
	}
	
	function showclientcode(str)
    {
	if(str!=0)
	{
	if(str=='client')
	{
	window.open("index.php?route=Client_Master&modid=9&frmid=151","_self")
	return true;
	}
	else if(str=='Vender')
	{
	window.open("index.php?route=Supplier_list&modid=9&frmid=152","_self")
	return true;
	}
	else if(str=='Ledger')
	{
	window.open("index.php?route=Account/LedgerDayBook&modid=8&frmid=23","_self")
	return true;
	}
	
	
	
	}
	else
	{
	alert("plz Select ledger type First");
	return false;
	}
	return true;
	}
	
	function showcurrency(str)
	{

	var count=document.getElementById("hiditemcount").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	
	document.getElementById("drcurrencyconv").innerHTML=xmlhttp.responseText;
	document.getElementById("crcurrencyconv").innerHTML=xmlhttp.responseText;
	for( var t=0;t<=count;t++)
		{
          if(document.getElementById("drcurrencyconv_"+t))
          {
          	 document.getElementById("drcurrencyconv_"+t).innerHTML=xmlhttp.responseText;
          }		
          if(document.getElementById("crcurrencyconv_"+t))
          {
          	 document.getElementById("crcurrencyconv_"+t).innerHTML=xmlhttp.responseText;
          }		
		}
	}
	}
	xmlhttp.open("GET","showcurrency.php?str="+str,true);
	xmlhttp.send();

	
		
	}
	
	function showcurrency1(str)
	{
	var count=document.getElementById("hiditemcount").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	
	document.getElementById("drcurrency").innerHTML=xmlhttp.responseText;
	document.getElementById("crcurrency").innerHTML=xmlhttp.responseText;
	for( var t=0;t<=count;t++)
		{
          if(document.getElementById("drcurrency_"+t))
          {
          	 document.getElementById("drcurrency_"+t).innerHTML=xmlhttp.responseText;
          }		
          if(document.getElementById("crcurrency_"+t))
          {
          	 document.getElementById("crcurrency_"+t).innerHTML=xmlhttp.responseText;
          }		
		}
	}
	}
	xmlhttp.open("GET","showcurrency1.php?str="+str,true);
	xmlhttp.send();
		
		
	}
	
	
	
	function showconvcurr(str)
	{
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("convcurrency").innerHTML=xmlhttp.responseText;
    var data1=document.getElementById("convcurrency").value;
	
	var data=showcurrency(data1);
	}
	}
	
	
	xmlhttp.open("GET","ajax_showcurrency.php?str="+str,true);
	xmlhttp.send();
	
	
	
	
	
	}
	
	function samedata(str)
	{
	//document.getElementById("banks_checkdate").value=str;
	
	}


	function getLedgerName(str,bilbooktype)
    {
	  
	  $('.modal22').show();

	   if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{

		  $('.modal22').hide();
	      // alert(xmlhttp.responseText);
		    if(bilbooktype=='CP' || bilbooktype=='BP' || bilbooktype=='VatTax'){
			document.getElementById("ledgerdr").innerHTML=xmlhttp.responseText; }
		    else if(bilbooktype=='CR' || bilbooktype=='BR'){
		    document.getElementById("ledgercrID").innerHTML=xmlhttp.responseText;
		    }
		    else if(bilbooktype=='JV' || bilbooktype=='CDN' || bilbooktype=='DBN' || bilbooktype=='MEMO' || bilbooktype=='ExDV'){
		    document.getElementById("ledgerdr").innerHTML=xmlhttp.responseText;
		    document.getElementById("ledgercrID").innerHTML=xmlhttp.responseText;
		    }
	        // var data1=document.getElementById("convcurrency").value;
		
		//var data=showcurrency(data1);
		}
	}
	 if(bilbooktype=='CP' || bilbooktype=='BP' || bilbooktype=='VatTax')
	 var undergroup=document.getElementById("undergroup1").value;
     else if(bilbooktype=='CR' || bilbooktype=='BR')
	 var undergroup=document.getElementById("undergroup2").value;
	 else 
	  var undergroup=document.getElementById("undergroup1").value;	
	//var undergroup1="/"+undergroup+"/";

	
	//alert("check_data_fin.php?section=Drledgername&site="+str+"&group="+undergroup);
	xmlhttp.open("Post","check_data_fin.php?section=Drledgername&site="+str+"&group="+undergroup,true);
	xmlhttp.send();
  
     
     
      }
function calculate_conversion(str)
{
	//alert(str.value)
	if(str.value!='')
	{
	var convrate=parseFloat(str.value);
	$('input[dramt="dramt"]').each(function(){
		if($(this).val()!='')
		{
			var row_amt=parseFloat($(this).val())*convrate;			
			var idcnt=$(this).attr('id').split('_');
			if(idcnt[1]==undefined)
			{
				$('#debitamount').val(row_amt);
			}
			else
			{
				$('#debitamount_'+idcnt[1]).val(row_amt);
			}

		}		
	})	
	$('input[cramt="cramt"]').each(function(){
		if($(this).val()!='')
		{

			var row_amt=parseFloat($(this).val())*convrate;
			var idcnt=$(this).attr('id').split('_');
			if(idcnt[1]==undefined)
			{
				$('#creditamount').val(row_amt);
			}
			else
			{
				$('#creditamount_'+idcnt[1]).val(row_amt);
			}

		}		
	})
	var tot_debit_amt=0;
	 			var tot_credit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 			tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
		 			}	 			
	 			});
	 			$('input[cramt="cramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 				//alert(tot_credit_amt)
		 			tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
		 			//alert(tot_credit_amt)
		 			}	 			
	 			})

		 		$('#total_cramount').val(tot_credit_amt);
		 		$('#total_dramount').val(tot_debit_amt);	
		 		//alert(tot_debit_amt)
		 		
		 			var con_rate1=parseFloat($('#convrate').val());
		 			$('#total_convercramount').val(con_rate1*tot_credit_amt);
		 			$('#total_convertdramount').val(con_rate1*tot_debit_amt);
	 			if(tot_credit_amt>tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_credit_amt)-parseFloat(tot_debit_amt)
	 			}
	 			else if(tot_credit_amt<tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_debit_amt)-parseFloat(tot_credit_amt)
	 			}
	 			else
	 			{
	 				var diff=0;
	 			}
	 			$('input[name="diff_amount"]').val(diff);
	 			$('input[name="convertdiff_amount"]').val(diff*con_rate1);
//$('#convertdiff_amount').val(0)
}
else
{
	var row_amt1=0;
	var row_amt2=0;
	$('input[dramt="dramt"]').each(function(){
		if($(this).val()!='')
		{
			var row_amt=$(this).val();
			 row_amt1+=parseFloat($(this).val());
			var idcnt=$(this).attr('id').split('_');
			if(idcnt[1]==undefined)
			{
				$('#debitamount').val(row_amt);
			}
			else
			{
				$('#debitamount_'+idcnt[1]).val(row_amt);
			}

		}		
	})	
	$('#total_convertdramount').val(row_amt1)
		$('input[cramt="cramt"]').each(function(){
		if($(this).val()!='')
		{
			var row_amt=$(this).val();
			row_amt2+=parseFloat($(this).val());
			var idcnt=$(this).attr('id').split('_');
			if(idcnt[1]==undefined)
			{
				$('#creditamount').val(row_amt);
			}
			else
			{
				$('#creditamount_'+idcnt[1]).val(row_amt);
			}

		}		
	})	
$('#total_convercramount').val(row_amt2)
}
}
function validate_floating(val,id)
{
   var data=id.split("_");
   var val1=parseFloat(val);
 
   if(val=="" || val1==0)
       {   //document.getElementById(id).value="";
           //document.getElementById(id).focus();
       }else{   
         document.getElementById(id).value=val1.toFixed(2);  
         //document.getElementById(id).value=Math.floor(val1 * 100) / 100;    
       }   
}
function all_calculation(str,event)
{
  if(event.keyCode!=9)
  {
	 	//alert("jhbjjkn");
	 	//alert($('#conv_check').val())
	 	//alert($(str).parent().prev().find('select').attr('class'));
	 	var dr=0;
	 	var cr=0;
	 	if($('#multipledr').length > 0)
	 	{
	 		 dr=1;
	 	}
	 	if($('#multiplecr').length > 0)
	 	{
	 		 cr=1;
	 	}
	 	if($('#conv_check').val()==1)
	 	{
	 	
	 	
	 	if(dr==1 && cr==1)
	 	{
	 		
	 		
	 		//alert($(str).closest('tr').find('td:eq(3)').find('select').attr('class'));
	 		//var $class=$(str).parent().prev().find('select').attr('class').split(' ');
	 		var $class=$(str).closest('tr').find('td:eq(3)').find('select').attr('class').split(' ');
	 		//alert($class[2])
	 		//alert("manoj");
	 		//alert(str.id)
	 		if($class[2]=='debitledger')
	 		{
	 			if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 			var row_cnt=str.id.split('_');
	 			if(str.value!='')
	 			var dr_amt=parseFloat(str.value);
	 		    else
	 		    var dr_amt=0;	
	 			var con_rate=parseFloat($('#convrate').val());
	 			var row_amt_wo=parseFloat(dr_amt*con_rate);
	 			var row_amt=row_amt_wo.toFixed(2);
	 			if(row_cnt[1]==undefined)
	 			{
	 				$('#debitamount').val(row_amt)
	 			}
	 			else
	 			{
					$('#debitamount_'+row_cnt[1]).val(row_amt)
	 			}
	 			
	 		}
	 		else if($class[2]=='creditledger')
	 		{
	 			if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 			var row_cnt=str.id.split('_');
	 			if(str.value!='')
	 			var cr_amt=parseFloat(str.value);
	 		    else
	 		    var cr_amt=0;
	 			var con_rate=parseFloat($('#convrate').val());
	 			var row_amt_wo=parseFloat(cr_amt*con_rate);
	 			var row_amt=row_amt_wo.toFixed(2);
	 			if(row_cnt[1]==undefined)
	 			{
	 				$('#creditamount').val(row_amt)
	 			}
	 			else
	 			{
					$('#creditamount_'+row_cnt[1]).val(row_amt)
	 			}

	 		}

	 		var tot_debit_amt=0;
	 			var tot_credit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 			tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
		 			}	 			
	 			});
	 			$('input[cramt="cramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 				//alert(tot_credit_amt)
		 			tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
		 			//alert(tot_credit_amt)
		 			}	 			
	 			})

		 		$('#total_cramount').val(tot_credit_amt.toFixed(2));
		 		$('#total_dramount').val(tot_debit_amt.toFixed(2));	
		 		//alert(tot_debit_amt)
		 		
		 			var con_rate1=parseFloat($('#convrate').val());
		 			$('#total_convercramount').val(parseFloat(con_rate1*tot_credit_amt).toFixed(2));
		 			$('#total_convertdramount').val(parseFloat(con_rate1*tot_debit_amt).toFixed(2));
	 			if(tot_credit_amt>tot_debit_amt)
	 			{
	 				var diff_wo=parseFloat(tot_credit_amt)-parseFloat(tot_debit_amt);
	 				var diff=diff_wo.toFixed(2);
	 			}
	 			else if(tot_credit_amt<tot_debit_amt)
	 			{
	 				var diff_wo=parseFloat(tot_debit_amt)-parseFloat(tot_credit_amt);
	 				var diff=diff_wo.toFixed(2);
	 			}
	 			else
	 			{
	 				var diff=0;
	 			}
	 			$('input[name="diff_amount"]').val(diff);
	 			$('input[name="convertdiff_amount"]').val(parseFloat(diff*con_rate).toFixed(2));
	 	}
	 	else if(dr==1 && cr==0)
	 	{
	 		//alert("dr")
	 		$('input[cramt="cramt"]').attr('readonly','true');
	 		if($('#convrate').val()=='')
	 		{ $('#convrate').val(1); }
	 		//var dr_amt=parseFloat(str.value);
	 		if(str.value!='')
	 			var dr_amt=parseFloat(str.value);
	 		    else
	 		    var dr_amt=0;	
	 		var con_rate=parseFloat($('#convrate').val());
	 		//alert(str.value)
	 		var cntr=str.id.split('_');
	 		var row_amt_wo=parseFloat(dr_amt*con_rate);
	 		var row_amt=row_amt_wo.toFixed(2);
	 		
	 			if(cntr[1]==undefined)
	 			{
	 				$('#debitamount').val(row_amt)
	 			}
	 			else
	 			{
	 				$('#debitamount_'+cntr[1]).val(row_amt)
	 			}
	 			var tot_debit_conv_amt=0;
	 		$('input[name="dramount[]"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_debit_conv_amt=parseFloat($(this).val())+parseFloat(tot_debit_conv_amt);
	 			}	 			
	 		})
	 		$('input[name="cramount[]"]').val(tot_debit_conv_amt);
	 		var tot_debit_amt=0;
	 		$('input[dramt="dramt"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 			}	 			
	 		})
	 		$('input[cramt="cramt"]').val(tot_debit_amt.toFixed(2));
	 		$('#creditamount').val(con_rate*tot_debit_amt.toFixed(2));
	 		$('#total_cramount').val(tot_debit_amt.toFixed(2));
	 		$('#total_dramount').val(tot_debit_amt.toFixed(2));
	 		$('input[name="diff_amount"]').val(0);
	 		var tot_con_amt=con_rate*tot_debit_amt;
	 		$('#total_convertdramount').val(tot_con_amt.toFixed(2));
	 		$('#total_convercramount').val(tot_con_amt.toFixed(2));
	 		$('input[name="convertdiff_amount"]').val(0);
	 	}
	 	else if(dr==0 && cr==1)
	 	{
	 		$('input[dramt="dramt"]').attr('readonly','true');
	 		if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 		if(str.value!='')
	 		var cr_amt=parseFloat(str.value);
	 	else
	 		var cr_amt=0;
	 		var con_rate=parseFloat($('#convrate').val());
	 		//alert(str.value)
	 		var cntr=str.id.split('_');
	 		var row_amt=parseFloat(cr_amt*con_rate);
	 		//alert(row_amt)
	 		if(cntr[1]==undefined)
	 			{
	 				$('#creditamount').val(row_amt.toFixed(2))
	 			}
	 			else
	 			{
	 				$('#creditamount_'+cntr[1]).val(row_amt.toFixed(2))
	 			}
	 			var tot_credit_conv_amt=0;
	 			$('input[name="cramount[]"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_credit_conv_amt=parseFloat($(this).val())+parseFloat(tot_credit_conv_amt);
	 			}	 			
	 		})
	 			$('input[name="dramount[]"]').val(tot_credit_conv_amt.toFixed(2));
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 			}	 			
	 		})
	 		$('input[dramt="dramt"]').val(tot_credit_amt.toFixed(2));
	 		$('#total_cramount').val(tot_credit_amt.toFixed(2));
	 		$('#total_dramount').val(tot_credit_amt.toFixed(2));
	 		$('input[name="diff_amount"]').val(0);
	 		var tot_con_amt=con_rate*tot_credit_amt;
	 		$('#total_convertdramount').val(tot_con_amt.toFixed(2));
	 		$('#total_convercramount').val(tot_con_amt.toFixed(2));
	 		$('input[name="convertdiff_amount"]').val(0);
	 	}
		 	else if(dr==0 && cr==0)
		 	{


		 		if($('#convrate').val()=='')
		 			{ $('#convrate').val(1); }	
		 		//alert($(str).parent().prev().find('select').attr('id'));
		 		//$(str).closest('tr').find('td:eq(3)').find('select')
		 		//if($(str).parent().prev().find('select').attr('id')=='ledgerdr')
		 		if($(str).closest('tr').find('td:eq(3)').find('select').attr('id')=='ledgerdr_1')
		 		{
		 			if(str.value!='')
		 			var dr_amt=parseFloat(str.value);
		 		    else
		 		    var dr_amt=0;	
		 			var con_rate=parseFloat($('#convrate').val());
					var row_amt=parseFloat(dr_amt*con_rate.toFixed(2));
						$('#creditamount_1').val(row_amt.toFixed(2));
						$('#debitamount_1').val(row_amt.toFixed(2))
						$('input[cramt="cramt"]').val(dr_amt.toFixed(2));	
						$('#total_cramount').val(dr_amt.toFixed(2));
		 				$('#total_dramount').val(dr_amt.toFixed(2));
		 				$('input[name="diff_amount"]').val(0);	
		 				$('#total_convertdramount').val(row_amt.toFixed(2));
		 				$('#total_convercramount').val(row_amt.toFixed(2));
		 				$('input[name="convertdiff_amount"]').val(0);
		 		}
		 		else if($(str).closest('tr').find('td:eq(3)').find('select').attr('id')=='ledgercrID_1')
		 		{
		 			if(str.value!='')
		 			var cr_amt=parseFloat(str.value);
		 		else
		 			var cr_amt=0;
		 			var con_rate=parseFloat($('#convrate').val());
		 			//alert("cr")
					var row_amt=parseFloat(cr_amt*con_rate);
						$('#creditamount_1').val(row_amt.toFixed(2));
						$('#debitamount_1').val(row_amt.toFixed(2))
						$('input[dramt="dramt"]').val(cr_amt.toFixed(2));
						$('#total_cramount').val(cr_amt.toFixed(2));
		 				$('#total_dramount').val(cr_amt.toFixed(2));
		 				$('input[name="diff_amount"]').val(0);
		 				$('#total_convertdramount').val(row_amt.toFixed(2));
		 				$('#total_convercramount').val(row_amt.toFixed(2));
		 				$('input[name="convertdiff_amount"]').val(0);
		 		}

		 	
		 	}
	 	}
	 	else
	 	{
	 		if(dr==1 && cr==0)
	 		{
	 			$('input[cramt="cramt"]').attr('readonly','true');
	 			var tot_debit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 				}
	 			})
	 			//tot_debit_amt=tot_debit_amt.toFixed(2)
	 			$('input[cramt="cramt"]').val(tot_debit_amt.toFixed(2));
	 			$('#total_cramount').val(tot_debit_amt.toFixed(2));
	 				$('#total_dramount').val(tot_debit_amt.toFixed(2));
	 			$('input[name="diff_amount"]').val(0);
	 		} 
	 		else if(dr==0 && cr==1)
	 		{
	 			$('input[dramt="dramt"]').attr('readonly','true');
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 				}
	 			})
	 			
	 			$('input[dramt="dramt"]').val(tot_credit_amt.toFixed(2));
	 			$('#total_cramount').val(tot_credit_amt.toFixed(2));
	 				$('#total_dramount').val(tot_credit_amt.toFixed(2));
	 			$('input[name="diff_amount"]').val(0);
	 		}
	 		else if(dr==1 && cr==1)
	 		{
	 			var tot_debit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 				}
	 			})
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 				}
	 			})
	 			$('#total_cramount').val(tot_credit_amt.toFixed(2));
	 				$('#total_dramount').val(tot_debit_amt.toFixed(2));

				if(tot_credit_amt>tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_credit_amt)-parseFloat(tot_debit_amt)
	 			}
	 			else if(tot_credit_amt<tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_debit_amt)-parseFloat(tot_credit_amt)
	 			}
	 			else
	 			{
	 				var diff=0;
	 			}
	 			$('input[name="diff_amount"]').val(diff);
	 		}
	 		else if(dr==0 && cr==0)
	 		{
	 			if($(str).parent().prev().find('select').attr('id')=='ledgerdr')
	 			{
	 				$('input[cramt="cramt"]').val(str.value);
	 				$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);
	 			}
	 			else
	 			{
	 				$('input[dramt="dramt"]').val(str.value);
	 				$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);
	 			}
	 		}

	 	}
	 }
 }    
/*function all_calculation(str)
	 {
	 	//alert("jhbjjkn");
	 	//alert($('#conv_check').val())
	 	var dr=0;
	 	var cr=0;
	 	if($('#multipledr').length > 0)
	 	{
	 		 dr=1;
	 	}
	 	if($('#multiplecr').length > 0)
	 	{
	 		 cr=1;
	 	}
	 	if($('#conv_check').val()==1)
	 	{
	 	
	 	
	 	if(dr==1 && cr==1)
	 	{
	 		//alert($(str).parent().prev().find('select').prop('id'))
	 		var $class=$(str).parent().prev().find('select').attr('class').split(' ');
	 		//alert($class[2])
	 		//alert(str.id)
	 		if($class[2]=='debitledger')
	 		{
	 			if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 			var row_cnt=str.id.split('_');
	 			var dr_amt=parseFloat(str.value);
	 			var con_rate=parseFloat($('#convrate').val());
	 			var row_amt=parseFloat(dr_amt*con_rate);
	 			if(row_cnt[1]==undefined)
	 			{
	 				$('#debitamount').val(row_amt)
	 			}
	 			else
	 			{
					$('#debitamount_'+row_cnt[1]).val(row_amt)
	 			}
	 			
	 		}
	 		else if($class[2]=='creditledger')
	 		{
	 			if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 			var row_cnt=str.id.split('_');
	 			var cr_amt=parseFloat(str.value);
	 			var con_rate=parseFloat($('#convrate').val());
	 			var row_amt=parseFloat(cr_amt*con_rate);

	 			if(row_cnt[1]==undefined)
	 			{
	 				$('#creditamount').val(row_amt)
	 			}
	 			else
	 			{
					$('#creditamount_'+row_cnt[1]).val(row_amt)
	 			}

	 		}

	 		var tot_debit_amt=0;
	 			var tot_credit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 			tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
		 			}	 			
	 			});
	 			$('input[cramt="cramt"]').each(function(){
		 			if($(this).val()!='')
		 			{
		 				//alert(tot_credit_amt)
		 			tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
		 			//alert(tot_credit_amt)
		 			}	 			
	 			})

		 		$('#total_cramount').val(tot_credit_amt);
		 		$('#total_dramount').val(tot_debit_amt);	
		 		//alert(tot_debit_amt)
		 		
		 			var con_rate1=parseFloat($('#convrate').val());
		 			$('#total_convercramount').val(con_rate1*tot_credit_amt);
		 			$('#total_convertdramount').val(con_rate1*tot_debit_amt);
	 			if(tot_credit_amt>tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_credit_amt)-parseFloat(tot_debit_amt)
	 			}
	 			else if(tot_credit_amt<tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_debit_amt)-parseFloat(tot_credit_amt)
	 			}
	 			else
	 			{
	 				var diff=0;
	 			}
	 			$('input[name="diff_amount"]').val(diff);
	 			$('input[name="convertdiff_amount"]').val(diff*con_rate);
	 	}
	 	else if(dr==1 && cr==0)
	 	{
	 		//alert("dr")
	 		$('input[cramt="cramt"]').attr('readonly','true');
	 		if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 		var dr_amt=parseFloat(str.value);
	 		var con_rate=parseFloat($('#convrate').val());
	 		//alert(str.value)
	 		var cntr=str.id.split('_');
	 		var row_amt=parseFloat(dr_amt*con_rate);
	 		
	 			if(cntr[1]==undefined)
	 			{
	 				$('#debitamount').val(row_amt)
	 			}
	 			else
	 			{
	 				$('#debitamount_'+cntr[1]).val(row_amt)
	 			}
	 			var tot_debit_conv_amt=0;
	 		$('input[name="dramount[]"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_debit_conv_amt=parseFloat($(this).val())+parseFloat(tot_debit_conv_amt);
	 			}	 			
	 		})
	 		$('input[name="cramount[]"]').val(tot_debit_conv_amt);
	 		var tot_debit_amt=0;
	 		$('input[dramt="dramt"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 			}	 			
	 		})	 		
	 		$('input[cramt="cramt"]').val(tot_debit_amt);
	 		$('#creditamount_1').val(con_rate*tot_debit_amt);
	 		$('#total_cramount').val(tot_debit_amt);
	 		$('#total_dramount').val(tot_debit_amt);
	 		$('input[name="diff_amount"]').val(0);
	 		var tot_con_amt=con_rate*tot_debit_amt;
	 		$('#total_convertdramount').val(tot_con_amt);
	 		$('#total_convercramount').val(tot_con_amt);
	 		$('input[name="convertdiff_amount"]').val(0);
	 	}
	 	else if(dr==0 && cr==1)
	 	{

	 		$('input[dramt="dramt"]').attr('readonly','true');
	 		if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }
	 		var cr_amt=parseFloat(str.value);
	 		var con_rate=parseFloat($('#convrate').val());
	 		//alert(str.value)
	 		var cntr=str.id.split('_');
	 		var row_amt=parseFloat(cr_amt*con_rate);
	 		
	 		if(cntr[1]==undefined)
	 			{
	 				$('#creditamount').val(row_amt)
	 			}
	 			else
	 			{
	 				//alert(row_amt);

	 				$('#creditamount_'+cntr[1]).val(row_amt)
	 			}
	 			var tot_credit_conv_amt=0;
	 			$('input[name="cramount[]"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_credit_conv_amt=parseFloat($(this).val())+parseFloat(tot_credit_conv_amt);
	 			}	 			
	 		});
	 			//alert(tot_credit_conv_amt);
	 			$('input[name="dramount[]"]').val(tot_credit_conv_amt);
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 			if($(this).val()!='')
	 			{
	 			tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 			}	 			
	 		})
	 		$('input[dramt="dramt"]').val(tot_credit_amt);
	 		$('#total_cramount').val(tot_credit_amt);
	 		$('#total_dramount').val(tot_credit_amt);
	 		$('input[name="diff_amount"]').val(0);
	 		var tot_con_amt=con_rate*tot_credit_amt;
	 		$('#total_convertdramount').val(tot_con_amt);
	 		$('#total_convercramount').val(tot_con_amt);
	 		$('input[name="convertdiff_amount"]').val(0);
	 	}
	 	else if(dr==0 && cr==0)
	 	{
	 		if($('#convrate').val()=='')
	 			{ $('#convrate').val(1); }	
	 		//alert($(str).parent().prev().find('select').attr('id'));
	 		if($(str).parent().prev().find('select').attr('id')=='ledgerdrID')
	 		{
	 			var dr_amt=parseFloat(str.value);
	 			var con_rate=parseFloat($('#convrate').val());
				var row_amt=parseFloat(dr_amt*con_rate);
					$('#creditamount').val(row_amt);
					$('#debitamount').val(row_amt)
					$('input[cramt="cramt"]').val(str.value);	
					$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);	
	 				$('#total_convertdramount').val(row_amt);
	 				$('#total_convercramount').val(row_amt);
	 				$('input[name="convertdiff_amount"]').val(0);
	 		}
	 		else if($(str).parent().prev().find('select').attr('id')=='ledgercrID')
	 		{
	 			var cr_amt=parseFloat(str.value);
	 			var con_rate=parseFloat($('#convrate').val());
	 			//alert("cr")
				var row_amt=parseFloat(cr_amt*con_rate);
					$('#creditamount').val(row_amt);
					$('#debitamount').val(row_amt)
					$('input[dramt="dramt"]').val(str.value);
					$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);
	 				$('#total_convertdramount').val(row_amt);
	 				$('#total_convercramount').val(row_amt);
	 				$('input[name="convertdiff_amount"]').val(0);
	 		}

	 	}
	 	}
	 	else
	 	{
	 		if(dr==1 && cr==0)
	 		{
	 			$('input[cramt="cramt"]').attr('readonly','true');
	 			var tot_debit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 				}
	 			})
	 			tot_debit_amt=tot_debit_amt.toFixed(2)
	 			$('input[cramt="cramt"]').val(tot_debit_amt);
	 			$('#total_cramount').val(tot_debit_amt);
	 				$('#total_dramount').val(tot_debit_amt);
	 			$('input[name="diff_amount"]').val(0);
	 		} 
	 		else if(dr==0 && cr==1)
	 		{
	 			$('input[dramt="dramt"]').attr('readonly','true');
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 				}
	 			})
	 			tot_credit_amt=tot_credit_amt.toFixed(2)
	 			$('input[dramt="dramt"]').val(tot_credit_amt);
	 			$('#total_cramount').val(tot_credit_amt);
	 				$('#total_dramount').val(tot_credit_amt);
	 			$('input[name="diff_amount"]').val(0);
	 		}
	 		else if(dr==1 && cr==1)
	 		{
	 			var tot_debit_amt=0;
	 			$('input[dramt="dramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_debit_amt=parseFloat($(this).val())+parseFloat(tot_debit_amt);
	 				}
	 			})
	 			var tot_credit_amt=0;
	 			$('input[cramt="cramt"]').each(function(){
	 				
	 				if($(this).val()!='')
	 				{
	 					tot_credit_amt=parseFloat($(this).val())+parseFloat(tot_credit_amt);
	 				}
	 			})
	 			$('#total_cramount').val(tot_credit_amt);
	 				$('#total_dramount').val(tot_debit_amt);

				if(tot_credit_amt>tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_credit_amt)-parseFloat(tot_debit_amt)
	 			}
	 			else if(tot_credit_amt<tot_debit_amt)
	 			{
	 				var diff=parseFloat(tot_debit_amt)-parseFloat(tot_credit_amt)
	 			}
	 			else
	 			{
	 				var diff=0;
	 			}
	 			$('input[name="diff_amount"]').val(diff);
	 		}
	 		else if(dr==0 && cr==0)
	 		{
	 			if($(str).parent().prev().find('select').attr('id')=='ledgerdrID')
	 			{
	 				$('input[cramt="cramt"]').val(str.value);
	 				$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);
	 			}
	 			else
	 			{
	 				$('input[dramt="dramt"]').val(str.value);
	 				$('#total_cramount').val(str.value);
	 				$('#total_dramount').val(str.value);
	 				$('input[name="diff_amount"]').val(0);
	 			}
	 		}

	 	}
	 }
        */
</script>

