Commit 96cee21e authored by dpawar's avatar dpawar

added functionality of auto confirmation Debit note


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93417 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 027a677b
......@@ -5,6 +5,7 @@ import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.fin.MiscDrCrRcpConf;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
......@@ -13,6 +14,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
......@@ -20,6 +22,7 @@ import javax.naming.InitialContext;
@Stateless
public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeliveryConfLocal,ProofOfDeliveryConfRemote
{
String debitNoteTranID="";
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
System.out.println("--------------confirm method of ProofOfDeliveryConf ------------- : ");
......@@ -43,11 +46,13 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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="";
String itmCodeDt2="",lotNo="",lotSl="", detail2xmlString="";
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();
......@@ -94,7 +99,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
if(wfStatus.trim().equalsIgnoreCase("S"))
{
String invoiceId="",custCode="",siteCode="",currCode="",loginCode="";
double ExchRate=0.0;
double ExchRate=0.0,actualDBamount=0.0;
boolean isRegPrice=false;
GenericUtility genericUtility=new GenericUtility();
loginCode=genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
......@@ -113,16 +118,17 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
if (updCnt > 0)
{
sql="";
sql="select cust_code,site_code,curr_code,exch_rate from spl_sales_por_hdr where tran_id = ?";
sql="select invoice_id,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);
invoiceId=rs.getString(1);
custCode=rs.getString(2)==null ? "" : rs.getString(2);
siteCode=rs.getString(3)==null ? "" : rs.getString(3);
currCode=rs.getString(4)==null ? "" : rs.getString(4);
ExchRate=rs.getDouble(5);
}
if(rs != null)
{
......@@ -136,7 +142,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
sql="";
sql="select item_code,rate__inv,quantity__inv,rate__resale,quantity__resale,line_no from spl_sales_por_det where tran_id = ?";
sql="select item_code,rate__inv,quantity__inv,rate__resale,quantity__resale,line_no,lot_no,lot_sl from spl_sales_por_det where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs=pstmt.executeQuery();
......@@ -148,40 +154,55 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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);
lotNo=rs.getString(7)== null ? "" : rs.getString(7);
lotSl=rs.getString(8)== null ? "" : rs.getString(8);
System.out.println("lotNo :"+lotNo+"------->> 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)
debitNoteAmtAct=debitNoteCalculation(conn,regulatedPrice,invRate,invQty,PODrate,PODqty,itemCode);
actualDBamount=actualDBamount + debitNoteAmtAct;
detail2xmlString=detail2xmlString + getDetail2xmlString(debitNoteAmtAct,itemCode,PODrate,PODqty,lotNo,lotSl,lineNo,conn);
System.out.println("itemCode : "+itemCode+" Line no -->"+lineNo+" --debitNoteAmtAct ------->>"+debitNoteAmtAct);
}
} //end while
System.out.println("Final actualDBamount---------->> : "+actualDBamount);
if ( actualDBamount > 0)
{
System.out.println("-----Debit note generation condition----------"+actualDBamount);
errString=genDebitNote(tranId,invoiceId,custCode,siteCode,xtraParams,actualDBamount,currCode,ExchRate,detail2xmlString, conn);
System.out.println("------@@@Debit Note Generated successfully for amount : "+actualDBamount);
//conn.commit();
System.out.println("Confirmation of Debit note1212112----------");
MiscDrCrRcpConf confDebitNote=new MiscDrCrRcpConf();
errString=confDebitNote.confirm(debitNoteTranID,xtraParams,"",conn);
System.out.println("Error String on DB Confirmation21212112 : "+errString);
if (errString.indexOf("Success") > -1)
{
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------------------");
System.out.println("------@@@Debit Note Generated successfully for amount : "+actualDBamount);
System.out.println("Confirmation of Debit note done successfully----------");
}
else
conn.rollback();
}
else
{
System.out.println("--------Debit note not generated------------- ");
conn.commit();
}
}
}
}
}
......@@ -244,7 +265,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return errString;
}
private String genDebitNote(String tranId,String custCode,String siteCode ,String xtraParams,double relAmt,String currencyCode,double exchRate, Connection conn) throws ITMException
private String genDebitNote(String tranId,String invoiceId,String custCode,String siteCode ,String xtraParams,double relAmt,String currencyCode,double exchRate,String detail2xmlString, Connection conn) throws ITMException
{
System.out.println("<--------Inside genDebitNote11----------->");
......@@ -255,13 +276,9 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
SimpleDateFormat sdf=null;
String currAppdate ="";
java.sql.Timestamp currDate = null;
//String siteCode="";
String finEntity="";
String acctCode="";
String cctrCode="";
String acctCodetotAR="";
String cctrCodetotAR="";
String miscDebitNoteTranID="";
String itemSer="";
String finEntity="",acctCode="",cctrCode="",acctCodetotAR="",cctrCodetotAR="",miscDebitNoteTranID="";
String acctCodeUDF1="",acctCodeUDF2="";
PreparedStatement pstmt=null;
ResultSet rs=null;
int count=0;
......@@ -292,13 +309,15 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
currAppdate = sdf.format(currDate);
//siteCode =(genutility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
itemSer =getColumnDescr(conn, "item_ser","invoice","invoice_id", invoiceId);
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);
//acctCodetotAR=getColumnDescr(conn,"ACCT_CODE__TOT_AR", "item_acct_detr", "item_ser", itemSer);
//cctrCodetotAR=getColumnDescr(conn,"CCTR_CODE__TOT_AR", "item_acct_detr", "item_ser", itemSer);
cctrCodetotAR = cctrCodetotAR== null ? " " :cctrCodetotAR;
xmlBuffer.append("<Detail1 objContext =\"1\"").append(" objName=\"misc_drcr_rcp_dr\" domID=\"1\" dbID=\"\">");
xmlBuffer.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
......@@ -315,11 +334,11 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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("<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("<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");
......@@ -329,6 +348,8 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
xmlBuffer.append("<chg_term/>\r\n");
xmlBuffer.append("<chg_date>").append("<![CDATA[").append(currAppdate).append("]]></chg_date>\r\n");
xmlBuffer.append("</Detail1>\r\n");
System.out.println("Detail 2 cml String ---->>[[ "+detail2xmlString+" ]]");
xmlBuffer.append(detail2xmlString);
/*xmlBuffer.append("<Detail2 objContext =\"2\"").append(" objName=\"misc_drcr_rcp_dr\" domID=\"1\" dbID=\"\">");
xmlBuffer.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
......@@ -336,23 +357,28 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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("<acct_code>").append("<![CDATA[").append(acctCodeUDF1).append("]]></acct_code>");
xmlBuffer.append("<cctr_code>").append("<![CDATA[").append(acctCodeUDF2).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("<item_code>").append("<![CDATA[").append(itmCodeDt2).append("]]></item_code>\r\n");
xmlBuffer.append("<rate>").append("<![CDATA[").append(rateDt2).append("]]></rate>\r\n");
xmlBuffer.append("<quantity>").append("<![CDATA[").append(qtyDt2).append("]]></quantity>\r\n");
xmlBuffer.append("<lot_no>").append("<![CDATA[").append(lotNo).append("]]></lot_no>\r\n");
xmlBuffer.append("<lot_sl>").append("<![CDATA[").append(lotSl).append("]]></lot_sl>\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("xmlString of Debit Note --->>139: [["+xmlString+"]]");
System.out.println("------ debit Note Data saving------------------");
retString=saveData(siteCode, xmlString, conn);
System.out.println("------ debit Note Data saved successfully123------------------");
System.out.println("debit Note Data saved successfully. retString : [["+retString+"]]");
if (retString.indexOf("Success") > -1)
{
System.out.println("retString.indexOf(Success) > -1)");
......@@ -371,6 +397,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
pstmt.setString(2, tranId);
pstmt.executeUpdate();
System.out.println("tran_id__drn updated successfully----------");
debitNoteTranID=miscDebitNoteTranID;
}
}
......@@ -386,6 +413,56 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return retString;
}
private String getDetail2xmlString(double debitNoteAmtItem, String itemCode, double PODrate,double PODqty,String lotNo, String lotSl,int LineNo,Connection conn)
{
System.out.println("in getDetail2xmlString -->> itemCode: "+itemCode+" LineNo : "+LineNo);
StringBuffer detail2xml=new StringBuffer();
PreparedStatement pstmt1=null;
ResultSet rs1=null;
String acctCodeUDF1="",acctCodeUDF2="",sql="";
try
{
sql="select UDF_STR1,UDF_STR2 from gencodes where FLD_NAME = ? AND MOD_NAME = ? AND FLD_VALUE = ? ";
pstmt1=conn.prepareStatement(sql);
pstmt1.setString(1, "REAS_CODE");
pstmt1.setString(2, "W_MISC_DRCR_RCP_DR");
pstmt1.setString(3, "PODDBTNOTE");
rs1=pstmt1.executeQuery();
if(rs1.next())
{
acctCodeUDF1=rs1.getString(1)==null ? "" :rs1.getString(1);
acctCodeUDF2=rs1.getString(2)==null ? "" :rs1.getString(2);
}
rs1.close();rs1=null;
pstmt1.close();pstmt1=null;
System.out.println("acctCodeUDF1 : "+acctCodeUDF1+" acctCodeUDF2 : "+acctCodeUDF2);
}
catch(Exception e)
{
System.out.println("Exception :getDetail2xmlString method :==>");
e.printStackTrace();
}
detail2xml.append("<Detail2 objContext =\"2\"").append(" objName=\"misc_drcr_rcp_dr\" domID=\"1\" dbID=\"\">");
detail2xml.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
detail2xml.append("<tran_id/>");
detail2xml.append("<line_no>").append("<![CDATA[").append(LineNo).append("]]></line_no>");
detail2xml.append("<net_amt>").append("<![CDATA[").append(debitNoteAmtItem).append("]]></net_amt>");
detail2xml.append("<amount>").append("<![CDATA[").append(debitNoteAmtItem).append("]]></amount>");
detail2xml.append("<acct_code>").append("<![CDATA[").append(acctCodeUDF1).append("]]></acct_code>");
detail2xml.append("<cctr_code>").append("<![CDATA[").append(acctCodeUDF2).append("]]></cctr_code>");
detail2xml.append("<sundry_type>").append("<![CDATA[").append("C").append("]]></sundry_type>\r\n");
detail2xml.append("<item_code>").append("<![CDATA[").append(itemCode).append("]]></item_code>\r\n");
detail2xml.append("<rate>").append("<![CDATA[").append(PODrate).append("]]></rate>\r\n");
detail2xml.append("<quantity>").append("<![CDATA[").append(PODqty).append("]]></quantity>\r\n");
detail2xml.append("<lot_no>").append("<![CDATA[").append(lotNo).append("]]></lot_no>\r\n");
detail2xml.append("<lot_sl>").append("<![CDATA[").append(lotSl).append("]]></lot_sl>\r\n");
detail2xml.append("<unit>").append("<![CDATA[").append("DOZ").append("]]></unit>\r\n");
detail2xml.append("</Detail2>");
System.out.println("Detail 2 xml string for line no--->>"+LineNo);
return detail2xml.toString();
}
private String saveData(String siteCode, String xmlString, Connection conn) throws ITMException
{
......@@ -452,7 +529,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
private double debitNoteCalculation(Connection conn,String regulaPrice,double rateInvoice,double qtyInvoice,double podRate,double podQty) throws ITMException, RemoteException
private double debitNoteCalculation(Connection conn,String regulaPrice,double rateInvoice,double qtyInvoice,double podRate,double podQty,String itemCode) throws ITMException, RemoteException
{
System.out.println("----------in debitNoteCalculation method----------");
double debitNoteAmount=0.0;
......@@ -470,19 +547,8 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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);
System.out.println("Item code wise debit note :[ItemCode] :["+itemCode+"] :"+debitNoteAmount);
//actualDBamount=actualDBamount + debitNoteAmount;
return debitNoteAmount;
}
else if(regulaPrice.equalsIgnoreCase("N"))
......@@ -494,20 +560,8 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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);
System.out.println("Item code wise debit note :[ItemCode] :["+itemCode+"] :"+debitNoteAmount);
//actualDBamount=actualDBamount + debitNoteAmount;
return debitNoteAmount;
}
......@@ -519,24 +573,11 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
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;*/
System.out.println("Item code wise debit note :[ItemCode] :["+itemCode+"] :"+debitNoteAmount);
//actualDBamount=actualDBamount + debitNoteAmount;
return debitNoteAmount;
}
return debitNoteAmount;
}
......@@ -598,4 +639,5 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return false;
}
}
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