Commit 673ad2b49283fdd9f5e20d12de437892db0a3ea7
1 parent
4880965f3e
Exists in
master
and in
1 other branch
Cambio en el servicio para traer el resumen de cuenta.
Showing
2 changed files
with
20 additions
and
17 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalResumenCuenta') | 1 | angular.module('focaModalResumenCuenta') |
| 2 | .controller('focaModalResumenCuentaController', [ | 2 | .controller('focaModalResumenCuentaController', [ |
| 3 | '$timeout', | 3 | '$timeout', |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalResumenCuentaService', | 7 | 'focaModalResumenCuentaService', |
| 8 | 'cliente', | 8 | 'cliente', |
| 9 | 'idMoneda', | ||
| 9 | '$uibModal', | 10 | '$uibModal', |
| 10 | 'focaModalService', | 11 | 'focaModalService', |
| 11 | function ($timeout, $filter, $scope, $uibModalInstance, | 12 | function ($timeout, $filter, $scope, $uibModalInstance, |
| 12 | focaModalResumenCuentaService, cliente, $uibModal, focaModalService) { | 13 | focaModalResumenCuentaService, cliente, idMoneda, $uibModal, focaModalService) { |
| 13 | var fecha = new Date(); | 14 | var fecha = new Date(); |
| 14 | $scope.generado = false; | 15 | $scope.generado = false; |
| 15 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); |
| 16 | $scope.currentPageFacturas = []; | 17 | $scope.currentPageFacturas = []; |
| 17 | $scope.currentPage = 1; | 18 | $scope.currentPage = 1; |
| 18 | $scope.numPerPage = 10; | 19 | $scope.numPerPage = 10; |
| 19 | $scope.selectedFactura = -1; | 20 | $scope.selectedFactura = -1; |
| 20 | 21 | ||
| 21 | $scope.generar = function () { | 22 | $scope.generar = function () { |
| 22 | focaModalResumenCuentaService | 23 | focaModalResumenCuentaService |
| 23 | .getResumenCuenta(cliente.COD, $scope.fechaDesde) | 24 | .getResumenCuenta(cliente.COD, idMoneda, $scope.fechaDesde) |
| 24 | .then(function (res) { | 25 | .then(function (res) { |
| 25 | res.data.facturas = res.data.facturas.filter(function(factura){ | 26 | res.data = res.data.filter(function(factura){ |
| 26 | return factura.TCO !== "RC" && factura.TCO !== "RE" | 27 | return factura.TCO !== "RC" && factura.TCO !== "RE" |
| 27 | }) | 28 | }) |
| 28 | res.data.facturas = calcularSaldos(res.data.facturas); | 29 | res.data = calcularSaldos(res.data); |
| 29 | $scope.generado = true; | 30 | $scope.generado = true; |
| 30 | $scope.results = res.data; | 31 | $scope.results = res.data; |
| 31 | $scope.results.fechaDesde = $scope.fechaDesde; | 32 | // $scope.results.fechaDesde = $scope.fechaDesde; |
| 32 | $scope.search(); | 33 | $scope.search(); |
| 33 | }); | 34 | }); |
| 34 | }; | 35 | }; |
| 35 | 36 | ||
| 36 | $scope.cancel = function () { | 37 | $scope.cancel = function () { |
| 37 | if ($scope.generado) { | 38 | if ($scope.generado) { |
| 38 | $scope.generado = false; | 39 | $scope.generado = false; |
| 39 | } else { | 40 | } else { |
| 40 | $uibModalInstance.dismiss('cancel'); | 41 | $uibModalInstance.dismiss('cancel'); |
| 41 | } | 42 | } |
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | $scope.enviarMail = function (factura) { | 45 | $scope.enviarMail = function (factura) { |
| 45 | focaModalService.mail( | 46 | focaModalService.mail( |
| 46 | { | 47 | { |
| 47 | titulo: 'Enviar comprobante', | 48 | titulo: 'Enviar comprobante', |
| 48 | descarga: { | 49 | descarga: { |
| 49 | nombre: factura.numeroFactura + '.pdf', | 50 | nombre: factura.numeroFactura + '.pdf', |
| 50 | url: '/mail/comprobante/descargar', | 51 | url: '/mail/comprobante/descargar', |
| 51 | }, | 52 | }, |
| 52 | envio: { | 53 | envio: { |
| 53 | mailCliente: cliente.MAIL, | 54 | mailCliente: cliente.MAIL, |
| 54 | url: '/mail/comprobante' | 55 | url: '/mail/comprobante' |
| 55 | }, | 56 | }, |
| 56 | options: { | 57 | options: { |
| 57 | factura: factura | 58 | factura: factura |
| 58 | } | 59 | } |
| 59 | } | 60 | } |
| 60 | ); | 61 | ); |
| 61 | }; | 62 | }; |
| 62 | 63 | ||
| 63 | $scope.enviarResumen = function () { | 64 | $scope.enviarResumen = function () { |
| 64 | focaModalService.mail( | 65 | focaModalService.mail( |
| 65 | { | 66 | { |
| 66 | titulo: 'Enviar resumen de cuenta', | 67 | titulo: 'Enviar resumen de cuenta', |
| 67 | descarga: { | 68 | descarga: { |
| 68 | nombre: 'resumen-de-cuenta.pdf', | 69 | nombre: 'resumen-de-cuenta.pdf', |
| 69 | url: '/mail/resumen-cuenta/descargar', | 70 | url: '/mail/resumen-cuenta/descargar', |
| 70 | }, | 71 | }, |
| 71 | envio: { | 72 | envio: { |
| 72 | mailCliente: cliente.MAIL, | 73 | mailCliente: cliente.MAIL, |
| 73 | url: '/mail/resumen-cuenta', | 74 | url: '/mail/resumen-cuenta', |
| 74 | }, | 75 | }, |
| 75 | options: { | 76 | options: { |
| 76 | resumen: $scope.results | 77 | resumen: $scope.results |
| 77 | } | 78 | } |
| 78 | } | 79 | } |
| 79 | ); | 80 | ); |
| 80 | }; | 81 | }; |
| 81 | 82 | ||
| 82 | $scope.verFactura = function (factura) { | 83 | $scope.verFactura = function (factura) { |
| 83 | var modalInstance = $uibModal.open( | 84 | var modalInstance = $uibModal.open( |
| 84 | { | 85 | { |
| 85 | ariaLabelledBy: 'Detalle de factura', | 86 | ariaLabelledBy: 'Detalle de factura', |
| 86 | templateUrl: 'foca-modal-factura-detalle.html', | 87 | templateUrl: 'foca-modal-factura-detalle.html', |
| 87 | controller: 'focaModalFacturaDetalleController', | 88 | controller: 'focaModalFacturaDetalleController', |
| 88 | size: 'md', | 89 | size: 'md', |
| 89 | resolve: { | 90 | resolve: { |
| 90 | factura: factura | 91 | factura: factura |
| 91 | } | 92 | } |
| 92 | } | 93 | } |
| 93 | ); | 94 | ); |
| 94 | modalInstance.result.then(); | 95 | modalInstance.result.then(); |
| 95 | }; | 96 | }; |
| 96 | 97 | ||
| 97 | 98 | ||
| 98 | $scope.search = function () { | 99 | $scope.search = function () { |
| 99 | if ($scope.results.facturas.length) { | 100 | if ($scope.results.length) { |
| 100 | $scope.lastPage = Math.ceil( | 101 | $scope.lastPage = Math.ceil( |
| 101 | $scope.results.facturas.length / $scope.numPerPage | 102 | $scope.results.length / $scope.numPerPage |
| 102 | ); | 103 | ); |
| 103 | $scope.resetPage(); | 104 | $scope.resetPage(); |
| 104 | } | 105 | } |
| 105 | }; | 106 | }; |
| 106 | 107 | ||
| 107 | $scope.resetPage = function () { | 108 | $scope.resetPage = function () { |
| 108 | $scope.currentPage = 1; | 109 | $scope.currentPage = 1; |
| 109 | $scope.selectPage(1); | 110 | $scope.selectPage(1); |
| 110 | }; | 111 | }; |
| 111 | 112 | ||
| 112 | $scope.selectPage = function (page) { | 113 | $scope.selectPage = function (page) { |
| 113 | var start = (page - 1) * $scope.numPerPage; | 114 | var start = (page - 1) * $scope.numPerPage; |
| 114 | var end = start + $scope.numPerPage; | 115 | var end = start + $scope.numPerPage; |
| 115 | $scope.paginas = []; | 116 | $scope.paginas = []; |
| 116 | $scope.paginas = calcularPages(page); | 117 | $scope.paginas = calcularPages(page); |
| 117 | $scope.currentPageFacturas = $scope.results.facturas.slice(start, end); | 118 | $scope.currentPageFacturas = $scope.results.slice(start, end); |
| 118 | $scope.currentPage = page; | 119 | $scope.currentPage = page; |
| 119 | }; | 120 | }; |
| 120 | 121 | ||
| 121 | function calcularPages(paginaActual) { | 122 | function calcularPages(paginaActual) { |
| 122 | var paginas = []; | 123 | var paginas = []; |
| 123 | paginas.push(paginaActual); | 124 | paginas.push(paginaActual); |
| 124 | 125 | ||
| 125 | if (paginaActual - 1 > 1) { | 126 | if (paginaActual - 1 > 1) { |
| 126 | 127 | ||
| 127 | paginas.unshift(paginaActual - 1); | 128 | paginas.unshift(paginaActual - 1); |
| 128 | if (paginaActual - 2 > 1) { | 129 | if (paginaActual - 2 > 1) { |
| 129 | paginas.unshift(paginaActual - 2); | 130 | paginas.unshift(paginaActual - 2); |
| 130 | } | 131 | } |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | if (paginaActual + 1 < $scope.lastPage) { | 134 | if (paginaActual + 1 < $scope.lastPage) { |
| 134 | paginas.push(paginaActual + 1); | 135 | paginas.push(paginaActual + 1); |
| 135 | if (paginaActual + 2 < $scope.lastPage) { | 136 | if (paginaActual + 2 < $scope.lastPage) { |
| 136 | paginas.push(paginaActual + 2); | 137 | paginas.push(paginaActual + 2); |
| 137 | } | 138 | } |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | if (paginaActual !== 1) { | 141 | if (paginaActual !== 1) { |
| 141 | paginas.unshift(1); | 142 | paginas.unshift(1); |
| 142 | } | 143 | } |
| 143 | 144 | ||
| 144 | if (paginaActual !== $scope.lastPage) { | 145 | if (paginaActual !== $scope.lastPage) { |
| 145 | paginas.push($scope.lastPage); | 146 | paginas.push($scope.lastPage); |
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | return paginas; | 149 | return paginas; |
| 149 | } | 150 | } |
| 150 | 151 | ||
| 151 | function calcularSaldos(facturas) { | 152 | function calcularSaldos(facturas) { |
| 152 | var saldo = 0; | 153 | var saldo = 0; |
| 153 | 154 | ||
| 154 | facturas.forEach(function (factura) { | 155 | facturas.forEach(function (factura) { |
| 155 | if (factura.TCO === 'CI' || | 156 | if (factura.TCO === 'CI' || |
| 156 | factura.TCO === 'FT' || | 157 | factura.TCO === 'FT' || |
| 157 | factura.TCO === 'ND') { | 158 | factura.TCO === 'ND') { |
| 158 | factura.IPA = factura.IPA * -1; | 159 | factura.IPA = factura.IPA * -1; |
| 159 | } else { | 160 | } else { |
| 160 | factura.IPA = factura.IPA; | 161 | factura.IPA = factura.IPA; |
| 161 | } | 162 | } |
| 162 | saldo += factura.IPA; | 163 | saldo += factura.IPA; |
| 163 | factura.saldo = saldo; | 164 | factura.saldo = saldo; |
| 164 | factura.saldo_show = Math.abs(saldo); | 165 | factura.saldo_show = Math.abs(saldo); |
| 165 | factura.IPA_SHOW = Math.abs(factura.IPA); | 166 | factura.IPA_SHOW = Math.abs(factura.IPA); |
| 166 | }); | 167 | }); |
| 167 | 168 | facturas.saldo = saldo; | |
| 168 | return facturas; | 169 | return facturas; |
| 169 | } | 170 | } |
| 170 | }] | 171 | }] |
| 171 | ); | 172 | ); |
| 172 | 173 |
src/js/service.js
| 1 | angular.module('focaModalResumenCuenta') | 1 | angular.module('focaModalResumenCuenta') |
| 2 | .factory('focaModalResumenCuentaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('focaModalResumenCuentaService', ['$http', 'API_ENDPOINT', function ($http, API_ENDPOINT) { |
| 3 | return { | 3 | return { |
| 4 | getResumenCuenta: function(idCliente, fechaDesde) { | 4 | getResumenCuenta: function (idCliente, idMoneda, fechaDesde) { |
| 5 | return $http.get(API_ENDPOINT.URL + | 5 | return $http.get(API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' + idMoneda + '/' + |
| 6 | '/factura/resumen/' + idCliente + '/' + fechaDesde); | 6 | fechaDesde + '/' + '2100-12-31' + '/' + true); |
| 7 | // '2001-01-01', | ||
| 8 | // '2100-12-31' | ||
| 7 | }, | 9 | }, |
| 8 | enviarFacturaPorMail: function(receiver, factura) { | 10 | enviarFacturaPorMail: function (receiver, factura) { |
| 9 | return $http.post(API_ENDPOINT.URL + '/mail', | 11 | return $http.post(API_ENDPOINT.URL + '/mail', |
| 10 | {receiver: receiver, factura: factura}); | 12 | { receiver: receiver, factura: factura }); |
| 11 | }, | 13 | }, |
| 12 | enviarResumenPorMail: function(receiver, resumen) { | 14 | enviarResumenPorMail: function (receiver, resumen) { |
| 13 | return $http.post(API_ENDPOINT.URL + '/mail/resumen-cuenta', | 15 | return $http.post(API_ENDPOINT.URL + '/mail/resumen-cuenta', |
| 14 | {receiver: receiver, resumen: resumen}); | 16 | { receiver: receiver, resumen: resumen }); |
| 15 | } | 17 | } |
| 16 | }; | 18 | }; |
| 17 | }]); | 19 | }]); |
| 18 | 20 |