---
id: object/codeunit/442
type: object
title: Codeunit 442 "Sales-Post Prepayments"
summary: Codeunit 442 "Sales-Post Prepayments" in Base Application (Microsoft.Sales.Posting). 23 public procedures, 75 events. Present since at least BC23, still in BC30, changed in BC24, BC26-28.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "28"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 0784cbc2ed0f318b5662f574b3088562e8e0fb2906107e332930507dca1bcc88
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al
    title: src/Layers/W1/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations:
    - localization/au
    - localization/ca
    - localization/fi
    - localization/it
    - localization/mx
    - localization/nz
    - localization/us
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/10171
    - change/bcapps/10123
    - change/bcapps/9656
    - change/bcapps/9222
object_type: codeunit
object_id: 442
name: Sales-Post Prepayments
namespace: Microsoft.Sales.Posting
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "26"
  - "27"
  - "28"
source_major: "29"
obsolete: null
countries:
  - au
  - ca
  - fi
  - it
  - mx
  - nz
  - us
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 142
  events: 75
  subscribers: 0
relations:
  out: 1
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 2
  calls: 14
  called_by: 4
  implements: 0
---

# Codeunit 442 "Sales-Post Prepayments"

> Codeunit 442 "Sales-Post Prepayments" in Base Application (Microsoft.Sales.Posting). 23 public procedures, 75 events. Present since at least BC23, still in BC30, changed in BC24, BC26-28.

Base Application · Microsoft.Sales.Posting · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| TableNo | Sales Header |
| Permissions | TableData "Sales Line" = rimd, TableData "Sales Invoice Header" = rimd, TableData "Sales Invoice Line" = rimd, TableData "Sales Cr.Memo Header" = rimd, TableData "Sales Cr.Memo Line" = rimd, TableData "General Posting Setup" = rimd |

## Events published

- `OnAfterApplyFilter(var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; DocumentType: Option)` (integration): Raised after applying filters on sales lines for prepayment processing.
- `OnAfterBuildInvLineBuffer(var PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer")` (integration): Raised after building the prepayment invoice line buffer.
- `OnAfterCalcVATAmountLines(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line"; DocumentType: Option Invoice,"Credit Memo",Statistic; Currency: Record Currency)` (integration): Raised after calculating VAT amount lines for prepayments.
- `OnAfterCheckPrepmtDoc(SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo"; CommitIsSuppressed: Boolean; var ErrorMessageMgt: Codeunit "Error Message Management")` (integration): Raised after checking the prepayment document for posting readiness.
  - subscribers: [Codeunit 5579 "Digital Voucher Impl."](../codeunit/5579.md) OnAfterCheckSalesPrepmtDoc
- `OnAfterCreateDimensions(var SalesLine: Record "Sales Line"; DefaultDimSource: List of [Dictionary of [Integer, Code[20]]])` (integration): Raised after creating dimensions for prepayment lines.
- `OnAfterCreateLinesOnBeforeGLPosting(var SalesHeader: Record "Sales Header"; SalesInvHeader: Record "Sales Invoice Header"; SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var TempPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary; DocumentType: Option; var LastLineNo: Integer)` (integration): Raised after creating prepayment lines and before posting to the general ledger.
- `OnAfterFillInvLineBuffer(var PrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer"; SalesLine: Record "Sales Line"; CommitIsSuppressed: Boolean; SalesHeader: Record "Sales Header")` (integration): Raised after filling the prepayment invoice line buffer from a sales line.
- `OnAfterInsertInvoiceRounding(SalesHeader: Record "Sales Header"; var PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; var TotalPrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer"; var PrevLineNo: Integer)` (integration): Raised after inserting the invoice rounding line for prepayments.
- `OnAfterPostPrepayments(var SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo"; CommitIsSuppressed: Boolean; var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var CustLedgerEntry: Record "Cust. Ledger Entry")` (integration): Raised after posting prepayments.
  - subscribers: [Codeunit 5579 "Digital Voucher Impl."](../codeunit/5579.md) CheckSalesVoucherOnAfterPostPrepayments
- `OnAfterPostPrepaymentsOnBeforeThrowPreviewModeError(var SalesHeader: Record "Sales Header"; var SalesInvHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; PreviewMode: Boolean)` (integration): Raised after posting prepayments before throwing a preview mode error.
- `OnAfterPostBalancingEntry(var GenJnlLine: Record "Gen. Journal Line"; CustLedgEntry: Record "Cust. Ledger Entry"; TotalPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; TotalPrepmtInvLineBufferLCY: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean; SalesHeader: Record "Sales Header")` (integration): Raised after posting the balancing entry for prepayments.
- `OnAfterPostCustomerEntry(var GenJnlLine: Record "Gen. Journal Line"; TotalPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; TotalPrepmtInvLineBufferLCY: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised after posting the customer entry for prepayments.
- `OnAfterPostPrepmtInvLineBuffer(var GenJnlLine: Record "Gen. Journal Line"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line")` (integration): Raised after posting a prepayment invoice line buffer entry.
- `OnAfterRoundAmounts(SalesHeader: Record "Sales Header"; var PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; var TotalPrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer"; var TotalPrepmtInvLineBufLCY: Record "Prepayment Inv. Line Buffer")` (integration): Raised after rounding prepayment amounts.
- `OnAfterSalesInvHeaderInsert(var SalesInvoiceHeader: Record "Sales Invoice Header"; SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean)` (integration): Raised after inserting a prepayment sales invoice header.
- `OnAfterSalesInvLineInsert(var SalesInvLine: Record "Sales Invoice Line"; SalesInvHeader: Record "Sales Invoice Header"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised after inserting a prepayment sales invoice line.
- `OnAfterSalesCrMemoHeaderInsert(var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean)` (integration): Raised after inserting a prepayment sales credit memo header.
- `OnAfterSalesCrMemoLineInsert(var SalesCrMemoLine: Record "Sales Cr.Memo Line"; SalesCrMemoHeader: Record "Sales Cr.Memo Header"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised after inserting a prepayment sales credit memo line.
- `OnAfterUpdatePostedSalesDocument(DocumentType: Option Invoice,"Credit Memo"; DocumentNo: Code[20]; CommitIsSuppressed: Boolean)` (integration): Raised after updating the posted sales document with prepayment information.
- `OnAfterUpdateVATOnLines(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line"; DocumentType: Option Invoice,"Credit Memo",Statistic)` (integration): Raised after updating VAT on lines for prepayments.
- `OnBeforeCheckPrepmtDoc(SalesHeader: Record "Sales Header"; DocumentType: Option; CommitIsSuppressed: Boolean)` (integration): Raised before checking the prepayment document for posting readiness.
- `OnBeforeCheckOpenPrepaymentLines(SalesHeader: Record "Sales Header"; DocumentType: Option; var Found: Boolean; var IsHandled: Boolean)` (integration): Raised before checking for open prepayment lines.
- `OnBeforeCreateLinesFromBuffer(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var TempGlobalPrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer" temporary; var LineCount: Integer; var SalesInvHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var PostedDocTabNo: Integer; DocumentType: Option; var LastLineNo: Integer; GenJnlLineDocNo: Code[20]; var IsHandled: Boolean)` (integration): Raised before creating lines from the prepayment buffer.
- `OnBeforeInvoice(var SalesHeader: Record "Sales Header"; var Handled: Boolean)` (integration): Raised before posting a prepayment invoice.
- `OnBeforeCreditMemo(var SalesHeader: Record "Sales Header"; var Handled: Boolean)` (integration): Raised before posting a prepayment credit memo.
- `OnBeforeFillInvLineBuffer(var PrepaymentInvLineBuffer: Record "Prepayment Inv. Line Buffer"; SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line")` (integration): Raised before filling the prepayment invoice line buffer.
- `OnBeforeInsertExtendedText(TabNo: Integer; DocNo: Code[20]; GLAccNo: Code[20]; DocDate: Date; LanguageCode: Code[10]; var PrevLineNo: Integer)` (integration): Raised before inserting extended text for prepayment lines.
- `OnBeforePostPrepayments(var SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo"; CommitIsSuppressed: Boolean; PreviewMode: Boolean)` (integration): Raised before posting prepayments.
- `OnBeforeSalesInvHeaderInsert(var SalesInvHeader: Record "Sales Invoice Header"; SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean; GenJnlDocNo: Code[20])` (integration): Raised before inserting the prepayment sales invoice header.
- `OnBeforeSalesAssertPrepmtAmountNotMoreThanDocAmount(var CustLedgEntry: Record "Cust. Ledger Entry"; SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; var IsHandled: Boolean)` (integration): Raised before asserting that the prepayment amount is not more than the document amount.
- `OnBeforeSalesInvLineInsert(var SalesInvLine: Record "Sales Invoice Line"; SalesInvHeader: Record "Sales Invoice Header"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised before inserting a prepayment sales invoice line.
- `OnBeforeSalesCrMemoHeaderInsert(var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean)` (integration): Raised before inserting the prepayment sales credit memo header.
- `OnBeforeSalesCrMemoLineInsert(var SalesCrMemoLine: Record "Sales Cr.Memo Line"; SalesCrMemoHeader: Record "Sales Cr.Memo Header"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised before inserting a prepayment sales credit memo line.
- `OnBeforePostCustomerEntry(var GenJnlLine: Record "Gen. Journal Line"; TotalPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; TotalPrepmtInvLineBufferLCY: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean; SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo")` (integration): Raised before posting the customer entry for the prepayment.
- `OnBeforeRunGenJnlPostLine(var GenJnlLine: Record "Gen. Journal Line")` (integration): Raised before running the general journal post line codeunit.
- `OnBeforeUpdateSalesDocument(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; DocumentType: Option; GenJnlLineDocNo: Code[20])` (integration): Raised before updating the sales document after prepayment posting.
- `OnBeforeUpdateDocNos(var SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo"; var DocNo: Code[20]; var NoSeriesCode: Code[20]; var ModifyHeader: Boolean; IsPreviewMode: Boolean; var IsHandled: Boolean)` (integration): Raised before updating document numbers for prepayment posting.
- `OnBeforeUpdatePostedSalesDocument(var CustLedgerEntry: Record "Cust. Ledger Entry"; var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; DocumentType: Option Invoice,"Credit Memo"; var IsHandled: Boolean; DocumentNo: Code[20])` (integration): Raised before updating the posted sales document with the customer ledger entry number.
- `OnBeforePostPrepmtInvLineBuffer(var GenJnlLine: Record "Gen. Journal Line"; PrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean)` (integration): Raised before posting the prepayment invoice line buffer to the general journal.
- `OnCalcVATAmountLinesOnBeforeUpdateLines(var NewAmount: Decimal; Currency: Record Currency; SalesHeader: Record "Sales Header"; var IsHandled: Boolean)` (integration): Raised during VAT amount lines calculation before updating lines.
- `OnCodeOnAfterBuildInvLineBuffer(var TempVATAmountLine: Record "VAT Amount Line" temporary; var TempPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary)` (integration): Raised after building the prepayment invoice line buffer in the Code procedure.
- `OnCodeOnBeforeCalcAndUpdateVATAmountLines(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var TempPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary; DocumentType: Option; var IsHandled: Boolean)` (integration): Raised before calculating and updating VAT amount lines in the Code procedure.
- `OnCodeOnBeforePostCustomerEntry(var SalesHeader: Record "Sales Header"; var TempPrepaymentInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary)` (integration): Raised before posting the customer entry in the Code procedure.
- `OnCodeOnBeforePostBalancingEntry(var SalesHeader: Record "Sales Header"; var TempPrepaymentInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary)` (integration): Raised before posting the balancing entry in the Code procedure.
- `OnCodeOnBeforeWindowOpen(var SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo")` (integration): Raised before opening the progress window in the Code procedure.
- `OnCodeOnAfterCalcShouldSetPendingPrepaymentStatus(var SalesHeader: Record "Sales Header"; var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; DocumentType: Option Invoice,"Credit Memo"; PreviewMode: Boolean; var ShouldSetPendingPrepaymentStatus: Boolean)` (integration): Raised after calculating whether to set pending prepayment status in the Code procedure.
- `OnInsertExtendedTextOnBeforeSalesInvLineInsert(var SalesInvoiceLine: Record "Sales Invoice Line"; TabNo: Integer; DocNo: Code[20]; NextLineNo: Integer; var TempExtendedTextLine: Record "Extended Text Line" temporary; SalesHeader: Record "Sales Header")` (integration): Raised before inserting a sales invoice line during extended text insertion.
- `OnInsertExtendedTextOnBeforeSalesCrMemoLineInsert(var SalesCrMemoLine: Record "Sales Cr.Memo Line"; TabNo: Integer; DocNo: Code[20]; NextLineNo: Integer; var TempExtendedTextLine: Record "Extended Text Line" temporary; SalesHeader: Record "Sales Header")` (integration): Raised before inserting a sales credit memo line during extended text insertion.
- `OnPostBalancingEntryOnBeforeGenJnlPostLineRunWithCheck(var GenJnlLine: Record "Gen. Journal Line"; CustLedgEntry: Record "Cust. Ledger Entry"; TotalPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer"; TotalPrepmtInvLineBufferLCY: Record "Prepayment Inv. Line Buffer"; CommitIsSuppressed: Boolean; SalesHeader: Record "Sales Header"; DocType: enum "Gen. Journal Document Type")` (integration): Raised before running the general journal post line with check during balancing entry posting.
- `OnRoundAmountsOnBeforeIncrAmounts(SalesHeader: Record "Sales Header"; var PrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer"; var TotalPrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer"; var TotalPrepmtInvLineBufLCY: Record "Prepayment Inv. Line Buffer")` (integration): Raised before incrementing amounts during the rounding process.
- `OnUpdateSalesDocumentOnBeforeFindSetCreditMemoSalesLine(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line")` (integration): Raised before finding the credit memo sales lines during prepayment document update.
- `OnUpdateSalesDocumentOnBeforeModifyCreditMemoSalesLine(var SalesLine: Record "Sales Line")` (integration): Raised before modifying the sales line during credit memo prepayment document update.
- `OnUpdateSalesDocumentOnBeforeModifyInvoiceSalesLine(var SalesLine: Record "Sales Line")` (integration): Raised before modifying the sales line during invoice prepayment document update.
- `OnUpdateVATOnLinesOnAfterGetRemainder(var VATAmountLineRemainder: Record "VAT Amount Line"; var RemainderExists: Boolean)` (integration): Raised after getting the remainder during VAT update on lines.
- `OnUpdateVATOnLinesOnAfterVATAmountLineGet(var VATAmountLine: Record "VAT Amount Line")` (integration): Raised after getting the VAT amount line during VAT update on lines.
- `OnUpdateVATOnLinesOnBeforeSalesLineModify(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var TempVATAmountLineRemainder: Record "VAT Amount Line"; NewAmount: Decimal; NewAmountIncludingVAT: Decimal; NewVATBaseAmount: Decimal)` (integration): Raised before modifying the sales line during VAT update on lines.
- `OnBeforeThrowPreviewError(SalesHeader: Record "Sales Header")` (integration): Raised before throwing a preview error.
- `OnBeforeCheckSalesLineIsNegative(SalesLine: Record "Sales Line"; var IsHandled: Boolean)` (integration): Raised before checking if the sales line is negative.
- `OnBeforeGetSalesLines(SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo",Statistic; var ToSalesLine: Record "Sales Line"; var IsHandled: Boolean)` (integration): Raised before getting sales lines for prepayment processing.
- `OnBeforeUpdatePrepmtAmountOnSaleslines(SalesHeader: Record "Sales Header"; NewTotalPrepmtAmount: Decimal; var IsHandled: Boolean)` (integration): Raised before updating prepayment amounts on sales lines.
- `OnUpdatePrepmtAmountOnSaleslinesOnAfterSetFilters(var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; var NewTotalPrepmtAmount: Decimal)` (integration): Raised after setting filters on sales lines when updating prepayment amounts.
- `OnUpdatePrepmtAmountOnSaleslinesOnBeforeModify(var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; var NewTotalPrepmtAmount: Decimal; var TotalPrepmtAmount: Decimal)` (integration): Raised before modifying a sales line with its updated prepayment amount.
- `OnGetSalesLinesOnBeforeInsertToSalesLine(var ToSalesLine: Record "Sales Line")` (integration): Raised before inserting to the sales line in the GetSalesLines procedure.
- `OnCodeOnBeforeInsertPostedHeaders(var SalesHeader: Record "Sales Header")` (integration): Raised before inserting posted headers in the Code procedure.
- `OnAfterUpdateDocNos(var SalesHeader: Record "Sales Header")` (integration): Raised after updating document numbers for prepayment posting.
- `OnBuildInvLineBufferOnBeforeFillInvLineBuffer(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line")` (integration): Raised before filling the invoice line buffer in the BuildInvLineBuffer procedure.
- `OnCodeOnAfterPostingDescriptionSet(var SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo"; var PostingDescription: Text[100])` (integration): Raised after setting the posting description in the Code procedure.
- `OnBeforePostCustomerEntryProcedure(var SalesHeader: Record "Sales Header"; TotalPrepmtInvLineBuffer: Record "Prepayment Inv. Line Buffer" temporary; TotalPrepmtInvLineBufferLCY: Record "Prepayment Inv. Line Buffer"; DocumentType: Option Invoice,"Credit Memo"; PostingDescription: Text[100]; DocType: Enum "Gen. Journal Document Type"; DocNo: Code[20]; ExtDocNo: Text[35]; SrcCode: Code[10]; PostingNoSeriesCode: Code[20]; CalcPmtDisc: Boolean; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; var IsHandled: Boolean)` (integration): Raised before the PostCustomerEntry procedure.
- `OnBeforePrepmtAmount(var SalesLine: Record "Sales Line"; DocumentType: Option Invoice,"Credit Memo",Statistic; var Result: Decimal; var IsHandled: Boolean)` (integration): Raised before calculating the prepayment amount.
- `OnInsertVATAmountOnBeforeInsert(var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line")` (integration): Raised before inserting a VAT amount line in the InsertVATAmount procedure.
- `OnFindVATAmountLineOnAfterSetFilters(var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line")` (integration): Raised after setting filters in the FindVATAmountLine procedure.
- `OnCodeOnBeforeCheckPrepmtDoc(var SalesHeader: Record "Sales Header"; var DocumentType: Option Invoice,"Credit Memo")` (integration): Raised before checking the prepayment document in the Code procedure.
- `OnAfterGetPrepmtAccNo(GenPostingSetup: Record "General Posting Setup"; var PrepmtAccNo: Code[20])` (integration): Raised after getting the prepayment account number from the general posting setup.
- `OnAfterGetCorrBalAccNo(SalesHeader: Record "Sales Header"; PositiveAmount: Boolean; var BalAccNo: Code[20])` (integration): Raised after getting the correction balancing account number.
- `OnCodeOnAfterSetSourceCode(var SalesHeader: Record "Sales Header"; SourceCodeSetup: Record "Source Code Setup"; var SrcCode: Code[10])` (integration): Raised after setting the source code in the Code procedure.

## Procedures

- `SetDocumentType(DocumentType: Option ,,Invoice,"Credit Memo")`: Sets the prepayment document type to be posted.
- `Invoice(var SalesHeader: Record "Sales Header")`: Posts a prepayment invoice for the sales order.
- `CreditMemo(var SalesHeader: Record "Sales Header")`: Posts a prepayment credit memo for the sales order.
- `CheckPrepmtDoc(SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo")`: Validates the sales order and prepayment settings before posting a prepayment document.
- `CheckOpenPrepaymentLines(SalesHeader: Record "Sales Header"; DocumentType: Option): Boolean`: Checks if there are open prepayment lines available for posting.
- `BuildInvLineBuffer(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; DocumentType: Option Invoice,"Credit Memo",Statistic; var PrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer")`: Builds the prepayment invoice line buffer from the sales lines for posting.
- `GetCorrBalAccNo(SalesHeader: Record "Sales Header"; PositiveAmount: Boolean): Code[20]`: Gets the correction balancing account number for prepayment adjustments.
- `GetInvRoundingAccNo(CustomerPostingGroup: Code[20]): Code[20]`: Gets the invoice rounding account number from the customer posting group.
- `FillInvLineBuffer(SalesHeader: Record "Sales Header"; SalesLine: Record "Sales Line"; var PrepmtInvLineBuf: Record "Prepayment Inv. Line Buffer")`: Fills the prepayment invoice line buffer with data from a sales line.
- `InitInvoiceRoundingLine(SalesHeader: Record "Sales Header"; TotalAmount: Decimal; var SalesLine: Record "Sales Line"): Boolean`: Initializes an invoice rounding line for the prepayment if rounding is required.
- `UpdateVATOnLines(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line"; DocumentType: Option Invoice,"Credit Memo",Statistic)`: Updates the VAT amounts on sales lines based on the VAT amount lines for prepayment documents.
- `CalcVATAmountLines(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line"; DocumentType: Option Invoice,"Credit Memo",Statistic)`: Calculates the VAT amount lines for prepayment documents.
- `SumPrepmt(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; var VATAmountLine: Record "VAT Amount Line"; var TotalAmount: Decimal; var TotalVATAmount: Decimal; var VATAmountText: Text[30])`: Calculates the total prepayment amount and VAT amount for statistics.
- `GetSalesLines(SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo",Statistic; var ToSalesLine: Record "Sales Line")`: Gets the sales lines with prepayment amounts for the specified document type.
- `ApplyFilter(SalesHeader: Record "Sales Header"; DocumentType: Option Invoice,"Credit Memo",Statistic; var SalesLine: Record "Sales Line")`: Applies filters to the sales lines for prepayment processing based on document type.
- `PrepmtAmount(SalesLine: Record "Sales Line"; DocumentType: Option Invoice,"Credit Memo",Statistic): Decimal`: Calculates the prepayment amount for the sales line based on the document type.
- `UpdatePrepmtAmountOnSaleslines(SalesHeader: Record "Sales Header"; NewTotalPrepmtAmount: Decimal)`: Distributes the new total prepayment amount across the sales lines proportionally.
- `PrepmtDocTypeToDocType(DocumentType: Option Invoice,"Credit Memo"): Integer`: Converts the prepayment document type to the corresponding sales document type integer value.
- `GetSalesLinesToDeduct(SalesHeader: Record "Sales Header"; var SalesLines: Record "Sales Line")`: Gets the sales lines that have prepayment amounts to deduct during final invoicing.
- `GetPreviewMode(): Boolean`: Gets whether the prepayment posting is running in preview mode.
- `GetSuppressCommit(): Boolean`: Gets whether database commits are being suppressed during prepayment posting.
- `SetSuppressCommit(NewSuppressCommit: Boolean)`: Sets whether database commits should be suppressed during prepayment posting.
- `SetPreviewMode(NewPreviewMode: Boolean)`: Sets whether the prepayment posting is running in preview mode.

Plus 44 local procedures.

## Triggers

OnRun

## Relations

- runs on [Table 36 "Sales Header"](../table/36.md)

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 28 "Error Message Management"](../codeunit/28.md) (11 calls: `BuildInvLineBuffer → FinishTopContext`, `CheckPrepmtDoc → Finish`, `CheckPrepmtDoc → GetFieldNo`, …)
- [Codeunit 12 "Gen. Jnl.-Post Line"](../codeunit/12.md) (3 calls: `PostBalancingEntry → RunWithCheck`, `PostCustomerEntry → RunWithCheck`, `RunGenJnlPostLine → RunWithCheck`)
- [Codeunit 408 "DimensionManagement"](../codeunit/408.md) (2 calls: `CreateDimensions → AddDimSource`, `CreateDimensions → GetRecDefaultDimID`)
- [Codeunit 441 "Prepayment Mgt."](../codeunit/441.md) (2 calls: `SalesAssertPrepmtAmountNotMoreThanDocAmount → AssertPrepmtAmountNotMoreThanDocAmount`, `SalesAssertPrepmtAmountNotMoreThanDocAmountBeforePost → AssertPrepmtAmountNotMoreThanDocAmount`)
- [Codeunit 8703 "Feature Telemetry"](../codeunit/8703.md) (2 calls: `Code → LogUptake`, `Code → LogUsage`)
- [Page 456 "No. Series"](../page/456.md) (2 calls: `UpdateCrMemoDocNos → (object)`, `UpdateInvoiceDocNos → (object)`)
- [Codeunit 11 "Gen. Jnl.-Check Line"](../codeunit/11.md) (1 call: `CheckPrepmtDoc → DateNotAllowed`)
- [Codeunit 1431 "Forward Link Mgt."](../codeunit/1431.md) (1 call: `CheckPrepmtDoc → GetHelpCodeForAllowedPostingDate`)
- [Codeunit 19 "Gen. Jnl.-Post Preview"](../codeunit/19.md) (1 call: `Code → ThrowError`)
- [Codeunit 378 "Transfer Extended Text"](../codeunit/378.md) (1 call: `InsertExtendedText → PrepmtGetAnyExtText`)
- [Codeunit 481 "Check Dimensions"](../codeunit/481.md) (1 call: `CheckPrepmtDoc → CheckSalesPrepmtDim`)
- [Codeunit 57 "Document Totals"](../codeunit/57.md) (1 call: `Code → SalesRedistributeInvoiceDiscountAmountsOnDocument`)
- [Codeunit 9070 "Document Errors Mgt."](../codeunit/9070.md) (1 call: `CheckPrepmtDoc → GetNothingToPostErrorMsg`)
- [Codeunit 9500 "Sequence No. Mgt."](../codeunit/9500.md) (1 call: `OnRun → SetPreviewMode`)

## Called by

- [Codeunit 443 "Sales-Post Prepayment (Yes/No)"](../codeunit/443.md) (6 calls: `OnRunPreview → (object)`, `OnRunPreview → SetDocumentType`, `OnRunPreview → SetPreviewMode`, …)
- [Page 402 "Sales Order Statistics"](../page/402.md) (5 calls: `RefreshOnAfterGetRecord → GetSalesLines`, `RefreshOnAfterGetRecord → SumPrepmt`, `UpdatePrepmtAmount → GetSalesLines`, …)
- [Codeunit 815 "Sales Post Invoice"](../codeunit/815.md) (2 calls: `PrepareLine → GetCorrBalAccNo`, `PrepareLine → GetInvRoundingAccNo`)
- [Table 37 "Sales Line"](../table/37.md) (1 call: `GetLineAmountToHandleInclPrepmt → PrepmtAmount`)

## Recent changes

- 2026-08-16 [#10171 [Extensibility Request] issue 30110: add prepayment update events](../../changes/bcapps/10171.md) (main, BC30, feature)
- 2026-08-14 [#10123 [Extensibility Request] issue 30401: add credit memo sales line filter event](../../changes/bcapps/10123.md) (main, BC30, feature)
- 2026-08-11 [#9656 [main] - Incorrect Prepayment Invoice Amount for Sales Orders with Invoice Discount, Prices Including VAT and negative non-inventory line.](../../changes/bcapps/9656.md) (main, BC30, fix)
- 2026-07-14 [#9222 [Main]- When issuing a prepayment invoice with an invoice discount applied, the prepayment amount does not take into account the total amount including tax.](../../changes/bcapps/9222.md) (main, BC30, fix)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24, BC26-28

## Countries that replace it

[AU](../../localizations/au.md), [CA](../../localizations/ca.md), [FI](../../localizations/fi.md), [IT](../../localizations/it.md), [MX](../../localizations/mx.md), [NZ](../../localizations/nz.md), [US](../../localizations/us.md)

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Sales-Post Prepayments")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
