diff --git a/adapter/procjustificationadapter.js b/adapter/procjustificationadapter.js index 50f42b1..8fa62e3 100644 --- a/adapter/procjustificationadapter.js +++ b/adapter/procjustificationadapter.js @@ -1067,6 +1067,48 @@ class ProcJustificationAdapter extends Adapter { } } + async queryUpdateProcJustificationBoq(req, callback) { + var apires = this.getApiResultDefined(); + try { + let nik = req.body.nik; + let vendors = JSON.parse(req.body.vendors); + + let boqList = []; + vendors.forEach(function (vendor) { + if (vendor.boq && vendor.boq.length > 0) { + vendor.boq.forEach(function (boq) { + boqList.push(boq); + }); + } + }); + + if (boqList.length === 0) { + apires.success = true; + apires.meta.message = "No BOQ to update"; + callback(null, apires); + return; + } + + let pending = boqList.length; + boqList.forEach(function (boq) { + let qry = "update tbl_procjustificationvendorboq "; + qry += "set items='" + boq.items + "',qty='" + boq.qty + "',unitprice='" + boq.unitprice + "',units='" + boq.units + "',total='" + boq.total + "',uby='" + nik + "',udt=now() "; + qry += "where _idx='" + boq._idx + "'"; + db.query(qry, [], function (err) { + if (--pending === 0) { + apires.success = true; + apires.meta.message = "BOQ Updated"; + callback(null, apires); + } + }); + }); + } catch (err) { + apires.meta.code = 500; + apires.meta.message = err.toString(); + callback("error", apires); + } + } + async queryUpdateStatusProcJustification(req, callback) { try { var apires = this.getApiResultDefined(); diff --git a/controllers/procjustification.js b/controllers/procjustification.js index cc689e2..3d7ec14 100644 --- a/controllers/procjustification.js +++ b/controllers/procjustification.js @@ -156,6 +156,21 @@ exports.procJustificationList = ( req, res ) => { } } +exports.updateProcJustificationBoq = ( req, res ) => { + try{ + procjustificationadapter.queryUpdateProcJustificationBoq(req, function(err, data) { + let statusCode = data != null ? data.meta.code : 200; + if(err) statusCode = 500; + procjustificationadapter.sendResponse(statusCode, data, res); + }); + } + catch(err){ + apireshandler.meta.code = 502; + apireshandler.meta.message = " [21] : ProcJustification controller, " + err.toString(); + procjustificationadapter.sendResponse(502, apireshandler, res); + } +} + exports.updateStatusProcJustification = ( req, res ) => { try{ diff --git a/routes/procjustification.js b/routes/procjustification.js index 3635d69..99942b5 100644 --- a/routes/procjustification.js +++ b/routes/procjustification.js @@ -15,5 +15,6 @@ router.get('/detailprocjustification',[jwtauth], procjustificationcontroller.det router.post('/procjustificationlist',[jwtauth], procjustificationcontroller.procJustificationList); router.post('/updatestatusprocjustification',[jwtauth], procjustificationcontroller.updateStatusProcJustification); router.post('/signprocjustification',[jwtauth], procjustificationcontroller.SignedProcJustification); +router.post('/updateprocjustificationboq',[jwtauth], procjustificationcontroller.updateProcJustificationBoq); module.exports = router; \ No newline at end of file