From ec438219531cc6f3318728d0ca3c0b4a93a01075 Mon Sep 17 00:00:00 2001 From: efernandez Date: Thu, 3 Jan 2019 13:25:42 -0300 Subject: [PATCH] =?UTF-8?q?controlo=20eliminaci=C3=B3n=20cuando=20el=20veh?= =?UTF-8?q?=C3=ADculo=20tiene=20remitos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/controller.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/js/controller.js b/src/js/controller.js index 08687b9..3ef5b87 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -59,7 +59,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo $scope.quitarVehiculo = function(vehiculo) { focaModalService.confirm('Esta seguro que desea eliminar el vehĂ­culo ' + vehiculo.codigo + '?').then(function() { - $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); + eliminarVehiculo(vehiculo); }); }; @@ -197,6 +197,19 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo } }); } + + function eliminarVehiculo(vehiculo) { + focaLogisticaPedidoRutaService.getRemitos(vehiculo.id).then(function(res) { + if(!focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data).length) { + $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); + }else { + focaModalService.alert('No ha sido posible eliminar el vehiculo porque ' + + 'tiene remitos asociados').then(function() { + $scope.hacerHojaRuta(vehiculo); + }); + } + }); + } $interval(function() { getSeguimiento(); }, 5000); -- 1.9.1