Commit 95334422e5241b30cc383c688f4d27756fe22644

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

envia facturas por email

1 angular.module('focaModalFactura', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda', 'focaModal']); 1 angular.module('focaModalFactura', [
2 'ui.bootstrap',
3 'focaDirectivas',
4 'angular-ladda',
5 'focaModal'
6 ]);
2 7
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 '$uibModal', 9 '$uibModal',
10 'focaModalService',
10 function($filter, $scope, $uibModalInstance, 11 function($filter, $scope, $uibModalInstance,
11 focaModalFacturaService, parametrosFactura, $uibModal 12 focaModalFacturaService, parametrosFactura, $uibModal, focaModalService
12 ) { 13 ) {
13 var fecha = new Date(); 14 var fecha = new Date();
14 $scope.fechaHasta = new Date(); 15 $scope.fechaHasta = new Date();
15 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 16 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
16 $scope.filters = ''; 17 $scope.filters = '';
17 $scope.facturas = []; 18 $scope.facturas = [];
18 $scope.primerBusqueda = false; 19 $scope.primerBusqueda = false;
19 $scope.searchLoading = false; 20 $scope.searchLoading = false;
20 $scope.parametrosFactura = parametrosFactura; 21 $scope.parametrosFactura = parametrosFactura;
21 // pagination 22 // pagination
22 $scope.numPerPage = 10; 23 $scope.numPerPage = 10;
23 $scope.currentPage = 1; 24 $scope.currentPage = 1;
24 $scope.filteredFacturas = []; 25 $scope.filteredFacturas = [];
25 $scope.currentPageFacturas = []; 26 $scope.currentPageFacturas = [];
26 $scope.selectedFactura = -1; 27 $scope.selectedFactura = -1;
27 28
28 //METODOS 29 //METODOS
29 $scope.busquedaPress = function(key) { 30 $scope.busquedaPress = function(key) {
30 if (key === 13) { 31 if (key === 13) {
31 //TODO Validaciones con alertas 32 //TODO Validaciones con alertas
32 if(!$scope.fechaDesde) { 33 if(!$scope.fechaDesde) {
33 alert('INGRESE FECHA DESDE'); 34 alert('INGRESE FECHA DESDE');
34 return; 35 return;
35 } 36 }
36 if(!$scope.fechaHasta) { 37 if(!$scope.fechaHasta) {
37 alert('INGRESE FECHA HASTA'); 38 alert('INGRESE FECHA HASTA');
38 return; 39 return;
39 } 40 }
40 if($scope.fechaDesde > $scope.fechaHasta) { 41 if($scope.fechaDesde > $scope.fechaHasta) {
41 alert('La fecha desde no puede ser mayor a la fecha hasta'); 42 alert('La fecha desde no puede ser mayor a la fecha hasta');
42 return; 43 return;
43 } 44 }
44 $scope.searchLoading = true; 45 $scope.searchLoading = true;
45 //TODO hacer filtro de fecha 46 //TODO hacer filtro de fecha
46 focaModalFacturaService 47 focaModalFacturaService
47 .getFacturasByIdCliente( 48 .getFacturasByIdCliente(
48 parametrosFactura.cliente.COD, 49 parametrosFactura.cliente.COD,
49 parametrosFactura.moneda, 50 parametrosFactura.moneda,
50 '2001-01-01', 51 '2001-01-01',
51 '2100-12-31' 52 '2100-12-31'
52 ) 53 )
53 .then(llenarDatos); 54 .then(llenarDatos);
54 } 55 }
55 }; 56 };
56 57
57 $scope.aceptar = function() { 58 $scope.aceptar = function() {
58 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 59 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
59 $uibModalInstance.close(result); 60 $uibModalInstance.close(result);
60 }; 61 };
61 62
62 $scope.tieneAlMenosUno = function() { 63 $scope.tieneAlMenosUno = function() {
63 var result = $scope.facturas.filter(function(a) {return a.checked === true;}); 64 var result = $scope.facturas.filter(function(a) {return a.checked === true;});
64 return !result.length; 65 return !result.length;
65 }; 66 };
66 67
67 function llenarDatos(res) { 68 function llenarDatos(res) {
68 $scope.facturas = []; 69 $scope.facturas = [];
69 $scope.filteredFacturas = []; 70 $scope.filteredFacturas = [];
70 $scope.currentPageFacturas = []; 71 $scope.currentPageFacturas = [];
71 $scope.selectedFactura = -1; 72 $scope.selectedFactura = -1;
72 $scope.searchLoading = false; 73 $scope.searchLoading = false;
73 $scope.primerBusqueda = true; 74 $scope.primerBusqueda = true;
74 $scope.facturas = calcularSaldos(res.data); 75 $scope.facturas = calcularSaldos(res.data);
75 $scope.search(); 76 $scope.search();
76 primera(); 77 primera();
77 } 78 }
78 79
79 $scope.verFactura = function(factura) { 80 $scope.verFactura = function(factura) {
80 var modalInstance = $uibModal.open( 81 var modalInstance = $uibModal.open(
81 { 82 {
82 ariaLabelledBy: 'Detalle de factura', 83 ariaLabelledBy: 'Detalle de factura',
83 templateUrl: 'foca-modal-factura-detalle.html', 84 templateUrl: 'foca-modal-factura-detalle.html',
84 controller: 'focaModalFacturaDetalleController', 85 controller: 'focaModalFacturaDetalleController',
85 size: 'md', 86 size: 'md',
86 resolve: { 87 resolve: {
87 factura: factura, 88 factura: factura
88 cliente: parametrosFactura.cliente
89 } 89 }
90 } 90 }
91 ); 91 );
92 modalInstance.result.then(); 92 modalInstance.result.then();
93 }; 93 };
94 94
95 $scope.search = function() { 95 $scope.search = function() {
96 if($scope.facturas.length > 0) { 96 if($scope.facturas.length > 0) {
97 $scope.filteredFacturas = $filter('filter')( 97 $scope.filteredFacturas = $filter('filter')(
98 $scope.facturas, 98 $scope.facturas,
99 {$: $scope.filters} 99 {$: $scope.filters}
100 ); 100 );
101 101
102 $scope.lastPage = Math.ceil( 102 $scope.lastPage = Math.ceil(
103 $scope.filteredFacturas.length / $scope.numPerPage 103 $scope.filteredFacturas.length / $scope.numPerPage
104 ); 104 );
105 105
106 $scope.resetPage(); 106 $scope.resetPage();
107 } 107 }
108 }; 108 };
109 109
110 $scope.resetPage = function() { 110 $scope.resetPage = function() {
111 $scope.currentPage = 1; 111 $scope.currentPage = 1;
112 $scope.selectPage(1); 112 $scope.selectPage(1);
113 }; 113 };
114 114
115 $scope.selectPage = function(page) { 115 $scope.selectPage = function(page) {
116 var start = (page - 1) * $scope.numPerPage; 116 var start = (page - 1) * $scope.numPerPage;
117 var end = start + $scope.numPerPage; 117 var end = start + $scope.numPerPage;
118 $scope.paginas = []; 118 $scope.paginas = [];
119 $scope.paginas = calcularPages(page); 119 $scope.paginas = calcularPages(page);
120 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end); 120 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
121 $scope.currentPage = page; 121 $scope.currentPage = page;
122 }; 122 };
123 123
124 $scope.cancel = function() { 124 $scope.cancel = function() {
125 $uibModalInstance.dismiss('cancel'); 125 $uibModalInstance.dismiss('cancel');
126 }; 126 };
127 127
128 $scope.busquedaDown = function(key) { 128 $scope.busquedaDown = function(key) {
129 if (key === 40) { 129 if (key === 40) {
130 primera(key); 130 primera(key);
131 } 131 }
132 }; 132 };
133 133
134 $scope.itemFactura = function(key) { 134 $scope.itemFactura = function(key) {
135 if (key === 38) { 135 if (key === 38) {
136 anterior(key); 136 anterior(key);
137 } 137 }
138 138
139 if (key === 40) { 139 if (key === 40) {
140 siguiente(key); 140 siguiente(key);
141 } 141 }
142 142
143 if (key === 37) { 143 if (key === 37) {
144 retrocederPagina(); 144 retrocederPagina();
145 } 145 }
146 146
147 if (key === 39) { 147 if (key === 39) {
148 avanzarPagina(); 148 avanzarPagina();
149 } 149 }
150 }; 150 };
151 151
152 $scope.enviarMail = function(factura) {
153 focaModalService
154 .prompt('Ingrese email para enviar comprobante', factura.MAIL_COBRANZA)
155 .then(function(res) {
156 return focaModalFacturaService.enviarFacturaPorMail(res, factura);
157 })
158 .then(function() {
159 focaModalService.alert('Mensaje enviado correctamente');
160 });
161 };
162
152 function calcularPages(paginaActual) { 163 function calcularPages(paginaActual) {
153 var paginas = []; 164 var paginas = [];
154 paginas.push(paginaActual); 165 paginas.push(paginaActual);
155 166
156 if (paginaActual - 1 > 1) { 167 if (paginaActual - 1 > 1) {
157 168
158 paginas.unshift(paginaActual - 1); 169 paginas.unshift(paginaActual - 1);
159 if (paginaActual - 2 > 1) { 170 if (paginaActual - 2 > 1) {
160 paginas.unshift(paginaActual - 2); 171 paginas.unshift(paginaActual - 2);
161 } 172 }
162 } 173 }
163 174
164 if (paginaActual + 1 < $scope.lastPage) { 175 if (paginaActual + 1 < $scope.lastPage) {
165 paginas.push(paginaActual + 1); 176 paginas.push(paginaActual + 1);
166 if (paginaActual + 2 < $scope.lastPage) { 177 if (paginaActual + 2 < $scope.lastPage) {
167 paginas.push(paginaActual + 2); 178 paginas.push(paginaActual + 2);
168 } 179 }
169 } 180 }
170 181
171 if (paginaActual !== 1) { 182 if (paginaActual !== 1) {
172 paginas.unshift(1); 183 paginas.unshift(1);
173 } 184 }
174 185
175 if (paginaActual !== $scope.lastPage) { 186 if (paginaActual !== $scope.lastPage) {
176 paginas.push($scope.lastPage); 187 paginas.push($scope.lastPage);
177 } 188 }
178 189
179 return paginas; 190 return paginas;
180 } 191 }
181 192
182 function primera() { 193 function primera() {
183 $scope.selectedFactura = 0; 194 $scope.selectedFactura = 0;
184 } 195 }
185 196
186 function anterior() { 197 function anterior() {
187 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { 198 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
188 retrocederPagina(); 199 retrocederPagina();
189 } else { 200 } else {
190 $scope.selectedFactura--; 201 $scope.selectedFactura--;
191 } 202 }
192 } 203 }
193 204
194 function siguiente() { 205 function siguiente() {
195 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { 206 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
196 $scope.selectedFactura++; 207 $scope.selectedFactura++;
197 } else { 208 } else {
198 avanzarPagina(); 209 avanzarPagina();
199 } 210 }
200 } 211 }
201 212
202 function retrocederPagina() { 213 function retrocederPagina() {
203 if ($scope.currentPage > 1) { 214 if ($scope.currentPage > 1) {
204 $scope.selectPage($scope.currentPage - 1); 215 $scope.selectPage($scope.currentPage - 1);
205 $scope.selectedFactura = $scope.numPerPage - 1; 216 $scope.selectedFactura = $scope.numPerPage - 1;
206 } 217 }
207 } 218 }
208 219
209 function avanzarPagina() { 220 function avanzarPagina() {
210 if ($scope.currentPage < $scope.lastPage) { 221 if ($scope.currentPage < $scope.lastPage) {
211 $scope.selectPage($scope.currentPage + 1); 222 $scope.selectPage($scope.currentPage + 1);
212 $scope.selectedFactura = 0; 223 $scope.selectedFactura = 0;
213 } 224 }
214 } 225 }
215 226
216 function calcularSaldos(facturas) { 227 function calcularSaldos(facturas) {
217 var saldo = 0; 228 var saldo = 0;
218 229
219 facturas.forEach(function(factura) { 230 facturas.forEach(function(factura) {
220 if (factura.TCO === 'CI' || 231 if (factura.TCO === 'CI' ||
221 factura.TCO === 'FT' || 232 factura.TCO === 'FT' ||
222 factura.TCO === 'ND'){ 233 factura.TCO === 'ND'){
223 factura.IPA = factura.IPA * -1; 234 factura.IPA = factura.IPA * -1;
224 }else{ 235 }else{
225 factura.IPA = factura.IPA; 236 factura.IPA = factura.IPA;
226 } 237 }
227 saldo += factura.IPA; 238 saldo += factura.IPA;
228 factura.saldo = saldo; 239 factura.saldo = saldo;
229 factura.saldo_show = Math.abs(saldo); 240 factura.saldo_show = Math.abs(saldo);
230 factura.IPA_SHOW = Math.abs(factura.IPA); 241 factura.IPA_SHOW = Math.abs(factura.IPA);
231 }); 242 });
232 243
233 return facturas; 244 return facturas;
234 } 245 }
235 246
236 $scope.busquedaPress(13); 247 $scope.busquedaPress(13);
237 } 248 }
238 ] 249 ]
239 ); 250 );
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, idMoneda, fechaDesde, fechaHasta) { 7 getFacturasByIdCliente: function(idCliente, idMoneda, fechaDesde, fechaHasta) {
8 return $http.get( 8 return $http.get(
9 API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' + idMoneda + '/' + 9 API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' + idMoneda + '/' +
10 fechaDesde + '/' + fechaHasta); 10 fechaDesde + '/' + fechaHasta);
11 },
12 enviarFacturaPorMail: function(receiver, factura){
13 return $http.post(API_ENDPOINT.URL + '/mail',
14 {receiver: receiver, factura: factura});
11 } 15 }
12 }; 16 };
13 } 17 }
14 ]); 18 ]);
15 19
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 <th class="text-right"></th> 17 <th class="text-right"></th>
18 <th class="text-right"></th> 18 <th class="text-right"></th>
19 </tr> 19 </tr>
20 </thead> 20 </thead>
21 <tbody> 21 <tbody>
22 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda"> 22 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
23 <td colspan="5"> 23 <td colspan="5">
24 No se encontraron resultados. 24 No se encontraron resultados.
25 </td> 25 </td>
26 </tr> 26 </tr>
27 <tr class="selectable" 27 <tr class="selectable"
28 ng-repeat="(key, factura) in currentPageFacturas"> 28 ng-repeat="(key, factura) in currentPageFacturas">
29 <td>{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td> 29 <td ng-click="factura.checked = !factura.checked">{{factura.numeroFactura}} {{factura.FECHA_COMPROBANTE | date : 'dd/MM/yyyy' : 'GMT'}}</td>
30 <td>{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td> 30 <td ng-click="factura.checked = !factura.checked">{{(factura.TCO == 'FT') ? factura.NCU + ' - ' : ''}}{{factura.FEV | date : 'dd/MM/yyyy' : 'GMT'}}</td>
31 <td class="text-right"> 31 <td class="text-right"
32 ng-click="factura.checked = !factura.checked">
32 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }} 33 {{ (factura.IPA_SHOW / parametrosFactura.cotizacion) | number:2 }}
33 <span ng-class="{'invisible': factura.IPA >= 0}">-</span> 34 <span ng-class="{'invisible': factura.IPA >= 0}">-</span>
34 </td> 35 </td>
35 <td class="text-right"> 36 <td class="text-right"
37 ng-click="factura.checked = !factura.checked">
36 {{ factura.saldo_show | number:2 }} 38 {{ factura.saldo_show | number:2 }}
37 <span ng-class="{'invisible': factura.saldo >= 0}">-</span> 39 <span ng-class="{'invisible': factura.saldo >= 0}">-</span>
38 </td> 40 </td>
39 <td class="text-right"> 41 <td class="text-right">
40 <input 42 <input
41 ng-class="{ 43 ng-class="{
42 'btn-secondary': selectedFactura != key, 44 'btn-secondary': selectedFactura != key,
43 'btn-primary': selectedFactura == key}" 45 'btn-primary': selectedFactura == key}"
44 ng-keydown="itemFactura($event.keyCode)" 46 ng-keydown="itemFactura($event.keyCode)"
45 foca-focus="selectedFactura == {{key}}" 47 foca-focus="selectedFactura == {{key}}"
46 type="checkbox" 48 type="checkbox"
47 ng-model="factura.checked" 49 ng-model="factura.checked"
48 /> 50 />
49 </td> 51 </td>
50 <td> 52 <td>
51 <button 53 <button
52 class="btn p-1" 54 class="btn p-1"
53 ng-click="verFactura(factura)" 55 ng-click="verFactura(factura)"
56 title="Ver comprobante"
54 > 57 >
55 <i class="fa fa-eye" aria-hidden="true"></i> 58 <i class="fa fa-eye" aria-hidden="true"></i>
56 </button> 59 </button>
57 </td> 60 </td>
58 <td> 61 <td>
59 <button 62 <button
60 class="btn p-1" 63 class="btn p-1"
64 ng-click="enviarMail(factura)"
65 title="Enviar comprobante por mail"
61 > 66 >
62 <i class="fa fa-envelope-o" aria-hidden="true"></i> 67 <i class="fa fa-envelope-o" aria-hidden="true"></i>
63 </button> 68 </button>
64 </td> 69 </td>
65 </tr> 70 </tr>
66 </tbody> 71 </tbody>
67 </table> 72 </table>
68 </div> 73 </div>
69 <div class="modal-footer py-1"> 74 <div class="modal-footer py-1">
70 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto"> 75 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda" class="mr-auto">
71 <ul class="pagination pagination-sm justify-content mb-0"> 76 <ul class="pagination pagination-sm justify-content mb-0">
72 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 77 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
73 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)"> 78 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
74 <span aria-hidden="true">&laquo;</span> 79 <span aria-hidden="true">&laquo;</span>
75 <span class="sr-only">Anterior</span> 80 <span class="sr-only">Anterior</span>
76 </a> 81 </a>
77 </li> 82 </li>
78 <li 83 <li
79 class="page-item" 84 class="page-item"
80 ng-repeat="pagina in paginas" 85 ng-repeat="pagina in paginas"
81 ng-class="{'active': pagina == currentPage}" 86 ng-class="{'active': pagina == currentPage}"
82 > 87 >
83 <a 88 <a
84 class="page-link" 89 class="page-link"
85 href="javascript:void();" 90 href="javascript:void();"
86 ng-click="selectPage(pagina)" 91 ng-click="selectPage(pagina)"
87 ng-bind="pagina" 92 ng-bind="pagina"
88 ></a> 93 ></a>
89 </li> 94 </li>
90 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 95 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
91 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)"> 96 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
92 <span aria-hidden="true">&raquo;</span> 97 <span aria-hidden="true">&raquo;</span>
93 <span class="sr-only">Siguiente</span> 98 <span class="sr-only">Siguiente</span>
94 </a> 99 </a>
95 </li> 100 </li>
96 </ul> 101 </ul>
97 </nav> 102 </nav>
98 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 103 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
99 <button 104 <button
100 class="btn btn-sm btn-primary" 105 class="btn btn-sm btn-primary"
101 type="button" 106 type="button"
102 ng-click="aceptar()" 107 ng-click="aceptar()"
103 ng-disabled="tieneAlMenosUno()" 108 ng-disabled="tieneAlMenosUno()"
104 >Aceptar</button> 109 >Aceptar</button>
105 </div> 110 </div>
106 111