Skip to content

navipartner/sales-receipt-print-codeunit-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sales Receipt Print Codeunit Example

A reference PTE (per-tenant extension) that reproduces NP Retail's standard static sales receipt print logic verbatim. Use it as the starting point for customer-specific receipt customizations on tenants that have switched to the "New Sales Receipt Experience" in NP Retail.

The receipt print itself is implemented in Application/src/SalesReceiptPrintExample.Codeunit.al (codeunit 50100 "Sales Receipt Print Example").

What this PTE does

It is functionally equivalent to NP Retail's codeunit 6248348 "NPR Static Sales Receipt":

  • Same column layout (0.465 / 0.35 / 0.235), same fonts, same labels.
  • Same conditional sections — logo, store header, copy banner, customer, contact, sale-line table with per-type rendering (Item / Comment / Customer / G/L / Payout / Voucher), VAT lines, total, payments, rounding, barcode (Code128 or QR), footer text, date/time/user line, papercut.

NP Retail's underlying tables are Access = Internal and therefore not reachable from a PTE. To bridge that, the example uses the public facade codeunit NPR ReceiptPrintUtilities (in NPCore's Application/src/Retail Print/_public/), which wraps the internal reads behind a stable, public API:

Need Facade method on NPR ReceiptPrintUtilities
Is this print a reprint of an earlier receipt? IsReprint(POSEntryNo: Integer): Boolean
Should the receipt barcode render as a QR code? ShowBarcodeAsQRCode(POSUnitNo: Code[10]): Boolean
Append the configured receipt footer text lines AddReceiptFooterText(POSUnitNo: Code[10]; var Printer: Codeunit "NPR RP Line Print"; Alignment: Integer): Boolean

Prerequisites

  • Business Central environment (BC17 runtime or newer; the example targets application: 28.0.0.0).
  • NP Retail 17.0.0.0 or newer installed on the tenant (see dependencies in Application/app.json).
  • A licensed PTE object range; the example uses 50000–50149.

Build and deploy

  1. Open Main.code-workspace in VS Code with the AL Language extension.
  2. Download symbols (AL: Download symbols) — requires access to a server that has the NP Retail symbols.
  3. Build (Ctrl+Shift+B). The produced .app lands in Application/ (e.g. NaviPartner_Sales Receipt Print Codeunit Example_1.0.0.0.app).
  4. Publish the .app to the target tenant (sandbox or production) via the BC Admin Center, Publish-NAVApp (on-prem), or the VS Code AL: Publish command for a dev environment.

Setup — wire the PTE into NP Retail

NP Retail dispatches the sales-receipt print through the NPR Report Selection Retail table. Each row defines what runs when a POS Entry is printed — a print template, a report, or a codeunit. To make this PTE handle prints, swap NP Retail's default codeunit reference for codeunit 50100 "Sales Receipt Print Example".

Step 1 — point Report Selection Retail at this PTE

  1. Search for Report Selection - Retail in BC.
  2. Set the Report Type filter at the top of the page to Sales Receipt (POS Entry).
  3. On the row(s) you want to override:
    • Set Codeunit ID to 50100 (the page will resolve Codeunit Name to Sales Receipt Print Example).
    • Optionally set Register No. to scope the override to a specific POS unit; leave blank to apply to all units that do not have a unit-specific row.
    • Leave Report ID and Print Template empty — they take precedence over Codeunit ID in NPR Retail Report Select. Mgt.RunSelection and will silently bypass the PTE if set.

Step 2 — verify

Run a sale on a POS unit covered by the rule. The receipt should print with the same layout as before; if the layout is unchanged that confirms the PTE is the one running (it's a 1:1 copy of the built-in). Change a string in SalesReceiptPrintExample.Codeunit.al, republish, and re-print to confirm the customization point is now under your control.

How the dispatch works

When NP Retail finishes posting a POS Entry, NPR Retail Report Select. Mgt..RunObjects looks up the matching Report Selection Retail rows for Sales Receipt (POS Entry), filtered by Register No. if a unit-specific row exists, falling back to the blank-register row otherwise. For each row it picks one of three branches, in this priority:

  1. Print Template set → run the template (legacy path, blocked once the new experience is enabled).
  2. Report ID set → run that report.
  3. Codeunit ID set → Codeunit.Run(ReportSelection."Codeunit ID", Variant) where Variant wraps a RecordRef of the POS Entry.

Branch 3 is what calls this PTE. Codeunit 50100 has TableNo = "NPR POS Entry", so the dispatched RecordRef is bound to Rec in OnRun.

Customizing

Most edits will land in AddReceiptInformation in SalesReceiptPrintExample.Codeunit.al. Useful entry points:

  • Add or remove header lines → the POSStore block.
  • Change line formatting → the case POSEntrySalesLine.Type of block.
  • Add a custom footer → before the date/time line, after ReceiptPrintUtilities.AddReceiptFooterText.
  • Switch to QR-only or Code128-only → the barcode block.

For data that NP Retail exposes via public objects (look in _public folders under Application/src/ in NPCore — facade codeunits, public tables, and public queries), call those directly.

Caveats

  • Logo lookup uses the currently signed-in POS unit. The line printer driver resolves the retail logo by POSUnit.GetCurrentPOSUnit(), not by POSEntry."POS Unit No.". For a first-print this is the same unit; for a reprint triggered from a different terminal, the logo of the printing terminal is used. This matches the built-in NPR Static Sales Receipt behavior exactly. If you need entry-unit-bound logo resolution, you'd have to drop the 'Logo'/'RECEIPT' pattern and emit the image yourself.

About

Sales Receipt Print codeunit example

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages