5001

Invoice Two Shipments at Once

Basics
Easy
Pro
sales
posting
get-shipment-lines

Invoice Two Shipments at Once

Your warehouse ships goods the moment they are ready, but finance wants one invoice per customer — not one invoice per truck. Business Central covers this with the Get Shipment Lines flow: orders are posted ship-only, and later the uninvoiced shipment lines are pulled together into a single sales invoice. Your job is to drive that flow from code.

Requirements

Create a codeunit named "Shipment Invoicer" with exactly this procedure:

procedure CreateInvoiceFromShipments(CustomerNo: Code[20]): Code[20]

The procedure must:

  1. Create exactly one new sales invoice document — a Sales Header with "Document Type" = Invoice — for the given customer. Leave "No." blank and insert the record with its insert trigger running, so the standard sales invoice number series assigns the number; then validate "Sell-to Customer No." with the given customer.
  2. Pull every posted sales shipment line of that customer that still has a quantity left to invoice into that one invoice, using codeunit 64 "Sales-Get Shipment": hand it your invoice header via SetSalesHeader, then pass the shipment lines to CreateInvLines.
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
  • 7 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