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): BooleanA rule applies to a request only when all four checks hold:
- Its
"Item No."equalsItemNo. - Its source matches: a
Customerrule applies when its"Source No."equalsCustomerNo; a"Customer Group"rule applies when its"Source No."equalsCustomerGroupCode— a blankCustomerGroupCodemeans the customer belongs to no group, so group rules never apply then; an"All Customers"rule applies to every request.
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.
Already on Pro? Sign in