diff --git a/modules/client/back/methods/client/getPostCodeFromZone.js b/modules/client/back/methods/client/getPostCodeFromZone.js
new file mode 100644
index 000000000..79d8de357
--- /dev/null
+++ b/modules/client/back/methods/client/getPostCodeFromZone.js
@@ -0,0 +1,38 @@
+module.exports = Self => {
+ Self.remoteMethod('getPostCodeFromZone', {
+ description: 'CHANGEEEEEEEEEEEEEEE',
+ accessType: 'READ',
+ accepts: [{
+ arg: 'zoneId',
+ type: 'number',
+ required: true,
+ description: 'zone id'
+ }],
+ returns: {
+ type: 'number',
+ root: true
+ },
+ http: {
+ path: `/getPostCodeFromZone`,
+ verb: 'GET'
+ }
+ });
+
+ Self.getPostCodeFromZone = async(zoneId, options) => {
+ const myOptions = {};
+
+ if (typeof options == 'object')
+ Object.assign(myOptions, options);
+
+ const query = `
+ SELECT p.code
+ FROM postCode p
+ JOIN zoneIncluded z ON z.geoFk = p.geoFk
+ WHERE z.zoneFk = ?`;
+ const postCodes = await Self.rawSql(query, [zoneId], myOptions);
+ const postCodeIds = [];
+ postCodes.map(postCode => postCodeIds.push(postCode.code));
+ console.log(postCodeIds);
+ return postCodeIds;
+ };
+};
diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js
index 9ec45f58d..9785703d3 100644
--- a/modules/client/back/models/client.js
+++ b/modules/client/back/models/client.js
@@ -30,6 +30,7 @@ module.exports = Self => {
require('../methods/client/consumption')(Self);
require('../methods/client/createReceipt')(Self);
require('../methods/client/updatePortfolio')(Self);
+ require('../methods/client/getPostCodeFromZone')(Self);
// Validations
diff --git a/modules/client/front/main/index.js b/modules/client/front/main/index.js
index 61cde8b22..04f357261 100644
--- a/modules/client/front/main/index.js
+++ b/modules/client/front/main/index.js
@@ -2,7 +2,7 @@ import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
export default class Client extends ModuleMain {
- exprBuilder(param, value) {
+ async exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
@@ -15,6 +15,10 @@ export default class Client extends ModuleMain {
{mobile: value}
]
};
+ case 'zoneFk':
+ await this.getPostCodesFromZone(value);
+ console.log(this.postCodeIds);
+ return {postcode: {inq: this.postCodeIds}};
case 'name':
case 'socialName':
case 'city':
@@ -23,10 +27,21 @@ export default class Client extends ModuleMain {
case 'id':
case 'fi':
case 'postcode':
+ case 'provinceFk':
case 'salesPersonFk':
return {[param]: value};
}
}
+
+ async getPostCodesFromZone(zoneId) {
+ const params = {
+ zoneId: zoneId
+ };
+ this.$http.get('Clients/getPostCodeFromZone', {params})
+ .then(res => {
+ this.postCodeIds = res.data;
+ });
+ }
}
ngModule.vnComponent('vnClient', {
diff --git a/modules/client/front/search-panel/index.html b/modules/client/front/search-panel/index.html
index 9caf4185b..a02f93882 100644
--- a/modules/client/front/search-panel/index.html
+++ b/modules/client/front/search-panel/index.html
@@ -50,6 +50,22 @@
ng-model="filter.postcode">
+
+
+
+
+
+