Commit da818256 authored by dpawar's avatar dpawar

added proof of delivery Source code


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93378 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 481427ad
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLocal,ProofOfDeliveryRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("------------ wfvalData method called-----------------");
System.out.println("xtraParams --->>> [["+xtraParams+" ]]");
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : ProofOfDelivery.java : wfValData(String xmlString) : ==>\n"+e.getMessage());
throw new ITMException(e);
}
return errString;
} //end of wfValData
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr=0;
String childNodeName = null;
String errString = "",errorType="",loginSite="";
Connection conn = null;
PreparedStatement pstmt;
ResultSet rs=null;
int cnt=0;
int currentFormNo=0;
int childNodeListLength;
ConnDriver connDriver = new ConnDriver();
//ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
try
{
String userId=null,errCode=null;
GenericUtility genericUtility = GenericUtility.getInstance();
conn = connDriver.getConnectDB("DriverITM");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("user ID form XtraParam : "+userId);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("Child name --->> "+childNodeName);
if (childNodeName.equalsIgnoreCase("invoice_id"))
{
String invoiceID="",invoiceConf="";
invoiceID = genericUtility.getColumnValue("invoice_id",dom);
if(invoiceID==null || invoiceID.trim().length() == 0)
{
errCode = "VTINVIDNN";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
else
{
cnt= getDBRowCount(conn,"invoice","invoice_id",invoiceID);
invoiceConf=getNameOrDescrForCode(conn, "invoice", "confirmed", "invoice_id", invoiceID);
System.out.println("invoiceConf--------->> 12121: "+invoiceConf);
if(invoiceConf.trim().equalsIgnoreCase("N"))
{
//Invoice Id not confirmed then show error
System.out.println("INSIDE--------------------");
errCode = "VTINVNCON";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
if(cnt == 0)
{
errCode = "VTINVIDNE";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
}
if (childNodeName.equalsIgnoreCase("wf_status"))
{
String wfStatus="";
wfStatus = genericUtility.getColumnValue("wf_status",dom);
wfStatus= wfStatus==null ?"":wfStatus;
if (wfStatus.trim().equalsIgnoreCase("R"))
{
errCode = "VTREJNOTA";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
} //end for loop
break;
case 2 :
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("quantity__resale"))
{
String qtyResale="",qtyInv="";
qtyResale=genericUtility.getColumnValue("quantity__resale", dom);
qtyInv=genericUtility.getColumnValue("quantity__inv", dom);
System.out.println("quantity__resale---->>"+qtyResale);
System.out.println("qtyInv---->>"+qtyInv);
if(qtyResale !=null && qtyResale.trim().length() >0)
{
double qtyInvD=0.0,qtyResaleD=0.0;
qtyInvD=Double.parseDouble(qtyInv);
qtyResaleD=Double.parseDouble(qtyResale);
System.out.println("qtyInvD---->>"+qtyInvD+" qtyResaleD"+qtyResaleD);
if(qtyResaleD > qtyInvD)
{
//POD quantity can not be greater than invoice quantity
errCode = "VTPODGRT";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
}
}
break;
} //end switch
int errListSize = errList.size();
cnt =0;
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
for (cnt = 0; cnt < errListSize; cnt++ )
{
errCode = (String)errList.get(cnt);
errFldName = (String)errFields.get(cnt);
System.out.println("errCode .........."+errCode);
errString = getErrorString( errFldName, errCode, userId );
errorType = errorType( conn, errCode );
if ( errString.length() > 0)
{
String bifurErrString = errString.substring( errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString =bifurErrString+errString.substring( errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........."+errStringXml);
errString = "";
}
if ( errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
} //end try
catch (SQLException se) {
System.out.println("SQLException ::"+se);
se.printStackTrace();
throw new ITMException(se);
}
catch(Exception e)
{
System.out.println("Exception ::"+e);
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(conn!=null)
{
conn.close();
conn = null;
}
if(connDriver!=null){
connDriver = null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
System.out.println("ErrString ::[ "+errStringXml.toString()+" ]");
return errStringXml.toString();
}
public String itemChanged(String xmlString,String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("------------------ itemChanged called------------------");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [ProofOFDelivery ][itemChanged(String,String)] :==>\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
{
System.out.println("@@@@@@@ itemChanged called");
StringBuffer valueXmlString = new StringBuffer();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
int currentFormNo =0;
String columnValue = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr = 0;
try
{
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver=null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext.trim());
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("-------- currentFormNo : "+currentFormNo);
switch(currentFormNo)
{
case 1 :
valueXmlString.append("<Detail1>");
System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
System.out.println("editFlag =>" +editFlag);
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ) )
{
System.out.println("------------in itm_default--------->");
String confirm="N",wfStatus="O";
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat simpleDateFormatObj = new SimpleDateFormat(genericUtility.getApplDateFormat());
String tranDate = simpleDateFormatObj.format(currentDate.getTime());
valueXmlString.append("<tran_date>").append("<![CDATA[" + tranDate + "]]>").append("</tran_date>");
valueXmlString.append("<confirmed>").append("<![CDATA[" + confirm + "]]>").append("</confirmed>");
valueXmlString.append("<wf_status>").append("<![CDATA[" + wfStatus + "]]>").append("</wf_status>");
}
if((currentColumn.trim().equalsIgnoreCase("invoice_id")))
{
String invoiceID ="",siteCode="",custCode="",sql="",siteDescr="",custName="",currencyCode="",prdCode="";
double amount=0.0,exchRate=0.0;
invoiceID = genericUtility.getColumnValue("invoice_id",dom);
System.out.println("invoiceID ----- :->> "+invoiceID);
if(invoiceID != null && invoiceID.trim().length()>0 )
{
sql="select site_code,cust_code,net_amt,curr_code,exch_rate,prd_code from invoice where invoice_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, invoiceID);
rs=pstmt.executeQuery();
if(rs.next())
{
siteCode=rs.getString(1)==null ? "" :rs.getString(1);
custCode=rs.getString(2)==null ? "" : rs.getString(2);
amount=rs.getDouble(3);
currencyCode=rs.getString(4)==null ? "" : rs.getString(4);
exchRate=rs.getDouble(5);
prdCode=rs.getString(6)==null ? "" :rs.getString(6);
}
rs.close();pstmt.close();
rs=null;pstmt=null;
if(siteCode.trim().length() > 0)
{
siteDescr=getNameOrDescrForCode(conn, "SITE", "DESCR", "SITE_CODE", siteCode);
}
if(custCode.trim().length() > 0)
{
custName=getNameOrDescrForCode(conn, "customer", "cust_name", "cust_code", custCode);
}
System.out.println("period code--->>"+prdCode);
valueXmlString.append("<site_code>").append("<![CDATA[" + siteCode + "]]>").append("</site_code>");
valueXmlString.append("<cust_code>").append("<![CDATA[" + custCode + "]]>").append("</cust_code>");
valueXmlString.append("<amount>").append("<![CDATA[" + amount + "]]>").append("</amount>");
valueXmlString.append("<exch_rate>").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
valueXmlString.append("<curr_code>").append("<![CDATA[" + currencyCode + "]]>").append("</curr_code>");
valueXmlString.append("<site_descr>").append("<![CDATA[" + siteDescr + "]]>").append("</site_descr>");
valueXmlString.append("<cust_name>").append("<![CDATA[" + custName+ "]]>").append("</cust_name>");
valueXmlString.append("<prd_code>").append("<![CDATA[" + prdCode+ "]]>").append("</prd_code>");
System.out.println("siteCode : "+siteCode+" cust code : "+custCode+" amount : "+amount+"exchnage rate : "+exchRate);
}
else
{
//valueXmlString.append("<project_descr>").append("").append("</project_descr>");
valueXmlString.append("<site_code>").append("<![CDATA[]]>").append("</site_code>");
valueXmlString.append("<cust_code>").append("<![CDATA[]]>").append("</cust_code>");
valueXmlString.append("<amount>").append("<![CDATA[]]>").append("</amount>");
valueXmlString.append("<exch_rate>").append("<![CDATA[]]>").append("</exch_rate>");
valueXmlString.append("<curr_code>").append("<![]]>").append("</curr_code>");
valueXmlString.append("<site_descr>").append("<![CDATA[]]>").append("</site_descr>");
valueXmlString.append("<cust_name>").append("<![CDATA[]]>").append("</cust_name>");
}
}
valueXmlString.append("</Detail1>");
break;
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail2>");
int childListLength = childNodeList.getLength();
if (currentColumn.trim().equals("quantity__resale"))
{
System.out.println("-------item chnage quantity__resale-------------");
String rateResale="",rateInv="",quantityInv="",podQty="";
double rateResaleD=0.0,rateInvoiceD=0.0,diffAmt=0.0,quantityInvD=0.0,podQtyD=0.0;
double actualPrice=0.0,PODprice=0.0;
rateInv=genericUtility.getColumnValue("rate__inv",dom);
quantityInv=genericUtility.getColumnValue("quantity__inv",dom);
rateResale=genericUtility.getColumnValue("rate__resale",dom);
podQty=genericUtility.getColumnValue("quantity__resale",dom);
rateInvoiceD=Double.parseDouble(checkSpaceNull(rateInv));
quantityInvD=Double.parseDouble(checkSpaceNull(quantityInv));
actualPrice= rateInvoiceD * quantityInvD;
System.out.println("rateInvoiceD ["+rateInvoiceD+"] * quantityInvD["+quantityInvD+"] = "+actualPrice);
rateResaleD=Double.parseDouble(checkSpaceNull(rateResale));
podQtyD=Double.parseDouble(checkSpaceNull(podQty));
System.out.println("rateResaleD -->>: "+rateResaleD+" podQtyD : "+podQtyD);
PODprice= rateResaleD * podQtyD;
System.out.println("POD Amount ------>>"+PODprice);
diffAmt= PODprice - actualPrice ;
System.out.println("Diff Amount ------>>"+PODprice);
valueXmlString.append("<amount>").append("<![CDATA["+diffAmt+"]]>").append("</amount>");
}
valueXmlString.append("</Detail2>");
}// end switch
valueXmlString.append("</Root>");
} //end try-------------------------------------------------------------
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
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 d)
{
d.printStackTrace();
}
}
return valueXmlString.toString();
}
private String checkSpaceNull(String str)
{
if(str == null || str.trim().length() == 0)
{
str="0.0";
}
return str;
}
private int getDBRowCount(Connection conn, String table_name, String whrCondCol, String whrCondVal)
{
int count=-1;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="select count(1) from "+table_name+" where "+whrCondCol+" = ?";
System.out.println("SQL in getDBRowCount method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception In getDBRowCount method of SalesEnquiry Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getDBRowCount method of SalesEnquiry Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("Connection passed to SalesEnquiry.getDBRowCount() method is null");
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}
private String errorType( Connection conn , String errorCode )
{
String msgType = "";
PreparedStatement pstmt = null ;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, checkNull(errorCode));
rs = pstmt.executeQuery();
while( rs.next() )
{
msgType = rs.getString("MSG_TYPE");
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
private String checkNull(String input)
{
if (input == null)
{
input="";
}
return input;
}
private String getNameOrDescrForCode(Connection conn, String table_name, String descr_col_name,String whrCondCol, String whrCondVal)
{
String descr = null;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="SELECT "+descr_col_name+" FROM "+table_name+" WHERE "+whrCondCol+" = ?";
System.out.println("SQL in getNameOrDescrForCode method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString(descr_col_name);
}
descr=descr==null ?"" :descr;
}
catch(SQLException e)
{
System.out.println("SQL Exception In getNameOrDescrForCode method of ProofOfDelivery Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getNameOrDescrForCode method of ProofOfDelivery Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("Connection passed to ProofOfDelivery.getNameOrDescrForCode() method is null");
} catch (SQLException e) {
e.printStackTrace();
}
}
return descr;
}
private void getStockistPercentage(String allowPercentage,double rateInvoice,double qtyInvoice,double podRate,double podQty)
{
System.out.println("-------- in getDebitNoteAmount method -------------");
double allowPercentageD=0.0,invoiceAmt=0.0,stockistAmt=0.0,actualAllowAmt=0.0,percentageAmtInv=0.0,debitNoteCaclAmount=0.0;
allowPercentage=allowPercentage==null ? "0.0" :allowPercentage;
allowPercentageD=Double.parseDouble(allowPercentage);
invoiceAmt= rateInvoice * qtyInvoice;//10 *100
percentageAmtInv= invoiceAmt * allowPercentageD/100; //1000 * 10/100
actualAllowAmt= invoiceAmt + percentageAmtInv; //1100
System.out.println("percentageAmtInv------>>"+percentageAmtInv);
System.out.println("getDebitNoteAmount -->> actualAllowAmt---------->> "+actualAllowAmt);
stockistAmt= podRate * podQty; //12 * 100 = 1200
if(stockistAmt > actualAllowAmt)
debitNoteCaclAmount= stockistAmt - actualAllowAmt; //1200 -1100 =100
else
debitNoteCaclAmount=0.0;
System.out.println("--------debitNoteCaclAmount------ :Debit note amount "+debitNoteCaclAmount);
}
}
package ibase.webitm.ejb.dis;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
@Stateless
public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeliveryConfLocal,ProofOfDeliveryConfRemote
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
System.out.println("--------------confirm method of ProofOfDeliveryConf ------------- : ");
String retString = "";
try
{
retString = confirmPOD(tranId,xtraParams,forcedFlag);
}
catch(Exception e)
{
System.out.println("Exception :ProofOfDeliveryConf :confirm():" + e.getMessage() + ":");
retString = GenericUtility.getInstance().createErrorString(e);
e.printStackTrace();
}
return retString;
}
private String confirmPOD(String tranId,String xtraParams,String forcedFlag)
{
System.out.println("---------Class : ProofOfDeliveryConf-->> confirm method called-----------");
ResultSet rs=null;
Connection conn=null;
ConnDriver ConnDriver = new ConnDriver();
PreparedStatement pstmt=null;
String errString="",sql="",loginSite="",wfStatus="",itemCode="",regulatedPrice="";
double invRate=0.0,invQty=0.0,PODrate=0.0,PODqty=0.0,allowedAmt=0.0,stockistAmt=0.0,debitNoteAmtAct=0.0;
int updCnt=0,lineNo=0;
ITMDBAccessEJB itmdbAccess=new ITMDBAccessEJB();
try
{
ConnDriver connDriver = null;
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverValidator");
conn.setAutoCommit(false);
String confirmed="";
sql = "select confirmed,wf_status from spl_sales_por_hdr WHERE tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if( rs.next() )
{
confirmed =rs.getString(1)==null ? "N":rs.getString(1);
wfStatus=rs.getString(2)==null ? "O" : rs.getString(2);
}
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if( wfStatus != null && wfStatus.equalsIgnoreCase("R") )
{
//Rejected transaction can not confirm
errString = itmdbAccess.getErrorString("", "VTRJCCONF", "", "", conn);
return errString;
}
if( confirmed != null && confirmed.equalsIgnoreCase("Y") )
{
//if already confirm then show error
errString = itmdbAccess.getErrorString("", "VTALCONF", "", "", conn);
return errString;
}
System.out.println("-------wfStatus before confirm -------"+wfStatus);
//Only submitted transaction allowed to confirm
if(wfStatus.trim().equalsIgnoreCase("S"))
{
String invoiceId="",custCode="",siteCode="",currCode="",loginCode="";
double ExchRate=0.0;
boolean isRegPrice=false;
GenericUtility genericUtility=new GenericUtility();
loginCode=genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("Login Code ------->> "+loginCode);
sql="";
//emp_code__aprv login code BASE not available in Employee Master
sql="update spl_sales_por_hdr set confirmed = ?,conf_date = ?, emp_code__aprv = ? where tran_id = ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "Y");
pstmt.setDate(2, new java.sql.Date(System.currentTimeMillis()));
pstmt.setString(3,"E10808");
pstmt.setString(4, tranId);
updCnt=pstmt.executeUpdate();
if (updCnt > 0)
{
sql="";
sql="select cust_code,site_code,curr_code,exch_rate from spl_sales_por_hdr where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if( rs.next() )
{
custCode=rs.getString(1)==null ? "" : rs.getString(1);
siteCode=rs.getString(2)==null ? "" : rs.getString(2);
currCode=rs.getString(3)==null ? "" : rs.getString(3);
ExchRate=rs.getDouble(4);
}
if(rs != null)
{
rs.close();
rs=null;
}
if(pstmt != null)
{
pstmt.close();
pstmt=null;
}
sql="";
sql="select item_code,rate__inv,quantity__inv,rate__resale,quantity__resale,line_no from spl_sales_por_det where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs=pstmt.executeQuery();
while(rs.next())
{
itemCode=rs.getString(1)==null ? "" :rs.getString(1);
invRate=rs.getDouble(2);
invQty=rs.getDouble(3);
PODrate=rs.getDouble(4);
PODqty=rs.getDouble(5);
lineNo=rs.getInt(6);
System.out.println("Line NO :"+lineNo+"------->> invRate : "+invRate+" invQty : "+invQty+" PODrate : "+PODrate+ " PODqty : "+PODqty);
regulatedPrice=getColumnDescr(conn,"regulated_price","item","item_code",itemCode);
//regulatedPrice if null then
//isRegPrice=;
if(isRegulatePriceNull(conn,tranId))
{
//Error : Regulated price is Null
errString = itmdbAccess.getErrorString("", "VTREGPRCN", "", "", conn);
System.out.println("---------Error : Regulated price is Null----------");
return errString;
}
else
{
debitNoteAmtAct=debitNoteCalculation(conn,regulatedPrice,invRate,invQty,PODrate,PODqty);
System.out.println("Line no -->"+lineNo+" --debitNoteAmtAct ------->>"+debitNoteAmtAct);
if (debitNoteAmtAct > 0)
{
System.out.println("-----Debit note generation condition----------");
errString=genDebitNote(tranId,custCode,siteCode,xtraParams,debitNoteAmtAct,currCode,ExchRate, conn);
conn.commit();
errString = itmdbAccess.getErrorString("", "VTCONSUCF", "", "", conn);
System.out.println("------@@@Debit Note Generated successfully------------------");
}
else
{
System.out.println("--------Debit note not generated------------- ");
conn.commit();
}
}
}
}
}
else
{
conn.rollback();
errString = itmdbAccess.getErrorString("", "VTNSUBCON", "", "", conn);
}
} // end try
catch(SQLException se)
{
System.out.println("SQLException : class ProofOfDeliveryConf : ");
se.printStackTrace();
try
{
conn.rollback();
}
catch(Exception e){
System.out.println("Exception : Occure during rollback........");e.printStackTrace();
}
}
catch(Exception e)
{
try
{
conn.rollback();
}
catch (Exception e1)
{
}
e.printStackTrace();
System.out.println("Exception Class [ProofOfDeliveryConf]::"+e.getMessage());
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (conn!=null)
{
conn.close();
conn=null;
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
System.out.println("[ProofOfDeliveryConf]errstring :"+errString);
return errString;
}
private String genDebitNote(String tranId,String custCode,String siteCode ,String xtraParams,double relAmt,String currencyCode,double exchRate, Connection conn) throws ITMException
{
System.out.println("<--------Inside genDebitNote11----------->");
StringBuffer xmlBuffer = new StringBuffer();
String xmlString = "", sql="", refNo="", procCode="";
String retString="";
GenericUtility genutility=null;
SimpleDateFormat sdf=null;
String currAppdate ="";
java.sql.Timestamp currDate = null;
//String siteCode="";
String finEntity="";
String acctCode="";
String cctrCode="";
String acctCodetotAR="";
String cctrCodetotAR="";
String miscDebitNoteTranID="";
PreparedStatement pstmt=null;
ResultSet rs=null;
int count=0;
xmlBuffer.append("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
xmlBuffer.append("<DocumentRoot>");
xmlBuffer.append("<description>").append("Datawindow Root").append("</description>");
xmlBuffer.append("<group0>");
xmlBuffer.append("<description>").append("Group0 description").append("</description>");
xmlBuffer.append("<Header0>");
xmlBuffer.append("<objName><![CDATA[").append("misc_drcr_rcp_dr").append("]]></objName>");
xmlBuffer.append("<pageContext><![CDATA[").append("1").append("]]></pageContext>");
xmlBuffer.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
xmlBuffer.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
xmlBuffer.append("<focusedColumn><![CDATA[").append("").append("]]></focusedColumn>");
xmlBuffer.append("<action><![CDATA[").append("SAVE").append("]]></action>");
xmlBuffer.append("<elementName><![CDATA[").append("").append("]]></elementName>");
xmlBuffer.append("<keyValue><![CDATA[").append("1").append("]]></keyValue>");
xmlBuffer.append("<taxKeyValue><![CDATA[").append(" ").append("]]></taxKeyValue>");
xmlBuffer.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
xmlBuffer.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
xmlBuffer.append("<taxInFocus><![CDATA[").append(false).append("]]></taxInFocus>");
xmlBuffer.append("<description>").append("Header0 members").append("</description>");
try
{
genutility=GenericUtility.getInstance();
sdf=new SimpleDateFormat(genutility.getApplDateFormat());
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
currAppdate = sdf.format(currDate);
//siteCode =(genutility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
finEntity = getColumnDescr(conn, "fin_entity","site","site_code", siteCode);
acctCode = getColumnDescr(conn,"acct_code__ar", "customer", "cust_code", custCode);
cctrCode = getColumnDescr(conn,"cctr_code__ar", "customer", "cust_code", custCode);
//acctCodetotAR=findValue(conn,"ACCT_CODE__TOT_AR", "item_acct_detr", "item_ser", itemser);
//cctrCodetotAR=findValue(conn,"CCTR_CODE__TOT_AR", "item_acct_detr", "item_ser", itemser);
System.out.println("-------FinEntity : "+finEntity+" acctCode : "+acctCode+ " cctrCode : "+cctrCode);
xmlBuffer.append("<Detail1 objContext =\"1\"").append(" objName=\"misc_drcr_rcp_dr\" domID=\"1\" dbID=\"\">");
xmlBuffer.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
xmlBuffer.append("<tran_id/>");
xmlBuffer.append("<tran_ser>").append("<![CDATA[").append("MDRCRD").append("]]></tran_ser>\r\n");
xmlBuffer.append("<tran_date>").append("<![CDATA[").append(currAppdate).append("]]></tran_date>\r\n");
xmlBuffer.append("<eff_date>").append("<![CDATA[").append(currAppdate).append("]]></eff_date>\r\n");
xmlBuffer.append("<fin_entity>").append("<![CDATA[").append(finEntity).append("]]></fin_entity>\r\n");
xmlBuffer.append("<site_code>").append("<![CDATA[").append(siteCode).append("]]></site_code>\r\n");
xmlBuffer.append("<cctr_code>").append("<![CDATA[").append(cctrCode).append("]]></cctr_code>\r\n");
xmlBuffer.append("<sundry_type>").append("<![CDATA[").append("C").append("]]></sundry_type>\r\n");
xmlBuffer.append("<sundry_code>").append("<![CDATA[").append(custCode).append("]]></sundry_code>\r\n");
xmlBuffer.append("<acct_code>").append("<![CDATA[").append(acctCode).append("]]></acct_code>\r\n");
xmlBuffer.append("<curr_code>").append("<![CDATA[" + currencyCode + "]]>").append("</curr_code>");
xmlBuffer.append("<amount>").append("<![CDATA[").append(relAmt).append("]]></amount>\r\n");
xmlBuffer.append("<drcr_flag>").append("<![CDATA[").append("D").append("]]></drcr_flag>\r\n");
//xmlBuffer.append("<item_ser>").append("<![CDATA[").append(itemser).append("]]></item_ser>\r\n");
xmlBuffer.append("<exch_rate>").append("<![CDATA[").append(exchRate).append("]]></exch_rate>\r\n");
xmlBuffer.append("<confirmed>").append("<![CDATA[").append("N").append("]]></confirmed>\r\n");
//xmlBuffer.append("<acct_code__tot_ar>").append("<![CDATA[").append(acctCodetotAR).append("]]></acct_code__tot_ar>\r\n");
//xmlBuffer.append("<cctr_code__tot_ar>").append("<![CDATA[").append(cctrCodetotAR).append("]]></cctr_code__tot_ar>\r\n");
//xmlBuffer.append("<milestone_id>").append("<![CDATA[").append(mileStoneId).append("]]></milestone_id>\r\n");
// xmlBuffer.append("<proj_code>").append("<![CDATA[").append(projCode).append("]]></proj_code>\r\n");
//xmlBuffer.append("<sale_order>").append("<![CDATA[").append(saleOrder).append("]]></sale_order>\r\n");
xmlBuffer.append("<tran_type>").append("<![CDATA[").append("HO").append("]]></tran_type>\r\n");
xmlBuffer.append("<remarks>").append("<![CDATA[").append("Auto Generated Debit Note for POD").append("]]></remarks>\r\n");
xmlBuffer.append("<chg_user/>\r\n");
xmlBuffer.append("<chg_term/>\r\n");
xmlBuffer.append("<chg_date>").append("<![CDATA[").append(currAppdate).append("]]></chg_date>\r\n");
xmlBuffer.append("</Detail1>\r\n");
/*xmlBuffer.append("<Detail2 objContext =\"2\"").append(" objName=\"misc_drcr_rcp_dr\" domID=\"1\" dbID=\"\">");
xmlBuffer.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
xmlBuffer.append("<tran_id/>");
xmlBuffer.append("<line_no>").append("<![CDATA[").append(1).append("]]></line_no>");
xmlBuffer.append("<net_amt>").append("<![CDATA[").append(relAmt).append("]]></net_amt>");
xmlBuffer.append("<amount>").append("<![CDATA[").append(relAmt).append("]]></amount>");
xmlBuffer.append("<acct_code>").append("<![CDATA[").append(acctCodetotAR).append("]]></acct_code>");
xmlBuffer.append("<cctr_code>").append("<![CDATA[").append(cctrCodetotAR).append("]]></cctr_code>");
xmlBuffer.append("<sundry_type>").append("<![CDATA[").append("C").append("]]></sundry_type>\r\n");
xmlBuffer.append("<tax_class>").append("<![CDATA[").append(taxClass).append("]]></tax_class>\r\n");
xmlBuffer.append("<tax_chap>").append("<![CDATA[").append(taxChap).append("]]></tax_chap>\r\n");
xmlBuffer.append("<tax_env>").append("<![CDATA[").append(taxEnv).append("]]></tax_env>\r\n");
xmlBuffer.append("</Detail2>");*/
xmlBuffer.append("</Header0>");
xmlBuffer.append("</group0>");
xmlBuffer.append("</DocumentRoot>");
System.out.println("^^^^^^After document root end^^^^^^^^");
xmlString=xmlBuffer.toString();
System.out.println("xmlString of Debit Note --->>: [["+xmlString+"]]");
System.out.println("------ debit Note Data saving------------------");
retString=saveData(siteCode, xmlString, conn);
System.out.println("------ debit Note Data saved successfully123------------------");
if (retString.indexOf("Success") > -1)
{
System.out.println("retString.indexOf(Success) > -1)");
String[] arrayForTranId = retString.split("<TranID>");
int endIndex = arrayForTranId[1].indexOf("</TranID>");
miscDebitNoteTranID = arrayForTranId[1].substring(0,endIndex);
//retString ="";
System.out.println("@@@@@@3: retString"+retString);
System.out.println("miscDebitNoteTranID : "+miscDebitNoteTranID);
if(miscDebitNoteTranID != null && miscDebitNoteTranID.trim().length() > 0)
{
sql="update spl_sales_por_hdr set tran_id__drn = ? where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,miscDebitNoteTranID);
pstmt.setString(2, tranId);
pstmt.executeUpdate();
System.out.println("tran_id__drn updated successfully----------");
}
}
}catch(Exception e)
{
retString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String saveData(String siteCode, String xmlString, Connection conn) throws ITMException
{
System.out.println("saving data...........");
InitialContext ctx = null;
String retString = null;
MasterStatefulLocal masterStateful = null; // for ejb3
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
String [] authencate = new String[2];
authencate[0] = "";
authencate[1] = "";
System.out.println("xmlString :::: " + xmlString);
retString = masterStateful.processRequest(authencate, siteCode, true, xmlString, true, conn);
masterStateful = null;
}
catch(ITMException itme)
{
System.out.println("ITMException :PosConfirm :saveData :==>");
throw itme;
}
catch(Exception e)
{
System.out.println("Exception :PosConfirm :saveData :==>");
throw new ITMException(e);
}
return retString;
}
private String getColumnDescr(Connection conn, String columnName ,String tableName, String columnName2, String value) throws ITMException, RemoteException
{
PreparedStatement pstmt = null ;
ResultSet rs = null ;
String sql = "";
String findValue = "";
try
{
sql = "SELECT " + columnName + " from " + tableName + " where " + columnName2 +"= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,value);
rs = pstmt.executeQuery();
if(rs.next())
{
findValue = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
System.out.println("Exception in findValue ");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning String from findValue " + findValue);
return findValue;
}
private double debitNoteCalculation(Connection conn,String regulaPrice,double rateInvoice,double qtyInvoice,double podRate,double podQty) throws ITMException, RemoteException
{
System.out.println("----------in debitNoteCalculation method----------");
double debitNoteAmount=0.0;
PreparedStatement pstmt1 = null ;
ResultSet rs1 = null ;
String sql = "";
if(regulaPrice.equalsIgnoreCase("Y"))
{
System.out.println("Regulated price-------->> "+regulaPrice);
double allowPercentageD=0.0,invoiceAmt=0.0,stockistAmt=0.0,actualAllowAmt=0.0,percentageAmtInv=0.0;
String varName="AML_REG_PER",allowPercentage="";
allowPercentage=getColumnDescr(conn,"100-var_value","disparm","var_name",varName);
debitNoteAmount=getDebitNoteAmount(allowPercentage,rateInvoice,qtyInvoice,podRate,podQty);
/*allowPercentage=allowPercentage==null ? "0.0" :allowPercentage;
allowPercentageD=Double.parseDouble(allowPercentage);
invoiceAmt= rateInvoice * qtyInvoice;//10 *100
percentageAmtInv= invoiceAmt * allowPercentageD/100; //1000 * 10/100
actualAllowAmt= invoiceAmt + percentageAmtInv; //1100
stockistAmt= podRate * podQty; //12 * 100 = 1200
if(stockistAmt > actualAllowAmt)
debitNoteAmount= stockistAmt - actualAllowAmt;
else
debitNoteAmount=0.0; */
System.out.println("Actual Debit note Amount : "+debitNoteAmount);
return debitNoteAmount;
}
else if(regulaPrice.equalsIgnoreCase("N"))
{
System.out.println("Regulated price-------->> "+regulaPrice);
double allowPercentageD=0.0,invoiceAmt=0.0,stockistAmt=0.0,actualAllowAmt=0.0,percentageAmtInv=0.0;
String varName="AML_NONREG_PER",allowPercentage="";
allowPercentage=getColumnDescr(conn,"100-var_value","disparm","var_name",varName);
debitNoteAmount=getDebitNoteAmount(allowPercentage,rateInvoice,qtyInvoice,podRate,podQty);
/*allowPercentage=allowPercentage==null ? "0.0" :allowPercentage;
allowPercentageD=Double.parseDouble(allowPercentage);
invoiceAmt= rateInvoice * qtyInvoice;//10 *100
percentageAmtInv= invoiceAmt * allowPercentageD/100; //1000 * 10/100
actualAllowAmt= invoiceAmt + percentageAmtInv; //1100
stockistAmt= podRate * podQty; //12 * 100 = 1200
if(stockistAmt > actualAllowAmt)
debitNoteAmount= stockistAmt - actualAllowAmt;
else
debitNoteAmount=0.0;*/
System.out.println("Actual Debit note Amount : "+debitNoteAmount);
return debitNoteAmount;
}
else if (regulaPrice.equalsIgnoreCase("D"))
{
System.out.println("Regulated price-------->> "+regulaPrice);
//double allowPercentageD=0.0,invoiceAmt=0.0,stockistAmt=0.0,actualAllowAmt=0.0,percentageAmtInv=0.0;
String varName="AML_DPCO_PER",allowPercentage="";
allowPercentage=getColumnDescr(conn,"100-var_value","disparm","var_name",varName);
debitNoteAmount=getDebitNoteAmount(allowPercentage,rateInvoice,qtyInvoice,podRate,podQty);
System.out.println("Actual Debit note Amount : "+debitNoteAmount);
/*invoiceAmt= rateInvoice * qtyInvoice;//10 *100
percentageAmtInv= invoiceAmt * allowPercentageD/100; //1000 * 10/100
actualAllowAmt= invoiceAmt + percentageAmtInv; //1100
stockistAmt= podRate * podQty; //12 * 100 = 1200
if(stockistAmt > actualAllowAmt)
debitNoteAmount= stockistAmt - actualAllowAmt; //1200 -1100 =100
else
debitNoteAmount=0.0;*/
return debitNoteAmount;
}
return debitNoteAmount;
}
private double getDebitNoteAmount (String allowPercentage,double rateInvoice,double qtyInvoice,double podRate,double podQty)
{
System.out.println("-------- in getDebitNoteAmount method -------------");
double allowPercentageD=0.0,invoiceAmt=0.0,stockistAmt=0.0,actualAllowAmt=0.0,percentageAmtInv=0.0,debitNoteCaclAmount=0.0;
allowPercentage=allowPercentage==null ? "0.0" :allowPercentage;
allowPercentageD=Double.parseDouble(allowPercentage);
invoiceAmt= rateInvoice * qtyInvoice;//10 *100
percentageAmtInv= invoiceAmt * allowPercentageD/100; //1000 * 10/100
actualAllowAmt= invoiceAmt + percentageAmtInv; //1100
System.out.println("getDebitNoteAmount -->> actualAllowAmt---------->> "+actualAllowAmt);
stockistAmt= podRate * podQty; //12 * 100 = 1200
if(stockistAmt > actualAllowAmt)
debitNoteCaclAmount= stockistAmt - actualAllowAmt; //1200 -1100 =100
else
debitNoteCaclAmount=0.0;
System.out.println("--------debitNoteCaclAmount------ :Debit note amount "+debitNoteCaclAmount);
return debitNoteCaclAmount;
}
private boolean isRegulatePriceNull(Connection conn,String tranId)
{
boolean isNull=false;
PreparedStatement pstmt1 = null ;
ResultSet rs1 = null ;
String sql="",itemCode="",regulatedPrice="";
sql="select item_code from spl_sales_por_det where tran_id = ?";
//getColumnDescr(conn,"regulated_price","item","item_code",itemCode);
try
{
pstmt1=conn.prepareStatement(sql);
pstmt1.setString(1, tranId);
rs1=pstmt1.executeQuery();
while(rs1.next())
{
itemCode=rs1.getString(1)==null ? "" :rs1.getString(1);
regulatedPrice=getColumnDescr(conn,"regulated_price","item","item_code",itemCode);
System.out.println("--regulatedPrice in isRegulatePriceNull method -->>"+regulatedPrice);
if(regulatedPrice == null || regulatedPrice.trim().length()==0)
return true;
}
}
catch(Exception e)
{
System.out.println("Exception in isRegulatePriceNull method ");
e.printStackTrace();
}
return false;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ActionHandlerLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface ProofOfDeliveryConfLocal extends ActionHandlerLocal
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ActionHandlerRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import java.rmi.RemoteException;
@Remote
public interface ProofOfDeliveryConfRemote extends ActionHandlerRemote
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
@Stateless
public class ProofOfDeliveryDefault extends ActionHandlerEJB implements ProofOfDeliveryDefaultLocal,ProofOfDeliveryDefaultRemote
{
public String actionHandler() throws RemoteException,ITMException
{
return "";
}
public String actionHandler(String actionType, String xmlString, String objContext, String xtraParams) throws RemoteException, ITMException
{
System.out.println("--------- ProofOfDeliveryDefault111-----------------actionType"+actionType);
Document dom=null;
String str=null;
System.out.println("actionType--->>"+actionType);
System.out.println("xmlString---"+xmlString);
System.out.println("Porder Value===="+objContext);
System.out.println("xtraParams---"+xtraParams);
try
{
GenericUtility genutility=GenericUtility.getInstance();
if((xmlString!=null) && (xmlString.trim().length()!=0))
{
System.out.println("xmlString from Servlet Side=="+xmlString);
dom=genutility.parseString(xmlString);
}
if(actionType.equalsIgnoreCase("Items"))
{
str=getItems(dom,objContext,xtraParams);
}
}catch(Exception e)
{
System.out.println("Exception :Porder :actionHandler(String xmlString):" + e.getMessage() + ":");
throw new ITMException(e);
}
return str;
}
private String getItems(Document dom,String objContext,String xtraParams) throws ITMException
{
ResultSet rs=null;
Connection conn=null;
ConnDriver ConnDriver = new ConnDriver();
PreparedStatement pstmt=null;
String retString="",sql="",invoiceID="",lotNo="",lotSl="",itemSerPorm="",itemCode="",itemCodeDesc="",locCode="";
int invLineNo=0;
double rate=0.0,quantity=0.0;
String errString="";
int updCnt=0;
StringBuffer valueXmlBuff = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n");
GenericUtility genutility = GenericUtility.getInstance();
try
{
ITMDBAccessEJB itmDBAccess = new ITMDBAccessEJB();
ConnDriver connDriver = null;
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverValidator");
conn.setAutoCommit(false);
invoiceID = genutility.getColumnValue("invoice_id", dom);
System.out.println("------invoiceID--------- :"+invoiceID);
if(objContext !=null)
{
sql="select rate,quantity,lot_no,lot_sl,item_ser__prom,item_code,inv_line_no from invoice_trace where invoice_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, invoiceID);
rs=pstmt.executeQuery();
int lineNo=0;
while(rs.next())
{
lineNo++;
rate=rs.getDouble(1);
quantity=rs.getDouble(2);
lotNo=rs.getString(3)==null ? "" :rs.getString(3);
lotSl=rs.getString(4)==null ? "" :rs.getString(4);
itemSerPorm=rs.getString(5)==null ? "" :rs.getString(5);
itemCode=rs.getString(6)==null ? "" : rs.getString(6);
invLineNo=rs.getInt(7);
valueXmlBuff.append("<Detail>\r\n");
valueXmlBuff.append("<line_no>").append("<![CDATA["+lineNo+"]]>").append("</line_no>");
valueXmlBuff.append("<line_no__trace>").append("<![CDATA["+invLineNo+"]]>").append("</line_no__trace>");
valueXmlBuff.append("<rate__inv>").append("<![CDATA["+rate+"]]>").append("</rate__inv>");
valueXmlBuff.append("<quantity__inv>").append("<![CDATA["+quantity+"]]>").append("</quantity__inv>");
valueXmlBuff.append("<lot_no>").append("<![CDATA["+lotNo+"]]>").append("</lot_no>");
valueXmlBuff.append("<lot_sl>").append("<![CDATA["+lotSl+"]]>").append("</lot_sl>");
valueXmlBuff.append("<item_ser__prom>").append("<![CDATA["+itemSerPorm+"]]>").append("</item_ser__prom>");
valueXmlBuff.append("<item_code>").append("<![CDATA["+itemCode+"]]>").append("</item_code>");
itemCodeDesc=getNameOrDescrForCode(conn, "item", "descr", "item_code", itemCode);
locCode=getNameOrDescrForCode(conn, "item", "loc_code", "item_code", itemCode);
valueXmlBuff.append("<descr>").append("<![CDATA["+itemCodeDesc+"]]>").append("</descr>");
valueXmlBuff.append("<loc_code>").append("<![CDATA["+locCode+"]]>").append("</loc_code>");
valueXmlBuff.append("</Detail>\r\n");
//select descr from item where item_code = ?
System.out.println("------->>>>Line no :"+lineNo+" rate inv :"+rate+"quantity : "+quantity+" Lot No : "+lotNo+" lotSl : "+lotSl);
System.out.println("------->>>>item_ser__prom : "+itemSerPorm+" itemCodeDesc:"+itemCodeDesc+" loc code "+locCode);
itemCodeDesc="";locCode="";
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
valueXmlBuff.append("</Root>\r\n");
retString = valueXmlBuff.toString();
}//end objContext
}
catch(SQLException se)
{
System.out.println("SQLException : class ProofOfDeliveryDefault : ");
retString = GenericUtility.getInstance().createErrorString(se);
se.printStackTrace();
try
{
conn.rollback();
}
catch(Exception e){
System.out.println("Exception : Occure during rollback........");e.printStackTrace();
}
}
catch(Exception e)
{
System.out.println("Exception : class ProofOfDeliveryDefault : ");
retString = GenericUtility.getInstance().createErrorString(e);
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception se){
System.out.println("Exception : Occure during rollback........");
se.printStackTrace();
}
}
finally
{
try{
if (pstmt != null)
{
pstmt.close();
pstmt=null;
}
if (rs !=null)
{
rs.close();
rs=null;
}
if(conn!=null)
{
conn.close();
conn = null;
}
}catch(Exception e)
{
System.out.println("inside Finally Exception ProofOfDeliveryDefault class:submit() ");
e.printStackTrace();
}
}
System.out.println("Return String ..in deafault EJB ----------->>>>>>>>>>> \n" + retString);
return retString;
}
private String getNameOrDescrForCode(Connection conn, String table_name, String descr_col_name,String whrCondCol, String whrCondVal)
{
String descr = null;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="SELECT "+descr_col_name+" FROM "+table_name+" WHERE "+whrCondCol+" = ?";
System.out.println("SQL in getNameOrDescrForCode method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString(descr_col_name);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception In getNameOrDescrForCode method of ProofOfDelivery Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getNameOrDescrForCode method of ProofOfDelivery Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("==========Connection is null in getNameOrDescrForCode method of ProofOfDeliveryDefault class===========");
} catch (SQLException e) {
e.printStackTrace();
}
}
return descr;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ActionHandlerLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface ProofOfDeliveryDefaultLocal extends ActionHandlerLocal
{
public abstract String actionHandler()
throws RemoteException, ITMException;
public abstract String actionHandler(String actionType, String xmlString, String objContext, String xtraParams)
throws RemoteException, ITMException;
//public abstract String confirm() throws RemoteException, ITMException;
//
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ActionHandlerRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface ProofOfDeliveryDefaultRemote extends ActionHandlerRemote
{
public abstract String actionHandler() throws RemoteException, ITMException;
public abstract String actionHandler(String actionType, String xmlString, String objContext, String xtraParams) throws RemoteException, ITMException;
//public String confirm() throws RemoteException, ITMException;
//
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
@Local
public interface ProofOfDeliveryLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.ejb.Stateless;
@Stateless
public class ProofOfDeliveryReject extends ActionHandlerEJB implements ProofOfDeliveryRejectLocal,ProofOfDeliveryRejectRemote
{
public String actionHandler(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
System.out.println("--------------actionHandler method of ProofOfDeliveryReject ------------- : ");
String retString = "";
try
{
retString = reject(tranId,xtraParams,forcedFlag);
}
catch(Exception e)
{
System.out.println("Exception :ProofOfDeliveryReject :actionHandler():" + e.getMessage() + ":");
retString = GenericUtility.getInstance().createErrorString(e);
e.printStackTrace();
}
return retString;
}
private String reject(String tranId,String xtraParams,String forcedFlag)
{
System.out.println("---------Class : ProofOfDeliveryReject-->> reject method called-----------");
ResultSet rs=null;
Connection conn=null;
PreparedStatement pstmt=null;
String errorString="",sql="";
String errString="";
int updCnt=0;
try
{
ITMDBAccessEJB itmDBAccess = new ITMDBAccessEJB();
ConnDriver connDriver = null;
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverValidator");
conn.setAutoCommit(false);
String wfStatus="",confirmed="";
sql = "select confirmed,wf_status from spl_sales_por_hdr WHERE tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs=pstmt.executeQuery();
if( rs.next() )
{
confirmed =rs.getString(1)==null ? "N":rs.getString(1);
wfStatus =rs.getString(1)==null ? "O":rs.getString(1);
}
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if( confirmed != null && confirmed.equalsIgnoreCase("Y") )
{
//Confirmed Transaction can not be rejected
errString = itmDBAccess.getErrorString("", "VTCONFCRJ", "", "", conn);
return errString;
}
if( wfStatus != null && wfStatus.equalsIgnoreCase("R") )
{
errString = itmDBAccess.getErrorString("", "VTALREJ", "", "", conn);
return errString;
}
sql="";
sql="update spl_sales_por_hdr set wf_status = ? where tran_id = ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "R");
pstmt.setString(2, tranId);
updCnt=pstmt.executeUpdate();
if (updCnt > 0)
{
conn.commit();
errString = itmDBAccess.getErrorString("", "VTREJSUCF", "", "", conn);
System.out.println("--------Column wf_status of spl_sales_por_hdr table updated successfully------- ");
return errString;
}
}
catch(SQLException se)
{
System.out.println("SQLException : class ProofOfDeliveryReject : ");
se.printStackTrace();
try
{
conn.rollback();
}
catch(Exception e){
System.out.println("Exception : Occure during rollback........");
e.printStackTrace();
}
}
catch(Exception e)
{
System.out.println("Exception : class ProofOfDeliveryReject : ");
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception se){
System.out.println("Exception : Occure during rollback........");
se.printStackTrace();
}
}
finally
{
try{
if (pstmt != null)
{
pstmt.close();
pstmt=null;
}
if (rs !=null)
{
rs.close();
rs=null;
}
if(conn!=null)
{
conn.close();
conn = null;
}
}catch(Exception e)
{
System.out.println("inside Finally Exception ProofOfDeliveryReject class:reject() ");
e.printStackTrace();
}
}
return errorString;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ActionHandlerLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface ProofOfDeliveryRejectLocal extends ActionHandlerLocal
{
public String actionHandler(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ActionHandlerRemote;
import javax.ejb.Remote;
@Remote
public interface ProofOfDeliveryRejectRemote extends ActionHandlerRemote
{
public String actionHandler(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
@Remote
public interface ProofOfDeliveryRemote extends ValidatorRemote
{
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment