feat(core): initial release of SKR03/SKR04 German accounting standards implementation
- 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
This commit is contained in:
39
ts/skr.database.ts
Normal file
39
ts/skr.database.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user