---
id: object/codeunit/56
type: object
title: Codeunit 56 "Sales - Calc Discount By Type"
summary: Codeunit 56 "Sales - Calc Discount By Type" in Base Application (Microsoft.Sales.Document). 9 public procedures, 6 events. Present since at least BC23, still in BC30, changed in BC24-25.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "25"
  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: 7ddb6e4fc1b8357227503fcec6b564ee2981db83b6c6dd4ef843e491341e802d
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/Document/SalesCalcDiscountByType.Codeunit.al
    title: src/Layers/W1/BaseApp/Sales/Document/SalesCalcDiscountByType.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 56
name: Sales - Calc Discount By Type
namespace: Microsoft.Sales.Document
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "25"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 19
  events: 6
  subscribers: 0
relations:
  out: 1
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 4
  calls: 3
  called_by: 27
  implements: 0
---

# Codeunit 56 "Sales - Calc Discount By Type"

> Codeunit 56 "Sales - Calc Discount By Type" in Base Application (Microsoft.Sales.Document). 9 public procedures, 6 events. Present since at least BC23, still in BC30, changed in BC24-25.

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

## Properties

| Property | Value |
|---|---|
| TableNo | Sales Line |

## Events published

- `OnAfterResetRecalculateInvoiceDisc(var SalesHeader: Record "Sales Header")` (integration)
  - subscribers: [Codeunit 5477 "Sales Invoice Aggregator"](../codeunit/5477.md) OnAfterResetRecalculateInvoiceDisc, [Codeunit 5496 "Graph Mgt - Sales Order Buffer"](../codeunit/5496.md) OnAfterResetRecalculateInvoiceDisc, [Codeunit 5506 "Graph Mgt - Sales Quote Buffer"](../codeunit/5506.md) OnAfterResetRecalculateInvoiceDisc, [Codeunit 5508 "Graph Mgt - Sal. Cr. Memo Buf."](../codeunit/5508.md) OnAfterResetRecalculateCreditMemoDisc
- `OnBeforeApplyDefaultInvoiceDiscount(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean; InvoiceDiscountAmount: Decimal)` (integration)
- `OnBeforeApplyInvDiscBasedOnAmt(InvoiceDiscountAmount: Decimal; var SalesHeader: Record "Sales Header")` (integration)
- `OnBeforeShouldRedistributeInvoiceDiscountAmount(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)` (integration)
- `OnGetCustInvoiceDiscountPctOnCaseInvDiscCalcPercent(var SkipCustInvDiscCheck: Boolean)` (integration)
- `OnShouldRedistributeInvoiceDiscountAmountOnCaseInvDiscCalculationNone(SalesHeader: Record "Sales Header"; var ShouldRedistributeInvDiscAmt: Boolean)` (integration)

## Procedures

- `ApplyDefaultInvoiceDiscount(InvoiceDiscountAmount: Decimal; var SalesHeader: Record "Sales Header")`: Applies the default invoice discount to the sales header.
- `ApplyDefaultInvoiceDiscount(InvoiceDiscountAmount: Decimal; var SalesHeader: Record "Sales Header"; ModifyBeforeApplying: Boolean)` (internal)
- `ApplyInvDiscBasedOnAmt(InvoiceDiscountAmount: Decimal; var SalesHeader: Record "Sales Header")`: Applies invoice discount based on a specific amount.
- `GetCustInvoiceDiscountPct(SalesLine: Record "Sales Line"): Decimal`: Gets the customer invoice discount percentage for a sales line.
- `ShouldRedistributeInvoiceDiscountAmount(var SalesHeader: Record "Sales Header"): Boolean`: Determines whether the invoice discount amount should be redistributed.
- `ResetRecalculateInvoiceDisc(SalesHeader: Record "Sales Header")`: Resets the recalculate invoice discount flag on all sales lines.
- `CustInvDiscRecExists(InvDiscCode: Code[20]): Boolean`: Checks if a customer invoice discount record exists for the given code.
- `InvoiceDiscIsAllowed(InvDiscCode: Code[20]): Boolean`: Checks if invoice discount is allowed for the given discount code.
- `CalcInvoiceDiscOnLine(CalcInvoiceDiscountOnLine: Boolean)`: Sets the flag to calculate invoice discount on a specific line.

Plus 4 local procedures.

## Triggers

OnRun

## Relations

- runs on [Table 37 "Sales Line"](../table/37.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 60 "Sales-Calc. Discount"](../codeunit/60.md) (2 calls: `ApplyInvDiscBasedOnPct → (object)`, `ApplyInvDiscBasedOnPct → CalculateInvoiceDiscountOnLine`)
- [Codeunit 65 "Discount Notification Mgt."](../codeunit/65.md) (1 call: `ApplyInvDiscBasedOnAmt → NotifyAboutMissingSetup`)
- [Codeunit 9179 "Application Area Mgmt. Facade"](../codeunit/9179.md) (1 call: `ShouldRedistributeInvoiceDiscountAmount → IsFoundationEnabled`)

## Called by

- [Codeunit 57 "Document Totals"](../codeunit/57.md) (3 calls: `SalesRedistributeInvoiceDiscountAmounts → (object)`, `SalesUpdateTotalsControls → InvoiceDiscIsAllowed`, `SalesUpdateTotalsControls → ShouldRedistributeInvoiceDiscountAmount`)
- [Codeunit 86 "Sales-Quote to Order"](../codeunit/86.md) (2 calls: `OnRun → ResetRecalculateInvoiceDisc`, `OnRun → ShouldRedistributeInvoiceDiscountAmount`)
- [Codeunit 87 "Blanket Sales Order to Order"](../codeunit/87.md) (2 calls: `OnRun → ResetRecalculateInvoiceDisc`, `OnRun → ShouldRedistributeInvoiceDiscountAmount`)
- [Page 95 "Sales Quote Subform"](../page/95.md) (2 calls: `UpdatePage → ApplyDefaultInvoiceDiscount`, `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Codeunit 5341 "CRM Int. Table. Subscriber"](../codeunit/5341.md) (1 call: `ApplySalesOrderDiscounts → ApplyInvDiscBasedOnAmt`)
- [Codeunit 5343 "CRM Sales Order to Sales Order"](../codeunit/5343.md) (1 call: `ApplySalesOrderDiscounts → ApplyInvDiscBasedOnAmt`)
- [Codeunit 5348 "CRM Quote to Sales Quote"](../codeunit/5348.md) (1 call: `ApplyQuoteDiscounts → ApplyInvDiscBasedOnAmt`)
- [Codeunit 5477 "Sales Invoice Aggregator"](../codeunit/5477.md) (1 call: `RedistributeInvoiceDiscounts → (object)`)
- [Codeunit 5496 "Graph Mgt - Sales Order Buffer"](../codeunit/5496.md) (1 call: `RedistributeInvoiceDiscounts → (object)`)
- [Codeunit 5506 "Graph Mgt - Sales Quote Buffer"](../codeunit/5506.md) (1 call: `RedistributeInvoiceDiscounts → (object)`)
- [Codeunit 5508 "Graph Mgt - Sal. Cr. Memo Buf."](../codeunit/5508.md) (1 call: `RedistributeCreditMemoDiscounts → (object)`)
- [Codeunit 60 "Sales-Calc. Discount"](../codeunit/60.md) (1 call: `CalculateInvoiceDiscount → ResetRecalculateInvoiceDisc`)
- [Page 160 "Sales Statistics"](../page/160.md) (1 call: `OnClosePage → ResetRecalculateInvoiceDisc`)
- [Page 20012 "APIV1 - Sales Invoices"](../page/20012.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 20028 "APIV1 - Sales Orders"](../page/20028.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 20037 "APIV1 - Sales Quotes"](../page/20037.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 20038 "APIV1 - Sales Credit Memos"](../page/20038.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30012 "APIV2 - Sales Invoices"](../page/30012.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30028 "APIV2 - Sales Orders"](../page/30028.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30037 "APIV2 - Sales Quotes"](../page/30037.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30038 "APIV2 - Sales Credit Memos"](../page/30038.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 402 "Sales Order Statistics"](../page/402.md) (1 call: `OnClosePage → ResetRecalculateInvoiceDisc`)
- [Page 46 "Sales Order Subform"](../page/46.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 47 "Sales Invoice Subform"](../page/47.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 508 "Blanket Sales Order Subform"](../page/508.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 6631 "Sales Return Order Subform"](../page/6631.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 96 "Sales Cr. Memo Subform"](../page/96.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-25

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 - Calc Discount By Type")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
