send sms from ticket descriptor & ticket line #991
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-03-29 07:29:09 +01:00
parent 2263da2e05
commit 8110325af8
17 changed files with 187 additions and 6 deletions

View File

@ -1 +0,0 @@
INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `user`, `password`, `title`) VALUES ('1', 'https://websms.xtratelecom.es/api_php/server.wsdl', 'FERRERTORIBIO', 'HERMANOS', 'Verdnatura');

View File

@ -34,3 +34,5 @@ import './sample/index';
import './sample/create'; import './sample/create';
import './web-payment'; import './web-payment';
import './log'; import './log';
import './sms';

View File

@ -0,0 +1,23 @@
<vn-dialog
vn-id="SMSDialog"
on-response="$ctrl.onResponse(response)">
<tpl-body>
<h5 pad-small-v translate>Send SMS</h5>
<vn-horizontal>
<vn-textfield vn-one
label="Recipient"
model="$ctrl.sms.recipient">
</vn-textfield>
</vn-horizontal>
<vn-horizontal >
<vn-textarea vn-one
label="Message"
field="$ctrl.sms.message">
</vn-textarea>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="CANCEL" translate-attr="{value: 'Cancel'}"/>
<button response="ACCEPT" translate>Send</button>
</tpl-buttons>
</vn-dialog>

View File

@ -0,0 +1,42 @@
import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
constructor($element, $scope, $http, $translate, vnApp) {
super($element, $scope);
this.$scope = $scope;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
}
open() {
this.$scope.SMSDialog.show();
}
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.vnApp.showMessage(this.$translate.instant('SMS sent!'));
if (res.data) this.emit('send', {response: res.data});
});
}
}
}
Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnClientSms', {
template: require('./index.html'),
controller: Controller,
bindings: {
sms: '<',
}
});

View File

@ -0,0 +1,34 @@
import './index';
describe('Client', () => {
describe('Component vnClientSms', () => {
let controller;
let $httpBackend;
let $element;
beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnClientSms', {$element});
controller.client = {id: 101};
}));
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'};
spyOn(controller.vnApp, 'showMessage');
$httpBackend.when('POST', `/client/api/Sms/send`, params).respond(200, params);
$httpBackend.expect('POST', `/client/api/Sms/send`, params).respond(params);
controller.onResponse('ACCEPT');
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
});
});
});
});

View File

@ -0,0 +1,4 @@
Send SMS: Enviar SMS
Recipient: Destinatario
Message: Mensaje
SMS sent!: ¡SMS enviado!

View File

@ -0,0 +1,7 @@
@import "variables";
vn-client-sms {
textarea {
height: 8em
}
}

View File

@ -7,6 +7,7 @@ class Controller {
this.filter = { this.filter = {
include: [ include: [
{relation: 'warehouse', scope: {fields: ['name']}}, {relation: 'warehouse', scope: {fields: ['name']}},
{relation: 'address'},
{relation: 'ship'}, {relation: 'ship'},
{relation: 'agencyMode', scope: {fields: ['name']}}, {relation: 'agencyMode', scope: {fields: ['name']}},
{relation: 'stowaway'}, {relation: 'stowaway'},

View File

@ -178,3 +178,7 @@
<button response="ACCEPT" translate>Save</button> <button response="ACCEPT" translate>Save</button>
</tpl-buttons> </tpl-buttons>
</vn-dialog> </vn-dialog>
<!-- SMS Dialog -->
<vn-client-sms vn-id="sms" sms="$ctrl.newSMS"></vn-client-sms>
<!-- SMS Dialog -->

View File

@ -13,7 +13,8 @@ class Controller {
{callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()}, {callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()},
{callback: this.showDeliveryNote, name: 'Show Delivery Note', show: true}, {callback: this.showDeliveryNote, name: 'Show Delivery Note', show: true},
{callback: this.showDeleteTicketDialog, name: 'Delete ticket', show: true}, {callback: this.showDeleteTicketDialog, name: 'Delete ticket', show: true},
{callback: this.showChangeShipped, name: 'Change shipped hour', show: true} {callback: this.showChangeShipped, name: 'Change shipped hour', show: true},
{callback: this.showSMSDialog, name: 'Send SMS', show: true}
]; ];
} }
@ -163,6 +164,15 @@ class Controller {
let url = `/api/report/rpt-delivery-note?ticketFk=${this.ticket.id}`; let url = `/api/report/rpt-delivery-note?ticketFk=${this.ticket.id}`;
window.open(url); window.open(url);
} }
showSMSDialog() {
const address = this.ticket.address;
this.newSMS = {
recipient: address.mobile || null,
message: this.$translate.instant('SMSPayment')
};
this.$scope.sms.open();
}
} }
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate']; Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];

View File

@ -0,0 +1,3 @@
SMSPayment: >-
Verdnatura communicates: Your order is pending of payment.
Please, enter the web page and make the payment with card. Thank you.

View File

@ -10,3 +10,6 @@ Are you sure you want to delete this stowaway?: ¿Estas seguro de que quieres bo
Show Delivery Note: Ver albarán Show Delivery Note: Ver albarán
Change shipped hour: Cambiar hora de envío Change shipped hour: Cambiar hora de envío
Shipped hour: Hora de envío Shipped hour: Hora de envío
SMSPayment: >-
Verdnatura le comunica: Su pedido está pendiente de pago.
Por favor, entre en la página web y efectue el pago con tarjeta. Muchas gracias.

View File

@ -285,6 +285,10 @@
</vn-horizontal> </vn-horizontal>
</div> </div>
</vn-popover> </vn-popover>
<!-- SMS Dialog -->
<vn-client-sms vn-id="sms" sms="$ctrl.newSMS"></vn-client-sms>
<!-- SMS Dialog -->
</vn-vertical> </vn-vertical>
<vn-confirm <vn-confirm
vn-id="delete-lines" vn-id="delete-lines"

View File

@ -15,7 +15,8 @@ class Controller {
{callback: this.markAsReserved, name: 'Mark as reserved'}, {callback: this.markAsReserved, name: 'Mark as reserved'},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'}, {callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
{callback: this.showEditDialog, name: 'Update discount'}, {callback: this.showEditDialog, name: 'Update discount'},
{callback: this.createClaim, name: 'Add claim'} {callback: this.createClaim, name: 'Add claim'},
{callback: this.showSMSDialog, name: 'Send SMS'}
]; ];
this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.imagesPath = '//verdnatura.es/vn-image-data/catalog';
@ -315,6 +316,26 @@ class Controller {
this.vnApp.showSuccess(this.$translate.instant('Order created')); this.vnApp.showSuccess(this.$translate.instant('Order created'));
}); });
} }
showSMSDialog() {
const address = this.ticket.address;
const lines = this.getCheckedLines();
const items = lines.map(line => {
const instance = this.sales[line.instance];
return `${instance.quantity} ${instance.concept}`;
});
const notAvailables = items.join(', ');
const params = {
ticketFk: this.ticket.id,
created: this.ticket.created,
notAvailables
};
this.newSMS = {
recipient: address.mobile || null,
message: this.$translate.instant('SMSAvailability', params)
};
this.$scope.sms.open();
}
} }
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];

View File

@ -11,16 +11,20 @@ describe('Ticket', () => {
id: 1, id: 1,
clientFk: 1, clientFk: 1,
shipped: 1, shipped: 1,
client: {salesPersonFk: 1} created: new Date(),
client: {salesPersonFk: 1},
address: {mobile: 111111111}
}; };
let sales = [ let sales = [
{ {
id: 1, id: 1,
concept: 'Item 1',
quantity: 5, quantity: 5,
price: 23.5, price: 23.5,
discount: 0 discount: 0
}, { }, {
id: 4, id: 4,
concept: 'Item 2',
quantity: 20, quantity: 20,
price: 5.5, price: 5.5,
discount: 0 discount: 0
@ -30,6 +34,7 @@ describe('Ticket', () => {
beforeEach(() => { beforeEach(() => {
ngModule('item'); ngModule('item');
ngModule('ticket'); ngModule('ticket');
ngModule('client');
}); });
beforeEach(angular.mock.inject(($compile, $rootScope, $state, _$httpBackend_) => { beforeEach(angular.mock.inject(($compile, $rootScope, $state, _$httpBackend_) => {
@ -166,5 +171,18 @@ describe('Ticket', () => {
$httpBackend.flush(); $httpBackend.flush();
}); });
}); });
describe('showSMSDialog()', () => {
it('should open an SMS dialog with specified data', () => {
spyOn(controller.$scope.sms, 'open');
controller.sales[1].checked = true;
controller.showSMSDialog();
expect(controller.$scope.sms.open).toHaveBeenCalledWith();
expect(controller.newSMS.recipient).toEqual(111111111);
expect(controller.newSMS.message).not.toEqual('');
});
});
}); });
}); });

View File

@ -0,0 +1,3 @@
SMSAvailability: >-
Verdnatura communicates: Your order {{ticketFk}} created on {{created | date: "dd/MM/yyyy"}}.
{{notAvailables}} not available. Sorry for the inconvenience.

View File

@ -28,3 +28,6 @@ Claim: Reclamación
Transfer lines: Transferir líneas Transfer lines: Transferir líneas
Change ticket state to 'Ok': Cambiar estado del ticket a 'Ok' Change ticket state to 'Ok': Cambiar estado del ticket a 'Ok'
Reserved: Reservado Reserved: Reservado
SMSAvailability: >-
Verdnatura le comunica: Pedido {{ticketFk}} día {{created | date: "dd/MM/yyyy"}}.
{{notAvailables}} no disponible/s. Disculpe las molestias.