Commit 02ce8ad9fb57f0a555aa103d76eb62ff1e0a0465

Authored by Eric Fernandez
1 parent fab780a800
Exists in master

selección múltiple de items

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