Files
einvoice/ts/interfaces/common.ts
Juergen Kunz 10e14af85b feat(validation): Implement EN16931 compliance validation types and VAT categories
- Added validation types for EN16931 compliance in `validation.types.ts`, including interfaces for `ValidationResult`, `ValidationOptions`, and `ValidationReport`.
- Introduced `VATCategoriesValidator` in `vat-categories.validator.ts` to validate VAT categories according to EN16931 rules, including detailed checks for standard, zero-rated, exempt, reverse charge, intra-community, export, and out-of-scope services.
- Enhanced `IEInvoiceMetadata` interface in `en16931-metadata.ts` to include additional fields required for full standards compliance, such as delivery information, payment information, allowances, and charges.
- Implemented helper methods for VAT calculations and validation logic to ensure accurate compliance with EN16931 standards.
2025-08-11 12:25:32 +00:00

91 lines
2.7 KiB
TypeScript

import { business, finance } from '../plugins.js';
/**
* Supported electronic invoice formats
*/
export enum InvoiceFormat {
UNKNOWN = 'unknown',
UBL = 'ubl', // Universal Business Language
CII = 'cii', // Cross-Industry Invoice
ZUGFERD = 'zugferd', // ZUGFeRD (German e-invoice format)
FACTURX = 'facturx', // Factur-X (French e-invoice format)
XRECHNUNG = 'xrechnung', // XRechnung (German e-invoice implementation of EN16931)
FATTURAPA = 'fatturapa' // FatturaPA (Italian e-invoice format)
}
/**
* Formats supported for export operations
* This is a subset of InvoiceFormat that only includes formats
* that can be generated and embedded in PDFs
*/
export type ExportFormat = 'facturx' | 'zugferd' | 'xrechnung' | 'ubl' | 'cii';
/**
* Describes a validation level for invoice validation
*/
export enum ValidationLevel {
SYNTAX = 'syntax', // Schema validation only
SEMANTIC = 'semantic', // Semantic validation (field types, required fields, etc.)
BUSINESS = 'business' // Business rule validation
}
/**
* Describes a validation error
*/
export interface ValidationError {
code: string; // Error code (e.g. "BR-16")
message: string; // Error message
location?: string; // XPath or location in the document
}
/**
* Result of a validation operation
*/
export interface ValidationResult {
valid: boolean; // Overall validation result
errors: ValidationError[]; // List of validation errors
warnings?: ValidationError[]; // List of validation warnings (optional)
level: ValidationLevel; // The level that was validated
}
/**
* Options for the EInvoice class
*/
export interface EInvoiceOptions {
validateOnLoad?: boolean; // Whether to validate when loading an invoice
validationLevel?: ValidationLevel; // Level of validation to perform
}
/**
* Interface for validator implementations
*/
export interface IValidator {
validate(level?: ValidationLevel): ValidationResult;
isValid(): boolean;
getValidationErrors(): ValidationError[];
}
/**
* PDF interface
*/
export interface IPdf {
name: string;
id: string;
metadata: {
textExtraction: string;
format?: string;
embeddedXml?: {
filename: string;
description: string;
};
};
buffer: Uint8Array;
}
// Re-export types from tsclass for convenience
export type { TInvoice } from '@tsclass/tsclass/dist_ts/finance/index.js';
export type { TCreditNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
export type { TDebitNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
export type { TContact } from '@tsclass/tsclass/dist_ts/business/index.js';
export type { TLetterEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';
export type { TDocumentEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';