<!-- md-source: 6357ef2ad743 FactoorSharpWeb/wwwroot/de/Service/CorrectionInvoice.md -->

# Correction invoice

> Markdown version of <https://www.factoorsharp.de/en/Service/CorrectionInvoice> for AI agents.
> Languages: [Deutsch](https://www.factoorsharp.de/de/Service/CorrectionInvoice.md) ·
> [English](https://www.factoorsharp.de/en/Service/CorrectionInvoice.md) ·
> [Français](https://www.factoorsharp.de/fr/Service/CorrectionInvoice.md)

The correction of an over-billed goods delivery: document type 384, all amounts negative,
the unit prices positive.

The basis is the official sample invoice `X14_01_Rechnungskorrektur` from the
Factur-X / ZUGFeRD documentation (FeRD sample package, ZUGFeRD 2.5.0, EXTENDED profile).
The code produces exactly that document, field by field and in the same order.

Note texts, product names and discount reasons stay in German throughout: they are the
payload of the official reference document, and translating them would break the
comparison with it.

## Correction or credit note?

Both kinds of document reduce a receivable, but they do so in opposite ways.

| | Correction invoice (384) | Credit note (381) |
|---|---|---|
| FactoorSharp | `InvoiceType.Correction` | `InvoiceType.CreditNote` |
| Quantities (BT-129) | **negative** | positive |
| Unit prices (BT-146 / BT-148) | positive | positive |
| Totals, taxes, discounts | **negative** | positive |
| Reading | corrects the original invoice by a difference | mirrors the original invoice as a whole |

The sign belongs in the **quantity**, not in the price. A negative unit price with a
positive quantity yields the same line total arithmetically, but it is unsound in
business terms.

## 1. Invoice header

```csharp
FacturXInvoice invoice = FacturXInvoice.CreateInvoice(
    invoiceNo: "RK21012345",
    invoiceDate: new DateTime(2025, 10, 1),
    currency: CurrencyCodes.EUR);

// BT-3: 384 = correction invoice. The decisive difference from 381 (credit note).
invoice.Type = InvoiceType.Correction;

invoice.Name = "RECHNUNGS-KORREKTUR";   // BT-X-2, EXTENDED only
invoice.IsTest = true;                  // ram:TestIndicator, EXTENDED only

// BT-23: business process → ram:BusinessProcessSpecifiedDocumentContextParameter
invoice.BusinessProcess = "Beispielgeschäftsprozess";
```

## 2. Free-text notes

In this reference the `AAK` note with a content code comes first. Since the cross-check
also compares the order, that is a requirement rather than a detail.

```csharp
invoice.AddNote("Es bestehen Rabatt- oder Bonusvereinbarungen.",
                subjectCode: SubjectCodes.AAK,
                contentCode: ContentCodes.ST3);

invoice.AddNote("Geschäftsführer: Herr Geschäftsführer , Muster Maschinenbau GmbH etc. ",
                subjectCode: SubjectCodes.REG);

invoice.AddNote("Es bestehen Vereinbarungen, aus denen sich Minderungen des Entgelts ergeben können.",
                subjectCode: SubjectCodes.AAI);

invoice.AddNote("ZUGFeRD vers 2.5.0 (Extended)", subjectCode: SubjectCodes.ACB);
invoice.AddNote("Dies ist eine Beispiel-für eine Korrektur einer Rechnung (Type 384)",
                subjectCode: SubjectCodes.ACB);
```

## 3. Seller and buyer

Unchanged compared to a normal invoice – a correction does not swap the roles. Unlike the
goods invoice, without an electronic address.

```csharp
invoice.SetSeller(
    name: "MUSTERLIEFERANT GMBH",
    postcode: "98765",
    city: "MUSTERHAUSEN",
    street: "BAHNHOFSTRASSE 99",
    country: CountryCodes.DE,
    id: "549910",
    globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4333741000005"));

invoice.SetSellerContact(
    emailAddress: "max.mustermann@musterlieferant.de",
    phoneno: "+49 932 431 500");

invoice.AddSellerTaxRegistration("DE123456788", TaxRegistrationSchemeID.VA);

invoice.SetBuyer(
    name: "MUSTER-KUNDE GMBH",
    postcode: "12345",
    city: "KUNDENDORF",
    street: "KUNDENWEG 88",
    country: CountryCodes.DE,
    id: "009420",
    globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4304171000002"));
```

## 4. Document references

Two additional document references (BT-18 / BG-24) with type code 130 carry the complaint
process and the original invoice number. The order of the calls determines the order in
the XML.

```csharp
invoice.SetBuyerOrderReferenceDocument("B123456789");   // BT-13

invoice.AddAdditionalReferencedDocument(
    id: "REKLA-2018-235",
    typeCode: AdditionalReferencedDocumentTypeCode.InvoiceDataSheet);
invoice.AddAdditionalReferencedDocument(
    id: "R87654321012345",
    typeCode: AdditionalReferencedDocumentTypeCode.InvoiceDataSheet);

invoice.SetDeliveryNoteReferenceDocument("L87654321012345");   // BT-16
invoice.ActualDeliveryDate = new DateTime(2025, 10, 1);        // BT-72
```

For the reference to the corrected invoice there is also a specialised element,
`ram:InvoiceReferencedDocument` (BT-25/BT-26). The FeRD reference does not use it here.

## 5. Ship-to party and invoicee

```csharp
invoice.ShipTo = new Party()
{
    GlobalID = new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4304171088093"),
    Name     = "MUSTER-MARKT",
    Postcode = "54321",
    Street   = "HAUPTSTRASSE 44",
    City     = "LIEFERSTADT",
    Country  = CountryCodes.DE
};

// ram:DefinedTradeContact/ram:DepartmentName – OrgUnit is exactly that field.
invoice.ShipToContact = new Contact() { OrgUnit = "8211" };

// BG-X-36, EXTENDED only
invoice.Invoicee = new Party()
{
    ID       = new GlobalID(null, "009420"),
    GlobalID = new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4304171000002"),
    Name     = "MUSTER-KUNDE GMBH",
    Postcode = "123456",
    Street   = "KUNDENWEG 88",
    City     = "KUNDENDORF",
    Country  = CountryCodes.DE
};
```

## 6. Invoice lines

Five bottles and two packs go back. The unit prices stay positive, the quantities turn
negative. The item discounts from the original invoice (BT-147) stay **positive** as well
– they are part of the price, not an amount on the invoice: 1.50 − 0.03 − 0.02 = 1.45.

```csharp
// −5 × 1.00 = −5.00, 19 %
TradeLineItem line1 = invoice.AddTradeLineItem(
    lineID: "1",
    name: "Zitronensäure 100ml",
    netUnitPrice: 1.00m,          // positive!
    grossUnitPrice: 1.00m,        // positive!
    unitCode: QuantityCodes.H87,
    billedQuantity: -5m,          // negative!
    lineTotalAmount: -5.00m,
    taxType: TaxTypes.VAT,
    categoryCode: TaxCategoryCodes.S,
    taxPercent: 19m,
    sellerAssignedID: "ZS997",
    id: new GlobalID(GlobalIDSchemeIdentifiers.EAN, "4123456000014"));

line1.PackageQuantity = 1m;
line1.PackageUnitCode = QuantityCodes.XBO;   // XBO = bottle

// −2 × 1.45 = −2.90, 7 %
TradeLineItem line2 = invoice.AddTradeLineItem(
    lineID: "2",
    name: "Gelierzucker Extra 250g",
    netUnitPrice: 1.45m,
    grossUnitPrice: 1.50m,
    unitCode: QuantityCodes.H87,
    billedQuantity: -2m,
    lineTotalAmount: -2.90m,
    taxType: TaxTypes.VAT,
    categoryCode: TaxCategoryCodes.S,
    taxPercent: 7m,
    sellerAssignedID: "GZ250",
    id: new GlobalID(GlobalIDSchemeIdentifiers.EAN, "4123456000021"));

line2.AddTradeAllowance(CurrencyCodes.EUR, basisAmount: null, actualAmount: 0.03m, reason: "Artikelrabatt 1");
line2.AddTradeAllowance(CurrencyCodes.EUR, basisAmount: null, actualAmount: 0.02m, reason: "Artikelrabatt 2");

line2.PackageQuantity = 1m;
line2.PackageUnitCode = QuantityCodes.XCT;   // XCT = carton
```

## 7. Document-level invoice discounts

A discount on a reversal is a reclaim: both the basis amount and the amount are negative.
As in any invoice with mixed tax rates, each discount needs its own entry per rate – two
discounts become four calls.

```csharp
// Invoice discount 1 – percentage based, 2 % (BT-94 CalculationPercent + BT-93 BasisAmount).
invoice.AddTradeAllowance(
    basisAmount: -5.00m, currency: CurrencyCodes.EUR, actualAmount: -0.10m,
    chargePercentage: 2.00m, reason: "Rechnungsrabatt 1",
    taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 19m);

invoice.AddTradeAllowance(
    basisAmount: -2.90m, currency: CurrencyCodes.EUR, actualAmount: -0.06m,
    chargePercentage: 2.00m, reason: "Rechnungsrabatt 1",
    taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 7m);

// Invoice discount 2 – a fixed amount, therefore without chargePercentage.
invoice.AddTradeAllowance(
    basisAmount: -5.00m, currency: CurrencyCodes.EUR, actualAmount: -0.05m,
    reason: "Rechnungsrabatt 2",
    taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 19m);

invoice.AddTradeAllowance(
    basisAmount: -2.90m, currency: CurrencyCodes.EUR, actualAmount: -0.02m,
    reason: "Rechnungsrabatt 2",
    taxTypeCode: TaxTypes.VAT, taxCategoryCode: TaxCategoryCodes.S, taxPercent: 7m);
```

## 8. VAT breakdown

A *negative* discount raises the basis amount again, which is why
`allowanceChargeBasisAmount` is positive here.

| Field | 19 % (line 1) | 7 % (line 2) |
|---|---|---|
| `lineTotalBasisAmount` | −5.00 | −2.90 |
| `allowanceChargeBasisAmount` | −(−0.10) − (−0.05) = **+0.15** | −(−0.06) − (−0.02) = **+0.08** |
| `basisAmount` | −5.00 + 0.15 = **−4.85** | −2.90 + 0.08 = **−2.82** |
| `taxAmount` | −4.85 × 19 % = −0.9215 → **−0.92** | −2.82 × 7 % = −0.1974 → **−0.20** |

```csharp
invoice.AddApplicableTradeTax(
    basisAmount: -4.85m, percent: 19m, taxAmount: -0.92m,
    typeCode: TaxTypes.VAT, categoryCode: TaxCategoryCodes.S,
    allowanceChargeBasisAmount: 0.15m,   // positive, because the discounts are negative
    lineTotalBasisAmount: -5.00m);

invoice.AddApplicableTradeTax(
    basisAmount: -2.82m, percent: 7m, taxAmount: -0.20m,
    typeCode: TaxTypes.VAT, categoryCode: TaxCategoryCodes.S,
    allowanceChargeBasisAmount: 0.08m,
    lineTotalBasisAmount: -2.90m);
```

## 9. Document totals

| BT code | Parameter | Calculation |
|---|---|---|
| BT-106 | `lineTotalAmount` | −5.00 + (−2.90) = **−7.90** |
| BT-107 | `allowanceTotalAmount` | −0.10 − 0.06 − 0.05 − 0.02 = **−0.23** |
| BT-109 | `taxBasisAmount` | −7.90 − (−0.23) = **−7.67** |
| BT-110 | `taxTotalAmount` | −0.92 + (−0.20) = **−1.12** |
| BT-112 | `grandTotalAmount` | −7.67 + (−1.12) = **−8.79** |
| BT-115 | `duePayableAmount` | **−8.79** – the amount goes back to the customer |

```csharp
invoice.SetTotals(
    lineTotalAmount: -7.90m,       // BT-106
    chargeTotalAmount: 0.00m,      // BT-108
    allowanceTotalAmount: -0.23m,  // BT-107
    taxBasisAmount: -7.67m,        // BT-109
    taxTotalAmount: -1.12m,        // BT-110
    grandTotalAmount: -8.79m,      // BT-112
    totalPrepaidAmount: 0.00m,     // BT-113
    duePayableAmount: -8.79m);     // BT-115
```

## 10. Saving and checking

```csharp
invoice.Save("X14_01_Rechnungskorrektur.xml",
             ZUGFeRDVersion.Version25,
             Profile.Extended,
             ZUGFeRDFormats.CII);
```

The result has to have the same tree structure as `X14_01_Rechnungskorrektur.xml` from
the FeRD sample package. The validator and the visualizer, and the detailed documentation
for them, live in the customer area at <https://www.factoorsharp.de/support/>.

## Related pages

- [Extended goods invoice](https://www.factoorsharp.de/en/Service/GoodsInvoice.md): six line items, two tax rates, discounts and an early payment discount in EXTENDED.
- [Foreign currency invoice](https://www.factoorsharp.de/en/Service/ForeignCurrencyInvoice.md): GBP with the tax amount also stated in EUR, including the exchange rate.
- [Getting started](https://www.factoorsharp.de/en/Home/GettingStarted.md): installation, license key and your first invoice.
- [Factur-X reference](https://www.factoorsharp.de/en/Service/Documentation): XML elements and BT/BG codes to look up.
