5070

Best Price Wins

Algorithm
Medium
Pro
table
enum
pricing
precedence
effective-dating

Best Price Wins

Every ERP eventually grows a pricing table nobody fully trusts: a special deal for one customer, a rate card for the wholesale group, a general price list, seasonal promos with start and end dates, and bulk discounts from 50 units. On any given order line, several of these rules apply at once — and the price engine must pick one, the same one, every time. Business Central's own price calculation is exactly this kind of waterfall; you are building its deterministic core.

Requirements

The starter ships an enum named "Price Rule Source Type" (values "All Customers", "Customer Group", Customer) and a table named "Price Rule" — keep their names, values, fields and primary key exactly as they are, because the grading tests write rows into the table directly:

Field Type
"Entry No." Integer (primary key)
"Item No." Code[20]
"Source Type" Enum "Price Rule Source Type"
"Source No." Code[20]
"Starting Date" Date
"Ending Date" Date
"Minimum Quantity" Decimal
"Unit Price" Decimal

Complete the codeunit named "Price Waterfall" with one public procedure:

procedure FindBestPrice(ItemNo: Code[20]; CustomerNo: Code[20]; CustomerGroupCode: Code[20]; Quantity: Decimal; OrderDate: Date; var UnitPrice: Decimal): Boolean

A rule applies to a request only when all four checks hold:

  1. Its "Item No." equals ItemNo.
  2. Its source matches: a Customer rule applies when its "Source No." equals CustomerNo; a "Customer Group" rule applies when its "Source No." equals CustomerGroupCode — a blank CustomerGroupCode means the customer belongs to no group, so group rules never apply then; an "All Customers" rule applies to every request.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 18 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade