6220-addressFilter #1886

Merged
carlossa merged 13 commits from 6220-addressFilter into dev 2023-12-18 11:45:12 +00:00
1 changed files with 39 additions and 42 deletions
Showing only changes of commit 6cefc982e4 - Show all commits

View File

@ -107,17 +107,29 @@ module.exports = Self => {
return {or: [ return {or: [
{'c.phone': {like: `%${value}%`}}, {'c.phone': {like: `%${value}%`}},
{'c.mobile': {like: `%${value}%`}}, {'c.mobile': {like: `%${value}%`}},
{'a.phone': {like: `%${value}%`}},
]}; ]};
case 'zoneFk': case 'zoneFk':
param = 'a.postalCode'; return {'a.postalCode': {inq: postalCode}};
return {[param]: {inq: postalCode}}; case 'city':
return {or: [
{'c.city': {like: `%${value}`}},
{'a.city': {like: `%${value}`}}
]};
case 'postcode':
return {or: [
{'c.postcode': {like: `%${value}`}},
{'a.postalCode': {like: `%${value}`}}
]};
case 'provinceFk':
return {or: [
{'p.name': {like: `%${value}`}},
{'a.provinceFk': {like: `%${value}`}}
]};
case 'name': case 'name':
case 'salesPersonFk': case 'salesPersonFk':
case 'fi': case 'fi':
case 'socialName': case 'socialName':
case 'city':
case 'postcode':
case 'provinceFk':
case 'email': case 'email':
param = `c.${param}`; param = `c.${param}`;
return {[param]: {like: `%${value}%`}}; return {[param]: {like: `%${value}%`}};
@ -129,47 +141,32 @@ module.exports = Self => {
const stmts = []; const stmts = [];
const stmt = new ParameterizedSQL( const stmt = new ParameterizedSQL(
`SELECT `SELECT
DISTINCT c.id, DISTINCT c.id,
c.name, c.name,
c.fi, c.fi,
c.socialName, c.socialName,
c.phone, CONCAT(c.phone, ',',GROUP_CONCAT(DISTINCT a.phone)) phone,
c.mobile, c.mobile,
c.city, CONCAT(c.city, ',',GROUP_CONCAT(DISTINCT a.city)) city,
c.postcode, c.postcode,
c.email, a.postalCode,
c.isActive, c.email,
c.isFreezed, c.isActive,
p.id, c.isFreezed,
p.name, p.id AS provinceFk2,
Review

provinceClientFk

provinceClientFk
u.id, a.provinceFk,
Review

provinceAddressFk

provinceAddressFk
u.name, p.name AS province,
a.street, u.id AS salesPersonFk,
a.city, u.name AS salesPerson
a.provinceFk, FROM client c
a.postalCode, LEFT JOIN account.user u ON u.id = c.salesPersonFk
a.phone, LEFT JOIN province p ON p.id = c.provinceFk
a.mobile, JOIN address a ON a.clientFk = c.id
a.nickname,
a.isDefaultAddress,
a.agencyModeFk,
a.isActive,
a.longitude,
a.latitude,
a.isEqualizated,
a.customsAgentFk,
a.incotermsFk,
a.isLogifloraAllowed,
a.editorFk
FROM client c
LEFT JOIN account.user u ON u.id = c.salesPersonFk
LEFT JOIN province p ON p.id = c.provinceFk
JOIN vn.address a ON a.clientFk = c.id;
` `
); );
stmt.merge(conn.makeWhere(filter.where)); stmt.merge(conn.makeWhere(filter.where));
stmt.merge('GROUP BY c.id');
stmt.merge(conn.makePagination(filter)); stmt.merge(conn.makePagination(filter));
const clientsIndex = stmts.push(stmt) - 1; const clientsIndex = stmts.push(stmt) - 1;