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