svn commit: r628825 - /ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r628825 - /ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

jleroux@apache.org
Author: jleroux
Date: Mon Feb 18 09:23:14 2008
New Revision: 628825

URL: http://svn.apache.org/viewvc?rev=628825&view=rev
Log:
Should definitively fix "Sales percent discount doesn't show up in Journal" (https://issues.apache.org/jira/browse/OFBIZ-1608) - OFBIZ-1608

Modified:
    ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=628825&r1=628824&r2=628825&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Mon Feb 18 09:23:14 2008
@@ -909,26 +909,43 @@
         if (cart != null) {
             double taxAmount = cart.getTotalSalesTax();
             double total = cart.getGrandTotal();
-            List adjustments = cart.getAdjustments();
+            List adjustments = cart.getAdjustments();            
+            Double itemsAdjustmentsAmount = 0.0;
 
+            Iterator i = cart.iterator();
+            while (i.hasNext()) {
+                ShoppingCartItem item = (ShoppingCartItem) i.next();
+                double adjustment = item.getOtherAdjustments();
+                if (adjustment != 0) {
+                    itemsAdjustmentsAmount =+ adjustment;
+                }
+            }
+            
             if (adjustments != null && adjustments.size() > 0) {
                 Iterator iter = adjustments.iterator();
                 while(iter.hasNext()){
                     GenericValue orderAdjustment = (GenericValue) iter.next();
+                    Double amount = orderAdjustment.getDouble("amount");                    
+                }
+
+                iter = adjustments.iterator();
+                while(iter.hasNext()){
+                    GenericValue orderAdjustment = (GenericValue) iter.next();
                     Double amount = orderAdjustment.getDouble("amount");
                     Double sourcePercentage = orderAdjustment.getDouble("sourcePercentage");
-                    if (UtilValidate.isNotEmpty(sourcePercentage)) {
-                        double percentage = sourcePercentage.doubleValue()/100.0; // sourcePercentage is negative
-                        amount = total / ((1 + percentage) / percentage);                        
-                    }                    
                     XModel adjustmentLine = Journal.appendNode(model, "tr", "adjustment", "");
                     Journal.appendNode(adjustmentLine, "td", "sku", "");
                     Journal.appendNode(adjustmentLine, "td", "desc",
                             UtilProperties.getMessage("pos", "(SalesDiscount)",defaultLocale));
-                    Journal.appendNode(adjustmentLine, "td", "qty", "");
                     if (UtilValidate.isNotEmpty(amount)) {
+                        Journal.appendNode(adjustmentLine, "td", "qty", "");
                         Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount));
-                    }
+                    } else if (UtilValidate.isNotEmpty(sourcePercentage)) {
+                        double percentage = - sourcePercentage.doubleValue()/100; // sourcePercentage is negative and must be show as a positive value (it's a discount not an amount)
+                        Journal.appendNode(adjustmentLine, "td", "qty", UtilFormatOut.formatPercentage(percentage));
+                        amount = new Double((cart.getItemTotal() + itemsAdjustmentsAmount) * percentage); // itemsAdjustmentsAmount is negative
+                        Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(- amount)); // amount must be shown as a negative value
+                    }                        
                     Journal.appendNode(adjustmentLine, "td", "index", "-1");
                 }    
             }