@fin.cx/skr
Version:
SKR03 and SKR04 German accounting standards for double-entry bookkeeping
288 lines (287 loc) • 6.82 kB
TypeScript
import type { TSKRType } from './skr.types.js';
/**
* Invoice direction
*/
export type TInvoiceDirection = 'inbound' | 'outbound';
/**
* Supported e-invoice formats
*/
export type TInvoiceFormat = 'xrechnung' | 'zugferd' | 'facturx' | 'peppol' | 'ubl';
/**
* Invoice status in the system
*/
export type TInvoiceStatus = 'draft' | 'validated' | 'posted' | 'partially_paid' | 'paid' | 'cancelled' | 'error';
/**
* Tax scenario classification
*/
export type TTaxScenario = 'domestic_taxed' | 'domestic_exempt' | 'reverse_charge' | 'intra_eu_supply' | 'intra_eu_acquisition' | 'export' | 'small_business';
/**
* VAT rate categories
*/
export interface IVATCategory {
code: string;
rate: number;
exemptionReason?: string;
}
/**
* Party information (supplier/customer)
*/
export interface IInvoiceParty {
id: string;
name: string;
address: {
street?: string;
city?: string;
postalCode?: string;
countryCode: string;
};
vatId?: string;
taxId?: string;
email?: string;
phone?: string;
bankAccount?: {
iban: string;
bic?: string;
accountHolder?: string;
};
}
/**
* Invoice line item
*/
export interface IInvoiceLine {
lineNumber: number;
description: string;
quantity: number;
unitPrice: number;
netAmount: number;
vatCategory: IVATCategory;
vatAmount: number;
grossAmount: number;
accountNumber?: string;
costCenter?: string;
productCode?: string;
allowances?: IAllowanceCharge[];
charges?: IAllowanceCharge[];
}
/**
* Allowance or charge
*/
export interface IAllowanceCharge {
reason: string;
amount: number;
percentage?: number;
vatCategory?: IVATCategory;
vatAmount?: number;
}
/**
* Payment terms
*/
export interface IPaymentTerms {
dueDate: Date;
paymentTermsNote?: string;
skonto?: {
percentage: number;
days: number;
baseAmount: number;
}[];
}
/**
* Validation result
*/
export interface IValidationResult {
isValid: boolean;
syntax: {
valid: boolean;
errors: string[];
warnings: string[];
};
semantic: {
valid: boolean;
errors: string[];
warnings: string[];
};
businessRules: {
valid: boolean;
errors: string[];
warnings: string[];
};
countrySpecific?: {
valid: boolean;
errors: string[];
warnings: string[];
};
validatedAt: Date;
validatorVersion: string;
}
/**
* Booking information
*/
export interface IBookingInfo {
journalEntryId: string;
transactionIds: string[];
bookedAt: Date;
bookedBy: string;
bookingRules: {
vendorAccount?: string;
customerAccount?: string;
expenseAccounts?: string[];
revenueAccounts?: string[];
vatAccounts?: string[];
};
confidence: number;
autoBooked: boolean;
}
/**
* Payment information
*/
export interface IPaymentInfo {
paymentId: string;
paymentDate: Date;
amount: number;
currency: string;
bankTransactionId?: string;
endToEndId?: string;
remittanceInfo?: string;
skontoTaken?: number;
}
/**
* Main invoice entity
*/
export interface IInvoice {
id: string;
direction: TInvoiceDirection;
format: TInvoiceFormat;
invoiceNumber: string;
issueDate: Date;
invoiceTypeCode?: string;
currencyCode: string;
taxCurrencyCode?: string;
taxPointDate?: Date;
paymentDueDate?: Date;
buyerReference?: string;
projectReference?: string;
contractReference?: string;
orderReference?: string;
sellerOrderReference?: string;
supplier: IInvoiceParty;
customer: IInvoiceParty;
payee?: IInvoiceParty;
lines: IInvoiceLine[];
allowances?: IAllowanceCharge[];
charges?: IAllowanceCharge[];
lineNetAmount: number;
allowanceTotalAmount?: number;
chargeTotalAmount?: number;
taxExclusiveAmount: number;
taxInclusiveAmount: number;
prepaidAmount?: number;
payableAmount: number;
vatBreakdown: {
vatCategory: IVATCategory;
taxableAmount: number;
taxAmount: number;
}[];
totalVATAmount: number;
paymentTerms?: IPaymentTerms;
paymentMeans?: {
code: string;
account?: IInvoiceParty['bankAccount'];
};
payments?: IPaymentInfo[];
invoiceNote?: string;
status: TInvoiceStatus;
taxScenario?: TTaxScenario;
skrType?: TSKRType;
contentHash: string;
xmlContent?: string;
pdfHash?: string;
pdfContent?: Buffer;
validationResult?: IValidationResult;
bookingInfo?: IBookingInfo;
createdAt: Date;
createdBy: string;
modifiedAt?: Date;
modifiedBy?: string;
metadata?: {
importSource?: string;
importedAt?: Date;
parserVersion?: string;
originalFilename?: string;
originalFormat?: string;
[key: string]: any;
};
}
/**
* Invoice import options
*/
export interface IInvoiceImportOptions {
autoBook?: boolean;
confidenceThreshold?: number;
validateOnly?: boolean;
skipDuplicateCheck?: boolean;
bookingRules?: {
vendorDefaults?: Record<string, string>;
customerDefaults?: Record<string, string>;
productCategoryMapping?: Record<string, string>;
};
}
/**
* Invoice export options
*/
export interface IInvoiceExportOptions {
format: TInvoiceFormat;
embedInPdf?: boolean;
sign?: boolean;
validate?: boolean;
}
/**
* Invoice search filter
*/
export interface IInvoiceFilter {
direction?: TInvoiceDirection;
status?: TInvoiceStatus;
format?: TInvoiceFormat;
dateFrom?: Date;
dateTo?: Date;
supplierId?: string;
customerId?: string;
minAmount?: number;
maxAmount?: number;
invoiceNumber?: string;
reference?: string;
isPaid?: boolean;
isOverdue?: boolean;
}
/**
* Duplicate check result
*/
export interface IDuplicateCheckResult {
isDuplicate: boolean;
matchedInvoiceId?: string;
matchedContentHash?: string;
matchedFields?: string[];
confidence: number;
}
/**
* Booking rules configuration
*/
export interface IBookingRules {
skrType: TSKRType;
vendorControlAccount: string;
customerControlAccount: string;
vatAccounts: {
inputVAT19: string;
inputVAT7: string;
outputVAT19: string;
outputVAT7: string;
reverseChargeVAT: string;
};
defaultExpenseAccount: string;
defaultRevenueAccount: string;
productCategoryMapping?: Record<string, string>;
vendorMapping?: Record<string, string>;
customerMapping?: Record<string, string>;
skontoMethod?: 'net' | 'gross';
skontoExpenseAccount?: string;
skontoRevenueAccount?: string;
}