diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 60b58864b..35bf9677d 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -221,24 +221,33 @@ module.exports = Self => { JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (ctx.args.daysOnward) { - stmt.merge({ - sql: ` - AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY - AND t.shipped >= util.VN_CURDATE() - `, - params: [ctx.args.daysOnward] - }); - } + const {daysAgo, daysOnward} = ctx.args; - if (ctx.args.daysAgo) { - stmt.merge({ - sql: ` + if (daysAgo || daysOnward) { + let sql = ''; + const params = []; + + 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() - `, - params: [ctx.args.daysAgo] - }); + `; + params.push(daysAgo); + } else if (daysOnward) { + sql = ` + AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY + AND t.shipped >= util.VN_CURDATE() + `; + params.push(daysOnward); + } + + stmt.merge({sql, params}); } stmt.merge(conn.makeSuffix(filter));