Commit 42c0dc8254da227cfc94d38ab3da4acd639e05ed

Authored by Eric Fernandez
1 parent 6bc2ef5eea
Exists in master

filtro de fecha para modal

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