2022-10-05 14:37:17 +00:00
|
|
|
import { getDefaultMetaFieldValueMap } from '../../backend/helpers';
|
|
|
|
import { DatabaseManager } from '../database/manager';
|
|
|
|
|
|
|
|
async function execute(dm: DatabaseManager) {
|
2023-01-31 09:12:54 +00:00
|
|
|
const s = (await dm.db?.getAll('SingleValue', {
|
|
|
|
fields: ['value'],
|
|
|
|
filters: { fieldname: 'setupComplete' },
|
|
|
|
})) as { value: string }[];
|
|
|
|
|
|
|
|
if (!Number(s?.[0]?.value ?? '0')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-14 08:30:11 +00:00
|
|
|
const names: Record<string, string> = {
|
|
|
|
StockMovement: 'SMOV-',
|
2023-01-31 09:12:54 +00:00
|
|
|
PurchaseReceipt: 'PREC-',
|
|
|
|
Shipment: 'SHPM-',
|
2022-11-14 08:30:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const referenceType in names) {
|
|
|
|
const name = names[referenceType];
|
|
|
|
await createNumberSeries(name, referenceType, dm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function createNumberSeries(
|
|
|
|
name: string,
|
|
|
|
referenceType: string,
|
|
|
|
dm: DatabaseManager
|
|
|
|
) {
|
|
|
|
const exists = await dm.db?.exists('NumberSeries', name);
|
2022-10-05 14:37:17 +00:00
|
|
|
if (exists) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-14 08:30:11 +00:00
|
|
|
await dm.db?.insert('NumberSeries', {
|
2022-10-05 14:37:17 +00:00
|
|
|
name,
|
|
|
|
start: 1001,
|
|
|
|
padZeros: 4,
|
|
|
|
current: 0,
|
2022-11-14 08:30:11 +00:00
|
|
|
referenceType,
|
2022-10-05 14:37:17 +00:00
|
|
|
...getDefaultMetaFieldValueMap(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default { execute, beforeMigrate: true };
|