/** * Sets <code>value</code> as the attribute value for Quantity. * * @param value value to set the Quantity */ public void setQuantity(Integer value) { Integer oldQuantity = getQuantity(); setAttributeInternal(QUANTITY, value); // Recalculate the order total if the quantity changes. SOrdImpl order = getSOrd(); // First of all remove the the old line item total from the order total BigDecimal orderTotal = order.getTotal().subtract(getPrice().multiply(new BigDecimal(oldQuantity))); // Now add the new line item total order.setTotal(orderTotal.add(getPrice().multiply(new BigDecimal(value)))); }
/** * Sets <code>value</code> as the attribute value for QuantityShipped. * * @param value value to set the QuantityShipped */ public void setQuantityShipped(Integer value) { // When ever this attribute is changed, the order total has to be updated as this is based // on the line item, which is the price * quantityShipped. // Get the quantityShipped before you change it Integer oldQuantity = getQuantityShipped(); setAttributeInternal(QUANTITYSHIPPED, value); // Recalculate the order total if the price changes. SOrdImpl order = (SOrdImpl) getSOrd(); // First of all remove the the old line item total from the order total BigDecimal orderTotal = order.getTotal().subtract(getPrice().multiply(new BigDecimal(oldQuantity))); // Now add the new line item total order.setTotal(orderTotal.add(getPrice().multiply(new BigDecimal(value)))); }
/** * Sets <code>value</code> as the attribute value for Price. * * @param value value to set the Price */ public void setPrice(BigDecimal value) { // When ever this attribute is changed, the order total has to be updated as this is based // on the line item, which is the price * quantity. // Get the price before you change it BigDecimal oldPrice = getPrice(); // When adding a new line you won't have an oldPrice if (oldPrice == null) { oldPrice = new BigDecimal(0); } setAttributeInternal(PRICE, value); // Recalculate the order total if the price changes. SOrdImpl order = getSOrd(); // First of all remove the the old line item total from the order total BigDecimal orderTotal = order.getTotal().subtract(new BigDecimal(getQuantity()).multiply(oldPrice)); // Now add the new line item total order.setTotal(orderTotal.add(new BigDecimal(getQuantity()).multiply(value))); }