package com.gpc.client.pointofsale.invoice.line; // Java Imports 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.PhoneRoomInvoiceBL; import com.gpc.common.*; import com.gpc.common.constants.refvalues.*; import com.gpc.common.displayprice.DisplayPriceStrategy; import com.gpc.common.displayprice.DisplayPriceStrategyFactory; import com.gpc.common.exception.ApplicationException; import com.gpc.common.pointofsale.invoice.line.CommonInvoiceLineBL; import com.gpc.common.pointofsale.invoice.line.PhoneRoomCommonInvoiceLineBL; import com.gpc.common.util.FwoUtil; import com.gpc.server.inventory.dataaccess.Inventory; import com.gpc.tams.comm.io.PhoneRoomTaapRouter; import com.gpc.tams.comm.io.TaapRouter; import com.gpc.valueobjects.common.IDValuePairVO; import com.gpc.valueobjects.customer.CustomerCertificateVO; import com.gpc.valueobjects.customer.CustomerVO; import com.gpc.valueobjects.inventory.*; import com.gpc.valueobjects.invoice.InvoiceVO; import com.gpc.valueobjects.invoice.line.*; import com.gpc.valueobjects.message.MessagePartVO; import com.gpc.valueobjects.price.PricesInVO; import com.gpc.valueobjects.price.PricesOutVO; import com.gpc.valueobjects.profile.InventoryProfileVO; import com.gpc.valueobjects.profile.InvoicingProfileVO; import com.gpc.valueobjects.profile.MultiStoreProfileVO; import com.gpc.valueobjects.profile.StoreProfileVO; import com.gpc.valueobjects.tax.TaxInfoVO; import org.apache.log4j.Logger; import com.gpc.common.constants.loyalty.LoyaltyConstants; import com.gpc.client.pointofsale.tax.PhoneRoomTax; import com.gpc.common.constants.refvalues.RefInvoiceLineItemType; import com.gpc.valueobjects.tax.TaxDecisionVO; import java.math.BigDecimal; import java.util.*; import static com.gpc.common.pointofsale.invoice.line.CommonInvoiceLineBL.isScanned; /** *

Description: CLASS DESCRIPTION GOES HERE

* @author Copyright © 1999-2003, Genuine Parts Company, All Rights Reserved * @version 1.0 */ public class PhoneRoomInvoiceLineBL extends PhoneRoomCommonInvoiceLineBL { private static final Logger logger = Logger.getLogger(PhoneRoomInvoiceLineBL.class); private static TaapRouter taapRouter= new TaapRouter(); private static PhoneRoomTaapRouter phoneRoomTaapRouter = new PhoneRoomTaapRouter(); private static ClientApplicationContext cac = ClientApplicationContext.getClientApplicationContext(); private PhoneRoomInvoiceLineBL() { } public static KitInventoryVO getVirtualKitDetailInfo(final CustomerVO customerVO, final BaseLineItemVO baseLineItemVO,final String remoteIpAddress) { List definitionComponents = new ArrayList(); final KitDefinitionVO kitDefinitionVO = new KitDefinitionVO(); final PartIdentifierVO kitPartIdentifierVO = new PartIdentifierVO(); final InventoryVO inventoryVO = phoneRoomTaapRouter.getPartDetailInfo(customerVO,baseLineItemVO.getLineAbbr(),baseLineItemVO.getPartNum(),false,remoteIpAddress,cac.getCurrentLocale().getLanguage(),false); kitPartIdentifierVO.setId(inventoryVO.getID()); kitPartIdentifierVO.setLoc(inventoryVO.getLOC()); kitPartIdentifierVO.setLineAbbrev(inventoryVO.getLineAbbrev()); kitPartIdentifierVO.setPartNumber(inventoryVO.getExpandedPartNumber()); kitDefinitionVO.setKitPartIdentifier(kitPartIdentifierVO); final KitInventoryVO kitInventoryVO = phoneRoomTaapRouter.getPartDetailInfoByKitDef(customerVO,baseLineItemVO.getLineAbbr(), baseLineItemVO.getPartNum(), false,remoteIpAddress, cac.getCurrentLocale().getLanguage(),true); 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 = phoneRoomTaapRouter.getPartDetailInfo(customerVO, kitLineItemVO.getLineAbbr(),kitLineItemVO.getPartNum(), false, remoteIpAddress,cac.getCurrentLocale().getLanguage(),false); 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 boolean checkDC(CustomerVO customerVO, BaseLineItemVO baseLineItemVO, boolean newBarcode, InventoryVO inventoryVO,String remoteStoreIP) { return PhoneRoomCommonInvoiceLineBL.checkDC(customerVO, baseLineItemVO, newBarcode, inventoryVO, Profile.POINT_OF_SALE_CLIENT,remoteStoreIP); } /** * Method is used to arrive at available quantity for virtual kit. * * @param storeProfileVO * * @param baseLineItemVO * * @param remoteIpAddress * @return */ public static BigDecimal getVirtualKitOnHandInServingDC(final BaseLineItemVO baseLineItemVO, InvoicingProfileVO invoicingProfileVO, StoreProfileVO storeProfileVO, final String remoteIpAddress) { if(invoicingProfileVO==null) invoicingProfileVO = taapRouter.getInvoicingProfile(remoteIpAddress); if(storeProfileVO == null) storeProfileVO = phoneRoomTaapRouter.getStoreProfile(remoteIpAddress); BigDecimal availableQty = new BigDecimal("0.00"); boolean useRads = invoicingProfileVO.getUseRads().booleanValue(); final boolean dcStore = storeProfileVO.getDcStore().booleanValue(); final boolean usStore = RefCountry.UNITED_STATES.equalsIgnoreCase(storeProfileVO.getRefCountryCd()); final boolean isNAPAXpress = storeProfileVO.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,remoteIpAddress); 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 IDValuePairVO getServingDC(final InventoryVO inventoryVO, final String remoteIpAddress) throws ApplicationException{ //service call to be created final Vector dcList = phoneRoomTaapRouter.getDistributionCenterList( inventoryVO.getExpandedPartNumber(), inventoryVO.getLineAbbrev(), ClientApplicationContext.getClientApplicationContext().getCurrentLocale().getLanguage(), ClientApplicationContext.getClientApplicationContext().getCurrentUser().getEmployeeId().intValue(), ClientApplicationContext.getClientApplicationContext().getLocation(), ClientApplicationContext.getClientApplicationContext().getCurrentUser(),remoteIpAddress); 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; } public static BigDecimal splitQuantity(final CustomerVO customerVO, final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity, String remoteStoreIP, final StoreProfileVO storeProfileVO){ PhoneRoomInvoiceLineBL.setSpecialOrder(customerVO, invoiceVO, baseLineItemVO, inventoryVO, quantity, dcStockQuantity,remoteStoreIP,storeProfileVO); BigDecimal newQuantity = quantity; if(baseLineItemVO.getNonAvailableQty().signum() > 0){ newQuantity = quantity.subtract(baseLineItemVO.getNonAvailableQty()); } return newQuantity; } public static void setSpecialOrder(final CustomerVO customerVO, final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity,final String remoteStoreIP,final StoreProfileVO storeProfileVO){ if(!storeProfileVO.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"); Map invProfileParams = new HashMap(); invProfileParams.put(TaapRouter.SERVING_STORE_IP_ADDRESS, "" + remoteStoreIP); invProfileParams.put(TaapRouter.LOC, "" + cac.getLocation()); InventoryProfileVO inventoryProfileVO = taapRouter.getInventoryProfile(invProfileParams); 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,remoteStoreIP,storeProfileVO); if(qtyEligibleForSpecialOrder.signum() == 1){ if(quantity.compareTo(qtyEligibleForSpecialOrder) == 1){ nonAvailableQty = qtyEligibleForSpecialOrder; } else if (PhoneRoomInvoiceBL.isMainCounter(storeProfileVO) && PhoneRoomInvoiceBL.doesInvoiceContainNOLBOPISOrder(invoiceVO)) { specialOrder = TsoConstant.LOCAL; }else{ specialOrder = TsoConstant.NAPA_XPRESS; } } else { specialOrder = TsoConstant.LOCAL; } } } baseLineItemVO.setNonAvailableQty(nonAvailableQty); baseLineItemVO.setSpecialOrder(specialOrder); } public static BigDecimal getQtyEligibleForSpecialOrder(final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, final InventoryVO inventoryVO, final BigDecimal quantity, final String dcStockQuantity, final String remoteStoreIP, StoreProfileVO storeProfileVO){ if(storeProfileVO==null) storeProfileVO = phoneRoomTaapRouter.getStoreProfile(remoteStoreIP); final BigDecimal qtyAlreadyAdded = PhoneRoomInvoiceLineBL.getQtyAlreadyAdded(invoiceVO, baseLineItemVO,remoteStoreIP,storeProfileVO); 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 = (PhoneRoomInvoiceLineBL.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(PhoneRoomInvoiceLineBL.getAvailableQty(inventoryVO, dcStockQuantity)).setScale(2, BigDecimal.ROUND_HALF_UP); } public static BigDecimal getQtyAlreadyAdded(final InvoiceVO invoiceVO, final BaseLineItemVO baseLineItemVO, String remoteStoreIP, StoreProfileVO storeProfileVO){ final Vector existingLines = invoiceVO.getLineItems(); BigDecimal qtyAlreadyAdded = new BigDecimal(0); BigDecimal effectiveAddedQtyOfOneLine = new BigDecimal(0); String storeLanguageCd =storeProfileVO.getRefLanguageCd(); String warrantyText= TsoConstant.WARRANTY_ADJUSTMENT_PERCENT_TEXT; warrantyText= phoneRoomTaapRouter.getInvoiceLineDescription( new Integer(RefInvoiceLineItemDescription.WARRANTY_ADJUSTMENT_PERCENT), storeLanguageCd,remoteStoreIP); 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; } /* * 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); } } } public static final BigDecimal getWarrantyAdjustment(BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, Date purchaseDate,String remoteStoreIP,StoreProfileVO storeProfileVO) { if (inventoryVO == null) { inventoryVO = phoneRoomTaapRouter.getPartDetailInfo(customerVO,baseLineItemVO.getLineAbbr(), baseLineItemVO.getPartNum(), false,remoteStoreIP,cac.getCurrentLocale().getLanguage(),false); } WarrantyVO warrantyVO = inventoryVO.getWarrantyVO(); if(warrantyVO == null) { return new BigDecimal("0.00"); } PricesOutVO pricesOutVO = getPricesPhoneRoom(customerVO, customerVO.getCustomerTypeCD(), baseLineItemVO.getPartNum(), baseLineItemVO.getLineAbbr(), baseLineItemVO .getQuantityBilled(),remoteStoreIP,storeProfileVO); 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 = phoneRoomTaapRouter .getPriceWithLandedFactor(inventoryVO, warrantyAmount, new Byte("1"),remoteStoreIP,cac.getLocation()); return landedFactors; } public static final void setDoesnotAffectSalesHistory( BaseLineItemVO baseLineItemVO, CustomerVO customerVO,String remoteStoreIP) { InvoicingProfileVO invoicingProfileVO = taapRouter.getInvoicingProfile(remoteStoreIP); boolean dnsInvoice = (invoicingProfileVO != null && invoicingProfileVO.getDnsInvoice() != null && invoicingProfileVO.getDnsInvoice().booleanValue()); // Code modified for Tender Types. // Do not set 'Does Not Affect Sales History' flag for a NAPA Gift Card item TRUE even // for the customer with 'Transfer-DNA Sales History' NAPA Customer Category. if (((customerVO.getREFNAPACustomerCategoryID() != null) && (customerVO.getREFNAPACustomerCategoryID().intValue() == RefNAPACustomerCategory.TRANSFER_DNA_SALES_HISTORY) && baseLineItemVO.getRefInvoiceLineItemTypeID().intValue() != RefInvoiceLineItemType.NAPA_GIFT_CARD && baseLineItemVO.getRefInvoiceLineItemTypeID().intValue() != RefInvoiceLineItemType.NEW_NAPA_GIFT_CARD) || (dnsInvoice && customerVO.getDnsCustomer().booleanValue())) { baseLineItemVO.setDoesNotAffectSalesHistory(Boolean.TRUE); } else { PhoneRoomCommonInvoiceLineBL.setDoesnotAffectSalesHistory(baseLineItemVO); } } /** * 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; } /** * 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, String remoteStoreIP, StoreProfileVO storeProfileVO, InvoicingProfileVO invoicingProfileVO) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); BaseLineItemVO feeLineItem = null; final String storeLanguageCd = storeProfileVO.getRefLanguageCd(); String retailDeliveryFeeDescription = null; final Integer employeeId = clientApplicationContext.getCurrentUser().getEmployeeId(); retailDeliveryFeeDescription = phoneRoomTaapRouter .getSpecialFuntionDescription(RefInvoiceSpecialFunction.COLORADO_DELIVERY_FEE, storeLanguageCd,remoteStoreIP); if (invoiceVO != null && customerVO != null && retailDeliveryFeeDescription != null && employeeId != null) { feeLineItem = createCDFLineItem(employeeId, RefInvoiceSpecialFunction.COLORADO_DELIVERY_FEE, retailDeliveryFeeDescription,remoteStoreIP,storeProfileVO, invoicingProfileVO); feeLineItem.setLOC(customerVO.getLOC()); feeLineItem.setGroupCode(new Short("0")); feeLineItem.setLoyaltyEligible(false); feeLineItem.setNonStocking(false); setDisplayPricesForLineItem(feeLineItem, customerVO, invoiceVO,remoteStoreIP,storeProfileVO.getIncludeTaxInPrice().booleanValue()); invoiceVO.setCoroladoFeeLineAdded(true); } return feeLineItem; } /** * 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,String remoteStoreIP) { String availableString = ""; boolean multiStoreInUse = false; boolean isRemoteStore = false; StoreProfileVO storeProfileVO = phoneRoomTaapRouter.getStoreProfile(remoteStoreIP); // Check for multi store in use if (invoiceVO != null && invoiceVO.getRemoteStoreNumber() != null) { multiStoreInUse = PhoneRoomInvoiceBL.isMultiStoreInUse(invoiceVO.getRemoteStoreNumber(), inventoryVO.getPartNumber(), inventoryVO.getLineAbbrev(),remoteStoreIP); isRemoteStore = PhoneRoomInvoiceBL.isRemoteStore(invoiceVO.getRemoteStoreNumber(), storeProfileVO); } // If multi store in use and if it is remote store , get available quantity from multi store if (multiStoreInUse && isRemoteStore ) { availableString = PhoneRoomInvoiceLineBL.getAvailableQuantityFromMultiStore( invoiceVO.getRemoteStoreNumber(), inventoryVO.getLineAbbrev(), inventoryVO.getPartNumber(),remoteStoreIP,storeProfileVO); } else if (invoiceVO != null && invoiceVO.getRemoteStoreNumber() != null && isRemoteStore) { try { availableString = cac.getInventoryDAO().getAvailableByStore( location, invoiceVO.getRemoteStoreNumber(), customerVO, inventoryVO); } 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; } /** * 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 remoteStoreIP,StoreProfileVO storeProfileVO) { String availableQuantity = "0.00"; Vector storeList = null; if(remoteStoreNumber == null || lineAbbreviation == null || partNumber == null) { return availableQuantity; } ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); if (storeProfileVO.getMultiStoreInUse().booleanValue()) { MultiStoreProfileVO multiStoreProfileVO = phoneRoomTaapRouter.getMulitStoreProfile(remoteStoreIP,clientApplicationContext.getLocation()); storeList = phoneRoomTaapRouter.getMSStockCheck( new Integer(clientApplicationContext.getLocation()), lineAbbreviation, partNumber,remoteStoreIP); } 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; } /** * 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,String remoteStoreIP,StoreProfileVO storeProfileVO) { 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 = getPricesPhoneRoom(customer, customer .getCustomerTypeCD(), componentInventory.getPartNumber(), componentInventory.getLineAbbrev(), requiredQuantity,remoteStoreIP,storeProfileVO); } 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; } public static final BigDecimal getPriceWithLandedFactor(BigDecimal price, String markupPercent, String priceSheetCD, InventoryVO inventoryVO, Byte landedFactorType, String remoteStoreIP) { 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 = phoneRoomTaapRouter.getPriceWithLandedFactor(inventoryVO, cost, landedFactorType,remoteStoreIP,clientApplicationContext.getLocation()); return cost; } //called from phoneroom controller /** * 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 */ //for phoneroom public static BigDecimal getDisplayPriceFromUnitPrice(final BigDecimal unitPrice, final BaseLineItemVO baseLineItem, final InvoiceVO invoiceVO, final CustomerVO customerVO, final InventoryVO inventoryVO, final MiscChgVO miscChgVO,String remoteAddressIP,Boolean includeTaxInProfile) { BigDecimal displayPrice = new BigDecimal("0.00"); TaxInfoVO productLineTaxInfo = null; PhoneRoomTaapRouter phoneRoomTaapRouter = new PhoneRoomTaapRouter(); if (baseLineItem != null) { if (inventoryVO != null) { productLineTaxInfo = phoneRoomTaapRouter.getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(),inventoryVO.getLOC(),remoteAddressIP); } displayPrice = getDisplayPriceFromUnitPrice(unitPrice, baseLineItem, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,includeTaxInProfile,remoteAddressIP); } return displayPrice; } /** * This method logs if virtual kit received by TAMS is different from what it has. * @param baseLineItemVO value object. * @param customerVO value object. */ // for phoneroom public static void logKitMismatchIfAny(BaseLineItemVO baseLineItemVO, CustomerVO customerVO,InventoryVO inventoryVO) { 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()); } } } public static final PricesOutVO getPricesPhoneRoom(CustomerVO customerVO, String customerTypeCD, String partNumber, String lineAbbrev, BigDecimal quantity,String remoteStoreIP,StoreProfileVO storeProfileVO) { ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); PhoneRoomTaapRouter phoneRoomTaapRouter = new PhoneRoomTaapRouter(); if(storeProfileVO==null){ storeProfileVO = phoneRoomTaapRouter.getStoreProfile(remoteStoreIP); } PricesOutVO priceOutputVO = null; PricesInVO pricesInputVO = new PricesInVO(); Integer loc = new Integer(clientApplicationContext.getLocation()); pricesInputVO.setLocation(loc); pricesInputVO.setCustomerId(customerVO.getID()); 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"); if (pricesInputVO == null || pricesInputVO.getPartNumber() == null || pricesInputVO.getPartNumber().trim().length() < 1 || pricesInputVO.getLineAbbreviation() == null || pricesInputVO.getLineAbbreviation().trim().length() < 1) { throw new IllegalArgumentException(); } try { boolean checkInventory = phoneRoomTaapRouter.checkInventory(pricesInputVO.getLineAbbreviation(), pricesInputVO.getPartNumber(), pricesInputVO.getLocation().intValue(),remoteStoreIP); if(checkInventory) priceOutputVO = phoneRoomTaapRouter.getPricesFromInventory(pricesInputVO,remoteStoreIP); else priceOutputVO = phoneRoomTaapRouter.getPricesFromDVD(pricesInputVO,remoteStoreIP); } catch (Exception ae) { logger.error("Exception in getPrice: ",ae); } if (pricesInputVO.getLocation() != null) { if (storeProfileVO != null && storeProfileVO.getIncludeTaxInPrice() != null && storeProfileVO.getIncludeTaxInPrice().booleanValue()) { try { setDisplayPrices(pricesInputVO, priceOutputVO, storeProfileVO,remoteStoreIP,customerVO); } catch (Exception e) { logger.error(e.getMessage(), e); } } } return priceOutputVO; } /** * To set display prices * @param pricesInVO * @param pricesOutVO * @param storeProfileVO * @throws ApplicationException * @throws PointOfSaleException */ //phone room private static void setDisplayPrices(final PricesInVO pricesInVO, final PricesOutVO pricesOutVO, final StoreProfileVO storeProfileVO, String remoteStoreIP, CustomerVO customervo) throws ApplicationException, PointOfSaleException { final String methodSpec = "PriceLoader.setDisplayPrices - "; logger.debug(methodSpec); // Determine the DisplayPrice Strategy DisplayPriceStrategy priceStrategy = DisplayPriceStrategyFactory.getInstance() .getDisplayPriceStrategyPR(pricesInVO.getLocation().intValue(),storeProfileVO.getIncludeTaxInPrice().booleanValue()); Inventory inventory = new Inventory(); InventoryVO inventoryVO = null; TaxInfoVO productLineTaxInfo = null; PhoneRoomTaapRouter phoneRoomTaapRouter = new PhoneRoomTaapRouter(); ClientApplicationContext clientApplicationContext = ClientApplicationContext.getClientApplicationContext(); try { if(pricesInVO.getPartNumber() != null && pricesInVO.getLineAbbreviation() != null) { inventoryVO = phoneRoomTaapRouter.getPartDetailInfo(customervo, pricesInVO.getLineAbbreviation(), pricesInVO.getPartNumber(), true,remoteStoreIP,clientApplicationContext.getCurrentLocale().getLanguage(),false); } if(inventoryVO != null){ productLineTaxInfo = phoneRoomTaapRouter.getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(),inventoryVO.getLOC(),remoteStoreIP); } } catch (Exception remoteException) { logger.error(remoteException.getMessage(), remoteException); throw new PointOfSaleException(remoteException.getMessage()); } logger.debug(methodSpec + "Tax applied for getPrice() price attributes "); priceStrategy.setDisplayPricesFromGetPricePhoneRoom(pricesInVO, pricesOutVO, inventoryVO, customervo, productLineTaxInfo, Profile.SERVER,remoteStoreIP); } 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 void setLineItemsRetailPrice(final InvoiceVO invoiceVO, final CustomerVO customerVO, String ip, Integer loc) { 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; Map customerParams = new HashMap(); customerParams.put(TaapRouter.SERVING_STORE_IP_ADDRESS, "" + ip); customerParams.put(TaapRouter.CUSTOMERNUM, "" + new Integer(0)); customerParams.put(TaapRouter.TYPE, "" + "N"); customerParams.put(TaapRouter.CUSTID, "" + "1"); customerParams.put(TaapRouter.LANG, "" + "EN"); customerParams.put(TaapRouter.LOC, "" + loc); //customerZeroVO = ClientApplicationContext.getClientApplicationContext() // .getCustomerDAO().getCustomerDetailInfo(new Integer(0)); CustomerVO customerZeroVO = taapRouter.getCustomerDetailInfoByID(customerParams); 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() || InvoiceLineBL.isDefectiveReplacementLineItem(baseLineItemVO) | InvoiceLineBL.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 PricesInVO vo = new PricesInVO(); vo.setCustomerTypeCD(customerZeroVO.getCustomerTypeCD()); vo.setCustomerId(customerZeroVO.getID()); vo.setCost(baseLineItemVO.getUnitCost()); customerZeroPrice = phoneRoomTaapRouter.getPickUpPrice(vo,ip,loc); // 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 MessagePartVO vo = new MessagePartVO(); vo.setLOC(loc); vo.setPartNumber(FwoUtil.stripChars(partNumber, new char[] {PartNumberFormatCertifier.DASH, PartNumberFormatCertifier.FORWARD_SLASH, PartNumberFormatCertifier.PERIOD, PartNumberFormatCertifier.SPACE})); vo.setLineAbbrev(lineAbbrev); vo.setInvoiceQty(baseLineItemVO.getQuantityBilled().abs()); customerZeroPrice = taapRouter.getPricesOutVO(vo,ip,customerZeroVO.getID()); // 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());*/ customerPrices = taapRouter.getPricesOutVO(vo,ip,customerVO.getID()); 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; } /** * 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, String ip) { if (baseLineItemVO.getReturnItems() != null) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); String storeNum = phoneRoomTaapRouter.getStoreProfile(ip).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 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,String remoteStoreNumber) { 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; String remoteStoreIP =null; try { remoteStoreIP= PhoneRoomInvoiceBL.getRemoteIpAddress(remoteStoreNumber); } catch (ApplicationException e) { e.printStackTrace(); } 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 = PhoneRoomInvoiceLineBL.getPricesPhoneRoom(customer, customer .getCustomerTypeCD(), componentInventory.getPartNumber(), componentInventory.getLineAbbrev(), requiredQuantity,remoteStoreIP,null); } 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; } /** * 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,String remoteStoreIp, boolean displayPriceWithTax) { BigDecimal actualPrice = null; if (baseLineItemVO != null && customerVO != null) { final ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); TaxInfoVO productLineTaxInfo = null; if (inventoryVO != null) { productLineTaxInfo = phoneRoomTaapRouter .getProductLineTaxInfo(inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(),clientApplicationContext.getLocation(),remoteStoreIp); } actualPrice = getActualPriceFromDisplayPrice(displayPrice, baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,remoteStoreIp,displayPriceWithTax); } return actualPrice; } /** * 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,String remoteStoreIP) { 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 = PhoneRoomInvoiceLineBL.getPriceWithLandedFactor(componentCost, TsoConstant.ZERO_MARKUP_PERCENT, priceSheet, componentInventory, landedFactorType,remoteStoreIP); } 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; } /** * 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,final String remoteStoreIP) { TaxInfoVO productLineTaxInfo = null; if (inventoryVO != null) { productLineTaxInfo = phoneRoomTaapRouter.getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(), cac.getLocation(), remoteStoreIP); } setDisplayPriceFromUnitPrice(unitPrice, baseLineItem, invoiceVO, customerVO, inventoryVO, productLineTaxInfo,remoteStoreIP); } public static final BarcodeVO getBarcodeVO(String barcode,String remoteStoreIP) { BarcodeVO barcodeVO = phoneRoomTaapRouter.getBarcode( barcode.substring(2, barcode.length()),remoteStoreIP); return barcodeVO; } /** * * @param partNumber * @param lineAbbrev * @param remoteStoreIP * @return */ public static final List getRemoteStoreRegulationPartDetails(String partNumber, String lineAbbrev, String remoteStoreIP) { List regulationRulePartVOList = phoneRoomTaapRouter .getRemoteStoreRegulationPartDetails(partNumber, lineAbbrev, remoteStoreIP); return regulationRulePartVOList; } /** * 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,String remoteStoreIP) { boolean isEligibleForPartSale = true; PartCertificationVO partCertificationVO = (inventoryVO == null ? null : inventoryVO.getPartCertificationVO()); Integer certPartGroupId = (partCertificationVO == null ? null : partCertificationVO .getCertificationPartGroupId()); if (partCertificationVO != null && partCertificationVO.isGovCertExistForCustomer()) { CustomerCertificateVO customerCertificate = null; customerCertificate = phoneRoomTaapRouter .getCustomerCertificateInfo(location, customerId, certPartGroupId,remoteStoreIP); isEligibleForPartSale = (customerCertificate == null) ? false : true; 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; } /** * 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,String remoteStoreIP) { boolean isEligibleForPartSale = false; PartCertificationVO partCertificationVO = (inventoryVO == null ? null : inventoryVO.getPartCertificationVO()); Integer certPartGroupId = (partCertificationVO == null ? null : partCertificationVO .getCertificationPartGroupId()); if (partCertificationVO != null && partCertificationVO.isGovCertExistForCustomer()) { CustomerCertificateVO customerCertificate = null; customerCertificate = phoneRoomTaapRouter .getCustomerCertificateInfo(location, customerId, certPartGroupId,remoteStoreIP); isEligibleForPartSale = (customerCertificate == null) ? false : true; } return isEligibleForPartSale; } /** * 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 remoteStoreIP,final boolean includeTaxInPrice) { final String methodSpec = "InvoiceLineBL.recalculateLineItemPrices() - "; logger.debug(methodSpec); TaxInfoVO productLineTaxInfo = null; final ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); if (inventoryVO != null) { productLineTaxInfo = phoneRoomTaapRouter.getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(),clientApplicationContext.getLocation(),remoteStoreIP); } if (baseLineItemVO.getDisplayPriceEntered() != null && baseLineItemVO.getDisplayPriceEntered().booleanValue()) { baseLineItemVO.setUnitPrice(getActualPriceFromDisplayPrice( baseLineItemVO.getDisplayUnitPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,remoteStoreIP,includeTaxInPrice)); baseLineItemVO.setExtendedPrice(getExtendedPrice(baseLineItemVO,remoteStoreIP,null)); } else { baseLineItemVO.setDisplayUnitPrice(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,includeTaxInPrice,remoteStoreIP)); baseLineItemVO.setDisplayExtendedPrice(getDisplayExtendedPrice(baseLineItemVO,remoteStoreIP)); } if (baseLineItemVO.getDisplayListPriceEntered() != null && baseLineItemVO.getDisplayListPriceEntered().booleanValue()) { baseLineItemVO.setUnitListPrice(getActualPriceFromDisplayPrice( baseLineItemVO.getDisplayUnitListPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,remoteStoreIP,includeTaxInPrice)); } else { baseLineItemVO.setDisplayUnitListPrice(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitListPrice(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,includeTaxInPrice,remoteStoreIP)); } baseLineItemVO.setDisplayUnitCost(getDisplayPriceFromUnitPrice( baseLineItemVO.getUnitCost(), baseLineItemVO, invoiceVO, customerVO, inventoryVO, miscChgVO, productLineTaxInfo,includeTaxInPrice,remoteStoreIP)); } public static final BaseLineItemVO createAGMiscChgLineItem(MiscChgVO miscChgVO, BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, InvoiceVO invoiceVO, StoreProfileVO storeProfileVO, boolean autoComplete, int segment, Integer countermanID,String remoteStoreIP) { ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); Short grpCode = new Short((short)0); TaxInfoVO taxInfoVO = phoneRoomTaapRouter .getProductLineTaxInfo(miscChgVO.getRefResvLineCD(), grpCode, clientApplicationContext.getLocation(), remoteStoreIP); return PhoneRoomCommonInvoiceLineBL.createAGMiscChgLineItem(miscChgVO, baseLineItemVO, customerVO, inventoryVO, invoiceVO, storeProfileVO, autoComplete, segment, countermanID, taxInfoVO,remoteStoreIP); } public static final BaseLineItemVO createAGCoreLineItem(BaseLineItemVO baseLineItemVO, CustomerVO customerVO, InventoryVO inventoryVO, InvoiceVO invoiceVO, StoreProfileVO storeProfileVO, PricesOutVO prices, boolean autoComplete, int segment, Integer countermanID,String remoteStoreIP) { TaxInfoVO taxInfoVO = phoneRoomTaapRouter.getProductLineTaxInfo( inventoryVO.getLineAbbrev(), inventoryVO.getGroupCode(), cac.getLocation(), remoteStoreIP); String storeLanguageCd = storeProfileVO.getRefLanguageCd(); String coreDescription = null; coreDescription = phoneRoomTaapRouter.getInvoiceLineDescription( new Integer(RefInvoiceLineItemDescription.CORE_DEPOSIT), storeLanguageCd,remoteStoreIP); return PhoneRoomCommonInvoiceLineBL.createAGCoreLineItem(baseLineItemVO, customerVO, inventoryVO, invoiceVO, storeProfileVO, prices, autoComplete, segment, countermanID, taxInfoVO, isPartAssociatedWithOrigInvoiceFromList(baseLineItemVO,remoteStoreIP), coreDescription,remoteStoreIP); } //Stela-890 public static BaseLineItemVO createLineItemForRewards(InvoiceVO invoiceVO, CustomerVO customerVO, BigDecimal price, BigDecimal quantity, String ip, String lang) { StoreProfileVO storeProfile = phoneRoomTaapRouter.getStoreProfile(ip); ClientApplicationContext clientApplicationContext = ClientApplicationContext .getClientApplicationContext(); BaseLineItemVO baseLineItemVO = new BaseLineItemVO(); /*InventoryVO inventoryVO = clientApplicationContext.getInventoryDAO() .getPartDetailInfo(customerVO, LoyaltyConstants.REWARD_PART, LoyaltyConstants.REWARD_LINE, false);*/ InventoryVO inventoryVO = phoneRoomTaapRouter.getPartDetailInfo(customerVO, LoyaltyConstants.REWARD_LINE, LoyaltyConstants.REWARD_PART, false,ip,clientApplicationContext.getCurrentLocale().getLanguage(),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(PhoneRoomCommonInvoiceLineBL.getExtendedPrice(baseLineItemVO,ip,storeProfile)); baseLineItemVO.setLoyaltyEligible(false); TaxDecisionVO taxDecision = PhoneRoomTax.getTaxDecision(customerVO, inventoryVO, null, baseLineItemVO, null, null, Profile.POINT_OF_SALE_CLIENT, ip, lang); if (!taxDecision.getPrimaryTax().equals(PhoneRoomTax.OPTIONAL)) { if (taxDecision.getPrimaryTax().equals(PhoneRoomTax.ALWAYS)) { baseLineItemVO.setTaxable1(Boolean.TRUE); } else { baseLineItemVO.setTaxable1(Boolean.FALSE); } } else { baseLineItemVO.setTaxable1(Boolean.TRUE); } if (!taxDecision.getSecondaryTax().equals(PhoneRoomTax.OPTIONAL)) { if (taxDecision.getSecondaryTax().equals(PhoneRoomTax.ALWAYS)) { baseLineItemVO.setTaxable2(Boolean.TRUE); } else { baseLineItemVO.setTaxable2(Boolean.FALSE); } } else { baseLineItemVO.setTaxable2(Boolean.TRUE); } } return baseLineItemVO; } public static final Vector getPartLines(String partNumber, boolean inventoryOnly,String remoteStoreIP) throws PointOfSaleException { Vector partLines = null; String lineAbbrev = null; if (isScanned(partNumber)) { BarcodeVO barcodeVO = phoneRoomTaapRouter.getBarcode( partNumber.substring(2, partNumber.length()),remoteStoreIP); if (barcodeVO == null) { return partLines; } else { partNumber = barcodeVO.getPartNumber(); lineAbbrev = barcodeVO.getLineAbbrev(); } } partLines = phoneRoomTaapRouter.getPartLines(partNumber, lineAbbrev,cac.getLocation(), inventoryOnly,remoteStoreIP); return partLines; } }