Unify material supplier and balance controls

This commit is contained in:
Cauê Faleiros
2026-08-24 16:43:03 -03:00
parent 7e18772a8a
commit 11443a9202
5 changed files with 230 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ const {
deleteReceipt,
getSupplySummary,
listFabricPlans,
listKnownSuppliers,
saveMaterialDetails,
listLots,
listMovements,
@@ -27,6 +28,14 @@ router.get('/supply', verifyToken, async (req, res, next) => {
}
});
router.get('/supply/suppliers', verifyToken, async (req, res, next) => {
try {
res.json(await listKnownSuppliers());
} catch (error) {
next(error);
}
});
router.get('/supply/receipts', verifyToken, async (req, res, next) => {
try {
res.json(await listReceipts());

View File

@@ -158,6 +158,26 @@ const listMaterialDetails = async () => {
return result.rows.map(mapMaterialDetails);
};
const listKnownSuppliers = async () => {
const result = await pool.query(`
SELECT DISTINCT supplier
FROM (
SELECT preferred_supplier AS supplier FROM supply_material_details
UNION ALL
SELECT supplier FROM supply_lots
UNION ALL
SELECT supplier FROM supply_receipts
UNION ALL
SELECT supplier FROM supply_fabric_plans
UNION ALL
SELECT supplier FROM production_yield_supplier_recommendations
) sources
WHERE NULLIF(BTRIM(supplier), '') IS NOT NULL
ORDER BY supplier;
`);
return result.rows.map(row => row.supplier);
};
const saveMaterialDetails = async (materialKey, payload) => {
const normalizedKey = normalizeKey(materialKey);
if (!normalizedKey) throw createValidationError('Material inválido para edição.');
@@ -1062,6 +1082,7 @@ module.exports = {
buildPurchaseNeeds,
listFabricPlans,
listMaterialDetails,
listKnownSuppliers,
listLots,
listMovements,
listPurchaseNeeds,