diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 68865a2427..9dcef17de5 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -1,11 +1,17 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('receipts', { description: 'Find all clients matched by the filter', accessType: 'READ', accepts: [ { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { arg: 'supplierId', type: 'number', description: 'The supplier id', @@ -21,6 +27,12 @@ module.exports = Self => { description: 'The currency', default: 1, }, + { + arg: 'bankFk', + type: 'number', + description: 'The bank', + default: 1, + }, { arg: 'orderBy', type: 'string', @@ -50,7 +62,12 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'bankFk': + return {'bankFk': value}; + } + }); let stmts = []; stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ args.supplierId, @@ -63,6 +80,8 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * FROM tmp.supplierStatement`); + filter = mergeFilters(args.filter, {where}); + stmt.merge(conn.makeSuffix(filter)); stmts.push(stmt); stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`);