- Complete implementation of German standard charts of accounts - SKR03 (Process Structure Principle) for trading/service companies - SKR04 (Financial Classification Principle) for manufacturing companies - Double-entry bookkeeping with MongoDB persistence - Comprehensive reporting suite with DATEV export - Full TypeScript support and type safety
40 lines
938 B
TypeScript
40 lines
938 B
TypeScript
import * as plugins from './plugins.js';
|
|
import type { IDatabaseConfig } from './skr.types.js';
|
|
|
|
let dbInstance: plugins.smartdata.SmartdataDb | null = null;
|
|
|
|
export const getDb = async (
|
|
config?: IDatabaseConfig,
|
|
): Promise<plugins.smartdata.SmartdataDb> => {
|
|
if (!dbInstance) {
|
|
if (!config) {
|
|
throw new Error(
|
|
'Database configuration required for first initialization',
|
|
);
|
|
}
|
|
|
|
dbInstance = new plugins.smartdata.SmartdataDb({
|
|
mongoDbUrl: config.mongoDbUrl,
|
|
mongoDbName: config.dbName || 'skr_accounting',
|
|
});
|
|
|
|
await dbInstance.init();
|
|
}
|
|
|
|
return dbInstance;
|
|
};
|
|
|
|
export const getDbSync = (): plugins.smartdata.SmartdataDb => {
|
|
if (!dbInstance) {
|
|
throw new Error('Database not initialized. Call getDb() first.');
|
|
}
|
|
return dbInstance;
|
|
};
|
|
|
|
export const closeDb = async (): Promise<void> => {
|
|
if (dbInstance) {
|
|
await dbInstance.close();
|
|
dbInstance = null;
|
|
}
|
|
};
|