<?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.invoices;
	
	var result = CheckFields();
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vAccLinkId  = x.txtAccLinkId.value;
	
	var vMainMode = x.mainaction.value;
	var vMode = x.actionmode.value;
	
	if (vAccLinkId == '')
		vMode = 'insertinvoice';	
	else
		vMode = 'editinvoice';	
	   
	if (result == 1) {
		x.action="Form_Trans_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SAccLinkId="+vAccLinkId;
		x.submit();
		
	}	
}


function DeleteRecord(AccLinkId) {
	x = document.invoices;
	
	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=deleteinvoice&mainmode="+vMainMode+"&TransType="+vTransType+"&STransId="+vTransId+"&STransDtId="+vTransDtId+"&SAccLinkId="+AccLinkId;
		x.submit();
	}

}

function UpdateRecord(AccLinkId) {
    x = document.invoices; 
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;
	var vMainMode   = x.mainaction.value;
	
	x.txtAccLinkId.value = AccLinkId;
	
	
	x.submit();

}

function CheckFields(){
  
    x = document.invoices;
	
	var vLinkRef          = x.txtLinkRef.value;
	var vAccLinkPaidAmt   = x.txtAccLinkPaidAmt_D.value;
	var vAccLinkBalAmt    = x.txtAccLinkBalAmt.value;
	var vAccLinkNetToPay  = x.txtAccLinkNetToPay_D.value;
	

	
	if (vAccLinkPaidAmt == '')   vAccLinkPaidAmt = 0;
	if (vAccLinkBalAmt == '')    vAccLinkBalAmt = 0;
	if (vAccLinkNetToPay == '')  vAccLinkNetToPay = 0;
	
	vAccLinkPaidAmt  = parseFloat(vAccLinkPaidAmt);
	vAccLinkBalAmt   = parseFloat(vAccLinkBalAmt);
	vAccLinkNetToPay = parseFloat(vAccLinkNetToPay);
	
	
	if (vLinkRef=='')
	{
		alert("Invoice Ref. is mandatory!");
		x.txtLinkRef.focus();
		return 0;
	}
	else if ((vAccLinkPaidAmt*1 != vAccLinkPaidAmt/1 || vAccLinkPaidAmt < 0) ) {
		alert('Paid Amount should be a NUMERIC and POSITIVE value.');
		x.txtAccLinkPaidAmt_D.focus();
		return 0;
	}
	else if (vAccLinkPaidAmt > vAccLinkNetToPay) {
		alert('Paid Amount must be less than or equal to Invoice Amount: '+vAccLinkNetToPay);
		x.txtAccLinkPaidAmt_D.focus();
		return 0;
	}
	else if (vAccLinkPaidAmt > vAccLinkBalAmt) {
		alert('Paid Amount must be less than or equal to Balance Amount: '+vAccLinkBalAmt);
		x.txtAccLinkPaidAmt_D.focus();
		return 0;
	}
	else if (vAccLinkPaidAmt==0) {
		alert('Paid Amount must be Greater than Zero.');
		x.txtAccLinkPaidAmt_D.focus();
		return 0;
	}
			
	else
	return 1 ;	
}

function ClearRecord() {

	x = document.invoices;

	x.txtAccLinkId.value='';
	x.txtLinkRef.value='';
	x.txtLinkType.value='';
	x.txtAccLinkNetTotAmt.value='';
	x.txtAccLinkNetTotAmt1.value='';
	x.txtAccLinkNetTotAmt2.value='';
	x.txtAccLinkNetToPay.value='';
	x.txtAccLinkNetToPay1.value='';
	x.txtAccLinkNetToPay2.value='';
	x.txtAccLinkPaidAmt.value='';
	x.txtAccLinkPaidAmt1.value='';
	x.txtAccLinkPaidAmt2.value='';
	x.txtAccLinkRemainAmt.value='';
	x.txtAccLinkRemainAmt1.value='';
	x.txtAccLinkRemainAmt2.value='';
	x.txtAccLinkNetToPay_D.value='';
	x.txtAccLinkPaidAmt_D.value='';
	x.txtAccLinkRemainAmt_D.value='';
	x.message.value='';

	x.submit();
}


function CheckAmount() {
	x=document.invoices;
	
	var vAccLinkPaidAmt  = x.txtAccLinkPaidAmt_D.value;
	var vAccLinkNetToPay = x.txtAccLinkNetToPay_D.value;
	
	if (vAccLinkPaidAmt == '')   vAccLinkPaidAmt  = 0;
	if (vAccLinkNetToPay == '')  vAccLinkNetToPay  = 0;
	
	if ((vAccLinkPaidAmt*1 != vAccLinkPaidAmt/1 || vAccLinkPaidAmt < 0  )) {
		alert('Paid Amount should be a Numeric and Positive value.');
		x.txtAccLinkPaidAmt_D.focus();
		return (false);
	}
	else if (vAccLinkPaidAmt > vAccLinkNetToPay) {
		alert('Paid Amount must be less than or equal to Invoice Amount: '+vAccLinkNetToPay);
		x.txtAccLinkPaidAmt_D.focus();
		return (false);
	}
	
}

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

	x=document.invoices;
	var vPer, vAccLinkPaidAmt, vAccLinkNetToPay;
	
	dec1  = parseInt(dec1);
	dec2  = parseInt(dec2);
	rate  = parseFloat(rate);
	rate1 = parseFloat(rate1);
	rate2 = parseFloat(rate2);
	
		
	var vAccLinkPaidAmt  = x.txtAccLinkPaidAmt_D.value;
	var vAccLinkNetToPay = x.txtAccLinkNetToPay_D.value;
	
	if (vAccLinkPaidAmt == '')   vAccLinkPaidAmt  = 0;
	if (vAccLinkNetToPay == '')  vAccLinkNetToPay  = 0;
	
	vAccLinkPaidAmt  = parseFloat(vAccLinkPaidAmt);
	vAccLinkNetToPay = parseFloat(vAccLinkNetToPay);
	
	x.txtAccLinkPaidAmt.value = vAccLinkPaidAmt;
		
	if (vAccLinkPaidAmt > 0) { 
		//vAccLinkPaidAmt1 = Math.round(((vAccLinkPaidAmt*rate)/rate1)*Math.pow(10,dec1))/Math.pow(10,dec1);
		//vAccLinkPaidAmt1 = parseFloat(vAccLinkPaidAmt1);
		//x.txtCstJourDtAmt1_D.value= vAmount1;
		x.txtAccLinkPaidAmt1.value= parseFloat((vAccLinkPaidAmt*rate)/rate1);
				
		//vAmount2=Math.round(((vAccLinkPaidAmt*rate)/rate2)*Math.pow(10,dec2))/Math.pow(10,dec2);
		//vAmount2=parseFloat(vAmount2);
		//x.txtCstJourDtAmt2_D.value=vAmount2;
		x.txtAccLinkPaidAmt2.value= parseFloat((vAccLinkPaidAmt*rate)/rate2);
			
	}	
	
}
*/
function CalcRemainAmount() {
	x=document.invoices;
	
	var vAccLinkPaidAmt   = x.txtAccLinkPaidAmt_D.value;
	var vAccLinkNetToPay  = x.txtAccLinkNetToPay_D.value;
	
	if (vAccLinkPaidAmt == '')   vAccLinkPaidAmt  = 0;
	if (vAccLinkNetToPay == '')  vAccLinkNetToPay  = 0;
	
	vAccLinkRemainAmt = vAccLinkNetToPay - vAccLinkPaidAmt;
	x.txtAccLinkRemainAmt_D.value = vAccLinkRemainAmt;
}


function showlistInvoices(){
	x = document.invoices;
	
	var vTransId    = x.PTransId.value;
	var vTransDtId  = x.PTransDtId.value;
	var vTransType  = x.PTransType.value;

	window.open('Form_Trans_ListInvoices.php?PTransId='+vTransId+'&PTransDtId='+vTransDtId+'&PTransType='+vTransType,'mywindow','width=800,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left=100,top=0');
}



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

}

function kd(e)
{
	x=document.invoices;
    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>Invoices</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='invoices' 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];
$Type_Label     = $sub_result[6];

$vMainCompanyName=explode('_',$HTTP_SESSION_VARS['dbName']);  
$DirCompany  = $vMainCompanyName[0];
$DirYear	 = $vMainCompanyName[1]; 
	
	
if ($txtAccLinkId != '') {
	$sub_query1 = " Select Acc_Id, Link_Ref, Link_Type, Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."), Round(ifNull(Sale_NetToPay,0), ".$DecimalBase."), ".
				  " Round(ifNull(Sale_PaidAmnt,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_PaidAmntBase1,0), ifNull(Sale_PaidAmntBase2,0), ".
				  " ifNull(Sale_RemainAmnt,0), ifNull(Sale_RemainAmntBase1,0), ifNull(Sale_RemainAmntBase2,0) ".
				  " From ".$HTTP_SESSION_VARS['dbLabel'].".Temp_AccLink As AccLink ".
				  " Where AccLink.Acc_Id = '".$txtAccLinkId."' ";
						  
	//echo $sub_query1;
	$sub_result1 = selectData($connection, $sub_query1);
			
	$txtLinkRef    = $sub_result1[1];
	$txtLinkType   = $sub_result1[2];
	$txtAccLinkNetTotAmt_D = $sub_result1[3];
	$txtAccLinkNetToPay_D  = $sub_result1[4];
	$txtAccLinkPaidAmt_D   = $sub_result1[5];
	$txtAccLinkRemainAmt_D = $sub_result1[6];
	$txtAccLinkNetTotAmt   = $sub_result1[7];
	$txtAccLinkNetTotAmt1  = $sub_result1[8];
	$txtAccLinkNetTotAmt2  = $sub_result1[9];
	$txtAccLinkNetToPay    = $sub_result1[10];
	$txtAccLinkNetToPay1   = $sub_result1[11];
	$txtAccLinkNetToPay2   = $sub_result1[12];
	$txtAccLinkPaidAmt     = $sub_result1[13];
	$txtAccLinkPaidAmt1    = $sub_result1[14];
	$txtAccLinkPaidAmt2    = $sub_result1[15];
	$txtAccLinkRemainAmt   = $sub_result1[16];
	$txtAccLinkRemainAmt1  = $sub_result1[17];
	$txtAccLinkRemainAmt2  = $sub_result1[18];
	
	
	$sub_query2 = " Select TransDt.TransDt_ID, ".
				  " (ifNull(Transdt_Amount,0) - Round(Sum(ifNull(Sale_PaidAmnt,0)),9) ) As PaidAmnt, ".
				  " (ifNull(Transdt_Amount1,0) - Round(Sum(ifNull(Sale_PaidAmntBase1,0)),9) ) As PaidAmnt1, ".
				  " (ifNull(Transdt_Amount2,0) - Round(Sum(ifNull(Sale_PaidAmntBase2,0)),9) ) As PaidAmnt2, ".
				  " ifNull(Transdt_Amount,0), ifNull(Transdt_Amount1,0), ifNull(Transdt_Amount2,0) ".
				  " From Temp_TransDt As TransDt Left Join ".$HTTP_SESSION_VARS['dbLabel'].".Temp_AccLink on TransDt.TransDt_ID = Temp_AccLink.Journal_ID ".
				  " And Temp_AccLink.Journal_Type = '".$PTransType."' ".
				  " 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   = $sub_result2[1];
	$txtAccLinkBalAmt1  = $sub_result2[2];
	$txtAccLinkBalAmt2  = $sub_result2[3];
	
	$txtAccLinkTotAmt   = $sub_result2[4];
	$txtAccLinkTotAmt1  = $sub_result2[5];
	$txtAccLinkTotAmt2  = $sub_result2[6];
	
	$txtAccLinkBalAmt   = $txtAccLinkBalAmt  + $sub_result1[13];
	$txtAccLinkBalAmt1  = $txtAccLinkBalAmt1 + $sub_result1[14];
	$txtAccLinkBalAmt2  = $txtAccLinkBalAmt2 + $sub_result1[15];
}

if ($txtAccLinkId == '') {

	$sub_query2 = " Select TransDt.TransDt_ID, ".
	              " Round((ifNull(Transdt_Amount,0) - Sum(ifNull(Sale_PaidAmnt,0))), ".$DecimalBase1.")  As PaidAmnt_D, ".
				  " Round((ifNull(Transdt_Amount1,0) - Sum(ifNull(Sale_PaidAmntBase1,0))), ".$DecimalBase1.") As PaidAmnt1_D, ".
				  " Round((ifNull(Transdt_Amount2,0) - Sum(ifNull(Sale_PaidAmntBase2,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)),9) ) As PaidAmnt, ".
				  " (ifNull(Transdt_Amount1,0) - Round(Sum(ifNull(Sale_PaidAmntBase1,0)),9) ) As PaidAmnt1, ".
				  " (ifNull(Transdt_Amount2,0) - Round(Sum(ifNull(Sale_PaidAmntBase2,0)),9) ) As PaidAmnt2 ".
				  " From Temp_TransDt As TransDt Left Join ".$HTTP_SESSION_VARS['dbLabel'].".Temp_AccLink on TransDt.TransDt_ID = Temp_AccLink.Journal_ID ".
				  " And Temp_AccLink.Journal_Type = '".$PTransType."' ".
				  " 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   = $sub_result2[7];
	$txtAccLinkBalAmt1  = $sub_result2[8];
	$txtAccLinkBalAmt2  = $sub_result2[9];
	
	$txtAccLinkTotAmt   = $sub_result2[4];
	$txtAccLinkTotAmt1  = $sub_result2[5];
	$txtAccLinkTotAmt2  = $sub_result2[6];
	
	$txtAccLinkPaidAmt_D = $sub_result2[1];
	
	$txtAccLinkPaidAmt   = $sub_result2[7];
	$txtAccLinkPaidAmt1  = $sub_result2[8];
	$txtAccLinkPaidAmt2  = $sub_result2[9];

}


//Getting Currency Rates
$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$TransDtCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$TransDtCurr."' )";
$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=120>
		  <col width=120>
		  <col width=120>
		  
		   <tr bgcolor='#F7F7F7' height='20'>
		     <td align='center' colspan='6'><span class='style16'>$Type_Label</span></td>
		   </tr>
		   
		   <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='6' 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>
		   </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'>Inv Ref.</span></td> 
			 <td valign='center' align='center' ><span class='style12'>Net To Pay</span></td>
			 <td valign='center' align='center' ><span class='style12'>Paid Amt</span></td>
			 <td valign='center' align='center' ><span class='style12'>Remain Amt</span></td>";

echo"	   </tr>
		   <tr bgcolor='#F7F7F7' >";
		  
		
		    echo"<td align='center' colspan='2'>&nbsp;
				    <input type='hidden' name='txtAccLinkId' value='$txtAccLinkId' >
					<input type='hidden' name='txtLinkType' value='$txtLinkType' >
					<input type='hidden' name='txtAccLinkNetTotAmt'  value='$txtAccLinkNetTotAmt' >
					<input type='hidden' name='txtAccLinkNetTotAmt1' value='$txtAccLinkNetTotAmt1' >
					<input type='hidden' name='txtAccLinkNetTotAmt2' value='$txtAccLinkNetTotAmt2' >
					<input type='hidden' name='txtAccLinkNetToPay'  value='$txtAccLinkNetToPay' >
					<input type='hidden' name='txtAccLinkNetToPay1' value='$txtAccLinkNetToPay1' >
					<input type='hidden' name='txtAccLinkNetToPay2' value='$txtAccLinkNetToPay2' >
					<input type='hidden' name='txtAccLinkPaidAmt'  value='$txtAccLinkPaidAmt' >
					<input type='hidden' name='txtAccLinkPaidAmt1' value='$txtAccLinkPaidAmt1' >
					<input type='hidden' name='txtAccLinkPaidAmt2' value='$txtAccLinkPaidAmt2' >
					<input type='hidden' name='txtAccLinkRemainAmt'  value='$txtAccLinkRemainAmt' >
					<input type='hidden' name='txtAccLinkRemainAmt1' value='$txtAccLinkRemainAmt1' >
					<input type='hidden' name='txtAccLinkRemainAmt2' value='$txtAccLinkRemainAmt2' >
					<input type='hidden' name='txtAccLinkBalAmt'  value='$txtAccLinkBalAmt' >
					<input type='hidden' name='txtAccLinkBalAmt1' value='$txtAccLinkBalAmt1' >
					<input type='hidden' name='txtAccLinkBalAmt2' value='$txtAccLinkBalAmt2' >
					<input type='hidden' name='txtAccLinkTotAmt'  value='$txtAccLinkTotAmt' >
					<input type='hidden' name='txtAccLinkTotAmt1' value='$txtAccLinkTotAmt1' >
					<input type='hidden' name='txtAccLinkTotAmt2' value='$txtAccLinkTotAmt2' ></td>";
				 
			echo "<td align='left' valign='center'><input type='text' name='txtLinkRef' id='txtLinkRef' value='".htmlspecialchars($txtLinkRef, ENT_QUOTES)."' maxlength='15' style='font-size:12px; width:100px; height:18px;' readonly /></td>";	

			echo"<td align='center'><input type='text' name='txtAccLinkNetToPay_D' value='$txtAccLinkNetToPay_D' maxlength='20' style='text-align:right; font-size:12px; width:110px; height:18px;' readonly ></td>
				 <td align='center'><input type='text' name='txtAccLinkPaidAmt_D'   value='$txtAccLinkPaidAmt_D'   maxlength='20' style='text-align:right; font-size:12px; width:110px; height:18px;' onBlur='CheckAmount();' onKeyup='CalcRemainAmount();'  ></td>
				 <td align='center'><input type='text' name='txtAccLinkRemainAmt_D' value='$txtAccLinkRemainAmt_D' maxlength='20' style='text-align:right; font-size:12px; width:110px; height:18px;' readonly ></td>";
				 
		
echo"       
		  </tr>
		  <tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='6' 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'>
				<input type='button' id='btnInvoice' name='btnInvoice'  value='Load Invoice(s)'  onclick='showlistInvoices();' $style title='Select Invoices'></td>
			 
		  </tr>";
		  
		 if ($PTransDtId != '') {
		     
			$sub_query3 = " Select Acc_Id, Link_Ref, Round(ifNull(Sale_NetToPay,0), ".$DecimalBase."), Round(ifNull(Sale_PaidAmnt,0), ".$DecimalBase."), Round(ifNull(Sale_RemainAmnt,0), ".$DecimalBase.") ".
					      " From ".$HTTP_SESSION_VARS['dbLabel'].".Temp_AccLink As AccLink ".
					      " Where AccLink.Journal_Id = '".$PTransDtId."' ".
						  " And AccLink.Journal_Type = '".$PTransType."' ".
						  " And upper(AccLink.CompanyName) = upper('".$DirCompany."') ".
						  " And upper(AccLink.DirYear) = upper('".$DirYear."') ".
					      " Order By Acc_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='right'><span class='style15'>".number_format($sub_rows3[2], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[3], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style15'>".number_format($sub_rows3[4], $DecimalBase)."</span></td>";	
				echo "</tr>";
								
			}
			
		 }  

echo" </table>";

	

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

HERE;


?>