Add material transformation planning
This commit is contained in:
@@ -559,6 +559,31 @@ const initDB = async () => {
|
||||
);
|
||||
`);
|
||||
|
||||
// A transformation is a planning/execution record, not a stock movement.
|
||||
// Physical stock remains controlled only by approved receipts and inventory
|
||||
// adjustments, so a planned dyeing run can never inflate availability.
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS supply_material_transformations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
batch_code VARCHAR(120),
|
||||
stage VARCHAR(40) NOT NULL,
|
||||
input_material TEXT NOT NULL,
|
||||
input_quantity_kg NUMERIC(14, 4) NOT NULL CHECK (input_quantity_kg > 0),
|
||||
output_material TEXT NOT NULL,
|
||||
output_color VARCHAR(120),
|
||||
expected_loss_percent NUMERIC(7, 4) NOT NULL DEFAULT 0 CHECK (expected_loss_percent >= 0 AND expected_loss_percent < 100),
|
||||
expected_output_kg NUMERIC(14, 4) NOT NULL CHECK (expected_output_kg >= 0),
|
||||
supplier TEXT,
|
||||
priority VARCHAR(40) NOT NULL DEFAULT 'Normal',
|
||||
status VARCHAR(30) NOT NULL DEFAULT 'planned',
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`);
|
||||
await pool.query(`CREATE INDEX IF NOT EXISTS idx_supply_material_transformations_status ON supply_material_transformations (status, created_at DESC);`);
|
||||
await pool.query(`CREATE INDEX IF NOT EXISTS idx_supply_material_transformations_batch ON supply_material_transformations (batch_code, created_at DESC);`);
|
||||
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS supply_purchase_orders (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
||||
Reference in New Issue
Block a user