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