Commit 6671d94ee741b7ffd06ee7052149051fb1c93ec0

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

filtro de fecha para modal

See merge request modulos-npm/foca-modal-nota-pedido!8
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 //TODO Validaciones con alertas
30 if(!$scope.fechaDesde) {
31 alert('INGRESE FECHA DESDE');
32 return;
33 }
34 if(!$scope.fechaHasta) {
35 alert('INGRESE FECHA HASTA');
36 return;
37 }
38 if($scope.fechaDesde > $scope.fechaHasta) {
39 alert('La fecha desde no puede ser mayor a la fecha hasta');
40 return;
41 }
27 $scope.searchLoading = true; 42 $scope.searchLoading = true;
28 focaModalNotaPedidoService.getNotasPedido(usadoPor).then(llenarDatos); 43 //TODO hacer filtro de fecha
44 focaModalNotaPedidoService
45 .getNotasPedido(usadoPor, $scope.fechaDesde.toISOString().split('.')[0],
46 $scope.fechaHasta.toISOString().split('.')[0])
47 .then(llenarDatos);
29 } 48 }
30 }; 49 };
31 function llenarDatos(res) { 50 function llenarDatos(res) {
51 $scope.notasPedido = [];
52 $scope.filteredNotasPedido = [];
53 $scope.currentPageNotasPedido = [];
54 $scope.selectedNotaPedido = -1;
32 $scope.searchLoading = false; 55 $scope.searchLoading = false;
33 $scope.primerBusqueda = true; 56 $scope.primerBusqueda = true;
34 $scope.notasPedido = res.data; 57 $scope.notasPedido = res.data;
35 $scope.search(); 58 $scope.search();
36 primera(); 59 primera();
37 } 60 }
38 $scope.search = function() { 61 $scope.search = function() {
39 if($scope.notasPedido.length > 0) { 62 if($scope.notasPedido.length > 0) {
40 $scope.filteredNotasPedido = $filter('filter')( 63 $scope.filteredNotasPedido = $filter('filter')(
41 $scope.notasPedido, 64 $scope.notasPedido,
42 {$: $scope.filters} 65 {$: $scope.filters}
43 ); 66 );
44 67
45 $scope.lastPage = Math.ceil( 68 $scope.lastPage = Math.ceil(
46 $scope.filteredNotasPedido.length / $scope.numPerPage 69 $scope.filteredNotasPedido.length / $scope.numPerPage
47 ); 70 );
48 71
49 $scope.resetPage(); 72 $scope.resetPage();
50 } 73 }
51 }; 74 };
52 75
53 $scope.resetPage = function() { 76 $scope.resetPage = function() {
54 $scope.currentPage = 1; 77 $scope.currentPage = 1;
55 $scope.selectPage(1); 78 $scope.selectPage(1);
56 }; 79 };
57 80
58 $scope.selectPage = function(page) { 81 $scope.selectPage = function(page) {
59 var start = (page - 1) * $scope.numPerPage; 82 var start = (page - 1) * $scope.numPerPage;
60 var end = start + $scope.numPerPage; 83 var end = start + $scope.numPerPage;
61 $scope.paginas = []; 84 $scope.paginas = [];
62 $scope.paginas = calcularPages(page); 85 $scope.paginas = calcularPages(page);
63 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); 86 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end);
64 $scope.currentPage = page; 87 $scope.currentPage = page;
65 }; 88 };
66 89
67 $scope.select = function(notaPedido) { 90 $scope.select = function(notaPedido) {
68 $uibModalInstance.close(notaPedido); 91 $uibModalInstance.close(notaPedido);
69 }; 92 };
70 93
71 $scope.cancel = function() { 94 $scope.cancel = function() {
72 $uibModalInstance.dismiss('cancel'); 95 $uibModalInstance.dismiss('cancel');
73 }; 96 };
74 97
75 $scope.busquedaDown = function(key) { 98 $scope.busquedaDown = function(key) {
76 if (key === 40) { 99 if (key === 40) {
77 primera(key); 100 primera(key);
78 } 101 }
79 }; 102 };
80 103
81 $scope.itemNotaPedido = function(key) { 104 $scope.itemNotaPedido = function(key) {
82 if (key === 38) { 105 if (key === 38) {
83 anterior(key); 106 anterior(key);
84 } 107 }
85 108
86 if (key === 40) { 109 if (key === 40) {
87 siguiente(key); 110 siguiente(key);
88 } 111 }
89 112
90 if (key === 37) { 113 if (key === 37) {
91 retrocederPagina(); 114 retrocederPagina();
92 } 115 }
93 116
94 if (key === 39) { 117 if (key === 39) {
95 avanzarPagina(); 118 avanzarPagina();
96 } 119 }
97 }; 120 };
98 121
99 function calcularPages(paginaActual) { 122 function calcularPages(paginaActual) {
100 var paginas = []; 123 var paginas = [];
101 paginas.push(paginaActual); 124 paginas.push(paginaActual);
102 125
103 if (paginaActual - 1 > 1) { 126 if (paginaActual - 1 > 1) {
104 127
105 paginas.unshift(paginaActual - 1); 128 paginas.unshift(paginaActual - 1);
106 if (paginaActual - 2 > 1) { 129 if (paginaActual - 2 > 1) {
107 paginas.unshift(paginaActual - 2); 130 paginas.unshift(paginaActual - 2);
108 } 131 }
109 } 132 }
110 133
111 if (paginaActual + 1 < $scope.lastPage) { 134 if (paginaActual + 1 < $scope.lastPage) {
112 paginas.push(paginaActual + 1); 135 paginas.push(paginaActual + 1);
113 if (paginaActual + 2 < $scope.lastPage) { 136 if (paginaActual + 2 < $scope.lastPage) {
114 paginas.push(paginaActual + 2); 137 paginas.push(paginaActual + 2);
115 } 138 }
116 } 139 }
117 140
118 if (paginaActual !== 1) { 141 if (paginaActual !== 1) {
119 paginas.unshift(1); 142 paginas.unshift(1);
120 } 143 }
121 144
122 if (paginaActual !== $scope.lastPage) { 145 if (paginaActual !== $scope.lastPage) {
123 paginas.push($scope.lastPage); 146 paginas.push($scope.lastPage);
124 } 147 }
125 148
126 return paginas; 149 return paginas;
127 } 150 }
128 151
129 function primera() { 152 function primera() {
130 $scope.selectedNotaPedido = 0; 153 $scope.selectedNotaPedido = 0;
131 } 154 }
132 155
133 function anterior() { 156 function anterior() {
134 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { 157 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) {
135 retrocederPagina(); 158 retrocederPagina();
136 } else { 159 } else {
137 $scope.selectedNotaPedido--; 160 $scope.selectedNotaPedido--;
138 } 161 }
139 } 162 }
140 163
141 function siguiente() { 164 function siguiente() {
142 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { 165 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) {
143 $scope.selectedNotaPedido++; 166 $scope.selectedNotaPedido++;
144 } else { 167 } else {
145 avanzarPagina(); 168 avanzarPagina();
146 } 169 }
147 } 170 }
148 171
149 function retrocederPagina() { 172 function retrocederPagina() {
150 if ($scope.currentPage > 1) { 173 if ($scope.currentPage > 1) {
151 $scope.selectPage($scope.currentPage - 1); 174 $scope.selectPage($scope.currentPage - 1);
152 $scope.selectedNotaPedido = $scope.numPerPage - 1; 175 $scope.selectedNotaPedido = $scope.numPerPage - 1;
153 } 176 }
154 } 177 }
155 178
156 function avanzarPagina() { 179 function avanzarPagina() {
157 if ($scope.currentPage < $scope.lastPage) { 180 if ($scope.currentPage < $scope.lastPage) {
158 $scope.selectPage($scope.currentPage + 1); 181 $scope.selectPage($scope.currentPage + 1);
159 $scope.selectedNotaPedido = 0; 182 $scope.selectedNotaPedido = 0;
160 } 183 }
161 } 184 }
162 } 185 }
163 ] 186 ]
164 ); 187 );
165 188
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