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