Commit e9edcb5b7ca0fd226f36f34f9e580eb9b13ac6ec

Authored by Jose Pinto
1 parent 2423867ccc
Exists in master

saco maxDate a calendario

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