From fe2f12cd8f13c61b68cd3eab234f498dcfc4cf6c Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 22 Oct 2020 09:35:11 +0200 Subject: [PATCH] first test step --- db/changes/10250-octoberFest/00-supplier.sql | 2 + db/dump/fixtures.sql | 8 +-- modules/client/front/fiscal-data/index.js | 2 +- .../supplier/back/methods/supplier/filter.js | 7 ++- .../back/methods/supplier/getSummary.js | 2 +- .../back/methods/supplier/isAClient.js | 26 ++++++++ .../methods/supplier/specs/getSummary.spec.js | 28 +++++++++ modules/supplier/back/models/supplier.js | 1 + modules/supplier/front/descriptor/index.html | 45 +++++++++++++- modules/supplier/front/descriptor/index.js | 59 ++++++++++++++++++- modules/supplier/front/main/index.html | 2 +- .../supplier/front/search-panel/index.html | 2 +- modules/supplier/front/summary/index.html | 2 +- modules/supplier/front/summary/index.js | 18 ------ modules/supplier/front/summary/locale/es.yml | 0 15 files changed, 174 insertions(+), 30 deletions(-) create mode 100644 db/changes/10250-octoberFest/00-supplier.sql create mode 100644 modules/supplier/back/methods/supplier/isAClient.js create mode 100644 modules/supplier/back/methods/supplier/specs/getSummary.spec.js delete mode 100644 modules/supplier/front/summary/locale/es.yml diff --git a/db/changes/10250-octoberFest/00-supplier.sql b/db/changes/10250-octoberFest/00-supplier.sql new file mode 100644 index 000000000..7a5daa92f --- /dev/null +++ b/db/changes/10250-octoberFest/00-supplier.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`supplier` +ADD COLUMN `email` VARCHAR(45) NULL AFTER `isTrucker`; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0bee9cf65..e1881a12f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1208,11 +1208,11 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) (104, 500), (105, 5000); -INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `phone`, `payDay`) +INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `phone`, `payDay`, `email`) VALUES - (1, 'Plants SL', 'Plants nick', 4000000001, 1, 'A11111111', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 123456789, 15), - (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 987654321, 10), - (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 987123654, 15); + (1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 123456789, 15, 'supplier_one@gmail.es'), + (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 987654321, 10, 'supplier_two@gmail.es'), + (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 987123654, 15, 'supplier_three@gmail.es'); INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) VALUES diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 58b22537c..6fb88140c 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -35,7 +35,7 @@ export default class Controller extends Section { const $t = this.$translate.instant; const filter = encodeURIComponent(JSON.stringify(filterObj)); - const query = `Clients/findOne?filter=${filter}`; + const query = `Clients/find?filter=${filter}`; this.$http.get(query).then(res => { const params = {clientId: res.data.id}; const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); diff --git a/modules/supplier/back/methods/supplier/filter.js b/modules/supplier/back/methods/supplier/filter.js index 3eddda294..b1e7d3884 100644 --- a/modules/supplier/back/methods/supplier/filter.js +++ b/modules/supplier/back/methods/supplier/filter.js @@ -60,7 +60,12 @@ module.exports = Self => { let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': - return {'s.id': value}; + return {or: [ + {'s.id': value}, + {'s.name': {like: `%${value}%`}}, + {'s.nickname': {like: `%${value}%`}} + ]}; + // return {'s.id': value}; case 'nickname': param = `s.${param}`; return {[param]: {like: `%${value}%`}}; diff --git a/modules/supplier/back/methods/supplier/getSummary.js b/modules/supplier/back/methods/supplier/getSummary.js index fb1fa9f01..24a592acf 100644 --- a/modules/supplier/back/methods/supplier/getSummary.js +++ b/modules/supplier/back/methods/supplier/getSummary.js @@ -50,7 +50,7 @@ module.exports = Self => { { relation: 'country', scope: { - fields: ['id', 'name', 'code'] + fields: ['id', 'country', 'code'] } }, { diff --git a/modules/supplier/back/methods/supplier/isAClient.js b/modules/supplier/back/methods/supplier/isAClient.js new file mode 100644 index 000000000..ec3bfe3dc --- /dev/null +++ b/modules/supplier/back/methods/supplier/isAClient.js @@ -0,0 +1,26 @@ +module.exports = Self => { + Self.remoteMethod('isAClient', { + description: 'Returns the supplier summary', + accessType: 'READ', + accepts: { + arg: 'nif', + type: 'string', + required: true, + description: 'The supplier nif', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:nif/isAClient`, + verb: 'GET' + } + }); + Self.isAClient = async nif => { + const client = await Self.app.models.Client.findOne({where: {fi: nif}}); + console.log('client', client); + return client; + }; +}; diff --git a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js new file mode 100644 index 000000000..58a1e0854 --- /dev/null +++ b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js @@ -0,0 +1,28 @@ +const app = require('vn-loopback/server/server'); + +describe('Supplier getSummary()', () => { + // it('should return the supplier matching "search"', async() => { + // let ctx = { + // args: { + // search: 1 + // } + // }; + + // let result = await app.models.Supplier.filter(ctx); + + // expect(result.length).toEqual(1); + // expect(result[0].id).toEqual(1); + // }); + + // it('should return the supplier matching the province', async() => { + // let ctx = { + // args: { + // provinceFk: 1 + // } + // }; + + // let result = await app.models.Supplier.filter(ctx); + + // expect(result.length).toEqual(2); + // }); +}); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index d3c32b814..8d77d612b 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/supplier/filter')(Self); require('../methods/supplier/getSummary')(Self); + require('../methods/supplier/isAClient')(Self); }; diff --git a/modules/supplier/front/descriptor/index.html b/modules/supplier/front/descriptor/index.html index 1ab95b529..53d27ed91 100644 --- a/modules/supplier/front/descriptor/index.html +++ b/modules/supplier/front/descriptor/index.html @@ -8,7 +8,50 @@ - + + + + + + + + + + +
+ + + + +
+ diff --git a/modules/supplier/front/descriptor/index.js b/modules/supplier/front/descriptor/index.js index 676a15418..7d4ee750e 100644 --- a/modules/supplier/front/descriptor/index.js +++ b/modules/supplier/front/descriptor/index.js @@ -8,14 +8,71 @@ class Controller extends Descriptor { set supplier(value) { this.entity = value; + this.iSupplierAClient(); } + + get entryFilter() { + if (!this.supplier) return null; + + const date = new Date(); + date.setHours(0, 0, 0, 0); + + const from = new Date(date.getTime()); + from.setDate(from.getDate() - 10); + + const to = new Date(date.getTime()); + to.setDate(to.getDate() + 10); + + return JSON.stringify({ + supplierFk: this.supplier.id, + from, + to + }); + } + iSupplierAClient() { + if (!this.supplier) return; + + const filter = { + where: {fi: this.supplier.nif} + }; + this.$http.get('Clients/findOne', {filter}).then(res => { + if (res.data) + this.isAClient = res.data; + }).catch(error => { + return this.isAClient = false; + }); + // this.$http.get(`Suppliers/${this.supplier.nif}/isAClient`).then(res => { + // this.isAClient = res.data; + // }); + } + loadData() { const filter = { fields: [ 'id', 'name', 'nickname', - 'nif' + 'nif', + 'payMethodFk', + 'payDemFk', + 'payDay', + 'isActive', + 'isOfficial', + 'account' + ], + include: [ + { + relation: 'payMethod', + scope: { + fields: ['id', 'name'] + } + }, + { + relation: 'payDem', + scope: { + fields: ['id', 'payDem'] + } + } ] }; diff --git a/modules/supplier/front/main/index.html b/modules/supplier/front/main/index.html index 2278087c2..5df346690 100644 --- a/modules/supplier/front/main/index.html +++ b/modules/supplier/front/main/index.html @@ -8,7 +8,7 @@ diff --git a/modules/supplier/front/search-panel/index.html b/modules/supplier/front/search-panel/index.html index 5ad5e6e3a..f5b3962e0 100644 --- a/modules/supplier/front/search-panel/index.html +++ b/modules/supplier/front/search-panel/index.html @@ -5,7 +5,7 @@ vn-one label="General search" ng-model="filter.search" - info="Search suppliers by id" + info="Search suppliers by id name or alias" vn-focus> diff --git a/modules/supplier/front/summary/index.html b/modules/supplier/front/summary/index.html index a05470cea..0df489bfb 100644 --- a/modules/supplier/front/summary/index.html +++ b/modules/supplier/front/summary/index.html @@ -38,7 +38,7 @@ value="{{$ctrl.summary.city}}"> + value="{{$ctrl.summary.postCode}}"> diff --git a/modules/supplier/front/summary/index.js b/modules/supplier/front/summary/index.js index f201127da..0cbe70785 100644 --- a/modules/supplier/front/summary/index.js +++ b/modules/supplier/front/summary/index.js @@ -15,24 +15,6 @@ class Controller extends Section { this.summary = response.data; }); } - - // sumRisk() { - // let total = 0; - // this.summary.clientRisks.forEach(risk => { - // total += risk.amount; - // }); - // return total; - // } - - // claimRate(priceIncreasing) { - // if (priceIncreasing) - // return priceIncreasing * 100; - // } - - // claimingRate(rate) { - // if (rate) - // return rate * 100; - // } } ngModule.vnComponent('vnSupplierSummary', { diff --git a/modules/supplier/front/summary/locale/es.yml b/modules/supplier/front/summary/locale/es.yml deleted file mode 100644 index e69de29bb..000000000