Commit 28be27837d43040bd34b01f83d4e3ce2a0aceb9f

Authored by Nicolás Guarnieri
1 parent ba29d625c5
Exists in master and in 1 other branch develop

mejor muestra de datos

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 function($filter, $scope, $uibModalInstance, 9 function($filter, $scope, $uibModalInstance,
10 focaModalFacturaService, parametrosFactura 10 focaModalFacturaService, parametrosFactura
11 ) { 11 ) {
12 var fecha = new Date(); 12 var fecha = new Date();
13 $scope.fechaHasta = new Date(); 13 $scope.fechaHasta = new Date();
14 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 14 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
15 $scope.filters = ''; 15 $scope.filters = '';
16 $scope.facturas = []; 16 $scope.facturas = [];
17 $scope.primerBusqueda = false; 17 $scope.primerBusqueda = false;
18 $scope.searchLoading = false; 18 $scope.searchLoading = false;
19 $scope.parametrosFactura = parametrosFactura; 19 $scope.parametrosFactura = parametrosFactura;
20 // pagination 20 // pagination
21 $scope.numPerPage = 10; 21 $scope.numPerPage = 10;
22 $scope.currentPage = 1; 22 $scope.currentPage = 1;
23 $scope.filteredFacturas = []; 23 $scope.filteredFacturas = [];
24 $scope.currentPageFacturas = []; 24 $scope.currentPageFacturas = [];
25 $scope.selectedFactura = -1; 25 $scope.selectedFactura = -1;
26 26
27 //METODOS 27 //METODOS
28 $scope.busquedaPress = function(key) { 28 $scope.busquedaPress = function(key) {
29 if (key === 13) { 29 if (key === 13) {
30 //TODO Validaciones con alertas 30 //TODO Validaciones con alertas
31 if(!$scope.fechaDesde) { 31 if(!$scope.fechaDesde) {
32 alert('INGRESE FECHA DESDE'); 32 alert('INGRESE FECHA DESDE');
33 return; 33 return;
34 } 34 }
35 if(!$scope.fechaHasta) { 35 if(!$scope.fechaHasta) {
36 alert('INGRESE FECHA HASTA'); 36 alert('INGRESE FECHA HASTA');
37 return; 37 return;
38 } 38 }
39 if($scope.fechaDesde > $scope.fechaHasta) { 39 if($scope.fechaDesde > $scope.fechaHasta) {
40 alert('La fecha desde no puede ser mayor a la fecha hasta'); 40 alert('La fecha desde no puede ser mayor a la fecha hasta');
41 return; 41 return;
42 } 42 }
43 $scope.searchLoading = true; 43 $scope.searchLoading = true;
44 //TODO hacer filtro de fecha 44 //TODO hacer filtro de fecha
45 focaModalFacturaService 45 focaModalFacturaService
46 .getFacturasByIdCliente( 46 .getFacturasByIdCliente(
47 parametrosFactura.cliente, 47 parametrosFactura.cliente,
48 '2001-01-01', 48 '2001-01-01',
49 '2100-12-31' 49 '2100-12-31'
50 ) 50 )
51 .then(llenarDatos); 51 .then(llenarDatos);
52 } 52 }
53 }; 53 };
54 54
55 $scope.aceptar = function() { 55 $scope.aceptar = function() {
56 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 56 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
57 $uibModalInstance.close(result); 57 $uibModalInstance.close(result);
58 }; 58 };
59 59
60 $scope.tieneAlMenosUno = function() { 60 $scope.tieneAlMenosUno = function() {
61 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 61 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
62 return !result.length; 62 return !result.length;
63 }; 63 };
64 64
65 function llenarDatos(res) { 65 function llenarDatos(res) {
66 $scope.facturas = []; 66 $scope.facturas = [];
67 $scope.filteredFacturas = []; 67 $scope.filteredFacturas = [];
68 $scope.currentPageFacturas = []; 68 $scope.currentPageFacturas = [];
69 $scope.selectedFactura = -1; 69 $scope.selectedFactura = -1;
70 $scope.searchLoading = false; 70 $scope.searchLoading = false;
71 $scope.primerBusqueda = true; 71 $scope.primerBusqueda = true;
72 $scope.facturas = calcularSaldos(res.data); 72 $scope.facturas = calcularSaldos(res.data);
73 $scope.search(); 73 $scope.search();
74 primera(); 74 primera();
75 } 75 }
76 $scope.search = function() { 76 $scope.search = function() {
77 if($scope.facturas.length > 0) { 77 if($scope.facturas.length > 0) {
78 $scope.filteredFacturas = $filter('filter')( 78 $scope.filteredFacturas = $filter('filter')(
79 $scope.facturas, 79 $scope.facturas,
80 {$: $scope.filters} 80 {$: $scope.filters}
81 ); 81 );
82 82
83 $scope.lastPage = Math.ceil( 83 $scope.lastPage = Math.ceil(
84 $scope.filteredFacturas.length / $scope.numPerPage 84 $scope.filteredFacturas.length / $scope.numPerPage
85 ); 85 );
86 86
87 $scope.resetPage(); 87 $scope.resetPage();
88 } 88 }
89 }; 89 };
90 90
91 $scope.resetPage = function() { 91 $scope.resetPage = function() {
92 $scope.currentPage = 1; 92 $scope.currentPage = 1;
93 $scope.selectPage(1); 93 $scope.selectPage(1);
94 }; 94 };
95 95
96 $scope.selectPage = function(page) { 96 $scope.selectPage = function(page) {
97 var start = (page - 1) * $scope.numPerPage; 97 var start = (page - 1) * $scope.numPerPage;
98 var end = start + $scope.numPerPage; 98 var end = start + $scope.numPerPage;
99 $scope.paginas = []; 99 $scope.paginas = [];
100 $scope.paginas = calcularPages(page); 100 $scope.paginas = calcularPages(page);
101 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); 101 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
102 $scope.currentPage = page; 102 $scope.currentPage = page;
103 }; 103 };
104 104
105 $scope.cancel = function() { 105 $scope.cancel = function() {
106 $uibModalInstance.dismiss('cancel'); 106 $uibModalInstance.dismiss('cancel');
107 }; 107 };
108 108
109 $scope.busquedaDown = function(key) { 109 $scope.busquedaDown = function(key) {
110 if (key === 40) { 110 if (key === 40) {
111 primera(key); 111 primera(key);
112 } 112 }
113 }; 113 };
114 114
115 $scope.itemFactura = function(key) { 115 $scope.itemFactura = function(key) {
116 if (key === 38) { 116 if (key === 38) {
117 anterior(key); 117 anterior(key);
118 } 118 }
119 119
120 if (key === 40) { 120 if (key === 40) {
121 siguiente(key); 121 siguiente(key);
122 } 122 }
123 123
124 if (key === 37) { 124 if (key === 37) {
125 retrocederPagina(); 125 retrocederPagina();
126 } 126 }
127 127
128 if (key === 39) { 128 if (key === 39) {
129 avanzarPagina(); 129 avanzarPagina();
130 } 130 }
131 }; 131 };
132 132
133 function calcularPages(paginaActual) { 133 function calcularPages(paginaActual) {
134 var paginas = []; 134 var paginas = [];
135 paginas.push(paginaActual); 135 paginas.push(paginaActual);
136 136
137 if (paginaActual - 1 > 1) { 137 if (paginaActual - 1 > 1) {
138 138
139 paginas.unshift(paginaActual - 1); 139 paginas.unshift(paginaActual - 1);
140 if (paginaActual - 2 > 1) { 140 if (paginaActual - 2 > 1) {
141 paginas.unshift(paginaActual - 2); 141 paginas.unshift(paginaActual - 2);
142 } 142 }
143 } 143 }
144 144
145 if (paginaActual + 1 < $scope.lastPage) { 145 if (paginaActual + 1 < $scope.lastPage) {
146 paginas.push(paginaActual + 1); 146 paginas.push(paginaActual + 1);
147 if (paginaActual + 2 < $scope.lastPage) { 147 if (paginaActual + 2 < $scope.lastPage) {
148 paginas.push(paginaActual + 2); 148 paginas.push(paginaActual + 2);
149 } 149 }
150 } 150 }
151 151
152 if (paginaActual !== 1) { 152 if (paginaActual !== 1) {
153 paginas.unshift(1); 153 paginas.unshift(1);
154 } 154 }
155 155
156 if (paginaActual !== $scope.lastPage) { 156 if (paginaActual !== $scope.lastPage) {
157 paginas.push($scope.lastPage); 157 paginas.push($scope.lastPage);
158 } 158 }
159 159
160 return paginas; 160 return paginas;
161 } 161 }
162 162
163 function primera() { 163 function primera() {
164 $scope.selectedFactura = 0; 164 $scope.selectedFactura = 0;
165 } 165 }
166 166
167 function anterior() { 167 function anterior() {
168 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { 168 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
169 retrocederPagina(); 169 retrocederPagina();
170 } else { 170 } else {
171 $scope.selectedFactura--; 171 $scope.selectedFactura--;
172 } 172 }
173 } 173 }
174 174
175 function siguiente() { 175 function siguiente() {
176 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { 176 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
177 $scope.selectedFactura++; 177 $scope.selectedFactura++;
178 } else { 178 } else {
179 avanzarPagina(); 179 avanzarPagina();
180 } 180 }
181 } 181 }
182 182
183 function retrocederPagina() { 183 function retrocederPagina() {
184 if ($scope.currentPage > 1) { 184 if ($scope.currentPage > 1) {
185 $scope.selectPage($scope.currentPage - 1); 185 $scope.selectPage($scope.currentPage - 1);
186 $scope.selectedFactura = $scope.numPerPage - 1; 186 $scope.selectedFactura = $scope.numPerPage - 1;
187 } 187 }
188 } 188 }
189 189
190 function avanzarPagina() { 190 function avanzarPagina() {
191 if ($scope.currentPage < $scope.lastPage) { 191 if ($scope.currentPage < $scope.lastPage) {
192 $scope.selectPage($scope.currentPage + 1); 192 $scope.selectPage($scope.currentPage + 1);
193 $scope.selectedFactura = 0; 193 $scope.selectedFactura = 0;
194 } 194 }
195 } 195 }
196 196
197 function calcularSaldos(facturas) { 197 function calcularSaldos(facturas) {
198 var saldo = 0; 198 var saldo = 0;
199 199
200 facturas.forEach(function(factura) { 200 facturas.forEach(function(factura) {
201 if (factura.TCO === 'CI' || 201 if (factura.TCO === 'CI' ||
202 factura.TCO === 'FT' || 202 factura.TCO === 'FT' ||
203 factura.TCO === 'ND'){ 203 factura.TCO === 'ND'){
204 factura.IPA = factura.IPA * -1; 204 factura.IPA = factura.IPA * -1;
205 }else{ 205 }else{
206 factura.IPA = factura.IPA; 206 factura.IPA = factura.IPA;
207 } 207 }
208 saldo += factura.IPA; 208 saldo += factura.IPA;
209 factura.saldo = saldo; 209 factura.saldo = saldo;
210 factura.saldo_show = Math.abs(saldo);
211 factura.IPA_SHOW = Math.abs(factura.IPA);
210 }); 212 });
211 213
212 return facturas; 214 return facturas;
213 } 215 }
214 216
215 $scope.busquedaPress(13); 217 $scope.busquedaPress(13);
216 } 218 }
217 ] 219 ]
218 ); 220 );
219 221
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" id="modal-body"> 8 <div class="modal-body" id="modal-body">
9 <table ng-show="primerBusqueda" class="table table-striped table-sm"> 9 <table ng-show="primerBusqueda" class="table table-striped table-sm">
10 <thead> 10 <thead>
11 <tr> 11 <tr>
12 <th>Comprobante</th> 12 <th>Comprobante</th>
13 <th>Vencimiento</th> 13 <th>Vencimiento</th>
14 <th class="text-right">Importe</th> 14 <th class="text-right">Importe</th>
15 <th class="text-right">Saldo</th> 15 <th class="text-right">Saldo</th>
16 <th class="text-right"></th> 16 <th class="text-right"></th>
17 </tr> 17 </tr>
18 </thead> 18 </thead>
19 <tbody> 19 <tbody>
20 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> 20 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
21 <td colspan="5"> 21 <td colspan="5">
22 No se encontraron resultados. 22 No se encontraron resultados.
23 </td> 23 </td>
24 </tr> 24 </tr>
25 <tr class="selectable" 25 <tr class="selectable"
26 ng-repeat="(key,factura) in currentPageFacturas" 26 ng-repeat="(key,factura) in currentPageFacturas"
27 ng-click="factura.checked = !factura.checked"> 27 ng-click="factura.checked = !factura.checked">
28 <td>{{factura.numeroFactura}} {{factura.FEP | date : 'dd/MM/yyyy' : 'GMT'}}</td> 28 <td>{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td>
29 <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> 29 <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td>
30 <td class="text-right"> 30 <td class="text-right">
31 <span ng-if="factura.IPA >= 0">+</span>{{(factura.IPA / parametrosFactura.cotizacion) | number:2}} 31 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }}
32 <span ng-if="factura.IPA < 0"> - </span>
33 <span ng-if="factura.IPA > 0" style="color: rgba(0,0,0,0);"> + </span>
32 </td> 34 </td>
33 <td class="text-right"> 35 <td class="text-right">
34 <span ng-if="factura.saldo >= 0">+</span>{{factura.saldo | number:2}} 36 {{ factura.saldo_show | number:2 }}
37 <span ng-if="factura.saldo < 0"> - </span>
38 <span ng-if="factura.saldo > 0" style="color: rgba(0,0,0,0);"> + </span>
35 </td> 39 </td>
36 <td class="text-right"> 40 <td class="text-right">
37 <input 41 <input
38 ng-class="{ 42 ng-class="{
39 'btn-secondary': selectedFactura != key, 43 'btn-secondary': selectedFactura != key,
40 'btn-primary': selectedFactura == key}" 44 'btn-primary': selectedFactura == key}"
41 ng-keydown="itemFactura($event.keyCode)" 45 ng-keydown="itemFactura($event.keyCode)"
42 foca-focus="selectedFactura == {{key}}" 46 foca-focus="selectedFactura == {{key}}"
43 type="checkbox" 47 type="checkbox"
44 ng-model="factura.checked" 48 ng-model="factura.checked"
45 /> 49 />
46 </td> 50 </td>
47 </tr> 51 </tr>
48 </tbody> 52 </tbody>
49 </table> 53 </table>
50 </div> 54 </div>
51 <div class="modal-footer py-1"> 55 <div class="modal-footer py-1">
52 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> 56 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto">
53 <ul class="pagination pagination-sm justify-content mb-0"> 57 <ul class="pagination pagination-sm justify-content mb-0">
54 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 58 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
55 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 59 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
56 <span aria-hidden="true">&laquo;</span> 60 <span aria-hidden="true">&laquo;</span>
57 <span class="sr-only">Anterior</span> 61 <span class="sr-only">Anterior</span>
58 </a> 62 </a>
59 </li> 63 </li>
60 <li 64 <li
61 class="page-item" 65 class="page-item"
62 ng-repeat="pagina in paginas" 66 ng-repeat="pagina in paginas"
63 ng-class="{'active': pagina == currentPage}" 67 ng-class="{'active': pagina == currentPage}"
64 > 68 >
65 <a 69 <a
66 class="page-link" 70 class="page-link"
67 href="javascript:void();" 71 href="javascript:void();"
68 ng-click="selectPage(pagina)" 72 ng-click="selectPage(pagina)"
69 ng-bind="pagina" 73 ng-bind="pagina"
70 ></a> 74 ></a>
71 </li> 75 </li>
72 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 76 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
73 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 77 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
74 <span aria-hidden="true">&raquo;</span> 78 <span aria-hidden="true">&raquo;</span>
75 <span class="sr-only">Siguiente</span> 79 <span class="sr-only">Siguiente</span>
76 </a> 80 </a>
77 </li> 81 </li>
78 </ul> 82 </ul>
79 </nav> 83 </nav>
80 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 84 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
81 <button 85 <button
82 class="btn btn-sm btn-primary" 86 class="btn btn-sm btn-primary"
83 type="button" 87 type="button"
84 ng-click="aceptar()" 88 ng-click="aceptar()"
85 ng-disabled="tieneAlMenosUno()" 89 ng-disabled="tieneAlMenosUno()"
86 >Aceptar</button> 90 >Aceptar</button>
87 </div> 91 </div>
88 92