Posted by
sichen on
Aug 30, 2006; 11:58pm
URL: http://ofbiz.116.s1.nabble.com/svn-commit-r438698-in-incubator-ofbiz-trunk-applications-order-src-org-ofbiz-order-order-OrderReadHel-tp208937.html
Author: sichen
Date: Wed Aug 30 15:58:28 2006
New Revision: 438698
URL:
http://svn.apache.org/viewvc?rev=438698&view=revLog:
Added methods to get the order and cart payment amounts by payment method (to get, say, the total being charged to a CC or billing account). Added methods to correctly determine the amount refunded and credited to billing accounts and appllied them to the order return totals in the create return pages.
Modified:
incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
incubator/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl
Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL:
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=438698&r1=438697&r2=438698&view=diff==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Wed Aug 30 15:58:28 2006
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.HashSet;
import org.apache.commons.collections.set.ListOrderedSet;
@@ -1052,6 +1053,73 @@
}
return shippableSizes;
}
+
+ /**
+ * Get the total payment preference amount by payment type. Specify null to get amount
+ * for all preference types. TODO: filter by status as well?
+ */
+ public BigDecimal getOrderPaymentPreferenceTotalByType(String paymentMethodTypeId) {
+ BigDecimal total = ZERO;
+ for (Iterator iter = getPaymentPreferences().iterator(); iter.hasNext(); ) {
+ GenericValue preference = (GenericValue) iter.next();
+ if (preference.get("maxAmount") == null) continue;
+ if (paymentMethodTypeId == null || paymentMethodTypeId.equals(preference.get("paymentMethodTypeId"))) {
+ total = total.add(preference.getBigDecimal("maxAmount")).setScale(scale, rounding);
+ }
+ }
+ return total;
+ }
+
+ public BigDecimal getCreditCardPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("CREDIT_CARD");
+ }
+
+ public BigDecimal getBillingAccountPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("EXT_BILLACT");
+ }
+
+ public BigDecimal getGiftCardPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("GIFT_CARD");
+ }
+
+ /**
+ * Get the total payment received amount by payment type. Specify null to get amount
+ * over all types. This method works by going through all the PaymentAndApplications
+ * for all order Invoices that have status PMNT_RECEIVED.
+ */
+ public BigDecimal getOrderPaymentReceivedTotalByType(String paymentMethodTypeId) {
+ BigDecimal total = ZERO;
+
+ try {
+ // get a set of invoice IDs that belong to the order
+ List orderItemBillings = orderHeader.getRelatedCache("OrderItemBilling");
+ Set invoiceIds = new HashSet();
+ for (Iterator iter = orderItemBillings.iterator(); iter.hasNext(); ) {
+ GenericValue orderItemBilling = (GenericValue) iter.next();
+ invoiceIds.add(orderItemBilling.get("invoiceId"));
+ }
+
+ // get the payments of the desired type for these invoices TODO: in models where invoices can have many orders, this needs to be refined
+ List conditions = UtilMisc.toList(
+ new EntityExpr("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED"),
+ new EntityExpr("invoiceId", EntityOperator.IN, invoiceIds)
+ );
+ if (paymentMethodTypeId != null) {
+ conditions.add(new EntityExpr("paymentMethodTypeId", EntityOperator.EQUALS, paymentMethodTypeId));
+ }
+ EntityConditionList ecl = new EntityConditionList(conditions, EntityOperator.AND);
+ List payments = orderHeader.getDelegator().findByConditionCache("PaymentAndApplication", ecl, null, null);
+
+ for (Iterator iter = payments.iterator(); iter.hasNext(); ) {
+ GenericValue payment = (GenericValue) iter.next();
+ if (payment.get("amountApplied") == null) continue;
+ total = total.add(payment.getBigDecimal("amountApplied")).setScale(scale, rounding);
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, e.getMessage(), module);
+ }
+ return total;
+ }
// TODO: Might want to use BigDecimal here if precision matters
public double getItemSize(GenericValue item) {
@@ -1731,6 +1799,56 @@
BigDecimal orderShippingNotReturned = this.getShippingTotalBd().multiply(orderFactorNotReturned).setScale(scale, rounding);
return totalTaxNotReturned.add(totalShippingNotReturned).add(orderTaxNotReturned).add(orderShippingNotReturned).setScale(scale, rounding);
+ }
+
+ /** Gets the total refunded to the order billing account by type. Specify null to get total over all types. */
+ public BigDecimal getBillingAccountReturnedTotalByTypeBd(String returnTypeId) {
+ BigDecimal returnedAmount = ZERO;
+ List returnedItemsBase = getOrderReturnItems();
+ if (returnTypeId != null) {
+ returnedItemsBase = EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("returnTypeId", returnTypeId));
+ }
+ List returnedItems = new ArrayList(returnedItemsBase.size());
+
+ // get only the RETURN_RECEIVED and RETURN_COMPLETED statusIds
+ returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_RECEIVED")));
+ returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED")));
+
+ // sum up the return items that have a return item response with a billing account defined
+ try {
+ for (Iterator iter = returnedItems.iterator(); iter.hasNext(); ) {
+ GenericValue returnItem = (GenericValue) iter.next();
+ GenericValue returnItemResponse = returnItem.getRelatedOne("ReturnItemResponse");
+ if (returnItemResponse == null) continue;
+ if (returnItemResponse.get("billingAccountId") == null) continue;
+
+ // we can just add the response amounts
+ returnedAmount = returnedAmount.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(scale, rounding);
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, e.getMessage(), module);
+ }
+ return returnedAmount;
+ }
+
+ /** Get the total return credited to the order billing accounts */
+ public BigDecimal getBillingAccountReturnedCreditTotalBd() {
+ return getBillingAccountReturnedTotalByTypeBd("RTN_CREDIT");
+ }
+
+ /** Get the total return refunded to the order billing accounts */
+ public BigDecimal getBillingAccountReturnedRefundTotalBd() {
+ return getBillingAccountReturnedTotalByTypeBd("RTN_REFUND");
+ }
+
+ /** Gets the total return credited amount with refunds and credits to the billing account figured in */
+ public BigDecimal getReturnedCreditTotalWithBillingAccountBd() {
+ return getOrderReturnedCreditTotalBd().add(getBillingAccountReturnedRefundTotalBd()).subtract(getBillingAccountReturnedCreditTotalBd());
+ }
+
+ /** Gets the total return refund amount with refunds and credits to the billing account figured in */
+ public BigDecimal getReturnedRefundTotalWithBillingAccountBd() {
+ return getOrderReturnedRefundTotalBd().add(getBillingAccountReturnedCreditTotalBd()).subtract(getBillingAccountReturnedRefundTotalBd());
}
/** @deprecated */
Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL:
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=438698&r1=438697&r2=438698&view=diff==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Aug 30 15:58:28 2006
@@ -2281,6 +2281,50 @@
return itemsTotal;
}
+ /**
+ * Get the total payment amount by payment type. Specify null to get amount
+ * over all types.
+ */
+ public double getOrderPaymentPreferenceTotalByType(String paymentMethodTypeId) {
+ double total = 0.0;
+ String thisPaymentMethodTypeId = null;
+ for (Iterator iter = paymentInfo.iterator(); iter.hasNext(); ) {
+ CartPaymentInfo payment = (CartPaymentInfo) iter.next();
+ if (payment.amount == null) continue;
+ if (payment.paymentMethodId != null) {
+ try {
+ // need to determine the payment method type from the payment method
+ GenericValue paymentMethod = this.getDelegator().findByPrimaryKeyCache("PaymentMethod", UtilMisc.toMap("paymentMethodId", payment.paymentMethodId));
+ if (paymentMethod != null) {
+ thisPaymentMethodTypeId = paymentMethod.getString("paymentMethodTypeId");
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, e.getMessage(), module);
+ }
+ } else {
+ thisPaymentMethodTypeId = payment.paymentMethodTypeId;
+ }
+
+ // add the amount according to paymentMethodType
+ if (paymentMethodTypeId == null || paymentMethodTypeId.equals(thisPaymentMethodTypeId)) {
+ total += payment.amount.doubleValue();
+ }
+ }
+ return total;
+ }
+
+ public double getCreditCardPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("CREDIT_CARD");
+ }
+
+ public double getBillingAccountPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("EXT_BILLACT");
+ }
+
+ public double getGiftCardPaymentPreferenceTotal() {
+ return getOrderPaymentPreferenceTotalByType("GIFT_CARD");
+ }
+
/** Add a contact mech to this purpose; the contactMechPurposeTypeId is required */
public void addContactMech(String contactMechPurposeTypeId, String contactMechId) {
if (contactMechPurposeTypeId == null) throw new IllegalArgumentException("You must specify a contactMechPurposeTypeId to add a ContactMech");
Modified: incubator/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl
URL:
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl?rev=438698&r1=438697&r2=438698&view=diff==============================================================================
--- incubator/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl (original)
+++ incubator/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl Wed Aug 30 15:58:28 2006
@@ -87,11 +87,11 @@
</tr>
<tr>
<td class="tabletext" width="25%">${uiLabelMap.OrderAmountAlreadyCredited}</td>
- <td class="tabletext"><@ofbizCurrency amount=orh.getOrderReturnedCreditTotalBd() isoCode=orh.getCurrency()/></td>
+ <td class="tabletext"><@ofbizCurrency amount=orh.getReturnedCreditTotalWithBillingAccountBd() isoCode=orh.getCurrency()/></td>
</tr>
<tr>
<td class="tabletext" width="25%">${uiLabelMap.OrderAmountAlreadyRefunded}</td>
- <td class="tabletext"><@ofbizCurrency amount=orh.getOrderReturnedRefundTotalBd() isoCode=orh.getCurrency()/></td>
+ <td class="tabletext"><@ofbizCurrency amount=orh.getReturnedRefundTotalWithBillingAccountBd() isoCode=orh.getCurrency()/></td>
</tr>
</table>
</td></tr>