Commit a78db01b authored by tmahadi's avatar tmahadi

Latest src updated in head


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104792 ce508802-f39f-4f6c-b175-0d175dae99d5
parent df38d33d
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* @author CustStockGWTPostSave written for itemchange issue on closing stock by Saurabh Jarande [16/02/17]
*
*/
package ibase.webitm.ejb.dis;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
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 CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPostSaveLocal,CustStockGWTPostSaveRemote {
public String postSave(String xmlString,String tranId,String editFlag, String xtraParams,Connection conn) throws RemoteException,ITMException
{
System.out.println("------------ postSave method called-111111111----------------CustStockGWTPostSave : ");
System.out.println("tranId111--->>["+tranId+"]");
System.out.println("xml String--->>["+xmlString+"]");
Document dom = null;
String errString="";
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
errString = postSave(dom,tranId,xtraParams,conn);
}
}
catch(Exception e)
{
System.out.println("Exception : CustStockGWTPostSave.java : postSave : ==>\n"+e.getMessage());
throw new ITMException(e);
}
return errString;
}
public String postSave(Document dom,String tranId,String xtraParams,Connection conn) throws ITMException, RemoteException
{
System.out.println("in CustStockGWTPostSave tran_id---->>["+tranId+"]");
ResultSet rs=null;
PreparedStatement pstmt=null;
String sql="";
String errString = "";
String invoiceId="",invoiceIdList="",selectedInvList="";
ibase.utility.E12GenericUtility genericUtility = null;
genericUtility = new ibase.utility.E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB=new ITMDBAccessEJB();
try
{
sql="select invoice_id from cust_stock_inv where tran_id=? and dlv_flg='Y' and ref_ser='S-INV' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery( );
while( rs.next() )
{
invoiceId = rs.getString("invoice_id");
invoiceIdList = invoiceIdList + "'"+invoiceId.trim() + "',";
}
callPstRs(pstmt, rs);
if(invoiceIdList.trim().length() > 0)
{
selectedInvList = invoiceIdList.substring(0,invoiceIdList.length() - 1);
}
else
{
selectedInvList = "' '";
}
System.out.println("selectedInvList>>>>"+selectedInvList);
errString =updateCustStockDet(dom,tranId,selectedInvList,conn);
System.out.println("errString>>>>"+errString);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
}
finally
{
try
{
System.out.println(">>>>>In finally errString:"+errString);
if(errString != null && errString.trim().length()>0 )
{
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
}
}
catch(Exception e)
{
System.out.println("Exception : "+e);
e.printStackTrace();
}
}
return errString;
}
private String updateCustStockDet(Document dom,String tranId,String selectedInvList, Connection conn) throws RemoteException, ITMException
{
// TODO Auto-generated method stub
E12GenericUtility genericUtility =new E12GenericUtility();
String errString="";
PreparedStatement pstmt,pstmt1,pstmt2=null;
ResultSet rs,rs1,rs2 =null;
String clStockInp="",itemCode1="",custCodeDom="",itemSerHd="",orderType="",itemSerHeaderSplit="",calCriItemSerStr="";
String invoiceMonths="",fromdate="",todate="",sql="",priceList="",sysDate="",tarnIdLast="";
int invoiceMonthsPrevious=0,UpdCnt=0;
double rcpQtmDom=0,rcpReplQtmDom=0,rcpFreeQtmDom=0,retQtyDom=0,retQtyFreeDom=0,opStkDom=0,rateOld=0,rateOrgOld=0,rcpValue=0,replValue=0,retValue=0,rcpFreeValue=0;
double clStock=0,formulaValue=0,rateStd=0,quantityStd=0,closingValue=0,rateAll=0,calRate=0,closingRate=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0,grossSecondaryRate=0,salesQtyCal=0;
boolean isClStockInt=false,isItemSerLocal=false;
Timestamp thirdMonthDay=null,prdFromoDateTmstmp=null,prdtoDateTmstmp=null;
ArrayList calCriItemSerList=null;
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
UtilMethods utlmethd = new UtilMethods();
Date currentDate = new Date();
ITMDBAccessEJB itmDBAccessEJB =new ITMDBAccessEJB();
try
{
invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS",conn);
System.out.println("invoiceMonths.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0) )
{
invoiceMonthsPrevious=-3;
}else
{
invoiceMonthsPrevious=Integer.parseInt(invoiceMonths);
}
System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious);
SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate = sdf2.format(currentDate.getTime());
calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn);
if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) )
{
isItemSerLocal=false;
}else
{
calCriItemSerList= new ArrayList(Arrays.asList(calCriItemSerStr.split(",")));
}
System.out.println("isItemSer@@@@@@@after>>>>"+isItemSerLocal);
sql=" select d.item_code,d.cl_stock,d.purc_rcp,d.purc_rcp__repl,d.purc_rcp__free,d.purc_ret,d.purc_ret__repl,d.op_stock," +
" c.cust_code,c.tran_id__last, " +
" d.rcp_val,d.rcp_repl_val,d.ret_val,d.rcp_free_val,c.item_ser,c.order_type,c.from_date,c.to_date " +
" from cust_stock_det d,cust_stock c" +
" where d.tran_id=c.tran_id " +
" and d.cl_value=0 and d.rate=0 and d.cl_stock>0 and d.tran_id=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery();
while(rs.next())
{
itemCode1=checkNull(rs.getString("item_code"));
clStockInp=checkNull(rs.getString("cl_stock"));
rcpQtmDom=rs.getDouble("purc_rcp");
rcpReplQtmDom=rs.getDouble("purc_rcp__repl");
rcpFreeQtmDom=rs.getDouble("purc_rcp__free");
retQtyDom=rs.getDouble("purc_ret");
retQtyFreeDom=rs.getDouble("purc_ret__repl");
opStkDom=rs.getDouble("op_stock");
custCodeDom=checkNull(rs.getString("cust_code"));
tarnIdLast=checkNull(rs.getString("tran_id__last"));
rcpValue=rs.getDouble("rcp_val");
replValue=rs.getDouble("rcp_repl_val");
retValue=rs.getDouble("ret_val");
rcpFreeValue=rs.getDouble("rcp_free_val");
itemSerHd = checkNull(rs.getString("item_ser"));
orderType = checkNull(rs.getString("order_type"));
prdFromoDateTmstmp = rs.getTimestamp("from_date");
prdtoDateTmstmp = rs.getTimestamp("to_date");
if(tarnIdLast.length()>0){
sql = " select CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," +
" CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " +
" cust_stock_det where tran_id=? and item_code=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tarnIdLast);
pstmt1.setString(2, itemCode1);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
rateOld = Double.parseDouble(rs1.getString("rate"));
rateOrgOld = Double.parseDouble(rs1.getString("rate__org"));
}
callPstRs(pstmt1, rs1);
}
System.out.println("prdFromoDateTmstmp :"+prdFromoDateTmstmp);
System.out.println("prdtoDateTmstmp :"+prdtoDateTmstmp);
if(calCriItemSerStr.trim().length()>0)
{
System.out.println("calCriItemSerList.contains(itemSerHd.trim())"+calCriItemSerList.contains(itemSerHd.trim()));
if(calCriItemSerList.contains(itemSerHd.trim()))
{
System.out.println("Inside ItemSer true::::["+calCriItemSerList.contains(itemSerHd.trim())+"]");
isItemSerLocal=true;
}
else{
System.out.println("Inside ItemSer false::::["+calCriItemSerList.contains(itemSerHd.trim())+"]");
isItemSerLocal=false;
}
}
else
{
System.out.println("isItemSer:::::"+isItemSerLocal);
}
itemSerHd=getItemSerList(itemSerHd,conn);
itemSerHeaderSplit=itemSerHd;
isClStockInt= isValidDouble(clStockInp);
System.out.println("isClStockInt>>>>>>"+isClStockInt);
if(isClStockInt && Double.parseDouble(clStockInp)>=0)
{
System.out.println("clStockInp :" + clStockInp);
if (clStockInp != null)
{
clStock = Math.round(Double.parseDouble(clStockInp));
} else
{
clStock = 0.0;
}
System.out.println("opStkDom :" + opStkDom);
System.out.println("rcpQtmDom :" + rcpQtmDom);
System.out.println("rcpReplQtmDom :" + rcpReplQtmDom);
System.out.println("retQtyDom :" + retQtyDom);
System.out.println("retQtyFreeDom :" + retQtyFreeDom);
System.out.println("rcpFreeQtmDom :" + rcpFreeQtmDom);
System.out.println("clStock :" + clStock);
formulaValue=clStock;
System.out.println("formulaValue@@@@@@>>>"+formulaValue);
System.out.println("isItemSer>>>>>"+isItemSerLocal);
if(!isItemSerLocal)
{
/*invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS",conn);
System.out.println("invoiceMonths.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0) )
{
invoiceMonthsPrevious=-3;
}else
{
invoiceMonthsPrevious=Integer.parseInt(invoiceMonths);
}
System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious);
*/
thirdMonthDay= utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay>>>>>>"+thirdMonthDay);
closingValue=0;
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as ,itrc.quantity__stduom,inv.tran_date " +
"FROM invoice_trace itrc,invoice inv WHERE itrc.item_code=? " +
"and itrc.invoice_id=inv.invoice_id and inv.tran_date>=? " +
"and inv.tran_date<=? AND itrc.rate__stduom >0.001 and inv.cust_code=? " +
" ORDER BY inv.tran_date DESC";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,itemCode1);
pstmt1.setTimestamp(2,thirdMonthDay);
pstmt1.setTimestamp(3,prdtoDateTmstmp);
pstmt1.setString(4, custCodeDom );
rs1 = pstmt1.executeQuery( );
while(rs1.next())
{
rateStd = rs1.getDouble("rate__stduom" );
quantityStd = rs1.getDouble("quantity__stduom" );
System.out.println("rateStd :"+rateStd);
System.out.println("quantityStd :"+quantityStd);
if(formulaValue>=quantityStd)
{
closingValue=closingValue+ quantityStd*rateStd;
System.out.println("closing value"+closingValue);
formulaValue=formulaValue-quantityStd;
}
else
{
closingValue=closingValue+ formulaValue*rateStd;
formulaValue=0;
System.out.println("closing value>>>>"+closingValue);
}
closingValue=getRequiredDcml(closingValue,3);
if(formulaValue == 0)
{
break;
}
}
callPstRs(pstmt1, rs1);
System.out.println("closingValue>>>>>>"+closingValue);
System.out.println("formulaValue>>>>>>"+formulaValue);
if(formulaValue>0)
{
sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCodeDom );
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
priceList = checkNull(rs1.getString("price_list"));
System.out.println("priceList edit :" + priceList);
}
callPstRs(pstmt1, rs1);
//Added by saurabh to get rate from DDF_PICK_MAX_RATE fuction[18/10/16|Start]
sysDate = genericUtility.getValidDateString( sysDate , getApplDateFormat() , getDBDateFormat());
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, TO_DATE( ? , ? ), ? ) FROM DUAL ";
pstmt1 = conn.prepareStatement( sql );
pstmt1.setString( 1, priceList );
pstmt1.setString( 2, sysDate );
pstmt1.setString( 3, getDBDateFormat() );
pstmt1.setString( 4, itemCode1 );
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
rateAll = rs1.getDouble(1);
System.out.println("rateAll-----------> [" +rateAll+ "]");
}
callPstRs(pstmt1, rs1);
rateAll=getRequiredDcml(rateAll,3);
//Added by saurabh to get rate from DDF_PICK_MAX_RATE fuction[18/10/16|end]
System.out.println("rateAll>>>>>"+rateAll);
closingValue=closingValue+formulaValue*rateAll;
closingValue=getRequiredDcml(closingValue,3);
}
}else
{
calRate=getOpeningRate(invoiceMonthsPrevious,orderType,itemSerHeaderSplit,selectedInvList,rcpQtmDom,itemCode1,prdtoDateTmstmp,prdFromoDateTmstmp,custCodeDom,conn);
calRate=getRequiredDcml(calRate,3);
closingValue=clStock*calRate;
}
if(clStock>0)
{
closingRate=closingValue/clStock;
}else
{
closingRate=0.0;
}
closingRate=getRequiredDcml(closingRate,3);
formulaValue=0;grossSecondaryQty=0;netSecondarySalesValue=0;grossSecondarySalesValue=0;salesQtyCal=0;
grossSecondaryQty=opStkDom+rcpQtmDom+rcpReplQtmDom+rcpFreeQtmDom-retQtyDom-clStock;
System.out.println("grossSecondaryQty>>>>"+grossSecondaryQty);
System.out.println("closingRate@@@@@@@@@"+closingRate);
System.out.println("grossSecondaryQty>>>>>>"+grossSecondaryQty);
System.out.println("formulaValue>>>>>"+formulaValue);
System.out.println("opStkDom>>>"+opStkDom+">>rateOld>>>"+rateOld);
System.out.println("rcpValue>>>"+rcpValue+">>replValue>>>"+replValue);
System.out.println("retValue>>>"+retValue+">>closingValue>>>"+closingValue);
System.out.println("rcpFreeValue>>>>"+rcpFreeValue);
netSecondarySalesValue=(opStkDom*rateOld)+rcpValue+replValue-retValue-closingValue;
netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3);
System.out.println("netSecondarySalesValue>>>>>>>"+netSecondarySalesValue);
grossSecondarySalesValue=(opStkDom*rateOrgOld)+rcpValue+replValue+rcpFreeValue-retValue-closingValue;
grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3);
System.out.println("grossSecondarySalesValue>>>>"+grossSecondarySalesValue);
if(grossSecondaryQty>0)
{
grossSecondaryRate = grossSecondarySalesValue / grossSecondaryQty;
}else
{
grossSecondaryRate=0.0;
}
grossSecondaryRate=getRequiredDcml(grossSecondaryRate,3);
System.out.println("grossSecondaryRate>>>"+grossSecondaryRate);
salesQtyCal = opStkDom + (rcpQtmDom + rcpReplQtmDom) - (retQtyDom + retQtyFreeDom) - clStock;
System.out.println("salesQtyCal :" + salesQtyCal);
sql =" update cust_stock_det set sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? where tran_id=? and item_code=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setDouble(1, salesQtyCal );//sales
pstmt1.setDouble(2, closingRate );//rate
pstmt1.setDouble(3, grossSecondaryRate );//rate__org
pstmt1.setDouble(4, grossSecondaryQty );//sales__org
pstmt1.setDouble(5, closingValue );//cl_value
pstmt1.setDouble(6, netSecondarySalesValue );//sales_value
pstmt1.setDouble(7, getRequiredDcml((opStkDom*rateOld),3) );//op_value
pstmt1.setString(8, tranId);
pstmt1.setString(9, itemCode1);
UpdCnt = pstmt1.executeUpdate();
if(UpdCnt>0)
{
System.out.println("No of record updated:"+UpdCnt+" for tranId>>"+tranId+">>>itemCode1"+itemCode1);
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
}
}
callPstRs(pstmt, rs);
}
catch(Exception e)
{
e.printStackTrace();
//errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
errString=e.getMessage();
}
finally
{
try
{
System.out.println(">>>In finally errString:"+errString);
if( errString != null && errString.trim().length()>0 )
{
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
}
}
catch(Exception e)
{
e.printStackTrace();
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
}
}
return errString;
}
private double getOpeningRate(int invoiceMonthsPrevious,String orderType,String itemSerHeaderSplit,String selectedInvList ,double rcpQtyDom,String itemCode, Timestamp prdtoDateTmstmp,Timestamp prdFromoDateTmstmp, String custCode, Connection conn) throws ITMException
{
E12GenericUtility genericUtility =new E12GenericUtility();
UtilMethods utlmethd = new UtilMethods();
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
String invoiceMonths="",sql="";
String sysDatetemp="",priceList="";
//int invoiceMonthsPrevious=0;
Timestamp thirdMonthDay=null;
double openingRate=0.0;
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null;
String sysDate="";
try
{
Date currentDate = new Date();
SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDatetemp = sdf2.format(currentDate.getTime());
if(rcpQtyDom > 0)
{
sql = " SELECT itrace.RATE__STDUOM as RATE__STDUOM FROM" +
" invoice invoice,invoice_trace itrace ,item item " +
" where invoice.invoice_id=itrace.invoice_id and itrace.item_code=item.item_code AND invoice.cust_code = ? " +
" and item.item_ser in ("+itemSerHeaderSplit+") "+
" AND itrace.RATE__STDUOM>0.001 "+
" and itrace.item_code = ? " +
"and itrace.invoice_id in("+selectedInvList+") ORDER BY invoice.tran_date DESC " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode );
pstmt.setString(2, itemCode );
rs = pstmt.executeQuery( );
if( rs.next() )
{
openingRate = rs.getDouble("RATE__STDUOM" );
System.out.println("openingRate>>>>>> :"+openingRate);
}
callPstRs(pstmt, rs);
}
else
{
/*invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn);
System.out.println("invoiceMonths>>>>.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0))
{
invoiceMonthsPrevious = -3;
} else
{
invoiceMonthsPrevious = Integer.parseInt(invoiceMonths);
}
System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious);*/
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay);
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,inv.tran_date " +
"FROM invoice_trace itrc,invoice inv WHERE itrc.item_code=? " +
"and itrc.invoice_id=inv.invoice_id and inv.tran_date>=? " +
"and inv.tran_date<=? AND itrc.rate__stduom >0.001 and inv.cust_code=? " +
" ORDER BY inv.tran_date DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
pstmt.setTimestamp(2, thirdMonthDay);
pstmt.setTimestamp(3, prdtoDateTmstmp);
pstmt.setString(4, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
openingRate = rs.getDouble("rate__stduom");
System.out.println("openingRate>>>>>> :" + openingRate);
}
callPstRs(pstmt, rs);
if (openingRate == 0)
{
sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
priceList = checkNull(rs1.getString("price_list"));
System.out.println("priceList edit :" + priceList);
}
callPstRs(pstmt1, rs1);
sysDate = genericUtility.getValidDateString( sysDatetemp , getApplDateFormat() , getDBDateFormat());
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, TO_DATE( ? , ? ), ? ) FROM DUAL ";
pstmt1 = conn.prepareStatement( sql );
pstmt1.setString( 1, priceList );
pstmt1.setString( 2, sysDate );
pstmt1.setString( 3, getDBDateFormat() );
pstmt1.setString( 4, itemCode );
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
openingRate = rs1.getDouble(1);
System.out.println("openingRate-----------> [" +openingRate+ "]");
}
callPstRs(pstmt1, rs1);
}
}
}catch(Exception exception)
{
exception.printStackTrace();
throw new ITMException( exception );
}
System.out.println("return openingRate>>>>"+openingRate);
return openingRate;
}
public String getItemSerList(String itemser, Connection conn)
{
String itemSerGrpValue="",itemSerSplit="",resultItemSer="";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = null;
try
{
sql= " select distinct item_ser from" +
"(select item_ser from itemser where grp_code=? " +
"union all " +
"select item_ser from itemser where item_ser=?) ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemser);
pstmt.setString(2, itemser);
rs = pstmt.executeQuery();
while(rs.next())
{
itemSerGrpValue=checkNull(rs.getString("item_ser")).trim();
itemSerSplit=itemSerSplit+"'"+itemSerGrpValue+"',";
}
callPstRs(pstmt, rs);
resultItemSer = itemSerSplit.substring(0, itemSerSplit.length() - 1);
System.out.println("resultItemSer>>>>>"+resultItemSer);
}
catch(Exception exception)
{
exception.printStackTrace();
try
{
throw new ITMException( exception );
} catch (ITMException e)
{
e.printStackTrace();
}
}
return resultItemSer;
}
public boolean isValidDouble(String number) throws ITMException, Exception
{
Boolean isReult = true;
double amount=0.0;
try
{
amount = Double.parseDouble(number);
System.out.println("amount>>>>>>>>"+amount);
} catch (NumberFormatException e)
{
isReult = false;
}
return isReult;
}
public double getRequiredDcml(double actVal, int prec)
{
double value=0.0;
String fmtStr = "############0";
if (prec > 0)
{
fmtStr = fmtStr + "." + "000000000".substring(0, prec);
}
DecimalFormat decFormat = new DecimalFormat(fmtStr);
if(decFormat.format(actVal) != null && decFormat.format(actVal).trim().length() > 0 )
{
value=Double.parseDouble(decFormat.format(actVal));
}else
{
value=0.00;
}
return value;
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.sql.Connection;
import javax.ejb.Local;
@Local
public interface CustStockGWTPostSaveLocal extends ValidatorLocal {
public String postSave(String xmlString,String tranId,String editFlag, String xtraParams,Connection conn) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.sql.Connection;
import javax.ejb.Remote;
@Remote
public interface CustStockGWTPostSaveRemote extends ValidatorRemote {
public String postSave(String xmlString,String tranId,String editFlag, String xtraParams,Connection conn) throws RemoteException,ITMException;
}
...@@ -91,14 +91,12 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -91,14 +91,12 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>"); StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
int currentFormNo =0; int currentFormNo =0;
SimpleDateFormat dateFormat2 = null; SimpleDateFormat dateFormat2 = null;
String dummyProduct="";
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
try try
{ dateFormat2 = new SimpleDateFormat(genericUtility.getApplDateFormat()); { dateFormat2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
System.out.println("@@@@@@@@ wfvaldata called"); System.out.println("@@@@@@@@ wfvaldata called");
//Changes and Commented By Bhushan on 09-06-2016 :START conn = connDriver.getConnectDB("DriverITM");
//conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
//Changes and Commented By Bhushan on 09-06-2016 :END
connDriver = null; connDriver = null;
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode"); userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
if(objContext != null && objContext.trim().length()>0) if(objContext != null && objContext.trim().length()>0)
...@@ -108,7 +106,9 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -108,7 +106,9 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
System.out.println("currentFormNo>>>>>"+currentFormNo); System.out.println("currentFormNo>>>>>"+currentFormNo);
switch(currentFormNo) switch(currentFormNo)
{ {
case 3: case 3:
System.out.println("Case 3::::::dom2 >>>>"+genericUtility.serializeDom(dom2));
parentNodeList = dom2.getElementsByTagName("Detail3"); parentNodeList = dom2.getElementsByTagName("Detail3");
parentNode = parentNodeList.item(0); parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes(); childNodeList = parentNode.getChildNodes();
...@@ -118,8 +118,23 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -118,8 +118,23 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
{ {
childNode = childNodeList.item(ctr); childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("item_code"))
{ //Added by saurabh[04/01/17]
if(childNodeName.equals("attribute"))
{
String updateFlag = "";
updateFlag = childNode.getAttributes().getNamedItem("updateFlag").getNodeValue();
System.out.println("updateFlag>>>"+updateFlag);
if ("D".equalsIgnoreCase(updateFlag))
{
System.out.println("Break from here as the record is deleted");
break;
}
}
//Added by saurabh[04/01/17]
if (childNodeName.equalsIgnoreCase("item_code"))
{
itemCode = this.genericUtility.getColumnValue("item_code", dom); itemCode = this.genericUtility.getColumnValue("item_code", dom);
lineNo = this.genericUtility.getColumnValue("line_no", dom); lineNo = this.genericUtility.getColumnValue("line_no", dom);
...@@ -130,7 +145,8 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -130,7 +145,8 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
errCode = "VTEMTITM"; errCode = "VTEMTITM";
errList.add(errCode); errList.add(errCode);
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
} else }
else
{ {
errCode = isExist("item", "item_code", itemCode, conn); errCode = isExist("item", "item_code", itemCode, conn);
if ("FALSE".equalsIgnoreCase(errCode)) if ("FALSE".equalsIgnoreCase(errCode))
...@@ -138,8 +154,31 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -138,8 +154,31 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
errCode = "VMITMNOTEX"; errCode = "VMITMNOTEX";
errList.add(errCode); errList.add(errCode);
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
}else }else
{ {
dummyProduct = dist.getDisparams("999999","DUMMY_PRODUCT",conn);
if (("NULLFOUND".equalsIgnoreCase(dummyProduct) || dummyProduct == null || dummyProduct.trim().length() == 0) )
{
System.out.println("Disparm not defined for dummy item!!!!");
if("FALSE".equalsIgnoreCase(isFrequent(itemCode,conn)))
{
errCode = "VMFRITMCHK";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else
{
if(!dummyProduct.trim().equalsIgnoreCase(itemCode.trim())){
if("FALSE".equalsIgnoreCase(isFrequent(itemCode,conn)))
{
errCode = "VMFRITMCHK";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
if (isDulplicateFrmDom(dom2,itemCode,lineNo)) if (isDulplicateFrmDom(dom2,itemCode,lineNo))
{ {
errCode = "VTDUPITMCD"; errCode = "VTDUPITMCD";
...@@ -333,6 +372,7 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -333,6 +372,7 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
System.out.println("@@@@ isexist["+value+"]:::["+retStr+"]:::["+cnt+"]"); System.out.println("@@@@ isexist["+value+"]:::["+retStr+"]:::["+cnt+"]");
return retStr; return retStr;
} }
private boolean isDulplicateFrmDom(Document dom,String itemCode, String lineNo) throws ITMException private boolean isDulplicateFrmDom(Document dom,String itemCode, String lineNo) throws ITMException
{ {
NodeList parentList = null; NodeList parentList = null;
...@@ -418,6 +458,36 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC ...@@ -418,6 +458,36 @@ public class CustStockGWTWizIC extends ValidatorEJB implements CustStockGWTWizIC
} }
System.out.println("isDulplicate>>>>>> ["+isDulplicate+"]"); System.out.println("isDulplicate>>>>>> ["+isDulplicate+"]");
return isDulplicate; return isDulplicate;
} }
//Commented by saurabh 040117
private String isFrequent( String itemCode,Connection conn) throws SQLException
{
String sql = "",retStr="";
PreparedStatement pstmt = null;
ResultSet rs = null ;
int cnt=0;
sql = " SELECT COUNT(1) FROM item WHERE item_code = ? and item_usage='F' ";//Added by saurabh[22/12/16]
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( cnt > 0)
{
retStr = "TRUE";
}
if( cnt == 0 )
{
retStr = "FALSE";
}
System.out.println("@@@@ isexist["+itemCode+"]:::["+retStr+"]:::["+cnt+"]");
return retStr;
}
//Commented by saurabh 040117
} }
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.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDataICLocal {
GenericUtility genericUtility = GenericUtility.getInstance();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{
System.out.println("In wfValData");
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = validate(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception : [PurcRCPIc][wfValData(String currFrmXmlStr)] : ==>\n" + e.getMessage());
}
return errString;
}
public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
System.out.println("In validate Data");
GenericUtility genericUtility = GenericUtility.getInstance();
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
int count = 0;
String errString = "";
String errorType = "";
String errCode = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
String childNodeName = "";
String sql = "";
int noOfChilds = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0;
ConnDriver connDriver = null;
Node childNode = null;
String table_no="",prd_code="";
try {
System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData Distribution receipt:::");
String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("**************loginCode************" + userId);
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail"+ currentFormNo);
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if ("prd_code".equalsIgnoreCase(childNodeName) )
{
prd_code = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(prd_code==null || prd_code.trim().length()==0)
{
errList.add("VTNULLPC");//Invalid-Division can not be blank
errFields.add(childNodeName.toLowerCase());
break;
}
}
if ("table_no".equalsIgnoreCase(childNodeName) )
{
table_no = checkNull(genericUtility.getColumnValue("table_no", currDom));
prd_code = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(table_no==null || table_no.trim().length()==0)
{
errList.add("VTNULLDV");//Invalid-Division can not be blank
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE item_ser = ? and prd_code=? and pos_code is not null ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, table_no);
pstmt.setString(2, prd_code);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTINVSEL");//Record Not found
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
}
break;
}
int errListSize = errList.size();
cnt = 0;
String errFldName = "";
if ((errList != null) && (errListSize > 0))
{
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String) errList.get(cnt);
errFldName = (String) errFields.get(cnt);
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("");
}
errString = errStringXml.toString();
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if ((conn != null) && (!conn.isClosed()))
conn.close();
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = null;
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = genericUtility.parseString(currFrmXmlStr);
System.out.println("currFrmXmlStr : " + currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = genericUtility.parseString(hdrFrmXmlStr);
System.out.println("hdrFrmXmlStr : " + hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = genericUtility.parseString(allFrmXmlStr);
System.out.println("allFrmXmlStr : " + allFrmXmlStr);
}
errString = itemChanged(currDom, hdrDom, allDom, objContext,currentColumn, editFlag, xtraParams);
System.out.println("ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":itemChanged :==>\n" + e.getMessage());
errString = genericUtility.createErrorString(e);
}
return errString;
}
public String itemChanged(Document currDom, Document hdrDom,Document allDom, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
int currentFormNo = 0,ctr = 0,childNodeListLength = 0;
String childNodeName = null;
Connection conn = null;
StringBuffer valueXmlString = new StringBuffer();
Date sysdate=null;
String asOnDate="";
try
{
try {
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
} catch (Exception e) {
System.out.println("Exception :Es3HDataUpdPrc :ejbCreate :==>" + e);
e.printStackTrace();
}
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDispDateFormat());
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</Header>\r\n");
System.out.println("currentFormNo-------*************** = "+ currentFormNo);
switch (currentFormNo)
{
case 1:
System.out.println("currentFormNo-------*************** = "+ currentFormNo);
parentNodeList = currDom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr++;
}while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println(" currentColumn : "+ currentColumn);
if (currentColumn.equalsIgnoreCase("itm_default"))
{
/*String sql="select sysdate from dual";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
sysdate = rs.getDate(1);
}
callPstRs(pstmt,rs);
asOnDate=sdf.format(sysdate).toString();
valueXmlString.append("<chg_date>").append(asOnDate).append("</chg_date>\r\n");*/
valueXmlString.append("<table_no>").append("").append("</table_no>\r\n");
valueXmlString.append("<prd_code>").append("").append("</prd_code>\r\n");
}
valueXmlString.append("</Detail1>\r\n");
}
}
catch (Exception localException)
{
localException.printStackTrace();
}
finally
{
try{
conn.close();
conn=null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
valueXmlString.append("</Root>\r\n");
System.out.println("\n****ValueXmlString :" + valueXmlString.toString()+ ":********");
return valueXmlString.toString();
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String checkNull(String inputVal)
{
if (inputVal == null)
{
inputVal = "";
}
return inputVal;
}
private String errorType(Connection conn, String errorCode)
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next())
msgType = rs.getString("MSG_TYPE");
}
catch (Exception ex)
{
ex.printStackTrace();
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return msgType;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface Es3HDataICLocal
{
public abstract String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException;
public String itemChanged(Document currDom, Document hdrDom,Document allDom, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface Es3HDataICRemote {
public abstract String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException;
public String itemChanged(Document currDom, Document hdrDom,Document allDom, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es3HDataUpdPrcRemote {
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
Connection conn = null;
String loginCode = null;
StringBuffer retBuf = null;
String errorString = null;
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null;
Document headerDom = null;
String retStr = "";
System.out.println("windowName[process]::::::::::;;;" + windowName);
System.out.println("xtraParams[process]:::::::::;;;" + xtraParams);
try
{
System.out.println("xmlString[process]::::::::::;;;" + xmlString);
if (xmlString != null && xmlString.trim().length() != 0)
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom" + headerDom);
}
System.out.println("xmlString2[process]::::::::::;;;" + xmlString2);
if (xmlString2 != null && xmlString2.trim().length() != 0) {
detailDom = genericUtility.parseString(xmlString2);
System.out.println("detailDom" + detailDom);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :Es3HDataUpdPrc :process(String xmlString, String xmlString2, String windowName, String xtraParams):"+ e.getMessage() + ":");
e.printStackTrace();
retStr = e.getMessage();
}
return retStr;
}// END OF PROCESS (1)
public String process(Document headerDom, Document detailDom,String windowName, String xtraParams) throws RemoteException,ITMException
{
int parentNodeListLength = 0;
int childNodeListLength = 0;
String errString = null;
String childNodeName = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null, pstmt3 = null;
ResultSet rs = null, rs1 = null, rs2 = null, rs3 = null;
String sql = "", tranId = "", itemCode = "", invoiceId = "", dlvFlag = "";
int sreturnCnt = 0;
double retQty = 0, retRate = 0,retDiscnt=0,totalRetVal=0;
double recptRetQty = 0, recptRetVal = 0;
double recptReplQty = 0, recptReplVal = 0;
double transitReplQty = 0, transitReplVal = 0;
String retReplFlag = "";
double invQty = 0, invRate = 0,invDisCnt=0,netAmt=0;
double recptInvQty = 0, recptInvValue = 0;
double sretQtyAllTot=0 ,primarySalesAll=0;
double transitInvQty = 0, transitInvValue = 0;
double FreeQty = 0, freeValue = 0;
double recptFreeQty = 0, recptFreeValue = 0;
double transitFreeQty = 0, transitFreeValue = 0;
String lineType = "";
double billRetQtyBonusQty = 0, billRetQtyBonusVal = 0,replNetVal=0,totalInvAmt=0,netAmtRet=0,netAmtRep=0;
Timestamp prdFromoDateTmstmp = null, prdtoDateTmstmp = null;
String custCode = "";
double rateStd = 0, quantityStd = 0, formulaValue = 0, closingValue = 0,retQtyFreeDom=0;
String priceList = "",tranIdLast="";
String sysDate = "";
String invoiceMonths = "",table_no="",prd_code="",invoiceIdList="",selectedInvList="";
int invoiceMonthsPrevious = 0,retCnt=0,chkCnt=0;
Timestamp thirdMonthDay = null;
Date currentDate = new Date();
String calCriItemSerStr="", refSer = "";
double priceListRate = 0, clStock = 0,opStkDom=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0;
double closingRate = 0,UpdCnt=0,grossSecondaryRate=0,salesQtyCal=0,rcpQtmDom=0;
double clStockLast=0.0,rateOld=0.0,rateOrgOld=0.0,opValue=0.0,calRate=0.0;
boolean isItemSerLocal=false,isItemFound=false;
ArrayList<String> calCriItemSerList=null;
ClosingStockBean closingStockBean=null;
HashMap<String,ClosingStockBean> closingStockMap=null;
UtilMethods utlmethd = new UtilMethods();
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
HashSet<String> invoiceItemSet=null;
String invoiceItemKey="";
try {
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
} catch (Exception e) {
System.out.println("Exception :Es3HDataUpdPrc :ejbCreate :==>" + e);
e.printStackTrace();
}
try {
calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn);
System.out.println("calCriItemSerStr.." + calCriItemSerStr);
System.out.println("isItemSer@@@@@@@before>>>>"+isItemSerLocal);
if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) )
{
isItemSerLocal=false;
System.out.println("isItemSer@@>>>>"+isItemSerLocal);
}else
{
calCriItemSerList= new ArrayList<String>(Arrays.asList(calCriItemSerStr.split(",")));
isItemSerLocal=false;
System.out.println("isItemSer@@Chk>>>>"+isItemSerLocal);
}
invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS", conn);
System.out.println("invoiceMonths.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0))
{
invoiceMonthsPrevious = -3;
}
else
{
invoiceMonthsPrevious = Integer.parseInt(invoiceMonths);
}
// thirdMonthDay= utlmethd.AddMonths(prdtoDateTmstmp, -3);
System.out.println("invoiceMonthsPrevious>>>>>"+ invoiceMonthsPrevious);
SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate = sdf2.format(currentDate.getTime());
parentNodeList = headerDom.getElementsByTagName("Detail1");
parentNodeListLength = parentNodeList.getLength();
if(parentNodeListLength == 0)
{
errString = itmDBAccessEJB.getErrorString("","VPSELONERD","","",conn);
return errString;
}
System.out.println("::::::parentNodeListLength["+parentNodeListLength+"]");
for (int i = 0; i < parentNodeListLength; i++) {
parentNode = parentNodeList.item(i);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength : "+childNodeListLength+" childNodeList : "+childNodeList);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
System.out.println("childNodeList.item(childRow) : "+ childNode);
System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue());
if("table_no".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
table_no=childNode.getFirstChild().getNodeValue();
table_no= table_no==null ? "" : table_no.trim();
}
if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
prd_code=childNode.getFirstChild().getNodeValue();
prd_code= prd_code==null ? "" : prd_code.trim();
}
}
}
if(calCriItemSerList.contains(table_no.trim()))
{
System.out.println("Inside ItemSer true::::["+calCriItemSerList.contains(table_no.trim())+"]");
isItemSerLocal=true;
}
else
{
System.out.println("Inside ItemSer false::::["+calCriItemSerList.contains(table_no.trim())+"]");
isItemSerLocal=false;
}
sql = "select tran_id,from_date,to_date,cust_code,tran_id__last from cust_stock where pos_code is not null and prd_code=? AND ITEM_SER=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prd_code);
pstmt.setString(2, table_no);
rs = pstmt.executeQuery();
while (rs.next())
{
tranId = checkNull(rs.getString("tran_id"));
prdFromoDateTmstmp = rs.getTimestamp("from_date");
prdtoDateTmstmp = rs.getTimestamp("to_date");
custCode = checkNull(rs.getString("cust_code"));
tranIdLast = checkNull(rs.getString("tran_id__last"));
System.out.println("tranId>>"+tranId+" prdFromoDateTmstmp>>"+prdFromoDateTmstmp+" prdtoDateTmstmp>>"+prdtoDateTmstmp+" custCode>>"+custCode);
//Modified by saurabh[13/02/17|Start]
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp,invoiceMonthsPrevious);
System.out.println("thirdMonthDay>>>>>>" + thirdMonthDay);
sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery();
if (rs1.next()) {
priceList = checkNull(rs1.getString("price_list"));
System.out.println("priceList edit :" + priceList);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
closingStockMap=new HashMap<String, ClosingStockBean>();
sql = " select item_code,cl_stock,CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," +
" CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " +
//"cust_stock_det where tran_id=? and item_code=? ";
"cust_stock_det where tran_id=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranIdLast);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
closingStockBean=new ClosingStockBean();
closingStockBean.setOpStock(rs1.getDouble("cl_stock"));
closingStockBean.setOpeningRate(rs1.getDouble("rate"));
closingStockBean.setOpeningRateOrg(rs1.getDouble("rate__org"));
closingStockMap.put(checkNull(rs1.getString(1)), closingStockBean);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
//Modified by saurabh[13/02/17|End]
sql="update cust_stock_inv set net_amt=0 where tran_id=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranId);
UpdCnt = pstmt1.executeUpdate();
if(UpdCnt>0)
{
System.out.println("Record reset for tran_id>>"+tranId+" net_amt>>"+netAmt);
}
pstmt1.close();
pstmt1 = null;
sql = "select item_code,cl_stock,op_stock from cust_stock_det where tran_id='"+tranId+"'";
pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery();
while (rs1.next()) {
itemCode = checkNull(rs1.getString("item_code"));
clStock = rs1.getDouble("cl_stock");
opStkDom = rs1.getDouble("op_stock");
System.out.println("itemCode>>> "+itemCode+" clStock>>>"+clStock+" opStkDom>>"+opStkDom);
clStockLast=0.0;rateOld=0.0;rateOrgOld=0.0;
transitInvQty=0;transitInvValue=0;recptInvQty=0;recptInvValue=0;transitFreeQty=0;transitFreeValue=0;recptFreeQty=0;recptFreeValue=0;
recptRetVal=0;recptRetQty=0;billRetQtyBonusQty=0;billRetQtyBonusVal=0;transitReplQty=0;transitReplVal=0;recptReplQty=0;recptReplVal=0;
salesQtyCal=0;closingRate = 0;grossSecondaryRate=0;grossSecondaryQty=0;closingValue=0;netSecondarySalesValue=0;opValue=0;sretQtyAllTot=0;primarySalesAll=0;
totalInvAmt=0;totalRetVal=0;
/*sql = " select cl_stock,CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," +
" CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " +
"cust_stock_det where tran_id=? and item_code=? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, tranIdLast);
pstmt2.setString(2, itemCode);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
clStockLast = rs2.getDouble("cl_stock");
rateOld = rs2.getDouble("rate");
rateOrgOld = rs2.getDouble("rate__org");
opStkDom=clStockLast;
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;*/
if(closingStockMap.size()>0)
{
if(closingStockMap.containsKey(itemCode))
{
clStockLast=closingStockMap.get(itemCode).getOpStock();
rateOld=closingStockMap.get(itemCode).getOpeningRate();
rateOrgOld=closingStockMap.get(itemCode).getOpeningRateOrg();
opStkDom=clStockLast;
}
else
{
clStockLast=0;
rateOld=0;
rateOrgOld=0;
opStkDom=0;
}
}
else
{
clStockLast=0;
rateOld=0;
rateOrgOld=0;
opStkDom=0;
}
System.out.println("itemCode>>>"+itemCode +"rateOld>>"+rateOld+" rateOrgOld>>>"+rateOrgOld+" opStkDom>>>"+opStkDom);
invoiceItemSet=new HashSet<String>();
sql="select invoice_id,item_code from invoice_trace where invoice_id in(select invoice_id from cust_stock_inv where tran_id='"+tranId+"' and ref_ser='S-INV')";
pstmt2 = conn.prepareStatement(sql);
rs2 = pstmt2.executeQuery();
while(rs2.next())
{
invoiceItemSet.add(checkNull(rs2.getString(1))+"@"+checkNull(rs2.getString(2)));
}
rs2.close();
rs2=null;
pstmt2.close();
pstmt2=null;
sql = "select invoice_id,dlv_flg,ref_ser from cust_stock_inv where tran_id='"+tranId+"'";
pstmt2 = conn.prepareStatement(sql);
rs2 = pstmt2.executeQuery();
while (rs2.next())
{
isItemFound=false;
netAmt=0;netAmtRet=0;netAmtRep=0;
sreturnCnt = 0;
invoiceId = checkNull(rs2.getString("invoice_id"));
dlvFlag = checkNull(rs2.getString("dlv_flg"));
refSer = checkNull(rs2.getString("ref_ser"));
System.out.println("invoiceId>>>"+invoiceId+">>dlvFlag>>>"+dlvFlag+">>refSer>>"+refSer);
if("Y".equalsIgnoreCase(dlvFlag))
{
invoiceIdList = invoiceIdList + "'"+invoiceId.trim() + "',";
}
/*sql = "SELECT tran_id FROM sreturn WHERE tran_id='"+invoiceId+"'";
pstmt3 = conn.prepareStatement(sql);
rs3 = pstmt3.executeQuery();
if (rs3.next())
{
sreturnCnt++;
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;*/
//if (sreturnCnt == 0)
if("S-INV".equalsIgnoreCase(refSer))
{
invoiceItemKey=invoiceId+"@"+itemCode;
if(invoiceItemSet.contains(invoiceItemKey))
{
//refSer="S-INV";
//sql = "select QUANTITY__STDUOM,RATE__STDUOM,DISCOUNT from invoice_trace where invoice_id='"+invoiceId+"' and item_code='"+itemCode+"' and RATE__STDUOM>0.001";
//sql = "select QUANTITY__STDUOM,RATE__STDUOM,DISCOUNT from invoice_trace where invoice_id='"+invoiceId+"' and item_code='"+itemCode+"' ";
sql = "SELECT itrc.QUANTITY__STDUOM as QUANTITY__STDUOM,itrc.RATE__STDUOM as RATE__STDUOM,itrc.DISCOUNT as DISCOUNT "
+ " FROM invoice_trace itrc,invoice inv WHERE itrc.invoice_id=inv.invoice_id "
+ " and inv.invoice_id='"+invoiceId+"' and inv.cust_code = '"+custCode+"' and itrc.item_code='"+itemCode+"' ";
pstmt3 = conn.prepareStatement(sql);
rs3 = pstmt3.executeQuery();
while (rs3.next())
{
invQty = rs3.getDouble("QUANTITY__STDUOM");
invRate = rs3.getDouble("RATE__STDUOM");
invDisCnt = rs3.getDouble("DISCOUNT");
if(invRate<=0.001){
isItemFound=true;
}
if(invRate>0.001)
{
//Formula
totalInvAmt = getRequiredDcml(((invQty * invRate)-((invQty *invRate * invDisCnt)/100)),3);
netAmt=(long)Math.round(totalInvAmt);
if (dlvFlag.equalsIgnoreCase("N"))
{
transitInvQty += invQty;//transit_qty
//transitInvValue += (invQty * invRate);// transit_bill_val
transitInvValue += totalInvAmt;// transit_bill_val
transitInvValue=getRequiredDcml(transitInvValue,3);
}
else
{
recptInvQty += invQty;//purc_rcp
//recptInvValue += (invQty * invRate);// rcp_val
recptInvValue += totalInvAmt;// rcp_val
recptInvValue=getRequiredDcml(recptInvValue,3);
}
}
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
if(isItemFound)
{
/*sql = "select sum(totfreeQty) as freeqty,sum(totFreeValue) as totalvalue from"
+ " (select invoice_id,sum(quantity) totfreeQty,sum(rate),sum(quantity)*sum(rate) as totFreeValue "
+ "from ( select invoice.invoice_id as invoice_id,0 quantity, max(rate__stduom) "
+ "rate from invoice invoice,invoice_trace itrace where invoice.invoice_id= Itrace.invoice_id "
+ "and invoice.invoice_id ='"+invoiceId+"' and itrace.item_code='"+itemCode+"' ";
sql = sql
+ " and rate__stduom>0.001 group by invoice.invoice_id "
+ "union all"
+ " select invoice.invoice_id as invoice_id,quantity__stduom quantity, 0 rate from "
+ "invoice invoice,invoice_trace itrace where invoice.invoice_id= Itrace.invoice_id and "
+ "invoice.invoice_id ='"+invoiceId+"' and itrace.item_code='"+itemCode+"' ";
sql = sql
+ " and itrace.rate__stduom<=0.001 ) group by invoice_id ) HAVING sum(totfreeQty)>0 ";*/
sql=" SELECT (totfreeQty) AS freeqty, (totFreeValue) AS totalvalue " +
" FROM (SELECT SUM(quantity) as totfreeQty, SUM(quantity) * SUM(rate) AS totFreeValue FROM " +
" ( SELECT invoice.invoice_id AS invoice_id,0 quantity, MAX(rate__stduom) rate " +
" FROM invoice invoice, invoice_trace itrace WHERE invoice.invoice_id= Itrace.invoice_id " +
" AND invoice.invoice_id ='"+invoiceId+"' AND itrace.item_code ='"+itemCode+"' AND rate__stduom >0.001 " +
" GROUP BY invoice.invoice_id UNION ALL SELECT invoice.invoice_id AS invoice_id,quantity__stduom quantity, " +
" 0 rate FROM invoice invoice, invoice_trace itrace WHERE invoice.invoice_id= Itrace.invoice_id " +
" AND invoice.invoice_id ='"+invoiceId+"' AND itrace.item_code ='"+itemCode+"' AND itrace.rate__stduom<=0.001 ) " +
" GROUP BY invoice_id ) WHERE totFreeValue >0 ";
pstmt3 = conn.prepareStatement(sql);
rs3 = pstmt3.executeQuery();
while (rs3.next())
{
//Bonus
FreeQty = rs3.getDouble(1);
freeValue = rs3.getDouble(2);
if (dlvFlag.equalsIgnoreCase("N"))
{
transitFreeQty += FreeQty;// transit_qty__free
transitFreeValue += (freeValue);// Transit_free_val
transitFreeValue=getRequiredDcml(transitFreeValue,3);
}
else
{
recptFreeQty += FreeQty;// purc_rcp__free
recptFreeValue += (freeValue);// rcp_free_val
recptFreeValue=getRequiredDcml(recptFreeValue,3);
}
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
}
}
}
else
{
//refSer="S-RET";
sql = " select count(1) as count from cust_stock_inv where tran_id=? and invoice_id=? ";
pstmt3 = conn.prepareStatement(sql);
pstmt3.setString(1, tranIdLast);
pstmt3.setString(2, invoiceId);
rs3 = pstmt3.executeQuery();
while(rs3.next())
{
retCnt=rs3.getInt("count");
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
sql = "select quantity__stduom,rate__stduom,RET_REP_FLAG,LINE_TYPE,discount from sreturndet where tran_id='"+invoiceId+"' and item_code='"+itemCode+"'";
pstmt3 = conn.prepareStatement(sql);
rs3 = pstmt3.executeQuery();
while (rs3.next())
{
retQty = rs3.getDouble("quantity__stduom");
retRate = rs3.getDouble("rate__stduom");
retReplFlag = rs3.getString("RET_REP_FLAG");
lineType = rs3.getString("LINE_TYPE");
retDiscnt = rs3.getDouble("discount");
totalRetVal=getRequiredDcml(((retQty * retRate)-((retQty * retRate * retDiscnt)/100)),3);
if (retReplFlag.equalsIgnoreCase("R"))
{
//recptRetVal += (retQty * retRate);// ret_val
if(retCnt>0)
{
netAmtRet=0;
recptRetQty=0;
recptRetVal=0;
}
else{
recptRetQty += retQty;// purc_ret
recptRetVal += totalRetVal;// ret_val
netAmtRet=(long)Math.round(totalRetVal);
}
if ("F".equalsIgnoreCase(lineType))
{
billRetQtyBonusQty += retQty;// purc_ret__free
//billRetQtyBonusVal += (retQty * retRate);// ret_free_val
billRetQtyBonusVal += totalRetVal;// ret_free_val
billRetQtyBonusVal=getRequiredDcml(billRetQtyBonusVal,3);
}
}
else
{
if (dlvFlag.equalsIgnoreCase("N"))
{
transitReplQty += retQty;// transit_qty__repl
//transitReplVal += (retQty * retRate);// transit_repl_val
transitReplVal += totalRetVal;// transit_repl_val
transitReplVal=getRequiredDcml(transitReplVal,3);
}
else
{
recptReplQty += retQty;// purc_rcp__repl
//recptReplVal += (retQty * retRate);// rcp_repl_val
recptReplVal += totalRetVal;// rcp_repl_val
recptReplVal=getRequiredDcml(recptReplVal,3);
}
netAmtRep=(long)Math.round(totalRetVal);
}
netAmt = (-netAmtRet+netAmtRep);
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
}
if(netAmt != 0){
sql="update cust_stock_inv set net_amt=net_amt+?,ref_ser=? where tran_id=? and invoice_id=? ";
pstmt3 = conn.prepareStatement(sql);
pstmt3.setDouble(1, netAmt);
pstmt3.setString(2, refSer);
pstmt3.setString(3, tranId);
pstmt3.setString(4, invoiceId);
UpdCnt = pstmt3.executeUpdate();
if(UpdCnt>0)
{
System.out.println("Record updated for tran_id>>"+tranId+" invoice_id>>"+invoiceId+" net_amt>>"+netAmt+" ref_ser>>"+refSer);
}
pstmt3.close();
pstmt3 = null;
}
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
if(invoiceIdList.trim().length() > 0)
{
selectedInvList = invoiceIdList.substring(0,invoiceIdList.length() - 1);
}
/* if(clStock>0)
{*/
formulaValue=clStock;
if(!isItemSerLocal)
{
System.out.println("formulaValue>>"+formulaValue);
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as quantity__stduom,inv.tran_date "
+ "FROM invoice_trace itrc,invoice inv WHERE itrc.invoice_id=inv.invoice_id "
+ "and itrc.item_code=? and inv.tran_date>=? "
+ "and inv.tran_date<=? and inv.cust_code=? AND itrc.rate__stduom >0.001 "
+ " ORDER BY inv.tran_date DESC";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, itemCode);
pstmt2.setTimestamp(2, thirdMonthDay);
pstmt2.setTimestamp(3, prdtoDateTmstmp);
pstmt2.setString(4, custCode);
rs2 = pstmt2.executeQuery();
while (rs2.next())
{
rateStd = rs2.getDouble("rate__stduom");
quantityStd = rs2.getDouble("quantity__stduom");
System.out.println("rateStd :" + rateStd);
System.out.println("quantityStd :" + quantityStd);
if (formulaValue >= quantityStd)
{
closingValue = closingValue + quantityStd * rateStd;
System.out.println("closing value" + closingValue);
formulaValue = formulaValue - quantityStd;
System.out.println("formulaValue2>>"+formulaValue);
}
else
{
closingValue = closingValue + formulaValue * rateStd;
formulaValue = 0;
System.out.println("closing value>>>>" + closingValue);
System.out.println("formulaValue3>>"+formulaValue);
}
closingValue = getRequiredDcml(closingValue, 3);
if (formulaValue == 0)
{
break;
}
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("closingValue>>>>>>" + closingValue);
System.out.println("formulaValue>>>>>>" + formulaValue);
if (formulaValue > 0)
{
// System.out.println("dbSysDate>>>>>>"+dbSysDate);
// priceListRate = getRate(custCodeStatic,dbSysDate,itemCode1,conn);
/*sql = "select price_list from customer where cust_code =? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, custCode);
rs2 = pstmt2.executeQuery();
if (rs2.next()) {
priceList = checkNull(rs2.getString("price_list"));
System.out.println("priceList edit :" + priceList);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;*/
//sysDate = genericUtility.getValidDateString(sysDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, SYSDATE , ? ) FROM DUAL ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, priceList);
//pstmt2.setString(2, sysDate);
//pstmt2.setString(3, genericUtility.getDBDateFormat());
pstmt2.setString(2, itemCode);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
priceListRate = rs2.getDouble(1);
System.out.println("rateAll-----------> ["+ priceListRate + "]");
}
if (rs2 != null)
{
rs2.close();
rs2 = null;
}
if (pstmt2 != null) {
pstmt2.close();
pstmt2 = null;
}
priceListRate = getRequiredDcml(priceListRate, 3);
// Added by saurabh to get rate from DDF_PICK_MAX_RATE fuction[18/10/16|end]
System.out.println("rateAll>>>>>" + priceListRate);
closingValue = closingValue + formulaValue * priceListRate;
closingValue = getRequiredDcml(closingValue, 3);//cl_value
}
}else
{
if(recptInvQty > 0)
{
sql = " SELECT itrace.RATE__STDUOM as RATE__STDUOM FROM" +
" invoice invoice,invoice_trace itrace " +
" where invoice.invoice_id=itrace.invoice_id and itrace.invoice_id in("+selectedInvList+")" +
" AND invoice.cust_code = ? " +
//" and invoice.inv_type=? " +
" and itrace.item_ser__prom in("+table_no+") "+
" and itrace.item_code = ? " +
" AND itrace.RATE__STDUOM>0.001 ORDER BY invoice.tran_date DESC " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode );
//pstmt.setString(2, orderType );
pstmt.setString(2, itemCode );
rs = pstmt.executeQuery( );
if( rs.next() )
{
calRate = rs.getDouble("RATE__STDUOM" );
System.out.println("openingRate>>>>>> :"+calRate);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
/*invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn);
System.out.println("invoiceMonths>>>>.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0))
{
invoiceMonthsPrevious = -3;
} else
{
invoiceMonthsPrevious = Integer.parseInt(invoiceMonths);
}
System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious);
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay);*/
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,inv.tran_date " +
"FROM invoice_trace itrc,invoice inv WHERE itrc.invoice_id=inv.invoice_id " +
"and itrc.item_code=? and inv.tran_date>=? " +
"and inv.tran_date<=? and inv.cust_code=? AND itrc.rate__stduom >0.001 " +
" ORDER BY inv.tran_date DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
pstmt.setTimestamp(2, thirdMonthDay);
pstmt.setTimestamp(3, prdtoDateTmstmp);
pstmt.setString(4, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
calRate = rs.getDouble("rate__stduom");
System.out.println("calRate>>>>>> :" + calRate);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (calRate == 0)
{
/*sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
priceList = checkNull(rs1.getString("price_list"));
System.out.println("priceList edit :" + priceList);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;*/
//Commented by Manoj dtd 26/10/2016
//openingRate = discmn.pickRate(priceList, sysDatetemp, itemCode, conn);
//Changed by Manoj dtd 26/10/2016
//sysDate = genericUtility.getValidDateString( sysDate , genericUtility.getApplDateFormat() , genericUtility.getDBDateFormat());
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, SYSDATE , ? ) FROM DUAL ";
pstmt1 = conn.prepareStatement( sql );
pstmt1.setString( 1, priceList );
/*pstmt1.setString( 2, sysDate );
pstmt1.setString( 3, genericUtility.getDBDateFormat() );
*/pstmt1.setString( 2, itemCode );
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
calRate = rs1.getDouble(1);
System.out.println("calRate-----------> [" +calRate+ "]");
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
}
}
calRate=getRequiredDcml(calRate,3);
closingValue=getRequiredDcml(clStock*calRate,3);
}
if (clStock > 0)
{
closingRate = closingValue / clStock;
}
else
{
closingRate = 0.0;
}
closingRate=getRequiredDcml(closingRate,3);//rate
System.out.println("closingRate@@@@@@@@@"+closingRate);
System.out.println("transitInvQty>>"+transitInvQty+"transitInvValue>>"+transitInvValue);
System.out.println("recptInvQty>>"+recptInvQty+"recptInvValue>>"+recptInvValue);
System.out.println("transitFreeQty>>"+transitFreeQty+"transitFreeValue>>"+transitFreeValue);
System.out.println("recptFreeQty>>"+recptFreeQty+"recptFreeValue>>"+recptFreeValue);
System.out.println("recptRetQty>>"+recptRetQty+"recptRetVal>>"+recptRetVal);
System.out.println("billRetQtyBonusQty>>"+billRetQtyBonusQty+"billRetQtyBonusVal>>"+billRetQtyBonusVal);
System.out.println("transitReplQty>>"+transitReplQty+"transitReplVal>>"+transitReplVal);
System.out.println("recptReplQty>>"+recptReplQty+"recptReplVal>>"+recptReplVal);
System.out.println("opStkDom>>"+opStkDom+"clStock>>>"+clStock);
sretQtyAllTot= recptRetQty - recptReplQty - billRetQtyBonusQty ;
System.out.println("sretQtyAllTot>>"+sretQtyAllTot);
primarySalesAll= recptInvQty - (sretQtyAllTot );
System.out.println("primarySalesAll>>"+primarySalesAll);
grossSecondaryQty=opStkDom+recptInvQty+recptReplQty+recptFreeQty-recptRetQty-clStock;//sales__org
System.out.println("grossSecondaryQty>>>>>>"+grossSecondaryQty);
formulaValue=0;
System.out.println("formulaValue>>>>>"+formulaValue);
netSecondarySalesValue=(opStkDom*rateOld)+recptInvValue+recptReplVal-recptRetVal-closingValue;
netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3);//sales_value
System.out.println("netSecondarySalesValue>>>>>"+netSecondarySalesValue);
grossSecondarySalesValue=(opStkDom*rateOrgOld)+recptInvValue+recptReplVal+recptFreeValue-recptRetVal-closingValue;
grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3);
System.out.println("grossSecondarySalesValue>>>>>"+grossSecondarySalesValue);
if(grossSecondaryQty>0)
{
grossSecondaryRate = grossSecondarySalesValue / grossSecondaryQty;
}else
{
grossSecondaryRate=0.0;
}
grossSecondaryRate=getRequiredDcml(grossSecondaryRate,3);//rate__org
System.out.println("grossSecondaryRate>>>"+grossSecondaryRate);
//End by chandrashekar on 29-dec-2015
salesQtyCal = opStkDom + (recptInvQty + recptReplQty) - (recptRetQty + retQtyFreeDom) - clStock;//sales
salesQtyCal=getRequiredDcml(salesQtyCal,3);
System.out.println("salesQtyCal>>>"+salesQtyCal);
opValue=getRequiredDcml(opStkDom*rateOld,3);//op_value
/*}
else
{
clStock=0.0;//cl_stock
}*/
sql = "update cust_stock_det set rcp_val=? , rcp_repl_val=? , rcp_free_val=? , ret_val=? , ret_free_val=? , transit_bill_val=? , " +
" transit_repl_val=? , transit_free_val=? , " +
" purc_rcp=? ,purc_rcp__repl=? ,purc_rcp__free=? ,purc_ret=? ,purc_ret__free=? , " +
" transit_qty=? ,transit_qty__repl=? ,transit_qty__free=? ," +
" sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? ,primary_sales=? " +
" where tran_id=? and item_code=? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setDouble(1, recptInvValue);//rcp_val
pstmt2.setDouble(2, recptReplVal);//rcp_repl_val
pstmt2.setDouble(3, recptFreeValue);//rcp_free_val
pstmt2.setDouble(4, recptRetVal);//ret_val
pstmt2.setDouble(5, billRetQtyBonusVal);//ret_free_val
pstmt2.setDouble(6, transitInvValue);//transit_bill_val
pstmt2.setDouble(7, transitReplVal);//transit_repl_val
pstmt2.setDouble(8, transitFreeValue);//Transit_free_val
pstmt2.setDouble(9, recptInvQty);//purc_rcp
pstmt2.setDouble(10, recptReplQty);//purc_rcp__repl
pstmt2.setDouble(11, recptFreeQty);//purc_rcp__free
pstmt2.setDouble(12, recptRetQty);//purc_ret
pstmt2.setDouble(13, billRetQtyBonusQty);//purc_ret__free
pstmt2.setDouble(14, transitInvQty);//transit_qty
pstmt2.setDouble(15, transitReplQty);//transit_qty__repl
pstmt2.setDouble(16, transitFreeQty);//transit_qty__free
pstmt2.setDouble(17, salesQtyCal );//sales
pstmt2.setDouble(18, closingRate );//rate
pstmt2.setDouble(19, grossSecondaryRate );//rate__org
pstmt2.setDouble(20, grossSecondaryQty );//sales__org
pstmt2.setDouble(21, closingValue );//cl_value
pstmt2.setDouble(22, netSecondarySalesValue );//sales_value
pstmt2.setDouble(23, opValue );//op_value
pstmt2.setDouble(24, primarySalesAll );//primary_sales
pstmt2.setString(25, tranId);
pstmt2.setString(26, itemCode);
UpdCnt = pstmt2.executeUpdate();
if(UpdCnt>0)
{
System.out.println("No of record updated:"+UpdCnt);
System.out.println("Data updated for tran_id:"+tranId+" and item_code>>"+itemCode);
chkCnt++;
}
System.out.println("Records done>>>>"+chkCnt+" >>>upto tranId"+tranId);
pstmt2.close();
pstmt2 = null;
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}// try end
catch (Exception e)
{
try
{
System.out.println("inside");
errString = itmDBAccessEJB.getErrorString("", "VTES3RLBCK","", "", conn);
conn.rollback();
}
catch (Exception d)
{
System.out.println("Exception : Es3HDataUpdPrc =>"+ d.toString());
d.printStackTrace();
}
System.out.println("Exception :Es3HDataUpdPrc :process(String xmlString2, String xmlString2, String windowName, String xtraParams):"+ e.getMessage() + ":");
e.printStackTrace();
errString = e.getMessage();
return errString;
}
finally
{
System.out.println("Closing Connection....");
try {
if (errString == null) {
System.out.println("Connection Commited");
errString = itmDBAccessEJB.getErrorString("", "VTES3SUCSS","", "", conn);
conn.commit();
}
else if (errString != null)
{
System.out.println("Connection is rollback");
errString = itmDBAccessEJB.getErrorString("", "VTES3RLBCK","", "", conn);
conn.rollback();
}
retBuf = null;
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
errString = e.getMessage();
e.printStackTrace();
return errString;
}
}
System.out.println("Error Message=>" + errString);
return errString;
}// END OF PROCESS(2)
private String checkNull(String input)
{
if (input == null) {
input = "";
}
else
{
input = input.trim();
}
return input;
}
public double getRequiredDcml(double actVal, int prec)
{
double value = 0.0;
String fmtStr = "############0";
if (prec > 0) {
fmtStr = fmtStr + "." + "000000000".substring(0, prec);
}
DecimalFormat decFormat = new DecimalFormat(fmtStr);
if (decFormat.format(actVal) != null
&& decFormat.format(actVal).trim().length() > 0) {
value = Double.parseDouble(decFormat.format(actVal));
} else {
value = 0.00;
}
return value;
}
class ClosingStockBean
{
private double opStock;
private double openingRate;
private double openingRateOrg;
public double getOpStock() {
return opStock;
}
public void setOpStock(double opStock) {
this.opStock = opStock;
}
public double getOpeningRate() {
return openingRate;
}
public void setOpeningRate(double openingRate) {
this.openingRate = openingRate;
}
public double getOpeningRateOrg() {
return openingRateOrg;
}
public void setOpeningRateOrg(double openingRateOrg) {
this.openingRateOrg = openingRateOrg;
}
}
}// END OF EJB
\ No newline at end of file
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface Es3HDataUpdPrcLocal extends ProcessLocal{
public abstract String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface Es3HDataUpdPrcRemote extends ProcessRemote{
public abstract String process(String arg0, String arg1, String arg2, String arg3) 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