Commit 3b31b7b9 authored by smanohar's avatar smanohar

New component to return xml instead of tab delimited data

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@208933 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 36964feb
package ibase.webitm.ejb.fin;
import ibase.webitm.utility.*;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.*;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.system.config.*;
import java.rmi.RemoteException;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import ibase.webitm.ejb.fin.FinCommon;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class AssetCWIPPrc extends ProcessEJB {
Connection conn = null;
String errorString = null;
// GenericUtility genericUtility = GenericUtility.getInstance();
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
DistCommon distCommon = new DistCommon();
/*
* public void ejbCreate() throws RemoteException, CreateException {
* System.out.println("Create Method Called...."); } public void ejbRemove() { }
* public void ejbActivate() { } public void ejbPassivate() { }
*/
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException, ITMException
{
System.out.println("AssetCWIP :getData() function called");
String rtrStr = "";
Document headerDom = null;
Document detailDom = null;
try {
if (xmlString != null && xmlString.trim().length() != 0) {
System.out.println("XML String :" + xmlString);
headerDom = genericUtility.parseString(xmlString);
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
System.out.println("XML String :" + xmlString2);
detailDom = genericUtility.parseString(xmlString2);
}
rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
} catch (Exception e) {
System.out.println(
"Exception :AssetCWIP :getData(String xmlString, String xmlString2, String windowName, String xtraParams):"
+ e.getMessage() + ":");
rtrStr = e.getMessage();
}
return rtrStr;
}// END OF GETDATA(1)
public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException, ITMException
{
String getDataSql = "";
String resultString = "";
String errString = "";
String errCode = "";
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
int cnt = 0;
java.sql.Timestamp refDateTs = null;
StringBuffer xmlStringBuff = new StringBuffer("<?xml version = \"1.0\"?>");
xmlStringBuff.append("<DocumentRoot>");
xmlStringBuff.append("<description>").append("Datawindow Root").append("</description>");
xmlStringBuff.append("<group0>");
xmlStringBuff.append("<description>").append("Group0 description").append("</description>");
xmlStringBuff.append("<Header0>");
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
E12GenericUtility genericUtility = new E12GenericUtility();
SimpleDateFormat sdf = null;
java.sql.Timestamp dateFrom = null , dateTo = null;
String siteCode = "", dateFromStr = "" , dateToStr = "", projCode = "",setBalYN = "", acctCodeFr = "",acctCodeTo = "", cWipTranType = "";
String tranId = "",lineNo = "",itemCode = "";
double quantity = 0, assetinstallQty = 0, balanceQty = 0, netAmt = 0,rate = 0, taxAmt = 0;
try {
conn = getConnection();
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
siteCode = genericUtility.getColumnValue("site_code",headerDom);
dateFromStr = genericUtility.getColumnValue("date_from",headerDom);
if (dateFromStr != null)
{
dateFrom = Timestamp.valueOf(genericUtility.getValidDateString(dateFromStr, genericUtility .getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
dateToStr = genericUtility.getColumnValue("date_to", headerDom);
if (dateToStr != null)
{
dateTo = Timestamp.valueOf(genericUtility.getValidDateString(dateToStr, genericUtility .getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
projCode = genericUtility.getColumnValue("proj_code", headerDom);
setBalYN = genericUtility.getColumnValue("set_balance_yn", headerDom);
if (setBalYN == null || setBalYN.trim().length() == 0)
{
setBalYN = "N";
}
acctCodeFr = genericUtility.getColumnValue("acct_code__fr", headerDom);
acctCodeTo = genericUtility.getColumnValue("acct_code__to", headerDom);
cWipTranType = genericUtility.getColumnValue("asset_cwip_porcp_tran_type", headerDom);
cWipTranType = distCommon.getDisparams("999999", "ASSET_PORCP_CWIP_TRAN_TYPE", conn);
if( "NULLFOUND".equals(cWipTranType) || cWipTranType.trim().length() == 0 || cWipTranType == null)
{
cWipTranType = " ";
}
getDataSql = "select a.tran_id, b.line_no, b.item_code, b.quantity, (case when b.assetinstall_qty is null then 0 else b.assetinstall_qty end ) assetinstall_qty, b.net_amt , b.rate, b.tax_amt "
+ " from porcp a, porcpdet b "
+ " where a.tran_Id = b.tran_Id "
+ " and a.tran_date >= ? "
+ " and a.tran_date <= ? "
+ " and b.acct_code__dr >= ? "
+ " and b.acct_code__dr <= ? "
+ " and a.site_code = ? ";
if(projCode != null && projCode.trim().length() > 0 )
{
getDataSql = getDataSql + " and a.proj_code = '" + projCode +"'";
}
getDataSql = getDataSql + " and a.tran_type = ? "
+ " and a.confirmed='Y' and b.purc_order is not null "
+ " and (b.quantity - (case when b.assetinstall_qty is null then 0 else b.assetinstall_qty end )) > 0 order by a.tran_id ";
System.out.println("The getDataSql becomes :" + getDataSql);
pstmt = conn.prepareStatement(getDataSql);
pstmt.setTimestamp(1, dateFrom);
pstmt.setTimestamp(2, dateTo);
pstmt.setString(3, acctCodeFr);
pstmt.setString(4, acctCodeTo);
pstmt.setString(5, siteCode);
pstmt.setString(6, cWipTranType);
rs = pstmt.executeQuery();
if (rs.next()) {
do {
tranId = checkNull(rs.getString("tran_id"));
lineNo = checkNull(rs.getString("line_no"));
itemCode = checkNull(rs.getString("item_code"));
rate = rs.getDouble("rate");
quantity = rs.getDouble("quantity");
assetinstallQty = rs.getDouble("assetinstall_qty");
taxAmt = rs.getDouble("tax_amt");
balanceQty = quantity - assetinstallQty;
if (assetinstallQty == 0)
{
netAmt = rs.getDouble("net_amt");
}
else
{
netAmt = ((quantity - assetinstallQty) * rate) + (taxAmt / quantity * (quantity - assetinstallQty) );
}
xmlStringBuff.append("<Detail2>");
xmlStringBuff.append("<tran_id>").append("<![CDATA[" + tranId + "]]>").append("</tran_id>");
xmlStringBuff.append("<line_no>").append("<![CDATA[" + lineNo + "]]>").append("</line_no>");
xmlStringBuff.append("<item_code>").append("<![CDATA[" + itemCode + "]]>").append("</item_code>");
xmlStringBuff.append("<quantity>").append("<![CDATA[" + quantity + "]]>").append("</quantity>");
xmlStringBuff.append("<assetinstall_qty>").append("<![CDATA[" + assetinstallQty + "]]>").append("</assetinstall_qty>");
if ("Y".equals(setBalYN))
{
xmlStringBuff.append("<balance_qty>").append("<![CDATA[" + balanceQty + "]]>").append("</balance_qty>");
}
else
{
xmlStringBuff.append("<balance_qty>").append("<![CDATA[0]]>").append("</balance_qty>");
}
xmlStringBuff.append("<net_amt>").append("<![CDATA[" + netAmt + "]]>").append("</net_amt>");
xmlStringBuff.append("</Detail2>");
cnt++;
} while (rs.next());
xmlStringBuff.append("</Header0>");
xmlStringBuff.append("</group0>");
xmlStringBuff.append("</DocumentRoot>");
resultString = xmlStringBuff.toString();
System.out.println("AssetCWIP--resultString:["+resultString+"]");
} else {
errCode = "VTNOREC2";
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
} catch (SQLException e) {
System.out.println(
"SQLException :AssetCWIP :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):"
+ e.getMessage() + ":");
throw new ITMException(e);
} catch (Exception e) {
System.out.println(
"Exception :AssetCWIP :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):"
+ e.getMessage() + ":");
throw new ITMException(e);
} finally {
try {
xmlStringBuff = null;
if (conn != null) {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
conn.close();
}
} catch (Exception e) {
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
}
return resultString;
}// END OF GETDATA(2)
public String process() throws RemoteException, ITMException {
return "";
}
public String process(String xmlString, String xmlString2, String windowName, String xtraParams)
throws RemoteException, ITMException {
Document detailDom = null;
Document headerDom = null;
// GenericUtility genericUtility = GenericUtility.getInstance();
String retStr = "";
try {
System.out.println("xmlString[process]::::::::::;;;" + xmlString);
System.out.println("xmlString2[process]::::::::::;;;" + xmlString2);
System.out.println("windowName[process]::::::::::;;;" + windowName);
System.out.println("xtraParams[process]:::::::::;;;" + xtraParams);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
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);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
} catch (Exception e) {
System.out.println(
"Exception :AssetCWIP :process(String xmlString, String xmlString2, String windowName, String xtraParams):"
+ e.getMessage() + ":");
e.printStackTrace();
retStr = e.getMessage();
}
return retStr;
}// END OF PROCESS (1)
/* public String process(Document headerDom, Document detailDom, String windowName, String xtraParams)
throws RemoteException, ITMException {
String retStr = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "", sql1 = "", errString = "";
String retString = "", errCode = "";
String sundryTypeOld = "";
String sundryCodeOld = "", tranid_ser = "", env = "", tranDateStr = "";
String sundryType = "", sundryCode = "", tranId = "", refSer = "", tranIdRef = "", taxCode = "", taxGroup = "";
Timestamp tranDate = null;
ConnDriver connDriver = new ConnDriver();
int parentNodeListLength = 0;
int childNodeListLength = 0;
String childNodeName = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String siteCode = null;
int printCnt = 0, cnt = 0, upd = 0;
try {
// Changes and Commented By Bhushan on 06-06-2016 :START
// conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
// Changes and Commented By Bhushan on 06-06-2016 :END
conn.setAutoCommit(false);
} catch (Exception e) {
System.out.println("Exception :WorkorderPrcEJB :ejbCreate :==>" + e);
e.printStackTrace();
}
try {
FinCommon finCommon = new FinCommon();
env = finCommon.getFinparams("999999", "TDSPRN", conn);
if (env.equalsIgnoreCase("NULLFOUND")) {
System.out.println("NULLFOUND..........");
errString = itmDBAccessEJB.getErrorString("", "TDSPRN", "", "", conn);// changes by Nandkumar Gadkari on
// 20/07/18
return errString;
} else {
printCnt = Integer.parseInt(env);
if (printCnt == 0) {
System.out.println("if(printCnt ==0)..........");
errString = itmDBAccessEJB.getErrorString("", "TDSPRN", "", "", conn);// changes by Nandkumar
// Gadkari on 20/07/18
return errString;
}
}
parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
System.out.println("parentNodeListLength:::::::::" + parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++) {
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength::: " + childNodeListLength + "\n");
for (int childRow = 0; childRow < childNodeListLength; childRow++) {
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
if (childNodeName.equals("sundry_type")) {
sundryType = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("sundry_code")) {
sundryCode = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("tranId")) {
tranId = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("ref_ser")) {
refSer = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("tranId__ref")) {
tranIdRef = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("tax_code")) {
taxCode = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("tax_group")) {
taxGroup = childNode.getFirstChild().getNodeValue();
}
if (childNodeName.equals("tran_date")) {
tranDateStr = childNode.getFirstChild().getNodeValue();
tranDateStr = genericUtility.getValidDateString(tranDateStr, genericUtility.getDBDateFormat(),
genericUtility.getApplDateFormat());
}
} // inner for loop
System.out.println("taxGroup..............." + taxGroup);
System.out.println("taxCode..............." + taxCode);
System.out.println("tranDateStr..............." + tranDateStr);
if (!sundryCode.equalsIgnoreCase(sundryCodeOld) || (!sundryType.equalsIgnoreCase(sundryTypeOld))
|| (cnt >= printCnt)) {
/// if different suntry_type and code then generate a different tranId
cnt = 1;
sql1 = "SELECT site_code " + "FROM misc_voucher WHERE tranId = '" + tranId + "' ";
System.out.println("sql1..............." + sql1);
pstmt = conn.prepareStatement(sql1);
rs = pstmt.executeQuery();
if (rs.next()) {
siteCode = rs.getString(1);
if (siteCode == null) {
errString = itmDBAccessEJB.getErrorString("", "VMVOUC4", "", "", conn);// changes by
// Nandkumar Gadkari
// on 20/07/18
return errString;
}
} else {
errString = itmDBAccessEJB.getErrorString("", "VMVOUC4", "", "", conn);// changes by Nandkumar
// Gadkari on 20/07/18
return errString;
}
rs.close();
pstmt.close();
tranid_ser = generateTranId("W_MISC_VOUCHER_TRACE", tranDateStr, siteCode, conn);
if (tranid_ser == null || tranid_ser.trim().length() == 0) {
// System.out.println("errcode......"+errCode);
errString = itmDBAccessEJB.getErrorString("", "VTTRANID", "", "", conn);// changes by Nandkumar
// Gadkari on 20/07/18
return errString;
}
} else {
cnt++;
}
sql = "update misc_voucher_trace set tranId__ser = '" + tranid_ser + "' " + "where tranId = '"
+ tranId + "' and ref_ser ='" + refSer + "' and tranId__ref ='" + tranIdRef + "' ";
System.out.println("sql.................. :" + sql);
pstmt = conn.prepareStatement(sql);
upd = pstmt.executeUpdate();
if (upd > 0) {
System.out.println("recoed updated " + upd);
} else {
System.out.println("recoed not updated " + upd);
}
pstmt.close();
pstmt = null;
sundryCodeOld = sundryCode;
sundryTypeOld = sundryType;
} // end for loop
} catch (Exception e) {
System.out.println("Exception in.AssetCWIP..." + e.getMessage());
e.printStackTrace();
errString = e.getMessage();
} finally {
try {
if (errString.trim().length() > 0) {
conn.rollback();
System.out.println(" Rollback connection.............");
errString = itmDBAccessEJB.getErrorString("", "VTPROUNSUC", "", "", conn);// changes by Nandkumar
// Gadkari on 20/07/18
} else {
conn.commit();
System.out.println(" commiting connection.............");
errString = itmDBAccessEJB.getErrorString("", "VTCONF", "", "", conn);// changes by Nandkumar
// Gadkari on 20/07/18
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
System.out.println("Error In closing connection::==> " + e);
e.printStackTrace();
}
}
System.out.println("returning from genTDS " + errString);
return (errString);
}
private String generateTranId(String windowName, String tranDate, String siteCode, Connection conn) {
Statement stmt = null;
ResultSet rs = null;
String sql = null;
String tranId = null;
String xmlValues = null;
try {
sql = "SELECT KEY_STRING, tranId_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW)= '" + windowName
+ "'";
System.out.println("Tran generator Sql" + sql);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
String tranSer1 = "";
String keyString = "";
String keyCol = "";
if (rs.next()) {
keyString = rs.getString(1);
keyCol = rs.getString(2);
tranSer1 = rs.getString(3);
}
System.out.println("keyString :" + keyString);
System.out.println("keyCol :" + keyCol);
System.out.println("tranSer1 :" + tranSer1);
xmlValues = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<tranId></tranId>";
xmlValues = xmlValues + "<site_code>" + siteCode + "</site_code>";
xmlValues = xmlValues + "<tran_date>" + tranDate + "</tran_date>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues :[" + xmlValues + "]");
TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", CommonConstants.DB_NAME);
tranId = tg.generateTranSeqID(tranSer1, keyCol, keyString, conn);
System.out.println("tranId :" + tranId);
} catch (SQLException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return tranId;
}
*/
private String getCurrdateInAppFormat() {
String currAppdate = null;
java.sql.Timestamp currDate = null;
Object date = null;
SimpleDateFormat DBDate = null;
// GenericUtility genericUtility = GenericUtility.getInstance();
try {
currDate = new java.sql.Timestamp(System.currentTimeMillis());
System.out.println(genericUtility.getDBDateFormat());
DBDate = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = DBDate.parse(currDate.toString());
currDate = java.sql.Timestamp.valueOf(DBDate.format(date).toString() + " 00:00:00.0");
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
} catch (Exception e) {
System.out.println("Exception in getCurrdateInAppFormat:::" + e.getMessage());
}
genericUtility = null;
return (currAppdate);
}
private String checkNull(String input)
{
if(input == null)
{
input = "";
}
return input;
}
}
\ No newline at end of file
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