Coder Social home page Coder Social logo

obter o xml autorizado about sped-cte HOT 8 CLOSED

nfephp-org avatar nfephp-org commented on July 21, 2024
obter o xml autorizado

from sped-cte.

Comments (8)

samuelbasso avatar samuelbasso commented on July 21, 2024

@maisonsakamoto olha essa funcao mas na biblioteca do NFePHP, talvez de para implementar no sped-cte também.

/**
 * sefazDistDFe
 * Serviço destinado à distribuição de informações
 * resumidas e documentos fiscais eletrônicos de interesse de um ator.
 * @param string $fonte sigla da fonte dos dados 'AN'
 *                      e para alguns casos pode ser 'RS'
 * @param string $tpAmb tiupo de ambiente
 * @param string $cnpj
 * @param integer $ultNSU ultimo numero NSU que foi consultado
 * @param integer $numNSU numero de NSU que se quer consultar
 * @param array $aRetorno array com os dados do retorno
 * @param boolean $descompactar se true irá descompactar os dados retornados,
 *        se não os dados serão retornados da forma que foram recebidos
 * @return string contento o xml retornado pela SEFAZ
 * @internal function zLoadServico (Common\Base\BaseTools)
 */
public function sefazDistDFe(
    $fonte = 'AN',
    $tpAmb = '2',
    $cnpj = '',
    $ultNSU = 0,
    $numNSU = 0,
    &$aRetorno = array()
) {
    if ($tpAmb == '') {
        $tpAmb = $this->aConfig['tpAmb'];
    }
    $siglaUF = $this->aConfig['siglaUF'];
    if ($cnpj == '') {
        $cnpj = $this->aConfig['cnpj'];
    }
    //carrega serviço
    $servico = 'NFeDistribuicaoDFe';
    $this->zLoadServico(
        'nfe',
        $servico,
        $fonte,
        $tpAmb
    );
    if ($this->urlService == '') {
        $msg = "A distribuição de documento DFe não está disponível na SEFAZ $fonte!!!";
        throw new Exception\RuntimeException($msg);
    }
    $cUF = self::zGetcUF($siglaUF);
    $ultNSU = str_pad($ultNSU, 15, '0', STR_PAD_LEFT);
    $tagNSU = "<distNSU><ultNSU>$ultNSU</ultNSU></distNSU>";
    if ($numNSU != 0) {
        $numNSU = str_pad($numNSU, 15, '0', STR_PAD_LEFT);
        $tagNSU = "<consNSU><NSU>$numNSU</NSU></consNSU>";
    }
    //monta a consulta
    $cons = "<distDFeInt xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
        . "<tpAmb>$tpAmb</tpAmb>"
        . "<cUFAutor>$cUF</cUFAutor>"
        . "<CNPJ>$cnpj</CNPJ>$tagNSU</distDFeInt>";
    //validar mensagem com xsd
    //if (! $this->validarXml($cons)) {
    //    $msg = 'Falha na validação. '.$this->error;
    //    throw new Exception\RuntimeException($msg);
    //}
    //montagem dos dados da mensagem SOAP
    $body = "<nfeDistDFeInteresse xmlns=\"$this->urlNamespace\">"
        . "<nfeDadosMsg xmlns=\"$this->urlNamespace\">$cons</nfeDadosMsg>"
        . "</nfeDistDFeInteresse>";
    //envia dados via SOAP e verifica o retorno este webservice não requer cabeçalho
    $this->urlHeader = '';
    $retorno = $this->oSoap->send(
        $this->urlService,
        $this->urlNamespace,
        $this->urlHeader,
        $body,
        $this->urlMethod
    );
    $lastMsg = $this->oSoap->lastMsg;
    $this->soapDebug = $this->oSoap->soapDebug;
    //salva mensagens
    $tipoNSU = (int) ($numNSU != 0 ? $numNSU : $ultNSU);
    $datahora = date('Ymd_His');
    $filename = "$tipoNSU-$datahora-distDFeInt.xml";
    $this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg);
    $filename = "$tipoNSU-$datahora-retDistDFeInt.xml";
    $this->zGravaFile('nfe', $tpAmb, $filename, $retorno);
    //tratar dados de retorno
    $aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno);
    return (string) $retorno;
}

from sped-cte.

maisonsakamoto avatar maisonsakamoto commented on July 21, 2024

Perfeito Samuel existe um serviço (CTeDistribuicaoDFe) que é o equivalente à esse que tu postou (NFeDistribuicaoDFe) então é possível sim, vou entrar no Desenv. agora e mando o Pull Request quando estiver funcional, obrigado !

from sped-cte.

samuelbasso avatar samuelbasso commented on July 21, 2024

@maisonsakamoto perfeito. Muito obrigado.

from sped-cte.

fhferreira avatar fhferreira commented on July 21, 2024

@maisonsakamoto chegaram a implementar o CTeDistribuicaoDFe ?

from sped-cte.

maisonsakamoto avatar maisonsakamoto commented on July 21, 2024

from sped-cte.

fhferreira avatar fhferreira commented on July 21, 2024

Eu criei o método em nosso projeto atual para que tenhamos como baixar os CTe's pelo ambiente nacional.

<UF>
        <sigla>AN</sigla>
        <homologacao>
            <CTeDistribuicaoDFe method='CTeDistribuicaoDFe' operation='CTeDistribuicaoDFe' version='3.00'>https://homologacao.cte.fazenda.gov.br/CTeDistribuicaoDFe/CTeDistribuicaoDFe.asmx</CTeDistribuicaoDFe>
        </homologacao>
        <producao>
            <CTeDistribuicaoDFe method='CTeDistribuicaoDFe' operation='CTeDistribuicaoDFe' version='3.00'>https://www1.cte.fazenda.gov.br/CTeDistribuicaoDFe/CTeDistribuicaoDFe.asmx</CTeDistribuicaoDFe>
        </producao>
    </UF>
/**
     * cteDownload
     * Solicita o download de CTes
     *
     * @param  string $chNFe
     * @param  string $tpAmb
     * @param  string $cnpj
     * @param  array  $aRetorno
     * @return string
     * @throws Exception\RuntimeException
     */
    public function cteDownload(
        $chCTe='',
        $tpAmb = '',
        $cnpj = '',
        &$aRetorno = array(),
        $ultimoNSU = 0
    ) {
        if ($tpAmb == '') {
            $tpAmb = $this->aConfig['tpAmb'];
        }
        $siglaUF = $this->aConfig['siglaUF'];
        if ($cnpj == '') {
            $cnpj = $this->aConfig['cnpj'];
        }
        //carrega serviço
        $servico = 'CTeDistribuicaoDFe';
        $this->zLoadServico(
            'cte',
            $servico,
            'AN',
            $tpAmb
        );

        if ($this->urlService == '') {
            $msg = "A distribuição de documento Cte não está disponível na SEFAZ !!!";
            throw new Exception\RuntimeException($msg);
        }
        $cUF = self::getcUF($siglaUF);

        $ultimoNSU = str_pad($ultimoNSU, 15, '0', STR_PAD_LEFT);

        $body  = "";
        $body .= "<cteDistDFeInteresse xmlns='http://www.portalfiscal.inf.br/cte/wsdl/CTeDistribuicaoDFe'>";
        $body .= "       <cteDadosMsg><distDFeInt xmlns='http://www.portalfiscal.inf.br/cte' versao='1.00'>";
        $body .= "           <tpAmb>{$tpAmb}</tpAmb>";
        $body .= "           <cUFAutor>{$cUF}</cUFAutor>";
        $body .= "           <CNPJ>{$cnpj}</CNPJ>";
        $body .= "           <distNSU><ultNSU>{$ultimoNSU}</ultNSU></distNSU>";
        $body .= "       </distDFeInt></cteDadosMsg>";
        $body .= "</cteDistDFeInteresse>";

        //envia dados via SOAP e verifica o retorno este webservice não requer cabeçalho
        $retorno = $this->oSoap->send(
            $this->urlService,
            $this->urlNamespace,
            $this->urlHeader,
            $body,
            $this->urlMethod
        );

        $lastMsg = $this->oSoap->lastMsg;
        //salva mensagens
        $filename = "$chCTe-downCTe.xml";
        $this->zGravaFile('cte', $tpAmb, $filename, $lastMsg);
        $filename = "$chCTe-retCTe.xml";
        $this->zGravaFile('cte', $tpAmb, $filename, $retorno);
        //tratar dados de retorno
        $aRetorno = Response::readReturnSefaz($servico, $retorno);
        return (string) $retorno;
    }

from sped-cte.

maisonsakamoto avatar maisonsakamoto commented on July 21, 2024

from sped-cte.

fhferreira avatar fhferreira commented on July 21, 2024

@maisonsakamoto estou recebendo CTe para uma Empresa que é de Ribeirão Preto - SP e esses CTe's vem de diversos estados, pelo que pude notar, há cte's de SP, SC, RJ, MG, BA, SC

from sped-cte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.