angular.module('focaAdminSeguimiento').controller('focaAdminSeguimientoController', [ '$scope', '$timeout', 'focaAdminSeguimientoService', '$uibModal', 'focaBotoneraLateralService','$location', '$routeParams', function($scope, $timeout, focaAdminSeguimientoService, $uibModal, focaBotoneraLateralService, $location, $routeParams) { $scope.actividad = ''; $scope.titulo = ''; var cabecera = ''; var plural = ''; $scope.now = new Date(); $scope.dateOptions = { maxDate: new Date() }; switch ($routeParams.parametro) { case 'nota-pedido': $scope.actividad = 'Nota de pedido'; $scope.titulo = 'Seguimiento de nota de pedido'; cabecera = 'Vendedor:'; plural = 'Vendedores'; break; case 'hoja-ruta': $scope.actividad = 'Entrega de producto'; $scope.titulo = 'Seguimiento de hoja de ruta'; cabecera = 'Vehiculo:'; plural = 'Vehiculos'; break; case 'cobranza': $scope.actividad = 'Cobranza'; $scope.titulo = 'Seguimiento de cobranza'; cabecera = 'Cobrador:'; plural = 'Cobradores'; break; } $scope.idUsuario = 0; $scope.marcadores = []; getSeguimiento(); //SETEO BOTONERA LATERAL focaBotoneraLateralService.showSalir(true); focaBotoneraLateralService.showPausar(false); focaBotoneraLateralService.showGuardar(false); $scope.general = function() { $scope.idUsuario = 0; getSeguimiento(); }; $scope.individual = function() { $scope.idUsuario = -1; }; $scope.salir = function() { $location.path('/'); }; $scope.search = function(key) { if (key === 13) { $scope.idUsuario = $scope.idUsuarioInput; getSeguimiento(); if ($scope.actividad === 'Entrega de producto' && $scope.idUsuario !== 0) { focaAdminSeguimientoService.obtenerRemitosVehiculo($scope.idUsuario) .then(function(res) { var remitos = []; for (var i = 0; i < res.data.length; i++) { remitos = remitos.concat(res.data[i].remitos); } $scope.remitosVehiculo = remitos; }); } } }; $scope.fecha = function() { getSeguimiento(); }; $scope.showMarcadores = function() { var texto = ''; if ($scope.actividad === 'Nota de pedido') { texto = 'Marcadores de notas de pedido'; } if ($scope.actividad === 'Entrega de producto') { texto = 'Marcadores de entregas'; } if ($scope.actividad === 'Cobranza') { texto = 'Marcadores de cobranzas'; } var modalInstance = $uibModal.open( { ariaLabelledBy: texto, templateUrl: 'foca-modal-marcadores.html', controller: 'focaModalMarcadoresController', size: 'lg', resolve: { parametros: function() { var parametros = { marcadores: $scope.marcadores, actividad: $scope.actividad }; return parametros; } } } ); modalInstance.result.then( function(localizacion) { $scope.$broadcast('moveMap', { latitud: localizacion.latitud, longitud: localizacion.longitud, indice: localizacion.indice }); }, function() { // funcion ejecutada cuando se cancela el modal } ); }; function getSeguimiento() { var now = $scope.now; var hasta = angular.copy(now); hasta.setDate(hasta.getDate() + 1); var datos = { actividad: $scope.actividad, idUsuario: $scope.idUsuario, fechaDesde: now, fechaHasta: hasta, entregado: $scope.filtroEstado ? true : ($scope.filtroEstado !== undefined ? false : undefined) }; $scope.datosBuscados = { actividad: $scope.actividad, individual: $scope.idUsuario !== 0 ? true : false }; focaAdminSeguimientoService .obtenerActividad(datos) .then(function(datos) { $scope.marcadores = datos.data; $scope.$broadcast('cleanCabecera'); if ($scope.idUsuario !== 0) { $scope.$broadcast('addCabecera', { label: 'Individual', valor: '' }); var valor = ''; switch ($routeParams.parametro) { case 'nota-pedido': if (datos.data.length) { valor = datos.data[0].notaPedido.vendedor.NUM + ' - ' + datos.data[0].notaPedido.vendedor.NOM.trim(); } else { valor = $scope.idUsuario; } break; case 'hoja-ruta': if (datos.data.length) { valor = datos.data[0].hojaRutaMovimiento.remito.hojaRuta .vehiculo.codigo + ' - ' + datos.data[0] .hojaRutaMovimiento.remito.hojaRuta.vehiculo.tractor.trim(); } else { valor = $scope.idUsuario; } break; case 'cobranza': if (datos.data.length) { valor = datos.data[0].recibo.cobrador.NUM + ' - ' + datos.data[0].recibo.cobrador.NOM.trim(); } else { valor = $scope.idUsuario; } break; } $scope.$broadcast('addCabecera', { label: cabecera, valor: valor }); } else { $scope.$broadcast('addCabecera',{ label: 'General', valor: '' }); } $scope.$broadcast('addCabecera', { label: 'Cantidad: ', valor: datos.data.length + ' Marcadores' }); }); } } ]);