Commit 7c01d16f authored by manohar's avatar manohar

Code optimisation for speed issue


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104151 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e6b67c2c
......@@ -1210,8 +1210,9 @@ public class PostOrderActivity {
sql=" select a.sord_line_no, a.sord_no, a.item_code, "
+ " sum(a.quantity__stduom) as quantity, sum(a.quantity__stduom * a.rate__stduom) as effNetAmt, b.item_code__parent "
+ " from invoice_trace a, item b "
+ " where a.item_code = b.item_code and "
+ " a.invoice_id = ? "
+ " where a.item_code = b.item_code "
+ " and b.item_code__parent is not null " // 06-Dec-16 manoharan unnecessary all items are considered
+ " and a.invoice_id = ? "
+ " group by a.sord_no, a.sord_line_no, a.item_code, a.item_code__ord, b.item_code__parent "
+ " order by a.sord_no, a.sord_line_no ";
pstmt=conn.prepareStatement(sql);
......@@ -1832,10 +1833,11 @@ public class PostOrderActivity {
double discRate=0.0,cashValueItem=0.0;
double totBBAmtHdr=0.0,totOffinvAmtHdr=0.0;
double offinvAmtHdr=0.0,billbackAmtHdr=0.0;
int cnt=0,hdrCnt=0;
int cnt=0,hdrCnt=0, schemeCount = 0;
Timestamp validUpto=null,invoiceDate=null,effFrom=null;
Timestamp sysDate = null;
E12GenericUtility genericUtility= new E12GenericUtility();
String prevSordNo = "";
try
{
......@@ -1871,6 +1873,24 @@ public class PostOrderActivity {
while(rs1.next())
{
sordNo=checkNull(rs1.getString("sord_no"));
if (!prevSordNo.trim().equals(sordNo.trim()))
{
schemeCount = 0;
sql="select count(1) from sorderdet_scheme where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,sordNo);
rs=pstmt.executeQuery();
if(rs.next())
{
schemeCount = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
prevSordNo = sordNo;
}
sordLineNo=checkNull(rs1.getString("sord_line_no"));
despId=checkNull(rs1.getString("desp_id"));
despLineNo=checkNull(rs1.getString("desp_line_no"));
......@@ -1879,7 +1899,10 @@ public class PostOrderActivity {
effNetAmount=rs1.getDouble("eff_net_amount");
totNetAmt = totNetAmt+effNetAmount;
if (schemeCount == 0)
{
continue;
}
sql="select scheme_code from sorderdet_scheme where tran_id = ? and line_no_form = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,sordNo);
......@@ -3378,7 +3401,7 @@ public class PostOrderActivity {
String lsItemAry[] = null, lsColname[] = null;
double FreeQty = 0, lcEffCostFree = 0.00, lcTotFreeEffCost = 0.00, ldChgAmt = 0.00, ldAmt = 0.00, ldTotAmt = 0.00, ldQtyStd = 0.00, ldEffCost = 0.00, lcFreeEffCost = 0.00;
double ldQtyAry[] = null, ldAmtAry[] = null;
int cnt = 0, llCtr = 0, llctrCol = 0, llCnt = 0;
int cnt = 0, llCtr = 0, llctrCol = 0, llCnt = 0, psCount = 0;
boolean lbOtherFreeItem = false, lbItemCharge = false, lbChkNull = false;
;
long llSchemeNum = 0L;
......@@ -3395,9 +3418,31 @@ public class PostOrderActivity {
ArrayList ldQtyAry1=new ArrayList();
ArrayList ldAmtAry1=new ArrayList();
Timestamp chgDate=null;
ArrayList <String> schemeKeyList= new ArrayList<String>();
boolean periodScheme = false;
String prevRefNo = "";
try
{
// 06-Dec-16 manoharan moved from inside loop
lsVarValue = distCommon.getDisparams("999999", "SCHEME_HIST_NUM", conn);
if (lsVarValue == null || lsVarValue.trim().length() == 0 || lsVarValue.equalsIgnoreCase("NULLFOUND"))
{
llSchemeNum = 1;
lbChkNull = true;
} else
{
llSchemeNum = Long.parseLong(lsVarValue);
lbChkNull = false;
for (int llCtrSch = 1; llCtrSch < llSchemeNum; llCtrSch++) // FOR LOOP [1]
{
lsScheme = "SCHEME_HIST_KEY" + llCtrSch;
lsVarValue = distCommon.getDisparams("999999", lsScheme, conn);
schemeKeyList.add(lsVarValue);
}
}
chgDate = Timestamp.valueOf(genericUtility.getValidDateString(chgDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
// GenericUtility genericUtility = GenericUtility.getInstance();
......@@ -3410,11 +3455,33 @@ public class PostOrderActivity {
+ " group by line_no,item_code order by line_no desc";
} else if ("I".equalsIgnoreCase(tranType))
{
sql = "select tran_date, cust_code,cust_code__bil as cust_code__bil from invoice " + " where invoice_id = ?";
sql = "select count(1) from invoice_trace t, item i where t.item_code = i.item_code and i.item_code__parent is not null and t.invoice_id = ? "
+ " group by t.sord_no,t.sord_line_no,t.item_code "
+ " order by t.sord_no, t.sord_line_no desc ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, invoiceId);
rs = pstmt.executeQuery();
if (rs.next())
{
psCount = rs.getInt(1);
periodScheme = true;
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (psCount > 0 )
{
}
sql = "select tran_date, cust_code,cust_code__bil as cust_code__bil from invoice " + " where invoice_id = ?";
sqlDetData = "select sord_no refNo,sord_line_no refLineNo,item_code,sum(net_amt - tax_amt) totamt,sum(quantity) totqty "
+ " from invoice_trace where invoice_id = ? "
+ " group by sord_no,sord_line_no,item_code "
+ " order by sord_no, sord_line_no desc ";
}
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, invoiceId);
......@@ -3473,15 +3540,48 @@ public class PostOrderActivity {
ldAmtAry1.add(ldAmt);
ldTotAmt = ldTotAmt + ldAmt;
if ("I".equalsIgnoreCase(tranType))
if ("I".equalsIgnoreCase(tranType) && !prevRefNo.trim().equals(refNo.trim())) // 06-dec-16 to avoid repeating for same order again
{
// 06-dec-16 manoharan commented and taken out side loop
prevRefNo = refNo;
sql = "select order_type, state_code__dlv, count_code__dlv from sorder where sale_order =?";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refNo);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
lsOrderType = rs2.getString("order_type");
lsStateCode = rs2.getString("state_code__dlv");
lsCountCode = rs2.getString("count_code__dlv");
}
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
sql = "select returnable,reas_code from sordertype where order_type =?";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, lsOrderType);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
lsReturnable = rs2.getString("returnable");
lsReasCode = rs2.getString("reas_code");
}
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
sql = "select item_code__ord from sorditem " + " where sale_order = ? and line_no = ? and item_code =? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, refNo);
pstmt1.setString(2, refLineNo);
pstmt1.setString(3, itemCode);
rs1 = pstmt1.executeQuery();
while (rs1.next())
if (rs1.next())
{
itemCodeOrd = rs1.getString(1);
}
......@@ -3629,7 +3729,7 @@ public class PostOrderActivity {
pstmt2 = null;
rs2.close();
rs2 = null;
/* // 06-dec-16 manoharan commented and taken out side loop
sql = "select order_type from sorder where sale_order =?";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refNo);
......@@ -3656,6 +3756,7 @@ public class PostOrderActivity {
pstmt2 = null;
rs2.close();
rs2 = null;
*/
}
if (ldEffCost == 0)
......@@ -3689,27 +3790,19 @@ public class PostOrderActivity {
rs2.close();
rs2 = null;
lsVarValue = distCommon.getDisparams("999999", "SCHEME_HIST_NUM", conn);
if (lsVarValue == null || lsVarValue.trim().length() == 0 || lsVarValue.equalsIgnoreCase("NULLFOUND"))
{
llSchemeNum = 1;
lbChkNull = true;
} else
{
llSchemeNum = Long.parseLong(lsVarValue);
lbChkNull = false;
}
// System.out.println("@V@ llSchemeNum before for LOOP 1 :- ["+llSchemeNum+"]");
for (int llCtrSch = 1; llCtrSch < llSchemeNum; llCtrSch++) // FOR LOOP [1]
//for (int llCtrSch = 1; llCtrSch < llSchemeNum; llCtrSch++) // FOR LOOP [1]
for (int llCtrSch = 0; llCtrSch < schemeKeyList.size(); llCtrSch++)
{
// System.out.println("@V@ FOR LOOP 1");
if (!lbChkNull)
{
llctrCol = 0;
lsScheme = "SCHEME_HIST_KEY" + llCtrSch;
lsVarValue = distCommon.getDisparams("999999", lsScheme, conn);
//lsScheme = "SCHEME_HIST_KEY" + llCtrSch;
lsVarValue = schemeKeyList.get(llCtrSch); //distCommon.getDisparams("999999", lsScheme, conn);
lsColname = lsVarValue.split(",");
llctrCol = lsColname.length;
}
......@@ -3751,7 +3844,7 @@ public class PostOrderActivity {
rs2.close();
rs2 = null;
if ("I".equalsIgnoreCase(tranType))
if ("I".equalsIgnoreCase(tranType) && periodScheme) // 06-Dec-16 manoharan periodScheme boolean variable considered to avoid checking for all item if no period scheme
{
if (lsColnameStr.equalsIgnoreCase("item_code") && (xFldValue != null && xFldValue.trim().length() > 0))
{
......@@ -3770,7 +3863,8 @@ public class PostOrderActivity {
if (lsItemCodeparent != null && lsItemCodeparent.trim().length() > 0)
{
sql = "select order_type, state_code__dlv, count_code__dlv from sorder where sale_order = ?";
// 06-dec-16 manoharan commented and taken out side loop
/* sql = "select order_type, state_code__dlv, count_code__dlv from sorder where sale_order = ?";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refNo);
rs2 = pstmt2.executeQuery();
......@@ -3784,7 +3878,7 @@ public class PostOrderActivity {
pstmt2 = null;
rs2.close();
rs2 = null;
*/
lsSchemeCode = checkScheme(lsItemCodeparent, lsOrderType, custCode, siteCode, lsStateCode, lsCountCode, tranDate, conn);
if (lsSchemeCode != null && lsSchemeCode.trim().length() > 0)
......
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