From b28a8a34dc6445e12d5c2f46fac6c78b31c5d520 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 11 Jul 2024 19:55:36 +0200 Subject: [PATCH] feat(salix): refs #7648 #7648 add new filter --- modules/entry/back/methods/entry/filter.js | 21 +++++++++++++++++-- .../back/methods/entry/specs/filter.spec.js | 10 ++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index f21d9dbc4..0981247ee 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -2,6 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; +const DEFAULT_INTERVAL_DAYS = 3; module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -95,6 +96,11 @@ module.exports = Self => { arg: 'to', type: 'date', description: `The to date filter` + }, + { + arg: 'days', + type: 'number', + description: `N days interval` } ], returns: { @@ -183,15 +189,26 @@ module.exports = Self => { t.landed, t.ref AS travelRef, t.warehouseInFk, - w.name warehouseInName + w.name warehouseInName, + util.VN_CURDATE() FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk - JOIN vn.currency cu ON cu.id = e.currencyFk` + JOIN vn.currency cu ON cu.id = e.currencyFk + ` ); + if (supplier) { + stmt.merge({ + sql: ` + AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY + AND t.shipped >= util.VN_CURDATE() + `, + params: Array(1).fill(ctx.args.days ?? DEFAULT_INTERVAL_DAYS) + }); + } stmt.merge(conn.makeSuffix(filter)); const itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index c8a5bd94f..d08400184 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(9); + expect(result.length).toEqual(14); await tx.rollback(); } catch (e) { @@ -61,7 +61,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -84,7 +84,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -107,7 +107,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(8); + expect(result.length).toEqual(13); await tx.rollback(); } catch (e) {