Files
einvoice/ts/formats/semantic/bt-bg.model.ts
Juergen Kunz cbb297b0b1 feat: Implement PEPPOL and XRechnung validators for compliance with e-invoice specifications
- Added PeppolValidator class to validate PEPPOL BIS 3.0 invoices, including checks for endpoint IDs, document type IDs, process IDs, party identification, and business rules.
- Implemented validation for GLN check digits, document types, and transport protocols specific to PEPPOL.
- Added XRechnungValidator class to validate XRechnung 3.0 invoices, focusing on German-specific requirements such as Leitweg-ID, payment details, seller contact, and tax registration.
- Included validation for IBAN and BIC formats, ensuring compliance with SEPA regulations.
- Established methods for checking B2G invoice indicators and validating mandatory fields for both validators.
2025-08-11 18:07:01 +00:00

524 lines
15 KiB
TypeScript

/**
* EN16931 Canonical Semantic Model
* Defines all Business Terms (BT) and Business Groups (BG) from the standard
* This provides a format-agnostic representation of invoice data
*/
/**
* Business Term (BT) definitions from EN16931
* Each BT represents a specific data element in an invoice
*/
export interface BusinessTerms {
// Document level information (BT-1 to BT-22)
BT1_InvoiceNumber: string;
BT2_InvoiceIssueDate: Date;
BT3_InvoiceTypeCode: string;
BT4_InvoiceNote?: string;
BT5_InvoiceCurrencyCode: string;
BT6_VATAccountingCurrencyCode?: string;
BT7_ValueDateForVATCalculation?: Date;
BT8_InvoicePeriodDescriptionCode?: string;
BT9_DueDate?: Date;
BT10_BuyerReference?: string;
BT11_ProjectReference?: string;
BT12_ContractReference?: string;
BT13_PurchaseOrderReference?: string;
BT14_SalesOrderReference?: string;
BT15_ReceivingAdviceReference?: string;
BT16_DespatchAdviceReference?: string;
BT17_TenderOrLotReference?: string;
BT18_InvoicedObjectIdentifier?: string;
BT19_BuyerAccountingReference?: string;
BT20_PaymentTerms?: string;
BT21_InvoiceNote?: string[];
BT22_ProcessSpecificNote?: string;
// Seller information (BT-23 to BT-40)
BT23_BusinessProcessType?: string;
BT24_SpecificationIdentifier?: string;
BT25_InvoiceAttachment?: Attachment[];
BT26_InvoiceDocumentReference?: string;
BT27_SellerName: string;
BT28_SellerTradingName?: string;
BT29_SellerIdentifier?: string;
BT30_SellerLegalRegistrationIdentifier?: string;
BT31_SellerVATIdentifier?: string;
BT32_SellerTaxRegistrationIdentifier?: string;
BT33_SellerAdditionalLegalInfo?: string;
BT34_SellerElectronicAddress?: string;
BT35_SellerAddressLine1?: string;
BT36_SellerAddressLine2?: string;
BT37_SellerAddressLine3?: string;
BT38_SellerCity?: string;
BT39_SellerPostCode?: string;
BT40_SellerCountryCode: string;
// Seller contact (BT-41 to BT-43)
BT41_SellerContactPoint?: string;
BT42_SellerContactTelephoneNumber?: string;
BT43_SellerContactEmailAddress?: string;
// Buyer information (BT-44 to BT-58)
BT44_BuyerName: string;
BT45_BuyerTradingName?: string;
BT46_BuyerIdentifier?: string;
BT47_BuyerLegalRegistrationIdentifier?: string;
BT48_BuyerVATIdentifier?: string;
BT49_BuyerElectronicAddress?: string;
BT50_BuyerAddressLine1?: string;
BT51_BuyerAddressLine2?: string;
BT52_BuyerAddressLine3?: string;
BT53_BuyerCity?: string;
BT54_BuyerPostCode?: string;
BT55_BuyerCountryCode: string;
BT56_BuyerContactPoint?: string;
BT57_BuyerContactTelephoneNumber?: string;
BT58_BuyerContactEmailAddress?: string;
// Payee information (BT-59 to BT-62)
BT59_PayeeName?: string;
BT60_PayeeIdentifier?: string;
BT61_PayeeLegalRegistrationIdentifier?: string;
BT62_PayeeLegalRegistrationIdentifierSchemeID?: string;
// Tax representative (BT-62 to BT-69)
BT63_SellerTaxRepresentativeName?: string;
BT64_SellerTaxRepresentativeVATIdentifier?: string;
BT65_SellerTaxRepresentativeAddressLine1?: string;
BT66_SellerTaxRepresentativeAddressLine2?: string;
BT67_SellerTaxRepresentativeCity?: string;
BT68_SellerTaxRepresentativePostCode?: string;
BT69_SellerTaxRepresentativeCountryCode?: string;
// Delivery information (BT-70 to BT-80)
BT70_DeliveryName?: string;
BT71_DeliveryLocationIdentifier?: string;
BT72_ActualDeliveryDate?: Date;
BT73_InvoicingPeriodStartDate?: Date;
BT74_InvoicingPeriodEndDate?: Date;
BT75_DeliveryAddressLine1?: string;
BT76_DeliveryAddressLine2?: string;
BT77_DeliveryAddressLine3?: string;
BT78_DeliveryCity?: string;
BT79_DeliveryPostCode?: string;
BT80_DeliveryCountryCode?: string;
// Payment instructions (BT-81 to BT-91)
BT81_PaymentMeansTypeCode: string;
BT82_PaymentMeansText?: string;
BT83_RemittanceInformation?: string;
BT84_PaymentAccountIdentifier?: string;
BT85_PaymentAccountName?: string;
BT86_PaymentServiceProviderIdentifier?: string;
BT87_PaymentCardAccountPrimaryNumber?: string;
BT88_PaymentCardAccountHolderName?: string;
BT89_MandateReferenceIdentifier?: string;
BT90_BankAssignedCreditorIdentifier?: string;
BT91_DebitedAccountIdentifier?: string;
// Document level allowances (BT-92 to BT-96)
BT92_DocumentLevelAllowanceAmount?: number;
BT93_DocumentLevelAllowanceBaseAmount?: number;
BT94_DocumentLevelAllowancePercentage?: number;
BT95_DocumentLevelAllowanceVATCategoryCode?: string;
BT96_DocumentLevelAllowanceVATRate?: number;
BT97_DocumentLevelAllowanceReason?: string;
BT98_DocumentLevelAllowanceReasonCode?: string;
// Document level charges (BT-99 to BT-105)
BT99_DocumentLevelChargeAmount?: number;
BT100_DocumentLevelChargeBaseAmount?: number;
BT101_DocumentLevelChargePercentage?: number;
BT102_DocumentLevelChargeVATCategoryCode?: string;
BT103_DocumentLevelChargeVATRate?: number;
BT104_DocumentLevelChargeReason?: string;
BT105_DocumentLevelChargeReasonCode?: string;
// Document totals (BT-106 to BT-115)
BT106_SumOfInvoiceLineNetAmount: number;
BT107_SumOfAllowancesOnDocumentLevel?: number;
BT108_SumOfChargesOnDocumentLevel?: number;
BT109_InvoiceTotalAmountWithoutVAT: number;
BT110_InvoiceTotalVATAmount?: number;
BT111_InvoiceTotalVATAmountInAccountingCurrency?: number;
BT112_InvoiceTotalAmountWithVAT: number;
BT113_PaidAmount?: number;
BT114_RoundingAmount?: number;
BT115_AmountDueForPayment: number;
// VAT breakdown (BT-116 to BT-121)
BT116_VATCategoryTaxableAmount?: number;
BT117_VATCategoryTaxAmount?: number;
BT118_VATCategoryCode?: string;
BT119_VATCategoryRate?: number;
BT120_VATExemptionReasonText?: string;
BT121_VATExemptionReasonCode?: string;
// Additional document references (BT-122 to BT-125)
BT122_SupportingDocumentReference?: string;
BT123_SupportingDocumentDescription?: string;
BT124_ExternalDocumentLocation?: string;
BT125_AttachedDocumentEmbedded?: string;
// Line level information (BT-126 to BT-162)
BT126_InvoiceLineIdentifier?: string;
BT127_InvoiceLineNote?: string;
BT128_InvoiceLineObjectIdentifier?: string;
BT129_InvoicedQuantity?: number;
BT130_InvoicedQuantityUnitOfMeasureCode?: string;
BT131_InvoiceLineNetAmount?: number;
BT132_ReferencedPurchaseOrderLineReference?: string;
BT133_InvoiceLineBuyerAccountingReference?: string;
BT134_InvoiceLinePeriodStartDate?: Date;
BT135_InvoiceLinePeriodEndDate?: Date;
BT136_InvoiceLineAllowanceAmount?: number;
BT137_InvoiceLineAllowanceBaseAmount?: number;
BT138_InvoiceLineAllowancePercentage?: number;
BT139_InvoiceLineAllowanceReason?: string;
BT140_InvoiceLineAllowanceReasonCode?: string;
BT141_InvoiceLineChargeAmount?: number;
BT142_InvoiceLineChargeBaseAmount?: number;
BT143_InvoiceLineChargePercentage?: number;
BT144_InvoiceLineChargeReason?: string;
BT145_InvoiceLineChargeReasonCode?: string;
BT146_ItemNetPrice?: number;
BT147_ItemPriceDiscount?: number;
BT148_ItemGrossPrice?: number;
BT149_ItemPriceBaseQuantity?: number;
BT150_ItemPriceBaseQuantityUnitOfMeasureCode?: string;
BT151_ItemVATCategoryCode?: string;
BT152_ItemVATRate?: number;
BT153_ItemName?: string;
BT154_ItemDescription?: string;
BT155_ItemSellersIdentifier?: string;
BT156_ItemBuyersIdentifier?: string;
BT157_ItemStandardIdentifier?: string;
BT158_ItemClassificationIdentifier?: string;
BT159_ItemClassificationListIdentifier?: string;
BT160_ItemOriginCountryCode?: string;
BT161_ItemAttributeName?: string;
BT162_ItemAttributeValue?: string;
}
/**
* Business Groups (BG) from EN16931
* Groups related business terms together
*/
export interface BusinessGroups {
BG1_InvoiceNote?: InvoiceNote;
BG2_ProcessControl?: ProcessControl;
BG3_PrecedingInvoiceReference?: PrecedingInvoiceReference[];
BG4_Seller: Seller;
BG5_SellerPostalAddress: PostalAddress;
BG6_SellerContact?: Contact;
BG7_Buyer: Buyer;
BG8_BuyerPostalAddress: PostalAddress;
BG9_BuyerContact?: Contact;
BG10_Payee?: Payee;
BG11_SellerTaxRepresentative?: TaxRepresentative;
BG12_PayerParty?: PayerParty;
BG13_DeliveryInformation?: DeliveryInformation;
BG14_InvoicingPeriod?: Period;
BG15_DeliverToAddress?: PostalAddress;
BG16_PaymentInstructions: PaymentInstructions;
BG17_PaymentCardInformation?: PaymentCardInformation;
BG18_DirectDebit?: DirectDebit;
BG19_PaymentTerms?: PaymentTerms;
BG20_DocumentLevelAllowances?: Allowance[];
BG21_DocumentLevelCharges?: Charge[];
BG22_DocumentTotals: DocumentTotals;
BG23_VATBreakdown?: VATBreakdown[];
BG24_AdditionalSupportingDocuments?: SupportingDocument[];
BG25_InvoiceLine: InvoiceLine[];
BG26_InvoiceLinePeriod?: Period;
BG27_InvoiceLineAllowances?: Allowance[];
BG28_InvoiceLineCharges?: Charge[];
BG29_PriceDetails?: PriceDetails;
BG30_LineVATInformation: VATInformation;
BG31_ItemInformation: ItemInformation;
BG32_ItemAttributes?: ItemAttribute[];
}
/**
* Supporting types for Business Groups
*/
export interface InvoiceNote {
subjectCode?: string;
noteContent: string;
}
export interface ProcessControl {
businessProcessType?: string;
specificationIdentifier: string;
}
export interface PrecedingInvoiceReference {
referenceNumber: string;
issueDate?: Date;
}
export interface Seller {
name: string;
tradingName?: string;
identifier?: string;
legalRegistrationIdentifier?: string;
vatIdentifier?: string;
taxRegistrationIdentifier?: string;
additionalLegalInfo?: string;
electronicAddress?: string;
}
export interface Buyer {
name: string;
tradingName?: string;
identifier?: string;
legalRegistrationIdentifier?: string;
vatIdentifier?: string;
electronicAddress?: string;
}
export interface PostalAddress {
addressLine1?: string;
addressLine2?: string;
addressLine3?: string;
city?: string;
postCode?: string;
countrySubdivision?: string;
countryCode: string;
}
export interface Contact {
contactPoint?: string;
telephoneNumber?: string;
emailAddress?: string;
}
export interface Payee {
name: string;
identifier?: string;
legalRegistrationIdentifier?: string;
}
export interface TaxRepresentative {
name: string;
vatIdentifier: string;
postalAddress: PostalAddress;
}
export interface PayerParty {
name: string;
identifier?: string;
legalRegistrationIdentifier?: string;
}
export interface DeliveryInformation {
name?: string;
locationIdentifier?: string;
actualDeliveryDate?: Date;
deliveryAddress?: PostalAddress;
}
export interface Period {
startDate?: Date;
endDate?: Date;
descriptionCode?: string;
}
export interface PaymentInstructions {
paymentMeansTypeCode: string;
paymentMeansText?: string;
remittanceInformation?: string;
paymentAccountIdentifier?: string;
paymentAccountName?: string;
paymentServiceProviderIdentifier?: string;
}
export interface PaymentCardInformation {
primaryAccountNumber: string;
holderName?: string;
}
export interface DirectDebit {
mandateReferenceIdentifier?: string;
bankAssignedCreditorIdentifier?: string;
debitedAccountIdentifier?: string;
}
export interface PaymentTerms {
note?: string;
}
export interface Allowance {
amount: number;
baseAmount?: number;
percentage?: number;
vatCategoryCode?: string;
vatRate?: number;
reason?: string;
reasonCode?: string;
}
export interface Charge {
amount: number;
baseAmount?: number;
percentage?: number;
vatCategoryCode?: string;
vatRate?: number;
reason?: string;
reasonCode?: string;
}
export interface DocumentTotals {
lineExtensionAmount: number;
taxExclusiveAmount: number;
taxInclusiveAmount: number;
allowanceTotalAmount?: number;
chargeTotalAmount?: number;
prepaidAmount?: number;
roundingAmount?: number;
payableAmount: number;
}
export interface VATBreakdown {
vatCategoryTaxableAmount: number;
vatCategoryTaxAmount: number;
vatCategoryCode: string;
vatCategoryRate?: number;
vatExemptionReasonText?: string;
vatExemptionReasonCode?: string;
}
export interface SupportingDocument {
documentReference: string;
documentDescription?: string;
externalDocumentLocation?: string;
attachedDocument?: Attachment;
}
export interface Attachment {
filename?: string;
mimeType?: string;
description?: string;
embeddedDocumentBinaryObject?: string;
externalDocumentURI?: string;
}
export interface InvoiceLine {
identifier: string;
note?: string;
objectIdentifier?: string;
invoicedQuantity: number;
invoicedQuantityUnitOfMeasureCode: string;
lineExtensionAmount: number;
purchaseOrderLineReference?: string;
buyerAccountingReference?: string;
period?: Period;
allowances?: Allowance[];
charges?: Charge[];
priceDetails: PriceDetails;
vatInformation: VATInformation;
itemInformation: ItemInformation;
}
export interface PriceDetails {
itemNetPrice: number;
itemPriceDiscount?: number;
itemGrossPrice?: number;
itemPriceBaseQuantity?: number;
itemPriceBaseQuantityUnitOfMeasureCode?: string;
}
export interface VATInformation {
categoryCode: string;
rate?: number;
}
export interface ItemInformation {
name: string;
description?: string;
sellersIdentifier?: string;
buyersIdentifier?: string;
standardIdentifier?: string;
classificationIdentifier?: string;
classificationListIdentifier?: string;
originCountryCode?: string;
attributes?: ItemAttribute[];
}
export interface ItemAttribute {
name: string;
value: string;
}
/**
* Complete EN16931 Semantic Model
* Combines all Business Terms and Business Groups
*/
export interface EN16931SemanticModel {
// Core document information
documentInformation: {
invoiceNumber: string; // BT-1
issueDate: Date; // BT-2
typeCode: string; // BT-3
currencyCode: string; // BT-5
notes?: InvoiceNote[]; // BG-1
};
// Process metadata
processControl?: ProcessControl; // BG-2
// References
references?: {
buyerReference?: string; // BT-10
projectReference?: string; // BT-11
contractReference?: string; // BT-12
purchaseOrderReference?: string; // BT-13
salesOrderReference?: string; // BT-14
precedingInvoices?: PrecedingInvoiceReference[]; // BG-3
};
// Parties
seller: Seller & { // BG-4
postalAddress: PostalAddress; // BG-5
contact?: Contact; // BG-6
};
buyer: Buyer & { // BG-7
postalAddress: PostalAddress; // BG-8
contact?: Contact; // BG-9
};
payee?: Payee; // BG-10
taxRepresentative?: TaxRepresentative; // BG-11
// Delivery
delivery?: DeliveryInformation; // BG-13
invoicingPeriod?: Period; // BG-14
// Payment
paymentInstructions: PaymentInstructions; // BG-16
paymentCardInfo?: PaymentCardInformation; // BG-17
directDebit?: DirectDebit; // BG-18
paymentTerms?: PaymentTerms; // BG-19
// Allowances and charges
documentLevelAllowances?: Allowance[]; // BG-20
documentLevelCharges?: Charge[]; // BG-21
// Totals
documentTotals: DocumentTotals; // BG-22
vatBreakdown?: VATBreakdown[]; // BG-23
// Supporting documents
additionalDocuments?: SupportingDocument[]; // BG-24
// Invoice lines
invoiceLines: InvoiceLine[]; // BG-25
}
/**
* Semantic model version and metadata
*/
export const SEMANTIC_MODEL_VERSION = '1.3.0';
export const EN16931_VERSION = '1.3.14';
export const SUPPORTED_SYNTAXES = ['UBL', 'CII', 'EDIFACT'];