5071

The Date Promising Engine

Algorithm
Medium
Pro
dates
calendar
precedence
working-days

The Date Promising Engine

"When can we deliver?" is the one question every order taker must answer instantly, and Business Central answers it with base calendars, customized calendars per customer, and date walks across them. Your job is that machinery distilled to its core: one rule table, one precedence ladder, and a day-walker that runs in both directions.

Requirements

The starter contains a table "Delivery Calendar Rule" — keep it exactly as shipped, the grading tests seed it and pass it to your procedures:

  • "Entry No." — Integer, the primary key
  • "Customer No." — Code[20]; blank means the rule belongs to the base calendar, otherwise to that customer's calendar
  • "Rule Type" — Option "Day of Week" or Date
  • "Day of Week" — Integer, 1 = Monday … 7 = Sunday (the Date2DWY convention); only meaningful on "Day of Week" rules
  • "Rule Date" — Date; only meaningful on Date rules
  • Nonworking — Boolean; true closes the day, false opens it (an override that re-opens a day some broader rule closed)

Create a codeunit named "Date Promising Engine" with three public procedures:

procedure IsWorkingDay(var DeliveryCalendarRule: Record "Delivery Calendar Rule"; CustomerNo: Code[20]; TargetDate: Date): Boolean
procedure PromisedDeliveryDate(var DeliveryCalendarRule: Record "Delivery Calendar Rule"; CustomerNo: Code[20]; OrderDate: Date; WorkingDays: Integer): Date
procedure LatestOrderDate(var DeliveryCalendarRule: Record "Delivery Calendar Rule"; CustomerNo: Code[20]; RequiredDate: Date; WorkingDays: Integer): Date

Whether a date is working — the precedence ladder

IsWorkingDay decides whether TargetDate is a working day for CustomerNo. Walk this ladder top to bottom and let the first matching rule decide — the day is nonworking exactly when that rule's Nonworking is true:

  1. a Date rule of that customer for exactly TargetDate
  2. a Date rule of the base calendar (blank "Customer No.") for exactly TargetDate
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
  • 23 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