Commit 6c6062216e74b117c0924a998b136608d560ba90
1 parent
3610265266
Exists in
develop
agrego descarga de remito sin valores
Showing
1 changed file
with
1 additions
and
0 deletions
Show diff stats
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 | $scope.checkboxVar = false; |
20 | 20 | ||
21 | $scope.aceptar = function () { | 21 | $scope.aceptar = function () { |
22 | $uibModalInstance.close(); | 22 | $uibModalInstance.close(); |
23 | }; | 23 | }; |
24 | $scope.salir = function () { | 24 | $scope.salir = function () { |
25 | $uibModalInstance.close($scope.descargado); | 25 | $uibModalInstance.close($scope.descargado); |
26 | }; | 26 | }; |
27 | $scope.validarImpresion = function () { | 27 | $scope.validarImpresion = function () { |
28 | var rutaComprobante; | 28 | var rutaComprobante; |
29 | if ($scope.checkboxVar === true) { | 29 | if ($scope.checkboxVar === true) { |
30 | rutaComprobante = options.descargaSinValorizar; | 30 | rutaComprobante = options.descargaSinValorizar; |
31 | } else { | 31 | } else { |
32 | rutaComprobante = options.descarga; | 32 | rutaComprobante = options.descarga; |
33 | } | 33 | } |
34 | console.log($scope.checkboxVar) | ||
34 | imprimir(rutaComprobante); | 35 | imprimir(rutaComprobante); |
35 | } | 36 | } |
36 | imprimir = function (rutaComprobante) { | 37 | imprimir = function (rutaComprobante) { |
37 | $scope.descargado = true; | 38 | $scope.descargado = true; |
38 | $scope.esperando = true; | 39 | $scope.esperando = true; |
39 | focaModalService | 40 | focaModalService |
40 | .imprimirComprobante(rutaComprobante.url, options.options) | 41 | .imprimirComprobante(rutaComprobante.url, options.options) |
41 | .then(function (res) { | 42 | .then(function (res) { |
42 | var data = new Blob([res.data], { type: 'application/pdf' }); | 43 | var data = new Blob([res.data], { type: 'application/pdf' }); |
43 | 44 | ||
44 | FileSaver.saveAs( | 45 | FileSaver.saveAs( |
45 | data, | 46 | data, |
46 | rutaComprobante.nombre | 47 | rutaComprobante.nombre |
47 | ); | 48 | ); |
48 | $scope.esperando = false; | 49 | $scope.esperando = false; |
49 | }); | 50 | }); |
50 | }; | 51 | }; |
51 | $scope.enviarCorreo = function (key) { | 52 | $scope.enviarCorreo = function (key) { |
52 | if (key === 13) { | 53 | if (key === 13) { |
53 | if (!validarMail()) { | 54 | if (!validarMail()) { |
54 | focaModalService.alert('Ingrese email/s válido/s'); | 55 | focaModalService.alert('Ingrese email/s válido/s'); |
55 | return; | 56 | return; |
56 | } | 57 | } |
57 | $scope.descargado = true; | 58 | $scope.descargado = true; |
58 | $scope.esperando = true; | 59 | $scope.esperando = true; |
59 | Object.assign(options.options, { receiver: $scope.mailCliente }); | 60 | Object.assign(options.options, { receiver: $scope.mailCliente }); |
60 | 61 | ||
61 | focaModalService | 62 | focaModalService |
62 | .enviarCorreo(options.envio.url, options.options) | 63 | .enviarCorreo(options.envio.url, options.options) |
63 | .then(function () { | 64 | .then(function () { |
64 | $scope.correoEnviado = true; | 65 | $scope.correoEnviado = true; |
65 | $scope.esperando = false; | 66 | $scope.esperando = false; |
66 | }, function () { | 67 | }, function () { |
67 | $scope.esperando = false; | 68 | $scope.esperando = false; |
68 | $scope.correoNoEnviado = true; | 69 | $scope.correoNoEnviado = true; |
69 | }); | 70 | }); |
70 | } | 71 | } |
71 | }; | 72 | }; |
72 | function validarMail() { | 73 | function validarMail() { |
73 | var emails = $scope.mailCliente.split(','); | 74 | var emails = $scope.mailCliente.split(','); |
74 | var result = true; | 75 | var result = true; |
75 | emails.forEach(function (email) { | 76 | emails.forEach(function (email) { |
76 | if (!regexMail.test(email.trim())) result = false; | 77 | if (!regexMail.test(email.trim())) result = false; |
77 | }); | 78 | }); |
78 | return result; | 79 | return result; |
79 | } | 80 | } |
80 | } | 81 | } |
81 | ]); | 82 | ]); |
82 | 83 |