Skip to content

Instantly share code, notes, and snippets.

@killnine
Created April 21, 2015 16:50
Show Gist options
  • Save killnine/ba4109d8489645bd0696 to your computer and use it in GitHub Desktop.
Save killnine/ba4109d8489645bd0696 to your computer and use it in GitHub Desktop.
Adjustment Order of Operations

Rule

Gross >= Net + MR

Other Info

Users can make individual adjustments to Gross, Net, and Makeready as long as the primary business rule is maintained.

Currently, the adjustments are made one at a time and always in the same order (Gross first, then Net, finally MR). This causes issues in certain situations

Examples

Initial State

  • Gross: 500
  • Net + MR: 250 + 100 (350)

Case 1

  • -200 Gross, -200 Net

Case 2

  • +50 Gross, +200 Net

Case 3

  • -50 Gross, +100 Net

Case 4

  • +50 Gross, -100 Net

Making a Common Order of Operations

How can I determine the order by which adjustments should be made?

/* The logic below assumes we've already checked that the final adjusted Gross, Net, MR values will comply with the Rule */
if(GrossAdjustment > 0 && (NetAdjustment + MRAdjustment) > 0)
{
	//Gross adjustment first
}
else if(GrossAdjustment < 0 && (NetAdjustment + MRAdjustment) > 0)
{
	//Gross adjustment first
}
else if(GrossAdjustment > 0 && (NetAdjustment + MRAdjustment) < 0)
{
	//Gross adjustment first
}
else
{
	//NetAdjustment & MRAdjustment first
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment