Files
gps-backend/models/OrdersTerminsModels.js
2025-05-29 08:59:40 +00:00

121 lines
3.0 KiB
JavaScript
Executable File

// const db = require(`../config/dbMysqlConn`);
const MysqlHelpers = require(`../library/LibMysqlHelper`);
class OrdersTerminsModels {
static FLOW_TYPE_PAYMENT = 1;
static FLOW_TYPE_BILLING = 2;
static FLOW_TYPE_HYBRID = 3;
static TYPE_CASH_OUT = 1;
static TYPE_CASH_IN = 2;
static TYPE_CASH_HYBRID = 3;
static AMT_TYPE_FLAT = 1;
static AMT_TYPE_PERCENT = 2;
// 1=>refer termin_ddln_at, 2=>refer to order finish(pengantaran selesai)
static DDLN_TERMIN_TYPE_TIME = 1;
static DDLN_TERMIN_TYPE_ORD_FINISH = 2;
static IS_PAID_NO = 0;
static IS_PAID_YES = 1;
// 1=>transfer
static PAID_TYPE_TF = 1;
// 1=>admin, 2=>finance
static CRT_TYPE_SYSTEM = 0;
static CRT_TYPE_ADMIN = 1;
static CRT_TYPE_FINANCE = 2;
static IS_ACTIVE_NO = 0;
static IS_ACTIVE_YES = 1;
// 1=>client, 2=>vendor
static TERMIN_FOR_CLIENT = 1;
static TERMIN_FOR_VENDOR = 2;
// merge per trx
static STTS_MERGE_NO = 0;
static STTS_MERGE_TO = 1;
static STTS_MERGE_RESULT = 2;
static listWithFilter(filter = {}) {
return new Promise(async (resolve, reject) => {
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
if (filter['ord_id']) {
where += ' AND ord_termin.ord_id = ?';
params.push(filter['ord_id']);
} else if (filter['ord_code']) {
where += ' AND ord_code = ?';
params.push(filter['ord_code']);
}
if (filter['termin_for']) {
where += ' AND termin_for = ?';
params.push(filter['termin_for']);
}
if (filter['crt_type']) {
where += ' AND crt_type = ?';
params.push(filter['crt_type']);
}
if (filter['termin_is_paid']) {
where += ' AND termin_is_paid = ?';
params.push(filter['termin_is_paid']);
}
if (filter['in_stts_merge'] && filter['in_stts_merge'].length > 0) {
where += ' AND ord_termin.stts_merge IN (';
for (const in_stts_merge of filter['in_stts_merge']) {
where += '?,';
params.push(in_stts_merge);
}
where = where.slice(0, -1) + ')';
}
if (filter['group_by']) {
group_by = filter['group_by'];
}
if (filter['limit']) {
limit = ' LIMIT ' + filter['limit'];
}
let query = `SELECT
ord_termin.*
${select}
FROM t_orders_termins as ord_termin
${join}
WHERE ord_termin.dlt is null
${where}
${group_by}
${order_by}
${limit}
;`;
try {
const conn = await MysqlHelpers.createConnection();
const result = await MysqlHelpers.query(conn, query, params);
await MysqlHelpers.releaseConnection(conn);
resolve(result);
} catch (e) {
reject(e);
}
// db.query(query, params, function (err, resp) {
// if (err) {
// reject(err);
// return false;
// }
// resolve(resp);
// return true;
// });
});
}
}
module.exports = OrdersTerminsModels;