public string EnviaDatosPrefeitura(PedidoEnvioLoteRPS Pedido) { var XML_Prefeitura = new EnvioLoteRPSRequest(); EnvioLoteRPSResponse Servicio_response = new EnvioLoteRPSResponse(); XmlSerializer serializador = new XmlSerializer(typeof(PedidoEnvioLoteRPS)); StringWriter XMLescritor = new StringWriter(); serializador.Serialize(XMLescritor, Pedido); LoteNFeSoapClient Servicio = new LoteNFeSoapClient(); X509Certificate2 cert = new X509Certificate2(); cert = GetCertificate(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc = GetXMLSigned(XMLescritor.ToString(), cert); XML_Prefeitura.VersaoSchema = 3; XML_Prefeitura.MensagemXML = xmlDoc.OuterXml; //StreamWriter ArchSalida = new StreamWriter("C:\\DESA\\TIISELAM\\PREFEITURA\\ARCHIVO_PREFEITURA.xml"); xmlDoc.Save("C:\\DESA\\TIISELAM\\PREFEITURA\\ARCHIVO_PREFEITURA.xml"); ///return XML_Prefeitura.MensagemXML; try { X509Store store = new X509Store(StoreLocation.CurrentUser); Servicio.ClientCredentials.ClientCertificate.Certificate = cert; // Servicio.ClientCredentials.ClientCertificate.SetCertificate(cert.SubjectName.Name, store.Location,StoreName.TrustedPeople); //Servicio.ClientCredentials.ClientCertificate.Certificate = cert; Servicio_response.RetornoXML = Servicio.TesteEnvioLoteRPS(XML_Prefeitura.VersaoSchema, XML_Prefeitura.MensagemXML); ; return(XML_Prefeitura.MensagemXML); // var response = Servicio.TesteEnvioLoteRPS(XML_Prefeitura.VersaoSchema, XML_Prefeitura.MensagemXML); // return response; // if (response == "O") // { // ; //byte[] converbyte = Convert.FromBase64String(response.xml.ToString()); //return System.Text.Encoding.UTF8.GetString(converbyte); //return response.xml.ToString(); /*return "Mensaje XML: " + response.mensaje + Environment.NewLine + * "Código error: " + response.codigo + Environment.NewLine + * "Estatus: " + response.estatus + Environment.NewLine + * "Hora: " + response.hora + Environment.NewLine + * "Id Transacción: " + response.idtransaccion + Environment.NewLine + * "Numeración: " + response.numeracion + Environment.NewLine + * "CRC: " + response.crc + Environment.NewLine + * "DebugXML: " + debug_xml + Environment.NewLine + * "XML: " + converbyte.ToString();*/ // } // else // { //throw new Exception("Mensaje: " + response.mensaje + Environment.NewLine + /*return "Mensaje Error XML: " + response.mensaje + Environment.NewLine + * "Código error: " + response.codigo + Environment.NewLine + * "Estatus: " + response.estatus + Environment.NewLine + * "Hora: " + response.hora + Environment.NewLine + * "Id Transacción: " + response.idtransaccion + Environment.NewLine + * "Numeración: " + response.numeracion + Environment.NewLine + * "CRC: " + response.crc + Environment.NewLine + * "DebugXML: " + debug_xml + Environment.NewLine;*/ // } } //catch (Exception ex) catch (Exception ex) { return("EX: " + ex.Message + Servicio_response.RetornoXML); } }
public PedidoEnvioLoteRPS GeneraDatosRPS(GBRADocumentoVentaGP documentoGP) { string Assinatura; //Defino la cultura para el punto decimal a hacer el ToString. ESto define . como separador decimal. try { // Inicializo el objeto donde voy a guardar todos los datos del RPS PedidoEnvioLoteRPS Pedido = new PedidoEnvioLoteRPS(); //Esto se agrega para tener rastro de la factura para los errores. Pedido.Soptype = documentoGP.DocVenta.soptype; Pedido.SopNumbe = documentoGP.DocVenta.SOPNUMBE; //Cabecalho Pedido.Cabecalho = new Cabeca(); { Pedido.Cabecalho.CPFCNPJRemetente = new Cabeca.CPFCNPJRemet(); Pedido.Cabecalho.CPFCNPJRemetente.CNPJ = documentoGP.DocVenta.CPFCNPJRemetente;//"02195059000108"; if (documentoGP.DocVenta.transacao == 0) { Pedido.Cabecalho.transacao = "false"; } Pedido.Cabecalho.dtInicio = documentoGP.DocVenta.fechaEmision.ToString(("yyyy-MM-dd")); Pedido.Cabecalho.dtFim = documentoGP.DocVenta.fechaEmision.ToString(("yyyy-MM-dd")); Pedido.Cabecalho.QtdRPS = documentoGP.DocVenta.QtdRPS.ToString(); Pedido.Cabecalho.ValorTotalServicos = documentoGP.DocVenta.montoTotalVenta.ToString(); Pedido.Cabecalho.ValorTotalDeducoes = documentoGP.DocVenta.descuentoGlobalMonto.ToString(); } // RPS Pedido.RPS = new RPSCompleto(); { Assinatura = documentoGP.DocVenta.InscricaoPrestador + documentoGP.DocVenta.serie + documentoGP.DocVenta.numero + documentoGP.DocVenta.fechaEmision.ToString("yyyy-MM-dd") + documentoGP.DocVenta.TributacaoRPS + documentoGP.DocVenta.StatusRPS + documentoGP.DocVenta.ISSRetido + documentoGP.DocVenta.ValorTotalRecebido.ToString("0.00", nfi) + documentoGP.DocVenta.ValorCargaTributaria.ToString("0.00", nfi) + documentoGP.DocVenta.CodigoServico + documentoGP.DocVenta.indicadorTomador + documentoGP.DocVenta.CPFCNPJTomador + documentoGP.DocVenta.indicadorIntermediario + documentoGP.DocVenta.CPFCNPJIntermediario + documentoGP.DocVenta.ISSRetidoIntermediario ; //documentoGP.DocVenta.ISSRetidoIntermediario //PAsar a Base64 el string 64 Pedido.RPS.Assinatura = GetHash1(Assinatura); Pedido.RPS.ChaveRPS = new RPSCompleto.Chave(); { Pedido.RPS.ChaveRPS.InscricaoPrestador = documentoGP.DocVenta.InscricaoPrestador; Pedido.RPS.ChaveRPS.SerieRPS = documentoGP.DocVenta.serie; Pedido.RPS.ChaveRPS.NumeroRPS = documentoGP.DocVenta.numero; } if (documentoGP.DocVenta.TipoRPS == "1") { Pedido.RPS.TipoRPS = "RPS"; } Pedido.RPS.DataEmissao = documentoGP.DocVenta.fechaEmision.ToString("yyyy-MM-dd"); Pedido.RPS.StatusRPS = documentoGP.DocVenta.StatusRPS; Pedido.RPS.TributacaoRPS = documentoGP.DocVenta.TributacaoRPS; Pedido.RPS.ValorServicos = documentoGP.DocVenta.montoTotalVenta.ToString("0.00", nfi); Pedido.RPS.ValorDeducoes = documentoGP.DocVenta.descuentoGlobalMonto.ToString("0.00", nfi); Pedido.RPS.ValorPIS = documentoGP.DocVenta.ValorPIS.ToString(); Pedido.RPS.ValorCOFINS = documentoGP.DocVenta.ValorCOFINS.ToString(); Pedido.RPS.ValorINSS = documentoGP.DocVenta.ValorINSS.ToString(); Pedido.RPS.ValorIR = documentoGP.DocVenta.ValorIR.ToString(); Pedido.RPS.ValorCSLL = documentoGP.DocVenta.ValorCSLL.ToString(); Pedido.RPS.CodigoServico = documentoGP.DocVenta.CodigoServico; Pedido.RPS.AliquotaServicos = documentoGP.DocVenta.AliquotaServicos; Pedido.RPS.ISSRetido = documentoGP.DocVenta.ISSRetido; Pedido.RPS.CPFCNPJTomador = new RPSCompleto.CPFCNP(); { Pedido.RPS.CPFCNPJTomador.CPF = documentoGP.DocVenta.CPFCNPJTomador.Replace("-", "").Replace("/", "").Replace(".", ""); } Pedido.RPS.InscricaoMunicipalTomador = documentoGP.DocVenta.InscricaoMunicipalTomador; Pedido.RPS.InscricaoEstadualTomador = documentoGP.DocVenta.InscricaoEstadualTomador; Pedido.RPS.RazaoSocialTomador = documentoGP.DocVenta.RazaoSocialTomador; Pedido.RPS.EnderecoTomador = new RPSCompleto.Endereco(); { Pedido.RPS.EnderecoTomador.TipoLogradouro = documentoGP.DocVenta.Emisor_TipoLogradouro; Pedido.RPS.EnderecoTomador.Logradouro = documentoGP.DocVenta.Emisor_Logradouro; Pedido.RPS.EnderecoTomador.NumeroEndereco = documentoGP.DocVenta.Emisor_NumeroEndereco; Pedido.RPS.EnderecoTomador.Bairro = documentoGP.DocVenta.Emisor_Bairro; Pedido.RPS.EnderecoTomador.Cidade = documentoGP.DocVenta.Emisor_Cidade; Pedido.RPS.EnderecoTomador.UF = documentoGP.DocVenta.Emisor_UF; Pedido.RPS.EnderecoTomador.CEP = documentoGP.DocVenta.Emisor_CEP.Replace("-", ""); } Pedido.RPS.EmailTomador = documentoGP.DocVenta.EmailTomador; Pedido.RPS.Discriminacao = documentoGP.DocVenta.Concepto; Pedido.RPS.ValorCargaTributaria = documentoGP.DocVenta.ValorCargaTributaria.ToString("0.00", nfi); Pedido.RPS.PercentualCargaTributaria = documentoGP.DocVenta.PercentualCargaTributaria.ToString("0.00", nfi); Pedido.RPS.FonteCargaTributaria = documentoGP.DocVenta.FonteCargaTributaria; Pedido.RPS.ValorTotalRecebido = documentoGP.DocVenta.ValorTotalRecebido.ToString("0.00", nfi); } return(Pedido); } catch (Exception ex) { throw new NotImplementedException(ex.Message); } }