Commit 71810a12b963a9676237cdf3011b34fb1118f034

Authored by Nicolás Guarnieri
1 parent 2686889eb4
Exists in master

funcionamiento para acobypag_vencimiento

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(parametrosFactura.cliente, $scope.fechaDesde 46 .getFacturasByIdCliente(
47 .toISOString().split('.')[0], 47 parametrosFactura.cliente,
48 $scope.fechaHasta.toISOString().split('.')[0]) 48 '2001-01-01',
49 '2100-12-31'
50 )
49 .then(llenarDatos); 51 .then(llenarDatos);
50 } 52 }
51 }; 53 };
52 54
53 $scope.aceptar = function() { 55 $scope.aceptar = function() {
54 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 56 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
55 $uibModalInstance.close(result); 57 $uibModalInstance.close(result);
56 }; 58 };
57 59
58 $scope.tieneAlMenosUno = function() { 60 $scope.tieneAlMenosUno = function() {
59 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 61 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
60 return !result.length; 62 return !result.length;
61 }; 63 };
62 64
63 function llenarDatos(res) { 65 function llenarDatos(res) {
64 $scope.facturas = []; 66 $scope.facturas = [];
65 $scope.filteredFacturas = []; 67 $scope.filteredFacturas = [];
66 $scope.currentPageFacturas = []; 68 $scope.currentPageFacturas = [];
67 $scope.selectedFactura = -1; 69 $scope.selectedFactura = -1;
68 $scope.searchLoading = false; 70 $scope.searchLoading = false;
69 $scope.primerBusqueda = true; 71 $scope.primerBusqueda = true;
70 $scope.facturas = res.data; 72 $scope.facturas = res.data;
71 $scope.search(); 73 $scope.search();
72 primera(); 74 primera();
73 } 75 }
74 $scope.search = function() { 76 $scope.search = function() {
75 if($scope.facturas.length > 0) { 77 if($scope.facturas.length > 0) {
76 $scope.filteredFacturas = $filter('filter')( 78 $scope.filteredFacturas = $filter('filter')(
77 $scope.facturas, 79 $scope.facturas,
78 {$: $scope.filters} 80 {$: $scope.filters}
79 ); 81 );
80 82
81 $scope.lastPage = Math.ceil( 83 $scope.lastPage = Math.ceil(
82 $scope.filteredFacturas.length / $scope.numPerPage 84 $scope.filteredFacturas.length / $scope.numPerPage
83 ); 85 );
84 86
85 $scope.resetPage(); 87 $scope.resetPage();
86 } 88 }
87 }; 89 };
88 90
89 $scope.resetPage = function() { 91 $scope.resetPage = function() {
90 $scope.currentPage = 1; 92 $scope.currentPage = 1;
91 $scope.selectPage(1); 93 $scope.selectPage(1);
92 }; 94 };
93 95
94 $scope.selectPage = function(page) { 96 $scope.selectPage = function(page) {
95 var start = (page - 1) * $scope.numPerPage; 97 var start = (page - 1) * $scope.numPerPage;
96 var end = start + $scope.numPerPage; 98 var end = start + $scope.numPerPage;
97 $scope.paginas = []; 99 $scope.paginas = [];
98 $scope.paginas = calcularPages(page); 100 $scope.paginas = calcularPages(page);
99 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); 101 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
100 $scope.currentPage = page; 102 $scope.currentPage = page;
101 }; 103 };
102 104
103 $scope.cancel = function() { 105 $scope.cancel = function() {
104 $uibModalInstance.dismiss('cancel'); 106 $uibModalInstance.dismiss('cancel');
105 }; 107 };
106 108
107 $scope.busquedaDown = function(key) { 109 $scope.busquedaDown = function(key) {
108 if (key === 40) { 110 if (key === 40) {
109 primera(key); 111 primera(key);
110 } 112 }
111 }; 113 };
112 114
113 $scope.itemFactura = function(key) { 115 $scope.itemFactura = function(key) {
114 if (key === 38) { 116 if (key === 38) {
115 anterior(key); 117 anterior(key);
116 } 118 }
117 119
118 if (key === 40) { 120 if (key === 40) {
119 siguiente(key); 121 siguiente(key);
120 } 122 }
121 123
122 if (key === 37) { 124 if (key === 37) {
123 retrocederPagina(); 125 retrocederPagina();
124 } 126 }
125 127
126 if (key === 39) { 128 if (key === 39) {
127 avanzarPagina(); 129 avanzarPagina();
128 } 130 }
129 }; 131 };
130 132
131 function calcularPages(paginaActual) { 133 function calcularPages(paginaActual) {
132 var paginas = []; 134 var paginas = [];
133 paginas.push(paginaActual); 135 paginas.push(paginaActual);
134 136
135 if (paginaActual - 1 > 1) { 137 if (paginaActual - 1 > 1) {
136 138
137 paginas.unshift(paginaActual - 1); 139 paginas.unshift(paginaActual - 1);
138 if (paginaActual - 2 > 1) { 140 if (paginaActual - 2 > 1) {
139 paginas.unshift(paginaActual - 2); 141 paginas.unshift(paginaActual - 2);
140 } 142 }
141 } 143 }
142 144
143 if (paginaActual + 1 < $scope.lastPage) { 145 if (paginaActual + 1 < $scope.lastPage) {
144 paginas.push(paginaActual + 1); 146 paginas.push(paginaActual + 1);
145 if (paginaActual + 2 < $scope.lastPage) { 147 if (paginaActual + 2 < $scope.lastPage) {
146 paginas.push(paginaActual + 2); 148 paginas.push(paginaActual + 2);
147 } 149 }
148 } 150 }
149 151
150 if (paginaActual !== 1) { 152 if (paginaActual !== 1) {
151 paginas.unshift(1); 153 paginas.unshift(1);
152 } 154 }
153 155
154 if (paginaActual !== $scope.lastPage) { 156 if (paginaActual !== $scope.lastPage) {
155 paginas.push($scope.lastPage); 157 paginas.push($scope.lastPage);
156 } 158 }
157 159
158 return paginas; 160 return paginas;
159 } 161 }
160 162
161 function primera() { 163 function primera() {
162 $scope.selectedFactura = 0; 164 $scope.selectedFactura = 0;
163 } 165 }
164 166
165 function anterior() { 167 function anterior() {
166 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { 168 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
167 retrocederPagina(); 169 retrocederPagina();
168 } else { 170 } else {
169 $scope.selectedFactura--; 171 $scope.selectedFactura--;
170 } 172 }
171 } 173 }
172 174
173 function siguiente() { 175 function siguiente() {
174 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { 176 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
175 $scope.selectedFactura++; 177 $scope.selectedFactura++;
176 } else { 178 } else {
177 avanzarPagina(); 179 avanzarPagina();
178 } 180 }
179 } 181 }
180 182
181 function retrocederPagina() { 183 function retrocederPagina() {
182 if ($scope.currentPage > 1) { 184 if ($scope.currentPage > 1) {
183 $scope.selectPage($scope.currentPage - 1); 185 $scope.selectPage($scope.currentPage - 1);
184 $scope.selectedFactura = $scope.numPerPage - 1; 186 $scope.selectedFactura = $scope.numPerPage - 1;
185 } 187 }
186 } 188 }
187 189
188 function avanzarPagina() { 190 function avanzarPagina() {
189 if ($scope.currentPage < $scope.lastPage) { 191 if ($scope.currentPage < $scope.lastPage) {
190 $scope.selectPage($scope.currentPage + 1); 192 $scope.selectPage($scope.currentPage + 1);
191 $scope.selectedFactura = 0; 193 $scope.selectedFactura = 0;
192 } 194 }
193 } 195 }
194 } 196 }
195 ] 197 ]
196 ); 198 );
197 199
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 Facturas</h5> 4 <h5 class="modal-title">Búsqueda de Comprobantes</h5>
5 </div> 5 </div>
6 <div class="input-group col-lg-6 pr-0 my-2"> 6 <div class="input-group col-lg-6 pr-0 my-2">
7 <input 7 <input
8 ladda="searchLoading" 8 ladda="searchLoading"
9 type="text" 9 type="text"
10 class="form-control form-control-sm" 10 class="form-control form-control-sm"
11 placeholder="Búsqueda" 11 placeholder="Búsqueda"
12 ng-model="filters" 12 ng-model="filters"
13 ng-change="search()" 13 ng-change="search()"
14 ng-keydown="busquedaDown($event.keyCode)" 14 ng-keydown="busquedaDown($event.keyCode)"
15 ng-keypress="busquedaPress($event.keyCode)" 15 ng-keypress="busquedaPress($event.keyCode)"
16 foca-focus="selectedFactura == -1" 16 foca-focus="selectedFactura == -1"
17 ng-focus="selectedFactura = -1" 17 ng-focus="selectedFactura = -1"
18 teclado-virtual 18 teclado-virtual
19 /> 19 />
20 <div class="input-group-append"> 20 <div class="input-group-append">
21 <button 21 <button
22 ladda="searchLoading" 22 ladda="searchLoading"
23 class="btn btn-outline-secondary" 23 class="btn btn-outline-secondary"
24 type="button" 24 type="button"
25 ng-click="busquedaPress(13)" 25 ng-click="busquedaPress(13)"
26 > 26 >
27 <i class="fa fa-search" aria-hidden="true"></i> 27 <i class="fa fa-search" aria-hidden="true"></i>
28 </button> 28 </button>
29 </div> 29 </div>
30 </div> 30 </div>
31 </div> 31 </div>
32 </div> 32 </div>
33 <div class="modal-body" id="modal-body"> 33 <div class="modal-body" id="modal-body">
34 <div ng-show="!primerBusqueda"> 34 <div ng-show="!primerBusqueda">
35 Debe realizar una primer búsqueda. 35 Debe realizar una primer búsqueda.
36 </div> 36 </div>
37 37
38 <table ng-show="primerBusqueda" class="table table-striped table-sm"> 38 <table ng-show="primerBusqueda" class="table table-striped table-sm">
39 <thead> 39 <thead>
40 <tr> 40 <tr>
41 <th>Cliente</th>
42 <th>Fecha</th> 41 <th>Fecha</th>
43 <th>Nro</th> 42 <th>Nro</th>
44 <th>Importe</th> 43 <th class="text-right">Importe</th>
45 <th></th> 44 <th class="text-right"></th>
46 </tr> 45 </tr>
47 </thead> 46 </thead>
48 <tbody> 47 <tbody>
49 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> 48 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
50 <td colspan="5"> 49 <td colspan="5">
51 No se encontraron resultados. 50 No se encontraron resultados.
52 </td> 51 </td>
53 </tr> 52 </tr>
54 <tr class="selectable" 53 <tr class="selectable"
55 ng-repeat="(key,factura) in currentPageFacturas"> 54 ng-repeat="(key,factura) in currentPageFacturas">
56 <td ng-bind="factura.cliente.NOM"></td>
57 <td ng-bind="factura.FEP | date : 'dd/MM/yyyy'"></td> 55 <td ng-bind="factura.FEP | date : 'dd/MM/yyyy'"></td>
58 <td ng-bind= 56 <td ng-bind= "factura.numeroFactura"></td>
59 "(factura.TCO + '-' + factura.TIP + '-' + factura.SUC + '-' + factura.NCO)">
60 </td>
61 <td 57 <td
62 class="text-right" 58 class="text-right"
63 ng-bind="(factura.IPA / parametrosFactura.cotizacion) | 59 ng-bind="(factura.IPA / parametrosFactura.cotizacion) |
64 currency: parametrosFactura.simbolo"></td> 60 currency: parametrosFactura.simbolo"></td>
65 <td><input 61 <td class="text-right">
62 <input
66 ng-class="{ 63 ng-class="{
67 'btn-secondary': selectedFactura != key, 64 'btn-secondary': selectedFactura != key,
68 'btn-primary': selectedFactura == key}" 65 'btn-primary': selectedFactura == key}"
69 ng-keydown="itemFactura($event.keyCode)" 66 ng-keydown="itemFactura($event.keyCode)"
70 foca-focus="selectedFactura == {{key}}" 67 foca-focus="selectedFactura == {{key}}"
71 type="checkbox" 68 type="checkbox"
72 ng-model="factura.checked"/> 69 ng-model="factura.checked"
70 />
73 </td> 71 </td>
74 </tr> 72 </tr>
75 </tbody> 73 </tbody>
76 </table> 74 </table>
77 </div> 75 </div>
78 <div class="modal-footer py-1"> 76 <div class="modal-footer py-1">
79 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> 77 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto">
80 <ul class="pagination pagination-sm justify-content mb-0"> 78 <ul class="pagination pagination-sm justify-content mb-0">
81 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 79 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
82 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 80 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
83 <span aria-hidden="true">&laquo;</span> 81 <span aria-hidden="true">&laquo;</span>
84 <span class="sr-only">Anterior</span> 82 <span class="sr-only">Anterior</span>
85 </a> 83 </a>
86 </li> 84 </li>
87 <li 85 <li
88 class="page-item" 86 class="page-item"
89 ng-repeat="pagina in paginas" 87 ng-repeat="pagina in paginas"
90 ng-class="{'active': pagina == currentPage}" 88 ng-class="{'active': pagina == currentPage}"
91 > 89 >
92 <a 90 <a
93 class="page-link" 91 class="page-link"
94 href="javascript:void();" 92 href="javascript:void();"
95 ng-click="selectPage(pagina)" 93 ng-click="selectPage(pagina)"
96 ng-bind="pagina" 94 ng-bind="pagina"
97 ></a> 95 ></a>
98 </li> 96 </li>
99 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 97 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
100 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 98 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
101 <span aria-hidden="true">&raquo;</span> 99 <span aria-hidden="true">&raquo;</span>
102 <span class="sr-only">Siguiente</span> 100 <span class="sr-only">Siguiente</span>
103 </a> 101 </a>
104 </li> 102 </li>
105 </ul> 103 </ul>
106 </nav> 104 </nav>
107 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 105 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
108 <button 106 <button
109 class="btn btn-sm btn-primary" 107 class="btn btn-sm btn-primary"
110 type="button" 108 type="button"
111 ng-click="aceptar()" 109 ng-click="aceptar()"
112 ng-disabled="tieneAlMenosUno()" 110 ng-disabled="tieneAlMenosUno()"
113 >Aceptar</button> 111 >Aceptar</button>