Commit d813bbe7a988244da2d507414b3abb52b93e43bd

Authored by Benjamin Rodriguez
1 parent 35d2a78d2a
Exists in develop

agrego descarga de remito sin valores

src/js/controller.js
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .controller('focaModalConfirmController', [ 2 .controller('focaModalConfirmController', [
3 '$uibModalInstance', '$scope', 'textoModal', 3 '$uibModalInstance', '$scope', 'textoModal',
4 function($uibModalInstance, $scope, textoModal) { 4 function($uibModalInstance, $scope, textoModal) {
5 $scope.textoModal = textoModal; 5 $scope.textoModal = textoModal;
6 $scope.cancelar = function() { 6 $scope.cancelar = function() {
7 $uibModalInstance.dismiss(false); 7 $uibModalInstance.dismiss(false);
8 }; 8 };
9 $scope.aceptar = function() { 9 $scope.aceptar = function() {
10 $uibModalInstance.close(true); 10 $uibModalInstance.close(true);
11 }; 11 };
12 } 12 }
13 ]) 13 ])
14 .controller('focaModalInfoController', [ 14 .controller('focaModalInfoController', [
15 '$uibModalInstance', '$scope', 'textoModal', 15 '$uibModalInstance', '$scope', 'textoModal',
16 function($uibModalInstance, $scope, textoModal) { 16 function($uibModalInstance, $scope, textoModal) {
17 $scope.textoModal = textoModal; 17 $scope.textoModal = textoModal;
18 $scope.aceptar = function() { 18 $scope.aceptar = function() {
19 $uibModalInstance.close(true); 19 $uibModalInstance.close(true);
20 }; 20 };
21 } 21 }
22 ]) 22 ])
23 .controller('focaModalAlertController', [ 23 .controller('focaModalAlertController', [
24 '$uibModalInstance', '$scope', 'textoModal', 24 '$uibModalInstance', '$scope', 'textoModal',
25 function($uibModalInstance, $scope, textoModal) { 25 function($uibModalInstance, $scope, textoModal) {
26 $scope.textoModal = textoModal; 26 $scope.textoModal = textoModal;
27 $scope.aceptar = function() { 27 $scope.aceptar = function() {
28 $uibModalInstance.close(true); 28 $uibModalInstance.close(true);
29 }; 29 };
30 } 30 }
31 ]) 31 ])
32 .controller('focaModalFechaController', [ 32 .controller('focaModalFechaController', [
33 '$uibModalInstance', '$scope', 'parametros', 33 '$uibModalInstance', '$scope', 'parametros',
34 function($uibModalInstance, $scope, parametros) { 34 function($uibModalInstance, $scope, parametros) {
35 $scope.parametros = parametros; 35 $scope.parametros = parametros;
36 $scope.fecha = new Date(); 36 $scope.fecha = new Date();
37 $scope.options = {}; 37 $scope.options = {};
38 38
39 if (parametros.minDate) $scope.options.minDate = parametros.minDate; 39 if (parametros.minDate) $scope.options.minDate = parametros.minDate;
40 40
41 $scope.cancelar = function() { 41 $scope.cancelar = function() {
42 $uibModalInstance.dismiss(); 42 $uibModalInstance.dismiss();
43 }; 43 };
44 $scope.aceptar = function() { 44 $scope.aceptar = function() {
45 $uibModalInstance.close($scope.fecha); 45 $uibModalInstance.close($scope.fecha);
46 }; 46 };
47 } 47 }
48 ]) 48 ])
49 .controller('focaModalPromptController', [ 49 .controller('focaModalPromptController', [
50 '$uibModalInstance', '$scope', 'options', 'focaModalService', 50 '$uibModalInstance', '$scope', 'options', 'focaModalService',
51 function($uibModalInstance, $scope, options, focaModalService) { 51 function($uibModalInstance, $scope, options, focaModalService) {
52 52
53 $scope.options = options; 53 $scope.options = options;
54 54
55 if (!$scope.options.tipo) { 55 if (!$scope.options.tipo) {
56 $scope.options.tipo = 'text' 56 $scope.options.tipo = 'text'
57 } 57 }
58 $scope.cancelar = function() { 58 $scope.cancelar = function() {
59 $uibModalInstance.dismiss(); 59 $uibModalInstance.dismiss();
60 }; 60 };
61 $scope.aceptar = function(key) { 61 $scope.aceptar = function(key) {
62 if (key === 13) { 62 if (key === 13) {
63 if (options.email && !validateEmails($scope.options.value)) { 63 if (options.email && !validateEmails($scope.options.value)) {
64 focaModalService.alert('Ingrese email/s válido/s'); 64 focaModalService.alert('Ingrese email/s válido/s');
65 return; 65 return;
66 } 66 }
67 $uibModalInstance.close($scope.options.value); 67 $uibModalInstance.close($scope.options.value);
68 } 68 }
69 }; 69 };
70 70
71 function validateEmails(emails) { 71 function validateEmails(emails) {
72 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 72 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
73 var arr = emails.split(','); 73 var arr = emails.split(',');
74 var result = true; 74 var result = true;
75 75
76 arr.forEach(function(email) { 76 arr.forEach(function(email) {
77 var val = String(email).trim().toLowerCase(); 77 var val = String(email).trim().toLowerCase();
78 78
79 if (!re.test(val)) result = false; 79 if (!re.test(val)) result = false;
80 }); 80 });
81 81
82 return result; 82 return result;
83 } 83 }
84 } 84 }
85 ]); 85 ]);
86 86
src/js/controllerMail.js
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .controller('focaModalMailController', [ 2 .controller('focaModalMailController', [
3 '$scope', 3 '$scope',
4 '$uibModalInstance', 4 '$uibModalInstance',
5 'FileSaver', 5 'FileSaver',
6 'Blob', 6 'Blob',
7 'focaModalService', 7 'focaModalService',
8 'options', 8 'options',
9 function($scope, $uibModalInstance, FileSaver, Blob, 9 function ($scope, $uibModalInstance, FileSaver, Blob,
10 focaModalService, options) { 10 focaModalService, options) {
11 11
12 var regexMail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 12 var regexMail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
13 $scope.descargado = false; 13 $scope.descargado = false;
14 $scope.correoEnviado = false; 14 $scope.correoEnviado = false;
15 $scope.correoNoEnviado = false; 15 $scope.correoNoEnviado = false;
16 $scope.esperando = false; 16 $scope.esperando = false;
17 $scope.titulo = options.titulo; 17 $scope.titulo = options.titulo;
18 $scope.mailCliente = options.envio.mailCliente; 18 $scope.mailCliente = options.envio.mailCliente;
19 $scope.checkboxVar = false;
19 20
20 $scope.aceptar = function() { 21 $scope.aceptar = function () {
21 $uibModalInstance.close(); 22 $uibModalInstance.close();
22 }; 23 };
23 $scope.salir = function() { 24 $scope.salir = function () {
24 $uibModalInstance.close($scope.descargado); 25 $uibModalInstance.close($scope.descargado);
25 }; 26 };
26 $scope.imprimir = function () { 27 $scope.validarImpresion = function () {
28 var rutaComprobante;
29 if ($scope.checkboxVar === true) {
30 rutaComprobante = options.descargaSinValorizar;
31 } else {
32 rutaComprobante = options.descarga;
33 }
34 imprimir(rutaComprobante);
35 }
36 imprimir = function (rutaComprobante) {
27 $scope.descargado = true; 37 $scope.descargado = true;
28 $scope.esperando = true; 38 $scope.esperando = true;
29 focaModalService 39 focaModalService
30 .imprimirComprobante(options.descarga.url, options.options) 40 .imprimirComprobante(rutaComprobante.url, options.options)
31 .then(function(res) { 41 .then(function (res) {
32 var data = new Blob([res.data], {type: 'application/pdf'}); 42 var data = new Blob([res.data], { type: 'application/pdf' });
33 43
34 FileSaver.saveAs( 44 FileSaver.saveAs(
35 data, 45 data,
36 options.descarga.nombre 46 rutaComprobante.nombre
37 ); 47 );
38 $scope.esperando = false; 48 $scope.esperando = false;
39 }); 49 });
40 }; 50 };
41 $scope.enviarCorreo = function(key) { 51 $scope.enviarCorreo = function (key) {
42 if (key === 13) { 52 if (key === 13) {
43 if (!validarMail()) { 53 if (!validarMail()) {
44 focaModalService.alert('Ingrese email/s válido/s'); 54 focaModalService.alert('Ingrese email/s válido/s');
45 return; 55 return;
46 } 56 }
47 $scope.descargado = true; 57 $scope.descargado = true;
48 $scope.esperando = true; 58 $scope.esperando = true;
49 Object.assign(options.options, {receiver: $scope.mailCliente}); 59 Object.assign(options.options, { receiver: $scope.mailCliente });
50 60
51 focaModalService 61 focaModalService
52 .enviarCorreo(options.envio.url, options.options) 62 .enviarCorreo(options.envio.url, options.options)
53 .then(function() { 63 .then(function () {
54 $scope.correoEnviado = true; 64 $scope.correoEnviado = true;
55 $scope.esperando = false; 65 $scope.esperando = false;
56 }, function() { 66 }, function () {
57 $scope.esperando = false; 67 $scope.esperando = false;
58 $scope.correoNoEnviado = true; 68 $scope.correoNoEnviado = true;
59 }); 69 });
60 } 70 }
61 }; 71 };
62 function validarMail() { 72 function validarMail() {
63 var emails = $scope.mailCliente.split(','); 73 var emails = $scope.mailCliente.split(',');
64 var result = true; 74 var result = true;
65 emails.forEach(function(email) { 75 emails.forEach(function (email) {
66 if (!regexMail.test(email.trim())) result = false; 76 if (!regexMail.test(email.trim())) result = false;
67 }); 77 });
68 return result; 78 return result;
69 } 79 }
70 } 80 }
71 ]); 81 ]);
72 82
1 angular.module('focaModal') 1 angular.module('focaModal')
2 .factory('focaModalService', [ 2 .factory('focaModalService', [
3 '$uibModal', 'API_ENDPOINT', '$http', 3 '$uibModal', 'API_ENDPOINT', '$http',
4 function($uibModal, API_ENDPOINT, $http) { 4 function($uibModal, API_ENDPOINT, $http) {
5 return { 5 return {
6 confirm: function(textoModal) { 6 confirm: function(textoModal) {
7 return $uibModal.open({ 7 return $uibModal.open({
8 templateUrl: 'modal-confirm.html', 8 templateUrl: 'modal-confirm.html',
9 controller: 'focaModalConfirmController', 9 controller: 'focaModalConfirmController',
10 animation: false, 10 animation: false,
11 backdrop: false, 11 backdrop: false,
12 resolve: { textoModal: function() { return textoModal; } } 12 resolve: { textoModal: function() { return textoModal; } }
13 }) 13 })
14 .result.then( 14 .result.then(
15 function(resultado) { 15 function(resultado) {
16 return resultado; 16 return resultado;
17 } 17 }
18 ); 18 );
19 }, 19 },
20 info: function(textoModal) { 20 info: function(textoModal) {
21 return $uibModal.open({ 21 return $uibModal.open({
22 templateUrl: 'modal-info.html', 22 templateUrl: 'modal-info.html',
23 controller: 'focaModalInfoController', 23 controller: 'focaModalInfoController',
24 animation: false, 24 animation: false,
25 backdrop: false, 25 backdrop: false,
26 resolve: { textoModal: function() { return textoModal; } } 26 resolve: { textoModal: function() { return textoModal; } }
27 }) 27 })
28 .result.then( 28 .result.then(
29 function(resultado) { 29 function(resultado) {
30 return resultado; 30 return resultado;
31 } 31 }
32 ); 32 );
33 }, 33 },
34 alert: function(textoModal) { 34 alert: function(textoModal) {
35 return $uibModal.open({ 35 return $uibModal.open({
36 templateUrl: 'modal-alert.html', 36 templateUrl: 'modal-alert.html',
37 controller: 'focaModalAlertController', 37 controller: 'focaModalAlertController',
38 animation: false, 38 animation: false,
39 backdrop: false, 39 backdrop: false,
40 resolve: { textoModal: function() { return textoModal; } } 40 resolve: { textoModal: function() { return textoModal; } }
41 }) 41 })
42 .result.then( 42 .result.then(
43 function(resultado) { 43 function(resultado) {
44 return resultado; 44 return resultado;
45 } 45 }
46 ); 46 );
47 }, 47 },
48 modal: function(parametrosModal) { 48 modal: function(parametrosModal) {
49 parametrosModal.size = (typeof parametrosModal.size === 'undefined') ? 49 parametrosModal.size = (typeof parametrosModal.size === 'undefined') ?
50 'lg' : parametrosModal.size; 50 'lg' : parametrosModal.size;
51 51
52 return $uibModal.open({ 52 return $uibModal.open({
53 templateUrl: 'foca-modal.html', 53 templateUrl: 'foca-modal.html',
54 controller: 'focaModalController', 54 controller: 'focaModalController',
55 size: parametrosModal.size, 55 size: parametrosModal.size,
56 resolve: { 56 resolve: {
57 parametrosModal: function() { return parametrosModal; } 57 parametrosModal: function() { return parametrosModal; }
58 } 58 }
59 }) 59 })
60 .result.then( 60 .result.then(
61 function(resultado) { 61 function(resultado) {
62 return resultado; 62 return resultado;
63 } 63 }
64 ); 64 );
65 }, 65 },
66 getEntidad: function(filters, query, tipo, json) { 66 getEntidad: function(filters, query, tipo, json) {
67 if (tipo === 'POST') { 67 if (tipo === 'POST') {
68 return $http.post(API_ENDPOINT.URL + query, json); 68 return $http.post(API_ENDPOINT.URL + query, json);
69 } else { 69 } else {
70 return $http.get(API_ENDPOINT.URL + query, {nombre: filters}); 70 return $http.get(API_ENDPOINT.URL + query, {nombre: filters});
71 } 71 }
72 }, 72 },
73 modalFecha: function(parametros) { 73 modalFecha: function(parametros) {
74 return $uibModal.open({ 74 return $uibModal.open({
75 templateUrl: 'foca-fecha.html', 75 templateUrl: 'foca-fecha.html',
76 controller: 'focaModalFechaController', 76 controller: 'focaModalFechaController',
77 size: 'md', 77 size: 'md',
78 resolve: { 78 resolve: {
79 parametros: function() { return parametros; } 79 parametros: function() { return parametros; }
80 } 80 }
81 }) 81 })
82 .result.then( 82 .result.then(
83 function(resultado) { 83 function(resultado) {
84 return resultado; 84 return resultado;
85 } 85 }
86 ); 86 );
87 }, 87 },
88 prompt: function(options) { 88 prompt: function(options) {
89 return $uibModal.open({ 89 return $uibModal.open({
90 templateUrl: 'modal-prompt.html', 90 templateUrl: 'modal-prompt.html',
91 controller: 'focaModalPromptController', 91 controller: 'focaModalPromptController',
92 size: 'md', 92 size: 'md',
93 resolve: { 93 resolve: {
94 options: function() {return options;}, 94 options: function() {return options;},
95 } 95 }
96 }) 96 })
97 .result.then( 97 .result.then(
98 function(resultado) { 98 function(resultado) {
99 return resultado; 99 return resultado;
100 } 100 }
101 ); 101 );
102 }, 102 },
103 mail: function(options) { 103 mail: function(options) {
104 return $uibModal.open({ 104 return $uibModal.open({
105 templateUrl: 'modal-mail.html', 105 templateUrl: 'modal-mail.html',
106 controller: 'focaModalMailController', 106 controller: 'focaModalMailController',
107 size: 'md', 107 size: 'md',
108 resolve: { 108 resolve: {
109 options: function() {return options;}, 109 options: function() {return options;},
110 } 110 }
111 }) 111 })
112 .result.then( 112 .result.then(
113 function(resultado) { 113 function(resultado) {
114 return resultado; 114 return resultado;
115 } 115 }
116 ); 116 );
117 }, 117 },
118 imprimirComprobante: function(url, options) { 118 imprimirComprobante: function(url, options) {
119 console.log('imprimirComprobante', url, options);
119 return $http.post( 120 return $http.post(
120 API_ENDPOINT.URL + url, 121 API_ENDPOINT.URL + url,
121 options, 122 options,
122 {responseType: 'arraybuffer'} 123 {responseType: 'arraybuffer'}
123 ); 124 );
124 }, 125 },
125 enviarCorreo: function(url, options) { 126 enviarCorreo: function(url, options) {
127 console.log('enviarCorreo', url, options);
126 return $http.post(API_ENDPOINT.URL + url, options); 128 return $http.post(API_ENDPOINT.URL + url, options);
127 } 129 }
128 }; 130 };
129 } 131 }
130 ]); 132 ]);
131 133
src/views/modal-mail.html
1 <div class="modal-header"> 1 <div class="modal-header">
2 <h5 ng-bind="titulo"></h5> 2 <h5 ng-bind="titulo"></h5>
3 </div> 3 </div>
4 <div class="modal-body"> 4 <div class="modal-body">
5 <div > 5 <div >
6 <label 6 <label
7 class="col-12 bg-success text-white" 7 class="col-12 bg-success text-white"
8 ng-show="correoEnviado">Correo enviado con éxito</label> 8 ng-show="correoEnviado">Correo enviado con éxito</label>
9 <label 9 <label
10 class="col-12 bg-danger text-white" 10 class="col-12 bg-danger text-white"
11 ng-show="correoNoEnviado">Hubo un error al enviar el correo</label> 11 ng-show="correoNoEnviado">Hubo un error al enviar el correo</label>
12 <label>Enviar correo a</label> 12 <label>Enviar correo a</label>
13 <div class="d-flex"> 13 <div class="d-flex">
14 <input 14 <input
15 class="form-control col-9" 15 class="form-control col-9"
16 ng-model="mailCliente" 16 ng-model="mailCliente"
17 ng-keypress="enviarCorreo($event.keyCode)" 17 ng-keypress="enviarCorreo($event.keyCode)"
18 teclado-virtual/> 18 teclado-virtual/>
19 <button 19 <button
20 type="button" 20 type="button"
21 class="btn btn-enviar ml-auto" 21 class="btn btn-enviar ml-auto"
22 ng-click="enviarCorreo(13)" 22 ng-click="enviarCorreo(13)"
23 ladda="esperando" 23 ladda="esperando"
24 >Enviar</button> 24 >Enviar</button>
25 </div> 25 </div>
26 </div> 26 </div>
27 <hr> 27 <hr>
28 <div> 28 <div>
29 <label>Descargar comprobante en este dispositivo</label> 29 <label>Descargar comprobante</label>
30 <button 30 <div class="col my-1 d-flex justify-content-end">
31 class="btn btn-enviar float-right" 31 <div class="custom-control custom-checkbox my-auto mr-2">
32 ng-click="imprimir()" 32 <input
33 ladda="esperando" 33 type="checkbox"
34 >Descargar</button> 34 class="custom-control-input"
35 id="check"
36 ng-click="checkboxVar = !checkboxVar">
37 <label class="custom-control-label disable-selection" for="check">
38 Combrobante sin valorizar
39 </label>
40 </div>
41 <button
42 class="btn btn-enviar float-right"
43 ng-click="validarImpresion()"
44 ladda="esperando"
45 >Descargar</button>
46 </div>
35 </div> 47 </div>
36 </div> 48 </div>
37 <div class="modal-footer"> 49 <div class="modal-footer">
38 <button 50 <button
39 type="button" 51 type="button"
40 class="btn btn-secondary" 52 class="btn btn-secondary"
41 ng-click="salir()" 53 ng-click="salir()"
42 ladda="esperando" 54 ladda="esperando"
43 >Salir</button> 55 >Salir</button>
44 <button 56 <button
45 type="button" 57 type="button"
46 class="btn btn-primary" 58 class="btn btn-primary"
47 ng-click="aceptar()" 59 ng-click="aceptar()"
48 ladda="esperando" 60 ladda="esperando"
49 ng-disabled="!descargado" 61 ng-disabled="!descargado"
50 >Aceptar</button> 62 >Aceptar</button>
51 </div> 63 </div>
52 64