<?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 Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostcenterDt,0) As Module_CostCenterDt, ".
             " ifNull(Module_TransStandardView,0) As Module_TransStandardView From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


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(ModuleProjectDt,ModuleCostcenterDt) {
	x = document.cstjourdt;
	
	var result = CheckFields(ModuleProjectDt,ModuleCostcenterDt);
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vCstJourDtId  = x.txtCstJourDtId.value;
	
	var vMainMode = x.mainaction.value;
	var vMode = x.actionmode.value;
	
	if (vCstJourDtId == '')
		vMode = 'insertcstjour';	
	else
		vMode = 'editcstjour';	
	   
	if (result == 1) {
		x.action="Form_Trans_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SCstJourDtId="+vCstJourDtId;
		x.submit();
		
	}	
}


function DeleteRecord(CstJourDtId) {
	x = document.cstjourdt;
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vMainMode   = x.mainaction.value;
	var vDelMsg = 'Are you sure you want to Delete Record.';
	
	   
	if (confirm ( vDelMsg ))
	{
		x.action="Form_Trans_Actions.php?mode=deletecstjour&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SCstJourDtId="+CstJourDtId;
		x.submit();
	}

}

function UpdateRecord(CstJourDtId) {
    x = document.cstjourdt; 
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vMainMode = x.mainaction.value;
	
	x.txtCstJourDtId.value = CstJourDtId;
	
	
	x.submit();

}

function CheckFields(ModuleProjectDt,ModuleCostcenterDt){
  
    x = document.cstjourdt;
	
	var vProjectDt     = x.txtProjectCodeDt.value;
	var vCostCenterDt  = x.txtCostCentCodeDt.value;
	var vCstJourDtPer  = x.txtCstJourDtPer.value;
	var vCstJourDtAmt  = x.txtCstJourDtAmt_D.value;
	var vCstJourDtAmt1 = x.txtCstJourDtAmt1_D.value;
	var vCstJourDtAmt2 = x.txtCstJourDtAmt2_D.value;
	var vCstJourDtBalAmt  = x.txtCstJourDtBalAmt.value;
	
	
	
	if (vCstJourDtPer == '') vCstJourDtPer = 0;
	if (vCstJourDtAmt == '') vCstJourDtAmt = 0;
	if (vCstJourDtAmt1 == '') vCstJourDtAmt1 = 0;
	if (vCstJourDtAmt2 == '') vCstJourDtAmt2 = 0;
	if (vCstJourDtBalAmt == '') vCstJourDtBalAmt = 0;
	
	vCstJourDtPer  = parseInt(vCstJourDtPer);
	vCstJourDtAmt  = parseFloat(vCstJourDtAmt);
	vCstJourDtAmt1 = parseFloat(vCstJourDtAmt1);
	vCstJourDtAmt2 = parseFloat(vCstJourDtAmt2);
	vCstJourDtBalAmt = parseFloat(vCstJourDtBalAmt);	
	
	if (vProjectDt=='' && ModuleProjectDt==1)
	{
		alert("Project is mandatory!");
		x.txtProjectCodeDt.focus();
		return 0;
	}
	else if (vCostCenterDt=='' && ModuleCostcenterDt==1)
	{
		alert("CostCenter is mandatory!");
		x.txtCostCentCodeDt.focus();
		return 0;
	}
	else if ( vCstJourDtPer*1 != vCstJourDtPer/1 || vCstJourDtPer <= 0 || vCstJourDtPer > 100 ) {
		alert('Percentage ('+vCstJourDtPer+') should be a NUMERIC and BETWEEN 1 and 100 . ');
		x.txtCstJourDtPer.focus();
		return 0;
	}
	else if ((vCstJourDtAmt*1 != vCstJourDtAmt/1 || vCstJourDtAmt < 0) ) {
		alert('Amount should be a NUMERIC and POSITIVE value.');
		x.txtCstJourDtAmt_D.focus();
		return 0;
	}
	else if ((vCstJourDtAmt1*1 != vCstJourDtAmt1/1 || vCstJourDtAmt1 < 0) ) {
		alert('Amount1 should be a NUMERIC and POSITIVE value.');
		x.txtCstJourDtAmt1_D.focus();
		return 0;
	}
	else if ((vCstJourDtAmt2*1 != vCstJourDtAmt2/1 || vCstJourDtAmt2 < 0) ) {
		alert('Amount2 should be a NUMERIC and POSITIVE value.');
		x.txtCstJourDtAmt2_D.focus();
		return 0;
	}
	else if (vCstJourDtAmt > vCstJourDtBalAmt) {
		alert('Amount must be less than or equal to Balance: '+vCstJourDtBalAmt);
		x.txtCstJourDtAmt_D.focus();
		return 0;
	}
	else if (vCstJourDtAmt==0 && vCstJourDtAmt1==0 && vCstJourDtAmt2==0) {
		alert('Amount/Amount1/Amoun2 must be Greater than Zero.');
		x.txtCstJourDtAmt_D.focus();
		return 0;
	}
			
	else
	return 1 ;	
}

function ClearRecord() {

	x = document.cstjourdt;

	x.txtCstJourDtId.value='';
	x.txtProjectCodeDt.value='';
	x.txtCostCentCodeDt.value='';
	x.txtCstJourDtPer.value='';
	x.txtCstJourDtAmt.value='';
	x.txtCstJourDtAmt1.value='';
	x.txtCstJourDtAmt2.value='';
	x.txtCstJourDtAmt_D.value='';
	x.txtCstJourDtAmt1_D.value='';
	x.txtCstJourDtAmt2_D.value='';

	x.submit();
}


function CheckAmount(option) {
	x=document.cstjourdt;
	var vAmount, vAmount1, vAmount1, vAmountBal, vAmountBal1, vAmountBal2;
	
	vAmount  = x.txtCstJourDtAmt_D.value;
	vAmount1 = x.txtCstJourDtAmt1_D.value;
	vAmount2 = x.txtCstJourDtAmt2_D.value;
	vAmountBal = x.txtCstJourDtBalAmt.value;
	vAmountBal1 = x.txtCstJourDtBalAmt1.value;
	vAmountBal2 = x.txtCstJourDtBalAmt2.value;
	
	
	if (vAmount == '')  vAmount  = 0;
	if (vAmount1 == '') vAmount1 = 0;
	if (vAmount2 == '') vAmount2 = 0;
	if (vAmountBal == '') vAmountBal = 0;
	if (vAmountBal1 == '') vAmountBal1 = 0;
	if (vAmountBal2 == '') vAmountBal2 = 0;
	
	
	if ((vAmount*1 != vAmount/1 || vAmount < 0  ) && option == 1 ) {
		alert('Amount should be a Numeric and Positive value.');
		x.txtCstJourDtAmt_D.focus();
		return (false);
	}
	else if ((vAmount1*1 != vAmount1/1 || vAmount1 < 0 ) && option == 2 ) {
		alert('Amount1 should be a Numeric and Positive value.');
		x.txtCstJourDtAmt1_D.focus();
		return (false);
	}
	else if ((vAmount2*1 != vAmount2/1 || vAmount2 < 0 ) && option == 3) {
		alert('Amount2 should be a Numeric and Positive value.');
		x.txtCstJourDtAmt2_D.focus();
		return (false);
	}
	
}


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

	x=document.cstjourdt;
	var vPer, vAmount, vAmount1, vAmount2, vAmountTot, vAmountTot1, vAmountTot2;
	
	dec1  = parseInt(dec1);
	dec2  = parseInt(dec2);
	rate  = parseFloat(rate);
	rate1 = parseFloat(rate1);
	rate2 = parseFloat(rate2);
	
	vAmountTot = x.txtCstJourDtTotAmt.value;
	if (vAmountTot == '') vAmountTot = 0;
	vAmountTot=parseFloat(vAmountTot);
	
	vAmountTot1 = x.txtCstJourDtTotAmt1.value;
	if (vAmountTot1 == '') vAmountTot1 = 0;
	vAmountTot1=parseFloat(vAmountTot1);
	
	vAmountTot2 = x.txtCstJourDtTotAmt2.value;
	if (vAmountTot2 == '') vAmountTot2 = 0;
	vAmountTot2=parseFloat(vAmountTot2);
	
	if (option == 1) {
		
		vAmount = x.txtCstJourDtAmt_D.value;
		if (vAmount == '') vAmount = 0;
	
		vAmount=parseFloat(vAmount);
		
		x.txtCstJourDtAmt.value= vAmount;
		
		if (vAmount > 0) { 
			vAmount1=Math.round(((vAmount*rate)/rate1)*Math.pow(10,dec1))/Math.pow(10,dec1);
			vAmount1=parseFloat(vAmount1);
			x.txtCstJourDtAmt1_D.value= vAmount1;
			x.txtCstJourDtAmt1.value= parseFloat((vAmount*rate)/rate1);
				
			vAmount2=Math.round(((vAmount*rate)/rate2)*Math.pow(10,dec2))/Math.pow(10,dec2);
			vAmount2=parseFloat(vAmount2);
			x.txtCstJourDtAmt2_D.value=vAmount2;
			x.txtCstJourDtAmt2.value= parseFloat((vAmount*rate)/rate2);
			
			vPer = Math.round(((vAmount/vAmountTot)*100)*Math.pow(10,dec1))/Math.pow(10,dec1);
			vPer=parseInt(vPer);
			x.txtCstJourDtPer.value = vPer;
			
			
		}	
	}	
	else if (option == 2) {
		vAmount1 = x.txtCstJourDtAmt1_D.value;
		if (vAmount1 == '') vAmount1 = 0;
		
		vAmount1=parseFloat(vAmount1);
		
		if (curr == currbase1 && vAmount1 > 0) {
			x.txtCstJourDtAmt_D.value= vAmount1;
			x.txtCstJourDtAmt.value= vAmount1;
		}	
			
		vPer = Math.round(((vAmount1/vAmountTot1)*100)*Math.pow(10,dec1))/Math.pow(10,dec1);
		vPer=parseInt(vPer);
		x.txtCstJourDtPer.value = vPer;	
	
	}
	else if (option == 3) {
		vAmount2 = x.txtCstJourDtAmt2_D.value;
		if (vAmount2 == '') vAmount2 = 0;
		
		vAmount2=parseFloat(vAmount2);
		
		if (curr == currbase2 && vAmount2 > 0) {
			x.txtCstJourDtAmt_D.value= vAmount2;
			x.txtCstJourDtAmt.value= vAmount2;
		}	
			
		vPer = Math.round(((vAmount2/vAmountTot2)*100)*Math.pow(10,dec1))/Math.pow(10,dec1);
		vPer=parseInt(vPer);
		x.txtCstJourDtPer.value = vPer;		
	
	}
	
		
	
}

function SetPercentage(dec1, dec2) {
	x=document.cstjourdt;
	var vPer, vAmount, vAmount1, vAmount2, vAmountTot, vAmountTot1, vAmountTot2;
	
	vAmountTot = x.txtCstJourDtTotAmt.value;
	if (vAmountTot == '') vAmountTot = 0;
	vAmountTot=parseFloat(vAmountTot);
	
	vAmountTot1 = x.txtCstJourDtTotAmt1.value;
	if (vAmountTot1 == '') vAmountTot1 = 0;
	vAmountTot1=parseFloat(vAmountTot1);
	
	vAmountTot2 = x.txtCstJourDtTotAmt2.value;
	if (vAmountTot2 == '') vAmountTot2 = 0;
	vAmountTot2=parseFloat(vAmountTot2);
	
	vPer = x.txtCstJourDtPer.value;
	if (vPer == '') vPer = 0;
	vPer=parseInt(vPer);
	
	
	if (vAmountTot > 0) { 
		vAmount=Math.round(((vAmountTot*vPer)/100)*Math.pow(10,dec1))/Math.pow(10,dec1);
		vAmount=parseFloat(vAmount);
		x.txtCstJourDtAmt_D.value= vAmount;
		x.txtCstJourDtAmt.value= parseFloat((vAmountTot*vPer)/100);
		
		vAmount1=Math.round(((vAmountTot1*vPer)/100)*Math.pow(10,dec1))/Math.pow(10,dec1);
		vAmount1=parseFloat(vAmount1);
		x.txtCstJourDtAmt1_D.value= vAmount1;
		x.txtCstJourDtAmt1.value= parseFloat((vAmountTot1*vPer)/100);
				
		vAmount2=Math.round(((vAmountTot2*vPer)/100)*Math.pow(10,dec2))/Math.pow(10,dec2);
		vAmount2=parseFloat(vAmount2);
		x.txtCstJourDtAmt2_D.value=vAmount2;
		x.txtCstJourDtAmt2.value= parseFloat((vAmountTot2*vPer)/100);
	}
}

function CheckPercentage() {
	x=document.cstjourdt;
	var vPer, vPerBal;
	
	vPer = x.txtCstJourDtPer.value;
	if (vPer == '') vPer = 0;
	vPer=parseInt(vPer);
	
	vPerBal = x.txtCstJourDtBalPer.value;
	if (vPerBal == '') vPerBal = 0;
	vPerBal=parseInt(vPerBal);
	
	
	if (vPer > vPerBal) {
		alert('Percentage must be less than or equal to '+vPerBal);
		x.txtCstJourDtPer.focus();
		return (false);
	}
}

function showlistProject(str){

  window.open('List_SorProject.php?frm=5&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=5&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


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

}

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

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Projects / Costcenters</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: 10px;
	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>
<form name='cstjourdt' method='post'>
<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='PTransDtId' value='$PTransDtId'>
<input type='hidden' name='PTransDtCurr' value='$PTransDtCurr'>

HERE;

if ($Module_Project == 1 || $Module_ProjectDt == 1)
	$ModuleProject = 1;
if ($Module_CostCenter == 1 || $Module_CostCenterDt == 1)
	$ModuleCostCenter = 1;
	
//Select Data From TransDt For Selected Record
$sub_query = " Select TransDt.Ledger_Number, Ledger.Ledger_Name, TransDt.Currency_Code, ".
			 " if(TransDt_dbcd='C', 'Credit Accounts', 'Debit Accounts') As TypeLabel ".
			 " From Temp_TransDt As TransDt Left 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];
$TransDtCurr  = $sub_result[2];
$Type_Label   = $sub_result[3]; 

//Select Data From Trans For Selected Record
$sub_query = " Select Trans.Project_Code, Trans.Costcent_code ".
			 " From Temp_Trans As Trans ".
	         " Where Trans.Trans_ID = '".$PTransId."' ";
//echo $sub_query;
$sub_result = selectData($connection, $sub_query);

$txtProjectCodeDt  = $sub_result[0];
$txtCostCentCodeDt = $sub_result[1];
	

if ($txtCstJourDtId != '') {
	$sub_query1 = " Select CstJourDt_id, Project_code, Costcenter_Code, CstjourDt_Per, Round(CstJourDt_Amount, ".$DecimalBase."), ".
				 " Round(CstJourDt_Amount1, ".$DecimalBase1."), Round(CstJourDt_Amount2, ".$DecimalBase2."), ".
				 " ifNull(CstJourDt_Amount,0), ifNull(CstJourDt_Amount1,0), ifNull(CstJourDt_Amount2,0) ".
				 " From Temp_CstjourDt As CstjourDt ".
				 " Where CstjourDt.CstJourDt_id = '".$txtCstJourDtId."' ";
					      
	//echo $sub_query1;
	$sub_result1 = selectData($connection, $sub_query1);
			
	$txtProjectCodeDt    = $sub_result1[1];
	$txtCostCentCodeDt   = $sub_result1[2];
	$txtCstJourDtPer     = $sub_result1[3];
	$txtCstJourDtAmt_D   = $sub_result1[4];
	$txtCstJourDtAmt1_D  = $sub_result1[5];
	$txtCstJourDtAmt2_D  = $sub_result1[6];
	$txtCstJourDtAmt     = $sub_result1[7];
	$txtCstJourDtAmt1    = $sub_result1[8];
	$txtCstJourDtAmt2    = $sub_result1[9];
	
	
	$sub_query2 = " Select TransDt.TransDt_ID, (100 - Sum(ifNull(CstjourDt_Per,0))) 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 Left Join Temp_CstjourDt on TransDt.TransDt_ID = Temp_CstjourDt.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);
	
	$txtCstJourDtBalPer   = $sub_result2[1];
	$txtCstJourDtBalAmt   = $sub_result2[2];
	$txtCstJourDtBalAmt1  = $sub_result2[3];
	$txtCstJourDtBalAmt2  = $sub_result2[4];
	
	$txtCstJourDtTotPer   = 100;
	$txtCstJourDtTotAmt   = $sub_result2[5];
	$txtCstJourDtTotAmt1  = $sub_result2[6];
	$txtCstJourDtTotAmt2  = $sub_result2[7];
	
	$txtCstJourDtBalPer   = $txtCstJourDtBalPer  + $sub_result1[3];	
	$txtCstJourDtBalAmt   = $txtCstJourDtBalAmt  + $sub_result1[7];
	$txtCstJourDtBalAmt1  = $txtCstJourDtBalAmt1 + $sub_result1[8];
	$txtCstJourDtBalAmt2  = $txtCstJourDtBalAmt2 + $sub_result1[9];
}

if ($txtCstJourDtId == '') {

	$sub_query2 = " Select TransDt.TransDt_ID, (100 - Sum(ifNull(CstjourDt_Per,0))) As CstjourDtPer, ".
	              " (Round(ifNull(Transdt_Amount,0), ".$DecimalBase1.") - Round(Sum(ifNull(CstJourDt_Amount,0)), ".$DecimalBase1.") ) As CstJourDtAmount_D, ".
				  " (Round(ifNull(Transdt_Amount1,0), ".$DecimalBase1.") - Round(Sum(ifNull(CstJourDt_Amount1,0)), ".$DecimalBase1.") ) As CstJourDtAmount1_D, ".
				  " (Round(ifNull(Transdt_Amount2,0), ".$DecimalBase1.") - Round(Sum(ifNull(CstJourDt_Amount2,0)), ".$DecimalBase1.") ) As CstJourDtAmount2_D, ".
				  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0), ".
				  " TransDt.Ledger_Number, ".
				  " (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 Left Join Temp_CstjourDt on TransDt.TransDt_ID = Temp_CstjourDt.TransDt_ID ".
				  " Where TransDt.TransDt_ID = '".$PTransDtId."' ".
				  " Group By TransDt.TransDt_ID, TransDt.Ledger_Number, Transdt_Amount, Transdt_Amount1, Transdt_Amount2 ";
				  
					      
	//echo $sub_query2;
	$sub_result2 = selectData($connection, $sub_query2);
	
	$txtCstJourDtBalPer   = $sub_result2[1];
	$txtCstJourDtBalAmt   = $sub_result2[9];
	$txtCstJourDtBalAmt1  = $sub_result2[10];
	$txtCstJourDtBalAmt2  = $sub_result2[11];
	
	$txtCstJourDtTotPer   = 100;
	$txtCstJourDtTotAmt   = $sub_result2[5];
	$txtCstJourDtTotAmt1  = $sub_result2[6];
	$txtCstJourDtTotAmt2  = $sub_result2[7];
	
	$txtCstJourDtPer     = $sub_result2[1];
	$txtCstJourDtAmt_D   = $sub_result2[2];
	$txtCstJourDtAmt1_D  = $sub_result2[3];
	$txtCstJourDtAmt2_D  = $sub_result2[4];
	
	$txtCstJourDtAmt   = $sub_result2[9];
	$txtCstJourDtAmt1  = $sub_result2[10];
	$txtCstJourDtAmt2  = $sub_result2[11];
	
	
	//Get Default Project and Default Coscenter
	if ($LedgerValidateProject == 1) {
		$queryledger = " select project_code as defaultproject, costcenter_code as defaultcostcent from ledger where ledger.ledger_number = '".$sub_result2[8]."' ";
		while($rows=mysql_fetch_array($queryledger)){
			extract($rows);
		}
		
	}
	
	if (empty($defaultproject)) {
		$querydflproject="select project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_project=1 ";
		$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($resultdflproject)){
			extract($rows);
		}
		
	}
	
	if (empty($defaultcostcent)) {
		$querydflcostcent="select costcent_code as defaultcostcent from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_costcenter=1 ";
		$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
		while($rows=mysql_fetch_array($resultdflcostcent)){
			extract($rows);
		}
	
	}


	if ((empty($txtProjectCodeDt)) && $ModuleProject == 1)
		$txtProjectCodeDt = $defaultproject;
	if ((empty($txtCostCentCodeDt)) && $ModuleCostCenter == 1)
		$txtCostCentCodeDt = $defaultcostcent;	

}


//Getting Currency Rates
$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$PTransDtCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$PTransDtCurr."' )";
$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];


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

	  
echo"   <tr><td valign='top'>
        <table border='0' style='table-layout:fixed' align='center' valign='top' >
          <col width=25>
		  <col width=25>
		  <col width=150>
		  <col width=150>
		  <col width=70>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  
		   <tr bgcolor='#F7F7F7' height='20'>
		     <td align='center' colspan='8'><span class='style16'>$Type_Label</span></td>
		   </tr>
		  
		   <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='8' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>

		   <tr bgcolor='#F7F7F7' >
		     <td align='left' colspan='2'><span class='style12'>Ledger</span></td>
			 <td align='left' colspan='2'><span class='style13'>$LedgerNumber &nbsp; $LedgerName</span></td>
			 <td align='right'><span class='style12'>Currency</span></td>
			 <td align='center'><span class='style13'>$TransDtCurr</span></td>
			 <td align='center' colspan='2'><span class='style13'>&nbsp;</span></td>
		   </tr>
			 
		   <tr bgcolor='#F7F7F7' height='20'>
			 <td valign='center' align='center' colspan='2'><span class='style12'>&nbsp;</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Project</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Costcenter</span></td>
			 <td valign='center' align='center' ><span class='style12'>Percentage</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Amount</span></td>";

		if ($Module_TransStandardView == 1) {	 
			echo" <td valign='center' align='center' ><span class='style12'>Amount $base1</span></td>
				  <td valign='center' align='center' ><span class='style12'>Amount $base2</span></td> ";
		} else 
			echo" <td valign='center' colspan='2' >&nbsp;</td>";
			
echo" 	   </tr>
		   <tr bgcolor='#F7F7F7' >";
		  
		
		    echo"<td align='center' colspan='2'>&nbsp;<input type='hidden' name='txtCstJourDtId' value='$txtCstJourDtId' >
					<input type='hidden' name='txtCstJourDtBalPer' value='$txtCstJourDtBalPer' >
					<input type='hidden' name='txtCstJourDtAmt' value='$txtCstJourDtAmt' >
					<input type='hidden' name='txtCstJourDtAmt1' value='$txtCstJourDtAmt1' >
					<input type='hidden' name='txtCstJourDtAmt2' value='$txtCstJourDtAmt2' >
					<input type='hidden' name='txtCstJourDtBalAmt' value='$txtCstJourDtBalAmt' >
					<input type='hidden' name='txtCstJourDtBalAmt1' value='$txtCstJourDtBalAmt1' >
					<input type='hidden' name='txtCstJourDtBalAmt2' value='$txtCstJourDtBalAmt2' >
					<input type='hidden' name='txtCstJourDtTotPer' value='$txtCstJourDtTotPer' >
					<input type='hidden' name='txtCstJourDtTotAmt' value='$txtCstJourDtTotAmt' >
					<input type='hidden' name='txtCstJourDtTotAmt1' value='$txtCstJourDtTotAmt1' >
					<input type='hidden' name='txtCstJourDtTotAmt2' value='$txtCstJourDtTotAmt2' ></td>";
				 
			if ($ModuleProject == 1) {
				echo "<td align='left' valign='center'><input type='text' name='txtProjectCodeDt' id='txtProjectCodeDt' value='$txtProjectCodeDt' maxlength='15' style='font-size:12px; width:120px; height:18px;' readonly />
						<img src='img/btnopen.jpg' title=' Select Project ' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></td>";
			} else	{
				echo "<td align='left'><input type='hidden' name='txtProjectCodeDt' id='txtProjectCodeDt' value='$txtProjectCodeDt' /></td>";
			}		

			if ($ModuleCostCenter == 1) {		  
				echo" <td align='left' ><input type='text' name='txtCostCentCodeDt' id='txtCostCentCodeDt' value='$txtCostCentCodeDt' maxlength='15' style='font-size:12px; width:120px; height:18px;' readonly />
						<label><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></label></td>";
			} else {
				echo "<td align='left'><input type='hidden' name='txtCostCentCodeDt' id='txtCostCentCodeDt' value='$txtCostCentCodeDt' /></td>";
			}
				 
				echo "<td align='center'><input type='text' name='txtCstJourDtPer' value='$txtCstJourDtPer' maxlength='3' style='font-size:12px; width:60px; height:18px;' onBlur='CheckPercentage();' onChange='SetPercentage($DecimalBase1,$DecimalBase2);'></td>";
				 
			
			if ($Module_TransStandardView == 1) {	
				echo"<td align='center'><input type='text' name='txtCstJourDtAmt_D' value='$txtCstJourDtAmt_D' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:18px;' onBlur='CheckAmount(1);' onChange=\"SetAmount(1,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$PTransDtCurr."','".$base1."','".$base2."');\"></td>
					 <td align='center'><input type='text' name='txtCstJourDtAmt1_D' value='$txtCstJourDtAmt1_D' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:18px;' onBlur='CheckAmount(2);' onChange=\"SetAmount(2,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$PTransDtCurr."','".$base1."','".$base2."');\"></td>
					 <td align='center'><input type='text' name='txtCstJourDtAmt2_D' value='$txtCstJourDtAmt2_D' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:18px;' onBlur='CheckAmount(3);' onChange=\"SetAmount(3,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$PTransDtCurr."','".$base1."','".$base2."');\"></td>";
			} else {
				echo"<td align='center'><input type='text' name='txtCstJourDtAmt_D' value='$txtCstJourDtAmt_D' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:18px;' onBlur='CheckAmount(1);' onChange=\"SetAmount(1,$Currate1,$CurrateB1,$CurrateB2,$DecimalBase1,$DecimalBase2,'".$PTransDtCurr."','".$base1."','".$base2."');\"></td>
					 <td align='center' colspan='2'><input type='hidden' name='txtCstJourDtAmt1_D' value='$txtCstJourDtAmt1_D' ><input type='hidden' name='txtCstJourDtAmt2_D' value='$txtCstJourDtAmt2_D' ></td>";	
			}	
				 
		
echo"       
		  </tr>
		  <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='8' align='center' bgcolor=#D8D8D8>
			    <input type='button' id='btnSubmitRecord' name='btnSubmitRecord'  value='Submit'  onclick='SubmitRecord($ModuleProject,$ModuleCostCenter)' $style title='Submit Record'>
				<input type='button' id='btnClear' name='btnClear'  value='Clear'  onclick='ClearRecord()' $style title='Clear Record'></td>
			 
		  </tr>";
		  
		 if ($PTransDtId != '') {
		     
			 
			$sub_query3 = " Select CstJourDt_id, Project_code, Costcenter_Code, CstjourDt_Per, Round(CstJourDt_Amount, ".$DecimalBase."), ".
					      " Round(CstJourDt_Amount1, ".$DecimalBase1."), Round(CstJourDt_Amount2, ".$DecimalBase2.") ".
					      " From Temp_CstjourDt As CstjourDt ".
					      " Where CstjourDt.TransDt_id = '".$PTransDtId."' ".
					      " Order By CstJourDt_id Desc ";
			//echo $sub_query3;
			$sub_result3=mysql_query($sub_query3,$connection) or die(mysql_error());
			while($sub_rows3=mysql_fetch_array($sub_result3)){
			    
				$ct+=1;

				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
						
				
				echo "<tr ".$Color." >";
				
				echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateRecord('".$sub_rows3[0]."') title='Edit Record'  ></span></td>";
				echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteRecord('".$sub_rows3[0]."') title='Delete Record'  ></span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows3[1]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows3[2]."</span></td>";
				echo "	<td align='left'><span class='style15'>".$sub_rows3[3]."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[4], $DecimalBase)."</span></td>";
				
				if ($Module_TransStandardView == 1) {	
					echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[5], $DecimalBase1)."</span></td>";
					echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[6], $DecimalBase2)."</span></td>";	
				} else
					echo "	<td align='right' colspan='2;><span class='style15'>&nbsp;</span></td>";	
				
				echo "</tr>";
								
			}
			
		 }  

echo" </table>";

	

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

HERE;


?>