Commit d9a8ec7d1e9c88874bacae986593c3c03475f0b9

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

Merge branch 'master' into 'master'

Master

See merge request !9
src/js/controller.js
1 angular.module('focaModalFactura') 1 angular.module('focaModalFactura')
2 .controller('focaModalFacturaController', 2 .controller('focaModalFacturaController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalFacturaService', 7 'focaModalFacturaService',
8 'parametrosFactura', 8 'parametrosFactura',
9 function($filter, $scope, $uibModalInstance, 9 function($filter, $scope, $uibModalInstance,
10 focaModalFacturaService, parametrosFactura 10 focaModalFacturaService, parametrosFactura
11 ) { 11 ) {
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.facturas = []; 16 $scope.facturas = [];
17 $scope.primerBusqueda = false; 17 $scope.primerBusqueda = false;
18 $scope.searchLoading = false; 18 $scope.searchLoading = false;
19 $scope.parametrosFactura = parametrosFactura; 19 $scope.parametrosFactura = parametrosFactura;
20 // pagination 20 // pagination
21 $scope.numPerPage = 10; 21 $scope.numPerPage = 10;
22 $scope.currentPage = 1; 22 $scope.currentPage = 1;
23 $scope.filteredFacturas = []; 23 $scope.filteredFacturas = [];
24 $scope.currentPageFacturas = []; 24 $scope.currentPageFacturas = [];
25 $scope.selectedFactura = -1; 25 $scope.selectedFactura = -1;
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 30 //TODO Validaciones con alertas
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 hacer filtro de fecha 44 //TODO hacer filtro de fecha
45 focaModalFacturaService 45 focaModalFacturaService
46 .getFacturasByIdCliente( 46 .getFacturasByIdCliente(
47 parametrosFactura.cliente, 47 parametrosFactura.cliente,
48 parametrosFactura.moneda,
48 '2001-01-01', 49 '2001-01-01',
49 '2100-12-31' 50 '2100-12-31'
50 ) 51 )
51 .then(llenarDatos); 52 .then(llenarDatos);
52 } 53 }
53 }; 54 };
54 55
55 $scope.aceptar = function() { 56 $scope.aceptar = function() {
56 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 57 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
57 $uibModalInstance.close(result); 58 $uibModalInstance.close(result);
58 }; 59 };
59 60
60 $scope.tieneAlMenosUno = function() { 61 $scope.tieneAlMenosUno = function() {
61 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 62 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
62 return !result.length; 63 return !result.length;
63 }; 64 };
64 65
65 function llenarDatos(res) { 66 function llenarDatos(res) {
66 $scope.facturas = []; 67 $scope.facturas = [];
67 $scope.filteredFacturas = []; 68 $scope.filteredFacturas = [];
68 $scope.currentPageFacturas = []; 69 $scope.currentPageFacturas = [];
69 $scope.selectedFactura = -1; 70 $scope.selectedFactura = -1;
70 $scope.searchLoading = false; 71 $scope.searchLoading = false;
71 $scope.primerBusqueda = true; 72 $scope.primerBusqueda = true;
72 $scope.facturas = calcularSaldos(res.data); 73 $scope.facturas = calcularSaldos(res.data);
73 $scope.search(); 74 $scope.search();
74 primera(); 75 primera();
75 } 76 }
76 $scope.search = function() { 77 $scope.search = function() {
77 if($scope.facturas.length > 0) { 78 if($scope.facturas.length > 0) {
78 $scope.filteredFacturas = $filter('filter')( 79 $scope.filteredFacturas = $filter('filter')(
79 $scope.facturas, 80 $scope.facturas,
80 {$: $scope.filters} 81 {$: $scope.filters}
81 ); 82 );
82 83
83 $scope.lastPage = Math.ceil( 84 $scope.lastPage = Math.ceil(
84 $scope.filteredFacturas.length / $scope.numPerPage 85 $scope.filteredFacturas.length / $scope.numPerPage
85 ); 86 );
86 87
87 $scope.resetPage(); 88 $scope.resetPage();
88 } 89 }
89 }; 90 };
90 91
91 $scope.resetPage = function() { 92 $scope.resetPage = function() {
92 $scope.currentPage = 1; 93 $scope.currentPage = 1;
93 $scope.selectPage(1); 94 $scope.selectPage(1);
94 }; 95 };
95 96
96 $scope.selectPage = function(page) { 97 $scope.selectPage = function(page) {
97 var start = (page - 1) * $scope.numPerPage; 98 var start = (page - 1) * $scope.numPerPage;
98 var end = start + $scope.numPerPage; 99 var end = start + $scope.numPerPage;
99 $scope.paginas = []; 100 $scope.paginas = [];
100 $scope.paginas = calcularPages(page); 101 $scope.paginas = calcularPages(page);
101 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); 102 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
102 $scope.currentPage = page; 103 $scope.currentPage = page;
103 }; 104 };
104 105
105 $scope.cancel = function() { 106 $scope.cancel = function() {
106 $uibModalInstance.dismiss('cancel'); 107 $uibModalInstance.dismiss('cancel');
107 }; 108 };
108 109
109 $scope.busquedaDown = function(key) { 110 $scope.busquedaDown = function(key) {
110 if (key === 40) { 111 if (key === 40) {
111 primera(key); 112 primera(key);
112 } 113 }
113 }; 114 };
114 115
115 $scope.itemFactura = function(key) { 116 $scope.itemFactura = function(key) {
116 if (key === 38) { 117 if (key === 38) {
117 anterior(key); 118 anterior(key);
118 } 119 }
119 120
120 if (key === 40) { 121 if (key === 40) {
121 siguiente(key); 122 siguiente(key);
122 } 123 }
123 124
124 if (key === 37) { 125 if (key === 37) {
125 retrocederPagina(); 126 retrocederPagina();
126 } 127 }
127 128
128 if (key === 39) { 129 if (key === 39) {
129 avanzarPagina(); 130 avanzarPagina();
130 } 131 }
131 }; 132 };
132 133
133 function calcularPages(paginaActual) { 134 function calcularPages(paginaActual) {
134 var paginas = []; 135 var paginas = [];
135 paginas.push(paginaActual); 136 paginas.push(paginaActual);
136 137
137 if (paginaActual - 1 > 1) { 138 if (paginaActual - 1 > 1) {
138 139
139 paginas.unshift(paginaActual - 1); 140 paginas.unshift(paginaActual - 1);
140 if (paginaActual - 2 > 1) { 141 if (paginaActual - 2 > 1) {
141 paginas.unshift(paginaActual - 2); 142 paginas.unshift(paginaActual - 2);
142 } 143 }
143 } 144 }
144 145
145 if (paginaActual + 1 < $scope.lastPage) { 146 if (paginaActual + 1 < $scope.lastPage) {
146 paginas.push(paginaActual + 1); 147 paginas.push(paginaActual + 1);
147 if (paginaActual + 2 < $scope.lastPage) { 148 if (paginaActual + 2 < $scope.lastPage) {
148 paginas.push(paginaActual + 2); 149 paginas.push(paginaActual + 2);
149 } 150 }
150 } 151 }
151 152
152 if (paginaActual !== 1) { 153 if (paginaActual !== 1) {
153 paginas.unshift(1); 154 paginas.unshift(1);
154 } 155 }
155 156
156 if (paginaActual !== $scope.lastPage) { 157 if (paginaActual !== $scope.lastPage) {
157 paginas.push($scope.lastPage); 158 paginas.push($scope.lastPage);
158 } 159 }
159 160
160 return paginas; 161 return paginas;
161 } 162 }
162 163
163 function primera() { 164 function primera() {
164 $scope.selectedFactura = 0; 165 $scope.selectedFactura = 0;
165 } 166 }
166 167
167 function anterior() { 168 function anterior() {
168 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { 169 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
169 retrocederPagina(); 170 retrocederPagina();
170 } else { 171 } else {
171 $scope.selectedFactura--; 172 $scope.selectedFactura--;
172 } 173 }
173 } 174 }
174 175
175 function siguiente() { 176 function siguiente() {
176 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { 177 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
177 $scope.selectedFactura++; 178 $scope.selectedFactura++;
178 } else { 179 } else {
179 avanzarPagina(); 180 avanzarPagina();
180 } 181 }
181 } 182 }
182 183
183 function retrocederPagina() { 184 function retrocederPagina() {
184 if ($scope.currentPage > 1) { 185 if ($scope.currentPage > 1) {
185 $scope.selectPage($scope.currentPage - 1); 186 $scope.selectPage($scope.currentPage - 1);
186 $scope.selectedFactura = $scope.numPerPage - 1; 187 $scope.selectedFactura = $scope.numPerPage - 1;
187 } 188 }
188 } 189 }
189 190
190 function avanzarPagina() { 191 function avanzarPagina() {
191 if ($scope.currentPage < $scope.lastPage) { 192 if ($scope.currentPage < $scope.lastPage) {
192 $scope.selectPage($scope.currentPage + 1); 193 $scope.selectPage($scope.currentPage + 1);
193 $scope.selectedFactura = 0; 194 $scope.selectedFactura = 0;
194 } 195 }
195 } 196 }
196 197
197 function calcularSaldos(facturas) { 198 function calcularSaldos(facturas) {
198 var saldo = 0; 199 var saldo = 0;
199 200
200 facturas.forEach(function(factura) { 201 facturas.forEach(function(factura) {
201 if (factura.TCO === 'CI' || 202 if (factura.TCO === 'CI' ||
202 factura.TCO === 'FT' || 203 factura.TCO === 'FT' ||
203 factura.TCO === 'ND'){ 204 factura.TCO === 'ND'){
204 factura.IPA = factura.IPA * -1; 205 factura.IPA = factura.IPA * -1;
205 }else{ 206 }else{
206 factura.IPA = factura.IPA; 207 factura.IPA = factura.IPA;
207 } 208 }
208 saldo += factura.IPA; 209 saldo += factura.IPA;
209 factura.saldo = saldo; 210 factura.saldo = saldo;
210 factura.saldo_show = Math.abs(saldo); 211 factura.saldo_show = Math.abs(saldo);
211 factura.IPA_SHOW = Math.abs(factura.IPA); 212 factura.IPA_SHOW = Math.abs(factura.IPA);
212 }); 213 });
213 214
214 return facturas; 215 return facturas;
215 } 216 }
216 217
217 $scope.busquedaPress(13); 218 $scope.busquedaPress(13);
218 } 219 }
219 ] 220 ]
220 ); 221 );
221 222
1 angular.module('focaModalFactura') 1 angular.module('focaModalFactura')
2 .factory('focaModalFacturaService', [ 2 .factory('focaModalFacturaService', [
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 getFacturasByIdCliente: function(idCliente, fechaDesde, fechaHasta) { 7 getFacturasByIdCliente: function(idCliente, idMoneda, fechaDesde, fechaHasta) {
8 return $http.get(API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' + 8 return $http.get(
9 API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' + idMoneda + '/' +
9 fechaDesde + '/' + fechaHasta); 10 fechaDesde + '/' + fechaHasta);
10 } 11 }
11 }; 12 };
12 } 13 }
13 ]); 14 ]);
14 15
src/views/foca-modal-factura.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">Búsqueda de Comprobantes</h5> 4 <h5 class="modal-title">Búsqueda de Comprobantes</h5>
5 </div> 5 </div>
6 </div> 6 </div>
7 </div> 7 </div>
8 <div class="modal-body" id="modal-body"> 8 <div class="modal-body" id="modal-body">
9 <table ng-show="primerBusqueda" class="table table-striped table-sm"> 9 <table ng-show="primerBusqueda" class="table table-striped table-sm">
10 <thead> 10 <thead>
11 <tr> 11 <tr>
12 <th>Comprobante</th> 12 <th>Comprobante</th>
13 <th>Vencimiento</th> 13 <th>Vencimiento</th>
14 <th class="text-right">Importe</th> 14 <th class="text-right">Importe</th>
15 <th class="text-right">Saldo</th> 15 <th class="text-right">Saldo</th>
16 <th class="text-right"></th> 16 <th class="text-right"></th>
17 </tr> 17 </tr>
18 </thead> 18 </thead>
19 <tbody> 19 <tbody>
20 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> 20 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
21 <td colspan="5"> 21 <td colspan="5">
22 No se encontraron resultados. 22 No se encontraron resultados.
23 </td> 23 </td>
24 </tr> 24 </tr>
25 <tr class="selectable" 25 <tr class="selectable"
26 ng-repeat="(key,factura) in currentPageFacturas" 26 ng-repeat="(key,factura) in currentPageFacturas"
27 ng-click="factura.checked = !factura.checked"> 27 ng-click="factura.checked = !factura.checked">
28 <td>{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td> 28 <td>{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td>
29 <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> 29 <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td>
30 <td class="text-right"> 30 <td class="text-right">
31 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }} 31 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }}
32 <span ng-class="{{'invisible': factura.IPA >= 0}}">-</span> 32 <span ng-class="{'invisible': factura.IPA >= 0}">-</span>
33 </td> 33 </td>
34 <td class="text-right"> 34 <td class="text-right">
35 {{ factura.saldo_show | number:2 }} 35 {{ factura.saldo_show | number:2 }}
36 <span ng-class="{{'invisible': factura.saldo >= 0}}">-</span> 36 <span ng-class="{'invisible': factura.saldo >= 0}">-</span>
37 </td> 37 </td>
38 <td class="text-right"> 38 <td class="text-right">
39 <input 39 <input
40 ng-class="{ 40 ng-class="{
41 'btn-secondary': selectedFactura != key, 41 'btn-secondary': selectedFactura != key,
42 'btn-primary': selectedFactura == key}" 42 'btn-primary': selectedFactura == key}"
43 ng-keydown="itemFactura($event.keyCode)" 43 ng-keydown="itemFactura($event.keyCode)"
44 foca-focus="selectedFactura == {{key}}" 44 foca-focus="selectedFactura == {{key}}"
45 type="checkbox" 45 type="checkbox"
46 ng-model="factura.checked" 46 ng-model="factura.checked"
47 /> 47 />
48 </td> 48 </td>
49 </tr> 49 </tr>
50 </tbody> 50 </tbody>
51 </table> 51 </table>
52 </div> 52 </div>
53 <div class="modal-footer py-1"> 53 <div class="modal-footer py-1">
54 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> 54 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto">
55 <ul class="pagination pagination-sm justify-content mb-0"> 55 <ul class="pagination pagination-sm justify-content mb-0">
56 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 56 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
57 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 57 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
58 <span aria-hidden="true">&laquo;</span> 58 <span aria-hidden="true">&laquo;</span>
59 <span class="sr-only">Anterior</span> 59 <span class="sr-only">Anterior</span>
60 </a> 60 </a>
61 </li> 61 </li>
62 <li 62 <li
63 class="page-item" 63 class="page-item"
64 ng-repeat="pagina in paginas" 64 ng-repeat="pagina in paginas"
65 ng-class="{'active': pagina == currentPage}" 65 ng-class="{'active': pagina == currentPage}"
66 > 66 >
67 <a 67 <a
68 class="page-link" 68 class="page-link"
69 href="javascript:void();" 69 href="javascript:void();"
70 ng-click="selectPage(pagina)" 70 ng-click="selectPage(pagina)"
71 ng-bind="pagina" 71 ng-bind="pagina"
72 ></a> 72 ></a>
73 </li> 73 </li>
74 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 74 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
75 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 75 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
76 <span aria-hidden="true">&raquo;</span> 76 <span aria-hidden="true">&raquo;</span>
77 <span class="sr-only">Siguiente</span> 77 <span class="sr-only">Siguiente</span>
78 </a> 78 </a>
79 </li> 79 </li>
80 </ul> 80 </ul>
81 </nav> 81 </nav>
82 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 82 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
83 <button 83 <button
84 class="btn btn-sm btn-primary" 84 class="btn btn-sm btn-primary"
85 type="button" 85 type="button"
86 ng-click="aceptar()" 86 ng-click="aceptar()"
87 ng-disabled="tieneAlMenosUno()" 87 ng-disabled="tieneAlMenosUno()"
88 >Aceptar</button> 88 >Aceptar</button>
89 </div> 89 </div>
90 90