Commit ac228012b3d12d4371b2188bb6696119dc448114
Exists in
master
and in
1 other branch
Merge branch 'develop' into 'master'
Develop See merge request !7
Showing
1 changed file
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 | 42 | focaModalService.mail( |
43 | .prompt({ | 43 | { |
44 | titulo: 'Ingrese los emails separados por coma para enviar comprobante', | 44 | titulo: 'Enviar comprobante', |
45 | value: factura.cliente.MAIL, | 45 | descarga: { |
46 | email: true | 46 | nombre: factura.numeroFactura + '.pdf', |
47 | }) | 47 | url: '/mail/comprobante/descargar', |
48 | .then(function(res) { | 48 | }, |
49 | return focaModalResumenCuentaService.enviarFacturaPorMail(res, factura); | 49 | envio: { |
50 | }) | 50 | mailCliente: cliente.MAIL, |
51 | .then(function() { | 51 | url: '/mail/comprobante' |
52 | focaModalService.alert('Mensaje enviado correctamente'); | 52 | }, |
53 | }); | 53 | options: { |
54 | factura: factura | ||
55 | } | ||
56 | } | ||
57 | ); | ||
54 | }; | 58 | }; |
55 | 59 | ||
56 | $scope.enviarResumen = function() { | 60 | $scope.enviarResumen = function() { |
57 | focaModalService | 61 | focaModalService.mail( |
58 | .prompt({ | 62 | { |
59 | titulo: 'Ingrese los emails separados por coma para enviar comprobante', | 63 | titulo: 'Enviar resumen de cuenta', |
60 | value: $scope.results.facturas[0].cliente.MAIL, | 64 | descarga: { |
61 | email: true | 65 | nombre: 'resumen-de-cuenta.pdf', |
62 | }) | 66 | url: '/mail/resumen-cuenta/descargar', |
63 | .then(function(res) { | 67 | }, |
64 | return focaModalResumenCuentaService.enviarResumenPorMail(res, | 68 | envio: { |
65 | $scope.results); | 69 | mailCliente: cliente.MAIL, |
66 | }) | 70 | url: '/mail/resumen-cuenta', |
67 | .then(function() { | 71 | }, |
68 | focaModalService.alert('Mensaje enviado correctamente'); | 72 | options: { |
69 | }); | 73 | resumen: $scope.results |
74 | } | ||
75 | } | ||
76 | ); | ||
70 | }; | 77 | }; |
71 | 78 | ||
72 | $scope.verFactura = function(factura) { | 79 | $scope.verFactura = function(factura) { |
73 | var modalInstance = $uibModal.open( | 80 | var modalInstance = $uibModal.open( |
74 | { | 81 | { |
75 | ariaLabelledBy: 'Detalle de factura', | 82 | ariaLabelledBy: 'Detalle de factura', |
76 | templateUrl: 'foca-modal-factura-detalle.html', | 83 | templateUrl: 'foca-modal-factura-detalle.html', |
77 | controller: 'focaModalFacturaDetalleController', | 84 | controller: 'focaModalFacturaDetalleController', |
78 | size: 'md', | 85 | size: 'md', |
79 | resolve: { | 86 | resolve: { |
80 | factura: factura | 87 | factura: factura |
81 | } | 88 | } |
82 | } | 89 | } |
83 | ); | 90 | ); |
84 | modalInstance.result.then(); | 91 | modalInstance.result.then(); |
85 | }; | 92 | }; |
86 | 93 | ||
87 | 94 | ||
88 | $scope.search = function() { | 95 | $scope.search = function() { |
89 | if ($scope.results.facturas.length) { | 96 | if ($scope.results.facturas.length) { |
90 | $scope.lastPage = Math.ceil( | 97 | $scope.lastPage = Math.ceil( |
91 | $scope.results.facturas.length / $scope.numPerPage | 98 | $scope.results.facturas.length / $scope.numPerPage |
92 | ); | 99 | ); |
93 | $scope.resetPage(); | 100 | $scope.resetPage(); |
94 | } | 101 | } |
95 | }; | 102 | }; |
96 | 103 | ||
97 | $scope.resetPage = function() { | 104 | $scope.resetPage = function() { |
98 | $scope.currentPage = 1; | 105 | $scope.currentPage = 1; |
99 | $scope.selectPage(1); | 106 | $scope.selectPage(1); |
100 | }; | 107 | }; |
101 | 108 | ||
102 | $scope.selectPage = function(page) { | 109 | $scope.selectPage = function(page) { |
103 | var start = (page - 1) * $scope.numPerPage; | 110 | var start = (page - 1) * $scope.numPerPage; |
104 | var end = start + $scope.numPerPage; | 111 | var end = start + $scope.numPerPage; |
105 | $scope.paginas = []; | 112 | $scope.paginas = []; |
106 | $scope.paginas = calcularPages(page); | 113 | $scope.paginas = calcularPages(page); |
107 | $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); | 114 | $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); |
108 | $scope.currentPage = page; | 115 | $scope.currentPage = page; |
109 | }; | 116 | }; |
110 | 117 | ||
111 | function calcularPages(paginaActual) { | 118 | function calcularPages(paginaActual) { |
112 | var paginas = []; | 119 | var paginas = []; |
113 | paginas.push(paginaActual); | 120 | paginas.push(paginaActual); |
114 | 121 | ||
115 | if (paginaActual - 1 > 1) { | 122 | if (paginaActual - 1 > 1) { |
116 | 123 | ||
117 | paginas.unshift(paginaActual - 1); | 124 | paginas.unshift(paginaActual - 1); |
118 | if (paginaActual - 2 > 1) { | 125 | if (paginaActual - 2 > 1) { |
119 | paginas.unshift(paginaActual - 2); | 126 | paginas.unshift(paginaActual - 2); |
120 | } | 127 | } |
121 | } | 128 | } |
122 | 129 | ||
123 | if (paginaActual + 1 < $scope.lastPage) { | 130 | if (paginaActual + 1 < $scope.lastPage) { |
124 | paginas.push(paginaActual + 1); | 131 | paginas.push(paginaActual + 1); |
125 | if (paginaActual + 2 < $scope.lastPage) { | 132 | if (paginaActual + 2 < $scope.lastPage) { |
126 | paginas.push(paginaActual + 2); | 133 | paginas.push(paginaActual + 2); |
127 | } | 134 | } |
128 | } | 135 | } |
129 | 136 | ||
130 | if (paginaActual !== 1) { | 137 | if (paginaActual !== 1) { |
131 | paginas.unshift(1); | 138 | paginas.unshift(1); |
132 | } | 139 | } |
133 | 140 | ||
134 | if (paginaActual !== $scope.lastPage) { | 141 | if (paginaActual !== $scope.lastPage) { |
135 | paginas.push($scope.lastPage); | 142 | paginas.push($scope.lastPage); |
136 | } | 143 | } |
137 | 144 | ||
138 | return paginas; | 145 | return paginas; |
139 | } | 146 | } |
140 | 147 | ||
141 | function calcularSaldos(facturas) { | 148 | function calcularSaldos(facturas) { |
142 | var saldo = 0; | 149 | var saldo = 0; |
143 | 150 | ||
144 | facturas.forEach(function(factura) { | 151 | facturas.forEach(function(factura) { |
145 | if (factura.TCO === 'CI' || | 152 | if (factura.TCO === 'CI' || |
146 | factura.TCO === 'FT' || | 153 | factura.TCO === 'FT' || |
147 | factura.TCO === 'ND'){ | 154 | factura.TCO === 'ND'){ |
148 | factura.IPA = factura.IPA * -1; | 155 | factura.IPA = factura.IPA * -1; |
149 | } else { | 156 | } else { |
150 | factura.IPA = factura.IPA; | 157 | factura.IPA = factura.IPA; |
151 | } | 158 | } |
152 | saldo += factura.IPA; | 159 | saldo += factura.IPA; |
153 | factura.saldo = saldo; | 160 | factura.saldo = saldo; |
154 | factura.saldo_show = Math.abs(saldo); | 161 | factura.saldo_show = Math.abs(saldo); |
155 | factura.IPA_SHOW = Math.abs(factura.IPA); | 162 | factura.IPA_SHOW = Math.abs(factura.IPA); |
156 | }); | 163 | }); |
157 | 164 | ||
158 | return facturas; | 165 | return facturas; |
159 | } | 166 | } |
160 | }] | 167 | }] |
161 | ); | 168 | ); |
162 | 169 |