Exemple #1
0
        public List <ModelViewFolios> GetLastFolio(ModelViewUserG objCred)
        {
            var NegocioPoliza   = new BusinessPolicy();
            var NegocioRef      = new BusinessRefsell();
            var NegocioOrden    = new BusinessOrder();
            var NegocioUsuario  = new BusinessUsers();
            var NegocioEmpleado = new BusinessEmployee();
            var dataUsuario     = NegocioUsuario.GetUserByToken(objCred.TokenUser);

            if (objCred.TokenApp != GlobalConfiguration.TokenWEB)
            {
                if (objCred.TokenApp != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }
            if (dataUsuario == null)
            {
                throw new Exception("UserPasswordInvalid");
            }


            DateTime date = objCred.Date.Value;


            List <ModelViewFolios> x = new List <ModelViewFolios>();

            var Empleado2 = NegocioEmpleado.GetEmployeUser(dataUsuario.UserID);
            var Empleado  = Empleado2[0];

            int Conteo;
            List <EntityQuotation> Cotizaciones;
            List <EntityPolicy>    Polizas;
            List <EntityRefSell>   Refacciones;

            string Tipo;
            int    count = 1;

            while (count < 4)
            {
                switch (count)
                {
                case 1:

                    Tipo         = "Cotizacion";
                    Conteo       = GetByEmpoyeeDate(Empleado.PK_EmployeeID, date).Count;
                    Cotizaciones = GetByEmpoyeeDate(Empleado.PK_EmployeeID, date);

                    var LastFolio = Cotizaciones.Count is 0 ? "": Cotizaciones[0].Folio;

                    x.Add(new ModelViewFolios(Tipo, Conteo, LastFolio));
                    count++;

                    break;

                case 2:
                    Tipo    = "Polizas";
                    Conteo  = NegocioPoliza.GetByEmpoyeeDate(Empleado.PK_EmployeeID, date).Count;
                    Polizas = NegocioPoliza.GetByEmpoyeeDate(Empleado.PK_EmployeeID, date);

                    LastFolio = Polizas.Count is 0 ? "" : Polizas[0].IDPolicy;

                    x.Add(new ModelViewFolios(Tipo, Conteo, LastFolio));
                    count++;
                    break;

                case 3:
                    Tipo        = "Refacciones";
                    Conteo      = NegocioRef.GetByEmpoyeeDate(Empleado.PK_EmployeeID, date).Count;
                    Refacciones = NegocioRef.GetByEmpoyeeDate(Empleado.PK_EmployeeID, date);
                    LastFolio   = Refacciones.Count is 0 ? "" : Refacciones[0].IDRefSell;

                    x.Add(new ModelViewFolios(Tipo, Conteo, LastFolio));
                    count++;
                    break;

                default:

                    count++;
                    break;
                }
            }



            return(x);
        }
Exemple #2
0
        public List <ModelViewQuotation> GetListAllQuotation(string StatusVisitID, string ModuleID, string PriorityID, string StatusOrderID, string ServiceID, string OrderID, string Employee, string StartDate, string EndDate, string User, string TypeQuotation)
        {
            var NegocioUser          = new BusinessUsers();
            var NegocioCiente        = new BusinessClient();
            var NegocioCotizacion    = new BusinessQuotation();
            var cotiza               = new BusinessQuotation();
            var NegocioPolizas       = new BusinessPolicy().GetAll();
            var NegocioEmpleado      = new BusinessEmployee();
            var NegocioMonitor       = new BusinessMonitor();
            var NegocioOrdenes       = new BusinessOrder();
            var NegocioEstatusOrden  = new BusinessStatusCauseOrder();
            var NegocioGarantia      = new BusinessGuaranty();
            var NegocioModulosMabe   = new BusinessModuleService();
            var NegocioCauseOrder    = new BusinessCauseOrder();
            var NegocioTypeQuotation = new BusinessTypeQuotation();
            var NegocioContrat       = new BusinessContrat();
            var estatusorden         = NegocioEstatusOrden.GetAll();
            int profileuser          = NegocioUser.GetProfileByToken(User).ProfileID;
            var ordenes              = new List <EntityOrder>();
            var polizas              = new List <EntityPolicy>();
            var user         = new List <ModelViewUserList>();
            var garantia     = new List <EntityGuaranty>();
            var modulos      = new List <EntityModuleService>();
            var estatus      = new List <EntityStatusOrder>();
            var empleado     = new List <EntityEmployee>();
            var visitas      = new List <ModelViewMonitorOrder>();
            var tipo         = new List <EntityTypeQuotation>();
            var Cotizaciones = new List <EntityQuotation>();
            var contrat      = new List <EntityContract>();

            var ModuleUser = NegocioUser.GetProfileByToken(User).ModuleID;

            //contrat = NegocioContrat.GetAll();
            user = NegocioUser.GetAll();

            if (StartDate != "" && EndDate != "")
            {
                DateTime inicio = DateTime.ParseExact(StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                DateTime fin    = DateTime.ParseExact(EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                //ordenes = NegocioOrdenes.GetAll().Where(p => p.OrderExecuteDate >= inicio && p.OrderExecuteDate <= fin).ToList();
                ordenes = NegocioOrdenes.GetByRange(inicio, fin);
                if (OrderID != "")
                {
                    ordenes = NegocioOrdenes.GetAll().Where(p => p.OrderID.Contains(OrderID)).ToList();
                }
                if (profileuser == 7)
                {
                    ordenes = (from a in ordenes
                               where a.FK_ModuleID == ModuleUser
                               select a).ToList();
                }
            }
            else
            {
                ordenes = NegocioOrdenes.GetAll();
            }

            if (StatusVisitID != "")
            {
                int[] nums = StatusVisitID.Split(',').Select(int.Parse).ToArray();
                visitas = GetAll().Where(p => nums.Contains(p.StatusVisitID.Value)).ToList();
            }
            else
            {
                visitas = GeListByOrder(ordenes.Select(p => p.PK_OrderID).ToList());
            }

            if (Employee != "")
            {
                empleado = NegocioEmpleado.GetAll().Where(p => p.FirstName.ToLower().Contains(Employee.ToLower()) || p.LastName.ToLower().Contains(Employee.ToLower())).ToList();
            }
            else
            {
                empleado = NegocioEmpleado.GetAll();
            }

            if (ServiceID != "")
            {
                int[] nums = ServiceID.Split(',').Select(int.Parse).ToArray();
                garantia = NegocioGarantia.GetAll().Where(p => nums.Contains(p.PK_GuarantyID)).ToList();
            }
            else
            {
                garantia = NegocioGarantia.GetAll();
            }

            if (ModuleID != "")
            {
                int[] nums = ModuleID.Split(',').Select(int.Parse).ToArray();
                modulos = NegocioModulosMabe.GetAll().Where(p => nums.Contains(p.ModuleID)).ToList();
            }
            else
            {
                modulos = NegocioModulosMabe.GetAll();
            }
            if (StatusOrderID != "")
            {
                int[] nums = StatusOrderID.Split(',').Select(int.Parse).ToArray();
                estatus = NegocioEstatusOrden.GetAll().Where(p => nums.Contains(p.PK_StatusOrderID)).ToList();
            }
            else
            {
                estatus = NegocioEstatusOrden.GetAll();
            }
            if (TypeQuotation != "")
            {
                int[] nums = TypeQuotation.Split(',').Select(int.Parse).ToArray();
                tipo = NegocioTypeQuotation.GetAll().Where(p => nums.Contains(p.PK_TypeQuotation)).ToList();
            }
            else
            {
                tipo = NegocioTypeQuotation.GetAll();
            }

            Cotizaciones = NegocioCotizacion.GeListByOrder(ordenes.Select(p => p.PK_OrderID).ToList());

            //var x = NegocioCotizacion.GetAll().Select(p => p.TypeQuotation).Distinct();
            List <ModelViewQuotation> x = (from c in Cotizaciones
                                           join j in tipo on c.TypeQuotation equals j.PK_TypeQuotation
                                           join p in ordenes on c.FK_OrdenID equals p.PK_OrderID
                                           join e in NegocioCiente.GetAll() on p.FK_ClientID equals e.PK_ClientID
                                           join t in empleado on p.TechnicalID equals t.EmployeeID
                                           join m in NegocioMonitor.GetAll() on p.PK_OrderID equals m.OrderID
                                           join b in estatus on m.StatusOrderID equals b.PK_StatusOrderID
                                           join g in garantia on p.FK_GuarantyID equals g.PK_GuarantyID
                                           join f in modulos on p.FK_ModuleID equals f.ModuleID


                                           join h in NegocioCauseOrder.GetAll() on m.CauseOrderID equals h.PK_CauseOrderID



                                           select new ModelViewQuotation()
            {
                FK_OrderID = c.FK_OrdenID.Value,
                QuotationID = c.PK_QuotationID,
                TypeQuotation = j.Description,
                OrdenVenta = c.OrdenVenta,
                OrderID = p.OrderID,
                StatusQuotation = h.PK_CauseOrderID,
                Folio = c.Folio,
                ClientName = e.FirstName + " " + e.LastName,
                EmployeeName = t.FirstName + " " + t.LastName,
                Total = "$ " + c.Total,
                URL = c.URL,
            }).OrderByDescending(p => p.QuotationID).ToList();

            //var z = (from r in x
            //         join y in contrat on r.FK_OrderID equals y.Fk_OrderID
            //         into ps
            //         from sub in ps.DefaultIfEmpty()

            //         select new ModelViewQuotation()
            //         {
            //             FK_OrderID = r.FK_OrderID,
            //             QuotationID = r.QuotationID,
            //             TypeQuotation = r.TypeQuotation,
            //             OrdenVenta = r.OrdenVenta,
            //             OrderID = r.OrderID,
            //             StatusQuotation = r.StatusQuotation,
            //             Folio = r.Folio,
            //             ClientName = r.ClientName,
            //             EmployeeName = r.EmployeeName,
            //             Total = r.Total,
            //             URL = r.URL,
            //             Contract = sub?.Ruta ?? String.Empty
            //         }).GroupBy(w => new { w.FK_OrderID, w.Folio }).Select(w => w.First()).ToList();



            return(x);
            //return z;
        }