<?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 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_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() {
	x = document.billjourdt;
	
	var result = CheckFields();
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vBillJourDtId  = x.txtBillJourDtId.value;
	
	var vMainMode = x.mainaction.value;
	var vMode = x.actionmode.value;
	
	if (vBillJourDtId == '')
		vMode = 'insertbilljour';	
	else
		vMode = 'editbilljour';	
	   
	if (result == 1) {
		x.action="Form_Trans_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SBillJourDtId="+vBillJourDtId;
		x.submit();
		
	}	
}


function DeleteRecord(BillJourDtId) {
	x = document.billjourdt;
	
	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=deletebilljour&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SBillJourDtId="+BillJourDtId;
		x.submit();
	}

}

function UpdateRecord(BillJourDtId) {
    x = document.billjourdt; 
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vMainMode = x.mainaction.value;
	
	x.txtBillJourDtId.value = BillJourDtId;
	
	
	x.submit();

}

function CheckFields(){
  
    x = document.billjourdt;
	
	var vBillNo        = x.txtBillNo.value;
	var vBank          = x.txtBank.value;
	var vValueDate     = x.txtValueDate.value;
	var vBillJourDtAmt  = x.txtBillJourDtAmt_D.value;
	var vBillJourDtAmt1 = x.txtBillJourDtAmt1_D.value;
	var vBillJourDtAmt2 = x.txtBillJourDtAmt2_D.value;
	var vBillJourDtBalAmt  = x.txtBillJourDtBalAmt.value;
	
	
	if (vBillJourDtAmt == '') vBillJourDtAmt = 0;
	if (vBillJourDtAmt1 == '') vBillJourDtAmt1 = 0;
	if (vBillJourDtAmt2 == '') vBillJourDtAmt2 = 0;
	if (vBillJourDtBalAmt == '') vBillJourDtBalAmt = 0;
	
	vBillJourDtAmt  = parseFloat(vBillJourDtAmt);
	vBillJourDtAmt1 = parseFloat(vBillJourDtAmt1);
	vBillJourDtAmt2 = parseFloat(vBillJourDtAmt2);
	vBillJourDtBalAmt = parseFloat(vBillJourDtBalAmt);
	
	if (vBillNo=='')
	{
		alert("Bill No. is mandatory!");
		x.txtBillNo.focus();
		return 0;
	}
	else if (vBank=='')
	{
		alert("Bank is mandatory!");
		x.txtBank.focus();
		return 0;
	}
	else if (vValueDate=='')
	{
		alert("Value Date is mandatory!");
		x.txtValueDate.focus();
		return 0;
	}
	else if ((vBillJourDtAmt*1 != vBillJourDtAmt/1 || vBillJourDtAmt < 0) ) {
		alert('Amount should be a NUMERIC and POSITIVE value.');
		x.txtBillJourDtAmt_D.focus();
		return 0;
	}
	else if ((vBillJourDtAmt1*1 != vBillJourDtAmt1/1 || vBillJourDtAmt1 < 0) ) {
		alert('Amount1 should be a NUMERIC and POSITIVE value.');
		x.txtBillJourDtAmt1_D.focus();
		return 0;
	}
	else if ((vBillJourDtAmt2*1 != vBillJourDtAmt2/1 || vBillJourDtAmt2 < 0) ) {
		alert('Amount2 should be a NUMERIC and POSITIVE value.');
		x.txtBillJourDtAmt2_D.focus();
		return 0;
	}
	else if (vBillJourDtAmt > vBillJourDtBalAmt) {
		alert('Amount must be less than or equal to Balance: '+vBillJourDtBalAmt);
		x.txtBillJourDtAmt_D.focus();
		return 0;
	}
	else if (vBillJourDtAmt==0 && vBillJourDtAmt1==0 && vBillJourDtAmt2==0) {
		alert('Amount/Amount1/Amoun2 must be Greater than Zero.');
		x.txtBillJourDtAmt_D.focus();
		return 0;
	}
			
	else
	return 1 ;	
}

function ClearRecord() {

	x = document.billjourdt;

	x.txtBillJourDtId.value='';
	x.txtBillJourDtLedger.value='';
	x.txtBillJourDtType.value='';
	x.txtBillNo.value='';
	x.txtBank.value='';
	x.txtValueDate.value='';
	x.txtCurrCode.value='';
	x.txtBillJourDtAmt.value='';
	x.txtBillJourDtAmt1.value='';
	x.txtBillJourDtAmt2.value='';
	x.txtBillJourDtAmt_D.value='';
	x.txtBillJourDtAmt1_D.value='';
	x.txtBillJourDtAmt2_D.value='';
	x.message.value='';

	x.submit();
}


function CheckAmount(option) {
	x=document.billjourdt;
	var vAmount, vAmount1, vAmount1, vAmountBal, vAmountBal1, vAmountBal2;
	
	vAmount  = x.txtBillJourDtAmt_D.value;
	vAmount1 = x.txtBillJourDtAmt1_D.value;
	vAmount2 = x.txtBillJourDtAmt2_D.value;
	vAmountBal = x.txtBillJourDtBalAmt.value;
	vAmountBal1 = x.txtBillJourDtBalAmt1.value;
	vAmountBal2 = x.txtBillJourDtBalAmt2.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.txtBillJourDtAmt_D.focus();
		return (false);
	}
	else if ((vAmount1*1 != vAmount1/1 || vAmount1 < 0 ) && option == 2 ) {
		alert('Amount1 should be a Numeric and Positive value.');
		x.txtBillJourDtAmt1_D.focus();
		return (false);
	}
	else if ((vAmount2*1 != vAmount2/1 || vAmount2 < 0 ) && option == 3) {
		alert('Amount2 should be a Numeric and Positive value.');
		x.txtBillJourDtAmt2_D.focus();
		return (false);
	}
	
}


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

	x=document.billjourdt;
	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.txtBillJourDtTotAmt.value;
	if (vAmountTot == '') vAmountTot = 0;
	vAmountTot=parseFloat(vAmountTot);
	
	vAmountTot1 = x.txtBillJourDtTotAmt1.value;
	if (vAmountTot1 == '') vAmountTot1 = 0;
	vAmountTot1=parseFloat(vAmountTot1);
	
	vAmountTot2 = x.txtBillJourDtTotAmt2.value;
	if (vAmountTot2 == '') vAmountTot2 = 0;
	vAmountTot2=parseFloat(vAmountTot2);
	
	if (option == 1) {
		
		vAmount = x.txtBillJourDtAmt_D.value;
		if (vAmount == '') vAmount = 0;
	
		vAmount=parseFloat(vAmount);
		
		x.txtBillJourDtAmt.value= vAmount;
		
		if (vAmount > 0) { 
			vAmount1=Math.round(((vAmount*rate)/rate1)*Math.pow(10,dec1))/Math.pow(10,dec1);
			vAmount1=parseFloat(vAmount1);
			x.txtBillJourDtAmt1_D.value= vAmount1;
			x.txtBillJourDtAmt1.value= parseFloat((vAmount*rate)/rate1);
				
			vAmount2=Math.round(((vAmount*rate)/rate2)*Math.pow(10,dec2))/Math.pow(10,dec2);
			vAmount2=parseFloat(vAmount2);
			x.txtBillJourDtAmt2_D.value=vAmount2;
			x.txtBillJourDtAmt2.value= parseFloat((vAmount*rate)/rate2);
			
		}	
	}	
	else if (option == 2) {
		vAmount1 = x.txtBillJourDtAmt1_D.value;
		if (vAmount1 == '') vAmount1 = 0;
		
		vAmount1=parseFloat(vAmount1);
		
		if (curr == currbase1 && vAmount1 > 0) {
			x.txtBillJourDtAmt_D.value= vAmount1;
			x.txtBillJourDtAmt.value= vAmount1;
		}	
			
	}
	else if (option == 3) {
		vAmount2 = x.txtBillJourDtAmt2_D.value;
		if (vAmount2 == '') vAmount2 = 0;
		
		vAmount2=parseFloat(vAmount2);
		
		if (curr == currbase2 && vAmount2 > 0) {
			x.txtBillJourDtAmt_D.value= vAmount2;
			x.txtBillJourDtAmt.value= vAmount2;
		}	
	
	}
	
		
	
}



function showlistBill(){
	x = document.billjourdt;
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vBillJourDtId = x.txtBillJourDtId.value;

	window.open('Form_Trans_ListBills.php?PTransDtId='+vTransDtId+'&PBillJourDtId='+vBillJourDtId,'mywindow','width=630,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



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

}

function kd(e)
{
	x=document.billjourdt;
    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>Checks / Bills</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='billjourdt' 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'>
<input type='hidden' name='message' value='$message'>

HERE;

//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, ".
			 " 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];
$LedgerActivity = $sub_result[2];
$TransDtCurr    = $sub_result[3];
$TransDtValueDate = $sub_result[4];
$TransDtdbcd      = $sub_result[5];
$Type_Label       = $sub_result[6];
	
	
if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C')) {
	$showlist = 0;
	$status = '';	
}	
else {
	$showlist = 1;
	$status = 'readonly';	
}	
	

$txtBillJourDtLedger = $LedgerNumber;
if(($LedgerActivity==3 && $TransDtdbcd=='D') or ($LedgerActivity==4 && $TransDtdbcd=='C'))
	$txtBillJourDtType = 'A'; 
else $txtBillJourDtType = 'C';
	
$txtValueDate = $TransDtValueDate;
$txtCurrCode = $TransDtCurr;


if ($txtBillJourDtId != '') {
	$sub_query1 = " Select BillJourDt_Id, Bill_number, Bill_bank, Date_Format(Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, Currency_Code, Ledger_Number, Bill_Type, ".
				  " 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.BillJourDt_Id = '".$txtBillJourDtId."' ";
						  
	//echo $sub_query1;
	$sub_result1 = selectData($connection, $sub_query1);
			
	$txtBillNo     = $sub_result1[1];
	$txtBank       = $sub_result1[2];
	$txtValueDate  = $sub_result1[3];
	$txtCurrCode   = $sub_result1[4];
	$txtBillJourDtLedger = $sub_result1[5];
	$txtBillJourDtType   = $sub_result1[6];
	$txtBillJourDtAmt_D  = $sub_result1[7];
	$txtBillJourDtAmt1_D = $sub_result1[8];
	$txtBillJourDtAmt2_D = $sub_result1[9];
	$txtBillJourDtAmt    = $sub_result1[10];
	$txtBillJourDtAmt1   = $sub_result1[11];
	$txtBillJourDtAmt2   = $sub_result1[12];
	
	
	$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);
	
	$txtBillJourDtBalAmt   = $sub_result2[1];
	$txtBillJourDtBalAmt1  = $sub_result2[2];
	$txtBillJourDtBalAmt2  = $sub_result2[3];
	
	$txtBillJourDtTotAmt   = $sub_result2[4];
	$txtBillJourDtTotAmt1  = $sub_result2[5];
	$txtBillJourDtTotAmt2  = $sub_result2[6];
	
	$txtBillJourDtBalAmt   = $txtBillJourDtBalAmt  + $sub_result1[10];
	$txtBillJourDtBalAmt1  = $txtBillJourDtBalAmt1 + $sub_result1[11];
	$txtBillJourDtBalAmt2  = $txtBillJourDtBalAmt2 + $sub_result1[12];
}

if ($txtBillJourDtId == '') {

	$sub_query2 = " Select TransDt.TransDt_ID, ".
	              " Round((ifNull(Transdt_Amount,0) - Sum(ifNull(Bill_Amount,0))), ".$DecimalBase1.")  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))), ".$DecimalBase1.") 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);
	
	$txtBillJourDtBalAmt   = $sub_result2[7];
	$txtBillJourDtBalAmt1  = $sub_result2[8];
	$txtBillJourDtBalAmt2  = $sub_result2[9];
	
	$txtBillJourDtTotAmt   = $sub_result2[4];
	$txtBillJourDtTotAmt1  = $sub_result2[5];
	$txtBillJourDtTotAmt2  = $sub_result2[6];
	
	$txtBillJourDtAmt_D   = $sub_result2[1];
	$txtBillJourDtAmt1_D  = $sub_result2[2];
	$txtBillJourDtAmt2_D  = $sub_result2[3];
	
	$txtBillJourDtAmt   = $sub_result2[7];
	$txtBillJourDtAmt1  = $sub_result2[8];
	$txtBillJourDtAmt2  = $sub_result2[9];

}


//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=130>
		  <col width=150>
		  <col width=100>
		  <col width=50>
		  <col width=100>
		  <col width=100>
		  <col width=100>
		  
		   <tr bgcolor='#F7F7F7' height='20'>
		     <td align='center' colspan='9'><span class='style16'>$Type_Label</span></td>
		   </tr>
		   
		   <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='9' 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='3'><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'>Bill No.</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Bank</span></td>
			 <td valign='center' align='center' ><span class='style12'>Value Date</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Curr.</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='txtBillJourDtId' value='$txtBillJourDtId' >
					<input type='hidden' name='txtBillJourDtLedger' value='$txtBillJourDtLedger' >
					<input type='hidden' name='txtBillJourDtType' value='$txtBillJourDtType' >
					<input type='hidden' name='txtBillJourDtAmt' value='$txtBillJourDtAmt' >
					<input type='hidden' name='txtBillJourDtAmt1' value='$txtBillJourDtAmt1' >
					<input type='hidden' name='txtBillJourDtAmt2' value='$txtBillJourDtAmt2' >
					<input type='hidden' name='txtBillJourDtBalAmt' value='$txtBillJourDtBalAmt' >
					<input type='hidden' name='txtBillJourDtBalAmt1' value='$txtBillJourDtBalAmt1' >
					<input type='hidden' name='txtBillJourDtBalAmt2' value='$txtBillJourDtBalAmt2' >
					<input type='hidden' name='txtBillJourDtTotAmt' value='$txtBillJourDtTotAmt' >
					<input type='hidden' name='txtBillJourDtTotAmt1' value='$txtBillJourDtTotAmt1' >
					<input type='hidden' name='txtBillJourDtTotAmt2' value='$txtBillJourDtTotAmt2' ></td>";
				 
			echo "<td align='left' valign='center'><input type='text' name='txtBillNo' id='txtBillNo' value='".htmlspecialchars($txtBillNo, ENT_QUOTES)."' maxlength='15' style='font-size:12px; width:100px; height:18px;' $status/>";
			if ($showlist == 1) 
				echo"<img src='img/btnopen.jpg' title=' Select Bill ' width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistBill(); '  />";
			
			echo"</td>";	
				

			echo" <td align='left' ><input type='text' name='txtBank' id='txtBank' value='".htmlspecialchars($txtBank, ENT_QUOTES)."' maxlength='15' style='font-size:12px; width:140px; height:18px;' $status /></td>";
			echo "<td align='left'><input type='text' name='txtValueDate' value='$txtValueDate' maxlength='10' style='font-size:12px; width:70px; height:18px;' $status >";
			
			if ($showlist == 0) 
			    echo"<A HREF='#' onClick=\"displayCalendar(document.billjourdt.txtValueDate,'dd/mm/yyyy',this);  return false; \" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></A>";
			echo "</td>";	

			echo" <td align='left' ><input type='text' name='txtCurrCode' id='txtCurrCode' value='$txtCurrCode' style='font-size:12px; width:50px; height:18px;' readonly /></td>";	
			
			if ($Module_TransStandardView == 1) {
				echo"<td align='center'><input type='text' name='txtBillJourDtAmt_D'  value='$txtBillJourDtAmt_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."');\" $status></td>
					 <td align='center'><input type='text' name='txtBillJourDtAmt1_D' value='$txtBillJourDtAmt1_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."');\" $status></td>
					 <td align='center'><input type='text' name='txtBillJourDtAmt2_D' value='$txtBillJourDtAmt2_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."');\" $status></td>";
			} else {
				echo"<td align='center'><input type='text' name='txtBillJourDtAmt_D'  value='$txtBillJourDtAmt_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."');\" $status></td>
					 <td align='center' colspan='2'><input type='hidden' name='txtBillJourDtAmt1_D' value='$txtBillJourDtAmt1_D' ><input type='hidden' name='txtBillJourDtAmt2_D' value='$txtBillJourDtAmt2_D' ></td>";
			}	
				 
		
echo"       
		  </tr>
		  <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='9' align='center' bgcolor=#D8D8D8>
			    <input type='button' id='btnSubmitRecord' name='btnSubmitRecord'  value='Submit'  onclick='SubmitRecord();' $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 BillJourDt_Id, BillJourDt.Bill_number, BillJourDt.Bill_bank, Date_Format(BillJourDt.Bill_ValueDate,'%d/%m/%Y') As Bill_ValueDate, BillJourDt.Currency_Code, BillJourDt.Ledger_Number, BillJourDt.Bill_Type, ".
					      " Round(BillJourDt.Bill_Amount, ".$DecimalBase."), Round(BillJourDt.Bill_Amount1, ".$DecimalBase1."), Round(BillJourDt.Bill_Amount2, ".$DecimalBase2."), ".
						  " Bills.Journaldt_id2 ".
					      " From Temp_BillJourDt As BillJourDt ".
						  " Left Join Bills on Bills.Bill_Number = BillJourDt.Bill_Number and Bills.Ledger_Number = BillJourDt.Ledger_Number  ".
					      " Where BillJourDt.TransDt_id = '".$PTransDtId."' ".
					      " Order By BillJourDt_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."'";	
				
				$ButtonStatus = '';
				if ($sub_rows3[10] != '' && $sub_rows3[6] == 'A')		
					$ButtonStatus = ' disabled ';
				
				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'  $ButtonStatus ></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'  $ButtonStatus ></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='left'><span class='style15'>".$sub_rows3[4]."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[7], $DecimalBase)."</span></td>";
				
				if ($Module_TransStandardView == 1) {
					echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[8], $DecimalBase1)."</span></td>";
					echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[9], $DecimalBase2)."</span></td>";	
				} else 	
					echo "	<td align='right' colspan='2'>&nbsp;</td>";
					
					
				echo "</tr>";
								
			}
			
		 }  

echo" </table>";

	

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

HERE;


?>