Commit af8a43d04a1e1b9135c3659695892401b15af8ef
1 parent
94dc34b5e1
Exists in
master
se seleccionar primer articulo por defecto
Showing
1 changed file
with
1 additions
and
0 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 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, | 10 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
| 11 | focaLogisticaPedidoRutaService | 11 | focaLogisticaPedidoRutaService |
| 12 | ) { | 12 | ) { |
| 13 | //seteo variables | 13 | //seteo variables |
| 14 | $scope.idRemito = idRemito; | 14 | $scope.idRemito = idRemito; |
| 15 | $scope.articulos = []; | 15 | $scope.articulos = []; |
| 16 | $scope.vehiculo = {}; | 16 | $scope.vehiculo = {}; |
| 17 | $scope.remito = {}; | 17 | $scope.remito = {}; |
| 18 | $scope.aCargar = []; | 18 | $scope.aCargar = []; |
| 19 | var cisternaMovimientos = []; | 19 | var cisternaMovimientos = []; |
| 20 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( | 20 | focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then( |
| 21 | function(res) { | 21 | function(res) { |
| 22 | $scope.vehiculo = res.data; | 22 | $scope.vehiculo = res.data; |
| 23 | } | 23 | } |
| 24 | ); | 24 | ); |
| 25 | if(idRemito !== -1) { | 25 | if(idRemito !== -1) { |
| 26 | focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( | 26 | focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito).then( |
| 27 | function(res) { | 27 | function(res) { |
| 28 | $scope.remito = res.data; | 28 | $scope.remito = res.data; |
| 29 | if($scope.remito.idUsuarioProceso) { | 29 | if($scope.remito.idUsuarioProceso) { |
| 30 | focaModalService.alert('El remito esta siendo cargado por otro usario'); | 30 | focaModalService.alert('El remito esta siendo cargado por otro usario'); |
| 31 | $uibModalInstance.close(); | 31 | $uibModalInstance.close(); |
| 32 | } | 32 | } |
| 33 | $scope.articulos = res.data.articulosRemito; | 33 | $scope.articulos = res.data.articulosRemito; |
| 34 | $scope.cambioArticulo($scope.articulos[0]); | ||
| 34 | } | 35 | } |
| 35 | ); | 36 | ); |
| 36 | } | 37 | } |
| 37 | $scope.aceptar = function() { | 38 | $scope.aceptar = function() { |
| 38 | $scope.cargando = true; | 39 | $scope.cargando = true; |
| 39 | var cisternaCargas = []; | 40 | var cisternaCargas = []; |
| 40 | for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { | 41 | for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { |
| 41 | delete $scope.vehiculo.cisternas[i].cisternaCarga.articulo; | 42 | delete $scope.vehiculo.cisternas[i].cisternaCarga.articulo; |
| 42 | cisternaCargas.push($scope.vehiculo.cisternas[i].cisternaCarga); | 43 | cisternaCargas.push($scope.vehiculo.cisternas[i].cisternaCarga); |
| 43 | } | 44 | } |
| 44 | var cisterna = { | 45 | var cisterna = { |
| 45 | cisternaMovimientos: cisternaMovimientos, | 46 | cisternaMovimientos: cisternaMovimientos, |
| 46 | cisternaCargas: cisternaCargas, | 47 | cisternaCargas: cisternaCargas, |
| 47 | idVehiculo: $scope.vehiculo.id | 48 | idVehiculo: $scope.vehiculo.id |
| 48 | }; | 49 | }; |
| 49 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) | 50 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) |
| 50 | .then(function() { | 51 | .then(function() { |
| 51 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { | 52 | focaModalService.alert('Cisternas cargadas con éxito').then(function() { |
| 52 | $scope.cargando = false; | 53 | $scope.cargando = false; |
| 53 | $uibModalInstance.close(); | 54 | $uibModalInstance.close(); |
| 54 | }); | 55 | }); |
| 55 | }).catch(function(error) { | 56 | }).catch(function(error) { |
| 56 | $scope.cargando = false; | 57 | $scope.cargando = false; |
| 57 | $uibModalInstance.close(); | 58 | $uibModalInstance.close(); |
| 58 | if (error.status === 403.1) { | 59 | if (error.status === 403.1) { |
| 59 | focaModalService.alert('ERROR: El vehículo esta en uso'); | 60 | focaModalService.alert('ERROR: El vehículo esta en uso'); |
| 60 | } | 61 | } |
| 61 | if(error.status === 403.2) { | 62 | if(error.status === 403.2) { |
| 62 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); | 63 | focaModalService.alert('ERROR: Otro usario ya cargó este remito'); |
| 63 | return; | 64 | return; |
| 64 | } | 65 | } |
| 65 | focaModalService.alert('Hubo un error al cargar las cisternas'); | 66 | focaModalService.alert('Hubo un error al cargar las cisternas'); |
| 66 | }); | 67 | }); |
| 67 | }; | 68 | }; |
| 68 | 69 | ||
| 69 | $scope.cancelar = function() { | 70 | $scope.cancelar = function() { |
| 70 | $uibModalInstance.close(); | 71 | $uibModalInstance.close(); |
| 71 | }; | 72 | }; |
| 72 | 73 | ||
| 73 | $scope.cargarACisternas = function(vehiculo) { | 74 | $scope.cargarACisternas = function(vehiculo) { |
| 74 | for(var i = 0; i < vehiculo.cisternas.length; i++) { | 75 | for(var i = 0; i < vehiculo.cisternas.length; i++) { |
| 75 | var cisterna = vehiculo.cisternas[i]; | 76 | var cisterna = vehiculo.cisternas[i]; |
| 76 | var aCargar = parseFloat($scope.aCargar[i]); | 77 | var aCargar = parseFloat($scope.aCargar[i]); |
| 77 | //validaciones | 78 | //validaciones |
| 78 | if(!aCargar) { | 79 | if(!aCargar) { |
| 79 | continue; | 80 | continue; |
| 80 | } | 81 | } |
| 81 | if(aCargar > cisterna.disponible) { | 82 | if(aCargar > cisterna.disponible) { |
| 82 | focaModalService.alert('La cantidad cargada supera la capacidad de la' + | 83 | focaModalService.alert('La cantidad cargada supera la capacidad de la' + |
| 83 | 'cisterna ' + cisterna.codigo); | 84 | 'cisterna ' + cisterna.codigo); |
| 84 | return; | 85 | return; |
| 85 | } | 86 | } |
| 86 | //cargar | 87 | //cargar |
| 87 | if(cisterna.cisternaCarga.cantidad) { | 88 | if(cisterna.cisternaCarga.cantidad) { |
| 88 | cisterna.cisternaCarga.cantidad += aCargar; | 89 | cisterna.cisternaCarga.cantidad += aCargar; |
| 89 | }else { | 90 | }else { |
| 90 | cisterna.cisternaCarga.cantidad = aCargar; | 91 | cisterna.cisternaCarga.cantidad = aCargar; |
| 91 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; | 92 | cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo; |
| 92 | } | 93 | } |
| 93 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; | 94 | cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad; |
| 94 | 95 | ||
| 95 | cisterna.cisternaCarga.articulo = { | 96 | cisterna.cisternaCarga.articulo = { |
| 96 | DetArt: $scope.articuloSeleccionado.descripcion | 97 | DetArt: $scope.articuloSeleccionado.descripcion |
| 97 | }; | 98 | }; |
| 98 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] | 99 | $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0] |
| 99 | .cargado = true; | 100 | .cargado = true; |
| 100 | 101 | ||
| 101 | $scope.calcularPorcentaje(cisterna); | 102 | $scope.calcularPorcentaje(cisterna); |
| 102 | //Guardar | 103 | //Guardar |
| 103 | var now = new Date(); | 104 | var now = new Date(); |
| 104 | var cisternaMovimiento = { | 105 | var cisternaMovimiento = { |
| 105 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 106 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
| 106 | cantidad: aCargar, | 107 | cantidad: aCargar, |
| 107 | metodo: 'carga', | 108 | metodo: 'carga', |
| 108 | idCisternaCarga: cisterna.cisternaCarga.id, | 109 | idCisternaCarga: cisterna.cisternaCarga.id, |
| 109 | idRemito: $scope.remito.id | 110 | idRemito: $scope.remito.id |
| 110 | }; | 111 | }; |
| 111 | cisternaMovimientos.push(cisternaMovimiento); | 112 | cisternaMovimientos.push(cisternaMovimiento); |
| 112 | } | 113 | } |
| 113 | var articuloSiguiente = $scope.articulos.filter( | 114 | var articuloSiguiente = $scope.articulos.filter( |
| 114 | function(filter) { | 115 | function(filter) { |
| 115 | return filter.cargado !== true; | 116 | return filter.cargado !== true; |
| 116 | } | 117 | } |
| 117 | ); | 118 | ); |
| 118 | if(articuloSiguiente.length > 0) { | 119 | if(articuloSiguiente.length > 0) { |
| 119 | $scope.cambioArticulo(articuloSiguiente[0]); | 120 | $scope.cambioArticulo(articuloSiguiente[0]); |
| 120 | } | 121 | } |
| 121 | $scope.aCargar = []; | 122 | $scope.aCargar = []; |
| 122 | }; | 123 | }; |
| 123 | $scope.calcularPorcentaje = function(cisterna) { | 124 | $scope.calcularPorcentaje = function(cisterna) { |
| 124 | if(!cisterna.cisternaCarga.cantidad) { | 125 | if(!cisterna.cisternaCarga.cantidad) { |
| 125 | cisterna.cisternaCarga.cantidad = 0; | 126 | cisterna.cisternaCarga.cantidad = 0; |
| 126 | } | 127 | } |
| 127 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / | 128 | var porcentaje = (cisterna.cisternaCarga.cantidad * 100 / |
| 128 | cisterna.capacidad) + '%'; | 129 | cisterna.capacidad) + '%'; |
| 129 | var elementHtml = document.getElementById(cisterna.id); | 130 | var elementHtml = document.getElementById(cisterna.id); |
| 130 | if(elementHtml) { | 131 | if(elementHtml) { |
| 131 | elementHtml.style.width = porcentaje; | 132 | elementHtml.style.width = porcentaje; |
| 132 | } | 133 | } |
| 133 | }; | 134 | }; |
| 134 | $scope.cambioArticulo = function(articulo) { | 135 | $scope.cambioArticulo = function(articulo) { |
| 135 | articulo.checked = true; | 136 | articulo.checked = true; |
| 136 | $scope.articuloSeleccionado = articulo; | 137 | $scope.articuloSeleccionado = articulo; |
| 137 | }; | 138 | }; |
| 138 | $scope.actualizarArticulo = function () { | 139 | $scope.actualizarArticulo = function () { |
| 139 | $scope.articuloSeleccionado.cantidadCargada = 0; | 140 | $scope.articuloSeleccionado.cantidadCargada = 0; |
| 140 | for (var i = 0; i < $scope.aCargar.length; i++) { | 141 | for (var i = 0; i < $scope.aCargar.length; i++) { |
| 141 | $scope.articuloSeleccionado.cantidadCargada += | 142 | $scope.articuloSeleccionado.cantidadCargada += |
| 142 | parseFloat($scope.aCargar[i]) || 0; | 143 | parseFloat($scope.aCargar[i]) || 0; |
| 143 | } | 144 | } |
| 144 | }; | 145 | }; |
| 145 | $scope.tieneArticulosPendientes = function() { | 146 | $scope.tieneArticulosPendientes = function() { |
| 146 | var articulosDescargados = $scope.articulos.filter(function(filter) { | 147 | var articulosDescargados = $scope.articulos.filter(function(filter) { |
| 147 | return filter.cargado === true; | 148 | return filter.cargado === true; |
| 148 | }); | 149 | }); |
| 149 | if(articulosDescargados.length === $scope.articulos.length) { | 150 | if(articulosDescargados.length === $scope.articulos.length) { |
| 150 | return false; | 151 | return false; |
| 151 | } | 152 | } |
| 152 | return true; | 153 | return true; |
| 153 | }; | 154 | }; |
| 154 | }]); | 155 | }]); |
| 155 | 156 |