From 90bbe1bd020a115bb21bda21fbb7b79ae7928e2d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Apr 2019 07:59:12 +0200 Subject: [PATCH 1/4] Log sent sms #1324 --- modules/client/back/methods/sms/send.js | 25 +++++++++++++----------- modules/client/back/models/sms.json | 6 +++++- modules/client/front/sms/index.html | 4 ++-- modules/client/front/sms/index.js | 6 +----- modules/client/front/sms/locale/es.yml | 2 +- modules/ticket/front/descriptor/index.js | 3 ++- modules/ticket/front/sale/index.js | 3 ++- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/modules/client/back/methods/sms/send.js b/modules/client/back/methods/sms/send.js index 539b6e546..d11b722f5 100644 --- a/modules/client/back/methods/sms/send.js +++ b/modules/client/back/methods/sms/send.js @@ -6,11 +6,11 @@ module.exports = Self => { Self.remoteMethodCtx('send', { description: 'Sends SMS to a destination phone', accepts: [{ - arg: 'recipientFk', + arg: 'destinationFk', type: 'Integer' }, { - arg: 'recipient', + arg: 'destination', type: 'String', required: true, }, @@ -20,7 +20,7 @@ module.exports = Self => { required: true, }], returns: { - type: 'boolean', + type: 'Object', root: true }, http: { @@ -29,7 +29,7 @@ module.exports = Self => { } }); - Self.send = async(ctx, recipientFk, recipient, message) => { + Self.send = async(ctx, destinationFk, destination, message) => { const userId = ctx.req.accessToken.userId; const smsConfig = await Self.app.models.SmsConfig.findOne(); const soapClient = await soap.createClientAsync(smsConfig.uri); @@ -37,7 +37,7 @@ module.exports = Self => { user: smsConfig.user, pass: smsConfig.password, src: smsConfig.title, - dst: recipient, + dst: destination, msg: message }; @@ -61,18 +61,21 @@ module.exports = Self => { console.error(e); } + const statusCode = status.codigo[0]; + const statusDescription = status.descripcion[0]; + const newSms = { senderFk: userId, - destinationFk: recipientFk || null, - destination: recipient, + destinationFk: destinationFk || null, + destination: destination, message: message, - statusCode: status.codigo, - status: status.descripcion + statusCode: statusCode, + status: statusDescription }; - const sms = Self.create(newSms); + const sms = await Self.create(newSms); - if (status.codigo != 200) + if (statusCode != 200) throw new UserError(`We weren't able to send this SMS`); return sms; diff --git a/modules/client/back/models/sms.json b/modules/client/back/models/sms.json index ec458e73d..aa9737478 100644 --- a/modules/client/back/models/sms.json +++ b/modules/client/back/models/sms.json @@ -1,7 +1,11 @@ { "name": "Sms", "description": "Sms sent to client", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ClientLog", + "relation": "recipient" + }, "options": { "mysql": { "table": "sms" diff --git a/modules/client/front/sms/index.html b/modules/client/front/sms/index.html index 30bf2dcc8..9d907e5c2 100644 --- a/modules/client/front/sms/index.html +++ b/modules/client/front/sms/index.html @@ -5,8 +5,8 @@
Send SMS
+ label="Destination" + model="$ctrl.sms.destination"> diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js index 03bafdec0..19d9ab3ea 100644 --- a/modules/client/front/sms/index.js +++ b/modules/client/front/sms/index.js @@ -18,11 +18,7 @@ class Controller extends Component { onResponse(response) { if (response === 'ACCEPT') { - let params = { - recipient: this.sms.recipient, - message: this.sms.message - }; - this.$http.post(`/client/api/Sms/send`, params).then(res => { + this.$http.post(`/client/api/Sms/send`, this.sms).then(res => { this.vnApp.showMessage(this.$translate.instant('SMS sent!')); if (res.data) this.emit('send', {response: res.data}); diff --git a/modules/client/front/sms/locale/es.yml b/modules/client/front/sms/locale/es.yml index 28933f774..10247b926 100644 --- a/modules/client/front/sms/locale/es.yml +++ b/modules/client/front/sms/locale/es.yml @@ -1,4 +1,4 @@ Send SMS: Enviar SMS -Recipient: Destinatario +Destination: Destinatario Message: Mensaje SMS sent!: ¡SMS enviado! \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index f61c94d23..1708a73d3 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -182,7 +182,8 @@ class Controller { showSMSDialog() { const address = this.ticket.address; this.newSMS = { - recipient: address.mobile || null, + destinationFk: this.ticket.clientFk, + destination: address.mobile || null, message: this.$translate.instant('SMSPayment') }; this.$scope.sms.open(); diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 492dd831c..16b668c4e 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -331,7 +331,8 @@ class Controller { notAvailables }; this.newSMS = { - recipient: address.mobile || null, + destinationFk: this.ticket.clientFk, + destination: address.mobile || null, message: this.$translate.instant('SMSAvailability', params) }; this.$scope.sms.open(); From 28bbc024b247dfbb19810155299dd3ca92b7971d Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 16 Apr 2019 08:09:16 +0200 Subject: [PATCH 2/4] #1195 claim.action regularize --- db/changes/10002-lent/00-greugesShipped.sql | 1 + modules/claim/front/action/index.html | 10 +++++-- modules/claim/front/action/index.js | 21 ++++++++++++++ modules/claim/front/action/index.spec.js | 32 +++++++++++++++++++++ modules/claim/front/action/locale/es.yml | 5 +++- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 db/changes/10002-lent/00-greugesShipped.sql diff --git a/db/changes/10002-lent/00-greugesShipped.sql b/db/changes/10002-lent/00-greugesShipped.sql new file mode 100644 index 000000000..25cb4df2f --- /dev/null +++ b/db/changes/10002-lent/00-greugesShipped.sql @@ -0,0 +1 @@ +ALTER TABLE `vn2008`.`Greuges` CHANGE COLUMN `Fecha` `Fecha` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ; \ No newline at end of file diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 7bace5a0e..44f9bb68c 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -30,7 +30,7 @@ vn-one label="Responsability" value="$ctrl.claim.responsibility" - max="5" + max="$ctrl.maxResponsibility" min="1" step="1" vn-acl="salesAssistant" @@ -191,4 +191,10 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index ec93f2ae1..0b12a54d0 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -23,6 +23,7 @@ class Controller { ] }; this.resolvedState = 3; + this.maxResponsibility = 5; } openAddSalesDialog() { @@ -135,9 +136,29 @@ class Controller { this.$http.post(query, data).then(() => { this.card.reload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2) + this.$.updateGreuge.show(); }); } + onUpdateGreugeResponse(response) { + if (response !== 'ACCEPT') + return; + let greugeTypeFreight = 7; + let query = `claim/api/Greuges/`; + let data = { + clientFk: this.claim.clientFk, + description: `claim: ${this.claim.id}`, + amount: 11, + greugeTypeFk: greugeTypeFreight, + ticketFk: this.claim.ticketFk + }; + + this.$http.post(query, data).then(() => { + this.card.reload(); + this.vnApp.showSuccess(this.$translate.instant('Greuge inserted!')); + }); + } // Item Descriptor showDescriptor(event, itemFk) { this.quicklinks = { diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 22f3f321b..9842bf646 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -158,5 +158,37 @@ describe('claim', () => { expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); + + describe('onUpdateGreugeResponse()', () => { + it('should do nothing', () => { + spyOn(controller.card, 'reload'); + spyOn(controller.vnApp, 'showSuccess'); + + controller.onUpdateGreugeResponse('CANCEL'); + + expect(controller.card.reload).not.toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!'); + }); + + it('should perform a insert into greuges', () => { + spyOn(controller.card, 'reload'); + spyOn(controller.vnApp, 'showSuccess'); + controller.claim.clientFk = 101; + controller.claim.id = 11; + let data = { + clientFk: 101, + description: `claim: ${controller.claim.id}`, + amount: 11, + greugeTypeFk: 7, + ticketFk: controller.claim.ticketFk + }; + $httpBackend.expect('POST', `claim/api/Greuges/`, data).respond(); + controller.onUpdateGreugeResponse('ACCEPT'); + $httpBackend.flush(); + + expect(controller.card.reload).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!'); + }); + }); }); }); diff --git a/modules/claim/front/action/locale/es.yml b/modules/claim/front/action/locale/es.yml index 8112d3c89..3950ec06a 100644 --- a/modules/claim/front/action/locale/es.yml +++ b/modules/claim/front/action/locale/es.yml @@ -5,4 +5,7 @@ Import claim: Importar reclamacion Imports claim details: Importa detalles de la reclamacion Import ticket: Importar ticket Imports ticket lines: Importa las lineas de un ticket -Regularize: Regularizar \ No newline at end of file +Regularize: Regularizar +Do you want to insert greuges?: Desea insertar greuges? +Insert greuges on client card: Insertar greuges en la ficha del cliente +Greuge inserted: Greuge insertado \ No newline at end of file From eac9980ee3c1a2e227b377bc1291756530552f85 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Apr 2019 08:11:27 +0200 Subject: [PATCH 3/4] import db changes on master --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 65aae2300..4ccc54b46 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -131,6 +131,7 @@ pipeline { stage('Database') { when { anyOf { branch 'test' + branch 'master' }} steps { configFileProvider([ From 6573e61a7c8d63acd834155b883e9a1517dd4334 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Apr 2019 08:21:20 +0200 Subject: [PATCH 4/4] fixed karma tests --- modules/client/back/methods/sms/specs/send.spec.js | 2 +- modules/client/front/sms/index.spec.js | 4 ++-- modules/ticket/front/sale/index.spec.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/client/back/methods/sms/specs/send.spec.js b/modules/client/back/methods/sms/specs/send.spec.js index 0045b148a..475e9fc1c 100644 --- a/modules/client/back/methods/sms/specs/send.spec.js +++ b/modules/client/back/methods/sms/specs/send.spec.js @@ -8,7 +8,7 @@ const app = require('vn-loopback/server/server'); describe('sms send()', () => { it('should should return the expected message and status code', async() => { let ctx = {req: {accessToken: {userId: 1}}}; - let result = await app.models.Sms.send(ctx, null, 'Invalid', 'My SMS Body'); + let result = await app.models.Sms.send(ctx, 101, 'Invalid', 'My SMS Body'); expect(result.statusCode).toEqual(200); expect(result.status).toEqual('Envio en procesamiento'); diff --git a/modules/client/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js index e8f530025..a1f18c23f 100644 --- a/modules/client/front/sms/index.spec.js +++ b/modules/client/front/sms/index.spec.js @@ -17,8 +17,8 @@ describe('Client', () => { describe('onResponse()', () => { it('should perform a POST query and show a success snackbar', () => { - let params = {recipient: 111111111, message: 'My SMS'}; - controller.sms = {recipient: 111111111, message: 'My SMS'}; + let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; + controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; spyOn(controller.vnApp, 'showMessage'); $httpBackend.when('POST', `/client/api/Sms/send`, params).respond(200, params); diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 113e29c80..23bc4b809 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -180,7 +180,7 @@ describe('Ticket', () => { controller.showSMSDialog(); expect(controller.$scope.sms.open).toHaveBeenCalledWith(); - expect(controller.newSMS.recipient).toEqual(111111111); + expect(controller.newSMS.destination).toEqual(111111111); expect(controller.newSMS.message).not.toEqual(''); }); });