Commit ceccb3d1 authored by ngadkari's avatar ngadkari

changes to set proper quantity in min_rate_history when scheme is apply

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@205914 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6434ee3f
...@@ -1089,4 +1089,310 @@ public class SalesReturnAct extends ActionHandlerEJB implements SalesReturnActLo ...@@ -1089,4 +1089,310 @@ public class SalesReturnAct extends ActionHandlerEJB implements SalesReturnActLo
System.out.println("getRelativeDate():relativeDate:"+relativeDate); System.out.println("getRelativeDate():relativeDate:"+relativeDate);
return relativeDate; return relativeDate;
} }
//Added By Mukesh Chauhan on 23/08/19
public String invoicePickaction(String actionType, String xmlString, String xmlString1, String objContext, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
String retString = null;
try
{
System.out.println("xmlString :::"+xmlString);
System.out.println("xmlString1 :::"+xmlString1);
if(xmlString != null && xmlString.trim().length()!=0)
{
dom = new ibase.utility.E12GenericUtility().parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()!=0)
{
dom1 = new ibase.utility.E12GenericUtility().parseString(xmlString1);
}
System.out.println("actionType:"+actionType+":");
if (actionType.equalsIgnoreCase("splitInvoice"))
{
retString = getInvoicePickBtn(dom, dom1, objContext, xtraParams);
}
}
catch(Exception e)
{
System.out.println("Exception :Porcp :actionHandlerTransform(String xmlString):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning String from Porcp : actionHandlerTransform"+retString);
return retString;
}
public String getInvoicePickBtn(Document dom, Document dom1,String objContext, String xtraParams)throws ITMException
{
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null,pstmt2 = null;
ResultSet rs = null,rs2 = null;
String sql = "";
String errCode = "";
String lotNo ="";
String siteCode = "";
String itemCode = "";
String errString = "";
String flag = "";
String invoiceId = "";
String locCode = "";
String lotNoInv = "";
String lotSlInv = "";
String sreturnAdjOpt = "";
String orderByStr = "";
String custCode = "";
String reason = "";
String docKey = "";
String siteCodeMfgFn = "";
String packCodeFn = "";
String chkDate = "";
String quantity = "";
String stkMfgDate = "";
String stkExpDate = "";
String lotSl ="";
String siteCodeMfg ="",newDomXml="";
String packCode ="";
String unit = "";
java.sql.Date expDate = null;
java.sql.Date mfgDate = null;
int minShelfLife = 0;
int detCnt =0,cnt=0,lotCnt=0;
double totStk =0.0;
double inputQty = 0.0,lotQty=0;
double qty =0;
double qtyStk = 0,invoiceQty=0,adjQty=0,rate=0;
DistCommon distCommon = null;
distCommon = new DistCommon();
E12GenericUtility genericUtility= new E12GenericUtility();
ITMDBAccessEJB itmDBAccess = new ITMDBAccessEJB();
ConnDriver connDriver = new ConnDriver();
StringBuffer valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n");
int domID = 0,domID1=0;
java.util.Date invoiceDate= null;
try
{
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = getConnection();
System.out.println("\n******************** S T A R T *******getInvoicePickBtn*********************");
siteCode = genericUtility.getColumnValue("site_code",dom1);
itemCode = genericUtility.getColumnValue("item_code",dom);
quantity = genericUtility.getColumnValue("quantity",dom);
lotNo = genericUtility.getColumnValue("lot_no",dom);
custCode = genericUtility.getColumnValue("cust_code",dom1);
System.out.println("Values From DOM :siteCode:"+siteCode+":invoiceId:"+invoiceId+":quantity:"+quantity+":");
if(quantity != null && quantity.trim().length() > 0)
{
qty = Double.parseDouble(quantity);
sreturnAdjOpt = distCommon.getDisparams("999999", "SRETURN_ADJ_OPT", conn);
System.out.println("sreturnAdjOpt:::["+sreturnAdjOpt+"]");
if (sreturnAdjOpt == null || sreturnAdjOpt.trim().length()== 0 || "NULLFOUND".equalsIgnoreCase(sreturnAdjOpt))
{
sreturnAdjOpt="M";
}
if ("M".equalsIgnoreCase(sreturnAdjOpt))
{
orderByStr = " ORDER BY MRH.EFF_COST ";
}
else if("E".equalsIgnoreCase(sreturnAdjOpt))
{
orderByStr = " ORDER BY MRH.INVOICE_DATE ASC,MRH.INVOICE_ID ASC ";
}
else if("L".equalsIgnoreCase(sreturnAdjOpt))
{
orderByStr = " ORDER BY MRH.INVOICE_DATE DESC,MRH.INVOICE_ID DESC ";
}
if(lotNo != null && lotNo.trim().length() > 0 && qty > 0 && itemCode != null && itemCode.trim().length() > 0)
{
sql = " SELECT MRH.DOC_KEY,MRH.INVOICE_ID,MRH.QUANTITY, MRH.CUST_CODE, MRH.ITEM_CODE, MRH.LOT_NO, MRH.SITE_CODE, MRH.INVOICE_DATE,"
+ " SUM( CASE WHEN SRDET.QUANTITY IS NULL THEN 0 ELSE SRDET.QUANTITY END) AS QTY_ADJ, MRH.EFF_COST"
+ " FROM MIN_RATE_HISTORY MRH, SRETURNDET SRDET"
+ " WHERE MRH.DOC_KEY =SRDET.DOC_KEY(+) AND MRH.CUST_CODE = ?"
+ " AND MRH.ITEM_CODE = ? AND MRH.LOT_NO = ?"
+ " AND MRH.SITE_CODE = ? AND MRH.QUANTITY - CASE WHEN MRH.QUANTITY_ADJ IS NULL THEN 0 ELSE MRH.QUANTITY_ADJ END > 0"
+ " AND MRH.QUANTITY IS NOT NULL"
+ " GROUP BY MRH.DOC_KEY,MRH.INVOICE_ID, MRH.QUANTITY, MRH.EFF_COST,MRH.CUST_CODE,MRH.ITEM_CODE,MRH.LOT_NO, MRH.SITE_CODE, MRH.INVOICE_DATE"
+ " HAVING MRH.QUANTITY-SUM( CASE WHEN SRDET.QUANTITY IS NULL THEN 0 ELSE SRDET.QUANTITY END) > 0 "
+ orderByStr;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, itemCode);
pstmt.setString(3, lotNo);
pstmt.setString(4, siteCode);
rs = pstmt.executeQuery();
while(rs.next())
{
if(qty >0)
{
invoiceId = checkNull(rs.getString("INVOICE_ID"));
invoiceQty =rs.getDouble("QUANTITY");
adjQty = rs.getDouble("QTY_ADJ");
docKey = checkNull(rs.getString("DOC_KEY"));
rate = rs.getDouble("EFF_COST");
invoiceDate = rs.getDate("INVOICE_DATE");
cnt=0;
System.out.println( " docKey.indexOf(invoiceId)" + docKey.indexOf(invoiceId) );
if( docKey.indexOf(invoiceId) != -1)
{
sql = "select count(*) from invoice_trace where invoice_id = ? and item_code = ? and lot_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, invoiceId);
pstmt2.setString(2, itemCode);
pstmt2.setString(3, lotNo);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
lotCnt = rs2.getInt(1);
}
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
if(lotCnt > 1 && adjQty == 0)
{
sql = "select quantity from invoice_trace where invoice_id = ? and item_code = ? and lot_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, invoiceId);
pstmt2.setString(2, itemCode);
pstmt2.setString(3, lotNo);
rs2 = pstmt2.executeQuery();
while (rs2.next())
{
lotQty = rs2.getDouble(1);
domID++;
valueXmlString.append("<Detail domId='"+(domID)+"' selected=\"Y\">\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code>\r\n");
valueXmlString.append("<lot_no>").append("<![CDATA[").append(lotNo).append("]]>").append("</lot_no>\r\n");
if(qty > lotQty)
{
valueXmlString.append("<quantity>").append("<![CDATA[").append(lotQty).append("]]>").append("</quantity>\r\n");
}
else {
valueXmlString.append("<quantity>").append("<![CDATA[").append(qty).append("]]>").append("</quantity>\r\n");
}
valueXmlString.append("<invoice_ref>").append("<![CDATA[").append(invoiceId).append("]]>").append("</invoice_ref>\r\n");
if(invoiceDate != null)
{
valueXmlString.append("<invoice_date>").append("<![CDATA[").append(sdf.format(invoiceDate)).append("]]>").append("</invoice_date>\r\n");
}
else
{
valueXmlString.append("<invoice_date>").append("<![CDATA[").append("").append("]]>").append("</invoice_date>\r\n");
}
valueXmlString.append("<effective_cost>").append("<![CDATA[").append(rate).append("]]>").append("</effective_cost>\r\n");
valueXmlString.append("<invoice_quantity>").append("<![CDATA[").append(lotQty).append("]]>").append("</invoice_quantity>\r\n");
valueXmlString.append("<used_quantity>").append("<![CDATA[").append(0.0).append("]]>").append("</used_quantity>\r\n");
valueXmlString.append("</Detail>\r\n");
qty=qty-lotQty;
if(qty <= 0)
{
break;
}
}
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
}
else
{
inputQty=invoiceQty-adjQty;
System.out.println( "inputQty :: " + inputQty);System.out.println( "qty :: " + qty);
if(inputQty > 0)
{
domID++;
valueXmlString.append("<Detail domId='"+(domID)+"' selected=\"Y\">\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code>\r\n");
valueXmlString.append("<lot_no>").append("<![CDATA[").append(lotNo).append("]]>").append("</lot_no>\r\n");
if(qty > inputQty)
{
valueXmlString.append("<quantity>").append("<![CDATA[").append(inputQty).append("]]>").append("</quantity>\r\n");
}
else {
valueXmlString.append("<quantity>").append("<![CDATA[").append(qty).append("]]>").append("</quantity>\r\n");
}
valueXmlString.append("<invoice_ref>").append("<![CDATA[").append(invoiceId).append("]]>").append("</invoice_ref>\r\n");
if(invoiceDate != null)
{
valueXmlString.append("<invoice_date>").append("<![CDATA[").append(sdf.format(invoiceDate)).append("]]>").append("</invoice_date>\r\n");
}
else
{
valueXmlString.append("<invoice_date>").append("<![CDATA[").append("").append("]]>").append("</invoice_date>\r\n");
}
valueXmlString.append("<effective_cost>").append("<![CDATA[").append(rate).append("]]>").append("</effective_cost>\r\n");
valueXmlString.append("<invoice_quantity>").append("<![CDATA[").append(invoiceQty).append("]]>").append("</invoice_quantity>\r\n");
valueXmlString.append("<used_quantity>").append("<![CDATA[").append(adjQty).append("]]>").append("</used_quantity>\r\n");
valueXmlString.append("</Detail>\r\n");
qty=qty-inputQty;
}
}
}
if(qty <= 0)
{
break;
}
}
}//loop end
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
}
}
valueXmlString.append("</Root>\r\n");
System.out.println("@@xmlString For Scheme :: "+valueXmlString.toString());
Document finalxml = genericUtility.parseString(valueXmlString.toString());
NodeList detail1NodeList = finalxml.getElementsByTagName("Detail");
System.out.println("@SchemeXml length:"+detail1NodeList.getLength());
for(int nodeCnt = 0;nodeCnt<detail1NodeList.getLength();nodeCnt++)
{
domID1++;
System.out.println("New DomID"+domID1);
detail1NodeList.item(nodeCnt).getAttributes().getNamedItem("domId").setNodeValue(String.valueOf(domID1));
}
System.out.println("");
newDomXml = genericUtility.serializeDom(finalxml);
System.out.println("XML For Scheme with new domID ["+newDomXml+"]");
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return newDomXml;
}
//End of Invoicepickbutton method
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment