// const db = require(`../config/dbMysqlConn`); const MysqlHelpers = require(`../library/LibMysqlHelper`); class OrdersPckDropsModels { // t_orders_pck_drop static STTS_DELIVERY_OTW_PICKUP = 1; static STTS_DELIVERY_ARRIVED_PICKUP = 2; static STTS_DELIVERY_PROCESS_PICKUP = 3; static STTS_DELIVERY_FINISH_PICKUP = 4; static STTS_DELIVERY_TRAVEL_DOC = 5; static STTS_DELIVERY_OTW_DROP = 6; static STTS_DELIVERY_ARRIVED_DROP = 7; static STTS_DELIVERY_PROCESS_DROP = 8; static STTS_DELIVERY_FINISH_DROP = 9; static STTS_DELIVERY_HANDOVER_DOC = 10; static IS_APRV_NO = 0; static IS_APRV_YES = 1; static listOrdPckDrop(filter = {}) { return new Promise(async (resolve, reject) => { let params = [], select = '', where = '', join = '', order_by = '', group_by = ''; if (filter['ord_pck_drop_id']) { where += ' AND ord_pck_drop.id = ?'; params.push(filter['ord_pck_drop_id']); } if (filter['ord_id']) { where += ' AND ord_pck_drop.ord_id = ?'; params.push(filter['ord_id']); } if (filter['pck_id']) { where += ' AND ord_pck_drop.pck_id = ?'; params.push(filter['pck_id']); } if (filter['drop_id']) { where += ' AND ord_pck_drop.drop_id = ?'; params.push(filter['drop_id']); } if (filter['stts'] && filter['stts'].length > 0) { where += ' AND ord_pck_drop.stts IN ('; for (const stts of filter['stts']) { where += '?,'; params.push(stts); } where = where.slice(0, -1) + ')'; } if (filter['not_stts'] && filter['not_stts'].length > 0) { where += ' AND ord_pck_drop.stts NOT IN ('; for (const stts of filter['not_stts']) { where += '?,'; params.push(stts); } where = where.slice(0, -1) + ')'; } if (filter['group_by']) { group_by = filter['group_by']; } if (filter['order_by']) { order_by = filter['order_by']; } let query = `SELECT ord_pck_drop.* ${select} FROM t_orders_pck_drop as ord_pck_drop ${join} WHERE ord_pck_drop.dlt is null ${where} ${group_by} ${order_by} ;`; try { const conn = await MysqlHelpers.createConnection(); const result = await MysqlHelpers.query(conn, query, params); await MysqlHelpers.releaseConnection(conn); resolve(result); } catch (e) { reject(e); } }); } } module.exports = OrdersPckDropsModels;