Esempio n. 1
0
        protected override void Process(InitEvent data)
        {
            if (Ticket.Vehiculo == null)
            {
                throw new NoVehicleException();
            }
            if (Ticket.Estado != Ticket.Estados.Pendiente)
            {
                throw new AlreadyOpenException();
            }

            FirstPosition();

            Ticket.Dispositivo = Ticket.Vehiculo.Dispositivo;

            var primerDetalle = Detalles.First();
            var primerEstado  = primerDetalle.EstadoLogistico;
            var messageCode   = primerEstado.Mensaje.Codigo;
            var needsSend     = true;


            if (primerEstado.EsPuntoDeControl == Estado.Evento.Iniciado)
            {
                primerDetalle.Automatico = primerDetalle.Manual = data.Date;
                if (Detalles.Count >= 2)
                {
                    messageCode = Detalles[1].EstadoLogistico.Mensaje.Codigo;
                }
                else
                {
                    needsSend = false;
                }
                DaoFactory.DetalleTicketDAO.SaveOrUpdate(primerDetalle);
            }

            var sent = !needsSend || MessageSender.CreateSetWorkflowState(Ticket.Vehiculo.Dispositivo, MessageSaver).AddWorkflowState(messageCode).Send();

            if (!sent)
            {
                throw new QueueException();
            }

            Ticket.Estado = Ticket.Estados.EnCurso;
            DaoFactory.TicketDAO.SaveOrUpdate(Ticket);

            SaveMessage(MessageCode.CicloLogisticoIniciado.GetMessageCode(), data.Date);

            if (primerEstado.EsPuntoDeControl == Estado.Evento.Iniciado)
            {
                SaveMessage(MessageCode.EstadoLogisticoCumplido.GetMessageCode(), primerDetalle.EstadoLogistico.Descripcion, data.Date.AddSeconds(1));
            }
        }
Esempio n. 2
0
 public virtual IList <EntregaDistribucion> GetEntregasOrdenadas()
 {
     if (Tipo == Tipos.Desordenado)
     {
         var salida  = Detalles.First();
         var llegada = Detalles.Last();
         if (llegada.Linea == null)
         {
             llegada = null;
         }
         var det = Detalles.Where(e => e.Linea == null).OrderBy(e => e.ManualOEntrada).ToList();
         det.Insert(0, salida);
         if (llegada != null && Detalles.Count > 1)
         {
             det.Add(llegada);
         }
         return(det.ToList());
     }
     return(Detalles.ToList());
 }
Esempio n. 3
0
            private int GetCompleted()
            {
                var firstDetalle = Detalles.First();
                var lastDetalle  = Detalles.Last();

                if (lastDetalle.Automatico.HasValue)
                {
                    return(100);
                }

                var totalTime = lastDetalle.Programado.Subtract(firstDetalle.Programado).TotalMinutes;

                lastDetalle = null;

                foreach (var detalle in Detalles)
                {
                    if (lastDetalle != null)
                    {
                        var duracion = detalle.Programado.Subtract(lastDetalle.Programado).TotalMinutes;
                        var parcial  = !detalle.Automatico.HasValue && lastDetalle.Automatico.HasValue
                                          ? (DateTime.UtcNow.Subtract(lastDetalle.Automatico.Value).TotalMinutes * 100) / duracion
                                          : 0;
                        if (parcial > 100)
                        {
                            parcial = 100;
                        }
                        detalle.Duracion           = Convert.ToInt32(duracion);
                        detalle.PorcentajeDelTotal = totalTime == 0 ? 0 : Convert.ToInt32((duracion / totalTime) * 100);
                        detalle.Completado         = detalle.Automatico.HasValue;
                        detalle.PorcentajeParcial  = detalle.Automatico.HasValue
                                                        ? 100
                                                        : Math.Min(90, Convert.ToInt32(parcial));
                    }
                    lastDetalle = detalle;
                }

                return(Convert.ToInt32(Detalles.Select(d => (d.PorcentajeParcial / 100) * d.PorcentajeDelTotal).Sum()));
            }
Esempio n. 4
0
            private void RecalculateTimes(ViajeDistribucion distribucion)
            {
                var firstDetalle = Detalles.First();
                var lastDetalle  = Detalles.Last();

                var totalTime = lastDetalle.Programado.Subtract(firstDetalle.Programado).TotalMinutes;

                if (totalTime == 0)
                {
                    lastDetalle = null;
                    foreach (var detalle in Detalles)
                    {
                        if (lastDetalle != null)
                        {
                            var distancia = Distancias.Loxodromica(lastDetalle.Latitud, lastDetalle.Longitud, detalle.Latitud, detalle.Longitud) / 1000;
                            var velocidad = distribucion.Vehiculo.VelocidadPromedio > 0 ? distribucion.Vehiculo.VelocidadPromedio: distribucion.Vehiculo.TipoCoche.VelocidadPromedio > 0?distribucion.Vehiculo.TipoCoche.VelocidadPromedio:40;
                            var tiempo    = TimeSpan.FromHours(distancia / velocidad);
                            detalle.Programado = lastDetalle.Programado.Add(tiempo) + TimeSpan.FromMinutes(10);
                        }
                        lastDetalle = detalle;
                    }
                }
            }