package com.gpc.client.pointofsale.invoice.line; import java.awt.Container; import java.awt.Frame; // Java Imports import java.math.BigDecimal; import java.rmi.RemoteException; import com.gpc.client.pointofsale.tax.PhoneRoomTax; import com.gpc.common.ResourceBundleReader; import com.gpc.client.pointofsale.invoice.PhoneRoomInvoiceBL; import com.gpc.common.pointofsale.invoice.line.PhoneRoomCommonInvoiceLineBL; import com.gpc.tams.comm.io.PhoneRoomTaapRouter; import com.gpc.valueobjects.inventory.InventoryOnHandResponseVO; import org.apache.commons.lang.StringUtils; import java.util.*; import javax.swing.SwingUtilities; import org.apache.log4j.Logger; import com.gpc.client.common.ClientApplicationContext; import com.gpc.client.common.input.document.PartNumberFormatCertifier; import com.gpc.client.pointofsale.customer.CustomerBL; import com.gpc.client.pointofsale.invoice.InvoiceBL; import com.gpc.client.pointofsale.tax.Tax; import com.gpc.common.ApplicationContext; import com.gpc.common.BOPISLogger; import com.gpc.common.Constants; import com.gpc.common.PointOfSaleException; import com.gpc.common.Profile; import com.gpc.common.TsoConstant; import com.gpc.common.constants.loyalty.LoyaltyConstants; import com.gpc.common.constants.refvalues.RefCountry; import com.gpc.common.constants.refvalues.RefFulfillmentIdentifierType; import com.gpc.common.constants.refvalues.RefInvoiceLineItemDescription; import com.gpc.common.constants.refvalues.RefInvoiceLineItemOrigin; import com.gpc.common.constants.refvalues.RefInvoiceLineItemType; import com.gpc.common.constants.refvalues.RefInvoiceNoteType; import com.gpc.common.constants.refvalues.RefInvoiceSpecialFunction; import com.gpc.common.constants.refvalues.RefPriceSheet; import com.gpc.common.constants.refvalues.RefRegulatoryType; import com.gpc.common.constants.refvalues.RefState; import com.gpc.common.exception.ApplicationException; import com.gpc.common.pattern.FwoDatePattern; import com.gpc.common.pattern.FwoPattern; import com.gpc.common.pattern.PatternParseException; import com.gpc.common.pointofsale.invoice.line.CommonInvoiceLineBL; import com.gpc.common.util.BooleanParser; import com.gpc.common.util.DateUtil; import com.gpc.common.util.FwoUtil; import com.gpc.common.util.RefStoreConfigurationUtil; import com.gpc.server.dataaccess.customer.Customer; import com.gpc.server.inventory.dataaccess.Inventory; import com.gpc.valueobjects.catalog.VehicleVO; import com.gpc.valueobjects.common.IDValuePairVO; import com.gpc.valueobjects.customer.CustomerCertificateVO; import com.gpc.valueobjects.customer.CustomerVO; import com.gpc.valueobjects.inventory.BarcodeVO; import com.gpc.valueobjects.inventory.InventoryStockVO; import com.gpc.valueobjects.inventory.InventoryVO; import com.gpc.valueobjects.inventory.KitDefinitionComponentVO; import com.gpc.valueobjects.inventory.KitDefinitionVO; import com.gpc.valueobjects.inventory.KitInventoryVO; import com.gpc.valueobjects.inventory.MSStockCheckVO; import com.gpc.valueobjects.inventory.MiscChgVO; import com.gpc.valueobjects.inventory.PartCertificationVO; import com.gpc.valueobjects.inventory.PartIdentifierVO; import com.gpc.valueobjects.inventory.ProductLineVO; import com.gpc.valueobjects.inventory.RegulationRuleMessageVO; import com.gpc.valueobjects.inventory.RegulationRulePartVO; import com.gpc.valueobjects.inventory.SupersedePartVO; import com.gpc.valueobjects.inventory.WarrantyPeriodVO; import com.gpc.valueobjects.inventory.WarrantyVO; import com.gpc.valueobjects.invoice.InvoiceListVO; import com.gpc.valueobjects.invoice.InvoiceVO; import com.gpc.valueobjects.invoice.line.BaseLineItemVO; import com.gpc.valueobjects.invoice.line.FulfillmentIdentifierVO; import com.gpc.valueobjects.invoice.line.FulfillmentItemVO; import com.gpc.valueobjects.invoice.line.FulfillmentVO; import com.gpc.valueobjects.invoice.line.InvoiceLineItemCertificationVO; import com.gpc.valueobjects.invoice.line.InvoiceLineItemReturnVO; import com.gpc.valueobjects.invoice.line.InvoiceLineItemVO; import com.gpc.valueobjects.invoice.line.InvoiceNoteVO; import com.gpc.valueobjects.invoice.line.KitLineItemVO; import com.gpc.valueobjects.invoice.line.PhoneRoomEjoeiVO; import com.gpc.valueobjects.invoice.line.PhoneRoomStoreVO; import com.gpc.valueobjects.message.MessageHeaderVO; import com.gpc.valueobjects.message.MessagePartVO; import com.gpc.valueobjects.message.MessageTextVO; import com.gpc.valueobjects.ordering.BuyoutItemVO; import com.gpc.valueobjects.ordering.BuyoutVO; import com.gpc.valueobjects.price.PricesInVO; import com.gpc.valueobjects.price.PricesOutVO; import com.gpc.valueobjects.profile.InventoryProfileVO; import com.gpc.valueobjects.profile.MultiStoreProfileVO; import com.gpc.valueobjects.profile.StoreProfileVO; import com.gpc.valueobjects.tax.TaxDecisionVO; import com.gpc.valueobjects.tax.TaxInfoVO; import com.gpc.valueobjects.tax.TaxTableVO; import net.sf.json.JSONObject; import com.gpc.valueobjects.inventory.BinRangeProfileVO; import com.gpc.client.pointofsale.invoice.BannedPartListController; /** *

Description: CLASS DESCRIPTION GOES HERE

* @author Copyright © 1999-2003, Genuine Parts Company, All Rights Reserved * @version 1.0 */ public class InvoiceLineBL extends CommonInvoiceLineBL { private static final Logger logger = Logger.getLogger(InvoiceLineBL.class); private static BannedPartListController bannedPartListController; private static final PhoneRoomTaapRouter phoneRoomTaapRouter = new PhoneRoomTaapRouter(); static ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); private InvoiceLineBL() { } public static final BarcodeVO getBarcodeVO(String barcode) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); BarcodeVO barcodeVO = clientApplicationContext.getInventoryDAO().getBarcode( barcode.substring(2, barcode.length())); return barcodeVO; } public static final Vector getPartLines(String partNumber, boolean inventoryOnly) throws PointOfSaleException { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); Vector partLines = null; String lineAbbrev = null; if (isScanned(partNumber)) { BarcodeVO barcodeVO = clientApplicationContext.getInventoryDAO().getBarcode( partNumber.substring(2, partNumber.length())); if (barcodeVO == null) { return null; } else { partNumber = barcodeVO.getPartNumber(); lineAbbrev = barcodeVO.getLineAbbrev(); } } partLines = clientApplicationContext.getInventoryDAO().getPartLines(partNumber, lineAbbrev, inventoryOnly); return partLines; } public static final Boolean isReservedLine(String lineAbbrev) { ProductLineVO productLineVO = null; productLineVO = ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getProductLineVO( lineAbbrev); if (productLineVO == null) { return null; } return productLineVO.isReservedLine(); } public static final Boolean isValidLine(String lineAbbrev) { Boolean retFlag = Boolean.TRUE; ProductLineVO productLineVO = null; productLineVO = ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getProductLineVO( lineAbbrev); if (productLineVO == null) { retFlag = Boolean.FALSE; } else { retFlag = Boolean.TRUE; } return retFlag; } public static final void setBackOrder(CustomerVO customerVO, BaseLineItemVO baseLineItemVO) { Boolean backOrderAllowed = new Boolean( ClientApplicationContext.getClientApplicationContext().getProfile( Profile.POINT_OF_SALE_CLIENT, ClientApplicationContext.getClientApplicationContext().getLocation() ).getInvoicingProfile().getAllowCtrmanBackorder().booleanValue() && customerVO.isBackOrderAllowed()); baseLineItemVO.setBackorder(backOrderAllowed); } public static final BigDecimal getPriceWithLandedFactor(BigDecimal price, String markupPercent, String priceSheetCD, InventoryVO inventoryVO, Byte landedFactorType) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); BigDecimal cost = null; int scale = clientApplicationContext.getSystemDAO().getPriceScale().intValue(); BigDecimal conv = new BigDecimal(markupPercent).divide( new BigDecimal(100).setScale(scale), scale, BigDecimal.ROUND_HALF_UP); if (priceSheetCD.equals("R") || priceSheetCD.equals("T")) { BigDecimal bdOne = new BigDecimal(1).setScale(scale); cost = price.divide(bdOne.subtract(conv), 4, BigDecimal.ROUND_HALF_UP); } else if (priceSheetCD.equals("%")) { cost = price.add(price.multiply(conv)).setScale( clientApplicationContext.getSystemDAO().getPriceScale().intValue(), BigDecimal.ROUND_HALF_UP); } else { cost = price; } cost = clientApplicationContext.getInventoryDAO().getPriceWithLandedFactor(inventoryVO, cost, landedFactorType); return cost; } public static final BigDecimal getExtendedSaved(BaseLineItemVO baseLineItemVO) { BigDecimal extendedSaved = null; if (baseLineItemVO.isCasePrice().booleanValue()) { extendedSaved = new BigDecimal("0.00").setScale(2, BigDecimal.ROUND_HALF_UP); } else { extendedSaved = baseLineItemVO.getUnitSaved().multiply( baseLineItemVO.getQuantityBilled()).setScale(2, BigDecimal.ROUND_HALF_UP); } return extendedSaved; } public static final BigDecimal getExtendedCost(BaseLineItemVO baseLineItemVO) { BigDecimal extendedCost = null; extendedCost = baseLineItemVO.getUnitCost().multiply( baseLineItemVO.getQuantityBilled()).setScale( ClientApplicationContext.getClientApplicationContext().getSystemDAO().getPriceScale().intValue(), BigDecimal.ROUND_HALF_UP); return extendedCost; } public static final BigDecimal getDefaultBarcodeQty(String barcode, InventoryStockVO inventoryStockVO) { BarcodeVO barcodeVO = ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getBarcode( barcode); return barcodeVO.getPkgQty().doubleValue() >= inventoryStockVO.getMinSaleQty().doubleValue() ? new BigDecimal(barcodeVO.getPkgQty().doubleValue()) : inventoryStockVO.getMinSaleQty(); } public static final PricesOutVO getPrices(Integer customerID, String customerTypeCD, String partNumber, String lineAbbrev, BigDecimal quantity) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); PricesOutVO priceOutputVO = null; PricesInVO pricesInputVO = new PricesInVO(); Integer loc = new Integer(clientApplicationContext.getLocation()); pricesInputVO.setLocation(loc); pricesInputVO.setCustomerId(customerID); pricesInputVO.setCustomerTypeCD(customerTypeCD); pricesInputVO.setPartNumber(FwoUtil.stripChars(partNumber, new char[] {PartNumberFormatCertifier.DASH, PartNumberFormatCertifier.FORWARD_SLASH, PartNumberFormatCertifier.PERIOD, PartNumberFormatCertifier.SPACE})); pricesInputVO.setLineAbbreviation(lineAbbrev); pricesInputVO.setQuantityBilled(quantity); pricesInputVO.setFieldsPassedIn("N"); try { long startMilliSeconds = System.currentTimeMillis(); priceOutputVO = clientApplicationContext.getPriceLoaderDAO().getPrices(pricesInputVO); long endMilliSeconds = System.currentTimeMillis(); long duration = (endMilliSeconds - startMilliSeconds); logger.info("getPrices isTAMSPriceLookupMetricsEnabled: "+clientApplicationContext.isTAMSPriceLookupMetricsEnabled()); if(clientApplicationContext.isTAMSPriceLookupMetricsEnabled()) { SwingUtilities.invokeLater(() -> buildAndSendPriceLookupMertricsToAzure(loc, customerTypeCD, partNumber, lineAbbrev, duration)); } } catch (ApplicationException ae) { clientApplicationContext.getMessageMgr().showMessage(ae.getUserMessageID(), ae.getUserMessageParameters()); } return priceOutputVO; } private static void buildAndSendPriceLookupMertricsToAzure(Integer location, String customerTypeCD, String partNumber, String lineAbbrev, long duration) { JSONObject azureJsonRequest = new JSONObject(); azureJsonRequest.put("partNumber", partNumber); azureJsonRequest.put("lineAbbrev", lineAbbrev); azureJsonRequest.put("customerType", customerTypeCD); azureJsonRequest.put("priceLookUpTimeInMilliSec", duration); try { clientApplicationContext.getInvoiceDAO().sendPriceMetricsToAzure(location, azureJsonRequest.toString()); } catch (ApplicationException e) { logger.error(e.getMessage()); } } public static boolean checkDC(CustomerVO customerVO, BaseLineItemVO baseLineItemVO, boolean newBarcode, InventoryVO inventoryVO) { return CommonInvoiceLineBL.checkDC(customerVO, baseLineItemVO, newBarcode, inventoryVO, Profile.POINT_OF_SALE_CLIENT); } public static final void setAverageCost(InventoryVO inventoryVO, BaseLineItemVO baseLineItemVO) { baseLineItemVO.setAverageCost(new Boolean( (inventoryVO.getAverageCost().doubleValue() > 0) && (ClientApplicationContext.getClientApplicationContext().getProfile( Profile.POINT_OF_SALE_CLIENT, ClientApplicationContext.getClientApplicationContext().getLocation() ).getStoreProfile().getUseAvgCost().booleanValue() && !baseLineItemVO.isCoreTransaction().booleanValue()))); } public static final Date parseDate(String stringDate) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); FwoDatePattern fwoDatePattern = (FwoDatePattern) FwoPattern.getDatePatternInstance( clientApplicationContext.getCurrentLocale(), new Integer( clientApplicationContext.getProfile(Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation() ).getStoreProfile().getRefDateFormatId().intValue())); Date parsedDate = null; try { parsedDate = (Date) fwoDatePattern.parse(stringDate); } catch (PatternParseException ppe) { return null; } return parsedDate; } /* * This method will calculate prorata warranty adjustment amount based on prorata percent * @param baseLineItemVO An instance of {@link BaseLineItemVO} * @param customerVO An instance of {@link CustomerVO} * @param inventoryVO An instance of {@link InventoryVO} * @param purchaseDate The purchase date of the part * @return warranty adjustment amount */ public static final BigDecimal getProRataWarrantyAdjustment(BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, Date purchaseDate) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); BigDecimal warrantyAmount = null; PricesOutVO pricesOutVO = getPrices(customerVO.getID(), customerVO.getCustomerTypeCD(), baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), baseLineItemVO .getQuantityBilled()); // Check if prorata warranty exists for the part WarrantyPeriodVO warrantyPeriodVO = getProRataWarranty(inventoryVO, purchaseDate); if (warrantyPeriodVO != null && warrantyPeriodVO.getRefundPercent() != null && pricesOutVO.getUnitPrice() != null) { warrantyAmount = pricesOutVO.getUnitPrice().subtract( pricesOutVO.getUnitPrice().multiply(warrantyPeriodVO.getRefundPercent())); warrantyAmount = clientApplicationContext.getInventoryDAO().getPriceWithLandedFactor( inventoryVO, warrantyAmount, new Byte("1")); } return warrantyAmount; } public static BigDecimal getRefundPercentForWarranty(InventoryVO inventoryVO, Date purchaseDate) { WarrantyPeriodVO warrantyPeriodVO = getProRataWarranty(inventoryVO, purchaseDate); BigDecimal refundPercent = null; if (warrantyPeriodVO != null && warrantyPeriodVO.getRefundPercent() != null) refundPercent=warrantyPeriodVO.getRefundPercent(); return refundPercent; } public static final BigDecimal getWarrantyAdjustment(BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, Date purchaseDate) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); if (inventoryVO == null) { inventoryVO = clientApplicationContext.getInventoryDAO().getPartDetailInfo(customerVO, baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), false); } WarrantyVO warrantyVO = inventoryVO.getWarrantyVO(); if(warrantyVO == null) { return new BigDecimal("0.00"); } PricesOutVO pricesOutVO = getPrices(customerVO.getID(), customerVO.getCustomerTypeCD(), baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), baseLineItemVO .getQuantityBilled()); BigDecimal warrantyAmount = warrantyVO.getConsumerAdjAmount(); if (purchaseDate != null && inventoryVO.getWarrantyList() != null && inventoryVO.getWarrantyList().size() > 1) { warrantyVO = getWarranty(inventoryVO, purchaseDate); warrantyAmount = warrantyVO.getConsumerAdjAmount(); } if (baseLineItemVO.isRebateItem().booleanValue() && (pricesOutVO.getPriceDecision().equals("!") || pricesOutVO.getPriceDecision().equals("*"))) { warrantyAmount = warrantyVO.getMIAdjAmount(); } else if (pricesOutVO.getPriceSheetCd().equalsIgnoreCase("M") || pricesOutVO.getPriceSheetCd().equalsIgnoreCase("J")) { warrantyAmount = warrantyVO.getMIAdjAmount(); } else if (pricesOutVO.getPriceSheetCd().equalsIgnoreCase("G")) { warrantyAmount = warrantyVO.getPreferredConsAdjAmount(); } BigDecimal landedFactors = clientApplicationContext.getInventoryDAO() .getPriceWithLandedFactor(inventoryVO, warrantyAmount, new Byte("1")); return landedFactors; } public static final void addToInvoiceTotals(InvoiceVO invoiceVO, BaseLineItemVO baseLineItemVO, CustomerVO customerVO) { if (baseLineItemVO != null) { if (baseLineItemVO.getCoreTransaction() != null && baseLineItemVO.getCoreTransaction().equals(Boolean.TRUE) && customerVO.getAlternateCoreCustomerID() != null && !invoiceVO.getManualTransaction().booleanValue()) { invoiceVO.setAlternateCoreSubTotal(invoiceVO.getAlternateCoreSubTotal().add( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); invoiceVO.setAlternateCoreDisplaySubTotal(invoiceVO.getAlternateCoreDisplaySubTotal() .add(getDisplayExtendedPrice(baseLineItemVO).setScale( 2, BigDecimal.ROUND_HALF_UP))); } else { if (baseLineItemVO.getTaxable1().booleanValue()) { invoiceVO.setTaxableSales1(invoiceVO.getTaxableSales1().add( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } else { invoiceVO.setNonTaxableSales1(invoiceVO.getNonTaxableSales1().add( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } if ((invoiceVO.getSecondaryTaxTableID() != null) && (invoiceVO.getSecondaryTaxTableID().intValue() >= 0)) { if (baseLineItemVO.getTaxable2().booleanValue()) { invoiceVO.setTaxableSales2(invoiceVO.getTaxableSales2().add( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } else { invoiceVO.setNonTaxableSales2(invoiceVO.getNonTaxableSales2().add( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } } } } } public static final void removeFromInvoiceTotals(InvoiceVO invoiceVO, BaseLineItemVO baseLineItemVO, CustomerVO customerVO) { if (baseLineItemVO != null) { if (baseLineItemVO.getCoreTransaction() != null && baseLineItemVO.getCoreTransaction().equals(Boolean.TRUE) && customerVO.getAlternateCoreCustomerID() != null && !invoiceVO.getManualTransaction().booleanValue()) { invoiceVO.setAlternateCoreSubTotal(invoiceVO.getAlternateCoreSubTotal().subtract( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); invoiceVO.setAlternateCoreDisplaySubTotal( invoiceVO.getAlternateCoreDisplaySubTotal().subtract( getDisplayExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } else { if (baseLineItemVO.getTaxable1().booleanValue()) { invoiceVO.setTaxableSales1(invoiceVO.getTaxableSales1().subtract( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } else { invoiceVO.setNonTaxableSales1(invoiceVO.getNonTaxableSales1().subtract( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } if ((invoiceVO.getSecondaryTaxTableID() != null) && (invoiceVO.getSecondaryTaxTableID().intValue() >= 0)) { if (baseLineItemVO.getTaxable2().booleanValue()) { invoiceVO.setTaxableSales2(invoiceVO.getTaxableSales2().subtract( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } else { invoiceVO.setNonTaxableSales2(invoiceVO.getNonTaxableSales2().subtract( getExtendedPrice(baseLineItemVO).setScale(2, BigDecimal.ROUND_HALF_UP))); } } } } } public static BaseLineItemVO createLineItemFromBuyout(InvoiceVO invoiceVO, CustomerVO customerVO, BuyoutItemVO buyoutItemVO, BuyoutVO buyoutVO) { logger.debug("inside createLineItemFromBuyout"); BaseLineItemVO baseLineItemVO = new BaseLineItemVO(); String ipAddress = ""; ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()) { try { ipAddress = PhoneRoomInvoiceBL.getRemoteIpAddress(invoiceVO.getRemoteStoreNumber()); } catch (ApplicationException e) { logger.error(e); } } baseLineItemVO.setLOC(buyoutItemVO.getLOC()); String part = FwoUtil.stripChars(buyoutItemVO.getPartNumber(), new char[] { PartNumberFormatCertifier.DASH, PartNumberFormatCertifier.FORWARD_SLASH, PartNumberFormatCertifier.PERIOD, PartNumberFormatCertifier.SPACE}); baseLineItemVO.setPartNum(part); baseLineItemVO.setExpandedPartNum(buyoutItemVO.getPartNumber()); baseLineItemVO.setLineAbbr(buyoutItemVO.getLineAbbrev()); baseLineItemVO.setPartDescription(buyoutItemVO.getDescription()); baseLineItemVO.setQuantityBilled(new BigDecimal(buyoutItemVO.getQuantity().toString())); baseLineItemVO.setCountermanEmployeeID( clientApplicationContext.getCurrentUser().getEmployeeId()); baseLineItemVO.setGroupCode(new Short("0")); baseLineItemVO.setRefUnitDesignator("1"); baseLineItemVO.setNonStocking(Boolean.TRUE); baseLineItemVO.setDoesNotAffectSalesHistory(Boolean.TRUE); PricesInVO pricesInVO = new PricesInVO(); pricesInVO.setPartNumber(baseLineItemVO.getPartNum()); pricesInVO.setLineAbbreviation(baseLineItemVO.getLineAbbr()); pricesInVO.setCustomerId(customerVO.getID()); pricesInVO.setCustomerTypeCD(customerVO.getCustomerTypeCD()); pricesInVO.setLocation(baseLineItemVO.getLOC()); pricesInVO.setCoreCost(buyoutItemVO.getCoreCost()); pricesInVO.setCost(buyoutItemVO.getUnitCost()); if (buyoutItemVO.getUnitCost() != null) { if (buyoutItemVO.getUnitCost().signum() == 0) { if (buyoutItemVO.getCoreCost() != null && buyoutItemVO.getCoreCost().signum() != 0 && buyoutItemVO.getQuantity().shortValue() < 0) { String storeLanguageCd = ""; if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()){ StoreProfileVO storeProfileVO = new PhoneRoomTaapRouter().getStoreProfile(ipAddress); storeLanguageCd = storeProfileVO.getRefLanguageCd(); }else { storeLanguageCd = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()) .getStoreProfile().getRefLanguageCd(); } String coreDescription = TsoConstant.CORE_DEPOSIT; try { if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()){ coreDescription = phoneRoomTaapRouter.getInvoiceLineDescription(new Integer( RefInvoiceLineItemDescription.CORE_DEPOSIT), storeLanguageCd,ipAddress); }else { coreDescription = clientApplicationContext.getRefTableDAO() .getInvoiceLineDescription(new Integer( RefInvoiceLineItemDescription.CORE_DEPOSIT), storeLanguageCd); } } catch (ApplicationException applicationException) { logger.error("Error occured while retreiving invoice line description" + applicationException.toString(), applicationException); } baseLineItemVO.setPartDescription(coreDescription); baseLineItemVO.setCoreTransaction(Boolean.TRUE); } } else { if (buyoutItemVO.getCoreCost() != null && buyoutItemVO.getCoreCost().signum() != 0) { baseLineItemVO.setHasCoreCharge(Boolean.TRUE); } } } PricesOutVO prices = new PricesOutVO(); if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()){ prices = phoneRoomTaapRouter.getPickUpPrice(pricesInVO,ipAddress,baseLineItemVO.getLOC()); }else { prices = clientApplicationContext.getOrderingDAO().getPickupPrice(pricesInVO); } if (baseLineItemVO.getCoreTransaction().booleanValue()) { baseLineItemVO.setUnitPrice(prices.getCorePrice()); } else { baseLineItemVO.setUnitPrice(prices.getUnitPrice()); } baseLineItemVO.setRefInvoiceLineItemOriginID(new Byte((byte) RefInvoiceLineItemOrigin.BUYOUT_PICKUP_PURCHASE_ORDER)); baseLineItemVO.setRefInvoiceLineItemTypeID(new Byte((byte) RefInvoiceLineItemType.NORMAL_ITEM)); CommonInvoiceLineBL.changeBillingType(customerVO, baseLineItemVO); baseLineItemVO.setDisplayTaxable2((customerVO.getSecondaryTaxTable() != null && customerVO.getSecondaryTaxTable().getID().shortValue() > 0) || (invoiceVO.getSavedInvoiceIdForDeletion() == null && isDeliverySecondaryTaxExists(customerVO))); baseLineItemVO.setPickupItem(Boolean.TRUE); baseLineItemVO.setSpecialOrder(TsoConstant.BUYOUT); baseLineItemVO.setCompletedLine(baseLineItemVO.getUnitPrice().signum() != 0); if (!baseLineItemVO.isCompletedLine()) { // Bug # 30784 added condition to check the null value for the UnitCost. if(buyoutItemVO.getUnitCost() != null && buyoutItemVO.getUnitCost().signum() != 0) { baseLineItemVO.setUnitCost(buyoutItemVO.getUnitCost()); }else{ if (buyoutItemVO.getCoreCost() != null && buyoutItemVO.getCoreCost().signum() != 0 && buyoutItemVO.getQuantity().shortValue() < 0) { baseLineItemVO.setUnitCost(buyoutItemVO.getCoreCost()); } } } baseLineItemVO.setBuyoutPONumber(buyoutVO.getPONumber()); baseLineItemVO.setBuyoutPODate(buyoutVO.getCreationDate()); baseLineItemVO.setBuyoutItemVO(buyoutItemVO); TaxDecisionVO taxDecision = new TaxDecisionVO(); if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()){ taxDecision = PhoneRoomTax.getTaxDecision(customerVO, null, null, baseLineItemVO, customerVO.getPrimaryTaxTable(), customerVO.getSecondaryTaxTable(), Profile.POINT_OF_SALE_CLIENT,ipAddress,new PhoneRoomTaapRouter().getStoreProfile(ipAddress).getRefLanguageCd()); } else{ taxDecision = Tax.getTaxDecision(customerVO, null, null, baseLineItemVO, customerVO.getPrimaryTaxTable(), customerVO.getSecondaryTaxTable(), Profile.POINT_OF_SALE_CLIENT); } if (!taxDecision.getPrimaryTax().equals(Tax.OPTIONAL)) { if (taxDecision.getPrimaryTax().equals(Tax.ALWAYS)) { baseLineItemVO.setTaxable1(Boolean.TRUE); } else { baseLineItemVO.setTaxable1(Boolean.FALSE); } } else { baseLineItemVO.setTaxable1(Boolean.TRUE); } if (!taxDecision.getSecondaryTax().equals(Tax.OPTIONAL)) { if (taxDecision.getSecondaryTax().equals(Tax.ALWAYS)) { baseLineItemVO.setTaxable2(Boolean.TRUE); } else { baseLineItemVO.setTaxable2(Boolean.FALSE); } } else { baseLineItemVO.setTaxable2(Boolean.TRUE); } if(invoiceVO != null && invoiceVO.isPhoneRoomMessagesFlag()){ StoreProfileVO storeProfileVO = new PhoneRoomTaapRouter().getStoreProfile(ipAddress); PhoneRoomCommonInvoiceLineBL.setDisplayPricesForLineItem(baseLineItemVO, customerVO, invoiceVO,ipAddress,storeProfileVO.getIncludeTaxInPrice().booleanValue()); }else{ setDisplayPricesForLineItem(baseLineItemVO, customerVO, invoiceVO); } if(invoiceVO.getSalesOrderVO() != null){ invoiceVO.getSalesOrderVO().addFulfillments(createFulfillmentForBuyout(buyoutVO, baseLineItemVO)); } return baseLineItemVO; } public static boolean isMaximumLinesExceeded(int currentInvoiceLines, int addedLines) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); int maxLines = clientApplicationContext.getSystemDAO().getInvoiceMaxLinesAllowed().intValue(); if (maxLines < 0) { return false; } if ((currentInvoiceLines + addedLines) > maxLines) { return true; } return false; } public static boolean checkListPrice(BaseLineItemVO baseLineItemVO, BigDecimal userListPrice) { boolean retFlag = false; if (userListPrice.compareTo(baseLineItemVO.getUnitPrice()) < 0) { logger.debug("InvoiceLineBL.checkListPrice - List Price is less than the entered"); ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); BigDecimal bdZero = new BigDecimal(0) .setScale(clientApplicationContext.getSystemDAO().getPriceScale().intValue()); baseLineItemVO.setUnitListPrice(bdZero); baseLineItemVO.setDisplayUnitListPrice(bdZero); retFlag = true; } else { logger.debug("InvoiceLineBL.checkListPrice - User List Price = " + userListPrice); baseLineItemVO.setActualListPrice(userListPrice); baseLineItemVO.setUnitListPrice(userListPrice); retFlag = false; } return retFlag; } public static void loadGeneratedLines(InvoiceVO invoiceVO) throws ApplicationException{ ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); CustomerVO customerVO = clientApplicationContext.getCustomerDAO().getCustomerDetailInfoByID( invoiceVO.getCustomerID(), invoiceVO.getCustomerTypeCD()); Vector tempVector = (Vector) invoiceVO.getLineItems().clone(); invoiceVO.getLineItems().removeAllElements(); invoiceVO.setNonTaxableSales1(new BigDecimal("0.00")); invoiceVO.setTaxableSales1(new BigDecimal("0.00")); invoiceVO.setNonTaxableSales2(new BigDecimal("0.00")); invoiceVO.setTaxableSales2(new BigDecimal("0.00")); invoiceVO.setAlternateCoreSubTotal(new BigDecimal("0.00")); invoiceVO.setAlternateCoreDisplaySubTotal(new BigDecimal("0.00")); for (int i = 0; i < tempVector.size(); i++) { if (tempVector.get(i) instanceof BaseLineItemVO) { PricesOutVO prices = null; BaseLineItemVO baseLineItemVO = (BaseLineItemVO) tempVector.get(i); if (baseLineItemVO.isPickupItem().booleanValue()) { PricesInVO pricesInVO = new PricesInVO(); pricesInVO.setCost(((BaseLineItemVO) tempVector.get(i)).getBuyoutItemVO().getUnitCost()); pricesInVO.setCoreCost(((BaseLineItemVO) tempVector.get(i)).getBuyoutItemVO().getCoreCost()); pricesInVO.setCustomerId(customerVO.getID()); pricesInVO.setCustomerTypeCD(customerVO.getCustomerTypeCD()); pricesInVO.setLocation(invoiceVO.getLOC()); prices = ClientApplicationContext.getClientApplicationContext() .getOrderingDAO().getPickupPrice(pricesInVO); baseLineItemVO.setUnitPrice(prices.getUnitPrice()); baseLineItemVO.setUnitListPrice(prices.getUnitPrice()); baseLineItemVO.setDisplayUnitPrice(InvoiceLineBL .getDisplayPriceFromUnitPrice(baseLineItemVO.getUnitPrice(), baseLineItemVO, invoiceVO, customerVO, null, null)); baseLineItemVO.setDisplayUnitListPrice(InvoiceLineBL .getDisplayPriceFromUnitPrice(baseLineItemVO.getUnitListPrice(), baseLineItemVO, invoiceVO, customerVO, null, null)); } else { prices = InvoiceLineBL.getPrices(customerVO.getID(), customerVO.getCustomerTypeCD(), baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), baseLineItemVO.getQuantityBilled()); baseLineItemVO.setUnitListPrice(prices.getCalculatedList()); baseLineItemVO.setDisplayUnitListPrice(prices.getDisplayListPrice()); baseLineItemVO.setPriceDecision(prices.getPriceDecision()); // sp_getprice returns correct values (including special sales) baseLineItemVO.setUnitPrice(prices.getUnitPrice()); baseLineItemVO.setDisplayUnitPrice(prices.getDisplayUnitPrice()); baseLineItemVO.setUnitCost(prices.getUnitCost()); // note: priceDecision holds "!" if special price/cost were actually used //ck for special sale to set extra properties if(prices.getSpecialSaleCode() != null) { baseLineItemVO.setSpecialSale(Boolean.TRUE); baseLineItemVO.setSpecialSaleCode(prices.getSpecialSaleCode()); } TaxTableVO primaryTaxTableVO = clientApplicationContext.getSystemDAO(). getTaxTable(invoiceVO.getLOC(), customerVO.getDefaultTaxTableID()); TaxTableVO secondaryTaxTableVO = Tax.getSecondaryTaxTableVO(primaryTaxTableVO); if (primaryTaxTableVO == null) { primaryTaxTableVO = new TaxTableVO(); } if (secondaryTaxTableVO == null) { secondaryTaxTableVO = new TaxTableVO(); } InventoryVO inventoryVO = clientApplicationContext.getInventoryDAO(). getPartDetailInfo(customerVO, baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), false); if (inventoryVO != null) { baseLineItemVO.setExpandedPartNum(inventoryVO.getExpandedPartNumber()); baseLineItemVO.setPartDescription(inventoryVO.getDescription()); TaxDecisionVO taxDecisionVO = Tax.getTaxDecisionNoPrompt(customerVO, inventoryVO, null, baseLineItemVO, primaryTaxTableVO, secondaryTaxTableVO, Profile.POINT_OF_SALE_CLIENT); baseLineItemVO.setTaxable1(BooleanParser.parseBoolean(Tax.TAXABLE_YES, Tax.TAXABLE_NO, taxDecisionVO.getPrimaryTax())); baseLineItemVO.setTaxable2(BooleanParser.parseBoolean(Tax.TAXABLE_YES, Tax.TAXABLE_NO, taxDecisionVO.getSecondaryTax())); } } baseLineItemVO.setExtendedPrice( InvoiceLineBL.getExtendedPrice(baseLineItemVO)); baseLineItemVO.setCompletedLine(true); LinkedList linesToAdd = LineGeneratorFactory.getInstance().getLineGenerator( invoiceVO, baseLineItemVO, customerVO, prices, null).createLineGenerationQueue(true); for (int j = 0; j < linesToAdd.size(); j++) { if (linesToAdd.get(j) instanceof BaseLineItemVO) { InvoiceLineBL.addToInvoiceTotals(invoiceVO, (BaseLineItemVO) linesToAdd.get(j), customerVO); } invoiceVO.getLineItems().add(linesToAdd.get(j)); } } else { invoiceVO.getLineItems().add(tempVector.get(i)); } } } public static SupersedePartVO getSupersedePartVO(InventoryVO inventoryVO, CustomerVO customerVO) { SupersedePartVO supersedePartVO = null; ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); //get the first supersede part Vector supersedingParts = clientApplicationContext.getInventoryDAO().getSupersedingParts( inventoryVO, customerVO.getID(), customerVO.getCustomerTypeCD(), clientApplicationContext.getProfile(Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()).getStoreProfile().getNapaAcctDcCode()); if ((supersedingParts == null) || (supersedingParts.size() == 0)) { supersedePartVO = new SupersedePartVO(); } else { supersedePartVO = (SupersedePartVO) supersedingParts.elementAt(0); } //get the text from the message file String typeDesc = supersedePartVO.getRefTypeDescription(); return supersedePartVO; } public static final BaseLineItemVO createAGMiscChgLineItem(MiscChgVO miscChgVO, BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, InvoiceVO invoiceVO, StoreProfileVO storeProfileVO, boolean autoComplete, int segment, Integer countermanID) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); Short grpCode = new Short((short)0); TaxInfoVO taxInfoVO = clientApplicationContext.getInventoryDAO() .getProductLineTaxInfo(miscChgVO.getRefResvLineCD(), grpCode); return CommonInvoiceLineBL.createAGMiscChgLineItem(miscChgVO, baseLineItemVO, customerVO, inventoryVO, invoiceVO, storeProfileVO, autoComplete, segment, countermanID, taxInfoVO); } public static final BaseLineItemVO createAGCoreLineItem(BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, InvoiceVO invoiceVO, StoreProfileVO storeProfileVO, PricesOutVO prices, boolean autoComplete, int segment, Integer countermanID) { final String methodSpec = "InvoiceLineBL.createAGCoreLineItem - "; logger.warn(methodSpec + "Creating Core line item"); ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); TaxInfoVO taxInfoVO = clientApplicationContext.getInventoryDAO().getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode()); String storeLanguageCd = clientApplicationContext.getProfile(Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()).getStoreProfile().getRefLanguageCd(); String coreDescription = null; try { coreDescription = clientApplicationContext.getRefTableDAO().getInvoiceLineDescription( new Integer(RefInvoiceLineItemDescription.CORE_DEPOSIT), storeLanguageCd); } catch (ApplicationException applicationException) { logger.error("Error occured while retreiving invoice line description" + applicationException.toString(), applicationException); } return CommonInvoiceLineBL.createAGCoreLineItem(baseLineItemVO, customerVO, inventoryVO, invoiceVO, storeProfileVO, prices, autoComplete, segment, countermanID, taxInfoVO, isPartAssociatedWithOrigInvoiceFromList(baseLineItemVO), coreDescription); } public static InvoiceNoteVO createAGInvNoteReturn(InvoiceLineItemReturnVO iliReturnVO) { InvoiceNoteVO invoiceNoteVO = null; if(iliReturnVO.getOriginalInvoiceNumber() != null || iliReturnVO.getOriginalInvoiceDate() != null){ String message=""; if (iliReturnVO.getOriginalInvoiceNumber() != null) { message = "# " + iliReturnVO.getOriginalInvoiceNumber() + " "; } if(iliReturnVO.getOriginalInvoiceDate() != null) { message += DateUtil.getDateAsString (iliReturnVO.getOriginalInvoiceDate(), "MM/dd/yyyy"); } invoiceNoteVO = new InvoiceNoteVO(); invoiceNoteVO.setRefInvoiceNoteTyepID(new Integer( RefInvoiceNoteType.RETURN_MESSAGE)); invoiceNoteVO.setText(message); invoiceNoteVO.setCompletedLine(true); } return invoiceNoteVO; } public static Collection createAGInvNoteReturnLineItems(BaseLineItemVO parent) { ArrayList noteList = new ArrayList(); ArrayList tmpLineItemInvoiceIDArray = new ArrayList(); if (parent.getReturnItems() != null) { for (Iterator iterReturnItems = parent.getReturnItems().iterator(); iterReturnItems.hasNext();) { InvoiceLineItemReturnVO vo = (InvoiceLineItemReturnVO) iterReturnItems.next(); InvoiceNoteVO invoiceNoteVO = InvoiceLineBL.createAGInvNoteReturn(vo); boolean toBeAdded = true; if(parent.isKitPart()) { for (Iterator IterReturnItemsTmp = parent.getReturnItems().iterator(); IterReturnItemsTmp.hasNext(); ) { InvoiceLineItemReturnVO voTmp = (InvoiceLineItemReturnVO) IterReturnItemsTmp.next(); String tmpLineItemInvoiceID = Integer.toString(voTmp.getOriginalInvoiceNumber()); if (!tmpLineItemInvoiceIDArray.contains(tmpLineItemInvoiceID)) { logger.debug("if !tmpLineIteminvoiceIDArray.contains(tmpLineIteminvoiceID)"); tmpLineItemInvoiceIDArray.add(tmpLineItemInvoiceID); } else { toBeAdded = false; break; } } } if (invoiceNoteVO != null && toBeAdded) { invoiceNoteVO.setGeneratedByLineItem(parent); noteList.add(invoiceNoteVO); } } } return noteList; } public static boolean isPartAssociatedWithOrigInvoice(BaseLineItemVO baseLineItemVO) { if (baseLineItemVO.getReturnItems() != null) { for (Iterator iterReturnItems = baseLineItemVO.getReturnItems().iterator(); iterReturnItems.hasNext();) { InvoiceLineItemReturnVO vo = (InvoiceLineItemReturnVO) iterReturnItems.next(); if (vo.getOriginalInvoiceAmount() != null && vo.getOriginalInvoiceAmount().signum() != 0) { return true; } } } return false; } /** * addExcldeNoteForAltCoreInvoice method is to add the line note * while customer having core in the invoice with Alt core customerId. * @return invoiceNoteVO */ public static InvoiceNoteVO addExcldeNoteForAltCoreInvoice() { InvoiceNoteVO invoiceNoteVO = new InvoiceNoteVO(); invoiceNoteVO.setRefInvoiceNoteTyepID(RefInvoiceNoteType.NORMAL_MESSAGE); invoiceNoteVO.setGeneratedByLineItem(null); invoiceNoteVO.setText(clientApplicationContext.getResourceBundleReader() .getLocalizedText(ResourceBundleReader.UI, "coreChargesNotIncludedMSG", clientApplicationContext.getCurrentLocale())); invoiceNoteVO.setCompletedLine(true); invoiceNoteVO.setLOC(clientApplicationContext.getLocation()); return invoiceNoteVO; } /** * This method checks whether return part is associated with original invoice * from current store or not. * @param baseLineItemVO value object for return item * @return boolean */ public static boolean isPartAssociatedWithOrigInvoiceFromList( BaseLineItemVO baseLineItemVO) { if (baseLineItemVO.getReturnItems() != null) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); String storeNum = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()).getStoreProfile() .getStoreNum(); for (Iterator iterReturnItems = baseLineItemVO.getReturnItems() .iterator(); iterReturnItems.hasNext();) { InvoiceLineItemReturnVO vo = (InvoiceLineItemReturnVO) iterReturnItems .next(); if (vo.getOriginalStoreNum() != null && vo.getOriginalStoreNum().equals(storeNum)) { return true; } } } return false; } /** * This method checks whether core line item is replacement line item or not. * @param baseLineItemVO value object. * @return a boolean indicator whether the line item is replacement core line item or not. */ public static boolean isReplacementCoreLineItem(BaseLineItemVO baseLineItemVO) { if (!baseLineItemVO.isCoreTransaction().booleanValue()) { return false; } InvoiceLineItemVO replacementPartLineItem = baseLineItemVO.getGeneratedByLineItem(); if (replacementPartLineItem == null) { return false; } if (!(replacementPartLineItem instanceof BaseLineItemVO)) { return false; } InvoiceLineItemVO invoiceLineItemVO = replacementPartLineItem.getGeneratedByLineItem(); if (invoiceLineItemVO == null) { return false; } if (!(invoiceLineItemVO instanceof BaseLineItemVO)) { return false; } BaseLineItemVO defectiveReturnLineItem = (BaseLineItemVO) invoiceLineItemVO; if (baseLineItemVO.getQuantityBilled().equals( defectiveReturnLineItem.getQuantityBilled().negate())) { return true; } return false; } /** * This method is used to set generated sequence for replacement core line items. * * @param invoiceVO value object for the invoice */ public static void setGenBySeqForReplacementCoreItem(InvoiceVO invoiceVO) { Vector itemList = invoiceVO.getLineItems(); if (itemList != null) { int listSize = itemList.size(); InvoiceLineItemVO lineItem = null; for (int index = 0; index < listSize; index++) { lineItem = (InvoiceLineItemVO) itemList.elementAt(index); if (lineItem instanceof BaseLineItemVO) { BaseLineItemVO baseLineItemVO = (BaseLineItemVO) lineItem; if (baseLineItemVO.isCoreTransaction().booleanValue() && !baseLineItemVO.isKitPart() && baseLineItemVO.getQuantityBilled().doubleValue() > 0 && baseLineItemVO.getGeneratedByLineItem() instanceof BaseLineItemVO && baseLineItemVO.getQuantityBilled().equals( ((BaseLineItemVO) baseLineItemVO.getGeneratedByLineItem()) .getQuantityBilled().negate()) && baseLineItemVO.getGeneratedBySequence() != null && baseLineItemVO.getGeneratedBySequence().intValue() > 0 && baseLineItemVO.getGeneratedBySequence().intValue() <= listSize) { baseLineItemVO.setGeneratedByLineItem((InvoiceLineItemVO) itemList .elementAt(baseLineItemVO.getGeneratedBySequence().intValue() - 1)); } } } } } /** * This method is used to check whether the return core is considered for mapping with the * purchase part on the same invoice. * * @param returnBaseLineItemVO value object for return item * @return boolean value indicates whether the return core is considered for mapping or not. */ public static boolean isReturnCoreConsideredForMapping(BaseLineItemVO returnBaseLineItemVO) { Vector returnItems = returnBaseLineItemVO.getReturnItems(); if (returnItems == null || returnItems.size() == 0 || returnItems.size() > 1) { return false; } if (returnItems.size() == 1) { InvoiceLineItemReturnVO invoiceLineItemReturnVO = (InvoiceLineItemReturnVO) returnItems .get(0); if (invoiceLineItemReturnVO.getOriginalInvoiceNumber() == null && invoiceLineItemReturnVO.getOriginalStoreNum() != null) { return true; } } return false; } /** * This method calculates the kit part unit cost as the sum of the cost of the components * associated with a kit part by calling getPrice() functionality on each component. * * @param inventory the data object containing the inventory information of a kit. * @param customer the data object containing the customer information. * * @return kit part unit cost as the sum of the cost of the components associated with a kit * part. */ public static final BigDecimal getKitPartCost(InventoryVO inventory, CustomerVO customer) { BOPISLogger.getInstance().setStoreProfile(customer.getLOC()).addBOPISLog(Constants.DEBUG, "getKitPartCost() starts"); BigDecimal bigDecimalZero = new BigDecimal("0"); BigDecimal kitPartUnitCost = bigDecimalZero; BigDecimal componentCost = bigDecimalZero; BigDecimal requiredQuantity = bigDecimalZero; PricesOutVO componentPrices = null; InventoryVO componentInventory = null; KitDefinitionComponentVO kitDefinitionComponent = null; if (inventory instanceof KitInventoryVO) { List inventoryRecords = ((KitInventoryVO) inventory).getComponentInventoryList(); if (inventoryRecords != null) { Iterator iterator = inventoryRecords.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof InventoryVO) { componentInventory = (InventoryVO) object; componentPrices = null; // Gets the data object that represents the combination of a PartIdentifier // and a quantity that describes the components associated with a kit part kitDefinitionComponent = ((KitInventoryVO) inventory) .getComponentDefinition(componentInventory); if (kitDefinitionComponent.getRequiredQuantity() != null) { requiredQuantity = new BigDecimal(kitDefinitionComponent .getRequiredQuantity().intValue()); } if (customer != null) { // Gets the prices of each component associated with a kit part from the // getPrice() functionality. componentPrices = InvoiceLineBL.getPrices(customer.getID(), customer .getCustomerTypeCD(), componentInventory.getPartNumber(), componentInventory.getLineAbbrev(), requiredQuantity); } if (componentPrices != null) { componentCost = componentPrices.getUnitCost(); // Calculates the kit part unit cost as the sum of unit cost of // components associated with a kit part. kitPartUnitCost = kitPartUnitCost.add(componentCost .multiply(requiredQuantity)); } } } } } BOPISLogger.getInstance().setStoreProfile(customer.getLOC()).addBOPISLog(Constants.DEBUG, "getKitPartCost() ends"); return kitPartUnitCost; } /** * This method calculates the kit part cost/average cost as the sum of individual kit component * cost/average cost with landed factor applied on it based on the price decision entry made at * the PD field. * * @param inventory the data object containing the inventory information of a kit part. * @param priceSheet the price decision entry made at the PD field of invoice line entry area. * @param landedFactorType the factor type to be applied for kit component cost /average cost. * * @return the kit part cost/average cost as the sum of the kit component cost/average cost with * landed factor applied on it based on the price decision entry made at the PD field. */ public static final BigDecimal getKitPriceWithLandedFactor(InventoryVO inventory, String priceSheet, Byte landedFactorType) { BigDecimal bigDecimalZero = new BigDecimal("0"); BigDecimal componentCost = bigDecimalZero; BigDecimal kitPartCost = bigDecimalZero; InventoryVO componentInventory = null; BigDecimal requiredQuantity = null; KitDefinitionComponentVO kitDefinitionComponent = null; if (inventory instanceof KitInventoryVO) { List inventoryRecords = ((KitInventoryVO) inventory).getComponentInventoryList(); if (inventoryRecords != null) { Iterator iterator = inventoryRecords.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof InventoryVO) { componentInventory = (InventoryVO) object; componentCost = null; // Gets the data object that represents the combination of a PartIdentifier // and a quantity that describes the components associated with a kit part kitDefinitionComponent = ((KitInventoryVO) inventory) .getComponentDefinition(componentInventory); if (kitDefinitionComponent.getRequiredQuantity() != null) { requiredQuantity = new BigDecimal(kitDefinitionComponent .getRequiredQuantity().intValue()); } if (priceSheet.equals(RefPriceSheet.AVERAGE_COST) || priceSheet.equals(RefPriceSheet .DESIRED_GROSS_PROFIT_BASED_ON_AVERAGE_INVENTORY_COST)) { // If the price decision entry is 'V' or 'T' it considers the component // average cost. componentCost = componentInventory.getAverageCost(); // If the average cost of a component is zero then its replacement cost // is considered. if (componentCost != null && componentCost.doubleValue() <= 0) { componentCost = componentInventory.getCost(); } } else if (priceSheet.equals(RefPriceSheet.COST) || priceSheet.equals(RefPriceSheet .DESIRED_GROSS_PROFIT_BASED_ON_REPLACEMENT_INVENTORY_COST)) { // If the price decision entry is 'Z' or 'R' it considers the component // replacement cost. componentCost = componentInventory.getCost(); } if (componentCost != null) { // Applies the landed factor to component cost based on the price // decision entry. componentCost = InvoiceLineBL.getPriceWithLandedFactor(componentCost, TsoConstant.ZERO_MARKUP_PERCENT, priceSheet, componentInventory, landedFactorType); } if (componentCost != null && requiredQuantity != null) { // Calculates the kit part cost as the sum of cost of components // associated with a kit with landed factors applied on it. kitPartCost = kitPartCost.add(componentCost.multiply(requiredQuantity)); } } } } } return kitPartCost; } /** * Removes the inter store and ejoei order information. * * @param invoiceVO the {@link InvoiceVO} object */ public static void removeInterStoreAndEjoeiOrderInformation(InvoiceVO invoiceVO) { Vector itemList = invoiceVO.getLineItems(); if (itemList != null) { int listSize = itemList.size(); InvoiceLineItemVO lineItem = null; for (int index = 0; index < listSize; index++) { lineItem = (InvoiceLineItemVO) itemList.elementAt(index); if (lineItem instanceof BaseLineItemVO) { BaseLineItemVO baseLineItemVO = (BaseLineItemVO) lineItem; baseLineItemVO.setPhoneRoomItems(new ArrayList()); } else { InvoiceNoteVO invoiceNoteVO = (InvoiceNoteVO) lineItem; if (invoiceNoteVO.getRefInvoiceNoteTyepID() != null && invoiceNoteVO.getRefInvoiceNoteTyepID().intValue() == RefInvoiceNoteType.PHONE_ROOM_MESSAGE) { itemList.remove(index); listSize = itemList.size(); index--; } } } } } /** * Creates the phone room message. * * @param remoteStoreNumber the remote store number * @param baseLineItemVO the {@link BaseLineItemVO} object * @param phoneRoomPartVO the {@link PhoneRoomStoreVO} object * * @return the {@link InvoiceNoteVO} object containing phone room message */ public static InvoiceNoteVO createPhoneRoomMessage(String remoteStoreNumber, BaseLineItemVO baseLineItemVO, PhoneRoomStoreVO phoneRoomPartVO) { InvoiceNoteVO agSPhoneRoomItem = new InvoiceNoteVO(); agSPhoneRoomItem .setRefInvoiceNoteTyepID(new Integer(RefInvoiceNoteType.PHONE_ROOM_MESSAGE)); agSPhoneRoomItem.setGeneratedByLineItem(baseLineItemVO); String invoiceNote = ClientApplicationContext.getClientApplicationContext() .getRefTableDAO().getInvoiceNoteText( agSPhoneRoomItem.getRefInvoiceNoteTyepID(), ClientApplicationContext.getClientApplicationContext().getCurrentLocale() .getLanguage()); if (invoiceNote != null) { StringBuffer invoiceNoteBuffer = new StringBuffer(); String invoiceNoteSeparator = ":"; int index = invoiceNote.indexOf(invoiceNoteSeparator); invoiceNoteBuffer.append(invoiceNote); invoiceNoteBuffer.insert((index + 1), " " + phoneRoomPartVO.getQtyChosen().toString() + " "); index = invoiceNoteBuffer.toString().lastIndexOf(invoiceNoteSeparator); String storeNumber = phoneRoomPartVO.getStoreNumber(); if (phoneRoomPartVO.getServingDC() == null || !phoneRoomPartVO.getServingDC().booleanValue()) { storeNumber = InvoiceBL.formatStoreNumber(phoneRoomPartVO.getStoreNumber()); } storeNumber = storeNumber + " - " + phoneRoomPartVO.getStoreName(); invoiceNoteBuffer.insert((index + 1), " " + storeNumber); if (remoteStoreNumber != null && !remoteStoreNumber.trim().equals(phoneRoomPartVO.getStoreNumber())) { if (phoneRoomPartVO.getServingDC() != null && phoneRoomPartVO.getServingDC().booleanValue()) { String ejoei = ClientApplicationContext.getClientApplicationContext() .getMessageMgr().getMessage("9541").getText(); invoiceNoteBuffer.append(" (" + ejoei + ")"); } else { String transfer = ClientApplicationContext.getClientApplicationContext() .getMessageMgr().getMessage("9540").getText(); invoiceNoteBuffer.append(" (" + transfer + ")"); } } agSPhoneRoomItem.setText(invoiceNoteBuffer.toString()); } agSPhoneRoomItem.setCompletedLine(true); return agSPhoneRoomItem; } public static InvoiceNoteVO createFulfillmentMessage(final BaseLineItemVO baseLineItemVO, FulfillmentVO fulfillmentVO) { final FulfillmentIdentifierVO fulfillmentIdentifierVO = fulfillmentVO.getFulfillmentIdentifierVO(); final FulfillmentItemVO fulfillmentItemVO = (FulfillmentItemVO)fulfillmentVO.getFulfillmentItems().get(0); final InvoiceNoteVO fulfillmentNote = new InvoiceNoteVO(); fulfillmentNote.setRefInvoiceNoteTyepID(new Integer(RefInvoiceNoteType.NORMAL_MESSAGE)); fulfillmentNote.setGeneratedByLineItem(baseLineItemVO); final String invoiceNote = ClientApplicationContext.getClientApplicationContext().getRefTableDAO() .getInvoiceNoteText(new Integer(RefInvoiceNoteType.PHONE_ROOM_MESSAGE), ClientApplicationContext.getClientApplicationContext().getCurrentLocale().getLanguage()); if (invoiceNote != null) { StringBuffer invoiceNoteBuffer = new StringBuffer(); String invoiceNoteSeparator = ":"; int index = invoiceNote.indexOf(invoiceNoteSeparator); invoiceNoteBuffer.append(invoiceNote); invoiceNoteBuffer.insert((index + 1), " " + fulfillmentItemVO.getOrderPartCount().toString() + " "); index = invoiceNoteBuffer.toString().lastIndexOf(invoiceNoteSeparator); if(fulfillmentIdentifierVO.getRefFulfillmentIdentifierTypeId().intValue() == 4){ final int spaceIndex = fulfillmentIdentifierVO.getFulfillmentIdentifier().indexOf(" "); String storeNumber = fulfillmentIdentifierVO.getFulfillmentIdentifier().substring(0, spaceIndex); storeNumber = InvoiceBL.formatStoreNumber(storeNumber); storeNumber = storeNumber + " - " + fulfillmentIdentifierVO.getFulfillmentIdentifier().substring(spaceIndex + 1); invoiceNoteBuffer.insert((index + 1), " " + storeNumber); } else { invoiceNoteBuffer.insert((index + 1), " " + fulfillmentIdentifierVO.getFulfillmentIdentifier()); } fulfillmentNote.setText(invoiceNoteBuffer.toString()); } fulfillmentNote.setCompletedLine(true); return fulfillmentNote; } /** * Generates {@link VehicleVO} object if vehicle information exists in {@link BaseLineItemVO} * object. * * @param baseLineItemVO the {@link BaseLineItemVO} object */ public static void generateVehicleVO(BaseLineItemVO baseLineItemVO) { VehicleVO vehicleVO = new VehicleVO(); if (baseLineItemVO.getVehicleMake() != null) { IDValuePairVO vehicleMake = new IDValuePairVO(); vehicleMake.setID(new Integer("0")); vehicleMake.setValue((Object) baseLineItemVO.getVehicleMake()); vehicleVO.setMake(vehicleMake); } if (baseLineItemVO.getVehicleModel() != null) { IDValuePairVO vehicleModel = new IDValuePairVO(); vehicleModel.setID(new Integer(0)); vehicleModel.setValue((Object) baseLineItemVO.getVehicleModel()); vehicleVO.setModel(vehicleModel); } if (baseLineItemVO.getVehicleYear() != null) { vehicleVO.setYear(baseLineItemVO.getVehicleYear().intValue()); } baseLineItemVO.setVehicleVO(vehicleVO); } /** * Removes the phone room message line items. * * @param invoiceVO the {@link InvoiceVO} object * @param baseLineItemVO the (@link BaseLineItemVO} object */ public static void removePhoneRoomMessages(InvoiceVO invoiceVO, BaseLineItemVO baseLineItemVO) { Vector itemList = invoiceVO.getLineItems(); if (itemList != null) { int listSize = itemList.size(); InvoiceLineItemVO lineItem = null; for (int index = 0; index < listSize; index++) { lineItem = (InvoiceLineItemVO) itemList.elementAt(index); if (lineItem instanceof InvoiceNoteVO) { InvoiceNoteVO invoiceNoteVO = (InvoiceNoteVO) lineItem; if (invoiceNoteVO.getGeneratedByLineItem() != null && invoiceNoteVO.getGeneratedByLineItem() == baseLineItemVO && invoiceNoteVO.getRefInvoiceNoteTyepID() != null && invoiceNoteVO.getRefInvoiceNoteTyepID().intValue() == RefInvoiceNoteType.PHONE_ROOM_MESSAGE) { itemList.remove(index); listSize = itemList.size(); index--; } } } } } /** * Gets the available quantity from multi store. * * @param remoteStoreNumber the remote store number * @param lineAbbreviation the line abbreviation * @param partNumber the part number * @return the available quantity */ public static String getAvailableQuantityFromMultiStore(String remoteStoreNumber, String lineAbbreviation, String partNumber) { String availableQuantity = "0.00"; Vector storeList = null; if(remoteStoreNumber == null || lineAbbreviation == null || partNumber == null) { return availableQuantity; } ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); StoreProfileVO storeProfile = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()) .getStoreProfile(); try { if (storeProfile.getMultiStoreInUse().booleanValue()) { MultiStoreProfileVO multiStoreProfileVO = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()) .getMulitStoreProfile(); storeList = clientApplicationContext.getInventoryDAO().getMSStockCheck( new Integer(clientApplicationContext.getLocation()), lineAbbreviation, partNumber, multiStoreProfileVO); logger.warn("****fetched storeList vector************"); } } catch (ApplicationException ex) { logger.error("An error occured while attempting to fetch multistore quantities " + "for item", ex); } if (storeList != null && !storeList.isEmpty()) { // Get last three digits of store number int lastThreeDigitsOfStore = 0; if (remoteStoreNumber != null && remoteStoreNumber.length() > 3) { lastThreeDigitsOfStore = new Integer( remoteStoreNumber.substring(remoteStoreNumber.length() - 3)).intValue(); } // Compare with multi store id to get the quantity int listSize = storeList.size(); for (int index = 0; index < listSize; index++) { MSStockCheckVO stockCheckVO = (MSStockCheckVO) storeList.get(index); Integer storeId = stockCheckVO.getStID(); logger.debug("storeId => " + storeId); logger.debug("lastThreeDigitsOfStore => " + lastThreeDigitsOfStore); if (storeId != null && stockCheckVO.getOnHand() != null && storeId.intValue() == lastThreeDigitsOfStore) { availableQuantity = stockCheckVO.getOnHand().toString() + ".00"; break; } } } return availableQuantity; } /** * Gets the on hand quantity for supersede parts from multi store. * * @param supersedePartVOList the {@link SupersedePartVO} objects list containing supersede * part information * @param remoteStoreNumber the remote store number * @return the vector of {@link SupersedePartVO} objects updated with on hand quantity * @throws ApplicationException if any application exception occurs. */ public static Vector getOnHandForSupersedePartsFromMultiStore(Vector supersedingParts, String remoteStoreNumber) throws ApplicationException { String availableQuantity = null; BigDecimal zeroAvailable = new BigDecimal("0.00"); Vector storeList = null; ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); Integer location = new Integer(clientApplicationContext.getLocation()); MultiStoreProfileVO multiStoreProfileVO = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, location.intValue()).getMulitStoreProfile(); StoreProfileVO storeProfile = clientApplicationContext.getProfile( Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()) .getStoreProfile(); int lastThreeDigitsOfStore = 0; if (remoteStoreNumber != null && remoteStoreNumber.length() > 3) { lastThreeDigitsOfStore = new Integer( remoteStoreNumber.substring(remoteStoreNumber.length() - 3)).intValue(); } boolean multiStoreInUse = storeProfile.getMultiStoreInUse().booleanValue(); if (supersedingParts != null) { int listSize = supersedingParts.size(); for (int index = 0; index < listSize; index++) { SupersedePartVO supersedePartVO = (SupersedePartVO) supersedingParts.get(index); if (multiStoreInUse) { storeList = clientApplicationContext.getInventoryDAO().getMSStockCheck( location, supersedePartVO.getSupersedingLineAbbrev(), supersedePartVO.getSupersedingPartNumber(), multiStoreProfileVO); if (storeList != null && !storeList.isEmpty()) { int storeListSize = storeList.size(); for (int storeListIndex = 0; storeListIndex < storeListSize; storeListIndex++) { MSStockCheckVO stockCheckVO = (MSStockCheckVO) storeList .get(storeListIndex); Integer storeId = stockCheckVO.getStID(); if (storeId != null && storeId.intValue() == lastThreeDigitsOfStore) { if (stockCheckVO.getOnHand() != null) { availableQuantity = stockCheckVO.getOnHand().toString() + ".00"; supersedePartVO .setStockOnHand(new BigDecimal(availableQuantity)); } else { supersedePartVO.setStockOnHand(zeroAvailable); } break; } } } } } } return supersedingParts; } /** * Gets the available quantity by store. * * @param location the location * @param invoiceVO the {@link InvoiceVO} object containing invoice information * @param inventoryVO the {@link InventoryVO} object containing inventory information * @param customerVO the {@link CustomerVO} object containing customer information * @return the available quantity by store */ public static String getAvailableQuantityByStore(Integer location, InvoiceVO invoiceVO, InventoryVO inventoryVO, CustomerVO customerVO, boolean isFromCheckout, String remoteStoreIP) { String availableString = ""; boolean multiStoreInUse = false; boolean isRemoteStore = false; ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); // Check for multi store in use if (invoiceVO != null && invoiceVO.getRemoteStoreNumber() != null) { logger.warn("****entering logic to get multiStoreInUse************"); multiStoreInUse = remoteStoreIP!=null?PhoneRoomInvoiceBL.isMultiStoreInUse(invoiceVO.getRemoteStoreNumber(), inventoryVO.getPartNumber(), inventoryVO.getLineAbbrev(),remoteStoreIP) :InvoiceBL.isMultiStoreInUse(invoiceVO.getRemoteStoreNumber(), inventoryVO.getPartNumber(), inventoryVO.getLineAbbrev()); isRemoteStore = InvoiceBL.isRemoteStore(invoiceVO.getRemoteStoreNumber()); } // If multi store in use and if it is remote store , get available quantity from multi store if (multiStoreInUse && isRemoteStore ) { logger.warn("****getAvailableQuantity From MultiStore************"); availableString = remoteStoreIP!=null?PhoneRoomInvoiceLineBL.getAvailableQuantityFromMultiStore( invoiceVO.getRemoteStoreNumber(), inventoryVO.getLineAbbrev(), inventoryVO.getPartNumber(),remoteStoreIP) :InvoiceLineBL.getAvailableQuantityFromMultiStore( invoiceVO.getRemoteStoreNumber(), inventoryVO.getLineAbbrev(), inventoryVO.getPartNumber()); logger.warn("****getAvailableQuantity From MultiStore END************"); } else if (invoiceVO != null && invoiceVO.getRemoteStoreNumber() != null && isRemoteStore) { try { logger.warn("****getAvailableByStore from remote store************"); //if the flow is through checkout button, then we need to do saperate call to get avail qty for all line items, so just sending string to handle that logic in InvoiceBL method if(isFromCheckout){ availableString = TsoConstant.Get_OnHand_For_Checkout_screen; }else{ List inventoryVOList = new ArrayList<>(); inventoryVOList.add(inventoryVO); List onHandResponse = null; if(invoiceVO.getRemoteStoreNumber()!=null){ onHandResponse= new PhoneRoomTaapRouter().getOnHandForRemoteStore(inventoryVOList, PhoneRoomInvoiceBL.getRemoteIpAddress(invoiceVO.getRemoteStoreNumber())); } availableString = onHandResponse!=null && !onHandResponse.isEmpty()?onHandResponse.get(0).getOnHandQuantity():"0.00"; } logger.warn("****getAvailableByStore from remote store end************"); } catch (ApplicationException exception) { logger.error("An error occured while attempting to fetch available quantity for item", exception); } } else if (inventoryVO != null && inventoryVO.getInventoryStockVO() != null) { availableString = inventoryVO.getInventoryStockVO().getInventoryAvailable(); } else { availableString = "0.00"; } return availableString; } public static IDValuePairVO getServingDC(final InventoryVO inventoryVO) throws ApplicationException{ final Vector dcList = ClientApplicationContext.getClientApplicationContext().getEJOEIDAO().getDistributionCenterList( inventoryVO.getExpandedPartNumber(), inventoryVO.getLineAbbrev(), ClientApplicationContext.getClientApplicationContext().getCurrentLocale().getLanguage(), ClientApplicationContext.getClientApplicationContext().getCurrentUser().getEmployeeId().intValue(), ClientApplicationContext.getClientApplicationContext().getLocation(), ClientApplicationContext.getClientApplicationContext().getCurrentUser()); String dcQuantity = null; String dcName = null; if(dcList != null && dcList.size() > 0){ //The serving DC should be the first one in the vector. IDValuePairVO valuePairVO = (IDValuePairVO)dcList.elementAt(0); int index = 0; while (valuePairVO != null && valuePairVO.validVO() && valuePairVO.getID() instanceof Integer && index < dcList.size()+1) { index = index+1; valuePairVO = (IDValuePairVO) dcList.elementAt(index); } if ((valuePairVO != null) && valuePairVO.validVO()) { try { dcName = (String)valuePairVO.getID(); if (valuePairVO.getValue() instanceof String) { dcQuantity = (String)valuePairVO.getValue(); if (dcQuantity.indexOf(",") > 0) { dcQuantity = dcQuantity.substring(0, dcQuantity.indexOf(",")); } dcQuantity = Integer.valueOf(dcQuantity).toString(); } else { dcQuantity = ((Integer)valuePairVO.getValue()).toString(); } } catch (Exception e){ //there was an exception when casting the above values...no error to report } } } if (dcName == null) { dcName = "N/A"; } if (dcQuantity == null) { dcQuantity = "N/A"; } final IDValuePairVO dcInfo = new IDValuePairVO(); dcInfo.setID(dcName); dcInfo.setValue(dcQuantity); return dcInfo; } /** * Method is used to arrive at available quantity for virtual kit. * * @param baseLineItemVO * * @param subtractWorkInProgress * * @return */ public static BigDecimal getVirtualKitOnHandInServingDC(final BaseLineItemVO baseLineItemVO) { BigDecimal availableQty = new BigDecimal("0.00"); final Profile profile = ClientApplicationContext.getClientApplicationContext() .getProfile(Profile.POINT_OF_SALE_CLIENT, ClientApplicationContext.getClientApplicationContext().getLocation()); boolean useRads = profile.getInvoicingProfile().getUseRads().booleanValue(); final boolean dcStore = profile.getStoreProfile().getDcStore().booleanValue(); final boolean usStore = RefCountry.UNITED_STATES.equalsIgnoreCase(profile.getStoreProfile().getRefCountryCd()); final boolean isNAPAXpress = profile.getStoreProfile().getUseNapaXpress().booleanValue(); if(!useRads || !dcStore || !usStore || !isNAPAXpress) { return availableQty; } if(availableQty.signum() == -1){ availableQty = new BigDecimal("0.00"); } int kitsOnHand = 0; List components = baseLineItemVO.getComponents(); if(components == null) return new BigDecimal(kitsOnHand); for (Iterator iterator = components.iterator();iterator.hasNext();) { KitLineItemVO kitLineItemVO = (KitLineItemVO) iterator.next(); int componentRequiredQty = kitLineItemVO.getRequiredQuantity().intValue(); if (componentRequiredQty > 0) { InventoryVO compInventoryVO = new InventoryVO(); compInventoryVO.setExpandedPartNumber(kitLineItemVO.getPartNum()); compInventoryVO.setLineAbbrev(kitLineItemVO.getLineAbbr()); int componentQty = 0; try { final IDValuePairVO dcInfo = getServingDC(compInventoryVO); componentQty = new Integer((String)dcInfo.getValue()).intValue(); } catch (ApplicationException applicationException) { logger.error(applicationException, applicationException); } if (componentQty == 0 || componentRequiredQty > componentQty) { kitsOnHand = 0; break; } int kitQty = componentQty / componentRequiredQty; if (kitsOnHand > 0) { kitsOnHand = Math.min(kitsOnHand, kitQty); } else { kitsOnHand = kitQty; } } } return new BigDecimal(kitsOnHand).setScale(2, BigDecimal.ROUND_DOWN); } public static BaseLineItemVO createLineItemForRewards(InvoiceVO invoiceVO, CustomerVO customerVO, BigDecimal price, BigDecimal quantity) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); BaseLineItemVO baseLineItemVO = new BaseLineItemVO(); InventoryVO inventoryVO = clientApplicationContext.getInventoryDAO() .getPartDetailInfo(customerVO, LoyaltyConstants.REWARD_PART, LoyaltyConstants.REWARD_LINE, false); if (inventoryVO != null){ baseLineItemVO.setLOC(inventoryVO.getLOC()); baseLineItemVO.setPartNum(inventoryVO.getPartNumber()); baseLineItemVO.setExpandedPartNum(inventoryVO.getPartNumber()); baseLineItemVO.setLineAbbr(inventoryVO.getLineAbbrev()); baseLineItemVO.setPartDescription(inventoryVO.getDescription()); baseLineItemVO.setQuantityBilled(quantity); baseLineItemVO.setCountermanEmployeeID(clientApplicationContext.getCurrentUser() .getEmployeeId()); baseLineItemVO.setGroupCode(inventoryVO.getGroupCode()); baseLineItemVO.setRefInvoiceLineItemTypeID(new Byte( (byte) RefInvoiceLineItemType.NAPA_REWARDS)); baseLineItemVO.setUnitPrice(price); baseLineItemVO.setUnitListPrice(price); baseLineItemVO.setExtendedPrice(CommonInvoiceLineBL.getExtendedPrice(baseLineItemVO)); baseLineItemVO.setLoyaltyEligible(false); TaxDecisionVO taxDecision = Tax.getTaxDecision(customerVO, inventoryVO, null, baseLineItemVO, null, null, Profile.POINT_OF_SALE_CLIENT); if (!taxDecision.getPrimaryTax().equals(Tax.OPTIONAL)) { if (taxDecision.getPrimaryTax().equals(Tax.ALWAYS)) { baseLineItemVO.setTaxable1(Boolean.TRUE); } else { baseLineItemVO.setTaxable1(Boolean.FALSE); } } else { baseLineItemVO.setTaxable1(Boolean.TRUE); } if (!taxDecision.getSecondaryTax().equals(Tax.OPTIONAL)) { if (taxDecision.getSecondaryTax().equals(Tax.ALWAYS)) { baseLineItemVO.setTaxable2(Boolean.TRUE); } else { baseLineItemVO.setTaxable2(Boolean.FALSE); } } else { baseLineItemVO.setTaxable2(Boolean.TRUE); } } return baseLineItemVO; } /** * This method checks for part and customer certificate. If customer is having valid certificate * then certificate information will be populated to {@link InvoiceLineItemCertificationVO} * object. * If the part is return item then it populate only the part certification info. * @param location - store location * @param customerId - customer id * @param inventoryVO - contains inventory information * @param baseLineItem - contains invoice line item information * @param bdQuantity - contains billed quantity * @return boolean value indicating part is allowed for sale or not */ public static boolean checkForPartSaleAndPopulateCertInfo(Integer location, Integer customerId, InventoryVO inventoryVO, BaseLineItemVO baseLineItem, BigDecimal bdQuantity) { boolean isEligibleForPartSale = true; ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); PartCertificationVO partCertificationVO = (inventoryVO == null ? null : inventoryVO.getPartCertificationVO()); Integer certPartGroupId = (partCertificationVO == null ? null : partCertificationVO .getCertificationPartGroupId()); if (partCertificationVO != null && partCertificationVO.isGovCertExistForCustomer()) { CustomerCertificateVO customerCertificate = null; try { customerCertificate = clientApplicationContext.getCustomerDAO() .getCustomerCertificateInfo(location, customerId, certPartGroupId); isEligibleForPartSale = (customerCertificate == null) ? false : true; } catch (ApplicationException exception) { logger.error("Exception occured while getting customer part certifications", exception); } if (isEligibleForPartSale && customerCertificate != null && bdQuantity.signum() > 0) { InvoiceLineItemCertificationVO invoiceLineItemCertification = new InvoiceLineItemCertificationVO(); invoiceLineItemCertification.setCertificationCategory(customerCertificate .getCertificationCategory()); invoiceLineItemCertification.setCertificateNumber(customerCertificate .getCertificateNumber()); invoiceLineItemCertification.setCertificationGroup(customerCertificate .getCertificationGroup()); invoiceLineItemCertification.setTechnicianName(customerCertificate .getTechnicianName()); invoiceLineItemCertification.setDescription(customerCertificate.getDescription()); invoiceLineItemCertification.setBeginDate(customerCertificate.getBeginDate()); invoiceLineItemCertification.setEndDate(customerCertificate.getEndDate()); baseLineItem.setInvoiceLineItemCertification(invoiceLineItemCertification); } } //populate part certification info when part returns if (bdQuantity.signum() < 0 && partCertificationVO != null) { InvoiceLineItemCertificationVO invoiceLineItemCertification = new InvoiceLineItemCertificationVO(); invoiceLineItemCertification.setCertificationCategory(partCertificationVO .getCertificationCategory()); invoiceLineItemCertification.setCertificationGroup(partCertificationVO .getCertificationGroup()); invoiceLineItemCertification.setDescription(partCertificationVO.getDescription()); baseLineItem.setInvoiceLineItemCertification(invoiceLineItemCertification); } return isEligibleForPartSale; } /** * * @param location * @param customerId * @param inventoryVO * @param baseLineItem * @param bdQuantity * @param remoteStoreIP * @return */ public static boolean waiverCertAvaialble(Integer location, CustomerVO customerVO, String partNumber, String LineAbbr, boolean isPhoneRoom) { boolean waiverCert = false; // As per Colette Blanton, Phone room will be excluded from Block Sales, so defaulting isPhoneRoom as false; isPhoneRoom= false; try { if (isPhoneRoom) { String remoteStoreIP = PhoneRoomInvoiceBL.getRemoteIpAddress( ((ClientApplicationContext) ClientApplicationContext.getInstance()).getRemoteStoreNumber()); InventoryVO inventoryVo = new PhoneRoomTaapRouter().getPartDetailInfo(customerVO, LineAbbr, partNumber, false, remoteStoreIP, clientApplicationContext.getCurrentLocale().getLanguage(), false); waiverCert = PhoneRoomInvoiceLineBL.isCertRequiredAndCustomerHasCert(location, customerVO.getID(), inventoryVo, remoteStoreIP); } else { InventoryVO inventoryVo = clientApplicationContext.getInventoryDAO().getPartDetailInfo(customerVO, partNumber, LineAbbr, false); waiverCert = isCertRequiredAndCustomerHasCert(location, customerVO.getID(), inventoryVo); } } catch (ApplicationException e) { logger.error(e.getMessage(), e); } return waiverCert; } /** * This method checks for part and customer certificate. If customer is having valid certificate * then certificate information will be populated to {@link InvoiceLineItemCertificationVO} * object. * If the part is return item then it populate only the part certification info. * @param location - store location * @param customerId - customer id * @param inventoryVO - contains inventory information * @param baseLineItem - contains invoice line item information * @param bdQuantity - contains billed quantity * @return boolean value indicating part is allowed for sale or not */ public static boolean isCertRequiredAndCustomerHasCert(Integer location, Integer customerId, InventoryVO inventoryVO) { boolean isEligibleForPartSale = false; ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); PartCertificationVO partCertificationVO = (inventoryVO == null ? null : inventoryVO.getPartCertificationVO()); Integer certPartGroupId = (partCertificationVO == null ? null : partCertificationVO .getCertificationPartGroupId()); if (partCertificationVO != null && partCertificationVO.isGovCertExistForCustomer()) { CustomerCertificateVO customerCertificate = null; try { customerCertificate = clientApplicationContext.getCustomerDAO() .getCustomerCertificateInfo(location, customerId, certPartGroupId); isEligibleForPartSale = (customerCertificate == null) ? false : true; } catch (ApplicationException exception) { logger.error("Exception occured while getting customer part certifications", exception); } } return isEligibleForPartSale; } /** * This method will check weather the customer is having alternate core customer or not * If customer is having alternate core customer and transaction is a core transaction and the * alternate core customer primary tax status is NEVER then this method will return true. * If customer is not having alternate core customer or transaction is not a core transaction * and the primary tax status is NEVER then this method will return true. * If non of the above conditions satisfy then this method will return false. * @param customerVO - Current customer details. * @return - true if conditions satisfy, if not false. */ public static boolean isPrimaryTaxEnabledForCustomer( CustomerVO customerVO, BaseLineItemVO baseLineItemVO) { if (((customerVO.getAlternateCoreCustomerTax() == null || !baseLineItemVO .isCoreTransaction().booleanValue()) && customerVO.getTaxStatusPrimaryRefOptionCD() .equals(Tax.NEVER)) || (customerVO.getAlternateCoreCustomerTax() != null && baseLineItemVO.isCoreTransaction().booleanValue() && customerVO .getAlternateCoreCustomerTax().getTaxStatusPrimaryRefOptionCD().equals( Tax.NEVER))) { return true; } return false; } /** * This method will check weather the customer is having alternate core customer or not * If customer is having alternate core customer and transaction is a core transaction and the * alternate core customer secondary tax status is NEVER then this method will return true. * If customer is not having alternate core customer or transaction is not a core transaction * and the secondary tax status is NEVER then this method will return true. * If non of the above conditions satisfy then this method will return false. * @param customerVO - Current customer details. * @return - true if conditions satisfy, if not false. */ public static boolean isSecondaryTaxEnabledForCustomer( CustomerVO customerVO, BaseLineItemVO baseLineItemVO) { if (((customerVO.getAlternateCoreCustomerTax() == null || !baseLineItemVO .isCoreTransaction().booleanValue()) && customerVO .getTaxStatusSecondaryRefOptionCD().equals(Tax.NEVER)) || (baseLineItemVO.isCoreTransaction().booleanValue() && customerVO.getAlternateCoreCustomerTax() != null && customerVO .getAlternateCoreCustomerTax().getTaxStatusSecondaryRefOptionCD().equals( Tax.NEVER))) { return true; } return false; } /* * This method will reset core return line item tax decision based on 'Validate Core Return * Tax Number' setting of primary and secondary tax tables */ public static void resetCoreTaxDecisionBasedOnCustTaxNumbers( InvoiceVO invoiceVO, BaseLineItemVO coreLineItem) { logger.error("invoiceVO.getPrimaryTaxNumber() => " + invoiceVO.getPrimaryTaxNumber()); logger.error("invoiceVO.getSecondaryTaxNumber() => " + invoiceVO.getSecondaryTaxNumber()); BOPISLogger.getInstance().setStoreProfile(invoiceVO.getLOC()).addBOPISLog(Constants.INFO, "invoiceVO.getPrimaryTaxNumber() => " + invoiceVO.getPrimaryTaxNumber() + "invoiceVO.getSecondaryTaxNumber() => " + invoiceVO.getSecondaryTaxNumber()); if(coreLineItem.getTaxable1().booleanValue() && invoiceVO.getPrimaryTaxTableVO().isValidateCoreReturnTaxNumber()) { if(invoiceVO.getPrimaryTaxNumber() == null || invoiceVO.getPrimaryTaxNumber().trim().equals(TsoConstant.EMPTY_STRING)) { coreLineItem.setTaxable1(Boolean.FALSE); } } if(coreLineItem.getTaxable2().booleanValue() && invoiceVO.getSecondaryTaxTableVO() != null && invoiceVO.getSecondaryTaxTableVO().isValidateCoreReturnTaxNumber()) { if(invoiceVO.getSecondaryTaxNumber() == null || invoiceVO.getSecondaryTaxNumber().trim().equals(TsoConstant.EMPTY_STRING)) { coreLineItem.setTaxable2(Boolean.FALSE); } } } /** * Method is used to round up the price value to next penny if the decimal value exists after * two decimal places. * * @param actualPriceValue is the input price value * * @return a rounded price value if the price value is having more than two decimal places. */ public static BigDecimal getRoundedValue(BigDecimal actualPriceValue) { final String methodSpec = "InvoiceLineBL.getRoundedValue - "; logger.debug(methodSpec + "actualPriceValue = " + actualPriceValue); BigDecimal roundedPriceValue = actualPriceValue; // Check if 3rd & 4th decimal places have non zero values if (actualPriceValue != null && actualPriceValue.scale() > 2) { try { final String priceValue = actualPriceValue.toString(); final String lastTwoDecimalDigits = priceValue.substring( priceValue.indexOf('.') + 3, priceValue.length()); logger.debug(methodSpec + "lastTwoDecimalDigits = " + lastTwoDecimalDigits); if (new Integer(lastTwoDecimalDigits).intValue() == 0) { actualPriceValue = actualPriceValue.setScale(2, BigDecimal.ROUND_HALF_UP); } } catch (Exception exception) { logger.error("Exception occured while rounding of value = " + actualPriceValue); } } if (actualPriceValue != null && actualPriceValue.scale() > 2) { // if price value is having more than two decimal places then the price value is // rounded to next penny final String priceValue = actualPriceValue.toString(); final String truncatedPriceValue = priceValue.substring(0, priceValue.indexOf('.') + 3); roundedPriceValue = new BigDecimal(truncatedPriceValue).add(new BigDecimal("0.01")); } logger.debug(methodSpec + "roundedPriceValue = " + roundedPriceValue); return roundedPriceValue; } /** * Method is used to get the display price value with tax included based on line item unit price * value. * * @param unitPrice is the line item unit price value * * @param {@link BaseLineItemVO} value object containing line item information. * * @param {@link InvoiceVO} value object containing invoice information. * * @param {@link CustomerVO} value object containing customer information. * * @param {@link InventoryVO} value object containing inventory information. * * @param {@link MiscChgVO} value object containing misc charge information */ public static BigDecimal getDisplayPriceFromUnitPrice(final BigDecimal unitPrice, final BaseLineItemVO baseLineItem, final InvoiceVO invoiceVO, final CustomerVO customerVO, final InventoryVO inventoryVO, final MiscChgVO miscChgVO) { BigDecimal displayPrice = new BigDecimal("0.00"); TaxInfoVO productLineTaxInfo = null; if (baseLineItem != null) { final ClientApplicationContext applicationContext = ClientApplicationContext .getClientApplicationContext(); if (inventoryVO != null) { productLineTaxInfo = applicationContext.getInventoryDAO().getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode()); } displayPrice = getDisplayPriceFromUnitPrice(unitPrice, baseLineItem, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo); BOPISLogger.getInstance().setStoreProfile(invoiceVO.getLOC()).addBOPISLog(Constants.INFO, "getDisplayPriceFromUnitPrice() displayPrice:- " + displayPrice); } return displayPrice; } /** * Method is used to set the display price value with tax included based on line item unit price * value. * * @param unitPrice is the line item unit price value * * @param {@link BaseLineItemVO} value object containing line item information. * * @param {@link InvoiceVO} value object containing invoice information. * * @param {@link CustomerVO} value object containing customer information. * * @param {@link InventoryVO} value object containing inventory information. */ public static void setDisplayPriceFromUnitPrice(final BigDecimal unitPrice, final BaseLineItemVO baseLineItem, final InvoiceVO invoiceVO, final CustomerVO customerVO, final InventoryVO inventoryVO) { TaxInfoVO productLineTaxInfo = null; final ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); if (inventoryVO != null) { productLineTaxInfo = clientApplicationContext.getInventoryDAO().getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode()); } setDisplayPriceFromUnitPrice(unitPrice, baseLineItem, invoiceVO, customerVO, inventoryVO, productLineTaxInfo); } /** * Method is used to get the line item unit price value based on the display price value entered * in line entry area PD / List field. * * @param displayPrice is the display price value * * @param {@link BaseLineItemVO} value object containing line item information. * * @param {@link InvoiceVO} value object containing invoice information. * * @param {@link CustomerVO} value object containing customer information. * * @param {@link InventoryVO} value object containing inventory information. * * @param {@link MiscChgVO} value object containing misc charge information. * * @return actual unit price value based on display price entered in line entry area. */ public static BigDecimal getActualPriceFromDisplayPrice(final BigDecimal displayPrice, final BaseLineItemVO baseLineItemVO, final InvoiceVO invoiceVO, final CustomerVO customerVO, final InventoryVO inventoryVO, final MiscChgVO miscChgVO) { BigDecimal actualPrice = null; if (baseLineItemVO != null && customerVO != null) { final ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); TaxInfoVO productLineTaxInfo = null; if (inventoryVO != null) { productLineTaxInfo = clientApplicationContext.getInventoryDAO() .getProductLineTaxInfo(inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode()); } actualPrice = getActualPriceFromDisplayPrice(displayPrice, baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo); } return actualPrice; } /** * Method is used to re-calculate line item price value based on primary/secondary tax flag. * * @param {@link BaseLineItemVO} value object containing line item information. * * @param {@link InvoiceVO} value object containing invoice information. * * @param {@link CustomerVO} value object containing customer information. * * @param {@link InventoryVO} value object containing inventory information. * * @param {@link MiscChgVO} value object containing misc charge information */ public static void recalculateLineItemPrices(final BaseLineItemVO baseLineItemVO, final InvoiceVO invoiceVO, final CustomerVO customerVO, final InventoryVO inventoryVO, final MiscChgVO miscChgVO) { final String methodSpec = "InvoiceLineBL.recalculateLineItemPrices() - "; logger.debug(methodSpec); TaxInfoVO productLineTaxInfo = null; final ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); if (inventoryVO != null) { productLineTaxInfo = clientApplicationContext.getInventoryDAO().getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode()); } if (baseLineItemVO.getDisplayPriceEntered() != null && baseLineItemVO.getDisplayPriceEntered().booleanValue()) { baseLineItemVO.setUnitPrice(getActualPriceFromDisplayPrice( baseLineItemVO.getDisplayUnitPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo)); baseLineItemVO.setExtendedPrice(getExtendedPrice(baseLineItemVO)); } else { baseLineItemVO.setDisplayUnitPrice(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo)); baseLineItemVO.setDisplayExtendedPrice(getDisplayExtendedPrice(baseLineItemVO)); } if (baseLineItemVO.getDisplayListPriceEntered() != null && baseLineItemVO.getDisplayListPriceEntered().booleanValue()) { baseLineItemVO.setUnitListPrice(getActualPriceFromDisplayPrice( baseLineItemVO.getDisplayUnitListPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo)); } else { baseLineItemVO.setDisplayUnitListPrice(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitListPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo)); } baseLineItemVO.setDisplayUnitCost(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitCost(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo)); } /** * This method checks whether line item is defective replacement line item or not. * @param baseLineItemVO value object. * @return a boolean indicator whether the line item is replacement defective line item or not. */ public static boolean isDefectiveReplacementLineItem(BaseLineItemVO baseLineItemVO) { InvoiceLineItemVO purchaseLineItem = baseLineItemVO.getGeneratedByLineItem(); if (purchaseLineItem == null) { return false; } if (!(purchaseLineItem instanceof BaseLineItemVO)) { return false; } if(purchaseLineItem.getQuantityBilled().signum() > 0){ return false; } if (baseLineItemVO.getQuantityBilled().equals( purchaseLineItem.getQuantityBilled().negate())) { return true; } return false; } /** * This method logs if virtual kit received by TAMS is different from what it has. * @param baseLineItemVO value object. * @param customerVO value object. */ public static void logKitMismatchIfAny(BaseLineItemVO baseLineItemVO, CustomerVO customerVO) { final InventoryVO inventoryVO = ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getPartDetailInfo( customerVO, baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), false); if (inventoryVO == null){ logger.error("Virtual kit mismatch: kit part not in inventory - "+baseLineItemVO.getPartNum()+" "+ baseLineItemVO.getLineAbbr()); printComponents(baseLineItemVO.getComponents()); } else { if (inventoryVO instanceof KitInventoryVO){ logger.error(" ***Virtual kit found in kit_participation*** "+baseLineItemVO.getPartNum()+ " "+ baseLineItemVO.getLineAbbr()); List inventoryRecords = ((KitInventoryVO) inventoryVO).getComponentInventoryList(); final List virtualKitComponents = baseLineItemVO.getComponents(); if (inventoryRecords != null && virtualKitComponents != null){ if( inventoryRecords.size() != virtualKitComponents.size()) { logger.error(" ***Components do not match with kit_participation entries *** "); printComponents(baseLineItemVO.getComponents()); } } } else { logger.error("Virtual kit mismatch: kit part found in inventory but not in kit_particiapation - "+baseLineItemVO.getPartNum()+" "+ baseLineItemVO.getLineAbbr()); printComponents(baseLineItemVO.getComponents()); } } } private static void printComponents(List components) { if (components == null || components.size() <= 0) { return; } logger.error("Virtual Kit components are: "); for (int index = 0; index < components.size(); index++) { final KitLineItemVO componentVO = (KitLineItemVO) components .get(index); logger.error("Compenent part/line: " + componentVO.getPartNum() + " " + componentVO.getLineAbbr()); } } public static KitInventoryVO getVirtualKitDetailInfo(final CustomerVO customerVO, final BaseLineItemVO baseLineItemVO) { List definitionComponents = new ArrayList(); final KitDefinitionVO kitDefinitionVO = new KitDefinitionVO(); final PartIdentifierVO kitPartIdentifierVO = new PartIdentifierVO(); final InventoryVO inventoryVO = ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getPartDetailInfo(customerVO, baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), false, null); kitPartIdentifierVO.setId(inventoryVO.getID()); kitPartIdentifierVO.setLoc(inventoryVO.getLOC()); kitPartIdentifierVO.setLineAbbrev(inventoryVO.getLineAbbrev()); kitPartIdentifierVO.setPartNumber(inventoryVO.getExpandedPartNumber()); kitDefinitionVO.setKitPartIdentifier(kitPartIdentifierVO); final KitInventoryVO kitInventoryVO = (KitInventoryVO)ClientApplicationContext.getClientApplicationContext().getInventoryDAO().getPartDetailInfo(customerVO, baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), false, kitDefinitionVO); final List components = baseLineItemVO.getComponents(); kitInventoryVO.setKitDefinition(kitDefinitionVO); final List componentsInventory = new ArrayList(); for (int index = 0; index < components.size(); index++) { final KitLineItemVO kitLineItemVO = (KitLineItemVO)components.get(index); InventoryVO componentInventoryVO = ClientApplicationContext.getClientApplicationContext( ).getInventoryDAO().getPartDetailInfo(customerVO, kitLineItemVO.getPartNum(), kitLineItemVO.getLineAbbr(), false, null); if(componentInventoryVO == null){ componentInventoryVO = new InventoryVO(); componentInventoryVO.setLineAbbrev(kitLineItemVO.getLineAbbr()); componentInventoryVO.setPartNumber(kitLineItemVO.getPartNum()); componentInventoryVO.setExpandedPartNumber(kitLineItemVO.getExpandedPartNum()); componentInventoryVO.setDescription(kitLineItemVO.getPartDescription()); componentInventoryVO.setLOC(kitLineItemVO.getLOC()); componentInventoryVO.setID(new Integer(index * -1)); } final PartIdentifierVO componentPartIdentifierVO = new PartIdentifierVO(); componentPartIdentifierVO.setLoc(componentInventoryVO.getLOC()); componentPartIdentifierVO.setLineAbbrev(componentInventoryVO.getLineAbbrev()); componentPartIdentifierVO.setPartNumber(componentInventoryVO.getExpandedPartNumber()); componentPartIdentifierVO.setId(componentInventoryVO.getID()); final KitDefinitionComponentVO kitDefinitionComponentVO = new KitDefinitionComponentVO(); kitDefinitionComponentVO.setKitComponentPartIdentifier(componentPartIdentifierVO); kitDefinitionComponentVO.setRequiredQuantity(kitLineItemVO.getRequiredQuantity() != null ? new Integer(kitLineItemVO.getRequiredQuantity().intValue()) : new Integer(0)); definitionComponents.add(kitDefinitionComponentVO); componentsInventory.add(componentInventoryVO); } kitDefinitionVO.setKitDefinitionComponents(definitionComponents); for(int index = 0; index < componentsInventory.size(); index++){ kitInventoryVO.addComponentInventory((InventoryVO)componentsInventory.get(index)); } return kitInventoryVO; } public static BigDecimal getQtyAlreadyAdded(final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO){ final Vector existingLines = invoiceVO.getLineItems(); BigDecimal qtyAlreadyAdded = new BigDecimal(0); BigDecimal effectiveAddedQtyOfOneLine = new BigDecimal(0); ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); String storeLanguageCd = clientApplicationContext.getProfile(Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()).getStoreProfile().getRefLanguageCd(); String warrantyText= TsoConstant.WARRANTY_ADJUSTMENT_PERCENT_TEXT; try { warrantyText= clientApplicationContext.getRefTableDAO().getInvoiceLineDescription( new Integer(RefInvoiceLineItemDescription.WARRANTY_ADJUSTMENT_PERCENT), storeLanguageCd); } catch (ApplicationException e) { logger.error(e.getMessage()); } for(int index = 0; index < existingLines.size(); index++) { final InvoiceLineItemVO existingLine = (InvoiceLineItemVO)existingLines.get(index); if (existingLine instanceof BaseLineItemVO && (existingLine.getGeneratedByLineItem() == null || (existingLine.getGeneratedByLineItem().getQuantityBilled().signum() < 0 && existingLine.getGeneratedByLineItem().isDefective().booleanValue())) && existingLine.getPartNum().equals(baseLineItemVO.getPartNum()) && existingLine.getLineAbbr().equals(baseLineItemVO.getLineAbbr()) && !existingLine.isCoreTransaction().booleanValue() && existingLine.getQuantityBilled().signum() == 1) { if(baseLineItemVO.getId() != null && baseLineItemVO.getId().equals(existingLine.getId())){ continue; } if(TsoConstant.NAPA_XPRESS.equals(((BaseLineItemVO)existingLine).getSpecialOrder()) || TsoConstant.NXP_ORDERED.equals(((BaseLineItemVO)existingLine).getSpecialOrder()) || TsoConstant.NXP_DIRECT_SHIP_APPROVED_ORDERED.equals(((BaseLineItemVO)existingLine).getSpecialOrder())){ continue; } if (!(existingLine.getPartDescription() != null && (existingLine.getPartDescription().equalsIgnoreCase("WARRANTY ADJUSTMENT") || (existingLine.getPartDescription().equalsIgnoreCase(warrantyText))))) { effectiveAddedQtyOfOneLine = existingLine.getQuantityBilled() .subtract(((BaseLineItemVO) existingLine).getSpecialOrderedQuantity()) .setScale(2, BigDecimal.ROUND_HALF_UP); } qtyAlreadyAdded = qtyAlreadyAdded.add(effectiveAddedQtyOfOneLine).setScale(2, BigDecimal.ROUND_HALF_UP); } } return qtyAlreadyAdded; } public static BigDecimal getAvailableQty(final InventoryVO inventoryVO, final String dcStockQuantity){ BigDecimal availableQty = new BigDecimal("0.00"); BigDecimal dcQty = new BigDecimal("0.00"); if(inventoryVO != null && inventoryVO.getInventoryStockVO() != null){ availableQty = new BigDecimal(inventoryVO.getInventoryStockVO().getInventoryAvailable()); } if(dcStockQuantity != null && dcStockQuantity.trim().length() > 0){ try{ dcQty = new BigDecimal(dcStockQuantity); } catch(Exception exception){} } availableQty = availableQty.add(dcQty); if(availableQty.signum() < 0 && !inventoryVO.isForSavedWip()){ availableQty = new BigDecimal("0.00"); } return availableQty; } public static BigDecimal getQtyEligibleForSpecialOrder(final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity){ final BigDecimal qtyAlreadyAdded = InvoiceLineBL.getQtyAlreadyAdded(invoiceVO, baseLineItemVO); final BigDecimal qtyWithAlreadyAddedLines = quantity.add(qtyAlreadyAdded).setScale(2, BigDecimal.ROUND_HALF_UP); if(invoiceVO != null && invoiceVO.getIsSavedInvoice().booleanValue() && invoiceVO.getWorkInProgressUpdated().booleanValue()) { if(invoiceVO.isLoadedFromRecallSavedInvoice() && "L".equals(baseLineItemVO.getSpecialOrder()) ) { return new BigDecimal("0.00"); } inventoryVO.setForSavedWip(true); BigDecimal alreadySavedInwip = new BigDecimal("0.00"); final Vector existingLines = invoiceVO.getSavedLineItems(); for(int index = 0; index < existingLines.size(); index++) { final InvoiceLineItemVO existingLine = (InvoiceLineItemVO)existingLines.get(index); if(existingLine instanceof BaseLineItemVO && existingLine.getPartNum().equals(baseLineItemVO.getPartNum()) && existingLine.getLineAbbr().equals(baseLineItemVO.getLineAbbr()) && !existingLine.isCoreTransaction().booleanValue() && existingLine.getQuantityBilled().signum() == 1){ alreadySavedInwip = alreadySavedInwip.add(existingLine.getQuantityBilled()); } } BigDecimal availableQty = (InvoiceLineBL.getAvailableQty(inventoryVO, dcStockQuantity)).add(alreadySavedInwip); inventoryVO.setForSavedWip(false); if(availableQty.signum() < 0){ availableQty = new BigDecimal("0.00"); } return qtyWithAlreadyAddedLines.subtract(availableQty).setScale(2, BigDecimal.ROUND_HALF_UP); } return qtyWithAlreadyAddedLines.subtract(InvoiceLineBL.getAvailableQty(inventoryVO, dcStockQuantity)).setScale(2, BigDecimal.ROUND_HALF_UP); } public static void setSpecialOrder(final CustomerVO customerVO, final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity){ if(!ClientApplicationContext.getClientApplicationContext().getProfile(Profile.POINT_OF_SALE_CLIENT, ClientApplicationContext.getClientApplicationContext().getLocation()).getStoreProfile().getUseNapaXpress().booleanValue()) { return; } if (baseLineItemVO.isWarrantyLaborClaim().booleanValue() || baseLineItemVO.getQuantityBilled().signum() < 0 || invoiceVO.getManualTransaction().booleanValue() || inventoryVO == null || (inventoryVO.getCurrentYearRefClassCD() != null && inventoryVO.getCurrentYearRefClassCD().equalsIgnoreCase("Z") && !baseLineItemVO.isKitPart())) { return; } BigDecimal nonAvailableQty = new BigDecimal("0.00"); final InventoryProfileVO inventoryProfileVO = ApplicationContext.getInstance() .getProfile(Profile.POINT_OF_SALE_CLIENT, ClientApplicationContext .getClientApplicationContext().getLocation()) .getInventoryProfile(); if (inventoryProfileVO != null && inventoryProfileVO.getSourceNonNAPAPartsLocally() != null && inventoryProfileVO.getSourceNonNAPAPartsLocally().booleanValue() && inventoryVO != null && inventoryVO.getSupplierID() != null && inventoryVO.getSupplierID().intValue() > 1) { baseLineItemVO.setNonAvailableQty(nonAvailableQty); baseLineItemVO.setSpecialOrder(TsoConstant.LOCAL); return; } String specialOrder = (baseLineItemVO.getSpecialOrder() == null) ? TsoConstant.LOCAL : baseLineItemVO.getSpecialOrder(); if((baseLineItemVO.getFulfillments() == null || baseLineItemVO.getFulfillments().isEmpty()) && !TsoConstant.INTERSTORE.equals(specialOrder) && !TsoConstant.JOEI.equals(specialOrder) && !TsoConstant.MANUAL.equals(specialOrder) && !TsoConstant.NXP_ORDERED.equals(specialOrder) && !TsoConstant.NXP_DIRECT_SHIP_APPROVED_ORDERED.equals(specialOrder)){ if(!CustomerBL.isNapaOnlineCustomer(customerVO) && baseLineItemVO.getRefInvoiceLineItemTypeID().intValue() == RefInvoiceLineItemType.NORMAL_ITEM){ final BigDecimal qtyEligibleForSpecialOrder = getQtyEligibleForSpecialOrder( invoiceVO, baseLineItemVO, inventoryVO, quantity, dcStockQuantity); if(qtyEligibleForSpecialOrder.signum() == 1){ if(quantity.compareTo(qtyEligibleForSpecialOrder) == 1){ nonAvailableQty = qtyEligibleForSpecialOrder; } else { specialOrder = TsoConstant.NAPA_XPRESS; } } else { specialOrder = TsoConstant.LOCAL; } } } baseLineItemVO.setNonAvailableQty(nonAvailableQty); baseLineItemVO.setSpecialOrder(specialOrder); } public static BigDecimal splitQuantity(final CustomerVO customerVO, final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity){ InvoiceLineBL.setSpecialOrder(customerVO, invoiceVO, baseLineItemVO, inventoryVO, quantity, dcStockQuantity); BigDecimal newQuantity = quantity; if(baseLineItemVO.getNonAvailableQty().signum() > 0){ newQuantity = quantity.subtract(baseLineItemVO.getNonAvailableQty()); } return newQuantity; } public static FulfillmentVO createFulfillmentForBuyout(final BuyoutVO buyoutVO, final BaseLineItemVO baseLineItemVO){ final FulfillmentItemVO fulfillmentItemVO = new FulfillmentItemVO(); fulfillmentItemVO.setLineAbbrev(baseLineItemVO.getLineAbbr()); fulfillmentItemVO.setPartNumber(baseLineItemVO.getPartNum()); fulfillmentItemVO.setOrderPartCount(baseLineItemVO.getQuantityBilled()); final List fulfillmentItems = new ArrayList(); fulfillmentItems.add(fulfillmentItemVO); final FulfillmentIdentifierVO fulfillmentIdentifierVO = new FulfillmentIdentifierVO(); fulfillmentIdentifierVO.setRefFulfillmentIdentifierTypeId(new Integer(RefFulfillmentIdentifierType.THIRD_PARTY_VENDOR)); fulfillmentIdentifierVO.setFulfillmentIdentifier(buyoutVO.getVendorValuePair().getValue().toString()); final FulfillmentVO fulfillmentVO = new FulfillmentVO(); fulfillmentVO.setFulfillmentIdentifierVO(fulfillmentIdentifierVO); fulfillmentVO.setFulfillmentItems(fulfillmentItems); fulfillmentVO.setPurchaseOrderNumber(buyoutVO.getPONumber()); return fulfillmentVO; } public static FulfillmentVO createFulfillmentForPhoneRoomItem(final BaseLineItemVO baseLineItem, final PhoneRoomStoreVO phoneRoomStoreVO){ final List fulfilledItems = new ArrayList(); final PhoneRoomEjoeiVO phoneRoomEjoeiVO = phoneRoomStoreVO.getPhoneRoomEjoeiVO(); short fulfillmentIdentifierId = RefFulfillmentIdentifierType.STORE; String fulfillmentIdentifier = phoneRoomStoreVO.getStoreNumber(); String purchaseOrderNumber = ""; if(phoneRoomEjoeiVO != null){ fulfillmentIdentifier = phoneRoomStoreVO.getStoreNumber() + "," + phoneRoomStoreVO.getStoreName(); purchaseOrderNumber = phoneRoomEjoeiVO.getPurchaseStringOrderNumber(); fulfillmentIdentifierId = RefFulfillmentIdentifierType.DC; if(phoneRoomEjoeiVO.isSupplier()){ fulfillmentIdentifierId = RefFulfillmentIdentifierType.SUPPLIER; } } final FulfillmentItemVO fulfillmentItem = new FulfillmentItemVO(); fulfillmentItem.setLineAbbrev(baseLineItem.getLineAbbr()); fulfillmentItem.setPartNumber(baseLineItem.getPartNum()); fulfillmentItem.setOrderPartCount(phoneRoomStoreVO.getQtyChosen()); fulfilledItems.add(fulfillmentItem); final FulfillmentIdentifierVO fulfillmentIdentifierVO = new FulfillmentIdentifierVO(); fulfillmentIdentifierVO.setRefFulfillmentIdentifierTypeId(new Integer(fulfillmentIdentifierId)); fulfillmentIdentifierVO.setFulfillmentIdentifier(fulfillmentIdentifier); final FulfillmentVO fulfillmentVO = new FulfillmentVO(); fulfillmentVO.setPurchaseOrderNumber(purchaseOrderNumber); fulfillmentVO.setFulfillmentIdentifierVO(fulfillmentIdentifierVO); fulfillmentVO.setFulfillmentItems(fulfilledItems); return fulfillmentVO; } public static void setLineItemsRetailPrice(final InvoiceVO invoiceVO, final CustomerVO customerVO) { final String methodSpec = "InvoiceLineBL.setLineItemsRetailPrice - "; logger.debug(methodSpec); if (invoiceVO != null && invoiceVO.getLineItems() != null && invoiceVO.getLineItems().size() > 0) { PricesOutVO customerZeroPrice = null; PricesOutVO customerPrices = null; BaseLineItemVO baseLineItemVO = null; String partNumber = null; String lineAbbrev = null; CustomerVO customerZeroVO = null; try { customerZeroVO = ClientApplicationContext.getClientApplicationContext() .getCustomerDAO().getCustomerDetailInfo(new Integer(0)); } catch (ApplicationException applicationException) { logger.error(applicationException.toString(), applicationException); } if (customerZeroVO != null) { InvoiceLineItemVO invoiceLineItemVO = null; int lineItemsSize = invoiceVO.getLineItems().size(); for (int index = 0; index < lineItemsSize; index++) { invoiceLineItemVO = (InvoiceLineItemVO) invoiceVO.getLineItems().get(index); if (invoiceLineItemVO instanceof BaseLineItemVO) { baseLineItemVO = (BaseLineItemVO) invoiceLineItemVO; if (baseLineItemVO.getGeneratedByLineItem() == null || baseLineItemVO.isCoreItem() || (baseLineItemVO.isCoreTransaction() != null && baseLineItemVO.isCoreTransaction().booleanValue()) || baseLineItemVO.isPickupItem().booleanValue() || baseLineItemVO.isDefective().booleanValue() || isDefectiveReplacementLineItem(baseLineItemVO) | isReplacementCoreLineItem(baseLineItemVO)) { partNumber = baseLineItemVO.getPartNum(); lineAbbrev = baseLineItemVO.getLineAbbr(); logger.debug(methodSpec + "PartNumber = " + partNumber + ", " + "LineAbbrev = " + lineAbbrev); if(baseLineItemVO.isPickupItem().booleanValue()){ // Get Customer Zero Pickup Item Price Details customerZeroPrice = InvoiceLineBL.getPickupPrice( customerZeroVO.getID(), customerZeroVO.getCustomerTypeCD(), baseLineItemVO.getUnitCost()); // Set Pickup Item Unit Retail Price if(customerZeroPrice != null){ baseLineItemVO.setUnitRetailPrice(customerZeroPrice.getUnitPrice()); } } else { if (isOKToCallGetPrice(partNumber, lineAbbrev, baseLineItemVO.getQuantityBilled())) { // Get Customer Zero Price Details customerZeroPrice = InvoiceLineBL.getPrices( customerZeroVO.getID(), customerZeroVO.getCustomerTypeCD(), partNumber, lineAbbrev, baseLineItemVO.getQuantityBilled().abs()); // Set Unit Retail Price if (customerZeroPrice != null) { if (baseLineItemVO.isCoreItem() || (baseLineItemVO.isCoreTransaction() != null && baseLineItemVO.isCoreTransaction().booleanValue())) { baseLineItemVO.setUnitRetailPrice(customerZeroPrice .getCorePrice()); } else if ((baseLineItemVO.isCasePrice() != null && baseLineItemVO.isCasePrice().booleanValue()) || (baseLineItemVO.isWarrantyItem() != null && baseLineItemVO.isWarrantyItem().booleanValue())) { baseLineItemVO.setUnitRetailPrice(new BigDecimal("0")); } else { baseLineItemVO.setUnitRetailPrice(customerZeroPrice .getUnitPrice()); } } // Set Unit Usual Price customerPrices = InvoiceLineBL.getPrices( customerVO.getID(), customerVO.getCustomerTypeCD(), partNumber, lineAbbrev, baseLineItemVO.getQuantityBilled() .abs()); if (customerPrices != null) { if (baseLineItemVO.isCoreItem() || (baseLineItemVO.isCoreTransaction() != null && baseLineItemVO.isCoreTransaction().booleanValue())) { baseLineItemVO.setUnitUsualPrice(customerPrices .getCoreUsualPrice()); logger.debug(methodSpec + "Core Usual Price = " + customerPrices.getCoreUsualPrice()); } else { baseLineItemVO.setUnitUsualPrice(customerPrices .getUsualPrice()); logger.debug(methodSpec + "Usual Price = " + customerPrices.getUsualPrice()); } } } } } } } } } } public static boolean isOKToCallGetPrice(final String partNumber, final String lineAbbrev, final BigDecimal quantityBilled) { return partNumber != null && partNumber.trim().length() > 0 && lineAbbrev != null && lineAbbrev.trim().length() > 0 && quantityBilled != null && quantityBilled.abs().intValue() > 0; } public static final PricesOutVO getPickupPrice(final Integer customerId, final String customerTypeCd, final BigDecimal unitCost) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); PricesInVO pricesInVO = new PricesInVO(); pricesInVO.setCost(unitCost); pricesInVO.setCustomerId(customerId); pricesInVO.setCustomerTypeCD(customerTypeCd); Integer loc = new Integer(clientApplicationContext.getLocation()); pricesInVO.setLocation(loc); PricesOutVO pricesOutVO = null; try { pricesOutVO = clientApplicationContext.getOrderingDAO().getPickupPrice(pricesInVO); } catch (Exception exception) { logger.error("Error occured while retrieving picup price = " + exception); } return pricesOutVO; } /** * This method creates Colorado Delivery Fee Line Item. * * @param invoiceVO the {@link InvoiceVO} object * * @param customerVO the {@link CustomerVO} object */ public static BaseLineItemVO createCODeliveryFeeLineItem(InvoiceVO invoiceVO, CustomerVO customerVO) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); BaseLineItemVO feeLineItem = null; final Profile profile = clientApplicationContext.getProfile(Profile.POINT_OF_SALE_CLIENT, clientApplicationContext.getLocation()); final String storeLanguageCd = profile.getStoreProfile().getRefLanguageCd(); String retailDeliveryFeeDescription = null; final Integer employeeId = clientApplicationContext.getCurrentUser().getEmployeeId(); try { retailDeliveryFeeDescription = clientApplicationContext.getRefTableDAO() .getSpecialFuntionDescription(RefInvoiceSpecialFunction.COLORADO_DELIVERY_FEE, storeLanguageCd); } catch (ApplicationException applicationException) { logger.error("Error occured while retrieving line description" + applicationException.toString(), applicationException); } if (invoiceVO != null && customerVO != null && retailDeliveryFeeDescription != null && employeeId != null) { feeLineItem = createCDFLineItem(employeeId, RefInvoiceSpecialFunction.COLORADO_DELIVERY_FEE, retailDeliveryFeeDescription, invoiceVO.getLOC()); feeLineItem.setLOC(customerVO.getLOC()); feeLineItem.setGroupCode(new Short("0")); feeLineItem.setLoyaltyEligible(false); feeLineItem.setNonStocking(false); setDisplayPricesForLineItem(feeLineItem, customerVO, invoiceVO); invoiceVO.setCoroladoFeeLineAdded(true); } return feeLineItem; } /** * This method checks whether invoice is eligible for Colorado Law. * * @param customerVO the {@link CustomerVO} object * * @param storeprofile the {@link StoreProfileVO} object */ public static boolean isEligibleForColoradoDeliveryLaw(CustomerVO customerVO, StoreProfileVO storeprofile) { if (storeprofile != null && customerVO != null && customerVO.getState().equalsIgnoreCase(RefState.COLORADO) && storeprofile.getRetailDeliveryFee().equalsIgnoreCase(customerVO.getState()) && customerVO.getCustomerDeliveryVO() != null && customerVO.getCustomerDeliveryVO().getDeliveryRefOptionCD().equalsIgnoreCase( TsoConstant.DELIVERY_OPTION_ALWAYS)) { return true; } return false; } /** * Removes the Colorado line item. * * @param invoiceVO the {@link InvoiceVO} object */ public static void removeCODeliveryLineItem(InvoiceVO invoiceVO) { Vector itemList = invoiceVO.getLineItems(); if (itemList != null) { int listSize = itemList.size(); InvoiceLineItemVO lineItem = null; for (int index = 0; index < listSize; index++) { lineItem = (InvoiceLineItemVO) itemList.elementAt(index); if (lineItem instanceof BaseLineItemVO) { InvoiceLineItemVO invoiceLineItemVO = (InvoiceLineItemVO) lineItem; if (invoiceLineItemVO.getGeneratedByLineItem() == null && invoiceLineItemVO.getRefInvoiceLineItemTypeID() != null && invoiceLineItemVO.getRefInvoiceLineItemTypeID().intValue() == RefInvoiceLineItemType.COLORADO_DELIVERY_FEE) { itemList.remove(index); listSize = itemList.size(); index--; invoiceVO.setCoroladoFeeLineAdded(false); } } } } } /** * This method retrieves BinRange Details. * * @param giftCardBinRange the Gift Card BinRange Number. * @return binRangeProfileVO the {@link BinRangeProfileVO} object. */ public static final BinRangeProfileVO getBinRangeDetails(String giftCardBinRange) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); BinRangeProfileVO binRangeProfileVO = clientApplicationContext.getInventoryDAO().getBinRangeProfileVO( giftCardBinRange); return binRangeProfileVO; } /** * Mask the first 14 digits of the 18 digit New Gift Card number * @param newGiftCardNote * @return maskedGiftCardNumberNote */ public static String maskNewGiftCardNumber(String newGiftCardNote) { String maskedGiftCardNumberNote = newGiftCardNote; int index = newGiftCardNote.indexOf(":"); if (index != -1 && newGiftCardNote.length() > index + 15 && StringUtils.isNumeric(newGiftCardNote.substring(index + 1))) { String masked = newGiftCardNote.replace(newGiftCardNote.substring(index + 1, index + 15), "##############"); if (null != masked && !masked.isEmpty()) { maskedGiftCardNumberNote = masked; } } return maskedGiftCardNumberNote; } public static Boolean getPartNumberDetails(String text) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); Boolean isNewGiftCardPartNumber = clientApplicationContext.getInventoryDAO() .getPartDetails(text); return isNewGiftCardPartNumber; } /** * This method calculates the kit part unit price as the sum of the unit price of the components * associated with a kit part by calling getPrice() functionality on each component. * * @param inventoryVO the data object containing the inventory information of a kit. * @param customerVO the data object containing the customer information. * * @return kit part unit price as the sum of the unit price of the components associated with a kit part. */ public static final BigDecimal getKitPartPrice(KitInventoryVO inventoryVO, CustomerVO customerVO, Map map) { BOPISLogger.getInstance().setStoreProfile(customerVO.getLOC()).addBOPISLog(Constants.DEBUG, "getKitPartPrice() starts"); BigDecimal bigDecimalZero = new BigDecimal("0"); BigDecimal kitPartUnitPrice = bigDecimalZero; BigDecimal componentPrice = bigDecimalZero; BigDecimal requiredQuantity = bigDecimalZero; InventoryVO componentInventory = null; KitDefinitionComponentVO kitDefinitionComponent = null; if (inventoryVO instanceof KitInventoryVO) { List inventoryRecordList = ((KitInventoryVO) inventoryVO).getComponentInventoryList(); if (inventoryRecordList != null && !inventoryRecordList.isEmpty()) { Iterator componentIterator = inventoryRecordList.iterator(); while (componentIterator.hasNext()) { Object object = componentIterator.next(); if (object instanceof InventoryVO) { componentInventory = (InventoryVO) object; // Gets the data object that represents the combination of a PartIdentifier // and a quantity that describes the components associated with a kit part kitDefinitionComponent = ((KitInventoryVO) inventoryVO) .getComponentDefinition(componentInventory); if (kitDefinitionComponent.getRequiredQuantity() != null) { requiredQuantity = new BigDecimal(kitDefinitionComponent .getRequiredQuantity()); } if (customerVO != null) { // Gets the prices of each component associated with a kit part from the // getPrice() functionality. String key = customerVO.getID() + customerVO.getCustomerTypeCD()+componentInventory.getPartNumber() + componentInventory.getLineAbbrev() + requiredQuantity; if(map.get(key) !=null) { componentPrice = (BigDecimal) map.get(key); }else { componentPrice = InvoiceLineBL.getPrices(customerVO.getID(), customerVO .getCustomerTypeCD(), componentInventory.getPartNumber(), componentInventory.getLineAbbrev(), requiredQuantity).getUnitPrice(); map.put(key, componentPrice); } // Calculates the kit part unit price as the sum of unit price of // components associated with a kit part. kitPartUnitPrice = kitPartUnitPrice.add(componentPrice .multiply(requiredQuantity)); } } } } } logger.info("Calculates the kit part unit price as the sum of unit prices of components."); BOPISLogger.getInstance().setStoreProfile(customerVO.getLOC()).addBOPISLog(Constants.DEBUG, "getKitPartPrice() ends"); return kitPartUnitPrice; } public static boolean isPartEligibleForSale(String partNumber, String lineAbbr, String partDesc, Container parentView, CustomerVO customerVO, boolean isKitPart, boolean isPhoneRoom) { boolean isPartBlockedForSale = false; ArrayList ruleList = new ArrayList (); boolean isPartEligibleForSale = isPartEligibleForSaleWithoutMessage(partNumber, lineAbbr, partDesc, ruleList, isKitPart, customerVO, isPhoneRoom); if(!isPartEligibleForSale) { while (!(parentView instanceof Frame) && (parentView != null)) { parentView = parentView.getParent(); } //display dialog bannedPartListController = new BannedPartListController(parentView, ruleList); bannedPartListController.show(); } return isPartEligibleForSale; } /** * * @param partNumber * @param lineAbbrev * @return */ public static KitDefinitionVO getKitDefinition(CustomerVO customerVO, String partNumber, String lineAbbrev, boolean isPhoneRoom) { KitDefinitionVO kitDefinitionVO =null; // As per Colette Blanton, Phone room will be excluded from Block Sales, so defaulting isPhoneRoom as false; isPhoneRoom= false; try { if (isPhoneRoom) { String remoteStoreIP = PhoneRoomInvoiceBL.getRemoteIpAddress( ((ClientApplicationContext) ClientApplicationContext.getInstance()).getRemoteStoreNumber()); kitDefinitionVO = PhoneRoomInvoiceLineBL.getKitDefinition(customerVO, partNumber, lineAbbrev, remoteStoreIP); } else { kitDefinitionVO = clientApplicationContext.getInventoryDAO() .getKitDefinition(lineAbbrev, partNumber); } } catch (ApplicationException e) { logger.error(e.getMessage(), e); kitDefinitionVO = null; } return kitDefinitionVO; } /** * * @param partNumber * @param lineAbbr * @param partDesc * @param baseDialog * @param isPartCertified * @param ruleList * @param isKitPart * @return */ public static boolean isPartEligibleForSaleWithoutMessage(String partNumber, String lineAbbr, String partDesc, ArrayList ruleList, boolean isKitPart, CustomerVO customerVO, boolean isPhoneRoom) { boolean isPartEligibleForSale = true; isPartEligibleForSale = InvoiceLineBL.isPartEligibleForSale(partNumber,lineAbbr, partDesc, ruleList, isKitPart, null, customerVO, isPhoneRoom); if (isPartEligibleForSale && isKitPart) { try { String parentPart = lineAbbr+ "/" + partNumber; KitDefinitionVO kitDefinitionVO = clientApplicationContext.getInventoryDAO() .getKitDefinition(lineAbbr, partNumber); if(kitDefinitionVO != null) { List kitItems = kitDefinitionVO.getKitDefinitionComponents(); for (int i = 0; i < kitItems.size(); i++) { KitDefinitionComponentVO defVO = (KitDefinitionComponentVO) kitItems.get(i); boolean isCurrentPartEligibleForSale = InvoiceLineBL.isPartEligibleForSale( defVO.getKitComponentPartIdentifier().getPartNumber(), defVO.getKitComponentPartIdentifier().getLineAbbrev(), defVO.getKitComponentPartIdentifier().getPartDesc(), ruleList, false, parentPart,customerVO, isPhoneRoom); if (!isCurrentPartEligibleForSale) { isPartEligibleForSale = isCurrentPartEligibleForSale; } } } } catch (Exception e) { logger.error("Error reading Kit component " + e.getMessage()); } } return isPartEligibleForSale; } /** * * @param list * @param regulationPart * @return */ private static boolean messageExistForBannedPart(ArrayList list, RegulationRulePartVO regulationPart) { boolean doesMessageExistForBannedPart=false; for(RegulationRuleMessageVO partMessageVO: list) { RegulationRulePartVO partvo = partMessageVO.getRegulationRulePartVO(); if(partvo!=null && regulationPart!=null && partvo.getRegulationRuleId().equals(regulationPart.getRegulationRuleId()) && partvo.getPartNumber().equalsIgnoreCase(regulationPart.getPartNumber()) && partvo.getLineAbbrev().equalsIgnoreCase(regulationPart.getLineAbbrev()) && ( (partvo.getAlternateLineAbbrev()!=null && regulationPart.getAlternateLineAbbrev()!=null && partvo.getAlternateLineAbbrev().equalsIgnoreCase(regulationPart.getAlternateLineAbbrev())) || (partvo.getAlternateLineAbbrev()==null && regulationPart.getAlternateLineAbbrev()==null) ) && ( (partvo.getAlternatePartNumber()!=null && regulationPart.getAlternatePartNumber()!=null && partvo.getAlternatePartNumber().equalsIgnoreCase(regulationPart.getAlternatePartNumber())) || (partvo.getAlternatePartNumber()==null && regulationPart.getAlternatePartNumber()==null) ) ){ doesMessageExistForBannedPart=true; break; } } return doesMessageExistForBannedPart; } /** * This method verify whether the part is eligible for sale or not. * * If the part is return item then it populate only the part certification info. * @param location - store location * @param customerId - customer id * @param inventoryVO - contains inventory information * @param baseLineItem - contains invoice line item information * @param bdQuantity - contains billed quantity * @return boolean value indicating part is allowed for sale or not */ private static boolean isPartEligibleForSale(String partNumber, String lineAbbr, String partDesc, ArrayList ruleList, boolean isKitPart, String parentPart, CustomerVO customerVO, boolean isPhoneRoom) { //If certificate required & customer has certificate good to sell even if blocked boolean isPartCertified = false; if(customerVO!=null) { isPartCertified = waiverCertAvaialble(clientApplicationContext.getLocation(), customerVO, partNumber, lineAbbr, isPhoneRoom); } if (isPartCertified && InvoiceBL.isCertificationEnabled()) { return true; } boolean isEligibleForPartSale = true; List regulationRulePartVOList = getRegulationPartDetails(partNumber, lineAbbr, isPhoneRoom); if (regulationRulePartVOList != null && regulationRulePartVOList.size() > 0 && regulationRulePartVOList.stream().filter(regulationRulePart -> regulationRulePart .getRegulationRuleVO().getRegulatoryType().equalsIgnoreCase(RefRegulatoryType.BANNED)) .count() > 0) { regulationRulePartVOList.stream().filter(regulationRule -> regulationRule.getRegulationRuleVO() .getRegulatoryType().equalsIgnoreCase(RefRegulatoryType.BANNED)).forEach(regulationPart -> { RegulationRuleMessageVO messageVO= new RegulationRuleMessageVO(); messageVO.setRegulationRulePartVO(regulationPart); messageVO.setKitPart(isKitPart); if(parentPart !=null) messageVO.setParentPartDetails(parentPart); if(ruleList !=null && ! messageExistForBannedPart(ruleList,regulationPart)) { ruleList.add(messageVO); } }); isEligibleForPartSale = false; } return isEligibleForPartSale; } /** * This method verify whether the part is eligible for sale or not. * * If the part is return item then it populate only the part certification info. * @param location - store location * @param customerId - customer id * @param inventoryVO - contains inventory information * @param baseLineItem - contains invoice line item information * @param bdQuantity - contains billed quantity * @return boolean value indicating part is allowed for sale or not */ public static boolean isPartBlockedForSale(String partNumber, String lineAbbr, boolean isKitItem, CustomerVO customerVO, boolean isPhoneRoom) { boolean isPartBlockedForSale = false; final StringBuffer regulationRuleTitle = new StringBuffer(); List regulationRulePartVOList = InvoiceLineBL .getRegulationPartDetails(partNumber,lineAbbr, isPhoneRoom); if (regulationRulePartVOList != null && regulationRulePartVOList.size() > 0 && regulationRulePartVOList.stream() .filter(regulationRulePart -> regulationRulePart.getRegulationRuleVO() .getRegulatoryType().equalsIgnoreCase(RefRegulatoryType.BANNED)) .count() > 0) { isPartBlockedForSale = true; } //if kit part check the child part if(isKitItem && ! isPartBlockedForSale && customerVO !=null) try { //TODO We can get the Kit items from invoice VO itself without going DB KitDefinitionVO kitDefinitionVO = clientApplicationContext.getInventoryDAO() .getKitDefinition(lineAbbr, partNumber); if(kitDefinitionVO !=null) { List kitItems = kitDefinitionVO.getKitDefinitionComponents(); for (int i = 0; i < kitItems.size(); i++) { KitDefinitionComponentVO defVO = (KitDefinitionComponentVO) kitItems.get(i); isPartBlockedForSale = InvoiceLineBL.isPartBlockedForSale( defVO.getKitComponentPartIdentifier().getPartNumber(), defVO.getKitComponentPartIdentifier().getLineAbbrev(), false, customerVO, isPhoneRoom); if(isPartBlockedForSale == true) break; } } } catch (Exception e) { logger.error("Error reading Kit component " + e.getMessage()); } return isPartBlockedForSale; } /** * @param messageHeaderVO * @return */ public static int updateInvoiceForBlockSaleParts(InvoiceVO invoiceVO, CustomerVO customerVO, boolean isPhoneRoomApplicable) { int cntBlockSalePart=0; try { if ( null != invoiceVO && null != invoiceVO.getLineItems()) { Vector lineItems = invoiceVO.getLineItems(); for (int index = 0; index < lineItems.size(); index++) { Object itemVO = lineItems.elementAt(index); if(isLineItemBlockForSale(itemVO, customerVO, isPhoneRoomApplicable)) { InvoiceLineItemVO lineItemVO = (InvoiceLineItemVO) itemVO; lineItemVO.setBlockSale(true); if (lineItemVO instanceof BaseLineItemVO) { BaseLineItemVO obj = (BaseLineItemVO) itemVO; if((obj.getGeneratedByLineItem() == null ||InvoiceLineBL.isDefectiveReplacementLineItem(obj)) && ! obj.isCoreItem()) cntBlockSalePart++; } } } } } catch (Exception ae) { ae.printStackTrace(); } return cntBlockSalePart; } /** * @param messageHeaderVO * @return */ public static int updateMessagesForBlockSaleParts(MessageHeaderVO messageHeaderVO) { int cntBlockSaleCnt=0; if (messageHeaderVO.getMessageItems() != null) { Vector messageItems = messageHeaderVO.getMessageItems(); int listSize = messageItems.size(); for (int index = 0; index < listSize; index++) { if (messageItems.get(index) instanceof MessagePartVO) { MessagePartVO messagePartVO = (MessagePartVO) messageItems.get(index); if (InvoiceLineBL.isPartBlockedForSale(messagePartVO.getPartNumber(), messagePartVO.getLineAbbrev(), false, messageHeaderVO.getCustomerVO(), false)) { if(!messagePartVO.isKitComponent()) cntBlockSaleCnt++; messagePartVO.setBlockSale(true); } } //look back until we get MessagePartVO if (messageItems.get(index) instanceof MessageTextVO) { MessageTextVO messageTextVO= (MessageTextVO) messageItems.get(index); boolean isblockSale=false; for (int subIndex = 0; subIndex < listSize; subIndex++) { if (messageItems.get(subIndex) instanceof MessagePartVO) { MessagePartVO messagePartVO = (MessagePartVO) messageItems.get(subIndex); if( messagePartVO.getSequence()!=null && messageTextVO.getAttachedToMessagePartSeq() !=null && Short.compare(messagePartVO.getSequence(), messageTextVO.getAttachedToMessagePartSeq()) == 0 && messagePartVO.isBlockSale() ){ messageTextVO.setBlockSale(messagePartVO.isBlockSale()); break; } } } } } } return cntBlockSaleCnt; } /** * * @param value * @return */ public static boolean isLineItemBlockForSale(Object value, CustomerVO customerVO, boolean isPhoneRoomApplicable) { boolean isPartBlockedForSale = false; if (value != null) { if (value instanceof BaseLineItemVO) { InvoiceLineItemVO lineItemVo = (BaseLineItemVO) value; if (lineItemVo != null && lineItemVo.getQuantityBilled() != null && lineItemVo.getQuantityBilled().doubleValue() > 0) { String partNumber = lineItemVo.getPartNum(); String lineAbbr = lineItemVo.getLineAbbr(); if (lineItemVo.getGeneratedByLineItem() != null) { partNumber = lineItemVo.getGeneratedByLineItem().getPartNum(); lineAbbr = lineItemVo.getGeneratedByLineItem().getLineAbbr(); } isPartBlockedForSale = InvoiceLineBL.isPartBlockedForSale(partNumber, lineAbbr, lineItemVo.isKitPart(), customerVO, isPhoneRoomApplicable); } } else if (value instanceof InvoiceNoteVO) { InvoiceNoteVO noteItemVo = (InvoiceNoteVO) value; InvoiceLineItemVO lineItemVo = noteItemVo.getGeneratedByLineItem(); if (lineItemVo != null && lineItemVo.getQuantityBilled() != null && lineItemVo.getQuantityBilled().doubleValue() > 0) { String partNumber = noteItemVo.getGeneratedByLineItem().getPartNum(); String lineAbbr = noteItemVo.getGeneratedByLineItem().getLineAbbr(); isPartBlockedForSale = InvoiceLineBL.isPartBlockedForSale(partNumber, lineAbbr, false, null, isPhoneRoomApplicable); } } else if (value instanceof MessagePartVO) { MessagePartVO messagePart = (MessagePartVO) value; String partNumber = messagePart.getPartNumber(); String lineAbbr = messagePart.getLineAbbrev(); isPartBlockedForSale = InvoiceLineBL.isPartBlockedForSale(partNumber, lineAbbr, false, null, isPhoneRoomApplicable); } } return isPartBlockedForSale; } /** * * @param partNumber * @param lineAbbrev * @return */ public static List getRegulationPartDetails(String partNumber, String lineAbbrev, boolean isPhoneRoom) { List regulationRulePartVOList = null; // As per Colette Blanton, Phone room will be excluded from Block Sales, so defaulting isPhoneRoom as false; isPhoneRoom= false; try { if (isPhoneRoom) { String remoteStoreIP = PhoneRoomInvoiceBL.getRemoteIpAddress( ((ClientApplicationContext) ClientApplicationContext.getInstance()).getRemoteStoreNumber()); regulationRulePartVOList = PhoneRoomInvoiceLineBL.getRemoteStoreRegulationPartDetails(partNumber, lineAbbrev, remoteStoreIP); } else { regulationRulePartVOList = clientApplicationContext.getInventoryDAO() .getRegulationRulePartDetails(partNumber, lineAbbrev); } } catch (ApplicationException e) { logger.error(e.getMessage(), e); regulationRulePartVOList = null; } return regulationRulePartVOList; } /** * * @param partNumber * @param lineAbbrev * @return */ public static boolean getBlockSaleFlag(boolean isPhoneRoom) { boolean isBlocksale=false; // As per Colette Blanton, Phone room will be excluded from Block Sales, so defaulting isPhoneRoom as false; isPhoneRoom= false; try { if (isPhoneRoom) { isBlocksale = PhoneRoomInvoiceLineBL.getRemoteStoreBlockSaleFlag(PhoneRoomInvoiceBL.getRemoteIpAddress(clientApplicationContext.getRemoteStoreNumber())); } else { isBlocksale= RefStoreConfigurationUtil.isBlockSaleEnabled(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return isBlocksale; } }