---
id: change/bcapps/9656
type: change
title: "#9656 [main] - Incorrect Prepayment Invoice Amount for Sales Orders with Invoice Discount, Prices Including VAT and negative non-inventory line."
summary: Fixes incorrect prepayment invoice amounts for sales orders with invoice discounts, prices including VAT, and negative non-inventory lines by computing expected prepayment amounts line-by-line instead of from the order header.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - codeunit sales-post prepayments
system: sales
review:
  state: reviewed
  by: opus
  at: "2026-10-08T02:09:33.228Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: 8b1040092d34c3b3d7734492eeaffabfff42213c
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/9656
    title: "microsoft/BCApps#9656: [main] - Incorrect Prepayment Invoice Amount for Sales Orders with Invoice Discount, Prices Including VAT and negative non-inventory line."
    date: "2026-08-11"
    commit: 8b1040092d34c3b3d7734492eeaffabfff42213c
    t: null
    quote: Compute the expected prepayment amount line by line from the actual prepayment lines, using each line's own Amount and Prepayment %
links:
  learn: []
  objects:
    - object/codeunit/442
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
number: 9656
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/9656
kind: pr
base_branch: main
major: "30"
merged_at: "2026-08-11T16:07:57Z"
author: v-ankitgoyal
author_type: User
community_contribution: false
labels:
  - "Team: SCM"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 12
  additions: 745
  deletions: 23
  al: 9
apps:
  - Base Application
objects_touched:
  - key: codeunit/442
    page: codeunit/442
    type: codeunit
    id: 442
    name: Sales-Post Prepayments
    app: Base Application
    status: modified
objects_unjoined:
  - path: src/Layers/BE/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al
    status: modified
    reason: not-in-snapshot
  - path: src/Layers/CH/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al
    status: modified
    reason: not-in-snapshot
  - path: src/Layers/ES/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al
    status: modified
    reason: not-in-snapshot
  - path: src/Layers/NL/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al
    status: modified
    reason: not-in-snapshot
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 643210
systems:
  - sales
quote: Compute the expected prepayment amount line by line from the actual prepayment lines, using each line's own Amount and Prepayment %
joined_against:
  major: "30"
  commit: f18567dc08e2bd162bf192e1da4d714b57eb099f
---

# #9656 [main] - Incorrect Prepayment Invoice Amount for Sales Orders with Invoice Discount, Prices Including VAT and negative non-inventory line.

> Fixes incorrect prepayment invoice amounts for sales orders with invoice discounts, prices including VAT, and negative non-inventory lines by computing expected prepayment amounts line-by-line instead of from the order header.

[Pull request](https://github.com/microsoft/BCApps/pull/9656) · merged into `main` (BC30) on 2026-08-11 by v-ankitgoyal · 12 files (+745 -23), 9 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- Prepayment calculation now uses each line's Amount and Prepayment % instead of header-level amounts
- Excludes negative and non-prepayment lines from prepayment base calculation
- Handles mixed prepayment percentages correctly across order lines
- Rounding correction only applies when there is genuine rounding surplus
- Fixes regression where posted prepayment invoices were understated
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 442 "Sales-Post Prepayments"](../../objects/codeunit/442.md), Base Application: modified
- `src/Layers/BE/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al`: modified, not in the BC30 snapshot
- `src/Layers/CH/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al`: modified, not in the BC30 snapshot
- `src/Layers/ES/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al`: modified, not in the BC30 snapshot
- `src/Layers/NL/BaseApp/Sales/Posting/SalesPostPrepayments.Codeunit.al`: modified, not in the BC30 snapshot

## Context

- Work items: AB#643210
- Labels: Team: SCM
- Systems: sales
- From the description: "Compute the expected prepayment amount line by line from the actual prepayment lines, using each line's own Amount and Prepayment %"

Source: metadata of a merged pull request in microsoft/BCApps (bcapps): title, labels, changed paths and counts, with a summary in our words. No source text and no description beyond one short quote (D10, D61).
