Пример #1
0
        public List <detallesplanillaDTO> getInformeRecorridos(DateTime fecha, int grupo)
        {
            fecha = fecha.Date;
            DateTime fechaFin = new DateTime(fecha.Year, fecha.Month, fecha.Day, 23, 59, 59);
            List <detallesplanillaDTO> lDpDto = new List <detallesplanillaDTO>();

            using (ctx = new tvEntities()) {
                planillacontrol PlaCtr = ctx.planillacontrol.Where(t => t.Fecha == fecha && t.Grupo == grupo).FirstOrDefault();

                if (PlaCtr != null)
                {
                    List <detallesplanilla> lDp = ctx.detallesplanilla.Where(t => t.idPlanillaControl == PlaCtr.id).ToList();

                    Mapper.Map(lDp, lDpDto);

                    foreach (var dP in lDpDto)
                    {
                        asignarbus aBus = ctx.asignarbus.Where(t => t.Placa == dP.PlacaBus && t.Estado == "A").FirstOrDefault();
                        if (aBus != null)
                        {
                            dP.Conductor = aBus.personas.Nombres + " " + aBus.personas.Apellidos;
                        }

                        dP.Recorridos = ctx.entradassalidas.Where(t => t.Fecha > fecha &&
                                                                  t.Fecha < fechaFin &&
                                                                  t.Placa == dP.PlacaBus && t.Estado == "E").Count();
                    }

                    return(lDpDto);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
        private List <List <detallesplanillaDTO> > crearRotacionesBuses(ref string[] nBus, ref int mes, ref DateTime fcha,
                                                                        ref int grupo, ref List <rutagrupo> lrGrupo,
                                                                        ref List <buses> lBus)
        {
            planillacontrol pC;

            int diasMes = DateTime.DaysInMonth(fcha.Year, fcha.Month);
            int d       = 1;
            int k       = 1;
            int daysToToday;

            daysToToday = Convert.ToInt32((fcha - (new DateTime(DateTime.Now.Year, 1, 1))).TotalDays);
            string[] mBus = new string[30];
            List <List <detallesplanillaDTO> > lldP = new List <List <detallesplanillaDTO> >();

            for (int i = 1; i <= mesTurno.GetLength(1); i++)
            {
                mBus[i] = nBus[mesTurno[mes - 1, i - 1]];
            }

            for (int i = 0; i < dia.GetLength(0); i++)
            {
                if (diasMes == lldP.Count)
                {
                    break;
                }

                List <detallesplanillaDTO> ldP = new List <detallesplanillaDTO>();
                for (int j = 0; j < dia.GetLength(1); j++)
                {
                    detallesplanillaDTO dP = new detallesplanillaDTO();
                    dP.Vial     = mBus[dia[i, j]];
                    dP.PlacaBus = lBus.Find(t => t.Vial == dP.Vial).Placa;
                    ldP.Add(dP);
                    k++;
                }

                if (i == dia.GetLength(0) - 1)
                {
                    i = 0;
                }


                lldP.Add(ldP);

                /////////////// Rutas para cada dia //////////////////
                //En el primer objeto de la lista de detallesplanilla
                if ((lldP.Count + daysToToday) % 2 == 0)
                {
                    ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
                }
                else
                {
                    try
                    {
                        ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(1).Ruta;
                    }
                    catch (ArgumentOutOfRangeException e)
                    {
                        ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
                    }
                }
                /////////////////////////////////////////////////////
            }

            ///Guardar Detalles de Planilla (Rotaciones del mes)
            ///
            using (ctx = new tvEntities()){
                foreach (List <detallesplanillaDTO> lDp in lldP)
                {
                    ////Creo una nueva Planilla control
                    pC       = new planillacontrol();
                    pC.Fecha = new DateTime(DateTime.Now.Year, mes, d);
                    pC.Grupo = grupo;
                    ctx.planillacontrol.Add(pC);
                    ctx.SaveChanges();
                    d++;

                    string ru   = lDp.ElementAt(0).Ruta;
                    rutas  ruta = ctx.rutas.Where(t => t.NomRuta == ru).FirstOrDefault();
                    int    frec = ruta.Frecuencia.Value;
                    time = ctx.horario.Where(t => t.id == ruta.idHorario).FirstOrDefault().hora.Value;

                    foreach (detallesplanillaDTO DpDTO in lDp)
                    {
                        DpDTO.idPlanillaControl = pC.id;
                        DpDTO.Ruta       = lDp.ElementAt(0).Ruta;
                        DpDTO.HoraSalida = time;
                        detallesplanilla dP = new detallesplanilla();
                        Mapper.Map(DpDTO, dP);
                        ctx.detallesplanilla.Add(dP);
                        ctx.SaveChanges();
                        DpDTO.id = dP.id;

                        time = time + new TimeSpan(0, frec, 0);
                    }
                }
            }
            ////////////////////////////////


            return(lldP);
        }
Пример #3
0
        public List <planillarecaudoDTO> get(DateTime fecha, int grupo)
        {
            fecha = fecha.Date;//new DateTime(fecha.Year,fecha.Month,fecha.d)
            DateTime fechaFin = new DateTime(fecha.Year, fecha.Month, fecha.Day, 23, 59, 59);
            List <planillarecaudoDTO> lPlaRecDto;
            planillarecaudo           pR;
            planillarecaudo           pRaux;
            planillarecaudoDTO        pRDto;
            gastos   gastos;
            DateTime fecha2;

            using (ctx = new tvEntities()) {
                planillacontrol PlaCtr = ctx.planillacontrol.Where(t => t.Fecha == fecha && t.Grupo == grupo).FirstOrDefault();

                if (PlaCtr != null)
                {
                    lPlaRecDto = new List <planillarecaudoDTO>();

                    List <detallesplanilla> lDePla = PlaCtr.detallesplanilla.OrderBy(t => t.id).Where(t => t.idPlanillaControl == PlaCtr.id).ToList();

                    foreach (detallesplanilla dP in lDePla)
                    {
                        pR    = ctx.planillarecaudo.OrderBy(t => t.idDetallesPlanilla).Where(t => t.idDetallesPlanilla == dP.id).FirstOrDefault();
                        pRDto = new planillarecaudoDTO();

                        if (pR == null)
                        {
                            pR     = new planillarecaudo();
                            gastos = new gastos();
                            pR.idDetallesPlanilla = dP.id;
                            pR.Recorridos         = ctx.entradassalidas.Where(t => t.Fecha > fecha &&
                                                                              t.Fecha < fechaFin &&
                                                                              t.Placa == dP.PlacaBus && t.Estado == "E").Count();// Calcular el numero de Recorridos. Corregir
                            pR.Fecha = fecha;
                            ctx.planillarecaudo.Add(pR);
                            ctx.SaveChanges();

                            gastos.idplanillarecaudo = pR.id;
                            ctx.gastos.Add(gastos);
                            ctx.SaveChanges();

                            //pRaux=ctx.planillarecaudo.OrderByDescending(t=> t.detallesplanilla.id)
                            //    .Where(t=> t.detallesplanilla.id<pR.idDetallesPlanilla &&
                            //        t.detallesplanilla.PlacaBus==
                            //        (ctx.detallesplanilla.Where(y=>y.id==pR.idDetallesPlanilla).FirstOrDefault().PlacaBus))
                            //    .FirstOrDefault();
                            fecha2 = fecha.AddDays(-1);
                            pRaux  = ctx.planillarecaudo.Where(t => t.Fecha == fecha2 && t.detallesplanilla.PlacaBus == dP.PlacaBus).FirstOrDefault();

                            if (pRaux == null)
                            {
                                pR.InicioTorniquete = 0;
                            }
                            else
                            {
                                pR.InicioTorniquete = pRaux.FinTorniquete;
                            }

                            ctx.SaveChanges();
                        }

                        Mapper.Map(pR, pRDto);
                        pRDto.Time = dP.HoraSalida.ToString();
                        Mapper.Map(pR.gastos, pRDto.gastos);
                        lPlaRecDto.Add(pRDto);
                    }

                    return(lPlaRecDto);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #4
0
        private List<List<detallesplanillaDTO>> crearRotacionesBuses(ref string[] nBus,ref int mes,ref DateTime fcha,
            ref int grupo,ref List<rutagrupo> lrGrupo,
            ref List<buses> lBus)
        {
            planillacontrol pC;

            int diasMes = DateTime.DaysInMonth(fcha.Year, fcha.Month);
            int d = 1;
            int k=1;
            int daysToToday;

            daysToToday = Convert.ToInt32((fcha - (new DateTime(DateTime.Now.Year, 1, 1))).TotalDays);
            string[] mBus = new string[30];
            List<List<detallesplanillaDTO>> lldP = new List<List<detallesplanillaDTO>>();

            for (int i = 1; i <= mesTurno.GetLength(1); i++)
            {
            mBus[i] = nBus[mesTurno[mes - 1, i - 1]];
            }

            for (int i = 0; i < dia.GetLength(0); i++)
            {
            if (diasMes == lldP.Count)
            {
                break;
            }

            List<detallesplanillaDTO> ldP = new List<detallesplanillaDTO>();
            for (int j = 0; j < dia.GetLength(1); j++)
            {
                detallesplanillaDTO dP = new detallesplanillaDTO();
                dP.Vial = mBus[dia[i, j]];
                dP.PlacaBus = lBus.Find(t => t.Vial == dP.Vial).Placa;
                ldP.Add(dP);
                k++;

            }

            if (i == dia.GetLength(0) - 1)
            {
                i = 0;
            }

            lldP.Add(ldP);

            /////////////// Rutas para cada dia //////////////////
            //En el primer objeto de la lista de detallesplanilla
            if ((lldP.Count + daysToToday) % 2 == 0)
            {
                ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
            }
            else
            {
                try
                {
                    ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(1).Ruta;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
                }
            }
            /////////////////////////////////////////////////////
            }

            ///Guardar Detalles de Planilla (Rotaciones del mes)
            ///
            using (ctx=new tvEntities()){

            foreach (List<detallesplanillaDTO> lDp in lldP)
            {
                ////Creo una nueva Planilla control
                pC = new planillacontrol();
                pC.Fecha = new DateTime(DateTime.Now.Year,mes,d);
                pC.Grupo = grupo;
                ctx.planillacontrol.Add(pC);
                ctx.SaveChanges();
                d++;

                string ru = lDp.ElementAt(0).Ruta;
                rutas ruta = ctx.rutas.Where(t => t.NomRuta == ru).FirstOrDefault();
                int frec = ruta.Frecuencia.Value;
                time = ctx.horario.Where(t => t.id == ruta.idHorario).FirstOrDefault().hora.Value;

                foreach (detallesplanillaDTO DpDTO in lDp)
                {
                    DpDTO.idPlanillaControl = pC.id;
                    DpDTO.Ruta = lDp.ElementAt(0).Ruta;
                    DpDTO.HoraSalida = time;
                    detallesplanilla dP = new detallesplanilla();
                    Mapper.Map(DpDTO, dP);
                    ctx.detallesplanilla.Add(dP);
                    ctx.SaveChanges();
                    DpDTO.id = dP.id;

                    time = time + new TimeSpan(0, frec, 0);
                }
            }

            }
            ////////////////////////////////

            return lldP;
        }
Пример #5
0
        public List <List <horarioDTO> > getHorarioPlanilla(string nomRuta, DateTime fecha, int grupo)
        {
            List <List <horarioDTO> > llHorDTO = new List <List <horarioDTO> >();
            List <horarioDTO>         lHorDTO  = new List <horarioDTO>();
            horarioDTO horDTO = new horarioDTO();
            TimeSpan   extra;
            int        cap = 0;

            using (ctx = new tvEntities()) {
                rutas           ruta = ctx.rutas.Where(t => t.NomRuta == nomRuta).FirstOrDefault();
                horario         Hor  = ctx.horario.Where(t => t.id == ruta.idHorario).FirstOrDefault();
                planillacontrol pC   = ctx.planillacontrol.Where(t => t.Fecha == fecha && t.Grupo == grupo).FirstOrDefault();
                cap = ctx.detallesplanilla.Where(t => t.Ruta == nomRuta && t.idPlanillaControl == pC.id).Count();

                if (ruta != null || Hor != null || pC != null || cap != 0)
                {
                    ruta.Capacidad = cap;/// capacidad del Bus

                    for (int i = 1; i <= ruta.NumeroRecorridos; i++)
                    {
                        createListaHor(ref lHorDTO, ruta, Hor);

                        if (nomRuta.ToUpper() != "RUTA 10B")
                        {
                            if (i % 2 == 0 && i != 1)
                            {
                                extra = new TimeSpan(0, 8, 0);
                            }
                            else
                            {
                                extra = new TimeSpan(0, 0, 0);
                            }
                        }
                        else
                        {
                            if (nomRuta.ToUpper() == "RUTA 8" || nomRuta.ToUpper() == "RUTA 12" || nomRuta.ToUpper() == "RUTA 10A")
                            {
                                if (i % 2 == 0 && i != 1)
                                {
                                    extra = new TimeSpan(0, 0, 0);
                                }
                                else
                                {
                                    extra = new TimeSpan(0, 8, 0);
                                }
                            }
                            else
                            {
                                extra = new TimeSpan(0, 0, 0);
                            }
                        }

                        Hor.hora = lHorDTO.ElementAt(0).hora + new TimeSpan(0, ruta.TiempoRecorrido.Value, 0) + extra;
                        llHorDTO.Add(lHorDTO);
                        lHorDTO = new List <horarioDTO>();
                    }

                    return(llHorDTO);
                }
                else
                {
                    return(null);
                }
            }
        }