Commit 706a9a54 authored by dpawar's avatar dpawar

done auto conf. debit note


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93951 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4c31e77e
......@@ -8,12 +8,14 @@ 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;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
......@@ -23,8 +25,8 @@ import javax.naming.InitialContext;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
......@@ -32,8 +34,7 @@ import javax.xml.rpc.ParameterMode;
public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeliveryConfLocal,ProofOfDeliveryConfRemote
{
String debitNoteTranID="";
boolean isRegPriceNotFound=false;
double debitNoteHeader=0.0;
boolean isRegPriceNotFound=false;
boolean isError = false;
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
......@@ -67,7 +68,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
String itmCodeDt2="",lotNo="",lotSl="", detail2xmlString="";
double aprvRate=0.0,PODrate=0.0,PODqty=0.0,allowedAmt=0.0,stockistAmt=0.0,debitNoteAmtDetail=0.0;
double debitNoteAmtHdr=0;
int updCnt=0,lineNo=0;
int updCnt=0,lineNo=0,lineNotrace=0;
ITMDBAccessEJB itmdbAccess=new ITMDBAccessEJB();
HashMap<Integer,Double> mapDebitNoteAmt=new HashMap<Integer,Double>();
try
......@@ -119,10 +120,10 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
if(wfStatus.trim().equalsIgnoreCase("S"))
{
String invoiceId="",custCode="",siteCode="",currCode="",loginCode="";
double ExchRate=0.0,actualDBamount=0.0,rateInv=0,qtyInv=0,detail3Amt=0;
double ExchRate=0.0,actualDBamount=0.0,rateInv=0,qtyInv=0,detail3Amt=0,detail3AmtT=0;
loginCode=GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
System.out.println("Login Code ------->> "+loginCode);
ArrayList invRateList=new ArrayList();
sql="";
......@@ -150,7 +151,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
sql="";
sql="select item_code,rate__resale,quantity__resale,aprv_rate,line_no,lot_no,lot_sl,rate__inv,quantity__inv " +
sql="select item_code,rate__resale,quantity__resale,aprv_rate,line_no,lot_no,lot_sl,rate__inv,quantity__inv,line_no__trace " +
"from spl_sales_por_det where tran_id = ? order by line_no";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, tranId);
......@@ -166,30 +167,34 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
lotSl=rs.getString(7);
rateInv=rs.getDouble(8);
qtyInv=rs.getDouble(9);
lineNotrace=rs.getInt(10);
itemCode=itemCode==null ? "" :itemCode.trim();
lotNo=lotNo==null ? "" :lotNo.trim();
lotSl=lotSl==null ? "" :lotSl.trim();
invRateList.add(0, rateInv);
//debitNoteAmtDetail=getDebitNoteAmount(conn, tranId, lineNo,aprvRate,PODrate,PODqty);
debitNoteAmtDetail=getDebitNoteAmount(conn, tranId, lineNo,rateInv,PODrate,PODqty,qtyInv);
debitNoteAmtDetail=getDebitNoteAmount(rateInv,qtyInv);
debitNoteAmtHdr=debitNoteAmtHdr+debitNoteAmtDetail;
detail3Amt=(PODrate - aprvRate) * PODqty;
detail3AmtT=detail3AmtT + detail3Amt;
mapDebitNoteAmt.put(lineNo, detail3Amt);
//detail2xmlString=getDetailsXmlString(conn, xtraParams, invoiceId, aprvRate, debitNoteAmtDetail);
detail2xmlString=getDetailsXmlString(conn, xtraParams, invoiceId, rateInv, debitNoteAmtDetail,detail3Amt);
detail2xmlString=detail2xmlString + getDetailsXmlString(invoiceId,lineNotrace,lineNo,rateInv,qtyInv,lotNo,lotSl,itemCode, debitNoteAmtDetail);
} //end while-------------------@@@@@@@@@@---------------------------------------
System.out.println("detail2xmlString3813---->>[["+detail2xmlString+"]]");
System.out.println("Final debitNoteAmtHdr---------->> : "+debitNoteAmtHdr);
System.out.println("Final detail3AmtT in debit note table---------->> : "+detail3AmtT);
//debitNoteAmtDetail=100.10;
System.out.println("-----Debit note generation condition----------"+actualDBamount);
errString=genDebitNote(tranId,invoiceId,custCode,siteCode,xtraParams,actualDBamount,currCode,ExchRate,detail2xmlString,conn);
errString=genDebitNote(tranId,invoiceId,custCode,siteCode,xtraParams,actualDBamount,currCode,ExchRate,detail2xmlString,debitNoteAmtHdr,detail3AmtT,conn);
System.out.println("------Error string after DN save--->>["+errString+"]");
if (errString.indexOf("Success") > -1)
{
int cnt=updateDrCrRcpHdrAmt(debitNoteTranID,conn);
int cnt=updateDrCrRcpHdrAmt(debitNoteTranID,detail3AmtT,conn);
if(cnt>0)
conn.commit();
System.out.println("Confirmation of Debit note1212112 COMMITED----------");
......@@ -218,8 +223,9 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
}
else{
errString = itmdbAccess.getErrorString("", "VTNCONFT", "", "", conn);
//errString = itmdbAccess.getErrorString("", "VTNCONFT", "", "", conn);
conn.rollback();
return errString;
}
......@@ -291,7 +297,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return errString;
}
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
private String genDebitNote(String tranId,String invoiceId,String custCode,String siteCode ,String xtraParams,double relAmt,String currencyCode,double exchRate,String detail2xmlString,double debitNoteAmtHdr,double detail3AmtT, Connection conn) throws ITMException
{
System.out.println("<--------Inside genDebitNote11----------->");
StringBuffer xmlBuff = new StringBuffer();
......@@ -369,7 +375,38 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
//xmlBuff.append("<gp_date><![CDATA["+ (gpDate==null?"":sdf.format(gpDate).toString()) +"]]></gp_date>");
xmlBuff.append("</Detail1>\r\n");
xmlBuff.append(detail2xmlString);
xmlBuff.append(detail2xmlString);
String lineNo1="1";
xmlBuff.append("<Detail3 dbID='' domID='"+lineNo1+"' objName=\"drcrrcp_dr\" objContext=\"2\">");
xmlBuff.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
xmlBuff.append("<tran_id/>");
xmlBuff.append("<line_no><![CDATA["+lineNo1+"]]></line_no>\r\n");
xmlBuff.append("<acct_code><![CDATA[2401]]></acct_code>\r\n");
xmlBuff.append("<cctr_code><![CDATA[H651]]></cctr_code>\r\n");
xmlBuff.append("<amount><![CDATA["+debitNoteAmtHdr+"]]></amount>\r\n");
xmlBuff.append("</Detail3>");
lineNo1="2";
pstmt=conn.prepareStatement("SELECT ACCT_CODE__SAL,CCTR_CODE__SAL from invoice where invoice_id=?" );
pstmt.setString(1, invoiceId);
rs=pstmt.executeQuery();
if(rs.next())
{
acctCode=rs.getString("ACCT_CODE__SAL");
cctrCode=rs.getString("CCTR_CODE__SAL");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
xmlBuff.append("<Detail3 dbID='' domID='"+lineNo1+"' objName=\"drcrrcp_dr\" objContext=\"2\">");
xmlBuff.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
xmlBuff.append("<tran_id/>");
xmlBuff.append("<line_no><![CDATA["+lineNo1+"]]></line_no>\r\n");
xmlBuff.append("<acct_code><![CDATA["+acctCode+"]]></acct_code>\r\n");
xmlBuff.append("<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>\r\n");
xmlBuff.append("<amount><![CDATA["+(detail3AmtT - debitNoteAmtHdr)+"]]></amount>\r\n");
xmlBuff.append("</Detail3>");
......@@ -416,119 +453,40 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return retString;
}
private String getDetailsXmlString(Connection conn,String xtraParams,String invoiceId,double rate,double debitNoteAmt,double detail3Amt)
private String getDetailsXmlString(String invoiceId, int lineNoTrace,int lineNo,double rateInv,double qtyInv,String lotNo,String lotSl,String itemCode, double debitNoteAmtDetail)
{
invoiceId=invoiceId==null ? "" : invoiceId.trim();
System.out.println("in getDetailsXmlString -->> invoiceId--->>["+invoiceId+"]");
StringBuffer detailsXml=new StringBuffer();
PreparedStatement pstmt1=null;
ResultSet rs1=null;
int lineNo = 0,invoiceLine = 0,invTraceLine = 0;
double quantity = 0,rateStd = 0, rateClg = 0,discount = 0,costRate = 0;
double exchRate = 0,roundAdj = 0, quantityStduom=0,totAmt=0;
String itemCode = "", taxClass = "",taxChapter = "",taxEnv = "",lotNo = "",lotSl = "";
String acctCode="",cctrCode="",loginSiteCode="",sql="";
GenericUtility genericUtility = GenericUtility.getInstance();
StringBuffer detailsXml=new StringBuffer();
try
{
sql = "select invoice_id,line_no,inv_line_no,item_code,tax_class,tax_chap,tax_env,cost_rate,rate__std,quantity,quantity__stduom," +
"rate__clg,discount,lot_no,lot_sl from invoice_trace where invoice_id = ? order by line_no " ;
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,invoiceId);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
lineNo ++;
invTraceLine = rs1.getInt("line_no");
invoiceLine = rs1.getInt("inv_line_no");
itemCode = rs1.getString("item_code");
taxClass = rs1.getString("tax_class");
taxChapter = rs1.getString("tax_chap");
taxEnv = rs1.getString("tax_env");
costRate = rs1.getDouble("cost_rate");
rateStd = rs1.getDouble("rate__std");
quantity = rs1.getDouble("quantity");
quantityStduom = rs1.getDouble("quantity__stduom");
//rate = rs1.getDouble("rate");
rateClg = rs1.getDouble("rate__clg");
discount = rs1.getDouble("discount");
lotNo = rs1.getString("lot_no");
lotSl = rs1.getString("lot_sl");
if(rateClg==0)
{
rateClg=rate;
}
itemCode=itemCode==null ? "" : itemCode.trim();
taxClass=taxClass==null ? "" : taxClass.trim();
taxChapter=taxChapter==null ? "" : taxChapter.trim();
taxEnv=taxEnv==null ? "" : taxEnv.trim();
lotNo=lotNo==null ? "" : lotNo.trim();
lotSl=lotSl==null ? "" : lotSl.trim();
detailsXml.append("<Detail2 dbID='' domID='"+lineNo+"' objName=\"drcrrcp_dr\" objContext=\"2\">");
detailsXml.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
detailsXml.append("<tran_id/>");
detailsXml.append("<line_no><![CDATA["+lineNo+"]]></line_no>\r\n");
detailsXml.append("<invoice_id><![CDATA["+invoiceId+"]]></invoice_id>\r\n");
detailsXml.append("<line_no__invtrace><![CDATA["+invTraceLine+"]]></line_no__invtrace>\r\n");
detailsXml.append("<line_no__inv><![CDATA["+invoiceLine+"]]></line_no__inv>\r\n");
detailsXml.append("<line_no__invtrace><![CDATA["+lineNoTrace+"]]></line_no__invtrace>\r\n");
detailsXml.append("<line_no__inv><![CDATA["+lineNoTrace+"]]></line_no__inv>\r\n");
detailsXml.append("<invoice_id><![CDATA["+invoiceId+"]]></invoice_id>\r\n");
detailsXml.append("<item_code><![CDATA["+itemCode+"]]></item_code>\r\n");
detailsXml.append("<rate><![CDATA["+rate+"]]></rate>\r\n");
detailsXml.append("<rate__std><![CDATA["+rateStd+"]]></rate__std>\r\n");
detailsXml.append("<quantity><![CDATA["+quantity+"]]></quantity>\r\n");
detailsXml.append("<rate><![CDATA["+rateInv+"]]></rate>\r\n");
detailsXml.append("<rate__std><![CDATA["+rateInv+"]]></rate__std>\r\n");
detailsXml.append("<quantity><![CDATA["+qtyInv+"]]></quantity>\r\n");
detailsXml.append("<lot_no><![CDATA["+lotNo+"]]></lot_no>\r\n");
detailsXml.append("<lot_sl><![CDATA["+lotSl+"]]></lot_sl>\r\n");
detailsXml.append("<discount><![CDATA["+discount+"]]></discount>\r\n");
detailsXml.append("<tax_class><![CDATA["+taxClass+"]]></tax_class>\r\n");
detailsXml.append("<tax_chap><![CDATA["+taxChapter+"]]></tax_chap>\r\n");
detailsXml.append("<tax_env><![CDATA["+taxEnv+"]]></tax_env>\r\n");
detailsXml.append("<cost_rate><![CDATA["+costRate+"]]></cost_rate>\r\n");
detailsXml.append("<rate__clg><![CDATA["+rateClg+"]]></rate__clg>\r\n");
detailsXml.append("<rate__clg><![CDATA["+rateInv+"]]></rate__clg>\r\n");
//String debitNoteAmt1="100.10";
detailsXml.append("<drcr_amt><![CDATA["+debitNoteAmt+"]]></drcr_amt>\r\n");
detailsXml.append("<net_amt><![CDATA["+debitNoteAmt+"]]></net_amt>\r\n");
detailsXml.append("<drcr_amt><![CDATA["+debitNoteAmtDetail+"]]></drcr_amt>\r\n");
detailsXml.append("<net_amt><![CDATA["+debitNoteAmtDetail+"]]></net_amt>\r\n");
//detailsXml.append("<reas_code><![CDATA["+reasCode+"]]></reas_code>");
detailsXml.append("</Detail2>");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
String lineNo1="1";
detailsXml.append("<Detail3 dbID='' domID='"+lineNo1+"' objName=\"drcrrcp_dr\" objContext=\"2\">");
detailsXml.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
detailsXml.append("<tran_id/>");
detailsXml.append("<line_no><![CDATA["+lineNo1+"]]></line_no>\r\n");
detailsXml.append("<acct_code><![CDATA[2401]]></acct_code>\r\n");
detailsXml.append("<cctr_code><![CDATA[H651]]></cctr_code>\r\n");
detailsXml.append("<amount><![CDATA["+debitNoteAmt+"]]></amount>\r\n");
detailsXml.append("</Detail3>");
lineNo1="2";
pstmt1=conn.prepareStatement("SELECT ACCT_CODE__SAL,CCTR_CODE__SAL from invoice where invoice_id=?" );
pstmt1.setString(1, invoiceId);
rs1=pstmt1.executeQuery();
if(rs1.next())
{
acctCode=rs1.getString("ACCT_CODE__SAL");
cctrCode=rs1.getString("CCTR_CODE__SAL");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
detailsXml.append("<Detail3 dbID='' domID='"+lineNo1+"' objName=\"drcrrcp_dr\" objContext=\"2\">");
detailsXml.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
detailsXml.append("<tran_id/>");
detailsXml.append("<line_no><![CDATA["+lineNo1+"]]></line_no>\r\n");
detailsXml.append("<acct_code><![CDATA["+acctCode+"]]></acct_code>\r\n");
detailsXml.append("<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>\r\n");
detailsXml.append("<amount><![CDATA["+(detail3Amt - debitNoteAmt)+"]]></amount>\r\n");
detailsXml.append("</Detail3>");
}
......@@ -546,7 +504,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
{
String sql="";
int lineNo=0,count=0;
double dbAmt=0.0;
double dbAmt=0.0,debitNoteHeaderL=0;
PreparedStatement pstmt=null;
//ResultSet rs=null;
......@@ -561,7 +519,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
System.out.println("Line NO--->>["+lineNo+"]");
System.out.println("dbAmt----->>["+dbAmt+"]");
if(lineNo > 0 && dbAmt > 0 ){
debitNoteHeader=debitNoteHeader + dbAmt;
debitNoteHeaderL=debitNoteHeaderL + dbAmt;
sql="update spl_sales_por_det set debit_note_amt = ? where tran_id = ? and line_no = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setDouble(1, dbAmt);
......@@ -569,16 +527,17 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
pstmt.setInt(3, lineNo);
count=pstmt.executeUpdate();
pstmt.close();
pstmt=null;
pstmt=null;
System.out.println("debitNoteHeaderL LOCAL---->>"+debitNoteHeaderL);
} //end condition
}// end while
System.out.println("spl_sales_por_det updated successfully but not commit yet------");
System.out.println("Final debitNote amt Header----->>["+debitNoteHeader+"]");
System.out.println("Final debitNote amt Header----->>["+debitNoteHeaderL+"]");
sql="update spl_sales_por_hdr set debit_note_amt = ? where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setDouble(1, debitNoteHeader);
pstmt.setDouble(1, debitNoteHeaderL);
pstmt.setString(2, tranId);
count=pstmt.executeUpdate();
pstmt.close();
......@@ -612,7 +571,7 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
return count;
}
private int updateDrCrRcpHdrAmt(String tranId,Connection conn)
private int updateDrCrRcpHdrAmt(String tranId,double actualDebitNote,Connection conn)
{
PreparedStatement pstmt=null;
ResultSet rs=null;
......@@ -634,6 +593,10 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Final amount drcr_racct------>>["+drCrAcctAmtM+"]");
sql="select amount,exch_rate from DRCR_RCP where tran_id= ?";
pstmt=conn.prepareStatement(sql);
......@@ -641,22 +604,27 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
rs=pstmt.executeQuery();
if(rs.next())
{
hdrDbAmt=rs.getDouble(1);
//hdrDbAmt=rs.getDouble(1);
exchRate=rs.getDouble(2);
}
System.out.println("Header amount in DRCR_RCP------>>["+hdrDbAmt+"]");
finalHdrAmt= hdrDbAmt + drCrAcctAmtM;
amountBc = finalHdrAmt * exchRate;
amountBc = actualDebitNote * exchRate;
System.out.println("Final Header amount in DRCR_RCP------>>["+finalHdrAmt+"]");
System.out.println("Final Header amount_bc in DRCR_RCP------>>["+amountBc+"]");
sql="update DRCR_RCP set amount = ?,amount__bc = ? where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setDouble(1, finalHdrAmt);
pstmt.setDouble(1, actualDebitNote);
pstmt.setDouble(2, amountBc);
pstmt.setString(3, tranId);
cnt=pstmt.executeUpdate();
cnt=pstmt.executeUpdate();
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
......@@ -735,25 +703,22 @@ public class ProofOfDeliveryConf extends ActionHandlerEJB implements ProofOfDeli
}
private double getDebitNoteAmount (Connection conn,String tranId,int lineNo,double rateInv,double podRate,double podQty,double qtyInv)
private double getDebitNoteAmount (double rateInv,double qtyInv)
{
System.out.println("-------- in getDebitNoteAmount method -------------");
double debitNoteAmount=0,aprvRate=0,dbResale=0,dbAmt=0;
System.out.println("rateInv-->>["+rateInv+"]");
System.out.println("podRate-->>["+podRate+"]");
System.out.println("podQty-->>["+podQty+"]");
System.out.println("rateInv-->>["+rateInv+"]");
System.out.println("qtyInv-->>["+qtyInv+"]");
//debitNoteAmount= (podRate - apprvRate) * podQty;
//dbResale= podRate * podQty;
dbAmt=rateInv * qtyInv;
debitNoteAmount=rateInv * qtyInv;
//System.out.println("dbResale-->>["+podQty+"]");
System.out.println("dbAmt-->>["+podQty+"]");
System.out.println("dbAmt-->>["+dbAmt+"]");
/*
if(dbResale > dbAmt){
debitNoteAmount=dbResale - dbAmt;
}*/
debitNoteAmount= dbAmt;
}*/
System.out.println("debitNoteAmount-->>["+debitNoteAmount+"]");
return debitNoteAmount;
}
......
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