@Test public void testGetOrderDeliveryTotalShippingTaxInfoNetIncl() throws Exception { final Total total = this.mockery.mock(Total.class, "total"); final CustomerOrder order = this.mockery.mock(CustomerOrder.class, "order"); final CustomerOrderDelivery delivery = this.mockery.mock(CustomerOrderDelivery.class, "delivery"); final ShoppingCart cart = this.mockery.mock(ShoppingCart.class, "cart"); final CheckoutServiceFacadeImpl facade = new CheckoutServiceFacadeImpl(null, null, null, null, null, null, null, null) { @Override public Total getOrderDeliveryTotal(final CustomerOrder customerOrder, final CustomerOrderDelivery orderDelivery) { assertSame(customerOrder, order); assertSame(orderDelivery, delivery); return total; } }; this.mockery.checking(new Expectations() {{ allowing(total).getDeliveryTax(); will(returnValue(new BigDecimal("1.67"))); allowing(total).getDeliveryCostAmount(); will(returnValue(new BigDecimal("9.99"))); allowing(total).getDeliveryListCost(); will(returnValue(new BigDecimal("9.99"))); allowing(total).getDeliveryCost(); will(returnValue(new BigDecimal("9.99"))); allowing(order).getCurrency(); will(returnValue("EUR")); allowing(cart).getShoppingContext(); will(returnValue(grossPercentTaxInfo())); allowing(delivery).getTaxCode(); will(returnValue("TAX")); }}); final PriceModel model = facade.getOrderDeliveryTotalShipping(order, delivery, cart); assertNotNull(model); assertEquals(CheckoutServiceFacadeImpl.DELIVERY_SHIPPING_REF, model.getRef()); assertEquals("EUR", model.getCurrency()); assertEquals("1", model.getQuantity().toPlainString()); assertEquals("9.99", model.getRegularPrice().toPlainString()); assertNull(model.getSalePrice()); assertTrue(model.isTaxInfoEnabled()); assertFalse(model.isTaxInfoUseNet()); assertFalse(model.isTaxInfoShowAmount()); assertEquals("TAX", model.getPriceTaxCode()); assertEquals("20.00", model.getPriceTaxRate().toPlainString()); assertFalse(model.isPriceTaxExclusive()); assertEquals("1.67", model.getPriceTax().toPlainString()); mockery.assertIsSatisfied(); }
@Override public PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart) { final Total grandTotal = getOrderDeliveryTotal(customerOrder, delivery); boolean hasTax = MoneyUtils.isPositive(grandTotal.getDeliveryTax()); final boolean showTax = hasTax && cart.getShoppingContext().isTaxInfoEnabled(); final boolean showTaxNet = showTax && cart.getShoppingContext().isTaxInfoUseNet(); final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscount = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost()); if (showTax) { final String firstTaxCode = delivery.getTaxCode(); final BigDecimal netAmount = grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()); final BigDecimal taxPercent = grandTotal.getDeliveryTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); final boolean priceTaxExclusive = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryCostAmount(), grandTotal.getDeliveryCost()); if (hasDiscount) { return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? MoneyUtils.getNetAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive) : MoneyUtils.getGrossAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive), showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), null, showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } if (hasDiscount) { return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost() ); } return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryCost(), null ); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart) { final Total grandTotal = getOrderDeliveryTotal(customerOrder, delivery); boolean hasTax = MoneyUtils.isPositive(grandTotal.getDeliveryTax()); final boolean showTax = hasTax && cart.getShoppingContext().isTaxInfoEnabled(); final boolean showTaxNet = showTax && cart.getShoppingContext().isTaxInfoUseNet(); final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscount = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost()); if (showTax) { final String firstTaxCode = delivery.getTaxCode(); final BigDecimal netAmount = grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()); final BigDecimal taxPercent = grandTotal.getDeliveryTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); final boolean priceTaxExclusive = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryCostAmount(), grandTotal.getDeliveryCost()); if (hasDiscount) { return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? MoneyUtils.getNetAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive) : MoneyUtils.getGrossAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive), showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), null, showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } if (hasDiscount) { return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost() ); } return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryCost(), null ); } }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart) { final Total grandTotal = getOrderDeliveryTotal(customerOrder, delivery); boolean hasTax = MoneyUtils.isPositive(grandTotal.getDeliveryTax()); final boolean showTax = hasTax && cart.getShoppingContext().isTaxInfoEnabled(); final boolean showTaxNet = showTax && cart.getShoppingContext().isTaxInfoUseNet(); final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscount = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost()); if (showTax) { final String firstTaxCode = delivery.getTaxCode(); final BigDecimal netAmount = grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()); final BigDecimal taxPercent = grandTotal.getDeliveryTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); final boolean priceTaxExclusive = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryCostAmount(), grandTotal.getDeliveryCost()); if (hasDiscount) { return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? MoneyUtils.getNetAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive) : MoneyUtils.getGrossAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive), showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), null, showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } if (hasDiscount) { return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost() ); } return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryCost(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart) { final Total grandTotal = getOrderDeliveryTotal(customerOrder, delivery); boolean hasTax = MoneyUtils.isPositive(grandTotal.getDeliveryTax()); final boolean showTax = hasTax && cart.getShoppingContext().isTaxInfoEnabled(); final boolean showTaxNet = showTax && cart.getShoppingContext().isTaxInfoUseNet(); final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscount = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost()); if (showTax) { final String firstTaxCode = delivery.getTaxCode(); final BigDecimal netAmount = grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()); final BigDecimal taxPercent = grandTotal.getDeliveryTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); final boolean priceTaxExclusive = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryCostAmount(), grandTotal.getDeliveryCost()); if (hasDiscount) { return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? MoneyUtils.getNetAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive) : MoneyUtils.getGrossAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive), showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), null, showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } if (hasDiscount) { return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost() ); } return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryCost(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override Total getOrderTotal(final CustomerOrder customerOrder); @Override PriceModel getOrderTotalSub(final CustomerOrder customerOrder, final ShoppingCart cart); @Override PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart); @Override Total getOrderDeliveryTotal(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery); @Override PriceModel getOrderDeliveryTotalSub(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override List<CustomerOrderPayment> findPaymentRecordsByOrderNumber(final String orderNumber); @Override Payment createPaymentToAuthorize(final CustomerOrder order); @Override PaymentGateway getOrderPaymentGateway(final CustomerOrder order); @Override List<Pair<PaymentGatewayDescriptor, String>> getPaymentGatewaysDescriptors(final Shop shop, final ShoppingCart cart); @Override boolean isOrderPaymentSuccessful(final CustomerOrder customerOrder); @Override Set<String> getOrderPromoCodes(final CustomerOrder customerOrder); @Override Set<String> getOrderShippingPromoCodes(final CustomerOrderDelivery orderDelivery); @Override Set<String> getOrderItemPromoCodes(final CartItem orderDeliveryDet); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override void estimateDeliveryTimeForOnlinePaymentOrder(final CustomerOrder customerOrder); @Override Map<String, Boolean> isMultipleDeliveryAllowedForCart(final ShoppingCart shoppingCart); @Override CustomerOrder update(final CustomerOrder customerOrder); @Override void printOrderByReference(final String reference, final OutputStream outputStream); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart) { final Total grandTotal = getOrderDeliveryTotal(customerOrder, delivery); boolean hasTax = MoneyUtils.isPositive(grandTotal.getDeliveryTax()); final boolean showTax = hasTax && cart.getShoppingContext().isTaxInfoEnabled(); final boolean showTaxNet = showTax && cart.getShoppingContext().isTaxInfoUseNet(); final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscount = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost()); if (showTax) { final String firstTaxCode = delivery.getTaxCode(); final BigDecimal netAmount = grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()); final BigDecimal taxPercent = grandTotal.getDeliveryTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); final boolean priceTaxExclusive = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getDeliveryCostAmount(), grandTotal.getDeliveryCost()); if (hasDiscount) { return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? MoneyUtils.getNetAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive) : MoneyUtils.getGrossAmount(grandTotal.getDeliveryListCost(), taxRate, !priceTaxExclusive), showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } return new PriceModelImpl(DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, showTaxNet ? grandTotal.getDeliveryCostAmount().subtract(grandTotal.getDeliveryTax()) : grandTotal.getDeliveryCostAmount(), null, showTax, showTaxNet, showTaxAmount, firstTaxCode, taxRate, priceTaxExclusive, grandTotal.getDeliveryTax() ); } if (hasDiscount) { return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryListCost(), grandTotal.getDeliveryCost() ); } return new PriceModelImpl( DELIVERY_SHIPPING_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getDeliveryCost(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override Total getOrderTotal(final CustomerOrder customerOrder); @Override PriceModel getOrderTotalSub(final CustomerOrder customerOrder, final ShoppingCart cart); @Override PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart); @Override Total getOrderDeliveryTotal(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery); @Override PriceModel getOrderDeliveryTotalSub(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override List<CustomerOrderPayment> findPaymentRecordsByOrderNumber(final String orderNumber); @Override Payment createPaymentToAuthorize(final CustomerOrder order); @Override PaymentGateway getOrderPaymentGateway(final CustomerOrder order); @Override List<Pair<PaymentGatewayDescriptor, String>> getPaymentGatewaysDescriptors(final Shop shop, final ShoppingCart cart); @Override boolean isOrderPaymentSuccessful(final CustomerOrder customerOrder); @Override Set<String> getOrderPromoCodes(final CustomerOrder customerOrder); @Override Set<String> getOrderShippingPromoCodes(final CustomerOrderDelivery orderDelivery); @Override Set<String> getOrderItemPromoCodes(final CartItem orderDeliveryDet); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override void estimateDeliveryTimeForOnlinePaymentOrder(final CustomerOrder customerOrder); @Override Map<String, Boolean> isMultipleDeliveryAllowedForCart(final ShoppingCart shoppingCart); @Override CustomerOrder update(final CustomerOrder customerOrder); @Override void printOrderByReference(final String reference, final OutputStream outputStream);  }