/** * Retrieves list of <code>OrderPayment</code>s associated with the specified gift certificate * grouped by their shipments. * * @param uidPk GiftCertificate uid. * @return map of shipments to their payments. */ public Map<Order, Money> retrieveOrdersBalances(final long uidPk) { sanityCheck(); final Map<Order, Money> ordersBalance = new TreeMap<Order, Money>( new Comparator<Order>() { public int compare(final Order order1, final Order order2) { return order1.getCreatedDate().compareTo(order2.getCreatedDate()); } }); List<Order> orders = getPersistenceEngine().retrieveByNamedQuery("ORDERS_BY_GIFT_CERTIFICATE", uidPk); for (Order order : orders) { List<GiftCertificateTransaction> transactions = getPersistenceEngine() .retrieveByNamedQuery( "GIFT_CERTIFICATE_TRANSACTIONS_BY_ORDER_AND_GIFT_CERTIFICATE", uidPk, PaymentType.GIFT_CERTIFICATE, order.getUidPk()); BigDecimal amount = getGiftCertificateTransactionService().calcTransactionBalance(transactions); Money money = MoneyFactory.createMoney(amount, order.getCurrency()); ordersBalance.put(order, money); } return ordersBalance; }
/** * Get the price. * * @return the price */ @Override public Price getPrice() { PricingScheme pricingScheme = getBeanFactory().getBean(ContextIdNames.PRICING_SCHEME); Price schedulePrice = findPrice(getBaseAmounts()); if (schedulePrice == null) { return null; } pricingScheme.setPriceForSchedule(getPriceSchedule(), schedulePrice); Price price; if (getPaymentSchedule() == null) { price = schedulePrice; } else { price = getPriceBean(); final Money zero = MoneyFactory.createMoney(BigDecimal.ZERO, schedulePrice.getCurrency()); price.setListPrice(zero); } price.setPricingScheme(pricingScheme); return price; }