Commit a18e70eeb596aa71707861aac995153687853349
1 parent
895c374da4
Exists in
master
aplico foca-modal mail
Showing
1 changed file
with
18 additions
and
11 deletions
Show diff stats
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 | 'focaModalService', |
| 11 | function($filter, $scope, $uibModalInstance, | 11 | function($filter, $scope, $uibModalInstance, |
| 12 | focaModalFacturaService, parametrosFactura, $uibModal, focaModalService | 12 | focaModalFacturaService, parametrosFactura, $uibModal, focaModalService |
| 13 | ) { | 13 | ) { |
| 14 | var fecha = new Date(); | 14 | var fecha = new Date(); |
| 15 | $scope.fechaHasta = new Date(); | 15 | $scope.fechaHasta = new Date(); |
| 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); |
| 17 | $scope.filters = ''; | 17 | $scope.filters = ''; |
| 18 | $scope.facturas = []; | 18 | $scope.facturas = []; |
| 19 | $scope.primerBusqueda = false; | 19 | $scope.primerBusqueda = false; |
| 20 | $scope.searchLoading = false; | 20 | $scope.searchLoading = false; |
| 21 | $scope.parametrosFactura = parametrosFactura; | 21 | $scope.parametrosFactura = parametrosFactura; |
| 22 | // pagination | 22 | // pagination |
| 23 | $scope.numPerPage = 10; | 23 | $scope.numPerPage = 10; |
| 24 | $scope.currentPage = 1; | 24 | $scope.currentPage = 1; |
| 25 | $scope.filteredFacturas = []; | 25 | $scope.filteredFacturas = []; |
| 26 | $scope.currentPageFacturas = []; | 26 | $scope.currentPageFacturas = []; |
| 27 | $scope.selectedFactura = -1; | 27 | $scope.selectedFactura = -1; |
| 28 | 28 | ||
| 29 | //METODOS | 29 | //METODOS |
| 30 | $scope.busquedaPress = function(key) { | 30 | $scope.busquedaPress = function(key) { |
| 31 | if (key === 13) { | 31 | if (key === 13) { |
| 32 | if(!$scope.fechaDesde) { | 32 | if(!$scope.fechaDesde) { |
| 33 | focaModalService.alert('INGRESE FECHA DESDE'); | 33 | focaModalService.alert('INGRESE FECHA DESDE'); |
| 34 | return; | 34 | return; |
| 35 | } | 35 | } |
| 36 | if(!$scope.fechaHasta) { | 36 | if(!$scope.fechaHasta) { |
| 37 | focaModalService.alert('INGRESE FECHA HASTA'); | 37 | focaModalService.alert('INGRESE FECHA HASTA'); |
| 38 | return; | 38 | return; |
| 39 | } | 39 | } |
| 40 | if($scope.fechaDesde > $scope.fechaHasta) { | 40 | if($scope.fechaDesde > $scope.fechaHasta) { |
| 41 | focaModalService | 41 | focaModalService |
| 42 | .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'); |
| 43 | return; | 43 | return; |
| 44 | } | 44 | } |
| 45 | $scope.searchLoading = true; | 45 | $scope.searchLoading = true; |
| 46 | //TODO hacer filtro de fecha | 46 | //TODO hacer filtro de fecha |
| 47 | focaModalFacturaService | 47 | focaModalFacturaService |
| 48 | .getFacturasByIdCliente( | 48 | .getFacturasByIdCliente( |
| 49 | parametrosFactura.cliente.COD, | 49 | parametrosFactura.cliente.COD, |
| 50 | parametrosFactura.moneda, | 50 | parametrosFactura.moneda, |
| 51 | '2001-01-01', | 51 | '2001-01-01', |
| 52 | '2100-12-31' | 52 | '2100-12-31' |
| 53 | ) | 53 | ) |
| 54 | .then(llenarDatos); | 54 | .then(llenarDatos); |
| 55 | } | 55 | } |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | $scope.aceptar = function() { | 58 | $scope.aceptar = function() { |
| 59 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); | 59 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); |
| 60 | $uibModalInstance.close(result); | 60 | $uibModalInstance.close(result); |
| 61 | }; | 61 | }; |
| 62 | 62 | ||
| 63 | $scope.tieneAlMenosUno = function() { | 63 | $scope.tieneAlMenosUno = function() { |
| 64 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); | 64 | var result = $scope.facturas.filter(function(a) {return a.checked === true;}); |
| 65 | return !result.length; | 65 | return !result.length; |
| 66 | }; | 66 | }; |
| 67 | 67 | ||
| 68 | function llenarDatos(res) { | 68 | function llenarDatos(res) { |
| 69 | $scope.facturas = []; | 69 | $scope.facturas = []; |
| 70 | $scope.filteredFacturas = []; | 70 | $scope.filteredFacturas = []; |
| 71 | $scope.currentPageFacturas = []; | 71 | $scope.currentPageFacturas = []; |
| 72 | $scope.selectedFactura = -1; | 72 | $scope.selectedFactura = -1; |
| 73 | $scope.searchLoading = false; | 73 | $scope.searchLoading = false; |
| 74 | $scope.primerBusqueda = true; | 74 | $scope.primerBusqueda = true; |
| 75 | $scope.facturas = calcularSaldos(res.data); | 75 | $scope.facturas = calcularSaldos(res.data); |
| 76 | $scope.search(); | 76 | $scope.search(); |
| 77 | primera(); | 77 | primera(); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | $scope.verFactura = function(factura) { | 80 | $scope.verFactura = function(factura) { |
| 81 | var modalInstance = $uibModal.open( | 81 | var modalInstance = $uibModal.open( |
| 82 | { | 82 | { |
| 83 | ariaLabelledBy: 'Detalle de factura', | 83 | ariaLabelledBy: 'Detalle de factura', |
| 84 | templateUrl: 'foca-modal-factura-detalle.html', | 84 | templateUrl: 'foca-modal-factura-detalle.html', |
| 85 | controller: 'focaModalFacturaDetalleController', | 85 | controller: 'focaModalFacturaDetalleController', |
| 86 | size: 'md', | 86 | size: 'md', |
| 87 | resolve: { | 87 | resolve: { |
| 88 | factura: factura | 88 | factura: factura |
| 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) { | 152 | $scope.enviarMail = function(factura) { |
| 153 | focaModalService | 153 | focaModalService.mail( |
| 154 | .prompt({ | 154 | { |
| 155 | titulo: 'Ingrese los emails separados por coma para enviar comprobante', | 155 | titulo: 'Enviar comprobante', |
| 156 | value: factura.cliente.MAIL | 156 | //TODO: CONFIGURAR DESCARGA |
| 157 | }) | 157 | descarga: { |
| 158 | .then(function(res) { | 158 | nombre: factura.numeroFactura + '.pdf', |
| 159 | return focaModalFacturaService.enviarFacturaPorMail(res, factura); | 159 | url: '/mail/comprobante/descargar', |
| 160 | }) | 160 | }, |
| 161 | .then(function() { | 161 | envio: { |
| 162 | focaModalService.alert('Mensaje enviado correctamente'); | 162 | //TODO: TOMAR EMAIL DEL CLIENTE |
| 163 | }); | 163 | mailCliente: 'jpinto@focasoftware.com', |
| 164 | url: '/mail/comprobante' | ||
| 165 | }, | ||
| 166 | options: { | ||
| 167 | factura: factura | ||
| 168 | } | ||
| 169 | } | ||
| 170 | ); | ||
| 164 | }; | 171 | }; |
| 165 | 172 | ||
| 166 | function calcularPages(paginaActual) { | 173 | function calcularPages(paginaActual) { |
| 167 | var paginas = []; | 174 | var paginas = []; |
| 168 | paginas.push(paginaActual); | 175 | paginas.push(paginaActual); |
| 169 | 176 | ||
| 170 | if (paginaActual - 1 > 1) { | 177 | if (paginaActual - 1 > 1) { |
| 171 | 178 | ||
| 172 | paginas.unshift(paginaActual - 1); | 179 | paginas.unshift(paginaActual - 1); |
| 173 | if (paginaActual - 2 > 1) { | 180 | if (paginaActual - 2 > 1) { |
| 174 | paginas.unshift(paginaActual - 2); | 181 | paginas.unshift(paginaActual - 2); |
| 175 | } | 182 | } |
| 176 | } | 183 | } |
| 177 | 184 | ||
| 178 | if (paginaActual + 1 < $scope.lastPage) { | 185 | if (paginaActual + 1 < $scope.lastPage) { |
| 179 | paginas.push(paginaActual + 1); | 186 | paginas.push(paginaActual + 1); |
| 180 | if (paginaActual + 2 < $scope.lastPage) { | 187 | if (paginaActual + 2 < $scope.lastPage) { |
| 181 | paginas.push(paginaActual + 2); | 188 | paginas.push(paginaActual + 2); |
| 182 | } | 189 | } |
| 183 | } | 190 | } |
| 184 | 191 | ||
| 185 | if (paginaActual !== 1) { | 192 | if (paginaActual !== 1) { |
| 186 | paginas.unshift(1); | 193 | paginas.unshift(1); |
| 187 | } | 194 | } |
| 188 | 195 | ||
| 189 | if (paginaActual !== $scope.lastPage) { | 196 | if (paginaActual !== $scope.lastPage) { |
| 190 | paginas.push($scope.lastPage); | 197 | paginas.push($scope.lastPage); |
| 191 | } | 198 | } |
| 192 | 199 | ||
| 193 | return paginas; | 200 | return paginas; |
| 194 | } | 201 | } |
| 195 | 202 | ||
| 196 | function primera() { | 203 | function primera() { |
| 197 | $scope.selectedFactura = 0; | 204 | $scope.selectedFactura = 0; |
| 198 | } | 205 | } |
| 199 | 206 | ||
| 200 | function anterior() { | 207 | function anterior() { |
| 201 | if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { | 208 | if ($scope.selectedFactura === 0 && $scope.currentPage > 1) { |
| 202 | retrocederPagina(); | 209 | retrocederPagina(); |
| 203 | } else { | 210 | } else { |
| 204 | $scope.selectedFactura--; | 211 | $scope.selectedFactura--; |
| 205 | } | 212 | } |
| 206 | } | 213 | } |
| 207 | 214 | ||
| 208 | function siguiente() { | 215 | function siguiente() { |
| 209 | if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { | 216 | if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) { |
| 210 | $scope.selectedFactura++; | 217 | $scope.selectedFactura++; |
| 211 | } else { | 218 | } else { |
| 212 | avanzarPagina(); | 219 | avanzarPagina(); |
| 213 | } | 220 | } |
| 214 | } | 221 | } |
| 215 | 222 | ||
| 216 | function retrocederPagina() { | 223 | function retrocederPagina() { |
| 217 | if ($scope.currentPage > 1) { | 224 | if ($scope.currentPage > 1) { |
| 218 | $scope.selectPage($scope.currentPage - 1); | 225 | $scope.selectPage($scope.currentPage - 1); |
| 219 | $scope.selectedFactura = $scope.numPerPage - 1; | 226 | $scope.selectedFactura = $scope.numPerPage - 1; |
| 220 | } | 227 | } |
| 221 | } | 228 | } |
| 222 | 229 | ||
| 223 | function avanzarPagina() { | 230 | function avanzarPagina() { |
| 224 | if ($scope.currentPage < $scope.lastPage) { | 231 | if ($scope.currentPage < $scope.lastPage) { |
| 225 | $scope.selectPage($scope.currentPage + 1); | 232 | $scope.selectPage($scope.currentPage + 1); |
| 226 | $scope.selectedFactura = 0; | 233 | $scope.selectedFactura = 0; |
| 227 | } | 234 | } |
| 228 | } | 235 | } |
| 229 | 236 | ||
| 230 | function calcularSaldos(facturas) { | 237 | function calcularSaldos(facturas) { |
| 231 | var saldo = 0; | 238 | var saldo = 0; |
| 232 | 239 | ||
| 233 | facturas.forEach(function(factura) { | 240 | facturas.forEach(function(factura) { |
| 234 | if (factura.TCO === 'CI' || | 241 | if (factura.TCO === 'CI' || |
| 235 | factura.TCO === 'FT' || | 242 | factura.TCO === 'FT' || |
| 236 | factura.TCO === 'ND'){ | 243 | factura.TCO === 'ND'){ |
| 237 | factura.IPA = factura.IPA * -1; | 244 | factura.IPA = factura.IPA * -1; |
| 238 | }else{ | 245 | }else{ |
| 239 | factura.IPA = factura.IPA; | 246 | factura.IPA = factura.IPA; |
| 240 | } | 247 | } |
| 241 | saldo += factura.IPA; | 248 | saldo += factura.IPA; |
| 242 | factura.saldo = saldo; | 249 | factura.saldo = saldo; |
| 243 | factura.saldo_show = Math.abs(saldo); | 250 | factura.saldo_show = Math.abs(saldo); |
| 244 | factura.IPA_SHOW = Math.abs(factura.IPA); | 251 | factura.IPA_SHOW = Math.abs(factura.IPA); |
| 245 | }); | 252 | }); |
| 246 | 253 | ||
| 247 | return facturas; | 254 | return facturas; |
| 248 | } | 255 | } |
| 249 | 256 | ||
| 250 | $scope.busquedaPress(13); | 257 | $scope.busquedaPress(13); |
| 251 | } | 258 | } |
| 252 | ] | 259 | ] |
| 253 | ); | 260 | ); |
| 254 | 261 |