Commit fc631e030480e28c4589e6df42ef3d8c692910e6

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

agrego importe a los resultados

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