controllerMail.js
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
angular.module('focaModal')
.controller('focaModalMailController', [
'$scope',
'$uibModalInstance',
'FileSaver',
'Blob',
'focaModalService',
'options',
function ($scope, $uibModalInstance, FileSaver, Blob,
focaModalService, options) {
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,}))$/;
$scope.descargado = false;
$scope.correoEnviado = false;
$scope.correoNoEnviado = false;
$scope.esperando = false;
$scope.titulo = options.titulo;
$scope.checkboxVar = false;
$scope.aceptar = function () {
$uibModalInstance.close();
};
$scope.salir = function () {
$uibModalInstance.close($scope.descargado);
};
$scope.validarImpresion = function () {
var rutaComprobante;
rutaComprobante = $scope.checkboxVar === true ? options.descargaSinValorizar : options.descarga;
imprimir(rutaComprobante);
}
imprimir = function (rutaComprobante) {
$scope.descargado = true;
$scope.esperando = true;
focaModalService
.imprimirComprobante(rutaComprobante.url, options.options)
.then(function (res) {
var data = new Blob([res.data], { type: 'application/pdf' });
FileSaver.saveAs(
data,
rutaComprobante.nombre
);
$scope.esperando = false;
});
};
$scope.enviarComprobante = function () {
var rutaEnvioComprobante;
rutaEnvioComprobante = $scope.checkboxVar === true ? options.envioSinValorizar : options.envio;
enviarCorreo(rutaEnvioComprobante, 13);
}
enviarCorreo = function (rutaEnvioComprobante, key) {
if (key === 13) {
if (!validarMail()) {
focaModalService.alert('Ingrese email/s válido/s');
return;
}
$scope.descargado = true;
$scope.esperando = true;
$scope.mailCliente = rutaEnvioComprobante.mailCliente;
Object.assign(options.options, { receiver: $scope.mailCliente });
focaModalService
.enviarCorreo(rutaEnvioComprobante.url, options.options)
.then(function () {
$scope.correoEnviado = true;
$scope.esperando = false;
}, function () {
$scope.esperando = false;
$scope.correoNoEnviado = true;
});
}
};
function validarMail() {
var emails = $scope.mailCliente.split(',');
var result = true;
emails.forEach(function (email) {
if (!regexMail.test(email.trim())) result = false;
});
return result;
}
}
]);