Exemplo n.º 1
0
        public string CreateContract(ModelViewContrat obj)
        {
            var NegocioOrden    = new BusinessOrder();
            var NegocioCliente  = new BusinessClient();
            var NegocioContrato = new BusinessContrat();
            var objAlerta       = new BusinessNotification();
            var Cliente         = NegocioCliente.GetByClientID(obj.NumbClient);

            SpreadsheetInfo.SetLicense("EQU2-3K5L-UZDC-SDYN");
            string        Origin = GlobalConfiguration.MabeAttachmentsLocal + "FormatoContrato.xlsx";
            List <string> result = obj.EMails.Split(new char[] { ';' }).ToList();

            ExcelFile      ef = ExcelFile.Load(Origin);
            ExcelWorksheet ws = ef.Worksheets[0];

            ws.Cells["N15"].Value = obj.Folio;
            //ws.Cells["L7"].Value = obj.ODS;
            ws.Cells["M20"].Value  = obj.Period;
            ws.Cells["M21"].Value  = obj.StartDate;
            ws.Cells["T21"].Value  = obj.EndDate;
            ws.Cells["M30"].Value  = obj.NumbClient;
            ws.Cells["M31"].Value  = Cliente.FirstName + " " + Cliente.LastName.ToUpper();
            ws.Cells["M32"].Value  = Cliente.StreetAddress;
            ws.Cells["M33"].Value  = Cliente.BoroughAddress;
            ws.Cells["M34"].Value  = Cliente.MunicipalityAddress;
            ws.Cells["M35"].Value  = Cliente.PostalCodeAddress;
            ws.Cells["M36"].Value  = obj.Town;
            ws.Cells["M37"].Value  = Cliente.PhoneNumber1;
            ws.Cells["M38"].Value  = obj.Totals;
            ws.Cells["M48"].Value  = obj.Model;
            ws.Cells["M49"].Value  = obj.Description;
            ws.Cells["M50"].Value  = obj.Serie;
            ws.Cells["R145"].Value = obj.Town;
            ws.Cells["V145"].Value = DateTime.Today.ToString("yyyyMMdd");


            string file    = "ContratoPoliza" + obj.Folio + ".pdf";
            string quotion = "Polizas_" + DateTime.Today.ToString("yyyyMMdd");
            string Destiny = GlobalConfiguration.MabeAttachmentsLocal + quotion + "/" + file;

            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    orden    = NegocioOrden.GetByOrderID(obj.FK_OrderID);
            var    Contrato = NegocioContrato.GetByOrderFolio(orden.PK_OrderID, obj.Folio);

            if (obj.EMails != "")
            {
                if (Contrato == null)
                {
                    Contrato = NegocioContrato.Insert(orden.PK_OrderID, obj.Folio, URL);
                }
                else
                {
                    Contrato.Fk_OrderID = orden.PK_OrderID;
                    Contrato.Folio      = obj.Folio;
                    Contrato.Ruta       = URL;
                    NegocioContrato.Update(Contrato);
                }
                string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "MailContratoPoliza.txt");

                sb = sb.Replace("#%Nombre%#", Cliente.FirstName + " " + Cliente.LastName);
                sb = sb.Replace("#%Folio%#", obj.Folio);
                sb = sb.Replace("#%Modelo%#", obj.Model);
                sb = sb.Replace("#%Descripcion%#", obj.Description.ToUpper());
                sb = sb.Replace("#%Serie%#", obj.Serie);
                sb = sb.Replace("#%Compra%#", DateTime.Today.ToString("dd/MM/yyyy"));

                objAlerta.SendMailExchange(GlobalConfiguration.exchangeUserCotiza, GlobalConfiguration.exchangePwdCotiza, result, "Contrato Póliza", sb.ToString(), Destiny);
            }
            else
            {
                string Tipo     = "Poliza";
                var    EnvioSMS = SendNotification(obj.PhoneNumber, Tipo, URL);

                return(EnvioSMS);
            }

            return(URL);
        }
Exemplo n.º 2
0
        public string CreateReceipt(ModelViewUserG objCred, ModelViewReceiptRef obj)
        {
            var objRepository   = new RepositoryOrder();
            var NegocioOrden    = new BusinessOrder();
            var objAlerta       = new BusinessNotification();
            var NegocioUsuario  = new BusinessUsers();
            var NegocioCliente  = new BusinessClient();
            var NegocioContrato = new BusinessContrat();
            var NegocioEmpleado = new BusinessEmployee();
            var NegocioBOM      = new BusinessBuildOfMaterial();

            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.FK_OrderID);
            var cliente  = NegocioCliente.GetByID(orden.FK_ClientID);


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


            ws.Cells["W9"].Value  = obj.Folio;
            ws.Cells["W12"].Value = DateTime.Today.ToString("dd-MM-yyyy");
            ws.Cells["L18"].Value = cliente.FirstName.ToUpper();
            ws.Cells["P18"].Value = cliente.LastName.ToUpper();
            ws.Cells["L21"].Value = cliente.PhoneNumber1;
            ws.Cells["T21"].Value = cliente.PhoneNumber2;
            ws.Cells["M23"].Value = cliente.Email;


            int cantidad = 29;


            foreach (var jko in obj.SpareParts)
            {
                if (cantidad == 60)
                {
                    cantidad = 85;
                }
                ////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["K" + cantidad.ToString()].Value = jko.RefManID;
                    ws.Cells["M" + cantidad.ToString()].Value = jko.SparePartsDescription;
                }
                ws.Cells["R" + cantidad.ToString()].Value = jko.Quantity;
                ws.Cells["U" + cantidad.ToString()].Value = Convert.ToDouble(jko.Price);
                ws.Cells["W" + cantidad.ToString()].Value = Convert.ToDouble(jko.Totals);
                cantidad = cantidad + 1;
            }

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

            ws.Cells["W41"].Value = subtotalref;

            ws.Cells["W42"].Value = iva;
            ws.Cells["W43"].Value = total;

            string file    = "ReciboRef" + obj.Folio + ".pdf";
            string quotion = "RecibosRefaccion_" + DateTime.Today.ToString("yyyyMMdd");
            string Destiny = GlobalConfiguration.MabeAttachmentsLocal + quotion + "/" + file;

            if (obj.SpareParts.Count < 11)
            {
                ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("J1", "X54"));
            }
            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    Recibo = NegocioContrato.GetByOrderFolio(orden.PK_OrderID, obj.Folio);



            if (obj.EMails != "")
            {
                if (Recibo == null)
                {
                    Recibo = NegocioContrato.Insert(orden.PK_OrderID, obj.Folio, URL);
                }
                else
                {
                    Recibo.Fk_OrderID = orden.PK_OrderID;
                    Recibo.Folio      = obj.Folio;
                    Recibo.Ruta       = URL;
                    NegocioContrato.Update(Recibo);
                }

                string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "MaiReciboRef.txt");
                sb = sb.Replace("#%Nombre%#", cliente.FirstName + " " + cliente.LastName);
                sb = sb.Replace("#%Folio%#", obj.Folio);

                objAlerta.SendMailExchange(GlobalConfiguration.exchangeUserCotiza, GlobalConfiguration.exchangePwdCotiza, result, "Recibo Refacciones", sb.ToString(), Destiny);
                return(URL);
            }
            else
            {
                string Tipo     = "Recibo";
                var    EnvioSMS = SendNotification(obj.PhoneNumber, Tipo, URL);

                return(EnvioSMS);
            }
        }
Exemplo n.º 3
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;
        }