Commit e5e4001c authored by kshinde's avatar kshinde

Sales Order group scheme update

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@176919 ce508802-f39f-4f6c-b175-0d175dae99d5
parent fe40280a
......@@ -9745,9 +9745,20 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
{
lsItemDesc = mDescr;
}
// setNodeValue( dom, "sch_attr", getAbsString("Y"));
String schAttr = checkNull(genericUtility.getColumnValue("sch_attr", dom));
System.out.println("9750::schAttr["+schAttr+"]");
if(schAttr != null && "N".equalsIgnoreCase(schAttr))
{
System.out.println("lsItemDesc["+lsItemDesc+"]");
valueXmlString.append("<item_descr>").append("<![CDATA[" + lsItemDesc + "]]>").append("</item_descr>");
setNodeValue( dom, "item_descr", getAbsString( lsItemDesc));
}
/*
System.out.println("lsItemDesc["+lsItemDesc+"]");
valueXmlString.append("<item_descr>").append("<![CDATA[" + lsItemDesc + "]]>").append("</item_descr>");
setNodeValue( dom, "item_descr", getAbsString( lsItemDesc));
*/
if (lsUnitSal == null || lsUnitSal.trim().length() == 0)
{
......@@ -12973,18 +12984,20 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
//pstmt1.setString(2, lsItemCodeOrd);
//System.out.println("lsItemCodeOrd in side @@@@"+sql+"]");
rs1 = pstmt1.executeQuery();
int countSch = 0;
if (rs1.next())
{
cnt = rs1.getInt("cnt");
countSch = rs1.getInt("cnt");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
System.out.println("prod_sch@@@@@@@["+sql+"]");
System.out.println("countSch@@@@@@@["+countSch+"]");
System.out.println("lsSchemeCode before "+lsSchemeCode+"]");
if(cnt>0)
if(countSch>0)
{
System.out.println("lsCurscheme"+lsCurscheme+"]");
/*if (rs.next())
{*/
......@@ -12994,7 +13007,7 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
//lsCurscheme = rs.getString("scheme_code");
System.out.println("lsCurscheme"+lsCurscheme+"]");
sql = "Select count(*) as cnt From scheme_applicability A,bom b "
/*sql = "Select count(*) as cnt From scheme_applicability A,bom b "
+ "Where A.scheme_code = b.bom_code And B.bom_code= ?"
+" And (? between case when b.min_qty is null then 0 else b.min_qty end"
+ " And case when b.max_qty is null then 0 else b.max_qty end)"
......@@ -13012,7 +13025,7 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
rs = null;
pstmt.close();
pstmt = null;
System.out.println("before cnt1 "+cnt+"]");
System.out.println("before cnt1 "+cnt+"]");*/
if(cnt > 0)
{
......@@ -13074,8 +13087,8 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
pstmt.close();
pstmt = null;
valueXmlString.append("<sch_descr>").append("<![CDATA[" + descr + "]]>").append("</sch_descr>");
setNodeValue( dom, "sch_descr", getAbsString( descr ) );
valueXmlString.append("<item_descr>").append("<![CDATA[" + descr + "]]>").append("</item_descr>");
setNodeValue( dom, "item_descr", getAbsString( descr ) );
// valueXmlString.append("<item_code>").append("<![CDATA[" + lsSchemeCode + "]]>").append("</item_code>");
// setNodeValue( dom, "item_code", getAbsString(lsSchemeCode));
System.out.println("descr SCH_GROUP_DEF"+descr+"]");
......@@ -13088,6 +13101,9 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
}
}else
{
}
......@@ -13098,6 +13114,12 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
rs = pstmt.executeQuery()*/
}
if(countSch > 0)
{
lsSchemeCode = "";
schecnt=0;
}
}
else
{
......
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
//import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
......@@ -16,6 +14,7 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import javax.ejb.Stateless;
......@@ -23,90 +22,73 @@ import javax.ejb.Stateless;
public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGroupSchemeActRemote, SorderGroupSchemeActLocal
{
E12GenericUtility genericUtility= new E12GenericUtility();
FinCommon finCommon = new FinCommon();
DistCommon disCommon= new DistCommon();
UtilMethods utilMethod = new UtilMethods();
public String actionHandler(String saleOrder, String xtraParams, String forcedFlag)throws RemoteException, ITMException
{
StringBuffer msgAppStrinrg = new StringBuffer("");
StringBuffer msgNotAppString = new StringBuffer("");
System.out.println(">>>>>>>>>>>>>>>>>>SorderGroupSchemeAct called>>>>>>>>>>>>>>>>>>>");
Connection conn = null;
String sql="", sql1="" , sql2="", sql3="", sql4="", sql5="";
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null, pstmt3 = null, pstmt4 = null, pstmt5 = null;
ResultSet rs = null, rs1 = null, rs2 = null, rs3 = null, rs4 = null;
int cnt = 0, cnt1 = 0, cnt2 = 0, count = 0;
String sql="", sql1="" , sql2="", sql3="";
String sql4="", sql5="";
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
PreparedStatement pstmt3 = null, pstmt4 = null, pstmt5 = null;
ResultSet rs = null, rs1 = null, rs2 = null, rs3 = null; // rs4 = null;
int count = 0, count1 = 0, count2 = 0, count3 = 0;
String errString = null;
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
double qty = 0.0, rate;
String schAttr = "" , itemCodeOrd="" ,nature = "" , schAttr1 = "", ordType = "", custCode = "", schmDesc = "", schmCode = "";
String ordtype = "", schemeCode="", itemCodeParent="" , curScheme = "", prevScheme = "", custSchemeCode = "";
String siteCode="", StateCodeDlv = "", CountCodeDlv="", lstype = "", lineNo = "";
double qty = 0.0, rate=0.0;
String schLineNo = "", schItemCode = "", schNature = "", schScheme = "", schFalg = "";
double schQty = 0.0, schRate=0.0;
String itemCodeOrd = "" ,nature = "" , schAttr1 = "", ordType = "", custCode = "", schmDesc = "", lineNo = "";
String ordtype = "", schemeCode="", schemeCode1="",itemCodeParent="" , curScheme = "", prevScheme = "", custSchemeCode = "";
String siteCode="", StateCodeDlv = "", CountCodeDlv="", lstype = "";
Timestamp ordDate = null;
String applyCustList = "", noApplyCustList = "" , applicableOrdTypes = "", mainStr="", msgApplied="", msgNotApplied="", itemCode1="";
boolean proceed = false;
String lineNo1 = "", nature1 = "";
String lineNo1 = "", nature1="";
double qty1 = 0.0, totalQty = 0.0, chargeAmt = 0.0 , freeDiscount = 0.0;
int no=0;
ArrayList<HashMap> itemList =new ArrayList<HashMap>();
String schemeType = "";
int PurcBase = 0, SchAllowence = 0;
double freeQty = 0.0;
try
{
ConnDriver connDriver = null;
//connDriver = new ConnDriver();
//conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
conn.setAutoCommit(false);
System.out.println("saleOrder...["+saleOrder+"]");
if (saleOrder != null && saleOrder.trim().length() > 0)
{
//sql = " select SCH_ATTR from SORDDET where sale_order = ?;";
/*sql = " select count(*) from SORDDET where sale_order = ? and sch_attr = 'Y'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, saleOrder);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
//System.out.println("schAttr..["+schAttr+"]");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("@@70..cnt is..["+cnt+"]");
if (cnt == 0)
{
errString = itmDBAccessLocal.getErrorString("", "VTNOSCHEME", "");
return errString;
}
*/
sql = " SELECT A.ITEM_CODE__ORD, A.QUANTITY, A.NATURE, A.SCH_ATTR, B.ORDER_TYPE, B.ORDER_DATE, A.SITE_CODE, B.STATE_CODE__DLV, B.COUNT_CODE__DLV, B.ORDER_TYPE, B.CUST_CODE, A.LINE_NO, A.RATE " +
"FROM SORDDET A, SORDER B " +
"WHERE A.SALE_ORDER = B.SALE_ORDER and A.SALE_ORDER = ? and A.SCH_ATTR = 'Y' and A.NATURE = 'C' AND (CASE WHEN A.SPEC_REASON IS NULL THEN ' ' ELSE TRIM(A.SPEC_REASON) END) != 'P'";
sql = "SELECT B.LINE_NO, B.ITEM_CODE__ORD, B.QUANTITY, B.RATE, B.NATURE, B.SCH_ATTR, A.ORDER_TYPE, A.ORDER_DATE, B.SITE_CODE, A.STATE_CODE__DLV, A.COUNT_CODE__DLV, A.CUST_CODE " +
"FROM SORDER A, SORDDET B " +
"WHERE A.SALE_ORDER = B.SALE_ORDER AND B.SALE_ORDER = ? AND B.SCH_ATTR = 'Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, saleOrder);
rs = pstmt.executeQuery();
while (rs.next())
{
itemCodeOrd = checkNull(rs.getString(1));
qty = rs.getDouble(2);
nature = checkNull(rs.getString(3));
schAttr1 = checkNull(rs.getString(4));
ordtype = checkNull(rs.getString(5));
ordDate = rs.getTimestamp(6);
siteCode = checkNull(rs.getString(7));
StateCodeDlv = checkNull(rs.getString(8));
CountCodeDlv = checkNull(rs.getString(9));
ordType = checkNull(rs.getString(10));
custCode = checkNull(rs.getString(11));
lineNo = checkNull(rs.getString(12));
rate = rs.getDouble(13);
lineNo = checkNull(rs.getString(1));
itemCodeOrd = checkNull(rs.getString(2));
qty = rs.getDouble(3);
rate = rs.getDouble(4);
nature = checkNull(rs.getString(5));
schAttr1 = checkNull(rs.getString(6));
ordtype = checkNull(rs.getString(7));
ordDate = rs.getTimestamp(8);
siteCode = checkNull(rs.getString(9));
StateCodeDlv = checkNull(rs.getString(10));
CountCodeDlv = checkNull(rs.getString(11));
custCode = checkNull(rs.getString(12));
System.out.println("lineNo["+lineNo+"]");
System.out.println("itemCodeOrd["+itemCodeOrd+"]");
System.out.println("qty["+qty+"]");
System.out.println("rate["+rate+"]");
System.out.println("nature["+nature+"]");
System.out.println("schAttr1["+schAttr1+"]");
System.out.println("ordtype["+ordtype+"]");
......@@ -114,142 +96,111 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
System.out.println("siteCode["+siteCode+"]");
System.out.println("StateCodeDlv["+StateCodeDlv+"]");
System.out.println("CountCodeDlv["+CountCodeDlv+"]");
System.out.println("ordType["+ordType+"]");
System.out.println("lineNo["+lineNo+"]");
System.out.println("custCode["+custCode+"]");
sql2 = "SELECT COUNT(*) FROM SORDDET WHERE LINE_NO = ? AND SALE_ORDER = ? AND NATURE = 'F'";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, lineNo);
pstmt2.setString(2, saleOrder);
rs2 = pstmt2.executeQuery();
if (rs2.next())
//checks the schemes of items from sorddet lineNo wise.
sql1 = "SELECT A.SCHEME_CODE FROM SCHEME_APPLICABILITY A, SCHEME_APPLICABILITY_DET B " +
"WHERE A.SCHEME_CODE = B.SCHEME_CODE AND (A.ITEM_CODE = ? OR A.PROD_SCH = 'Y') " +
"AND A.APP_FROM <= ? AND A.VALID_UPTO >= ? " +
"AND (B.SITE_CODE = ? OR B.STATE_CODE = ? OR B.COUNT_CODE = ? ) ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, itemCodeOrd);
pstmt1.setTimestamp(2, ordDate);
pstmt1.setTimestamp(3, ordDate);
pstmt1.setString(4, siteCode);
pstmt1.setString(5, StateCodeDlv);
pstmt1.setString(6, CountCodeDlv);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
cnt = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("128## cnt...["+cnt+"]");
if(cnt > 0)
schemeCode = checkNull(rs1.getString("scheme_code"));
System.out.println("schemeCode...["+schemeCode+"]");
if (schemeCode != null && schemeCode.trim().length() > 0)
{
continue;
}
sql2 = "select bom_code,item_stru from item where item_code = ?";
//-----------------------------------------------------------------------------------
/* sql2 = "select item_code__parent from item where item_code =?";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, itemCodeOrd);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
schemeCode = checkNull(rs2.getString("bom_code"));
lstype = checkNull(rs2.getString("item_stru"));
itemCodeParent = checkNull(rs2.getString("item_code__parent"));
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("schemeCode[BOM]::["+schemeCode+"] lstype::["+lstype+"]");
if (!"C".equalsIgnoreCase(lstype))
int no12 = 0;
System.out.println("itemCodeParent::["+itemCodeParent+"]");
if (itemCodeParent == null || itemCodeParent.trim().length() == 0)
{
sql3 = "select a.scheme_code from scheme_applicability a,scheme_applicability_det b"
+ " where a.scheme_code= b.scheme_code and (a.item_code= ? or (a.item_code in (select (case when product_code is null then ' ' else product_code end ) from item where item_code = ? )))"
+ " and a.app_from<= ? and a.valid_upto>= ?"
+ " and (b.site_code= ? or b.state_code= ? or b.count_code =? ) and a.PROD_SCH = 'Y' ";
sql3 = "select count(1) as cnt from item where item_code__parent =?";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, itemCodeOrd);
pstmt3.setString(2, itemCodeOrd);
pstmt3.setTimestamp(3, ordDate);
pstmt3.setTimestamp(4, ordDate);
pstmt3.setString(5, siteCode);
pstmt3.setString(6, StateCodeDlv);
pstmt3.setString(7, CountCodeDlv);
rs3 = pstmt3.executeQuery();
while (rs3.next())
{
curScheme = checkNull(rs3.getString("scheme_code"));
System.out.println("curScheme...["+curScheme+"]");
if (curScheme != null || curScheme.trim().length() == 0)
{
sql1 = "select item_code__parent from item where item_code =?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, itemCodeOrd);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
itemCodeParent = checkNull(rs1.getString("item_code__parent"));
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
System.out.println("itemCodeParent::["+itemCodeParent+"]");
if (itemCodeParent == null || itemCodeParent.trim().length() == 0)
{
sql1 = "select count(1) as cnt from item where item_code__parent =?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, itemCodeOrd);
rs1 = pstmt1.executeQuery();
if (rs1.next())
rs3 = pstmt3.executeQuery();
if (rs3.next())
{
cnt1 = rs1.getInt("cnt");
no12 = rs3.getInt("cnt");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
}
System.out.println("cnt1 is..["+cnt1+"]");
if (cnt1 > 0)
System.out.println("no12 is..["+no12+"]");
if (no12 > 0)
{
break;
}
}
sql1 = "Select count(1) as cnt From scheme_applicability A, bom b Where A.scheme_code = b.bom_code And B.bom_code= ?" + " And(? between case when b.min_qty is null then 0 else b.min_qty end" + " And case when b.max_qty is null then 0 else b.max_qty end) and B.promo_term is null";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, curScheme);
pstmt1.setDouble(2, qty);
rs1 = pstmt1.executeQuery();
int no12 = 0 ;
sql2 = "Select count(1) as cnt From scheme_applicability A, bom b Where A.scheme_code = b.bom_code And B.bom_code= ?" + " And(? between case when b.min_qty is null then 0 else b.min_qty end" + " And case when b.max_qty is null then 0 else b.max_qty end) and B.promo_term is null";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, schemeCode);
pstmt2.setDouble(2, qty);
rs2 = pstmt2.executeQuery();
if (rs1.next())
{
cnt1 = rs1.getInt("cnt");
no12 = rs1.getInt("cnt");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("cnt1 from scheme_applicability..["+cnt1+"]");
if(cnt1 == 0)
continue;
System.out.println("no12 from scheme_applicability..["+no12+"]");
if(no12 == 0)
continue;*/
sql1 = "select (case when apply_cust_list is null then ' ' else apply_cust_list end) as ls_apply_cust_list, "
sql2 = "select (case when apply_cust_list is null then ' ' else apply_cust_list end) as ls_apply_cust_list, "
+ " (case when noapply_cust_list is null then ' ' else noapply_cust_list end) as ls_noapply_cust_list, order_type "
+ " from scheme_applicability where scheme_code = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, curScheme);
rs1 = pstmt1.executeQuery();
if (rs1.next())
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, schemeCode);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
applyCustList = checkNull(rs1.getString("ls_apply_cust_list"));
noApplyCustList = checkNull(rs1.getString("ls_noapply_cust_list"));
applicableOrdTypes = checkNull(rs1.getString("order_type"));
applyCustList = checkNull(rs2.getString("ls_apply_cust_list"));
noApplyCustList = checkNull(rs2.getString("ls_noapply_cust_list"));
applicableOrdTypes = checkNull(rs2.getString("order_type"));
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("applyCustList["+applyCustList+"]noApplyCustList["+noApplyCustList+"][applicableOrdTypes["+applicableOrdTypes+"]");
System.out.println("ordType..["+ordType+"]");
if ("NE".equalsIgnoreCase(ordType) && (applicableOrdTypes == null || applicableOrdTypes.trim().length() == 0))
if ("NE".equalsIgnoreCase(ordtype) && (applicableOrdTypes == null || applicableOrdTypes.trim().length() == 0))
{
// goto Nextrec
} else if (applicableOrdTypes != null && applicableOrdTypes.trim().length() > 0)
{ System.out.println("PAVAN R Inside If *****applicableOrdTypes***");
}
else if (applicableOrdTypes != null && applicableOrdTypes.trim().length() > 0)
{
System.out.println("PAVAN R Inside If *****applicableOrdTypes***");
proceed = false;
String applicableOrdTypesArr[] = applicableOrdTypes.split(",");
System.out.println("applicableOrdTypesArr Length::["+applicableOrdTypesArr.length+"]");
......@@ -268,9 +219,9 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
// goto Nextrec
}
}
prevScheme = schemeCode;
schemeCode = curScheme;
System.out.println("250@@@ schemeCode["+schemeCode+"]curScheme["+curScheme+"]");
schemeCode1 = schemeCode;
schemeCode = schemeCode1;
System.out.println("250@@@ schemeCode["+schemeCode+"]");
if (applyCustList.trim().length() > 0)
{
schemeCode = null;
......@@ -302,36 +253,97 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
break;
}
}
cnt1 = 0;
if (schemeCode != null)
if ( schemeCode != null)
{
count3 ++;
} else if (count3 == 1)
{
cnt2++;
} else if (cnt2 == 1)
schemeCode = schemeCode1;
System.out.println("lsSchemeCode264:::::::"+schemeCode);
}
// Nextrec:
// fetch next curscheme into :ls_curscheme;
//-----------------------------------------------------
}else
{
schemeCode = prevScheme;
System.out.println("lsSchemeCode:::::::2"+schemeCode);
System.out.println("Scheme not found for Item::["+itemCodeOrd+"]");
}
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
System.out.println("outside while..schemeCode..["+schemeCode+"]");
/*if (cnt2 > 1)
if (count3 > 1)
{
schemeCode = "";
} else*/
if (custSchemeCode.trim().length() > 0)
}
//---IF SCHEME CODE IS GREATER THAN 0 START
if(schemeCode!= null && schemeCode.trim().length() > 0)
{
//To check free item against SchemeCode
sql2 = "SELECT COUNT(*) FROM SCH_OFFER_ITEMS WHERE SCHEME_CODE = ? and ITEM_CODE = ?";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, schemeCode);
pstmt2.setString(2, itemCodeOrd);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
System.out.println("lsSchemeCode:::::::3"+schemeCode);
schemeCode = custSchemeCode;
count2 = rs2.getInt(1);
System.out.println("sch _off-1 count2--["+count2+"]");
}
String schemeType = "";
int PurcBase = 0, SchAllowence = 0;
double freeQty = 0.0;
//To Get Offer aginst scheme
System.out.println("sch _off-2 count2--["+count2+"]");
if (count2 > 0)
{
HashMap schemItemMap = new HashMap();
schemItemMap.put("lineNo", lineNo);
schemItemMap.put("itemCode", itemCodeOrd);
schemItemMap.put("scheme", schemeCode);
schemItemMap.put("qty", qty);
schemItemMap.put("rate", rate);
schemItemMap.put("nature", nature);
schemItemMap.put("schemeNature", "F");
itemList.add(schemItemMap);
}
count2 = 0;
sql2 = "SELECT COUNT(*) FROM SCH_PUR_ITEMS WHERE SCHEME_CODE = ? AND ITEM_CODE = ?";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, schemeCode);
pstmt2.setString(2, itemCodeOrd);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
count2 = rs2.getInt(1);
System.out.println("sch_pur--1 count2--["+count2+"]");
}
System.out.println("sch_pur--2 count2--["+count2+"]");
if (count2 > 0)
{
HashMap schemItemMap = new HashMap();
schemItemMap.put("lineNo", lineNo);
schemItemMap.put("itemCode", itemCodeOrd);
schemItemMap.put("scheme", schemeCode);
schemItemMap.put("qty", qty);
schemItemMap.put("rate", rate);
schemItemMap.put("nature", nature);
schemItemMap.put("schemeNature", "C");
itemList.add(schemItemMap);
}
}
//--------------------------------------
/*//To Get Offer aginst scheme
sql3 = "SELECT DESCR, SCHEME_TYPE, PURC_BASE, SCH_ALLOWENCE FROM SCH_GROUP_DEF where SCHEME_CODE= ?";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, schemeCode);
......@@ -347,94 +359,160 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
rs3 = null;
pstmt3.close();
pstmt3 = null;
System.out.println("schmDesc"+schmDesc+"]");
System.out.println("schmDesc"+schmDesc+"]"); */
//abouve sql added in if schNature='F'
sql3 ="select count (*) as cnt from sch_pur_items where SCHEME_CODE =? and item_code=?";
/* sql3 ="select count (*) as cnt from sch_pur_items where SCHEME_CODE =? and item_code=?";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, schemeCode);
pstmt3.setString(2, itemCodeOrd);
int count5 = 0;
rs3 = pstmt3.executeQuery();
if (rs3.next())
{
cnt2 = rs3.getInt(1);
count5 = rs3.getInt(1);
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
if (cnt2 == 0)
if (count5 == 0)
{
schemeCode = "";
continue;
}*/
/*
if(!("Y".equalsIgnoreCase(schAttr)))
{
errString = itmDBAccessLocal.getErrorString("", "VTMCONF20", "");
return errString;
}else if(!"P".equalsIgnoreCase(""))
{
errString = itmDBAccessLocal.getErrorString("", "VTSOSTAT", "Sales order is not in pending status");
return errString;
} */
} //sorder/sorddet while end
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//ArrayList<String>
System.out.println("itemList::[~"+itemList+"~]");
double freeTotQty = 0.0, chrgbleTotQty = 0.0;
for (HashMap schemItemMap: itemList)
{
schLineNo = (String)schemItemMap.get("lineNo");
schItemCode = (String)schemItemMap.get("itemCode");
schScheme = (String)schemItemMap.get("scheme");
schQty = (Double)schemItemMap.get("qty");
schRate = (Double)schemItemMap.get("rate");
schNature = (String)schemItemMap.get("nature");
schFalg = (String)schemItemMap.get("schemeNature");
System.out.println("schemItemMap[-"+schLineNo+"-"+schFalg+"-"+schItemCode+"-"+schScheme+"-"+schQty+"-"+schRate+"-"+schNature);
if ("F".equalsIgnoreCase(schFalg))
{
freeTotQty = freeTotQty+schQty;
}else if("C".equalsIgnoreCase(schFalg)){
chrgbleTotQty = chrgbleTotQty + schQty;
}
System.out.println("freeTotQty["+freeTotQty+"]--chrgbleTotQty["+chrgbleTotQty+"]");
}
//To Check offer againts Scheme code...
//sql3 = "SELECT count(1) FROM SCH_OFFER_ITEMS where SCHEME_CODE= ?";
sql3 = "SELECT count(*) FROM SORDDET WHERE ITEM_CODE IN " +
"(SELECT ITEM_CODE FROM SCH_OFFER_ITEMS WHERE SCHEME_CODE=?) AND SCH_ATTR = 'Y' AND RATE != 0 AND SALE_ORDER = ? ";
//Check If Items are chargable but offer item not selected then Error Msg
if(chrgbleTotQty > 0 && freeTotQty== 0)
{
for (HashMap schemItemMap: itemList)
{
schLineNo = (String)schemItemMap.get("lineNo");
schItemCode = (String)schemItemMap.get("itemCode");
schScheme = (String)schemItemMap.get("scheme");
schQty = (Double)schemItemMap.get("qty");
schRate = (Double)schemItemMap.get("rate");
schNature = (String)schemItemMap.get("nature");
schFalg = (String)schemItemMap.get("schemeNature");
System.out.println("schemItemMap[-"+schLineNo+"-"+schFalg+"-"+schItemCode+"-"+schScheme+"-"+schQty+"-"+schRate+"-"+schNature);
if ("F".equalsIgnoreCase(schFalg))
{
freeTotQty = freeTotQty+schQty;
}else if("C".equalsIgnoreCase(schFalg)){
chrgbleTotQty = chrgbleTotQty + schQty;
}
System.out.println("freeTotQty["+freeTotQty+"]--chrgbleTotQty["+chrgbleTotQty+"]");
}
//Scheme applied msg
mainStr="Line No:"+schLineNo+" Item Code:"+schItemCode+" Scheme:"+schScheme;
msgNotAppString = msgNotAppString.append(mainStr);
System.out.println("--msgNotAppString--"+msgNotAppString);
}
//Checks scheme type and description
sql3 = "SELECT DESCR, SCHEME_TYPE, PURC_BASE, SCH_ALLOWENCE FROM SCH_GROUP_DEF where SCHEME_CODE= ?";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, schemeCode);
pstmt3.setString(2, saleOrder);
pstmt3.setString(1, schScheme);
rs3 = pstmt3.executeQuery();
if (rs3.next())
{
count = rs3.getInt(1);
schmDesc = checkNull(rs3.getString(1));
schemeType = checkNull(rs3.getString(2));
PurcBase = rs3.getInt(3);
SchAllowence = rs3.getInt(4);
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
System.out.println("count...["+count+"]");
if (count == 0)
{
mainStr="Line No:"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schemeCode; //+" Description:"+schmDesc;
msgNotAppString = msgNotAppString.append(mainStr);
System.out.println("--msgNotAppString--"+msgNotAppString);
System.out.println("schmDesc"+schmDesc+"]");
}else
//update value from map
for (HashMap schemItemMap: itemList)
{
schLineNo = (String)schemItemMap.get("lineNo");
schItemCode = (String)schemItemMap.get("itemCode");
schScheme = (String)schemItemMap.get("scheme");
schQty = (Double)schemItemMap.get("qty");
schRate = (Double)schemItemMap.get("rate");
schNature = (String)schemItemMap.get("nature");
schFalg = (String)schemItemMap.get("schemeNature");
System.out.println("schemItemMap[-"+schLineNo+"-"+schFalg+"-"+schItemCode+"-"+schScheme+"-"+schQty+"-"+schRate+"-"+schNature);
sql3 = "SELECT LINE_NO, QUANTITY, NATURE, ITEM_CODE FROM SORDDET WHERE ITEM_CODE IN " +
"(SELECT ITEM_CODE FROM SCH_OFFER_ITEMS WHERE SCHEME_CODE = ?) AND SALE_ORDER = ? AND SCH_ATTR = 'Y'AND RATE != 0 ";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, schemeCode);
pstmt3.setString(2, saleOrder);
rs3 = pstmt3.executeQuery();
if ("F".equalsIgnoreCase(schFalg))
{
freeTotQty = freeTotQty+schQty;
if("0".equalsIgnoreCase(schemeType))
{
freeQty = ((qty * SchAllowence) / PurcBase);
//freeQty = ((qty * SchAllowence) / PurcBase);
freeQty = ((chrgbleTotQty * SchAllowence) / PurcBase);
}
else if("1".equalsIgnoreCase(schemeType))
{
chargeAmt = (qty * rate);
chargeAmt = (chrgbleTotQty * rate);
if(chargeAmt >= PurcBase)
{
freeQty = roundValue(((((qty * rate)* SchAllowence) / PurcBase)), 0);
freeQty = roundValue(((((chrgbleTotQty * rate)* SchAllowence) / PurcBase)), 0);
}
}else if("2".equalsIgnoreCase(schemeType))
{
chargeAmt = (qty * rate);
chargeAmt = (chrgbleTotQty * rate);
if(chargeAmt >= PurcBase)
{
freeDiscount = SchAllowence;
}
}
while (rs3.next())
{
lineNo1 = checkNull(rs3.getString(1));
qty1 = rs3.getDouble(2);
nature1 = checkNull(rs3.getString(3));
itemCode1 = checkNull(rs3.getString(4));
if("2".equalsIgnoreCase(schemeType))
{
sql4 = "UPDATE SORDDET SET DISCOUNT = ? WHERE SALE_ORDER = ? AND LINE_NO = ?";
pstmt4 = conn.prepareStatement(sql4);
pstmt4.setDouble(1, freeDiscount);
pstmt4.setString(2, saleOrder);
pstmt4.setString(2, lineNo1);
pstmt4.setString(3, lineNo1);
no = pstmt4.executeUpdate();
System.out.println("419...no...1..["+no+"]");
pstmt4.close();
......@@ -453,44 +531,29 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
System.out.println("totalQty::["+totalQty+"]");
//Scheme applied msg
mainStr="\nLine No"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schemeCode; //+" Description:"+schmDesc;
mainStr="\nLine No"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schScheme; //+" Description:"+schmDesc;
msgAppStrinrg = msgAppStrinrg.append(mainStr);
System.out.println("--msgString--"+msgAppStrinrg);
}
}
if(qty1 <= freeQty && totalQty <= freeQty)
System.out.println("schQty:["+schQty+"]<= freeQty["+freeQty+"]");
System.out.println("totalQty:["+totalQty+"]<= freeQty["+freeQty+"]");
if(schQty <= freeQty && totalQty < freeQty)
{
sql4 = "UPDATE SORDDET SET NATURE = 'F', RATE = 0, RATE__STDUOM = 0 WHERE SALE_ORDER = ? AND LINE_NO = ?";
pstmt4 = conn.prepareStatement(sql4);
pstmt4.setString(1, saleOrder);
pstmt4.setString(2, lineNo1);
pstmt4.setString(2, schLineNo);
no = pstmt4.executeUpdate();
System.out.println("471...no...["+no+"]");
pstmt4.close();
pstmt4 = null;
if(no > 0)
{
sql5 = "UPDATE SORDDET SET SPEC_REASON='P' WHERE SALE_ORDER = ? AND LINE_NO = ?";
pstmt5 = conn.prepareStatement(sql5);
pstmt5.setString(1, saleOrder);
pstmt5.setString(2, lineNo);
int nos2 = pstmt5.executeUpdate();
System.out.println("430...nos2...["+nos2+"]");
pstmt5.close();
pstmt5 = null;
System.out.println("totalQty::["+totalQty+"]");
//Scheme applied msg
mainStr="Line No:"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schemeCode; //+"// Description:"+schmDesc;
msgAppStrinrg = msgAppStrinrg.append(mainStr);
System.out.println("**msgString**"+msgAppStrinrg);
}
}
totalQty = totalQty + qty1;
totalQty = totalQty + schQty;
System.out.println("@@@516 ToatlQty:"+totalQty);
if(totalQty == freeQty)
{
break;
//break;
}
System.out.println("totalQty::["+totalQty+"]");
......@@ -498,38 +561,50 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
String mainStr="Line No:"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schemeCode+" Description:"+schmDesc;
msgString = msgString.append(mainStr);
System.out.println("--msgString--"+msgString);
*/
*/
if(totalQty == freeQty)
{
continue;
//continue;
}
}else if("C".equalsIgnoreCase(schFalg)){
chrgbleTotQty = chrgbleTotQty + schQty;
}
}
//upadate value from map end
//To Check offer againts Scheme code...
/*sql3 = "SELECT count(*) FROM SORDDET WHERE ITEM_CODE IN " +
"(SELECT ITEM_CODE FROM SCH_OFFER_ITEMS WHERE SCHEME_CODE = ?) AND SCH_ATTR = 'Y' AND RATE != 0 AND SALE_ORDER = ? ";
pstmt3 = conn.prepareStatement(sql3);
pstmt3.setString(1, schScheme);
pstmt3.setString(2, saleOrder);
rs3 = pstmt3.executeQuery();
if (rs3.next())
{
count = rs3.getInt(1);
}
rs3.close();
rs3 = null;
pstmt3.close();
pstmt3 = null;
System.out.println("schemeType::417::["+schemeType+"]");
System.out.println("count...["+count+"]");
if (count == 0)
{
mainStr="Line No:"+lineNo+" Item Code:"+itemCodeOrd+" Scheme:"+schScheme;
msgNotAppString = msgNotAppString.append(mainStr);
System.out.println("--msgNotAppString--"+msgNotAppString);
}
else
{*/
//errString = msgString+"\n~~~Scheme Item But Offer Not Selected.~~~\n"+msgString;
}
}
/*
if(!("Y".equalsIgnoreCase(schAttr)))
{
errString = itmDBAccessLocal.getErrorString("", "VTMCONF20", "");
return errString;
}else if(!"P".equalsIgnoreCase(""))
{
errString = itmDBAccessLocal.getErrorString("", "VTSOSTAT", "Sales order is not in pending status");
return errString;
} */
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//errString = msgString+"\n~~~Scheme Item But Offer Not Selected.~~~\n"+msgString;
......@@ -632,3 +707,4 @@ public class SorderGroupSchemeAct extends ActionHandlerEJB implements SorderGrou
}
}
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