#7884 added new filter field #2981
|
@ -221,36 +221,29 @@ module.exports = Self => {
|
|||
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
||||
);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
jon marked this conversation as resolved
Outdated
|
||||
|
||||
const {daysAgo, daysOnward} = ctx.args;
|
||||
alexm
commented
Jo li diria a chatgpt si teu pot simplificar Jo li diria a chatgpt si teu pot simplificar
|
||||
|
||||
if (daysAgo || daysOnward) {
|
||||
let sql = '';
|
||||
if (daysOnward || daysAgo) {
|
||||
const params = [];
|
||||
let today = 'util.VN_CURDATE()';
|
||||
let from = today;
|
||||
let to = today;
|
||||
|
||||
if (daysAgo && daysOnward) {
|
||||
sql = `
|
||||
AND t.shipped >= util.VN_CURDATE() - INTERVAL ? DAY
|
||||
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
||||
`;
|
||||
params.push(daysAgo, daysOnward);
|
||||
} else if (daysAgo) {
|
||||
sql = `
|
||||
AND t.shipped >= util.VN_CURDATE() - INTERVAL ? DAY
|
||||
AND t.shipped < util.VN_CURDATE()
|
||||
`;
|
||||
if (daysAgo) {
|
||||
from += ' - INTERVAL ? DAY';
|
||||
params.push(daysAgo);
|
||||
} else if (daysOnward) {
|
||||
sql = `
|
||||
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
||||
AND t.shipped >= util.VN_CURDATE()
|
||||
`;
|
||||
}
|
||||
if (daysOnward) {
|
||||
to += ' + INTERVAL ? DAY';
|
||||
params.push(daysOnward);
|
||||
}
|
||||
|
||||
stmt.merge({sql, params});
|
||||
const whereDays = (filter.where ? 'AND' : 'WHERE') + ` t.shipped BETWEEN ${from} AND ${to}`;
|
||||
stmt.merge({sql: whereDays, params});
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
const itemsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
|
Loading…
Reference in New Issue
Revisar si estan los dos a la vez