Commit f1e5145c authored by smanohar's avatar smanohar

Migrated component imported

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@206622 ce508802-f39f-4f6c-b175-0d175dae99d5
parent af4a10f1
package ibase.webitm.ejb.fin;
/*
* Author:Manoharan
* Date:20-JAN-18
* Request W16CBAS005 (Bug Resolution Process)
*/
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
import java.rmi.RemoteException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import org.w3c.dom.Document;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.ejb.mfg.MfgCommon;
import java.util.*;
import java.sql.*;
public class UnpostFin extends ProcessEJB
{
FinCommon finCommon = new FinCommon();
DistCommon distCommon = new DistCommon();
E12GenericUtility genericUtility = new E12GenericUtility();
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null;
Document headerDom = null;
String retStr = "";
//ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
long startTime = 0, endTime = 0, totalTime = 0, totalHrs = 0, totlMts = 0, totSecs = 0; // Added
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom" + headerDom);
}
if(xmlString2 != null && xmlString2.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString2);
System.out.println("detailDom" + detailDom);
//writeLog(filePtr,"detailDom-->"+detailDom,true);
}
startTime = System.currentTimeMillis();
retStr = process(headerDom, detailDom, windowName, xtraParams);
endTime = System.currentTimeMillis();
totalTime = endTime - startTime;
//System.out.println("Total Time Spend :: " + totalTime + " Milliseconds");
totSecs = (int) (((double) 1 / 1000) * (totalTime));
totalHrs = (int) (totSecs / 3600);
totlMts = (int) (((totSecs - (totalHrs * 3600)) / 60));
totSecs = (int) (totSecs - ((totalHrs * 3600) + (totlMts * 60)));
System.out.println("Total Time Spend [" + totalHrs + "] Hours [" + totlMts + "] Minutes [" + totSecs + "] seconds");
//Changed By Nasruddin 04-11-16 End
System.out.println("@@@@@@@@@@@ retStr["+retStr+"]");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
String errString = "",refSer = "", refIdFr = "", refIdTo = "";
Connection conn = null;
boolean isError = false;
try
{
conn = getConnection() ;
refSer = genericUtility.getColumnValue("mref_series",headerDom);
refIdFr = genericUtility.getColumnValue("ref_id__fr",headerDom);
refIdTo = genericUtility.getColumnValue("ref_id__to",headerDom);
errString = unPost(refSer, refIdFr, refIdTo , conn);
if (errString.indexOf("PRCSUCES") == -1 )
{
isError = true;
}
}
catch(Exception e)
{
isError = true;
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(!isError)
{
conn.commit();
}
else
{
conn.rollback();
}
if(conn !=null)
{
conn.close();
conn=null;
}
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public String unPost(String refSer, String refIdFr, String refIdTo , Connection conn) throws ITMException, Exception
{
String errCode = "", errString = "", paySer = "", paymentNo = "", refSerAdv = "", refNoAdv = "", vouchType = "", siteCode = "", tranSer = "";
String tableName = "", pkColName = "", sql = "", errMsg = "", refId = "";
String tempStr1 = "", tempStr2 = "", tempStr = "";
double payAmount = 0, adjAmtAdv = 0, tempAmount1 = 0, chqAmount = 0;
int count = 0;
PreparedStatement pstmt = null, pstmt1 = null, pstmtUpd = null;
ResultSet rs = null, rs1 = null;
ArrayList<String> tranList = new ArrayList<String>();
try
{
refSer = refSer.trim();
if("CRNRCP".equals(refSer) || "DRNRCP".equals(refSer)) // credit note (invoice)
{
tableName = "drcr_rcp";
pkColName = "tran_id";
}
else if("P-IBCA".equals(refSer)) // payable IBCA
{
tableName = "pay_ibca";
pkColName = "tran_id";
}
else if("R-IBCA".equals(refSer)) // receivable IBCA
{
tableName = "rcp_ibca";
pkColName = "tran_id";
}
else if("JOUR".equals(refSer)) // journal
{
tableName = "journal";
pkColName = "tran_id";
}
else if("VOUCH".equals(refSer)) // Purchase Voucher
{
tableName = "voucher";
pkColName = "tran_id";
}
else if("M-VOUC".equals(refSer)) // Payable voucher
{
tableName = "misc_voucher";
pkColName = "tran_id";
}
else if("P-VOUC".equals(refSer)) // payroll voucher
{
tableName = "payr_voucher";
pkColName = "tran_id";
}
else if("MDRCRC".equals(refSer) || "MDRCRD".equals(refSer)) // misc credit / debit note
{
tableName = "misc_drcr_rcp";
pkColName = "tran_id";
}
else if("E-PAY".equals(refSer)) // direct payments
{
tableName = "payment_exp";
pkColName = "tran_id";
}
else if("M-PAY".equals(refSer)) // payments
{
tableName = "misc_payment";
pkColName = "tran_id";
}
else if("MPCANC".equals(refSer)) // payment cancellation
{
tableName = "misc_payment_canc";
pkColName = "tran_id";
}
else if("M-RCP".equals(refSer)) // misc receipts
{
tableName = "misc_receipt";
pkColName = "tran_id";
}
else if("R-DIS".equals(refSer)) // receipt dishonour
{
tableName = "rcpdishnr";
pkColName = "tran_id";
}
else if("F-XFR".equals(refSer)) // fundtransfer
{
tableName = "fundtransfer";
pkColName = "tran_id";
}
else if("S-INV".equals(refSer)) // invoice
{
tableName = "invoice";
pkColName = "invoice_id";
}
else if("RCP".equals(refSer)) // receipt // added by sheetal - 18/9/02
{
tableName = "receipt";
pkColName = "tran_id";
}
System.out.println("Before loop refSer["+ refSer + "]");
sql = "select " + pkColName + " as tran_id from " + tableName + " where " + pkColName + " >= ? and " + pkColName + " <= ? and confirmed = 'Y' order by 1 " ;
if("F-XFR".equals(refSer)) // fundtransfer
{
sql = "select " + pkColName + " as tran_id from " + tableName + " where " + pkColName + " >= ? and " + pkColName + " <= ? and status = 'C' order by 1 " ;
}
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refIdFr);
pstmt.setString(2, refIdTo);
rs = pstmt.executeQuery();
while(rs.next())
{
tranList.add(rs.getString("tran_id"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (tranList.size() == 0)
{
errCode = "VTNOREC ";
errString = getMsg("No transaction in the range selected for unposting",errCode, conn);
}
for(int tranCtr = 0; tranCtr<tranList.size(); tranCtr++)
{
errCode = "";
errString = "";
refId = (String) tranList.get(tranCtr);
while (true)
{
if("CRNRCP".equals(refSer) || "DRNRCP".equals(refSer)) // credit note (invoice)
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update drcr_rcp set confirmed = 'N' where tran_id = ? and confirmed = 'Y' ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update drcr_rcp failed ",errCode, conn);
break;
}
sql = "delete from receivables where tran_ser = ? and ref_no = ? and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Deleting receivables failed ",errCode, conn);
break;
}
sql = "delete from drcr_racct where tran_id = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count <= 1)
{
errCode = "DS000NR";
errString = getMsg("Deleting drcr_racct failed ",errCode, conn);
break;
}
}
else if("P-IBCA".equals(refSer))
{
sql = "select tran_ser, site_code__to from pay_ibca where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
tranSer = rs.getString("tran_ser");
siteCode = rs.getString("site_code__to");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//if tempStr1 = 'I' then
// errCode = 'Unpost option only for Receipt type'
// exit
//end if
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "select ref_ser, ref_no from pay_ibca_det where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
tempStr1 = rs.getString("ref_ser");
tempStr2 = rs.getString("ref_no");
if("I".equals(tranSer))
{
sql = "delete from misc_payables where tran_ser = ? and ref_no = ? and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, tempStr2);
}
else
{
sql = "delete from misc_payables where tran_ser like 'P-IBC%' and ref_no = ? and adj_amt = 0 and site_code = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, tempStr2);
pstmtUpd.setString(2, siteCode);
}
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Deleting misc_payables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "update pay_ibca set confirmed = 'N' where tran_id = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update pay_ibca failed ",errCode, conn);
break;
}
}
else if("R-IBCA".equals(refSer))
{
sql = "select tran_ser from rcp_ibca where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
tempStr = rs.getString("tran_ser");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "select ref_ser, ref_no , tot_amt from rcp_ibca_det where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
tempStr1 = rs.getString("ref_ser");
tempStr2 = rs.getString("ref_no");
tempAmount1 = rs.getDouble("tot_amt");
if("R".equals(tempStr))
{
sql = "delete from receivables where tran_ser = ? and ref_no = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, tempStr1);
pstmtUpd.setString(2, tempStr2);
}
else
{
sql = "update receivables set adj_amt = adj_amt - ? where tran_ser = ? and ref_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, tempAmount1);
pstmtUpd.setString(2, tempStr1);
pstmtUpd.setString(3, tempStr2);
}
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update receivables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "update rcp_ibca set confirmed = 'N' where tran_id = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update rcp_ibca failed ",errCode, conn);
break;
}
}
else if("JOUR".equals(refSer))
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update journal set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update journal failed ",errCode, conn);
break;
}
}
else if ( "VOUCH".equals(refSer)) // Purchase Voucher
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "select count(1) as count from vouchadv where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("count");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( count !=0)
{
//errCode = 'VTVOUCHADV'
//exit
//to verify for advance - check the commented code below
sql = " select ref_ser, ref_no, adj_amt from vouchadv from rcp_ibca_det where tran_id ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
refSerAdv = rs.getString("ref_ser");
refNoAdv = rs.getString("ref_no");
adjAmtAdv = rs.getDouble("adj_amt");
sql = "update misc_payables set adj_amt = adj_amt - ? where tran_ser = ? and ref_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, adjAmtAdv);
pstmtUpd.setString(2, refSerAdv);
pstmtUpd.setString(3, refNoAdv);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update rcp_ibca failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(errString != null && errString.trim().length() > 0 )
{
break;
}
}
sql = "update voucher set confirmed = 'N', "
+ " net_amt = net_amt - (case when rnd_amt is null then 0 else rnd_amt end), "
+ " net_amt__bc = (net_amt - (case when rnd_amt is null then 0 else rnd_amt end))*exch_rate, "
+ " rnd_amt = 0 where tran_id = ? and confirmed = 'Y' ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update rcp_ibca failed ",errCode, conn);
break;
}
sql = "delete from misc_payables where tran_ser = ? and ref_no = ? and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update rcp_ibca failed ",errCode, conn);
break;
}
sql = "select vouch_type from voucher where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
vouchType = rs.getString("vouch_type");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (!"A".equals(vouchType ))
{
sql = "delete from vouchdet where tran_id = ( select tran_id from voucher where tran_id = ? and vouch_type <> 'A') ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update rcp_ibca failed ",errCode, conn);
break;
}
}
}
else if ( "M-VOUC".equals(refSer)) // Payable voucher
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "select count(1) as count from misc_vouchadv where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("count");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( count != 0)
{
sql = "select ref_ser, ref_no, adj_amt from misc_vouchadv where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
refSerAdv = rs.getString("ref_ser");
refNoAdv = rs.getString("ref_no");
adjAmtAdv = rs.getDouble("adj_amt");
sql = "update misc_payables set adj_amt = adj_amt - ? where tran_ser = ? and ref_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, adjAmtAdv);
pstmtUpd.setString(2, refSerAdv);
pstmtUpd.setString(3, refNoAdv);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "MVOUCHADV";
errString = getMsg("Update misc_payables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "select vouch_type from misc_voucher where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
vouchType = rs.getString("vouch_type");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "update misc_voucher set confirmed = 'N', net_amt = net_amt - rnd_amt, "
+ " net_amt__bc = (net_amt - rnd_amt)*exch_rate, rnd_amt = 0 "
+ " where tran_id = ? and confirmed = 'Y' ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_voucher failed ",errCode, conn);
break;
}
// Rajesh Nair 18/03/04
if ("A".equals(vouchType ))
{
sql = "delete from misc_payables "
+" where ltrim(rtrim(tran_ser))= 'M-ADV' " //prince 21-03-06
+ " and ref_no = ?"
+ " and adj_amt = 0 " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_voucher failed ",errCode, conn);
break;
}
}
// Rajesh Nair
sql = "delete from misc_payables "
+ " where tran_ser = ? " //:
+ " and ref_no = ? " //:
+ " and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_voucher failed ",errCode, conn);
break;
}
sql = "delete from misc_vouchacct where tran_id = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_voucher failed ",errCode, conn);
break;
}
}
else if ( "P-VOUC".equals(refSer)) // payroll voucher
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update payr_voucher set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update payr_voucher failed ",errCode, conn);
break;
}
sql = "select count(1) as count from payr_vouchadv where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("count");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "delete from misc_payables where tran_ser = ? and ref_no = ? and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update payr_voucher failed ",errCode, conn);
break;
}
}
else if("MDRCRC".equals(refSer) || "MDRCRD".equals(refSer)) // misc credit / debit note
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update misc_drcr_rcp set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_drcr_rcp failed ",errCode, conn);
break;
}
sql = "delete from receivables where tran_ser = ? and ref_no = ? and adj_amt = 0 ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Delete receivables failed ",errCode, conn);
break;
}
}
else if ( "E-PAY".equals(refSer)) // direct payments
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update payment_exp set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update payment_exp failed ",errCode, conn);
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update banktran_log failed ",errCode, conn);
break;
}
}
else if ( "M-PAY".equals(refSer)) // // payments
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update misc_payment set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_payment failed ",errCode, conn);
break;
}
// cursor for updating misc_payables
sql = "select tran_ser, vouch_no, pay_amt from misc_paydet where tran_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
paySer = rs.getString("tran_ser");
paymentNo = rs.getString("vouch_no");
payAmount = rs.getDouble("pay_amt");
sql = "update misc_payables set adj_amt = adj_amt - ? where tran_ser = ? and ref_no = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, payAmount);
pstmtUpd.setString(2, paySer);
pstmtUpd.setString(3, paymentNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_payables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Delete of banktran_log failed ",errCode, conn);
break;
}
}
else if ( "MPCANC".equals(refSer)) // payment cancellation
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update misc_payment_canc set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_payment_canc failed ",errCode, conn);
break;
}
// cursor for updating misc_payables
sql = "select tran_ser, vouch_no, pay_amt from misc_payment_cancdet where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
paySer = rs.getString("tran_ser");
paymentNo = rs.getString("vouch_no");
payAmount = rs.getDouble("pay_amt");
sql = "update misc_payables set adj_amt = adj_amt + ? where tran_ser = ? and ref_no = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, payAmount);
pstmtUpd.setString(2, paySer);
pstmtUpd.setString(3, paymentNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_payables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Delete of banktran_log failed ",errCode, conn);
break;
}
}
else if ( "M-RCP".equals(refSer)) // misc receipts
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update misc_receipt set confirmed = 'N' where tran_id = ? and confirmed = 'Y' ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_receipt failed ",errCode, conn);
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_receipt failed ",errCode, conn);
break;
}
}
else if ( "R-DIS".equals(refSer)) // receipt dishonour
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update rcpdishnr set confirmed = 'N' where tran_id = ? and confirmed = 'Y' ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update misc_receipt failed ",errCode, conn);
break;
}
// cursor for updating receivables
sql = "select ref_ser, ref_no, rcp_amt from rcpdishnr_det where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
paySer = rs.getString("ref_ser");
paymentNo = rs.getString("ref_no");
payAmount = rs.getDouble("rcp_amt");
sql = "update receivables set adj_amt = adj_amt + ? where tran_ser = ? and ref_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, payAmount);
pstmtUpd.setString(2, paySer);
pstmtUpd.setString(3, paymentNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update receivables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ?" ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update banktran_log failed ",errCode, conn);
break;
}
}
else if ( "F-XFR".equals(refSer)) // fundtransfer
{
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
sql = "update fundtransfer set status = 'E' where tran_id = ? and status = 'C'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update fundtransfer failed ",errCode, conn);
break;
}
sql = "delete from banktran_log where tran_ser = ? and tran_no = ?" ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update banktran_log failed ",errCode, conn);
break;
}
}
else if ( "S-INV".equals(refSer)) // invoice
{
// 23-08-04 manoharan
// receivables_adj to be reverse updated
errString = updRecAdj(refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
// end 23-08-04 manoharan
sql = "update invoice set confirmed = 'N' where invoice_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update invoice failed ",errCode, conn);
break;
}
sql = "delete from invacct where invoice_id = ?" ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Delete invacct failed ",errCode, conn);
break;
}
sql = "delete from receivables where tran_ser = ? and ref_no = ? and adj_amt = 0" ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Delete invacct failed ",errCode, conn);
break;
}
}
else if ( "RCP".equals(refSer)) // added by sheetal as on 18/09/02
{
// specific unpost only for cases where receipt has been booked as advances
errString = unPost(refSer, refId, conn);
if(errString != null && errString.trim().length() > 0 )
{
break;
}
// added by shiri 20/02/06 - to unpost receivables JV
sql = "select chq_amt from receipt where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
chqAmount = rs.getInt("chq_amt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "update receipt set confirmed = 'N' where tran_id = ? and confirmed = 'Y'";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DSNR00";
errString = getMsg("Update of receipt failed ",errCode, conn);
break;
}
sql = "delete from receivables where tran_ser = 'R-ADV' and ref_no = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
sql = "delete from banktran_log where tran_ser = ? and tran_no = ?";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
// amish 27-03-06 delete from rcpacct
sql = "delete from rcpacct where tran_id = ? "
+ " and ( acct_code in (select acct_code__adv from receipt where tran_id = rcpacct.tran_id ) or "
+ " acct_code in (select acct_code__ar from rcpdet where tran_id = rcpacct.tran_id ) ) ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
// cursor for updating receivables
sql = "select ref_ser, ref_no, rcp_amt from rcpdet where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refId);
rs = pstmt.executeQuery();
while(rs.next())
{
paySer = rs.getString("ref_ser");
paymentNo = rs.getString("ref_no");
payAmount = rs.getDouble("rcp_amt");
sql = "update receivables set adj_amt = adj_amt - ? where tran_ser = ? and ref_no = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, payAmount);
pstmtUpd.setString(2, paySer);
pstmtUpd.setString(3, paymentNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("Update receivables failed ",errCode, conn);
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
errCode = "SORRY";
errString = getMsg("Transation series unposting not implemented ",errCode, conn);
break;
}
break;
}
if (errString == null || errString.trim().length() == 0)
{
conn.commit();
}
else
{
conn.rollback();
}
}
System.out.println("Error string after loop ["+errString + "]");
if (errString == null || errString.trim().length() == 0)
{
errCode = "PRCSUCES";
errString = getMsg("Unposting completed",errCode, conn);
}
}
catch(Exception exception)
{
exception.printStackTrace();
throw new ITMException(exception);
}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if (pstmtUpd != null)
{
pstmtUpd.close();
pstmtUpd = null;
}
if (finCommon != null)
{
finCommon = null;
}
if (distCommon != null)
{
distCommon = null;
}
if (genericUtility != null)
{
genericUtility = null;
}
}
System.out.println("Return string from UnPost(1) ["+errString + "]");
return errString ;
}
private String unPost(String refSer, String refId, Connection conn) throws ITMException
{
String errCode = "", errString = "", acctPrd = "", prdCode = "", siteCode = "", acctCode = "", sundryType = "", sundryCode= "";
String cctrCode = "", entryBatchNo = "", postType = "", tranIdTrace = "",acctCodeCoinDiff = "", sql = "";
String cctrCodeCoinDiff = "", ledgPostCoinDiff = "", postStat = "", cctrCodeUpd = "", cctrCodesundryBal = "";
double drAmount = 0, crAmount = 0, drAmountBase = 0, crAmountBase = 0, totalDrAmount = 0, totalCrAmount = 0, diffAmount = 0, exchRate = 0;
int glTraceCnt =0, glTranCnt = 0, count = 0;
double tempAmount1 = 0, tempAmount2 = 0;
PreparedStatement pstmt = null, pstmt1 = null, pstmtUpd = null;
ResultSet rs = null, rs1 = null;
try
{
acctCodeCoinDiff = finCommon.getFinparams("999999", "COIN_ACCT", conn);
if ("NULLFOUND".equals(acctCodeCoinDiff))
{
errCode = "VSENVAR1";
errString = getMsg("FINPARM COIN_ACCT not defined",errCode, conn);
return errString;
}
cctrCodeCoinDiff = finCommon.getFinparams("999999", "COIN_CCTR", conn);
if ("NULLFOUND".equals(cctrCodeCoinDiff))
{
cctrCodeCoinDiff = " ";
}
acctCodeCoinDiff = acctCodeCoinDiff.trim();
cctrCodeCoinDiff = cctrCodeCoinDiff.trim();
if (cctrCodeCoinDiff.trim().length() == 0)
{
cctrCodeCoinDiff = " ";
}
sql = "select ledg_post from accounts where acct_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, acctCodeCoinDiff);
rs = pstmt.executeQuery();
if(rs.next())
{
ledgPostCoinDiff = rs.getString("ledg_post");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (ledgPostCoinDiff == null || "null".equals(ledgPostCoinDiff))
{
ledgPostCoinDiff = "D";
}
// 04-11-04 manoharan moved from inside loop
// not required in side the loop
// SHEETAL ADDED THE FOLLOWING - - 4/3/02
cctrCodeUpd = finCommon.getFinparams("999999", "SUND_UPD_CCTR", conn);
if ("NULLFOUND".equals(acctCodeCoinDiff))
{
errCode = "VSENVAR1";
errString = getMsg("FINPARM SUND_UPD_CCTR not defined",errCode, conn);
return errString;
}
if (!"Y".equals(cctrCodeUpd) && !"N".equals(cctrCodeUpd))
{
errCode = "VTFINPARM1";
errString = getMsg("The values of SUND_UPD_CCTR should be Y or N",errCode, conn);
return errString;
}
// END OF SHEETAL - 4/3/02
// end 04-11-04 manoharan moved from inside loop
refSer = refSer.trim();
glTraceCnt = 0;
totalDrAmount = 0;
totalCrAmount = 0;
sql = "select gltrace.tran_id as tran_id, gltrace.acct_prd as acct_prd, gltrace.prd_code as prd_code, gltrace.site_code as site_code, gltrace.acct_code as acct_code, "
+ " gltrace.cctr_code as cctr_code, gltrace.sundry_type as sundry_type, gltrace.sundry_code as sundry_code, gltrace.dr_amt as dr_amt, "
+ " gltrace.cr_amt as cr_amt, gltrace.exch_rate as exch_rate, gltrace.entry_batch_no as entry_batch_no, "
+ " (case when accounts.ledg_post is null then 'D' else accounts.ledg_post end) as ledg_post, "
+ " (case when gltrace.post_stat is null then 'N' else gltrace.post_stat end) as post_stat "
+ " from gltrace, accounts "
+ " where gltrace.acct_code = accounts.acct_code "
+ " and ref_ser = ? "
+ " and ref_id = ? " ;
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, refSer);
pstmt1.setString(2, refId);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
tranIdTrace = rs1.getString("tran_id");
acctPrd = rs1.getString("acct_prd");
prdCode = rs1.getString("prd_code");
siteCode = rs1.getString("site_code");
acctCode = rs1.getString("acct_code");
cctrCode = rs1.getString("cctr_code");
sundryType = rs1.getString("sundry_type");
sundryCode = rs1.getString("sundry_code");
drAmount = rs1.getDouble("dr_amt");
crAmount = rs1.getDouble("cr_amt");
exchRate = rs1.getDouble("exch_rate");
entryBatchNo = rs1.getString("entry_batch_no");
postType = rs1.getString("ledg_post");
postStat = rs1.getString("post_stat");
totalDrAmount = totalDrAmount + (drAmount * exchRate) ;
totalCrAmount = totalCrAmount + (crAmount * exchRate) ;
totalDrAmount = getReqDecimal(totalDrAmount, 3) ;
totalCrAmount = getReqDecimal(totalCrAmount, 3) ;
glTraceCnt++;
if (drAmount != 0 || crAmount != 0)
{
if(entryBatchNo == null || "null".equals(entryBatchNo))
{
entryBatchNo = "";
}
drAmountBase = drAmount * exchRate ;
crAmountBase = crAmount * exchRate ;
if (!"O".equals(sundryType))
{
if (!"Y".equals(cctrCodeUpd))
{
cctrCodesundryBal = " ";
}
else
{
cctrCodesundryBal = cctrCode;
}
// undo sundrybal
sql = "update sundrybal "
+ " set dr_amt = dr_amt - ?, "
+" cr_amt = cr_amt - ?, "
+ " dr_amt__base = dr_amt__base - ?, "
+ " cr_amt__base = cr_amt__base - ? "
+ " where acct_prd = ? "
+ " and prd_code in (?, 'zzzzzz') "
+ " and site_code = ? "
+ " and sundry_type = ? "
+ " and sundry_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, drAmount);
pstmtUpd.setDouble(2, crAmount);
pstmtUpd.setDouble(3, drAmountBase);
pstmtUpd.setDouble(4, crAmountBase);
pstmtUpd.setString(5, acctPrd);
pstmtUpd.setString(6, prdCode);
pstmtUpd.setString(7, siteCode);
pstmtUpd.setString(8, sundryType);
pstmtUpd.setString(9, sundryCode);
pstmtUpd.setString(10, acctCode);
pstmtUpd.setString(11, cctrCodesundryBal);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 2)
{
errCode = "DS000NR1";
errString = getMsg("Insert Into SUNDRYBAL Failed For Period :[" +prdCode +"]",errCode, conn);
break;
}
}
if ("Y".equals(postStat ))
{
// unpost gltran
if("D".equals(postType))
{
sql = "delete from gltran where ref_ser = ? and ref_id = ? and tran_id__trace = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
pstmtUpd.setString(3, tranIdTrace);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR1";
errString = getMsg("delete gltrace failed for ref_id :[" +refId +"]",errCode, conn);
break;
}
}
else if ("S".equals(postType))
{
// // unpost summ.
// // reduce from gltran
//
// // amit-06-04-02
// String ls_var1
// // long ll_c1
// // declare lcur_test(lc_v1,lc_v2) cursor for
// // select TRAN_ID from gltran
// // where acct_prd = :acctPrd
// // and prd_code = :prdCode
// // and site_code = :siteCode
// // and acct_code = :acctCode
// // and cctr_code = :cctrCode
// // and (dr_amt = 0 or dr_amt = lc_v1 )
// // and (cr_amt =0 or cr_amt = lc_v2) ;
// // open lcur_test(:drAmount,:crAmount;
// // if sqlca.sqlcode < 0 then
// // errCode = 'DS000NR' + ' ~t ' + sqlca.sqlerrtext
// // exit
// // end if
// // do while sqlca.sqlcode = 0
// // fetch lcur_test into :ls_var1 ;
// // messagebox('aa',ls_var1)
// // loop
// // close lcur_test ;
//
// // shiri 25/7/02 changed to include ref ser and remove dr amt and cr amt checking
// // and also the next not found condition is commented as the record must be found
// select tran_id into :ls_var1 from gltran
// where acct_prd = :acctPrd
// and prd_code = :prdCode
// and site_code = :siteCode
// and acct_code = :acctCode
// and cctr_code = :cctrCode
// and ref_ser = :refSer ;
// // and dr_amt = :drAmount
// // and cr_amt = :crAmount ;
// if sqlca.sqlcode < 0 then
// errCode = 'DS000NR' + ' ~t ' + sqlca.sqlerrtext
// exit
// // elseif sqlca.sqlnrows = 0 then
// // select tran_id into :ls_var1 from gltran
// // where acct_prd = :acctPrd
// // and prd_code = :prdCode
// // and site_code = :siteCode
// // and acct_code = :acctCode
// // and cctr_code = :cctrCode
// // and dr_amt <> 0 and cr_amt <> 0 ;
// // and ref_ser = :refSer
// end if
// if sqlca.sqlcode < 0 then
// errCode = 'DS000NR' + ' ~t ' + sqlca.sqlerrtext
// exit
// elseif sqlca.sqlcode = 100 then
// errCode = 'DS000100'
// exit
// end if
// // end amit-06-04-02
//
// update gltran
// set dr_amt = dr_amt - :drAmount,
// cr_amt = cr_amt - :crAmount
// where tran_id = :ls_var1 ;
// // acct_prd = :acctPrd
// // and prd_code = :prdCode
// // and site_code = :siteCode
// // and acct_code = :acctCode
// // and cctr_code = :cctrCode
// // and dr_amt > 0 and cr_amt > 0 ;
// // and ref_ser = :refSer ;
// if sqlca.sqlcode < 0 then
// errCode = 'DS000' + String(sqlca.sqldbcode) + ' ~t ' + ' : ' + sqlca.sqlerrtext
// exit
// elseif sqlca.sqlnrows <> 1 then
// errCode = 'DS000NR1A'
// exit
// end if
// // amit-06-04-02
//
////////////////////////////////////////////////////////////////////////////////////
// 04-11-04 manoharan script re-written to
// consider entry_batch_no for summary type posting
//
if("S-INV".equals(refSer) || "D-ISS".equals(refSer)
|| "D-RCP".equals(refSer) || "S-DSP".equals(refSer)
|| "P-RCP".equals(refSer) || "C-ISS".equals(refSer)
|| "W-ISS".equals(refSer) || "W-RCP".equals(refSer)
|| "ADJISS".equals(refSer) || "ADJRCP".equals(refSer)
|| "VOUCH".equals(refSer) || "CRNRCP".equals(refSer)
|| "DRNRCP".equals(refSer) || "MDRCRC".equals(refSer)
|| "MDRCRD".equals(refSer) || "P-VOUC".equals(refSer)
|| "RCP".equals(refSer) || "R-DIS".equals(refSer)
|| "M-RCP".equals(refSer) || "M-PAY".equals(refSer)
|| "MPCANC".equals(refSer) || "E-PAY".equals(refSer)
|| "S-RET".equals(refSer) || "P-RET".equals(refSer)
|| "M-VOUC".equals(refSer) || "P-IBCA".equals(refSer)
|| "R-IBCA".equals(refSer) )
{
entryBatchNo = refSer.trim() + prdCode.trim();
}
else
{
entryBatchNo = " " ;
}
sql = "select count(1) as count from gltran "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and tran_id__trace = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, acctPrd);
pstmt.setString(2, prdCode);
pstmt.setString(3, siteCode);
pstmt.setString(4, acctCode);
pstmt.setString(5, cctrCode);
pstmt.setString(6, refSer);
pstmt.setString(7, entryBatchNo);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("count");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (count > 1 )
{
// multiple records found for summ. updation
errCode = "VTGLTRAN1";
errString = getMsg("Duplicate records for summary updation were found in gltran for summary type posing [" +refSer +"]",errCode, conn);
break;
}
else if (count == 1)
{
sql = "update gltran set dr_amt = dr_amt - ?, "
+ " cr_amt = cr_amt - ? "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and tran_id__trace = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, drAmountBase);
pstmtUpd.setDouble(2, crAmountBase);
pstmtUpd.setString(3, acctPrd);
pstmtUpd.setString(4, prdCode);
pstmtUpd.setString(5, siteCode);
pstmtUpd.setString(6, acctCode);
pstmtUpd.setString(7, cctrCode);
pstmtUpd.setString(8, refSer);
pstmtUpd.setString(9, entryBatchNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR1A";
errString = getMsg("Error updating gltran [" +refSer +"]",errCode, conn);
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
sql = "select dr_amt, cr_amt from gltran "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and tran_id__trace = ? " ;
//where tran_id = :ls_var1 ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, acctPrd);
pstmt.setString(2, prdCode);
pstmt.setString(3, siteCode);
pstmt.setString(4, acctCode);
pstmt.setString(5, cctrCode);
pstmt.setString(6, refSer);
pstmt.setString(7, entryBatchNo);
rs = pstmt.executeQuery();
if(rs.next())
{
tempAmount1 = rs.getDouble("dr_amt");
tempAmount2 = rs.getDouble("cr_amt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (tempAmount1 < 0 || tempAmount2 < 0 )
{
errCode = "wrong amount";
errString = getMsg("Wrong update amount goes negative in gltran [" +refSer +"]",errCode, conn);
break;
}
// end amit-06-04-02
}
else
{
errCode = "error";
errString = getMsg("Invalid lpost type for account [" +acctCode +"]",errCode, conn);
break;
}
// undo acctbal
sql = "update acctbal set dr_amt = dr_amt - ?, "
+ " cr_amt = cr_amt - ?, "
+ " dr_amt__base = dr_amt__base - ?, "
+ " cr_amt__base = cr_amt__base - ? "
+ " where acct_prd = ? "
+ " and prd_code in (?, 'zzzzzz') "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, drAmount);
pstmtUpd.setDouble(2, crAmount);
pstmtUpd.setDouble(3, drAmountBase);
pstmtUpd.setDouble(4, crAmountBase);
pstmtUpd.setString(5, acctPrd);
pstmtUpd.setString(6, prdCode);
pstmtUpd.setString(7, siteCode);
pstmtUpd.setString(8, acctCode);
pstmtUpd.setString(9, cctrCode);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if ( count != 2)
{
errCode = "DS000NR1B";
errString = getMsg("Invalid count for update of acctbal [" +acctCode +"]",errCode, conn);
break;
}
// end unpost gltran
}
}
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
if (errString != null && errString.trim().length() > 0 )
{
return errString;
}
totalDrAmount = getReqDecimal(totalDrAmount, 2) ;
totalCrAmount = getReqDecimal(totalCrAmount, 2) ;
if (totalDrAmount != totalCrAmount)
{
String coinDiffLimit = finCommon.getFinparams("999999", "COIN_DIFF_LIMIT", conn);
coinDiffLimit = coinDiffLimit == null ? "1" : coinDiffLimit;
if(coinDiffLimit.trim().length() == 0 || coinDiffLimit.trim().equalsIgnoreCase("NULLFOUND"))
{
coinDiffLimit = "1";
}
diffAmount = totalDrAmount - totalCrAmount;
if(Math.abs(diffAmount) > Double.parseDouble(coinDiffLimit))
{
errCode = "VCOINDIFF1";
errString = getMsg("Difference in debit and credit [" + Math.abs(diffAmount) +"] exceeds limit [" +coinDiffLimit +"]",errCode, conn);
return errString;
}
if ( diffAmount > 0 )
{
crAmount = diffAmount;
drAmount = 0;
crAmountBase = diffAmount;
drAmountBase = 0;
}
else
{
drAmount = diffAmount;
crAmount = 0;
drAmountBase = diffAmount;
crAmountBase = 0;
}
sql = "update acctbal set dr_amt = dr_amt - ?,"
+ " cr_amt = cr_amt - ?, "
+ " dr_amt__base = dr_amt__base - ?, "
+ " cr_amt__base = cr_amt__base - ? "
+ " where acct_prd = ? "
+ " and prd_code in (?, 'zzzzzz') "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, drAmount);
pstmtUpd.setDouble(2, crAmount);
pstmtUpd.setDouble(3, drAmountBase);
pstmtUpd.setDouble(4, crAmountBase);
pstmtUpd.setString(5, acctPrd);
pstmtUpd.setString(6, prdCode);
pstmtUpd.setString(7, siteCode);
pstmtUpd.setString(8, acctCodeCoinDiff);
pstmtUpd.setString(9, cctrCodeCoinDiff);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if ( count != 2)
{
errCode = "DS000NR1C";
errString = getMsg("Invalid count for update of acctbal [" +acctCodeCoinDiff +"]",errCode, conn);
return errString;
}
if("S-INV".equals(refSer) || "D-ISS".equals(refSer)
|| "D-RCP".equals(refSer) || "S-DSP".equals(refSer)
|| "P-RCP".equals(refSer) || "C-ISS".equals(refSer)
|| "W-ISS".equals(refSer) || "W-RCP".equals(refSer)
|| "ADJISS".equals(refSer) || "ADJRCP".equals(refSer)
|| "VOUCH".equals(refSer) || "CRNRCP".equals(refSer)
|| "DRNRCP".equals(refSer) || "MDRCRC".equals(refSer)
|| "MDRCRD".equals(refSer) || "P-VOUC".equals(refSer)
|| "RCP".equals(refSer) || "R-DIS".equals(refSer)
|| "M-RCP".equals(refSer) || "M-PAY".equals(refSer)
|| "MPCANC".equals(refSer) || "E-PAY".equals(refSer)
|| "S-RET".equals(refSer) || "P-RET".equals(refSer)
|| "M-VOUC".equals(refSer) || "P-IBCA".equals(refSer)
|| "R-IBCA".equals(refSer) )
{
entryBatchNo = refSer.trim() + prdCode.trim();
}
else
{
entryBatchNo = " " ;
}
if("S".equals(ledgPostCoinDiff))
{
sql = "update gltran set dr_amt = dr_amt - ?, "
+ " cr_amt = cr_amt - ? "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and tran_id__trace = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, drAmount);
pstmtUpd.setDouble(2, crAmount);
pstmtUpd.setString(3, acctPrd);
pstmtUpd.setString(4, prdCode);
pstmtUpd.setString(5, siteCode);
pstmtUpd.setString(6, acctCodeCoinDiff);
pstmtUpd.setString(7, cctrCodeCoinDiff);
pstmtUpd.setString(8, refSer);
pstmtUpd.setString(9, entryBatchNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR1D";
errString = getMsg("Error updating gltran [" +refSer +"]",errCode, conn);
return errString;
}
}
else
{
// in case there is a difference in total debit/credit in gltrace
// as there is no corresponding row in gltrace table during posting
// the following logic is used, the same is repeated here
// get the entry_batch_no using a cursor as done during posting
sql = "select gltrace.entry_batch_no as entry_batch_no from gltrace, finent "
+ " where gltrace.fin_entity = finent.fin_entity "
+ " and gltrace.ref_ser = ? "
+ " and gltrace.ref_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refSer);
pstmt.setString(2, refId);
rs = pstmt.executeQuery();
if(rs.next())
{
entryBatchNo = rs.getString("entry_batch_no");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "select count(1) as count from gltran "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and ref_id = ? "
+ " and tran_id__trace = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, acctPrd);
pstmt.setString(2, prdCode);
pstmt.setString(3, siteCode);
pstmt.setString(4, acctCodeCoinDiff);
pstmt.setString(5, cctrCodeCoinDiff);
pstmt.setString(6, refSer);
pstmt.setString(7, refId);
pstmt.setString(8, entryBatchNo);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("count");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (count > 1 )
{
// multiple records found for summ. updation
errCode = "VTGLTRAN1";
errString = getMsg("Duplicate records for coin difference updation were found in gltran [" +refSer +"]",errCode, conn);
return errString;
}
else if (count == 1)
{
sql = "delete from gltran "
+ " where acct_prd = ? "
+ " and prd_code = ? "
+ " and site_code = ? "
+ " and acct_code = ? "
+ " and cctr_code = ? "
+ " and ref_ser = ? "
+ " and ref_id = ? "
+ " and tran_id__trace = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, acctPrd);
pstmtUpd.setString(2, prdCode);
pstmtUpd.setString(3, siteCode);
pstmtUpd.setString(4, acctCodeCoinDiff);
pstmtUpd.setString(5, cctrCodeCoinDiff);
pstmtUpd.setString(6, refSer);
pstmtUpd.setString(7, refId);
pstmtUpd.setString(8, entryBatchNo);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR1D";
errString = getMsg("Error deleting gltran [" +refSer +"]",errCode, conn);
return errString;
}
}
}
}
sql = "delete from gltrace where ref_ser = ? and ref_id = ? ";
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setString(1, refSer);
pstmtUpd.setString(2, refId);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != glTraceCnt)
{
errCode = "DS000NR2";
errString = getMsg("Error deleting gltrace [" +refSer +"]",errCode, conn);
return errString;
}
}
catch(Exception exception)
{
exception.printStackTrace();
throw new ITMException(exception);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if (pstmtUpd != null)
{
pstmtUpd.close();
pstmtUpd = null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("Return string from UnPost(2) ["+errString + "]");
return (errString);
}
private String updRecAdj (String invoiceId, Connection conn) throws ITMException, Exception
{
String errCode = "", errString = "", refNO = "", refSer = "", refNoAdj = "", contactCode= "";
String refSerAdj = "", tranID = "", tranIDReceivable = "", status = "", tranIdRcv = "";
double totalAmount = 0, adjAmount = 0, netAmount = 0, recTotal = 0, recAdj,exchRate = 0;
Timestamp statDate = null, tranDate = null, effDate = null;
String finEntity = "", siteCode = "", custCode = "", acctCode = "", cctrCode = "",currCode = "", sql = "";
HashMap sundryBalMap = null;
PreparedStatement pstmt = null, pstmt1 = null, pstmtUpd = null;
ResultSet rs = null, rs1 = null;
int count = 0;
try
{
//// Changed By Surender : 17/05/2001 as per MR Kandarp Inst.
//select tran_id into :tranIdRcv
//from receivables
//where tran_ser = 'S-INV' and
// ref_no = :invoiceId ;
//if get_sqlcode() < 0 then
// errCode = "DS000" + String(sqlca.sqldbcode)
// return errCode
//end if
//
//update receivables_adj
// set tran_id__rcv = :tranIdRcv
// WHERE ref_ser = 'S-INV' AND
// ref_no = :invoiceId AND
// tran_id__rcv = ' ' ;
//if get_sqlcode() < 0 then
// errCode = "DS000" + String(sqlca.sqldbcode)
// return errCode
//end if
////
sql = " SELECT tran_id, ref_ser, ref_no, tot_amt, adj_amt, ref_ser_adj, ref_no_adj, net_amt, tran_id__rcv "
+ " FROM receivables_adj "
+ " WHERE ((ref_ser = 'S-INV' AND ref_no = ?) OR (ref_ser_adj = 'S-INV' AND ref_no_adj = ?)) " ;
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, invoiceId);
pstmt1.setString(2, invoiceId);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
tranID = rs1.getString("tran_id");
refSer = rs1.getString("ref_ser");
refNO = rs1.getString("ref_no");
totalAmount = rs1.getDouble("tot_amt");
adjAmount = rs1.getDouble("adj_amt");
refSerAdj = rs1.getString("ref_ser_adj");
refNoAdj = rs1.getString("ref_no_adj");
netAmount = rs1.getDouble("net_amt");
tranIDReceivable = rs1.getString("tran_id__rcv");
sql = "select tot_amt, adj_amt from receivables where tran_ser = ? and ref_no = ?" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refSer);
pstmt.setString(2, refNO);
rs = pstmt.executeQuery();
if(rs.next())
{
recTotal = rs.getDouble("tot_amt");
recAdj = rs.getDouble("adj_amt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
// if recTotal = (adjAmount + recAdj) then
// status = 'A'
// else
status = "P";
// end if
statDate = (Timestamp) Calendar.getInstance().getTime();
sql = "update receivables "
+" set adj_amt = adj_amt - ?, "
+ " status = ?, "
+ " stat_date = ? "
+ " where tran_ser = ? "
+ " ref_no = ? " ;
pstmtUpd = conn.prepareStatement(sql);
pstmtUpd.setDouble(1, adjAmount);
pstmtUpd.setString(2, status);
pstmtUpd.setTimestamp(3, statDate);
pstmtUpd.setString(4, refSer);
pstmtUpd.setString(5, refNO);
count = pstmtUpd.executeUpdate();
pstmtUpd.close();
pstmtUpd = null;
if(count != 1)
{
errCode = "DS000NR";
errString = getMsg("updte receivable failed ",errCode, conn);
break;
}
// update sundrybal for adv amt > 0 - zahid 14/05/04
if ("R-ADV".equals(refSer))
{
sql = "select fin_entity, site_code, cust_code, acct_code, cctr_code,curr_code, exch_rate "
+ " from receivables where tran_ser = ? and ref_no = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refSer);
pstmt.setString(2, refNO);
rs = pstmt.executeQuery();
if(rs.next())
{
finEntity = rs.getString("fin_entity");
siteCode = rs.getString("site_code");
custCode = rs.getString("cust_code");
acctCode = rs.getString("acct_code");
cctrCode = rs.getString("cctr_code");
currCode = rs.getString("curr_code");
exchRate = rs.getDouble("exch_rate");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "select tran_date,eff_date "
+ " from invoice where invoice_id = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, invoiceId);
rs = pstmt.executeQuery();
if(rs.next())
{
tranDate = rs.getTimestamp("tran_date");
effDate = rs.getTimestamp("eff_date");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sundryBalMap = new HashMap();
sundryBalMap.put("tran_date",new Timestamp(tranDate.getTime()));
sundryBalMap.put("eff_date",new Timestamp(effDate.getTime()));
sundryBalMap.put("fin_entity", finEntity);
sundryBalMap.put("site_code", siteCode);
sundryBalMap.put("sundry_type", "C");
sundryBalMap.put("sundry_code", custCode);
sundryBalMap.put("acct_code", acctCode);
sundryBalMap.put("cctr_code", cctrCode);
contactCode = finCommon.getContactCode("C",custCode, conn);
sundryBalMap.put("contact_code", contactCode);
sundryBalMap.put("curr_code", currCode);
sundryBalMap.put("exch_rate", exchRate);
sundryBalMap.put("dr_amt", 0.0);
sundryBalMap.put("cr_amt", 0.0);
sundryBalMap.put("adv_amt", -1 * adjAmount);
errString = finCommon.gbf_sundrybal_upd(sundryBalMap,conn);
sundryBalMap = null;
if(errString.trim().length() > 0 )
{
break;
}
}
//zahid end
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
catch(Exception exception)
{
exception.printStackTrace();
throw new ITMException(exception);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if (pstmtUpd != null)
{
pstmtUpd.close();
pstmtUpd = null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
return errString;
}
private String getMsg(String trace,String Code,Connection conn) throws ITMException, Exception
{
String mainStr ="";
try
{
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String errString = "";
errString = itmDBAccessEJB.getErrorString("",Code,"","",conn);
String begPart = errString.substring(0,errString.indexOf("<message>")+9);
String begDesc = errString.substring(0,errString.indexOf("<description>")+13);
String endDesc = errString.substring(errString.indexOf("</description>"));
mainStr= begPart + trace + " </message><description>";
mainStr= mainStr+endDesc;
begPart = null;
itmDBAccessEJB = null;
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return mainStr;
}
private double getReqDecimal(double actVal, int prec) throws ITMException, Exception
{
String fmtStr = "############0";
String strValue = null;
double retVal = 0;
if (prec > 0)
{
fmtStr = fmtStr + "." + "000000000".substring(0, prec);
}
DecimalFormat decFormat = new DecimalFormat(fmtStr);
retVal = Double.parseDouble(decFormat.format(actVal));
if (Math.abs(retVal) == 0)
{
retVal = 0;
}
return retVal;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment