feat: refs #7884 added filter when daysOnward and daysAgo have value and refactor ifs block
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jon Elias 2024-09-17 12:42:47 +02:00
parent 1d47690bb4
commit 71362baa66
1 changed files with 24 additions and 15 deletions

View File

@ -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));