private void SetInfoInControls() { try { txtID.Text = info.IdDocumento.ToString(); txtTipo.Text = info.Tipo; txtCodDocumento.Text = info.CodDocumento; txtEstablecimiento.Text = info.Establecimiento; txtPuntoEmision.Text = info.PuntoEmision; txtNumDocumento.Text = info.NumeroDocumento; txtClaveAcceso.Text = info.ClaveAcceso; txtIdentificacion.Text = info.emi_Ruc; txtRazonSocial.Text = info.emi_RazonSocial; txtNombreComercial.Text = info.emi_NombreComercial; txtDireccion.Text = info.emi_DireccionMatriz; txtSubtotal0.Text = info.Subtotal0.ToString(); txtSubtotalIVA.Text = info.SubtotalIVA.ToString(); txtPorcentaje.Text = info.Porcentaje.ToString(); txtIVA.Text = info.ValorIVA.ToString(); txtTotal.Text = info.Total.ToString(); deFecha.DateTime = Convert.ToDateTime(info.FechaEmision).Date; txtContribuyente.Text = info.emi_ContribuyenteEspecial; txtRetEstablecimiento.Text = info.ret_Establecimiento; txtRetPuntoEmision.Text = info.ret_PuntoEmision; txtRetNumeroDocumento.Text = info.ret_NumeroDocumento; txtRetAutorizacion.Text = info.ret_NumeroAutorizacion; deRetFechaAutorizacion.DateTime = info.ret_FechaAutorizacion ?? DateTime.Now.Date; deRetFecha.DateTime = info.ret_Fecha ?? DateTime.Now.Date; cmbFormaPago.EditValue = info.FormaPago; deRetFecha.DateTime = Convert.ToDateTime(info.FechaEmision).Date; blst = new BindingList <cp_XML_Documento_Retencion_Info>(bus_det.GetList(param.IdEmpresa, info.IdDocumento)); gcRetencion.DataSource = blst; if (!string.IsNullOrEmpty(info.ret_NumeroDocumento)) { btnEliminarRetencion.Visible = true; } else { btnEliminarRetencion.Visible = false; } gcDetalleXML.DataSource = bus_xml_det.GetList(param.IdEmpresa, info.IdDocumento); var MicroEmpresa = busMicroEmpresa.GetInfo(info.emi_Ruc); lblMicroEmpresa.Visible = MicroEmpresa == null ? false : true; } catch (Exception) { throw; } }
private void btnVerificarCarpeta_Click(object sender, EventArgs e) { try { ListaMicroEmpresa = new List <cp_proveedor_microempresa_Info>(); bus_ruta.GuardarDB(new cp_RutaPorEmpresaPorUsuario_Info { IdEmpresa = param.IdEmpresa, IdUsuario = param.IdUsuario, RutaXML = txtRutaXml.Text }); blst = new BindingList <cp_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("infoFactura"); var infoTributaria = rootElement.Element("infoTributaria"); var IdentificacionComprador = infoFactura.Element("identificacionComprador").Value; if (IdentificacionComprador == param.InfoEmpresa.em_ruc) { var Documento = new cp_XML_Documento_Info { XML = sXml_a_descerializar, Tipo = infoTributaria.Element("codDoc").Value == "01" ? "FACTURA" : "NOTA DE CREDITO", emi_Ruc = infoTributaria.Element("ruc").Value, emi_RazonSocial = infoTributaria.Element("razonSocial").Value, emi_NombreComercial = infoTributaria.Element("nombreComercial") == null?infoTributaria.Element("razonSocial").Value : infoTributaria.Element("nombreComercial").Value, ClaveAcceso = infoTributaria.Element("claveAcceso").Value, emi_ContribuyenteEspecial = infoFactura.Element("contribuyenteEspecial") == null ? "NO" : infoFactura.Element("contribuyenteEspecial").Value, CodDocumento = infoTributaria.Element("codDoc").Value, Establecimiento = infoTributaria.Element("estab").Value, PuntoEmision = infoTributaria.Element("ptoEmi").Value, NumeroDocumento = infoTributaria.Element("secuencial").Value, emi_DireccionMatriz = infoTributaria.Element("dirMatriz").Value, FechaEmision = DateTime.ParseExact(infoFactura.Element("fechaEmision").Value, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture), rec_RazonSocial = infoFactura.Element("razonSocialComprador").Value, rec_Identificacion = infoFactura.Element("identificacionComprador").Value }; Documento.FormaPago = infoFactura.Element("pagos") == null ? null : infoFactura.Element("pagos").Element("pago") == null ? null : (infoFactura.Element("pagos").Element("pago").Element("formaPago") == null ? null : infoFactura.Element("pagos").Element("pago").Element("formaPago").Value); Documento.Plazo = infoFactura.Element("pagos") == null ? 0 : infoFactura.Element("pagos").Element("pago") == null ? 0 : (infoFactura.Element("pagos").Element("pago").Element("plazo") == null ? 0 : Convert.ToInt32(Convert.ToDecimal(infoFactura.Element("pagos").Element("pago").Element("plazo").Value))); var list = infoFactura.Element("totalConImpuestos").Elements("totalImpuesto") .Select(element => element) .ToList(); Documento.SubtotalIVA = 0; Documento.Subtotal0 = 0; Documento.ValorIVA = 0; foreach (var Impuesto in list) { if (Impuesto.Element("codigo").Value.ToString() != "3") { Documento.Porcentaje = Convert.ToDouble(Impuesto.Element("valor").Value); if (Documento.Porcentaje == 0) { Documento.Descuento += Impuesto.Element("descuentoAdicional") == null ? 0 : Convert.ToDouble(Impuesto.Element("descuentoAdicional").Value); Documento.Subtotal0 += Convert.ToDouble(Impuesto.Element("baseImponible").Value) - Documento.Descuento; } else { Documento.Descuento += Impuesto.Element("descuentoAdicional") == null ? 0 : Convert.ToDouble(Impuesto.Element("descuentoAdicional").Value); Documento.SubtotalIVA += Convert.ToDouble(Impuesto.Element("baseImponible").Value) - Documento.Descuento; Documento.ValorIVA += Convert.ToDouble(Impuesto.Element("valor").Value); Documento.Porcentaje = bus_impuesto.Get_Info_impuesto(param.Get_Parametro_Info(tb_parametro_enum.P_IVA).Valor).porcentaje; } } } Documento.Total = Documento.Subtotal0 + Documento.SubtotalIVA + Documento.ValorIVA; double ValorIva = Math.Round((double)Documento.SubtotalIVA * 0.12, 2, MidpointRounding.AwayFromZero); if (ValorIva != Documento.ValorIVA) { MessageBox.Show("Revisar: \n" + item + "\nIVA no cuadra con el subtotal con IVA :\nIVA calculado: " + ValorIva.ToString("c2") + "\nIVA en factura: " + Convert.ToDouble(Documento.ValorIVA).ToString("c2")); } Documento.Comprobante = Documento.CodDocumento + '-' + Documento.Establecimiento + "-" + Documento.PuntoEmision + "-" + Documento.NumeroDocumento; var listD = rootElement.Element("detalles").Elements("detalle") .Select(element => element) .ToList(); Documento.lstDetalle = new List <cp_XML_DocumentoDet_Info>(); foreach (var Detalle in listD) { var d = new cp_XML_DocumentoDet_Info { NombreProducto = Detalle.Element("descripcion").Value.ToString(), Cantidad = Convert.ToDouble(Detalle.Element("cantidad").Value), Precio = Convert.ToDouble(Detalle.Element("precioTotalSinImpuesto").Value) }; var ImpuestoD = Detalle.Element("impuestos").Elements("impuesto") .Select(element => element) .FirstOrDefault(); d.PorcentajeIVA = Convert.ToDouble(ImpuestoD.Element("tarifa").Value); d.ValorIva = Convert.ToDouble(ImpuestoD.Element("valor").Value); d.Total = d.Precio + d.ValorIva; Documento.lstDetalle.Add(d); } if (Documento.Total == 0) { Documento.Descuento = infoFactura.Element("totalDescuento") == null ? 0 : Convert.ToDouble(infoFactura.Element("totalDescuento").Value); Documento.Subtotal0 = Convert.ToDouble(infoFactura.Element("totalSinImpuestos").Value) - Documento.Descuento; Documento.Total = Documento.Subtotal0; } if (ListaCodigoProveedor.Where(q => q.IdEmpresa == param.IdEmpresa && q.pe_cedulRuc == Documento.emi_Ruc).Count() == 0) { var ListaDet = bus_codigoProveedor.GetList(param.IdEmpresa, Documento.emi_Ruc); if (ListaDet.Count > 0) { Documento.Automatico = true; ListaCodigoProveedor.AddRange(ListaDet); } } else { Documento.Automatico = true; } var CodigoProveedor = ListaCodigoProveedor.Where(q => q.IdEmpresa == param.IdEmpresa && q.pe_cedulRuc == Documento.emi_Ruc).ToList(); if (CodigoProveedor != null && CodigoProveedor.Count > 0 && Documento.ValorIVA > 0) { if (CodigoProveedor.Where(q => q.re_tipo == "IVA").Count() == 0) { MessageBox.Show("El proveedor " + Documento.emi_RazonSocial + " no tiene parametrizada un código para retención de IVA para el documento " + Documento.Comprobante, param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } #region Validar microempresas var MicroEmpresa = ListaMicroEmpresa.Where(q => q.Ruc == Documento.emi_Ruc).FirstOrDefault(); if (MicroEmpresa == null) { MicroEmpresa = busMicroEmpresa.GetInfo(Documento.emi_Ruc); if (MicroEmpresa == null) { ListaMicroEmpresa.Add(new cp_proveedor_microempresa_Info { Ruc = Documento.emi_Ruc, EsMicroEmpresa = false }); } else { ListaMicroEmpresa.Add(new cp_proveedor_microempresa_Info { Ruc = MicroEmpresa.Ruc, EsMicroEmpresa = true, Nombre = MicroEmpresa.Nombre }); Documento.EsMicroEmpresa = true; } } else { Documento.EsMicroEmpresa = MicroEmpresa.EsMicroEmpresa; } #endregion Documento.Imagen = bus_xml.Existe(param.IdEmpresa, Documento.emi_Ruc, Documento.CodDocumento, Documento.Establecimiento, Documento.PuntoEmision, Documento.NumeroDocumento); if (blst.Where(q => q.Comprobante == Documento.Comprobante && q.emi_Ruc == Documento.emi_Ruc).Count() == 0) { blst.Add(Documento); } gcDetalle.DataSource = null; gcDetalle.DataSource = blst; } } lblContador.Text = blst.Count.ToString(); gcDetalle.DataSource = blst; if (blst.Where(q => q.EsMicroEmpresa == true).Count() > 0) { MessageBox.Show("Existen microempresas en el listado de documentos, revise la parametrización", param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { gcDetalle.DataSource = blst; lblContador.Text = blst.Count.ToString(); MessageBox.Show(ex.Message, param.Nombre_sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } }