Commit 3ab9ce57 authored by manohar's avatar manohar

Min rate history update bug fixing done


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104385 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 9b18aa03
......@@ -3389,21 +3389,21 @@ public class PostOrderActivity {
public String schemeHistoryUpd(String invoiceId, String siteCode, String tranType, Connection conn) throws ITMException, Exception
{
String retString = "", sql = "", sqlDetData = "", lsScheme = "", lsDocValue = "", lsSchemeCode = "";
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
ResultSet rs = null, rs1 = null, rs2 = null;
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null,pstmtLot = null;
ResultSet rs = null, rs1 = null, rs2 = null,rsLot = null;
String custCode = "", xFldValue = "", lsItemCodeparent = "", lsOriginalItemCodeOrd = "";
Timestamp tranDate = null;
String itemCode = "", itemCodeOrd = "", refNo = "", refLineNo = "", priceList = "", nature = "", lsOrderType = "", lsReturnable = "", lsReasCode = "", cLotNo1 = "", lsVarValue = "";
String itemCodeOld = "",itemCode = "", itemCodeOrd = "", refNo = "", refLineNo = "", priceList = "", nature = "", lsOrderType = "", lsReturnable = "", lsReasCode = "", lotNo = "", lsVarValue = "";
double totAmt = 0, totQty = 0, rate = 0, lcDiscount = 0.00, lcTotChargeQty = 0.00, lcTotFreeQty = 0.00, lcEffNetAmount = 0.00, ldSchCost = 0.00;
String custCodeBill = "", lsStateCode = "", lsCountCode = "";
Timestamp sysdate = new Timestamp((new Date()).getTime());
String freeItem = "", lsColnameStr = "", lsSelectSql = "";
String freeItem = "",refNoOld ="", lsColnameStr = "", lsSelectSql = "";
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 FreeQty = 0, lcEffCostFree = 0.00, lcTotFreeEffCost = 0.00, ldChgAmt = 0.00, ldAmt = 0.00, ldTotAmt = 0.00, ldEffCost = 0.00, lcFreeEffCost = 0.00;
double ldQtyAry[] = null, ldAmtAry[] = null;
int cnt = 0, llCtr = 0, llctrCol = 0, llCnt = 0, psCount = 0;
boolean lbOtherFreeItem = false, lbItemCharge = false, lbChkNull = false;
;
double ldQtyStd = 0.00;
long llSchemeNum = 0L;
UserInfoBean userInfo = new UserInfoBean();
......@@ -3430,11 +3430,14 @@ public class PostOrderActivity {
if (lsVarValue == null || lsVarValue.trim().length() == 0 || lsVarValue.equalsIgnoreCase("NULLFOUND"))
{
llSchemeNum = 1;
lbChkNull = true;
//lbChkNull = true; // 13-jan-17 manoharan not required
// 13-Jan-17 manoharan
lsVarValue = "site_code,item_code,lot_no";
schemeKeyList.add(lsVarValue);
} else
{
llSchemeNum = Long.parseLong(lsVarValue);
lbChkNull = false;
//lbChkNull = false; // 13-jan-17 manoharan not required
//Changed by Santosh on 04/01/17 to change condition in for loop
//for (int llCtrSch = 1; llCtrSch < llSchemeNum; llCtrSch++) // FOR LOOP [1]
for (int llCtrSch = 1; llCtrSch <= llSchemeNum; llCtrSch++) // FOR LOOP [1]
......@@ -3446,8 +3449,6 @@ public class PostOrderActivity {
}
chgDate = Timestamp.valueOf(genericUtility.getValidDateString(chgDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
// GenericUtility genericUtility = GenericUtility.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
......@@ -3506,11 +3507,28 @@ public class PostOrderActivity {
rs = pstmt.executeQuery();
while (rs.next())
{
//ldEffCost = 0;
itemCode = rs.getString("item_code");
refNo = rs.getString("refNo");
refLineNo = rs.getString("refLineNo");
totAmt = rs.getDouble("totamt");
totQty = rs.getDouble("totqty");
ldQtyStd = totQty; // 13-Jan-17 manoharan
ldAmt = totAmt;
if(!itemCodeOld.trim().equals(itemCode.trim()) || !refNoOld.trim().equals(refNo.trim()))
{
ldTotAmt = 0;
ldChgAmt = 0;
llCtr = 0;
lsItemAry1 = null;
ldQtyAry1 = null;
ldAmtAry1 = null;
lsItemAry1=new ArrayList();
ldQtyAry1=new ArrayList();
ldAmtAry1=new ArrayList();
}
if ("R".equalsIgnoreCase(tranType))
{
itemCodeOrd = itemCode;
......@@ -3528,10 +3546,26 @@ public class PostOrderActivity {
rs1 = null;
pstmt1.close();
pstmt1 = null;
if ((priceList.trim()).length() > 0)
// 13-jan-17 manoharan lot_no required to pick rate, taken below inside distinct lot_no loop
//if ((priceList.trim()).length() > 0)
//{
// rate = distCommon.pickRate(priceList, sdf.format(sysdate), itemCode, "", "B", conn);
//}
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();
if (rs1.next())
{
rate = distCommon.pickRate(priceList, sdf.format(sysdate), itemCode, "", "B", conn);
itemCodeOrd = rs1.getString(1);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
llCtr++;
......@@ -3579,25 +3613,11 @@ public class PostOrderActivity {
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();
if (rs1.next())
{
itemCodeOrd = rs1.getString(1);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
sql = "select a.item_code as freeItem, sum(a.quantity) as FreeQty from sorditem a "
+ " where a.sale_order = ? " + " and line_no= ? " + " and nature = 'F' "
+ " and not exists (select b.item_code from sorditem b " + " where b.sale_order = ? "
+ " and b.line_no= ? " + " and a.item_code = b.item_code and nature = 'C' ) group by a.item_code ";
+ " where a.sale_order = ? and a.line_no= ? and a.nature = 'F' "
+ " and not exists (select b.item_code from sorditem b where b.sale_order = ? "
+ " and b.line_no= ? and a.item_code = b.item_code and nature = 'C' ) group by a.item_code ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, refNo);
......@@ -3684,8 +3704,9 @@ public class PostOrderActivity {
rs2 = null;
lcFreeEffCost = ldEffCost;
lbItemCharge = true;
// 13-jan-17 manoharan blindly assigned true
//lbItemCharge = true;
lbItemCharge = false;
sql = "select nature from bomdet where bom_code = ? and item_code =?";
pstmt2 = conn.prepareStatement(sql);
......@@ -3700,6 +3721,10 @@ public class PostOrderActivity {
pstmt2 = null;
rs2.close();
rs2 = null;
if ("C".equals(nature))
{
lbItemCharge = true;
}
}
if (ldEffCost == 0 && lbItemCharge)
{
......@@ -3771,6 +3796,10 @@ public class PostOrderActivity {
}
}
// 13-jan-17 manoharan in case there is no scheme or discount then effe_cost is total value / total quantity
ldEffCost = totAmt / totQty;
if ("R".equalsIgnoreCase(tranType))
{
sql = "select distinct lot_no from sreturndet where tran_id = ? and line_no = ? and item_code = ? order by lot_no";
......@@ -3779,37 +3808,34 @@ public class PostOrderActivity {
sql = "select distinct lot_no from invoice_trace where invoice_id = ? and sord_no = ?"
+ " and sord_line_no = ? and item_code = ? order by lot_no";
}
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, invoiceId);
pstmt2.setString(2, refNo);
pstmt2.setString(3, refLineNo);
pstmt2.setString(4, itemCode);
rs2 = pstmt2.executeQuery();
while (rs2.next())
pstmtLot = conn.prepareStatement(sql);
pstmtLot.setString(1, invoiceId);
pstmtLot.setString(2, refNo);
pstmtLot.setString(3, refLineNo);
pstmtLot.setString(4, itemCode);
rsLot = pstmtLot.executeQuery();
while (rsLot.next())
{
lotNo = rsLot.getString("lot_no");
// 13-jan-17 manoharan moved from above as lot_no not available
if ((priceList.trim()).length() > 0)
{
cLotNo1 = rs2.getString("lot_no");
rate = distCommon.pickRate(priceList, sdf.format(sysdate), itemCode, lotNo, "B", conn);
}
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
// System.out.println("@V@ llSchemeNum before for LOOP 1 :- ["+llSchemeNum+"]");
//System.out.println("@V@ llSchemeNum before for LOOP 1 :- ["+llSchemeNum+"]");
//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)
{
//if (!lbChkNull) // 13-jan-17 manoharan not required
//{
llctrCol = 0;
//lsScheme = "SCHEME_HIST_KEY" + llCtrSch;
lsVarValue = schemeKeyList.get(llCtrSch); //distCommon.getDisparams("999999", lsScheme, conn);
lsColname = lsVarValue.split(",");
llctrCol = lsColname.length;
}
//}
lsDocValue = "";
llCnt = 0;
lsSchemeCode = "";
......@@ -3817,8 +3843,10 @@ public class PostOrderActivity {
// System.out.println("@V@ llctrCol before for LOOP 2 :- ["+llctrCol+"]");
for (llCnt = 0; llCnt < llctrCol; llCnt++) // FOR LOOP [2]
{
// System.out.println("@V@ FOR LOOP 2");
xFldValue = "";
lsColnameStr = lsColname[llCnt];
//System.out.println("@V@ FOR LOOP (1) llCnt [" + llCnt+ "] lsColnameStr ["+ lsColnameStr+"] llCtrSch ["+ llCtrSch+ "] lsVarValue [" +lsVarValue +"]");
if (lsColnameStr.trim().equalsIgnoreCase("site_code"))
{
lsDocValue = lsDocValue + ',' + siteCode.trim();
......@@ -3840,14 +3868,14 @@ public class PostOrderActivity {
{
if ("R".equalsIgnoreCase(tranType))
{
lsSelectSql = "select " + lsColnameStr + " from sreturndet where tran_id = '" + invoiceId + "'" + " and line_no = " + refLineNo + " and lot_no ='" + cLotNo1 + " and item_code ='" + itemCode + "'";
lsSelectSql = "select " + lsColnameStr + " from sreturndet where tran_id = '" + invoiceId + "'" + " and line_no = " + refLineNo + " and lot_no ='" + lotNo + " and item_code ='" + itemCode + "'";
} else
{
lsSelectSql = "select " + lsColnameStr + " from invoice_trace where invoice_id = '" + invoiceId + "'" + " and sord_line_no = " + refLineNo + " and lot_no ='" + cLotNo1 + "'" + " and item_code ='" + itemCode + "' and item_code__ord = '" + itemCodeOrd + "' and sord_no ='" + refNo + "'";
lsSelectSql = "select " + lsColnameStr + " from invoice_trace where invoice_id = '" + invoiceId + "'" + " and sord_line_no = " + refLineNo + " and lot_no ='" + lotNo + "'" + " and item_code ='" + itemCode + "' and item_code__ord = '" + itemCodeOrd + "' and sord_no ='" + refNo + "'";
}
pstmt2 = conn.prepareStatement(lsSelectSql);
rs2 = pstmt2.executeQuery();
while (rs2.next())
if (rs2.next())
{
xFldValue = checkNull(rs2.getString(1));
}
......@@ -3935,14 +3963,14 @@ public class PostOrderActivity {
{
if ("R".equalsIgnoreCase(tranType))
{
lsSelectSql = "select " + lsColnameStr + " from sreturndet where tran_id = '" + invoiceId + "'" + " and line_no = " + refLineNo + " and lot_no ='" + cLotNo1 + "' and item_code ='" + itemCode + "'";
lsSelectSql = "select " + lsColnameStr + " from sreturndet where tran_id = '" + invoiceId + "'" + " and line_no = " + refLineNo + " and lot_no ='" + lotNo + "' and item_code ='" + itemCode + "'";
} else
{
lsSelectSql = "select " + lsColnameStr + " from invoice_trace where invoice_id = '" + invoiceId + "'" + " and sord_line_no = '" + refLineNo + "' and lot_no ='" + cLotNo1 + "' and rate = " + rate + "" + " and item_code ='" + itemCode + "' and item_code__ord = '" + itemCodeOrd + "' and sord_no ='" + refNo + "'";
lsSelectSql = "select " + lsColnameStr + " from invoice_trace where invoice_id = '" + invoiceId + "'" + " and sord_line_no = '" + refLineNo + "' and lot_no ='" + lotNo + "' and rate = " + rate + "" + " and item_code ='" + itemCode + "' and item_code__ord = '" + itemCodeOrd + "' and sord_no ='" + refNo + "'";
}
pstmt2 = conn.prepareStatement(lsSelectSql);
rs2 = pstmt2.executeQuery();
while (rs2.next())
if (rs2.next())
{
xFldValue = checkNull(rs2.getString(1));
}
......@@ -4026,7 +4054,7 @@ public class PostOrderActivity {
}
}// FOR LOOP [2] --END--
//System.out.println("lsDocValue>>>>>>["+lsDocValue+"]");
//System.out.println("13-jan-17 lsDocValue>>>>>>["+lsDocValue+"]");
lsDocValue = lsDocValue.substring(1, lsDocValue.length());
if ("I".equalsIgnoreCase(tranType))
......@@ -4087,7 +4115,7 @@ public class PostOrderActivity {
pstmt2.setString(6, custCode);
pstmt2.setString(7, itemCode);
pstmt2.setString(8, siteCode);
pstmt2.setString(9, cLotNo1);
pstmt2.setString(9, lotNo);
pstmt2.setString(10, lsReturnable);
pstmt2.setString(11, lsReasCode);
pstmt2.setTimestamp(12, chgDate);
......@@ -4167,7 +4195,7 @@ public class PostOrderActivity {
pstmt2.setString(6, custCode);
pstmt2.setString(7, itemCode);
pstmt2.setString(8, siteCode);
pstmt2.setString(9, cLotNo1);
pstmt2.setString(9, lotNo);
pstmt2.setString(10, lsReturnable);
pstmt2.setString(11, lsReasCode);
pstmt2.setTimestamp(12, chgDate);
......@@ -4229,73 +4257,15 @@ public class PostOrderActivity {
}
}// FOR LOOP [1] --END--
// sql = "select count(*) as cnt from scheme_history where doc_key = ?";
// pstmt2 = conn.prepareStatement(sql);
// pstmt2.setString(1, lsDocValue);
// rs2 = pstmt2.executeQuery();
// if (rs2.next())
// {
// cnt = rs2.getInt("cnt");
// }
// pstmt2.close();
// pstmt2 = null;
// rs2.close();
// rs2 = null;
//
// if (cnt == 0)
// {
// sql = "insert into scheme_history (doc_key, eff_cost, scheme_code, invoice_id, invoice_date, cust_code, item_code, site_code, lot_no," + " chg_date, chg_user, chg_term ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
// pstmt2 = conn.prepareStatement(sql);
// pstmt2.setString(1, lsDocValue);
// pstmt2.setDouble(2, ldEffCost);
// pstmt2.setString(3, itemCodeOrd);
// pstmt2.setString(4, invoiceId);
// pstmt2.setTimestamp(5, tranDate);
// pstmt2.setString(6, custCode);
// pstmt2.setString(7, itemCode);
// pstmt2.setString(8, siteCode);
// pstmt2.setString(9, cLotNo1);
// pstmt2.setString(10, chgDate);
// pstmt2.setString(11, logInCode);
// pstmt2.setString(12, termId);
// cnt = pstmt2.executeUpdate();
//
// pstmt2.close();
// pstmt2 = null;
// } else
// {
// sql = "select eff_cost from scheme_history where doc_key = ?";
// pstmt2 = conn.prepareStatement(sql);
// pstmt2.setString(1, lsDocValue);
// rs2 = pstmt2.executeQuery();
// if (rs2.next())
// {
// ldSchCost = rs2.getDouble("eff_cost");
// }
// pstmt2.close();
// pstmt2 = null;
// rs2.close();
// rs2 = null;
//
// if (ldEffCost < ldSchCost && ldEffCost != 0)
// {
// sql = "update scheme_history set eff_cost =?, scheme_code =?, chg_date =?, chg_user =?,chg_term =?" + " where doc_key =?";
// pstmt2 = conn.prepareStatement(sql);
// pstmt2.setDouble(1, ldEffCost);
// pstmt2.setString(2, itemCodeOrd);
// pstmt2.setString(3, chgDate);
// pstmt2.setString(4, logInCode);
// pstmt2.setString(5, termId);
// pstmt2.setString(6, lsDocValue);
//
// cnt = pstmt2.executeUpdate();
//
// pstmt2.close();
// pstmt2 = null;
// }
// }
}
pstmtLot.close();
pstmtLot = null;
rsLot.close();
rsLot = null;
}
itemCodeOld = itemCode;
refNoOld = refNo;
}
rs.close();
rs = null;
......
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