<?php

session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Trans.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " ifNull(Ledger_ValidateProject,0) As LedgerValidateProject from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From TransSetup Table							
$querytranssetup= " select DefaultCur  from transsetup where JournalType = '".$PTransType."'";
$resulttranssetup=mysql_query($querytranssetup,$connection) or die(mysql_error());
while($rowtranssetup=mysql_fetch_array($resulttranssetup)){
	extract($rowtranssetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_TransStandardView,0) As Module_TransStandardView, ifNull(Module_ShowBalance,0) As Module_ShowBalance From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

if (empty($SetCurrency))
	$SetCurrency = 0;	
	
$message = ereg_replace("'"," ",$message);	

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function SubmitRecord(ClientDetail) {
	x = document.transdt;
	
	
	var result = CheckFields(ClientDetail);
	var vTransId   = x.PTransId.value;
	var vTransType = x.PTransType.value;
	var vAccountType = x.PAccountType.value;
	var vTransDtId = x.txtTransDtId.value;
	
	
	var vMainMode = x.mainaction.value;
	var vMode = x.actionmode.value;
	
	if (vTransDtId == '')
		vMode = 'submitrecord';	
	else
		vMode = 'editdt';	
	   
	if (result == 1) {
		x.action="Form_Trans_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SAccountType="+vAccountType;
		x.submit();
		
	}	
}


function ClearRecord(){
	x = document.transdt;
	
	x.txtTransDtId.value='';
	x.txtTransDtdbcd.value='';
	x.txtLedgerNo.value='';
	x.txtLedgerName.value='';
	x.txtClientDtCode.value='';
	x.txtClientDtName.value='';
	x.txtTransDtDesc.value='';
	x.txtTransDtCurr.value='';
	x.txtTransDtAmount.value='';
	x.txtTransDtAmountB1.value='';
	x.txtTransDtAmountB2.value='';
	x.txtTransDtAmount_D.value='';
	x.txtTransDtAmountB1_D.value='';
	x.txtTransDtAmountB2_D.value='';
	x.txtTransDtValueDate.value='';
	
	x.SetCurrency.value='';		
	x.message.value='';

	x.submit();	
	
}


function CheckFields(ClientDetail){
  
    x = document.transdt;
	
	var vLedgerNo = x.txtLedgerNo.value;
	var vCurr     = x.txtTransDtCurr.value;
	var vAmount   = x.txtTransDtAmount_D.value;
	var vAmountB1 = x.txtTransDtAmountB1_D.value;
	var vAmountB2 = x.txtTransDtAmountB2_D.value;
	
	var vClientDt = x.txtClientDtCode.value;
	
	
	if (vAmount == '')   vAmount  = 0;
	if (vAmountB1 == '') vAmountB1 = 0;
	if (vAmountB2 == '') vAmountB2 = 0;
	
	
	
	if (vLedgerNo=='')
	{
		alert("Ledger No. is mandatory!");
		x.txtLedgerNo.focus();
		return 0;
	}
	else if (vCurr=='')
	{
		alert("Currency is mandatory!");
		x.txtTransDtCurr.focus();
		return 0;
	}
	else if (vAmount==0 && vAmountB1==0 && vAmountB2==0)
	{
		alert("Amount is mandatory!");
		x.txtTransDtAmount_D.focus();
		return 0;
	}
	else if (vClientDt=='' && ClientDetail==1)
	{
		alert("Client Detail is mandatory!");
		x.txtClientDtCode.focus();
		return 0;
	}		
	
	else
	return 1 ;	
}


function CheckAmount(option) {
	x=document.transdt;
	var vAmount, vAmount1, vAmount1;
	
	vAmount  = x.txtTransDtAmount_D.value;
	vAmount1 = x.txtTransDtAmountB1_D.value;
	vAmount2 = x.txtTransDtAmountB2_D.value;
	
	
	if (vAmount == '')  vAmount  = 0;
	if (vAmount1 == '') vAmount1 = 0;
	if (vAmount2 == '') vAmount2 = 0;
	
	
	if ((vAmount*1 != vAmount/1 || vAmount < 0) && option == 1 ) {
		alert('Amount should be a Numeric and Positive value.');
		x.txtTransDtAmount_D.focus();
		return (false);
	}
	else if ((vAmount1*1 != vAmount1/1 || vAmount1 < 0) && option == 2 ) {
		alert('Amount1 should be a Numeric and Positive value.');
		x.txtTransDtAmountB1_D.focus();
		return (false);
	}
	else if ((vAmount2*1 != vAmount2/1 || vAmount2 < 0) && option == 3) {
		alert('Amount2 should be a Numeric and Positive value.');
		x.txtTransDtAmountB2_D.focus();
		return (false);
	}

}


function SetAmount(option, rate, rate1, rate2, dec1, dec2, curr, currbase1, currbase2) {

	x=document.transdt;
	var vAmount, vAmount1, vAmount2;
	
	dec1  = parseInt(dec1);
	dec2  = parseInt(dec2);
	rate  = parseFloat(rate);
	rate1 = parseFloat(rate1);
	rate2 = parseFloat(rate2);
	
	if (option == 1) {
		
		vAmount = x.txtTransDtAmount_D.value;
		if (vAmount == '') vAmount = 0;
	
		vAmount=parseFloat(vAmount);
		
		x.txtTransDtAmount.value= vAmount;
		
		if (vAmount > 0) { 
			vAmount1=Math.round(((vAmount*rate)/rate1)*Math.pow(10,dec1))/Math.pow(10,dec1);
			vAmount1=parseFloat(vAmount1);
			x.txtTransDtAmountB1_D.value= vAmount1;
			x.txtTransDtAmountB1.value= parseFloat((vAmount*rate)/rate1);
				
			vAmount2=Math.round(((vAmount*rate)/rate2)*Math.pow(10,dec2))/Math.pow(10,dec2);
			vAmount2=parseFloat(vAmount2);
			x.txtTransDtAmountB2_D.value=vAmount2;
			x.txtTransDtAmountB2.value= parseFloat((vAmount*rate)/rate2);
		}	
	}	
	else if (option == 2) {
		vAmount1 = x.txtTransDtAmountB1_D.value;
		if (vAmount1 == '') vAmount1 = 0;
		
		vAmount1=parseFloat(vAmount1);
		
		if (curr == currbase1 && vAmount1 > 0) {
			x.txtTransDtAmount_D.value= vAmount1;
			x.txtTransDtAmount.value= vAmount1;
			x.txtTransDtAmountB1.value=vAmount1;
		}	
		else if (curr == currbase2 && vAmount1 > 0) {
			x.txtTransDtAmountB1.value=vAmount1;
		}
		else if (vAmount1 > 0) {
			x.txtTransDtAmountB1.value=vAmount1;
		}
	
	}
	else if (option == 3) {
		vAmount2 = x.txtTransDtAmountB2_D.value;
		if (vAmount2 == '') vAmount2 = 0;
		
		vAmount2=parseFloat(vAmount2);

		
		if (curr == currbase2 && vAmount2 > 0) {
			x.txtTransDtAmount_D.value= vAmount2;
			x.txtTransDtAmount.value= vAmount2;
			x.txtTransDtAmountB2.value=vAmount2;
		}	
		else if (curr == currbase1 && vAmount2 > 0) {
			x.txtTransDtAmountB2.value=vAmount2;
		}
		else if (vAmount2 > 0) {
			x.txtTransDtAmountB2.value=vAmount2;
		}
	
	}
		
	
}

function showlistLedgers(str){
	x = document.transdt;

	var vTransType   = x.PTransType.value;
	var vAccountType = x.PAccountType.value;
	var vCashType    = x.PTransCashType.value;
	
	vCashType = vCashType.replace('&','%26');

	window.open('Form_Trans_ListLedgers.php?str='+str+'&PTransType='+vTransType+'&PAccountType='+vAccountType+'&PCashType='+vCashType,'mywindow','width=650,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistClientDetail(str){
	x = document.transdt;
    var vcltcode, vcode;
	vcode   = x.txtClientDtCode.value;
	vcltcode= x.txtLedgerNo.value;
	  
	window.open('List_ClientDetail.php?frm=2&item='+str+'&PDetailCode='+vcode+'&PClientCode='+vcltcode,'List_ClientDetail','width=700,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistManualNo(str) {
	x = document.transdt;

	var vTransType = x.PTransType.value;
	var vLedgerNo  = x.txtLedgerNo.value;
	
	window.open('Form_Trans_ListManualNo.php?str='+str+'&PTransType='+vTransType+'&PLedgerNo='+vLedgerNo,'Form_Trans_ListManualNo','width=740,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function RefreshPage()
{
  document.transdt.submit();

}

function ChangeCurrency() {
	x = document.transdt;
	x.SetCurrency.value = 1;
	
	x.submit();
}

function ChangeLocation() {
	x = document.transdt;
	var vMode = x.actionmode.value;
	
	if (vMode == 'submitrecord') {
		
		opener.document.trans.actionmode.value = x.actionmode.value;
		opener.document.trans.mainaction.value = x.mainaction.value;
		//opener.document.trans.message.value = x.message.value;
		opener.document.trans.txtTransId.value = x.PTransId.value;
		opener.document.trans.submit();
		
	} 
	else if (vMode == 'editdt') {
		opener.document.trans.actionmode.value = x.actionmode.value;
		opener.document.trans.mainaction.value = x.mainaction.value;
		opener.document.trans.txtTransId.value = x.PTransId.value;
		opener.document.trans.submit();
		
		self.close();
	}
	
	//x.txtItemCode.focus();
}

function kd(e)
{
	x=document.transdt;
    var intKey = (window.Event) ? e.which : e.keyCode;
    if (intKey == 13) { //enter key
        //x.btnSubmitRecord.click();
		return false;
    }
    return true;
}

/*function loadXMLDoc(url) {   
	// branch for native XMLHttpRequest object    
	if (window.XMLHttpRequest) {        
		req = new XMLHttpRequest();        
		req.onreadystatechange = processReqChange;        
		req.open("GET", url, true);        
		req.send(null);    
	// branch for IE/Windows ActiveX version    
	} else if (window.ActiveXObject) {        
		req = new ActiveXObject("Microsoft.XMLHTTP");        
		if (req) {            
			req.onreadystatechange = processReqChange;            
			req.open("GET", url, true);            
			req.send();        
		}    
	}
}


function processReqChange() {
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			response  = req.responseXML.documentElement;
			method    = response.getElementsByTagName('method')[0].firstChild.data;
			result    = response.getElementsByTagName('result')[0].firstChild.data;
			eval(method + '(\'\', result)');
		} else {
			alert("There was a problem retrieving the XML data:" + req.statusText);
		}
	}
}*/

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Details</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}

.style13 {
	font-size: 11px;
	font-weight: bold;
}

.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body onLoad='ChangeLocation();'>
<form name='transdt' method='post'>
<input type='hidden' name='message' value='$message' >
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='PTransType' value='$PTransType'>
<input type='hidden' name='PTransId' value='$PTransId'>
<input type='hidden' name='PTransDate' value='$PTransDate'>
<input type='hidden' name='PTransCurr' value='$PTransCurr'>
<input type='hidden' name='PTransCashType' value='$PTransCashType'>
<input type='hidden' name='PTransDtId' value='$PTransDtId'>
<input type='hidden' name='PAccountType' value='$PAccountType'>
<input type='hidden' name='SetCurrency' value='$SetCurrency' >
HERE;

echo "<input type='hidden' name='PTransManualNo' value='".htmlspecialchars($PTransManualNo, ENT_QUOTES)."' > 
	  <input type='hidden' name='PTransProjectCode' value='".htmlspecialchars($PTransProjectCode, ENT_QUOTES)."' >
	  <input type='hidden' name='PTransCostCentCode' value='".htmlspecialchars($PTransCostCentCode, ENT_QUOTES)."' >
	  <input type='hidden' name='PTransRemark' value='".htmlspecialchars($PTransRemark, ENT_QUOTES)."' >
	  <input type='hidden' name='PTransRepresent' value='".htmlspecialchars($PTransRepresent, ENT_QUOTES)."' > ";
	  


$query_buttons = " Select JourTypeButton_DBCD ".
				 " From JourTypeButton ".
				 " Where JourType_code = '".$PTransType."' ".
				 " And JourTypeButton_Name = '".$PAccountType."' ".
				 " Order By JourTypeButton_Order ";
$result_buttons = selectData($connection, $query_buttons);				 
				 
if ($result_buttons[0]=='D') {
	$Type_dbcd  = 'D'; 
	$Type_Label = $PAccountType.' Accounts'; 
} else {
	$Type_dbcd  = 'C';
	$Type_Label = $PAccountType.' Accounts'; 
}	

if (empty($txtTransDtCurr))	{
	if ($Module_TransStandardView == 1)
		$txtTransDtCurr = $DefaultCur;
	else
		$txtTransDtCurr = $PTransCurr;
}	
if (empty($txtTransDtValueDate))	
	$txtTransDtValueDate = displayToday();
	

if (empty($txtTransDtdbcd))     $txtTransDtdbcd = $Type_dbcd;
if (empty($txtTransDtDesc))     $txtTransDtDesc = $PTransRemark;
if (empty($txtTransDtManualNo)) $txtTransDtManualNo = $PTransManualNo;


$DisableLedger = 0;
$ShowDetail = 0;

if ($PTransDtId != '') {
	$sub_query3 = " Select TransDt.TransDt_id, TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt_Description, TransDt.Currency_Code, ".
			      " Round(Transdt_Amount, ".$DecimalBase."), Round(Transdt_Amount1, ".$DecimalBase."), Round(Transdt_Amount2, ".$DecimalBase."), ".
			      " Date_Format(TransDt_ValueDate,'%d/%m/%Y') As TransDt_ValueDate, TransDt_dbcd, ".
				  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1, 0), ifNull(Transdt_Amount2,0), ".
				  " ClientsDetail.Detail_Code, ClientsDetail.Detail_Name, TransDt.TransDt_ManualNo ".
			      " From Temp_TransDt As TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
				  " Left Join ClientsDetail on TransDt.Detail_Code = ClientsDetail.Detail_Code ".
			      " Where TransDt.Trans_ID = ".$PTransId.
				  " And TransDt.TransDt_ID = '".$PTransDtId."' ";
					      
	//echo $sub_query3;
	$sub_result3 = selectData($connection, $sub_query3);
			
	$txtTransDtId        = $sub_result3[0];
	
	if ($txtLedgerNo == '') {
		$txtLedgerNo     = $sub_result3[1];
		$txtLedgerName   = $sub_result3[2];
	}	
	$txtTransDtDesc      = $sub_result3[3];
	
	$txtClientDtCode   	 = $sub_result3[13];
	$txtClientDtName  	 = $sub_result3[14];
	
			
	if ($SetCurrency != 1) {
		$txtTransDtCurr  	  = $sub_result3[4];
		$txtTransDtAmount_D   = $sub_result3[5];
		$txtTransDtAmountB1_D = $sub_result3[6];
		$txtTransDtAmountB2_D = $sub_result3[7];
		$txtTransDtAmount     = $sub_result3[10];
		$txtTransDtAmountB1   = $sub_result3[11];
		$txtTransDtAmountB2   = $sub_result3[12];
		
	}
			
	$txtTransDtValueDate = $sub_result3[8];
	$txtTransDtdbcd      = $sub_result3[9];
	$txtTransDtManualNo  = $sub_result3[15];
	
	$sub_query1 = " Select Sum(Q1.CountRec) From  ".
               	  " ( Select Count(*) As CountRec ".
				  "   From Temp_ChkJourDt ".
				  "   Where TransDt_id = '".$PTransDtId."' ".
				  "   Union ".
				  "   Select Count(*) As CountRec ".
				  "   From Temp_BillJourDt ".
				  "   Where TransDt_id = '".$PTransDtId."' ".
				  " ) As Q1 ";
	$sub_result1 = selectData($connection, $sub_query1);			  
	if (empty($sub_result1[0])) $sub_result1[0] = 0;
	
	if ($sub_result1[0] > 0) $DisableLedger = 1;
			

}

//Getting Currency Rates
$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$txtTransDtCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$txtTransDtCurr."' )";
$result = selectData($connection, $query);
$Currate1 = $result[0];

$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base1."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base1."' )";
$result = selectData($connection, $query);
$CurrateB1 = $result[0];
		
$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base2."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base2."' )";
$result = selectData($connection, $query);
$CurrateB2 = $result[0];


if ($PTransDtId == '') {

	$sub_query2 = " Select TransDt.Trans_ID, ".
	              " (Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)), ".$DecimalBase1.") - Round(Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), ".$DecimalBase1.") ) As TransDtAmount_D, ".
				  " (Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)), ".$DecimalBase1.") - Round(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)), ".$DecimalBase1.") - Round(Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount2,0), 0)), ".$DecimalBase1.") ) As TransDtAmount2_D, ".
				  " (Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount ,0), 0)), 9) - Round(Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount ,0), 0)), 9) ) As TransDtAmount, ".
				  " (Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount1,0), 0)), 9) - Round(Sum(if(Transdt_dbcd='C', ifNull(Transdt_Amount1,0), 0)), 9) ) As TransDtAmount1, ".
				  " (Round(Sum(if(Transdt_dbcd='D', ifNull(Transdt_Amount2,0), 0)), 9) - Round(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) {
		$txtTransDtAmount   = abs($sub_result2[5]);
		$txtTransDtAmount   = ConvertCurrency($base1, $txtTransDtCurr, insertMySQLDate($PTransDate), $txtTransDtAmount, $connection);
		
		$txtTransDtAmountB1 = abs($sub_result2[5]);
		$txtTransDtAmountB2 = abs($sub_result2[6]);
		
		$txtTransDtAmount_D   = abs($sub_result2[2]);	
		$txtTransDtAmount_D   = ConvertCurrency($base1, $txtTransDtCurr, insertMySQLDate($PTransDate), $txtTransDtAmount_D, $connection);
		$txtTransDtAmount_D   = number_format($txtTransDtAmount_D, $DecimalBase);
		
		$txtTransDtAmountB1_D = number_format(abs($sub_result2[2]), $DecimalBase1);
		$txtTransDtAmountB2_D = number_format(abs($sub_result2[3]), $DecimalBase2);
	}
	else if ($Type_dbcd == 'C' && $sub_result2[2] > 0) {
		$txtTransDtAmount   = abs($sub_result2[5]);
		$txtTransDtAmount   = ConvertCurrency($base1, $txtTransDtCurr, insertMySQLDate($PTransDate), $txtTransDtAmount, $connection);
		
		$txtTransDtAmountB1 = abs($sub_result2[5]);
		$txtTransDtAmountB2 = abs($sub_result2[6]);
				
		$txtTransDtAmount_D   = abs($sub_result2[2]);	
		$txtTransDtAmount_D   = ConvertCurrency($base1, $txtTransDtCurr, insertMySQLDate($PTransDate), $txtTransDtAmount_D, $connection);
		$txtTransDtAmount_D   = number_format($txtTransDtAmount_D, $DecimalBase);
		
		$txtTransDtAmountB1_D = number_format(abs($sub_result2[2]), $DecimalBase1);
		$txtTransDtAmountB2_D = number_format(abs($sub_result2[3]), $DecimalBase2);
	}
	
}

if ($SetCurrency == 1 && $txtTransDtAmount > 0) { 
	$txtTransDtAmountB1 = ConvertCurrency($txtTransDtCurr, $base1, insertMySQLDate($PTransDate), $txtTransDtAmount, $connection);
	$txtTransDtAmountB2 = ConvertCurrency($txtTransDtCurr, $base2, insertMySQLDate($PTransDate), $txtTransDtAmount, $connection);
			
	$txtTransDtAmountB1_D = Round($txtTransDtAmountB1, $DecimalBase1);
	$txtTransDtAmountB2_D = Round($txtTransDtAmountB2, $DecimalBase2);
			
}

 

if ($txtLedgerNo != "" && $PTransType == 'RV'){				
	$query = " SELECT ifNull(Clients.Client_Detail,0) ".
	         " FROM Clients WHERE Clients.Ledger_Number = '".$txtLedgerNo."'";
	$result = selectData($connection, $query);
	$ShowDetail = $result[0];
	
	if (empty($ShowDetail)) $ShowDetail = 0;

}
	
	




$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

	  
echo"   <tr><td valign='top'>";
echo"     <table border='0' style='table-layout:fixed'>
		  <col width=80>
		  <col width=120>
		  <col width=120>
		  <col width=120>
		  <col width=120>";
		  
		   
		  
		  echo"<tr bgcolor='#F7F7F7' height='20'>";
		  echo"  <td align='center' colspan='5'><span class='style16'>$Type_Label</span></td>";
		  echo"</tr>";
		  
		  echo"<tr bgcolor='#F7F7F7' height='20'>";
		  echo"  <td align='center' colspan='5'><span class='style16'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></span></td>";
		  echo"</tr>";
		  
		  
		  echo"<tr bgcolor='#F7F7F7'>";
		  echo"  <td align='left' ><span class='style12'>Ledger No.
		           <input type='hidden' name='txtTransDtId' id='txtTransDtId' value='$txtTransDtId' >
				   <input type='hidden' name='txtTransDtdbcd' id='txtTransDtdbcd' value='$txtTransDtdbcd' >
				   <input type='hidden' name='txtTransDtAmount' id='txtTransDtAmount' value='$txtTransDtAmount' >
				   <input type='hidden' name='txtTransDtAmountB1' id='txtTransDtAmountB1' value='$txtTransDtAmountB1' >
				   <input type='hidden' name='txtTransDtAmountB2' id='txtTransDtAmountB2' value='$txtTransDtAmountB2' >
				   </span></td>";
		  
          if ($DisableLedger == 0) {		  
			  echo"  <td ><span class='style11'><input type='text' name='txtLedgerNo' id='txtLedgerNo' value='".htmlspecialchars($txtLedgerNo, ENT_QUOTES)."' maxlength='10' style='font-size:12px; width:90px; height=20px;' /></span>
						  <label><span class='style11'><img src='img/btnopen.jpg' title=' Select Ledger ' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistLedgers(1); '  /></span></label></td>";
			  echo"  <td colspan='3'><span class='style11'><input type='text' name='txtLedgerName' id='txtLedgerName' value='".htmlspecialchars($txtLedgerName, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:300px; height=20px;' /></span></td>";
		  } else {
			  echo"  <td ><input type='hidden' name='txtLedgerNo' id='txtLedgerNo' value='".htmlspecialchars($txtLedgerNo, ENT_QUOTES)."'  /><span class='style13'>$txtLedgerNo</span></td>";
			  echo"  <td colspan='3'><input type='hidden' name='txtLedgerName' id='txtLedgerName' value='".htmlspecialchars($txtLedgerName, ENT_QUOTES)."'  /><span class='style13'>$txtLedgerName</span></td>";
		  }
		  
		  echo"</tr>";
		  
		if ($txtLedgerNo != "" && $Module_ShowBalance == 1) {
			$querybalance  = "SELECT IFNULL(SUM(if(journaldt_dbcd = 'D', journaldt_amount1, (-1)*journaldt_amount1)), 0) As Balance FROM journaldt where ledger_number = '".$txtLedgerNo."' and date_format(journaldt.journal_date,'%Y%m%d') <= date_format('".insertMySQLDate($PTransDate)."','%Y%m%d')";
			$resultbalance = selectData($connection, $querybalance);
			$CurrBalance   = $resultbalance[0];
	
			echo"<tr bgcolor='#F7F7F7' height='25px;'>";
			echo"  <td align='left' ><span class='style12'>Balance</td>";
			echo"  <td colspan='4'><span class='style13'>".number_format($CurrBalance, $DecimalBase1)." ".$base1."</span></td>";
			echo"</tr>";
		}
		  
		  //Tarek 20111007
		if($ShowDetail == 1) {
			echo"<tr bgcolor='#F7F7F7' >
					<td align='left' ><span class='style12'>Detail</span></td>";
			echo"   <td><span class='style11'>";
			echo"      <input type='text'   name='txtClientDtCode' id='txtClientDtCode' value='$txtClientDtCode' style='font-size:12px; width:90px; height=20px;' maxlength='50'  />
					   <label><img src='img/btnopen.jpg' title=' Select Client Detail ' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistClientDetail(1); ' /></label></span>
					</td>
					<td colspan='3'><span class='style11'>
					   <input type='text'   name='txtClientDtName' id='txtClientDtName' value='$txtClientDtName' style='font-size:12px; width:300px; height=20px;'  />
					  </span>
					</td>";
			echo"</tr>";

		} else {
			echo"<input type='hidden'   name='txtClientDtCode' id='txtClientDtCode' value='$txtClientDtCode'  />
				 <input type='hidden'   name='txtClientDtName' id='txtClientDtName' value='$txtClientDtName' />";
		}
		  
		  echo"<tr bgcolor='#F7F7F7'>";
		  echo"  <td align='left' ><span class='style12'>Description</span></td>";
		  echo"  <td colspan='4'><span class='style11'><input type='text' name='txtTransDtDesc' id='txtTransDtDesc' value='".htmlspecialchars($txtTransDtDesc, ENT_QUOTES)."' maxlength='150' style='font-size:12px; width:422px; height=20px;' /></span></td>";
		  echo"</tr>";
		  
		  echo"<tr bgcolor='#F7F7F7'>";
		  echo"  <td align='left' ><span class='style12'>Value Date</span></td>";
		  echo"  <td colspan='4'><span class='style11'><input type='text' name='txtTransDtValueDate' value='$txtTransDtValueDate'  maxlength='10' style='font-size:12px; width:80px; height=18px;' ></span>
		                   <A HREF='#' onClick=\"displayCalendar(document.transdt.txtTransDtValueDate,'dd/mm/yyyy',this);  return false; \" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></A></td>";
		  echo"</tr>";
		  
		  if ($Module_TransStandardView == 1) {
		  
			  echo"<tr bgcolor='#F7F7F7'>";
			  echo"  <td align='left' ><span class='style12'>Manual No</span></td>";
			  echo"  <td colspan='4' align='left'><span class='style11'><input type='text' name='txtTransDtManualNo' value='$txtTransDtManualNo' style='text-align:left; font-size:12px; width:80px; height=18px;' maxlength='45' >
					 <label><img src='img/btnopen.jpg' title='Select Manual No' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(1); '  /></label></td>";
			  echo"</tr>";		 
			  
			  echo"<tr height='20'>";
			  echo"  <td bgcolor='#F7F7F7' align='center'><span class='style12'>Manual No</span></td>";
			  echo"  <td bgcolor='#F7F7F7' align='center'><span class='style12'>Currency</span></td>";
			  echo"  <td bgcolor='#F7F7F7' align='center'><span class='style12'>Amount</span></td>";
			  echo"  <td bgcolor='#F7F7F7' align='center'><span class='style12'>Amount $base1</span></td>";
			  echo"  <td bgcolor='#F7F7F7' align='center'><span class='style12'>Amount $base2</span></td>";
			  echo"</tr>";
			  
			  echo"<tr bgcolor='#F7F7F7'>";
			  echo"  <td align='center'>&nbsp;</td>";
			  
			  if ($DisableLedger == 0) {
				  echo"  <td align='center'><span class='style11'><select name='txtTransDtCurr' id='txtTransDtCurr' style='font-size:11px; width:55px; height=18px;' onChange='ChangeCurrency();' >";
					echo"<option></option>";
					while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
						if ($txtTransDtCurr==$curf[0])
							echo " selected ";
						echo" value='$curf[0]'>$curf[0] </option>";
					}
					echo"</select></span></td>";	
			  } else
				  echo"  <td align='center'><input type='hidden' name='txtTransDtCurr' id='txtTransDtCurr' value='$txtTransDtCurr'><span class='style13'>$txtTransDtCurr</span></td>";	
				  
				  
			  echo"  <td align='center'><span class='style11'><input type='text' name='txtTransDtAmount_D' value='$txtTransDtAmount_D' style='text-align:right; font-size:12px; width:100px; height=18px;'     onBlur='CheckAmount(1);' onChange=\"SetAmount(1,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$txtTransDtCurr."','".$base1."','".$base2."');\"></td>";	 
			  echo"  <td align='center'><span class='style11'><input type='text' name='txtTransDtAmountB1_D' value='$txtTransDtAmountB1_D' style='text-align:right; font-size:12px; width:100px; height=18px;' onBlur='CheckAmount(2);' onChange=\"SetAmount(2,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$txtTransDtCurr."','".$base1."','".$base2."');\"></td>";	
			  echo"  <td align='center'><span class='style11'><input type='text' name='txtTransDtAmountB2_D' value='$txtTransDtAmountB2_D' style='text-align:right; font-size:12px; width:100px; height=18px;' onBlur='CheckAmount(3);' onChange=\"SetAmount(3,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$txtTransDtCurr."','".$base1."','".$base2."');\"></td>";	
			  
			  echo"</tr>";
		  
		  }  else {
			  echo"<tr bgcolor='#F7F7F7' height='20'>";
			  echo"  <td align='left' ><span class='style12'>Currency</span></td>";
			  echo"  <td colspan='4'>";
			  
			  if ($DisableLedger == 0) {
				  echo"  <span class='style11'><select name='txtTransDtCurr' id='txtTransDtCurr' style='font-size:11px; width:70px; height=18px;' onChange='ChangeCurrency();' >";
					echo"<option></option>";
					while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
						if ($txtTransDtCurr==$curf[0])
							echo " selected ";
						echo" value='$curf[0]'>$curf[0] </option>";
					}
					echo"</select></span>";	
			  } else
				  echo"  <input type='hidden' name='txtTransDtCurr' id='txtTransDtCurr' value='$txtTransDtCurr'><span class='style13'>$txtTransDtCurr</span>";	
				  

			  echo"	 </td>";
			  echo"</tr>";
			  
			  echo"<tr bgcolor='#F7F7F7' height='20'>";
			  echo"  <td align='left' ><span class='style12'>Amount</span></td>";
			  echo"  <td colspan='4'><span class='style11'><input type='text' name='txtTransDtAmount_D' value='$txtTransDtAmount_D' style='text-align:right; font-size:12px; width:100px; height=18px;'     onBlur='CheckAmount(1);' onChange=\"SetAmount(1,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$txtTransDtCurr."','".$base1."','".$base2."');\">";	 
			  echo"  <input type='hidden' name='txtTransDtAmountB1_D' value='$txtTransDtAmountB1_D' ><input type='hidden' name='txtTransDtAmountB2_D' value='$txtTransDtAmountB2_D' ></td>";	
			  echo"</tr>";
			  
			  echo"<tr bgcolor='#F7F7F7' height='22'>";
			  echo"  <td align='left' ><span class='style12'>Manual No</span></td>";
			  echo"  <td colspan='4'><span class='style11'><input type='text' name='txtTransDtManualNo' value='$txtTransDtManualNo' style='text-align:left; font-size:12px; width:100px; height=18px;' maxlength='45' >
						<label><img src='img/btnopen.jpg' title='Select Manual No' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistManualNo(1); '  /></label></td>";
			  echo"</tr>";
		  }
		  
		  echo"<tr bgcolor='#F7F7F7' height='25'>
				<td colspan='5' align='center' bgcolor=#D8D8D8>
					<input type='button' name='btnSubmit' id='btnSubmit' value='Submit' onclick=\"SubmitRecord($ShowDetail);\" $style	style='width:55px;' title='Submit Record' />
		         	<input type='button' id='btnClear' name='btnClear'  value='Clear'  onclick='ClearRecord();' $style title='Clear Record'></td>
		      </tr>";
		  
	 
		 
				 
		
		echo "</table>"; 

	

print <<<HERE
</form>
</body>

HERE;


?>