<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);

if (!function_exists('ConvertCurrency')) {
	function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
	{
		$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
		$result = selectData($connection, $query);
		//echo $query;
		Return	$result[0];

	}
}

if (!empty($_GET["action"])) {
	$dftorderby   = $_GET["dftorderby"];
	$action 	  = $_GET["action"];
	$orderby 	  = $_GET["orderby"];
	$morelines	  = $_GET["morelines"];
	$startrange   = $_GET["startrange"];
	$perpage 	  = $_GET["perpage"];
	$totalrows    = $_GET["totalrows"];
	$direction    = $_GET["direction"];
	$filepath     = $_GET["filepath"];
	$transid      = $_GET["transid"];
	$transdtid    = $_GET["transdtid"];
	$form      	  = $_GET["form"];
	
	
	
	include("config.inc.php");
	include("Functions_Sales.php");
	
	$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
	mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
	
    if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
        mysql_query("SET NAMES 'utf8'"); 
        mysql_query('SET CHARACTER SET utf8'); 
        mysql_set_charset('utf8', $connection);
    }


	//echo $_SESSION['dbName']."<br>";
	if ($form == 'TRS-1') {
		$actions = explode("-",$action);
		$type = $actions[1];
		
		$ParamSessionName  = 'gtrs_parameters'.$type;
		$AccessSessionName = 'gtrs_arrayaccess'.$type;
		ShowTransDtGrid($connection,$form,$transid,$_SESSION[$ParamSessionName],$_SESSION[$AccessSessionName],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);	
	}
	else if ($form == 'TRS-2') {
		$actions = explode("-",$action);
		$type = $actions[1];
		
		$ParamSessionName  = 'gtrs_parameters'.$type;
		$AccessSessionName = 'gtrs_arrayaccess'.$type;
		ShowTransDtGrid2($connection,$form,$transid,$_SESSION[$ParamSessionName],$_SESSION[$AccessSessionName],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);	
	}
	else if ($form == 'TRS-TOT') {
		ShowTransTotals($connection,$transid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess'],$_SESSION['query_labels']);
	}
	else if (strpos($form,'TRS-D') !== false) {
		$divtype = strtoupper(trim($form,'TRS-D-')); 
		ShowTransDtGridDivisions($connection,$form,$transid,$transdtid,$divtype,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);	
	}
	else if (strpos($form,'TRS-2-D') !== false) {
		$divtype = strtoupper(trim($form,'TRS-2-D-')); 
		ShowTransDtGridDivisions2($connection,$form,$transid,$transdtid,$divtype,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);	
	}
	else if ($form == 'TRS-C') {
		ShowTransDtGridChecks($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	}
	else if ($form == 'TRS-2-C') {
		ShowTransDtGridChecks2($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	}	
	else if ($form == 'TRS-B') {
		ShowTransDtGridBills($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	}
	else if ($form == 'TRS-2-B') {
		ShowTransDtGridBills2($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	}
	else if ($form == 'TRS-I') {
		ShowTransDtGridInvoices($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	}
	else if ($form == 'TRS-2-I') {
		ShowTransDtGridInvoices2($connection,$form,$transid,$transdtid,$_SESSION['gtrs_parameters'],$_SESSION['gtrs_arrayaccess']);
	} 
	
}

function ShowTransDtGrid($connection,$form,$PTransId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction,$query_labels){
	
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels    = mysql_fetch_array($result_labels);
	extract($row_labels);
	$DecimalBase  					= $arrayparams['DecimalBase'];
	$DecimalBase1 					= $arrayparams['DecimalBase1'];
	$DecimalBase2 					= $arrayparams['DecimalBase2'];
	$DefaultCur   					= $arrayparams['DefaultCur'];
	$Base1 							= $arrayparams['Base1'];
	$Base2 							= $arrayparams['Base2'];
	
	$Module_Project 				= $arrayparams['Module_Project'];
	$Module_CostCenter 				= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost 		= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 			= $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView		= $arrayparams['Module_TransStandardView'];
	$Module_ShowBalance 			= $arrayparams['Module_ShowBalance'];
	$ModuleRestrictCashType 		= $arrayparams['ModuleRestrictCashType'];
    $Module_MultiCashType 			= $arrayparams['Module_MultiCashType'];
    $Module_Form_Trans 			    = $arrayparams['Module_Form_Trans'];
    $Module_Trans_Desc1 			    = $arrayparams['Module_Trans_Desc1'];
	
	$Module_ProjectDt 				= $arrayparams['Module_ProjectDt'];
	$Module_ReferenceByCostCenter 	= $arrayparams['Module_ReferenceByCostCenter'];
	$Module_CostCenterDt 			= $arrayparams['Module_CostCenterDt'];
	$module_ledgerrestrictcur		= $arrayparams['module_ledgerrestrictcur'];
	$Hide_ValueDate		 			= $arrayparams['Hide_ValueDate'];
	$Hide_Base2			 			= $arrayparams['Hide_Base2'];
	
	$txtDate   						= $arrayparams['txtDate'];
	$TransType  					= $arrayparams['TransType'];
	$Type_dbcd  					= $arrayparams['Type_dbcd1'];
	$TypeIndex  					= $arrayparams['TypeIndex'];
	$ErrorRecId 					= $arrayparams['ErrorRecId'];
	$GridID     					= $arrayparams['GridID1'];
	$showRate						= $arrayparams['showRate'];
	
	$showCheckNo_RV					= $arrayparams['showCheckNo_RV'];
		
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	
	$i = 0;
	
	if ($startrange=='') $startrange 	= 0;
	if ($perpage=='')	 $perpage 		= 1000;
	if ($orderby=='')	 $orderby 		= $dftorderby;
	if ($morelines=='')	 $morelines 	= 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') 		$direction = 'desc';
		else if ($direction == 'desc') 	$direction = 'asc';
		else							$direction = 'asc';
	}
	
		
	$columnsarray = array("ledgernumber", "ledgername", "transdtdesc");
	if ($showRate == 1)
		array_push($columnsarray, "transdtrate");
	array_push($columnsarray, "currencycode");
	array_push($columnsarray, "transdtamount");
	array_push($columnsarray, "transdtamount1");
	if ($Hide_Base2 == 0) array_push($columnsarray, "transdtamount2");
	if ($Hide_ValueDate == 0) array_push($columnsarray, "transdtvaluedate");
	array_push($columnsarray, "transdtmanualno");
	if ($TransType == 'RV') array_push($columnsarray, "clientdtcode");
	if ($showCheckNo_RV == 1) array_push($columnsarray, "transdtcheckno");
	array_push($columnsarray, "transdtdesc1");
	
	$columnsarrayall = array("ledgernumber", "ledgername", "transdtdesc", "transdtdesc1", "transdtamount", "transdtamount1");  
	if ($Hide_Base2 == 0) array_push($columnsarrayall, "transdtamount2");
	if ($Hide_ValueDate == 0) array_push($columnsarrayall, "transdtvaluedate");
	array_push($columnsarrayall, "transdtmanualno", "transdtid");
	
	$orderbyarray = array("Ledger.Ledger_Number", "Ledger.Ledger_Name", "TransDt.TransDt_Description", "TransDt.TransDt_Description2" );
	if ($Hide_ValueDate == 0) array_push($orderbyarray,"TransDt.TransDt_ValueDate");
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
		
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

	
	
	$query = " Select TransDt.TransDt_id, TransDt.Trans_id, Ledger.Ledger_Number, Ledger.Ledger_Name, TransDt.TransDt_Description, TransDt.TransDt_Description2, ".
			 " TransDt_dbcd, Round(ifNull(Transdt_Amount,0), ".$DecimalBase."), Round(ifNull(Transdt_Amount1,0), ".$DecimalBase1."),".
			 " Round(ifNull(Transdt_Amount2,0), ".$DecimalBase2."), date_format(TransDt_ValueDate,'%d/%m/%Y'), TransDt.currency_code, TransDt.TransDt_ManualNo, ".
			 " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0), ClientsDetail.Detail_Code, ClientsDetail.Detail_Name, transdt_rate, ".
			 " transdt_checkNo ".
			 " From Temp_TransDt As TransDt ".
			 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
			 " Left Join ClientsDetail on TransDt.Detail_Code = ClientsDetail.Detail_Code ".
			 " Where TransDt.Trans_ID = ".$PTransId;
			 
	if ($Type_dbcd != -1) $query .= " And TransDt.TransDt_dbcd = '".$Type_dbcd."' ";
	
	$query .= " Order By $orderby $direction ";
	
	//echo $query; exit;
			
	$result=mysql_query($query,$connection);
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	$result=mysql_query($query,$connection);
	
	/// grid Motion
		$Motion = 1;
		if ($Module_ReferenceByCostCenter == 1 || ($Module_ReferenceByCostCenter == 0 && $Module_Project == 0 && $Module_ProjectDt == 0
			&& $Module_CostCenter == 0 && $Module_CostCenterDt == 0)){
			$NextCell = "ledgernumber[1]";
			$TabIndex = 0 ;
		}
		else if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)){
			$NextCell = 'projectcodedt[0]';
			$TabIndex = 0 ;
			
			}
		else {
				$NextCell = 'chkjournumber[0]';	
				$TabIndex = 0 ;
				
			}	
	
	
	
	/////////////
	
	
	
	//Initializations for Div Ids
	$ContainerDiv = 'container1';
	$LoaderDiv    = 'Loader1';
	$HeaderDiv    = 'grid_headerDiv1';
	$ContentDiv   = 'grid_contentDiv1';
	$TableFocus   = 'table-focus-g1';
	
	$TableWidth = '1200px;';
	if ($TransType == 'RV') $TableWidth = '1520px;';
	
		
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	if($Module_Form_Trans == 1){
        if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)
            echo "	<div id='datagrid-1-d' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:4px solid gray;margin-top:10px;margin-left:10px'></div>";
        // if($Module_Checks == 1)
        //     echo "	<div id='datagrid-1-c' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;'>;
        if($Module_bill==1)
            echo "	<div id='datagrid-1-b' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:4px solid gray;margin-top:10px;margin-left:10px'></div>";
        if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)
            echo "	<div id='datagrid-1-i' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:4px solid gray;margin-top:10px;margin-left:10px'></div>";
    }
    echo"	<div id='$LoaderDiv' class=''><div></div></div>";
    if($Module_Form_Trans == 0){
        $headerDivWidth = '783px';
    }else{
        $headerDivWidth = '1096px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$headerDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='0' style='width:$TableWidth'>";
	if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px';
		echo"<tr height='20px;'  >";
		echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		echo"  <th width='$wdth;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','Ledger.Ledger_Number','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ><span>$LedgerNo". $orderimg1."</span><span class='style2'>*</span></th>";
		echo"  <th width='200px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','Ledger.Ledger_Name','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ><span >$LedgerName". $orderimg2."</span></th>";
		echo"  <th width='300px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ><span >$Descr". $orderimg3."</span></th>";
		if($showCheckNo_RV == 1)
			echo"  <th width='85px;' align='center' ><span >Check Number</span></th>";
		if ($showRate == 1)
			echo"  <th width='60px;' align='center' ><span >Rate</span></th> ";	
		echo"  <th width='60px;' align='center' ><span >$Curr</span></th> ";	
		echo"  <th width='85px;' align='center' ><span >$Amount</span></th>";
		echo"  <th width='85px;' align='center' ><span >".$Base1."</span></th> ";
		if ($Hide_Base2 == 0) echo"  <th width='85px;' align='center' ><span >".$Base2."</span></th>";
		if ($Hide_ValueDate == 0) echo"  <th width='70px;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_ValueDate','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ><span >$ValueDate". $orderimg5."</span></th>";
		echo"  <th width='105px;' align='center' ><span >$ManualNo</span></th> ";
		
		if ($TransType == 'RV'){
			echo"  <th width='115px;' align='center' ><span >$DetailCode</span></th> ";
			echo"  <th width='205px;' align='center' ><span >$Name</span></th> ";	
        }

        if($Module_Trans_Desc1 == 1)
        echo"  <th width='205px;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_Description2','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>$Descr 1". $orderimg4."</span></th>";

		if($Module_Form_Trans == 1){
            if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)   
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            // if($Module_Checks == 1)
            //     echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            if($Module_bill==1)
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)            
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
        }
		
        echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $contentDivWidth = '800px';
        }else{
            $contentDivWidth = '1113px';
		}
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$contentDivWidth;height:135px;' >";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:$TableWidth;'>";
		echo"<input type='hidden' name='SelectedRec_G1' id='SelectedRec_G1' value='$SelectedRec_G1'>
			 <input type='hidden' name='SelectedRecColor_G1' id='SelectedRecColor_G1' value='$SelectedRecColor_G1'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>"; 
		
		$nc = mysql_num_rows($result);
		if ($NextCell == "ledgernumber[1]" && $nc != ''){
			$NextCell = "ledgernumber[$nc]";
		}
			 
		if ($PTransId != '' ) {
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				if ($ErrorRecId != "" && $ErrorRecId == $rowsdt[0]) $bgcolor='bgcolor3';
					
				$querycurrency="select currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
			
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
				
				$ShowDetail = 0;
				if ($TransType == 'RV'){
					$sub_query = " SELECT ifNull(Clients.Client_Detail,0) ".
								 " FROM Clients WHERE Clients.Ledger_Number = '".$rowsdt[2]."'";
					$sub_result = selectData($connection, $sub_query);
					$ShowDetail = $sub_result[0];
					
					if (empty($ShowDetail)) $ShowDetail = 0;

				}
				
			
				echo"<tr id='CurRec_G1$i' onclick=\"LoadDetails('".$filepath."','".$form."','LIST','".$GridID."','".$PTransId."','".$rowsdt[0]."','".$i."'); \" class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGrid('".$filepath."','".$form."','".$GridID."','".$PTransId."','".$rowsdt[0]."','".$TransType."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px';
				echo "	<td width='$wdth;' align='left'>
							<input type='hidden' name='txtTransDtId[$i]' id='transdtid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtTransDtAmount[$i]'  id='transdtamount_h[$i]'  value='".$rowsdt[13]."' >
							<input type='hidden' name='txtTransDtAmount1[$i]' id='transdtamount1_h[$i]' value='".$rowsdt[14]."' >
							<input type='hidden' name='txtTransDtAmount2[$i]' id='transdtamount2_h[$i]' value='".$rowsdt[15]."' >
							<input type='hidden' name='txtTransDtdbcd[$i]' id='transdtdbcd[$i]' value='".$rowsdt[6]."' >";
							
							if ($Module_ShowBalance == 1) {
								echo"<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"GetLedgerBalance('getbalance','ledgernumber','currbalance','currbalanceb2','".$i."','".$txtDate."');ShowSlidingDiv('#slidingDiv-1$i');\" style='vertical-align:bottom;'/></span></label>";
							}
				echo "		<img src='img/printer-24.png' onMouseOver=\"style.cursor='hand'\" title='Preview Statement' style='width: 20px; height: 20px; ' onclick=\"printStatement('$i','ledgernumber','currencycode','$Base1','$Base2');\">
							<input type='text' name='txtLedgerNo[$i]' id='ledgernumber[$i]' value='".$rowsdt[2]."'  maxlength='10' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','ledger','ledger_number',this.value,'lstLedgerCode[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'ledgernumber[$i]','ledgername[$i]','ledgers');checkLedger(event,'$i', '1');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedger(22,1,'all',0,$i);\" style='vertical-align:bottom;'/></span></label>
							
							<div id='slidingDiv-1$i' class='slidingDiv slidingDivHide' style='height:fit-content;'>
								<table align='center' border='0' cellpadding='0' cellspacing='0'>
									<tr height='25px;'><td width='60px;' rowspan='2'><span class='style1'>Balance</span></td><td width='140px;' align='right'>
									<input type='text' name='txtCurrBalance[$i]' id='currbalance[$i]' value='$txtCurrBalance[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td></tr>
									<tr height='25px;'><td width='140px;' align='right'>
									<input type='text' name='txtCurrBalanceb2[$i]' id='currbalanceb2[$i]' value='$txtCurrBalanceb2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td></tr>
								</table>
								<div style='text-align:right;display:block;margin-top:5px;'>
									<a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv-1$i');\" style='text-decoration:none;'>
									<span style='font-weight: bold;color: black;font-size: 12px;border: 1px solid navajowhite;box-shadow: 1px 1px white;background-color: aliceblue;'>close</span></a></div>
							</div>
						</td>";
										
				echo"  	<td width='200px;' align='center'><input type='text' name='txtLedgerName[$i]' id='ledgername[$i]' value='".$rowsdt[3]."' title='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','ledger','ledger_name',this.value,'lstLedgerName[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerName[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedgerName(22,1,'all',0,$i);\" style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
						
				echo"  	<td width='300px;' align='center'><input type='text' name='txtTransDtDesc[$i]' id='transdtdesc[$i]' value='".$rowsdt[4]."' title='".$rowsdt[4]."' maxlength='150' class='".$ClassE."' style='font-size:12px; width:295px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\"  ".$KeyDown."   /></td>";
				if($showCheckNo_RV == 1)
					echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtCheckNo[$i]' id='transdtcheckno[$i]' value='".$rowsdt[19]."' title='".$rowsdt[20]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onChange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." /></td>";
				else echo "<input type='hidden' name='txtTransDtCheckNo[$i]' id='transdtcheckno[$i]' value='".$rowsdt[19]."' >";
				//nadine rate for non base 1
				if ($showRate == 1)
					echo"  	<td width='60px;' align='center'><input type='text' name='txtTransDtRate[$i]' id='transdtrate[$i]' value='$rowsdt[18]'  class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); SetAmountRate(1,1,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);\"  ".$KeyDown."   /></td>";
				else echo "<input type='hidden' name='txtTransDtRate[$i]' id='transdtrate[$i]' value=''>";
				
				echo"   <td width='60px;' align='center'><select name='txtCurrencyCode[$i]' id='currencycode[$i]' class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G1','$i'); ";
				if($module_ledgerrestrictcur==1) echo "checkCurrency(4,$DecimalBase1,$DecimalBase2,'".$Base1."','".$Base2."','".$txtDate."',$i);";
				else echo "SetAmount(4,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i); ";
				echo "\" ".$KeyDown." >";
				echo"	<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($rowsdt[11]==$curf[0])	echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"	</select></td>";	
				
					  
				echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount_D[$i]' id='transdtamount[$i]' value='".number_format($rowsdt[7],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onkeyup=\"formatFieldDigits(this);\" onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G1','$i'); SetAmount(1,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount1_D[$i]' id='transdtamount1[$i]' value='".number_format($rowsdt[8],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G1','$i'); SetAmount(2,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				if ($Hide_Base2 == 0) echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount2_D[$i]' id='transdtamount2[$i]' value='".number_format($rowsdt[9],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G1','$i'); SetAmount(3,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtTransDtAmount2_D[$i]' id='transdtamount2[$i]' value='".$rowsdt[9]."' maxlength='20' >";
				if ($Hide_ValueDate == 0) echo"   <td width='70px;'><input type='text' name='txtValueDate[$i]' id='transdtvaluedate[$i]' value='".$rowsdt[10]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:65px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				else 				echo"  <input type='hidden' name='txtValueDate[$i]' id='transdtvaluedate[$i]' value='".$rowsdt[10]."' maxlength='10' >";
				echo"   <td width='105px;'><input type='text' name='txtTransDtManualNo[$i]' id='transdtmanualno[$i]' value='".$rowsdt[12]."' maxlength='40' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Manual No' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(4,$i); '  style='vertical-align:bottom;'/></span></label>
						</td>";
				// jp changes on 12.2.2020
				echo"<input type='hidden'   name='txtClientDtCode[$i]' id='GridAllocDt1[$i]' value='0'  />";
				//-- jp changes on 12.2.2020		
				if ($TransType == 'RV'){
					echo"   <td width='115px;' align='center'><input type='text'   name='txtClientDtCode[$i]' id='clientdtcode[$i]' value='".$rowsdt[16]."' class='".$ClassE."' style='font-size:12px; width:80px; height=18px;' maxlength='50' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." />
							   <label><span><img src='img/openlist.png' title='Select Client Detail' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistClientDetail(1,$i); '  style='vertical-align:bottom;'/></span></label>
							</td>
							<td width='205px;' align='center'><input type='text'   name='txtClientDtName[$i]' id='clientdtname[$i]' value='".$rowsdt[17]."' class='".$ClassE."' style='font-size:12px; width:200px; height=18px;' readonly /></td>";
					
				} else {
					echo"<input type='hidden'   name='txtClientDtCode[$i]' id='clientdtcode[$i]' value=''  />
						 <input type='hidden'   name='txtClientDtName[$i]' id='clientdtname[$i]' value='' />";
				}
                if($Module_Trans_Desc1 == 1)
                    echo"  	<td width='205px;' align='center'><input type='text' name='txtTransDtDesc1[$i]' id='transdtdesc1[$i]' value='".$rowsdt[5]."' maxlength='150' class='".$ClassE."' style='font-size:12px; width:190px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown."  /></td>";
                
                if($Module_Form_Trans == 1){
                    if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-D', 'datagrid-1-d', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='CstJour'></td>";
                    // if($Module_Checks == 1)
                    //     echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-C', 'datagrid-1-c', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Add Container'><div id='datagrid-1-c' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;'></td>";
                    if($Module_bill==1)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-B', 'datagrid-1-b', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Bill'></td>";
                    if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-I', 'datagrid-1-i', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Invoice'></td>";
                }

        				
				//echo "	<td width='25px;' align='center' valign='center'><img src='img/confirm-1.png' id='imgSubmit_1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$TransType."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail,'$NextCell',$Motion,$TabIndex); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo"	<td width='25px;'>$recno</td>";
				echo "</tr>";
						
	
				$previousDesc = $rowsdt[4];
				$i+=1;
				
				
			}
			
		}
		echo "<input type='hidden' name='lastinputrow' id='lastinputrow' value='$i' >";
		if ($NextCell == "ledgernumber[$nc]"){
			$nc++;
			$NextCell = "ledgernumber[$nc]";
		}
		$query1 = " select date_format(Trans_Date,'%d/%m/%Y') from temp_trans where trans_id = ".$PTransId;
		$res1 = mysql_query($query1,$connection);
		$rw1 = mysql_fetch_row($res1);
		if($rw1[0] != '') $txtDate = $rw1[0];
		
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\');"';
			$KeyDown1   = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_1[".$i."]','1');LeaveGrid('ledgernumber[$i]','ledgernumber2[0]','','')\" ";
			//Initializations
			if (empty($DefaultCur))  $DefaultCur = $Base1;

			if (empty($txtCurrencyCode[$i])) $txtCurrencyCode[$i] = $DefaultCur;
			if (empty($txtValueDate[$i]))    $txtValueDate[$i]    = displayToday();
			if (empty($txtTransDtdbcd[$i]))	 $txtTransDtdbcd[$i]  = $Type_dbcd;
			
			$ShowDetail = 0;

			$querycurrency="select currency_code from currency order by currency_code";
			$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
			
			
			$sub_query2 = " Select TransDt.Trans_ID, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), ".$DecimalBase.") As TransDtAmount_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount1,0), 0)), ".$DecimalBase1.") As TransDtAmount1_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount2,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount2,0), 0)), ".$DecimalBase2.") As TransDtAmount2_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), 9) As TransDtAmount, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount1,0), 0)), 9) As TransDtAmount1, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount2,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount2,0), 0)), 9) As TransDtAmount2 ".
						  " From Temp_TransDt As TransDt ".
						  " Where TransDt.Trans_ID = '".$PTransId."' ".
						  " Group By TransDt.Trans_ID ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			if ($Type_dbcd == 'D' && $sub_result2[2] < 0) {
				if($txtCurrencyCode[$i] == $Base1) {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[2]);	
				}
				else if($txtCurrencyCode[$i] == $Base2) {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[6]);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[3]);	
				}
				else {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount[$i]   = ConvertCurrency($Base1, $txtCurrencyCode[$i], insertMySQLDate($txtDate), $txtTransDtAmount[$i], $connection);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[2]);	
					$txtTransDtAmount_D[$i] = ConvertCurrency($Base1, $txtCurrencyCode[$i], insertMySQLDate($txtDate), $txtTransDtAmount_D[$i], $connection);
				}
				
				$txtTransDtAmount1[$i] = mabsolute($sub_result2[5]);
				$txtTransDtAmount2[$i] = mabsolute($sub_result2[6]);
				
				
				//$txtTransDtAmount_D[$i]   = number_format($txtTransDtAmount_D[$i], $DecimalBase);
				
				$txtTransDtAmount1_D[$i] = mabsolute($sub_result2[2]);
				$txtTransDtAmount2_D[$i] = mabsolute($sub_result2[3]);
			}
			else if ($Type_dbcd == 'C' && $sub_result2[2] > 0) {
				if($txtCurrencyCode[$i] == $Base1) {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[2]);	
				}
				else if($txtCurrencyCode[$i] == $Base2) {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[6]);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[3]);	
				}
				else {
					$txtTransDtAmount[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount[$i]   = ConvertCurrency($Base1, $txtCurrencyCode[$i], insertMySQLDate($txtDate), $txtTransDtAmount[$i], $connection);
					$txtTransDtAmount_D[$i] = mabsolute($sub_result2[2]);	
					$txtTransDtAmount_D[$i] = ConvertCurrency($Base1, $txtCurrencyCode[$i], insertMySQLDate($txtDate), $txtTransDtAmount_D[$i], $connection);
				}
				
				$txtTransDtAmount1[$i] = mabsolute($sub_result2[5]);
				$txtTransDtAmount2[$i] = mabsolute($sub_result2[6]);
						
				//$txtTransDtAmount_D[$i]   = number_format($txtTransDtAmount_D[$i], $DecimalBase);
				
				$txtTransDtAmount1_D[$i] = mabsolute($sub_result2[2]);
				$txtTransDtAmount2_D[$i] = mabsolute($sub_result2[3]);

			}
			
			$sub_query3 = " Select TransDt.TransDt_Description From Temp_TransDt as TransDt ".
						  " Where TransDt.Trans_ID = '".$PTransId."' ".
						  " Order By TransDt.TransDt_ID desc Limit 1 ";
			$sub_result3 = selectData($connection, $sub_query3);
			
			if ($txtTransDtAmount[$i] != 0)	$txtTransDtDesc[$i] = $sub_result3[0];
				
			echo"<tr id='CurRec_G1$i' onclick=\"LoadDetails('".$filepath."','".$form."','LIST','".$GridID."','".$PTransId."','-1','".$i."');\" class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G1');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			 if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px'; 
			echo "	<td width='$wdth;' align='left'>
						<input type='hidden' name='txtTransDtId[$i]' id='transdtid[$i]' value='$txtTransDtId[$i]' >
						<input type='hidden' name='txtTransDtAmount[$i]'  id='transdtamount_h[$i]'  value='$txtTransDtAmount[$i]' >
						<input type='hidden' name='txtTransDtAmount1[$i]' id='transdtamount1_h[$i]' value='$txtTransDtAmount1[$i]' >
						<input type='hidden' name='txtTransDtAmount2[$i]' id='transdtamount2_h[$i]' value='$txtTransDtAmount2[$i]' >
						<input type='hidden' name='txtTransDtdbcd[$i]' id='transdtdbcd[$i]' value='$txtTransDtdbcd[$i]' >";
						
						if ($Module_ShowBalance == 1) {
							echo"<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"GetLedgerBalance('getbalance','ledgernumber','currbalance','currbalanceb2','".$i."','".$txtDate."');ShowSlidingDiv('#slidingDiv-1$i');\" style='vertical-align:bottom;'/></span></label>";
						}
							
			echo "		<img src='img/printer-24.png' onMouseOver=\"style.cursor='hand'\" title='Preview Statement' style='width: 20px; height: 20px; ' onclick=\"printStatement('$i','ledgernumber','currencycode','$Base1','$Base2');\">
						<input type='text' name='txtLedgerNo[$i]' id='ledgernumber[$i]' value='$txtLedgerNo[$i]'  maxlength='10' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;'  onBlur=\"LeaveGrid('ledgernumber[$i]','ledgernumber2[0]','','')\"  onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','ledger','ledger_number',this.value,'lstLedgerCode[$i]'); GetNameFromCode('getname','ledger','ledger_number','Ledger_name','currency_code',this.value,'ledgername[$i]','currencycode[$i]'); SetRecordGridDefaults($i); GetLedgerAmount('getledgeramount',1,'".$PTransId."','".$Type_dbcd."','".$i."','".$txtCurrencyCode[$i]."','".$txtDate."'); \" onkeyup=\"AutoCompleteData(event,this.id,'ledgernumber[$i]','ledgername[$i]','ledgers');checkLedger(event,'$i', '1');\" ".$KeyDown1." />
						<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedger(22,1,'all',0,$i);\" style='vertical-align:bottom;'/></span></label>
						
						<div id='slidingDiv-1$i' class='slidingDiv slidingDivHide' style='height:fit-content;'>
								<table align='center' border='0' cellpadding='0' cellspacing='0'>
									<tr height='25px;'><td width='60px;' rowspan='2'><span class='style1'>Balance</span></td><td width='140px;' align='right'>
									<input type='text' name='txtCurrBalance[$i]' id='currbalance[$i]' value='$txtCurrBalance[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td></tr>
									<tr height='25px;'><td width='140px;' align='right'>
									<input type='text' name='txtCurrBalanceb2[$i]' id='currbalanceb2[$i]' value='$txtCurrBalanceb2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td></tr>
								</table>
								<div style='text-align:right;display:block;margin-top:5px;'>
									<a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv-1$i');\" style='text-decoration:none;'>
									<span style='font-weight: bold;color: black;font-size: 12px;border: 1px solid navajowhite;box-shadow: 1px 1px white;background-color: aliceblue;'>close</span></a></div>
							</div>
					</td>";
										
			echo"  	<td width='200px;' align='center'><input type='text' name='txtLedgerName[$i]' id='ledgername[$i]' value='$txtLedgerName[$i]' class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','ledger','ledger_name',this.value,'lstLedgerName[$i]');\" ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerName[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedgerName(22,1,'all',0,$i);\" style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			
			$txtTransDtDesc[$i] = $previousDesc;
			
			echo"  	<td width='300px;' align='center'><input type='text' name='txtTransDtDesc[$i]' id='transdtdesc[$i]' value='".htmlspecialchars($txtTransDtDesc[$i], ENT_QUOTES)."'  maxlength='150' class='".$ClassI."' style='font-size:12px; width:295px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown."   /></td>";
			
			
			if($showCheckNo_RV == 1)
				echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtCheckNo[$i]' id='transdtcheckno[$i]' value='".$txtTransDtCheckNo[$i]."' title='".$rowsdt[20]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onChange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." /></td>";
			else echo "<input type='hidden' name='txtTransDtCheckNo[$i]' id='transdtcheckno[$i]' value='".$rowsdt[19]."' >";
			
			//nadine rate for non base 1
			if ($showRate == 1)
				echo"  	<td width='60px;' align='center'><input type='text' name='txtTransDtRate[$i]' id='transdtrate[$i]' value='$txtTransDtCheckNo[$i]'  class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); SetAmountRate(1,1,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);\"   ".$KeyDown."   /></td>";
			else echo "<input type='hidden' name='txtTransDtRate[$i]' id='transdtrate[$i]' value='' >";
			
			echo"   <td width='60px;' align='center'><select name='txtCurrencyCode[$i]' id='currencycode[$i]' class='".$ClassI."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G1','$i'); "; 
			if($module_ledgerrestrictcur==1) echo "checkCurrency(4,$DecimalBase1,$DecimalBase2,'".$Base1."','".$Base2."','".$txtDate."',$i);";
			else echo "SetAmount(4,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i); ";
			echo "\" ".$KeyDown." >";
			echo"	<option></option>";
			while($curf=mysql_fetch_row($resultcurrency)){
				echo"<option ";
				if ($txtCurrencyCode[$i]==$curf[0])	echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"	</select></td>";	
				  
			$txtValueDate[$i] = $txtDate;
			echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount_D[$i]' id='transdtamount[$i]' value='".number_format($txtTransDtAmount_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onkeyup=\"formatFieldDigits(this);\" onChange=\"CheckAmount(this.id); SetModRecord('ModRec_G1','$i'); SetAmount(1,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount1_D[$i]' id='transdtamount1[$i]' value='".number_format($txtTransDtAmount1_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G1','$i'); SetAmount(2,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			if ($Hide_Base2 == 0) echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount2_D[$i]' id='transdtamount2[$i]' value='".number_format($txtTransDtAmount2_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G1','$i'); SetAmount(3,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			else 				echo"  <input type='hidden' name='txtTransDtAmount2_D[$i]' id='transdtamount2[$i]' value='0' maxlength='20' >";
			if ($Hide_ValueDate == 0)  echo"   <td width='70px;'><input type='text' name='txtValueDate[$i]' id='transdtvaluedate[$i]' value='$txtValueDate[$i]' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
			else 				echo"   <input type='hidden' name='txtValueDate[$i]' id='transdtvaluedate[$i]' value='00/00/0000' maxlength='10' >";
			echo"   <td width='105px;'><input type='text' name='txtTransDtManualNo[$i]' id='transdtmanualno[$i]' value='".htmlspecialchars($txtTransDtManualNo[$i], ENT_QUOTES)."' maxlength='40' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Manual No' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(4,$i); '  style='vertical-align:bottom;'/></span></label>
					</td>";
					
			if ($TransType == 'RV'){
				echo"   <td width='115px;' align='center'><input type='text'   name='txtClientDtCode[$i]' id='clientdtcode[$i]' value='$txtClientDtCode[$i]' class='".$ClassI."' style='font-size:12px; width:80px; height=18px;' maxlength='50' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." />
						   <label><span><img src='img/openlist.png' title='Select Client Detail' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistClientDetail(1,$i); '  style='vertical-align:bottom;'/></span></label>
						</td>
						<td width='205px;' align='center'><input type='text'   name='txtClientDtName[$i]' id='clientdtname[$i]' value='$txtClientDtName[$i]' class='".$ClassI."' style='font-size:12px; width:200px; height=18px;' readonly /></td>";
				
			} else {
				echo"<input type='hidden'   name='txtClientDtCode[$i]' id='clientdtcode[$i]' value=''  />
					 <input type='hidden'   name='txtClientDtName[$i]' id='clientdtname[$i]' value='' />";
			}
			if($Module_Trans_Desc1 == 1)
                echo"  	<td width='205px;' align='center'><input type='text' name='txtTransDtDesc1[$i]' id='transdtdesc1[$i]' value='".htmlspecialchars($txtTransDtDesc1[$i], ENT_QUOTES)."' maxlength='150' class='".$ClassI."' style='font-size:12px; width:190px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown."  /></td>";
                
			if($Module_Form_Trans == 1){
                if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)
                    echo "<td width='25px;'></td>";
                if($Module_bill==1)
                    echo "<td width='25px;'></td>";
                if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)
                    echo "<td width='25px;'></td>";
            }	
			//echo "	<td width='25px;' align='center' valign='center'><img src='img/confirm-1.png' id='imgSubmit_1[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid('".$i."', '".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGrid('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$TransType."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail,'$NextCell',$Motion,$TabIndex); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"	<td width='25px;'>$recno</td>";
			echo"</tr>";  

			$i+=1;	
		}
	
	echo"		<input type='hidden' name='RecCount_G1' id='RecCount_G1' value='$i'>"; 
	echo"		<input type='hidden' name='RecIndex_G1' id='RecIndex_G1' value='$RecIndex_G1'>"; 
	echo"	</table>";  
	echo"	</div>";
	$query = " Select Count(*) FROM Temp_TransDt ".
			 " WHERE Trans_id = ".$PTransId; //echo $query;
	$result = selectData($connection, $query);
	$txtCountDetail = $result[0];
	if($txtCountDetail == '') $txtCountDetail = 0;
	echo "<input type='hidden' name='txtCountDetail' value='$txtCountDetail' >";
	showDataGridFooter($filepath,$form,$PTransId,$GridID,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}

function ShowTransDtGrid2($connection,$form,$PTransId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction,$query_labels){
	
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels    = mysql_fetch_array($result_labels);
	extract($row_labels);
	
	$DecimalBase  					= $arrayparams['DecimalBase'];
	$DecimalBase1 					= $arrayparams['DecimalBase1'];
	$DecimalBase2 					= $arrayparams['DecimalBase2'];
	$DefaultCur  					= $arrayparams['DefaultCur'];
	$Base1 							= $arrayparams['Base1'];
	$Base2 							= $arrayparams['Base2'];
	
	$Module_Project 				= $arrayparams['Module_Project'];
	$Module_CostCenter				= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost	 	= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 			= $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView	 	= $arrayparams['Module_TransStandardView'];
    $Module_ShowBalance 			= $arrayparams['Module_ShowBalance'];
    $Module_Form_Trans 			    = $arrayparams['Module_Form_Trans'];
    $Module_Trans_Desc1 			= $arrayparams['Module_Trans_Desc1'];
	$ModuleRestrictCashType 		= $arrayparams['ModuleRestrictCashType'];
	$Module_MultiCashType 			= $arrayparams['Module_MultiCashType'];
	$Module_ReferenceByCostCenter 	= $arrayparams['Module_ReferenceByCostCenter'];
	$Module_ProjectDt 				= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt 			= $arrayparams['Module_CostCenterDt'];
	$module_ledgerrestrictcur 		= $arrayparams['module_ledgerrestrictcur'];
	
	$Hide_ValueDate 				= $arrayparams['Hide_ValueDate'];
	$Hide_Base2 					= $arrayparams['Hide_Base2'];
	
	$txtDate    					= $arrayparams['txtDate'];
	$TransType  					= $arrayparams['TransType'];
	$Type_dbcd  					= $arrayparams['Type_dbcd2'];
	$TypeIndex  					= $arrayparams['TypeIndex'];
	$ErrorRecId 					= $arrayparams['ErrorRecId'];
	$GridID     					= $arrayparams['GridID2'];
	$showRate						= $arrayparams['showRate'];
	
	$showCheckNo_RV					= $arrayparams['showCheckNo_RV'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	
	$i = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 1000;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	/// grid Motion
		$Motion = 1;
		if ($Module_ReferenceByCostCenter == 1 || ($Module_ReferenceByCostCenter == 0 && $Module_Project == 0 && $Module_ProjectDt == 0
			&& $Module_CostCenter == 0 && $Module_CostCenterDt == 0)){
			$NextCell = "ledgernumber2[1]";
			$TabIndex = 0 ;
		}
		else if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)){
			$NextCell = 'projectcodedt2[0]';
			$TabIndex = 0 ;
			
			}
		else {
				$NextCell = 'chkjournumber2[0]';	
				$TabIndex = 0 ;
				
			}	
		
	
	
	/////////////


	
	$columnsarray 		= 		array("ledgernumber2", "ledgername2", "transdtdesc2");
	if ($showRate == 1)
		array_push($columnsarray, "transdtrate2");
	
		array_push($columnsarray, "currencycode2");
		array_push($columnsarray, "transdtamount02");
		array_push($columnsarray, "transdtamount12");
	
	if($Hide_Base2 == 0)  		array_push($columnsarray, "transdtamount22");
	if($Hide_ValueDate == 0)    array_push($columnsarray, "transdtvaluedate2");
	array_push($columnsarray, "transdtmanualno2");
	
	if ($TransType == 'RV') 	array_push($columnsarray, "clientdtcode2");
	array_push($columnsarray, "transdtdesc12");
	
	$columnsarrayall 	= 		array("ledgernumber2", "ledgername2", "transdtdesc22", "transdtdesc12", "transdtamount02", "transdtamount12");
	if($Hide_Base2 == 0)  		array_push($columnsarrayall, "transdtamount22");
	if($Hide_ValueDate == 0)  	array_push($columnsarrayall, "transdtvaluedate2");
	array_push($columnsarrayall, "transdtmanualno2", "transdtid2");
	
	$orderbyarray 		= 		array("Ledger.Ledger_Number", "Ledger.Ledger_Name", "TransDt.TransDt_Description", "TransDt.TransDt_Description2" );
	if($Hide_ValueDate == 0)  	array_push($orderbyarray, "TransDt.TransDt_ValueDate");
	$columnslist 	= implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
		
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

	
	
	
	$query = " Select TransDt.TransDt_id, TransDt.Trans_id, Ledger.Ledger_Number, Ledger.Ledger_Name, TransDt.TransDt_Description, TransDt.TransDt_Description2, ".
			 " TransDt_dbcd, Round(ifNull(Transdt_Amount,0), ".$DecimalBase."), Round(ifNull(Transdt_Amount1,0), ".$DecimalBase1."),".
			 " Round(ifNull(Transdt_Amount2,0), ".$DecimalBase2."), date_format(TransDt_ValueDate,'%d/%m/%Y'), TransDt.currency_code, TransDt.TransDt_ManualNo, ".
			 " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0), ClientsDetail.Detail_Code, ClientsDetail.Detail_Name, transdt_rate ".
			 " From Temp_TransDt As TransDt ".
			 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
			 " Left Join ClientsDetail on TransDt.Detail_Code = ClientsDetail.Detail_Code ".
			 " Where TransDt.Trans_ID = ".$PTransId;
			 
	if ($Type_dbcd != -1) $query .= " And TransDt.TransDt_dbcd = '".$Type_dbcd."' ";
	
	$query .= " Order By $orderby $direction ";
	
	//echo $query;// exit;
			
	$result=mysql_query($query,$connection);
	$totalrows = mysql_num_rows($result);

	$query = $query." limit ".$startrange.",".$perpage;
	$result=mysql_query($query,$connection);
	
	$nc = mysql_num_rows($result);
	if ($NextCell == "ledgernumber2[1]" && $nc != ''){
		$NextCell = "ledgernumber2[$nc]";
	}
	
	//Initializations for Div Ids
	$ContainerDiv = 'container2';
	$LoaderDiv    = 'Loader2';
	$HeaderDiv    = 'grid_headerDiv2';
	$ContentDiv   = 'grid_contentDiv2';
	$TableFocus   = 'table-focus-g2';
	
	$TableWidth = '1200px;';
	if ($TransType == 'RV') $TableWidth = '1520px;';
		
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	if($Module_Form_Trans == 1){
        if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)
            echo "	<div id='datagrid-2-d' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;margin-top:10px;margin-left:10px'></div>";
        if($Module_Checks == 1)
            echo "	<div id='datagrid-2-c' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;margin-top:10px;margin-left:10px'></div>";
        if($Module_bill==1)
            echo "	<div id='datagrid-2-b' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;margin-top:10px;margin-left:10px'></div>";
        if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)
            echo "	<div id='datagrid-2-i' style='z-index:999;position:Absolute;display:none;background-color:Azure;border:1px solid gray;margin-top:10px;margin-left:10px'></div>";
    }
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $headerDivWidth = '783px';
    }else{
        $headerDivWidth = '1096px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$headerDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:$TableWidth'>";
	if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px';
		echo"<tr height='20px;'>";
		echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		echo"  <th width='$wdth;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','Ledger.Ledger_Number','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span class='style1'>$LedgerNo". $orderimg1."</span><span class='style2'>*</span></th>";
		echo"  <th width='200px;' align='left'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','Ledger.Ledger_Name','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span class='style1'>$LedgerName". $orderimg2."</span></th>";
		echo"  <th width='300px;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span class='style1'>$Descr". $orderimg3."</span></th>";
		if ($showRate == 1)
			echo"  <th width='60px;' align='center' ><span >Rate</span></th> ";	
		echo"  <th width='60px;' align='center' ><span >$Curr</span></th> ";	
		echo"  <th width='85px;' align='center' ><span >$Amount</span></th>";
		echo"  <th width='85px;' align='center' ><span >".$Base1."</span></th> ";
		if($Hide_Base2 == 0) echo"  <th width='85px;' align='center' ><span >".$Base2."</span></th>";
		if($Hide_ValueDate == 0) echo"  <th width='70px;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_ValueDate','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span class='style1'>$ValueDate". $orderimg5."</span></th>";
		echo"  <th width='105px;' align='center' ><span >$ManualNo</span></th> ";
		
		if ($TransType == 'RV'){
			echo"  <th width='115px;' align='center' ><span >$DetailCode</span></th> ";
			echo"  <th width='205px;' align='center' ><span >$Name</span></th> ";	
		}
        
        if($Module_Trans_Desc1 == 1)
            echo"  <th width='205px;' align='center'  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PTransId."', '".$GridID."', 1, '".$dftorderby."', 'COR','TransDt.TransDt_Description2','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span class='style1'>$Descr 1". $orderimg4."</span></th>";
            
        if($Module_Form_Trans == 1){
            if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)   
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            if($Module_Checks == 1)
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            if($Module_bill==1)
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
            if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)            
                echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
        } 
		echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
		echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $contentDivWidth = '800px';
        }else{
            $contentDivWidth = '1113px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$contentDivWidth;height:135px;' >";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:$TableWidth'>";
		echo"<input type='hidden' name='SelectedRec_G2' id='SelectedRec_G2' value='$SelectedRec_G2'>
			 <input type='hidden' name='SelectedRecColor_G2' id='SelectedRecColor_G2' value='$SelectedRecColor_G2'>
			 <input type='hidden' name='ModRec_G2' id='ModRec_G2' value='$ModRec_G2'>"; 
		
			 
			 
		if ($PTransId != '' ) {
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				if ($ErrorRecId != "" && $ErrorRecId == $rowsdt[0]) $bgcolor='bgcolor3';
					
				$querycurrency="select currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
			
				$ShowDetail = 0;
				if ($TransType == 'RV'){
					$sub_query = " SELECT ifNull(Clients.Client_Detail,0) ".
								 " FROM Clients WHERE Clients.Ledger_Number = '".$rowsdt[2]."'";
					$sub_result = selectData($connection, $sub_query);
					$ShowDetail = $sub_result[0];
					
					if (empty($ShowDetail)) $ShowDetail = 0;

				}
			
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
				
			
				echo"<tr id='CurRec_G2$i' onclick=\"LoadDetails2('".$filepath."','".$form."','LIST','".$GridID."','".$PTransId."','".$rowsdt[0]."','".$i."'); \" class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGrid('".$filepath."','".$form."','".$GridID."','".$PTransId."','".$rowsdt[0]."','".$TransType."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px';
				echo "	<td width='$wdth;' align='left'>
							<input type='hidden' name='txtTransDtId[$i]' id='transdtid2[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtTransDtAmount02[$i]'  id='transdtamount02_h[$i]'  value='".$rowsdt[13]."' >
							<input type='hidden' name='txtTransDtAmount12[$i]' id='transdtamount12_h[$i]' value='".$rowsdt[14]."' >
							<input type='hidden' name='txtTransDtAmount22[$i]' id='transdtamount22_h[$i]' value='".$rowsdt[15]."' >
							<input type='hidden' name='txtTransDtdbcd2[$i]' id='transdtdbcd2[$i]' value='".$rowsdt[6]."' >";
							
							if ($Module_ShowBalance == 1) {
								echo"<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"GetLedgerBalance('getbalance','ledgernumber2','currbalance2','currbalance2b2','".$i."','".$txtDate."');ShowSlidingDiv('#slidingDiv-2$i');\" style='vertical-align:bottom;'/></span></label>";
							}
							
				echo"		<img src='img/printer-24.png' onMouseOver=\"style.cursor='hand'\" title='Preview Statement' style='width: 20px; height: 20px; ' onclick=\"printStatement('$i','ledgernumber2','currencycode2','$Base1','$Base2');\">
							<input type='text' name='txtLedgerNo2[$i]' id='ledgernumber2[$i]' value='".$rowsdt[2]."'  maxlength='10' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','ledger','ledger_number',this.value,'lstLedgerCode2[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'ledgernumber2[$i]','ledgername2[$i]','ledgers'); checkLedger(event,$i, '2');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedger(23,1,'all',0,$i);\" style='vertical-align:bottom;'/></span></label>
							
							<div id='slidingDiv-2$i' class='slidingDiv slidingDivHide' style='height:fit-content;'>
								<table align='center' border='0' cellpadding='0' cellspacing='0'>
									<tr height='25px;'><td width='60px;' rowspan='2'><span class='style1'>Balance</span></td>
										<td width='140px;' align='right'><input type='text' name='txtCurrBalance2[$i]' id='currbalance2[$i]' value='$txtCurrBalance2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td>
									</tr>
									<tr height='25px;'>
										<td width='140px;' align='right'><input type='text' name='txtCurrBalance2b2[$i]' id='currbalance2b2[$i]' value='$txtCurrBalance2b2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td>
									</tr>
								</table>
								<div style='text-align:right;display:block;margin-top:5px;'><a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv-2$i');\" style='text-decoration:none;'>
									<span style='font-weight: bold;color: black;font-size: 12px;border: 1px solid navajowhite;box-shadow: 1px 1px white;background-color: aliceblue;'>close</span></a></div>
							</div>
						</td>";
										
				echo"  	<td width='200px;' align='center'><input type='text' name='txtLedgerName2[$i]' id='ledgername2[$i]' value='".$rowsdt[3]."' title='".$rowsdt[3]."' class='".$ClassE."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','ledger','ledger_name',this.value,'lstLedgerName2[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerName2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedgerName(23,1,'all',0,$i);\" style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
		
				
				echo"  	<td width='300px;' align='center'><input type='text' name='txtTransDtDesc2[$i]' id='transdtdesc2[$i]' value='".$rowsdt[4]."' title='".$rowsdt[4]."' maxlength='150' class='".$ClassE."' style='font-size:12px; width:295px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\"  ".$KeyDown."   /></td>";
				
				//nadine rate for non base 1
				if ($showRate == 1)
					echo"  	<td width='60px;' align='center'><input type='text' name='txtTransDtRate2[$i]' id='transdtrate2[$i]' value='$rowsdt[18]'  class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); SetAmountRate(2,11,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);\"  ".$KeyDown."   /></td>";
				else 
					echo "<input type='hidden' name='txtTransDtRate2[$i]' id='transdtrate2[$i]' value=''>";
				
				echo"   <td width='60px;' align='center'><select name='txtCurrencyCode2[$i]' id='currencycode2[$i]' class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G2','$i'); ";
				if($module_ledgerrestrictcur ==1 ) echo "checkCurrency(14,$DecimalBase1,$DecimalBase2,'".$Base1."','".$Base2."','".$txtDate."',$i); ";
				else echo "SetAmount(14,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);";
				echo "\" ".$KeyDown." >";
				echo"	<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($rowsdt[11]==$curf[0])	echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"	</select></td>";	
				
					  
				echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount02_D[$i]' id='transdtamount02[$i]' value='".number_format($rowsdt[7],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;'  onkeyup=\"formatFieldDigits(this);\" onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(11,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount12_D[$i]' id='transdtamount12[$i]' value='".number_format($rowsdt[8],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(12,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				if($Hide_Base2 == 0) echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount22_D[$i]' id='transdtamount22[$i]' value='".number_format($rowsdt[9],$DecimalBase)."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(13,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtTransDtAmount22_D[$i]' id='transdtamount22[$i]' value='".$rowsdt[9]."' maxlength='20' >";
				if($Hide_ValueDate == 0) echo"   <td width='70px;'><input type='text' name='txtValueDate2[$i]' id='transdtvaluedate2[$i]' value='".$rowsdt[10]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:65px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				else 				echo"  <input type='hidden' name='txtValueDate2[$i]' id='transdtvaluedate2[$i]' value='".$rowsdt[10]."' maxlength='10' >";
				echo"   <td width='105px;'><input type='text' name='txtTransDtManualNo2[$i]' id='transdtmanualno2[$i]' value='".$rowsdt[12]."' maxlength='40' class='".$ClassE."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Manual No' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(5,$i); '  style='vertical-align:bottom;'/></span></label>
						</td>";
						
				if ($TransType == 'RV'){
					echo"   <td width='115px;' align='center'><input type='text'   name='txtClientDtCode2[$i]' id='clientdtcode2[$i]' value='".$rowsdt[16]."' class='".$ClassE."' style='font-size:12px; width:80px; height=18px;' maxlength='50' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." />
							   <label><span><img src='img/openlist.png' title='Select Client Detail' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistClientDetail(2,$i); '  style='vertical-align:bottom;'/></span></label>
							</td>
							<td width='205px;' align='center'><input type='text'   name='txtClientDtName2[$i]' id='clientdtname2[$i]' value='".$rowsdt[17]."' class='".$ClassE."' style='font-size:12px; width:200px; height=18px;' readonly /></td>";
					
				} else {
					echo"<input type='hidden'   name='txtClientDtCode2[$i]' id='clientdtcode2[$i]' value=''  />
						 <input type='hidden'   name='txtClientDtName2[$i]' id='clientdtname2[$i]' value='' />";
                }
                
                if($Module_Trans_Desc1 == 1)
                    echo"  	<td width='205px;' align='center'><input type='text' name='txtTransDtDesc12[$i]' id='transdtdesc12[$i]' value='".$rowsdt[5]."' maxlength='150' class='".$ClassE."' style='font-size:12px; width:190px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown."  /></td>";
                    
				if($Module_Form_Trans == 1){
                    if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-2-D', 'datagrid-2-d', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='CstJour'></td>";
                    if($Module_Checks == 1)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-2-C', 'datagrid-2-c', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Checks'></td>";
                    if($Module_bill==1)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-2-B', 'datagrid-2-b', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Bill'></td>";
                    if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)
                        echo "	<td width='25px;' align='center' valign='center'><img src='img/show.png' height='16px' width='16px' onclick=\"getGridForm('".$i."','".$filepath."', 'TRS-2-I', 'datagrid-2-i', '".$PTransId."', '".$TransType."',0);\" style='cursor:pointer;' title='Invoice'></td>";
                }
				//echo "	<td width='25px;' align='center' valign='center'><img src='img/confirm-1.png' id='imgSubmit_2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid2('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGrid2('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$TransType."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail,'$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo"	<td width='25px;'>$recno</td>";
				echo "</tr>";
						
	
				
				$i+=1;
				$previousDesc = $rowsdt[4];
				
			}
			
		}
		
		
		echo "<input type='hidden' name='lastinputrow2' id='lastinputrow2' value='$i' >";
		$query2 = " select date_format(Trans_Date,'%d/%m/%Y') from temp_trans where trans_id = ".$PTransId;
		$res2 = mysql_query($query2,$connection);
		$rw2 = mysql_fetch_row($res2); 
		if($rw2[0] != '') $txtDate = $rw2[0];
		
		if ($NextCell == "ledgernumber2[$nc]"){
			$nc++;
			$NextCell = "ledgernumber2[$nc]";
		}
		
		$queryNum = " Select TransDt.TransDt_id From Temp_TransDt As TransDt ".
			 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
			 " Left Join ClientsDetail on TransDt.Detail_Code = ClientsDetail.Detail_Code ".
			 " Where TransDt.Trans_ID = ".$PTransId;
			 
		if ($Type_dbcd != -1) $queryNum .= " And TransDt.TransDt_dbcd = '".$arrayparams['Type_dbcd1']."' ";
		$resultNum = mysql_query($queryNum,$connection);
		$rowsNum = mysql_num_rows($resultNum);
		
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
			$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_2[".$i."]','1');LeaveGrid('ledgernumber2[$i]','ledgernumber[0]','','')\" ";		
			//Initializations
			if (empty($DefaultCur))  $DefaultCur = $Base1;

			if (empty($txtCurrencyCode2[$i])) $txtCurrencyCode2[$i] = $DefaultCur;
			if (empty($txtValueDate2[$i]))    $txtValueDate2[$i]    = displayToday();
			if (empty($txtTransDtdbcd2[$i]))  $txtTransDtdbcd2[$i]  = $Type_dbcd;
			
			$ShowDetail = 0;
			
			$querycurrency="select currency_code from currency order by currency_code";
			$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));
			
			
			$sub_query2 = " Select TransDt.Trans_ID, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), ".$DecimalBase.") As TransDtAmount_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount1,0), 0)), ".$DecimalBase1.") As TransDtAmount1_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount2,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount2,0), 0)), ".$DecimalBase2.") As TransDtAmount2_D, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), 9) As TransDtAmount, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount1,0), 0)), 9) As TransDtAmount1, ".
						  " Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount2,0), 0)) - Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount2,0), 0)), 9) As TransDtAmount2 ".
						  " From Temp_TransDt As TransDt ".
						  " Where TransDt.Trans_ID = '".$PTransId."' ".
						  " Group By TransDt.Trans_ID ";
						  
								  
	
			$sub_result2 = selectData($connection, $sub_query2);
			//echo mabsolute($sub_result2[5]);
			if ($Type_dbcd == 'D' && $sub_result2[2] < 0) {
				//echo "debit"; 
				//echo $txtCurrencyCode2[$i];
				if($txtCurrencyCode2[$i] == $Base1) {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[2]);	
				}
				else if($txtCurrencyCode2[$i] == $Base2) {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[6]);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[3]);	
				}
				else {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount02[$i]   = ConvertCurrency($Base1, $txtCurrencyCode2[$i], insertMySQLDate($txtDate), $txtTransDtAmount02[$i], $connection);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[2]);	
					$txtTransDtAmount02_D[$i] = ConvertCurrency($Base1, $txtCurrencyCode2[$i], insertMySQLDate($txtDate), $txtTransDtAmount02_D[$i], $connection);
				}
				
				$txtTransDtAmount12[$i] = mabsolute($sub_result2[5]);
				$txtTransDtAmount22[$i] = mabsolute($sub_result2[6]);
				
				
				//$txtTransDtAmount02_D[$i]   = number_format($txtTransDtAmount02_D[$i], $DecimalBase);
				
				$txtTransDtAmount12_D[$i] = mabsolute($sub_result2[2]);
				$txtTransDtAmount22_D[$i] = mabsolute($sub_result2[3]);
			}
			else if ($Type_dbcd == 'C' && $sub_result2[2] > 0) {
				//echo "credit";
				if($txtCurrencyCode2[$i] == $Base1) {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[2]);	
				}
				else if($txtCurrencyCode2[$i] == $Base2) {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[6]);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[3]);	
				}
				else {
					$txtTransDtAmount02[$i]   = mabsolute($sub_result2[5]);
					$txtTransDtAmount02[$i]   = ConvertCurrency($Base1, $txtCurrencyCode2[$i], insertMySQLDate($txtDate), $txtTransDtAmount02[$i], $connection);
					$txtTransDtAmount02_D[$i] = mabsolute($sub_result2[2]);	
					$txtTransDtAmount02_D[$i] = ConvertCurrency($Base1, $txtCurrencyCode2[$i], insertMySQLDate($txtDate), $txtTransDtAmount02_D[$i], $connection);
				}
				
				$txtTransDtAmount12[$i] = mabsolute($sub_result2[5]);
				$txtTransDtAmount22[$i] = mabsolute($sub_result2[6]);
						
				
				//$txtTransDtAmount02_D[$i]   = number_format($txtTransDtAmount02_D[$i], $DecimalBase);
				
				$txtTransDtAmount12_D[$i] = mabsolute($sub_result2[2]);
				$txtTransDtAmount22_D[$i] = mabsolute($sub_result2[3]);

			}
			
			$sub_query3 = " Select TransDt.TransDt_Description From Temp_TransDt as TransDt ".
						  " Where TransDt.Trans_ID = '".$PTransId."' ".
						  " Order By TransDt.TransDt_ID desc Limit 1 ";
						  
			$sub_result3 = selectData($connection, $sub_query3);
			//echo $sub_query2; 
			//exit;
			if ($txtTransDtAmount02[$i] != 0)	$txtTransDtDesc2[$i] = $sub_result3[0];
			
				
			echo"<tr id='CurRec_G2$i' onclick=\"LoadDetails2('".$filepath."','".$form."','LIST','".$GridID."','".$PTransId."','-1','".$i."');\" class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G2');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			if ($Module_ShowBalance == 1) $wdth='150px'; else $wdth='125px';  
			echo "	<td width='$wdth;' align='left'>
						<input type='hidden' name='txtTransDtId2[$i]' id='transdtid2[$i]' value='$txtTransDtId2[$i]' >
						<input type='hidden' name='txtTransDtAmount02[$i]'  id='transdtamount02_h[$i]'  value='$txtTransDtAmount02[$i]' >
						<input type='hidden' name='txtTransDtAmount12[$i]' id='transdtamount12_h[$i]' value='$txtTransDtAmount12[$i]' >
						<input type='hidden' name='txtTransDtAmount22[$i]' id='transdtamount22_h[$i]' value='$txtTransDtAmount22[$i]' >
						<input type='hidden' name='txtTransDtdbcd2[$i]' id='transdtdbcd2[$i]' value='$txtTransDtdbcd2[$i]' >";
						
						if ($Module_ShowBalance == 1) {
							echo"<label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"GetLedgerBalance('getbalance','ledgernumber2','currbalance2','currbalance2b2','".$i."','".$txtDate."');ShowSlidingDiv('#slidingDiv-2$i');\" style='vertical-align:bottom;'/></span></label>";
						}
							
			echo"		<img src='img/printer-24.png' onMouseOver=\"style.cursor='hand'\" title='Preview Statement' style='width: 20px; height: 20px; ' onclick=\"printStatement('$i','ledgernumber2','currencycode2','$Base1','$Base2');\">
						<input type='text' name='txtLedgerNo2[$i]' id='ledgernumber2[$i]' value='$txtLedgerNo2[$i]'  maxlength='10' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onBlur=\"LeaveGrid('ledgernumber2[$i]','ledgernumber[0]','','')\"   onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','ledger','ledger_number',this.value,'lstLedgerCode2[$i]'); GetNameFromCode('getname','ledger','ledger_number','Ledger_name','currency_code',this.value,'ledgername2[$i]','currencycode2[$i]'); SetRecordGridDefaults2($i); GetLedgerAmount('getledgeramount',2,'".$PTransId."','".$Type_dbcd."','".$i."','".$txtCurrencyCode2[$i]."','".$txtDate."'); \" onkeyup=\"AutoCompleteData(event,this.id,'ledgernumber2[$i]','ledgername2[$i]','ledgers');checkLedger(event,$i, '2');\" ".$KeyDown1." />
						<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedger(23,1,'all',0,$i);\" style='vertical-align:bottom;'/></span></label>
						
						<div id='slidingDiv-2$i' class='slidingDiv slidingDivHide' style='height:fit-content;'>
								<table align='center' border='0' cellpadding='0' cellspacing='0'>
									<tr height='25px;'><td width='60px;' rowspan='2'><span class='style1'>Balance</span></td>
										<td width='140px;' align='right'><input type='text' name='txtCurrBalance2[$i]' id='currbalance2[$i]' value='$txtCurrBalance2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td>
									</tr>
									<tr height='25px;'>
										<td width='140px;' align='right'><input type='text' name='txtCurrBalance2b2[$i]' id='currbalance2b2[$i]' value='$txtCurrBalance2b2[$i]' style='font-size:12px; font-weight:bold; text-align:right; border-width:0px; background-color:transparent; width:140px; height:20px;' readonly></td>
									</tr>
								</table>
								<div style='text-align:right;display:block;margin-top:5px;'><a href='javascript:void(0);' onclick=\"ShowSlidingDiv('#slidingDiv-2$i');\" style='text-decoration:none;'>
									<span style='font-weight: bold;color: black;font-size: 12px;border: 1px solid navajowhite;box-shadow: 1px 1px white;background-color: aliceblue;'>close</span></a></div>
							</div>
					</td>";
										
			echo"  	<td width='200px;' align='center'><input type='text' name='txtLedgerName2[$i]' id='ledgername2[$i]' value='$txtLedgerName2[$i]' class='".$ClassI."' style='font-size:12px; width:195px; height:20px;' onchange=\"CheckLookup('chkcodeexists','ledger','ledger_name',this.value,'lstLedgerName2[$i]');\" ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Ledger' id='lstLedgerName2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedgerName(23,1,'all',0,$i);\" style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			
			if($previousDesc != '') $txtTransDtDesc2[$i] = $previousDesc;	
			    echo"  	<td width='300px;' align='center'><input type='text' name='txtTransDtDesc2[$i]' id='transdtdesc2[$i]' value='".htmlspecialchars($txtTransDtDesc2[$i], ENT_QUOTES)."'  maxlength='150' class='".$ClassI."' style='font-size:12px; width:295px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown."   /></td>";
			
			//nadine rate for non base 1
			if ($showRate == 1)
			echo"  	<td width='60px;' align='center'>
					<input type='text' name='txtTransDtRate2[$i]' id='transdtrate2[$i]' value='$txtTransDtRate2[$i]'  class='".$ClassE."' style='font-size:12px; width:55px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); SetAmountRate(2,11,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);\"  ".$KeyDown."   />
					</td>";
			else echo "<input type='hidden' name='txtTransDtRate2[$i]' id='transdtrate2[$i]' value=''>";
			
			echo"   <td width='60px;' align='center'><select name='txtCurrencyCode2[$i]' id='currencycode2[$i]' class='".$ClassI."' style='font-size:12px; width:55px; height:20px;' onChange=\"SetModRecord('ModRec_G2','$i'); ";
			if($module_ledgerrestrictcur ==1 ) echo "checkCurrency(14,$DecimalBase1,$DecimalBase2,'".$Base1."','".$Base2."','".$txtDate."',$i); ";
			else echo "SetAmount(14,$DecimalBase1,$DecimalBase2,this.value,'".$Base1."','".$Base2."','".$txtDate."',$i);";
			echo "\" ".$KeyDown." >";
			echo"	<option></option>";
			while($curf=mysql_fetch_row($resultcurrency)){
				echo"<option ";
				if ($txtCurrencyCode2[$i]==$curf[0])	echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"	</select></td>";	
				  
			$txtValueDate2[$i] = $txtDate;
			echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount02_D[$i]' id='transdtamount02[$i]' value='".number_format($txtTransDtAmount02_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onkeyup=\"formatFieldDigits(this);\" onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(11,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount12_D[$i]' id='transdtamount12[$i]' value='".number_format($txtTransDtAmount12_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(12,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			if($Hide_Base2 == 0) echo"	<td width='85px;' align='center'><input type='text' name='txtTransDtAmount22_D[$i]' id='transdtamount22[$i]' value='".number_format($txtTransDtAmount22_D[$i],$DecimalBase)."' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G2','$i'); SetAmount(13,$DecimalBase1,$DecimalBase2,'','".$Base1."','".$Base2."','".$txtDate."',$i);formatFieldDigits(this);\" ".$KeyDown." /></td>";
			else 				echo"	<input type='hidden' name='txtTransDtAmount22_D[$i]' id='transdtamount22[$i]' value='0' maxlength='20' >";
			if($Hide_ValueDate == 0) echo"   <td width='70px;'><input type='text' name='txtValueDate2[$i]' id='transdtvaluedate2[$i]' value='$txtValueDate2[$i]' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
			else 					echo"  <input type='hidden' name='txtValueDate2[$i]' id='transdtvaluedate2[$i]' value='00/00/0000' maxlength='10' >";
			echo"   <td width='105px;'><input type='text' name='txtTransDtManualNo2[$i]' id='transdtmanualno2[$i]' value='".htmlspecialchars($txtTransDtManualNo2[$i], ENT_QUOTES)."' maxlength='40' class='".$ClassI."' style='font-size:12px; width:70px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Manual No' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(5,$i); '  style='vertical-align:bottom;'/></span></label>
					</td>";
					
			if ($TransType == 'RV'){
				echo"   <td width='115px;' align='center'><input type='text'   name='txtClientDtCode2[$i]' id='clientdtcode2[$i]' value='$txtClientDtCode2[$i]' class='".$ClassI."' style='font-size:12px; width:80px; height=18px;' maxlength='50' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." />
						   <label><span><img src='img/openlist.png' title='Select Client Detail' width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistClientDetail(2,$i); '  style='vertical-align:bottom;'/></span></label>
						</td>
						<td width='205px;' align='center'><input type='text'   name='txtClientDtName2[$i]' id='clientdtname2[$i]' value='$txtClientDtName2[$i]' class='".$ClassI."' style='font-size:12px; width:200px; height=18px;' readonly /></td>";
					
			} else {
				echo"<input type='hidden'   name='txtClientDtCode2[$i]' id='clientdtcode2[$i]' value=''  />
					 <input type='hidden'   name='txtClientDtName2[$i]' id='clientdtname2[$i]' value='' />";
			}
            
            if($Module_Trans_Desc1 == 1)
                echo"  	<td width='205px;' align='center'><input type='text' name='txtTransDtDesc12[$i]' id='transdtdesc12[$i]' value='".htmlspecialchars($txtTransDtDesc12[$i], ENT_QUOTES)."' maxlength='150' class='".$ClassI."' style='font-size:12px; width:190px; height:20px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown."  /></td>";
                
            if($Module_Form_Trans == 1){
                if ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)   
                    echo"  <td width='25px;' align='center' ><span >&nbsp;</span></td>";
                if($Module_Checks == 1)
                    echo"  <td width='25px;' align='center' ><span >&nbsp;</span></td>";
                if($Module_bill==1)
                    echo"  <td width='25px;' align='center' ><span >&nbsp;</span></td>";
                if ($ModuleInvoiceGrid == 1  && $module_invoicegridAll != 0)            
                    echo"  <td width='25px;' align='center' ><span >&nbsp;</span></td>";
            }
			//echo "	<td width='25px;' align='center' valign='center'><img src='img/confirm-1.png' id='imgSubmit_2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitRecordGrid2('".$i."', '".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail); return false;\" title='Submit Record' style='vertical-align:bottom;' ></td>";
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGrid2('".$i."','".$filepath."', '".$form."', '".$GridID."', '".$PTransId."', '".$TransType."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."',$Module_RestrictProjCost,$Module_RestrictCost,$Module_Project,$Module_CostCenter,$ModuleRestrictCashType,$Module_MultiCashType,$ShowDetail,'$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"	<td width='25px;'>$recno</td>";
			echo"</tr>";  

			$i+=1;	
		}
	
	echo"		<input type='hidden' name='RecCount_G2' id='RecCount_G2' value='$i'>"; 
	echo"		<input type='hidden' name='RecIndex_G2' id='RecIndex_G2' value='$RecIndex_G2'>"; 
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PTransId,$GridID,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}

function ShowTransDtGridDivisions($connection,$form,$PTransId,$PTransDtId,$PDivType,$arrayparams,$arrayaccess){
    
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels = mysql_fetch_array($result_labels);
	extract($row_labels);
    // echo $query_labels;
    
	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$DefaultCur   = $arrayparams['DefaultCur'];
	$Base1 		  = $arrayparams['Base1'];
	$Base2 		  = $arrayparams['Base2'];
	
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost = $arrayparams['Module_RestrictProjCost'];
    $Module_RestrictCost = $arrayparams['Module_RestrictCost'];
    $Module_Form_Trans = $arrayparams['Module_Form_Trans'];
	
	$Hide_Base2		     = $arrayparams['Hide_Base2'];
	$txtDate = $arrayparams['txtDate'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
		
	
	$columnsarray = array();
	if ($Module_Project == 1 || $Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt');
	if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) array_push($columnsarray, 'costcentcodedt');
	array_push($columnsarray, 'cstjourperc');
	array_push($columnsarray, 'cstjouramount');
	array_push($columnsarray, 'cstjouramount1');
	if($Hide_Base2==0)	array_push($columnsarray, 'cstjouramount2');
	
	$columnsarrayall = array("projectcodedt", "costcentcodedt", "cstjourperc", "cstjouramount", "cstjouramount1");
	                       
	if($Hide_Base2==0)	array_push($columnsarrayall, 'cstjouramount2');
	array_push($columnsarrayall,  "cstjouramount_h", "cstjouramount1_h");
	if($Hide_Base2==0)	array_push($columnsarrayall, 'cstjouramount2_h');	
	array_push($columnsarrayall,  "cstjourid", "cstjourbalperc", "cstjourbalamt","cstjourbalamt1");
	if($Hide_Base2==0)	array_push($columnsarrayall, 'cstjourbalamt2');	
	array_push($columnsarrayall,  "cstjourtotperc", "cstjourtotamt", "cstjourtotamt1");
	if($Hide_Base2==0)	array_push($columnsarrayall, 'cstjourtotamt2');
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd, ".
				 " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
	$TransDtAmount    = $sub_result[6];
	$TransDtAmount1   = $sub_result[7];
	$TransDtAmount2   = $sub_result[8];
		
	//Initializations for Div Ids
	$ContainerDiv = 'container3';
	$LoaderDiv    = 'Loader3';
	$HeaderDiv    = 'grid_headerDiv3';
	$ContentDiv   = 'grid_contentDiv3';
	$TableFocus   = 'table-focus-g3';
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv ' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '910px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:580px;'>";
	
		echo"<tr height='20px;'>";
		echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		
		if ($Module_Project == 1 || $Module_ProjectDt == 1) {
            echo"  <th width='125px;' align='center' ><span class='style1'>$Project</span></th>";
            echo"  <th width='125px;' align='center' ><span class='style1'>$Project Name</span></th>";
		}
		if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
            echo"  <th width='125px;' align='center' ><span class='style1'>$Costcenter</span></th>";
            echo"  <th width='125px;' align='center' ><span class='style1'>$Costcenter Name</span></th>";
		}
		
		echo"  <th width='45px;' align='center' ><span >$Per</span><span class='style2'>*</span></th>";
		echo"  <th width='85px;' align='center' ><span >$Amount</span><span class='style2'>*</span></th>";
		echo"  <th width='85px;' align='center' ><span >$Base1</span></th>";
		if($Hide_Base2==0) echo"  <th width='85px;' align='center' ><span >$Base2</span></th>";
		echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
		echo"  <th width='25px;' align='center' ><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '910px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:580px;'>";
		echo"<input type='hidden' name='SelectedRec_G3' id='SelectedRec_G3' value='$SelectedRec_G3'>
			 <input type='hidden' name='SelectedRecColor_G3' id='SelectedRecColor_G3' value='$SelectedRecColor_G3'>
			 <input type='hidden' name='ModRec_G3' id='ModRec_G3' value='$ModRec_G3'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, (100 - Round(Sum(ifNull(CstJourDt_Per,0)),2)) As CstJourDtPer, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(CstJourDt_Amount,0)),9) ) As CstJourDtAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(CstJourDt_Amount1,0)),9) ) As CstJourDtAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(CstJourDt_Amount2,0)),9) ) As CstJourDtAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt ".
						  " Inner Join Temp_CstjourDt As CstjourDt on TransDt.TransDt_ID = CstjourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtCstJourBalPerc_M  = $sub_result2[1];
			$txtCstJourBalAmt_M   = $sub_result2[2];
			$txtCstJourBalAmt1_M  = $sub_result2[3];
			$txtCstJourBalAmt2_M  = $sub_result2[4];
				
			$txtCstJourTotPerc  = 100;
			$txtCstJourTotAmt   = $sub_result2[5];
			$txtCstJourTotAmt1  = $sub_result2[6];
			$txtCstJourTotAmt2  = $sub_result2[7];
			
				
			$query = " SELECT CstJourDt_id, TransDt_ID, CstjourDt.Project_Code, CstjourDt.Costcenter_Code, ".
					 " Round(ifNull(CstJourDt_Amount,0), ".$DecimalBase."), Round(ifNull(CstJourDt_Amount1,0), ".$DecimalBase1."), ".
					 " Round(ifNull(CstJourDt_Amount2,0), ".$DecimalBase2."), Round(ifNull(CstJourDt_Per,0),2), ".
					 " ifNull(CstJourDt_Amount,0), ifNull(CstJourDt_Amount1,0), ifNull(CstJourDt_Amount2,0), ".
                     " Project_Name, Costcent_name ".
					 " FROM Temp_CstjourDt As CstjourDt ".
                     " Left Join Project on Project.Project_Code = CstjourDt.Project_Code".
                     " Left Join costcent on costcent.Costcent_Code = CstjourDt.Costcenter_Code".
					 " Where CstjourDt.TransDt_ID = '".$PTransDtId."' ";
				
			//echo $query;
			
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      	
			/// grid Motion
					$Motion = 1;
					$NextCell = 'chkjournumber[0]';	
						$TabIndex = 1;
					$down = 1;
					
		
			//////////
			
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtCstJourBalPerc  = $txtCstJourBalPerc_M + $rowsdt[7];
				$txtCstJourBalAmt   = $txtCstJourBalAmt_M  + $rowsdt[8];
				$txtCstJourBalAmt1  = $txtCstJourBalAmt1_M + $rowsdt[9];
				$txtCstJourBalAmt2  = $txtCstJourBalAmt2_M + $rowsdt[10];
			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_D['.$i.']\')"';
				
					
				echo"<tr id='CurRec_G3$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteDivisionDt('".$filepath."','".$form."','DEL','datagrid-1-d','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";

				echo"		<input type='hidden' name='txtCstJourId[$i]' id='cstjourid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtCstJourAmount[$i]'  id='cstjouramount_h[$i]'  value='".$rowsdt[8]."' >
							<input type='hidden' name='txtCstJourAmount1[$i]' id='cstjouramount1_h[$i]' value='".$rowsdt[9]."' >
							<input type='hidden' name='txtCstJourAmount2[$i]' id='cstjouramount2_h[$i]' value='".$rowsdt[10]."' >
							<input type='hidden' name='txtCstJourBalPerc[$i]'  id='cstjourbalperc[$i]'  value='$txtCstJourBalPerc' >
							<input type='hidden' name='txtCstJourBalAmt[$i]' id='cstjourbalamt[$i]'  value='$txtCstJourBalAmt' >
							<input type='hidden' name='txtCstJourBalAmt1[$i]' id='cstjourbalamt1[$i]'  value='$txtCstJourBalAmt1' >
							<input type='hidden' name='txtCstJourBalAmt2[$i]' id='cstjourbalamt2[$i]'  value='$txtCstJourBalAmt2' >
							<input type='hidden' name='txtCstJourTotPerc[$i]'  id='cstjourtotperc[$i]'  value='$txtCstJourTotPerc' >
							<input type='hidden' name='txtCstJourTotAmt[$i]' id='cstjourtotamt[$i]'  value='$txtCstJourTotAmt' >
							<input type='hidden' name='txtCstJourTotAmt1[$i]' id='cstjourtotamt1[$i]'  value='$txtCstJourTotAmt1' >
							<input type='hidden' name='txtCstJourTotAmt2[$i]' id='cstjourtotamt2[$i]'  value='$txtCstJourTotAmt2' >";
							
				if ($Module_Project == 1 || $Module_ProjectDt == 1) {
					echo"<td width='125px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[2]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
                            <label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(25,1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
                    echo"<td width='125px;' align='center'><input type='text' name='txtProjectNameDt[$i]' id='projectnamedt[$i]' value='".$rowsdt[11]."' class='".$ClassE."' style='width:120px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span></td>";
				} else {
					echo"<input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' />";
				}
				if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
					echo"<td width='125px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
                            <label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(25,1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
                    echo"<td width='125px;' align='center'><input type='text' name='txtCostCentNameDt[$i]' id='costcentnamedt[$i]' value='".$rowsdt[12]."' class='".$ClassE."' style='width:120px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span></td>";
				} else {
					echo"<input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' />";
				}			
				//$TotalPer = $TotalPer + $rowsdt[7];
				
				echo"   <td width='45px;' align='center'><input type='text' name='txtCstJourPerc[$i]' id='cstjourperc[$i]' value='".$rowsdt[7]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:40px; height:20px;' onBlur=\"CheckPercentage(this.id,'cstjourperc[$i]');\" onChange=\"SetModRecord('ModRec_G3','$i'); SetPercentageDivision(1,this.id,$DecimalBase1,$DecimalBase2,'',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount_D[$i]' id='cstjouramount[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(1,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount1_D[$i]' id='cstjouramount1[$i]' value='".$rowsdt[5]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(2,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				if($Hide_Base2==0) echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount2_D[$i]' id='cstjouramount2[$i]' value='".$rowsdt[6]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(3,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtCstJourAmount2_D[$i]' id='cstjouramount2[$i]' value='".$rowsdt[6]."' maxlength='20' >";
				
				//echo "	<td width='25px;' align='center' valign='center'><img src='img/confirm-1.png' id='imgSubmit_D[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitDivisionDt('".$i."','".$filepath."', '".$form."', 'ADD','datagrid-1-d','".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex',$down, $Module_RestrictProjCost, $Module_RestrictCost); return false;\" title='Submit Record' style='vertical-align:bottom;'  ></td>";
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_D[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitDivisionDt('".$i."','".$filepath."', '".$form."', 'ADD','datagrid-1-d','".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down', '$Module_RestrictProjCost', '$Module_RestrictCost');return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_D['.$i.']\')"';
			
			
		$sub_query2 = " Select TransDt.TransDt_ID, (100 - Round(Sum(ifNull(CstJourDt_Per,0)),2)) As CstJourDtPer,  ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(CstJourDt_Amount,0))), ".$DecimalBase.")  As CstJourDtAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(CstJourDt_Amount1,0))), ".$DecimalBase1.") As CstJourDtAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(CstJourDt_Amount2,0))), ".$DecimalBase2.") As CstJourDtAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(CstJourDt_Amount,0)),9) ) As CstJourDtAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(CstJourDt_Amount1,0)),9) ) As CstJourDtAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(CstJourDt_Amount2,0)),9) ) As CstJourDtAmount2 ".
					  " From Temp_TransDt As TransDt ".
					  " Inner Join Temp_CstjourDt As CstjourDt on TransDt.TransDt_ID = CstjourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID ";

		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		if ($sub_result2[0] != "") { 
			$txtCstJourBalPerc  = $sub_result2[1];
			$txtCstJourBalAmt   = $sub_result2[8];
			$txtCstJourBalAmt1  = $sub_result2[9];
			$txtCstJourBalAmt2  = $sub_result2[10];
			
			$txtCstJourTotPerc  = 100;
			$txtCstJourTotAmt   = $sub_result2[5];
			$txtCstJourTotAmt1  = $sub_result2[6];
			$txtCstJourTotAmt2  = $sub_result2[7];
			
			$txtCstJourPerc       = $sub_result2[1];
			$txtCstJourAmount_D   = $sub_result2[2];
			$txtCstJourAmount1_D  = $sub_result2[3];
			$txtCstJourAmount2_D  = $sub_result2[4];
			
			$txtCstJourAmount   = $sub_result2[8];
			$txtCstJourAmount1  = $sub_result2[9];
			$txtCstJourAmount2  = $sub_result2[10];	
		} else {
			$txtCstJourBalPerc  = 100;
			$txtCstJourBalAmt   = $TransDtAmount;
			$txtCstJourBalAmt1  = $TransDtAmount1;
			$txtCstJourBalAmt2  = $TransDtAmount2;
			
			$txtCstJourTotPerc  = 100;
			$txtCstJourTotAmt   = $TransDtAmount;
			$txtCstJourTotAmt1  = $TransDtAmount1;
			$txtCstJourTotAmt2  = $TransDtAmount2;
			
			$txtCstJourPerc       = 100;
			$txtCstJourAmount_D   = number_format($TransDtAmount,$DecimalBase,".","");
			$txtCstJourAmount1_D  = number_format($TransDtAmount1,$DecimalBase1,".","");
			$txtCstJourAmount2_D  = number_format($TransDtAmount2,$DecimalBase2,".","");
			
			$txtCstJourAmount   = $TransDtAmount;
			$txtCstJourAmount1  = $TransDtAmount1;
			$txtCstJourAmount2  = $TransDtAmount2;
		}
			

		echo"<tr id='CurRec_G3$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G3');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "		<input type='hidden' name='txtCstJourId[$i]' id='cstjourid[$i]' value='$txtCstJourId' >
					<input type='hidden' name='txtCstJourAmount[$i]'  id='cstjouramount_h[$i]'  value='$txtCstJourAmount' >
					<input type='hidden' name='txtCstJourAmount1[$i]' id='cstjouramount1_h[$i]' value='$txtCstJourAmount1' >
					<input type='hidden' name='txtCstJourAmount2[$i]' id='cstjouramount2_h[$i]' value='$txtCstJourAmount2' >
					<input type='hidden' name='txtCstJourBalPerc[$i]'  id='cstjourbalperc[$i]'  value='$txtCstJourBalPerc' >
					<input type='hidden' name='txtCstJourBalAmt[$i]' id='cstjourbalamt[$i]'  value='$txtCstJourBalAmt' >
					<input type='hidden' name='txtCstJourBalAmt1[$i]' id='cstjourbalamt1[$i]'  value='$txtCstJourBalAmt1' >
					<input type='hidden' name='txtCstJourBalAmt2[$i]' id='cstjourbalamt2[$i]'  value='$txtCstJourBalAmt2' >
					<input type='hidden' name='txtCstJourTotPerc[$i]'  id='cstjourtotperc[$i]'  value='$txtCstJourTotPerc' >
					<input type='hidden' name='txtCstJourTotAmt[$i]' id='cstjourtotamt[$i]'  value='$txtCstJourTotAmt' >
					<input type='hidden' name='txtCstJourTotAmt1[$i]' id='cstjourtotamt1[$i]'  value='$txtCstJourTotAmt1' >
					<input type='hidden' name='txtCstJourTotAmt2[$i]' id='cstjourtotamt2[$i]'  value='$txtCstJourTotAmt2' >";
				
		if ($Module_Project == 1 || $Module_ProjectDt == 1) {
			echo"<td width='125px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='$txtProjectCodeDt[$i]' class='".$ClassI."' onBlur=\"checkperc('$txtCstJourPerc')\" style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
                    <label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onBlur=\"checkperc('$txtCstJourPerc')\" onClick='showlistProjectDt(25,1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
            echo"<td width='125px;' align='center'><input type='text' name='txtProjectNameDt[$i]' id='projectnamedt[$i]' value='' class='".$ClassE."' style='width:120px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span></td>";
		} else {
			echo"<input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' />";
		}
		if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
			echo"<td width='125px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='$txtCostCentCodeDt[$i]' class='".$ClassI."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
                    <label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"   onBlur=\"checkperc('$txtCstJourPerc')\" onClick='showlistCostcenterDt(25,1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
            echo"<td width='125px;' align='center'><input type='text' name='txtCostCentNameDt[$i]' id='costcentnamedt[$i]' value='' class='".$ClassE."' style='width:120px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G3','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span></td>";
		} else {
			echo"<input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' />";
		}			
										
		echo"   <td width='45px;' align='center'><input type='text' name='txtCstJourPerc[$i]' id='cstjourperc[$i]' value='$txtCstJourPerc' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:40px; height:20px;' onBlur=\"CheckPercentage(this.id,'cstjourbalperc[$i]');checkperc('$txtCstJourPerc')\" onChange=\"SetModRecord('ModRec_G3','$i'); SetPercentageDivision(1,this.id,$DecimalBase1,$DecimalBase2,'',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount_D[$i]' id='cstjouramount[$i]' value='$txtCstJourAmount_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);checkperc('$txtCstJourPerc')' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(1,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount1_D[$i]' id='cstjouramount1[$i]' value='$txtCstJourAmount1_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);checkperc('$txtCstJourPerc')' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(2,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		if($Hide_Base2==0) echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount2_D[$i]' id='cstjouramount2[$i]' value='$txtCstJourAmount2_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);checkperc('$txtCstJourPerc')' onChange=\"SetModRecord('ModRec_G3','$i'); SetAmountDivision(3,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		else 				echo"	<input type='hidden' name='txtCstJourAmount2_D[$i]' id='cstjouramount2[$i]' value='0' maxlength='20' >";
			
		
		echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_D[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitDivisionDt('".$i."','".$filepath."', '".$form."', 'ADD','datagrid-1-d','".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down', '$Module_RestrictProjCost', '$Module_RestrictCost'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
}

function ShowTransDtGridDivisions2($connection,$form,$PTransId,$PTransDtId,$PDivType,$arrayparams,$arrayaccess){
    //echo "test";
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels    = mysql_fetch_array($result_labels);
	extract($row_labels);
	
	$DecimalBase  				= $arrayparams['DecimalBase'];
	$DecimalBase1 				= $arrayparams['DecimalBase1'];
	$DecimalBase2 				= $arrayparams['DecimalBase2'];
	$DefaultCur   				= $arrayparams['DefaultCur'];
	$Base1 						= $arrayparams['Base1'];
	$Base2 						= $arrayparams['Base2'];
	
	$Module_ProjectDt 			= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt 		= $arrayparams['Module_CostCenterDt'];
	$Module_Project 			= $arrayparams['Module_Project'];
	$Module_CostCenter 			= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost 	= $arrayparams['Module_RestrictProjCost'];
    $Module_RestrictCost 		= $arrayparams['Module_RestrictCost'];
    $Module_Form_Trans 			= $arrayparams['Module_Form_Trans'];
	
	$Hide_Base2 				= $arrayparams['Hide_Base2'];
	
	$txtDate = $arrayparams['txtDate'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
		
	/// grid Motion
					$Motion = 1;
					$NextCell = 'chkjournumber2[0]';	
						$TabIndex = 1;
					$down = 1;
					
		
			//////////
			
			
			
			
	$columnsarray = array();
	if ($Module_Project == 1 || $Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt2');
	if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) array_push($columnsarray, 'costcentcodedt2');
	array_push($columnsarray, 'cstjourperc2');
	array_push($columnsarray, 'cstjouramount20');
	array_push($columnsarray, 'cstjouramount21');
	if($Hide_Base2 == 0 ) array_push($columnsarray, 'cstjouramount22');
	
	$columnsarrayall = array("projectcodedt2", "costcentcodedt2", "cstjourperc2", "cstjouramount20", "cstjouramount21");
	                      
	if($Hide_Base2 == 0 )  	array_push($columnsarrayall, 'cstjouramount22');	
	array_push($columnsarrayall, "cstjouramount20_h", "cstjouramount21_h");	
	if($Hide_Base2 == 0 )  	array_push($columnsarrayall, 'cstjouramount22_h');	
	array_push($columnsarrayall, "cstjourid2", "cstjourbalperc2", "cstjourbalamt20", "cstjourbalamt21");	
	if($Hide_Base2 == 0 )  	array_push($columnsarrayall, 'cstjourbalamt22');	
	array_push($columnsarrayall, "cstjourtotperc2", "cstjourtotamt20", "cstjourtotamt21");
	if($Hide_Base2 == 0 )  	array_push($columnsarrayall, 'cstjourtotamt22');
	
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd, ".
				 " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
	$TransDtAmount    = $sub_result[6];
	$TransDtAmount1   = $sub_result[7];
	$TransDtAmount2   = $sub_result[8];
		
	//Initializations for Div Ids
	$ContainerDiv = 'container4';
	$LoaderDiv    = 'Loader4';
	$HeaderDiv    = 'grid_headerDiv4';
	$ContentDiv   = 'grid_contentDiv4';
	$TableFocus   = 'table-focus-g4';
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv ' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '910px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:580px;'>";
	
		echo"<tr height='20px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		if ($Module_Project == 1 || $Module_ProjectDt == 1) {
            echo"  <th width='125px;' align='center' ><span class='style1'>$Project</span></th>";
            echo"  <th width='125px;' align='center' ><span class='style1'>$Project Name</span></th>";
		}
		if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
            echo"  <th width='125px;' align='center' ><span class='style1'>$Costcenter</span></th>";
            echo"  <th width='125px;' align='center' ><span class='style1'>$Costcenter Name</span></th>";
		}
		
		echo"  <th width='45px;' align='center' ><span >$Per</span><span class='style2'>*</span></th>";
		echo"  <th width='85px;' align='center' ><span >$Amount</span><span class='style2'>*</span></th>";
		echo"  <th width='85px;' align='center' ><span >$Base1</span> </th>";
		if($Hide_Base2 == 0 ) echo"  <th width='85px;' align='center' ><span >$Base2</span></th>";
		echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
		echo"  <th width='25px;' align='center' ><span >&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '910px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:580px;'>";
		echo"<input type='hidden' name='SelectedRec_G4' id='SelectedRec_G4' value='$SelectedRec_G4'>
			 <input type='hidden' name='SelectedRecColor_G4' id='SelectedRecColor_G4' value='$SelectedRecColor_G4'>
			 <input type='hidden' name='ModRec_G4' id='ModRec_G4' value='$ModRec_G4'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, (100 - Round(Sum(ifNull(CstJourDt_Per,0)),2)) As CstJourDtPer, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(CstJourDt_Amount,0)),9) ) As CstJourDtAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(CstJourDt_Amount1,0)),9) ) As CstJourDtAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(CstJourDt_Amount2,0)),9) ) As CstJourDtAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt ".
						  " Inner Join Temp_CstjourDt As CstjourDt on TransDt.TransDt_ID = CstjourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtCstJourBalPerc2_M  = $sub_result2[1];
			$txtCstJourBalAmt20_M  = $sub_result2[2];
			$txtCstJourBalAmt21_M  = $sub_result2[3];
			$txtCstJourBalAmt22_M  = $sub_result2[4];
				
			$txtCstJourTotPerc2  = 100;
			$txtCstJourTotAmt20  = $sub_result2[5];
			$txtCstJourTotAmt21  = $sub_result2[6];
			$txtCstJourTotAmt22  = $sub_result2[7];
			
				
			$query = " SELECT CstJourDt_id, TransDt_ID, CstjourDt.Project_Code, CstjourDt.Costcenter_Code, ".
					 " Round(ifNull(CstJourDt_Amount,0), ".$DecimalBase."), Round(ifNull(CstJourDt_Amount1,0), ".$DecimalBase1."), ".
					 " Round(ifNull(CstJourDt_Amount2,0), ".$DecimalBase2."), Round(ifNull(CstJourDt_Per,0),2), ".
					 " ifNull(CstJourDt_Amount,0), ifNull(CstJourDt_Amount1,0), ifNull(CstJourDt_Amount2,0), ".
                     " Project.project_name, Costcent.costcent_name ".
					 " FROM Temp_CstjourDt As CstjourDt ".
                     " Left Join Costcent on Costcent.costcent_code = CstjourDt.costcenter_code ".
                     " Left Join Project on Project.Project_code = CstjourDt.Project_code ".
					 " Where CstjourDt.TransDt_ID = '".$PTransDtId."' ";
				
			//echo $query;
			
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtCstJourBalPerc2  = $txtCstJourBalPerc2_M + $rowsdt[7];
				$txtCstJourBalAmt20  = $txtCstJourBalAmt20_M + $rowsdt[8];
				$txtCstJourBalAmt21  = $txtCstJourBalAmt21_M + $rowsdt[9];
				$txtCstJourBalAmt22  = $txtCstJourBalAmt22_M + $rowsdt[10];
			
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_D['.$i.']\')"';
				
					
				echo"<tr id='CurRec_G4$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteDivisionDt('".$filepath."','".$form."','DEL','datagrid-2-d','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";

				echo"		<input type='hidden' name='txtCstJourId2[$i]' id='cstjourid2[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtCstJourAmount20[$i]'  id='cstjouramount20_h[$i]'  value='".$rowsdt[8]."' >
							<input type='hidden' name='txtCstJourAmount21[$i]' id='cstjouramount21_h[$i]' value='".$rowsdt[9]."' >
							<input type='hidden' name='txtCstJourAmount22[$i]' id='cstjouramount22_h[$i]' value='".$rowsdt[10]."' >
							<input type='hidden' name='txtCstJourBalPerc2[$i]'  id='cstjourbalperc2[$i]'  value='$txtCstJourBalPerc2' >
							<input type='hidden' name='txtCstJourBalAmt20[$i]' id='cstjourbalamt20[$i]'  value='$txtCstJourBalAmt20' >
							<input type='hidden' name='txtCstJourBalAmt21[$i]' id='cstjourbalamt21[$i]'  value='$txtCstJourBalAmt21' >
							<input type='hidden' name='txtCstJourBalAmt22[$i]' id='cstjourbalamt22[$i]'  value='$txtCstJourBalAmt22' >
							<input type='hidden' name='txtCstJourTotPerc2[$i]'  id='cstjourtotperc2[$i]'  value='$txtCstJourTotPerc2' >
							<input type='hidden' name='txtCstJourTotAmt20[$i]' id='cstjourtotamt20[$i]'  value='$txtCstJourTotAmt20' >
							<input type='hidden' name='txtCstJourTotAmt21[$i]' id='cstjourtotamt21[$i]'  value='$txtCstJourTotAmt21' >
							<input type='hidden' name='txtCstJourTotAmt22[$i]' id='cstjourtotamt22[$i]'  value='$txtCstJourTotAmt22' >";
							
				if ($Module_Project == 1 || $Module_ProjectDt == 1) {
					echo"<td width='125px;' align='center'><input type='text' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='".$rowsdt[2]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode2[$i]');\" ".$KeyDown." /></span>
                            <label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(25,2,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
                    echo"<td width='125px;' align='center'><input type='text' name='txtProjectNameDt2[$i]' id='projectnamedt2[$i]' value='".$rowsdt[11]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode2[$i]');\" ".$KeyDown." /></span></td>";
				} else {
					echo"<input type='hidden' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='' />";
				}
				if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
					echo"<td width='125px;' align='center'><input type='text' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='".$rowsdt[3]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode2[$i]');\" ".$KeyDown." /></span>
                            <label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(25,2,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
                    echo"<td width='125px;' align='center'><input type='text' name='txtCostCentNameDt2[$i]' id='costcentnamedt2[$i]' value='".$rowsdt[12]."' class='".$ClassE."' style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode2[$i]');\" ".$KeyDown." /></span></td>";
				} else {
					echo"<input type='hidden' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='' />";
				}			
							
				echo"   <td width='45px;' align='center'><input type='text' name='txtCstJourPerc2[$i]' id='cstjourperc2[$i]' value='".$rowsdt[7]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:40px; height:20px;' onBlur=\"CheckPercentage(this.id,'cstjourperc2[$i]');\" onChange=\"SetModRecord('ModRec_G4','$i'); SetPercentageDivision(2,this.id,$DecimalBase1,$DecimalBase2,'',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount20_D[$i]' id='cstjouramount20[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(4,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount21_D[$i]' id='cstjouramount21[$i]' value='".$rowsdt[5]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(5,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				if($Hide_Base2 == 0 ) echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount22_D[$i]' id='cstjouramount22[$i]' value='".$rowsdt[6]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(6,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtCstJourAmount22_D[$i]' id='cstjouramount22[$i]' value='".$rowsdt[6]."' maxlength='20' >";
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_D[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitDivisionDt2('".$i."','".$filepath."', '".$form."', 'ADD','datagrid-2-d','".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down', '$Module_RestrictProjCost', '$Module_RestrictCost'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);'></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_D['.$i.']\')"';
			
		$sub_query2 = " Select TransDt.TransDt_ID, (100 - Round(Sum(ifNull(CstJourDt_Per,0)),2)) As CstJourDtPer,  ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(CstJourDt_Amount,0))), ".$DecimalBase.")  As CstJourDtAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(CstJourDt_Amount1,0))), ".$DecimalBase1.") As CstJourDtAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(CstJourDt_Amount2,0))), ".$DecimalBase2.") As CstJourDtAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(CstJourDt_Amount,0)),9) ) As CstJourDtAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(CstJourDt_Amount1,0)),9) ) As CstJourDtAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(CstJourDt_Amount2,0)),9) ) As CstJourDtAmount2 ".
					  " From Temp_TransDt As TransDt ".
					  " Inner Join Temp_CstjourDt As CstjourDt on TransDt.TransDt_ID = CstjourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID ";

		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		if ($sub_result2[0] != "") { 
			$txtCstJourBalPerc2  = $sub_result2[1];
			$txtCstJourBalAmt20  = $sub_result2[8];
			$txtCstJourBalAmt21  = $sub_result2[9];
			$txtCstJourBalAmt22  = $sub_result2[10];
			
			$txtCstJourTotPerc2  = 100;
			$txtCstJourTotAmt20  = $sub_result2[5];
			$txtCstJourTotAmt21  = $sub_result2[6];
			$txtCstJourTotAmt22  = $sub_result2[7];
			
			$txtCstJourPerc2       = $sub_result2[1];
			$txtCstJourAmount20_D  = $sub_result2[2];
			$txtCstJourAmount21_D  = $sub_result2[3];
			$txtCstJourAmount22_D  = $sub_result2[4];
			
			$txtCstJourAmount20  = $sub_result2[8];
			$txtCstJourAmount21  = $sub_result2[9];
			$txtCstJourAmount22  = $sub_result2[10];	
		} else {
			$txtCstJourBalPerc2  = 100;
			$txtCstJourBalAmt20  = $TransDtAmount;
			$txtCstJourBalAmt21  = $TransDtAmount1;
			$txtCstJourBalAmt22  = $TransDtAmount2;
			
			$txtCstJourTotPerc2  = 100;
			$txtCstJourTotAmt20  = $TransDtAmount;
			$txtCstJourTotAmt21  = $TransDtAmount1;
			$txtCstJourTotAmt22  = $TransDtAmount2;
			
			$txtCstJourPerc2       = 100;
			$txtCstJourAmount20_D  = number_format($TransDtAmount,$DecimalBase,".","");
			$txtCstJourAmount21_D  = number_format($TransDtAmount1,$DecimalBase1,".","");
			$txtCstJourAmount22_D  = number_format($TransDtAmount2,$DecimalBase2,".","");
			
			$txtCstJourAmount20  = $TransDtAmount;
			$txtCstJourAmount21  = $TransDtAmount1;
			$txtCstJourAmount22  = $TransDtAmount2;
		}
			

		echo"<tr id='CurRec_G4$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G4');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "		<input type='hidden' name='txtCstJourId2[$i]' id='cstjourid2[$i]' value='$txtCstJourId2' >
					<input type='hidden' name='txtCstJourAmount20[$i]'  id='cstjouramount20_h[$i]'  value='$txtCstJourAmount20' >
					<input type='hidden' name='txtCstJourAmount21[$i]' id='cstjouramount21_h[$i]' value='$txtCstJourAmount21' >
					<input type='hidden' name='txtCstJourAmount22[$i]' id='cstjouramount22_h[$i]' value='$txtCstJourAmount22' >
					<input type='hidden' name='txtCstJourBalPerc2[$i]'  id='cstjourbalperc2[$i]'  value='$txtCstJourBalPerc2' >
					<input type='hidden' name='txtCstJourBalAmt20[$i]' id='cstjourbalamt20[$i]'  value='$txtCstJourBalAmt20' >
					<input type='hidden' name='txtCstJourBalAmt21[$i]' id='cstjourbalamt21[$i]'  value='$txtCstJourBalAmt21' >
					<input type='hidden' name='txtCstJourBalAmt22[$i]' id='cstjourbalamt22[$i]'  value='$txtCstJourBalAmt22' >
					<input type='hidden' name='txtCstJourTotPerc2[$i]'  id='cstjourtotperc2[$i]'  value='$txtCstJourTotPerc2' >
					<input type='hidden' name='txtCstJourTotAmt20[$i]' id='cstjourtotamt20[$i]'  value='$txtCstJourTotAmt20' >
					<input type='hidden' name='txtCstJourTotAmt21[$i]' id='cstjourtotamt21[$i]'  value='$txtCstJourTotAmt21' >
					<input type='hidden' name='txtCstJourTotAmt22[$i]' id='cstjourtotamt22[$i]'  value='$txtCstJourTotAmt22' >";
				
		if ($Module_Project == 1 || $Module_ProjectDt == 1) {
			echo"<td width='125px;' align='center'><input type='text' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='$txtProjectCodeDt2[$i]' class='".$ClassI."'  onBlur=\"checkperc2('$txtCstJourPerc2')\"  style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode2[$i]');\" ".$KeyDown." /></span>
                    <label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(25,2,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
            echo"<td width='125px;' align='center'><input type='text' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='$txtProjectCodeDt2[$i]' class='".$ClassI."'  onBlur=\"checkperc2('$txtCstJourPerc2')\"  style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode2[$i]');\" ".$KeyDown." /></span></td>";
		} else {
			echo"<input type='hidden' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='' />";
		}
		if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1) {
			echo"<td width='125px;' align='center'><input type='text' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='$txtCostCentCodeDt2[$i]' class='".$ClassI."' onBlur=\"checkperc2('$txtCstJourPerc2')\"  style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode2[$i]');\" ".$KeyDown." /></span>
                    <label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode2[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(25,2,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
            echo"<td width='125px;' align='center'><input type='text' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='$txtCostCentCodeDt2[$i]' class='".$ClassI."' onBlur=\"checkperc2('$txtCstJourPerc2')\"  style='width:95px;height:20px;' maxlength='20' onchange=\"SetModRecord('ModRec_G4','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode2[$i]');\" ".$KeyDown." /></span></td>";
		} else {
			echo"<input type='hidden' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='' />";
		}			
										
		echo"   <td width='45px;' align='center'><input type='text' name='txtCstJourPerc2[$i]' id='cstjourperc2[$i]' value='$txtCstJourPerc2' maxlength='20' class='".$ClassI."'  onBlur=\"checkperc2('$txtCstJourPerc2')\" style='text-align:right; font-size:12px; width:40px; height:20px;' onBlur=\"CheckPercentage(this.id,'cstjourbalperc2[$i]');\" onChange=\"SetModRecord('ModRec_G4','$i'); SetPercentageDivision(2,this.id,$DecimalBase1,$DecimalBase2,'',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount20_D[$i]' id='cstjouramount20[$i]' value='$txtCstJourAmount20_D' maxlength='20' class='".$ClassI."' onBlur=\"checkperc2('$txtCstJourPerc2')\"  style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(4,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount21_D[$i]' id='cstjouramount21[$i]' value='$txtCstJourAmount21_D' maxlength='20' class='".$ClassI."'  onBlur=\"checkperc2('$txtCstJourPerc2')\" style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(5,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		if($Hide_Base2 == 0 ) echo"	<td width='85px;' align='center'><input type='text' name='txtCstJourAmount22_D[$i]' id='cstjouramount22[$i]' value='$txtCstJourAmount22_D' maxlength='20' class='".$ClassI."'  onBlur=\"checkperc2('$txtCstJourPerc2')\" style='text-align:right; font-size:12px; width:80px; height:20px;' onBlur='CheckAmount(this.id);' onChange=\"SetModRecord('ModRec_G4','$i'); SetAmountDivision(6,$DecimalBase1,$DecimalBase2,'".$TransDtCurrCode."','".$Base1."','".$Base2."','".$txtDate."','',$i);\" ".$KeyDown." /></td>";
		else 				echo"	<input type='hidden' name='txtCstJourAmount22_D[$i]' id='cstjouramount22[$i]' value='$txtCstJourAmount22_D' maxlength='20' >";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_D[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitDivisionDt2('".$i."','".$filepath."', '".$form."', 'ADD','datagrid-2-d','".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down', '$Module_RestrictProjCost', '$Module_RestrictCost'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
}

function ShowTransDtGridChecks($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess, $query_labels){
	
	    $query_labels = $_SESSION['query_labels'];
	    $result_labels = mysql_query($query_labels, $connection);
		//echo $result_labels;
		$row_labels    = mysql_fetch_array($result_labels);
		extract($row_labels);
		//echo "test";;
	$Module_Project 			= $arrayparams['Module_Project'];
	$Module_CostCenter			= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost 	= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 		= $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView 	= $arrayparams['Module_TransStandardView'];
	$Module_ShowBalance 		= $arrayparams['Module_ShowBalance'];
	$ModuleRestrictCashType 	= $arrayparams['ModuleRestrictCashType'];
	$Module_MultiCashType 		= $arrayparams['Module_MultiCashType'];
	$Module_ProjectDt 			= $arrayparams['Module_ProjectDt'];
    $Module_CostCenterDt 		= $arrayparams['Module_CostCenterDt'];
    $Module_Form_Trans          = $arrayparams['Module_Form_Trans'];
	
		
	$DecimalBase  				= $arrayparams['DecimalBase'];
	$DecimalBase1 				= $arrayparams['DecimalBase1'];
	$DecimalBase2 				= $arrayparams['DecimalBase2'];
	$DefaultCur 				= $arrayparams['DefaultCur'];
	$Base1 						= $arrayparams['Base1'];
	$Base2 						= $arrayparams['Base2'];
	
	$Hide_ValueDate 			= $arrayparams['Hide_ValueDate'];
	$Hide_Base2 				= $arrayparams['Hide_Base2'];
	
	$txtDate = $arrayparams['txtDate'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	
	$columnsarray = array("chkjournumber", "chkjourbank"); 
	if($Hide_ValueDate == 0) array_push($columnsarray, "chkjourvaluedate");
	array_push($columnsarray,"chkjouramount", "chkjouramount1");
	if($Hide_Base2 == 0) array_push($columnsarray, "chkjouramount2");
	
	$columnsarrayall = array("chkjournumber", "chkjourbank" );
	if($Hide_ValueDate == 0) array_push($columnsarrayall, "chkjourvaluedate");
	array_push($columnsarrayall, "chkjouramount", "chkjouramount1");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "chkjouramount2");
	array_push($columnsarrayall, "chkjouramount_h", "chkjouramount1_h");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "chkjouramount2_h");
	array_push($columnsarrayall, "chkjourledgerno", "chkjourcurrcode", "chkjourid", "chkjourtype", "chkjourbalamt", "chkjourbalamt1");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "chkjourbalamt2");
	array_push($columnsarrayall, "chkjourtotamt", "chkjourtotamt1");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "chkjourtotamt2");
	
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	if(($LedgerActivity==1 && $TransDtdbcd=='D') or ($LedgerActivity==2 && $TransDtdbcd=='C')) {
		$showlist = 0;
		$status = '';	
	}	
	else {
		$showlist = 1;
		$status = 'readonly';	
	}	
		

		
		/// grid Motion
		$Motion = 1;
		$NextCell = 'billjournumber[0]';
		$down = 0;
		
	
		if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)){
			$TabIndex = 2 ;		
			}
		else 	
		$TabIndex = 1 ;		
	/////////////
	
	
	
	
	//Initializations for Div Ids
	$ContainerDiv = 'container5';
	$LoaderDiv    = 'Loader5';
	$HeaderDiv    = 'grid_headerDiv5';
	$ContentDiv   = 'grid_contentDiv5';
	$TableFocus   = 'table-focus-g5';
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '910px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'>$CheckNo</th>";
		echo"  <th width='105px;' align='left'><span>$Bank</span></th>";
		if($Hide_ValueDate==0) echo"  <th width='70px;' align='center'><span>$ValueDate</span></th>";
		echo"  <th width='45px;' align='center'><span>$Curr</span></th>";
		echo"  <th width='95px;' align='center'><span>$Amount</span></th>";
		echo"  <th width='95px;' align='center'><span>$Base1</span></th>";
		if($Hide_Base2==0)  echo"  <th width='95px;' align='center'><span>$Base2</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '910px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
		echo"<input type='hidden' name='SelectedRec_G5' id='SelectedRec_G5' value='$SelectedRec_G5'>
			 <input type='hidden' name='SelectedRecColor_G5' id='SelectedRecColor_G5' value='$SelectedRecColor_G5'>
			 <input type='hidden' name='ModRec_G5' id='ModRec_G5' value='$ModRec_G5'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(Chk_Amount,0)),9) ) As ChkAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Chk_Amount1,0)),9) ) As ChkAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Chk_Amount2,0)),9) ) As ChkAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join Temp_ChkJourDt on TransDt.TransDt_ID = Temp_ChkJourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtChkJourBalAmt_M   = $sub_result2[1];
			$txtChkJourBalAmt1_M  = $sub_result2[2];
			$txtChkJourBalAmt2_M  = $sub_result2[3];
			
			$txtChkJourTotAmt   = $sub_result2[4];
			$txtChkJourTotAmt1  = $sub_result2[5];
			$txtChkJourTotAmt2  = $sub_result2[6];
			
		 
			$query = " SELECT ChkJourDt_Id, TransDt_ID, Ledger_Number, Chk_Number, Chk_Bank, date_format(Chk_ValueDate,'%d/%m/%Y'), Chk_Type, ChkJourDt.Currency_Code, ".
					 " Round(ifNull(Chk_Amount,0), ".$DecimalBase."), Round(ifNull(Chk_Amount1,0), ".$DecimalBase1."), Round(ifNull(Chk_Amount2,0), ".$DecimalBase2."), ".
					 " ifNull(Chk_Amount,0), ifNull(Chk_Amount1,0), ifNull(Chk_Amount2,0) ".
					 " FROM Temp_ChkJourDt As ChkJourDt ".
					 " WHERE ChkJourDt.TransDt_ID = '".$PTransDtId."'";
				
			//echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtChkJourBalAmt   = $txtChkJourBalAmt_M  + $rowsdt[11];
				$txtChkJourBalAmt1  = $txtChkJourBalAmt1_M + $rowsdt[12];
				$txtChkJourBalAmt2  = $txtChkJourBalAmt2_M + $rowsdt[13];
					
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_C['.$i.']\')"';
				
				echo"<tr id='CurRec_G5$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteChkJour('".$filepath."','".$form."','DEL','datagrid-1-c','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtChkJourId[$i]' id='chkjourid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtChkJourType[$i]' id='chkjourtype[$i]' value='".$rowsdt[6]."' >
							<input type='hidden' name='txtChkJourLedgerNo[$i]' id='chkjourledgerno[$i]' value='".$rowsdt[2]."' >
							<input type='hidden' name='txtChkJourAmount[$i]'  id='chkjouramount_h[$i]'  value='".$rowsdt[11]."' >
							<input type='hidden' name='txtChkJourAmount1[$i]' id='chkjouramount1_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtChkJourAmount2[$i]' id='chkjouramount2_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtChkJourBalAmt[$i]' id='chkjourbalamt[$i]'  value='$txtChkJourBalAmt' >
							<input type='hidden' name='txtChkJourBalAmt1[$i]' id='chkjourbalamt1[$i]'  value='$txtChkJourBalAmt1' >
							<input type='hidden' name='txtChkJourBalAmt2[$i]' id='chkjourbalamt2[$i]'  value='$txtChkJourBalAmt2' >
							<input type='hidden' name='txtChkJourTotAmt[$i]' id='chkjourtotamt[$i]'  value='$txtChkJourTotAmt' >
							<input type='hidden' name='txtChkJourTotAmt1[$i]' id='chkjourtotamt1[$i]'  value='$txtChkJourTotAmt1' >
							<input type='hidden' name='txtChkJourTotAmt2[$i]' id='chkjourtotamt2[$i]'  value='$txtChkJourTotAmt2' >
							<input type='text' name='txtChkJourNumber[$i]' id='chkjournumber[$i]' value='".$rowsdt[3]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown." $status />";
							
							if ($showlist == 1) 
								echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistCheck(1,".$i.",'".$PTransDtId."','".$rowsdt[0]."');\" style='vertical-align:bottom;' title='Select Check'  /></span></label>";
				echo"	</td>";
	
										
				echo"  	<td width='105px;' align='center'><input type='text' name='txtChkJourBank[$i]' id='chkjourbank[$i]' value='".$rowsdt[4]."' maxlength='30' class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown."  /></td>";
				if($Hide_ValueDate==0) echo"   <td width='70px;' align='center'><input type='text' name='txtChkJourValueDate[$i]' id='chkjourvaluedate[$i]' value='".$rowsdt[5]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown." $status ></td>";
				else 				  echo"   <input type='hidden' name='txtChkJourValueDate[$i]' id='chkjourvaluedate[$i]' value='".$rowsdt[5]."' maxlength='10' >";
				echo"   <td width='45px;' align='center'><input type='text' name='txtChkJourCurrCode[$i]' id='chkjourcurrcode[$i]' value='".$rowsdt[7]."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount_D[$i]' id='chkjouramount[$i]' value='".$rowsdt[8]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(5,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount1_D[$i]' id='chkjouramount1[$i]' value='".$rowsdt[9]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(6,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				if($Hide_Base2==0) echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount2_D[$i]' id='chkjouramount2[$i]' value='".$rowsdt[10]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(7,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtChkJourAmount2_D[$i]' id='chkjouramount2[$i]' value='".$rowsdt[10]."' maxlength='20' >";
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_C[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitChkJour('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-c', '".$PTransDtId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_C['.$i.']\')"';
		$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_C[".$i."]','1');LeaveGrid('chkjournumber[$i]','billjournumber[0]','','')\" ";		
					
		//Initializations
		
		if(($LedgerActivity==1 && $TransDtdbcd=='D') or ($LedgerActivity==2 && $TransDtdbcd=='C'))
			$txtChkJourType = 'A'; 
		else $txtChkJourType = 'C';
		 
		
		if (empty($txtChkJourCurrCode))	 $txtChkJourCurrCode  = $TransDtCurrCode;
		if (empty($txtChkJourValueDate)) $txtChkJourValueDate = $TransDtValueDate;
		if (empty($txtChkJourLedgerNo))  $txtChkJourLedgerNo  = $LedgerNumber;
			
		
		$sub_query2 = " Select TransDt.TransDt_ID, ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(Chk_Amount,0))), ".$DecimalBase.")  As ChkAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(Chk_Amount1,0))), ".$DecimalBase1.") As ChkAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(Chk_Amount2,0))), ".$DecimalBase2.") As ChkAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(Chk_Amount,0)),9) ) As ChkAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Chk_Amount1,0)),9) ) As ChkAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Chk_Amount2,0)),9) ) As ChkAmount2 ".
					  " From Temp_TransDt As TransDt Left Join Temp_ChkJourDt on TransDt.TransDt_ID = Temp_ChkJourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
					  
							  
		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		$txtChkJourBalAmt   = $sub_result2[7];
		$txtChkJourBalAmt1  = $sub_result2[8];
		$txtChkJourBalAmt2  = $sub_result2[9];
			
		$txtChkJourTotAmt   = $sub_result2[4];
		$txtChkJourTotAmt1  = $sub_result2[5];
		$txtChkJourTotAmt2  = $sub_result2[6];
			
		$txtChkJourAmount_D   = $sub_result2[1];
		$txtChkJourAmount1_D  = $sub_result2[2];
		$txtChkJourAmount2_D  = $sub_result2[3];
		
		$txtChkJourAmount   = $sub_result2[7];
		$txtChkJourAmount1  = $sub_result2[8];
		$txtChkJourAmount2  = $sub_result2[9];	
				
		echo"<tr id='CurRec_G5$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G3');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "	<td width='105px;' align='left'>
					<input type='hidden' name='txtChkJourId[$i]' id='chkjourid[$i]' value='$txtChkJourId' >
					<input type='hidden' name='txtChkJourType[$i]' id='chkjourtype[$i]' value='$txtChkJourType' >
					<input type='hidden' name='txtChkJourLedgerNo[$i]' id='chkjourledgerno[$i]' value='$txtChkJourLedgerNo' >
					<input type='hidden' name='txtChkJourAmount[$i]'  id='chkjouramount_h[$i]'  value='$txtChkJourAmount' >
					<input type='hidden' name='txtChkJourAmount1[$i]' id='chkjouramount1_h[$i]' value='$txtChkJourAmount1' >
					<input type='hidden' name='txtChkJourAmount2[$i]' id='chkjouramount2_h[$i]' value='$txtChkJourAmount2' >
					<input type='hidden' name='txtChkJourBalAmt[$i]' id='chkjourbalamt[$i]'  value='$txtChkJourBalAmt' >
					<input type='hidden' name='txtChkJourBalAmt1[$i]' id='chkjourbalamt1[$i]'  value='$txtChkJourBalAmt1' >
					<input type='hidden' name='txtChkJourBalAmt2[$i]' id='chkjourbalamt2[$i]'  value='$txtChkJourBalAmt2' >
					<input type='hidden' name='txtChkJourTotAmt[$i]' id='chkjourtotamt[$i]'  value='$txtChkJourTotAmt' >
					<input type='hidden' name='txtChkJourTotAmt1[$i]' id='chkjourtotamt1[$i]'  value='$txtChkJourTotAmt1' >
					<input type='hidden' name='txtChkJourTotAmt2[$i]' id='chkjourtotamt2[$i]'  value='$txtChkJourTotAmt2' >
					<input type='text' name='txtChkJourNumber[$i]' id='chkjournumber[$i]' value='$txtChkJourNumber'  maxlength='20' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;'  onBlur=\"LeaveGrid('chkjournumber[$i]','billjournumber[0]','tab1','".$TabIndex."')\"   onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown1." $status />";
					
					if ($showlist == 1) 
						echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistCheck(1,".$i.",'".$PTransDtId."','-1');\" style='vertical-align:bottom;' title='Select Check'  /></span></label>";
		echo"	</td>";
										
		echo"  	<td width='105px;' align='center'><input type='text' name='txtChkJourBank[$i]' id='chkjourbank[$i]' value='$txtChkJourBank' maxlength='30' class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown."  /></td>";
		if($Hide_ValueDate==0) echo"   <td width='70px;' align='center'><input type='text' name='txtChkJourValueDate[$i]' id='chkjourvaluedate[$i]' value='$chkjourvaluedate[$i]' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G5','$i');\" ".$KeyDown." $status /></td>";
		else 				 echo"  <input type='hidden' name='txtChkJourValueDate[$i]' id='chkjourvaluedate[$i]' value='00/00/0000' maxlength='10' >";
		echo"   <td width='45px;' align='center'><input type='text' name='txtChkJourCurrCode[$i]' id='chkjourcurrcode[$i]' value='$txtChkJourCurrCode' maxlength='10' class='".$ClassI."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount_D[$i]' id='chkjouramount[$i]' value='$txtChkJourAmount_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(5,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount1_D[$i]' id='chkjouramount1[$i]' value='$txtChkJourAmount1_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(6,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		if($Hide_Base2==0)  echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount2_D[$i]' id='chkjouramount2[$i]' value='$txtChkJourAmount2_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G5','$i'); SetAmount(7,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		else 				echo"	<input type='hidden' name='txtChkJourAmount2_D[$i]' id='chkjouramount2[$i]' value='0' maxlength='20'>";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_C[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitChkJour('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-1-c', '".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);'></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransDtGridChecks2($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess){
	
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels = mysql_fetch_array($result_labels);
	extract($row_labels);
	$Module_Project 			= $arrayparams['Module_Project'];
	$Module_CostCenter 			= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost 	= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 		= $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView 	= $arrayparams['Module_TransStandardView'];
	$Module_ShowBalance 		= $arrayparams['Module_ShowBalance'];
	$ModuleRestrictCashType 	= $arrayparams['ModuleRestrictCashType'];
	$Module_MultiCashType		= $arrayparams['Module_MultiCashType'];
	$Module_ProjectDt		 	= $arrayparams['Module_ProjectDt'];
    $Module_CostCenterDt 		= $arrayparams['Module_CostCenterDt'];
    $Module_Form_Trans          = $arrayparams['Module_Form_Trans'];
	
	
	$DecimalBase  				= $arrayparams['DecimalBase'];
	$DecimalBase1 				= $arrayparams['DecimalBase1'];
	$DecimalBase2 				= $arrayparams['DecimalBase2'];
	$DefaultCur 				= $arrayparams['DefaultCur'];
	$Base1 						= $arrayparams['Base1'];
	$Base2 						= $arrayparams['Base2'];
	
	$Hide_Base2 				= $arrayparams['Hide_Base2'];
	$Hide_ValueDate				= $arrayparams['Hide_ValueDate'];
	$txtDate 					= $arrayparams['txtDate'];
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	
	$columnsarray = array("chkjournumber2", "chkjourbank2");
	if($Hide_ValueDate == 0)  array_push($columnsarray, "chkjourvaluedate2");
	array_push($columnsarray,  "chkjouramount02", "chkjouramount21");
	if($Hide_Base2 == 0)  array_push($columnsarray, "chkjouramount22");
	
	$columnsarrayall = array("chkjournumber2", "chkjourbank2");
	
	if($Hide_ValueDate == 0)  array_push($columnsarrayall, "chkjourvaluedate2");
	array_push($columnsarrayall,  "chkjouramount02", "chkjouramount21");
	if($Hide_Base2 == 0)  array_push($columnsarrayall, "chkjouramount22");
	array_push($columnsarrayall,   "chkjouramount02_h", "chkjouramount21_h");
	if($Hide_Base2 == 0)  array_push($columnsarrayall, "chkjouramount22_h");
	array_push($columnsarrayall,   "chkjourledgerno2", "chkjourcurrcode2", "chkjourid2", "chkjourtype2", "chkjourbalamt02", "chkjourbalamt21");
	if($Hide_Base2 == 0)  array_push($columnsarrayall, "chkjourbalamt22");
	array_push($columnsarrayall,  "chkjourtotamt02", "chkjourtotamt21");
	if($Hide_Base2 == 0)  array_push($columnsarrayall, "chkjourtotamt22");
	
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	if(($LedgerActivity==1 && $TransDtdbcd=='D') or ($LedgerActivity==2 && $TransDtdbcd=='C')) {
		$showlist = 0;
		$status = '';	
	}	
	else {
		$showlist = 1;
		$status = 'readonly';	
	}	
		
		
		$Motion = 1;
		$NextCell = 'billjournumber2[0]';
		$down = 0;
		
	
		if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1)){
			$TabIndex = 2 ;		
			}
		else 	
		$TabIndex = 1 ;		
	/////////////
	
	

	//Initializations for Div Ids
	$ContainerDiv = 'container6';
	$LoaderDiv    = 'Loader6';
	$HeaderDiv    = 'grid_headerDiv6';
	$ContentDiv   = 'grid_contentDiv6';
	$TableFocus   = 'table-focus-g6';
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '638px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'><span>$CheckNo</span></th>";
		echo"  <th width='105px;' align='left'><span>$Bank</span></th>";
		if( $Hide_ValueDate == 0 ) echo"  <th width='70px;' align='center'><span>$ValueDate</span></th>";
		echo"  <th width='45px;' align='center'><span>$Curr</span></th>";
		echo"  <th width='95px;' align='center'><span>$Amount</span></th>";
		echo"  <th width='95px;' align='center'><span>$Base1</span></th>";
		if( $Hide_Base2 == 0 ) echo"  <th width='95px;' align='center'><span>$Base2</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '700px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
		echo"<input type='hidden' name='SelectedRec_G6' id='SelectedRec_G6' value='$SelectedRec_G6'>
			 <input type='hidden' name='SelectedRecColor_G6' id='SelectedRecColor_G6' value='$SelectedRecColor_G6'>
			 <input type='hidden' name='ModRec_G6' id='ModRec_G6' value='$ModRec_G6'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(Chk_Amount,0)),9) ) As ChkAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Chk_Amount1,0)),9) ) As ChkAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Chk_Amount2,0)),9) ) As ChkAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join Temp_ChkJourDt on TransDt.TransDt_ID = Temp_ChkJourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtChkJourBalAmt02_M  = $sub_result2[1];
			$txtChkJourBalAmt21_M  = $sub_result2[2];
			$txtChkJourBalAmt22_M  = $sub_result2[3];
			
			$txtChkJourTotAmt02  = $sub_result2[4];
			$txtChkJourTotAmt21  = $sub_result2[5];
			$txtChkJourTotAmt22  = $sub_result2[6];
			
		 
			$query = " SELECT ChkJourDt_Id, TransDt_ID, Ledger_Number, Chk_Number, Chk_Bank, date_format(Chk_ValueDate,'%d/%m/%Y'), Chk_Type, ChkJourDt.Currency_Code, ".
					 " Round(ifNull(Chk_Amount,0), ".$DecimalBase."), Round(ifNull(Chk_Amount1,0), ".$DecimalBase1."), Round(ifNull(Chk_Amount2,0), ".$DecimalBase2."), ".
					 " ifNull(Chk_Amount,0), ifNull(Chk_Amount1,0), ifNull(Chk_Amount2,0) ".
					 " FROM Temp_ChkJourDt As ChkJourDt ".
					 " WHERE ChkJourDt.TransDt_ID = '".$PTransDtId."'";
				
			//echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtChkJourBalAmt02  = $txtChkJourBalAmt02_M + $rowsdt[11];
				$txtChkJourBalAmt21  = $txtChkJourBalAmt21_M + $rowsdt[12];
				$txtChkJourBalAmt22  = $txtChkJourBalAmt22_M + $rowsdt[13];
					
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_C['.$i.']\')"';
				
				echo"<tr id='CurRec_G6$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteChkJour('".$filepath."','".$form."','DEL','datagrid-2-c','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtChkJourId2[$i]' id='chkjourid2[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtChkJourType2[$i]' id='chkjourtype2[$i]' value='".$rowsdt[6]."' >
							<input type='hidden' name='txtChkJourLedgerNo2[$i]' id='chkjourledgerno2[$i]' value='".$rowsdt[2]."' >
							<input type='hidden' name='txtChkJourAmount02[$i]'  id='chkjouramount02_h[$i]'  value='".$rowsdt[11]."' >
							<input type='hidden' name='txtChkJourAmount21[$i]' id='chkjouramount21_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtChkJourAmount22[$i]' id='chkjouramount22_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtChkJourBalAmt02[$i]' id='chkjourbalamt02[$i]'  value='$txtChkJourBalAmt02' >
							<input type='hidden' name='txtChkJourBalAmt21[$i]' id='chkjourbalamt21[$i]'  value='$txtChkJourBalAmt21' >
							<input type='hidden' name='txtChkJourBalAmt22[$i]' id='chkjourbalamt22[$i]'  value='$txtChkJourBalAmt22' >
							<input type='hidden' name='txtChkJourTotAmt02[$i]' id='chkjourtotamt02[$i]'  value='$txtChkJourTotAmt02' >
							<input type='hidden' name='txtChkJourTotAmt21[$i]' id='chkjourtotamt21[$i]'  value='$txtChkJourTotAmt21' >
							<input type='hidden' name='txtChkJourTotAmt22[$i]' id='chkjourtotamt22[$i]'  value='$txtChkJourTotAmt22' >
							<input type='text' name='txtChkJourNumber2[$i]' id='chkjournumber2[$i]' value='".$rowsdt[3]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onBlur=\"checkCHKNumber('".$i."');\"  onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown." $status />";
							
							if ($showlist == 1) 
								echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistCheck(2,".$i.",'".$PTransDtId."','".$rowsdt[0]."');\" style='vertical-align:bottom;' title='Select Check'  /></span></label>";
				echo"	</td>";
	
										
				echo"  	<td width='105px;' align='center'><input type='text' name='txtChkJourBank2[$i]' id='chkjourbank2[$i]' value='".$rowsdt[4]."' maxlength='30' class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown."  /></td>";
				if( $Hide_ValueDate == 0 ) echo"   <td width='70px;' align='center'><input type='text' name='txtChkJourValueDate2[$i]' id='chkjourvaluedate2[$i]' value='".$rowsdt[5]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown." $status ></td>";
				else 					echo"   <input type='hidden' name='txtChkJourValueDate2[$i]' id='chkjourvaluedate2[$i]' value='".$rowsdt[5]."' maxlength='10' >";
				echo"   <td width='45px;' align='center'><input type='text' name='txtChkJourCurrCode2[$i]' id='chkjourcurrcode2[$i]' value='".$rowsdt[7]."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount02_D[$i]' id='chkjouramount02[$i]' value='".$rowsdt[8]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(15,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount21_D[$i]' id='chkjouramount21[$i]' value='".$rowsdt[9]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(16,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				if( $Hide_Base2 == 0 ) echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount22_D[$i]' id='chkjouramount22[$i]' value='".$rowsdt[10]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(17,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				else 				echo"	<input type='hidden' name='txtChkJourAmount22_D[$i]' id='chkjouramount22[$i]' value='".$rowsdt[10]."' maxlength='20' >";
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_C[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitChkJour2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-c', '".$PTransDtId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_C['.$i.']\')"';
		$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_2_C[".$i."]','1');LeaveGrid('chkjournumber2[$i]','billjournumber2[0]','tab3','$TabIndex')\" ";		
					
		//Initializations
		
		if(($LedgerActivity==1 && $TransDtdbcd=='D') or ($LedgerActivity==2 && $TransDtdbcd=='C'))
			$txtChkJourType2 = 'A'; 
		else $txtChkJourType2 = 'C';
		 
		
		if (empty($txtChkJourCurrCode2))  $txtChkJourCurrCode2  = $TransDtCurrCode;
		if (empty($txtChkJourValueDate2)) $txtChkJourValueDate2 = $TransDtValueDate;
		if (empty($txtChkJourLedgerNo2))  $txtChkJourLedgerNo2  = $LedgerNumber;
			
		
		$sub_query2 = " Select TransDt.TransDt_ID, ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(Chk_Amount,0))), ".$DecimalBase.")  As ChkAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(Chk_Amount1,0))), ".$DecimalBase1.") As ChkAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(Chk_Amount2,0))), ".$DecimalBase2.") As ChkAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(Chk_Amount,0)),9) ) As ChkAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Chk_Amount1,0)),9) ) As ChkAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Chk_Amount2,0)),9) ) As ChkAmount2 ".
					  " From Temp_TransDt As TransDt Left Join Temp_ChkJourDt on TransDt.TransDt_ID = Temp_ChkJourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
					  
							  
		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		$txtChkJourBalAmt02  = $sub_result2[7];
		$txtChkJourBalAmt21  = $sub_result2[8];
		$txtChkJourBalAmt22  = $sub_result2[9];
			
		$txtChkJourTotAmt02  = $sub_result2[4];
		$txtChkJourTotAmt21  = $sub_result2[5];
		$txtChkJourTotAmt22  = $sub_result2[6];
			
		$txtChkJourAmount02_D  = $sub_result2[1];
		$txtChkJourAmount21_D  = $sub_result2[2];
		$txtChkJourAmount22_D  = $sub_result2[3];
		
		$txtChkJourAmount02  = $sub_result2[7];
		$txtChkJourAmount21  = $sub_result2[8];
		$txtChkJourAmount22  = $sub_result2[9];	
				
		echo"<tr id='CurRec_G6$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G6');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "	<td width='105px;' align='left'>
					<input type='hidden' name='txtChkJourId2[$i]' id='chkjourid2[$i]' value='$txtChkJourId2' >
					<input type='hidden' name='txtChkJourType2[$i]' id='chkjourtype2[$i]' value='$txtChkJourType2' >
					<input type='hidden' name='txtChkJourLedgerNo2[$i]' id='chkjourledgerno2[$i]' value='$txtChkJourLedgerNo2' >
					<input type='hidden' name='txtChkJourAmount02[$i]'  id='chkjouramount02_h[$i]'  value='$txtChkJourAmount02' >
					<input type='hidden' name='txtChkJourAmount21[$i]' id='chkjouramount21_h[$i]' value='$txtChkJourAmount21' >
					<input type='hidden' name='txtChkJourAmount22[$i]' id='chkjouramount22_h[$i]' value='$txtChkJourAmount22' >
					<input type='hidden' name='txtChkJourBalAmt02[$i]' id='chkjourbalamt02[$i]'  value='$txtChkJourBalAmt02' >
					<input type='hidden' name='txtChkJourBalAmt21[$i]' id='chkjourbalamt21[$i]'  value='$txtChkJourBalAmt21' >
					<input type='hidden' name='txtChkJourBalAmt22[$i]' id='chkjourbalamt22[$i]'  value='$txtChkJourBalAmt22' >
					<input type='hidden' name='txtChkJourTotAmt02[$i]' id='chkjourtotamt02[$i]'  value='$txtChkJourTotAmt02' >
					<input type='hidden' name='txtChkJourTotAmt21[$i]' id='chkjourtotamt21[$i]'  value='$txtChkJourTotAmt21' >
					<input type='hidden' name='txtChkJourTotAmt22[$i]' id='chkjourtotamt22[$i]'  value='$txtChkJourTotAmt22' >
					<input type='text' name='txtChkJourNumber2[$i]' id='chkjournumber2[$i]' value='$txtChkJourNumber2'  maxlength='20' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;'   onBlur=\"LeaveGrid('chkjournumber2[$i]','billjournumber2[0]','tab3','".$TabIndex."')\"   onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown1." $status />";
					
					if ($showlist == 1) 
						echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistCheck(2,".$i.",'".$PTransDtId."','-1');\" style='vertical-align:bottom;' title='Select Check'  /></span></label>";
		echo"	</td>";
										
		echo"  	<td width='105px;' align='center'><input type='text' name='txtChkJourBank2[$i]' id='chkjourbank2[$i]' value='$txtChkJourBank2' maxlength='30' class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown."  /></td>";
		if( $Hide_ValueDate == 0 ) echo"   <td width='70px;' align='center'><input type='text' name='txtChkJourValueDate2[$i]' id='chkjourvaluedate2[$i]' value='$chkjourvaluedate2[$i]' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G6','$i');\" ".$KeyDown." $status /></td>";
		else					echo" <input type='hidden' name='txtChkJourValueDate2[$i]' id='chkjourvaluedate2[$i]' value='00/00/0000' maxlength='10' >";
		echo"   <td width='45px;' align='center'><input type='text' name='txtChkJourCurrCode2[$i]' id='chkjourcurrcode2[$i]' value='$txtChkJourCurrCode2' maxlength='10' class='".$ClassI."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount02_D[$i]' id='chkjouramount02[$i]' value='$txtChkJourAmount02_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(15,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount21_D[$i]' id='chkjouramount21[$i]' value='$txtChkJourAmount21_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(16,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		if( $Hide_Base2 == 0 )  echo"	<td width='95px;' align='center'><input type='text' name='txtChkJourAmount22_D[$i]' id='chkjouramount22[$i]' value='$chkjouramount22[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G6','$i'); SetAmount(17,$DecimalBase1,$DecimalBase2,'".$txtChkJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		else 				echo" <input type='hidden' name='txtChkJourAmount22_D[$i]' id='chkjouramount22[$i]' value='0' maxlength='20' >";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button'  id='imgSubmit_2_C[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitChkJour2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-c', '".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);'></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransDtGridBills($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess){
	
	
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost = $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost = $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView = $arrayparams['Module_TransStandardView'];
	$Module_ShowBalance = $arrayparams['Module_ShowBalance'];
	$ModuleRestrictCashType = $arrayparams['ModuleRestrictCashType'];
	$Module_MultiCashType = $arrayparams['Module_MultiCashType'];
	$ModuleInvoiceGrid = $arrayparams['Module_InvoiceGridPV'];
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
    $Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
    $Module_Form_Trans = $arrayparams['Module_Form_Trans'];
		
	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$DefaultCur   = $arrayparams['DefaultCur'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$txtDate 			= $arrayparams['txtDate'];
	$Hide_ValueDate 	= $arrayparams['Hide_ValueDate'];
	$Hide_Base2 		= $arrayparams['Hide_Base2'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	if($ModuleInvoiceGrid==1) {
		/// grid Motion
		$Motion = 1;
		$NextCell = 'linkref[0]';
		$down = 0;
		
		
		if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1) ){
			$TabIndex = 3 ;		
			}
		else 	
		$TabIndex = 2 ;
		
	}
	else {
		$Motion = 1;
		$down = 0;
		$NextCell = 'linkref[0]';
		$TabIndex = 3 ;		
	}
	/////////////
	
	
	
	$columnsarray = array("billjournumber", "billjourbank"); 
	if($Hide_ValueDate == 0) array_push($columnsarray, "billjourvaluedate");
	array_push($columnsarray, "billjouramount", "billjouramount1");
	if($Hide_Base2 == 0)	array_push($columnsarray, "billjouramount2");
	
	$columnsarrayall = array("billjournumber", "billjourbank");  
	
	if($Hide_ValueDate == 0) array_push($columnsarray, "billjourvaluedate");
	array_push($columnsarray, "billjouramount", "billjouramount1");
	if($Hide_Base2 == 0)	array_push($columnsarray, "billjouramount2");
	array_push($columnsarray,"billjouramount_h", "billjouramount1_h");
	if($Hide_Base2 == 0)	array_push($columnsarray, "billjouramount2_h");
	array_push($columnsarray,"billjourledgerno", "billjourcurrcode", "billjourid", "billjourtype", "billjourbalamt", "billjourbalamt1");
	if($Hide_Base2 == 0)	array_push($columnsarray, "billjourbalamt2");
	array_push($columnsarray,"billjourtotamt", "billjourtotamt1");
	if($Hide_Base2 == 0)	array_push($columnsarray, "billjourtotamt2");
	
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C')) {
		$showlist = 0;
		$status = '';	
	}	
	else {
		$showlist = 1;
		$status = 'readonly';	
	}	
		

	//Initializations for Div Ids
	$ContainerDiv = 'container7';
	$LoaderDiv    = 'Loader7';
	$HeaderDiv    = 'grid_headerDiv7';
	$ContentDiv   = 'grid_contentDiv7';
	$TableFocus   = 'table-focus-g7';	
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '638px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'><span>Bill No</span></th>";
		echo"  <th width='105px;' align='left'><span>Bank</span></th>";
		if($Hide_ValueDate == 0) echo"  <th width='70px;' align='center'><span>Value Date</span></th>";
		echo"  <th width='45px;' align='center'><span>Curr.</span></th>";
		echo"  <th width='95px;' align='center'><span>Amount</span></th>";
		echo"  <th width='95px;' align='center'><span>$Base1</span></th>";
		if($Hide_Base2 == 0) echo"  <th width='95px;' align='center'><span>$Base2</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '700px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
		echo"<input type='hidden' name='SelectedRec_G7' id='SelectedRec_G7' value='$SelectedRec_G7'>
			 <input type='hidden' name='SelectedRecColor_G7' id='SelectedRecColor_G7' value='$SelectedRecColor_G7'>
			 <input type='hidden' name='ModRec_G7' id='ModRec_G7' value='$ModRec_G7'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(Bill_Amount,0)),9) ) As BillAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Bill_Amount1,0)),9) ) As BillAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Bill_Amount2,0)),9) ) As BillAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join Temp_BillJourDt on TransDt.TransDt_ID = Temp_BillJourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtBillJourBalAmt_M   = $sub_result2[1];
			$txtBillJourBalAmt1_M  = $sub_result2[2];
			$txtBillJourBalAmt2_M  = $sub_result2[3];
			
			$txtBillJourTotAmt   = $sub_result2[4];
			$txtBillJourTotAmt1  = $sub_result2[5];
			$txtBillJourTotAmt2  = $sub_result2[6];
			
		 
			$query = " SELECT BillJourDT_ID, TransDt_ID, Ledger_Number, Bill_Number, Bill_Bank, date_format(Bill_ValueDate,'%d/%m/%Y'), Bill_Type, BillJourDt.Currency_Code, ".
					 " Round(ifNull(Bill_Amount,0), ".$DecimalBase."), Round(ifNull(Bill_Amount1,0), ".$DecimalBase1."), Round(ifNull(Bill_Amount2,0), ".$DecimalBase2."), ".
					 " ifNull(Bill_Amount,0), ifNull(Bill_Amount1,0), ifNull(Bill_Amount2,0) ".
					 " FROM Temp_BillJourDt As BillJourDt ".
					 " WHERE BillJourDt.TransDt_ID = '".$PTransDtId."'";
				
			//echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtBillJourBalAmt   = $txtBillJourBalAmt_M  + $rowsdt[11];
				$txtBillJourBalAmt1  = $txtBillJourBalAmt1_M + $rowsdt[12];
				$txtBillJourBalAmt2  = $txtBillJourBalAmt2_M + $rowsdt[13];
					
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_B['.$i.']\')"';
				
				echo"<tr id='CurRec_G7$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteBillJour('".$filepath."','".$form."','DEL','datagrid-1-b','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtBillJourId[$i]' id='billjourid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtBillJourType[$i]' id='billjourtype[$i]' value='".$rowsdt[6]."' >
							<input type='hidden' name='txtBillJourLedgerNo[$i]' id='billjourledgerno[$i]' value='".$rowsdt[2]."' >
							<input type='hidden' name='txtBillJourAmount[$i]'  id='billjouramount_h[$i]'  value='".$rowsdt[11]."' >
							<input type='hidden' name='txtBillJourAmount1[$i]' id='billjouramount1_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtBillJourAmount2[$i]' id='billjouramount2_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtBillJourBalAmt[$i]' id='billjourbalamt[$i]'  value='$txtBillJourBalAmt' >
							<input type='hidden' name='txtBillJourBalAmt1[$i]' id='billjourbalamt1[$i]'  value='$txtBillJourBalAmt1' >
							<input type='hidden' name='txtBillJourBalAmt2[$i]' id='billjourbalamt2[$i]'  value='$txtBillJourBalAmt2' >
							<input type='hidden' name='txtBillJourTotAmt[$i]' id='billjourtotamt[$i]'  value='$txtBillJourTotAmt' >
							<input type='hidden' name='txtBillJourTotAmt1[$i]' id='billjourtotamt1[$i]'  value='$txtBillJourTotAmt1' >
							<input type='hidden' name='txtBillJourTotAmt2[$i]' id='billjourtotamt2[$i]'  value='$txtBillJourTotAmt2' >
							<input type='text' name='txtBillJourNumber[$i]' id='billjournumber[$i]' value='".$rowsdt[3]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown." $status />";
							
							if ($showlist == 1) 
								echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistBill(1,".$i.",'".$PTransDtId."','".$rowsdt[0]."');\" style='vertical-align:bottom;' title='Select Bill'  /></span></label>";
				echo"	</td>";
	
										
				echo"  	<td width='105px;' align='center'><input type='text' name='txtBillJourBank[$i]' id='billjourbank[$i]' value='".$rowsdt[4]."' maxlength='30' class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown."  /></td>";
				if($Hide_ValueDate == 0) echo"   <td width='70px;' align='center'><input type='text' name='txtBillJourValueDate[$i]' id='billjourvaluedate[$i]' value='".$rowsdt[5]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:80px; height:20px;' onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown." $status ></td>";
				else 				echo"   <input type='hidden' name='txtBillJourValueDate[$i]' id='billjourvaluedate[$i]' value='".$rowsdt[5]."' maxlength='10' >";
				echo"   <td width='45px;' align='center'><input type='text' name='txtBillJourCurrCode[$i]' id='billjourcurrcode[$i]' value='".$rowsdt[7]."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:45px; height:20px;' readonly ></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount_D[$i]' id='billjouramount[$i]' value='".$rowsdt[8]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(8,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount1_D[$i]' id='billjouramount1[$i]' value='".$rowsdt[9]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(9,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				if($Hide_Base2 == 0) echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount2_D[$i]' id='billjouramount2[$i]' value='".$rowsdt[10]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(10,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				else 			echo"	<input type='hidden' name='txtBillJourAmount2_D[$i]' id='billjouramount2[$i]' value='".$rowsdt[10]."' maxlength='20' >";
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_B[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitBillJour('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-1-b', '".$PTransId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_B['.$i.']\')"';
		$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_B[".$i."]','1');LeaveGrid('billjournumber[$i]','linkref[0]','tab1','".$TabIndex."')\" ";		
					
		//Initializations
		
		if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C'))
			$txtBillJourType = 'A'; 
		else $txtBillJourType = 'C';
		 
		 
		if (empty($txtBillJourCurrCode))  $txtBillJourCurrCode  = $TransDtCurrCode;
		if (empty($txtBillJourValueDate)) $txtBillJourValueDate = $TransDtValueDate;
		if (empty($txtBillJourLedgerNo))  $txtBillJourLedgerNo  = $LedgerNumber;
		
		$sub_query2 = " Select TransDt.TransDt_ID, ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(Bill_Amount,0))), ".$DecimalBase.")  As BillAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(Bill_Amount1,0))), ".$DecimalBase1.") As BillAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(Bill_Amount2,0))), ".$DecimalBase2.") As BillAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(Bill_Amount,0)),9) ) As BillAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Bill_Amount1,0)),9) ) As BillAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Bill_Amount2,0)),9) ) As BillAmount2 ".
					  " From Temp_TransDt As TransDt Left Join Temp_BillJourDt on TransDt.TransDt_ID = Temp_BillJourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
					  
							  
		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		$txtBillJourBalAmt   = $sub_result2[7];
		$txtBillJourBalAmt1  = $sub_result2[8];
		$txtBillJourBalAmt2  = $sub_result2[9];
			
		$txtBillJourTotAmt   = $sub_result2[4];
		$txtBillJourTotAmt1  = $sub_result2[5];
		$txtBillJourTotAmt2  = $sub_result2[6];
			
		$txtBillJourAmount_D   = $sub_result2[1];
		$txtBillJourAmount1_D  = $sub_result2[2];
		$txtBillJourAmount2_D  = $sub_result2[3];
			
		$txtBillJourAmount   = $sub_result2[7];
		$txtBillJourAmount1  = $sub_result2[8];
		$txtBillJourAmount2  = $sub_result2[9];	
				
		echo"<tr id='CurRec_G7$i' class='$bgcolor $TableFocus' >";
		echo"<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G7');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "	<td width='105px;' align='left'>
					<input type='hidden' name='txtBillJourId[$i]' id='billjourid[$i]' value='$txtBillJourId' >
					<input type='hidden' name='txtBillJourType[$i]' id='billjourtype[$i]' value='$txtBillJourType' >
					<input type='hidden' name='txtBillJourLedgerNo[$i]' id='billjourledgerno[$i]' value='$txtBillJourLedgerNo' >
					<input type='hidden' name='txtBillJourAmount[$i]'  id='billjouramount_h[$i]'  value='$txtBillJourAmount' >
					<input type='hidden' name='txtBillJourAmount1[$i]' id='billjouramount1_h[$i]' value='$txtBillJourAmount1' >
					<input type='hidden' name='txtBillJourAmount2[$i]' id='billjouramount2_h[$i]' value='$txtBillJourAmount2' >
					<input type='hidden' name='txtBillJourBalAmt[$i]' id='billjourbalamt[$i]'  value='$txtBillJourBalAmt' >
					<input type='hidden' name='txtBillJourBalAmt1[$i]' id='billjourbalamt1[$i]'  value='$txtBillJourBalAmt1' >
					<input type='hidden' name='txtBillJourBalAmt2[$i]' id='billjourbalamt2[$i]'  value='$txtBillJourBalAmt2' >
					<input type='hidden' name='txtBillJourTotAmt[$i]' id='billjourtotamt[$i]'  value='$txtBillJourTotAmt' >
					<input type='hidden' name='txtBillJourTotAmt1[$i]' id='billjourtotamt1[$i]'  value='$txtBillJourTotAmt1' >
					<input type='hidden' name='txtBillJourTotAmt2[$i]' id='billjourtotamt2[$i]'  value='$txtBillJourTotAmt2' >
					<input type='text' name='txtBillJourNumber[$i]' id='billjournumber[$i]' value='$txtBillJourNumber'  maxlength='20' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;'   onBlur=\"LeaveGrid('billjournumber[$i]','linkref[0]','tab1','".$TabIndex."')\"   onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown." $status />";
					
					if ($showlist == 1) 
						echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistBill(1,".$i.",'".$PTransDtId."','-1');\" style='vertical-align:bottom;' title='Select Bill'  /></span></label>";
		echo"	</td>";
										
		echo"  	<td width='105px;' align='center'><input type='text' name='txtBillJourBank[$i]' id='billjourbank[$i]' value='$txtBillJourBank' maxlength='30' class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown."  /></td>";
		if($Hide_ValueDate == 0) echo"   <td width='70px;' align='center'><input type='text' name='txtBillJourValueDate[$i]' id='billjourvaluedate[$i]' value='$billjourvaluedate[$i]' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G7','$i');\" ".$KeyDown." $status /></td>";
		else 				echo"   <input type='hidden' name='txtBillJourValueDate[$i]' id='billjourvaluedate[$i]' value='00/00/0000' maxlength='10' >";
		echo"   <td width='45px;' align='center'><input type='text' name='txtBillJourCurrCode[$i]' id='billjourcurrcode[$i]' value='$txtBillJourCurrCode' maxlength='10' class='".$ClassI."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount_D[$i]' id='billjouramount[$i]' value='$txtBillJourAmount_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(8,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount1_D[$i]' id='billjouramount1[$i]' value='$txtBillJourAmount1_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(9,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		if($Hide_Base2 == 0)  echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount2_D[$i]' id='billjouramount2[$i]' value='$billjouramount2[$i]' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G7','$i'); SetAmount(10,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		else 		 echo"	<input type='hidden' name='txtBillJourAmount2_D[$i]' id='billjouramount2[$i]' value='0' maxlength='20' >";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_B[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitBillJour('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-1-b', '".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransDtGridBills2($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess){
	
	$Module_Project 			= $arrayparams['Module_Project'];
	$Module_CostCenter 			= $arrayparams['Module_CostCenter'];
	$Module_RestrictProjCost 	= $arrayparams['Module_RestrictProjCost'];
	$Module_RestrictCost 		= $arrayparams['Module_RestrictCost'];
	$Module_TransStandardView 	= $arrayparams['Module_TransStandardView'];
	$Module_ShowBalance 		= $arrayparams['Module_ShowBalance'];
	$ModuleRestrictCashType	 	= $arrayparams['ModuleRestrictCashType'];
	$Module_MultiCashType 		= $arrayparams['Module_MultiCashType'];
	$ModuleInvoiceGrid 			= $arrayparams['Module_InvoiceGridPV'];
	$Module_ProjectDt 			= $arrayparams['Module_ProjectDt'];
    $Module_CostCenterDt 		= $arrayparams['Module_CostCenterDt'];
    $Module_Form_Trans          = $arrayparams['Module_Form_Trans'];
		
	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$DefaultCur   = $arrayparams['DefaultCur'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$txtDate 		= $arrayparams['txtDate'];
	$Hide_Base2		= $arrayparams['Hide_Base2'];
	$Hide_ValueDate	= $arrayparams['Hide_ValueDate'];
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	if($ModuleInvoiceGrid==1) {
		/// grid Motion
		$Motion = 1;
		$NextCell = 'linkref2[0]';
		$down = 0;
		
		
		if ($Module_TransStandardView==1 && ($Module_Project == 1 || $Module_CostCenter == 1 || $Module_ProjectDt == 1 || $Module_CostCenterDt == 1) ){
			$TabIndex = 3 ;		
			}
		else 	
		$TabIndex = 2 ;
		
	}
	else {
		$Motion = 1;
		$down = 0;
		$NextCell = 'linkref2[0]';
		$TabIndex = 3 ;		
	}
	/////////////
	
	$columnsarray = array("billjournumber2", "billjourbank2"); 
	if($Hide_ValueDate == 0) array_push($columnsarray, "billjourvaluedate2");
	array_push($columnsarray, "billjouramount02", "billjouramount21");
	if($Hide_Base2 == 0) array_push($columnsarray, "billjouramount22");
	
	$columnsarrayall = array("billjournumber2", "billjourbank2");

	if($Hide_ValueDate == 0) array_push($columnsarrayall, "billjourvaluedate2");
	array_push($columnsarrayall, "billjouramount02", "billjouramount21");
	if($Hide_Base2 == 0) array_push($columnsarrayall, "billjouramount22");	
	array_push($columnsarrayall, "billjouramount02_h", "billjouramount21_h");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "billjouramount22_h");
	array_push($columnsarrayall, "billjourledgerno2", "billjourcurrcode2", "billjourid2", "billjourtype2", "billjourbalamt02", "billjourbalamt21");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "billjourbalamt22");
	array_push($columnsarrayall, "billjourtotamt02", "billjourtotamt21");	
	if($Hide_Base2 == 0) array_push($columnsarrayall, "billjourtotamt22");
	
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C')) {
		$showlist = 0;
		$status = '';	
	}	
	else {
		$showlist = 1;
		$status = 'readonly';	
	}	
		

	//Initializations for Div Ids
	$ContainerDiv = 'container8';
	$LoaderDiv    = 'Loader8';
	$HeaderDiv    = 'grid_headerDiv8';
	$ContentDiv   = 'grid_contentDiv8';
	$TableFocus   = 'table-focus-g8';	
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '638px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'><span>Bill No</span></th>";
		echo"  <th width='105px;' align='left'><span>Bank</span></th>";
		if($Hide_ValueDate == 0) echo"  <th width='70px;' align='center'><span>Value Date</span></th>";
		echo"  <th width='45px;' align='center'><span>Curr.</span></th>";
		echo"  <th width='95px;' align='center'><span>Amount</span></th>";
		echo"  <th width='95px;' align='center'><span>$Base1</span></th>";
		if($Hide_Base2 == 0) echo"  <th width='95px;' align='center'><span>$Base2</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '700px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:635px;'>";
		echo"<input type='hidden' name='SelectedRec_G87' id='SelectedRec_G8' value='$SelectedRec_G8'>
			 <input type='hidden' name='SelectedRecColor_G8' id='SelectedRecColor_G8' value='$SelectedRecColor_G8'>
			 <input type='hidden' name='ModRec_G8' id='ModRec_G8' value='$ModRec_G8'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {

			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(TransDt_Amount,0)  - Round(Sum(ifNull(Bill_Amount,0)),9) ) As BillAmount, ".
						  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Bill_Amount1,0)),9) ) As BillAmount1, ".
						  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Bill_Amount2,0)),9) ) As BillAmount2, ".
						  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join Temp_BillJourDt on TransDt.TransDt_ID = Temp_BillJourDt.TransDt_ID ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
						  
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtBillJourBalAmt02_M  = $sub_result2[1];
			$txtBillJourBalAmt21_M  = $sub_result2[2];
			$txtBillJourBalAmt22_M  = $sub_result2[3];
			
			$txtBillJourTotAmt02  = $sub_result2[4];
			$txtBillJourTotAmt21  = $sub_result2[5];
			$txtBillJourTotAmt22  = $sub_result2[6];
			
		 
			$query = " SELECT BillJourDT_ID, TransDt_ID, Ledger_Number, Bill_Number, Bill_Bank, date_format(Bill_ValueDate,'%d/%m/%Y'), Bill_Type, BillJourDt.Currency_Code, ".
					 " Round(ifNull(Bill_Amount,0), ".$DecimalBase."), Round(ifNull(Bill_Amount1,0), ".$DecimalBase1."), Round(ifNull(Bill_Amount2,0), ".$DecimalBase2."), ".
					 " ifNull(Bill_Amount,0), ifNull(Bill_Amount1,0), ifNull(Bill_Amount2,0) ".
					 " FROM Temp_BillJourDt As BillJourDt ".
					 " WHERE BillJourDt.TransDt_ID = '".$PTransDtId."'";
				
			//echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtBillJourBalAmt02  = $txtBillJourBalAmt02_M + $rowsdt[11];
				$txtBillJourBalAmt21  = $txtBillJourBalAmt21_M + $rowsdt[12];
				$txtBillJourBalAmt22  = $txtBillJourBalAmt22_M + $rowsdt[13];
					
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_B['.$i.']\')"';
				
				echo"<tr id='CurRec_G8$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteBillJour('".$filepath."','".$form."','DEL','datagrid-2-b','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtBillJourId2[$i]' id='billjourid2[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtBillJourType2[$i]' id='billjourtype2[$i]' value='".$rowsdt[6]."' >
							<input type='hidden' name='txtBillJourLedgerNo2[$i]' id='billjourledgerno2[$i]' value='".$rowsdt[2]."' >
							<input type='hidden' name='txtBillJourAmount02[$i]'  id='billjouramount02_h[$i]'  value='".$rowsdt[11]."' >
							<input type='hidden' name='txtBillJourAmount21[$i]' id='billjouramount21_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtBillJourAmount22[$i]' id='billjouramount22_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtBillJourBalAmt02[$i]' id='billjourbalamt02[$i]'  value='$txtBillJourBalAmt02' >
							<input type='hidden' name='txtBillJourBalAmt21[$i]' id='billjourbalamt21[$i]'  value='$txtBillJourBalAmt21' >
							<input type='hidden' name='txtBillJourBalAmt22[$i]' id='billjourbalamt22[$i]'  value='$txtBillJourBalAmt22' >
							<input type='hidden' name='txtBillJourTotAmt02[$i]' id='billjourtotamt02[$i]'  value='$txtBillJourTotAmt02' >
							<input type='hidden' name='txtBillJourTotAmt21[$i]' id='billjourtotamt21[$i]'  value='$txtBillJourTotAmt21' >
							<input type='hidden' name='txtBillJourTotAmt22[$i]' id='billjourtotamt22[$i]'  value='$txtBillJourTotAmt22' >
							<input type='text' name='txtBillJourNumber2[$i]' id='billjournumber2[$i]' value='".$rowsdt[3]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown." $status />";
							
							if ($showlist == 1) 
								echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistBill(2,".$i.",'".$PTransDtId."','".$rowsdt[0]."');\" style='vertical-align:bottom;' title='Select Bill'  /></span></label>";
				echo"	</td>";
	
										
				echo"  	<td width='105px;' align='center'><input type='text' name='txtBillJourBank2[$i]' id='billjourbank2[$i]' value='".$rowsdt[4]."' maxlength='30' class='".$ClassE."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown."  /></td>";
				if($Hide_ValueDate == 0) echo"   <td width='70px;' align='center'><input type='text' name='txtBillJourValueDate2[$i]' id='billjourvaluedate2[$i]' value='".$rowsdt[5]."' maxlength='10' class='".$ClassE." date' style='font-size:12px; width:80px; height:20px;' onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown." $status ></td>";
				else 					echo"  <input type='hidden' name='txtBillJourValueDate2[$i]' id='billjourvaluedate2[$i]' value='".$rowsdt[5]."' maxlength='10' >";
				echo"   <td width='45px;' align='center'><input type='text' name='txtBillJourCurrCode2[$i]' id='billjourcurrcode2[$i]' value='".$rowsdt[7]."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:45px; height:20px;' readonly ></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount02_D[$i]' id='billjouramount02[$i]' value='".$rowsdt[8]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(18,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount21_D[$i]' id='billjouramount21[$i]' value='".$rowsdt[9]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(19,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				if($Hide_Base2 == 0) echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount22_D[$i]' id='billjouramount22[$i]' value='".$rowsdt[10]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(20,$DecimalBase1,$DecimalBase2,'".$rowsdt[7]."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
				 else 				echo"	<input type='hidden' name='txtBillJourAmount22_D[$i]' id='billjouramount22[$i]' value='".$rowsdt[10]."' maxlength='20' >";
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_B[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitBillJour2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-b', '".$PTransId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_B['.$i.']\')"';
		$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_2_B[".$i."]','1');LeaveGrid('billjournumber2[$i]','linkref2[0]','tab3','".$TabIndex."')\" ";			
		//Initializations
		
		if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C'))
			$txtBillJourType2 = 'A'; 
		else $txtBillJourType2 = 'C';
		 
		 
		if (empty($txtBillJourCurrCode2))  $txtBillJourCurrCode2  = $TransDtCurrCode;
		if (empty($txtBillJourValueDate2)) $txtBillJourValueDate2 = $TransDtValueDate;
		if (empty($txtBillJourLedgerNo2))  $txtBillJourLedgerNo2  = $LedgerNumber;
		
		$sub_query2 = " Select TransDt.TransDt_ID, ".
					  " Round((ifNull(TransDt_Amount,0)  - Sum(ifNull(Bill_Amount,0))), ".$DecimalBase.")  As BillAmount_D, ".
					  " Round((ifNull(TransDt_Amount1,0) - Sum(ifNull(Bill_Amount1,0))), ".$DecimalBase1.") As BillAmount1_D, ".
					  " Round((ifNull(TransDt_Amount2,0) - Sum(ifNull(Bill_Amount2,0))), ".$DecimalBase2.") As BillAmount2_D, ".
					  " ifNull(TransDt_Amount,0), ifNull(TransDt_Amount1,0), ifNull(TransDt_Amount2,0), ".
					  " (ifNull(TransDt_Amount,0) -  Round(Sum(ifNull(Bill_Amount,0)),9) ) As BillAmount, ".
					  " (ifNull(TransDt_Amount1,0) - Round(Sum(ifNull(Bill_Amount1,0)),9) ) As BillAmount1, ".
					  " (ifNull(TransDt_Amount2,0) - Round(Sum(ifNull(Bill_Amount2,0)),9) ) As BillAmount2 ".
					  " From Temp_TransDt As TransDt Left Join Temp_BillJourDt on TransDt.TransDt_ID = Temp_BillJourDt.TransDt_ID ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID, TransDt_Amount, TransDt_Amount1, TransDt_Amount2 ";
					  
							  
		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		$txtBillJourBalAmt02  = $sub_result2[7];
		$txtBillJourBalAmt21  = $sub_result2[8];
		$txtBillJourBalAmt22  = $sub_result2[9];
			
		$txtBillJourTotAmt02  = $sub_result2[4];
		$txtBillJourTotAmt21  = $sub_result2[5];
		$txtBillJourTotAmt22  = $sub_result2[6];
			
		$txtBillJourAmount02_D  = $sub_result2[1];
		$txtBillJourAmount21_D  = $sub_result2[2];
		$txtBillJourAmount22_D  = $sub_result2[3];
			
		$txtBillJourAmount02  = $sub_result2[7];
		$txtBillJourAmount21  = $sub_result2[8];
		$txtBillJourAmount22  = $sub_result2[9];	
				
		echo"<tr id='CurRec_G8$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G8');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "	<td width='105px;' align='left'>
					<input type='hidden' name='txtBillJourId2[$i]' id='billjourid2[$i]' value='$txtBillJourId2' >
					<input type='hidden' name='txtBillJourType2[$i]' id='billjourtype2[$i]' value='$txtBillJourType2' >
					<input type='hidden' name='txtBillJourLedgerNo2[$i]' id='billjourledgerno2[$i]' value='$txtBillJourLedgerNo2' >
					<input type='hidden' name='txtBillJourAmount02[$i]'  id='billjouramount02_h[$i]'  value='$txtBillJourAmount02' >
					<input type='hidden' name='txtBillJourAmount21[$i]' id='billjouramount21_h[$i]' value='$txtBillJourAmount21' >
					<input type='hidden' name='txtBillJourAmount22[$i]' id='billjouramount22_h[$i]' value='$txtBillJourAmount22' >
					<input type='hidden' name='txtBillJourBalAmt02[$i]' id='billjourbalamt02[$i]'  value='$txtBillJourBalAmt02' >
					<input type='hidden' name='txtBillJourBalAmt21[$i]' id='billjourbalamt21[$i]'  value='$txtBillJourBalAmt21' >
					<input type='hidden' name='txtBillJourBalAmt22[$i]' id='billjourbalamt22[$i]'  value='$txtBillJourBalAmt22' >
					<input type='hidden' name='txtBillJourTotAmt02[$i]' id='billjourtotamt02[$i]'  value='$txtBillJourTotAmt02' >
					<input type='hidden' name='txtBillJourTotAmt21[$i]' id='billjourtotamt12[$i]'  value='$txtBillJourTotAmt21' >
					<input type='hidden' name='txtBillJourTotAmt22[$i]' id='billjourtotamt22[$i]'  value='$txtBillJourTotAmt22' >
					<input type='text' name='txtBillJourNumber2[$i]' id='billjournumber2[$i]' value='$txtBillJourNumber2'  maxlength='20' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onBlur=\"LeaveGrid('billjournumber2[$i]','linkref2[0]','tab3','".$TabIndex."')\"  onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown1." $status />";
					
					if ($showlist == 1) 
						echo"<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistBill(2,".$i.",'".$PTransDtId."','-1');\" style='vertical-align:bottom;' title='Select Bill'  /></span></label>";
		echo"	</td>";
										
		echo"  	<td width='105px;' align='center'><input type='text' name='txtBillJourBank2[$i]' id='billjourbank2[$i]' value='$txtBillJourBank2' maxlength='30' class='".$ClassI."' style='font-size:12px; width:100px; height:20px;' onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown."  /></td>";
		if($Hide_ValueDate == 0) echo"   <td width='70px;' align='center'><input type='text' name='txtBillJourValueDate2[$i]' id='billjourvaluedate2[$i]' value='$txtBillJourValueDate2' maxlength='10' class='".$ClassI." date' style='font-size:12px; width:65px; height:20px;' onChange=\"SetModRecord('ModRec_G8','$i');\" ".$KeyDown." $status /></td>";
		else 					echo"  <input type='hidden' name='txtBillJourValueDate2[$i]' id='billjourvaluedate2[$i]' value='00/00/0000' maxlength='10' >";
		echo"   <td width='45px;' align='center'><input type='text' name='txtBillJourCurrCode2[$i]' id='billjourcurrcode2[$i]' value='$txtBillJourCurrCode2' maxlength='10' class='".$ClassI."' style='font-size:12px; width:40px; height:20px;' readonly ></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount02_D[$i]' id='billjouramount02[$i]' value='$txtBillJourAmount02_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(18,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount21_D[$i]' id='billjouramount21[$i]' value='$txtBillJourAmount21_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(19,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		if($Hide_Base2 == 0) echo"	<td width='95px;' align='center'><input type='text' name='txtBillJourAmount22_D[$i]' id='billjouramount22[$i]' value='$txtBillJourAmount22_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onChange=\"SetModRecord('ModRec_G8','$i'); SetAmount(20,$DecimalBase1,$DecimalBase2,'".$txtBillJourCurrCode2."','".$Base1."','".$Base2."','".$txtDate."',$i);\" ".$KeyDown." /></td>";
		else 				echo"	<input type='hidden' name='txtBillJourAmount22_D[$i]' id='billjouramount22[$i]' value='0' maxlength='20' >";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button'  id='imgSubmit_2_B[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitBillJour2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-b', '".$PTransId."', '".$PTransDtId."','$NextCell','$Motion','$TabIndex','$down'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransDtGridInvoices($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess){
	
	$DecimalBase  			= $arrayparams['DecimalBase'];
	$DecimalBase1 			= $arrayparams['DecimalBase1'];
	$DecimalBase2 			= $arrayparams['DecimalBase2'];
	$DefaultCur   			= $arrayparams['DefaultCur'];
	$Base1 		  			= $arrayparams['Base1'];
	$Base2 		  			= $arrayparams['Base2'];
    $module_invoicegridAll 	= $arrayparams['module_invoicegridAll'];
    $Module_Form_Trans      = $arrayparams['Module_Form_Trans'];
	$Hide_Base2 			= $arrayparams['Hide_Base2'];

	$txtDate   = $arrayparams['txtDate'];
	$TransType = $arrayparams['TransType'];
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	
	$columnsarray = array("linkref", "acclinkpaidamt");
	$columnsarrayall = array("linkref", "linkid", "acclinknettopay", "acclinkpaidamt", "acclinkremainamt", "acclinkcurrcode", "acclinkid", "linktype", "acclinknettotamt_h", "acclinknettotamt1_h");
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinknettotamt2_h");
	array_push($columnsarrayall,"acclinknettopay_h", "acclinknettopay1_h");
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinknettopay2_h");
	array_push($columnsarrayall,"acclinkpaidamt_h", "acclinkpaidamt1_h");
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinkpaidamt2_h");
	array_push($columnsarrayall,"acclinkremainamt_h", "acclinkremainamt1_h");
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinkremainamt2_h");	
	array_push($columnsarrayall,"acclinkbalamt", "acclinkbalamt1");	
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinkbalamt2");	
	array_push($columnsarrayall, "acclinktotamt", "acclinktotamt1");
	if($Hide_Base2 == 0) array_push($columnsarrayall,"acclinktotamt2");
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	$vMainCompanyName=explode('_',$_SESSION['dbName']);  
	$DirCompany  = $vMainCompanyName[0];
	$DirYear	 = $vMainCompanyName[1]; 
	if($module_invoicegridAll == 2) {
		preg_match_all('!\d+!', $vMainCompanyName[1] ,$DirYears );
		$DirYear =  $DirYears[0][0];  
	}
	//Initializations for Div Ids
	$ContainerDiv = 'container9';
	$LoaderDiv    = 'Loader9';
	$HeaderDiv    = 'grid_headerDiv9';
	$ContentDiv   = 'grid_contentDiv9';
	$TableFocus   = 'table-focus-g9';	
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '638px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:475px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'><span>Inv Ref.</span></th>";
		echo"  <th width='50px;' align='center'><span>Curr.</span></th>";
		if($module_invoicegridAll != 2) echo"  <th width='95px;' align='center'><span>Net To Pay</span></th>";
		if($module_invoicegridAll == 2) echo"  <th width='95px;' align='center'><span>Invoice Amt</span></th>";
		echo"  <th width='95px;' align='center'><span>Paid Amt</span></th>";
		if($module_invoicegridAll != 2) echo"  <th width='95px;' align='center'><span>Remain Amt</span></th>";
		if($module_invoicegridAll == 2) echo"  <th width='95px;' align='center'><span>Date</span></th>";
		// echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		// echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '700px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:475px;'>";
		echo"<input type='hidden' name='SelectedRec_G9' id='SelectedRec_G9' value='$SelectedRec_G9'>
			 <input type='hidden' name='SelectedRecColor_G9' id='SelectedRecColor_G9' value='$SelectedRecColor_G9'>
			 <input type='hidden' name='ModRec_G9' id='ModRec_G9' value='$ModRec_G9'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {
			if($module_invoicegridAll == 2)
			$sub_query2 = " SELECT
							TransDt.TransDt_ID,
							sum( ifNull( temp_detaillink.amount, 0 ) ) AS PaidAmnt,
							sum(
								ifNull( amountbase1, 0 )) AS PaidAmnt1,
								sum(
									ifNull( amountbase2, 0 )) AS PaidAmnt2,
									ifNull( Transdt_Amount, 0 ),
									ifNull( Transdt_Amount1, 0 ),
									ifNull( Transdt_Amount2, 0 ) 
								FROM
									Temp_TransDt AS TransDt Left Join ".$_SESSION['dbLabel'].".temp_Alloclink AS temp_detaillink ON TransDt.TransDt_ID = temp_detaillink.TransDt_ID  ".
 						  " And upper(temp_detaillink.Alloccomp) = upper('".$DirCompany."') ".
						  " And upper(temp_detaillink.AllocYEAR) = upper('".$DirYear."') ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
			else
			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(Transdt_Amount,0) - Round(Sum(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0)),9) ) As PaidAmnt, ".
						  " (ifNull(Transdt_Amount1,0) - Round(Sum(ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0)),9) ) As PaidAmnt1, ".
						  " (ifNull(Transdt_Amount2,0) - Round(Sum(ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0)),9) ) As PaidAmnt2, ".
						  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join ".$_SESSION['dbLabel'].".Temp_AccLink on TransDt.TransDt_ID = Temp_AccLink.Journal_ID ".
						  " And Temp_AccLink.Journal_Type = '".$TransType."' ".
						  " And upper(Temp_AccLink.CompanyName) = upper('".$DirCompany."') ".
						  " And upper(Temp_AccLink.DirYear) = upper('".$DirYear."') ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtAccLinkBalAmt_M   = $sub_result2[1];
			$txtAccLinkBalAmt1_M  = $sub_result2[2];
			$txtAccLinkBalAmt2_M  = $sub_result2[3];
			
			$txtAccLinkTotAmt   = $sub_result2[4];
			$txtAccLinkTotAmt1  = $sub_result2[5];
			$txtAccLinkTotAmt2  = $sub_result2[6];
			
			if($module_invoicegridAll == 2){
				$queryJournalId = "select journal_id from temp_trans where trans_id = $PTransId";
				$resJournal_id   = selectData($connection, $queryJournalId);
				$CurrJVID = $resJournal_id[0];
				
				if($TransType == 'PV' || $TransType == 'DV'){ 
				$query = "SELECT
						temp_alloclink.AllocLink_id,
						journal.Journal_refgovernment,
						Journal_type,
						temp_alloclink.currency_code ,
						Transdt_Amount,
						temp_alloclink.amount,
						Transdt_Amount - temp_alloclink.amount,
						date_format(temp_alloclink.alloclink_date, '%d/%m/%Y')
						FROM
							".$_SESSION['dbLabel'].".temp_alloclink 
							left join temp_transdt on temp_alloclink.transdt_id = temp_transdt.transdt_id
							left join journal on temp_alloclink.journal_idC = journal.journal_id
						WHERE
							(  temp_alloclink.transdt_id = '".$PTransDtId."'  or temp_alloclink.journal_idD = '".$CurrJVID."')
							AND upper( temp_alloclink.Alloccomp ) = upper('".$DirCompany."') 
							AND upper( temp_alloclink.Allocyear ) = upper('".$DirYear."') "; 
				}else{
					$query = "SELECT
							X.AllocLink_id,
							journal.Journal_refgovernment,
							journal.Journal_type,
							X.currency_code ,
							Transdt_Amount,
							X.amount,
							Transdt_Amount - X.amount,
							date_format(X.alloclink_date, '%d/%m/%Y')
							FROM
							".$_SESSION['dbLabel'].".temp_alloclink X
								LEFT JOIN temp_transdt ON X.transdt_id = temp_transdt.transdt_id
								LEFT JOIN journal ON X.journal_idD = journal.journal_id
								LEFT JOIN Deliveries ON X.journal_idD = Deliveries.journal_id
							WHERE 
							X.transdt_id = '".$PTransDtId."' 
								AND upper( X.Alloccomp ) = upper('".$DirCompany."') 
								AND upper( X.Allocyear ) = upper('".$DirYear."') ";
				}
			}
		
			else
			$query = " Select Acc_Id, Link_Ref, Link_Type, Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."), Round(ifNull(Sale_NetToPay,0), ".$DecimalBase."), ".
					 " Round(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0), ".$DecimalBase."), Round(ifNull(Sale_RemainAmnt,0), ".$DecimalBase."), ".
					 " ifNull(Sale_NetTotal,0), ifNull(Sale_NetTotalBase1,0), ifNull(Sale_NetTotalBase2,0), ".
					 " ifNull(Sale_NetToPay,0), ifNull(Sale_NetToPayBase1,0), ifNull(Sale_NetToPayBase2,0), ".
					 " ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0), ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0), ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0), ".
					 " ifNull(Sale_RemainAmnt,0), ifNull(Sale_RemainAmntBase1,0), ifNull(Sale_RemainAmntBase2,0), Link_ID ".
					 " From ".$_SESSION['dbLabel'].".Temp_AccLink As AccLink ".
					 " Where AccLink.Journal_Id = '".$PTransDtId."' ".
					 " And AccLink.Journal_Type = '".$TransType."' ".
					 " And upper(AccLink.CompanyName) = upper('".$DirCompany."') ".
					 " And upper(AccLink.DirYear) = upper('".$DirYear."') ";
			
			 // echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtAccLinkBalAmt   = $txtAccLinkBalAmt_M  + $rowsdt[13];
				$txtAccLinkBalAmt1  = $txtAccLinkBalAmt1_M + $rowsdt[14];
				$txtAccLinkBalAmt2  = $txtAccLinkBalAmt2_M + $rowsdt[15];
					
				
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_I['.$i.']\')"';
				if($module_invoicegridAll == 2){
					$TransDtCurrCode = $rowsdt[3];
				}
				echo"<tr id='CurRec_G9$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"";
				if($module_invoicegridAll == 2)
				echo "DeleteDetailLink";
				else 
				echo "DeleteAccLink";
				echo "('".$filepath."','".$form."','DEL','datagrid-1-i','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtAccLinkId[$i]' id='acclinkid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtLinkID[$i]'  id='linkid[$i]'  value='".$rowsdt[19]."' >
							<input type='hidden' name='txtLinkType[$i]'  id='linktype[$i]'  value='".$rowsdt[2]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt[$i]'  id='acclinknettotamt_h[$i]'  value='".$rowsdt[7]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt1[$i]' id='acclinknettotamt1_h[$i]'  value='".$rowsdt[8]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt2[$i]' id='acclinknettotamt2_h[$i]'  value='".$rowsdt[9]."' >
							<input type='hidden' name='txtAccLinkNetToPay[$i]'  id='acclinknettopay_h[$i]'  value='".$rowsdt[10]."' >
							<input type='hidden' name='txtAccLinkNetToPay1[$i]' id='acclinknettopay1_h[$i]' value='".$rowsdt[11]."' >
							<input type='hidden' name='txtAccLinkNetToPay2[$i]' id='acclinknettopay2_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtAccLinkPaidAmt[$i]'  id='acclinkpaidamt_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtAccLinkPaidAmt1[$i]' id='acclinkpaidamt1_h[$i]' value='".$rowsdt[14]."' >
							<input type='hidden' name='txtAccLinkPaidAmt2[$i]' id='acclinkpaidamt2_h[$i]' value='".$rowsdt[15]."' >
							<input type='hidden' name='txtAccLinkRemainAmt[$i]'  id='acclinkremainamt_h[$i]' value='".$rowsdt[16]."' >
							<input type='hidden' name='txtAccLinkRemainAmt1[$i]' id='acclinkremainamt1_h[$i]' value='".$rowsdt[17]."' >
							<input type='hidden' name='txtAccLinkRemainAmt2[$i]' id='acclinkremainamt2_h[$i]' value='".$rowsdt[18]."' >
							<input type='hidden' name='txtAccLinkBalAmt[$i]' id='acclinkbalamt[$i]'  value='$txtAccLinkBalAmt' >
							<input type='hidden' name='txtAccLinkBalAmt1[$i]' id='acclinkbalamt1[$i]'  value='$txtAccLinkBalAmt1' >
							<input type='hidden' name='txtAccLinkBalAmt2[$i]' id='acclinkbalamt2[$i]'  value='$txtAccLinkBalAmt2' >
							<input type='hidden' name='txtAccLinkTotAmt[$i]' id='acclinktotamt[$i]'  value='$txtAccLinkTotAmt' >
							<input type='hidden' name='txtAccLinkTotAmt1[$i]' id='acclinktotamt1[$i]'  value='$txtAccLinkTotAmt1' >
							<input type='hidden' name='txtAccLinkTotAmt2[$i]' id='acclinktotamt2[$i]'  value='$txtAccLinkTotAmt2' >
							<input type='text' name='txtLinkRef[$i]' id='linkref[$i]' value='".$rowsdt[1]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onChange=\"SetModRecord('ModRec_G9','$i');\" ".$KeyDown." />";
				echo"		<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistInvoices(1,".$i.",'".$PTransDtId."','$module_invoicegridAll');\" style='vertical-align:bottom;' title='Select Invoice'  /></span></label>";
				echo"	</td>";
	
										
				echo"   <td width='50px;' align='center'><input type='text' name='txtAccLinkCurrCode[$i]' id='acclinkcurrcode[$i]' value='".$TransDtCurrCode."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:45px; height:20px;' readonly ></td>";
				if($module_invoicegridAll != 2)	
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkNetToPay_D[$i]' id='acclinknettopay[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
				if($module_invoicegridAll == 2)	
				echo"	<td width='95px;' align='center'><input type='text' name='txtTotalInv20_D[$i]' id='totalinv20[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
			
				
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkPaidAmt_D[$i]' id='acclinkpaidamt[$i]' value='".$rowsdt[5]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onKeyup='CalcRemainAmount(1,$i);' onChange=\"SetModRecord('ModRec_G9','$i'); \" ".$KeyDown." /></td>";
			if($module_invoicegridAll != 2)
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkRemainAmt_D[$i]' id='acclinkremainamt[$i]' value='".$rowsdt[6]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
			if($module_invoicegridAll == 2)
					echo"	<td width='95px;' align='center'><input type='text' name='txtinvoicedate_D[$i]' id='txtinvoicedated[$i]' value='".$rowsdt[7]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";	
				
				// echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_I[$i]'  onMouseOver=\"style.cursor='pointer'\" onclick=\"";
				// if($module_invoicegridAll == 2)
				// echo "SubmitDetailLink";
				// else 
				// echo "SubmitAccLink";
				// echo "('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-1-i', '".$PTransId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></td>";
				// echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		 
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransDtGridInvoices2($connection,$form,$PTransId,$PTransDtId,$arrayparams,$arrayaccess){
	
	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$DefaultCur   = $arrayparams['DefaultCur'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
    $module_invoicegridAll = $arrayparams['module_invoicegridAll'];
    $Module_Form_Trans = $arrayparams['Module_Form_Trans'];
	
	$txtDate   = $arrayparams['txtDate'];
	$TransType = $arrayparams['TransType'];
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_Datagrid_Trans.php';
	
	$i = 0;
	
	
	$columnsarray = array("linkref2", "acclinkpaidamt20");
	$columnsarrayall = array("linkref2", "linkid2", "acclinknettopay20", "acclinkpaidamt20", "acclinkremainamt20", "acclinkcurrcode2", "acclinkid2", "linktype2", "acclinknettotamt20_h", "acclinknettotamt21_h", "acclinknettotamt22_h", 
							 "acclinknettopay20_h", "acclinknettopay21_h", "acclinknettopay22_h", "acclinkpaidamt20_h", "acclinkpaidamt21_h", "acclinkpaidamt22_h", "acclinkremainamt20_h", "acclinkremainamt21_h", "acclinkremainamt22_h", 
							 "acclinkbalamt20", "acclinkbalamt21", "acclinkbalamt22", "acclinktotamt20", "acclinktotamt21", "acclinktotamt22");
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
		

	//Select Data From TransDt For Selected Record
	$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, ifNull(Ledger.Ledger_Activity,0), ".
				 " TransDt.Currency_Code, Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, Transdt_dbcd ".
				 " From Temp_TransDt As TransDt ".
				 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				 " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
							  
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);

	$LedgerNumber     = $sub_result[0];
	$LedgerName       = $sub_result[1];
	$LedgerActivity   = $sub_result[2];
	$TransDtCurrCode  = $sub_result[3];
	$TransDtValueDate = $sub_result[4];
	$TransDtdbcd      = $sub_result[5];
		
		
	$vMainCompanyName=explode('_',$_SESSION['dbName']);  
	$DirCompany  = $vMainCompanyName[0];
	$DirYear	 = $vMainCompanyName[1]; 
	if($module_invoicegridAll == 2)
	{
		preg_match_all('!\d+!', $vMainCompanyName[1] ,$DirYears );
		$DirYear =  $DirYears[0][0];  
	}
	//Initializations for Div Ids
	$ContainerDiv = 'container10';
	$LoaderDiv    = 'Loader10';
	$HeaderDiv    = 'grid_headerDiv10';
	$ContentDiv   = 'grid_contentDiv10';
	$TableFocus   = 'table-focus-g10';	
	
	echo"<div id='$ContainerDiv' style='position:relative; z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''><div></div></div>";
	if($Module_Form_Trans == 0){
        $HeaderDivWidth = '263px';
    }else{
        $HeaderDivWidth = '638px';
    }
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:$HeaderDivWidth;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:475px;'>";
	
		echo"<tr height='25px;'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='105px;' align='center'><span>Inv Ref.</span></th>";
		echo"  <th width='50px;' align='center'><span>Curr.</span></th>";
		if($module_invoicegridAll != 2) echo"  <th width='95px;' align='center'><span>Net To Pay</span></th>";
		if($module_invoicegridAll == 2) echo"  <th width='95px;' align='center'><span>Invoice Amt</span></th>";
		echo"  <th width='95px;' align='center'><span>Paid Amt</span></th>";
		if($module_invoicegridAll != 2) echo"  <th width='95px;' align='center'><span>Remain Amt</span></th>";
		if($module_invoicegridAll == 2) echo"  <th width='95px;' align='center'><span>Date</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		if($Module_Form_Trans == 0){
            $ContentDivHeight = '135px';
            $ContentDivWidth = '280px';
        }else{
            $ContentDivHeight = '165px';
            $ContentDivWidth = '700px';
        }
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv')\" style='width:$ContentDivWidth;height:$ContentDivHeight;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:475px;'>";
		echo"<input type='hidden' name='SelectedRec_G10' id='SelectedRec_G10' value='$SelectedRec_G10'>
			 <input type='hidden' name='SelectedRecColor_G10' id='SelectedRecColor_G10' value='$SelectedRecColor_G10'>
			 <input type='hidden' name='ModRec_G10' id='ModRec_G10' value='$ModRec_G10'>";  
			 
			 
		if ($PTransId != '' && $PTransDtId != '') {
			if($module_invoicegridAll == 2)
			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " sum(ifNull(temp_detaillink.amount,0))  As PaidAmnt, ".
						  " sum(ifNull(amountbase1,0)) As PaidAmnt1, ".
						  " sum(ifNull(amountbase2,0)) As PaidAmnt2, ".
						  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join ".$_SESSION['dbLabel'].".temp_detaillink as temp_detaillink on TransDt.TransDt_ID = temp_detaillink.relation_id ".
						  " And temp_detaillink.journal_type = '".$TransType."' ".
						  " And upper(temp_detaillink.company) = upper('".$DirCompany."') ".
						  " And upper(temp_detaillink.year) = upper('".$DirYear."') ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
			else				
			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " (ifNull(Transdt_Amount,0) - Round(Sum(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0)),9) ) As PaidAmnt, ".
						  " (ifNull(Transdt_Amount1,0) - Round(Sum(ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0)),9) ) As PaidAmnt1, ".
						  " (ifNull(Transdt_Amount2,0) - Round(Sum(ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0)),9) ) As PaidAmnt2, ".
						  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join ".$_SESSION['dbLabel'].".Temp_AccLink on TransDt.TransDt_ID = Temp_AccLink.Journal_ID ".
						  " And Temp_AccLink.Journal_Type = '".$TransType."' ".
						  " And upper(Temp_AccLink.CompanyName) = upper('".$DirCompany."') ".
						  " And upper(Temp_AccLink.DirYear) = upper('".$DirYear."') ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
								  
			//echo $sub_query2;
			$sub_result2 = selectData($connection, $sub_query2);
			
			$txtAccLinkBalAmt20_M  = $sub_result2[1];
			$txtAccLinkBalAmt21_M  = $sub_result2[2];
			$txtAccLinkBalAmt22_M  = $sub_result2[3];
			
			$txtAccLinkTotAmt20  = $sub_result2[4];
			$txtAccLinkTotAmt21  = $sub_result2[5];
			$txtAccLinkTotAmt22  = $sub_result2[6];
			
			if($module_invoicegridAll == 2)
			$query = "select Detaillink_id, temp_detaillink.reference as Link_Ref,temp_detaillink.journal_type, Round(ifNull(Transdt_Amount,0), 2),
					Round(ifNull(headerlink.amount,0), 2),Round(ifNull(temp_detaillink.amount,0), 2),
					date_format(detaillink_date,'%d-%m-%y'), ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0),ifNull(Transdt_Amount2,0),ifNull(Transdt_Amount,0),
					ifNull(Transdt_Amount1,0),ifNull(Transdt_Amount2,0),ifNull(temp_detaillink.amount,0),ifNull(temp_detaillink.amountbase1,0),ifNull(temp_detaillink.amountbase2,0),
					ifNull(Transdt_Amount-temp_detaillink.amount,0),
					ifNull(Transdt_Amount1-temp_detaillink.amountbase1,0),ifNull(Transdt_Amount2-temp_detaillink.amountbase2,0), temp_detaillink.id ".
					 "From ".$_SESSION['dbLabel'].".temp_detaillink As temp_detaillink".
					 " Left Join Temp_TransDt as TransDt on TransDt.TransDt_ID = temp_detaillink.relation_id ".
					 " Left Join ".$_SESSION['dbLabel'].".headerlink as headerlink  on headerlink.form_id = temp_detaillink.form_id ".
					 " Where temp_detaillink.relation_id = '".$PTransDtId."' ".
					 " And temp_detaillink.journal_type = '".$TransType."' ".
					 " And upper(temp_detaillink.company) = upper('".$DirCompany."') ".
					 " And upper(temp_detaillink.year) = upper('".$DirYear."') 
					 #Group By TransDt.TransDt_ID ";		
			else		 
			$query = " Select Acc_Id, Link_Ref, Link_Type, Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."), Round(ifNull(Sale_NetToPay,0), ".$DecimalBase."), ".
					 " Round(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0), ".$DecimalBase."), Round(ifNull(Sale_RemainAmnt,0), ".$DecimalBase."), ".
					 " ifNull(Sale_NetTotal,0), ifNull(Sale_NetTotalBase1,0), ifNull(Sale_NetTotalBase2,0), ".
					 " ifNull(Sale_NetToPay,0), ifNull(Sale_NetToPayBase1,0), ifNull(Sale_NetToPayBase2,0), ".
					 " ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0), ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0), ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0), ".
					 " ifNull(Sale_RemainAmnt,0), ifNull(Sale_RemainAmntBase1,0), ifNull(Sale_RemainAmntBase2,0), Link_ID ".
					 " From ".$_SESSION['dbLabel'].".Temp_AccLink As AccLink ".
					 " Where AccLink.Journal_Id = '".$PTransDtId."' ".
					 " And AccLink.Journal_Type = '".$TransType."' ".
					 " And upper(AccLink.CompanyName) = upper('".$DirCompany."') ".
					 " And upper(AccLink.DirYear) = upper('".$DirYear."') ";
			
			//echo $query;
						
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);
		      
			while($rowsdt=mysql_fetch_array($result)){
			    				
				$recno = $i+1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$txtAccLinkBalAmt20  = $txtAccLinkBalAmt20_M + $rowsdt[13];
				$txtAccLinkBalAmt21  = $txtAccLinkBalAmt21_M + $rowsdt[14];
				$txtAccLinkBalAmt22  = $txtAccLinkBalAmt22_M + $rowsdt[15];
					
				if($module_invoicegridAll == 2){
					$TransDtCurrCode = $rowsdt[20];
				}
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_I['.$i.']\')"';
				
				echo"<tr id='CurRec_G10$i' class='$bgcolor $TableFocus'>";		
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"";
				if($module_invoicegridAll == 2)
				echo "DeleteDetailLink";
				else 
				echo "DeleteAccLink";
				echo "('".$filepath."','".$form."','DEL','datagrid-2-i','".$PTransId."','".$PTransDtId."','".$rowsdt[0]."');return false;\" title='Delete Record'  ></td>";
				
				echo "	<td width='105px;' align='left'>
							<input type='hidden' name='txtAccLinkId2[$i]' id='acclinkid2[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='txtLinkID2[$i]'  id='linkid2[$i]'  value='".$rowsdt[19]."' >
							<input type='hidden' name='txtLinkType2[$i]'  id='linktype2[$i]'  value='".$rowsdt[2]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt20[$i]'  id='acclinknettotamt20_h[$i]'  value='".$rowsdt[7]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt21[$i]' id='acclinknettotamt21_h[$i]'  value='".$rowsdt[8]."' >
							<input type='hidden' name='txtAccLinkNetTotAmt22[$i]' id='acclinknettotamt22_h[$i]'  value='".$rowsdt[9]."' >
							<input type='hidden' name='txtAccLinkNetToPay20[$i]'  id='acclinknettopay20_h[$i]'  value='".$rowsdt[10]."' >
							<input type='hidden' name='txtAccLinkNetToPay21[$i]' id='acclinknettopay21_h[$i]' value='".$rowsdt[11]."' >
							<input type='hidden' name='txtAccLinkNetToPay22[$i]' id='acclinknettopay22_h[$i]' value='".$rowsdt[12]."' >
							<input type='hidden' name='txtAccLinkPaidAmt20[$i]'  id='acclinkpaidamt20_h[$i]' value='".$rowsdt[13]."' >
							<input type='hidden' name='txtAccLinkPaidAmt21[$i]' id='acclinkpaidamt21_h[$i]' value='".$rowsdt[14]."' >
							<input type='hidden' name='txtAccLinkPaidAmt22[$i]' id='acclinkpaidamt22_h[$i]' value='".$rowsdt[15]."' >
							<input type='hidden' name='txtAccLinkRemainAmt20[$i]'  id='acclinkremainamt20_h[$i]' value='".$rowsdt[16]."' >
							<input type='hidden' name='txtAccLinkRemainAmt21[$i]' id='acclinkremainaAmt21_h[$i]' value='".$rowsdt[17]."' >
							<input type='hidden' name='txtAccLinkRemainAmt22[$i]' id='acclinkremainamt22_h[$i]' value='".$rowsdt[18]."' >
							<input type='hidden' name='txtAccLinkBalAmt20[$i]' id='acclinkbalamt20[$i]'  value='$txtAccLinkBalAmt20' >
							<input type='hidden' name='txtAccLinkBalAmt21[$i]' id='acclinkbalamt21[$i]'  value='$txtAccLinkBalAmt21' >
							<input type='hidden' name='txtAccLinkBalAmt22[$i]' id='acclinkbalamt22[$i]'  value='$txtAccLinkBalAmt22' >
							<input type='hidden' name='txtAccLinkTotAmt20[$i]' id='acclinktotamt20[$i]'  value='$txtAccLinkTotAmt20' >
							<input type='hidden' name='txtAccLinkTotAmt21[$i]' id='acclinktotamt21[$i]'  value='$txtAccLinkTotAmt21' >
							<input type='hidden' name='txtAccLinkTotAmt22[$i]' id='acclinktotamt22[$i]'  value='$txtAccLinkTotAmt22' >
							<input type='text' name='txtLinkRef2[$i]' id='linkref2[$i]' value='".$rowsdt[1]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:20px;' onChange=\"SetModRecord('ModRec_G10','$i');\" ".$KeyDown." />";
				echo"		<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistInvoices(2,".$i.",'".$PTransDtId."','$module_invoicegridAll');\" style='vertical-align:bottom;' title='Select Invoice'  /></span></label>";
				echo"	</td>";
	
										
				echo"   <td width='50px;' align='center'><input type='text' name='txtAccLinkCurrCode2[$i]' id='acclinkcurrcode2[$i]' value='".$TransDtCurrCode."' maxlength='10' class='".$ClassE."' style='font-size:12px; width:45px; height:20px;' readonly ></td>";
			if($module_invoicegridAll != 2)	
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkNetToPay20_D[$i]' id='acclinknettopay20[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
			if($module_invoicegridAll == 2)	
				echo"	<td width='95px;' align='center'><input type='text' name='txtTotalInv20_D[$i]' id='totalinv20[$i]' value='".$rowsdt[4]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkPaidAmt20_D[$i]' id='acclinkpaidamt20[$i]' value='".$rowsdt[5]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onKeyup='CalcRemainAmount(2,$i);' onChange=\"SetModRecord('ModRec_G10','$i'); \" ".$KeyDown." /></td>";
			if($module_invoicegridAll != 2)
				echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkRemainAmt20_D[$i]' id='acclinkremainamt20[$i]' value='".$rowsdt[6]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
			if($module_invoicegridAll == 2)	
				echo"	<td width='95px;' align='center'><input type='text' name='txtinvoicedate2_D[$i]' id='txtinvoicedate2d[$i]' value='".$rowsdt[6]."' maxlength='20' class='".$ClassE."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";	
				
				echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_I[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitAccLink2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-i', '".$PTransId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);'></button></td>";
				echo"	<td width='25px;' align='center'>$recno</td>";
				echo "</tr>";
			
				$i+=1;
				
				
			}
			
		}
		
		
		
		$recno = $i+1;
		
		if ($i%2==0) $bgcolor='bgcolor1';
		else $bgcolor='bgcolor2';	

		$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2_I['.$i.']\')"';
		$KeyDown1  = "onkeydown=\"return dokey1(event,this,".$i.",'".$columnslist."','imgSubmit_2_I[".$i."]','1');LeaveToMainGrid('linkref2[$i]','ledgernumber2','RecIndex_G2','')\" ";						
		if($module_invoicegridAll == 2)
			$sub_query2 = " Select TransDt.TransDt_ID, ".
						  " ifNull(temp_detaillink.amount_paid,0)  As PaidAmnt, ".
						  " ifNull(amountbase1_paid,0) As PaidAmnt1, ".
						  " (ifNull(amountbase2_paid,0) As PaidAmnt2, ".
						  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0) ".
						  " From Temp_TransDt As TransDt Left Join ".$_SESSION['dbLabel'].".temp_detaillink as temp_detaillink on TransDt.TransDt_ID = temp_detaillink.form_id ".
						  " And temp_detaillink.journal_type = '".$TransType."' ".
						  " And upper(temp_detaillink.company) = upper('".$DirCompany."') ".
						  " And upper(temp_detaillink.year) = upper('".$DirYear."') ".
						  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
						  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
									
			else
		$sub_query2 = " Select TransDt.TransDt_ID, ".
					  " Round((ifNull(Transdt_Amount,0) - Sum(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0))), ".$DecimalBase1.")  As PaidAmnt_D, ".
					  " Round((ifNull(Transdt_Amount1,0) - Sum(ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0))), ".$DecimalBase1.") As PaidAmnt1_D, ".
					  " Round((ifNull(Transdt_Amount2,0) - Sum(ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0))), ".$DecimalBase1.") As PaidAmnt2_D, ".
					  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0), ".
					  " (ifNull(Transdt_Amount,0) - Round(Sum(ifNull(Sale_PaidAmnt,0) + ifNull(Sale_ReturnAmnt,0)),9) ) As PaidAmnt, ".
					  " (ifNull(Transdt_Amount1,0) - Round(Sum(ifNull(Sale_PaidAmntBase1,0) + ifNull(Sale_ReturnAmntbase1,0)),9) ) As PaidAmnt1, ".
					  " (ifNull(Transdt_Amount2,0) - Round(Sum(ifNull(Sale_PaidAmntBase2,0) + ifNull(Sale_ReturnAmntbase2,0)),9) ) As PaidAmnt2 ".
					  " From Temp_TransDt As TransDt Left Join ".$_SESSION['dbLabel'].".Temp_AccLink on TransDt.TransDt_ID = Temp_AccLink.Journal_ID ".
					  " And Temp_AccLink.Journal_Type = '".$TransType."' ".
					  " And upper(Temp_AccLink.CompanyName) = upper('".$DirCompany."') ".
					  " And upper(Temp_AccLink.DirYear) = upper('".$DirYear."') ".
					  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
					  " Group By TransDt.TransDt_ID, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";

							  
		//echo $sub_query2;
		$sub_result2 = selectData($connection, $sub_query2);
		
		$txtAccLinkBalAmt20  = $sub_result2[7];
		$txtAccLinkBalAmt21  = $sub_result2[8];
		$txtAccLinkBalAmt22  = $sub_result2[9];
			
		$txtAccLinkTotAmt20  = $sub_result2[4];
		$txtAccLinkTotAmt21  = $sub_result2[5];
		$txtAccLinkTotAmt22  = $sub_result2[6];
			
		$txtAccLinkPaidAmt20_D = $sub_result2[1];
	
		$txtAccLinkPaidAmt20  = $sub_result2[7];
		$txtAccLinkPaidAmt21  = $sub_result2[8];
		$txtAccLinkPaidAmt22  = $sub_result2[9];
				
		echo"<tr id='CurRec_G10$i' class='$bgcolor $TableFocus' >";
		echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G10');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
			  
		echo "	<td width='105px;' align='left'>
					<input type='hidden' name='txtAccLinkId2[$i]' id='acclinkid2[$i]' value='$txtAccLinkId2' >
					<input type='hidden' name='txtLinkID2[$i]'  id='linkid2[$i]'  value='$txtLinkID2' >
					<input type='hidden' name='txtLinkType2[$i]'  id='linktype2[$i]'  value='$txtLinkType2' >
					<input type='hidden' name='txtAccLinkNetTotAmt20[$i]'  id='acclinknettotamt20_h[$i]'  value='$txtAccLinkNetTotAmt20' >
					<input type='hidden' name='txtAccLinkNetTotAmt21[$i]' id='acclinknettotamt21_h[$i]'  value='$txtAccLinkNetTotAmt21' >
					<input type='hidden' name='txtAccLinkNetTotAmt22[$i]' id='acclinknettotamt22_h[$i]'  value='$txtAccLinkNetTotAmt22' >
					<input type='hidden' name='txtAccLinkNetToPay20[$i]'  id='acclinknettopay20_h[$i]'  value='$txtAccLinkNetToPay20' >
					<input type='hidden' name='txtAccLinkNetToPay21[$i]' id='acclinknettopay21_h[$i]' value='$txtAccLinkNetToPay21' >
					<input type='hidden' name='txtAccLinkNetToPay22[$i]' id='acclinknettopay22_h[$i]' value='$txtAccLinkNetToPay22' >
					<input type='hidden' name='txtAccLinkPaidAmt20[$i]'  id='acclinkpaidamt20_h[$i]' value='$txtAccLinkPaidAmt20' >
					<input type='hidden' name='txtAccLinkPaidAmt21[$i]' id='acclinkpaidamt21_h[$i]' value='$txtAccLinkPaidAmt21' >
					<input type='hidden' name='txtAccLinkPaidAmt22[$i]' id='acclinkpaidamt22_h[$i]' value='$txtAccLinkPaidAmt22' >
					<input type='hidden' name='txtAccLinkRemainAmt20[$i]'  id='acclinkremainamt20_h[$i]' value='$txtAccLinkRemainAmt20' >
					<input type='hidden' name='txtAccLinkRemainAmt21[$i]' id='acclinkremainaAmt21_h[$i]' value='$txtAccLinkRemainAmt21' >
					<input type='hidden' name='txtAccLinkRemainAmt22[$i]' id='acclinkremainamt22_h[$i]' value='$txtAccLinkRemainAmt22' >
					<input type='hidden' name='txtAccLinkBalAmt20[$i]' id='acclinkbalamt20[$i]'  value='$txtAccLinkBalAmt20' >
					<input type='hidden' name='txtAccLinkBalAmt21[$i]' id='acclinkbalamt21[$i]'  value='$txtAccLinkBalAmt21' >
					<input type='hidden' name='txtAccLinkBalAmt22[$i]' id='acclinkbalamt22[$i]'  value='$txtAccLinkBalAmt22' >
					<input type='hidden' name='txtAccLinkTotAmt20[$i]' id='acclinktotamt20[$i]'  value='$txtAccLinkTotAmt20' >
					<input type='hidden' name='txtAccLinkTotAmt21[$i]' id='acclinktotamt21[$i]'  value='$txtAccLinkTotAmt21' >
					<input type='hidden' name='txtAccLinkTotAmt22[$i]' id='acclinktotamt22[$i]'  value='$txtAccLinkTotAmt22' >
					<input type='text' name='txtLinkRef2[$i]' id='linkref2[$i]' value='$txtLinkRef2'  maxlength='20' class='".$ClassI."' style='font-size:12px; width:75px; height:20px;' onBlur=\"LeaveToMainGrid('linkref2[$i]','ledgernumber2','RecIndex_G2','')\"    onChange=\"SetModRecord('ModRec_G10','$i');\" ".$KeyDown1." />";
		echo"		<label><span><img src='img/openlist.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"showlistInvoices(2,".$i.",'".$PTransDtId."','$module_invoicegridAll');\" style='vertical-align:bottom;' title='Select Invoice'  /></span></label>";			
		echo"	</td>";
										
		echo"   <td width='50px;' align='center'><input type='text' name='txtAccLinkCurrCode2[$i]' id='acclinkcurrcode2[$i]' value='".$TransDtCurrCode."' maxlength='10' class='".$ClassI."' style='font-size:12px; width:45px; height:20px;' readonly ></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkNetToPay20_D[$i]' id='acclinknettopay20[$i]' value='$txtAccLinkNetToPay20_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkPaidAmt20_D[$i]' id='acclinkpaidamt20[$i]' value='$txtAccLinkPaidAmt20_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;' onBlur='CheckAmount(this.id,$i);' onKeyup='CalcRemainAmount(2,$i);' onChange=\"SetModRecord('ModRec_G10','$i'); \" ".$KeyDown." /></td>";
		echo"	<td width='95px;' align='center'><input type='text' name='txtAccLinkRemainAmt20_D[$i]' id='acclinkremainamt20[$i]' value='$txtAccLinkRemainAmt20_D' maxlength='20' class='".$ClassI."' style='text-align:right; font-size:12px; width:90px; height:20px;'  readonly /></td>";
			
		echo "	<td width='25px;' align='center' valign='center'><button type='button' id='imgSubmit_2_I[$i]' onMouseOver=\"style.cursor='pointer'\" onclick=\"SubmitAccLink2('".$i."','".$filepath."', '".$form."', 'ADD', 'datagrid-2-i', '".$PTransId."', '".$PTransDtId."'); return false;\" title='Submit Record' style='width:20px;height: 20px;background-image: url(img/confirm-1.png);' ></button></td>";
		echo"	<td width='25px;' align='center'>$recno</td>";
		echo"</tr>";  

		
	echo"	</table>";  
	echo"	</div>";
	
	echo"</div>";
	
	
}

function ShowTransTotals($connection,$PTransId,$arrayparams,$arrayaccess, $query_labels){
    
	$query_labels = $_SESSION['query_labels'];
	$result_labels = mysql_query($query_labels, $connection);
	$row_labels    = mysql_fetch_array($result_labels);
	extract($row_labels); 
	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$Base1 		  = $arrayparams['Base1'];
	$Base2 		  = $arrayparams['Base2'];
	$Hide_Base2   = $arrayparams['Hide_Base2'];
	
	$Module_TransStandardView = $arrayparams['Module_TransStandardView'];
	

	$sub_query = " Select Trans_Date, Currency_Code, ifNull(Trans_AmountDb1,0), ifNull(Trans_AmountDb2,0), ifNull(Trans_Amountcd1,0), ifNull(Trans_Amountcd2,0)  ".
				 " From Temp_Trans As Trans ".
				 " Where Trans_ID = ".$PTransId;
			 
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);
	
	$txtDate = $sub_result[0];
	$txtCurr = $sub_result[1];
	$txtTransAmountDb1   = $sub_result[2];
	$txtTransAmountDb2   = $sub_result[3];
	$txtTransAmountCd1   = $sub_result[4];
	$txtTransAmountCd2   = $sub_result[5];
	$txtTransBalance1  = $txtTransAmountDb1 - $txtTransAmountCd1;
	$txtTransBalance2  = $txtTransAmountDb2 - $txtTransAmountCd2;
	
	$txtTransAmtDb    = ConvertCurrency($Base1, $txtCurr, insertMySQLDate($txtDate), $txtTransAmountDb1, $connection); 
	$txtTransAmtCr    = ConvertCurrency($Base1, $txtCurr, insertMySQLDate($txtDate), $txtTransAmountCd1, $connection);
	$txtTransAmtBal   = $txtTransAmtDb - $txtTransAmtCr;
	
	echo"	  <table valign='top' width='240' border='0' cellspacing=0 cellpadding=0>
				<tr>
					<td id='total-top' style='width:240px;height:12px;'></td>
				</tr>
				<tr>
					<td id='total-content' style='width:240px;height:12px;'>";
				
				echo"	<table border='0' cellspacing=0 width=100% >";
			
			if ($Module_TransStandardView == 1) {				
				echo"	<tr>
							<td valign='middle' align='center' width='15%'><span class='style10'>$Base1</span></td> 
							<td valign='middle' align='right' width='25%'><span class='style10'>$Debit</span>&nbsp;</td>
							<td align='left'><input type='text' id='transamnt1db'  name='txtTransAmountDb1' value='".number_format($txtTransAmountDb1,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style10'>$Credit</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transamnt1cd' name='txtTransAmountCd1' value='".number_format($txtTransAmountCd1,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style10'>$Balance</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transbalance1' name='txtTransBalance1' value='".number_format($txtTransBalance1,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
							
							if($txtTransBalance1<0) echo " color:#FF0000;";
							echo" ' readonly></td>
						</tr>";
			if($Hide_Base2==0){
				echo" <tr>
							<td valign='middle' align='center' width='15%'><span class='style11'>$Base2</span></td> 
							<td valign='middle' align='right' width='25%'><span class='style11'>$Debit</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transamnt2db' name='txtTransAmountDb2' value='".number_format($txtTransAmountDb2,$DecimalBase2)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>	
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style11'>$Credit</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transamnt2cd' name='txtTransAmountCd2' value='".number_format($txtTransAmountCd2,$DecimalBase2)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style11'>$Balance</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transbalance2' name='txtTransBalance2' value='".number_format($txtTransBalance2,$DecimalBase2)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
						if($txtTransBalance2<0) echo " color:#FF0000;";
							echo " ' readonly></td>
						</tr>";
			} else {
				echo" <tr>
							<td valign='middle' align='center' width='15%'><span class='style11'></span></td> 
							<td valign='middle' align='right' width='25%'><span class='style11'></span>&nbsp;</td> 
							<td align='left'><input type='hidden' id='transamnt2db' name='txtTransAmountDb2' value='0' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>	
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style11'></span>&nbsp;</td> 
							<td align='left'><input type='hidden' id='transamnt2cd' name='txtTransAmountCd2' value='0' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style11'></span>&nbsp;</td> 
							<td align='left'><input type='hidden' id='transbalance2' name='txtTransBalance2' value='0' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;";
						if($txtTransBalance2<0) echo " color:#FF0000;";
							echo " ' readonly></td>
						</tr>";
			}
				echo"	<input type='hidden' id='transamntdb'  name='txtTransAmtDb' value='".number_format($txtTransAmtDb,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transamntcd'  name='txtTransAmtCr' value='".number_format($txtTransAmtCr,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transbalance'  name='txtTransAmtBal' value='".number_format($txtTransAmtBal,$DecimalBase1)."'>";
			} else {
				echo"	<tr>
							<td valign='middle' align='center' width='15%'><span class='style10'>$txtCurr</span></td> 
							<td valign='middle' align='right' width='25%'><span class='style10'>Debit</span>&nbsp;</td>
							<td align='left'><input type='text' id='transamntdb'  name='txtTransAmtDb' value='".number_format($txtTransAmtDb,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style10'>Credit</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transamntcd' name='txtTransAmtCr' value='".number_format($txtTransAmtCr,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>
						<tr><td valign='middle' align='right' width='40%' colspan='2'><span class='style10'>Balance</span>&nbsp;</td> 
							<td align='left'><input type='text' id='transbalance' name='txtTransAmtBal' value='".number_format($txtTransAmtBal,$DecimalBase1)."' maxlength='20' style='text-align:right; width:120px; height=20px;background:#C6D4E5;' readonly></td>
						</tr>";
						
				echo"	<input type='hidden' id='transamnt1db'  name='txtTransAmountDb1' value='".number_format($txtTransAmountDb1,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transamnt1cd'  name='txtTransAmountCd1' value='".number_format($txtTransAmountCd1,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transbalance1'  name='txtTransBalance1' value='".number_format($txtTransBalance1,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transamnt2db'  name='txtTransAmountDb2' value='".number_format($txtTransAmountDb2,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transamnt2cd'  name='txtTransAmountCd2' value='".number_format($txtTransAmountCd2,$DecimalBase1)."'>";
				echo"	<input type='hidden' id='transbalance2'  name='txtTransBalance2' value='".number_format($txtTransBalance2,$DecimalBase1)."'>";
			}
						
	echo "					
						</table>
					</td>
				</tr>";
			
	echo "		<tr>
					<td id='total-bottom' style='width:240px;height:12px;'></td>
				</tr>
			  </table>";
}

function showDataGridFooter($filepath,$form,$transid,$gridid,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction, $query_journal_labels, $connection) {
	//echo $query_journal_labels;
	$result_journal_labels = mysql_query($query_journal_labels, $connection);
	//echo $result_journal_labels;
	$row_journal_labels    = mysql_fetch_array($result_journal_labels);
	//echo $row_journal_labels;
	extract($row_journal_labels);
	echo"<div class='grid_toolbarDiv'>
			<table width='100%' border=0 cellpadding='0' cellspacing='0'>
			<tr>";
	
	$rangefrom = ($startrange + 1);
	if (($startrange + $perpage) >= $totalrows) $rangeto = $totalrows; else $rangeto = ($startrange + $perpage);
				
	if ($totalrows > 0)			
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>View ".$rangefrom." - ".$rangeto." of ".$totalrows."</span></td>";
	else
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>".$NoRecords."</span></td>";
	
	echo"		<td align='center' style='width:15%;border-top:1px solid #000000;'><span class='toolbar_style'>".$Perpage." </span><span class='toolbar_style'><select name='perpage' id='perpage' value='$perpage' onchange=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'CP','".$orderby."','".$morelines."',0,this.value,'".$totalrows."','".$direction."');\">";
				  
				if ($perpage==10)		 $s10 = 'selected';
				else if ($perpage==20)	 $s20 = 'selected';
				else if ($perpage==30)	 $s30 = 'selected';
				else if ($perpage==40)	 $s40 = 'selected';
				else if ($perpage==50)	 $s50 = 'selected';
				else if ($perpage==100)	 $s100 = 'selected';
				else if ($perpage==1000) $s1000 = 'selected';

								
				echo'<option '.$s10.' value="10">10</option>
					 <option '.$s20.' value="20">20</option>
					 <option '.$s30.' value="30">30</option>
					 <option '.$s40.' value="40">40</option>
					 <option '.$s50.' value="50">50</option>
					 <option '.$s100.' value="100">100</option>
					 <option '.$s1000.' value="1000">1000</option>
					 </select></span>
				</td>';
				
	echo"		<td  style='width:10%;border-right:1px solid #000000;text-align:right;border-top:1px solid #000000;'>";
				
				if($startrange > 0)
					echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='pointer'\"    onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'F','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";

				$diff= $startrange - $perpage;
					
				if (($diff) >= 0 ){
					$prvstartrange = $startrange - $perpage;
					echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'P','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";
				}
				else
					echo "&nbsp;";
			
	echo"		</td><td  align='left' style='width:10%;border-top:1px solid #000000;'>&nbsp;";
			
			
				if ($startrange <= $totalrows){
					$startrange1 = $startrange + $perpage;
					if  ($startrange1 < $totalrows){ 
						echo"<img src='img/arrowright.png' title='Next' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'N','".$orderby."','".$morelines."','".$startrange1."','".$perpage."','".$totalrows."','".$direction."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'L','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				
				$currentpage = ($startrange / $perpage) + 1;
				$totalpages  = ceil($totalrows / $perpage);
				
	echo"		</td><td style='text-align:center; width:14%;border-top:1px solid #000000;'>&nbsp;<span class='toolbar_style'>".$Page." $currentpage / $totalpages</span></td>";
	

	
	echo"		<td style='text-align:center; width:6%;border-top:1px solid #000000;'><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"  width='20' height='20' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'R','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ></td>";
	echo"		<td align='right' style='width:12%; padding-right:10px;border-top:1px solid #000000;'>&nbsp;</td>";
	
	echo"	</tr>";
	echo"	</table></div>";

}

?>