public HttpResponseMessage Post([FromBody] Roles rol) { try { G.AbrirConexionAPP(out db); var Rol = db.Roles.Where(a => a.idRol == rol.idRol).FirstOrDefault(); if (Rol == null) { Rol = new Roles(); Rol.NombreRol = rol.NombreRol; db.Roles.Add(Rol); db.SaveChanges(); } else { throw new Exception("Este rol YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Rol)); } catch (Exception ex) { G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] SeguridadRolesModulos[] objeto) { G.AbrirConexionAPP(out db); var t = db.Database.BeginTransaction(); try { var primero = objeto[0].CodRol; var rolesModulos = db.SeguridadRolesModulos.Where(a => a.CodRol == primero).ToList(); foreach (var item in rolesModulos) { var Objeto = db.SeguridadRolesModulos.Where(a => a.CodRol == item.CodRol && a.CodModulo == item.CodModulo).FirstOrDefault(); if (Objeto != null) { db.SeguridadRolesModulos.Remove(Objeto); db.SaveChanges(); } } foreach (var item in objeto) { var Objeto = db.SeguridadRolesModulos.Where(a => a.CodRol == item.CodRol && a.CodModulo == item.CodModulo).FirstOrDefault(); if (Objeto == null) { var Objetos = new SeguridadRolesModulos(); Objetos.CodRol = item.CodRol; Objetos.CodModulo = item.CodModulo; db.SeguridadRolesModulos.Add(Objetos); db.SaveChanges(); } } t.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, objeto)); } catch (Exception ex) { t.Rollback(); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public async Task <HttpResponseMessage> Get([FromUri] Filtros filtro) { try { G.AbrirConexionAPP(out db); var Login = db.Login.ToList(); if (!string.IsNullOrEmpty(filtro.Texto)) { Login = Login.Where(a => a.Nombre.ToUpper().Contains(filtro.Texto.ToUpper()) || a.Email.ToUpper().Contains(filtro.Texto.ToUpper())).ToList(); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Login)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "GET de Usuario"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] CuentasContables cuenta) { try { G.AbrirConexionAPP(out db); var Cuenta = db.CuentasContables.Where(a => a.idCuentaContable == cuenta.idCuentaContable).FirstOrDefault(); if (Cuenta == null) { Cuenta = new CuentasContables(); Cuenta.CodSAP = cuenta.CodSAP; Cuenta.Nombre = cuenta.Nombre; db.CuentasContables.Add(Cuenta); db.SaveChanges(); } else { throw new Exception("Esta cuenta YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Cuenta)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insercion de Cuentas Contables"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] NormasReparto norma) { try { G.AbrirConexionAPP(out db); var Norma = db.NormasReparto.Where(a => a.id == norma.id).FirstOrDefault(); if (Norma == null) { Norma = new NormasReparto(); Norma.idLogin = norma.idLogin; Norma.CodSAP = norma.CodSAP; Norma.Nombre = norma.Nombre; Norma.idDimension = norma.idDimension; db.NormasReparto.Add(Norma); db.SaveChanges(); } else { throw new Exception("Esta norma de reparto YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Norma)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insercion de Norma de Reparto"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] Gastos gasto) { try { G.AbrirConexionAPP(out db); var Gasto = db.Gastos.Where(a => a.idTipoGasto == gasto.idTipoGasto).FirstOrDefault(); if (Gasto == null) { Gasto = new Gastos(); Gasto.idCuentaContable = gasto.idCuentaContable; Gasto.Nombre = gasto.Nombre; Gasto.PalabrasClave = gasto.PalabrasClave; db.Gastos.Add(Gasto); db.SaveChanges(); } else { throw new Exception("Este gasto YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Gasto)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insercion de Gastos"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] Dimensiones dimension) { try { G.AbrirConexionAPP(out db); var Dimension = db.Dimensiones.Where(a => a.id == dimension.id).FirstOrDefault(); if (Dimension == null) { Dimension = new Dimensiones(); Dimension.codigoSAP = dimension.codigoSAP; Dimension.Nombre = dimension.Nombre; db.Dimensiones.Add(Dimension); db.SaveChanges(); } else { throw new Exception("Esta dimensión YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, Dimension)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insertar Dimension"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public async Task <HttpResponseMessage> Get([FromUri] Filtros filtro) { try { G.AbrirConexionAPP(out db); var time = new DateTime(); var Liquidaciones = db.EncCierre.Where(a => a.Estado != "R" && (filtro.FechaInicio != time ? a.FechaCierre >= filtro.FechaInicio : true)).ToList(); if (filtro.FechaInicio.Date != new DateTime().Date) { filtro.FechaFinal = filtro.FechaFinal.AddDays(1); Liquidaciones = Liquidaciones.Where(a => a.FechaCierre >= filtro.FechaInicio && a.FechaCierre <= filtro.FechaFinal).ToList(); } if (filtro.Codigo1 > 0) { Liquidaciones = Liquidaciones.Where(a => a.idLogin == filtro.Codigo1).ToList(); } if (!string.IsNullOrEmpty(filtro.CodMoneda)) { Liquidaciones = Liquidaciones.Where(a => a.CodMoneda == filtro.CodMoneda).ToList(); } var MontoAcumulado = Liquidaciones.Sum(a => a.Total); List <EncCompras> comp = new List <EncCompras>(); List <EncCompras> compa = new List <EncCompras>(); foreach (var item in Liquidaciones) { var detalle = db.DetCierre.Where(a => a.idCierre == item.idCierre).ToList(); var EncCompras = db.EncCompras.Where(a => a.idCierre == item.idCierre).ToList(); foreach (var ite in detalle) { var fac = EncCompras.Where(a => a.id == ite.idFactura).FirstOrDefault(); comp.Add(fac); } } var Normas = db.NormasReparto.ToList(); var Login = db.Login.ToList(); foreach (var item in comp) { var login = Login.Where(a => a.id == item.idLoginAsignado).FirstOrDefault(); var NormaRepartoActual = Normas.Where(a => a.idLogin == login.id).FirstOrDefault(); if (NormaRepartoActual.id != item.idNormaReparto) { compa.Add(item); } } decimal Total = 0; foreach (var item in compa) { Total += ((item.TotalVenta - item.TotalDescuentos) + (item.TotalImpuesto + item.TotalOtrosCargos)).Value; } MontoAcumulado = MontoAcumulado - Total; HeaderReportViewModel he = new HeaderReportViewModel(); he.MontoAcumulado = MontoAcumulado.Value; G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, he)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Error totalizado"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage GetEnviarCorreo([FromBody] InfoLiquid item) { try { G.AbrirConexionAPP(out db); List <Attachment> adjuntos = new List <Attachment>(); // List<EncCompras> compras = new List<EncCompras>(); SendGridEmail.EmailSender emailsender = new SendGridEmail.EmailSender(); var parametros = db.Parametros.FirstOrDefault(); var Cierre = db.DetCierre.Where(a => a.idCierre == item.idCierre).ToList(); foreach (var det in Cierre) { var Compra = db.EncCompras.Where(a => a.id == det.idFactura).FirstOrDefault(); if (Compra.PdfFac != null) { Attachment att = new Attachment(new MemoryStream(Compra.PdfFac), Compra.PdfFactura); adjuntos.Add(att); } } var bodyH = item.body; HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = PdfPageSize.A4; converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait; converter.Options.MarginLeft = 5; converter.Options.MarginRight = 5; // create a new pdf document converting an html string SelectPdf.PdfDocument doc = converter.ConvertHtmlString(bodyH); var bytes = doc.Save(); doc.Close(); Attachment att3 = new Attachment(new MemoryStream(bytes), "Liquidacion.pdf"); adjuntos.Add(att3); var resp = emailsender.SendV2(item.emailDest, item.emailCC, "", parametros.RecepcionEmail, "Liquidación", "Liquidación por revisar", item.body, parametros.RecepcionHostName, parametros.EnvioPort, parametros.RecepcionUseSSL.Value, parametros.RecepcionEmail, parametros.RecepcionPassword, adjuntos); if (!resp) { throw new Exception("No se ha podido enviar el correo con la liquidación"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Error de Correo"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); G.GuardarTxt("ErrorCorreo.txt", ex.Message + " -> " + ex.StackTrace); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage Post([FromBody] LoginViewModel usuario) { try { var Empresa = dbLogin.LicEmpresas.Where(a => a.CedulaJuridica == usuario.CedulaJuridica).FirstOrDefault(); if (Empresa == null) { throw new Exception("Empresa no existe"); } db = new ModelCliente(Empresa.CadenaConexionBD); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } var t = db.Database.BeginTransaction(); var d = dbLogin.Database.BeginTransaction(); try { var User = dbLogin.LicUsuarios.Where(a => a.Email.ToUpper().Contains(usuario.Email.ToUpper()) && a.Activo == true).FirstOrDefault(); var usuario1 = db.Login.Where(a => a.Email.ToUpper().Contains(usuario.Email.ToUpper()) && a.Activo == true).FirstOrDefault(); if (usuario1 == null) { User = new LicUsuarios(); User.Nombre = usuario.Nombre; User.Clave = BCrypt.Net.BCrypt.HashPassword(usuario.Clave); User.Email = usuario.Email; User.Activo = true; User.CedulaJuridica = usuario.CedulaJuridica; Login login = new Login(); login.Nombre = User.Nombre; login.Clave = User.Clave; login.Activo = true; login.idRol = usuario.idRol; login.Email = User.Email; login.CardCode = usuario.CardCode; login.idLoginAceptacion = usuario.idLoginAceptacion; login.CambiarClave = true; login.CambioFecha = false; db.Login.Add(login); dbLogin.LicUsuarios.Add(User); dbLogin.SaveChanges(); db.SaveChanges(); if (login.idLoginAceptacion == 0) { db.Entry(login).State = EntityState.Modified; login.idLoginAceptacion = login.id; db.SaveChanges(); } d.Commit(); t.Commit(); } else { throw new Exception("Este usuario YA existe"); } G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insercion de Usuario"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); t.Rollback(); d.Rollback(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage GetAsientos([FromUri] int idCierre = 0) { object resp; decimal imp1 = 0; decimal imp2 = 0; decimal imp4 = 0; decimal imp8 = 0; decimal imp13 = 0; try { G.AbrirConexionAPP(out db); var Cierre = db.EncCierre.Where(a => a.idCierre == idCierre).FirstOrDefault(); G.GuardarTxt("ErrorSAP.txt", "Entro"); var Compañia = G.ObtenerCedulaJuridia(); var Licencia = dbLogin.LicEmpresas.Where(a => a.CedulaJuridica == Compañia).FirstOrDefault(); var Pais = Licencia.CadenaConexionSAP; if (Cierre.ProcesadaSAP == true) { throw new Exception("Esta liquidación ya fue procesada"); } var Detalle = db.DetCierre.Where(a => a.idCierre == Cierre.idCierre).ToList(); List <EncCompras> enc = new List <EncCompras>(); var Encabezados = db.EncCompras.Where(a => a.idCierre == Cierre.idCierre).ToList(); foreach (var item in Detalle) { var compra = Encabezados.Where(a => a.id == item.idFactura).FirstOrDefault(); enc.Add(compra); } var login = db.Login.Where(a => a.id == Cierre.idLogin).FirstOrDefault(); var param = db.Parametros.FirstOrDefault(); var oInvoice = (Documents)Conexion.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); oInvoice.DocObjectCode = BoObjectTypes.oPurchaseInvoices; oInvoice.CardCode = login.CardCode; //CardCode que viene de login if (login.CambioFecha) { //int DiferenciaDias = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15) - DateTime.Now).Days; //oInvoice.DocDate = DateTime.Now.AddDays(DiferenciaDias); //Fecha que se realiza el asiento //oInvoice.DocDueDate = DateTime.Now.AddDays(DiferenciaDias); //Fecha que se realiza el asiento oInvoice.DocDate = DateTime.Now; //Fecha que se realiza el asiento oInvoice.DocDueDate = DateTime.Now; //Fecha que se realiza el asiento } else { oInvoice.DocDate = Cierre.FechaFinal; //Final del periodo de cierre oInvoice.DocDueDate = Cierre.FechaFinal; //Final del periodo de cierre } oInvoice.DocCurrency = (Cierre.CodMoneda == "CRC" ? "COL" : Cierre.CodMoneda); //Moneda de la liquidacion if (Pais == "P") { if (Cierre.CodMoneda == "USD") { oInvoice.DocCurrency = "$"; } } oInvoice.DocType = BoDocumentTypes.dDocument_Service; oInvoice.NumAtCard = "Liquidación: " + idCierre.ToString(); var i = 0; foreach (var item in enc) { Gastos TipoGasto = new Gastos(); //Esto no va para panama if (Pais == "C") { if (item.RegimenSimplificado) { TipoGasto = db.Gastos.Where(a => a.Nombre.ToUpper().Contains("Regimen Simplificado".ToUpper())).FirstOrDefault(); } else { TipoGasto = db.Gastos.Where(a => a.idTipoGasto == item.idTipoGasto).FirstOrDefault(); } } else //Panama { TipoGasto = db.Gastos.Where(a => a.idTipoGasto == item.idTipoGasto).FirstOrDefault(); } var Cuenta = db.CuentasContables.Where(a => a.idCuentaContable == TipoGasto.idCuentaContable).FirstOrDefault(); var Norma = db.NormasReparto.Where(a => a.id == item.idNormaReparto).FirstOrDefault(); var Dimension = db.Dimensiones.Where(a => a.id == Norma.idDimension).FirstOrDefault(); oInvoice.Lines.SetCurrentLine(i); if (Pais == "C") { oInvoice.Lines.ItemDescription = item.CodProveedor + "-" + item.NomProveedor;//"3102751358 - D y D Consultores"; // Factura -> Cedula } else { oInvoice.Lines.ItemDescription = item.CodProveedor.Split('[')[0] + " - " + item.CodProveedor.Split('[')[1] + "-" + item.NomProveedor; //"3102751358 - D y D Consultores"; // Factura -> Cedula } oInvoice.Lines.AccountCode = Cuenta.CodSAP; //"6-01-02-05-000"; //Cuenta contable del gasto if (Pais == "C") { oInvoice.Lines.TaxCode = param.IMPEX; //Exento para Panama -> Verificar el codigo C0 } else { oInvoice.Lines.VatGroup = param.IMPEX; } //Redifinir para Panama if (Pais == "C") { imp1 += item.Impuesto1; imp2 += item.Impuesto2; imp4 += item.Impuesto4; imp8 += item.Impuesto8; imp13 += item.Impuesto13; } else //Panama { imp1 += item.Impuesto1; imp2 += item.Impuesto2; } //Normas de reparto switch (Dimension.codigoSAP) { case "1": { oInvoice.Lines.CostingCode = Norma.CodSAP; oInvoice.Lines.CostingCode2 = ""; oInvoice.Lines.CostingCode3 = ""; oInvoice.Lines.CostingCode4 = ""; oInvoice.Lines.CostingCode5 = ""; break; } case "2": { oInvoice.Lines.CostingCode = ""; oInvoice.Lines.CostingCode2 = Norma.CodSAP; oInvoice.Lines.CostingCode3 = ""; oInvoice.Lines.CostingCode4 = ""; oInvoice.Lines.CostingCode5 = ""; break; } case "3": { oInvoice.Lines.CostingCode = ""; oInvoice.Lines.CostingCode2 = ""; oInvoice.Lines.CostingCode3 = Norma.CodSAP; oInvoice.Lines.CostingCode4 = ""; oInvoice.Lines.CostingCode5 = ""; break; } case "4": { oInvoice.Lines.CostingCode = ""; oInvoice.Lines.CostingCode2 = ""; oInvoice.Lines.CostingCode3 = ""; oInvoice.Lines.CostingCode4 = Norma.CodSAP; oInvoice.Lines.CostingCode5 = ""; break; } case "5": { oInvoice.Lines.CostingCode = ""; oInvoice.Lines.CostingCode2 = ""; oInvoice.Lines.CostingCode3 = ""; oInvoice.Lines.CostingCode4 = ""; oInvoice.Lines.CostingCode5 = Norma.CodSAP; break; } default: { oInvoice.Lines.CostingCode = Norma.CodSAP; oInvoice.Lines.CostingCode2 = ""; oInvoice.Lines.CostingCode3 = ""; oInvoice.Lines.CostingCode4 = ""; oInvoice.Lines.CostingCode5 = ""; break; } } oInvoice.Lines.LineTotal = Convert.ToDouble(item.TotalComprobante.Value - item.TotalImpuesto); if (Pais == "C") { G.GuardarTxt("ErrorSAP.txt", "Entro en: " + Pais); if (TipoGasto.Nombre.ToUpper().Contains("Combustible".ToUpper())) { var DetalleFac = db.DetCompras.Where(a => a.NumFactura == item.NumFactura && a.ClaveHacienda == item.ClaveHacienda && a.ConsecutivoHacienda == item.ConsecutivoHacienda).FirstOrDefault(); oInvoice.Lines.UserFields.Fields.Item("U_CantLitrosKw").Value = int.Parse(Math.Round(DetalleFac.Cantidad.Value).ToString()); oInvoice.Lines.UserFields.Fields.Item("U_Tipo").Value = (DetalleFac.NomPro.ToUpper().Contains("Diesel".ToUpper()) ? "Diesel" : QuitarTilde(DetalleFac.NomPro).ToUpper().Contains("Super".ToUpper()) ? "Gasolina Super" : QuitarTilde(DetalleFac.NomPro).ToUpper().Contains("Regular".ToUpper()) ? "Gasolina Regular" : "Diesel"); } oInvoice.Lines.UserFields.Fields.Item("U_NumFactura").Value = item.NumFactura.ToString(); oInvoice.Lines.UserFields.Fields.Item("U_FechaFactura").Value = item.FecFactura; } else //Panama { G.GuardarTxt("ErrorSAP.txt", "Entro en: " + Pais); if (TipoGasto.Nombre.ToUpper().Contains("Comb".ToUpper())) { var DetalleFac = db.DetCompras.Where(a => a.NumFactura == item.NumFactura && a.ClaveHacienda == item.ClaveHacienda && a.ConsecutivoHacienda == item.ConsecutivoHacienda).FirstOrDefault(); oInvoice.Lines.UserFields.Fields.Item("U_CantLitrosKw").Value = int.Parse(Math.Round(DetalleFac.Cantidad.Value).ToString()); oInvoice.Lines.UserFields.Fields.Item("U_Tipo").Value = (DetalleFac.NomPro.ToUpper().Contains("Diesel".ToUpper()) ? "Diesel" : QuitarTilde(DetalleFac.NomPro).ToUpper().Contains("Gasolina 95".ToUpper()) ? "Gasolina 95" : QuitarTilde(DetalleFac.NomPro).ToUpper().Contains("Gasolina 90".ToUpper()) ? "Gasolina 90" : "Gas LP"); } oInvoice.Lines.UserFields.Fields.Item("U_REFFAC").Value = item.NumFactura.ToString(); oInvoice.Lines.UserFields.Fields.Item("U_FechaFac").Value = item.FecFactura; switch (item.CodProveedor.Replace("-", "").Replace("-", "").Length) { case 8: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "1"; break; } case 9: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "1"; break; } case 10: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "3"; break; } case 14: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "2"; break; } case 15: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "2"; break; } default: { oInvoice.Lines.UserFields.Fields.Item("U_Tipoid").Value = "1"; break; } } oInvoice.Lines.UserFields.Fields.Item("U_RUC").Value = item.CodProveedor.Split('[')[0]; oInvoice.Lines.UserFields.Fields.Item("U_DV").Value = item.CodProveedor.Split('[')[1]; oInvoice.Lines.UserFields.Fields.Item("U_Proveedor").Value = item.NomProveedor; } oInvoice.Lines.Add(); i++; } //Preguntar por el pais if (Pais == "C") { if (imp1 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "Impuesto 1"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp1); oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI1; oInvoice.Lines.Add(); i++; } if (imp2 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "Impuesto 2"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp2); oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI2; oInvoice.Lines.Add(); i++; } if (imp4 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "Impuesto 4"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp4); oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI4; oInvoice.Lines.Add(); i++; } if (imp8 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "Impuesto 8"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp8); oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI8; oInvoice.Lines.Add(); i++; } if (imp13 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "Impuesto 13"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp13); oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI13; oInvoice.Lines.Add(); i++; } } else //Panama { if (imp1 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "ITBMS(7%)"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp1); oInvoice.Lines.VatGroup = param.IMPEX; //oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI1; oInvoice.Lines.Add(); i++; } if (imp2 > 0) { oInvoice.Lines.SetCurrentLine(i); oInvoice.Lines.ItemDescription = "ITBMS(10%)"; oInvoice.Lines.LineTotal = Convert.ToDouble(imp2); oInvoice.Lines.VatGroup = param.IMPEX; // oInvoice.Lines.TaxCode = param.IMPEX; oInvoice.Lines.AccountCode = param.CI2; oInvoice.Lines.Add(); i++; } } var respuesta = oInvoice.Add(); G.GuardarTxt("ErrorSAP.txt", "Respuesta: " + respuesta.ToString()); if (respuesta == 0) { var docEntry = Conexion.Company.GetNewObjectKey(); db.Entry(Cierre).State = EntityState.Modified; Cierre.ProcesadaSAP = true; db.SaveChanges(); resp = new { DocEntry = docEntry, // Series = pedido.Series.ToString(), Type = "oPurchaiseInvoice", Status = 1, Message = "Factura creada exitosamente", User = Conexion.Company.UserName }; G.CerrarConexionAPP(db); Conexion.Desconectar(); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } BitacoraErrores be = new BitacoraErrores(); be.Descripcion = Conexion.Company.GetLastErrorDescription(); be.StackTrace = Conexion.Company.UserName; be.Metodo = "Insercion de Asiento"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); resp = new { // Series = pedido.Series.ToString(), DocEntry = 0, Type = "oPurchaiseInvoice", Status = 0, Message = Conexion.Company.GetLastErrorDescription(), User = Conexion.Company.UserName }; Conexion.Desconectar(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } catch (Exception ex) { resp = new { DocEntry = 0, Type = "oPurchaiseInvoice", Status = 0, Message = "[Stack] -> " + ex.StackTrace + " -- [Message] --> " + ex.Message, User = Conexion.Company.UserName }; BitacoraErrores be = new BitacoraErrores(); be.Descripcion = ex.Message; be.StackTrace = ex.StackTrace; be.Metodo = "Insercion de Asiento"; be.Fecha = DateTime.Now; db.BitacoraErrores.Add(be); db.SaveChanges(); Conexion.Desconectar(); G.CerrarConexionAPP(db); return(Request.CreateResponse(HttpStatusCode.InternalServerError, resp)); } }