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 static void SendSMS() //{ // new BusinessPolicy().SendNotification(); //} public static string CreateReceipt(ModelViewUserG objCred, ModelViewReceiptRef obj) { return(new BusinessPolicy().CreateReceipt(objCred, obj)); }