angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [ '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter', 'focaModalService', 'focaBotoneraLateralService', function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter, focaModalService, focaBotoneraLateralService ) { $scope.now = new Date(); $scope.actividad = 'Logistica'; //Datos Pantalla $scope.titulo = 'Logistica de Pedidos'; $scope.botonera = ['Vehiculo']; var cabecera = ''; $scope.idUsuario = 0; $scope.marcadores = []; $scope.vehiculos = []; var idsRemitos = []; getSeguimiento(); $scope.arrastrando = false; $scope.general = function() { $scope.idUsuario = 0; getSeguimiento(); }; //SETEO BOTONERA LATERAL focaBotoneraLateralService.showSalir(true); focaBotoneraLateralService.showPausar(false); focaBotoneraLateralService.showGuardar(false); $scope.general = function() { $scope.idUsuario = 0; getSeguimiento(); $scope.$broadcast('removeCabecera', cabecera); $scope.$broadcast('addCabecera',{ label: 'General', valor: '' }); }; $scope.cargar = function(idVehiculo, punto) { var idRemito = JSON.parse(punto).notaPedido.remito.id; var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Vehiculo', templateUrl: 'foca-detalle-vehiculo.html', controller: 'focaDetalleVehiculo', size: 'lg', resolve: { idVehiculo: function() {return idVehiculo;}, idRemito: function() {return idRemito;} } } ); modalInstance.result.then(function(idRemito) { idsRemitos.push(idRemito); }, function() { }); }; $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); }); }; $scope.hacerHojaRuta = function(vehiculo) { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Creación hoja ruta', templateUrl: 'foca-modal-crear-hoja-ruta.html', controller: 'focaModalCrearHojaRuta', size: 'lg', resolve: { idVehiculo: function() {return vehiculo.id;}, idsRemitos: function() {return idsRemitos;} } } ); modalInstance.result.then(function() { }, function() { //usar cuando se cancela el modal }); }; $scope.arrastra = function() { $scope.arrastrando = true; $scope.$digest(); }; $scope.noArrastra = function() { $scope.arrastrando = false; $scope.$digest(); }; $scope.individual = function() { $scope.idUsuario = -1; }; $scope.mostrarDetalle = function() { $scope.detalle = true; }; $scope.salir = function() { $location.path('/'); }; $scope.search = function(key) { if (key === 13) { $scope.idUsuario = $scope.idUsuarioInput; getSeguimiento(); $scope.$broadcast('removeCabecera', 'General'); $scope.$broadcast('addCabecera', { label: cabecera, valor: $scope.idUsuarioInput }); } }; $scope.fecha = function() { getSeguimiento(); }; $scope.seleccionarVehiculo = function() { var modalInstance = $uibModal.open( { ariaLabelledBy: 'Busqueda de Vehiculo', templateUrl: 'modal-vehiculo.html', controller: 'focaModalVehiculoController', size: 'lg' } ); modalInstance.result.then( function(vehiculo) { var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id}); if(existe.length) { focaModalService.alert('El vehiculo que intenta cargar 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 } ); }; function getSeguimiento() { var now = $scope.now; var desde = new Date(new Date(now.setHours(0)).setMinutes(0)); desde = desde.setDate(desde.getDate() - 1); desde = new Date(desde); var datos = { actividad: $scope.actividad, idUsuario: $scope.idUsuario, fechaDesde: desde, fechaHasta: new Date(new Date(now.setHours(23)).setMinutes(59)) }; $scope.datosBuscados = { actividad: $scope.actividad, individual: $scope.idUsuario !== 0 ? true : false }; focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) { $scope.marcadores = datos.data; }); } } ]);