Commit 1f6504de413697b39f36c168d58cef8134a88beb

Authored by Eric Fernandez
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !19
src/js/controller.js
1 angular.module('focaModalFactura') 1 angular.module('focaModalFactura')
2 .controller('focaModalFacturaController', 2 .controller('focaModalFacturaController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalFacturaService', 7 'focaModalFacturaService',
8 'parametrosFactura', 8 'parametrosFactura',
9 '$uibModal', 9 '$uibModal',
10 'focaModalService', 10 'focaModalService',
11 function($filter, $scope, $uibModalInstance, 11 function($filter, $scope, $uibModalInstance,
12 focaModalFacturaService, parametrosFactura, $uibModal, focaModalService 12 focaModalFacturaService, parametrosFactura, $uibModal, focaModalService
13 ) { 13 ) {
14 var fecha = new Date(); 14 var fecha = new Date();
15 $scope.fechaHasta = new Date(); 15 $scope.fechaHasta = new Date();
16 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 16 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
17 $scope.filters = ''; 17 $scope.filters = '';
18 $scope.facturas = []; 18 $scope.facturas = [];
19 $scope.primerBusqueda = false; 19 $scope.primerBusqueda = false;
20 $scope.searchLoading = false; 20 $scope.searchLoading = false;
21 $scope.parametrosFactura = parametrosFactura; 21 $scope.parametrosFactura = parametrosFactura;
22 // pagination 22 // pagination
23 $scope.numPerPage = 10; 23 $scope.numPerPage = 10;
24 $scope.currentPage = 1; 24 $scope.currentPage = 1;
25 $scope.filteredFacturas = []; 25 $scope.filteredFacturas = [];
26 $scope.currentPageFacturas = []; 26 $scope.currentPageFacturas = [];
27 $scope.selectedFactura = -1; 27 $scope.selectedFactura = -1;
28 28
29 //METODOS 29 //METODOS
30 $scope.busquedaPress = function(key) { 30 $scope.busquedaPress = function(key) {
31 if (key === 13) { 31 if (key === 13) {
32 if(!$scope.fechaDesde) { 32 if(!$scope.fechaDesde) {
33 focaModalService.alert('INGRESE FECHA DESDE'); 33 focaModalService.alert('INGRESE FECHA DESDE');
34 return; 34 return;
35 } 35 }
36 if(!$scope.fechaHasta) { 36 if(!$scope.fechaHasta) {
37 focaModalService.alert('INGRESE FECHA HASTA'); 37 focaModalService.alert('INGRESE FECHA HASTA');
38 return; 38 return;
39 } 39 }
40 if($scope.fechaDesde > $scope.fechaHasta) { 40 if($scope.fechaDesde > $scope.fechaHasta) {
41 focaModalService 41 focaModalService
42 .alert('La fecha desde no puede ser mayor a la fecha hasta'); 42 .alert('La fecha desde no puede ser mayor a la fecha hasta');
43 return; 43 return;
44 } 44 }
45 $scope.searchLoading = true; 45 $scope.searchLoading = true;
46 //TODO hacer filtro de fecha 46 //TODO hacer filtro de fecha
47 focaModalFacturaService 47 focaModalFacturaService
48 .getFacturasByIdCliente( 48 .getFacturasByIdCliente(
49 parametrosFactura.cliente.COD, 49 parametrosFactura.cliente.COD,
50 parametrosFactura.moneda, 50 parametrosFactura.moneda,
51 '2001-01-01', 51 '2001-01-01',
52 '2100-12-31' 52 '2100-12-31'
53 ) 53 )
54 .then(llenarDatos); 54 .then(llenarDatos);
55 } 55 }
56 }; 56 };
57 57
58 $scope.aceptar = function() { 58 $scope.aceptar = function() {
59 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 59 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
60 $uibModalInstance.close(result); 60 $uibModalInstance.close(result);
61 }; 61 };
62 62
63 $scope.tieneAlMenosUno = function() { 63 $scope.tieneAlMenosUno = function() {
64 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 64 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
65 return !result.length; 65 return !result.length;
66 }; 66 };
67 67
68 function llenarDatos(res) { 68 function llenarDatos(res) {
69 $scope.facturas = []; 69 $scope.facturas = [];
70 $scope.filteredFacturas = []; 70 $scope.filteredFacturas = [];
71 $scope.currentPageFacturas = []; 71 $scope.currentPageFacturas = [];
72 $scope.selectedFactura = -1; 72 $scope.selectedFactura = -1;
73 $scope.searchLoading = false; 73 $scope.searchLoading = false;
74 $scope.primerBusqueda = true; 74 $scope.primerBusqueda = true;
75 $scope.facturas = calcularSaldos(res.data); 75 $scope.facturas = calcularSaldos(res.data);
76 $scope.search(); 76 $scope.search();
77 primera(); 77 primera();
78 } 78 }
79 79
80 $scope.verFactura = function(factura) { 80 $scope.verFactura = function(factura) {
81 var modalInstance = $uibModal.open( 81 var modalInstance = $uibModal.open(
82 { 82 {
83 ariaLabelledBy: 'Detalle de factura', 83 ariaLabelledBy: 'Detalle de factura',
84 templateUrl: 'foca-modal-factura-detalle.html', 84 templateUrl: 'foca-modal-factura-detalle.html',
85 controller: 'focaModalFacturaDetalleController', 85 controller: 'focaModalFacturaDetalleController',
86 size: 'md', 86 size: 'md',
87 resolve: { 87 resolve: {
88 factura: factura 88 factura: factura
89 } 89 }
90 } 90 }
91 ); 91 );
92 modalInstance.result.then(); 92 modalInstance.result.then();
93 }; 93 };
94 94
95 $scope.search = function() { 95 $scope.search = function() {
96 if($scope.facturas.length > 0) { 96 if($scope.facturas.length > 0) {
97 $scope.filteredFacturas = $filter('filter')( 97 $scope.filteredFacturas = $filter('filter')(
98 $scope.facturas, 98 $scope.facturas,
99 {$: $scope.filters} 99 {$: $scope.filters}
100 ); 100 );
101 101
102 $scope.lastPage = Math.ceil( 102 $scope.lastPage = Math.ceil(
103 $scope.filteredFacturas.length / $scope.numPerPage 103 $scope.filteredFacturas.length / $scope.numPerPage
104 ); 104 );
105 105
106 $scope.resetPage(); 106 $scope.resetPage();
107 } 107 }
108 }; 108 };
109 109
110 $scope.resetPage = function() { 110 $scope.resetPage = function() {
111 $scope.currentPage = 1; 111 $scope.currentPage = 1;
112 $scope.selectPage(1); 112 $scope.selectPage(1);
113 }; 113 };
114 114
115 $scope.selectPage = function(page) { 115 $scope.selectPage = function(page) {
116 var start = (page - 1) * $scope.numPerPage; 116 var start = (page - 1) * $scope.numPerPage;
117 var end = start + $scope.numPerPage; 117 var end = start + $scope.numPerPage;
118 $scope.paginas = []; 118 $scope.paginas = [];
119 $scope.paginas = calcularPages(page); 119 $scope.paginas = calcularPages(page);
120 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); 120 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
121 $scope.currentPage = page; 121 $scope.currentPage = page;
122 }; 122 };
123 123
124 $scope.cancel = function() { 124 $scope.cancel = function() {
125 $uibModalInstance.dismiss('cancel'); 125 $uibModalInstance.dismiss('cancel');
126 }; 126 };
127 127
128 $scope.busquedaDown = function(key) { 128 $scope.busquedaDown = function(key) {
129 if (key === 40) { 129 if (key === 40) {
130 primera(key); 130 primera(key);
131 } 131 }
132 }; 132 };
133 133
134 $scope.itemFactura = function(key) { 134 $scope.itemFactura = function(key) {
135 if (key === 38) { 135 if (key === 38) {
136 anterior(key); 136 anterior(key);
137 } 137 }
138 138
139 if (key === 40) { 139 if (key === 40) {
140 siguiente(key); 140 siguiente(key);
141 } 141 }
142 142
143 if (key === 37) { 143 if (key === 37) {
144 retrocederPagina(); 144 retrocederPagina();
145 } 145 }
146 146
147 if (key === 39) { 147 if (key === 39) {
148 avanzarPagina(); 148 avanzarPagina();
149 } 149 }
150 }; 150 };
151 151
152 $scope.enviarMail = function(factura) { 152 $scope.enviarMail = function(factura) {
153 focaModalService 153 focaModalService.mail(
154 .prompt({ 154 {
155 titulo: 'Ingrese los emails separados por coma para enviar comprobante', 155 titulo: 'Enviar comprobante',
156 value: factura.cliente.MAIL 156 descarga: {
157 }) 157 nombre: factura.numeroFactura + '.pdf',
158 .then(function(res) { 158 url: '/mail/comprobante/descargar',
159 return focaModalFacturaService.enviarFacturaPorMail(res, factura); 159 },
160 }) 160 envio: {
161 .then(function() { 161 mailCliente: factura.cliente.MAIL,
162 focaModalService.alert('Mensaje enviado correctamente'); 162 url: '/mail/comprobante'
163 }); 163 },
164 options: {
165 factura: factura
166 }
167 }
168 );
164 }; 169 };
165 170
166 function calcularPages(paginaActual) { 171 function calcularPages(paginaActual) {
167 var paginas = []; 172 var paginas = [];
168 paginas.push(paginaActual); 173 paginas.push(paginaActual);
169 174
170 if (paginaActual - 1 > 1) { 175 if (paginaActual - 1 > 1) {
171 176
172 paginas.unshift(paginaActual - 1); 177 paginas.unshift(paginaActual - 1);
173 if (paginaActual - 2 > 1) { 178 if (paginaActual - 2 > 1) {
174 paginas.unshift(paginaActual - 2); 179 paginas.unshift(paginaActual - 2);
175 } 180 }
176 } 181 }
177 182
178 if (paginaActual + 1 < $scope.lastPage) { 183 if (paginaActual + 1 < $scope.lastPage) {
179 paginas.push(paginaActual + 1); 184 paginas.push(paginaActual + 1);
180 if (paginaActual + 2 < $scope.lastPage) { 185 if (paginaActual + 2 < $scope.lastPage) {
181 paginas.push(paginaActual + 2); 186 paginas.push(paginaActual + 2);
182 } 187 }
183 } 188 }
184 189
185 if (paginaActual !== 1) { 190 if (paginaActual !== 1) {
186 paginas.unshift(1); 191 paginas.unshift(1);
187 } 192 }
188 193
189 if (paginaActual !== $scope.lastPage) { 194 if (paginaActual !== $scope.lastPage) {
190 paginas.push($scope.lastPage); 195 paginas.push($scope.lastPage);
191 } 196 }
192 197
193 return paginas; 198 return paginas;
194 } 199 }
195 200
196 function primera() { 201 function primera() {
197 $scope.selectedFactura = 0; 202 $scope.selectedFactura = 0;
198 } 203 }
199 204
200 function anterior() { 205 function anterior() {
201 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { 206 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
202 retrocederPagina(); 207 retrocederPagina();
203 } else { 208 } else {
204 $scope.selectedFactura--; 209 $scope.selectedFactura--;
205 } 210 }
206 } 211 }
207 212
208 function siguiente() { 213 function siguiente() {
209 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { 214 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
210 $scope.selectedFactura++; 215 $scope.selectedFactura++;
211 } else { 216 } else {
212 avanzarPagina(); 217 avanzarPagina();
213 } 218 }
214 } 219 }
215 220
216 function retrocederPagina() { 221 function retrocederPagina() {
217 if ($scope.currentPage > 1) { 222 if ($scope.currentPage > 1) {
218 $scope.selectPage($scope.currentPage - 1); 223 $scope.selectPage($scope.currentPage - 1);
219 $scope.selectedFactura = $scope.numPerPage - 1; 224 $scope.selectedFactura = $scope.numPerPage - 1;
220 } 225 }
221 } 226 }
222 227
223 function avanzarPagina() { 228 function avanzarPagina() {
224 if ($scope.currentPage < $scope.lastPage) { 229 if ($scope.currentPage < $scope.lastPage) {
225 $scope.selectPage($scope.currentPage + 1); 230 $scope.selectPage($scope.currentPage + 1);
226 $scope.selectedFactura = 0; 231 $scope.selectedFactura = 0;
227 } 232 }
228 } 233 }
229 234
230 function calcularSaldos(facturas) { 235 function calcularSaldos(facturas) {
231 var saldo = 0; 236 var saldo = 0;
232 237
233 facturas.forEach(function(factura) { 238 facturas.forEach(function(factura) {
234 if (factura.TCO === 'CI' || 239 if (factura.TCO === 'CI' ||
235 factura.TCO === 'FT' || 240 factura.TCO === 'FT' ||
236 factura.TCO === 'ND'){ 241 factura.TCO === 'ND'){
237 factura.IPA = factura.IPA * -1; 242 factura.IPA = factura.IPA * -1;
238 }else{ 243 }else{
239 factura.IPA = factura.IPA; 244 factura.IPA = factura.IPA;
240 } 245 }
241 saldo += factura.IPA; 246 saldo += factura.IPA;
242 factura.saldo = saldo; 247 factura.saldo = saldo;
243 factura.saldo_show = Math.abs(saldo); 248 factura.saldo_show = Math.abs(saldo);
244 factura.IPA_SHOW = Math.abs(factura.IPA); 249 factura.IPA_SHOW = Math.abs(factura.IPA);
245 }); 250 });
246 251
247 return facturas; 252 return facturas;
248 } 253 }
249 254
250 $scope.busquedaPress(13); 255 $scope.busquedaPress(13);
251 } 256 }
252 ] 257 ]
253 ); 258 );
254 259
src/views/foca-modal-factura.html
1 <div class="modal-header py-1"> 1 <div class="modal-header py-1">
2 <div class="row w-100"> 2 <div class="row w-100">
3 <div class="col-lg-6"> 3 <div class="col-lg-6">
4 <h5 class="modal-title">Búsqueda de Comprobantes</h5> 4 <h5 class="modal-title">Búsqueda de Comprobantes</h5>
5 </div> 5 </div>
6 </div> 6 </div>
7 </div> 7 </div>
8 <div class="modal-body ladda-w-100" 8 <div class="modal-body d-flex"
9 id="modal-body" 9 id="modal-body">
10 ladda="!primerBusqueda" 10 <div
11 data-spinner-color="#000000" 11 ladda="!primerBusqueda"
12 data-spinner-size="30"> 12 data-spinner-color="#000000"
13 <table ng-show="primerBusqueda" class="table table-striped table-sm"> 13 data-spinner-size="30"
14 <thead> 14 class="w-100 ladda-w-100">
15 <tr> 15 <table ng-show="primerBusqueda" class="table table-striped table-sm">
16 <th>Comprobante</th> 16 <thead>
17 <th>Vencimiento</th> 17 <tr>
18 <th class="text-right">Importe</th> 18 <th>Comprobante</th>
19 <th class="text-right">Saldo</th> 19 <th>Vencimiento</th>
20 <th class="text-right"></th> 20 <th class="text-right">Importe</th>
21 <th class="text-right"></th> 21 <th class="text-right">Saldo</th>
22 <th class="text-right"></th> 22 <th class="text-right"></th>
23 </tr> 23 <th class="text-right"></th>
24 </thead> 24 <th class="text-right"></th>
25 <tbody> 25 </tr>
26 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> 26 </thead>
27 <td colspan="5"> 27 <tbody>
28 No se encontraron resultados. 28 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
29 </td> 29 <td colspan="5">
30 </tr> 30 No se encontraron resultados.
31 <tr class="selectable" 31 </td>
32 ng-repeat="(key, factura) in currentPageFacturas"> 32 </tr>
33 <td ng-click="factura.checked = !factura.checked">{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td> 33 <tr class="selectable"
34 <td ng-click="factura.checked = !factura.checked">{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> 34 ng-repeat="(key, factura) in currentPageFacturas">
35 <td class="text-right" 35 <td ng-click="factura.checked = !factura.checked">{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td>
36 ng-click="factura.checked = !factura.checked"> 36 <td ng-click="factura.checked = !factura.checked">{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td>
37 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }} 37 <td class="text-right"
38 <span ng-class="{'invisible': factura.IPA >= 0}">-</span> 38 ng-click="factura.checked = !factura.checked">
39 </td> 39 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }}
40 <td class="text-right" 40 <span ng-class="{'invisible': factura.IPA >= 0}">-</span>
41 ng-click="factura.checked = !factura.checked"> 41 </td>
42 {{ factura.saldo_show | number:2 }} 42 <td class="text-right"
43 <span ng-class="{'invisible': factura.saldo >= 0}">-</span> 43 ng-click="factura.checked = !factura.checked">
44 </td> 44 {{ factura.saldo_show | number:2 }}
45 <td class="text-right"> 45 <span ng-class="{'invisible': factura.saldo >= 0}">-</span>
46 <input 46 </td>
47 ng-class="{ 47 <td class="text-right">
48 'btn-secondary': selectedFactura != key, 48 <input
49 'btn-primary': selectedFactura == key}" 49 ng-class="{
50 ng-keydown="itemFactura($event.keyCode)" 50 'btn-secondary': selectedFactura != key,
51 foca-focus="selectedFactura == {{key}}" 51 'btn-primary': selectedFactura == key}"
52 type="checkbox" 52 ng-keydown="itemFactura($event.keyCode)"
53 ng-model="factura.checked" 53 foca-focus="selectedFactura == {{key}}"
54 /> 54 type="checkbox"
55 </td> 55 ng-model="factura.checked"
56 <td> 56 />
57 <button 57 </td>
58 class="btn p-1" 58 <td>
59 ng-click="verFactura(factura)" 59 <button
60 title="Ver comprobante" 60 class="btn p-1"
61 > 61 ng-click="verFactura(factura)"
62 <i class="fa fa-eye" aria-hidden="true"></i> 62 title="Ver comprobante"
63 </button> 63 >
64 </td> 64 <i class="fa fa-eye" aria-hidden="true"></i>
65 <td> 65 </button>
66 <button 66 </td>
67 class="btn p-1" 67 <td>
68 ng-click="enviarMail(factura)" 68 <button
69 title="Enviar comprobante por mail" 69 class="btn p-1"
70 > 70 ng-click="enviarMail(factura)"
71 <i class="fa fa-envelope-o" aria-hidden="true"></i> 71 title="Enviar comprobante por mail"
72 </button> 72 >
73 </td> 73 <i class="fa fa-envelope-o" aria-hidden="true"></i>
74 </tr> 74 </button>
75 </tbody> 75 </td>
76 </table> 76 </tr>
77 </tbody>
78 </table>
79 </div>
77 </div> 80 </div>
78 <div class="modal-footer py-1"> 81 <div class="modal-footer py-1">
79 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> 82 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto">
80 <ul class="pagination pagination-sm justify-content mb-0"> 83 <ul class="pagination pagination-sm justify-content mb-0">
81 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 84 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
82 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 85 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
83 <span aria-hidden="true">&laquo;</span> 86 <span aria-hidden="true">&laquo;</span>
84 <span class="sr-only">Anterior</span> 87 <span class="sr-only">Anterior</span>
85 </a> 88 </a>
86 </li> 89 </li>
87 <li 90 <li
88 class="page-item" 91 class="page-item"
89 ng-repeat="pagina in paginas" 92 ng-repeat="pagina in paginas"
90 ng-class="{'active': pagina == currentPage}" 93 ng-class="{'active': pagina == currentPage}"
91 > 94 >
92 <a 95 <a
93 class="page-link" 96 class="page-link"
94 href="javascript:void();" 97 href="javascript:void();"
95 ng-click="selectPage(pagina)" 98 ng-click="selectPage(pagina)"
96 ng-bind="pagina" 99 ng-bind="pagina"
97 ></a> 100 ></a>
98 </li> 101 </li>
99 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 102 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
100 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 103 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
101 <span aria-hidden="true">&raquo;</span> 104 <span aria-hidden="true">&raquo;</span>
102 <span class="sr-only">Siguiente</span> 105 <span class="sr-only">Siguiente</span>
103 </a> 106 </a>
104 </li> 107 </li>
105 </ul> 108 </ul>
106 </nav> 109 </nav>
107 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 110 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
108 <button 111 <button
109 class="btn btn-sm btn-primary" 112 class="btn btn-sm btn-primary"
110 type="button" 113 type="button"
111 ng-click="aceptar()" 114 ng-click="aceptar()"
112 ng-disabled="tieneAlMenosUno()" 115 ng-disabled="tieneAlMenosUno()"
113 >Aceptar</button> 116 >Aceptar</button>
114 </div> 117 </div>
115 118