Commit f0bb186662b59308600d514e7be5491b1b73298c

Authored by Jose Pinto
1 parent fc631e0304
Exists in master and in 1 other branch develop

saco maxDate a calendarios

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