Ejemplo n.º 1
0
        public IList FindParteReport(int aseguradora, int locacion, int linea, int movil, int equipo, DateTime inicio, DateTime fin, int estado, int usuario)
        {
            var empresaDAO = new EmpresaDAO();
            var lineaDAO   = new LineaDAO();
            var cocheDAO   = new CocheDAO();

            var lin = linea > 0 ? lineaDAO.FindById(linea) : null;
            var emp = lin != null ? lin.Empresa : locacion > 0 ? empresaDAO.FindById(locacion) : null;

            IEnumerable <string> coches;

            if (movil > 0)
            {
                coches = new List <string>(new[] { movil.ToString("#0") });
            }
            else
            {
                coches = cocheDAO.GetList(new[] { emp != null ? emp.Id : -1 }, new[] { lin != null ? lin.Id : -1 })
                         .Select(c => c.Id.ToString("#0"))
                         .ToList();
            }

            var script =
                @"from Documento d 
                    where d.Fecha >= :ini
                    and d.Fecha <= :fin    
                    and d.Estado != -1
                    and d.Id in 
                        (select v.Documento.Id from DocumentoValor v 
                        where v.Parametro.TipoDato like 'Aseguradora'  and v.Valor = :ase)       
                ";

            if (equipo > 0)
            {
                script +=
                    @" and d.Id in 
                        (select v.Documento.Id from DocumentoValor v 
                        where v.Parametro.Nombre like 'Equipo'  and v.Valor = :equ) ";
            }

            if (estado >= 0)
            {
                script +=
                    @" and ((:est = '0' and d.Id not in 
                        (select v.Documento.Id from DocumentoValor v 
                            where v.Parametro.Nombre like 'Estado Control' and v.Valor <> :est)
                        ) or (:est <> '0' and d.Id in (select v.Documento.Id from DocumentoValor v 
                            where v.Parametro.Nombre like 'Estado Control' and v.Valor = :est))) ";
            }

            script += " order by d.Fecha";

            var q = Session.CreateQuery(script)
                    .SetParameter("ini", inicio)
                    .SetParameter("fin", fin)
                    .SetParameter("ase", aseguradora.ToString("#0"));

            if (equipo > 0)
            {
                q.SetParameter("equ", equipo.ToString("#0"));
            }

            if (estado >= 0)
            {
                q.SetParameter("est", estado.ToString("#0"));
            }

            return(q.List().Cast <Documento>().Where(documento => documento.Parametros.OfType <DocumentoValor>().Any(v => v.Parametro.TipoDato.ToLower().Equals("coche") && coches.Contains(v.Valor))).ToList());
        }