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