diff --git a/adapter/procjustificationadapter.js b/adapter/procjustificationadapter.js index 4b59d52..2243c11 100644 --- a/adapter/procjustificationadapter.js +++ b/adapter/procjustificationadapter.js @@ -899,23 +899,71 @@ class ProcJustificationAdapter extends Adapter { }; // result[key]['ttd'] = JSON.parse(JSON.stringify(result3)); } - if (0 === --dataRows) { - let resultJson = JSON.stringify(result); - resultJson = JSON.parse(resultJson); - apires.success = true; - apires.data = resultJson; - callback(null, apires); - } + + /* ========================= + SHOW VENDORS + ========================= */ + qry = + "select * from tbl_procjustificationvendor where idxprocjustification='" + + _idx + + "' and isdeleted=0 order by numberoffile asc"; + + db.query(qry, [], function (err, vendors, fields) { + if (err) { + apires.meta["message"] = err.toString(); + apires.meta["code"] = 500; + callback("error", apires); + } else { + if (vendors.length > 0) { + let vendorRows = vendors.length; + + vendors.forEach(function (vendor, vkey) { + let qryBoq = + "select * from tbl_procjustificationvendorboq where idxprocjustificationvendor='" + + vendor._idx + + "' and isdeleted=0 order by _idx asc"; + + db.query(qryBoq, [], function (err, boq, fields) { + if (!err) { + vendors[vkey]["boq"] = JSON.parse(JSON.stringify(boq)); + } + + if (0 === --vendorRows) { + result[key]["vendor"] = JSON.parse(JSON.stringify(vendors)); + + if (0 === --dataRows) { + let resultJson = JSON.stringify(result); + resultJson = JSON.parse(resultJson); + apires.success = true; + apires.data = resultJson; + callback(null, apires); + } + } + }); + }); + } else { + result[key]["vendor"] = []; + + if (0 === --dataRows) { + let resultJson = JSON.stringify(result); + resultJson = JSON.parse(resultJson); + apires.success = true; + apires.data = resultJson; + callback(null, apires); + } + } + } + }); + + // if (0 === --dataRows) { + // let resultJson = JSON.stringify(result); + // resultJson = JSON.parse(resultJson); + // apires.success = true; + // apires.data = resultJson; + // callback(null, apires); + // } } }); - - // if(0 === --dataRows){ - // let resultJson = JSON.stringify(result); - // resultJson = JSON.parse(resultJson); - // apires.success = true; - // apires.data = resultJson; - // callback(null,apires); - // } } }); });