Commit 2723a81a4692351f209c4599dfc28f581f86e467
1 parent
4f696483ae
Exists in
master
seteo fecha en el servicio
Showing
1 changed file
with
9 additions
and
6 deletions
Show diff stats
src/js/controllerDetalleVehiculo.js
| 1 | angular.module('focaLogisticaPedidoRuta') | 1 | angular.module('focaLogisticaPedidoRuta') |
| 2 | .controller('focaDetalleVehiculo', | 2 | .controller('focaDetalleVehiculo', |
| 3 | ['$scope', | 3 | ['$scope', |
| 4 | '$uibModalInstance', | 4 | '$uibModalInstance', |
| 5 | 'idVehiculo', | 5 | 'idVehiculo', |
| 6 | 'idRemito', | 6 | 'idRemito', |
| 7 | 'focaModalService', | 7 | 'focaModalService', |
| 8 | '$filter', | 8 | '$filter', |
| 9 | 'focaLogisticaPedidoRutaService', | 9 | 'focaLogisticaPedidoRutaService', |
| 10 | 'fechaReparto', | ||
| 11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
| 12 | focaLogisticaPedidoRutaService, fechaReparto | 11 | focaLogisticaPedidoRutaService |
| 13 | ) { | 12 | ) { |
| 14 | //seteo variables | 13 | //seteo variables |
| 15 | $scope.cargandoDatos = true; | 14 | $scope.cargandoDatos = true; |
| 16 | $scope.idRemito = idRemito; | 15 | $scope.idRemito = idRemito; |
| 17 | $scope.articulos = []; | 16 | $scope.articulos = []; |
| 18 | $scope.vehiculo = {}; | 17 | $scope.vehiculo = {}; |
| 19 | $scope.cisternas = []; | 18 | $scope.cisternas = []; |
| 20 | $scope.cisternasCarga = []; | 19 | $scope.cisternasCarga = []; |
| 21 | $scope.remito = {}; | 20 | $scope.remito = {}; |
| 22 | $scope.aCargar = []; | 21 | $scope.aCargar = []; |
| 23 | var cisternaMovimientos = []; | 22 | var cisternaMovimientos = []; |
| 24 | var promesaRemito; | 23 | var promesaRemito; |
| 25 | var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); | 24 | var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); |
| 26 | var promesaCisternas = focaLogisticaPedidoRutaService | 25 | var promesaCisternas = focaLogisticaPedidoRutaService |
| 27 | .obtenerCisternasPorFecha(idVehiculo, fechaReparto); | 26 | .obtenerCisternasPorFecha(idVehiculo); |
| 28 | if(idRemito !== -1) { | 27 | if(idRemito !== -1) { |
| 29 | promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); | 28 | promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); |
| 30 | } | 29 | } |
| 31 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | 30 | Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { |
| 32 | $scope.cargandoDatos = false; | 31 | $scope.cargandoDatos = false; |
| 33 | $scope.vehiculo = res[0].data; | 32 | $scope.vehiculo = res[0].data; |
| 34 | $scope.cisternas = res[1].data; | 33 | $scope.cisternas = res[1].data; |
| 35 | if(!res[2]) return; | 34 | if(!res[2]) return; |
| 36 | $scope.remito = res[2].data; | 35 | $scope.remito = res[2].data; |
| 37 | if($scope.remito.idUsuarioProceso) { | 36 | if($scope.remito.idUsuarioProceso) { |
| 38 | focaModalService.alert('Remito ya asignado'); | 37 | focaModalService.alert('Remito ya asignado'); |
| 39 | $uibModalInstance.close(); | 38 | $uibModalInstance.close(); |
| 40 | } | 39 | } |
| 41 | $scope.articulos = $scope.remito.articulosRemito; | 40 | $scope.articulos = $scope.remito.articulosRemito; |
| 42 | $scope.seleccionarArticulo($scope.articulos[0]); | 41 | $scope.seleccionarArticulo($scope.articulos[0]); |
| 43 | }); | 42 | }); |
| 44 | $scope.aceptar = function() { | 43 | $scope.aceptar = function() { |
| 45 | $scope.cargando = true; | 44 | $scope.cargando = true; |
| 46 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { | 45 | for(var i = 0; i < $scope.cisternasCarga.length; i++) { |
| 47 | delete $scope.cisternasCarga[i].articulo; | 46 | delete $scope.cisternasCarga[i].articulo; |
| 48 | } | 47 | } |
| 49 | var cisterna = { | 48 | var cisterna = { |
| 50 | cisternaMovimientos: cisternaMovimientos, | 49 | cisternaMovimientos: cisternaMovimientos, |
| 51 | cisternaCargas: $scope.cisternasCarga, | 50 | cisternaCargas: $scope.cisternasCarga, |
| 52 | idVehiculo: $scope.vehiculo.id | 51 | idVehiculo: $scope.vehiculo.id |
| 53 | }; | 52 | }; |
| 54 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) | 53 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) |
| 55 | .then(function() { | 54 | .then(function() { |
| 56 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { | 55 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { |
| 57 | $scope.cargando = false; | 56 | $scope.cargando = false; |
| 58 | $uibModalInstance.close(); | 57 | $uibModalInstance.close(); |
| 59 | }); | 58 | }); |
| 60 | }).catch(function(error) { | 59 | }).catch(function(error) { |
| 61 | $scope.cargando = false; | 60 | $scope.cargando = false; |
| 62 | $uibModalInstance.close(); | 61 | $uibModalInstance.close(); |
| 63 | if (error.status === 403.1) { | 62 | if (error.status === 403.1) { |
| 64 | focaModalService.alert('ERROR: El vehículo esta en uso'); | 63 | focaModalService.alert('ERROR: El vehículo esta en uso'); |
| 65 | } | 64 | } |
| 66 | if(error.status === 403.2) { | 65 | if(error.status === 403.2) { |
| 67 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); | 66 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); |
| 68 | return; | 67 | return; |
| 69 | } | 68 | } |
| 70 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 69 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
| 71 | }); | 70 | }); |
| 72 | }; | 71 | }; |
| 73 | $scope.cancelar = function() { | 72 | $scope.cancelar = function() { |
| 74 | $uibModalInstance.close(); | 73 | $uibModalInstance.close(); |
| 75 | }; | 74 | }; |
| 76 | $scope.cargarACisternas = function() { | 75 | $scope.cargarACisternas = function() { |
| 77 | for(var i = 0; i < $scope.cisternas.length; i++) { | 76 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 78 | var cisterna = $scope.cisternas[i]; | 77 | var cisterna = $scope.cisternas[i]; |
| 79 | var aCargar = parseFloat($scope.aCargar[i]); | 78 | var aCargar = parseFloat($scope.aCargar[i]); |
| 79 | var fechaReparto = focaLogisticaPedidoRutaService.fecha; | ||
| 80 | //validaciones | 80 | //validaciones |
| 81 | if(!aCargar) { | 81 | if(!aCargar) { |
| 82 | continue; | 82 | continue; |
| 83 | } | 83 | } |
| 84 | //cargar | 84 | //cargar |
| 85 | if(cisterna.cisternaCarga.cantidad) { | 85 | if(cisterna.cisternaCarga.cantidad) { |
| 86 | cisterna.cisternaCarga.cantidad += aCargar; | 86 | cisterna.cisternaCarga.cantidad += aCargar; |
| 87 | }else { | 87 | }else { |
| 88 | cisterna.cisternaCarga.cantidad = aCargar; | 88 | cisterna.cisternaCarga.cantidad = aCargar; |
| 89 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 89 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
| 90 | } | 90 | } |
| 91 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 91 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
| 92 | 92 | ||
| 93 | cisterna.cisternaCarga.articulo = { | 93 | cisterna.cisternaCarga.articulo = { |
| 94 | DetArt: $scope.articuloSeleccionado.descripcion | 94 | DetArt: $scope.articuloSeleccionado.descripcion |
| 95 | }; | 95 | }; |
| 96 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 96 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
| 97 | .cargado = true; | 97 | .cargado = true; |
| 98 | 98 | ||
| 99 | $scope.calcularPorcentaje(cisterna); | 99 | $scope.calcularPorcentaje(cisterna); |
| 100 | //Guardar | 100 | //Guardar |
| 101 | var now = new Date(); | 101 | var now = new Date(); |
| 102 | var cisternaMovimiento = { | 102 | var cisternaMovimiento = { |
| 103 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 103 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
| 104 | cantidad: aCargar, | 104 | cantidad: aCargar, |
| 105 | metodo: 'carga', | 105 | metodo: 'carga', |
| 106 | idCisternaCarga: cisterna.cisternaCarga.id, | 106 | idCisternaCarga: cisterna.cisternaCarga.id, |
| 107 | idRemito: $scope.remito.id | 107 | idRemito: $scope.remito.id |
| 108 | }; | 108 | }; |
| 109 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 109 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
| 110 | cisterna.cisternaCarga.idCisterna = cisterna.id; | 110 | cisterna.cisternaCarga.idCisterna = cisterna.id; |
| 111 | $scope.cisternasCarga.push(cisterna.cisternaCarga); | 111 | $scope.cisternasCarga.push(cisterna.cisternaCarga); |
| 112 | cisternaMovimientos.push(cisternaMovimiento); | 112 | cisternaMovimientos.push(cisternaMovimiento); |
| 113 | } | 113 | } |
| 114 | var articuloSiguiente = $scope.articulos.filter( | 114 | var articuloSiguiente = $scope.articulos.filter( |
| 115 | function(filter) { | 115 | function(filter) { |
| 116 | return filter.cargado !== true; | 116 | return filter.cargado !== true; |
| 117 | } | 117 | } |
| 118 | ); | 118 | ); |
| 119 | if(articuloSiguiente.length > 0) { | 119 | if(articuloSiguiente.length > 0) { |
| 120 | $scope.seleccionarArticulo(articuloSiguiente[0]); | 120 | $scope.seleccionarArticulo(articuloSiguiente[0]); |
| 121 | } | 121 | } |
| 122 | }; | 122 | }; |
| 123 | $scope.calcularPorcentaje = function(cisterna) { | 123 | $scope.calcularPorcentaje = function(cisterna) { |
| 124 | if(!cisterna.cisternaCarga.cantidad) { | 124 | if(!cisterna.cisternaCarga) { |
| 125 | cisterna.cisternaCarga.cantidad = 0; | 125 | cisterna.cisternaCarga = { |
| 126 | cantidad: 0 | ||
| 127 | }; | ||
| 126 | } | 128 | } |
| 127 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 129 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
| 128 | cisterna.capacidad) + '%'; | 130 | cisterna.capacidad) + '%'; |
| 129 | var elementHtml = document.getElementById(cisterna.id); | 131 | var elementHtml = document.getElementById(cisterna.id); |
| 130 | if(elementHtml) { | 132 | if(elementHtml) { |
| 131 | elementHtml.style.width = porcentaje; | 133 | elementHtml.style.width = porcentaje; |
| 132 | } | 134 | } |
| 133 | }; | 135 | }; |
| 134 | $scope.seleccionarArticulo = function(articulo) { | 136 | $scope.seleccionarArticulo = function(articulo) { |
| 135 | $scope.articuloSeleccionado = articulo; | 137 | $scope.articuloSeleccionado = articulo; |
| 136 | $scope.cisternaDisponible(); | 138 | $scope.cisternaDisponible(); |
| 137 | $scope.autoCompletar(); | 139 | $scope.autoCompletar(); |
| 138 | $scope.actualizarArticulo(); | 140 | $scope.actualizarArticulo(); |
| 139 | }; | 141 | }; |
| 140 | $scope.actualizarArticulo = function () { | 142 | $scope.actualizarArticulo = function () { |
| 141 | $scope.articuloSeleccionado.cantidadCargada = 0; | 143 | $scope.articuloSeleccionado.cantidadCargada = 0; |
| 142 | for (var i = 0; i < $scope.aCargar.length; i++) { | 144 | for (var i = 0; i < $scope.aCargar.length; i++) { |
| 143 | $scope.articuloSeleccionado.cantidadCargada += | 145 | $scope.articuloSeleccionado.cantidadCargada += |
| 144 | parseFloat($scope.aCargar[i]) || 0; | 146 | parseFloat($scope.aCargar[i]) || 0; |
| 145 | } | 147 | } |
| 146 | }; | 148 | }; |
| 147 | $scope.autoCompletar = function() { | 149 | $scope.autoCompletar = function() { |
| 148 | $scope.aCargar = []; | 150 | $scope.aCargar = []; |
| 149 | var disponible = $filter('filter')($scope.cisternas, {disabled: false}); | 151 | var disponible = $filter('filter')($scope.cisternas, {disabled: false}); |
| 150 | var index = $scope.cisternas.indexOf(disponible[0]); | 152 | var index = $scope.cisternas.indexOf(disponible[0]); |
| 151 | $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; | 153 | $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; |
| 152 | }; | 154 | }; |
| 153 | $scope.cisternaDisponible = function() { | 155 | $scope.cisternaDisponible = function() { |
| 154 | for(var i = 0; i < $scope.cisternas.length; i++) { | 156 | for(var i = 0; i < $scope.cisternas.length; i++) { |
| 155 | if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | 157 | if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { |
| 156 | $scope.cisternas[i].disabled = true; | 158 | $scope.cisternas[i].disabled = true; |
| 157 | continue; | 159 | continue; |
| 158 | } | 160 | } |
| 159 | if($scope.cisternas[i].cisternaCarga.idProducto && | 161 | if($scope.cisternas[i].cisternaCarga && |
| 162 | $scope.cisternas[i].cisternaCarga.idProducto && | ||
| 160 | $scope.articuloSeleccionado.idArticulo !== | 163 | $scope.articuloSeleccionado.idArticulo !== |
| 161 | $scope.cisternas[i].cisternaCarga.idProducto) | 164 | $scope.cisternas[i].cisternaCarga.idProducto) |
| 162 | { | 165 | { |
| 163 | $scope.cisternas[i].disabled = true; | 166 | $scope.cisternas[i].disabled = true; |
| 164 | continue; | 167 | continue; |
| 165 | } | 168 | } |
| 166 | $scope.cisternas[i].disabled = false; | 169 | $scope.cisternas[i].disabled = false; |
| 167 | } | 170 | } |
| 168 | }; | 171 | }; |
| 169 | $scope.rellenarInput = function(input) { | 172 | $scope.rellenarInput = function(input) { |
| 170 | if(!$scope.articuloSeleccionado) return; | 173 | if(!$scope.articuloSeleccionado) return; |
| 171 | if($scope.articuloSeleccionado.cantidad - | 174 | if($scope.articuloSeleccionado.cantidad - |
| 172 | $scope.articuloSeleccionado.cantidadCargada === 0) { | 175 | $scope.articuloSeleccionado.cantidadCargada === 0) { |
| 173 | return input; | 176 | return input; |
| 174 | } | 177 | } |
| 175 | if(!input) input = 0; | 178 | if(!input) input = 0; |
| 176 | input = parseFloat(input); | 179 | input = parseFloat(input); |
| 177 | input += parseFloat($scope.articuloSeleccionado.cantidad - | 180 | input += parseFloat($scope.articuloSeleccionado.cantidad - |
| 178 | $scope.articuloSeleccionado.cantidadCargada); | 181 | $scope.articuloSeleccionado.cantidadCargada); |
| 179 | return input; | 182 | return input; |
| 180 | }; | 183 | }; |
| 181 | $scope.distribucionDisponible = function() { | 184 | $scope.distribucionDisponible = function() { |
| 182 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - | 185 | if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad - |
| 183 | $scope.articuloSeleccionado.cantidadCargada !== 0 || | 186 | $scope.articuloSeleccionado.cantidadCargada !== 0 || |
| 184 | !$scope.tieneArticulosPendientes()) { | 187 | !$scope.tieneArticulosPendientes()) { |
| 185 | return false; | 188 | return false; |
| 186 | } | 189 | } |
| 187 | return true; | 190 | return true; |
| 188 | }; | 191 | }; |
| 189 | $scope.tieneArticulosPendientes = function() { | 192 | $scope.tieneArticulosPendientes = function() { |
| 190 | var algunValorNegativo = $scope.aCargar.filter(function(p) { | 193 | var algunValorNegativo = $scope.aCargar.filter(function(p) { |
| 191 | return p < 0; | 194 | return p < 0; |
| 192 | }); | 195 | }); |
| 193 | if(algunValorNegativo.length) { | 196 | if(algunValorNegativo.length) { |
| 194 | return false; | 197 | return false; |
| 195 | } | 198 | } |
| 196 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 199 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
| 197 | return filter.cargado === true; | 200 | return filter.cargado === true; |
| 198 | }); | 201 | }); |
| 199 | if(articulosDescargados.length === $scope.articulos.length) { | 202 | if(articulosDescargados.length === $scope.articulos.length) { |
| 200 | $scope.aCargar = []; | 203 | $scope.aCargar = []; |
| 201 | return false; | 204 | return false; |
| 202 | } | 205 | } |
| 203 | return true; | 206 | return true; |
| 204 | }; | 207 | }; |
| 205 | }]); | 208 | }]); |