Login / Register  search  syndication  about

          Kris Halsrud's Blog

Kris Halsrud on development and Integration with CRM and Development

A rounding issue in the SalesLogix 7.5.4 Sales Order area and how to fix it.

Those using the Sales Order area in SalesLogix have likely run into a bug where applying discounts causes the Sales order total to calculate incorrectly.  Today I am going to describe the problem and how to fix it.

First lets take a look at what is going on.


Lets say we add a single line item to our Sales order that has a sell price of $399.00.  We enter a quantity of 50.  The extended price of the line item shows correctly as $19950.00.  The Sales Order total also correctly reflects Now lets say we want to discount the selling price to be $100.00 each so we enter $100.00 in the Adjusted Price column.  The line item we have now added an discount adjustment of 74.97%.  The extended price of the line item now shows correctly as $5000.00.  But look at the Sales Order total, it now shows $4999.47

 

 What happened?

Well, digging in a little we find that on the SalesOrderItem Entity events of OnBeforeUpdate, OnBeforeInsert, and OnBeforeDelete they are calling methods in the Sage.SalesLogix.BusinessRules.dll assembly, Looking at this assembly with Reflector we are able to find that a method is called from each of these events called "SetOrderTotal".  This event calls another event of "GetAdjustedPrice".  This method has the following code:

public static double GetAdjustedPrice(ISalesOrder salesOrder)
{
    double num = 0.0;
    foreach (ISalesOrderItem item in salesOrder.SalesOrderItems)
    {
        double num2 = (item.Price.HasValue && (item.Price.Value > 0.0)) ? item.Price.Value : ((item.CalculatedPrice.HasValue && (item.CalculatedPrice.Value > 0M)) ? Convert.ToDouble(item.CalculatedPrice.Value) : 0.0);
        if (item.Discount.HasValue)
        {
            double? quantity = item.Quantity;
            num += (num2 * (quantity.HasValue ? quantity.GetValueOrDefault() : 0.0)) * (1.0 - item.Discount.Value);
        }
        else
        {
            num += num2;
        }
    }
    return num;
}


Here we can see the problem inside the For Each loop.  It is using the item.Discount.Value multiplied by the original Sell Price and Quantity to determine the price of the item.  These items are the rolled up to return the Sales Order total.  The problem is that the Discount field is rounded to 2 decimal places.  When you do the math with our sample you see the results returned are $4999.47.  What it should use is just the Adjusted Price field instead of the rounded Adjustment field.

All of this code is inside a compiled Sage assembly so how do we modify it?  The answer is we don't.  What we can do is to add our own code to the Entities that will run after the base code does and correctly calculate our total.

First we create a new business rule at the Sales order level called FXSetOrderTotal.  Here is the code we can then use:

public static partial class SalesOrderBusinessRules
    {
        public static void FXSetOrderTotalStep( ISalesOrder salesorder)
        {
            if (!Sage.SalesLogix.SalesOrder.SalesOrderHelperClass.HasSynced(salesorder))
            {
                salesorder.OrderTotal = new double?(FXGetAdjustedPrice(salesorder));
            }
            Sage.SalesLogix.SalesOrder.SalesOrder.SetGrandTotal(salesorder);
        }
       
        public static double FXGetAdjustedPrice(ISalesOrder salesOrder)
        {
            double num = 0.0;
            foreach (ISalesOrderItem item in salesOrder.SalesOrderItems)
            {
                double num2 = item.CalculatedPrice.HasValue && (item.CalculatedPrice.Value > 0M) ? Convert.ToDouble(item.CalculatedPrice.Value) : ((item.Price.HasValue && (item.Price.Value > 0.0)) ? item.Price.Value : 0.0);
                num += (num2 * (item.Quantity.HasValue ? item.Quantity.GetValueOrDefault() : 0.0));
            }
            return num;
        }
    }

 Now with that rule established we can then add code to the Post execute event of each of the SalesOrderItem Entity events of OnBeforeUpdate, OnBeforeInsert, and OnBeforeDelete.

In the post execute step we simply then need to call:

salesorderitem.SalesOrder.FXSetOrderTotal();

Now the rounding issue will be gone!

What's This?
  
Bookmark and Share

About Kris Halsrud

   Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.


Related Content
   Easily Showing and Hiding Tabs at Runtime in Infor CRM (Saleslogix)
Showing and hiding tabs in the Infor CRM (Saleslogix) client should be an easy thing. It should be someth
Posted on Dec 16, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Problem setting SLXTextbox enabled property / Setting unexposed base control properties for a custom control
I recently had an issue with a Quickform where I was attempting to set the Enabled property of a TextBox
Posted on Dec 05, 2014 by Jason Buss to Jason Buss' Blog
 
   Checking Infor CRM (Saleslogix) Picklists for valid data
This week I received a question about a particular picklist. One of the picklist items, when chosen, wou
Posted on Dec 05, 2014 by Dale Richter to Infor CRM Questions & Answers
 
   Avoiding the Dirty Data Message When Programatically Redirecting to a Record in Infor CRM (Saleslogix)
In my last post I wrote about using the OnClientClick property of a control (or button) to run JavaScript
Posted on Dec 02, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Infor CRM (formerly Saleslogix) Web- Dependency Lookup OnChange Event Not Working Correctly
In the Saleslogix 8.1 web client the dependency lookup still has a problem with the OnChange event. 
Posted on Nov 26, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register