Re: svn commit: r628552 - /ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

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

Re: svn commit: r628552 - /ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Jacques Le Roux
Administrator
Hi David,

I just read by chance in this thread http://www.nabble.com/Percentage-discounts-%28code-snippet-included%29-to6737939.html#a6745868
<<Iain,
Have you tried this out and checked other areas? My guess is that
this would mess a few things up... The sourcePercentage is meant for
information only and should already be accounted for an adjustment
amount, which shouldn't be recalculated because this is not meant to
represent all of the information that goes into that.
-David >>

Do you think there could be any problems with the code below. I think it's ok because at this stage all calculations are already
done.

Thanks

Jacques

> Author: jleroux
> Date: Sun Feb 17 13:41:49 2008
> New Revision: 628552
>
> URL: http://svn.apache.org/viewvc?rev=628552&view=rev
> Log:
> Fix "Sales percent discount doesn't show up in Journal" (https://issues.apache.org/jira/browse/OFBIZ-1608) - OFBIZ-1608
>
> Modified:
>    ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
>
> Modified: ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
> URL:
> http://svn.apache.org/viewvc/ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=628552&r1=628551&r2=628552&view=diff
> ==============================================================================
> --- ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
> +++ ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Sun Feb 17 13:41:49 2008
> @@ -735,6 +735,29 @@
>         if (cart != null) {
>             double taxAmount = cart.getTotalSalesTax();
>             double total = cart.getGrandTotal();
> +            List adjustments = cart.getAdjustments();
> +
> +            if (adjustments != null && adjustments.size() > 0) {
> +                Iterator 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 = new Double(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", "price", UtilFormatOut.formatPrice(amount));
> +                    }
> +                    Journal.appendNode(adjustmentLine, "td", "index", "-1");
> +                }
> +            }
>
>             XModel taxLine = Journal.appendNode(model, "tr", "", "");
>             Journal.appendNode(taxLine, "td", "sku", "");
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r628552 - /ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Jacques Le Roux
Administrator
David, All,

I have thought about it and tested more. I think it's really ok now. I commited trunk changes in  r628825 and reverted release4.0 as
it's not a bug fix.

Jacques


From: "Jacques Le Roux" <[hidden email]>

> Hi David,
>
> I just read by chance in this thread
> http://www.nabble.com/Percentage-discounts-%28code-snippet-included%29-to6737939.html#a6745868
> <<Iain,
> Have you tried this out and checked other areas? My guess is that
> this would mess a few things up... The sourcePercentage is meant for
> information only and should already be accounted for an adjustment
> amount, which shouldn't be recalculated because this is not meant to
> represent all of the information that goes into that.
> -David >>
>
> Do you think there could be any problems with the code below. I think it's ok because at this stage all calculations are already
> done.
>
> Thanks
>
> Jacques
>
>> Author: jleroux
>> Date: Sun Feb 17 13:41:49 2008
>> New Revision: 628552
>>
>> URL: http://svn.apache.org/viewvc?rev=628552&view=rev
>> Log:
>> Fix "Sales percent discount doesn't show up in Journal" (https://issues.apache.org/jira/browse/OFBIZ-1608) - OFBIZ-1608
>>
>> Modified:
>>    ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
>>
>> Modified: ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=628552&r1=628551&r2=628552&view=diff
>> ==============================================================================
>> --- ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
>> +++ ofbiz/branches/release4.0/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Sun Feb 17 13:41:49 2008
>> @@ -735,6 +735,29 @@
>>         if (cart != null) {
>>             double taxAmount = cart.getTotalSalesTax();
>>             double total = cart.getGrandTotal();
>> +            List adjustments = cart.getAdjustments();
>> +
>> +            if (adjustments != null && adjustments.size() > 0) {
>> +                Iterator 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 = new Double(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", "price", UtilFormatOut.formatPrice(amount));
>> +                    }
>> +                    Journal.appendNode(adjustmentLine, "td", "index", "-1");
>> +                }
>> +            }
>>
>>             XModel taxLine = Journal.appendNode(model, "tr", "", "");
>>             Journal.appendNode(taxLine, "td", "sku", "");
>>
>>
>>
>
>