private void gvDetalle_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { try { cxc_XML_Documento_Info row = (cxc_XML_Documento_Info)gvDetalle.GetRow(e.FocusedRowHandle); if (row == null) { return; } if (!row.Estado) { gvDetalle.Appearance.FocusedRow.ForeColor = Color.Red; gvDetalle.Appearance.FocusedCell.ForeColor = Color.Red; } else { gvDetalle.Appearance.FocusedRow.ForeColor = Color.Black; gvDetalle.Appearance.FocusedCell.ForeColor = Color.Black; } } catch (Exception) { throw; } }
public bool GuardarDB(cxc_XML_Documento_Info info) { try { return(odata.GuardarDB(info)); } catch (Exception ex) { throw ex; } }
public frmCXC_XML_Mantenimiento() { InitializeComponent(); busXML = new cxc_XML_Documento_Bus(); busXMLDet = new cxc_XML_DocumentoDet_Bus(); infoXML = new cxc_XML_Documento_Info(); blst = new BindingList <cxc_XML_DocumentoDet_Info>(); busTipoCobro = new cxc_cobro_tipo_Bus(); param = cl_parametrosGenerales_Bus.Instance; event_delegate_frmCXC_XML_Mantenimiento_FormClosed += frmCXC_XML_Mantenimiento_event_delegate_frmCXC_XML_Mantenimiento_FormClosed; }
public cxc_XML_Documento_Info GetInfoParaCruzar(int IdEmpresa, string dc_TipoDocumento, string NumDocSustento, double ValorRetenido, decimal IdCliente) { try { cxc_XML_Documento_Info info = new cxc_XML_Documento_Info(); EntitiesFacturacion dbFac = new EntitiesFacturacion(); EntitiesCuentas_x_Cobrar dbCxc = new EntitiesCuentas_x_Cobrar(); string Establecimiento = NumDocSustento.Substring(0, 3); string PuntoEmision = NumDocSustento.Substring(3, 3); string NumeroDocumento = NumDocSustento.Substring(6, 9); if (dc_TipoDocumento == "FACT") { var Factura = dbFac.vwfa_factura.Where(q => q.IdEmpresa == IdEmpresa && q.vt_serie1 == Establecimiento && q.vt_serie2 == PuntoEmision && q.vt_NumFactura == NumeroDocumento && q.Estado == "A" && q.IdCliente == IdCliente).FirstOrDefault(); if (Factura != null) { info.IdEmpresa = Factura.IdEmpresa; info.IdSucursal = Factura.IdSucursal; info.IdBodega_Cbte = Factura.IdBodega; info.IdCbte_vta_nota = Factura.IdCbteVta; int CobroRetencion = dbCxc.cxc_cobro_det.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdSucursal == info.IdSucursal && q.IdBodega_Cbte == info.IdBodega_Cbte && q.IdCbte_vta_nota == info.IdCbte_vta_nota && q.cxc_cobro.cr_estado == "A" && q.cxc_cobro.IdCobro_tipo.Contains("RT")).Count(); if (CobroRetencion > 0) { info.AplicaRetencion = 2; info.Motivo = "Documento ya tiene una retención aplicada"; return(info); } if (Math.Round(Factura.vt_saldo, 2, MidpointRounding.AwayFromZero) >= Math.Round(ValorRetenido, 2, MidpointRounding.AwayFromZero)) { info.AplicaRetencion = 1; } else { info.AplicaRetencion = 2; info.Motivo = "Documento no tiene saldo suficiente, \nTiene: " + Math.Round(Factura.vt_saldo, 2, MidpointRounding.AwayFromZero).ToString("c2") + "\nNecesita: " + Math.Round(ValorRetenido, 2, MidpointRounding.AwayFromZero).ToString("c2"); } } else { info.Motivo = "No existe documento " + NumDocSustento; } } return(info); } catch (Exception) { throw; } }
public cxc_XML_Documento_Info GetInfo(int IdEmpresa, decimal IdDocumento) { try { cxc_XML_Documento_Info info = new cxc_XML_Documento_Info(); using (EntitiesCuentas_x_Cobrar db = new EntitiesCuentas_x_Cobrar()) { var Entity = db.cxc_XML_Documento.Where(q => q.IdEmpresa == IdEmpresa && q.IdDocumento == IdDocumento).FirstOrDefault(); if (Entity == null) { return(null); } info = new cxc_XML_Documento_Info { IdEmpresa = Entity.IdEmpresa, IdDocumento = Entity.IdDocumento, Comprobante = Entity.Comprobante, XML = Entity.XML, Tipo = Entity.Tipo, emi_RazonSocial = Entity.emi_RazonSocial, emi_NombreComercial = Entity.emi_NombreComercial, emi_Ruc = Entity.emi_Ruc, emi_DireccionMatriz = Entity.emi_DireccionMatriz, emi_ContribuyenteEspecial = Entity.emi_ContribuyenteEspecial, ClaveAcceso = Entity.ClaveAcceso, CodDocumento = Entity.CodDocumento, Establecimiento = Entity.Establecimiento, PuntoEmision = Entity.PuntoEmision, NumeroDocumento = Entity.NumeroDocumento, FechaEmision = Entity.FechaEmision, rec_RazonSocial = Entity.rec_RazonSocial, rec_Identificacion = Entity.rec_Identificacion, Estado = Entity.Estado, Observacion = Entity.Observacion, }; } return(info); } catch (Exception) { throw; } }
private void gvDetalle_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { try { cxc_XML_Documento_Info row = (cxc_XML_Documento_Info)gvDetalle.GetRow(e.RowHandle); if (row == null) { return; } if (!row.Estado) { e.Appearance.ForeColor = Color.Red; } } catch (Exception) { throw; } }
private void btnVerificarCarpeta_Click(object sender, EventArgs e) { try { bus_ruta.GuardarDB(new cp_RutaPorEmpresaPorUsuario_Info { IdEmpresa = param.IdEmpresa, IdUsuario = param.IdUsuario, RutaXML = txtRutaXml.Text }); blst = new BindingList <cxc_XML_Documento_Info>(); string folder = txtRutaXml.Text; string filter = "*.XML*"; string[] files = Directory.GetFiles(folder, filter); foreach (var item in files) { string readText = File.ReadAllText(item); XmlDocument xmlComprobanteOrigen = new XmlDocument(); xmlComprobanteOrigen.Load(new StringReader(readText)); string mensajeErrorOut = string.Empty; string sXml_a_descerializar = Quitar_a_xml_CDATA_y_Signature(xmlComprobanteOrigen.GetElementsByTagName("comprobante")[0].InnerXml, ref mensajeErrorOut); var rootElement = XElement.Parse(sXml_a_descerializar); var infoFactura = rootElement.Element("infoCompRetencion"); var infoTributaria = rootElement.Element("infoTributaria"); var IdentificacionComprador = infoFactura.Element("identificacionSujetoRetenido").Value; if (IdentificacionComprador == param.InfoEmpresa.em_ruc) { #region Cabecera var Documento = new cxc_XML_Documento_Info(); Documento.IdEmpresa = param.IdEmpresa; Documento.XML = sXml_a_descerializar; Documento.Tipo = infoTributaria.Element("codDoc").Value == "07" ? "RETENCION" : ""; Documento.emi_Ruc = infoTributaria.Element("ruc").Value; Documento.emi_RazonSocial = infoTributaria.Element("razonSocial").Value; Documento.emi_NombreComercial = infoTributaria.Element("nombreComercial") == null?infoTributaria.Element("razonSocial").Value : infoTributaria.Element("nombreComercial").Value; Documento.ClaveAcceso = infoTributaria.Element("claveAcceso").Value; Documento.emi_ContribuyenteEspecial = infoFactura.Element("contribuyenteEspecial") == null ? "NO" : infoFactura.Element("contribuyenteEspecial").Value; Documento.CodDocumento = infoTributaria.Element("codDoc").Value; Documento.Establecimiento = infoTributaria.Element("estab").Value; Documento.PuntoEmision = infoTributaria.Element("ptoEmi").Value; Documento.NumeroDocumento = infoTributaria.Element("secuencial").Value; Documento.emi_DireccionMatriz = infoTributaria.Element("dirMatriz").Value; Documento.FechaEmision = DateTime.ParseExact(infoFactura.Element("fechaEmision").Value, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture); Documento.rec_RazonSocial = infoFactura.Element("razonSocialSujetoRetenido").Value; Documento.rec_Identificacion = infoFactura.Element("identificacionSujetoRetenido").Value; Documento.Comprobante = Documento.CodDocumento + "-" + Documento.Establecimiento + "-" + Documento.PuntoEmision + "-" + Documento.NumeroDocumento; Documento.IdUsuarioCreacion = param.IdUsuario; #endregion #region Cliente var Cliente = ListaCliente.Where(q => q.Persona_Info.pe_cedulaRuc == Documento.emi_Ruc).FirstOrDefault(); if (Cliente == null) { Cliente = busCliente.GetCliente(param.IdEmpresa, Documento.emi_Ruc); if (Cliente == null) { Documento.AplicaRetencion = 2; Documento.Motivo = "El cliente no existe en el sistema"; } else { ListaCliente.Add(Cliente); Documento.IdCliente = Cliente.IdCliente; } } else { Documento.IdCliente = Cliente.IdCliente; } #endregion #region Detalle var infoImpuestos = rootElement.Element("impuestos"); if (infoImpuestos != null) { var list = infoImpuestos.Elements("impuesto") .Select(element => element) .ToList(); Documento.ListaDet = new List <cxc_XML_DocumentoDet_Info>(); foreach (var Impuesto in list) { var det = new cxc_XML_DocumentoDet_Info { TipoRetencion = Impuesto.Element("codigo").Value == "1" ? "FTE" : "IVA", CodigoRetencion = Impuesto.Element("codigoRetencion").Value.ToString(), BaseImponible = Convert.ToDecimal(Impuesto.Element("baseImponible").Value.ToString()), PorcentajeRetencion = Convert.ToDecimal(Impuesto.Element("porcentajeRetener").Value.ToString()), ValorRetenido = Convert.ToDecimal(Impuesto.Element("valorRetenido").Value.ToString()), CodDocSustento = Impuesto.Element("codDocSustento").Value.ToString(), NumDocSustento = Impuesto.Element("numDocSustento").Value.ToString(), FechaEmisionDocSustento = DateTime.ParseExact(Impuesto.Element("fechaEmisionDocSustento").Value, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture), }; if (det.TipoRetencion == "FTE") { Documento.TotalRetencionFTE += Convert.ToDouble(det.ValorRetenido); double Porcentaje = Convert.ToDouble(det.PorcentajeRetencion); var TipoCobro = ListaTipoCobro.Where(q => q.ESRetenFTE == "S" && q.PorcentajeRet == Porcentaje).FirstOrDefault(); if (TipoCobro == null) { MessageBox.Show("El porcentaje de retención de fuente " + Porcentaje.ToString() + " no se encuentra registrado", param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } det.IdCobro_tipo = TipoCobro.IdCobro_tipo; } else { Documento.TotalRetencionIVA += Convert.ToDouble(det.ValorRetenido); double Porcentaje = Convert.ToDouble(det.PorcentajeRetencion); var TipoCobro = ListaTipoCobro.Where(q => q.ESRetenIVA == "S" && q.PorcentajeRet == Porcentaje).FirstOrDefault(); if (TipoCobro == null) { MessageBox.Show("El porcentaje de retención de IVA " + Porcentaje.ToString() + " no se encuentra registrado", param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } det.IdCobro_tipo = TipoCobro.IdCobro_tipo; } det.dc_TipoDocumento = det.CodDocSustento == "01" ? "FACT" : "NTDB"; Documento.DocumentoSustento = det.NumDocSustento; Documento.ListaDet.Add(det); } #region Validar saldo factura if (Documento.AplicaRetencion == 0 && Documento.ListaDet.Count > 0) { var Det1 = Documento.ListaDet.First(); var Cab = busDet.GetInfoParaCruzar(param.IdEmpresa, Det1.dc_TipoDocumento, Det1.NumDocSustento, Convert.ToDouble(Documento.ListaDet.Sum(q => q.ValorRetenido)), Documento.IdCliente); if (Cab.IdSucursal > 0) { Documento.IdSucursal = Cab.IdSucursal; Documento.IdBodega_Cbte = Cab.IdBodega_Cbte; Documento.IdCbte_vta_nota = Cab.IdCbte_vta_nota; } Documento.AplicaRetencion = Cab.AplicaRetencion; Documento.Motivo = Cab.Motivo; } #endregion #endregion } else { MessageBox.Show("El archivo: " + item + "\nNo cumple las especificaciones técnicas", param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } blst.Add(Documento); gcDetalle.DataSource = null; gcDetalle.DataSource = blst; } } } catch (Exception ex) { gcDetalle.DataSource = blst; lblContador.Text = blst.Count.ToString(); MessageBox.Show(ex.Message, param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool GuardarDB(cxc_XML_Documento_Info info) { try { try { using (EntitiesCuentas_x_Cobrar db = new EntitiesCuentas_x_Cobrar()) { if (!string.IsNullOrEmpty(info.Motivo)) { return(false); } var Entity = new cxc_XML_Documento { IdEmpresa = info.IdEmpresa, IdDocumento = info.IdDocumento = GetID(info.IdEmpresa), Comprobante = info.Comprobante, XML = info.XML, Tipo = info.Tipo, emi_RazonSocial = info.emi_RazonSocial, emi_NombreComercial = info.emi_NombreComercial, emi_Ruc = info.emi_Ruc, emi_DireccionMatriz = info.emi_DireccionMatriz, emi_ContribuyenteEspecial = info.emi_ContribuyenteEspecial, ClaveAcceso = info.ClaveAcceso, CodDocumento = info.CodDocumento, Establecimiento = info.Establecimiento, PuntoEmision = info.PuntoEmision, NumeroDocumento = info.NumeroDocumento, FechaEmision = info.FechaEmision, rec_RazonSocial = info.rec_RazonSocial, rec_Identificacion = info.rec_Identificacion, Estado = true, IdUsuarioCreacion = info.IdUsuarioCreacion, FechaCreacion = DateTime.Now, Observacion = info.Observacion ?? "", DocumentoSustento = info.DocumentoSustento, TotalRetencionIVA = info.TotalRetencionIVA, TotalRetencionFTE = info.TotalRetencionFTE }; int Secuencia = 1; foreach (var item in info.ListaDet) { item.IdEmpresa = info.IdEmpresa; item.IdSucursal = info.IdSucursal; item.IdBodega_Cbte = info.IdBodega_Cbte; item.IdCbte_vta_nota = info.IdCbte_vta_nota; cxc_XML_DocumentoDet d = new cxc_XML_DocumentoDet { IdEmpresa = info.IdEmpresa, IdDocumento = info.IdDocumento, Secuencia = Secuencia++, TipoRetencion = item.TipoRetencion, CodigoRetencion = item.CodigoRetencion, BaseImponible = item.BaseImponible, PorcentajeRetencion = item.PorcentajeRetencion, ValorRetenido = item.ValorRetenido, CodDocSustento = item.CodDocSustento, NumDocSustento = item.NumDocSustento, FechaEmisionDocSustento = item.FechaEmisionDocSustento, IdSucursal = info.IdSucursal, IdCobro = item.IdCobro = ArmarCobro(info.IdEmpresa, info.IdSucursal, info.IdCliente, info.FechaEmision, info.Comprobante, info.IdUsuarioCreacion, item), dc_TipoDocumento = item.dc_TipoDocumento, IdBodega_Cbte = info.IdBodega_Cbte, IdCbte_vta_nota = info.IdCbte_vta_nota, IdCobro_tipo = item.IdCobro_tipo }; odata.ContabilizarRetencion(d.IdEmpresa, d.IdSucursal ?? 0, d.IdCobro ?? 0); db.cxc_XML_DocumentoDet.Add(d); } db.cxc_XML_Documento.Add(Entity); db.SaveChanges(); } return(true); } catch (DbEntityValidationException ex) { string mensaje = string.Empty; string arreglo = ToString(); tb_sis_Log_Error_Vzen_Data oDataLog = new tb_sis_Log_Error_Vzen_Data(); tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now); oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje); mensaje = ex.ToString() + " " + ex.Message; mensaje = "Error al Grabar" + ex.Message; throw new Exception(ex.ToString()); } } catch (Exception ex) { string arreglo = ToString(); string strMensaje = ""; tb_sis_Log_Error_Vzen_Data oDataLog = new tb_sis_Log_Error_Vzen_Data(); tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now); strMensaje = ex.ToString() + " " + ex.Message; oDataLog.Guardar_Log_Error(Log_Error_sis, ref strMensaje); throw new Exception(ex.ToString()); } }
public void SetInfo(Cl_Enumeradores.eTipo_action _Accion, cxc_XML_Documento_Info _info) { Accion = _Accion; infoXML = _info; }