Commit 17144b6f0af6043d5f7f967e7100f7c4d50c67be
1 parent
ac32559d1a
Exists in
master
espacio, reemplazo alert por modal.alert
Showing
2 changed files
with
11 additions
and
5 deletions
Show diff stats
src/js/app.js
| 1 | angular.module('focaModalPuntoDescarga', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']); | 1 | angular.module('focaModalPuntoDescarga', [ |
| 2 | 'ui.bootstrap', | ||
| 3 | 'focaModal', | ||
| 4 | 'focaDirectivas', | ||
| 5 | 'angular-ladda' | ||
| 6 | ]); | ||
| 2 | 7 |
src/js/controller.js
| 1 | angular.module('focaModalPuntoDescarga') | 1 | angular.module('focaModalPuntoDescarga') |
| 2 | .controller('focaModalPuntoDescargaController', [ | 2 | .controller('focaModalPuntoDescargaController', [ |
| 3 | '$timeout', | 3 | '$timeout', |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalPuntoDescargaService', | 7 | 'focaModalPuntoDescargaService', |
| 8 | 'filters', | 8 | 'filters', |
| 9 | 'focaModalService', | ||
| 9 | function($timeout, $filter, $scope, $uibModalInstance, | 10 | function($timeout, $filter, $scope, $uibModalInstance, |
| 10 | focaModalPuntoDescargaService, filters) { | 11 | focaModalPuntoDescargaService, filters, focaModalService) { |
| 11 | 12 | ||
| 12 | $scope.cantidadArticulo = 0; | 13 | $scope.cantidadArticulo = 0; |
| 13 | $scope.articuloSeleccionado = 0; | 14 | $scope.articuloSeleccionado = 0; |
| 14 | $scope.ivas = []; | 15 | $scope.ivas = []; |
| 15 | $scope.puntosSeleccionados = []; | 16 | $scope.puntosSeleccionados = []; |
| 16 | $scope.puntoDescarga = { | 17 | $scope.puntoDescarga = { |
| 17 | id: 0, | 18 | id: 0, |
| 18 | id_cliente: filters.idCliente, | 19 | id_cliente: filters.idCliente, |
| 19 | id_da_config_0: filters.idDomicilio | 20 | id_da_config_0: filters.idDomicilio |
| 20 | }; | 21 | }; |
| 21 | $scope.articulos = angular.copy(filters.articulos); | 22 | $scope.articulos = angular.copy(filters.articulos); |
| 22 | $scope.articulos.map(function(articulo) { | 23 | $scope.articulos.map(function(articulo) { |
| 23 | articulo.restante = articulo.cantidad; | 24 | articulo.restante = articulo.cantidad; |
| 24 | }); | 25 | }); |
| 25 | actualizarTabla(); | 26 | actualizarTabla(); |
| 26 | cargarPuntos(filters.puntosDescarga); | 27 | cargarPuntos(filters.puntosDescarga); |
| 27 | 28 | ||
| 28 | $scope.cancel = function() { | 29 | $scope.cancel = function() { |
| 29 | if($scope.ingreso) { | 30 | if($scope.ingreso) { |
| 30 | $scope.ingreso = false; | 31 | $scope.ingreso = false; |
| 31 | }else { | 32 | }else { |
| 32 | $uibModalInstance.dismiss('cancel'); | 33 | $uibModalInstance.dismiss('cancel'); |
| 33 | } | 34 | } |
| 34 | }; | 35 | }; |
| 35 | 36 | ||
| 36 | $scope.aceptar = function() { | 37 | $scope.aceptar = function() { |
| 37 | if($scope.cargaArticulos) { | 38 | if($scope.cargaArticulos) { |
| 38 | cargarArticulos(); | 39 | cargarArticulos(); |
| 39 | }else { | 40 | }else { |
| 40 | verCargaArticulos(); | 41 | verCargaArticulos(); |
| 41 | } | 42 | } |
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | $scope.guardar = function() { | 45 | $scope.guardar = function() { |
| 45 | focaModalPuntoDescargaService | 46 | focaModalPuntoDescargaService |
| 46 | .guardarPuntoDescarga($scope.puntoDescarga) | 47 | .guardarPuntoDescarga($scope.puntoDescarga) |
| 47 | .then(function() { | 48 | .then(function() { |
| 48 | actualizarTabla(); | 49 | actualizarTabla(); |
| 49 | $scope.ingreso = false; | 50 | $scope.ingreso = false; |
| 50 | }); | 51 | }); |
| 51 | }; | 52 | }; |
| 52 | 53 | ||
| 53 | $scope.editar = function(id) { | 54 | $scope.editar = function(id) { |
| 54 | focaModalPuntoDescargaService.getPuntoDescargaById(id).then(function(res) { | 55 | focaModalPuntoDescargaService.getPuntoDescargaById(id).then(function(res) { |
| 55 | $scope.puntoDescarga = res.data; | 56 | $scope.puntoDescarga = res.data; |
| 56 | $scope.ingreso = true; | 57 | $scope.ingreso = true; |
| 57 | }); | 58 | }); |
| 58 | }; | 59 | }; |
| 59 | 60 | ||
| 60 | $scope.eliminar = function(idx, id) { | 61 | $scope.eliminar = function(idx, id) { |
| 61 | focaModalPuntoDescargaService.eliminarPuntoDescarga(id).then(function() { | 62 | focaModalPuntoDescargaService.eliminarPuntoDescarga(id).then(function() { |
| 62 | $scope.puntosDescarga.splice(idx, 1); | 63 | $scope.puntosDescarga.splice(idx, 1); |
| 63 | }); | 64 | }); |
| 64 | }; | 65 | }; |
| 65 | 66 | ||
| 66 | $scope.seleccionarPunto = function(idx) { | 67 | $scope.seleccionarPunto = function(idx) { |
| 67 | var indexPunto = $scope.puntosSeleccionados.indexOf(idx); | 68 | var indexPunto = $scope.puntosSeleccionados.indexOf(idx); |
| 68 | if(indexPunto !== -1) { | 69 | if(indexPunto !== -1) { |
| 69 | $scope.puntosSeleccionados.splice(indexPunto, 1); | 70 | $scope.puntosSeleccionados.splice(indexPunto, 1); |
| 70 | }else { | 71 | }else { |
| 71 | $scope.puntosSeleccionados.push(idx); | 72 | $scope.puntosSeleccionados.push(idx); |
| 72 | } | 73 | } |
| 73 | }; | 74 | }; |
| 74 | 75 | ||
| 75 | $scope.agregarArticulo = function(punto) { | 76 | $scope.agregarArticulo = function(punto) { |
| 76 | var articulo = $scope.articulos[$scope.articuloSeleccionado], | 77 | var articulo = $scope.articulos[$scope.articuloSeleccionado], |
| 77 | cantidadRestante = articulo.restante - punto.cantidadACargar; | 78 | cantidadRestante = articulo.restante - punto.cantidadACargar; |
| 78 | 79 | ||
| 79 | if(cantidadRestante < 0) { | 80 | if(cantidadRestante < 0) { |
| 80 | alert('La cantidad a cargar debe ser menor o igual al restante'); | 81 | focaModalService.alert('La cantidad a cargar debe ser menor o igual al restante'); |
| 81 | }else if(punto.cantidadACargar <= 0) { | 82 | }else if(punto.cantidadACargar <= 0) { |
| 82 | alert('La cantidad a cargar debe ser mayor que cero'); | 83 | focaModalService.alert('La cantidad a cargar debe ser mayor que cero'); |
| 83 | }else { | 84 | }else { |
| 84 | punto.cargado += parseInt(punto.cantidadACargar); | 85 | punto.cargado += parseInt(punto.cantidadACargar); |
| 85 | articulo.restante = cantidadRestante; | 86 | articulo.restante = cantidadRestante; |
| 86 | var existeArticulo = punto.articulosAgregados.filter( | 87 | var existeArticulo = punto.articulosAgregados.filter( |
| 87 | function (articuloAAgregar) { | 88 | function (articuloAAgregar) { |
| 88 | return articuloAAgregar.id === articulo.id; | 89 | return articuloAAgregar.id === articulo.id; |
| 89 | }); | 90 | }); |
| 90 | //Si el articulo ya fue agregado | 91 | //Si el articulo ya fue agregado |
| 91 | if(existeArticulo.length) { | 92 | if(existeArticulo.length) { |
| 92 | //Solo sumo cantidad | 93 | //Solo sumo cantidad |
| 93 | var total = parseInt(existeArticulo[0].cantidad) + parseInt(punto.cantidadACargar); | 94 | var total = parseInt(existeArticulo[0].cantidad) + parseInt(punto.cantidadACargar); |
| 94 | existeArticulo[0].cantidad = total; | 95 | existeArticulo[0].cantidad = total; |
| 95 | }else { | 96 | }else { |
| 96 | //Agrego el articulo con la cantidad | 97 | //Agrego el articulo con la cantidad |
| 97 | punto.articulosAgregados.push({ | 98 | punto.articulosAgregados.push({ |
| 98 | id: articulo.id, | 99 | id: articulo.id, |
| 99 | descripcion: articulo.descripcion, | 100 | descripcion: articulo.descripcion, |
| 100 | cantidad: punto.cantidadACargar, | 101 | cantidad: punto.cantidadACargar, |
| 101 | index: $scope.articuloSeleccionado | 102 | index: $scope.articuloSeleccionado |
| 102 | }); | 103 | }); |
| 103 | } | 104 | } |
| 104 | punto.cantidadACargar = 0; | 105 | punto.cantidadACargar = 0; |
| 105 | } | 106 | } |
| 106 | }; | 107 | }; |
| 107 | 108 | ||
| 108 | $scope.quitarArticulo = function(articulo, idx, punto) { | 109 | $scope.quitarArticulo = function(articulo, idx, punto) { |
| 109 | var articuloAEliminar = $scope.articulos.filter(function(art) { | 110 | var articuloAEliminar = $scope.articulos.filter(function(art) { |
| 110 | return art.id == articulo.id; | 111 | return art.id == articulo.id; |
| 111 | }); | 112 | }); |
| 112 | var restante = parseInt(articuloAEliminar[0].restante); | 113 | var restante = parseInt(articuloAEliminar[0].restante); |
| 113 | restante += parseInt(articulo.cantidad); | 114 | restante += parseInt(articulo.cantidad); |
| 114 | articuloAEliminar[0].restante = restante; | 115 | articuloAEliminar[0].restante = restante; |
| 115 | 116 | ||
| 116 | punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); | 117 | punto.cargado -= parseInt(punto.articulosAgregados[idx].cantidad); |
| 117 | punto.articulosAgregados.splice(idx, 1); | 118 | punto.articulosAgregados.splice(idx, 1); |
| 118 | }; | 119 | }; |
| 119 | 120 | ||
| 120 | function actualizarTabla() { | 121 | function actualizarTabla() { |
| 121 | focaModalPuntoDescargaService | 122 | focaModalPuntoDescargaService |
| 122 | .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) | 123 | .getPuntosDescargaByClienDom(filters.idDomicilio, filters.idCliente) |
| 123 | .then(function(res) { | 124 | .then(function(res) { |
| 124 | $scope.puntosDescarga = res.data; | 125 | $scope.puntosDescarga = res.data; |
| 125 | }); | 126 | }); |
| 126 | } | 127 | } |
| 127 | function verCargaArticulos() { | 128 | function verCargaArticulos() { |
| 128 | $scope.puntosACargar = []; | 129 | $scope.puntosACargar = []; |
| 129 | $scope.cargaArticulos = true; | 130 | $scope.cargaArticulos = true; |
| 130 | $scope.puntosSeleccionados.forEach(function(idx) { | 131 | $scope.puntosSeleccionados.forEach(function(idx) { |
| 131 | $scope.puntosACargar.push($scope.puntosDescarga[idx]); | 132 | $scope.puntosACargar.push($scope.puntosDescarga[idx]); |
| 132 | }); | 133 | }); |
| 133 | 134 | ||
| 134 | $scope.puntosACargar.map(function(punto) { | 135 | $scope.puntosACargar.map(function(punto) { |
| 135 | punto.articulosAgregados = []; | 136 | punto.articulosAgregados = []; |
| 136 | punto.cantidadACargar = 0; | 137 | punto.cantidadACargar = 0; |
| 137 | punto.cargado = 0; | 138 | punto.cargado = 0; |
| 138 | }); | 139 | }); |
| 139 | } | 140 | } |
| 140 | function cargarArticulos() { | 141 | function cargarArticulos() { |
| 141 | $uibModalInstance.close($scope.puntosACargar); | 142 | $uibModalInstance.close($scope.puntosACargar); |
| 142 | } | 143 | } |
| 143 | function cargarPuntos(puntosDescarga) { | 144 | function cargarPuntos(puntosDescarga) { |
| 144 | //Si existen puntos ya cargados | 145 | //Si existen puntos ya cargados |
| 145 | if(puntosDescarga) { | 146 | if(puntosDescarga) { |
| 146 | if(!puntosDescarga[0].cargado) { | 147 | if(!puntosDescarga[0].cargado) { |
| 147 | agregarTotalCargado(puntosDescarga); | 148 | agregarTotalCargado(puntosDescarga); |
| 148 | } | 149 | } |
| 149 | $scope.puntosACargar = puntosDescarga; | 150 | $scope.puntosACargar = puntosDescarga; |
| 150 | $scope.cargaArticulos = true; | 151 | $scope.cargaArticulos = true; |
| 151 | //Recorro los puntos | 152 | //Recorro los puntos |
| 152 | puntosDescarga.forEach(function(punto) { | 153 | puntosDescarga.forEach(function(punto) { |
| 153 | //Recorro los articulos cargados en cada punto | 154 | //Recorro los articulos cargados en cada punto |
| 154 | punto.articulosAgregados.forEach(function(articulo) { | 155 | punto.articulosAgregados.forEach(function(articulo) { |
| 155 | var articuloARestar = $scope.articulos.filter(function(art) { | 156 | var articuloARestar = $scope.articulos.filter(function(art) { |
| 156 | return art.id == articulo.id; | 157 | return art.id == articulo.id; |
| 157 | }); | 158 | }); |
| 158 | articuloARestar[0].restante -= articulo.cantidad; | 159 | articuloARestar[0].restante -= articulo.cantidad; |
| 159 | }); | 160 | }); |
| 160 | }); | 161 | }); |
| 161 | } | 162 | } |
| 162 | } | 163 | } |
| 163 | function agregarTotalCargado(puntosDescarga){ | 164 | function agregarTotalCargado(puntosDescarga) { |
| 164 | puntosDescarga.map(function(punto) { | 165 | puntosDescarga.map(function(punto) { |
| 165 | punto.cantidadACargar = 0; | 166 | punto.cantidadACargar = 0; |
| 166 | punto.cargado = 0; | 167 | punto.cargado = 0; |
| 167 | }); | 168 | }); |
| 168 | //Agrego cantidad de combustible cargada en los puntos de descarga | 169 | //Agrego cantidad de combustible cargada en los puntos de descarga |
| 169 | puntosDescarga.forEach(function(punto) { | 170 | puntosDescarga.forEach(function(punto) { |
| 170 | punto.articulosAgregados.forEach(function(articulo) { | 171 | punto.articulosAgregados.forEach(function(articulo) { |
| 171 | punto.cargado += articulo.cantidad; | 172 | punto.cargado += articulo.cantidad; |
| 172 | }); | 173 | }); |
| 173 | }); | 174 | }); |
| 174 | } | 175 | } |
| 175 | }] | 176 | }] |
| 176 | ); | 177 | ); |
| 177 | 178 |