Commit 9e9b710b authored by manohar's avatar manohar

This commit was generated by cvs2svn to compensate for changes in r131,

which included commits to RCS files with non-trunk default branches.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@91196 ce508802-f39f-4f6c-b175-0d175dae99d5
parent c6000c76
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import java.text.*;
import java.util.Date;
import java.sql.*;
import java.text.SimpleDateFormat;
import org.w3c.dom.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ChargeBackLoc extends ValidatorEJB implements ChargeBackLocLocal, ChargeBackLocRemote
{
GenericUtility genericUtility = GenericUtility.getInstance();
String loginSite = "";
/* public void ejbCreate() throws RemoteException, CreateException
{
System.out.println("ChargeBackLocEJB is in Process..........");
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
} */
public String wfValData() throws RemoteException,ITMException
{
return "";
}
public String itemChanged() throws RemoteException,ITMException
{
return "";
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = null;
System.out.println("Validation Start..........");
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString(xmlString2);
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : AssetRegisterICEJB : wfValData(String xmlString) : ==>\n"+e.getMessage());
}
return (errString);
}
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String errString = " ";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String columnValue = null;
String childNodeName = null;
String billNo = "";
String tranId = "";
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String errCode = null;
String userId = null;
String custCode = null;
String itemCode = "";
String quantity = "";
String saleQty = "";
String saleRetQty = "";
String unconfQty = "";
String confQty = "";
int cnt = 0;
int ctr = 0;
int currentFormNo = 0;
int childNodeListLength;
Connection conn = null;
PreparedStatement pStmt=null;
ResultSet rs = null;
String sql = null;
ConnDriver connDriver = new ConnDriver();
String lineNoDet = null;
String updateFlag = null;
try
{
System.out.println( "wfValData called" );
conn = connDriver.getConnectDB("DriverITM");
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
System.out.println("VALIDATION FOR DETAIL [ 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();
if ( childNodeName.equalsIgnoreCase( "cust_code" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("cust_code","VMCUSTNUL",userId);
break ;
}
else
{
custCode = genericUtility.getColumnValue( "cust_code", dom, "1" );
sql = " SELECT COUNT(*) FROM customer WHERE cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
cnt = rs.getInt( 1 );
}
if( cnt == 0 )
{
errCode = "VMINVCUST";
errString = getErrorString( "cust_code", errCode, userId );
break ;
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
if ( childNodeName.equalsIgnoreCase( "tran_type" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("tran_type","VMTRNTPNUL",userId);
break ;
}
}
if ( childNodeName.equalsIgnoreCase( "type" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("type","VMSDRTPNUL",userId);
break ;
}
}
if ( childNodeName.equalsIgnoreCase( "item_ser" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("item_ser","VMITMSRNUL",userId);
break ;
}
}
if ( childNodeName.equalsIgnoreCase( "cust_code__credit" ) )
{
custCode = genericUtility.getColumnValue( "cust_code__credit", dom, "1" );
if( custCode != null && custCode.trim().length() > 0 )
{
sql = " SELECT COUNT(*) FROM customer WHERE cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
cnt = rs.getInt( 1 );
}
if( cnt == 0 )
{
errCode = "VMINVCUST";
errString = getErrorString( "cust_code__credit", errCode, userId );
break ;
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
}
//END OF CASE1
break;
case 2 :
System.out.println("VALIDATION FOR DETAIL [ 2 ]..........");
//String update_flag = null;
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if ( childNodeName.equalsIgnoreCase( "item_code" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("item_code","VTITMNUL",userId);
break ;
}
else
{
itemCode = genericUtility.getColumnValue( "item_code", dom );
if( itemCode != null & itemCode.trim().length() > 0 )
{
sql = "SELECT count(*) from item"
+" where item_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,itemCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
cnt = rs.getInt( 1 );
}
System.out.println(" COUNT =====> [" + cnt + "]");
if( cnt == 0 )
{
errString =itmDBAccessEJB.getErrorString("item_code","VTINVITM",userId);
break ;
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
}
if ( childNodeName.equalsIgnoreCase( "lot_no" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("lot_no","VTLOTNUL",userId);
break ;
}
}
if ( childNodeName.equalsIgnoreCase( "porder_no" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("porder_no","VTBILNONUL",userId);
break ;
}
else
{
billNo = genericUtility.getColumnValue( "porder_no", dom );
custCode = genericUtility.getColumnValue( "cust_code", dom1 );
tranId = genericUtility.getColumnValue( "tran_id", dom1 );
sql = "Select count(1) from charge_back A, charge_back_det B where"
+" A.tran_id = B.tran_id "
+" and A.cust_code = ? "
+" and B.porder_no = ? "
+" and A.tran_id <> '"+tranId+"' ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode.trim() );
pStmt.setString(2, billNo.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
cnt = rs.getInt( 1 );
}
pStmt.close();
rs.close();
if( cnt >= 1 )
{
errString =itmDBAccessEJB.getErrorString("porder_no","VTBILNOPST",userId);
break ;
}
}
}
if ( childNodeName.equalsIgnoreCase( "porder_date" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("porder_date","VTBILDTNUL",userId);
break ;
}
}
/* if ( childNodeName.equalsIgnoreCase( "discount_per" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("discount_per","VTDISPNUL",userId);
break ;
}
} */
if ( childNodeName.equalsIgnoreCase( "item_ser" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("item_ser","VTITMSRNUL",userId);
break ;
}
}
if ( childNodeName.equalsIgnoreCase( "quantity" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("quantity","VTQUANTNUL",userId);
break ;
}
else
{
quantity = genericUtility.getColumnValue( "quantity", dom );
saleQty = genericUtility.getColumnValue( "sale_qty", dom );
saleRetQty = genericUtility.getColumnValue( "sale_ret_qty", dom );
unconfQty = genericUtility.getColumnValue( "unconf_claimed", dom );
confQty = genericUtility.getColumnValue( "conf_claimed", dom );
double qtyDbl = Double.parseDouble(quantity);
double saleQtyDbl = Double.parseDouble(saleQty);
double saleRetQtyDbl = Double.parseDouble(saleRetQty);
double unconfQtyDbl = Double.parseDouble(unconfQty);
double confQtyDbl = Double.parseDouble(confQty);
if( qtyDbl > ( saleQtyDbl + saleRetQtyDbl - unconfQtyDbl - confQtyDbl ) )
{
errString =itmDBAccessEJB.getErrorString("quantity","VTINVQUANT",userId);
break ;
}
}
}
if ( childNodeName.equalsIgnoreCase( "rate__contr" ) )
{
if ( childNode.getFirstChild() == null )
{
errString =itmDBAccessEJB.getErrorString("rate__contr","VTRATCRNUL",userId);
break ;
}
}
}//END FOR OF CASE2
break;
}//END SWITCH
}//END TRY
catch(Exception e)
{
System.out.println("Exception ::" +e);
e.printStackTrace();
errCode = "VALEXCEP";
errString = getErrorString( "", errCode, userId );
}
finally
{
try
{
if(conn != null)
{
if( pStmt != null )
{
pStmt.close();
pStmt = null;
}
if( rs != null )
{
rs.close();
rs = null;
}
conn.close();
}
conn = null;
}
catch(Exception d)
{
d.printStackTrace();
}
System.out.println(" < AssetRegisterIcEJB > CONNECTION IS CLOSED");
}
System.out.println("ErrString ::" + errString);
return errString;
}//END OF VALIDATION
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = null;
try
{
System.out.println("xmlString" + xmlString);
dom = parseString(xmlString);
System.out.println("xmlString1" + xmlString1);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
System.out.println("xmlString2" + xmlString2);
dom2 = parseString("<Root>" + xmlString2 + "</Root>");
}
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [AssetRegisterICEJB][itemChanged] :==>\n"+e.getMessage());
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
PreparedStatement pStmt = null;
ResultSet rs = null;
String sql = null;
int currentFormNo = 0;
StringBuffer valueXmlString = new StringBuffer();
String columnValue = null;
NodeList parentNodeList = null;
Node parentNode = null;
Node childNode = null;
NodeList childNodeList = null;
String childNodeName = null;
int childNodeListLength = 0;
int ctr = 0;
int cnt = 0;
String itemCode = "";
String siteCode = "";
String lotNo = "";
String rateSell = "";
String discPer = "";
String rateContr = "";
String tranId = "";
String lineNo = "";
String itmchgData = "";
String custName = "";
String priceList = "";
String itemSeries = "";
String firstName = "", middleName = "", lastName = "";
String chguserhdr = null;
String type = "";
String chgtermhdr = null;
String custCode = "";
SimpleDateFormat sdf = null;
String siteDescr = "";
String currCode = "";
double exchRate = 0.0;
String custCdEnd = "";
double saleQty = 0.0;
double discPerc = 0.0;
double saleRetQty = 0.0;
double confQty = 0.0, rate = 0.0, discPerUnit = 0.0;
double unconfQty = 0.0, rateSellDbl = 0.0, discPerDbl = 0.0, rateContrDbl = 0.0;
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
try
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
chguserhdr = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgtermhdr = getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("Current Form No ["+currentFormNo+"]");
switch (currentFormNo)
{
case 1:
valueXmlString.append("<Detail1>");
//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equals(currentColumn))
{
if (childNode.getFirstChild() != null)
{
columnValue=childNode.getFirstChild().getNodeValue().trim();
}
}
ctr++;
}while(ctr < childNodeListLength && !childNodeName.equals(currentColumn));
System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
if (currentColumn.trim().equals( "itm_default" ))
{
if( loginSite != null || loginSite.trim().length()==0 )
{
sql = "select descr from site where site_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,loginSite);
rs = pStmt.executeQuery();
if( rs.next() )
{
siteDescr = rs.getString( "descr" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select curr_code from finent where fin_entity = ( Select fin_entity "
+" from site where site_code = '"+loginSite+"')";
pStmt = conn.prepareStatement( sql );
rs = pStmt.executeQuery();
if( rs.next() )
{
currCode = rs.getString( "curr_code" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
if( currCode != null && currCode.trim().length() > 0 )
{
sql = "select std_exrt from currency where curr_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,currCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
exchRate = rs.getDouble( "std_exrt" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
valueXmlString.append("<tran_date>").append("<![CDATA[" + getCurrdateAppFormat() + "]]>").append("</tran_date>");
valueXmlString.append("<eff_date>").append("<![CDATA[" + getCurrdateAppFormat() + "]]>").append("</eff_date>");
valueXmlString.append("<site_code__log>").append("<![CDATA[" + ( loginSite )+ "]]>").append("</site_code__log>");
valueXmlString.append("<site_log_descr>").append("<![CDATA[" + ( siteDescr )+ "]]>").append("</site_log_descr>");
valueXmlString.append("<site_code>").append("<![CDATA[" + ( loginSite )+ "]]>").append("</site_code>");
valueXmlString.append("<site_bill_descr>").append("<![CDATA[" + ( siteDescr )+ "]]>").append("</site_bill_descr>");
valueXmlString.append("<site_code__cr>").append("<![CDATA[" + ( loginSite )+ "]]>").append("</site_code__cr>");
valueXmlString.append("<site_cr_descr>").append("<![CDATA[" + ( siteDescr )+ "]]>").append("</site_cr_descr>");
valueXmlString.append("<type>").append("R").append("</type>");
valueXmlString.append("<curr_code>").append("<![CDATA[" + ( currCode )+ "]]>").append("</curr_code>");
valueXmlString.append("<exch_rate>").append("<![CDATA[" + ( exchRate )+ "]]>").append("</exch_rate>");
//valueXmlString.append("<cust_code__end protect=\"1\" >").append("").append("</cust_code__end>");
valueXmlString.append("<chg_user>").append("<![CDATA["+ chguserhdr + "]]>").append("</chg_user>");
valueXmlString.append("<chg_term>").append("<![CDATA["+ chgtermhdr + "]]>").append("</chg_term>");
}
}
if(currentColumn.trim().equalsIgnoreCase("itm_defaultedit"))
{
custCode = genericUtility.getColumnValue( "cust_code__end", dom );
type = genericUtility.getColumnValue( "type", dom );
if( type != null && custCode != null )
{
if( type.equals("R") )
{
sql = "select cust_name from customer "
+" where cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
custName = rs.getString( "cust_name" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
else
{
sql = "Select first_name, middle_name, last_name from strg_customer "
+" where sc_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
firstName = rs.getString( "first_name" );
middleName = rs.getString( "middle_name" );
lastName = rs.getString( "last_name" );
}
custName = firstName + " " + middleName + " " + lastName;
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
valueXmlString.append("<cust_end_name>").append("<![CDATA[" + ( custName )+ "]]>").append("</cust_end_name>");
/*String siteCodeEdit = getColumnValue("site_code",dom);
String itemGrpEdit = getColumnValue("item_grp",dom);
String tranId = genericUtility.getColumnValue( "tran_id", dom );
sql = "SELECT count(1) from ASSET_SHIFTDET"
+" where tran_id = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,tranId);
rs = pStmt.executeQuery();
if( rs.next() )
{
cnt = rs.getInt( 1 );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
String grpDescr = null;
sql = "select fn_get_gen_descr('GRP_CODE','W_ITEM', ? ,'D') descr"
+" from dual";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1, itemGrpEdit != null ? itemGrpEdit.trim() : "" );
rs = pStmt.executeQuery();
if( rs.next() )
{
grpDescr = rs.getString( 1 );
}
if( cnt == 0 )
{
valueXmlString.append("<site_code>").append("<![CDATA[" + ( siteCodeEdit != null ? siteCodeEdit.trim() : "" )+ "]]>").append("</site_code>");
valueXmlString.append("<item_grp>").append("<![CDATA[" + ( itemGrpEdit != null ? itemGrpEdit.trim() : "" )+ "]]>").append("</item_grp>");
valueXmlString.append("<grp_descr>").append("<![CDATA[" + ( grpDescr != null ? grpDescr.trim() : "" )+ "]]>").append("</grp_descr>");
}
else
{
valueXmlString.append("<site_code protect=\"1\" >").append("<![CDATA["+siteCodeEdit+"]]>").append("</site_code>");
valueXmlString.append("<item_grp protect=\"1\" >").append("<![CDATA["+itemGrpEdit+"]]>").append("</item_grp>");
valueXmlString.append("<grp_descr>").append("<![CDATA[" + ( grpDescr != null ? grpDescr.trim() : "" )+ "]]>").append("</grp_descr>");
}*/
}
if (currentColumn.trim().equals( "cust_code" ))
{
custCode = genericUtility.getColumnValue( "cust_code", dom );
if( custCode != null && custCode.trim().length() > 0 )
{
sql = "select cust_name from customer "
+" where cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
custName = rs.getString( "cust_name" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select price_list from site_customer where site_code = ? and cust_code = ?";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,loginSite.trim());
pStmt.setString(2,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
priceList = rs.getString( "price_list" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
if( priceList == null || priceList.trim().length() == 0 )
{
sql = "Select price_list from customer where cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
priceList = rs.getString("price_list");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
sql = "SELECT item_ser__inv FROM customer_series where cust_code = ? "
+" AND item_ser__inv IS NOT NULL ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
itemSeries = rs.getString( "item_ser__inv" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
if( itemSeries == null || itemSeries.trim().length() == 0 )
{
sql = "SELECT item_ser FROM customer_series where cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
itemSeries = rs.getString( "item_ser" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
valueXmlString.append("<cust_name>").append("<![CDATA[" + ( custName )+ "]]>").append("</cust_name>");
valueXmlString.append("<cust_code__credit>").append("<![CDATA[" + ( custCode != null ? custCode.trim() : "" )+ "]]>").append("</cust_code__credit>");
valueXmlString.append("<cust_cr_name>").append("<![CDATA[" + ( custName )+ "]]>").append("</cust_cr_name>");
valueXmlString.append("<price_list>").append("<![CDATA[" + ( priceList == null ? "" : priceList )+ "]]>").append("</price_list>");
valueXmlString.append("<item_ser>").append("<![CDATA[" + ( itemSeries )+ "]]>").append("</item_ser>");
}
if (currentColumn.trim().equals( "type" ))
{
type = genericUtility.getColumnValue( "type", dom );
valueXmlString.append("<cust_code__end>").append("").append("</cust_code__end>");
valueXmlString.append("<cust_end_name>").append("").append("</cust_end_name>");
/* if( type != null )
{
valueXmlString.append("<cust_code__end protect=\"0\" >").append("").append("</cust_code__end>");
}
else
{
valueXmlString.append("<cust_code__end protect=\"1\" >").append("").append("</cust_code__end>");
} */
}
if (currentColumn.trim().equals( "cust_code__credit" ))
{
custCode = genericUtility.getColumnValue( "cust_code__credit", dom );
if( custCode != null && custCode.trim().length() > 0 )
{
sql = "select cust_name from customer "
+" where cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
custName = rs.getString( "cust_name" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
valueXmlString.append("<cust_cr_name>").append("<![CDATA[" + ( custName )+ "]]>").append("</cust_cr_name>");
}
if (currentColumn.trim().equals( "cust_code__end" ))
{
custCode = genericUtility.getColumnValue( "cust_code__end", dom );
type = genericUtility.getColumnValue( "type", dom );
if( type != null )
{
if( type.equals("R") )
{
sql = "select cust_name from customer "
+" where cust_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
custName = rs.getString( "cust_name" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
else
{
sql = "Select first_name, middle_name, last_name from strg_customer "
+" where sc_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,custCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
firstName = rs.getString( "first_name" );
middleName = rs.getString( "middle_name" );
lastName = rs.getString( "last_name" );
}
custName = firstName + " " + middleName + " " + lastName;
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
valueXmlString.append("<cust_end_name>").append("<![CDATA[" + ( custName )+ "]]>").append("</cust_end_name>");
}
if (currentColumn.trim().equals( "curr_code" ))
{
currCode = genericUtility.getColumnValue( "curr_code", dom );
if( currCode != null && currCode.trim().length() > 0 )
{
sql = "select std_exrt from currency where curr_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,currCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
exchRate = rs.getDouble( "std_exrt" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
valueXmlString.append("<exch_rate>").append("<![CDATA[" + ( exchRate )+ "]]>").append("</exch_rate>");
}
valueXmlString.append("</Detail1>");
valueXmlString.append("</Root>");
break;
///////////////
case 2:
valueXmlString.append("<Detail2>");
//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equals(currentColumn))
{
if (childNode.getFirstChild() != null)
{
columnValue=childNode.getFirstChild().getNodeValue().trim();
}
}
ctr++;
}while(ctr < childNodeListLength && !childNodeName.equals(currentColumn));
System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
if (currentColumn.trim().equals( "itm_default" ))
{
itemSeries = genericUtility.getColumnValue( "item_ser", dom1 );
custCdEnd = genericUtility.getColumnValue( "cust_code__end", dom1 );
type = genericUtility.getColumnValue( "type", dom1 );
if( type != null && custCdEnd != null )
{
if( type.equals("S") )
{
sql = "select disc_perc from disc_apr_strg where item_ser = ? "
+" and sc_code = ? "
+" and ? between eff_from and valid_upto ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSeries.trim() );
pStmt.setString(2, custCdEnd.trim() );
pStmt.setTimestamp(3, getCurrdateTsFormat() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
else
{
sql = "select disc_perc from customer_series where item_ser = ? "
+" and cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSeries.trim() );
pStmt.setString(2, custCdEnd.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
valueXmlString.append("<discount_per>").append("<![CDATA["+ discPerc + "]]>").append("</discount_per>");
}
valueXmlString.append("<item_ser>").append("<![CDATA["+ itemSeries != null ? itemSeries : "" + "]]>").append("</item_ser>");
}
if (currentColumn.trim().equals( "itm_defaultedit" ))
{
itemCode = genericUtility.getColumnValue( "item_code", dom );
siteCode = genericUtility.getColumnValue( "site_code", dom1 );
custCode = genericUtility.getColumnValue( "cust_code", dom1 );
lotNo = genericUtility.getColumnValue( "lot_no", dom );
rateSell = genericUtility.getColumnValue( "rate__sell", dom );
discPer = genericUtility.getColumnValue( "discount_per", dom );
rateContr = genericUtility.getColumnValue( "rate__contr", dom );
tranId = genericUtility.getColumnValue( "tran_id", dom );
lineNo = genericUtility.getColumnValue( "line_no", dom );
String itemDescr = "";
String itemSer = "";
if( itemCode != null && itemCode.trim().length() > 0 )
{
sql = "select DESCR, item_ser from item "
+"where item_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,itemCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
itemDescr = rs.getString( "DESCR" );
itemSer = rs.getString( "item_ser" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
valueXmlString.append("<item_descr>").append("<![CDATA[" + ( itemDescr )+ "]]>").append("</item_descr>");
valueXmlString.append("<item_ser>").append("<![CDATA[" + ( itemSer )+ "]]>").append("</item_ser>");
if( lotNo != null && lotNo.trim().length() > 0 )
{
sql = "select sum(b.quantity) as saleQty from invoice a, invoice_trace b "
+" where a.invoice_id = b.invoice_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.tran_date <= ? "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.confirmed = 'Y'" ;
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setTimestamp(3, getCurrdateTsFormat());
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
saleQty = rs.getDouble("saleQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when B.ret_rep_flag = 'R' then -b.quantity else b.quantity end) as saleRetQty "
+" from sreturn a, sreturndet b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.tran_date <= ? "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.confirmed = 'Y'" ;
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setTimestamp(3, getCurrdateTsFormat());
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
saleRetQty = rs.getDouble("saleRetQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when b.quantity is null then 0 else b.quantity end) as confQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.confirmed = 'Y' "
+" and b.item_code = ? "
+" and b.lot_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setString(3, itemCode);
pStmt.setString(4, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
confQty = rs.getDouble("confQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when b.quantity is null then 0 else b.quantity end) as unconfQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and (case when a.confirmed is null then 'N' else a.confirmed end) = 'N' "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.tran_id <> ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setString(3, itemCode);
pStmt.setString(4, lotNo);
pStmt.setString(5, tranId);
rs = pStmt.executeQuery();
if( rs.next() )
{
unconfQty = rs.getDouble("unconfQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
/* sql = "select ('"+unconfQty+"' - (case when b.quantity is null then 0 else b.quantity end)) as unconfQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and b.tran_id = ? "
+" and b.line_no = ? "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and (case when a.confirmed is null then 'N' else a.confirmed end) = 'N' "
+" and b.item_code = ? "
+" and b.lot_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, tranId);
pStmt.setString(2, lineNo);
pStmt.setString(2, custCode);
pStmt.setString(3, siteCode);
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
unconfQty = rs.getDouble("unconfQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null; */
//saleRetQty = Math.abs(saleRetQty);
valueXmlString.append("<sale_qty>").append("<![CDATA["+ saleQty + "]]>").append("</sale_qty>");
valueXmlString.append("<sale_ret_qty>").append("<![CDATA["+ saleRetQty + "]]>").append("</sale_ret_qty>");
valueXmlString.append("<conf_claimed>").append("<![CDATA["+ confQty + "]]>").append("</conf_claimed>");
valueXmlString.append("<unconf_claimed>").append("<![CDATA["+ unconfQty + "]]>").append("</unconf_claimed>");
}
if( rateSell != null && rateSell.trim().length() > 0 )
rateSellDbl = Double.parseDouble(rateSell);
if( discPer != null && discPer.trim().length() > 0 )
discPerDbl = Double.parseDouble(discPer);
if( rateContr != null && rateContr.trim().length() > 0 )
rateContrDbl = Double.parseDouble(rateContr);
if( rateContrDbl <= 0 )
rate = rateSellDbl;
else
rate = Math.min( rateContrDbl, rateSellDbl );
discPerUnit = (rate * discPerDbl) / 100;
valueXmlString.append("<discount_per_unit>").append("<![CDATA["+ discPerUnit + "]]>").append("</discount_per_unit>");
}
if (currentColumn.trim().equals("item_code"))
{
itmchgData = getItemChgdata( dom, dom1, conn );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("lot_no"))
{
itmchgData = getItemChgdata( dom, dom1, conn );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("quantity"))
{
itmchgData = getCalculations( dom );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("discount_per"))
{
itmchgData = getCalculations( dom );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("rate__sell"))
{
itmchgData = getCalculations( dom );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("rate__contr"))
{
itmchgData = getCalculations( dom );
valueXmlString.append( itmchgData );
}
if (currentColumn.trim().equals("item_ser"))
{
itemSeries = genericUtility.getColumnValue( "item_ser", dom1 );
custCdEnd = genericUtility.getColumnValue( "cust_code__end", dom1 );
type = genericUtility.getColumnValue( "type", dom1 );
if( type != null && custCdEnd != null )
{
if( type.equals("S") )
{
sql = "select disc_perc from disc_apr_strg where item_ser = ? "
+" and sc_code = ? "
+" and ? between eff_from and valid_upto ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSeries.trim() );
pStmt.setString(2, custCdEnd.trim() );
pStmt.setTimestamp(3, getCurrdateTsFormat() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
else
{
sql = "select disc_perc from customer_series where item_ser = ? "
+" and cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSeries.trim() );
pStmt.setString(2, custCdEnd.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
valueXmlString.append("<discount_per>").append("<![CDATA["+ discPerc + "]]>").append("</discount_per>");
}
}
valueXmlString.append("</Detail2>");
valueXmlString.append("</Root>");
////////////////
}//END OF TRY
}
catch(Exception e)
{
System.out.println("Exception ::"+ e.getMessage());
e.printStackTrace();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pStmt != null )
{
pStmt.close();
pStmt = null;
}
if ( conn != null )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
}
}
return valueXmlString.toString();
}//END OF ITEMCHANGE
private String getCurrdateAppFormat()
{
String s = "";
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
java.util.Date date = null;
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = simpledateformat.parse(timestamp.toString());
timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
s = (new SimpleDateFormat(genericUtility.getApplDateFormat())).format(timestamp).toString();
}
catch(Exception exception)
{
System.out.println("Exception in getCurrdateAppFormat " + exception.getMessage());
}
return s;
}
private Timestamp getCurrdateTsFormat()
{
String s = "";
Timestamp timestamp = null;
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
java.util.Date date = null;
timestamp = new Timestamp(System.currentTimeMillis());
SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = simpledateformat.parse(timestamp.toString());
timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
}
catch(Exception exception)
{
System.out.println("Exception in getCurrdateAppFormat " + exception.getMessage());
}
return timestamp;
}
private String getNodeValue( Node currDet, String fldName, boolean isAttribute )
{
String fldValue = null;
boolean isFound = false;
NodeList currNodes = currDet.getChildNodes();
int currDetLen = currNodes.getLength();
for(int detIdx = 0; detIdx < currDetLen && !isFound ; detIdx++ )
{
Node currNode = currNodes.item( detIdx );
String nodeName = currNode.getNodeName();
if( isAttribute == true )
{
if ( nodeName.equalsIgnoreCase( "attribute" ) )
{
fldValue = currNode.getAttributes().getNamedItem( fldName ).getNodeValue();
isFound = true;
}
}
else if ( currNode.getNodeType() == Node.ELEMENT_NODE && nodeName.equalsIgnoreCase( fldName ) )
{
fldValue = currNode.getFirstChild() != null ? currNode.getFirstChild().getNodeValue().trim() : null;
isFound = true;
}
}
return fldValue;
}
private String getItemChgdata( Document dom, Document dom1, Connection conn ) throws RemoteException,ITMException
{
StringBuffer itmChangeString = new StringBuffer("");
String sql = "";
ResultSet rs = null;
PreparedStatement pStmt = null;
try
{
String itemDescr = "";
String itemSer = "";
double discPerc = 0.0;
double rate = 0.0;
double saleQty = 0.0;
double saleRetQty = 0.0;
double confQty = 0.0;
double unconfQty = 0.0;
java.sql.Timestamp tranDateTs = null;
String itemCode = genericUtility.getColumnValue( "item_code", dom );
String lotNo = genericUtility.getColumnValue( "lot_no", dom );
String rateSell = genericUtility.getColumnValue( "rate__sell", dom );
String discPerStr = genericUtility.getColumnValue( "discount_per", dom );
String tranId = genericUtility.getColumnValue( "tran_id", dom );
String tranDate = genericUtility.getColumnValue( "tran_date", dom1 );
String lineNo = genericUtility.getColumnValue( "line_no", dom );
String siteCode = genericUtility.getColumnValue( "site_code", dom1 );
String siteCodeCr = genericUtility.getColumnValue( "site_code__cr", dom1 );
String custCode = genericUtility.getColumnValue( "cust_code", dom1 );
String custCdEnd = genericUtility.getColumnValue( "cust_code__end", dom1 );
String type = genericUtility.getColumnValue( "type", dom1 );
String priceList = genericUtility.getColumnValue( "price_list", dom1 );
System.out.println("tranDate++>"+tranDate);
tranDateTs = Timestamp.valueOf(genericUtility.getValidDateString(tranDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("tranDateTs++>"+tranDateTs);
if( itemCode != null && itemCode.trim().length() > 0 )
{
sql = "select DESCR, item_ser from item "
+"where item_code = ? ";
pStmt = conn.prepareStatement( sql );
pStmt.setString(1,itemCode.trim());
rs = pStmt.executeQuery();
if( rs.next() )
{
itemDescr = rs.getString( "DESCR" );
itemSer = rs.getString( "item_ser" );
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
itmChangeString.append("<item_descr>").append("<![CDATA[" + ( itemDescr )+ "]]>").append("</item_descr>");
itmChangeString.append("<item_ser>").append("<![CDATA[" + ( itemSer )+ "]]>").append("</item_ser>");
}
//itmChangeString.append("<item_descr>").append("<![CDATA[" + ( itemDescr )+ "]]>").append("</item_descr>");
// itmChangeString.append("<item_ser>").append("<![CDATA[" + ( itemSer )+ "]]>").append("</item_ser>");
if( type != null && custCdEnd != null && itemSer != null && (discPerStr == null || discPerStr.trim().equals("0.0")) )
{
if( type.equals("S") )
{
sql = "select disc_perc from disc_apr_strg where item_ser = ? "
+" and sc_code = ? "
+" and ? between eff_from and valid_upto ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSer.trim() );
pStmt.setString(2, custCdEnd.trim() );
pStmt.setTimestamp(3, getCurrdateTsFormat() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
else
{
sql = "select disc_perc from customer_series where item_ser = ? "
+" and cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemSer.trim() );
pStmt.setString(2, custCdEnd.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
discPerc = rs.getDouble("disc_perc");
}
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
itmChangeString.append("<discount_per>").append("<![CDATA["+ discPerc + "]]>").append("</discount_per>");
}
if( (priceList == null || priceList.trim().length() == 0) && ( siteCodeCr != null ) )
{
sql = "select price_list from site_customer "
+" where site_code = ? "
+" and cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, siteCodeCr.trim() );
pStmt.setString(2, custCode.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
priceList = rs.getString("price_list");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
if( priceList == null )
{
sql = "Select price_list from customer where cust_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode.trim() );
rs = pStmt.executeQuery();
if( rs.next() )
{
priceList = rs.getString("price_list");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
}
/* if( itemCode != null && itemCode.trim().length() > 0 && lotNo != null && lotNo.trim().length() > 0 )
{
sql = "Select rate from pricelist where "
+" price_list = ? "
+" and item_code = ? "
+" and list_type = 'B' "
+" and lot_no__from <= ? "
+" and lot_no__to >= ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, priceList);
pStmt.setString(2, itemCode);
pStmt.setString(3, lotNo);
pStmt.setString(4, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = rs.getDouble("rate");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
} */
if( lotNo != null && lotNo.trim().length() > 0 )
{
sql = "Select min(eff_cost) as rate from min_rate_history "
+" where item_code = ? "
+" and lot_no = ? "
+" and cust_code = ? "
+" and site_code = ?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemCode);
pStmt.setString(2, lotNo);
pStmt.setString(3, custCode);
pStmt.setString(4, siteCode);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = rs.getDouble("rate");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
if( rate == 0.0 )
{
sql = "Select rate from pricelist "
+" where price_list = ?"
+" and item_code = ?"
+" and lot_no__from <= ?"
+" and lot_no__to >= ?"
+ "and eff_from <= ? "
+ "and valid_upto >= ?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, priceList);
pStmt.setString(2, itemCode);
pStmt.setString(3, lotNo);
pStmt.setString(4, lotNo);
pStmt.setTimestamp(5, tranDateTs);
pStmt.setTimestamp(6, tranDateTs);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = rs.getDouble("rate");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
if( rate == 0.0 )
{
sql = "Select min(b.rate) as rate from invoice a, invoice_trace b "
+" where a.invoice_id = b.invoice_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.tran_date <= ? "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.confirmed = 'Y'" ;
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setTimestamp(3, getCurrdateTsFormat());
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = rs.getDouble("rate");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
}
sql = "select sum(b.quantity) as saleQty from invoice a, invoice_trace b "
+" where a.invoice_id = b.invoice_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.tran_date <= ? "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.confirmed = 'Y'" ;
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setTimestamp(3, getCurrdateTsFormat());
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
saleQty = rs.getDouble("saleQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when B.ret_rep_flag = 'R' then -b.quantity else b.quantity end) as saleRetQty "
+" from sreturn a, sreturndet b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.tran_date <= ? "
+" and b.item_code = ? "
+" and b.lot_no = ? "
+" and a.confirmed = 'Y'" ;
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setTimestamp(3, getCurrdateTsFormat());
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
saleRetQty = rs.getDouble("saleRetQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when b.quantity is null then 0 else b.quantity end) as confQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and a.confirmed = 'Y' "
+" and b.item_code = ? "
+" and b.lot_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setString(3, itemCode);
pStmt.setString(4, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
confQty = rs.getDouble("confQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
sql = "select sum(case when b.quantity is null then 0 else b.quantity end) as unconfQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and (case when a.confirmed is null then 'N' else a.confirmed end) = 'N' "
+" and b.item_code = ? "
+" and b.lot_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, custCode);
pStmt.setString(2, siteCode);
pStmt.setString(3, itemCode);
pStmt.setString(4, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
unconfQty = rs.getDouble("unconfQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null;
/* sql = "select ('"+unconfQty+"' - (case when b.quantity is null then 0 else b.quantity end)) as unconfQty "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and b.tran_id = ? "
+" and b.line_no = ? "
+" and a.cust_code = ? "
+" and a.site_code = ? "
+" and (case when a.confirmed is null then 'N' else a.confirmed end) = 'N' "
+" and b.item_code = ? "
+" and b.lot_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, tranId);
pStmt.setString(2, lineNo);
pStmt.setString(2, custCode);
pStmt.setString(3, siteCode);
pStmt.setString(4, itemCode);
pStmt.setString(5, lotNo);
rs = pStmt.executeQuery();
if( rs.next() )
{
unconfQty = rs.getDouble("unconfQty");
}
rs.close();
rs = null;
pStmt.close();
pStmt = null; */
//saleRetQty = Math.abs(saleRetQty);
itmChangeString.append("<rate__sell>").append("<![CDATA["+ rate + "]]>").append("</rate__sell>");
itmChangeString.append("<sale_qty>").append("<![CDATA["+ saleQty + "]]>").append("</sale_qty>");
itmChangeString.append("<sale_ret_qty>").append("<![CDATA["+ saleRetQty + "]]>").append("</sale_ret_qty>");
itmChangeString.append("<conf_claimed>").append("<![CDATA["+ confQty + "]]>").append("</conf_claimed>");
itmChangeString.append("<unconf_claimed>").append("<![CDATA["+ unconfQty + "]]>").append("</unconf_claimed>");
}
}
catch(Exception e)
{
System.out.println("Exception :ChargeBackLoc :itemChange(String xmlString2, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
return itmChangeString.toString();
}
private String getCalculations( Document dom ) throws RemoteException,ITMException
{
StringBuffer itmChangeString = new StringBuffer("");
double rate = 0.0;
double discAmt = 0.0;
double rateDiff = 0.0;
double amount = 0.0, endCustRateDbl = 0.0, taxAmtDbl = 0.0;
double netAmt = 0.0, quantityDbl = 0.0, rateSellDbl = 0.0, discPerDbl = 0.0;
double discPerUnit = 0.0;
try
{
String quantity = genericUtility.getColumnValue( "quantity", dom );
String rateSell = genericUtility.getColumnValue( "rate__sell", dom );
String discPer = genericUtility.getColumnValue( "discount_per", dom );
String endCustRate = genericUtility.getColumnValue( "rate__contr", dom );
String taxAmt = genericUtility.getColumnValue( "tax_amt", dom );
if( quantity != null && quantity.trim().length() > 0 )
quantityDbl = Double.parseDouble(quantity);
if( rateSell != null && rateSell.trim().length() > 0 )
rateSellDbl = Double.parseDouble(rateSell);
if( discPer != null && discPer.trim().length() > 0 )
discPerDbl = Double.parseDouble(discPer);
if( endCustRate != null && endCustRate.trim().length() > 0 )
endCustRateDbl = Double.parseDouble(endCustRate);
if( taxAmt != null && taxAmt.trim().length() > 0 )
taxAmtDbl = Double.parseDouble(taxAmt);
if( endCustRateDbl <= 0 )
{
rate = rateSellDbl;
}
else
{
rate = Math.min( endCustRateDbl, rateSellDbl );
rateDiff = rateSellDbl - endCustRateDbl;
}
discAmt = (quantityDbl * rate * discPerDbl)/ 100;
amount = rateDiff * quantityDbl;
netAmt = amount + discAmt + taxAmtDbl;
discPerUnit = (rate * discPerDbl) / 100;
itmChangeString.append("<discount_amt>").append("<![CDATA["+ discAmt + "]]>").append("</discount_amt>");
itmChangeString.append("<amount>").append("<![CDATA["+ amount + "]]>").append("</amount>");
itmChangeString.append("<net_amt>").append("<![CDATA["+ netAmt + "]]>").append("</net_amt>");
itmChangeString.append("<discount_per_unit>").append("<![CDATA["+ discPerUnit + "]]>").append("</discount_per_unit>");
itmChangeString.append("<rate__diff>").append("<![CDATA["+ rateDiff + "]]>").append("</rate__diff>");
}
catch(Exception e)
{
System.out.println("Exception :ChargeBackLoc :itemChange(String xmlString2, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
return itmChangeString.toString();
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
import ibase.webitm.utility.ITMException;
import org.w3c.dom.*;
import ibase.webitm.ejb.ValidatorLocal;
//import javax.ejb.CreateException;
//import javax.ejb.EJBHome;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface ChargeBackLocLocal extends ValidatorLocal
{
//public Validator create() throws RemoteException, CreateException;
public String wfValData() throws RemoteException,ITMException;
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;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
\ No newline at end of file
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.*;
//import javax.ejb.EJBObject;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import javax.ejb.Remote; // added for ejb3
import ibase.webitm.ejb.ValidatorRemote;// added for ejb3
@Remote // added for ejb3
public interface ChargeBackLocRemote extends ValidatorRemote
{
public String wfValData() throws RemoteException,ITMException;
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;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
\ No newline at end of file
package ibase.webitm.ejb.dis;
import ibase.webitm.utility.*;
import org.w3c.dom.*;
import ibase.utility.CommonConstants;
import ibase.webitm.ejb.*;
import ibase.system.config.*;
import java.rmi.RemoteException;
import java.util.*;
import java.text.*;
import java.sql.*;
import javax.ejb.*;
import java.util.Calendar;
import java.util.Date;
import javax.naming.InitialContext;
import ibase.system.config.AppConnectParm;
//import ibase.webitm.ejb.MasterStateful;
//import ibase.webitm.ejb.MasterStatefulHome;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ChrgBckLocConf extends ActionHandlerEJB implements ChrgBckLocConfLocal, ChrgBckLocConfRemote
{
GenericUtility genericUtility = GenericUtility.getInstance();
String userId ="";
String termId = "";
String loginSite = "";
/* public void ejbCreate() throws RemoteException, CreateException
{
System.out.println("Create Method Called....");
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
} */
public String confirm() throws RemoteException,ITMException
{
System.out.println("confirm() Method Called....");
return "";
}
public String confirm(String xmlString, String xtraParams, String objContext) throws RemoteException,ITMException
{
String retString = null;
System.out.println("Xtra Params : " + xtraParams);
//genericUtility = GenericUtility.getInstance();
try
{
retString = actionConfirm(xmlString, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception :actionHandler(String xmlString):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from actionHandler"+retString);
return (retString);
}
private String actionConfirm(String tranID, String xtraParams) throws RemoteException,ITMException, Exception
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int cnt = 0;
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
ConnDriver connDriver = new ConnDriver();
String sql = "";
String siteCode = "";
String custCode = "";
String empCode = "";
String confirmed = "";
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
empCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
termId = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "termId" );
java.sql.Timestamp currDate = null;
java.sql.Timestamp tranDate = null;
String returnString = null;
boolean conFlag = false;
String errStr = "";
try
{
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
currDate = new Timestamp( System.currentTimeMillis() );
sql = "select tran_id, tran_date, site_code, cust_code, confirmed "
+" from charge_back "
+" where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, tranID );
rs = pstmt.executeQuery();
if( rs.next() )
{
tranDate = rs.getTimestamp("tran_date");
siteCode = rs.getString("site_code");
custCode = rs.getString("cust_code");
confirmed = rs.getString("confirmed");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( confirmed != null && confirmed.trim().equals("Y") )
{
errStr = "TRNADYCONF";
returnString = itmDBAccessEJB.getErrorString("",errStr,userId);
return returnString;
}
sql = "update charge_back set "
+" confirmed = 'Y', "
+" VERIFY_FLAG = 'Y', "
+" conf_date = ?, "
+" emp_code__aprv = ?"
+" where tran_id = ? ";
// +" and confirmed <> 'Y' ";
System.out.println( "upd sql " + sql );
pstmt = conn.prepareStatement( sql );
pstmt.setTimestamp( 1, currDate );
pstmt.setString( 2, empCode );
pstmt.setString( 3, tranID );
int chkupdt = pstmt.executeUpdate();
System.out.println("chkupdt==>"+chkupdt);
pstmt.close();
pstmt = null;
returnString = createMiscCrnoteCback(currDate, "", siteCode, tranID, tranID, tranDate, tranDate, custCode, custCode, "Y", xtraParams, conn );
if( returnString .equals("VTSUCC1") )
{
conFlag = true;
errStr = "TRANCONFSC";
}
else
{
conFlag = false;
errStr = returnString;
}
returnString = itmDBAccessEJB.getErrorString("",errStr,userId);
}
catch(Exception e)
{
System.out.println("ChrgBckLocConfEJB..."+e.getMessage());
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception e1)
{
System.out.println("ChrgBckLocConfEJB..."+e1.getMessage());
e1.printStackTrace();
}
}
finally
{
try
{
if(conFlag)
{
System.out.println("Commiting connection.......");
conn.commit();
}
else
{
System.out.println("Connection Rollback.......");
conn.rollback();
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(conn != null)
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
System.out.println("Exception ChrgBckLocConfEJB....... :\n"+e.getMessage());
}
}
System.out.println("retString ::"+returnString);
return returnString;
}
private String createMiscCrnoteCback(Timestamp currDate, String str, String siteCode, String tranIdFr, String tranIdTo, Timestamp tranDateFr, Timestamp tranDateTo, String custCodeFr, String custCodeTo, String confirm, String xtraParams, Connection conn ) throws RemoteException,ITMException
{
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmtHdr = null;
PreparedStatement pstmtDtl = null;
ResultSet rs = null;
Statement stmt = null;
ResultSet rSet = null;
String sql = null;
String custCodeCr = "";
String currCode = "";
String finEntity = "";
String acctCode = "";
String cctrCode = "";
String empCodeAprv = "";
String tranIdSel = "";
String pOrderNo = "";
String siteCodeCr = "";
String itemSer = "";
String remarks = "";
String detAcct = "";
String errCode = "";
String retString = "";
String detCctr = "";
String tranType = "";
String reasonCd = "";
String crNtTranId = "";
String acctCodeTax = "";
String cctrCodeTax = "";
String round = "";
String insDtlsql = "";
String asPost = confirm;
double roundTo = 0.0;
double exchgRate = 0.0;
double netAmt = 0.0;
double claimAmt = 0.0;
double grossAmount = 0.0;
double drcrAmt = 0.0;
double amtTax = 0.0;
double total = 0.0;
double roundAmt = 0.0;
double diffAmt = 0.0;
double discountAmt = 0.0;
int llLineNo = 0;
java.sql.Timestamp tranDate = null;
java.sql.Timestamp pOrderDate = null;
String insHdrSql = "insert into MISC_DRCR_RCP ( "
+" TRAN_ID, TRAN_SER, TRAN_DATE, EFF_DATE, FIN_ENTITY, "
+" SITE_CODE, SUNDRY_TYPE, SUNDRY_CODE, ACCT_CODE, CCTR_CODE, "
+" AMOUNT, CURR_CODE, EXCH_RATE, REMARKS, DRCR_FLAG, "
+" TRAN_ID__RCV, CONFIRMED, CHG_USER, CHG_DATE, CHG_TERM, "
+" CONF_DATE, EMP_CODE__APRV, DUE_DATE, TRAN_TYPE, ITEM_SER, "
+" AMOUNT__BC, SRETURN_NO, ADJ_MISC_CRN, ADJ_AMOUNT, PARENT__TRAN_ID, "
+" REV__TRAN, ROUND_ADJ, "
+" CUST_REF_NO, CUST_REF_DATE, CUST_REF_AMT, RND_OFF, RND_TO ) "
+" values ( "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ?, "
+" ?, ? ) ";
String insertDtl = "insert into MISC_DRCR_RDET( "
+" TRAN_ID, LINE_NO, ACCT_CODE, CCTR_CODE, AMOUNT, "
+" NET_AMT, REF_NO, REAS_CODE, ANAL_CODE"
+" ) values ( "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ? )";
DistCommon disComm = new DistCommon();
try
{
pstmtHdr = conn.prepareStatement( insHdrSql );
pstmtDtl = conn.prepareStatement( insertDtl );
sql = "select a.cust_code__credit, a.curr_code, a.exch_rate, a.emp_code__aprv, a.tran_id, "
+" a.net_amt, a.porder_no, a.porder_date, a.claum_amt, a.site_code__cr, a.item_ser, "
+" a.amount, a.remarks, sum(b.discount_amt) as discAmt "
+" from charge_back a, charge_back_det b "
+" where a.tran_id = b.tran_id "
+" and a.tran_id >= ? "
+" and a.tran_id <= ? "
+" and a.tran_date >= ? "
+" and a.tran_date <= ? "
+" and a.cust_code >= ? "
+" and a.cust_code <= ? "
+" and a.site_code = ? "
// +" and a.confirmed = 'Y' "
+" group by a.cust_code__credit, a.curr_code, a.exch_rate, a.emp_code__aprv, a.tran_id, "
+" a.net_amt, a.porder_no, a.porder_date, a.claum_amt, a.site_code__cr, a.item_ser, "
+" a.amount, a.remarks";
pstmt = conn.prepareStatement( sql );
pstmt.setString( 1, tranIdFr );
pstmt.setString( 2, tranIdTo );
pstmt.setTimestamp( 3, tranDateFr );
pstmt.setTimestamp( 4, tranDateTo );
pstmt.setString( 5, custCodeFr );
pstmt.setString( 6, custCodeTo );
pstmt.setString( 7, siteCode );
rs = pstmt.executeQuery();
while( rs.next() )
{
custCodeCr = rs.getString("cust_code__credit");
currCode = rs.getString("curr_code");
exchgRate = rs.getDouble("exch_rate");
empCodeAprv = rs.getString("emp_code__aprv");
tranIdSel = rs.getString("tran_id");
netAmt = rs.getDouble("net_amt");
pOrderNo = rs.getString("porder_no");
pOrderDate = rs.getTimestamp("porder_date");
claimAmt = rs.getDouble("claum_amt");
siteCodeCr = rs.getString("site_code__cr");
itemSer = rs.getString("item_ser");
grossAmount = rs.getDouble("amount");
remarks = rs.getString("remarks");
discountAmt = rs.getDouble("discAmt");
//System.out.println("claimAmt==>["+claimAmt+"]");
//System.out.println("netAmt==>["+netAmt+"]");
//System.out.println("grossAmount ie amount==>["+grossAmount+"]");
if( siteCodeCr == null || siteCodeCr.trim().length() == 0 )
{
siteCodeCr = siteCode;
}
sql = "select fin_entity from site where site_code = ?" ;
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, siteCodeCr.trim() );
rSet = pstmt1.executeQuery();
if( rSet.next() )
{
finEntity = rSet.getString( "fin_entity" );
}
rSet.close();
rSet = null;
pstmt1.close();
pstmt1 = null;
sql = "select acct_code__ar, cctr_code__ar from customer where cust_code = ? " ;
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCodeCr.trim() );
rSet = pstmt1.executeQuery();
if( rSet.next() )
{
acctCode = rSet.getString( "acct_code__ar" );
cctrCode = rSet.getString( "cctr_code__ar" );
}
rSet.close();
rSet = null;
pstmt1.close();
pstmt1 = null;
detAcct = disComm.getDisparams( "999999", "DRCR_ACCT_CBACK", conn );
if( detAcct == null || detAcct.equalsIgnoreCase( "NULLFOUND" ) || detAcct.trim().length() == 0 )
{
errCode = "VMDRCRACCT"; //'DS000' + string(sqlca.sqldbcode)
break;
}
detCctr = disComm.getDisparams( "999999", "DRCR_CCTR_CBACK", conn );
if( detCctr == null || detCctr.equalsIgnoreCase( "NULLFOUND" ) || detCctr.trim().length() == 0 )
{
errCode = "VMLSCCTR"; //'DS000' + string(sqlca.sqldbcode)
break;
}
tranType = disComm.getDisparams( "999999", "CHARGE_BACK_TRAN_TYPE", conn );
if( tranType == null || tranType.equalsIgnoreCase( "NULLFOUND" ) || tranType.trim().length() == 0 )
{
errCode = "VMLSTRTYPE"; //'DS000' + string(sqlca.sqldbcode)
break;
}
reasonCd = disComm.getDisparams( "999999", "CHARGE_BACK_REASON_CODE", conn );
System.out.println( "reasonCd ::" + reasonCd );
if( reasonCd == null || reasonCd.equalsIgnoreCase( "NULLFOUND" ) || reasonCd.trim().length() == 0 )
{
errCode = "VMREASON"; //'DS000' + string(sqlca.sqldbcode)
break;
}
if( claimAmt <= 0 )
{
claimAmt = 0;
drcrAmt = netAmt;
}
else
{
drcrAmt = claimAmt < netAmt ? claimAmt : netAmt;
}
crNtTranId = generateTranId("W_MISC_DRCR_RCP_CR", getCurrdateInAppFormat(), loginSite, userId, tranType );
//-----------------------Inserting into header-----------------------------------
pstmtHdr.setString( 1, crNtTranId );
pstmtHdr.setString( 2, "MDRCRC" );
pstmtHdr.setTimestamp( 3, currDate );
pstmtHdr.setTimestamp( 4, currDate );
pstmtHdr.setString( 5, finEntity );
pstmtHdr.setString( 6, siteCodeCr.trim() );
pstmtHdr.setString( 7, "C" );
pstmtHdr.setString( 8, custCodeCr.trim() );
pstmtHdr.setString( 9, acctCode == null || acctCode.trim().length() == 0 ? "" : acctCode.trim() );
pstmtHdr.setString( 10, cctrCode == null || cctrCode.trim().length() == 0 ? "" : cctrCode.trim() );
pstmtHdr.setDouble( 11, drcrAmt );
pstmtHdr.setString( 12, currCode == null || currCode.trim().length() == 0 ? "" : currCode.trim() );
pstmtHdr.setDouble( 13, exchgRate );
if( remarks == null || remarks.trim().length() == 0 )
{
String tRemStr = null;
System.out.println("tranIdSel->"+tranIdSel+" pOrderNo->"+pOrderNo+" pOrderDate->"+pOrderDate);
tRemStr = ( "CB " + tranIdSel );
pstmtHdr.setString( 14, tRemStr );
}
else
{
pstmtHdr.setString( 14, remarks.trim() );
}
pstmtHdr.setString( 15, "C" );
pstmtHdr.setString( 16, "" );
pstmtHdr.setString( 17, "N" );
pstmtHdr.setString( 18, userId );
pstmtHdr.setTimestamp( 19, currDate );
pstmtHdr.setString( 20, termId );
pstmtHdr.setNull( 21, java.sql.Types.DATE );
pstmtHdr.setString( 22, empCodeAprv );
pstmtHdr.setTimestamp( 23, currDate );
pstmtHdr.setString( 24, ( tranType == null || tranType.trim().length() == 0 ? "" :tranType.trim() ) );
pstmtHdr.setString( 25, ( itemSer == null || itemSer.trim().length() == 0 ? "" : itemSer.trim() ) );
pstmtHdr.setDouble( 26, drcrAmt );
pstmtHdr.setString( 27, ( tranIdSel == null || tranIdSel.trim().length() == 0 ? "" : tranIdSel.trim() ) );
pstmtHdr.setString( 28, "" ); //ADJ_MISC_CRN
pstmtHdr.setDouble( 29, 0.0 ); //ADJ_AMOUNT
pstmtHdr.setString( 30, "" ); //PARENT__TRAN_ID
pstmtHdr.setString( 31, "" ); //REV__TRAN
pstmtHdr.setDouble( 32, 0.0 ); //ROUND_ADJ
//pstmt.setInt( 33, 0 ); //LINE_NO__SRET
//pstmt.setInt( 34, 0 ); //LINE_NO__SRET
//pstmt.setString( 35, "" ); //LOT_NO
pstmtHdr.setString( 33, "" ); //CUST_REF_NO
pstmtHdr.setNull( 34, java.sql.Types.DATE ); //CUST_REF_DATE
pstmtHdr.setDouble( 35, 0.0 ); //CUST_REF_AMT
pstmtHdr.setDouble( 36, 0.0 ); //RND_OFF
pstmtHdr.setDouble( 37, 0.0 ); //RND_TO
int updtCnt = pstmtHdr.executeUpdate();
//System.out.println("updtCnt==>"+updtCnt);
//-----------------------Inserting into detail-----------------------------------
llLineNo = 0;
pstmtDtl.setString( 1, crNtTranId );
llLineNo++;
pstmtDtl.setInt( 2, llLineNo );
pstmtDtl.setString( 3, detAcct );
pstmtDtl.setString( 4, detCctr );
if( claimAmt > 0 && claimAmt < netAmt )
{
pstmtDtl.setDouble( 5, drcrAmt );
pstmtDtl.setDouble( 6, drcrAmt );
}
else
{
pstmtDtl.setDouble( 5, grossAmount );
pstmtDtl.setDouble( 6, grossAmount );
}
pstmtDtl.setString( 7, tranIdSel ); //ref_no
pstmtDtl.setString( 8, ( reasonCd == null || reasonCd.trim().length() == 0 ? "" : reasonCd.trim() ) ); //reas_code
pstmtDtl.setString( 9, "" ); //ANAL_CODE
pstmtDtl.addBatch();
sql = "select acct_code, cctr_code, sum(tax_amt) taxamt "
+" from taxtran "
+" where tran_code = 'S-CHB' and tran_id = ? "
+" and tax_amt <> 0 "
+" and effect <> 'N' "
+" group by acct_code, cctr_code " ;
//
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranIdSel);
rSet = pstmt1.executeQuery();
while( rSet.next() )
{
acctCodeTax = rSet.getString( "acct_code" );
cctrCodeTax = rSet.getString( "acct_code" );
amtTax = rSet.getDouble( "taxamt" );
if( acctCodeTax == null || acctCodeTax.trim().length() == 0 )
{
acctCodeTax = detAcct;
}
if( cctrCodeTax == null || cctrCodeTax.trim().length() == 0 )
{
cctrCodeTax = detCctr;
}
total = total + amtTax;
pstmtDtl.setString( 1, crNtTranId );
llLineNo++;
pstmtDtl.setInt( 2, llLineNo );
pstmtDtl.setString( 3, acctCodeTax );
pstmtDtl.setString( 4, cctrCodeTax );
pstmtDtl.setDouble( 5, amtTax);
pstmtDtl.setDouble( 6, 0.0 );
pstmtDtl.setString( 7, "" ); //ref_no
pstmtDtl.setString( 8, "" ); //reas_code
pstmtDtl.setString( 9, "" ); //ANAL_CODE
pstmtDtl.addBatch();
}
rSet.close();
rSet = null;
pstmt1.close();
pstmt1 = null;
pstmtDtl.executeBatch();
pstmtDtl.close();
pstmtDtl = null;
pstmtHdr.close();
pstmtHdr = null;
sql = "update charge_back set "
+" tran_id__crn = ? "
+" where tran_id = ? ";
pstmt1 = conn.prepareStatement( sql );
pstmt1.setString(1, crNtTranId );
pstmt1.setString(2, tranIdSel );
int updCount = 0 ;
updCount = pstmt1.executeUpdate();
if( updCount == 0 )
{
errCode = "DS000NR";
break;
}
pstmt1.close();
pstmt1 = null;
sql = "select nvl(round,'N') ls_round, nvl(round_to,0.001) lc_round_to from customer where cust_code = ? ";
pstmt1 = conn.prepareStatement( sql );
pstmt1.setString(1, custCodeCr );
rSet = pstmt1.executeQuery();
if( rSet.next() )
{
round = rSet.getString( "ls_round" );
roundTo = rSet.getDouble( "lc_round_to" );
}
rSet.close();
rSet = null;
pstmt1.close();
pstmt1 = null;
roundAmt = disComm.getRndamt( drcrAmt, round, roundTo );
diffAmt = roundAmt - drcrAmt;
if( diffAmt != 0 )
{
//1. update header
//2. insert record in detail
insDtlsql = "insert into MISC_DRCR_RDET( "
+" TRAN_ID, LINE_NO, ACCT_CODE, CCTR_CODE, AMOUNT, "
+" NET_AMT, REF_NO, REAS_CODE, ANAL_CODE, TAX_AMT"
+" ) values ( "
+" ?, ?, ?, ?, ?, "
+" ?, ?, ?, ?, ? )";
pstmt1 = conn.prepareStatement( insDtlsql );
pstmt1.setString( 1, crNtTranId );
llLineNo++;
pstmt1.setInt( 2, llLineNo );
pstmt1.setString( 3, detAcct );
pstmt1.setString( 4, detCctr );
pstmt1.setDouble( 5, -diffAmt);
pstmt1.setDouble( 6, -diffAmt );
pstmt1.setString( 7, "" ); //ref_no
pstmt1.setString( 8, reasonCd.trim() ); //reas_code
pstmt1.setString( 9, "" ); //ANAL_CODE
pstmt1.setDouble( 10, 0 );
pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( "Y".equalsIgnoreCase( asPost ) )
{
conn.commit();
retString = retrieveMiscDrcrRcp( "misc_drcr_rcp",crNtTranId,xtraParams,"N" );
errCode = getErrCodeFromErrStr(retString);
}
}
catch(Exception e)
{
System.out.println("Exception :" + e.getMessage() + ":");
throw new ITMException(e);
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(pstmtDtl != null)
{
pstmtDtl.close();
pstmtDtl = null;
}
if(pstmtHdr != null)
{
pstmtHdr.close();
pstmtHdr = null;
}
}
catch(Exception e)
{
System.out.println("Exception ChrgBckLocConfEJB....... :\n"+e.getMessage());
}
}
return errCode;
}
public String retrieveMiscDrcrRcp(String businessObj, String tranIdFr,String xtraParams, String forcedFlag) throws ITMException
{
String methodName = "";
String compName = "";
String retString = "";
String serviceCode = "";
String serviceURI = "";
String actionURI = "";
String sql = "";
Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
int cnt = 0;
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
methodName = "gbf_post";
actionURI = "http://NvoServiceurl.org/" + methodName;
sql = "SELECT SERVICE_CODE,COMP_NAME FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND EVENT_CODE = 'pre_confirm' ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1,businessObj);
rs = pStmt.executeQuery();
if ( rs.next() )
{
serviceCode = rs.getString("SERVICE_CODE");
compName = rs.getString("COMP_NAME");
}
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1,serviceCode);
rs = pStmt.executeQuery();
if ( rs.next() )
{
serviceURI = rs.getString("SERVICE_URI");
}
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[4];
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tran_id"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "forced_flag"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(compName);
aobj[1] = new String(tranIdFr);
aobj[2] = new String(xtraParams);
aobj[3] = new String(forcedFlag);
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke(aobj);
System.out.println("Return string from NVO is:==>["+retString+"]");
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (pStmt != null )
{
pStmt.close();
pStmt = null;
}
if( conn != null ){
conn.close();
conn = null;
}
}
catch(Exception e)
{}
}
return retString;
}
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());
}
return (currAppdate);
}
private String generateTranId(String windowName, String tranDate, String siteCode ,String signBy,String tranType)
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String generateTranIdSql = null;
String tranId = null;
String xmlValues = null;
StringBuffer xmlValuesBuff = new StringBuffer();
String refSer = "";
String keyString = "";
String tranIdCol = "";
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB( "DriverITM" );
conn.setAutoCommit(false);
generateTranIdSql = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW)= ?";
System.out.println("[ChargeBackLocConfEJB :: generateTranId : input Paramaters][windowName]["+windowName+"][tranDate]["+tranDate+"][siteCode]["+siteCode+"]");
System.out.println( "[ChargeBackLocConfEJB : generateTranId : Tran generator Sql[" + generateTranIdSql+"]" );
pstmt = conn.prepareStatement( generateTranIdSql );
pstmt.setString(1, windowName);
rs = pstmt.executeQuery();
if( rs.next() )
{
keyString = rs.getString("KEY_STRING");
tranIdCol = rs.getString("TRAN_ID_COL");
refSer = rs.getString("REF_SER");
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
System.out.println("[Output of Tran generator Sql ][keyString]["+keyString+"][tranIdCol]["+tranIdCol+"][refSer]["+refSer+"]");
xmlValuesBuff.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>");
xmlValuesBuff.append("<Header></Header>");
xmlValuesBuff.append("<Detail1>");
xmlValuesBuff.append("<tran_id></tran_id>");
xmlValuesBuff.append("<site_code><![CDATA["+siteCode+"]]></site_code>");
xmlValuesBuff.append("<tran_date><![CDATA["+tranDate+"]]></tran_date>");
xmlValuesBuff.append("<vouch_type><![CDATA[F]]></vouch_type>");
xmlValuesBuff.append("<tran_type><![CDATA["+tranType+"]]></tran_type>");
xmlValuesBuff.append("</Detail1></Root>");
xmlValues = xmlValuesBuff.toString();
System.out.println("xmlValues :[" + xmlValues + "]");
TransIDGenerator tg = new TransIDGenerator(xmlValues,signBy, CommonConstants.DB_NAME);
tranId = tg.generateTranSeqID(refSer, tranIdCol, keyString, conn);
System.out.println("tranId :"+tranId);
conn.commit();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if( conn != null ){
conn.close();
conn = null;
}
if( rs != null )
{
rs.close();
rs = null;
}
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
return tranId;
}
private String getErrCodeFromErrStr( String errStr ) throws RemoteException,ITMException
{
String retErrCode = null;
try
{
Document ParseRetString = genericUtility.parseString( errStr );
NodeList RetStringNodeList = ParseRetString.getElementsByTagName("error");
Node RetStringNode = RetStringNodeList.item(0);
retErrCode = RetStringNode.getAttributes().getNamedItem("id").getNodeValue();
}
catch(Exception exception)
{
exception.printStackTrace();
throw new ITMException( exception );
}
return retErrCode;
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.utility.ITMException;
//import javax.ejb.CreateException;
//import javax.ejb.EJBHome;
//import ibase.webitm.ejb.ActionHandlerHome;
//import ibase.webitm.ejb.ActionHandler;
import ibase.webitm.ejb.ActionHandlerLocal;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface ChrgBckLocConfLocal extends ActionHandlerLocal
{
//public ActionHandler create() throws RemoteException, CreateException;
public String confirm() throws RemoteException,ITMException;
public String confirm(String xmlString, String xtraParams, String objContext) throws RemoteException,ITMException;
}
\ No newline at end of file
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import ibase.webitm.utility.ITMException;
//import ibase.webitm.ejb.ActionHandler;
import ibase.webitm.ejb.ActionHandlerRemote;
import javax.ejb.Remote; // added for ejb3
@Remote
public interface ChrgBckLocConfRemote extends ActionHandlerRemote
{
public String confirm() throws RemoteException,ITMException;
public String confirm(String xmlString, String xtraParams, String objContext) throws RemoteException,ITMException;
}
\ 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