Esempio n. 1
0
        private void CarregaItensEventoCartaCorrecao(belPesquisaCCe objbelPesquisa)
        {
            try
            {
                if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                {
                    objEnvEvento        = new belEnvEvento();
                    objEnvEvento.versao = this._VERSAO;
                    objEnvEvento.id     = objbelPesquisa.CD_NRLANC;
                    belEvento objEvento = new belEvento();
                    objEvento.versao              = _VERSAO;
                    objEvento.infEvento           = new _infEvento();
                    objEvento.infEvento.CNPJ      = objbelPesquisa.CNPJ;
                    objEvento.infEvento.CPF       = objbelPesquisa.CPF;
                    objEvento.infEvento.dhEvento  = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
                    objEvento.infEvento.verEvento = _VERSAO;
                    objEvento.infEvento.tpAmb     = Acesso.TP_AMB;
                    objEvento.infEvento.chNFe     = objbelPesquisa.CHNFE;
                    objEvento.infEvento.cOrgao    = Acesso.cUF.ToString();
                    objEvento.infEvento.detEvento = new _detEvento
                    {
                        versao = _VERSAO
                    };
                    objEvento.infEvento.detEvento.xCorrecao = BuscaCorrecoes(objbelPesquisa.CD_NRLANC);
                    objEvento.infEvento.nSeqEvento          = objbelPesquisa.QT_ENVIO + 1;
                    objEvento.idLote = "ID" + objEvento.infEvento.tpEvento + objEvento.infEvento.chNFe + objEvento.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    objEnvEvento.evento.Add(objEvento);
                }
                else
                {
                    objEvCCeCTe = new TEvento();

                    objEvCCeCTe.versao               = Acesso.versaoCTe;
                    objEvCCeCTe.infEvento            = new  TEventoInfEvento();
                    objEvCCeCTe.infEvento.tpEvento   = "110110";
                    objEvCCeCTe.infEvento.nSeqEvento = (objbelPesquisa.QT_ENVIO + 1).ToString();// numero de evento
                    objEvCCeCTe.infEvento.Id         = "ID" + objEvCCeCTe.infEvento.tpEvento + objlItensPesquisa.FirstOrDefault().CHNFE + objEvCCeCTe.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    //objEvCCeCTe.infEvento.Id = "ID" + objlItensPesquisa.FirstOrDefault().CHNFE;
                    objEvCCeCTe.infEvento.cOrgao    = Convert.ToByte(Acesso.cUF);
                    objEvCCeCTe.infEvento.tpAmb     = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                    objEvCCeCTe.infEvento.CNPJ      = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                    objEvCCeCTe.infEvento.chCTe     = objbelPesquisa.CHNFE;
                    objEvCCeCTe.infEvento.dhEvento  = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                    objEvCCeCTe.infEvento.detEvento = new TEventoInfEventoDetEvento();
                    objEvCCeCTe.infEvento.detEvento.versaoEvento = Acesso.versaoCTe;

                    evCCeCTe objEvCanc = new evCCeCTe();
                    objEvCanc.descEvento  = evCCeCTeDescEvento.CartadeCorrecao;
                    objEvCanc.infCorrecao = new List <evCCeCTeInfCorrecao>();
                    objEvCanc.CD_NRLANC   = objbelPesquisa.CD_NRLANC;
                    foreach (DataRow item in BuscaCorrecoesCTe(objbelPesquisa.CD_NRLANC).Rows)
                    {
                        objEvCanc.infCorrecao.Add(new evCCeCTeInfCorrecao
                        {
                            grupoAlterado   = item["grupoAlterado"].ToString(),
                            campoAlterado   = item["campoAlterado"].ToString(),
                            valorAlterado   = item["valorAlterado"].ToString(),
                            nroItemAlterado = item["nroItemAlterado"].ToString(),
                        });
                    }
                    objEvCanc.xCondUso = evCCeCTeXCondUso.ACartadeCorreçãoédisciplinadapeloArt58BdoCONVÊNIOSINIEF0689FicapermitidaautilizaçãodecartadecorreçãopararegularizaçãodeerroocorridonaemissãodedocumentosfiscaisrelativosàprestaçãodeserviçodetransportedesdequeoerronãoestejarelacionadocomIasvariáveisquedeterminamovalordoimpostotaiscomobasedecálculoalíquotadiferençadepreçoquantidadevalordaprestaçãoIIacorreçãodedadoscadastraisqueimpliquemudançadoemitentetomadorremetenteoudodestinatárioIIIadatadeemissãooudesaída;
                    string xFile = Pastas.CCe + "\\" + objEvCanc.CD_NRLANC + "_prevalida.xml";
                    SerializeClassToXml.SerializeClasse <evCCeCTe>(objEvCanc, xFile);
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xFile);
                    objEvCCeCTe.infEvento.detEvento.Any = (System.Xml.XmlElement)xml.DocumentElement;


                    XmlSerializer xs      = new XmlSerializer(typeof(TEvento));
                    MemoryStream  memory  = new MemoryStream();
                    XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
                    xs.Serialize(xmltext, objEvCCeCTe);
                    UTF8Encoding encoding = new UTF8Encoding();
                    this.sXMLfinal = encoding.GetString(memory.ToArray());
                    this.sXMLfinal = this.sXMLfinal.Substring(1);

                    belAssinaXml Assinatura = new belAssinaXml();
                    this.sXMLfinal = Assinatura.ConfigurarArquivo(this.sXMLfinal, "infEvento", Acesso.cert_CTe);

                    xml = new XmlDocument();
                    xml.LoadXml(this.sXMLfinal);
                    string sPath = Pastas.PROTOCOLOS + "\\" + objbelPesquisa.CHNFE + "_ped-cce.xml";
                    if (File.Exists(sPath))
                    {
                        File.Delete(sPath);
                    }
                    xml.Save(sPath);
                    try
                    {
                        belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        private void CarregaItensEventoCartaCorrecao(belPesquisaCCe objbelPesquisa)
        {
            try
            {
                if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                {
                    objEnvEvento = new belEnvEvento();
                    objEnvEvento.versao = this._VERSAO;
                    objEnvEvento.id = objbelPesquisa.CD_NRLANC;
                    belEvento objEvento = new belEvento();
                    objEvento.versao = _VERSAO;
                    objEvento.infEvento = new _infEvento();
                    objEvento.infEvento.CNPJ = objbelPesquisa.CNPJ;
                    objEvento.infEvento.CPF = objbelPesquisa.CPF;
                    objEvento.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
                    objEvento.infEvento.verEvento = _VERSAO;
                    objEvento.infEvento.tpAmb = Acesso.TP_AMB;
                    objEvento.infEvento.chNFe = objbelPesquisa.CHNFE;
                    objEvento.infEvento.cOrgao = Acesso.cUF.ToString();
                    objEvento.infEvento.detEvento = new _detEvento
                    {
                        versao = _VERSAO
                    };
                    objEvento.infEvento.detEvento.xCorrecao = BuscaCorrecoes(objbelPesquisa.CD_NRLANC);
                    objEvento.infEvento.nSeqEvento = objbelPesquisa.QT_ENVIO + 1;
                    objEvento.idLote = "ID" + objEvento.infEvento.tpEvento + objEvento.infEvento.chNFe + objEvento.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    objEnvEvento.evento.Add(objEvento);
                }
                else
                {

                    objEvCCeCTe = new TEvento();

                    objEvCCeCTe.versao = Acesso.versaoCTe;
                    objEvCCeCTe.infEvento = new  TEventoInfEvento();
                    objEvCCeCTe.infEvento.tpEvento = "110110";
                    objEvCCeCTe.infEvento.nSeqEvento = (objbelPesquisa.QT_ENVIO + 1).ToString();// numero de evento
                    objEvCCeCTe.infEvento.Id = "ID" + objEvCCeCTe.infEvento.tpEvento + objlItensPesquisa.FirstOrDefault().CHNFE + objEvCCeCTe.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    //objEvCCeCTe.infEvento.Id = "ID" + objlItensPesquisa.FirstOrDefault().CHNFE;                   
                    objEvCCeCTe.infEvento.cOrgao = Convert.ToByte(Acesso.cUF);
                    objEvCCeCTe.infEvento.tpAmb = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                    objEvCCeCTe.infEvento.CNPJ = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                    objEvCCeCTe.infEvento.chCTe = objbelPesquisa.CHNFE;
                    objEvCCeCTe.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                    objEvCCeCTe.infEvento.detEvento = new TEventoInfEventoDetEvento();
                    objEvCCeCTe.infEvento.detEvento.versaoEvento = Acesso.versaoCTe;

                    evCCeCTe objEvCanc = new evCCeCTe();
                    objEvCanc.descEvento = evCCeCTeDescEvento.CartadeCorrecao;
                    objEvCanc.infCorrecao = new List<evCCeCTeInfCorrecao>();
                    objEvCanc.CD_NRLANC = objbelPesquisa.CD_NRLANC;
                    foreach (DataRow item in BuscaCorrecoesCTe(objbelPesquisa.CD_NRLANC).Rows)
                    {
                        objEvCanc.infCorrecao.Add(new evCCeCTeInfCorrecao
                        {
                            grupoAlterado = item["grupoAlterado"].ToString(),
                            campoAlterado = item["campoAlterado"].ToString(),
                            valorAlterado = item["valorAlterado"].ToString(),
                            nroItemAlterado = item["nroItemAlterado"].ToString(),
                        });
                    }
                    objEvCanc.xCondUso = evCCeCTeXCondUso.ACartadeCorreçãoédisciplinadapeloArt58BdoCONVÊNIOSINIEF0689FicapermitidaautilizaçãodecartadecorreçãopararegularizaçãodeerroocorridonaemissãodedocumentosfiscaisrelativosàprestaçãodeserviçodetransportedesdequeoerronãoestejarelacionadocomIasvariáveisquedeterminamovalordoimpostotaiscomobasedecálculoalíquotadiferençadepreçoquantidadevalordaprestaçãoIIacorreçãodedadoscadastraisqueimpliquemudançadoemitentetomadorremetenteoudodestinatárioIIIadatadeemissãooudesaída;
                    string xFile = Pastas.CCe + "\\" + objEvCanc.CD_NRLANC + "_prevalida.xml";
                    SerializeClassToXml.SerializeClasse<evCCeCTe>(objEvCanc, xFile);
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xFile);
                    objEvCCeCTe.infEvento.detEvento.Any = (System.Xml.XmlElement)xml.DocumentElement;


                    XmlSerializer xs = new XmlSerializer(typeof(TEvento));
                    MemoryStream memory = new MemoryStream();
                    XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
                    xs.Serialize(xmltext, objEvCCeCTe);
                    UTF8Encoding encoding = new UTF8Encoding();
                    this.sXMLfinal = encoding.GetString(memory.ToArray());
                    this.sXMLfinal = this.sXMLfinal.Substring(1);

                    belAssinaXml Assinatura = new belAssinaXml();
                    this.sXMLfinal = Assinatura.ConfigurarArquivo(this.sXMLfinal, "infEvento", Acesso.cert_CTe);

                    xml = new XmlDocument();
                    xml.LoadXml(this.sXMLfinal);
                    string sPath = Pastas.PROTOCOLOS + "\\" + objbelPesquisa.CHNFE + "_ped-cce.xml";
                    if (File.Exists(sPath))
                    {
                        File.Delete(sPath);
                    }
                    xml.Save(sPath);
                    try
                    {
                        belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }