/** * tgaide * Informações de identificação da NF-e B01 pai A01 * tag NFe/infNFe/ide * @param string $cUF * @param string $cNF * @param string $natOp * @param string $indPag * @param string $mod * @param string $serie * @param string $nNF * @param string $dhEmi * @param string $dhSaiEnt * @param string $tpNF * @param string $idDest * @param string $cMunFG * @param string $tpImp * @param string $tpEmis * @param string $cDV * @param string $tpAmb * @param string $finNFe * @param string $indFinal * @param string $indPres * @param string $procEmi * @param string $verProc * @param string $dhCont * @param string $xJust * @return DOMElement */ public function tagide($cUF = '', $cNF = '', $natOp = '', $indPag = '', $mod = '', $serie = '', $nNF = '', $dhEmi = '', $dhSaiEnt = '', $tpNF = '', $idDest = '', $cMunFG = '', $tpImp = '', $tpEmis = '', $cDV = '', $tpAmb = '', $finNFe = '', $indFinal = '0', $indPres = '', $procEmi = '', $verProc = '', $dhCont = '', $xJust = '') { $this->tpAmb = $tpAmb; $identificador = 'B01 <ide> - '; $ide = $this->dom->createElement("ide"); $this->dom->addChild($ide, "cUF", $cUF, true, $identificador . "Código da UF do emitente do Documento Fiscal"); $this->dom->addChild($ide, "cNF", $cNF, true, $identificador . "Código Numérico que compõe a Chave de Acesso"); $this->dom->addChild($ide, "natOp", $natOp, true, $identificador . "Descrição da Natureza da Operaçãoo"); $this->dom->addChild($ide, "indPag", $indPag, true, $identificador . "Indicador da forma de pagamento"); $this->dom->addChild($ide, "mod", $mod, true, $identificador . "Código do Modelo do Documento Fiscal"); $this->dom->addChild($ide, "serie", $serie, true, $identificador . "Série do Documento Fiscal"); $this->dom->addChild($ide, "nNF", $nNF, true, $identificador . "Número do Documento Fiscal"); if ($dhEmi == '') { $dhEmi = DateTime::convertTimestampToSefazTime(); } $this->dom->addChild($ide, "dhEmi", $dhEmi, true, $identificador . "Data e hora de emissão do Documento Fiscal"); if ($mod == '55' && $dhSaiEnt != '') { $this->dom->addChild($ide, "dhSaiEnt", $dhSaiEnt, false, $identificador . "Data e hora de Saída ou da Entrada da Mercadoria/Produto"); } $this->dom->addChild($ide, "tpNF", $tpNF, true, $identificador . "Tipo de Operação"); $this->dom->addChild($ide, "idDest", $idDest, true, $identificador . "Identificador de local de destino da operação"); $this->dom->addChild($ide, "cMunFG", $cMunFG, true, $identificador . "Código do Município de Ocorrência do Fato Gerador"); $this->dom->addChild($ide, "tpImp", $tpImp, true, $identificador . "Formato de Impressão do DANFE"); $this->dom->addChild($ide, "tpEmis", $tpEmis, true, $identificador . "Tipo de Emissão da NF-e"); $this->dom->addChild($ide, "cDV", $cDV, true, $identificador . "Dígito Verificador da Chave de Acesso da NF-e"); $this->dom->addChild($ide, "tpAmb", $tpAmb, true, $identificador . "Identificação do Ambiente"); $this->dom->addChild($ide, "finNFe", $finNFe, true, $identificador . "Finalidade de emissão da NF-e"); $this->dom->addChild($ide, "indFinal", $indFinal, true, $identificador . "Indica operação com Consumidor final"); $this->dom->addChild($ide, "indPres", $indPres, true, $identificador . "Indicador de presença do comprador no estabelecimento comercial no momento da operação"); $this->dom->addChild($ide, "procEmi", $procEmi, true, $identificador . "Processo de emissão da NF-e"); $this->dom->addChild($ide, "verProc", $verProc, true, $identificador . "Versão do Processo de emissão da NF-e"); if ($dhCont != '' && $xJust != '') { $this->dom->addChild($ide, "dhCont", $dhCont, true, $identificador . "Data e Hora da entrada em contingência"); $this->dom->addChild($ide, "xJust", $xJust, true, $identificador . "Justificativa da entrada em contingência"); } $this->mod = $mod; $this->ide = $ide; return $ide; }
/** * sefazEPEC * Solicita autorização em contingência EPEC * TODO: terminar esse método * @param string|array $aXml * @param string $tpAmb * @param string $siglaUF * @param array $aRetorno * @return string * @throws Exception\InvalidArgumentException */ public function sefazEPEC($aXml, $tpAmb = '2', $siglaUF = 'AN', &$aRetorno = array()) { //na nfe deve estar indicado a entrada em contingencia da data hora e o motivo //caso contrario ignorar a solicitação de EPEC if (!is_array($aXml)) { $aXml[] = $aXml; //se não é um array converte } if (count($aXml) > 20) { $msg = "O limite é de 20 NFe em um lote EPEC, você está passando [" . count($aXml) . "]"; throw new Exception\InvalidArgumentException($msg); } if ($tpAmb == '') { $tpAmb = $this->aConfig['tpAmb']; } //carrega serviço $servico = 'RecepcaoEPEC'; $this->zLoadServico('nfe', $servico, $siglaUF, $tpAmb); if ($this->urlService == '') { $msg = "A recepção de EPEC não está disponível na SEFAZ !!!"; throw new Exception\RuntimeException($msg); } $aRetorno = array(); $cnpj = $this->aConfig['cnpj']; $aRet = $this->zTpEv($tpEvento); $descEvento = $aRet['desc']; $cOrgao = '91'; $tpEvento = '110140'; //EPEC $datEv = ''; $numLote = LotNumber::geraNumLote(); foreach ($aXml as $xml) { $dat = $this->zGetInfo($xml); if ($dat['dhCont'] == '' || $dat['xJust'] == '') { $msg = "Somente é possivel enviar para EPEC as notas emitidas " . "em contingência com a data/hora e justificativa da contingência."; throw new Exception\InvalidArgumentException($msg); } $sSeqEvento = str_pad('1', 2, "0", STR_PAD_LEFT); $eventId = "ID" . $tpEvento . $chNFe . $sSeqEvento; $chNFe = $dat['chave']; $dhEvento = DateTime::convertTimestampToSefazTime(); $mensagem = "<evento xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<infEvento Id=\"{$eventId}\">" . "<cOrgao>{$cOrgao}</cOrgao>" . "<tpAmb>{$tpAmb}</tpAmb>" . "<CNPJ>{$cnpj}</CNPJ>" . "<chNFe>{$chNFe}</chNFe>" . "<dhEvento>{$dhEvento}</dhEvento>" . "<tpEvento>{$tpEvento}</tpEvento>" . "<nSeqEvento>1</nSeqEvento>" . "<verEvento>{$this->urlVersion}</verEvento>" . "<detEvento versao=\"{$this->urlVersion}\">" . "<descEvento>{$descEvento}</descEvento>" . "<cOrgaoAutor>" . $dat['cOrgaoAutor'] . "</cOrgaoAutor>" . "<tpAutor>" . $dat['tpAutor'] . "</tpAutor>" . "<verAplic>{$this->verAplic}</verAplic>" . "<dhEmi>" . $dat['dhEmi'] . "</dhEmi>" . "<tpNF>" . $dat['tpNF'] . "</tpNF>" . "<IE>" . $dat['IE'] . "</IE>" . "<dest>" . "<UF>" . $dat['UF'] . "</UF> "; if ($dat['CNPJ'] != '') { $mensagem .= "<CNPJ>." . $dat['CNPJ'] . "</CNPJ>"; } elseif ($dat['CPF'] != '') { $mensagem .= "<CPF>" . $dat['CPF'] . "</CPF>"; } else { $mensagem .= "<idEstrangeiro>" . $dat['idEstrangeiro'] . "</idEstrangeiro>"; } if ($dat['IEdest'] != '') { $mensagem .= "<IE>" . $dat['IEdest'] . "</IE>"; } $mensagem .= "</dest>" . "<vNF>" . $dat['vNF'] . "</vNF>" . "<vICMS>" . $dat['vICMS'] . "</vICMS>" . "<vST>" . $dat['vST'] . "</vST>" . "</detEvento>" . "</infEvento>" . "</evento>"; //assinatura dos dados $signedMsg = $this->oCertificate->signXML($mensagem, 'infEvento'); $signedMsg = Strings::clearXml($signedMsg, true); $datEv .= $signedMsg; } $cons = "<envEvento xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<idLote>{$numLote}</idLote>" . "{$datEv}" . "</envEvento>"; //valida mensagem com xsd //no caso do evento nao tem xsd organizado, esta fragmentado //e por vezes incorreto por isso essa validação está desabilitada //if (! $this->zValidMessage($cons, 'nfe', 'envEvento', $version)) { // $msg = 'Falha na validação. '.$this->error; // throw new Exception\RuntimeException($msg); //} $body = "<nfeDadosMsg xmlns=\"{$this->urlNamespace}\">{$cons}</nfeDadosMsg>"; //envia a solicitação via SOAP $retorno = $this->oSoap->send($this->urlService, $this->urlNamespace, $this->urlHeader, $body, $this->urlMethod); $lastMsg = $this->oSoap->lastMsg; $this->soapDebug = $this->oSoap->soapDebug; //salva mensagens $filename = "{$numLote}-envEpec.xml"; $this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg); $filename = "{$numLote}-retEnvEpec.xml"; $this->zGravaFile('nfe', $tpAmb, $filename, $retorno); //tratar dados de retorno //TODO : incluir nos xml das NF o protocolo EPEC $aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno); return $retorno; }
/** * tgaide * Informações de identificação da MDFe 4 pai 1 * tag MDFe/infMDFe/ide * * @param string $cUF * @param string $tbAmb * @param string $tpEmit * @param string $mod * @param string $serie * @param string $nMDF * @param string $cMDF * @param string $cDV * @param string $modal * @param string $dhEmi * @param string $tpEmis * @param string $procEmi * @param string $verProc * @param string $ufIni * @param string $ufFim * @return DOMElement */ public function tagide($cUF = '', $tpAmb = '', $tpEmit = '', $mod = '58', $serie = '', $nMDF = '', $cMDF = '', $cDV = '', $modal = '', $dhEmi = '', $tpEmis = '', $procEmi = '', $verProc = '', $ufIni = '', $ufFim = '') { $this->tpAmb = $tpAmb; if ($dhEmi == '') { $dhEmi = DateTime::convertTimestampToSefazTime(); } $identificador = '[4] <ide> - '; $ide = $this->dom->createElement("ide"); $this->dom->addChild($ide, "cUF", $cUF, true, $identificador . "Código da UF do emitente do Documento Fiscal"); $this->dom->addChild($ide, "tpAmb", $tpAmb, true, $identificador . "Identificação do Ambiente"); $this->dom->addChild($ide, "tpEmit", $tpEmit, true, $identificador . "Indicador da tipo de emitente"); $this->dom->addChild($ide, "mod", $mod, true, $identificador . "Código do Modelo do Documento Fiscal"); $this->dom->addChild($ide, "serie", $serie, true, $identificador . "Série do Documento Fiscal"); $this->dom->addChild($ide, "nMDF", $nMDF, true, $identificador . "Número do Documento Fiscal"); $this->dom->addChild($ide, "cMDF", $cMDF, true, $identificador . "Código do numérico do MDF"); $this->dom->addChild($ide, "cDV", $cDV, true, $identificador . "Dígito Verificador da Chave de Acesso da NF-e"); $this->dom->addChild($ide, "modal", $modal, true, $identificador . "Modalidade de transporte"); $this->dom->addChild($ide, "dhEmi", $dhEmi, true, $identificador . "Data e hora de emissão do Documento Fiscal"); $this->dom->addChild($ide, "tpEmis", $tpEmis, true, $identificador . "Tipo de Emissão do Documento Fiscal"); $this->dom->addChild($ide, "procEmi", $procEmi, true, $identificador . "Processo de emissão"); $this->dom->addChild($ide, "verProc", $verProc, true, $identificador . "Versão do Processo de emissão"); $this->dom->addChild($ide, "UFIni", $ufIni, true, $identificador . "Sigla da UF do Carregamento"); $this->dom->addChild($ide, "UFFim", $ufFim, true, $identificador . "Sigla da UF do Descarregamento"); $this->mod = $mod; $this->ide = $ide; return $ide; }
public function testConvertTimestampToSefazTimeEmBranco() { $dateTime = $this->getMock('\\DateTime', array('format'), array('2015-08-01 10:11:09')); $dateTime->expects($this->once())->method('format')->with('Y-m-d H:i:sP')->will($this->returnValue('2015-08-01T10:11:09-03:00')); $this->assertEquals('2015-08-01T10:11:09-03:00', DateTime::convertTimestampToSefazTime(0, $dateTime)); }
public function testConvertTimestampToSefazTime() { DateTime::tzdBR('CE'); $seft = DateTime::convertTimestampToSefazTime($this->tstp); $this->assertEquals($seft, $this->sefTime); }