feat: implement dispensing module with transaction-safe stock management, FEFO allocation, and H1 compliance reporting
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
const { Client } = require('pg');
|
||||
const client = new Client('postgres://postgres:csh%402018@localhost:5432/ai_pharmacy');
|
||||
|
||||
client.connect().then(async () => {
|
||||
try {
|
||||
const res = await client.query('SELECT DISTINCT tenant_id FROM products WHERE tenant_id IS NOT NULL');
|
||||
const tenants = res.rows.map(r => r.tenant_id);
|
||||
if (!tenants.includes('act_admin')) tenants.push('act_admin');
|
||||
|
||||
// Expiry date 2 years from now
|
||||
const expiry = new Date(Date.now() + 2 * 365 * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
|
||||
|
||||
for (const t of tenants) {
|
||||
const batchNo = 'B_FIX_' + t.substring(0,8) + '_' + Date.now();
|
||||
await client.query(`
|
||||
INSERT INTO batches (batch_no, product_id, expiry, qty_on_hand, purchase_price, tenant_id)
|
||||
VALUES ($1, 'prd_4410', $2, 1000, 50.00, $3)
|
||||
`, [batchNo, expiry, t]);
|
||||
console.log(`Added stock for tenant ${t}`);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error adding stock:', err);
|
||||
}
|
||||
process.exit(0);
|
||||
}).catch(console.error);
|
||||
Reference in New Issue
Block a user