package com.napa.pulse.dao.impl; import com.google.gson.Gson; import com.napa.pulse.dao.interfaces.ReviewDAO; import com.napa.pulse.dao.interfaces.SessionDAO; import com.napa.pulse.dto.*; import com.napa.pulse.entity.security.User; import com.napa.pulse.enums.EPTSRules; import com.napa.pulse.exception.PulseException; import com.napa.pulse.rowmappers.IntegerRowMapper; import com.napa.pulse.service.interfaces.CommonService; import com.napa.pulse.utils.PulseConstants; import com.napa.pulse.utils.SiteQueueMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcCall; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.stereotype.Repository; import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.util.*; import java.util.stream.Collectors; import static org.apache.commons.lang.StringUtils.isNotEmpty; import static org.apache.commons.lang.StringUtils.isNotBlank; /** * @author Tathagata *

* Created on 05/12/2015 */ @Repository public class ReviewDAOImpl implements ReviewDAO { private static final Logger LOGGER = LoggerFactory.getLogger(ReviewDAOImpl.class); private final Gson gson = new Gson(); @Autowired private CommonService commonService; @Autowired private JdbcTemplate jdbcTemplate; @Autowired SiteQueueMap siteQueueMap; @Autowired SessionDAO sessionDAO; // @Autowired // User user; ArrayList ProductIds=new ArrayList(); @Override public List> getSKUTableData ( SKUTableWidgetData skuTableWidgetData, User user ) { boolean isFinalized = isSessionFinalized(skuTableWidgetData.getSessionId()); int startRowNumber = (skuTableWidgetData.getPageNumber() - 1) * skuTableWidgetData.getNumberOfRecordsPerPage() + 1; int endRowNumber = skuTableWidgetData.getPageNumber() * skuTableWidgetData.getNumberOfRecordsPerPage(); ActionResult result = new ActionResult(); List> skuTableData = new ArrayList<>(); try { Map sortMap = new HashMap() { private static final long serialVersionUID = 1L; { put("sku", "(P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER)"); put("description", "P." + (("en".equals(user.getLanguage()) || user.getLanguage() == null) ? "PRODUCT_DESC" : "PRODUCT_DESC_FR")); put("perCar", "P.PER_CAR"); put("introDate", "P.INTRO_DT"); put("avgAge", "P.AVG_AGE"); put("topApp", "P.TOP_APP"); put("salesPotential", "NVL(MAX(ssp.PTS),0)"); put("prolinkNational", "NVL(pdc.nat_product_views_12,0)"); put("prolinkDc", "NVL(pdc.product_views_12,0)"); put("prolinkSite", "NVL(L.product_views_12,0)"); put("dcrPts", "MAX(ssp.DCR_PTS)"); put("stdPack", "P.JBR_STD_PKG"); put("groupCode", "P.GROUP_CODE"); put("nationalVIO", "P.NATIONAL_VIO"); put("national12", "P.NATIONAL_SALES_12"); put("national24", "P.NATIONAL_SALES_24"); put("reviewed", "NVL(REVIEWED,0)"); put("approxSize", "P.PRODUCT_CUBIC"); put("skucost", "MAX(ssp.price_wt_core)"); } }; //counting the number of dc siteIds Integer dcCount = jdbcTemplate.queryForObject("select nvl(count(distinct s.product_availability_id),0) from site s where site_id in " + "(select site_id from session_site where session_id=" + skuTableWidgetData.getSessionId() + ")", Integer.class); Integer siteCount = jdbcTemplate.queryForObject("select count(distinct site_id) from session_site where session_id=" + skuTableWidgetData.getSessionId(), Integer.class); String query3 = (dcCount != null && dcCount != 0) ? " MAX(NVL(pdc.nat_product_views_12,0)) " : " 0 "; String query = (dcCount != null && dcCount == 1) ? "MAX(NVL(pdc.product_views_12,0)) " : " 0 "; String query2 = ((skuTableWidgetData.getSiteIdsArray() != null && skuTableWidgetData.getSiteIdsArray().length == 1) || (siteCount != null && siteCount == 1)) ? " MAX(NVL(L.product_views_12,0)) " : " 0 "; List site_Type_Code = jdbcTemplate.queryForList("select site_type_code from site where site_id in " + "(select site_id from session_site where session_id=" + skuTableWidgetData.getSessionId() + ")", String.class); boolean site_type = false; for (String site_type_cd : site_Type_Code) { if ("MA".equals(site_type_cd)) { site_type = true;} break; } String hintForSessionSiteProduct = isFinalized? "": " /*+ no_index(ssp) */ "; String sql = " SELECT \"productId\", \"sku\", \"description\", \"perCar\", \"introDate\",\"prolinkNational\",\"prolinkDc\",\"prolinkSite\", \"topApp\", \"salesPotential\",\"dcrPts\",\"businessRulesApplied\",\"stdPack\", \"avgAge\", \"groupCode\", \"nationalVIO\", \"national12\", \"national24\", \"reviewed\", \"approxSize\",\"skucost\", RN FROM " + "(select " + hintForSessionSiteProduct + " P.PRODUCT_ID AS \"productId\", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS \"sku\", P." + (("en".equals(user.getLanguage()) || user.getLanguage() == null) ? "PRODUCT_DESC" : "PRODUCT_DESC_FR") + " AS \"description\", " + " P.PER_CAR AS \"perCar\", P.INTRO_DT AS \"introDate\", " + query3 + " AS \"prolinkNational\"," + query + "as \"prolinkDc\"," + query2 + "as \"prolinkSite\",P.TOP_APP AS \"topApp\", NVL(MAX(ROUND(ssp.PTS*100)),0) AS \"salesPotential\", MAX(ROUND(ssp.DCR_PTS,2)) AS \"dcrPts\", SUM(CASE WHEN ssp.business_rules_applied = '000' THEN 0 ELSE 1 END) as \"businessRulesApplied\", P.JBR_STD_PKG AS \"stdPack\", P.AVG_AGE AS \"avgAge\", P.GROUP_CODE as \"groupCode\", P.NATIONAL_VIO AS \"nationalVIO\", " + "P.NATIONAL_SALES_12 as \"national12\", P.NATIONAL_SALES_24 as \"national24\", NVL(REVIEWED,0) as \"reviewed\", nvl(P.PRODUCT_CUBIC,0) as \"approxSize\", MAX(ssp.price_wt_core) AS \"skucost\", "; if ("sku".equals(skuTableWidgetData.getSortBy())) { sql += " DENSE_RANK() OVER (ORDER BY " + sortMap.get(skuTableWidgetData.getSortBy()) + " " + skuTableWidgetData.getSortingOrder() + ")RN "; } else { sql += " DENSE_RANK() OVER (ORDER BY " + sortMap.get(skuTableWidgetData.getSortBy()) + " " + skuTableWidgetData.getSortingOrder() + ", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER))RN "; } sql += " from product p, " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " ssp ,(SELECT site_id, product_id, product_views_12 FROM prolink_rollup WHERE is_dc = 0) L" + " , (SELECT site_id, product_id, product_views_12, nat_product_views_12 FROM prolink_rollup WHERE is_dc = 1) pdc"; // code here if (!site_type) { if (dcCount != null && dcCount == 1) { sql += " ,(SELECT dc.site_id dc_id ,s.site_id siteId FROM site s," + "site dc WHERE s.product_availability_id = dc.product_availability_id " + " AND dc.site_type_code = 'DC' and s.site_id in(select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") ) dcSite "; } else { sql += " ,(SELECT s.site_id siteId, dc.site_id dc_id FROM site s," + "site dc WHERE s.product_availability_id = dc.product_availability_id " + " AND dc.site_type_code = 'DC' and s.site_id in(select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ")) dcSite"; } } // lost sales if (skuTableWidgetData.isSoldNotStocked()) { sql += " , SITE_PARAMETER SP, Site s "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " , Site s "; } // Similar Parts Filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (select /*+ no_index(ssp_) */ distinct sp_.product_id, (sp_.SIMILAR_PRODUCT_ID) similar_product_id, order_qty from SESSION_SITE_PRODUCT ssp_, SIMILAR_PRODUCT sp_" + " where ssp_.SESSION_ID = " + skuTableWidgetData.getSessionId() + " and ssp_.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " )" + " and sp_.similar_PRODUCT_ID = ssp_.PRODUCT_ID) sim " + " , (SELECT DISTINCT sp.product_id, sim.similar_product_id," + " SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (SELECT DISTINCT sp.product_id, SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else sql += " , SIMILAR_PRODUCT similarproduct , (SELECT /*+ no_index(site_product) */ DISTINCT product_id FROM site_product WHERE site_id IN" + " (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")) sp "; } if (skuTableWidgetData.isDcStocking()) { sql += " , (select product_id,MIN_STOCKING_QTY,MAX_STOCKING_QTY " + "from site_product where site_id IN ( " + "SELECT site_id FROM site WHERE site_type_code = 'DC' AND " + "product_availability_id IN (SELECT product_availability_id FROM site WHERE site_type_code <> 'DC' " + "AND site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")))) dc_sp "; } // Fleets Filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += ", SESSION_SITE_FLEET_PRODUCTS_V flt "; } sql += " where ssp.session_id = " + skuTableWidgetData.getSessionId() + " and ssp.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " ) " + "and ssp.product_id=p.product_id "; sql += " and ssp.product_id=L.product_id(+) and ssp.site_id=L.site_id(+) "; if (dcCount != null) { sql += " and ssp.product_id=pdc.product_id(+) "; } if (!site_type) { sql += " and ssp.site_id=dcSite.siteId(+)" + " and dcSite.dc_id=pdc.site_id(+) "; } // Hide system followers filter if (skuTableWidgetData.isHideSystemFollowers()) { sql += " and nvl(ssp.system_recommended, 'N') = 'N' "; } // New Number filter if (skuTableWidgetData.isNewNumber()) { sql += " and ssp.reason_id = 8 "; } //Min Max Set To Zero I8 filter if (skuTableWidgetData.isMinMaxSetZeroI8()) { sql += " and ssp.i8_check ='Y' "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ssp.site_id=s.site_id "; } // expensiveItem if (skuTableWidgetData.isExpensiveItem()) { sql += " and ORDER_QTY*PRICE_WT_CORE > 500 "; } // largeOrderQty if (skuTableWidgetData.isLargeOrderQty()) { sql += " and ( ORDER_QTY > STD_PKG and ORDER_QTY > (PER_CAR * 2) ) "; } // Lost Sales if (skuTableWidgetData.isSoldNotStocked()) { sql += " and sp.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " ) " + "and ssp.SITE_ID=sp.SITE_ID and SSP.LEVEL4_PARENT_ID=sp.HIERARCHY_ID and sp.SITE_ID=s.SITE_ID " + " and (ssp.effective_pts = 230 and ssp.RECOMMENDED_ORDER_QTY > 0) "; } //PUL-7923 Stocked and Non Stocked if (skuTableWidgetData.isDcStocking() && ("stockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.max_stocking_qty, 0) > 0 ) "; } else if (skuTableWidgetData.isDcStocking() && ("nonstockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.min_stocking_qty, 0) = 0 ) "; } // obsolete filter if (skuTableWidgetData.isObsoleteSkus()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.CLASS = 'O' "; } // App / Non-App Filter if (skuTableWidgetData.isAppNonApp()) { if (("nonApplication").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NULL "; else if (("application").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NOT NULL "; } // Reviewed if (skuTableWidgetData.getIsReviewed() != null && skuTableWidgetData.getIsReviewed()) { sql += " and ssp.REVIEWED=1 "; } else if (skuTableWidgetData.getIsReviewed() != null && !skuTableWidgetData.getIsReviewed()) { sql += " and NVL(ssp.REVIEWED, 0) = 0 "; } // fleets filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " AND ssp.session_id = flt.session_id AND ssp.site_id = flt.site_id AND ssp.product_id = flt.product_id and flt.fleet_id in (" + java.util.Arrays.toString(skuTableWidgetData.getFleetGroupIdsArray()).replace("[", "") .replace("]", "") + ") and EFFECTIVE_PTS=500 "; // EFFECTIVE_PTS=500 } // TODO: I think this was added sometime back in anticipation for fleets and is // no longer relevant // Fleet parts filter // if (skuTableWidgetData.isFleets()) { // sql += " and ssp.EFFECTIVE_PTS=" + EPTSRules.FLEET.value() + " "; // } // Display Flag filter if (skuTableWidgetData.isDisplayFlag()) { sql += " and ssp.DISPLAY_QTY > 0 "; } // Keep Flag filter if (skuTableWidgetData.isKeepFlag()) { sql += " and ssp.KEEP_FLAG ='Y' "; } //Similar Parts filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and (similarproduct.coverage > 0 OR sim.order_qty > 0)" + " and sim.product_id = ssp.product_id and (ssp.RECOMMENDED_ORDER_QTY > 0 or ssp.MIN_STOCKING_QTY > 0) "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and similarproduct.coverage = 0 and NVL(ssp.MIN_STOCKING_QTY, 0) = 0 "; else sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID AND similarproduct.similar_product_id = sp.product_id "; } //Block Order Suggestions if (skuTableWidgetData.isBlockOrderSuggestion()) { sql += " and ssp.product_id in (SELECT product_id from PRODUCT_OVERRIDE WHERE OVERRIDE_ID = 2 AND IS_ACTIVE = 1 " + "AND SITE_ID IN (SELECT SITE_ID FROM SESSION_SITE WHERE SESSION_ID = " + skuTableWidgetData.getSessionId() + ")) "; } // LOW VEHICLE COUNT filter -- PUL -7328 - Removed 'and ssp.recommended_order_qty > 0' if (skuTableWidgetData.getLowVehicleCount() != null) { if (skuTableWidgetData.getLowVehicleOperator() != null && (skuTableWidgetData.getLowVehicleOperator().trim().equals("<") || skuTableWidgetData.getLowVehicleOperator().trim().equals(">"))) { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) " + skuTableWidgetData.getLowVehicleOperator().trim() + " " + skuTableWidgetData.getLowVehicleCount() + " AND p.top_app IS NOT NULL "; } else { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) < " + skuTableWidgetData.getLowVehicleCount() + " AND p.top_app IS NOT NULL "; } sql += " "; } // Supersedes filter if (skuTableWidgetData.isSupersedes()) { sql += " and ssp.product_id in (select SURVIVING_PRODUCT_ID from SUPERSEDE_PRODUCT where SURVIVING_PRODUCT_ID=ssp.product_id ) "; } // Specials filter if (skuTableWidgetData.isSpecials()) { sql += " and ssp.reason_id = 3 "; } // Other filter if (skuTableWidgetData.isOther()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.INITIAL_STOCKING_DT is null and ssp.class != 'O' "; } // Overstock Filter if (skuTableWidgetData.isOverstock()) { sql += " and ssp.recommended_return_qty > 0 AND ssp.recommended_return_qty < ssp.on_hand "; } // 24 and Out filter if (skuTableWidgetData.isTwentyFourAndOut()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and (ssp.RETURN_QTY = ssp.ON_HAND) and ssp.MIN_STOCKING_QTY>0 and ssp.INITIAL_STOCKING_DT is not null and ssp.class != 'O' "; } // Systems filter if (skuTableWidgetData.isSystem()) { sql += " and nvl(ssp.system_recommended, 'N') = 'Y' and (ssp.ORDER_QTY > 0 OR ssp.RECOMMENDED_ORDER_QTY > 0) "; } // Orders and Returns filters String orderFilter = ""; if (("recommended").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "ssp.ORDER_QTY > 0"; } else if (("declined").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY <> 0 and ssp.ORDER_QTY = 0)"; } String returnFilter = ""; if (("recommended").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RETURN_QTY = ssp.RECOMMENDED_RETURN_QTY and ssp.RETURN_QTY > 0)"; } else if (("declined").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY <> 0 and ssp.RETURN_QTY = 0)"; } if (skuTableWidgetData.isReturn() && skuTableWidgetData.isOrder() && isNotBlank(orderFilter) && isNotBlank(returnFilter)) { sql += " and (" + orderFilter + " OR " + returnFilter + ") "; } else if (skuTableWidgetData.isReturn() && isNotBlank(returnFilter)) { sql += " and " + returnFilter; } else if (skuTableWidgetData.isOrder() && isNotBlank(orderFilter)) { sql += " and " + orderFilter; } //String storeInvFilter = ""; if (skuTableWidgetData.isStoreInventory() == true && isNotEmpty(skuTableWidgetData.getSelectedStoreInventoryOption())) { if (("allStockedOnhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onandwithnoMinMax").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0 AND (NVL(ssp.MIN_STOCKING_QTY, 0) = 0 OR NVL(ssp.max_stocking_qty, 0) = 0)"; } else if (("grt0min").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } else if (("grt0min0withnoOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) = 0"; } else if (("grt0excludeOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0excludeMin").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } /* On Hand > 0 ----- ssp.on_hand > 0 On Hand > 0 with no Min Max --- ssp.on_hand > 0 and min_stocking_qty & max_stocking_qty = null Min > 0 ---- ssp.min_stocking_qty > 0 Min > 0 with no On Hand ----- ssp.min_stocking_qty > 0 and ssp.on_hand = null Exclude On Hand > 0 ----- ! ssp.on_hand >0 Exclude Min > 0 ----- !ssp.min_stocking_qty > 0*/ } // Hub & Spoke Filter //viewData if (("hubOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'H' "; } else if (("spokeOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'S' "; } else if (("HSOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NOT NULL "; } else if (("hideHS").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NULL "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ((ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0) " + "or (ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 and s.SITE_TYPE_CODE='DC' and ssp.EFFECTIVE_PTS > 0.25 )) "; } // filter by hierarchy if (skuTableWidgetData.getHierarchyId() > 0) { sql += " and ssp.LEVEL4_PARENT_ID in (select HIERARCHY_ID from product_hierarchy where HIERARCHY_LEVEL=4 " + "start with HIERARCHY_ID = " + skuTableWidgetData.getHierarchyId() + " connect by prior HIERARCHY_ID = PARENT_ID) "; } //FirstStockDate Filter if (isNotEmpty(skuTableWidgetData.getFirstStockToDt()) && isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt between '" + skuTableWidgetData.getFirstStockFromDt() + "' and '" + skuTableWidgetData.getFirstStockToDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt >= '" + skuTableWidgetData.getFirstStockFromDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockToDt())) { sql += " and ssp.initial_stocking_dt <='" + skuTableWidgetData.getFirstStockToDt() + "' "; } if (skuTableWidgetData.getHighSkuEditHierarchyId() != null) { sql += " and ssp.LEVEL4_PARENT_ID = " + skuTableWidgetData.getHighSkuEditHierarchyId() + " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } //dcSales Filter if (skuTableWidgetData.getDcSalesMonth() != null) { //dcSales 12 Filter if (skuTableWidgetData.getDcSalesMonth() == 12) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_12_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_12_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_12_months >= " + skuTableWidgetData.getDcSalesMin(); } } //DcSales 24 Filter if (skuTableWidgetData.getDcSalesMonth() == 24) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_24_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_24_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_24_months >= " + skuTableWidgetData.getDcSalesMin(); } } } //*dcSales Filter if (skuTableWidgetData.getDcWideSalesMonth() != null) { //*dcSales 12 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 12) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_12_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_12_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_12_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } //*DcSales 24 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 24) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_24_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_24_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = dcSite.dc_id " + " and nvl(sp.SALES_LAST_24_MONTHS ,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } } //hub demand Filter if (skuTableWidgetData.getHubDemandMonth() != null && user.getAccessItemIds().contains(159)) { //hub demand 12 Filter if (skuTableWidgetData.getHubDemandMonth() == 12) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } //hub demand 24 Filter if (skuTableWidgetData.getHubDemandMonth() == 24) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } } // HubSiteCountData if ((skuTableWidgetData.getHubSiteCountMin ( ) != null || skuTableWidgetData.getHubSiteCountMax ( ) != null) && user.getAccessItemIds().contains(160) ) { if (( null == skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ()) && (null==skuTableWidgetData.getHubSiteCountMax ()|| 0==skuTableWidgetData.getHubSiteCountMax ( )) ) { sql += " and not exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + ")"; // " and nvl(CNT_MIN_GTR_0,0) BETWEEN " //+ skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null==skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ( )) && (null!=skuTableWidgetData.getHubSiteCountMax () && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and ( exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) <= " + skuTableWidgetData.getHubSiteCountMax() + ") OR" + " not exists (select product_id from network_product where network_id in ( " + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss " + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1 " + " )" + " and ssp.product_id=product_id )) "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null==skuTableWidgetData.getHubSiteCountMax ( ) || 0==skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) >= " + skuTableWidgetData.getHubSiteCountMin() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) || 0!=skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() && 0!=skuTableWidgetData.getHubSiteCountMin()) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } } if (skuTableWidgetData.getHighSkuEdit() != null) { sql += " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } // Line Abbr filter if (isNotEmpty(skuTableWidgetData.getLineAbbr())) { sql += " and P.FIELD_ABBR IN ( " + skuTableWidgetData.getLineAbbr() + ")"; } // Group Code if (skuTableWidgetData.getGroupCode() >= 0) { sql += " and P.GROUP_CODE = " + skuTableWidgetData.getGroupCode() + " "; } // Avg Age filter if (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null) { sql += " and p.AVG_AGE between " + skuTableWidgetData.getAvgAgeMin() + " and " + skuTableWidgetData.getAvgAgeMax() + " "; } // Part Number filter if (isNotEmpty(skuTableWidgetData.getPartNumber())) { String partNumber = skuTableWidgetData.getPartNumber().toUpperCase().replaceAll("[^A-Z0-9]+", ""); if (partNumber.length() > 0) { sql += " and P.PART_NUMBER = '" + partNumber + "'"; } } // Site filter if (skuTableWidgetData.getSiteIdsArray() != null && skuTableWidgetData.getSiteIdsArray().length > 0) { sql += " and ssp.site_id in (" + String.join(",", Arrays.asList(skuTableWidgetData.getSiteIdsArray()) .stream().map(Object::toString).collect(Collectors.toList())) + ") "; } //SalesPotential Filter if(user.getAccessItemIds().contains(128)){ if (skuTableWidgetData.getPtsMin() != null && skuTableWidgetData.getPtsMax() != null && skuTableWidgetData.getPtsMax() >= skuTableWidgetData.getPtsMin()) { sql += " and nvl(ROUND(ssp.PTS*100),0) >= " + skuTableWidgetData.getPtsMin() + " and nvl(round(ssp.PTS*100),0) <= " + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMax() !=null && skuTableWidgetData.getPtsMin() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) <=" + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMin() !=null && skuTableWidgetData.getPtsMax() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) >=" +skuTableWidgetData.getPtsMin(); }} //SalesOccurr Filter if (skuTableWidgetData.getSalesOccurrMonth() != null) { //SalesOccurr 12 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 12) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_12_months, 0) + NVL(ssp.HSN_lost_sales_12_months, 0) + NVL(SSP.HSN_SUPERSEDE_12_MONTHS,0) ELSE" + " NVL(ssp.occurance_12_months, 0) + NVL(ssp.lost_sales_12_months, 0) + NVL(SSP.SUPERSEDE_12_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } //SalesOccurr 24 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 24) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_24_months, 0) + NVL(ssp.HSN_lost_sales_24_months, 0) + NVL(SSP.HSN_SUPERSEDE_24_MONTHS,0) ELSE" + " NVL(ssp.occurance_24_months, 0) + NVL(ssp.lost_sales_24_months, 0) + NVL(SSP.SUPERSEDE_24_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } } //DCR_PTS Filter if (skuTableWidgetData.getDcrPtsMin() != null && skuTableWidgetData.getDcrPtsMax() != null) { sql += " and ssp.DCR_PTS >= " + skuTableWidgetData.getDcrPtsMin() + " and ssp.DCR_PTS <= " + skuTableWidgetData.getDcrPtsMax(); } if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin() + " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } else if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() == null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin(); } else if (skuTableWidgetData.getCostMin() == null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } sql += " group by P.PRODUCT_ID, (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER), " + (("en".equals(user.getLanguage()) || user.getLanguage() == null) ? "P.PRODUCT_DESC, " : "P.PRODUCT_DESC_FR, ") + " P.PER_CAR, P.INTRO_DT, P.TOP_APP, P.JBR_STD_PKG, P.AVG_AGE, P.GROUP_CODE, " + "P.NATIONAL_VIO, P.NATIONAL_SALES_12, P.NATIONAL_SALES_24, NVL(REVIEWED,0), P.PRODUCT_CUBIC )"; sql += " WHERE RN BETWEEN " +startRowNumber+ " AND " +endRowNumber+ " ORDER BY RN "; long start = System.currentTimeMillis(); skuTableData = jdbcTemplate.queryForList(sql); System.out.println("Review" +sql); LOGGER.debug("getSKUTableData request for sessionId " + skuTableWidgetData.getSessionId() + " took: " + (System.currentTimeMillis() - start)); return skuTableData; } catch (Exception e) { LOGGER.error("Exception message is: " + e.getMessage()); LOGGER.error("Exception stacktrace is: " + e.getStackTrace()); result.setMessage("Cannot Update SKU details table data"); result.setSuccess(Boolean.FALSE); Map map = new HashMap<>(); map.put("message", "Exception is in SKU details " + e.getMessage()); map.put("success", Boolean.FALSE); List> jsonList = new ArrayList<>(); jsonList.add(map); return jsonList; } } /* * (non-Javadoc) * * @see com.napa.pulse.dao.interfaces.ReviewDAO#getSKUTableDataCount(int) */ @Override public List> getSKUTableDataCount ( SKUTableWidgetData skuTableWidgetData, User user ) { boolean isFinalized = isSessionFinalized(skuTableWidgetData.getSessionId()); String sql = " SELECT distinct P.PRODUCT_ID AS \"productId\" " + " FROM ( select * from" + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " where session_id = "+skuTableWidgetData.getSessionId ()+" ) SSP, PRODUCT P "; // lost sales filter if (skuTableWidgetData.isSoldNotStocked()) { sql += " , SITE_PARAMETER SP, Site s "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " , Site s "; } // Similar Parts Filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (select distinct sp_.product_id, (sp_.SIMILAR_PRODUCT_ID) similar_product_id, order_qty from SESSION_SITE_PRODUCT ssp_, SIMILAR_PRODUCT sp_" + " where ssp_.SESSION_ID = " + skuTableWidgetData.getSessionId() + " and ssp_.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " )" + " and sp_.similar_PRODUCT_ID = ssp_.PRODUCT_ID) sim " + " , (SELECT DISTINCT sp.product_id, sim.similar_product_id," + " SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (SELECT DISTINCT sp.product_id, SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else sql += " , SIMILAR_PRODUCT similarproduct , (SELECT DISTINCT product_id FROM site_product WHERE site_id IN" + " (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")) sp "; } if (skuTableWidgetData.isDcStocking()) { sql += " , (select product_id,MIN_STOCKING_QTY,MAX_STOCKING_QTY " + "from site_product where site_id IN ( " + "SELECT site_id FROM site WHERE site_type_code = 'DC' AND " + "product_availability_id IN (SELECT product_availability_id FROM site WHERE site_type_code <> 'DC' " + "AND site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")))) dc_sp "; } // Fleets Filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += ", SESSION_SITE_FLEET_PRODUCTS_V flt "; } sql += " WHERE SSP.PRODUCT_ID=p.PRODUCT_ID "; // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ssp.site_id=s.site_id "; } //Min Max Set To Zero I8 filter if (skuTableWidgetData.isMinMaxSetZeroI8()) { sql += " and ssp.i8_check ='Y' "; } // Hide system followers filter if (skuTableWidgetData.isHideSystemFollowers()) { sql += " and nvl(ssp.system_recommended, 'N') = 'N' "; } if (skuTableWidgetData.isBlockOrderSuggestion()) { sql += " and ssp.product_id in (SELECT product_id from PRODUCT_OVERRIDE WHERE OVERRIDE_ID = 2 AND IS_ACTIVE = 1 " + "AND SITE_ID IN (SELECT SITE_ID FROM SESSION_SITE WHERE SESSION_ID =" + skuTableWidgetData.getSessionId() + ")) "; } // New Number filter if (skuTableWidgetData.isNewNumber()) { sql += " and ssp.reason_id = 8 "; } // expensiveItem if (skuTableWidgetData.isExpensiveItem()) { sql += " and ORDER_QTY*PRICE_WT_CORE > 500 "; } // Reviewed if (skuTableWidgetData.getIsReviewed() != null && skuTableWidgetData.getIsReviewed()) { sql += " and ssp.REVIEWED=1 "; } else if (skuTableWidgetData.getIsReviewed() != null && !skuTableWidgetData.getIsReviewed()) { sql += " and NVL(ssp.REVIEWED, 0) = 0 "; } // largeOrderQty if (skuTableWidgetData.isLargeOrderQty()) { sql += " and ( ORDER_QTY > STD_PKG and ORDER_QTY > (PER_CAR * 2) ) "; } // Lost Sales Filter if (skuTableWidgetData.isSoldNotStocked()) { sql += " and sp.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " ) " + "and ssp.SITE_ID=sp.SITE_ID and SSP.LEVEL4_PARENT_ID=sp.HIERARCHY_ID and sp.SITE_ID=s.SITE_ID " + " and (ssp.effective_pts = 230 and ssp.RECOMMENDED_ORDER_QTY > 0) "; } //PUL-7923 Stocked and Non Stocked if (skuTableWidgetData.isDcStocking() && ("stockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.max_stocking_qty, 0) > 0 ) "; } else if (skuTableWidgetData.isDcStocking() && ("nonstockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.min_stocking_qty, 0) = 0 ) "; } // obsolete filter if (skuTableWidgetData.isObsoleteSkus()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.CLASS = 'O' "; } // App / Non-App Filter if (skuTableWidgetData.isAppNonApp()) { if (("nonApplication").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NULL "; else if (("application").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NOT NULL "; } // fleets filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " AND ssp.session_id = flt.session_id AND ssp.site_id = flt.site_id AND ssp.product_id = flt.product_id and flt.fleet_id in (" + java.util.Arrays.toString(skuTableWidgetData.getFleetGroupIdsArray()).replace("[", "") .replace("]", "") + ") and EFFECTIVE_PTS=500 "; } // Display Flag filter if (skuTableWidgetData.isDisplayFlag()) { sql += " and ssp.DISPLAY_QTY > 0 "; } // Keep Flag filter if (skuTableWidgetData.isKeepFlag()) { sql += " and ssp.KEEP_FLAG ='Y' "; } //Similar Parts filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and (similarproduct.coverage > 0 OR sim.order_qty > 0)" + " and sim.product_id = ssp.product_id and (ssp.RECOMMENDED_ORDER_QTY > 0 or ssp.MIN_STOCKING_QTY > 0) "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and similarproduct.coverage = 0 and NVL(ssp.MIN_STOCKING_QTY, 0) = 0 "; else sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID AND similarproduct.similar_product_id = sp.product_id "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ((ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0) " + "or (ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 and s.SITE_TYPE_CODE='DC' and ssp.EFFECTIVE_PTS > 0.25 )) "; } // LOW VEHICLE COUNT filter -- PUL -7328 - Removed 'and ssp.recommended_order_qty > 0' if (skuTableWidgetData.getLowVehicleCount() != null) { if (skuTableWidgetData.getLowVehicleOperator() != null && (skuTableWidgetData.getLowVehicleOperator().trim().equals("<") || skuTableWidgetData.getLowVehicleOperator().trim().equals(">"))) { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) " + skuTableWidgetData.getLowVehicleOperator().trim() + " " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } else { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) < " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } sql += " "; } // Line Abbr filter if (isNotEmpty(skuTableWidgetData.getLineAbbr())) { sql += " and P.FIELD_ABBR IN ( " + skuTableWidgetData.getLineAbbr() + ")"; } // Group Code if (skuTableWidgetData.getGroupCode() >= 0) { sql += " and P.GROUP_CODE = " + skuTableWidgetData.getGroupCode() + " "; } // Avg Age filter if (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null) { sql += " and p.AVG_AGE between " + skuTableWidgetData.getAvgAgeMin() + " and " + skuTableWidgetData.getAvgAgeMax() + " "; } // Supersedes filter if (skuTableWidgetData.isSupersedes()) { sql += " and ssp.product_id in (select SURVIVING_PRODUCT_ID from SUPERSEDE_PRODUCT where SURVIVING_PRODUCT_ID=ssp.product_id ) "; } // Specials filter if (skuTableWidgetData.isSpecials()) { sql += " and ssp.reason_id = 3 "; } //FirstStockDate Filter if (isNotEmpty(skuTableWidgetData.getFirstStockToDt()) && isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt between '" + skuTableWidgetData.getFirstStockFromDt() + "' and '" + skuTableWidgetData.getFirstStockToDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt >= '" + skuTableWidgetData.getFirstStockFromDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockToDt())) { sql += " and ssp.initial_stocking_dt <='" + skuTableWidgetData.getFirstStockToDt() + "' "; } // Other filter if (skuTableWidgetData.isOther()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.INITIAL_STOCKING_DT is null and ssp.class != 'O' "; } // Overstock Filter if (skuTableWidgetData.isOverstock()) { sql += " and ssp.recommended_return_qty > 0 AND ssp.recommended_return_qty < ssp.on_hand "; } //dcSales Filter if (skuTableWidgetData.getDcSalesMonth() != null) { //dcSales 12 Filter if (skuTableWidgetData.getDcSalesMonth() == 12) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_12_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_12_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_12_months >= " + skuTableWidgetData.getDcSalesMin(); } } //DcSales 24 Filter if (skuTableWidgetData.getDcSalesMonth() == 24) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_24_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_24_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_24_months >= " + skuTableWidgetData.getDcSalesMin(); } } } //*dcSales Filter if (skuTableWidgetData.getDcWideSalesMonth() != null) { //*dcSales 12 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 12) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS ,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } //*DcSales 24 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 24) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } } //hub demand Filter if (skuTableWidgetData.getHubDemandMonth() != null && user.getAccessItemIds().contains(159)) { //hub demand 12 Filter if (skuTableWidgetData.getHubDemandMonth() == 12) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } //hub demand 24 Filter if (skuTableWidgetData.getHubDemandMonth() == 24) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } } // Min HubSiteCount Filter if ((skuTableWidgetData.getHubSiteCountMin ( ) != null || skuTableWidgetData.getHubSiteCountMax ( ) != null) && user.getAccessItemIds().contains(160) ) { if (( null == skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ()) && (null==skuTableWidgetData.getHubSiteCountMax ()|| 0==skuTableWidgetData.getHubSiteCountMax ( )) ) { sql += " and not exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + ")"; //" and nvl(CNT_MIN_GTR_0,0) BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null==skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ( )) && (null!=skuTableWidgetData.getHubSiteCountMax () && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and ( exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) <= " + skuTableWidgetData.getHubSiteCountMax() + ") OR" + " not exists (select product_id from network_product where network_id in ( " + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss " + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1 " + " )" + " and ssp.product_id=product_id )) "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null==skuTableWidgetData.getHubSiteCountMax ( ) || 0==skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) >= " + skuTableWidgetData.getHubSiteCountMin() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) || 0!=skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() && 0!=skuTableWidgetData.getHubSiteCountMin()) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } } // 24 and Out filter if (skuTableWidgetData.isTwentyFourAndOut()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.MIN_STOCKING_QTY>0 and ssp.INITIAL_STOCKING_DT is not null and ssp.class != 'O' "; } // Systems filter if (skuTableWidgetData.isSystem()) { sql += " and nvl(ssp.system_recommended, 'N') = 'Y' and (ssp.ORDER_QTY > 0 OR ssp.RECOMMENDED_ORDER_QTY > 0) "; } //SalesPotential Filter if(user.getAccessItemIds().contains(128)){ if (skuTableWidgetData.getPtsMin() != null && skuTableWidgetData.getPtsMax() != null && skuTableWidgetData.getPtsMax() >= skuTableWidgetData.getPtsMin()) { sql += " and nvl(ROUND(ssp.PTS*100),0) >= " + skuTableWidgetData.getPtsMin() + " and nvl(round(ssp.PTS*100),0) <= " + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMax() !=null && skuTableWidgetData.getPtsMin() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) <=" + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMin() !=null && skuTableWidgetData.getPtsMax() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) >=" +skuTableWidgetData.getPtsMin(); }} //SalesOccurr Filter if (skuTableWidgetData.getSalesOccurrMonth() != null) { //SalesOccurr 12 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 12) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_12_months, 0) + NVL(ssp.HSN_lost_sales_12_months, 0) + NVL(SSP.HSN_SUPERSEDE_12_MONTHS,0) ELSE" + " NVL(ssp.occurance_12_months, 0) + NVL(ssp.lost_sales_12_months, 0) + NVL(SSP.SUPERSEDE_12_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } //SalesOccurr 24 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 24) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_24_months, 0) + NVL(ssp.HSN_lost_sales_24_months, 0) + NVL(SSP.HSN_SUPERSEDE_24_MONTHS,0) ELSE" + " NVL(ssp.occurance_24_months, 0) + NVL(ssp.lost_sales_24_months, 0) + NVL(SSP.SUPERSEDE_24_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } } //DCR_PTS Filter if (skuTableWidgetData.getDcrPtsMin() != null && skuTableWidgetData.getDcrPtsMax() != null) { sql += " and ssp.DCR_PTS >= " + skuTableWidgetData.getDcrPtsMin() + " and ssp.DCR_PTS <= " + skuTableWidgetData.getDcrPtsMax(); } if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin() + " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } else if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() == null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin(); } else if (skuTableWidgetData.getCostMin() == null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } // Orders and Returns filters String orderFilter = ""; if (("recommended").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "ssp.ORDER_QTY > 0"; } else if (("declined").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY <> 0 and ssp.ORDER_QTY = 0)"; } String returnFilter = ""; if (("recommended").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RETURN_QTY = ssp.RECOMMENDED_RETURN_QTY and ssp.RETURN_QTY > 0)"; } else if (("declined").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY <> 0 and ssp.RETURN_QTY = 0)"; } if (skuTableWidgetData.isReturn() && skuTableWidgetData.isOrder()) { sql += " and (" + orderFilter + " OR " + returnFilter + ") "; } else if (skuTableWidgetData.isReturn()) { sql += " and " + returnFilter; } else if (skuTableWidgetData.isOrder()) { sql += " and " + orderFilter; } /** StoreInventory PUL-7910*/ if (skuTableWidgetData.isStoreInventory() == true && skuTableWidgetData.getSelectedStoreInventoryOption() != null) { if (("allStockedOnhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onandwithnoMinMax").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0 AND (NVL(ssp.MIN_STOCKING_QTY, 0) = 0 OR NVL(ssp.max_stocking_qty, 0) = 0)"; } else if (("grt0min").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } else if (("grt0min0withnoOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) = 0"; } else if (("grt0excludeOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0excludeMin").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } } // Hub & Spoke Filter //viewData if (("hubOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'H' "; } else if (("spokeOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'S' "; } else if (("HSOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NOT NULL "; } else if (("hideHS").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NULL "; } // filter by hierarchy if (skuTableWidgetData.getHierarchyId() > 0) { sql += " and ssp.LEVEL4_PARENT_ID in (select HIERARCHY_ID from product_hierarchy where HIERARCHY_LEVEL=4 start " + "with HIERARCHY_ID = " + skuTableWidgetData.getHierarchyId() + " connect by prior HIERARCHY_ID = PARENT_ID) "; } if (skuTableWidgetData.getHighSkuEditHierarchyId() != null) { sql += " and ssp.LEVEL4_PARENT_ID = " + skuTableWidgetData.getHighSkuEditHierarchyId() + " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } if (skuTableWidgetData.getHighSkuEdit() != null) { sql += " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } // Part Number filter if (skuTableWidgetData.getPartNumber() != null) { String partNumber = skuTableWidgetData.getPartNumber().toUpperCase().replaceAll("[^A-Z0-9]+", ""); if (partNumber.length() > 0) { sql += " and P.PART_NUMBER = '" + partNumber + "'"; } } // Site filter if (skuTableWidgetData.getSiteIdsArray() != null && skuTableWidgetData.getSiteIdsArray().length > 0) { sql += " and ssp.site_id in (" + String.join(",", Arrays.asList(skuTableWidgetData.getSiteIdsArray()) .stream().map(Object::toString).collect(Collectors.toList())) + ") "; } long start = System.currentTimeMillis(); List> productIds; productIds = jdbcTemplate.queryForList(sql); LOGGER.debug("getSKUTableDataCount request for sessionId " + skuTableWidgetData.getSessionId() + " took: " + (System.currentTimeMillis() - start)); List> result = new ArrayList<>(); Map count = new HashMap<>(); count.put("count", productIds.size()); result.add(count); Map productIdMap = new HashMap<>(); productIdMap.put("allProductIds", productIds.stream().map(x -> Integer.parseInt(x.get("productId").toString())).collect(Collectors.toList())); result.add(productIdMap); return result; } public boolean reviewBulkEdit ( SKUTableWidgetData skuTableWidgetData,User user) { try { long start = System.currentTimeMillis(); //getProductIdsAsCommaSeparated(skuTableWidgetData.getBulkEditProductIds(), 990).parallelStream().forEach(productIds -> bulkEditSql(skuTableWidgetData, productIds)); SqlRowSet rs; String productIds=skuTableWidgetData.getBulkEditProductIds().stream().map(Object::toString).collect(Collectors.joining(",")); bulkEditSql(skuTableWidgetData, productIds,user); // call is made to the procedure to recalculate the totals. rs = jdbcTemplate.queryForRowSet("select site_id from session_site where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { sessionDAO.reCalculateSessionTotals(skuTableWidgetData.getSessionId(), rs.getInt("site_id")); } // calling this again to calculate UIC After column rs = jdbcTemplate.queryForRowSet("select site_id from session_site where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { sessionDAO.reCalculateSessionTotals(skuTableWidgetData.getSessionId(), rs.getInt("site_id")); } LOGGER.info("Bulk edit completed in {} ms", System.currentTimeMillis() - start); return true; } catch (Exception e) { LOGGER.error("error processing reviewBulkEdit: ", e); return false; } } public boolean reviewBulkEditOld ( SKUTableWidgetData skuTableWidgetData,User user ) { /* * 1. returnAll (R) shall set the Keep quantity back to the recommended Keep * quantity and Return quantity back to On hand – Keep, only if the SKU was * originally recommended for return. * * 2. keepAll (S) shall set the Keep quantity to On hand and Return quantity to * On hand - Keep (this is taken care in DB table as Return = On Hand - Keep) * * 3. orderNone (N) shall set the Order quantity to zero. * * 4. orderAll (O) shall set the Order quantity to Suggested Stocking * quantity(initial_stock_amount in DB) * * 5. revertAll will revert all keeps and orders to recommended * * 6. In case of "special orders" that need to be returned, if user clicks a * Return pin, it will automatically switch part to Stocked. * */ try { int perCarOrder = 0; int storeDepth = 0; SqlRowSet rs = jdbcTemplate.queryForRowSet( "select PER_CAR_ORDER, PROVIDE_STORE_DEPTH " + "from pulse_session where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { perCarOrder = Integer.parseInt(rs.getString("PER_CAR_ORDER")); storeDepth = Integer.parseInt(rs.getString("PROVIDE_STORE_DEPTH")); } String sql = "merge into SESSION_SITE_PRODUCT SSP using ( "; sql += " SELECT distinct(ssp.product_id) as product_id, ssp.session_id, ssp.site_id "; if (storeDepth == 1) { sql += ", PRODUCT_DEPTH_QTY "; } if (perCarOrder == 1) { sql += ", PER_CAR "; } sql += "FROM SESSION_SITE_PRODUCT SSP " ; if (skuTableWidgetData.isAppNonApp()||perCarOrder==1||skuTableWidgetData.getLowVehicleCount() != null ||skuTableWidgetData.getLineAbbr() != null||skuTableWidgetData.getGroupCode() >= 0|| (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null)||skuTableWidgetData.getPartNumber() != null) { sql += "inner join PRODUCT P on SSP.PRODUCT_ID=p.PRODUCT_ID "; } // PROVIDE_STORE_DEPTH if (storeDepth == 1) { sql += " inner join site s on ssp.site_id=s.site_id " + "left join DC_PRODUCT_DEPTH pd on pd.dc_id=s.PRODUCT_AVAILABILITY_ID and ssp.product_id=pd.product_id "; } // lost sales filter if (skuTableWidgetData.isSoldNotStocked()) { sql += "inner join SITE_PARAMETER SP on ssp.SITE_ID=sp.SITE_ID and SSP.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + "inner join Site s on sp.SITE_ID=s.SITE_ID "; } //Similar Parts filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) { sql += " inner join (select distinct sp_.product_id, (sp_.SIMILAR_PRODUCT_ID) similar_product_id, order_qty from SESSION_SITE_PRODUCT ssp_, SIMILAR_PRODUCT sp_" + " where ssp_.SESSION_ID = " + skuTableWidgetData.getSessionId() + " and ssp_.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " )" + " and sp_.similar_PRODUCT_ID = ssp_.PRODUCT_ID) sim " + " on sim.product_id = ssp.product_id"; sql += " inner join (SELECT DISTINCT sp.product_id, sim.similar_product_id," + " SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct " + " on similarproduct.PRODUCT_ID = ssp.PRODUCT_ID "; sql += " and (similarproduct.coverage > 0 OR sim.order_qty > 0) and (ssp.RECOMMENDED_ORDER_QTY > 0 or ssp.MIN_STOCKING_QTY > 0) "; } else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " inner join (SELECT DISTINCT sp.product_id, SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM session_site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.session_id= "+skuTableWidgetData.getSessionId() + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct" + " on similarProduct.PRODUCT_ID = ssp.PRODUCT_ID and similarproduct.coverage = 0 and NVL(ssp.MIN_STOCKING_QTY, 0) = 0 "; else sql += " inner join SIMILAR_PRODUCT similarproduct on similarproduct.PRODUCT_ID = ssp.PRODUCT_ID " + " inner join (SELECT DISTINCT product_id FROM site_product WHERE site_id IN (SELECT site_id FROM session_site WHERE" + " session_id = " + skuTableWidgetData.getSessionId() + ") ) sp on similarproduct.similar_product_id = sp.product_id "; } if (skuTableWidgetData.isDcStocking()) { sql += "left join (SELECT DISTINCT d.product_id, d.min_stocking_qty, d.max_stocking_qty " + " FROM session_site a, site b, site c, site_product d " + " WHERE a.session_id = " + skuTableWidgetData.getSessionId() + " AND a.site_id = b.site_id" + " AND b.site_type_code <> 'DC' " + " AND b.product_availability_id = c.product_availability_id " + " AND c.site_type_code = 'DC' " + " AND c.site_id = d.site_id) dc_sp " + " ON ssp.product_id = dc_sp.product_id "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " inner join Site s on ssp.site_id=s.site_id "; } // Fleets Filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " inner join SESSION_SITE_FLEET_PRODUCTS_V flt on ssp.session_id = flt.session_id AND ssp.site_id = flt.site_id AND ssp.product_id = flt.product_id"; } sql += " WHERE ssp.SESSION_ID = :sessionId "; if ("returnAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_return is null and ssp.lt_std_pkg = 0 "; } else if ("keepAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_return is null AND ssp.CLASS <> 'O' and lt_std_pkg = 0 "; } else if ("revertAll".equals(skuTableWidgetData.getAction())) { sql += " and DECLINE_ORDER=0 and DECLINE_RETURN=0 "; } else if ("orderAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_order is null AND ssp.CLASS <> 'O' and nvl(ssp.MIN_STOCKING_QTY,0) <= 0 "; } //StoreInventory PUL-7910 if (skuTableWidgetData.isStoreInventory() == true && skuTableWidgetData.getSelectedStoreInventoryOption() != null) { if (("allStockedOnhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onandwithnoMinMax").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0 AND (NVL(ssp.MIN_STOCKING_QTY, 0) = 0 OR NVL(ssp.max_stocking_qty, 0) = 0)"; } else if (("grt0min").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } else if (("grt0min0withnoOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) = 0"; } else if (("grt0excludeOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0excludeMin").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } } //Min Max Set To Zero I8 filter if (skuTableWidgetData.isMinMaxSetZeroI8()) { sql += " and ssp.i8_check ='Y' "; } // Lost Sales Filter if (skuTableWidgetData.isSoldNotStocked()) { sql += " and (ssp.effective_pts = 230 and ssp.RECOMMENDED_ORDER_QTY > 0) "; } // Hide system followers filter if (skuTableWidgetData.isHideSystemFollowers()) { sql += " and nvl(ssp.system_recommended, 'N') = 'N' "; } // New Number filter if (skuTableWidgetData.isNewNumber()) { sql += " and ssp.reason_id = 8 "; } // expensiveItem if (skuTableWidgetData.isExpensiveItem()) { sql += " and ORDER_QTY*PRICE_WT_CORE > 500 "; } //FirstStockDate Filter if (skuTableWidgetData.getFirstStockToDt() != null && skuTableWidgetData.getFirstStockFromDt() != null) { sql += " and ssp.initial_stocking_dt between '" + skuTableWidgetData.getFirstStockFromDt() + "' and '" + skuTableWidgetData.getFirstStockToDt() + "' "; } else if (skuTableWidgetData.getFirstStockFromDt() != null) { sql += " and ssp.initial_stocking_dt >= '" + skuTableWidgetData.getFirstStockFromDt() + "' "; } else if (skuTableWidgetData.getFirstStockToDt() != null) { sql += " and ssp.initial_stocking_dt <='" + skuTableWidgetData.getFirstStockToDt() + "' "; } // Reviewed if (skuTableWidgetData.getIsReviewed() != null && skuTableWidgetData.getIsReviewed()) { sql += " and ssp.REVIEWED=1 "; } else if (skuTableWidgetData.getIsReviewed() != null && !skuTableWidgetData.getIsReviewed()) { sql += " and NVL(ssp.REVIEWED, 0) = 0 "; } if (skuTableWidgetData.isDcStocking() && ("stockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and NVL(dc_sp.max_stocking_qty, 0) > 0 "; } else if (skuTableWidgetData.isDcStocking() && ("nonstockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and NVL(dc_sp.min_stocking_qty, 0) = 0 "; } // largeOrderQty if (skuTableWidgetData.isLargeOrderQty()) { sql += " and ( ORDER_QTY > STD_PKG and ORDER_QTY > (PER_CAR * 2) ) "; } //dcSales Filter if (skuTableWidgetData.getDcSalesMonth() != null) { //dcSales 12 Filter if (skuTableWidgetData.getDcSalesMonth() == 12) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_12_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_12_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_12_months >= " + skuTableWidgetData.getDcSalesMin(); } } //DcSales 24 Filter if (skuTableWidgetData.getDcSalesMonth() == 24) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_24_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_24_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_24_months >= " + skuTableWidgetData.getDcSalesMin(); } } } //*dcSales Filter if (skuTableWidgetData.getDcWideSalesMonth() != null) { //*dcSales 12 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 12) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } //*DcSales 24 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 24) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } } //hub demand Filter if (skuTableWidgetData.getHubDemandMonth() != null && user.getAccessItemIds().contains(159)) { //hub demand 12 Filter if (skuTableWidgetData.getHubDemandMonth() == 12) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } //hub demand 24 Filter if (skuTableWidgetData.getHubDemandMonth() == 24) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } } // HubSiteCountData if ((skuTableWidgetData.getHubSiteCountMin ( ) != null || skuTableWidgetData.getHubSiteCountMax ( ) != null) && user.getAccessItemIds().contains(160) ) { if (( null == skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ()) && (null==skuTableWidgetData.getHubSiteCountMax ()|| 0==skuTableWidgetData.getHubSiteCountMax ( )) ) { sql += " and not exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + ")"; } else if ((null==skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ( )) && (null!=skuTableWidgetData.getHubSiteCountMax () && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and ( exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) <= " + skuTableWidgetData.getHubSiteCountMax() + ") OR" + " not exists (select product_id from network_product where network_id in ( " + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss " + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1 " + " )" + " and ssp.product_id=product_id )) "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null==skuTableWidgetData.getHubSiteCountMax ( ) || 0==skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) >= " + skuTableWidgetData.getHubSiteCountMin() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) || 0!=skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() && 0!=skuTableWidgetData.getHubSiteCountMin()) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } } // obsolete filter if (skuTableWidgetData.isObsoleteSkus()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.CLASS = 'O' "; } // App / Non-App Filter if (skuTableWidgetData.isAppNonApp()) { if (("nonApplication").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NULL "; else if (("application").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NOT NULL "; } // fleets filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " and flt.fleet_id in (" + java.util.Arrays.toString(skuTableWidgetData.getFleetGroupIdsArray()) .replace("[", "").replace("]", "") + ") and EFFECTIVE_PTS=500 "; } // Display Flag filter if (skuTableWidgetData.isDisplayFlag()) { sql += " and ssp.DISPLAY_QTY > 0 "; } // Keep Flag filter if (skuTableWidgetData.isKeepFlag()) { sql += " and ssp.KEEP_FLAG ='Y' "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ((ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0) " + "or (ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 and s.SITE_TYPE_CODE='DC' and ssp.EFFECTIVE_PTS > 0.25 )) "; } //SalesPotential Filter if(user.getAccessItemIds().contains(128)){ if (skuTableWidgetData.getPtsMin() != null && skuTableWidgetData.getPtsMax() != null && skuTableWidgetData.getPtsMax() >= skuTableWidgetData.getPtsMin()) { sql += " and nvl(ROUND(ssp.PTS*100),0) >= " + skuTableWidgetData.getPtsMin() + " and nvl(round(ssp.PTS*100),0) <= " + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMax() !=null && skuTableWidgetData.getPtsMin() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) <=" + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMin() !=null && skuTableWidgetData.getPtsMax() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) >=" +skuTableWidgetData.getPtsMin(); }} //SalesOccurr Filter if (skuTableWidgetData.getSalesOccurrMonth() != null) { //SalesOccurr 12 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 12) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_12_months, 0) + NVL(ssp.HSN_lost_sales_12_months, 0) + NVL(SSP.HSN_SUPERSEDE_12_MONTHS,0) ELSE" + " NVL(ssp.occurance_12_months, 0) + NVL(ssp.lost_sales_12_months, 0) + NVL(SSP.SUPERSEDE_12_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } //SalesOccurr 24 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 24) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_24_months, 0) + NVL(ssp.HSN_lost_sales_24_months, 0) + NVL(SSP.HSN_SUPERSEDE_24_MONTHS,0) ELSE" + " NVL(ssp.occurance_24_months, 0) + NVL(ssp.lost_sales_24_months, 0) + NVL(SSP.SUPERSEDE_24_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } } //DCR_PTS Filter if (skuTableWidgetData.getDcrPtsMin() != null && skuTableWidgetData.getDcrPtsMax() != null) { sql += " and ssp.DCR_PTS >= " + skuTableWidgetData.getDcrPtsMin() + " and ssp.DCR_PTS <= " + skuTableWidgetData.getDcrPtsMax(); } if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin() + " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } else if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() == null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin(); } else if (skuTableWidgetData.getCostMin() == null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } // LOW VEHICLE COUNT filter -- PUL -7328 - Removed 'and ssp.recommended_order_qty > 0' // Added operator check inclusion for PUL-7508 if (skuTableWidgetData.getLowVehicleCount() != null) { if (skuTableWidgetData.getLowVehicleOperator() != null && (skuTableWidgetData.getLowVehicleOperator().trim().equals("<") || skuTableWidgetData.getLowVehicleOperator().trim().equals(">"))) { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) " + skuTableWidgetData.getLowVehicleOperator().trim() + " " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } else { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) < " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } sql += " "; } // Line Abbr filter if (isNotEmpty(skuTableWidgetData.getLineAbbr())) { sql += " and P.FIELD_ABBR IN ( " + skuTableWidgetData.getLineAbbr() + ")"; } // Group Code if (skuTableWidgetData.getGroupCode() >= 0) { sql += " and P.GROUP_CODE = " + skuTableWidgetData.getGroupCode() + " "; } // Avg Age filter if (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null) { sql += " and p.AVG_AGE between " + skuTableWidgetData.getAvgAgeMin() + " and " + skuTableWidgetData.getAvgAgeMax() + " "; } // Supersedes filter if (skuTableWidgetData.isSupersedes()) { sql += " and ssp.product_id in (select SURVIVING_PRODUCT_ID from SUPERSEDE_PRODUCT where SURVIVING_PRODUCT_ID=ssp.product_id ) "; } // Specials filter if (skuTableWidgetData.isSpecials()) { sql += " and ssp.reason_id = 3 "; } // Other filter if (skuTableWidgetData.isOther()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.INITIAL_STOCKING_DT is null and ssp.class != 'O' "; } // Overstock Filter if (skuTableWidgetData.isOverstock()) { sql += " and ssp.recommended_return_qty > 0 AND ssp.recommended_return_qty < ssp.on_hand "; } // 24 and Out filter if (skuTableWidgetData.isTwentyFourAndOut()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.MIN_STOCKING_QTY>0 and ssp.INITIAL_STOCKING_DT is not null and ssp.class != 'O' "; } // Systems filter if (skuTableWidgetData.isSystem()) { sql += " and nvl(ssp.system_recommended, 'N') = 'Y' and (ssp.ORDER_QTY > 0 OR ssp.RECOMMENDED_ORDER_QTY > 0) "; } // Orders and Returns filters String orderFilter = ""; if (("recommended").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(nvl(ssp.RECOMMENDED_ORDER_QTY,0) > 0)"; } else if (("accepted").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "ssp.ORDER_QTY > 0"; } else if (("declined").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY <> 0 and ssp.ORDER_QTY = 0)"; } String returnFilter = ""; if (("recommended").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RETURN_QTY = ssp.RECOMMENDED_RETURN_QTY and ssp.RETURN_QTY > 0)"; } else if (("declined").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY <> 0 and ssp.RETURN_QTY = 0)"; } if (skuTableWidgetData.isReturn() && skuTableWidgetData.isOrder()) { if ("orderAll".equals((skuTableWidgetData.getAction()))) sql += " and " + orderFilter; else sql += " and (" + orderFilter + " OR " + returnFilter + ") "; } else if (skuTableWidgetData.isReturn()) { if ("orderAll".equals((skuTableWidgetData.getAction())) && orderFilter.length() == 0) sql += " and (nvl(ssp.RECOMMENDED_ORDER_QTY,0) > 0) "; else sql += " and " + returnFilter; } else if (skuTableWidgetData.isOrder()) { sql += " and " + orderFilter; } // Hub & Spoke Filter //viewData if (("hubOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'H' "; } else if (("spokeOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'S' "; } else if (("HSOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NOT NULL "; } else if (("hideHS").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NULL "; } // filter by hierarchy if (skuTableWidgetData.getHierarchyId() > 0) { sql += " and ssp.LEVEL4_PARENT_ID in (select HIERARCHY_ID from product_hierarchy where HIERARCHY_LEVEL=4 start " + "with HIERARCHY_ID = " + skuTableWidgetData.getHierarchyId() + " connect by prior HIERARCHY_ID = PARENT_ID) "; } if (skuTableWidgetData.getHighSkuEditHierarchyId() != null) { sql += " and ssp.LEVEL4_PARENT_ID = " + skuTableWidgetData.getHighSkuEditHierarchyId() + " and ssp.PRODUCT_ID IN (select product_id from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } if (skuTableWidgetData.getHighSkuEdit() != null) { sql += " and ssp.PRODUCT_ID IN (select product_id from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } // Part Number filter if (isNotEmpty(skuTableWidgetData.getPartNumber())) { String partNumber = skuTableWidgetData.getPartNumber().toUpperCase().replaceAll("[^A-Z0-9]+", ""); if (partNumber.length() > 0) { sql += " and P.PART_NUMBER = '" + partNumber + "'"; } } // Site filter if (skuTableWidgetData.getSiteIdsArray() != null && skuTableWidgetData.getSiteIdsArray().length > 0) { sql += " and ssp.site_id in (" + String.join(",", Arrays.asList(skuTableWidgetData.getSiteIdsArray()) .stream().map(Object::toString).collect(Collectors.toList())) + ") "; } sql += ") A on (ssp.session_id=a.session_id and ssp.site_id=a.site_id and ssp.product_id=a.product_id) "; String declineOrderSkus = "select distinct b.hierarchy_id_l4 from decline_order_return a, hierarchy_levels b" + " where session_id =" + skuTableWidgetData.getSessionId() + " and decline_order = 1 " + "and (a.hierarchy_id = b.hierarchy_id_l4 OR a.hierarchy_id = b.hierarchy_id_l3 OR " + "a.hierarchy_id = b.hierarchy_id_l2 OR a.hierarchy_id = b.hierarchy_id_l1 ) " + "AND b.hierarchy_id_l4 IS NOT NULL "; String declineReturnSkus = "select b.hierarchy_id_l4 from decline_order_return a, hierarchy_levels b" + " where session_id =" + skuTableWidgetData.getSessionId() + " and decline_return = 1 " + "and (a.hierarchy_id = b.hierarchy_id_l4 OR a.hierarchy_id = b.hierarchy_id_l3 OR a.hierarchy_id = b.hierarchy_id_l2 OR a.hierarchy_id = b.hierarchy_id_l1 ) " + "AND b.hierarchy_id_l4 IS NOT NULL "; if ("returnAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id = :userId, keep_qty = (on_hand - RECOMMENDED_RETURN_QTY), " + "hq_keep_qty = case when :storeUser = 1 then hq_keep_qty else (on_hand - RECOMMENDED_RETURN_QTY) end " + "where not exists (select hierarchy_id_l4 from (" + declineReturnSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if ("keepAll".equals(skuTableWidgetData.getAction())) { if(skuTableWidgetData.isMinMaxSetToZero()) { sql += " WHEN MATCHED THEN UPDATE SET user_Id = :userId, ssp.keep_qty = (CASE WHEN NVL(ssp.return_qty,0) > 0 THEN on_hand ELSE ssp.keep_qty END), hq_keep_qty = (case when :storeUser = 1 then hq_keep_qty else (CASE WHEN NVL(ssp.return_qty,0) > 0 THEN on_hand ELSE hq_keep_qty END) end) " + " ,min_stocking_qty=(" + "CASE WHEN (NVL(ON_HAND,0)>NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY 0 and initial_stock_amount <= PER_CAR then PER_CAR else initial_stock_amount end), " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty " + " else (case when PER_CAR>0 and initial_stock_amount <= PER_CAR then PER_CAR else initial_stock_amount end) end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if (storeDepth == 1 && "orderAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id=:userId, " + " order_qty = (case when nvl(PRODUCT_DEPTH_QTY,0)>0 then PRODUCT_DEPTH_QTY else initial_stock_amount end), " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty else (case when nvl(PRODUCT_DEPTH_QTY,0)>0 " + " then PRODUCT_DEPTH_QTY else initial_stock_amount end) end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if ("orderAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id=:userId, " + " order_qty = initial_stock_amount, " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty " + "else initial_stock_amount end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("sessionId", skuTableWidgetData.getSessionId()); parameters.addValue("userId", skuTableWidgetData.getUser().getUserId()); parameters.addValue("storeUser", skuTableWidgetData.getUser().isStoreUser() ? 1 : 0); namedParameterJdbcTemplate.update(sql, parameters); // call is made to the procedure to recalculate the totals. rs = jdbcTemplate.queryForRowSet("select site_id from session_site where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { sessionDAO.reCalculateSessionTotals(skuTableWidgetData.getSessionId(), rs.getInt("site_id")); } // calling this again to calculate UIC After column rs = jdbcTemplate.queryForRowSet("select site_id from session_site where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { sessionDAO.reCalculateSessionTotals(skuTableWidgetData.getSessionId(), rs.getInt("site_id")); } return true; } catch (Exception e) { LOGGER.error("error processing reviewBulkEdit: ", e); return false; } } private void bulkEditSql(SKUTableWidgetData skuTableWidgetData, String productIds,User user) { /* * 1. returnAll (R) shall set the Keep quantity back to the recommended Keep * quantity and Return quantity back to On hand – Keep, only if the SKU was * originally recommended for return. * * 2. keepAll (S) shall set the Keep quantity to On hand and Return quantity to * On hand - Keep (this is taken care in DB table as Return = On Hand - Keep) * * 3. orderNone (N) shall set the Order quantity to zero. * * 4. orderAll (O) shall set the Order quantity to Suggested Stocking * quantity(initial_stock_amount in DB) * * 5. revertAll will revert all keeps and orders to recommended * * 6. In case of "special orders" that need to be returned, if user clicks a * Return pin, it will automatically switch part to Stocked. * */ try { int perCarOrder = 0; int storeDepth = 0; SqlRowSet rs = jdbcTemplate.queryForRowSet( "select PER_CAR_ORDER, PROVIDE_STORE_DEPTH " + "from pulse_session where session_id=?", skuTableWidgetData.getSessionId()); while (rs.next()) { perCarOrder = Integer.parseInt(rs.getString("PER_CAR_ORDER")); storeDepth = Integer.parseInt(rs.getString("PROVIDE_STORE_DEPTH")); } String sql = "merge into SESSION_SITE_PRODUCT SSP using ( "; sql += " SELECT distinct(ssp.product_id) as product_id, ssp.session_id, ssp.site_id "; if (storeDepth == 1) { sql += ", PRODUCT_DEPTH_QTY "; } if (perCarOrder == 1) { sql += ", PER_CAR "; } sql += "FROM SESSION_SITE_PRODUCT SSP " ; if (skuTableWidgetData.isAppNonApp()||perCarOrder==1||skuTableWidgetData.getLowVehicleCount() != null ||isNotEmpty(skuTableWidgetData.getLineAbbr())||skuTableWidgetData.getGroupCode() >= 0|| (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null)||isNotEmpty(skuTableWidgetData.getPartNumber())) { sql+= "inner join PRODUCT P on SSP.PRODUCT_ID=p.PRODUCT_ID "; } // PROVIDE_STORE_DEPTH if (storeDepth == 1) { sql += " inner join site s on ssp.site_id=s.site_id " + "left join DC_PRODUCT_DEPTH pd on pd.dc_id=s.PRODUCT_AVAILABILITY_ID and ssp.product_id=pd.product_id "; } // lost sales filter if (skuTableWidgetData.isSoldNotStocked()) { sql += "inner join SITE_PARAMETER SP on ssp.SITE_ID=sp.SITE_ID and SSP.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + "inner join Site s on sp.SITE_ID=s.SITE_ID "; } //Similar Parts filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) { sql += " inner join (select distinct sp_.product_id, (sp_.SIMILAR_PRODUCT_ID) similar_product_id, order_qty from SESSION_SITE_PRODUCT ssp_, SIMILAR_PRODUCT sp_" + " where ssp_.SESSION_ID = " + skuTableWidgetData.getSessionId() + " and ssp_.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " )" + " and sp_.similar_PRODUCT_ID = ssp_.PRODUCT_ID) sim " + " on sim.product_id = ssp.product_id"; sql += " inner join (SELECT DISTINCT sp.product_id, sim.similar_product_id," + " SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct " + " on similarproduct.PRODUCT_ID = ssp.PRODUCT_ID "; sql += " and (similarproduct.coverage > 0 OR sim.order_qty > 0) and (ssp.RECOMMENDED_ORDER_QTY > 0 or ssp.MIN_STOCKING_QTY > 0) "; } else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " inner join (SELECT DISTINCT sp.product_id, SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM site_product sp, similar_product sim, site_product sim_sp" + " WHERE sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct" + " on similarProduct.PRODUCT_ID = ssp.PRODUCT_ID and similarproduct.coverage = 0 and NVL(ssp.MIN_STOCKING_QTY, 0) = 0 "; else sql += " inner join SIMILAR_PRODUCT similarproduct on similarproduct.PRODUCT_ID = ssp.PRODUCT_ID " + " inner join (SELECT DISTINCT product_id FROM site_product WHERE site_id IN (SELECT site_id FROM session_site WHERE" + " session_id = " + skuTableWidgetData.getSessionId() + ") ) sp on similarproduct.similar_product_id = sp.product_id "; } if (skuTableWidgetData.isDcStocking()) { sql += "left join (SELECT DISTINCT d.product_id, d.min_stocking_qty, d.max_stocking_qty " + " FROM session_site a, site b, site c, site_product d " + " WHERE a.session_id = " + skuTableWidgetData.getSessionId() + " AND a.site_id = b.site_id" + " AND b.site_type_code <> 'DC' " + " AND b.product_availability_id = c.product_availability_id " + " AND c.site_type_code = 'DC' " + " AND c.site_id = d.site_id) dc_sp " + " ON ssp.product_id = dc_sp.product_id "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " inner join Site s on ssp.site_id=s.site_id "; } // Fleets Filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " inner join SESSION_SITE_FLEET_PRODUCTS_V flt on ssp.session_id = flt.session_id AND ssp.site_id = flt.site_id AND ssp.product_id = flt.product_id"; } sql += " WHERE ssp.SESSION_ID = :sessionId "; if ("returnAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_return is null and ssp.lt_std_pkg = 0 "; } else if ("keepAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_return is null AND ssp.CLASS <> 'O' and lt_std_pkg = 0 "; } else if ("revertAll".equals(skuTableWidgetData.getAction())) { sql += " and DECLINE_ORDER=0 and DECLINE_RETURN=0 "; } else if ("orderAll".equals(skuTableWidgetData.getAction())) { sql += " and ssp.block_order is null AND ssp.CLASS <> 'O' and nvl(ssp.MIN_STOCKING_QTY,0) <= 0 "; } //StoreInventory PUL-7910 if (skuTableWidgetData.isStoreInventory() == true && isNotEmpty(skuTableWidgetData.getSelectedStoreInventoryOption())) { if (("allStockedOnhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onhand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0onandwithnoMinMax").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.ON_HAND, 0) > 0 AND (NVL(ssp.MIN_STOCKING_QTY, 0) = 0 OR NVL(ssp.max_stocking_qty, 0) = 0)"; } else if (("grt0min").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } else if (("grt0min0withnoOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NVL(ssp.MIN_STOCKING_QTY, 0) > 0 AND NVL(ssp.ON_HAND, 0) = 0"; } else if (("grt0excludeOnHand").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.ON_HAND, 0) > 0"; } else if (("grt0excludeMin").equals(skuTableWidgetData.getSelectedStoreInventoryOption().trim())) { sql += " and NOT NVL(ssp.MIN_STOCKING_QTY, 0) > 0"; } } //Min Max Set To Zero I8 filter if (skuTableWidgetData.isMinMaxSetZeroI8()) { sql += " and ssp.i8_check ='Y' "; } // Lost Sales Filter if (skuTableWidgetData.isSoldNotStocked()) { sql += " and (ssp.effective_pts = 230 and ssp.RECOMMENDED_ORDER_QTY > 0) "; } // Hide system followers filter if (skuTableWidgetData.isHideSystemFollowers()) { sql += " and nvl(ssp.system_recommended, 'N') = 'N' "; } // New Number filter if (skuTableWidgetData.isNewNumber()) { sql += " and ssp.reason_id = 8 "; } // expensiveItem if (skuTableWidgetData.isExpensiveItem()) { sql += " and ORDER_QTY*PRICE_WT_CORE > 500 "; } //FirstStockDate Filter if (isNotEmpty(skuTableWidgetData.getFirstStockToDt()) && isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt between '" + skuTableWidgetData.getFirstStockFromDt() + "' and '" + skuTableWidgetData.getFirstStockToDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt >= '" + skuTableWidgetData.getFirstStockFromDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockToDt())) { sql += " and ssp.initial_stocking_dt <='" + skuTableWidgetData.getFirstStockToDt() + "' "; } // Reviewed if (skuTableWidgetData.getIsReviewed() != null && skuTableWidgetData.getIsReviewed()) { sql += " and ssp.REVIEWED=1 "; } else if (skuTableWidgetData.getIsReviewed() != null && !skuTableWidgetData.getIsReviewed()) { sql += " and NVL(ssp.REVIEWED, 0) = 0 "; } if (skuTableWidgetData.isDcStocking() && ("stockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and NVL(dc_sp.max_stocking_qty, 0) > 0 "; } else if (skuTableWidgetData.isDcStocking() && ("nonstockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and NVL(dc_sp.min_stocking_qty, 0) = 0 "; } // largeOrderQty if (skuTableWidgetData.isLargeOrderQty()) { sql += " and ( ORDER_QTY > STD_PKG and ORDER_QTY > (PER_CAR * 2) ) "; } //dcSales Filter if (skuTableWidgetData.getDcSalesMonth() != null) { //dcSales 12 Filter if (skuTableWidgetData.getDcSalesMonth() == 12) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_12_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_12_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_12_months >= " + skuTableWidgetData.getDcSalesMin(); } } //DcSales 24 Filter if (skuTableWidgetData.getDcSalesMonth() == 24) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_24_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_24_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_24_months >= " + skuTableWidgetData.getDcSalesMin(); } } } //*dcSales Filter if (skuTableWidgetData.getDcWideSalesMonth() != null) { //*dcSales 12 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 12) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_12_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } //*DcSales 24 Filter if (skuTableWidgetData.getDcWideSalesMonth() == 24 ) { if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMax() >= skuTableWidgetData.getDcWideSalesMin()) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) BETWEEN "+skuTableWidgetData.getDcWideSalesMin() + "AND "+ skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMax() != null && skuTableWidgetData.getDcWideSalesMin() == null) { sql += "and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) <= "+skuTableWidgetData.getDcWideSalesMax() +" )"; } else if (skuTableWidgetData.getDcWideSalesMin() != null && skuTableWidgetData.getDcWideSalesMax() == null) { sql +="and ssp.product_id in (Select sp.product_id from STORE_SALES_ROLLUP_NEW sp where sp.dc_site_id = " + " (select s.site_id from site s where s.site_type_code='DC' " + " and s.product_availability_id= (select product_availability_id from site where site_id=ssp.site_id))" + " and nvl(sp.SALES_LAST_24_MONTHS,0) >= " + skuTableWidgetData.getDcWideSalesMin()+" )"; } } } //hub demand Filter if (skuTableWidgetData.getHubDemandMonth() != null && user.getAccessItemIds().contains(159)) { //hub demand 12 Filter if (skuTableWidgetData.getHubDemandMonth() == 12) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_12,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } //hub demand 24 Filter if (skuTableWidgetData.getHubDemandMonth() == 24) { if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMax() >= skuTableWidgetData.getHubDemandMin()) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) BETWEEN "+skuTableWidgetData.getHubDemandMin() + " AND "+ skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMax() != null && skuTableWidgetData.getHubDemandMin() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) <= "+skuTableWidgetData.getHubDemandMax() +" ) "; } else if (skuTableWidgetData.getHubDemandMin() != null && skuTableWidgetData.getHubDemandMax() == null) { sql += " AND ssp.product_id IN ( SELECT hdr.product_id FROM hsn_demand_rollup hdr " + " WHERE hdr.hsn_network_id in(select hsn_network_id from hub_spoke_network_mapping where is_active=1 and ssp.site_id=hsn_site_id) " + " AND nvl(hdr.demand_24,0) >= "+skuTableWidgetData.getHubDemandMin() +" ) "; } } } // HubSiteCountData if ((skuTableWidgetData.getHubSiteCountMin ( ) != null || skuTableWidgetData.getHubSiteCountMax ( ) != null) && user.getAccessItemIds().contains(160) ) { if (( null == skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ()) && (null==skuTableWidgetData.getHubSiteCountMax ()|| 0==skuTableWidgetData.getHubSiteCountMax ( )) ) { sql += " and not exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + ")"; } else if ((null==skuTableWidgetData.getHubSiteCountMin ( ) || 0==skuTableWidgetData.getHubSiteCountMin ( )) && (null!=skuTableWidgetData.getHubSiteCountMax () && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and ( exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) <= " + skuTableWidgetData.getHubSiteCountMax() + ") OR" + " not exists (select product_id from network_product where network_id in ( " + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss " + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1 " + " )" + " and ssp.product_id=product_id )) "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null==skuTableWidgetData.getHubSiteCountMax ( ) || 0==skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and nvl(CNT_MIN_GTR_0,0) >= " + skuTableWidgetData.getHubSiteCountMin() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() || 0!=skuTableWidgetData.getHubSiteCountMin( )) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) || 0!=skuTableWidgetData.getHubSiteCountMax ())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } else if ((null!=skuTableWidgetData.getHubSiteCountMin() && 0!=skuTableWidgetData.getHubSiteCountMin()) && (null!=skuTableWidgetData.getHubSiteCountMax ( ) && 0!=skuTableWidgetData.getHubSiteCountMax())) { sql += " and exists (select product_id from network_product where network_id in (" + " SELECT DISTINCT hsn_network_id FROM hub_spoke_network_mapping WHERE hsn_site_id IN ( SELECT ss.site_id " + " FROM session_site ss" + " WHERE ss.session_id = " + skuTableWidgetData.getSessionId() + " )" + " AND is_active = 1" + " )" + " and ssp.product_id=product_id" + " and CNT_MIN_GTR_0 BETWEEN " + skuTableWidgetData.getHubSiteCountMin() + " and " + skuTableWidgetData.getHubSiteCountMax() + ") "; } } // obsolete filter if (skuTableWidgetData.isObsoleteSkus()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.CLASS = 'O' "; } // App / Non-App Filter if (skuTableWidgetData.isAppNonApp()) { if (("nonApplication").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NULL "; else if (("application").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NOT NULL "; } // fleets filter if (skuTableWidgetData.getFleetGroupIdsArray() != null && skuTableWidgetData.getFleetGroupIdsArray().length > 0) { sql += " and flt.fleet_id in (" + java.util.Arrays.toString(skuTableWidgetData.getFleetGroupIdsArray()) .replace("[", "").replace("]", "") + ") and EFFECTIVE_PTS=500 "; } // Display Flag filter if (skuTableWidgetData.isDisplayFlag()) { sql += " and ssp.DISPLAY_QTY > 0 "; } // Keep Flag filter if (skuTableWidgetData.isKeepFlag()) { sql += " and ssp.KEEP_FLAG ='Y' "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ((ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0) " + "or (ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 and s.SITE_TYPE_CODE='DC' and ssp.EFFECTIVE_PTS > 0.25 )) "; } //SalesPotential Filter if(user.getAccessItemIds().contains(128)){ if (skuTableWidgetData.getPtsMin() != null && skuTableWidgetData.getPtsMax() != null && skuTableWidgetData.getPtsMax() >= skuTableWidgetData.getPtsMin()) { sql += " and nvl(ROUND(ssp.PTS*100),0) >= " + skuTableWidgetData.getPtsMin() + " and nvl(round(ssp.PTS*100),0) <= " + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMax() !=null && skuTableWidgetData.getPtsMin() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) <=" + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMin() !=null && skuTableWidgetData.getPtsMax() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) >=" +skuTableWidgetData.getPtsMin(); }} //SalesOccurr Filter if (skuTableWidgetData.getSalesOccurrMonth() != null) { //SalesOccurr 12 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 12) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_12_months, 0) + NVL(ssp.HSN_lost_sales_12_months, 0) + NVL(SSP.HSN_SUPERSEDE_12_MONTHS,0) ELSE" + " NVL(ssp.occurance_12_months, 0) + NVL(ssp.lost_sales_12_months, 0) + NVL(SSP.SUPERSEDE_12_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } //SalesOccurr 24 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 24) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_24_months, 0) + NVL(ssp.HSN_lost_sales_24_months, 0) + NVL(SSP.HSN_SUPERSEDE_24_MONTHS,0) ELSE" + " NVL(ssp.occurance_24_months, 0) + NVL(ssp.lost_sales_24_months, 0) + NVL(SSP.SUPERSEDE_24_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } } //DCR_PTS Filter if (skuTableWidgetData.getDcrPtsMin() != null && skuTableWidgetData.getDcrPtsMax() != null) { sql += " and ssp.DCR_PTS >= " + skuTableWidgetData.getDcrPtsMin() + " and ssp.DCR_PTS <= " + skuTableWidgetData.getDcrPtsMax(); } if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin() + " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } else if (skuTableWidgetData.getCostMin() != null && skuTableWidgetData.getCostMax() == null) { sql += " and ssp.price_wt_core >= " + skuTableWidgetData.getCostMin(); } else if (skuTableWidgetData.getCostMin() == null && skuTableWidgetData.getCostMax() != null) { sql += " and ssp.price_wt_core <= " + skuTableWidgetData.getCostMax(); } // LOW VEHICLE COUNT filter -- PUL -7328 - Removed 'and ssp.recommended_order_qty > 0' // Added operator check inclusion for PUL-7508 if (skuTableWidgetData.getLowVehicleCount() != null) { if (skuTableWidgetData.getLowVehicleOperator() != null && (skuTableWidgetData.getLowVehicleOperator().trim().equals("<") || skuTableWidgetData.getLowVehicleOperator().trim().equals(">"))) { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) " + skuTableWidgetData.getLowVehicleOperator().trim() + " " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } else { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) < " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } sql += " "; } // Line Abbr filter if (isNotEmpty(skuTableWidgetData.getLineAbbr())) { sql += " and P.FIELD_ABBR IN ( " + skuTableWidgetData.getLineAbbr() + ")"; } // Group Code if (skuTableWidgetData.getGroupCode() >= 0) { sql += " and P.GROUP_CODE = " + skuTableWidgetData.getGroupCode() + " "; } // Avg Age filter if (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null) { sql += " and p.AVG_AGE between " + skuTableWidgetData.getAvgAgeMin() + " and " + skuTableWidgetData.getAvgAgeMax() + " "; } // Supersedes filter if (skuTableWidgetData.isSupersedes()) { sql += " and ssp.product_id in (select SURVIVING_PRODUCT_ID from SUPERSEDE_PRODUCT where SURVIVING_PRODUCT_ID=ssp.product_id ) "; } // Specials filter if (skuTableWidgetData.isSpecials()) { sql += " and ssp.reason_id = 3 "; } // Other filter if (skuTableWidgetData.isOther()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.INITIAL_STOCKING_DT is null and ssp.class != 'O' "; } // Overstock Filter if (skuTableWidgetData.isOverstock()) { sql += " and ssp.recommended_return_qty > 0 AND ssp.recommended_return_qty < ssp.on_hand "; } // 24 and Out filter if (skuTableWidgetData.isTwentyFourAndOut()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.MIN_STOCKING_QTY>0 and ssp.INITIAL_STOCKING_DT is not null and ssp.class != 'O' "; } // Systems filter if (skuTableWidgetData.isSystem()) { sql += " and nvl(ssp.system_recommended, 'N') = 'Y' and (ssp.ORDER_QTY > 0 OR ssp.RECOMMENDED_ORDER_QTY > 0) "; } // Orders and Returns filters String orderFilter = ""; if (("recommended").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(nvl(ssp.RECOMMENDED_ORDER_QTY,0) > 0)"; } else if (("accepted").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "ssp.ORDER_QTY > 0"; } else if (("declined").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY <> 0 and ssp.ORDER_QTY = 0)"; } String returnFilter = ""; if (("recommended").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RETURN_QTY = ssp.RECOMMENDED_RETURN_QTY and ssp.RETURN_QTY > 0)"; } else if (("declined").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY <> 0 and ssp.RETURN_QTY = 0)"; } if (skuTableWidgetData.isReturn() && skuTableWidgetData.isOrder()) { if ("orderAll".equals((skuTableWidgetData.getAction()))) sql += " and " + orderFilter; else sql += " and (" + orderFilter + " OR " + returnFilter + ") "; } else if (skuTableWidgetData.isReturn()) { if ("orderAll".equals((skuTableWidgetData.getAction())) && orderFilter.length() == 0) sql += " and (nvl(ssp.RECOMMENDED_ORDER_QTY,0) > 0) "; else sql += " and " + returnFilter; } else if (skuTableWidgetData.isOrder()) { sql += " and " + orderFilter; } // Hub & Spoke Filter //viewData if (("hubOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'H' "; } else if (("spokeOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'S' "; } else if (("HSOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NOT NULL "; } else if (("hideHS").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NULL "; } // filter by hierarchy if (skuTableWidgetData.getHierarchyId() > 0) { sql += " and ssp.LEVEL4_PARENT_ID in (select HIERARCHY_ID from product_hierarchy where HIERARCHY_LEVEL=4 start " + "with HIERARCHY_ID = " + skuTableWidgetData.getHierarchyId() + " connect by prior HIERARCHY_ID = PARENT_ID) "; } if (skuTableWidgetData.getHighSkuEditHierarchyId() != null) { sql += " and ssp.LEVEL4_PARENT_ID = " + skuTableWidgetData.getHighSkuEditHierarchyId() + " and ssp.PRODUCT_ID IN (select product_id from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } if (skuTableWidgetData.getHighSkuEdit() != null) { sql += " and ssp.PRODUCT_ID IN (select product_id from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } // Part Number filter if (skuTableWidgetData.getPartNumber() != null) { String partNumber = skuTableWidgetData.getPartNumber().toUpperCase().replaceAll("[^A-Z0-9]+", ""); if (partNumber.length() > 0) { sql += " and P.PART_NUMBER = '" + partNumber + "'"; } } // Site filter if (skuTableWidgetData.getSiteIdsArray() != null && skuTableWidgetData.getSiteIdsArray().length > 0) { sql += " and ssp.site_id in (" + String.join(",", Arrays.asList(skuTableWidgetData.getSiteIdsArray()) .stream().map(Object::toString).collect(Collectors.toList())) + ") "; } sql += "and ssp.product_id in (" + productIds + ")" + ") A on (ssp.session_id=a.session_id and ssp.site_id=a.site_id and ssp.product_id=a.product_id) "; String declineOrderSkus = "select distinct b.hierarchy_id_l4 from decline_order_return a, hierarchy_levels b" + " where session_id =" + skuTableWidgetData.getSessionId() + " and decline_order = 1 " + "and (a.hierarchy_id = b.hierarchy_id_l4 OR a.hierarchy_id = b.hierarchy_id_l3 OR " + "a.hierarchy_id = b.hierarchy_id_l2 OR a.hierarchy_id = b.hierarchy_id_l1 ) " + "AND b.hierarchy_id_l4 IS NOT NULL "; String declineReturnSkus = "select b.hierarchy_id_l4 from decline_order_return a, hierarchy_levels b" + " where session_id =" + skuTableWidgetData.getSessionId() + " and decline_return = 1 " + "and (a.hierarchy_id = b.hierarchy_id_l4 OR a.hierarchy_id = b.hierarchy_id_l3 OR a.hierarchy_id = b.hierarchy_id_l2 OR a.hierarchy_id = b.hierarchy_id_l1 ) " + "AND b.hierarchy_id_l4 IS NOT NULL "; if ("returnAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id = :userId, keep_qty = (on_hand - RECOMMENDED_RETURN_QTY), " + "hq_keep_qty = case when :storeUser = 1 then hq_keep_qty else (on_hand - RECOMMENDED_RETURN_QTY) end " + "where not exists (select hierarchy_id_l4 from (" + declineReturnSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if ("keepAll".equals(skuTableWidgetData.getAction())) { if(skuTableWidgetData.isMinMaxSetToZero()) { sql += " WHEN MATCHED THEN UPDATE SET user_Id = :userId, ssp.keep_qty = (CASE WHEN NVL(ssp.return_qty,0) > 0 THEN on_hand ELSE ssp.keep_qty END), hq_keep_qty = (case when :storeUser = 1 then hq_keep_qty else (CASE WHEN NVL(ssp.return_qty,0) > 0 THEN on_hand ELSE hq_keep_qty END) end) " + " ,min_stocking_qty=(" + "CASE WHEN (NVL(ON_HAND,0)>NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY NVL(ORG_MAX_STOCKING_QTY,0) AND NVL(ORG_MAX_STOCKING_QTY,0)!=0 AND NVL(ORG_MAX_STOCKING_QTY,0)=(NVL(ON_HAND,0)-NVL(RECOMMENDED_RETURN_QTY,0))) OR (SSP.CLASS='O')"+" OR (SSP.RECOMMENDED_RETURN_QTY >0 AND SSP.RECOMMENDED_RETURN_QTY 0 THEN on_hand ELSE ssp.keep_qty END)," + " hq_keep_qty = (case when :storeUser = 1 then hq_keep_qty " + "else (CASE WHEN NVL(ssp.return_qty,0) > 0 THEN on_hand ELSE hq_keep_qty END) end) "; } } else if ("orderNone".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_Id = :userId, order_qty = 0, hq_order_qty = case when :storeUser = 1 then hq_order_qty else 0 end "; } else if ("revertAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_Id = :userId, ORDER_QTY=RECOMMENDED_ORDER_QTY, " + "HQ_ORDER_QTY = (case when :storeUser = 1 then HQ_ORDER_QTY else RECOMMENDED_ORDER_QTY end), KEEP_QTY=(ON_HAND-RECOMMENDED_RETURN_QTY), " + "HQ_KEEP_QTY = (case when :storeUser = 1 then HQ_KEEP_QTY else (ON_HAND-RECOMMENDED_RETURN_QTY) end), " + " MIN_STOCKING_QTY = ORG_MIN_STOCKING_QTY ,MAX_STOCKING_QTY=ORG_MAX_STOCKING_QTY "+ " ,i8_check=(" + "CASE WHEN (ssp.i8_check='Y')" + " THEN 'N' " + " END) " ; } else if (perCarOrder == 1 && "orderAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id=:userId, " + " order_qty = (case when PER_CAR>0 and initial_stock_amount <= PER_CAR then PER_CAR else initial_stock_amount end), " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty " + " else (case when PER_CAR>0 and initial_stock_amount <= PER_CAR then PER_CAR else initial_stock_amount end) end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if (storeDepth == 1 && "orderAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id=:userId, " + " order_qty = (case when nvl(PRODUCT_DEPTH_QTY,0)>0 then PRODUCT_DEPTH_QTY else initial_stock_amount end), " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty else (case when nvl(PRODUCT_DEPTH_QTY,0)>0 " + " then PRODUCT_DEPTH_QTY else initial_stock_amount end) end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } else if ("orderAll".equals(skuTableWidgetData.getAction())) { sql += " WHEN MATCHED THEN UPDATE SET user_id=:userId, " + " order_qty = initial_stock_amount, " + " hq_order_qty = case when :storeUser = 1 then hq_order_qty " + "else initial_stock_amount end " + "where not exists (select hierarchy_id_l4 from (" + declineOrderSkus + " ) h where ssp.level4_parent_id=h.hierarchy_id_l4)"; } NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("sessionId", skuTableWidgetData.getSessionId()); parameters.addValue("userId", skuTableWidgetData.getUser().getUserId()); parameters.addValue("storeUser", skuTableWidgetData.getUser().isStoreUser() ? 1 : 0); namedParameterJdbcTemplate.update(sql, parameters); } catch(Exception e){ LOGGER.error("Error in bulkEditSql {}",e.getMessage()); } } /* * (non-Javadoc) * * @see com.napa.pulse.dao.interfaces.ReviewDAO#getSiteSKUDetailsTableData(int, * int) */ static List getProductIdsAsCommaSeparated(List listOfNumbers, int partitionSize) { List result = new ArrayList<>(); if (listOfNumbers.size() <= partitionSize) { result.add(listOfNumbers.stream().map(Object::toString).collect(Collectors.joining(","))); return result; } //work only when list size is more than partition size int noOfPartions = listOfNumbers.size() / partitionSize + (listOfNumbers.size() % partitionSize == 0 ? 0 : 1); for (int i = 0; i < noOfPartions - 1; i++) { result.add(listOfNumbers.subList(partitionSize * i, (i * partitionSize) + partitionSize).stream().map(Object::toString).collect(Collectors.joining(","))); if (i == noOfPartions - 2) result.add(listOfNumbers.subList((i * partitionSize) + partitionSize, listOfNumbers.size()).stream().map(Object::toString).collect(Collectors.joining(","))); } return result; } @Override public List> getSiteSKUDetailsTableData ( Integer sessionId, Integer productId, Integer siteId, Integer vehicleCount ) { ActionResult result = new ActionResult(); List> siteSKUTableData = new ArrayList<>(); try { LOGGER.info("getSiteSKUDetailsTableData request for sessionId " + sessionId + ", productId " + productId + ", siteId " + siteId + ", vehicleCnt " + vehicleCount); boolean isFinalized = isSessionFinalized(sessionId); List remainingSites; String remainingSitesSQL = "SELECT SITE_ID FROM SESSION_SITE WHERE SESSION_ID = ? " + ((siteId != null) ? " AND SITE_ID = ? " : "") + " minus select site_id " + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " where SESSION_ID = ? and product_id = ? "; if (siteId == null) { remainingSites = jdbcTemplate.query(remainingSitesSQL, new IntegerRowMapper(), sessionId, sessionId, productId); } else { remainingSites = jdbcTemplate.query(remainingSitesSQL, new IntegerRowMapper(), sessionId, siteId, sessionId, productId); } String siteSKUTableDataSQL = "SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " nvl(ROUND(ssp.PTS*100),0) AS \"salesPotential\", " + " CASE WHEN ssp.business_rules_applied = '000' THEN 0 ELSE 1 END as \"businessRulesApplied\", " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS \"lost24\", " + " nullif(ssp.dc_sales_last_12_months, 0) AS \"dcSales12\", " + " nullif(ssp.dc_sales_last_24_months, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND, 0) AS \"onHand\", " + " SSP.ORDER_QTY AS \"order\", " + " SSP.RETURN_QTY AS \"return\", " + " (case " + "when ssp.return_qty > 0 then 'R' " + "when ssp.order_qty > 0 then 'O' " + "when SSP.MIN_STOCKING_QTY > 0 OR (RETURN_QTY = 0 AND RECOMMENDED_RETURN_QTY > 0) then 'S' " + "when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as \"mapFlag\"," + " SSP.KEEP_QTY AS \"keep\", " + " nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG, 0) AS \"stdPack\", " + " NVL(SSP.MIN_STOCKING_QTY, 0) AS \"min\", " + " NVL(SSP.MAX_STOCKING_QTY, 0) AS \"max\", " + " (CASE " + "WHEN SSP.ORDER_QTY > 0 " + "THEN (SSP.PRICE_WT_CORE * SSP.ORDER_QTY) " + "WHEN SSP.RETURN_QTY > 0 " + "THEN -(SSP.PRICE_WT_CORE * SSP.RETURN_QTY) " + "ELSE null " + "END) AS \"extPrice\", " + " NVL(TO_CHAR(SSP.VIO), '-') AS \"vio\", " + " SSP.PCT_MARKET AS \"pctMrkt\", " + " (case when (PO.OVERRIDE_ID = 2 and PO.is_Active = 1) then 'Y' " + " else 'N' END) as \"blockOrder\" , " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", " + " nullif(SSP.DISPLAY_QTY, 0) AS \"displayQty\", " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", " + " SSP.KEEP_FLAG AS \"keepFlag\", " + " (case " + " when SSP.CLASS = 'O' then 'obsolete' " + " when ((ssp.PTS < NVL(sp.OFFSET,0)+0.5) and ssp.DEMAND_12_MONTHS > 1 and ssp.RECOMMENDED_ORDER_QTY > 0) then 'lostSales' " + " when ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 then 'prospectParts' " + " when nvl(ssp.system_recommended, 'N') = 'Y' and ssp.RECOMMENDED_ORDER_QTY > 0 then 'followerSku' " + " when (ssp.VIO > 0 AND ssp.VIO < " + vehicleCount + " and ssp.recommended_order_qty > 0 ) then 'lowVehicle' end ) as \"colorCode\", " + " (case when ssp.effective_pts = 230 then 1 else 0 end) as \"isSoldNotStocked\", " + " S.LATITUDE, S.LONGITUDE, " + " (case when SUBSTR(ssp.business_rules_applied, 2,1) = '3' THEN 1 when (ssp.effective_pts = 230 AND NVL(ssp.min_stocking_qty, 0) <= 0 AND SUBSTR(ssp.business_rules_applied, 2,1) <> 'S') OR order_qty > 0 THEN 0 when (DECLINE_ORDER>0) OR (ssp.block_order is not null) OR (recommended_return_qty is not null) OR (ssp.MIN_STOCKING_QTY > 0) then 1 else 0 end) as \"orderNotEditable\", " + " (case when (DECLINE_RETURN>0) OR (ssp.block_return is not null) OR (recommended_return_qty is null) then 1 else 0 end) as \"keepNotEditable\", " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\" , nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\", " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\", " + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as \"propensity\", " + " case when pulsesess.session_type_code = 'IS' then sp.PTS else null END as \"pts\", " + " CASE WHEN NVL(SYSTEM_RECOMMENDED, 0) = 'Y' THEN 1 ELSE 0 END AS \"isFollowerSku\", CASE WHEN NVL(SYSTEM_FLAG, 0) = 'Y' THEN 1 ELSE 0 END AS \"isSystemSku\", " + " (case when fh.isFleet is not null then 1 else null end) as \"isFleetSku\", nvl(sim.sim_part_ct,0) as \"siteSimPartsCount\", " + " nvl(hub.sim_hub_part_ct,0) as \"hubSimPartsCount\", SSP.DECLINE_ORDER as \"declineOrder\", SSP.DECLINE_RETURN as \"declineReturn\", " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " REGEXP_REPLACE(ssp.BUSINESS_RULES_APPLIED, '(.)(.)(.)', '\\1,\\2,\\3') as \"ruleInfo\", " + " (CASE WHEN REASON_ID = 8 THEN 1 ELSE 0 END) as \"isNewNumber\",dcWideSales12, dcWideSales24 , hubDemand12 as \"hubDemand12\", hubDemand24 as \"hubDemand24\" ,NVL(hub_min_gtr_0,0) as \"hubSiteCount\"" + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " INNER JOIN PULSE_SESSION pulsesess ON ssp.SESSION_ID = pulsesess.SESSION_ID " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " LEFT JOIN PRODUCT_OVERRIDE PO ON SSP.SITE_ID = PO.SITE_ID and SSP.PRODUCT_ID = PO.PRODUCT_ID " + " left JOIN (select site_id, product_id, 1 as isFleet from SESSION_SITE_PRODUCT where session_id=:sessionId " + " and site_id in (select site_id from session_site where session_id=:sessionId) and (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') " + " and product_id= :productId group by SITE_ID, product_id) fh " + " on ssp.SITE_ID=fh.SITE_ID and SSP.product_id=fh.product_id " + " left JOIN (select SESSION_ID, SITE_ID, PRODUCT_ID, count(PRODUCT_ID) as sim_part_ct from ( " + " select SESSION_ID, SITE_ID, simp.product_id, ssp.PRODUCT_ID as sim_part_ct " + " from session_site_product ssp, similar_product simp " + " where session_id=:sessionId " + " and site_id in (select site_id from session_site where session_id=:sessionId) " + " and ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and simp.product_id=:productId " + " and ( " + " ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and nvl(RETURN_QTY, 0) = 0 and class != 'O') " + " OR ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and RETURN_QTY > 1 and KEEP_QTY > 1 and class!='O') " + " OR ORDER_QTY>0 " + " ) " + " union " + " select :sessionId as SESSION_ID, SITE_ID, simp.product_id, sp.PRODUCT_ID as sim_part_ct " + " from site_product sp, similar_product simp " + " where site_id in (select site_id from session_site where session_id=:sessionId) " + " and sp.product_id=simp.similar_product_id " + " and simp.product_id=:productId and MIN_STOCKING_QTY>0 " + " and not exists (select * from session_site_product where session_id=:sessionId " + " and site_id in (select site_id from session_site where session_id=:sessionId) " + " and product_id=sp.product_id)) " + " group by SESSION_ID, SITE_ID, PRODUCT_ID) sim " + " on ssp.session_id=sim.session_id and ssp.SITE_ID=sim.SITE_ID and SSP.product_id=sim.product_id " + " left JOIN (select SESSION_ID, SITE_ID, PRODUCT_ID, count(PRODUCT_ID) as sim_hub_part_ct from ( " + " select SESSION_ID, SITE_ID, ssp.product_id, simp.PRODUCT_ID as sim_part_ct " + " from session_site_product ssp, SIMILAR_PRODUCT simp " + " where session_id=:sessionId " + " and ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and ssp.product_id=:productId " + " and site_id in (select distinct site_id " + " from SESSION_SITE ss, TRANSFER_MAPPING tm " + " where session_id=:sessionId " + " and SITE_ID=SOURCE_SITE_ID) " + " and ( " + " ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and nvl(RETURN_QTY, 0) = 0 and class != 'O') " + " OR ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and RETURN_QTY > 1 and KEEP_QTY > 1 and class!='O') " + " OR ORDER_QTY>0 " + " ) " + " union all " + " select :sessionId as SESSION_ID, SITE_ID, simp.product_id, ssp.PRODUCT_ID as sim_hub_part_ct " + " from site_product ssp, SIMILAR_PRODUCT simp " + " where ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and ssp.product_id=:productId " + " and site_id in (select distinct SOURCE_SITE_ID as site_id " + " from SESSION_SITE ss, TRANSFER_MAPPING tm " + " where session_id=:sessionId " + " and tm.TARGET_SITE_ID= ss.site_id " + " and SOURCE_SITE_ID not in (select site_id " + " from session_site where session_id=:sessionId)) " + " and MIN_STOCKING_QTY>0 " + " ) group by SESSION_ID, SITE_ID, PRODUCT_ID) hub " + " on ssp.session_id=hub.session_id and ssp.SITE_ID=hub.SITE_ID and SSP.product_id=hub.product_id " + " left join ( SELECT DC_SAL.site_id ,DC_SAL.product_id ,DC_SAL.dcSales12 ,DC_SAL.dcSales24 ,nullif(SSRN.SALES_LAST_12_MONTHS, 0) AS dcWideSales12 ,nullif(SSRN.SALES_LAST_24_MONTHS, 0) AS dcWideSales24, " + " nullif(hdrn.DEMAND_12, 0) AS hubDemand12 ,nullif(hdrn.DEMAND_24, 0) AS hubDemand24 , CNT_MIN_GTR_0 AS hub_min_gtr_0 FROM " + "(SELECT /*+ INDEX (sp SITE_PRODUCT_PRODUCT_IDX) */ ss.site_id, sp.product_id, dc_id , nullif(sp.dc_sales_last_12_months,0) as dcSales12, nullif(sp.dc_sales_last_24_months,0) as dcSales24 ,dc.HSN_NETWORK_ID" + " FROM session_site ss " + " JOIN ( " + " SELECT s.site_id, dc.site_id dc_id ,(select hsnm.HSN_NETWORK_ID from hub_spoke_network_mapping hsnm where hsnm.is_active = 1 AND hsnm.hsn_site_id = s.site_id) as HSN_NETWORK_ID " + " FROM site s, site dc " + " WHERE s.product_availability_id = dc.product_availability_id " + " AND dc.site_type_code = 'DC' " + " AND s.active_flag = 'Y' AND dc.active_flag = 'Y' " + " ) dc ON ss.site_id= dc.site_id " + " JOIN site_product sp ON (sp.site_id = dc.dc_id) " + " WHERE session_id = :sessionId) DC_SAL LEFT OUTER JOIN STORE_SALES_ROLLUP_NEW SSRN ON DC_SAL.DC_ID=SSRN.DC_SITE_ID AND DC_SAL.PRODUCT_ID=SSRN.PRODUCT_ID " +" LEFT OUTER JOIN HSN_DEMAND_ROLLUP HDRN on DC_SAL.HSN_NETWORK_ID = HDRN.HSN_NETWORK_ID AND DC_SAL.PRODUCT_ID =HDRN.PRODUCT_ID" +" LEFT OUTER JOIN NETWORK_PRODUCT NP ON DC_SAL.HSN_NETWORK_ID = NP.NETWORK_ID AND DC_SAL.PRODUCT_ID = NP.PRODUCT_ID ) " +" dc_sp on ssp.product_id = dc_sp.product_id and ssp.site_id = dc_sp.site_id " + " WHERE SSP.SESSION_ID = :sessionId and ssp.product_id = :productId " + " and ssp.site_id in (select site_id from session_site where session_id = :sessionId) "; if (siteId != null) { siteSKUTableDataSQL += " AND SSP.SITE_ID = :siteId "; } if (remainingSites.size() > 0) { siteSKUTableDataSQL += " union SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " ROUND(ssp.PTS*100) AS \"salesPotential\", " + " CASE WHEN ssp.business_rules_applied = '000' THEN 0 ELSE 1 END as \"businessRulesApplied\", " + " nullif(SSP.SOLD_LAST_12_MONTHS,0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS,0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS,0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS,0) AS \"lost24\", " + " nullif(ssp.dc_sales_last_12_months, 0) AS \"dcSales12\", " + " nullif(ssp.dc_sales_last_24_months, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND,0) AS \"onHand\", " + " NULL AS \"order\", " + " NULL AS \"return\", " + " (case when SSP.MIN_STOCKING_QTY > 0 then 'S' " + " when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as \"mapFlag\", " + " NULL AS \"keep\", " + " nullif(SSP.INITIAL_STOCK_AMOUNT,0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG,0) AS \"stdPack\", " + " nullif(SSP.MIN_STOCKING_QTY,0) AS \"min\", " + " nullif(SSP.MAX_STOCKING_QTY,0) AS \"max\", " + " NULL AS \"extPrice\", " + " NVL(TO_CHAR(SSP.VIO),'-') AS \"vio\", " + " SSP.PCT_MARKET AS \"pctMrkt\", " + " (case when (PO.OVERRIDE_ID = 2 and PO.is_Active = 1) then 'Y' " + " else 'N' END) as \"blockOrder\" , " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", " + " nullif(SSP.DISPLAY_QTY,0) AS \"displayQty\", " + " SSP.KEEP_FLAG AS \"keepFlag\", " + " case when ssP.CLASS = 'O' then 'obsolete' else null " + " end as \"colorCode\", " + " 0 as \"isSoldNotStocked\", " + " S.LATITUDE, S.LONGITUDE, " + " (case when nvl(SSP.MIN_STOCKING_QTY,0) = 0 and block_order is null and nvl(SH.INCLUDE_ORDER,0) = 1 then 0 " + " else 1 end) as \"orderNotEditable\", " + " 1 as \"keepNotEditable\", round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\", nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\", " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\", " + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (ssp.PTS >= 0 and ssp.PTS < 0.3) then '1_red_right' " + " when (ssp.PTS >= 0.3 and ssp.PTS < 0.4) then '2_yellow_right' " + " when (ssp.PTS >= 0.4 and ssp.PTS < 0.5) then '3_green_right' " + " when (ssp.PTS = 0.5) then '4_green' " + " when (ssp.PTS > 0.5 and ssp.PTS <= 0.6) then '5_green_left' " + " when (ssp.PTS > 0.6 and ssp.PTS <= 0.7) then '6_yellow_left' " + " when (ssp.PTS > 0.7 and ssp.PTS < 1) then '7_red_left' " + " else '' END) as \"propensity\"," + " case when pulsesess.session_type_code = 'IS' then ssp.PTS else null END as \"pts\", " + " 0 as \"isFollowerSku\", NVL((SELECT DISTINCT 1 FROM SESSION_SITE_SYSTEM SSS, SYS_CATG_SUPERSEDE_PRODUCT_V SCP WHERE SSS.SESSION_ID = :sessionId AND SSS.SITE_ID = S.SITE_ID AND SSS.SYSTEM_CATEGORY_ID = SCP.SYSTEM_CATEGORY_ID AND SCP.FOLLOWER_PRODUCT_ID = :productId), 0) AS \"isSystemSku\", " + " (case when fh.isFleet is not null then 1 else null end) as \"isFleetSku\", nvl(sim.sim_part_ct,0) as \"siteSimPartsCount\", " + " nvl(hub.sim_hub_part_ct,0) as \"hubSimPartsCount\",0 as \"declineOrder\", 0 as \"declineReturn\", " + " TO_CHAR(CAST(last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " REGEXP_REPLACE(BUSINESS_RULES_APPLIED, '(.)(.)(.)', '\\1,\\2,\\3') as \"ruleInfo\", 0 as \"isNewNumber\" , dcWideSales12, dcWideSales24 , hubDemand12 as \"hubDemand12\", hubDemand24 as \"hubDemand24\" , NVL(dc_sp.hub_min_gtr_0,0) as \"hubSiteCount\"" + " FROM (select site_id, product_id, level4_parent_id, SOLD_LAST_12_MONTHS, SOLD_LAST_24_MONTHS, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " ON_HAND, MIN_STOCKING_QTY, MAX_STOCKING_QTY, INITIAL_STOCK_AMOUNT, VIO, PCT_MARKET, INITIAL_STOCKING_DT, OCCURANCE_12_MONTHS, OCCURANCE_24_MONTHS, DISPLAY_QTY, KEEP_FLAG, CLASS, " + " CLUSTER_PCT_SALE, TRANSFER_12_MONTHS, TRANSFER_24_MONTHS, SUPERSEDE_12_MONTHS, SUPERSEDE_24_MONTHS, PEER_SALES_12, PTS, block_order, 0 as DECLINE_ORDER, 0 as DECLINE_RETURN, " + " last_sale_dt, business_rules_applied,Demand_12_months " + " from SITE_PRODUCT WHERE SITE_ID IN (:remainingSites) and product_id = :productId ) SSP " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN PULSE_SESSION pulsesess ON pulsesess.SESSION_ID = :sessionId " + " LEFT JOIN SESSION_HIERARCHY SH ON SH.SESSION_ID = :sessionId and SSP.LEVEL4_PARENT_ID = SH.HIERARCHY_ID " + " LEFT JOIN PRODUCT_OVERRIDE PO ON SSP.SITE_ID = PO.SITE_ID and SSP.PRODUCT_ID = PO.PRODUCT_ID " + " left JOIN (select site_id, product_id, 1 as isFleet from SESSION_SITE_PRODUCT where session_id=:sessionId " + " and site_id in (select site_id from session_site where session_id=:sessionId) and (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') " + " and product_id= :productId group by SITE_ID, product_id) fh " + " on ssp.SITE_ID=fh.SITE_ID and SSP.product_id=fh.product_id " + " left JOIN (select SESSION_ID, SITE_ID, PRODUCT_ID, count(PRODUCT_ID) as sim_part_ct from ( " + " select SESSION_ID, SITE_ID, simp.product_id, ssp.PRODUCT_ID as sim_part_ct " + " from session_site_product ssp, similar_product simp " + " where session_id=:sessionId " + " and site_id in (select site_id from session_site where session_id=:sessionId) " + " and ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and simp.product_id=:productId " + " and ( " + " ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and nvl(RETURN_QTY, 0) = 0 and class != 'O') " + " OR ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and RETURN_QTY > 1 and KEEP_QTY > 1 and class!='O') " + " OR ORDER_QTY>0 " + " ) " + " union " + " select :sessionId as SESSION_ID, SITE_ID, simp.product_id, sp.PRODUCT_ID as sim_part_ct " + " from site_product sp, similar_product simp " + " where site_id in (select site_id from session_site where session_id=:sessionId) " + " and sp.product_id=simp.similar_product_id " + " and simp.product_id=:productId and MIN_STOCKING_QTY>0 " + " and not exists (select * from session_site_product where session_id =:sessionId " + " and site_id in (select site_id from session_site where session_id =:sessionId) " + " and product_id=sp.product_id)) " + " group by SESSION_ID, SITE_ID, PRODUCT_ID) sim " + " on sim.session_id=:sessionId and ssp.SITE_ID=sim.SITE_ID and SSP.product_id=sim.product_id " + " left JOIN (select SESSION_ID, SITE_ID, PRODUCT_ID, count(PRODUCT_ID) as sim_hub_part_ct from ( " + " select SESSION_ID, SITE_ID, ssp.product_id, simp.PRODUCT_ID as sim_part_ct " + " from session_site_product ssp, SIMILAR_PRODUCT simp " + " where session_id=:sessionId " + " and ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and ssp.product_id=:productId " + " and site_id in (select distinct site_id " + " from SESSION_SITE ss, TRANSFER_MAPPING tm " + " where session_id=:sessionId " + " and SITE_ID=SOURCE_SITE_ID) " + " and ( " + " ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and nvl(RETURN_QTY, 0) = 0 and class != 'O') " + " OR ((MIN_STOCKING_QTY>0 or MAX_STOCKING_QTY>0) and RETURN_QTY > 1 and KEEP_QTY > 1 and class!='O') " + " OR ORDER_QTY>0 " + " ) " + " union all " + " select :sessionId as SESSION_ID, SITE_ID, ssp.product_id, simp.PRODUCT_ID as sim_hub_part_ct " + " from site_product ssp, SIMILAR_PRODUCT simp " + " where ssp.product_id=simp.SIMILAR_PRODUCT_ID " + " and ssp.product_id=:productId " + " and site_id in (select distinct SOURCE_SITE_ID as site_id " + " from SESSION_SITE ss, TRANSFER_MAPPING tm " + " where session_id=:sessionId " + " and tm.TARGET_SITE_ID= ss.site_id " + " and SOURCE_SITE_ID not in (select site_id " + " from session_site where session_id=:sessionId)) " + " and MIN_STOCKING_QTY>0 " + " ) group by SESSION_ID, SITE_ID, PRODUCT_ID) hub " + " on hub.session_id=:sessionId and ssp.SITE_ID=hub.SITE_ID and SSP.product_id=hub.product_id " + " left join ( SELECT DC_SAL.site_id " + ",DC_SAL.product_id " + ",DC_SAL.dcSales12 " + ",DC_SAL.dcSales24 " + ",nullif(SSRN.SALES_LAST_12_MONTHS, 0) AS dcWideSales12 " + ",nullif(SSRN.SALES_LAST_24_MONTHS, 0) AS dcWideSales24 " + ",nullif(hdrn.DEMAND_12, 0) AS hubDemand12 " + ",nullif(hdrn.DEMAND_24, 0) AS hubDemand24 " + ",CNT_MIN_GTR_0 AS hub_min_gtr_0 " + " FROM ( " + "SELECT /*+ INDEX (sp SITE_PRODUCT_PRODUCT_IDX) */ ss.site_id, sp.product_id,dc_id, nullif(sp.dc_sales_last_12_months,0) as dcSales12, nullif(sp.dc_sales_last_24_months,0) as dcSales24 " + ",dc.HSN_NETWORK_ID " + " FROM session_site ss " + " JOIN ( " + " SELECT s.site_id, dc.site_id dc_id " + ",( " + " SELECT hsnm.HSN_NETWORK_ID " + " FROM hub_spoke_network_mapping hsnm " + " WHERE hsnm.is_active = 1 " + " AND hsnm.hsn_site_id = s.site_id " + ") AS HSN_NETWORK_ID " + " FROM site s, site dc " + " WHERE s.product_availability_id = dc.product_availability_id " + " AND dc.site_type_code = 'DC' " + " AND s.active_flag = 'Y' AND dc.active_flag = 'Y' " + " ) dc ON ss.site_id= dc.site_id " + " JOIN site_product sp ON (sp.site_id = dc.dc_id) " + " WHERE session_id = :sessionId) DC_SAL " + " LEFT OUTER JOIN STORE_SALES_ROLLUP_NEW SSRN ON DC_SAL.DC_ID = SSRN.DC_SITE_ID " + " AND DC_SAL.PRODUCT_ID = SSRN.PRODUCT_ID " + " LEFT OUTER JOIN HSN_DEMAND_ROLLUP HDRN ON DC_SAL.HSN_NETWORK_ID = HDRN.HSN_NETWORK_ID " + " AND DC_SAL.PRODUCT_ID = HDRN.PRODUCT_ID " + " LEFT OUTER JOIN NETWORK_PRODUCT NP ON DC_SAL.HSN_NETWORK_ID = NP.NETWORK_ID " + "AND DC_SAL.PRODUCT_ID = NP.PRODUCT_ID ) " + " dc_sp ON ssp.product_id = dc_sp.product_id " + " AND ssp.site_id = dc_sp.site_id " + " WHERE ssp.product_id = :productId "; } NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); MapSqlParameterSource parameters = new MapSqlParameterSource(); if (remainingSites.size() > 0) { parameters.addValue("remainingSites", remainingSites); } parameters.addValue("sessionId", sessionId); parameters.addValue("productId", productId); if (siteId != null) { parameters.addValue("siteId", siteId); } siteSKUTableData = namedParameterJdbcTemplate.queryForList(siteSKUTableDataSQL, parameters); } catch (Exception e) { LOGGER.error("Exception in Site/SKU Details: " + sessionId); LOGGER.error("Exception message is: " + e.getMessage()); LOGGER.error("Exception stacktrace is: " + e.getStackTrace()); result.setMessage("Cannot Update table data"); result.setSuccess(false); Map map = new HashMap<>(); map.put("message", "Exception is " + e.getMessage()); map.put("success", false); List> jsonList = new ArrayList<>(); jsonList.add(map); return jsonList; } return siteSKUTableData; } /* * (non-Javadoc) * * @see com.napa.pulse.dao.interfaces.ReviewDAO#getSiteSKUDetailsTableDataCount( * int, int) */ @Override public List> getSiteSKUDetailsTableDataCount ( int sessionId, int productId ) { boolean isFinalized = isSessionFinalized(sessionId); String sql = " SELECT count(s.site_id) as \"count\" FROM PULSE_SESSION PS " + " INNER JOIN " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP ON PS.SESSION_ID = SSP.SESSION_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " WHERE PS.SESSION_ID = " + sessionId + " and ssp.product_id = " + productId; List> skuTableDataCount = jdbcTemplate.queryForList(sql); return skuTableDataCount; } /* * (non-Javadoc) * * @see * com.napa.pulse.dao.interfaces.ReviewDAO#saveOrderReturn(com.napa.pulse.entity * .security.User, java.lang.Integer, java.lang.Integer, java.lang.Integer, * java.lang.Integer, java.lang.Double, java.lang.Integer, boolean, boolean, * java.lang.Integer, boolean) */ @Override public ActionResultItem>> saveOrderReturn ( User user, Integer sessionId, Integer siteId, Integer productId, Integer orderQty, Double keepQty, Integer vehicleCount, boolean isSimilarPart, boolean isSimilarHubPart, Integer similarProductId, boolean isSimilarPartEdit ) throws PulseException { ActionResultItem>> actionItem = new ActionResultItem<>(); List> product = jdbcTemplate .queryForList("SELECT PRODUCT_ID FROM SESSION_SITE_PRODUCT WHERE SESSION_ID = ? AND SITE_ID = ? " + " AND PRODUCT_ID = ? AND CLASS <> 'O' ", sessionId, siteId, productId); boolean returnCode = siteQueueMap.canStart(siteId, "saveOrderReturn"); if (!returnCode) { throw new PulseException(PulseConstants.OPERATION_TIMEOUT); } else { try { if (product.size() > 0) { jdbcTemplate.update( "UPDATE SESSION_SITE_PRODUCT SET ORDER_QTY = ?, KEEP_QTY = ?, USER_ID = ?, EDIT_LINKED_SIM_PROD_ID = ?, SIMILAR_PRODUCT_EDIT = ?," + " HQ_ORDER_QTY = (case when ? = 1 then HQ_ORDER_QTY else ? end), HQ_KEEP_QTY = (case when ? = 1 then HQ_KEEP_QTY else ? end)" + " WHERE SESSION_ID = ? AND SITE_ID = ? AND PRODUCT_ID = ? ", ps -> { if (orderQty != null) { ps.setInt(1, orderQty); } else { ps.setNull(1, Types.NULL); } if (keepQty != null) { ps.setDouble(2, keepQty); } else { ps.setNull(2, Types.NULL); } ps.setInt(3, user.getUserId()); if (isSimilarPartEdit) { ps.setInt(4, similarProductId); ps.setString(5, "Y"); } else { ps.setNull(4, Types.INTEGER); ps.setString(5, "N"); } ps.setInt(6, user.isStoreUser() ? 1 : 0); if (orderQty != null) { ps.setInt(7, orderQty); } else { ps.setNull(7, Types.NUMERIC); } ps.setInt(8, user.isStoreUser() ? 1 : 0); if (keepQty != null) { ps.setDouble(9, keepQty); } else { ps.setNull(9, Types.NUMERIC); } ps.setInt(10, sessionId); ps.setInt(11, siteId); ps.setInt(12, productId); }); // call is made to the procedure to recalculate the totals. SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); // call is made to the procedure to recalculate the totals. sessionDAO.reCalculateSessionTotals(sessionId, siteId); if (isSimilarPart) { actionItem.setItem(getSimilarPartsWidgetData(sessionId, siteId, productId, vehicleCount, true)); actionItem.setSuccess(true); } else if (isSimilarHubPart) { actionItem.setItem( getHubSimilarPartsWidgetData(sessionId, siteId, productId, vehicleCount, true)); actionItem.setSuccess(true); } else { actionItem.setItem(getSiteSKUDetailsTableData(sessionId, productId, siteId, vehicleCount)); actionItem.setSuccess(true); } } else if (orderQty != null && orderQty > 0) { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS, EDIT_LINKED_SIM_PROD_ID, SIMILAR_PRODUCT_EDIT) " + " SELECT ?, SITE_ID, PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " ? AS ORDER_QTY, NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS, ?, ? " + " FROM SITE_PRODUCT WHERE SITE_ID = ? AND PRODUCT_ID = ? AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null", ps -> { ps.setInt(1, sessionId); ps.setInt(2, orderQty); ps.setInt(3, user.getUserId()); if (isSimilarPartEdit) { ps.setInt(4, similarProductId); ps.setString(5, "Y"); } else { ps.setNull(4, Types.INTEGER); ps.setString(5, "N"); } ps.setInt(6, siteId); ps.setInt(7, productId); }); // call is made to the procedure to recalculate the totals. SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); // call is made to the procedure to recalculate the totals. sessionDAO.reCalculateSessionTotals(sessionId, siteId); if (isSimilarPart) { actionItem.setItem(getSimilarPartsWidgetData(sessionId, siteId, productId, vehicleCount, true)); actionItem.setSuccess(true); } else if (isSimilarHubPart) { actionItem.setItem( getHubSimilarPartsWidgetData(sessionId, siteId, productId, vehicleCount, true)); actionItem.setSuccess(true); } else { actionItem.setItem(getSiteSKUDetailsTableData(sessionId, productId, siteId, vehicleCount)); actionItem.setSuccess(true); } } else { actionItem.setMessage("Row not allowed to be edited"); } } finally { siteQueueMap.removeHead(siteId, "saveOrderReturn"); } } return actionItem; } /* * (non-Javadoc) * * @see com.napa.pulse.dao.interfaces.ReviewDAO#getUserViewPreference(java.lang. * Integer, java.lang.String) */ @Override public List> getUserViewPreference ( Integer userId, String preferenceKey ) { StringBuilder builder = new StringBuilder(); builder.append(" SELECT "); builder.append(" UP.PREFERENCES AS \"preference\" "); builder.append(" FROM "); builder.append(" USER_PREFERENCE UP, "); builder.append(" INTERFACE_ITEM II "); builder.append(" WHERE "); builder.append(" II.ITEM_KEY = UP.ITEM_KEY AND "); builder.append(" UP.USER_ID = " + userId + " AND "); builder.append(" UP.ITEM_KEY = (SELECT III.ITEM_KEY FROM INTERFACE_ITEM III WHERE III.ITEM_SHORT_DESC = '" + preferenceKey + "') "); List> userPref = jdbcTemplate.queryForList(builder.toString()); return userPref; } /* * (non-Javadoc) * * @see * com.napa.pulse.dao.interfaces.ReviewDAO#saveUserViewPreference(com.napa.pulse * .entity.security.User, java.lang.String, java.lang.String) */ @Override public ActionResult saveUserViewPreference ( User user, String prefKey, String prefValue ) { StringBuilder builder = new StringBuilder(); builder.append(" SELECT "); builder.append(" UP.PREFERENCES AS PREFERENCES, "); builder.append(" II.ITEM_KEY AS ITEM_KEY "); builder.append(" FROM "); builder.append(" USER_PREFERENCE UP, "); builder.append(" INTERFACE_ITEM II "); builder.append(" WHERE "); builder.append(" II.ITEM_KEY = UP.ITEM_KEY AND "); builder.append(" UP.USER_ID = " + user.getUserId() + " AND "); builder.append(" UP.ITEM_KEY = (SELECT III.ITEM_KEY FROM INTERFACE_ITEM III WHERE III.ITEM_SHORT_DESC = '" + prefKey + "') "); RowMapper rowMapper = ( rs, rowNum ) -> { UserPreference data = new UserPreference(); data.setPreferences(rs.getString("preferences")); data.setItemKey(rs.getInt("item_key")); return data; }; List list = jdbcTemplate.query(builder.toString(), rowMapper); if (list == null || list.size() == 0) { String insertSql = "INSERT INTO USER_PREFERENCE (USER_ID, ITEM_KEY, PREFERENCES) VALUES (" + user.getUserId() + ", (SELECT ITEM_KEY FROM INTERFACE_ITEM WHERE ITEM_SHORT_DESC = '" + prefKey + "') ,'" + prefValue + "')"; jdbcTemplate.execute(insertSql); return new ActionResult("recordInserted"); } else { String updateSql = "UPDATE USER_PREFERENCE SET PREFERENCES = ? WHERE USER_ID = ? AND ITEM_KEY = ? "; jdbcTemplate.update(updateSql, prefValue, user.getUserId(), list.get(0).getItemKey()); return new ActionResult("recordUpdated"); } } @Override public List> getProductImageUrl ( int productId ) { String productImagePathSQL = "SELECT PI.IMAGE_URL as \"imageUrl\" FROM PRODUCT_IMAGES PI WHERE LOWER(PI.IMAGE_NAME) != 'logo' AND PI.PRODUCT_ID = ?"; List> imagePath = jdbcTemplate.queryForList(productImagePathSQL, productId); return imagePath; } @Override public List> getProductDimension ( int productId ) { return jdbcTemplate.queryForList( "select round(nvl(PRODUCT_LENGTH,0), 2) as \"length\", round(nvl(PRODUCT_WIDTH,0), 2) as \"width\", " + "round(nvl(PRODUCT_HEIGHT,0), 2) as \"height\", round(nvl(PRODUCT_WEIGHT,0), 2) as \"weight\", nvl(PRODUCT_CUBIC,0) as \"approxSize\" " + "from product where product_id=?", productId); } @Override public List> getTopThreeFactors ( int productId, int siteId, User user ) { List> topThreeFactors = jdbcTemplate.queryForList("SELECT P." + (("en".equals(user.getLanguage()) || user.getLanguage() == null) ? "PREDICTOR_DESC" : "PREDICTOR_DESC_FR") + " as PREDICTOR_DESC, " + " P." + (("en".equals(user.getLanguage()) || user.getLanguage() == null) ? "PREDICTOR_LONG_DESC" : "PREDICTOR_LONG_DESC_FR") + " as PREDICTOR_LONG_DESC " + "FROM " + "PREDICTOR P,HIERARCHY_TOP_PREDICTOR HP ,SITE_PRODUCT SP " + "WHERE " + "P.PREDICTOR_ID=HP.PREDICTOR_ID AND SP.SITE_ID = ? " + "AND PRODUCT_ID = ? " + "AND HP.HIERARCHY_ID=SP.LEVEL4_PARENT_ID " + "AND HP.FORECAST_MODEL_ID=SP.FORECAST_MODEL_ID " + "ORDER BY RANKING", siteId, productId); return topThreeFactors; } /* * (non-Javadoc) * * @see * com.napa.pulse.dao.interfaces.ReviewDAO#getUpdatedSiteSkuDetails(Integer, * java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, * java.lang.Integer) */ @Override public List> getUpdatedSiteSkuDetails ( User user, String mapFlag, Integer sessionId, Integer siteId, Integer productId, Integer vehicleCount ) throws PulseException { String sql; boolean returnCode = siteQueueMap.canStart(siteId, "getUpdatedSiteSkuDetails"); if (!returnCode) { throw new PulseException(PulseConstants.OPERATION_TIMEOUT); } else { try { /* * 1. Changing from Stocked to Return shall set the Keep quantity back to the * recommended Keep quantity and Return quantity back to On hand – Keep, only if * the SKU was originally recommended for return. */ switch (mapFlag) { case "S": jdbcTemplate.update( "update session_site_product set user_id = ?, keep_qty = (on_hand - RECOMMENDED_RETURN_QTY), hq_keep_qty = case when ? = 1 then hq_keep_qty else (on_hand - RECOMMENDED_RETURN_QTY) end " + "where session_id = ? and site_id = ? and product_id = ? and block_return is null and lt_std_pkg = 0", user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); break; // 2. Changing from Return to Stocked shall set the Keep // quantity to On hand and Return quantity to On hand - Keep // (this is taken care in DB table as Return = On Hand - Keep) case "R": sql = "update session_site_product set user_Id = ?, keep_qty = on_hand, hq_keep_qty = case when ? = 1 then hq_keep_qty else on_hand end where session_Id = ? and site_Id = ? and product_Id = ? and block_return is null AND CLASS <> 'O' and lt_std_pkg = 0"; jdbcTemplate.update(sql, user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); break; // 3. Changing from Order to Not Stocked shall set the Order // quantity to zero. case "O": sql = "update session_site_product set user_Id = ?, order_qty = 0, hq_order_qty = case when ? = 1 then hq_order_qty else 0 end where session_Id = ? and site_Id = ? and product_Id = ? and (block_order is null or effective_pts = 230) and lt_std_pkg = 0"; jdbcTemplate.update(sql, user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); break; // 4. Changing from Not Stocked to Order shall set the Order // quantity to Suggested Stocking quantity(initial_stock_amount // in DB) default: List> sessionType = jdbcTemplate.queryForList( "select PER_CAR_ORDER, PROVIDE_STORE_DEPTH " + "from pulse_session where session_id=?", sessionId); Map sessTypeMap = sessionType.get(0); List> product = jdbcTemplate.queryForList( "SELECT class, block_order FROM SESSION_SITE_PRODUCT WHERE SESSION_ID = ? AND SITE_ID = ? AND PRODUCT_ID = ?", sessionId, siteId, productId); if (product != null && product.size() > 0) { if (sessTypeMap.get("PER_CAR_ORDER").equals("1")) { jdbcTemplate.update("merge into session_site_product ssp using " + "(select ssp.session_id, ssp.site_id, ssp.product_id, ssp.initial_stock_amount, PER_CAR " + "from session_site_product ssp, product p " + "where session_id=? and site_id=? and ssp.product_id=? and block_order is null " + "AND ssp.CLASS <> 'O' and ssp.product_id=p.product_id) src " + "on (ssp.session_id=src.session_id and ssp.site_id=src.site_id and ssp.product_id=src.product_id) " + "when matched then update set user_id=?, " + "order_qty = (case when PER_CAR>0 and src.initial_stock_amount <= src.PER_CAR then src.PER_CAR else src.initial_stock_amount end), " + "hq_order_qty = case when ? = 1 then hq_order_qty else (case when PER_CAR>0 and src.initial_stock_amount <= src.PER_CAR then src.PER_CAR else src.initial_stock_amount end) end", sessionId, siteId, productId, user.getUserId(), user.isStoreUser() ? 1 : 0); } else if (((BigDecimal) sessTypeMap.get("PROVIDE_STORE_DEPTH")).intValueExact() == 1) { jdbcTemplate.update("merge into session_site_product ssp using " + "(select ssp.session_id, ssp.site_id, ssp.product_id, ssp.initial_stock_amount, PRODUCT_DEPTH_QTY " + "from session_site_product ssp " + "inner join site s on ssp.site_id=s.site_id " + "left join DC_PRODUCT_DEPTH p on p.dc_id=s.PRODUCT_AVAILABILITY_ID and ssp.product_id=p.product_id " + "where ssp.session_id=? and ssp.site_id=? and ssp.product_id=? and block_order is null AND ssp.CLASS <> 'O') src " + "on (ssp.session_id=src.session_id and ssp.site_id=src.site_id and ssp.product_id=src.product_id) " + "when matched then update set user_id=?, " + "order_qty = (case when nvl(PRODUCT_DEPTH_QTY,0)>0 then src.PRODUCT_DEPTH_QTY else src.initial_stock_amount end), " + "hq_order_qty = case when ? = 1 then hq_order_qty else (case when nvl(PRODUCT_DEPTH_QTY,0)>0 then src.PRODUCT_DEPTH_QTY else src.initial_stock_amount end) end", sessionId, siteId, productId, user.getUserId(), user.isStoreUser() ? 1 : 0); } else { jdbcTemplate.update( "update session_site_product set user_Id = ?, order_qty = initial_stock_amount, hq_order_qty = case when ? = 1 then hq_order_qty else initial_stock_amount end " + "where session_id = ? and site_id = ? and product_id = ? and (block_order is null or effective_pts = 230) AND CLASS <> 'O' ", user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); } } else { if (sessTypeMap.get("PER_CAR_ORDER").equals("1")) { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS, HQ_ORDER_QTY) " + " SELECT ?, SITE_ID, sp.PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " sp.INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " sp.CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " (case when p.PER_CAR>0 and sp.initial_stock_amount <= p.PER_CAR then p.PER_CAR else sp.initial_stock_amount end) AS ORDER_QTY, " + " NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS, case when ? = 1 then NULL else (case when p.PER_CAR>0 and sp.initial_stock_amount <= p.PER_CAR then p.PER_CAR else sp.initial_stock_amount end) END " + " FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " inner join product p on sp.product_id=p.product_id " + " WHERE SITE_ID = ? AND sp.PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); } else if (((BigDecimal) sessTypeMap.get("PROVIDE_STORE_DEPTH")).intValueExact() == 1) { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS, HQ_ORDER_QTY) " + " SELECT ?, sp.SITE_ID, sp.PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " sp.INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " sp.CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " (case when SITE_TYPE_CODE = 'DC' then sp.INITIAL_STOCK_AMOUNT " + " when PRODUCT_DEPTH_QTY>sp.INITIAL_STOCK_AMOUNT then PRODUCT_DEPTH_QTY " + " else sp.INITIAL_STOCK_AMOUNT end) AS ORDER_QTY, " + " NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS, case when ? = 1 then NULL else " + " (case when SITE_TYPE_CODE = 'DC' then sp.INITIAL_STOCK_AMOUNT " + " when PRODUCT_DEPTH_QTY>sp.INITIAL_STOCK_AMOUNT then PRODUCT_DEPTH_QTY " + " else sp.INITIAL_STOCK_AMOUNT end) end " + " FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " inner join site s on sp.site_id=s.site_id " + " left join DC_PRODUCT_DEPTH p on p.dc_id=s.PRODUCT_AVAILABILITY_ID and sp.product_id=p.product_id " + " WHERE sp.SITE_ID = ? AND sp.PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); } else { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS, HQ_ORDER_QTY) " + " SELECT ?, SITE_ID, PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " INITIAL_STOCK_AMOUNT AS ORDER_QTY, NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS, case when ? = 1 then NULL else INITIAL_STOCK_AMOUNT end FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " WHERE SITE_ID = ? AND PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, user.getUserId(), user.isStoreUser() ? 1 : 0, sessionId, siteId, productId); } } break; } // 5. In case of "special orders" that need to be returned, if // user clicks a Return pin, it will automatically switch part // to Stocked. // call is made to the procedure to recalculate the totals. SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); } finally { siteQueueMap.removeHead(siteId, "getUpdatedSiteSkuDetails"); } } // send back the updated data to the front List> siteSKUDetailsTableData = getSiteSKUDetailsTableData(sessionId, productId, siteId, vehicleCount); return siteSKUDetailsTableData; } @Override public List> setMapFlagForList ( Integer userId, String toMapFlag, Integer sessionId, Integer[] siteIds, Integer productId, Integer vehicleCount ) { String sql; StringBuilder siteSqlString = new StringBuilder("("); for (Integer id : siteIds) { siteSqlString.append(id).append(","); } siteSqlString.append(PulseConstants.DYNAMIC_QUERY_END_INTEGER); if ("NS".equals(toMapFlag)) { sql = "update session_site_product set user_Id = ?, order_qty = 0 where session_Id = ? and site_Id in " + siteSqlString + " and product_Id = ? and block_order is null"; jdbcTemplate.update(sql, userId, sessionId, productId); } else if ("R".equals(toMapFlag)) { jdbcTemplate.update( "update session_site_product set user_id = ?, keep_qty = (on_hand - RECOMMENDED_RETURN_QTY) " + "where session_id = ? and site_id in " + siteSqlString + " and product_id = ? and block_return is null", userId, sessionId, productId); } // 2. Changing from Return to Stocked shall set the Keep // quantity to On hand and Return quantity to On hand - Keep // (this is taken care in DB table as Return = On Hand - Keep) else if ("S".equals(toMapFlag)) { sql = "update session_site_product set user_Id = ?, keep_qty = on_hand where session_Id = ? and site_id in " + siteSqlString + " and product_Id = ? and block_return is null AND CLASS <> 'O'"; jdbcTemplate.update(sql, userId, sessionId, productId); } else { for (Integer siteId : siteIds) { List> sessionType = jdbcTemplate.queryForList( "select PER_CAR_ORDER, PROVIDE_STORE_DEPTH " + "from pulse_session where session_id=?", sessionId); Map sessTypeMap = sessionType.get(0); List> product = jdbcTemplate.queryForList( "SELECT class, block_order FROM SESSION_SITE_PRODUCT WHERE SESSION_ID = ? AND SITE_ID = ? AND PRODUCT_ID = ?", sessionId, siteId, productId); if (product != null && product.size() > 0) { if (sessTypeMap.get("PER_CAR_ORDER").equals("1")) { jdbcTemplate.update("merge into session_site_product ssp using " + "(select ssp.session_id, ssp.site_id, ssp.product_id, ssp.initial_stock_amount, PER_CAR " + "from session_site_product ssp, product p " + "where session_id=? and site_id=? and ssp.product_id=? and block_order is null " + "AND ssp.CLASS <> 'O' and ssp.product_id=p.product_id) src " + "on (ssp.session_id=src.session_id and ssp.site_id=src.site_id and ssp.product_id=src.product_id) " + "when matched then update set user_id=?, " + "order_qty = (case when nvl(PER_CAR,0)>0 then src.PER_CAR else src.initial_stock_amount end)", sessionId, siteId, productId, userId); } else if (((BigDecimal) sessTypeMap.get("PROVIDE_STORE_DEPTH")).intValueExact() == 1) { jdbcTemplate.update("merge into session_site_product ssp using " + "(select ssp.session_id, ssp.site_id, ssp.product_id, ssp.initial_stock_amount, PRODUCT_DEPTH_QTY " + "from session_site_product ssp " + "inner join site s on ssp.site_id=s.site_id " + "left join DC_PRODUCT_DEPTH p on p.dc_id=s.PRODUCT_AVAILABILITY_ID and ssp.product_id=p.product_id " + "where ssp.session_id=? and ssp.site_id=? and ssp.product_id=? and block_order is null AND ssp.CLASS <> 'O') src " + "on (ssp.session_id=src.session_id and ssp.site_id=src.site_id and ssp.product_id=src.product_id) " + "when matched then update set user_id=?, " + "order_qty = (case when nvl(PRODUCT_DEPTH_QTY,0)>0 then src.PRODUCT_DEPTH_QTY else src.initial_stock_amount end)", sessionId, siteId, productId, userId); } else { jdbcTemplate.update( "update session_site_product set user_Id = ?, order_qty = initial_stock_amount " + "where session_id = ? and site_id = ? and product_id = ? and block_order is null AND CLASS <> 'O' ", userId, sessionId, siteId, productId); } } else { if (sessTypeMap.get("PER_CAR_ORDER").equals("1")) { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS) " + " SELECT ?, SITE_ID, sp.PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " sp.INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " sp.CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " (case when PER_CAR>0 then PER_CAR else sp.INITIAL_STOCK_AMOUNT end) AS ORDER_QTY, " + " NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS " + " FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " inner join product p on sp.product_id=p.product_id " + " WHERE SITE_ID = ? AND sp.PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, userId, sessionId, siteId, productId); } else if (((BigDecimal) sessTypeMap.get("PROVIDE_STORE_DEPTH")).intValueExact() == 1) { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS) " + " SELECT ?, sp.SITE_ID, sp.PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " sp.INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " sp.CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " (case when PRODUCT_DEPTH_QTY>0 then PRODUCT_DEPTH_QTY else sp.INITIAL_STOCK_AMOUNT end) AS ORDER_QTY, " + " NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS " + " FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " inner join site s on sp.site_id=s.site_id " + " left join DC_PRODUCT_DEPTH p on p.dc_id=s.PRODUCT_AVAILABILITY_ID and sp.product_id=p.product_id " + " WHERE sp.SITE_ID = ? AND sp.PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, userId, sessionId, siteId, productId); } else { jdbcTemplate.update( "INSERT INTO SESSION_SITE_PRODUCT (SESSION_ID,SITE_ID,PRODUCT_ID,EFFECTIVE_PTS,ON_HAND,SOLD_LAST_12_MONTHS,MIN_STOCKING_QTY,MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT,LEVEL4_PARENT_ID,PRICE_WT_CORE,INITIAL_STOCKING_DT,DEMAND_12_MONTHS,OCCURANCE_12_MONTHS,OCCURANCE_18_MONTHS,OCCURANCE_24_MONTHS, " + " CLASS,KEEP_FLAG,DISPLAY_QTY,SOLD_LAST_24_MONTHS,VIO,LOST_SALES_12_MONTHS,LOST_SALES_24_MONTHS,ORDER_QTY,KEEP_QTY,PCT_MARKET,PTS,STD_PKG,RECOMMENDED_RETURN_QTY, " + " RECOMMENDED_ORDER_QTY,BLOCK_ORDER,BLOCK_RETURN,USER_ID,REASON_ID,FORECAST_MODEL_ID,PRIORITY_ORDERS,CLUSTER_PCT_SALE,DC_SALES_LAST_12_MONTHS,DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS,TRANSFER_24_MONTHS) " + " SELECT ?, SITE_ID, PRODUCT_ID, EFFECTIVE_PTS, ON_HAND, SOLD_LAST_12_MONTHS, MIN_STOCKING_QTY, MAX_STOCKING_QTY, " + " INITIAL_STOCK_AMOUNT, LEVEL4_PARENT_ID, PRICE_WT_CORE, INITIAL_STOCKING_DT, DEMAND_12_MONTHS, OCCURANCE_12_MONTHS, OCCURANCE_18_MONTHS, OCCURANCE_24_MONTHS, " + " CLASS, KEEP_FLAG, DISPLAY_QTY, SOLD_LAST_24_MONTHS, VIO, LOST_SALES_12_MONTHS, LOST_SALES_24_MONTHS, " + " INITIAL_STOCK_AMOUNT AS ORDER_QTY, NULL AS KEEP_QTY, PCT_MARKET, PTS, STD_PKG, NULL AS RECOMMENDED_RETURN_QTY, NULL AS RECOMMENDED_ORDER_QTY, " + " BLOCK_ORDER,BLOCK_RETURN, ? AS USER_ID, 1 AS REASON_ID, FORECAST_MODEL_ID, PRIORITY_ORDERS, CLUSTER_PCT_SALE, DC_SALES_LAST_12_MONTHS, DC_SALES_LAST_24_MONTHS, " + " TRANSFER_12_MONTHS, TRANSFER_24_MONTHS " + " FROM SITE_PRODUCT sp " + " inner join session_hierarchy sh on sh.session_id = ? and sp.level4_parent_id = sh.hierarchy_id " + " WHERE SITE_ID = ? AND PRODUCT_ID = ? " + " AND nvl(MIN_STOCKING_QTY,0) = 0 and block_order is null AND INCLUDE_ORDER = 1", sessionId, userId, sessionId, siteId, productId); } } } } // 5. In case of "special orders" that need to be returned, if // user clicks a Return pin, it will automatically switch part // to Stocked. // call is made to the procedure to recalculate the totals. for (Integer siteId : siteIds) { SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); } // send back the updated data to the front List> siteSKUDetailsTableData = getSiteSKUDetailsTableData(sessionId, productId, siteIds[0], vehicleCount); return siteSKUDetailsTableData; } @Override public List> getVehicleRegistrationTab ( int siteId, int productId ) { String sql = "select initcap((v.MAKE || ' ' || v.MODEL|| ' ' || v.SUB_MODEL)) AS \"vehicleDescription\", " + "(CASE WHEN ((MAX (v.model_year) - MIN (v.model_year)) = 0) THEN SUBSTR (MAX (v.model_year),3,4) " + "ELSE SUBSTR(MIN(v.model_year),3,4) || '-' || SUBSTR (MAX(v.model_year),3,4) END) as \"years\", " + "sum(p.vehicle_count) as \"vehicleCount\" " + "from (select vehicle_id, product_id from vehicle_fitment where product_id = ?) vf " + "join vehicle v on vf.vehicle_id = v.vehicle_id join POLK_POSTAL p on p.vehicle_id = v.vehicle_id " + "join (select MARKET_POSTAL, site_id from site_market where site_id = ?) sm on sm.MARKET_POSTAL = p.POSTAL " + "group by v.MAKE,v.MODEL,v.SUB_MODEL " + "order by \"vehicleCount\" desc, \"vehicleDescription\""; List> skuTableDataCount = jdbcTemplate.queryForList(sql, productId, siteId); return skuTableDataCount; } @Override public List> getVehicleApplicationRegistrationTab ( int productId ) { String sql = "select distinct initcap((v.MAKE || ' ' || v.MODEL|| ' ' || v.SUB_MODEL)) AS \"vehicleDescription\", " + "(CASE WHEN ((MAX (v.model_year) - MIN (v.model_year)) = 0) THEN SUBSTR (MAX (v.model_year),3,4) " + "ELSE SUBSTR(MIN(v.model_year),3,4) || '-' || SUBSTR (MAX(v.model_year),3,4) END) AS \"years\" " + "from vehicle v where vehicle_id in (select vehicle_id from vehicle_fitment where product_id=?) " + "group by v.MAKE,v.MODEL,v.SUB_MODEL " + "order by \"vehicleDescription\" "; List> skuTableDataCount = jdbcTemplate.queryForList(sql, productId); return skuTableDataCount; } @Override public List> getVehicleNoRegistrationTab ( int siteId, int productId ) { String sql = "select distinct initcap((v.MAKE || ' ' || v.MODEL|| ' ' || v.SUB_MODEL)) as \"vehicleDescription\", " + "(CASE WHEN ((MAX (v.model_year) - MIN (v.model_year)) = 0) THEN SUBSTR (MAX (v.model_year),3,4) " + "ELSE SUBSTR(MIN(v.model_year),3,4) || '-' || SUBSTR (MAX(v.model_year),3,4) END) AS \"years\", " + "0 as \"vehicleCount\" " + "from vehicle v " + "where vehicle_id in " + "((select vehicle_id from vehicle_fitment where product_id=?) minus " + "(select vehicle_id from POLK_POSTAL,site_market where POLK_POSTAL.POSTAL=site_market.MARKET_POSTAL and site_id=?)) " + "group by v.MAKE,v.MODEL,v.SUB_MODEL " + "order by \"vehicleDescription\" "; List> skuTableDataCount = jdbcTemplate.queryForList(sql, productId, siteId); return skuTableDataCount; } /* * (non-Javadoc) * * US340: SKU Review - Multi-Site Order Ability * * @see * com.napa.pulse.dao.interfaces.ReviewDAO#saveOrderReturn(com.napa.pulse.entity * .security.User, java.lang.Integer, java.lang.Integer) */ @Override public ActionResultItem>> revertAllOrdersToRecomended ( User user, Integer sessionId, Integer productId ) { ActionResultItem>> actionItem = new ActionResultItem<>(); try { jdbcTemplate.update( "update session_site_product set ORDER_QTY=RECOMMENDED_ORDER_QTY, HQ_ORDER_QTY = (case when ? = 1 then HQ_ORDER_QTY else RECOMMENDED_ORDER_QTY end) " + "where session_id=? and site_id in (select site_id from session_site where session_id=?) " + "and product_id=? and DECLINE_ORDER=0 and DECLINE_RETURN=0 ", user.isStoreUser() ? 1 : 0, sessionId, sessionId, productId); List siteLst = jdbcTemplate.queryForList("select site_id from session_site where session_id=?", Integer.class, sessionId); for (Integer siteId : siteLst) { // call is made to the procedure to recalculate the totals. SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); sessionDAO.reCalculateSessionTotals(sessionId, siteId); } actionItem.setSuccess(true); } catch (Exception e) { LOGGER.error("revertAllOrdersToRecomended: ", e); actionItem.setSuccess(false); } return actionItem; } /* * (non-Javadoc) * * US353: SKU Review - Multi Site Keep Ability * * @see * com.napa.pulse.dao.interfaces.ReviewDAO#saveOrderReturn(com.napa.pulse.entity * .security.User, java.lang.Integer, java.lang.Integer) */ @Override public ActionResultItem>> revertAllKeepsToRecommended ( User user, Integer sessionId, Integer productId ) { ActionResultItem>> actionItem = new ActionResultItem<>(); try { jdbcTemplate.update( "update session_site_product set KEEP_QTY=(ON_HAND-RECOMMENDED_RETURN_QTY), HQ_KEEP_QTY = (case when ? = 1 then HQ_KEEP_QTY else (ON_HAND-RECOMMENDED_RETURN_QTY) end) where session_id=? " + "and site_id in (select site_id from session_site where session_id=?) and product_id=? and DECLINE_ORDER=0 and DECLINE_RETURN=0", user.isStoreUser() ? 1 : 0, sessionId, sessionId, productId); List siteLst = jdbcTemplate.queryForList("select site_id from session_site where session_id=?", Integer.class, sessionId); for (Integer siteId : siteLst) { // call is made to the procedure to recalculate the totals. SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); Map inParamMap = new HashMap<>(); inParamMap.put("session_id_in", sessionId); inParamMap.put("site_id_in", siteId); inParamMap.put("product_id_in", productId); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in); sessionDAO.reCalculateSessionTotals(sessionId, siteId); } actionItem.setSuccess(true); } catch (Exception e) { LOGGER.error("revertAllKeepsToRecommended: ", e); actionItem.setSuccess(false); } return actionItem; } @Override public ActionResultItem>> updateSkuTableWidgetSetReviewedList ( Integer sessionId, SkuList[] skuListArr ) { ActionResultItem>> actionItem = new ActionResultItem<>(); try { boolean isFinalized = isSessionFinalized(sessionId); jdbcTemplate.batchUpdate( "update " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + "set REVIEWED=? where SESSION_ID=? " + "and SITE_ID in (select site_id from session_site where SESSION_ID=?) and PRODUCT_ID=?", new BatchPreparedStatementSetter() { @Override public void setValues ( PreparedStatement ps, int i ) throws SQLException { SkuList skuList = skuListArr[i]; ps.setBoolean(1, skuList.getIsReviewed()); ps.setInt(2, sessionId); ps.setInt(3, sessionId); ps.setInt(4, skuList.getProductId()); } @Override public int getBatchSize ( ) { return skuListArr.length; } }); actionItem.setSuccess(true); } catch (Exception e) { LOGGER.error("updateSkuTableWidgetSetReviewedList: ", e); actionItem.setSuccess(false); } return actionItem; } @Override public ActionResultItem>> updateSkuTableWidgetSetReviewedFilter ( SKUTableWidgetData skuTableWidgetData ) { ActionResultItem>> actionItem = new ActionResultItem<>(); int sessionId = skuTableWidgetData.getSessionId(); try { boolean isFinalized = isSessionFinalized(sessionId); String sql = "update " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + "set REVIEWED=? where SESSION_ID=? " + "and SITE_ID in (select site_id from session_site where SESSION_ID=?) and PRODUCT_ID in ("; sql += " select P.PRODUCT_ID "; sql += " from product p, " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " ssp "; // lost sales if (skuTableWidgetData.isSoldNotStocked()) { sql += " , SITE_PARAMETER SP, Site s "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " , Site s "; } // Similar Parts Filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (select distinct sp_.product_id, (sp_.SIMILAR_PRODUCT_ID) similar_product_id, order_qty from SESSION_SITE_PRODUCT ssp_, SIMILAR_PRODUCT sp_" + " where ssp_.SESSION_ID = " + skuTableWidgetData.getSessionId() + " and ssp_.site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + " )" + " and sp_.similar_PRODUCT_ID = ssp_.PRODUCT_ID) sim " + " , (SELECT DISTINCT sp.product_id, sim.similar_product_id," + " SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " , (SELECT DISTINCT sp.product_id, SUM( CASE WHEN sim_sp.min_stocking_qty > 0 THEN 1 ELSE 0 END) OVER (PARTITION BY sp.product_id) coverage" + " FROM site_product sp , similar_product sim, site_product sim_sp" + " WHERE sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sim_sp.site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")" + " AND sp.product_id = sim.product_id AND sim.similar_product_id = sim_sp.product_id ) similarproduct "; else sql += " , SIMILAR_PRODUCT similarproduct , (SELECT DISTINCT product_id FROM site_product WHERE site_id IN" + " (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")) sp "; } if (skuTableWidgetData.isDcStocking()) { sql += " , (select DISTINCT product_id,MIN_STOCKING_QTY,MAX_STOCKING_QTY " + "from site_product where site_id IN ( " + "SELECT site_id FROM site WHERE site_type_code = 'DC' AND " + "product_availability_id IN (SELECT product_availability_id FROM site WHERE site_type_code <> 'DC' " + "AND site_id IN (SELECT site_id FROM session_site WHERE session_id = " + skuTableWidgetData.getSessionId() + ")))) dc_sp "; } sql += " where ssp.session_id = ? and ssp.site_id in (select site_id from session_site where session_id = ? ) and ssp.product_id=p.product_id "; // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ssp.site_id=s.site_id "; } // expensiveItem if (skuTableWidgetData.isExpensiveItem()) { sql += " and ORDER_QTY*PRICE_WT_CORE > 500 "; } //FirstStockDate Filter if (isNotEmpty(skuTableWidgetData.getFirstStockToDt()) && isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt between '" + skuTableWidgetData.getFirstStockFromDt() + "' and '" + skuTableWidgetData.getFirstStockToDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockFromDt())) { sql += " and ssp.initial_stocking_dt >= '" + skuTableWidgetData.getFirstStockFromDt() + "' "; } else if (isNotEmpty(skuTableWidgetData.getFirstStockToDt())) { sql += " and ssp.initial_stocking_dt <='" + skuTableWidgetData.getFirstStockToDt() + "' "; } // largeOrderQty if (skuTableWidgetData.isLargeOrderQty()) { sql += " and ( ORDER_QTY > STD_PKG and ORDER_QTY > (PER_CAR * 2) ) "; } // Lost Sales if (skuTableWidgetData.isSoldNotStocked()) { sql += " and sp.site_id in (select site_id from session_site where session_id = ? ) " + "and ssp.SITE_ID=sp.SITE_ID and SSP.LEVEL4_PARENT_ID=sp.HIERARCHY_ID and sp.SITE_ID=s.SITE_ID " + " and (ssp.effective_pts = 230 and ssp.RECOMMENDED_ORDER_QTY > 0) "; } // obsolete filter if (skuTableWidgetData.isObsoleteSkus()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.CLASS = 'O' "; } // App / Non-App Filter if (skuTableWidgetData.isAppNonApp()) { if (("nonApplication").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NULL "; else if (("application").equals(skuTableWidgetData.getAppNonAppOption())) sql += " AND P.TOP_APP IS NOT NULL "; } // Reviewed if (skuTableWidgetData.getIsReviewed() != null && skuTableWidgetData.getIsReviewed()) { sql += " and ssp.REVIEWED=1 "; } else if (skuTableWidgetData.getIsReviewed() != null && !skuTableWidgetData.getIsReviewed()) { sql += " and NVL(ssp.REVIEWED, 0) = 0 "; } //PUL-7923 Stocked and Non Stocked if (skuTableWidgetData.isDcStocking() && ("stockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.max_stocking_qty, 0) > 0 ) "; } else if (skuTableWidgetData.isDcStocking() && ("nonstockedatdc").equals(skuTableWidgetData.getSelectedStockNonStockOption().trim())) { sql += " and (ssp.product_id = dc_sp.product_id(+) AND NVL(dc_sp.min_stocking_qty, 0) = 0 ) "; } // Fleet parts filter if (skuTableWidgetData.isFleets()) { sql += " and ssp.EFFECTIVE_PTS=" + EPTSRules.FLEET.value() + " "; } // Display Flag filter if (skuTableWidgetData.isDisplayFlag()) { sql += " and ssp.DISPLAY_QTY > 0 "; } // Keep Flag filter if (skuTableWidgetData.isKeepFlag()) { sql += " and ssp.KEEP_FLAG ='Y' "; } //Similar Parts filter if (skuTableWidgetData.isSimilarParts()) { if (("duplicationRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and (similarproduct.coverage > 0 OR sim.order_qty > 0)" + " and sim.product_id = ssp.product_id and (ssp.RECOMMENDED_ORDER_QTY > 0 or ssp.MIN_STOCKING_QTY > 0) "; else if (("coverageRisk").equals(skuTableWidgetData.getSimPartsOption())) sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID and similarproduct.coverage = 0 and NVL(ssp.MIN_STOCKING_QTY, 0) = 0 "; else sql += " and similarproduct.PRODUCT_ID = ssp.PRODUCT_ID AND similarproduct.similar_product_id = sp.product_id "; } // PUL-7215 // Low Vehicle Count filter -- PUL -7328 - Removed 'and ssp.recommended_order_qty > 0' // Operator check inclusion for PUL-7508 if (skuTableWidgetData.getLowVehicleCount() != null) { if (skuTableWidgetData.getLowVehicleOperator() != null && (skuTableWidgetData.getLowVehicleOperator().trim().equals("<") || skuTableWidgetData.getLowVehicleOperator().trim().equals(">"))) { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) " + skuTableWidgetData.getLowVehicleOperator().trim() + " " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } else { sql += " and nvl(ssp.VIO,0) >= 0 AND nvl(ssp.VIO,0) < " + skuTableWidgetData.getLowVehicleCount() + " AND P.TOP_APP IS NOT NULL "; } sql += " "; } // Supersedes filter if (skuTableWidgetData.isSupersedes()) { sql += " and ssp.product_id in (select SURVIVING_PRODUCT_ID from SUPERSEDE_PRODUCT where SURVIVING_PRODUCT_ID=ssp.product_id ) "; } // Specials filter if (skuTableWidgetData.isSpecials()) { sql += " and ssp.reason_id = 3 "; } //dcSales Filter if (skuTableWidgetData.getDcSalesMonth() != null) { //dcSales 12 Filter if (skuTableWidgetData.getDcSalesMonth() == 12) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_12_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_12_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_12_months >= " + skuTableWidgetData.getDcSalesMin(); } } //DcSales 24 Filter if (skuTableWidgetData.getDcSalesMonth() == 24) { if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMax() >= skuTableWidgetData.getDcSalesMin()) { sql += " and ssp.dc_sales_last_24_months between " + skuTableWidgetData.getDcSalesMin() + " and " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMax() != null && skuTableWidgetData.getDcSalesMin() == null) { sql += " and ssp.dc_sales_last_24_months <= " + skuTableWidgetData.getDcSalesMax(); } else if (skuTableWidgetData.getDcSalesMin() != null && skuTableWidgetData.getDcSalesMax() == null) { sql += " and ssp.dc_sales_last_24_months >= " + skuTableWidgetData.getDcSalesMin(); } } } // Overstock Filter if (skuTableWidgetData.isOverstock()) { sql += " and ssp.recommended_return_qty > 0 AND ssp.recommended_return_qty < ssp.on_hand "; } // 24 and Out filter if (skuTableWidgetData.isTwentyFourAndOut()) { sql += " and ssp.ON_HAND>0 and ssp.RECOMMENDED_RETURN_QTY>0 and ssp.MIN_STOCKING_QTY>0 and ssp.INITIAL_STOCKING_DT is not null and ssp.class != 'O' "; } //SalesPotential Filter if(skuTableWidgetData.getPtsMin() != null || skuTableWidgetData.getPtsMax() != null){ if (skuTableWidgetData.getPtsMin() != null && skuTableWidgetData.getPtsMax() != null && skuTableWidgetData.getPtsMax() >= skuTableWidgetData.getPtsMin()) { sql += " and nvl(ROUND(ssp.PTS*100),0) >= " + skuTableWidgetData.getPtsMin() + " and nvl(round(ssp.PTS*100),0) <= " + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMax() !=null && skuTableWidgetData.getPtsMin() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) <=" + skuTableWidgetData.getPtsMax(); }else if (skuTableWidgetData.getPtsMin() !=null && skuTableWidgetData.getPtsMax() ==null){ sql +="and ROUND(nvl(ssp.PTS,0) * 100) >=" +skuTableWidgetData.getPtsMin(); }} //DCR_PTS Filter if (skuTableWidgetData.getDcrPtsMin() != null && skuTableWidgetData.getDcrPtsMax() != null) { sql += " and ssp.DCR_PTS >= " + skuTableWidgetData.getDcrPtsMin() + " and ssp.DCR_PTS <= " + skuTableWidgetData.getDcrPtsMax(); } //SalesOccurr Filter if (skuTableWidgetData.getSalesOccurrMonth() != null) { //SalesOccurr 12 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 12) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_12_months, 0) + NVL(ssp.HSN_lost_sales_12_months, 0) + NVL(SSP.HSN_SUPERSEDE_12_MONTHS,0) ELSE" + " NVL(ssp.occurance_12_months, 0) + NVL(ssp.lost_sales_12_months, 0) + NVL(SSP.SUPERSEDE_12_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } //SalesOccurr 24 Filter if (skuTableWidgetData.getSalesOccurrMonth() == 24) { sql += " and ( CASE NVL(hs_part, 'X')" + "WHEN 'H' THEN NVL(ssp.HSN_occurance_24_months, 0) + NVL(ssp.HSN_lost_sales_24_months, 0) + NVL(SSP.HSN_SUPERSEDE_24_MONTHS,0) ELSE" + " NVL(ssp.occurance_24_months, 0) + NVL(ssp.lost_sales_24_months, 0) + NVL(SSP.SUPERSEDE_24_MONTHS,0) END )"; if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMax() >= skuTableWidgetData.getSalesOccurrMin()) { sql += " between " + skuTableWidgetData.getSalesOccurrMin() + " and " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMax() != null && skuTableWidgetData.getSalesOccurrMin() == null) { sql += " <= " + skuTableWidgetData.getSalesOccurrMax(); } else if (skuTableWidgetData.getSalesOccurrMin() != null && skuTableWidgetData.getSalesOccurrMax() == null) { sql += " >= " + skuTableWidgetData.getSalesOccurrMin(); } } } // Orders and Returns filters String orderFilter = ""; if (("recommended").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "ssp.ORDER_QTY > 0"; } else if (("declined").equals(skuTableWidgetData.getOrderOption())) { orderFilter = "(ssp.RECOMMENDED_ORDER_QTY <> 0 and ssp.ORDER_QTY = 0)"; } String returnFilter = ""; if (("recommended").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY > 0)"; } else if (("accepted").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RETURN_QTY = ssp.RECOMMENDED_RETURN_QTY and ssp.RETURN_QTY > 0)"; } else if (("declined").equals(skuTableWidgetData.getReturnOption())) { returnFilter = "(ssp.RECOMMENDED_RETURN_QTY <> 0 and ssp.RETURN_QTY = 0)"; } if (skuTableWidgetData.isReturn() && skuTableWidgetData.isOrder()) { sql += " and (" + orderFilter + " OR " + returnFilter + ") "; } else if (skuTableWidgetData.isReturn() && isNotEmpty(returnFilter)) { sql += " and " + returnFilter; } else if (skuTableWidgetData.isOrder() && isNotEmpty(orderFilter)) { sql += " and " + orderFilter; } // Hub & Spoke Filter //viewData if (("hubOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'H' "; } else if (("spokeOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART = 'S' "; } else if (("HSOnly").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NOT NULL "; } else if (("hideHS").equals(skuTableWidgetData.getHubSpokeOption())) { sql += " and ssp.HS_PART IS NULL "; } // New Parts filter if (skuTableWidgetData.isProspectParts()) { sql += " and ((ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0) " + "or (ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 and s.SITE_TYPE_CODE='DC' and ssp.EFFECTIVE_PTS > 0.25 )) "; } // filter by hierarchy if (skuTableWidgetData.getHierarchyId() > 0) { sql += " and ssp.LEVEL4_PARENT_ID in (select HIERARCHY_ID from product_hierarchy where HIERARCHY_LEVEL=4 " + "start with HIERARCHY_ID = " + skuTableWidgetData.getHierarchyId() + " connect by prior HIERARCHY_ID = PARENT_ID) "; } if (skuTableWidgetData.getHighSkuEditHierarchyId() != null) { sql += " and ssp.LEVEL4_PARENT_ID = " + skuTableWidgetData.getHighSkuEditHierarchyId() + " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } if (skuTableWidgetData.getHighSkuEdit() != null) { sql += " and ssp.PRODUCT_ID IN (select product_id " + " from session_site_product " + " where session_id = " + skuTableWidgetData.getSessionId() + " and site_id in (select site_id from session_site where session_id = " + skuTableWidgetData.getSessionId() + ") " + " group by product_id " + " having (case when max(case when recommended_return_qty > 0 and return_qty < recommended_return_qty then 1 else 0 end) = 1 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 1 and " + " max(case when order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when min_stocking_qty > 0 and (keep_qty is null or keep_qty > 0) then 1 else 0 end) = 0 then 1 " + " when max(case when recommended_order_qty > 0 then 1 else 0 end) = 0 and " + " max(case when order_qty > 0 then 1 else 0 end) = 1 then 1 " + " else 0 end) = 1 ) "; } // Line Abbr filter if (isNotEmpty(skuTableWidgetData.getLineAbbr())) { sql += " and P.FIELD_ABBR IN ( " + skuTableWidgetData.getLineAbbr() + ")"; } // Group Code if (skuTableWidgetData.getGroupCode() >= 0) { sql += " and P.GROUP_CODE = " + skuTableWidgetData.getGroupCode() + " "; } // Avg Age filter if (skuTableWidgetData.getAvgAgeMin() != null && skuTableWidgetData.getAvgAgeMax() != null) { sql += " and p.AVG_AGE between " + skuTableWidgetData.getAvgAgeMin() + " and " + skuTableWidgetData.getAvgAgeMax() + " "; } // Part Number filter if (isNotEmpty(skuTableWidgetData.getPartNumber())) { String partNumber = skuTableWidgetData.getPartNumber().toUpperCase().replaceAll("[^A-Z0-9]+", ""); if (partNumber.length() > 0) { sql += " and P.PART_NUMBER = '" + partNumber + "'"; } } sql += ")"; if (skuTableWidgetData.isSoldNotStocked()) { jdbcTemplate.update(sql, skuTableWidgetData.getReviewed(), sessionId, sessionId, sessionId, sessionId, sessionId); } else { jdbcTemplate.update(sql, skuTableWidgetData.getReviewed(), sessionId, sessionId, sessionId, sessionId); } actionItem.setSuccess(true); } catch (Exception e) { LOGGER.error("updateSkuTableWidgetSetReviewedFilter: ", e); actionItem.setSuccess(false); } return actionItem; } public boolean isSessionFinalized ( int sessionId ) { LOGGER.debug("ReviewDAOImpl.isSessionFinalized: " + sessionId); int status = 0; try { status = jdbcTemplate.queryForObject("SELECT STATUS_ID FROM PULSE_SESSION WHERE SESSION_ID = ?", new Object[]{sessionId}, Integer.class); } catch (Exception e) { LOGGER.error("Session " + sessionId + " was not found in PULSE_SESSION table."); } return status == 3; } @Override public List> getSimilarPartsWidgetData ( Integer sessionId, Integer siteId, Integer productId, Integer vehicleCount, boolean isSaveOrderReturn ) { boolean isFinalized = isSessionFinalized(sessionId); List> siteSKUTableData; String sitePSKUTableDataSQL = "SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " ssp.PRODUCT_ID as \"productId\", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS \"sku\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS \"lost24\", " // + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS \"dcSales12\", " // + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS \"dcSales24\", " + " nullif(dc_sp.dcSales12, 0) AS \"dcSales12\", " + " nullif(dc_sp.dcSales24, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND, 0) AS \"onHand\", " + " SSP.ORDER_QTY AS \"order\", " + " SSP.RETURN_QTY AS \"return\", " + " (case " + "when ssp.return_qty > 0 then 'R' " + "when ssp.order_qty > 0 then 'O' " + "when SSP.MIN_STOCKING_QTY > 0 OR (RETURN_QTY = 0 AND RECOMMENDED_RETURN_QTY > 0) then 'S' " + "when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as \"mapFlag\"," + " SSP.KEEP_QTY AS \"keep\", " + " nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG, 0) AS \"stdPack\", " + " nullif(SSP.MIN_STOCKING_QTY, 0) AS \"min\", " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS \"max\", " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as \"cost\", " + " (CASE " + "WHEN SSP.ORDER_QTY > 0 " + "THEN (SSP.PRICE_WT_CORE * SSP.ORDER_QTY) " + "WHEN SSP.RETURN_QTY > 0 " + "THEN -(SSP.PRICE_WT_CORE * SSP.RETURN_QTY) " + "ELSE null " + "END) AS \"extPrice\", " + " NVL(TO_CHAR(SSP.VIO), '-') AS \"vio\", " + " SSP.PCT_MARKET AS \"pctMrkt\", " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", nullif(SSP.DISPLAY_QTY, 0) AS \"displayQty\", " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", " + " SSP.KEEP_FLAG AS \"keepFlag\", " + " (case " + " when SSP.CLASS = 'O' then 'obsolete' " + " when ((ssp.PTS < NVL(sp.OFFSET,0)+0.5) and ssp.DEMAND_12_MONTHS > 1 and ssp.RECOMMENDED_ORDER_QTY > 0) then 'lostSales' " + " when ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 then 'prospectParts' " + " when nvl(ssp.system_recommended, 'N') = 'Y' and ssp.RECOMMENDED_ORDER_QTY > 0 then 'followerSku' " + " when (ssp.VIO > 0 AND ssp.VIO < " + vehicleCount + " and ssp.recommended_order_qty > 0 ) then 'lowVehicle' end ) as \"colorCode\", " + " S.LATITUDE, S.LONGITUDE, " + " (case when (ssp.block_order is not null) OR (recommended_return_qty is not null) OR (ssp.MIN_STOCKING_QTY > 0) then 1 else 0 end) as \"orderNotEditable\", " + " (case when (ssp.block_return is not null) OR (recommended_return_qty is null) then 1 else 0 end) as \"keepNotEditable\", " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\" , nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\", " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\", " + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as \"propensity\", " + " CASE WHEN NVL(SYSTEM_RECOMMENDED, 0) = 'Y' THEN 1 ELSE 0 END AS \"isFollowerSku\", CASE WHEN NVL(SYSTEM_FLAG, 0) = 'Y' THEN 1 ELSE 0 END AS \"isSystemSku\", " + " (case when (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') then 1 else null end) as \"isFleetSku\", " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " 1 as \"similarPartIsEditable\", " + (isSaveOrderReturn ? "0" : "1") + " as \"isFirst\", ssp.DECLINE_ORDER as \"declineOrder\", ssp.DECLINE_RETURN as \"declineReturn\" " + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " left join (SELECT /*+ INDEX (sp SITE_PRODUCT_PRODUCT_IDX) */ ss.site_id, sp.product_id, nullif(sp.dc_sales_last_12_months,0) as dcSales12, nullif(sp.dc_sales_last_24_months,0) as dcSales24 " + " FROM session_site ss " + " JOIN ( " + " SELECT s.site_id, dc.site_id dc_id " + " FROM site s, site dc " + " WHERE s.product_availability_id = dc.product_availability_id " + " AND s.site_type_code <> 'DC' " + " AND dc.site_type_code = 'DC' " + " AND s.active_flag = 'Y' AND dc.active_flag = 'Y' " + " AND s.virtual_site_flag IS NULL AND dc.virtual_site_flag IS NULL " + " ) dc ON ss.site_id= dc.site_id " + " JOIN site_product sp ON (sp.site_id = dc.dc_id) " + " WHERE session_id = :sessionId) dc_sp on ssp.product_id = dc_sp.product_id and ssp.site_id = dc_sp.site_id " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " WHERE SSP.session_id=:sessionId and SSP.site_id=:siteId and SSP.product_id=:productId "; String siteSKUTableDataSQL = "SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " SIMILAR_PRODUCT_ID as \"productId\", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS \"sku\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS \"lost24\", " // + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS \"dcSales12\", " // + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS \"dcSales24\", " + " nullif(dc_sp.dcSales12, 0) AS \"dcSales12\", " + " nullif(dc_sp.dcSales24, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND, 0) AS \"onHand\", " + " SSP.ORDER_QTY AS \"order\", " + " SSP.RETURN_QTY AS \"return\", " + " (case " + "when ssp.return_qty > 0 then 'R' " + "when ssp.order_qty > 0 then 'O' " + "when SSP.MIN_STOCKING_QTY > 0 OR (RETURN_QTY = 0 AND RECOMMENDED_RETURN_QTY > 0) then 'S' " + "when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as \"mapFlag\"," + " SSP.KEEP_QTY AS \"keep\", nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG, 0) AS \"stdPack\", " + " nullif(SSP.MIN_STOCKING_QTY, 0) AS \"min\", " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS \"max\", " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as \"cost\", " + " (case when nvl(ssp.MIN_STOCKING_QTY,0) = 0 and nvl(ssp.order_qty,0) > 0 then (SSP.PRICE_WT_CORE*nvl(ssp.order_qty,0)) " + " when nvl(ssp.MIN_STOCKING_QTY,0) = 0 and nvl(ssp.order_qty,0) = 0 then NULL " + " when nvl(ssp.MIN_STOCKING_QTY,0) > 0 and nvl(ssp.return_qty,0) > 0 then -(SSP.PRICE_WT_CORE*nvl(ssp.return_qty,0)) " + " END) AS \"extPrice\", " + " NVL(TO_CHAR(SSP.VIO), '-') AS \"vio\", " + " SSP.PCT_MARKET AS \"pctMrkt\", " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", " + " nullif(SSP.DISPLAY_QTY, 0) AS \"displayQty\", " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", " + " SSP.KEEP_FLAG AS \"keepFlag\", " + " (case " + " when SSP.CLASS = 'O' then 'obsolete' " + " when ((ssp.PTS < NVL(sp.OFFSET,0)+0.5) and ssp.DEMAND_12_MONTHS > 1 and ssp.RECOMMENDED_ORDER_QTY > 0) then 'lostSales' " + " when ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 then 'prospectParts' " + " when nvl(ssp.system_recommended, 'N') = 'Y' and ssp.RECOMMENDED_ORDER_QTY > 0 then 'followerSku' " + " when (ssp.VIO > 0 AND ssp.VIO < " + vehicleCount + " and ssp.recommended_order_qty > 0 ) then 'lowVehicle' end ) as \"colorCode\", " + " S.LATITUDE, S.LONGITUDE, " + " (case when (include_order = 0) OR (ssp.block_order is not null) OR (recommended_return_qty is not null) OR (ssp.MIN_STOCKING_QTY > 0) then 1 else 0 end) as \"orderNotEditable\", " + " (case when (ssp.block_return is not null) OR (recommended_return_qty is null) then 1 else 0 end) as \"keepNotEditable\", " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\" , nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\", " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\", " + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as \"propensity\", " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " CASE WHEN NVL(SYSTEM_RECOMMENDED, 0) = 'Y' THEN 1 ELSE 0 END AS \"isFollowerSku\", CASE WHEN NVL(SYSTEM_FLAG, 0) = 'Y' THEN 1 ELSE 0 END AS \"isSystemSku\", " + " (case when (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') then 1 else null end) as \"isFleetSku\", " + " 1 as \"similarPartIsEditable\", 0 as \"isFirst\", ssp.DECLINE_ORDER as \"declineOrder\", ssp.DECLINE_RETURN as \"declineReturn\", 'I' as \"source\" " + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP " + " INNER JOIN (select SIMILAR_PRODUCT_ID from SESSION_SITE_SIM_PRODUCT_V " + " where session_id=:sessionId and site_id=:siteId and product_id=:productId) sim on " + " ssp.session_id=:sessionId and ssp.site_id=:siteId and ssp.product_id=sim.SIMILAR_PRODUCT_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " left join (SELECT /*+ INDEX (sp SITE_PRODUCT_PRODUCT_IDX) */ ss.site_id, sp.product_id, nullif(sp.dc_sales_last_12_months,0) as dcSales12, nullif(sp.dc_sales_last_24_months,0) as dcSales24 " + " FROM session_site ss " + " JOIN ( " + " SELECT s.site_id, dc.site_id dc_id " + " FROM site s, site dc " + " WHERE s.product_availability_id = dc.product_availability_id " + " AND s.site_type_code <> 'DC' " + " AND dc.site_type_code = 'DC' " + " AND s.active_flag = 'Y' AND dc.active_flag = 'Y' " + " AND s.virtual_site_flag IS NULL AND dc.virtual_site_flag IS NULL " + " ) dc ON ss.site_id= dc.site_id " + " JOIN site_product sp ON (sp.site_id = dc.dc_id) " + " WHERE session_id = :sessionId) dc_sp on ssp.product_id = dc_sp.product_id and ssp.site_id = dc_sp.site_id " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " LEFT JOIN session_hierarchy sh on sh.session_id=:sessionId and ssp.LEVEL4_PARENT_ID=sh.HIERARCHY_ID" + " WHERE SSP.SESSION_ID = :sessionId "; String siteSKUTableDataNotEditableSQL = "SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " SIMILAR_PRODUCT_ID as \"productId\", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS \"sku\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS \"lost24\", " // + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS \"dcSales12\", " // + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS \"dcSales24\", " + " nullif(dc_sp.dcSales12, 0) AS \"dcSales12\", " + " nullif(dc_sp.dcSales24, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND, 0) AS \"onHand\", null AS \"order\"," + " null AS \"return\", null as \"mapFlag\"," + " null AS \"keep\", nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG, 0) AS \"stdPack\", nullif(SSP.MIN_STOCKING_QTY, 0) AS \"min\"," + " nullif(SSP.MAX_STOCKING_QTY, 0) AS \"max\", " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as \"cost\", " + " NVL(TO_CHAR(SSP.VIO), '-') AS \"vio\", SSP.PCT_MARKET AS \"pctMrkt\", " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", nullif(SSP.DISPLAY_QTY, 0) AS \"displayQty\"," + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", SSP.KEEP_FLAG AS \"keepFlag\"," + " null as \"colorCode\", " + " S.LATITUDE, S.LONGITUDE, " + " 0 as \"orderNotEditable\", " + " 0 as \"keepNotEditable\", " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\" , nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\"," + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\"," + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right'" + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right'" + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right'" + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left'" + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left'" + " else '' END) as \"propensity\", " + " 0 AS \"isFollowerSku\", 0 AS \"isSystemSku\"," + " null as \"isFleetSku\", " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " 0 as \"similarPartIsEditable\", 0 as \"isFirst\", 'I' as \"source\" " + " FROM SITE_PRODUCT SSP " + " INNER JOIN (select SIMILAR_PRODUCT_ID from SITE_SIM_PRODUCT_V sim where site_id=:siteId and product_id=:productId" + " and not exists (select 1 from session_site_product where session_id = :sessionId and site_id = :siteId " + " and product_id=sim.SIMILAR_PRODUCT_ID)) sim on ssp.site_id=:siteId and ssp.product_id=sim.SIMILAR_PRODUCT_ID" + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID" + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " left join (SELECT /*+ INDEX (sp SITE_PRODUCT_PRODUCT_IDX) */ ss.site_id, sp.product_id, nullif(sp.dc_sales_last_12_months,0) as dcSales12, nullif(sp.dc_sales_last_24_months,0) as dcSales24 " + " FROM session_site ss " + " JOIN ( " + " SELECT s.site_id, dc.site_id dc_id " + " FROM site s, site dc " + " WHERE s.product_availability_id = dc.product_availability_id " + " AND s.site_type_code <> 'DC' " + " AND dc.site_type_code = 'DC' " + " AND s.active_flag = 'Y' AND dc.active_flag = 'Y' " + " AND s.virtual_site_flag IS NULL AND dc.virtual_site_flag IS NULL " + " ) dc ON ss.site_id= dc.site_id " + " JOIN site_product sp ON (sp.site_id = dc.dc_id) " + " WHERE session_id = :sessionId) dc_sp on ssp.product_id = dc_sp.product_id and ssp.site_id = dc_sp.site_id " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " WHERE SSP.site_id=:siteId"; NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("sessionId", sessionId); parameters.addValue("siteId", siteId); parameters.addValue("productId", productId); if (isSaveOrderReturn) { siteSKUTableData = namedParameterJdbcTemplate.queryForList(sitePSKUTableDataSQL, parameters); } else { siteSKUTableData = namedParameterJdbcTemplate.queryForList(sitePSKUTableDataSQL, parameters); siteSKUTableData.addAll(namedParameterJdbcTemplate.queryForList(siteSKUTableDataSQL, parameters)); siteSKUTableData .addAll(namedParameterJdbcTemplate.queryForList(siteSKUTableDataNotEditableSQL, parameters)); } return siteSKUTableData; } /* * HUB Similar Parts (PUL-5021): - display, and allow to be edited, the similar * parts that are at the HUB and are in the session hierarchy as long as the HUB * is in session. - display only, no editing, the similar parts that are at the * HUB, but are not in the session hierarchy as long as the HUB is in session. - * If the HUB is not in session, then display only (no edit) any similar part at * the HUB. */ @Override public List> getHubSimilarPartsWidgetData ( Integer sessionId, Integer siteId, Integer productId, Integer vehicleCount, boolean isSaveOrderReturn ) { boolean isFinalized = isSessionFinalized(sessionId); List> siteSKUTableData; String sitePSKUTableDataSQL = "SELECT S.SITE_ID AS \"siteId\", S.SITE_NAME AS \"site\", " + " ssp.PRODUCT_ID as \"productId\", (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS \"sku\", " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As \"Address\", " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS \"sales12\", " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS \"sales24\", " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS \"lost12\", " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS \"lost24\", " + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS \"dcSales12\", " + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS \"dcSales24\", " + " nullif(SSP.ON_HAND, 0) AS \"onHand\", " + " SSP.ORDER_QTY AS \"order\", " + " SSP.RETURN_QTY AS \"return\", " + " (case " + "when ssp.return_qty > 0 then 'R' " + "when ssp.order_qty > 0 then 'O' " + "when SSP.MIN_STOCKING_QTY > 0 OR (RETURN_QTY = 0 AND RECOMMENDED_RETURN_QTY > 0) then 'S' " + "when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as \"mapFlag\"," + " SSP.KEEP_QTY AS \"keep\", " + " nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS \"suggestedStockingQty\", " + " nullif(P.JBR_STD_PKG, 0) AS \"stdPack\", " + " nullif(SSP.MIN_STOCKING_QTY, 0) AS \"min\", " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS \"max\", " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as \"cost\", " + " (CASE " + "WHEN SSP.ORDER_QTY > 0 " + "THEN (SSP.PRICE_WT_CORE * SSP.ORDER_QTY) " + "WHEN SSP.RETURN_QTY > 0 " + "THEN -(SSP.PRICE_WT_CORE * SSP.RETURN_QTY) " + "ELSE null " + "END) AS \"extPrice\", " + " NVL(TO_CHAR(SSP.VIO), '-') AS \"vio\", " + " SSP.PCT_MARKET AS \"pctMrkt\", " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS \"firstStockDate\", " + " nullif(SSP.DISPLAY_QTY, 0) AS \"displayQty\", " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS \"occurrence12\", " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS \"occurrence24\", " + " SSP.KEEP_FLAG AS \"keepFlag\", " + " (case " + " when SSP.CLASS = 'O' then 'obsolete' " + " when ((ssp.PTS < NVL(sp.OFFSET,0)+0.5) and ssp.DEMAND_12_MONTHS > 1 and ssp.RECOMMENDED_ORDER_QTY > 0) then 'lostSales' " + " when ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 then 'prospectParts' " + " when nvl(ssp.system_recommended, 'N') = 'Y' and ssp.RECOMMENDED_ORDER_QTY > 0 then 'followerSku' " + " when (ssp.VIO > 0 AND ssp.VIO < " + vehicleCount + " and ssp.recommended_order_qty > 0 ) then 'lowVehicle' end ) as \"colorCode\", " + " S.LATITUDE, S.LONGITUDE, " + " (case when (ssp.block_order is not null) OR (recommended_return_qty is not null) OR (ssp.MIN_STOCKING_QTY > 0) then 1 else 0 end) as \"orderNotEditable\", " + " (case when (ssp.block_return is not null) OR (recommended_return_qty is null) then 1 else 0 end) as \"keepNotEditable\", " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as \"peerSales\" , nullif(ssp.TRANSFER_12_MONTHS, 0) as \"transfer12\", " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as \"transfer24\", " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as \"superseded12\", nullif(ssp.SUPERSEDE_24_MONTHS, 0) as \"superseded24\", " + " nullif(ssp.PEER_SALES_12, 0) as \"peerSales12\", " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as \"propensity\", " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " CASE WHEN NVL(SYSTEM_RECOMMENDED, 0) = 'Y' THEN 1 ELSE 0 END AS \"isFollowerSku\", CASE WHEN NVL(SYSTEM_FLAG, 0) = 'Y' THEN 1 ELSE 0 END AS \"isSystemSku\", " + " (case when (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') then 1 else null end) as \"isFleetSku\", " + " 1 as \"similarPartIsEditable\", " + (isSaveOrderReturn ? "0" : "1") + " as \"isFirst\", ssp.DECLINE_ORDER as \"declineOrder\", ssp.DECLINE_RETURN as \"declineReturn\" " + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " WHERE SSP.session_id=:sessionId and SSP.site_id=:siteId and SSP.product_id=:productId "; String siteSKUTableDataSQL = "SELECT hubId AS \"hubId\", hubName AS \"hubName\", siteId AS \"siteId\", site AS \"site\"," + " productId AS \"productId\", sku AS \"sku\", address AS \"address\", sales12 AS \"sales12\", sales24 AS \"sales24\", " + " lost12 AS \"lost12\", lost24 AS \"lost24\", dcSales12 AS \"dcSales12\", dcSales24 AS \"dcSales24\"," + " onHand AS \"onHand\", O AS \"order\", R AS \"return\", mapFlag AS \"mapFlag\", keep AS \"keep\", " + " suggestedStockingQty AS \"suggestedStockingQty\", stdPack AS \"stdPack\", min AS \"min\", max AS \"max\", cost AS \"cost\", extPrice AS \"extPrice\", " + " vio AS \"vio\", pctMrkt AS \"pctMrkt\", firstStockDate AS \"firstStockDate\", " + " displayQty AS \"displayQty\", occurrence12 AS \"occurrence12\", occurrence24 AS \"occurrence24\", keepFlag AS \"keepFlag\", " + " colorCode AS \"colorCode\", latitude AS \"latitude\", longitude AS \"longitude\", " + " orderNotEditable AS \"orderNotEditable\", keepNotEditable AS \"keepNotEditable\", peerSales AS \"peerSales\", transfer12 AS \"transfer12\", " + " transfer24 AS \"transfer24\", superseded12 AS \"superseded12\", " + " superseded24 AS \"superseded24\", PEER_SALES_12 AS \"peerSales12\", PROPENSITY AS \"propensity\", FOLLOWER_SKU AS \"isFollowerSku\", " + " SYSTEM_SKU AS \"isSystemSku\", FLEET_SKU AS \"isFleetSku\", " + " SIM_PART_EDITABLE AS \"similarPartIsEditable\", IS_FIRST AS \"isFirst\", DECLINE_ORDER as \"declineOrder\", DECLINE_RETURN as \"declineReturn\", source as \"source\" from ( " + " SELECT /*+ ORDERED */ HUB_ID as hubId, (select site_name from site where site_id=hub_id) as hubName, " + " S.SITE_ID AS siteId, S.SITE_NAME AS site, " + " SIMILAR_PRODUCT_ID as productId, (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS sku, " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As Address, " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS sales12, " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS sales24, " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS lost12, " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS lost24, " + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS dcSales12, " + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS dcSales24, " + " nullif(SSP.ON_HAND, 0) AS onHand, SSP.ORDER_QTY AS O, " + " SSP.RETURN_QTY AS R, (case when ssp.return_qty > 0 then 'R' " + " when ssp.order_qty > 0 then 'O' " + " when SSP.MIN_STOCKING_QTY > 0 OR (RETURN_QTY = 0 AND RECOMMENDED_RETURN_QTY > 0) then 'S' " + " when nvl(SSP.MIN_STOCKING_QTY,0) = 0 then 'NS' else null end) as mapFlag, " + " SSP.KEEP_QTY AS keep, nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS suggestedStockingQty, " + " nullif(P.JBR_STD_PKG, 0) AS stdPack, nullif(SSP.MIN_STOCKING_QTY, 0) AS min, " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS max, " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as cost, " + " (case when nvl(ssp.MIN_STOCKING_QTY,0) = 0 and nvl(ssp.order_qty,0) > 0 then (SSP.PRICE_WT_CORE*nvl(ssp.order_qty,0)) " + " when nvl(ssp.MIN_STOCKING_QTY,0) = 0 and nvl(ssp.order_qty,0) = 0 then NULL " + " when nvl(ssp.MIN_STOCKING_QTY,0) > 0 and nvl(ssp.return_qty,0) > 0 then -(SSP.PRICE_WT_CORE*nvl(ssp.return_qty,0)) " + " END) AS extPrice, " + " NVL(TO_CHAR(SSP.VIO), '-') AS vio, SSP.PCT_MARKET AS pctMrkt, " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS firstStockDate, nullif(SSP.DISPLAY_QTY, 0) AS displayQty, " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS occurrence12, " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS occurrence24, SSP.KEEP_FLAG AS keepFlag, " + " (case when SSP.CLASS = 'O' then 'obsolete' " + " when ((ssp.PTS < NVL(sp.OFFSET,0)+0.5) and ssp.DEMAND_12_MONTHS > 1 and ssp.RECOMMENDED_ORDER_QTY > 0) then 'lostSales' " + " when ssp.FORECAST_MODEL_ID IN (0,200, 20000) AND ssp.RECOMMENDED_ORDER_QTY > 0 then 'prospectParts' " + " when nvl(ssp.system_recommended, 'N') = 'Y' and ssp.RECOMMENDED_ORDER_QTY > 0 then 'followerSku' " + " when (ssp.VIO > 0 AND ssp.VIO < " + vehicleCount + " and ssp.recommended_order_qty > 0 ) then 'lowVehicle' end ) as colorCode, " + " S.LATITUDE, S.LONGITUDE, " + " (case when (include_order = 0) OR (ssp.block_order is not null) OR (recommended_return_qty is not null) OR (ssp.MIN_STOCKING_QTY > 0) then 1 else 0 end) as orderNotEditable, " + " (case when (ssp.block_return is not null) OR (recommended_return_qty is null) then 1 else 0 end) as keepNotEditable, " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as peerSales , nullif(ssp.TRANSFER_12_MONTHS, 0) as transfer12, " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as transfer24, " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as superseded12, nullif(ssp.SUPERSEDE_24_MONTHS, 0) as superseded24, " + " nullif(ssp.PEER_SALES_12, 0) as PEER_SALES_12, " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as PROPENSITY, " + " CASE WHEN NVL(SYSTEM_RECOMMENDED, 0) = 'Y' THEN 1 ELSE 0 END AS FOLLOWER_SKU, CASE WHEN NVL(SYSTEM_FLAG, 0) = 'Y' THEN 1 ELSE 0 END AS SYSTEM_SKU, " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " (case when (FLEET_FLAG = 'U' or FLEET_FLAG = 'F') then 1 else null end) as FLEET_SKU, " + " 1 as SIM_PART_EDITABLE, 0 as IS_FIRST, SSP.DECLINE_ORDER, SSP.DECLINE_RETURN, 'I' as source " + " FROM " + (isFinalized ? " SESSION_SITE_PRODUCT_FINALIZED " : " SESSION_SITE_PRODUCT ") + " SSP " + " INNER JOIN (select SIMILAR_PRODUCT_ID, HUB_ID from HUB_SESSION_SITE_SIM_PRODUCT_V " + " where session_id=:sessionId and site_id=:siteId and product_id=:productId) sim on " + " ssp.session_id=:sessionId and ssp.site_id=:siteId and ssp.product_id=sim.SIMILAR_PRODUCT_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID " + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " LEFT JOIN session_hierarchy sh on sh.session_id=:sessionId and ssp.LEVEL4_PARENT_ID=sh.HIERARCHY_ID" + " WHERE SSP.SESSION_ID = :sessionId) " + " group by hubId, hubName, siteId, site, productId, sku, address, sales12, sales24, " + " lost12, lost24, dcSales12, dcSales24, onHand, O, R, mapFlag, keep, " + " suggestedStockingQty, stdPack, min, max, cost, extPrice, vio, pctMrkt, firstStockDate, " + " displayQty, occurrence12, occurrence24, keepFlag, colorCode, latitude, longitude, " + " orderNotEditable, keepNotEditable, peerSales, transfer12, transfer24, superseded12, " + " superseded24, PEER_SALES_12, PROPENSITY, FOLLOWER_SKU, SYSTEM_SKU, FLEET_SKU, " + " SIM_PART_EDITABLE, IS_FIRST, DECLINE_ORDER, DECLINE_RETURN, source " + " order by hubName "; String siteSKUTableDataNotEditableSQL = "SELECT hubId AS \"hubId\", hubName AS \"hubName\", siteId AS \"siteId\", site AS \"site\"," + " productId AS \"productId\", sku AS \"sku\", address AS \"address\", sales12 AS \"sales12\", sales24 AS \"sales24\", " + " lost12 AS \"lost12\", lost24 AS \"lost24\", dcSales12 AS \"dcSales12\", dcSales24 AS \"dcSales24\"," + " onHand AS \"onHand\", O AS \"order\", R AS \"return\", mapFlag AS \"mapFlag\", keep AS \"keep\", " + " suggestedStockingQty AS \"suggestedStockingQty\", stdPack AS \"stdPack\", min AS \"min\", max AS \"max\", " + " cost as \"cost\", vio AS \"vio\", pctMrkt AS \"pctMrkt\", firstStockDate AS \"firstStockDate\", " + " displayQty AS \"displayQty\", occurrence12 AS \"occurrence12\", occurrence24 AS \"occurrence24\", keepFlag AS \"keepFlag\", " + " colorCode AS \"colorCode\", latitude AS \"latitude\", longitude AS \"longitude\", " + " ORDER_NOT_EDITABLE AS \"orderNotEditable\", KEEP_NOT_EDITABLE AS \"keepNotEditable\", peerSales AS \"peerSales\", transfer12 AS \"transfer12\", " + " transfer24 AS \"transfer24\", superseded12 AS \"superseded12\", " + " superseded24 AS \"superseded24\", PEER_SALES_12 AS \"peerSales12\", PROPENSITY AS \"propensity\", FOLLOWER_SKU AS \"isFollowerSku\", " + " SYSTEM_SKU AS \"isSystemSku\", FLEET_SKU AS \"isFleetSku\", " + " SIM_PART_EDITABLE AS \"similarPartIsEditable\", IS_FIRST AS \"isFirst\", source as \"source\" from ( " + " SELECT /*+ ORDERED */ HUB_ID as hubId, (select site_name from site where site_id=hub_id) as hubName, " + " S.SITE_ID AS siteId, S.SITE_NAME AS site, " + " SIMILAR_PRODUCT_ID as productId, (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS sku, " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As Address, " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS sales12, " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS sales24, " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS lost12, " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS lost24, " + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS dcSales12, " + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS dcSales24, " + " nullif(SSP.ON_HAND, 0) AS onHand, null AS O, " + " null AS R, null as mapFlag, " + " null AS keep, nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS suggestedStockingQty, " + " nullif(P.JBR_STD_PKG, 0) AS stdPack, nullif(SSP.MIN_STOCKING_QTY, 0) AS min, " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS max, " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as cost, " + " NVL(TO_CHAR(SSP.VIO), '-') AS vio, SSP.PCT_MARKET AS pctMrkt, " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS firstStockDate, nullif(SSP.DISPLAY_QTY, 0) AS displayQty, " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS occurrence12, " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS occurrence24, SSP.KEEP_FLAG AS keepFlag, " + " null as colorCode, " + " S.LATITUDE, S.LONGITUDE, " + " 0 as ORDER_NOT_EDITABLE, " + " 0 as KEEP_NOT_EDITABLE, " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as peerSales , nullif(ssp.TRANSFER_12_MONTHS, 0) as transfer12, " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as transfer24, " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as superseded12, nullif(ssp.SUPERSEDE_24_MONTHS, 0) as superseded24, " + " nullif(ssp.PEER_SALES_12, 0) as PEER_SALES_12, " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as PROPENSITY, " + " 0 AS \"FOLLOWER_SKU\", 0 AS \"SYSTEM_SKU\"," + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " null as \"FLEET_SKU\", " + " 0 as \"SIM_PART_EDITABLE\", 0 as \"IS_FIRST\", 'I' as source " + " FROM (select SIMILAR_PRODUCT_ID, HUB_ID from HUB_SITE_SIM_PRODUCT_V sim where site_id=:siteId and product_id=:productId and SIMILAR_PRODUCT_ID is not null) A " + " LEFT JOIN SITE_PRODUCT SSP on ssp.site_id=:siteId and ssp.product_id=A.SIMILAR_PRODUCT_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID" + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID " + " where not exists ( select 1 from session_hierarchy where session_id=:sessionId and hierarchy_id=ssp.LEVEL4_PARENT_ID)) " + " group by hubId, hubName, siteId, site, productId, sku, address, sales12, sales24, " + " lost12, lost24, dcSales12, dcSales24, onHand, O, R, mapFlag, keep, " + " suggestedStockingQty, stdPack, min, max, cost, vio, pctMrkt, firstStockDate, " + " displayQty, occurrence12, occurrence24, keepFlag, colorCode, latitude, longitude, " + " ORDER_NOT_EDITABLE, KEEP_NOT_EDITABLE, peerSales, transfer12, transfer24, superseded12, " + " superseded24, PEER_SALES_12, PROPENSITY, FOLLOWER_SKU, SYSTEM_SKU, FLEET_SKU, " + " SIM_PART_EDITABLE, IS_FIRST, source " + " order by hubName "; String siteSKUTableDataNotEditableNoHUBSQL = "SELECT hubId AS \"hubId\", hubName AS \"hubName\", siteId AS \"siteId\", site AS \"site\"," + " productId AS \"productId\", sku AS \"sku\", address AS \"address\", sales12 AS \"sales12\", sales24 AS \"sales24\", " + " lost12 AS \"lost12\", lost24 AS \"lost24\", dcSales12 AS \"dcSales12\", dcSales24 AS \"dcSales24\"," + " onHand AS \"onHand\", O AS \"order\", R AS \"return\", mapFlag AS \"mapFlag\", keep AS \"keep\", " + " suggestedStockingQty AS \"suggestedStockingQty\", stdPack AS \"stdPack\", min AS \"min\", max AS \"max\", cost AS \"cost\", extPrice AS \"extPrice\", " + " vio AS \"vio\", pctMrkt AS \"pctMrkt\", firstStockDate AS \"firstStockDate\", " + " displayQty AS \"displayQty\", occurrence12 AS \"occurrence12\", occurrence24 AS \"occurrence24\", keepFlag AS \"keepFlag\", " + " colorCode AS \"colorCode\", latitude AS \"latitude\", longitude AS \"longitude\", " + " ORDER_NOT_EDITABLE AS \"orderNotEditable\", KEEP_NOT_EDITABLE AS \"keepNotEditable\", peerSales AS \"peerSales\", transfer12 AS \"transfer12\", " + " transfer24 AS \"transfer24\", superseded12 AS \"superseded12\", " + " superseded24 AS \"superseded24\", PEER_SALES_12 AS \"peerSales12\", PROPENSITY AS \"propensity\", FOLLOWER_SKU AS \"isFollowerSku\", " + " SYSTEM_SKU AS \"isSystemSku\", FLEET_SKU AS \"isFleetSku\", " + " SIM_PART_EDITABLE AS \"similarPartIsEditable\", IS_FIRST AS \"isFirst\", source as \"source\" from ( " + " SELECT /*+ ORDERED */ HUB_ID as hubId, (select site_name from site where site_id=hub_id) as hubName, " + " S.SITE_ID AS siteId, S.SITE_NAME AS site, " + " SIMILAR_PRODUCT_ID as productId, (P.FIELD_ABBR || ' ' || P.EXT_PART_NUMBER) AS sku, " + " (S.Address1 || ', ' || S.Address2 || ', ' || S.CITY || ', ' || " + " S.STATE || ', ' || S.Postal_Code || ', ' || S.Country) As Address, " + " nullif(SSP.SOLD_LAST_12_MONTHS, 0) AS sales12, " + " nullif(SSP.SOLD_LAST_24_MONTHS, 0) AS sales24, " + " nullif(SSP.LOST_SALES_12_MONTHS, 0) AS lost12, " + " nullif(SSP.LOST_SALES_24_MONTHS, 0) AS lost24, " + " nullif(SSP.DC_SALES_LAST_12_MONTHS, 0) AS dcSales12, " + " nullif(SSP.DC_SALES_LAST_24_MONTHS, 0) AS dcSales24, " + " nullif(SSP.ON_HAND, 0) AS onHand, null AS O, " + " null AS R, null as mapFlag, " + " null AS keep, nullif(SSP.INITIAL_STOCK_AMOUNT, 0) AS suggestedStockingQty, " + " nullif(P.JBR_STD_PKG, 0) AS stdPack, nullif(SSP.MIN_STOCKING_QTY, 0) AS min, " + " (case when (SITE_TYPE_CODE = 'COJ' or SITE_TYPE_CODE = 'J') then p.GOLDEN_PRICE else p.DC_PRICE end) as cost, " + " nullif(SSP.MAX_STOCKING_QTY, 0) AS max, null AS extPrice, " + " NVL(TO_CHAR(SSP.VIO), '-') AS vio, SSP.PCT_MARKET AS pctMrkt, " + " TO_CHAR(CAST(SSP.INITIAL_STOCKING_DT AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') AS firstStockDate, nullif(SSP.DISPLAY_QTY, 0) AS displayQty, " + " nullif(SSP.OCCURANCE_12_MONTHS, 0) AS occurrence12, " + " nullif(SSP.OCCURANCE_24_MONTHS, 0) AS occurrence24, SSP.KEEP_FLAG AS keepFlag, " + " null as colorCode, " + " S.LATITUDE, S.LONGITUDE, " + " 0 as ORDER_NOT_EDITABLE, " + " 0 as KEEP_NOT_EDITABLE, " + " round(NVL(ssp.CLUSTER_PCT_SALE,0),3) as peerSales , nullif(ssp.TRANSFER_12_MONTHS, 0) as transfer12, " + " nullif(ssp.TRANSFER_24_MONTHS, 0) as transfer24, " + " nullif(ssp.SUPERSEDE_12_MONTHS, 0) as superseded12, nullif(ssp.SUPERSEDE_24_MONTHS, 0) as superseded24, " + " nullif(ssp.PEER_SALES_12, 0) as PEER_SALES_12, " + " (case when (sp.PTS >= 0 and sp.PTS < 0.3) then '1_red_right' " + " when (sp.PTS >= 0.3 and sp.PTS < 0.4) then '2_yellow_right' " + " when (sp.PTS >= 0.4 and sp.PTS < 0.5) then '3_green_right' " + " when (sp.PTS = 0.5) then '4_green' " + " when (sp.PTS > 0.5 and sp.PTS <= 0.6) then '5_green_left' " + " when (sp.PTS > 0.6 and sp.PTS <= 0.7) then '6_yellow_left' " + " when (sp.PTS > 0.7 and sp.PTS < 1) then '7_red_left' " + " else '' END) as PROPENSITY, " + " TO_CHAR(CAST(ssp.last_sale_dt AS TIMESTAMP WITH TIME ZONE), 'YYYY-MM-DD\"T\"HH24:MI:SS.FF3TZHTZM') as \"lastSaleDate\", " + " 0 AS \"FOLLOWER_SKU\", 0 AS \"SYSTEM_SKU\"," + " null as \"FLEET_SKU\", " + " 0 as \"SIM_PART_EDITABLE\", 0 as \"IS_FIRST\", 'I' as source " + " FROM (select SIMILAR_PRODUCT_ID, HUB_ID from HUB_SITE_SIM_PRODUCT_V sim where site_id=:siteId and product_id=:productId and SIMILAR_PRODUCT_ID is not null) A " + " LEFT JOIN SITE_PRODUCT SSP on ssp.site_id=:siteId and ssp.product_id=A.SIMILAR_PRODUCT_ID " + " INNER JOIN PRODUCT P ON SSP.PRODUCT_ID = P.PRODUCT_ID" + " INNER JOIN SITE S ON S.SITE_ID = SSP.SITE_ID " + " LEFT JOIN SITE_PRODUCT sp ON sp.site_id=ssp.site_id and sp.product_id = ssp.product_id " + " LEFT JOIN SITE_PARAMETER sp ON ssp.SITE_ID=sp.SITE_ID and ssp.LEVEL4_PARENT_ID=sp.HIERARCHY_ID) " + " group by hubId, hubName, siteId, site, productId, sku, address, sales12, sales24, " + " lost12, lost24, dcSales12, dcSales24, onHand, O, R, mapFlag, keep, " + " suggestedStockingQty, stdPack, min, max, cost, extPrice, vio, pctMrkt, firstStockDate, " + " displayQty, occurrence12, occurrence24, keepFlag, colorCode, latitude, longitude, " + " ORDER_NOT_EDITABLE, KEEP_NOT_EDITABLE, peerSales, transfer12, transfer24, superseded12, " + " superseded24, PEER_SALES_12, PROPENSITY, FOLLOWER_SKU, SYSTEM_SKU, FLEET_SKU, " + " SIM_PART_EDITABLE, IS_FIRST, source " + " order by hubName "; boolean isHubInSession = false; String isHubInSessionSQL = "select 1 from session_site where session_id=:sessionId and site_id in (select HUB_ID from HUB_SITE_SIM_PRODUCT_V " + "sim where site_id=:siteId and product_id=:productId and SIMILAR_PRODUCT_ID is not null)"; NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("sessionId", sessionId); parameters.addValue("siteId", siteId); parameters.addValue("productId", productId); SqlRowSet rs = namedParameterJdbcTemplate.queryForRowSet(isHubInSessionSQL, parameters); while (rs.next()) { isHubInSession = true; } if (isSaveOrderReturn) { siteSKUTableData = namedParameterJdbcTemplate.queryForList(sitePSKUTableDataSQL, parameters); } else if (isHubInSession) { siteSKUTableData = namedParameterJdbcTemplate.queryForList(sitePSKUTableDataSQL, parameters); siteSKUTableData.addAll(namedParameterJdbcTemplate.queryForList(siteSKUTableDataSQL, parameters)); siteSKUTableData .addAll(namedParameterJdbcTemplate.queryForList(siteSKUTableDataNotEditableSQL, parameters)); } else { siteSKUTableData = namedParameterJdbcTemplate.queryForList(sitePSKUTableDataSQL, parameters); siteSKUTableData .addAll(namedParameterJdbcTemplate.queryForList(siteSKUTableDataNotEditableNoHUBSQL, parameters)); } return siteSKUTableData; } @Override public HubSpokeSitesDTO getHubSpokeFlag ( Integer sessionId , Integer userId ) { HubSpokeSitesDTO dto = new HubSpokeSitesDTO ( ); List hubspokeFlagforfilter = new ArrayList<>(); try { SqlRowSet rs2 = jdbcTemplate.queryForRowSet ( "SELECT " + "ss.site_id, "+ " case " + "when (select count(1) from hub_spoke_network_mapping where hsn_site_id = ss.site_id and is_active=1)>0 then 'true' " + "else 'false' end as flagofhubspoke FROM " + "session_site ss " + "WHERE ss.session_id= "+sessionId ); while (rs2.next ( )) { hubspokeFlagforfilter.add(rs2.getString("flagofhubspoke")); } dto.setHubspokeFlagforfilter(hubspokeFlagforfilter); } catch ( Exception ex ) { LOGGER.error ( "Exception in GetHubSpokeFlagsforfilter for sessionId : " + sessionId ); LOGGER.error ( "Exception message is: " + ex.getMessage ( ) ); LOGGER.error ( "Exception stacktrace is: " + Arrays.toString ( ex.getStackTrace ( ) ) ); } return dto; } @Override public boolean updateSkuEditCount ( SkuReviewEditDTO skuReviewEditDTO ) { try { String sqlQuery = "MERGE INTO sku_edit_count " + "USING DUAL " + "ON (session_id = " + skuReviewEditDTO.getSessionId() + " AND user_id = " + skuReviewEditDTO.getUserId() + " AND edit_type = '" + skuReviewEditDTO.getEditType() + "') " + "WHEN MATCHED THEN UPDATE SET edit_count = edit_count + 1, last_updated_time = SYSDATE " + "WHEN NOT MATCHED THEN INSERT (session_id, user_id, edit_type, edit_count, last_updated_time) VALUES " + "(" + skuReviewEditDTO.getSessionId() + " , " + skuReviewEditDTO.getUserId() + ", '" + skuReviewEditDTO.getEditType() + "', 1, sysdate)"; jdbcTemplate.execute(sqlQuery); } catch (Exception e) { LOGGER.error("exception in updateSkuEditCount"); } return true; } @Override public String getBlockOrderSuggestion ( Integer sessionId, Integer siteId, Integer productId, Boolean isBlockOrder, User user ) { try { if (isBlockOrder) {// blockOrder = Y String updateSiteProduct = "UPDATE SITE_PRODUCT SET BLOCK_ORDER = 'Y',\n" + "BUSINESS_RULES_APPLIED = SUBSTR(business_rules_applied, 1,1) || 'S' || SUBSTR(business_rules_applied, 3,1)\n" + "WHERE SITE_ID = ? AND PRODUCT_ID = ?"; jdbcTemplate.update(updateSiteProduct, ps -> { ps.setInt(1, siteId); ps.setInt(2, productId); }); SqlRowSet rs = jdbcTemplate.queryForRowSet("select product_id from PRODUCT_OVERRIDE where product_id = ? and site_id = ? ", productId, siteId); if (rs.next()) { jdbcTemplate.update( "UPDATE PRODUCT_OVERRIDE SET IS_ACTIVE = ? WHERE PRODUCT_ID = ? AND SITE_ID = ? AND OVERRIDE_ID = ?", ps -> { ps.setInt(1, 1); ps.setInt(2, productId); ps.setInt(3, siteId); ps.setInt(4, 2); }); } else { String flag = jdbcTemplate.queryForObject(" SELECT NVL(site_type_code,'nonDC') from site where SITE_ID = " + siteId, String.class); String dcSql = "INSERT INTO PRODUCT_OVERRIDE (PRODUCT_ID,SITE_ID,OVERRIDE_ID,APPLY_TO_STORE,IS_ACTIVE) VALUES(?,?,?,?,?)"; if (("DC").equalsIgnoreCase(flag)) dcSql = "INSERT INTO PRODUCT_OVERRIDE (PRODUCT_ID,SITE_ID,OVERRIDE_ID,APPLY_TO_DC,IS_ACTIVE) VALUES(?,?,?,?,?)"; jdbcTemplate.update(dcSql, ps -> { ps.setInt(1, productId); ps.setInt(2, siteId); ps.setInt(3, 2); ps.setInt(4, 1); ps.setInt(5, 1); } ); } } else { // blockOrder = N jdbcTemplate.update( "UPDATE PRODUCT_OVERRIDE SET IS_ACTIVE = ? WHERE PRODUCT_ID = ? AND SITE_ID = ? AND OVERRIDE_ID = ?", ps -> { ps.setInt(1, 0); ps.setInt(2, productId); ps.setInt(3, siteId); ps.setInt(4, 2); }); int overrideId = jdbcTemplate.queryForObject("Select NVL(OVERRIDE_ID,0) from PRODUCT_OVERRIDE WHERE PRODUCT_ID = " + productId + " AND SITE_ID = " + siteId, Integer.class); if (overrideId == 2) { jdbcTemplate.update("UPDATE SITE_PRODUCT SET BLOCK_ORDER = 'N'," + " business_rules_applied = SUBSTR(business_rules_applied, 1,1) || '0' || SUBSTR(business_rules_applied, 3,1)" + " WHERE SITE_ID = ? AND PRODUCT_ID = ? AND SUBSTR(business_rules_applied, 2,1) = 'S'", ps -> { ps.setInt(1, siteId); ps.setInt(2, productId); }); } } SqlRowSet rps = jdbcTemplate.queryForRowSet("Select SITE_ID from SESSION_SITE_PRODUCT WHERE PRODUCT_ID = ? AND SITE_ID = ? AND SESSION_ID = ? ", productId, siteId, sessionId); String initialStockAmount = jdbcTemplate.queryForObject("Select initial_stock_amount from SESSION_SITE_PRODUCT WHERE PRODUCT_ID = " + productId + " AND SITE_ID = " + siteId + " AND SESSION_ID = " + sessionId, String.class); SqlRowSet businessRuleQuery = jdbcTemplate.queryForRowSet("select SUBSTR(business_rules_applied, 1,1) || 'S' || SUBSTR(business_rules_applied, 3,1) business_rules_applied from session_site_product \n" + "where product_id = ? and site_id =? and session_id = ? ", productId, siteId, sessionId); String businessRule = ""; if (businessRuleQuery.next()) { businessRule = businessRuleQuery.getString(1); } if (rps.next()) { String finalBusinessRule = businessRule; if (!isBlockOrder && initialStockAmount == null) { jdbcTemplate.update("UPDATE SESSION_SITE_PRODUCT SET BLOCK_ORDER = ?, BUSINESS_RULES_APPLIED = SUBSTR(business_rules_applied, 1,1) || '0' || SUBSTR(business_rules_applied, 3,1) WHERE PRODUCT_ID = ? AND SITE_ID = ? AND SESSION_ID = ? ", ps -> { ps.setString(1, "N"); //ps.setString(2, finalBusinessRule); ps.setInt(2, productId); ps.setInt(3, siteId); ps.setInt(4, sessionId); }); } else { // jdbcTemplate.update("UPDATE SESSION_SITE_PRODUCT SET BLOCK_ORDER = ?, BUSINESS_RULES_APPLIED = ?, ORDER_QTY = ? WHERE PRODUCT_ID = ? AND SITE_ID = ? AND SESSION_ID = ? ", // ps -> { if (isBlockOrder) { jdbcTemplate.update("UPDATE SESSION_SITE_PRODUCT SET BLOCK_ORDER = 'Y', ORDER_QTY = '0'," + " business_rules_applied = SUBSTR(business_rules_applied, 1,1) || 'S' || SUBSTR(business_rules_applied, 3,1)" + " WHERE SITE_ID = ? AND PRODUCT_ID = ? AND SESSION_ID = ? ", ps -> { ps.setInt(1, siteId); ps.setInt(2, productId); ps.setInt(3, sessionId); }); } else { jdbcTemplate.update("UPDATE SESSION_SITE_PRODUCT SET BLOCK_ORDER = 'N', ORDER_QTY = ?," + " business_rules_applied = SUBSTR(business_rules_applied, 1,1) || '0' || SUBSTR(business_rules_applied, 3,1)" + " WHERE SITE_ID = ? AND PRODUCT_ID = ? AND SESSION_ID = ? AND SUBSTR(business_rules_applied, 2,1) = 'S'", ps -> { ps.setString(1, initialStockAmount); ps.setInt(2, siteId); ps.setInt(3, productId); ps.setInt(4, sessionId); }); } //ps.setString(2, finalBusinessRule); // }); // SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate) // .withProcedureName("CALC_TOTAL_SAVE_ORD_RET"); // Map inParamMap = new HashMap<>(); // inParamMap.put("session_id_in", sessionId); // inParamMap.put("site_id_in", siteId); // inParamMap.put("product_id_in", productId); // SqlParameterSource in = new MapSqlParameterSource(inParamMap); // simpleJdbcCall.execute(in); List> hierarchyItemMap = commonService.getHierarchyPath(productId, user); Map level4 = hierarchyItemMap.get(3); BigDecimal level4_hierarchyId = (BigDecimal) level4.get("hierarchyId"); SimpleJdbcCall simpleJdbcCal = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("DECLINE_ORDERS"); Map inParamMapp = new HashMap<>(); inParamMapp.put("sessionid_in", sessionId); inParamMapp.put("siteid_in", siteId); inParamMapp.put("hierarchyid_in", level4_hierarchyId); inParamMapp.put("decline_order_in", -1); inParamMapp.put("update_hq_values_in", 0); SqlParameterSource inn = new MapSqlParameterSource(inParamMapp); simpleJdbcCal.execute(inn); } } } catch (Exception e) { e.printStackTrace(); return "{\"success\":false}"; } return "{\"success\":true}"; } @Override public String getStockedNonStockedData ( Integer sessionId ) { String sql1 = "select case when Count(DISTINCT(product_availability_id)) > 1 then 'true' else 'false' end as sNsRes\n" + "from site where site_id in \n" + "(select site_id from session_site where session_id =? )"; String siteCount = jdbcTemplate.queryForObject(sql1, String.class, sessionId); return siteCount; } @Override public List getSiteSkuMinQtyCount ( Integer sessionId ,String siteList, Integer productId ) { if (siteList.length ()>0) { List hubSiteProductsList = new ArrayList<> ( ); String query = "select Distinct hsn_network_id,hsn_site_id from hub_spoke_network_mapping where hsn_site_id in (" + siteList + ") and is_active = 1"; SqlRowSet HsnsiteList = jdbcTemplate.queryForRowSet ( query ); while ( HsnsiteList.next ()) { HubSiteProducts hubSiteProducts = new HubSiteProducts (); Integer hsnNetworkId = HsnsiteList.getInt ( "hsn_network_id" ); Integer hsnSiteId = HsnsiteList.getInt ( "hsn_site_id" ); String query2 = "select count(1) from site_product where site_id in (select HSN_SITE_ID from hub_spoke_network_mapping where hsn_network_id="+hsnNetworkId+") and product_id="+productId+" and MIN_STOCKING_QTY >0 "; SqlRowSet rowCount = jdbcTemplate.queryForRowSet ( query2 ); while (rowCount.next ()) { hubSiteProducts.setCountMinQty ( rowCount.getInt ( 1 ) ); } hubSiteProducts.setNetworkId ( hsnNetworkId ); hubSiteProducts.setHubSiteId ( hsnSiteId ); hubSiteProductsList.add ( hubSiteProducts ); } return hubSiteProductsList; } return null; } }