diff --git a/src/js/controller.js b/src/js/controller.js index c1cd949..8234f46 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -4,8 +4,8 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon function ($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, focaModalService, focaBotoneraLateralService, $interval ) { + $scope.actividad = 'Logistica'; - //Datos Pantalla $scope.titulo = 'Logistica de Pedidos'; var transportista = { @@ -47,6 +47,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon }; $scope.cargar = function (idVehiculo, punto) { + if (!eligioFecha()) return; var idRemito; if (punto === -1) { @@ -70,6 +71,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon }; $scope.quitarVehiculo = function (vehiculo) { + if (!eligioFecha() || vehiculoEnUso(vehiculo)) return; focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + @@ -93,44 +95,52 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon } } ); - modalInstance.result.then(function () { + modalInstance.result + .then(function () { - }, function () { - //usar cuando se cancela el modal - }); + }) + .catch(function (err) { console.error(err); }); }; $scope.arrastra = function () { + $scope.arrastrando = true; $scope.$digest(); }; $scope.noArrastra = function () { + $scope.arrastrando = false; $scope.$digest(); }; $scope.individual = function () { + $scope.idVendedor = -1; }; $scope.mostrarDetalle = function () { + $scope.detalle = true; }; $scope.salir = function () { + $location.path('/'); }; $scope.search = function () { + getSeguimiento(); }; $scope.fecha = function () { + getSeguimiento(); }; $scope.seleccionarVehículo = function () { + var parametrosModal = { titulo: 'Búsqueda de Transportista', query: '/transportista', @@ -149,12 +159,14 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon } ] }; - focaModalService.modal(parametrosModal).then(function (transportista) { - $scope.selectVehiculo(transportista.COD, transportista.NOM); - }); + focaModalService.modal(parametrosModal) + .then(function (transportista) { + $scope.selectVehiculo(transportista.COD, transportista.NOM); + }); }; $scope.busquedaAvanzada = function () { + var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda Avanzada', @@ -169,15 +181,15 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon } } ); - modalInstance.result.then(function(data) { - actualizarMarcadores(data); - }, function () { - // funcion ejecutada cuando se cancela el modal - } - ); + modalInstance.result + .then(function (data) { + actualizarMarcadores(data); + }) + .catch(function (err) { console.err(err); }); }; - $scope.selectVehiculo = function(idTransportista, nombreTransportista) { + $scope.selectVehiculo = function (idTransportista, nombreTransportista) { + var parametrosModal = { columnas: [ { @@ -201,33 +213,36 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon titulo: 'Búsqueda de vehiculos', subTitulo: idTransportista + '-' + nombreTransportista }; - focaModalService.modal(parametrosModal).then( - function (vehiculo) { - var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); - if (existe.length) { - focaModalService.alert('El vehiculo ya ha sido cargado'); - return; - } - if (!vehiculo.cisternas.length) { - focaModalService.alert('El vehiculo no tiene cisternas'); - return; - } - $scope.vehiculos.push(vehiculo); - }, function () { - // funcion ejecutada cuando se cancela el modal - }); + focaModalService.modal(parametrosModal) + .then( + function (vehiculo) { + var existe = $filter('filter')($scope.vehiculos, { id: vehiculo.id }); + if (existe.length) { + focaModalService.alert('El vehiculo ya ha sido cargado'); + return; + } + if (!vehiculo.cisternas.length) { + focaModalService.alert('El vehiculo no tiene cisternas'); + return; + } + $scope.vehiculos.push(vehiculo); + }, function () { + // funcion ejecutada cuando se cancela el modal + }); }; - $scope.seleccionarFechaReparto = function() { - focaModalService.modalFecha('Fecha de reparto').then(function(fecha) { + $scope.seleccionarFechaReparto = function () { + + focaModalService.modalFecha('Fecha de reparto').then(function (fecha) { setearFecha(fecha); }); }; - function actualizarMarcadores (filtros) { + function actualizarMarcadores(filtros) { + var marcadores = []; if (filtros.cliente && filtros.remito === undefined) { - $scope.marcadores.forEach( function (marcador) { + $scope.marcadores.forEach(function (marcador) { if (marcador.notaPedido.cliente.NOM === filtros.cliente) { marcadores.push(marcador); } @@ -251,7 +266,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon }); } } else { - $scope.marcadores.forEach( function (marcador) { + $scope.marcadores.forEach(function (marcador) { if (filtros.remito.id === marcador.notaPedido.remito.id) { marcadores.push(marcador); } @@ -277,18 +292,21 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon } function setearFecha(fecha) { + $scope.fechaReparto = fecha; focaLogisticaPedidoRutaService.setFechaReparto(fecha); - focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha).then(function (res) { - $scope.vehiculos = res.data; - $scope.$broadcast('addCabecera', { - label: 'Fecha:', - valor: fecha.toLocaleDateString() + focaLogisticaPedidoRutaService.getUnidadesByFecha(fecha) + .then(function (res) { + $scope.vehiculos = res.data; + $scope.$broadcast('addCabecera', { + label: 'Fecha:', + valor: fecha.toLocaleDateString() + }); }); - }); } function getSeguimiento() { + var desde = new Date('1900/01/01'); var hasta = new Date('2099/01/01'); if ($scope.fechaDesde) { @@ -316,28 +334,32 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon individual: $scope.idVendedor ? true : false }; - focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { - if (!angular.equals($scope.marcadores, datos.data)) { - $scope.marcadores = datos.data; - $scope.marcadoresFiltro = $scope.marcadores; - } - }); + focaLogisticaPedidoRutaService.obtenerActividad(datos) + .then(function (datos) { + if (!angular.equals($scope.marcadores, datos.data)) { + $scope.marcadores = datos.data; + $scope.marcadoresFiltro = $scope.marcadores; + } + }); } function eliminarVehiculo(vehiculo) { - focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id).then(function (res) { - if (!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, true); - }); - } - }); + + focaLogisticaPedidoRutaService.getRemitosByIdVehiculo(vehiculo.id) + .then(function (res) { + if (!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, true); + }); + } + }); } function eligioFecha() { + if (!$scope.fechaReparto) { focaModalService.alert('Primero seleccione fecha de reparto'); return false; @@ -346,6 +368,7 @@ angular.module('focaLogisticaPedidoRuta').controller('focaLogisticaPedidoRutaCon } function vehiculoEnUso(vehiculo) { + var idUsuario = focaLogisticaPedidoRutaService.idUsuario; for (var i = 0; i < vehiculo.cisternas.length; i++) { for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {