Commit fee56bd1 authored by prane's avatar prane

Validation for tax calculation per tax environment configuration for Despatche

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@203822 ce508802-f39f-4f6c-b175-0d175dae99d5
parent d712c2b0
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class InvoiceProformaIC extends ValidatorEJB implements InvoiceProformaICLocal, InvoiceProformaICRemote {
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag,String xtraParams) throws RemoteException, ITMException
{
System.out.println("---------- InvoiceProformaIC :: wfValData() ----------");
String errString = "";
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() > 0) {
dom = parseString(xmlString);
System.out.println("xmlString[" + xmlString + "]");
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
dom1 = parseString(xmlString1);
System.out.println("xmlString1[" + xmlString1 + "]");
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
dom2 = parseString(xmlString2);
System.out.println("xmlString2[" + xmlString2 + "]");
}
errString = wfValData(dom, dom1, dom2, objContext, editFlag,
xtraParams);
} catch (Exception e) {
throw new ITMException(e);
}
return (errString);
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
System.out.println("---------- InvoiceProformaIC :: wfValData() ----------");
E12GenericUtility genericUtility = new E12GenericUtility();
System.out.println("PavanR :: DOM ["+genericUtility.serializeDom(dom)+"]\n\n");
System.out.println("PavanR :: DOM1 ["+genericUtility.serializeDom(dom1)+"]\n\n");
System.out.println("PavanR :: DOM2 ["+genericUtility.serializeDom(dom2)+"]\n\n");
int ctr = 0;
int childNodeListLength;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
Connection conn = null;
PreparedStatement pstmt = null,pstmt1=null;
ResultSet rs = null,rs1=null;
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
int currentFormNo = 0;
String errorType="";
String childNodeName = null;
String errString = "", errCode = "", userId = "", sql = "", sqlInner = "";
String taxEnv = "", despId = "", despLine = "", despNoFr = "", despNoTo = "";
int taxEnvCnt = 0;
int taxCount = 0;
ArrayList<String> lineList = null;
HashMap<String, ArrayList<String>> DespMap = new HashMap<String, ArrayList<String>>();
try {
conn = getConnection();
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("childNodeName>>>>["+childNodeName+"]");
if ( (childNodeName.equalsIgnoreCase("as_desp_id_fr")))
{
despNoFr = checkNull(genericUtility.getColumnValue("as_desp_id_fr", dom));
despNoTo = checkNull(genericUtility.getColumnValue("as_desp_id_to", dom));
sql = "select b.desp_id, b.line_no, b.tax_env from despatch a, despatchdet b "
+ " where a.desp_id = b.desp_id and a.desp_id >= ?"
+ " and a.desp_id <= ?";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, despNoFr);
pstmt.setString(2, despNoTo);
rs = pstmt.executeQuery();
while( rs.next() )
{
lineList = new ArrayList<String>();
despId = "";
despLine = "";
taxEnv = "";
despId = rs.getString("desp_id");
despLine = rs.getString("line_no");
taxEnv = rs.getString("tax_env");
System.out.println("inside while.....despId["+despId+"]despLine["+despLine+"]taxEnv["+taxEnv+"]");
if (taxEnv != null && taxEnv.trim().length() > 0)
{
sqlInner = "select count(1) from tenvseq where ref_ser = 'S-DSP' and tax_env = ? ";
pstmt1 = conn.prepareStatement(sqlInner);
pstmt1.setString(1, taxEnv);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
taxEnvCnt = rs1.getInt(1);
}
pstmt1.close();pstmt1 = null;
rs1.close();rs1 = null;
if (taxEnvCnt == 0)
{
sqlInner = "select count(1) from tenvseq where ref_ser = ' ' and tax_env = ? ";
pstmt1 = conn.prepareStatement(sqlInner);
pstmt1.setString(1, taxEnv);
rs1 = pstmt1.executeQuery();
if (rs1.next()) {
taxEnvCnt = rs1.getInt(1);
}
pstmt1.close();pstmt1 = null;
rs1.close();rs1 = null;
}
if (taxEnvCnt > 0)
{
sqlInner = "select count(1) from taxtran where tran_code = 'S-DSP' and tran_id = ? and line_no = ?";
pstmt1 = conn.prepareStatement(sqlInner);
pstmt1.setString(1, despId);
pstmt1.setString(2, despLine);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
taxCount = rs1.getInt(1);
}
pstmt1.close();pstmt1 = null;
rs1.close();rs1 = null;
}
if ((taxCount == 0) || (taxEnvCnt != taxCount))
{
System.out.println("taxCount["+taxCount+"]taxEnvCnt["+taxEnvCnt+"]");
System.out.println("TaxEnv Count Mismatch.....despId["+despId+"]despLine["+despLine+"]taxEnv["+taxEnv+"]");
if (!DespMap.containsKey(despId))
{
lineList.add(despLine);
DespMap.put(despId, lineList);
}
else {
if(DespMap.containsKey(despId))
{
ArrayList<String> tempList = new ArrayList<String>();
tempList = DespMap.get(despId);
tempList.add(despLine);
DespMap.put(despId, tempList);
}
}
errCode = "VTAXENVSEQ";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else
{
System.out.println("TaxEnv not defined>>>despId["+despId+"]despLine["+despLine+"]taxEnv["+taxEnv+"]");
}
}
pstmt.close();pstmt = null;
rs.close();rs = null;
}
}// end for <purc_order>
break;
}
System.out.println("DespMap::"+DespMap+"]\ngetErrString(DespMap)::"+getErrString(DespMap));
int errListSize = errList.size();
int cnt = 0;
String errFldName = null;
System.out.println("errListSize [" + errListSize+ "] errFields size [" + errFields.size() + "]");
if (errList != null && errListSize > 0)
{
System.out.println("errList["+ errList.toString() +"]");
for (cnt = 0; cnt < errListSize; cnt++) {
errCode = errList.get(cnt);
errFldName = errFields.get(cnt);
System.out.println("errFldName ..........[" + errFldName+"]\n ErrCode ..........[" + errCode+"]");
errString = getErrorString(errFldName, errCode, userId);
System.out.println("errString ..........[" + errString+"]");
errorType = errorType(conn, errCode);
System.out.println("errorType ..........[" + errorType+"]");
if("VTAXENVSEQ".equalsIgnoreCase(errCode))
{
String begPart = errString.substring( 0, errString.indexOf("<description>") + 13 );
String endPart = errString.substring( errString.indexOf("</description>"));
String errMsg ="Taxes are not calculated as per tax environment configuration for Despatches: \t ";
if( !DespMap.isEmpty() )
{
errString = begPart + errMsg +getErrString(DespMap).toString() + endPart;
}else
{
errString = begPart + errMsg + endPart;
}
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,
errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8,
errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
else if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,
errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8,
errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer("");
}
}catch (Exception e)
{
e.printStackTrace();
errString = e.getMessage();
throw new ITMException(e);
} finally {
try {
if (conn != null) {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs1 != null) {
rs1.close();
rs1 = null;
}
if (pstmt1 != null) {
pstmt1.close();
pstmt1 = null;
}
conn.close();
conn = null;
}
} catch (Exception d) {
d.printStackTrace();
throw new ITMException(d);
}
}
errString = errStringXml.toString();
System.out.println("Pavan Rane::Final["+errString+"]");
return errString;
}
private String errorType(Connection conn, String errorCode) {
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if (rs.next()) {
msgType = rs.getString("MSG_TYPE");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
} catch (Exception ex) {
ex.printStackTrace();
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (Exception e) {
e.printStackTrace();
}
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return msgType;
}
private String checkNull(String input) {
if (input == null || "null".equalsIgnoreCase(input)) {
input = "";
}
return input;
}
private StringBuffer getErrString(HashMap<String, ArrayList<String>> DespMap)
{
StringBuffer DespString = new StringBuffer();
if(!DespMap.isEmpty())
{
DespString.append("Despatch:");
String DespId= "";
Set setDesp = DespMap.entrySet();
Iterator itrDesp = setDesp.iterator();
while (itrDesp.hasNext())
{
StringBuffer lineString = new StringBuffer();
Map.Entry DespMapEntry = (Map.Entry) itrDesp.next();
DespId = (String) DespMapEntry.getKey();
ArrayList<String> LineList = (ArrayList) DespMapEntry.getValue();
int linecnt = 0;
for(String lineNo : LineList)
{
if(linecnt == 0)
{
lineString.append(lineNo.trim());
}else {
lineString.append(", ").append(lineNo.trim());
}
linecnt ++;
}
DespString.append(" #").append(DespId).append("Line: ").append(lineString).append("\n");
lineString = null;
LineList = null;
DespMapEntry = null;
}
setDesp = null;
itrDesp = null;
return DespString;
}
return DespString;
}
}
\ No newline at end of file
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
@Local
public interface InvoiceProformaICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
@Remote
public interface InvoiceProformaICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
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