feat(client_search-panel): add zone and province
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-05 15:21:20 +02:00
parent 43fcd0c473
commit ade5e9256d
6 changed files with 95 additions and 3 deletions

View File

@ -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;
};
};

View File

@ -30,6 +30,7 @@ module.exports = Self => {
require('../methods/client/consumption')(Self); require('../methods/client/consumption')(Self);
require('../methods/client/createReceipt')(Self); require('../methods/client/createReceipt')(Self);
require('../methods/client/updatePortfolio')(Self); require('../methods/client/updatePortfolio')(Self);
require('../methods/client/getPostCodeFromZone')(Self);
// Validations // Validations

View File

@ -2,7 +2,7 @@ import ngModule from '../module';
import ModuleMain from 'salix/components/module-main'; import ModuleMain from 'salix/components/module-main';
export default class Client extends ModuleMain { export default class Client extends ModuleMain {
exprBuilder(param, value) { async exprBuilder(param, value) {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
@ -15,6 +15,10 @@ export default class Client extends ModuleMain {
{mobile: value} {mobile: value}
] ]
}; };
case 'zoneFk':
await this.getPostCodesFromZone(value);
console.log(this.postCodeIds);
return {postcode: {inq: this.postCodeIds}};
case 'name': case 'name':
case 'socialName': case 'socialName':
case 'city': case 'city':
@ -23,10 +27,21 @@ export default class Client extends ModuleMain {
case 'id': case 'id':
case 'fi': case 'fi':
case 'postcode': case 'postcode':
case 'provinceFk':
case 'salesPersonFk': case 'salesPersonFk':
return {[param]: value}; 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', { ngModule.vnComponent('vnClient', {

View File

@ -50,6 +50,22 @@
ng-model="filter.postcode"> ng-model="filter.postcode">
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal>
<vn-autocomplete
ng-model="filter.provinceFk"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
<vn-autocomplete
ng-model="filter.zoneFk"
url="Zones"
show-field="name"
value-field="id"
label="Zone">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield
vn-one vn-one

View File

@ -26,5 +26,17 @@
"sons": { "sons": {
"type": "Number" "type": "Number"
} }
},
"relations": {
"zoneIncluded": {
"type": "hasMany",
"model": "Zone",
"foreignKey": "geoFk"
},
"postcode": {
"type": "hasMany",
"model": "PostCode",
"foreignKey": "geoFk"
}
} }
} }

View File

@ -48,6 +48,11 @@
"model": "AgencyMode", "model": "AgencyMode",
"foreignKey": "agencyModeFk" "foreignKey": "agencyModeFk"
}, },
"geo": {
"type": "belongsTo",
"model": "ZoneGeo",
"foreignKey": "geoFk"
},
"events": { "events": {
"type": "hasMany", "type": "hasMany",
"model": "ZoneEvent", "model": "ZoneEvent",
@ -67,6 +72,11 @@
"type": "hasMany", "type": "hasMany",
"model": "ZoneClosure", "model": "ZoneClosure",
"foreignKey": "zoneFk" "foreignKey": "zoneFk"
},
"provinces": {
"type": "hasMany",
"model": "Province",
"foreignKey": "zoneFk"
} }
} }
} }