3328-item_search-panel #779

Merged
carlosjr merged 16 commits from 3328-item_search-panel into dev 2021-11-18 10:47:38 +00:00
7 changed files with 93 additions and 6 deletions
Showing only changes of commit 5c7efbb838 - Show all commits

View File

@ -1,9 +1,9 @@
DROP PROCEDURE IF EXISTS vn.item_getBalance; DROP PROCEDURE IF EXISTS `vn`.`item_getBalance`;
DELIMITER $$ DELIMITER $$
$$ $$
CREATE CREATE
definer = root@`%` procedure vn.item_getBalance(IN vItemId int, IN vWarehouse int) definer = root@`%` procedure `vn`.`item_getBalance`(IN vItemId int, IN vWarehouse int)
BEGIN BEGIN
DECLARE vDateInventory DATETIME; DECLARE vDateInventory DATETIME;
DECLARE vCurdate DATE DEFAULT CURDATE(); DECLARE vCurdate DATE DEFAULT CURDATE();

View File

@ -739,7 +739,7 @@ INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `warehouseFk`, `
(3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0), (3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0),
(4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1), (4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1),
(5, 'CON', 'Container', 3, 1, NULL, 35, 1), (5, 'CON', 'Container', 3, 1, NULL, 35, 1),
(6, 'ALS', 'Alstroemeria', 1, 1, 31, 35, 0); (6, 'ALS', 'Alstroemeria', 1, 1, 31, 16, 0);
INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`) INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`)
VALUES VALUES

View File

@ -0,0 +1,42 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.activeWorkers = async(query, filter) => {
let conn = Self.dataSource.connector;
if (filter.where && filter.where.and && Array.isArray(filter.where.and)) {
let where = {};
filter.where.and.forEach(element => {
where[Object.keys(element)[0]] = Object.values(element)[0];
});
filter.where = where;
}
let clientFilter = Object.assign({}, filter);
clientFilter.where = buildFilter(filter.where, (param, value) => {
switch (param) {
case 'role':
return {'r.name': value};
case 'firstName':
return {or: [
{'w.firstName': {like: `%${value}%`}},
{'w.lastName': {like: `%${value}%`}},
{'u.name': {like: `%${value}%`}},
{'u.nickname': {like: `%${value}%`}}
]};
case 'id':
return {'w.id': value};
}
});
let myFilter = {
where: {'u.active': true}
};
myFilter = mergeFilters(myFilter, clientFilter);
let stmt = new ParameterizedSQL(query);
stmt.merge(conn.makeSuffix(myFilter));
return conn.executeStmt(stmt);
};
};

View File

@ -0,0 +1,31 @@
module.exports = Self => {
Self.remoteMethod('activeWithBuyer', {
description: 'Returns active workers in itemType',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
description: 'Filter defining where and paginated data',
required: false
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/activeWithBuyer`,
verb: 'GET'
}
});
Self.activeWithBuyer = async filter => {
const query =
`SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname
FROM worker w
JOIN itemType i ON i.workerFk = w.id
JOIN account.user u ON u.id = w.id`;
return Self.activeWorkers(query, filter);
};
};

View File

@ -0,0 +1,14 @@
const models = require('vn-loopback/server/server').models;
describe('Worker activeWithBuyer', () => {
it('should return the buyers in itemType as result', async() => {
const filter = {};
const result = await models.Item.activeWithBuyer(filter);
const firstWorker = result[0];
const secondWorker = result[1];
expect(result.length).toEqual(2);
expect(firstWorker.nickname).toEqual('logisticBossNick');
expect(secondWorker.nickname).toEqual('buyerNick');
});
});

View File

@ -14,6 +14,8 @@ module.exports = Self => {
require('../methods/item/getWasteByWorker')(Self); require('../methods/item/getWasteByWorker')(Self);
require('../methods/item/getWasteByItem')(Self); require('../methods/item/getWasteByItem')(Self);
require('../methods/item/createIntrastat')(Self); require('../methods/item/createIntrastat')(Self);
require('../methods/item/active')(Self);
require('../methods/item/activeWithBuyer')(Self);
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'}); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});

View File

@ -41,12 +41,10 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
disabled="false" disabled="false"
ng-model="filter.salesPersonFk" url="Items/activeWithBuyer"
url="Workers/activeWithRole"
show-field="nickname" show-field="nickname"
search-function="{firstName: $search}" search-function="{firstName: $search}"
value-field="id" value-field="id"
where="{role: {inq: ['logistic', 'buyer']}}"
label="Buyer"> label="Buyer">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>