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); } }
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); }