コード例 #1
0
        public List <ModelViewFailures> GetListCodeFailure(ModelViewUserG objCred)
        {
            var NegocioUsuario = new BusinessUsers();
            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");
            }
            var NegocioOrdenes     = new BusinessOrder();
            var NegocioEmpleado    = new BusinessEmployee();
            var NegocioCodigoFalla = new BusinessCodeFailure();
            var NegocioBase        = new BusinessInstalledBase();
            var codefailure        = NegocioCodigoFalla.GetAll();
            var empleado           = NegocioEmpleado.GetByUserID(dataUsuario.UserID);

            if (objCred.ProductID == 0)
            {
                //var ordenes = NegocioOrdenes.GetAll().Where(p => empleado.Select(q => q.PK_EmployeeID).ToArray<int>().Contains(p.FK_EmployeeID.Value) && p.OrderExecuteDate >= objCred.Date.Value.Date);
                //var prod = NegocioBase.GetAll();
                //var modelos = (from c in ordenes
                //               join p in prod on c.FK_InstalledBaseID equals p.PK_InstalledBaseID
                //               select p.FK_ProductID).Distinct().ToList();
                //modelos = modelos.Where(x => x != null).ToList();
                var        ordenes       = NegocioOrdenes.GetAll(empleado.Select(q => q.PK_EmployeeID).ToList(), objCred.Date.Value, false);
                List <int> baseInstalada = ordenes.Select(p => p.FK_InstalledBaseID).ToList();
                var        modelos       = NegocioBase.GetAllByBI(baseInstalada).Select(p => p.FK_ProductID).Distinct();
                modelos = modelos.Where(x => x != null).ToList();
                List <int> modelo    = modelos.Where(x => x != null).Cast <int>().ToList();
                var        codfallas = new List <ModelViewFailures>();
                foreach (var item in modelos)
                {
                    var x = (from c in GetByProductID(item.Value)
                             join p in codefailure on c.FK_CodeFailureID equals p.PK_CodeFailureID
                             select new ModelViewFailures()
                    {
                        CodeFailureID = p.PK_CodeFailureID,
                        ProductID = c.FK_ProductID,
                        CodeFailure = p.CodeFailure1,
                        Failure = p.Failure,
                        Complexity = c.Complexity.GetValueOrDefault(),
                        Status = c.Status
                    }).ToList();

                    codfallas.AddRange(x);
                }
                return(codfallas);
                //return (from c in modelos
                //        join p in GetAll() on c equals p.FK_ProductID
                //        join d in  codefailure on p.FK_CodeFailureID equals d.PK_CodeFailureID
                //        select new ModelViewFailures()
                //        {
                //            CodeFailureID = p.FK_CodeFailureID,
                //            ProductID = p.FK_ProductID,
                //            CodeFailure = d.CodeFailure1,
                //            Failure = d.Failure,
                //            Complexity = p.Complexity.GetValueOrDefault(),
                //            Status = p.Status
                //        }).ToList();
            }
            else
            {
                return((from c in GetByProductID(objCred.ProductID)
                        join p in codefailure on c.FK_CodeFailureID equals p.PK_CodeFailureID
                        select new ModelViewFailures()
                {
                    CodeFailureID = p.PK_CodeFailureID,
                    ProductID = c.FK_ProductID,
                    CodeFailure = p.CodeFailure1,
                    Failure = p.Failure,
                    Complexity = c.Complexity.GetValueOrDefault(),
                    Status = c.Status
                }).ToList());
            }
        }
コード例 #2
0
        public string SetRefQuotation(ModelViewUserG objCred, ModelViewBilling obj)
        {
            var objRepository            = new RepositoryOrder();
            var NegocioOrden             = new BusinessOrder();
            var objAlerta                = new BusinessNotification();
            var NegocioUsuario           = new BusinessUsers();
            var NegocioCliente           = new BusinessClient();
            var NegocioBase              = new BusinessInstalledBase();
            var NegocioProducto          = new BusinessProduct();
            var NegocioFallas            = new BusinessCodeFailure();
            var NegocioBOM               = new BusinessBuildOfMaterial();
            var NegocioCotizacion        = new BusinessQuotation();
            var NegocioCotizacionDetalle = new BusinessRefsellDetail();
            var NegocioCFP               = new BusinessCodeFailureByProduct();
            var NegocioCF                = new BusinessCodeFailure();
            var NegocioLugarCompra       = new BusinessShopPlace();
            var NegocioEmpleado          = new BusinessEmployee();
            var NegocioMonitor           = new BusinessVisit();
            var NegocioHistorico         = new BusinessHistory();
            var NegocioGarantia          = new BusinessGuaranty();
            var NegocioPayment           = new BusinessPayment();
            var NegocioInvoice           = new BusinessInvoice();
            var NegocioRefsell           = new BusinessRefsell();
            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");
            }

            var empleado = NegocioEmpleado.GetByUserID(dataUsuario.UserID);
            var orden    = NegocioOrden.GetByOrderID(obj.ODS);


            var cliente = NegocioCliente.GetByID(orden.FK_ClientID);

            var lugarcompra = NegocioLugarCompra.GetByShopPlaceID(obj.FK_ShopPlaceID.Value);
            var pro         = NegocioProducto.GetByID(obj.FK_ProductID.Value);

            SpreadsheetInfo.SetLicense("EQU2-3K5L-UZDC-SDYN");
            string         Origin = GlobalConfiguration.MabeAttachmentsLocal + "FormatoVentaRefacciones.xlsx";
            List <string>  result = obj.EMails.Split(new char[] { ';' }).ToList();
            ExcelFile      ef     = ExcelFile.Load(Origin);
            ExcelWorksheet ws     = ef.Worksheets[0];
            string         Folio  = "";

            ws.Cells["L7"].Value  = obj.ODS;
            ws.Cells["L9"].Value  = cliente.ClientID;
            ws.Cells["L11"].Value = cliente.FirstName.ToUpper() + " " + cliente.LastName.ToUpper();
            ws.Cells["L13"].Value = pro.Model + " / " + pro.ProductName.ToUpper();
            ws.Cells["U13"].Value = DateTime.Today.ToString("dd-MM-yyyy");

            ws.Cells["L80"].Value = obj.ODS;
            int cantidad  = 30;
            int cantidad1 = 31;

            foreach (var jko in obj.BillingDetails)
            {
                if (jko.SparePartsDescription.EndsWith("-R"))
                {
                    Folio = jko.SparePartsDescription;
                    ws.Cells["L6"].Value  = Folio;
                    ws.Cells["L79"].Value = Folio;
                }
                else
                {
                    if (cantidad == 60)
                    {
                        cantidad  = 85;
                        cantidad1 = 86;
                    }
                    var bom = NegocioBOM.GetByID(jko.ProductID);
                    if (bom != null)
                    {
                        ws.Cells["L" + cantidad1.ToString()].Value = bom.SparePartsID;
                        ws.Cells["L" + cantidad.ToString()].Value  = bom.SparePartDescription;
                    }
                    else
                    {
                        ws.Cells["L" + cantidad1.ToString()].Value = jko.RefManID;
                        ws.Cells["L" + cantidad.ToString()].Value  = jko.SparePartsDescription;
                    }
                    ws.Cells["J" + cantidad.ToString()].Value = jko.Quantity;
                    ws.Cells["T" + cantidad.ToString()].Value = Convert.ToDouble(jko.Price);
                    ws.Cells["V" + cantidad.ToString()].Value = Convert.ToDouble(jko.Totals);
                    cantidad  = cantidad + 3;
                    cantidad1 = cantidad1 + 3;
                }
            }

            double subtotal    = Convert.ToDouble(obj.SubTotal.Substring(1));
            double iva         = Convert.ToDouble(obj.IVA.Substring(1));
            double total       = Convert.ToDouble(obj.Total.Substring(1));
            double subtotalref = subtotal;
            string totalletras = NegocioOrden.enletras(total.ToString());

            ws.Cells["M16"].Value = subtotalref;
            ws.Cells["M17"].Value = subtotal;
            ws.Cells["M18"].Value = iva;
            ws.Cells["U17"].Value = total;
            ws.Cells["M19"].Value = totalletras;
            string file    = "Cotización_" + Folio + ".pdf";
            string quotion = "CotizacionesRefaccion_" + DateTime.Today.ToString("yyyyMMdd");
            string Destiny = GlobalConfiguration.MabeAttachmentsLocal + quotion + "/" + file;

            if (obj.BillingDetails.Count < 11)
            {
                ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("J1", "W74"));
            }
            string Cotizaciones = new DirectoryInfo(GlobalConfiguration.MabeAttachmentsLocal).ToString() + quotion;

            if (!(Directory.Exists(Cotizaciones)))
            {
                Directory.CreateDirectory(Cotizaciones);
            }
            ef.Save(Destiny);
            string URL        = GlobalConfiguration.urlRequest + "Content/Attachments/" + quotion + "/" + file;
            var    cotizacion = NegocioCotizacion.GetByOrderFolio(orden.PK_OrderID, Folio);
            var    Payment    = NegocioPayment.GetPolicyPayment(orden.PK_OrderID, Folio);
            var    Invoice    = NegocioInvoice.GetPolicyInvoice(orden.PK_OrderID, Folio);


            var LsVenta = NegocioRefsell.GetByFolio(orden.PK_OrderID, Folio);

            if (obj.EMails != "")
            {
                if (cotizacion == null)
                {
                    cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                }
                else
                {
                    cotizacion.Folio         = Folio;
                    cotizacion.IVA           = iva.ToString();
                    cotizacion.SubTotal      = subtotal.ToString();
                    cotizacion.Total         = total.ToString();
                    cotizacion.URL           = URL;
                    cotizacion.ModifyDate    = DateTime.UtcNow;
                    cotizacion.TypeQuotation = obj.EstimatedTipe;
                    cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                    NegocioCotizacion.Update(cotizacion);
                }

                string sb     = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationCotizacion.txt");
                string lugCom = obj.ShopDate != null ? obj.ShopDate : "";
                sb = sb.Replace("#%Nombre%#", cliente.FirstName + " " + cliente.LastName);
                sb = sb.Replace("#%OrderID%#", obj.ODS);
                sb = sb.Replace("#%Folio%#", Folio);
                sb = sb.Replace("#%Modelo%#", pro.Model);
                sb = sb.Replace("#%Descripcion%#", pro.ProductName.ToUpper());
                sb = sb.Replace("#%Serie%#", obj.SerialNumber);
                sb = sb.Replace("#%Fecha%#", lugCom);
                sb = sb.Replace("#%Lugar%#", lugarcompra.ShopPlace1);
                //objAlerta.SendMails(result, "Cotización ServiPlus", sb.ToString(), Destiny);
                objAlerta.SendMailExchange(GlobalConfiguration.exchangeUserCotiza, GlobalConfiguration.exchangePwdCotiza, result, "Cotización ServiPlus", sb.ToString(), Destiny);
            }
            else
            {
                if (LsVenta.PK_RefSellID == 0)
                {
                    if (cotizacion == null)
                    {
                        cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                    }
                    else
                    {
                        cotizacion.Folio         = Folio;
                        cotizacion.IVA           = iva.ToString();
                        cotizacion.SubTotal      = subtotal.ToString();
                        cotizacion.Total         = total.ToString();
                        cotizacion.URL           = URL;
                        cotizacion.ModifyDate    = DateTime.UtcNow;
                        cotizacion.TypeQuotation = obj.EstimatedTipe;
                        cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                        NegocioCotizacion.Update(cotizacion);
                    }
                    var NewRefSell = new EntityRefSell();
                    var NuevaVenta = new EntityRefSell();

                    NewRefSell.FK_OrderID     = orden.PK_OrderID;
                    NewRefSell.FK_ClientID    = cliente.PK_ClientID;
                    NewRefSell.FK_EmployeeID  = empleado[0].PK_EmployeeID;
                    NewRefSell.FK_PaymentID   = Payment.PK_PaymentID;
                    NewRefSell.FK_Invoice_ID  = Invoice.InvoicingID;
                    NewRefSell.FK_ProductID   = obj.FK_ProductID.Value;
                    NewRefSell.FK_ShopPlace   = obj.FK_ShopPlaceID.Value;
                    NewRefSell.FK_QuotationID = cotizacion.PK_QuotationID;
                    NewRefSell.IDRefSell      = Folio;
                    NuevaVenta = NegocioRefsell.Insert(NewRefSell);
                }
                else
                {
                    LsVenta.FK_OrderID     = orden.PK_OrderID;
                    LsVenta.FK_ClientID    = cliente.PK_ClientID;
                    LsVenta.FK_EmployeeID  = empleado[0].PK_EmployeeID;
                    LsVenta.FK_PaymentID   = Payment.PK_PaymentID;
                    LsVenta.FK_Invoice_ID  = Invoice.InvoicingID;
                    LsVenta.FK_QuotationID = LsVenta.FK_QuotationID;
                    LsVenta.FK_ProductID   = obj.FK_ProductID.Value;
                    LsVenta.FK_ShopPlace   = obj.FK_ShopPlaceID.Value;

                    NegocioRefsell.Update(LsVenta);

                    if (cotizacion == null)
                    {
                        cotizacion = NegocioCotizacion.Insert(orden.PK_OrderID, subtotal.ToString(), iva.ToString(), total.ToString(), Folio, URL, obj.EstimatedTipe, empleado[0].PK_EmployeeID);
                    }
                    else
                    {
                        cotizacion.Folio         = Folio;
                        cotizacion.IVA           = iva.ToString();
                        cotizacion.SubTotal      = subtotal.ToString();
                        cotizacion.Total         = total.ToString();
                        cotizacion.URL           = URL;
                        cotizacion.ModifyDate    = DateTime.UtcNow;
                        cotizacion.TypeQuotation = obj.EstimatedTipe;
                        cotizacion.FK_EmployeeID = empleado[0].PK_EmployeeID;
                        NegocioCotizacion.Update(cotizacion);
                    }
                }
                string[] lstADR = { "T002", "T012", "T024" };

                foreach (var jko in obj.BillingDetails)
                {
                    string ADRAnt   = "";
                    int    ADRCount = 0;
                    bool   AddFlete = false;

                    if (jko.SparePartsDescription != Folio)
                    {
                        switch (jko.SparePartsDescription)
                        {
                        case "Fletes":
                        {
                            var DetailCotation2 = NegocioCotizacionDetalle.GetList(cotizacion.PK_QuotationID);

                            foreach (var items in DetailCotation2)
                            {
                                if (lstADR.Contains(items.Origen))
                                {
                                    if (ADRAnt != items.Origen)
                                    {
                                        ADRAnt = items.Origen;
                                        ADRCount++;
                                        if (ADRCount < 3)
                                        {
                                            AddFlete = true;
                                        }
                                        else
                                        {
                                            AddFlete = false;
                                        }
                                    }
                                    if (AddFlete)
                                    {
                                        items.Flete      = true;
                                        items.CostoFlete = jko.Price;
                                        NegocioCotizacionDetalle.Update(items);
                                        AddFlete = false;
                                    }
                                }
                            }
                        }

                        break;

                        default:
                            var newDetailquotion = NegocioCotizacionDetalle.GetDetail(cotizacion.PK_QuotationID, jko.ProductID);

                            if (newDetailquotion == null)
                            {
                                NegocioCotizacionDetalle.Insert(cotizacion.PK_QuotationID, jko.ProductID, jko.Quantity.ToString(), jko.RefManID, jko.Origins, jko.Price);
                            }
                            break;
                        }
                    }
                }


                var Refacciones = new BusinessMabe().Orden_Venta(obj.ODS, obj.ServiceTypes, Folio);
            }
            return(obj.ODS);
        }