---
id: object/codeunit/66
type: object
title: Codeunit 66 "Purch - Calc Disc. By Type"
summary: Codeunit 66 "Purch - Calc Disc. By Type" in Base Application (Microsoft.Purchases.Document). 6 public procedures, 5 events. Present since at least BC23, still in BC30.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: null
  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: 4cd5238ca7bc55bfb77eb7228e7b6235bc66d167b41e8dd7bc81ed4ae55a0e3b
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Purchases/Document/PurchCalcDiscByType.Codeunit.al
    title: src/Layers/W1/BaseApp/Purchases/Document/PurchCalcDiscByType.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: 66
name: Purch - Calc Disc. By Type
namespace: Microsoft.Purchases.Document
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in: []
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 14
  events: 5
  subscribers: 0
relations:
  out: 1
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 3
  calls: 3
  called_by: 21
  implements: 0
---

# Codeunit 66 "Purch - Calc Disc. By Type"

> Codeunit 66 "Purch - Calc Disc. By Type" in Base Application (Microsoft.Purchases.Document). 6 public procedures, 5 events. Present since at least BC23, still in BC30.

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

## Properties

| Property | Value |
|---|---|
| TableNo | Purchase Line |

## Events published

- `OnAfterInvoiceDiscIsAllowed(InvDiscCode: Code[20]; var Result: Boolean)` (integration)
- `OnAfterResetRecalculateInvoiceDisc(var PurchaseHeader: Record "Purchase Header")` (integration)
  - subscribers: [Codeunit 5497 "Graph Mgt - Purch Order Buffer"](../codeunit/5497.md) OnAfterResetRecalculateInvoiceDisc, [Codeunit 5511 "Graph Mgt - Purch. Cr. Memo"](../codeunit/5511.md) OnAfterResetRecalculateCreditMemoDisc, [Codeunit 5529 "Purch. Inv. Aggregator"](../codeunit/5529.md) OnAfterResetRecalculateInvoiceDisc
- `OnBeforeApplyDefaultInvoiceDiscount(var PurchaseHeader: Record "Purchase Header"; var IsHandled: Boolean; InvoiceDiscountAmount: Decimal)` (integration)
- `OnBeforeShouldRedistributeInvoiceDiscountAmount(var PurchaseHeader: Record "Purchase Header"; var IsHandled: Boolean)` (integration)
- `OnResetRecalculateInvoiceDiscOnAfterSetLoadFields(var PurchaseLine: Record "Purchase Line")` (integration)

## Procedures

- `ApplyDefaultInvoiceDiscount(InvoiceDiscountAmount: Decimal; var PurchHeader: Record "Purchase Header")`
- `ApplyInvDiscBasedOnAmt(InvoiceDiscountAmount: Decimal; var PurchHeader: Record "Purchase Header")`
- `GetVendInvoiceDiscountPct(PurchLine: Record "Purchase Line"): Decimal`
- `ShouldRedistributeInvoiceDiscountAmount(PurchHeader: Record "Purchase Header"): Boolean`
- `ResetRecalculateInvoiceDisc(PurchHeader: Record "Purchase Header")`
- `InvoiceDiscIsAllowed(InvDiscCode: Code[20]): Boolean`

Plus 3 local procedures.

## Triggers

OnRun

## Relations

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

## Called by

- [Codeunit 57 "Document Totals"](../codeunit/57.md) (3 calls: `PurchaseRedistributeInvoiceDiscountAmounts → (object)`, `PurchaseUpdateTotalsControlsForceable → InvoiceDiscIsAllowed`, `PurchaseUpdateTotalsControlsForceable → ShouldRedistributeInvoiceDiscountAmount`)
- [Codeunit 1218 "Map Incoming Doc to Purch Doc"](../codeunit/1218.md) (2 calls: `ApplyInvoiceDiscounts → ApplyInvDiscBasedOnAmt`, `ApplyInvoiceDiscounts → InvoiceDiscIsAllowed`)
- [Codeunit 96 "Purch.-Quote to Order"](../codeunit/96.md) (2 calls: `OnRun → ResetRecalculateInvoiceDisc`, `OnRun → ShouldRedistributeInvoiceDiscountAmount`)
- [Codeunit 97 "Blanket Purch. Order to Order"](../codeunit/97.md) (2 calls: `OnRun → ResetRecalculateInvoiceDisc`, `OnRun → ShouldRedistributeInvoiceDiscountAmount`)
- [Codeunit 5497 "Graph Mgt - Purch Order Buffer"](../codeunit/5497.md) (1 call: `RedistributeInvoiceDiscounts → (object)`)
- [Codeunit 5511 "Graph Mgt - Purch. Cr. Memo"](../codeunit/5511.md) (1 call: `RedistributeCreditMemoDiscounts → (object)`)
- [Codeunit 5529 "Purch. Inv. Aggregator"](../codeunit/5529.md) (1 call: `RedistributeInvoiceDiscounts → (object)`)
- [Codeunit 70 "Purch.-Calc.Discount"](../codeunit/70.md) (1 call: `CalculateInvoiceDiscount → ResetRecalculateInvoiceDisc`)
- [Codeunit 99000813 "Carry Out Action"](../codeunit/99000813.md) (1 call: `PrintMultiplePurchaseOrders → ApplyDefaultInvoiceDiscount`)
- [Page 161 "Purchase Statistics"](../page/161.md) (1 call: `OnClosePage → ResetRecalculateInvoiceDisc`)
- [Page 20042 "APIV1 - Purchase Invoices"](../page/20042.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30042 "APIV2 - Purchase Invoices"](../page/30042.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30066 "APIV2 - Purchase Orders"](../page/30066.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 30083 "APIV2 - Purchase Credit Memos"](../page/30083.md) (1 call: `UpdateDiscount → ApplyInvDiscBasedOnAmt`)
- [Page 403 "Purchase Order Statistics"](../page/403.md) (1 call: `OnClosePage → ResetRecalculateInvoiceDisc`)
- [Page 510 "Blanket Purchase Order Subform"](../page/510.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 54 "Purchase Order Subform"](../page/54.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 55 "Purch. Invoice Subform"](../page/55.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 6641 "Purchase Return Order Subform"](../page/6641.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 97 "Purchase Quote Subform"](../page/97.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)
- [Page 98 "Purch. Cr. Memo Subform"](../page/98.md) (1 call: `ValidateInvoiceDiscountAmount → ApplyInvDiscBasedOnAmt`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: none

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