Commit 0f110cee2da93dfd369aecc4e67ad0feaae6e887

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master

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