Commit 72406e4b5fa4fccbf378817f2e689b1c481f1c72
1 parent
97d48a46a6
Exists in
master
and in
1 other branch
agrego date's
Showing
3 changed files
with
57 additions
and
7 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalRemito') | 1 | angular.module('focaModalRemito') |
2 | .controller('focaModalRemitoController', | 2 | .controller('focaModalRemitoController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalRemitoService', | 7 | 'focaModalRemitoService', |
8 | 'usadoPor', | ||
8 | function($filter, $scope, $uibModalInstance, | 9 | function($filter, $scope, $uibModalInstance, |
9 | focaModalRemitoService | 10 | focaModalRemitoService, usadoPor |
10 | ) { | 11 | ) { |
11 | 12 | var fecha = new Date(); | |
13 | $scope.fechaHasta = new Date(); | ||
14 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | ||
12 | $scope.filters = ''; | 15 | $scope.filters = ''; |
13 | $scope.remitos = []; | 16 | $scope.remitos = []; |
14 | $scope.primerBusqueda = false; | 17 | $scope.primerBusqueda = false; |
15 | $scope.searchLoading = false; | 18 | $scope.searchLoading = false; |
16 | // pagination | 19 | // pagination |
17 | $scope.numPerPage = 10; | 20 | $scope.numPerPage = 10; |
18 | $scope.currentPage = 1; | 21 | $scope.currentPage = 1; |
19 | $scope.filteredRemitos = []; | 22 | $scope.filteredRemitos = []; |
20 | $scope.currentPageRemitos = []; | 23 | $scope.currentPageRemitos = []; |
21 | $scope.selectedRemito = -1; | 24 | $scope.selectedRemito = -1; |
22 | 25 | ||
23 | //METODOS | 26 | //METODOS |
24 | $scope.busquedaPress = function(key) { | 27 | $scope.busquedaPress = function(key) { |
25 | if (key === 13) { | 28 | if (key === 13) { |
26 | $scope.searchLoading = true; | 29 | $scope.searchLoading = true; |
27 | focaModalRemitoService.getRemitos().then(llenarDatos); | 30 | //TODO: usar filtros en vez de toISOString |
31 | focaModalRemitoService | ||
32 | .getRemitos(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], | ||
33 | $scope.fechaHasta.toISOString().split('.')[0]) | ||
34 | .then(llenarDatos); | ||
28 | } | 35 | } |
29 | }; | 36 | }; |
30 | function llenarDatos(res) { | 37 | function llenarDatos(res) { |
38 | $scope.remitos = []; | ||
39 | $scope.filteredRemitos = []; | ||
40 | $scope.currentPageRemitos = []; | ||
41 | $scope.selectedRemito = -1; | ||
31 | $scope.searchLoading = false; | 42 | $scope.searchLoading = false; |
32 | $scope.primerBusqueda = true; | 43 | $scope.primerBusqueda = true; |
33 | $scope.remitos = res.data; | 44 | $scope.remitos = res.data; |
34 | $scope.search(); | 45 | $scope.search(); |
35 | primera(); | 46 | primera(); |
36 | } | 47 | } |
37 | $scope.search = function() { | 48 | $scope.search = function() { |
38 | if($scope.remitos.length > 0) { | 49 | if($scope.remitos.length > 0) { |
39 | $scope.filteredRemitos = $filter('filter')( | 50 | $scope.filteredRemitos = $filter('filter')( |
40 | $scope.remitos, | 51 | $scope.remitos, |
41 | {$: $scope.filters} | 52 | {$: $scope.filters} |
42 | ); | 53 | ); |
43 | 54 | ||
44 | $scope.lastPage = Math.ceil( | 55 | $scope.lastPage = Math.ceil( |
45 | $scope.filteredRemitos.length / $scope.numPerPage | 56 | $scope.filteredRemitos.length / $scope.numPerPage |
46 | ); | 57 | ); |
47 | 58 | ||
48 | $scope.resetPage(); | 59 | $scope.resetPage(); |
49 | } | 60 | } |
50 | }; | 61 | }; |
51 | 62 | ||
52 | $scope.resetPage = function() { | 63 | $scope.resetPage = function() { |
53 | $scope.currentPage = 1; | 64 | $scope.currentPage = 1; |
54 | $scope.selectPage(1); | 65 | $scope.selectPage(1); |
55 | }; | 66 | }; |
56 | 67 | ||
57 | $scope.selectPage = function(page) { | 68 | $scope.selectPage = function(page) { |
58 | var start = (page - 1) * $scope.numPerPage; | 69 | var start = (page - 1) * $scope.numPerPage; |
59 | var end = start + $scope.numPerPage; | 70 | var end = start + $scope.numPerPage; |
60 | $scope.paginas = []; | 71 | $scope.paginas = []; |
61 | $scope.paginas = calcularPages(page); | 72 | $scope.paginas = calcularPages(page); |
62 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); | 73 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); |
63 | $scope.currentPage = page; | 74 | $scope.currentPage = page; |
64 | }; | 75 | }; |
65 | 76 | ||
66 | $scope.select = function(remito) { | 77 | $scope.select = function(remito) { |
67 | $uibModalInstance.close(remito); | 78 | $uibModalInstance.close(remito); |
68 | }; | 79 | }; |
69 | 80 | ||
70 | $scope.cancel = function() { | 81 | $scope.cancel = function() { |
71 | $uibModalInstance.dismiss('cancel'); | 82 | $uibModalInstance.dismiss('cancel'); |
72 | }; | 83 | }; |
73 | 84 | ||
74 | $scope.busquedaDown = function(key) { | 85 | $scope.busquedaDown = function(key) { |
75 | if (key === 40) { | 86 | if (key === 40) { |
76 | primera(key); | 87 | primera(key); |
77 | } | 88 | } |
78 | }; | 89 | }; |
79 | 90 | ||
80 | $scope.itemRemito = function(key) { | 91 | $scope.itemRemito = function(key) { |
81 | if (key === 38) { | 92 | if (key === 38) { |
82 | anterior(key); | 93 | anterior(key); |
83 | } | 94 | } |
84 | 95 | ||
85 | if (key === 40) { | 96 | if (key === 40) { |
86 | siguiente(key); | 97 | siguiente(key); |
87 | } | 98 | } |
88 | 99 | ||
89 | if (key === 37) { | 100 | if (key === 37) { |
90 | retrocederPagina(); | 101 | retrocederPagina(); |
91 | } | 102 | } |
92 | 103 | ||
93 | if (key === 39) { | 104 | if (key === 39) { |
94 | avanzarPagina(); | 105 | avanzarPagina(); |
95 | } | 106 | } |
96 | }; | 107 | }; |
97 | 108 | ||
98 | function calcularPages(paginaActual) { | 109 | function calcularPages(paginaActual) { |
99 | var paginas = []; | 110 | var paginas = []; |
100 | paginas.push(paginaActual); | 111 | paginas.push(paginaActual); |
101 | 112 | ||
102 | if (paginaActual - 1 > 1) { | 113 | if (paginaActual - 1 > 1) { |
103 | 114 | ||
104 | paginas.unshift(paginaActual - 1); | 115 | paginas.unshift(paginaActual - 1); |
105 | if (paginaActual - 2 > 1) { | 116 | if (paginaActual - 2 > 1) { |
106 | paginas.unshift(paginaActual - 2); | 117 | paginas.unshift(paginaActual - 2); |
107 | } | 118 | } |
108 | } | 119 | } |
109 | 120 | ||
110 | if (paginaActual + 1 < $scope.lastPage) { | 121 | if (paginaActual + 1 < $scope.lastPage) { |
111 | paginas.push(paginaActual + 1); | 122 | paginas.push(paginaActual + 1); |
112 | if (paginaActual + 2 < $scope.lastPage) { | 123 | if (paginaActual + 2 < $scope.lastPage) { |
113 | paginas.push(paginaActual + 2); | 124 | paginas.push(paginaActual + 2); |
114 | } | 125 | } |
115 | } | 126 | } |
116 | 127 | ||
117 | if (paginaActual !== 1) { | 128 | if (paginaActual !== 1) { |
118 | paginas.unshift(1); | 129 | paginas.unshift(1); |
119 | } | 130 | } |
120 | 131 | ||
121 | if (paginaActual !== $scope.lastPage) { | 132 | if (paginaActual !== $scope.lastPage) { |
122 | paginas.push($scope.lastPage); | 133 | paginas.push($scope.lastPage); |
123 | } | 134 | } |
124 | 135 | ||
125 | return paginas; | 136 | return paginas; |
126 | } | 137 | } |
127 | 138 | ||
128 | function primera() { | 139 | function primera() { |
129 | $scope.selectedRemito = 0; | 140 | $scope.selectedRemito = 0; |
130 | } | 141 | } |
131 | 142 | ||
132 | function anterior() { | 143 | function anterior() { |
133 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { | 144 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { |
134 | retrocederPagina(); | 145 | retrocederPagina(); |
135 | } else { | 146 | } else { |
136 | $scope.selectedRemito--; | 147 | $scope.selectedRemito--; |
137 | } | 148 | } |
138 | } | 149 | } |
139 | 150 | ||
140 | function siguiente() { | 151 | function siguiente() { |
141 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { | 152 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { |
142 | $scope.selectedRemito++; | 153 | $scope.selectedRemito++; |
143 | } else { | 154 | } else { |
144 | avanzarPagina(); | 155 | avanzarPagina(); |
145 | } | 156 | } |
146 | } | 157 | } |
147 | 158 | ||
148 | function retrocederPagina() { | 159 | function retrocederPagina() { |
149 | if ($scope.currentPage > 1) { | 160 | if ($scope.currentPage > 1) { |
150 | $scope.selectPage($scope.currentPage - 1); | 161 | $scope.selectPage($scope.currentPage - 1); |
151 | $scope.selectedRemito = $scope.numPerPage - 1; | 162 | $scope.selectedRemito = $scope.numPerPage - 1; |
152 | } | 163 | } |
153 | } | 164 | } |
154 | 165 | ||
155 | function avanzarPagina() { | 166 | function avanzarPagina() { |
156 | if ($scope.currentPage < $scope.lastPage) { | 167 | if ($scope.currentPage < $scope.lastPage) { |
157 | $scope.selectPage($scope.currentPage + 1); | 168 | $scope.selectPage($scope.currentPage + 1); |
158 | $scope.selectedRemito = 0; | 169 | $scope.selectedRemito = 0; |
159 | } | 170 | } |
160 | } | 171 | } |
161 | } | 172 | } |
162 | ] | 173 | ] |
163 | ); | 174 | ); |
164 | 175 |
src/js/service.js
1 | angular.module('focaModalRemito') | 1 | angular.module('focaModalRemito') |
2 | .service('focaModalRemitoService', [ | 2 | .service('focaModalRemitoService', [ |
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 | getRemitos: function() { | 7 | getRemitos: function(usadoPor, fechaDesde, fechaHasta) { |
8 | return $http.get(API_ENDPOINT.URL + '/remito'); | 8 | var sinHojaRuta = (usadoPor === 'hojaRuta' ? '/sin-hoja-Ruta' : ''); |
9 | return $http.get(API_ENDPOINT.URL + '/remito/listar/' + fechaDesde + '/' + | ||
10 | fechaHasta + sinHojaRuta); | ||
9 | } | 11 | } |
10 | }; | 12 | }; |
11 | } | 13 | } |
12 | ]); | 14 | ]); |
13 | 15 |
src/views/foca-modal-remito.html
1 | <div class="modal-header py-1"> | 1 | <div class="modal-header py-1"> |
2 | <h5 class="modal-title">Busqueda de Remito</h5> | 2 | <h5 class="modal-title">Busqueda de Remito</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="Razón social" |
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="selectedRemito == -1" | 51 | foca-focus="selectedRemito == -1" |
16 | ng-focus="selectedRemito = -1" | 52 | ng-focus="selectedRemito = -1" |
53 | teclado-virtual | ||
17 | > | 54 | > |
18 | <div class="input-group-append"> | 55 | <div class="input-group-append"> |
19 | <button | 56 | <button |
20 | ladda="searchLoading" | 57 | ladda="searchLoading" |
21 | class="btn btn-outline-secondary" | 58 | class="btn btn-outline-secondary" |
22 | type="button" | 59 | type="button" |
23 | ng-click="busquedaPress(13)" | 60 | ng-click="busquedaPress(13)" |
24 | > | 61 | > |
25 | <i class="fa fa-search" aria-hidden="true"></i> | 62 | <i class="fa fa-search" aria-hidden="true"></i> |
26 | </button> | 63 | </button> |
27 | </div> | 64 | </div> |
28 | </div> | 65 | </div> |
29 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> | 66 | <table ng-show="primerBusqueda" class="table table-striped table-sm"> |
30 | <thead> | 67 | <thead> |
31 | <tr> | 68 | <tr> |
32 | <th>Fecha</th> | 69 | <th>Fecha</th> |
33 | <th>Cliente</th> | 70 | <th>Cliente</th> |
34 | <th>Comprobante</th> | 71 | <th>Comprobante</th> |
35 | <th></th> | 72 | <th></th> |
36 | </tr> | 73 | </tr> |
37 | </thead> | 74 | </thead> |
38 | <tbody> | 75 | <tbody> |
39 | <tr ng-show="currentPageRemitos.length == 0 && primerBusqueda"> | 76 | <tr ng-show="currentPageRemitos.length == 0 && primerBusqueda"> |
40 | <td colspan="5"> | 77 | <td colspan="5"> |
41 | No se encontraron resultados. | 78 | No se encontraron resultados. |
42 | </td> | 79 | </td> |
43 | </tr> | 80 | </tr> |
44 | <tr class="selectable" | 81 | <tr class="selectable" |
45 | ng-repeat="(key, remito) in currentPageRemitos" | 82 | ng-repeat="(key, remito) in currentPageRemitos" |
46 | ng-click="select(remito)"> | 83 | ng-click="select(remito)"> |
47 | <td ng-bind="remito.fechaRemito | date : 'dd/MM/yyyy'"></td> | 84 | <td ng-bind="remito.fechaRemito | date : 'dd/MM/yyyy'"></td> |
48 | <td ng-bind="remito.nombreCliente"></td> | 85 | <td ng-bind="remito.nombreCliente"></td> |
49 | <td ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></td> | 86 | <td ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></td> |
50 | <td> | 87 | <td> |
51 | <button | 88 | <button |
52 | type="button" | 89 | type="button" |
53 | class="btn btn-xs p-1 float-right" | 90 | class="btn btn-xs p-1 float-right" |
54 | ng-class="{ | 91 | ng-class="{ |
55 | 'btn-secondary': selectedRemito != key, | 92 | 'btn-secondary': selectedRemito != key, |
56 | 'btn-primary': selectedRemito == key | 93 | 'btn-primary': selectedRemito == key |
57 | }" | 94 | }" |
58 | foca-focus="selectedRemito == {{key}}" | 95 | foca-focus="selectedRemito == {{key}}" |
59 | ng-keydown="itemRemito($event.keyCode)" | 96 | ng-keydown="itemRemito($event.keyCode)" |
60 | > | 97 | > |
61 | <i class="fa fa-arrow-right" aria-hidden="true"></i> | 98 | <i class="fa fa-arrow-right" aria-hidden="true"></i> |
62 | </button> | 99 | </button> |
63 | </td> | 100 | </td> |
64 | </tr> | 101 | </tr> |
65 | </tbody> | 102 | </tbody> |
66 | </table> | 103 | </table> |
67 | <nav ng-show="currentPageRemitos.length > 0 && primerBusqueda"> | 104 | <nav ng-show="currentPageRemitos.length > 0 && primerBusqueda"> |
68 | <ul class="pagination pagination-sm justify-content mb-0"> | 105 | <ul class="pagination pagination-sm justify-content mb-0"> |
69 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | 106 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
70 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | 107 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> |
71 | <span aria-hidden="true">«</span> | 108 | <span aria-hidden="true">«</span> |
72 | <span class="sr-only">Anterior</span> | 109 | <span class="sr-only">Anterior</span> |
73 | </a> | 110 | </a> |
74 | </li> | 111 | </li> |
75 | <li | 112 | <li |
76 | class="page-item" | 113 | class="page-item" |
77 | ng-repeat="pagina in paginas" | 114 | ng-repeat="pagina in paginas" |
78 | ng-class="{'active': pagina == currentPage}" | 115 | ng-class="{'active': pagina == currentPage}" |
79 | > | 116 | > |
80 | <a | 117 | <a |
81 | class="page-link" | 118 | class="page-link" |
82 | href="#" | 119 | href="#" |
83 | ng-click="selectPage(pagina)" | 120 | ng-click="selectPage(pagina)" |
84 | ng-bind="pagina" | 121 | ng-bind="pagina" |
85 | ></a> | 122 | ></a> |
86 | </li> | 123 | </li> |
87 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | 124 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> |
88 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | 125 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> |
89 | <span aria-hidden="true">»</span> | 126 | <span aria-hidden="true">»</span> |
90 | <span class="sr-only">Siguiente</span> | 127 | <span class="sr-only">Siguiente</span> |
91 | </a> | 128 | </a> |
92 | </li> | 129 | </li> |
93 | </ul> | 130 | </ul> |
94 | </nav> | 131 | </nav> |
95 | </div> | 132 | </div> |
96 | <div class="modal-footer py-1"> | 133 | <div class="modal-footer py-1"> |
97 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 134 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> |
98 | </div> | 135 | </div> |
99 | 136 |