NFePHP\NFe\MakeNFe::montaNFe PHP Method

montaNFe() public method

montaNFe Método de montagem do xml da NFe essa função retorna TRUE em caso de sucesso ou FALSE se houve erro O xml da NFe deve ser recuperado pela funçao getXML() ou diretamente pela propriedade publica $xml
public montaNFe ( ) : boolean
return boolean
    public function montaNFe()
    {
        if (count($this->erros) > 0) {
            return false;
        }
        //cria a tag raiz da Nfe
        $this->zTagNFe();
        //processa nfeRef e coloca as tags na tag ide
        foreach ($this->aNFref as $nfeRef) {
            $this->dom->appChild($this->ide, $nfeRef, 'Falta tag "ide"');
        }
        //monta as tags det com os detalhes dos produtos
        $this->zTagdet();
        //[2] tag ide (5 B01)
        $this->dom->appChild($this->infNFe, $this->ide, 'Falta tag "infNFe"');
        //[8] tag emit (30 C01)
        $this->dom->appChild($this->infNFe, $this->emit, 'Falta tag "infNFe"');
        //[10] tag dest (62 E01)
        $this->dom->appChild($this->infNFe, $this->dest, 'Falta tag "infNFe"');
        //[12] tag retirada (80 F01)
        $this->dom->appChild($this->infNFe, $this->retirada, 'Falta tag "infNFe"');
        //[13] tag entrega (89 G01)
        $this->dom->appChild($this->infNFe, $this->entrega, 'Falta tag "infNFe"');
        //[14] tag autXML (97a.1 G50)
        foreach ($this->aAutXML as $aut) {
            $this->dom->appChild($this->infNFe, $aut, 'Falta tag "infNFe"');
        }
        //[14a] tag det (98 H01)
        foreach ($this->aDet as $det) {
            $this->dom->appChild($this->infNFe, $det, 'Falta tag "infNFe"');
        }
        //[28a] tag total (326 W01)
        $this->dom->appChild($this->infNFe, $this->total, 'Falta tag "infNFe"');
        //[32] tag transp (356 X01)
        $this->dom->appChild($this->infNFe, $this->transp, 'Falta tag "infNFe"');
        //[39a] tag cobr (389 Y01)
        $this->dom->appChild($this->infNFe, $this->cobr, 'Falta tag "infNFe"');
        //[42] tag pag (398a YA01)
        //processa aPag e coloca as tags na tag pag
        foreach ($this->aPag as $pag) {
            $this->dom->appChild($this->infNFe, $pag, 'Falta tag "infNFe"');
        }
        //[44] tag infAdic (399 Z01)
        $this->dom->appChild($this->infNFe, $this->infAdic, 'Falta tag "infNFe"');
        //[48] tag exporta (402 ZA01)
        $this->dom->appChild($this->infNFe, $this->exporta, 'Falta tag "infNFe"');
        //[49] tag compra (405 ZB01)
        $this->dom->appChild($this->infNFe, $this->compra, 'Falta tag "infNFe"');
        //[50] tag cana (409 ZC01)
        $this->dom->appChild($this->infNFe, $this->cana, 'Falta tag "infNFe"');
        //[1] tag infNFe (1 A01)
        $this->dom->appChild($this->NFe, $this->infNFe, 'Falta tag "NFe"');
        //[0] tag NFe
        $this->dom->appChild($this->dom, $this->NFe, 'Falta DOMDocument');
        // testa da chave
        $this->zTestaChaveXML($this->dom);
        //convert DOMDocument para string
        $this->xml = $this->dom->saveXML();
        return true;
    }

Usage Example

Example #1
0
 /**
  * txt2xml
  * Converte uma ou multiplas NF em formato txt em xml
  *
  * @param  mixed $txt Path para txt, txt ou array de txt
  * @return array
  */
 public function txt2xml($txt)
 {
     $aNF = array();
     if (is_file($txt)) {
         //extrai cada linha do arquivo em um campo de matriz
         $aDados = file($txt, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT);
     } elseif (is_array($txt)) {
         //carrega a matriz
         $aDados = $txt;
     } else {
         if (strlen($txt) > 0) {
             //carrega a matriz com as linha do arquivo
             $aDados = explode("\n", $txt);
         } else {
             return $aNF;
         }
     }
     //verificar se existem mais de uma NF
     $aNotas = $this->zSliceNotas($aDados);
     foreach ($aNotas as $nota) {
         $this->zArray2xml($nota);
         //carrega os volumes, movido de yEntity
         foreach ($this->linhaX26 as $vol) {
             $this->zLinhaXVolEntity($vol);
         }
         if ($this->make->montaNFe()) {
             $aNF[] = $this->make->getXML();
         }
     }
     return $aNF;
 }
All Usage Examples Of NFePHP\NFe\MakeNFe::montaNFe