Commit 1ef53506a0b3f46c8b6eb40dbb23d5cb6e86d0f3
1 parent
18d87d47eb
Exists in
master
ok mail
Showing
1 changed file
with
5 additions
and
8 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalResumenCuenta') | 1 | angular.module('focaModalResumenCuenta') |
2 | .controller('focaModalResumenCuentaController', [ | 2 | .controller('focaModalResumenCuentaController', [ |
3 | '$timeout', | 3 | '$timeout', |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalResumenCuentaService', | 7 | 'focaModalResumenCuentaService', |
8 | 'idCliente', | 8 | 'cliente', |
9 | '$uibModal', | 9 | '$uibModal', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | function($timeout, $filter, $scope, $uibModalInstance, | 11 | function($timeout, $filter, $scope, $uibModalInstance, |
12 | focaModalResumenCuentaService, idCliente, $uibModal, focaModalService) { | 12 | focaModalResumenCuentaService, cliente, $uibModal, focaModalService) { |
13 | var fecha = new Date(); | 13 | var fecha = new Date(); |
14 | $scope.generado = false; | 14 | $scope.generado = false; |
15 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 15 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); |
16 | $scope.currentPageFacturas = []; | 16 | $scope.currentPageFacturas = []; |
17 | $scope.currentPage = 1; | 17 | $scope.currentPage = 1; |
18 | $scope.numPerPage = 10; | 18 | $scope.numPerPage = 10; |
19 | $scope.selectedFactura = -1; | 19 | $scope.selectedFactura = -1; |
20 | 20 | ||
21 | $scope.generar = function() { | 21 | $scope.generar = function() { |
22 | focaModalResumenCuentaService | 22 | focaModalResumenCuentaService |
23 | .getResumenCuenta(idCliente, $scope.fechaDesde) | 23 | .getResumenCuenta(cliente.COD, $scope.fechaDesde) |
24 | .then(function(res) { | 24 | .then(function(res) { |
25 | res.data.facturas = calcularSaldos(res.data.facturas); | 25 | res.data.facturas = calcularSaldos(res.data.facturas); |
26 | $scope.generado = true; | 26 | $scope.generado = true; |
27 | $scope.results = res.data; | 27 | $scope.results = res.data; |
28 | $scope.results.fechaDesde = $scope.fechaDesde; | 28 | $scope.results.fechaDesde = $scope.fechaDesde; |
29 | $scope.search(); | 29 | $scope.search(); |
30 | }); | 30 | }); |
31 | }; | 31 | }; |
32 | 32 | ||
33 | $scope.cancel = function() { | 33 | $scope.cancel = function() { |
34 | if ($scope.generado) { | 34 | if ($scope.generado) { |
35 | $scope.generado = false; | 35 | $scope.generado = false; |
36 | } else { | 36 | } else { |
37 | $uibModalInstance.dismiss('cancel'); | 37 | $uibModalInstance.dismiss('cancel'); |
38 | } | 38 | } |
39 | }; | 39 | }; |
40 | 40 | ||
41 | $scope.enviarMail = function(factura) { | 41 | $scope.enviarMail = function(factura) { |
42 | focaModalService.mail( | 42 | focaModalService.mail( |
43 | { | 43 | { |
44 | titulo: 'Enviar comprobante', | 44 | titulo: 'Enviar comprobante', |
45 | //TODO: CONFIGURAR DESCARGA | ||
46 | descarga: { | 45 | descarga: { |
47 | nombre: factura.numeroFactura + '.pdf', | 46 | nombre: factura.numeroFactura + '.pdf', |
48 | url: '/mail/comprobante/descargar', | 47 | url: '/mail/comprobante/descargar', |
49 | }, | 48 | }, |
50 | envio: { | 49 | envio: { |
51 | //TODO: TOMAR EMAIL DEL CLIENTE | 50 | mailCliente: cliente.MAIL, |
52 | mailCliente: 'jpinto@focasoftware.com', | ||
53 | url: '/mail/comprobante' | 51 | url: '/mail/comprobante' |
54 | }, | 52 | }, |
55 | options: { | 53 | options: { |
56 | factura: factura | 54 | factura: factura |
57 | } | 55 | } |
58 | } | 56 | } |
59 | ); | 57 | ); |
60 | }; | 58 | }; |
61 | 59 | ||
62 | $scope.enviarResumen = function() { | 60 | $scope.enviarResumen = function() { |
63 | focaModalService.mail( | 61 | focaModalService.mail( |
64 | { | 62 | { |
65 | titulo: 'Enviar resumen de cuenta', | 63 | titulo: 'Enviar resumen de cuenta', |
66 | descarga: { | 64 | descarga: { |
67 | nombre: 'resumen-de-cuenta.pdf', | 65 | nombre: 'resumen-de-cuenta.pdf', |
68 | url: '/mail/resumen-cuenta/descargar', | 66 | url: '/mail/resumen-cuenta/descargar', |
69 | }, | 67 | }, |
70 | envio: { | 68 | envio: { |
71 | //TODO: TOMAR EMAIL DEL CLIENTE | 69 | mailCliente: cliente.MAIL, |
72 | mailCliente: 'jpinto@focasoftware.com', | ||
73 | url: '/mail/resumen-cuenta', | 70 | url: '/mail/resumen-cuenta', |
74 | }, | 71 | }, |
75 | options: { | 72 | options: { |
76 | resumen: $scope.results | 73 | resumen: $scope.results |
77 | } | 74 | } |
78 | } | 75 | } |
79 | ); | 76 | ); |
80 | }; | 77 | }; |
81 | 78 | ||
82 | $scope.verFactura = function(factura) { | 79 | $scope.verFactura = function(factura) { |
83 | var modalInstance = $uibModal.open( | 80 | var modalInstance = $uibModal.open( |
84 | { | 81 | { |
85 | ariaLabelledBy: 'Detalle de factura', | 82 | ariaLabelledBy: 'Detalle de factura', |
86 | templateUrl: 'foca-modal-factura-detalle.html', | 83 | templateUrl: 'foca-modal-factura-detalle.html', |
87 | controller: 'focaModalFacturaDetalleController', | 84 | controller: 'focaModalFacturaDetalleController', |
88 | size: 'md', | 85 | size: 'md', |
89 | resolve: { | 86 | resolve: { |
90 | factura: factura | 87 | factura: factura |
91 | } | 88 | } |
92 | } | 89 | } |
93 | ); | 90 | ); |
94 | modalInstance.result.then(); | 91 | modalInstance.result.then(); |
95 | }; | 92 | }; |
96 | 93 | ||
97 | 94 | ||
98 | $scope.search = function() { | 95 | $scope.search = function() { |
99 | if ($scope.results.facturas.length) { | 96 | if ($scope.results.facturas.length) { |
100 | $scope.lastPage = Math.ceil( | 97 | $scope.lastPage = Math.ceil( |
101 | $scope.results.facturas.length / $scope.numPerPage | 98 | $scope.results.facturas.length / $scope.numPerPage |
102 | ); | 99 | ); |
103 | $scope.resetPage(); | 100 | $scope.resetPage(); |
104 | } | 101 | } |
105 | }; | 102 | }; |
106 | 103 | ||
107 | $scope.resetPage = function() { | 104 | $scope.resetPage = function() { |
108 | $scope.currentPage = 1; | 105 | $scope.currentPage = 1; |
109 | $scope.selectPage(1); | 106 | $scope.selectPage(1); |
110 | }; | 107 | }; |
111 | 108 | ||
112 | $scope.selectPage = function(page) { | 109 | $scope.selectPage = function(page) { |
113 | var start = (page - 1) * $scope.numPerPage; | 110 | var start = (page - 1) * $scope.numPerPage; |
114 | var end = start + $scope.numPerPage; | 111 | var end = start + $scope.numPerPage; |
115 | $scope.paginas = []; | 112 | $scope.paginas = []; |
116 | $scope.paginas = calcularPages(page); | 113 | $scope.paginas = calcularPages(page); |
117 | $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); | 114 | $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); |
118 | $scope.currentPage = page; | 115 | $scope.currentPage = page; |
119 | }; | 116 | }; |
120 | 117 | ||
121 | function calcularPages(paginaActual) { | 118 | function calcularPages(paginaActual) { |
122 | var paginas = []; | 119 | var paginas = []; |
123 | paginas.push(paginaActual); | 120 | paginas.push(paginaActual); |
124 | 121 | ||
125 | if (paginaActual - 1 > 1) { | 122 | if (paginaActual - 1 > 1) { |
126 | 123 | ||
127 | paginas.unshift(paginaActual - 1); | 124 | paginas.unshift(paginaActual - 1); |
128 | if (paginaActual - 2 > 1) { | 125 | if (paginaActual - 2 > 1) { |
129 | paginas.unshift(paginaActual - 2); | 126 | paginas.unshift(paginaActual - 2); |
130 | } | 127 | } |
131 | } | 128 | } |
132 | 129 | ||
133 | if (paginaActual + 1 < $scope.lastPage) { | 130 | if (paginaActual + 1 < $scope.lastPage) { |
134 | paginas.push(paginaActual + 1); | 131 | paginas.push(paginaActual + 1); |
135 | if (paginaActual + 2 < $scope.lastPage) { | 132 | if (paginaActual + 2 < $scope.lastPage) { |
136 | paginas.push(paginaActual + 2); | 133 | paginas.push(paginaActual + 2); |
137 | } | 134 | } |
138 | } | 135 | } |
139 | 136 | ||
140 | if (paginaActual !== 1) { | 137 | if (paginaActual !== 1) { |
141 | paginas.unshift(1); | 138 | paginas.unshift(1); |
142 | } | 139 | } |
143 | 140 | ||
144 | if (paginaActual !== $scope.lastPage) { | 141 | if (paginaActual !== $scope.lastPage) { |
145 | paginas.push($scope.lastPage); | 142 | paginas.push($scope.lastPage); |
146 | } | 143 | } |
147 | 144 | ||
148 | return paginas; | 145 | return paginas; |
149 | } | 146 | } |
150 | 147 | ||
151 | function calcularSaldos(facturas) { | 148 | function calcularSaldos(facturas) { |
152 | var saldo = 0; | 149 | var saldo = 0; |
153 | 150 | ||
154 | facturas.forEach(function(factura) { | 151 | facturas.forEach(function(factura) { |
155 | if (factura.TCO === 'CI' || | 152 | if (factura.TCO === 'CI' || |
156 | factura.TCO === 'FT' || | 153 | factura.TCO === 'FT' || |
157 | factura.TCO === 'ND'){ | 154 | factura.TCO === 'ND'){ |
158 | factura.IPA = factura.IPA * -1; | 155 | factura.IPA = factura.IPA * -1; |
159 | } else { | 156 | } else { |
160 | factura.IPA = factura.IPA; | 157 | factura.IPA = factura.IPA; |
161 | } | 158 | } |
162 | saldo += factura.IPA; | 159 | saldo += factura.IPA; |
163 | factura.saldo = saldo; | 160 | factura.saldo = saldo; |
164 | factura.saldo_show = Math.abs(saldo); | 161 | factura.saldo_show = Math.abs(saldo); |
165 | factura.IPA_SHOW = Math.abs(factura.IPA); | 162 | factura.IPA_SHOW = Math.abs(factura.IPA); |
166 | }); | 163 | }); |
167 | 164 | ||
168 | return facturas; | 165 | return facturas; |
169 | } | 166 | } |
170 | }] | 167 | }] |
171 | ); | 168 | ); |
172 | 169 |