controller.js
5.63 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
angular.module('focaModalResumenCuenta')
.controller('focaModalResumenCuentaController', [
'$timeout',
'$filter',
'$scope',
'$uibModalInstance',
'focaModalResumenCuentaService',
'idCliente',
'$uibModal',
'focaModalService',
function($timeout, $filter, $scope, $uibModalInstance,
focaModalResumenCuentaService, idCliente, $uibModal, focaModalService) {
var fecha = new Date();
$scope.generado = false;
$scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
$scope.currentPageFacturas = [];
$scope.currentPage = 1;
$scope.numPerPage = 10;
$scope.selectedFactura = -1;
$scope.generar = function() {
focaModalResumenCuentaService
.getResumenCuenta(idCliente, $scope.fechaDesde)
.then(function(res) {
res.data.facturas = calcularSaldos(res.data.facturas);
$scope.generado = true;
$scope.results = res.data;
$scope.results.fechaDesde = $scope.fechaDesde;
$scope.search();
});
};
$scope.cancel = function() {
if ($scope.generado) {
$scope.generado = false;
} else {
$uibModalInstance.dismiss('cancel');
}
};
$scope.enviarMail = function(factura) {
focaModalService
.prompt('Ingrese los emails separados por coma para enviar comprobante',
factura.cliente.MAIL)
.then(function(res) {
return focaModalResumenCuentaService.enviarFacturaPorMail(res, factura);
})
.then(function() {
focaModalService.alert('Mensaje enviado correctamente');
});
};
$scope.enviarResumen = function() {
focaModalService
.prompt('Ingrese los emails separados por coma para enviar comprobante',
$scope.results.facturas[0].cliente.MAIL)
.then(function(res) {
return focaModalResumenCuentaService.enviarResumenPorMail(res,
$scope.results);
})
.then(function() {
focaModalService.alert('Mensaje enviado correctamente');
});
};
$scope.verFactura = function(factura) {
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Detalle de factura',
templateUrl: 'foca-modal-factura-detalle.html',
controller: 'focaModalFacturaDetalleController',
size: 'md',
resolve: {
factura: factura
}
}
);
modalInstance.result.then();
};
$scope.search = function() {
if ($scope.results.facturas.length) {
$scope.lastPage = Math.ceil(
$scope.results.facturas.length / $scope.numPerPage
);
$scope.resetPage();
}
};
$scope.resetPage = function() {
$scope.currentPage = 1;
$scope.selectPage(1);
};
$scope.selectPage = function(page) {
var start = (page - 1) * $scope.numPerPage;
var end = start + $scope.numPerPage;
$scope.paginas = [];
$scope.paginas = calcularPages(page);
$scope.currentPageFacturas = $scope.results.facturas.slice(start, end);
$scope.currentPage = page;
};
function calcularPages(paginaActual) {
var paginas = [];
paginas.push(paginaActual);
if (paginaActual - 1 > 1) {
paginas.unshift(paginaActual - 1);
if (paginaActual - 2 > 1) {
paginas.unshift(paginaActual - 2);
}
}
if (paginaActual + 1 < $scope.lastPage) {
paginas.push(paginaActual + 1);
if (paginaActual + 2 < $scope.lastPage) {
paginas.push(paginaActual + 2);
}
}
if (paginaActual !== 1) {
paginas.unshift(1);
}
if (paginaActual !== $scope.lastPage) {
paginas.push($scope.lastPage);
}
return paginas;
}
function calcularSaldos(facturas) {
var saldo = 0;
facturas.forEach(function(factura) {
if (factura.TCO === 'CI' ||
factura.TCO === 'FT' ||
factura.TCO === 'ND'){
factura.IPA = factura.IPA * -1;
} else {
factura.IPA = factura.IPA;
}
saldo += factura.IPA;
factura.saldo = saldo;
factura.saldo_show = Math.abs(saldo);
factura.IPA_SHOW = Math.abs(factura.IPA);
});
return facturas;
}
}]
);