PHP code example of awacode / importnfe

1. Go to this page and download the library: Download awacode/importnfe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awacode / importnfe example snippets



   ml = new AwaCode\ImportNfe\Xml("uploads", "xmlnfe", "imports", "error", false); //("importados", "xmlnfe");

    //NORMALIZA O ARRAY PARA ENVIAR PARA CADASTRO
    if ($_FILES)
    {
          $nfe = $_FILES["xml"];
          for ($i = 0; $i < count($nfe["type"]); $i++)
         {
            foreach (array_keys($nfe) as $keys)
             {
                $nfeFiles[$i][$keys] = $nfe[$keys][$i];
              }
         }

         //CORRE PELO ARRAY NORMALIZADO E FAZ O UPLOAD
         foreach ($nfeFiles as $file)
         {
            $upload = $xml->upload($file);
         }

        //PEGA O ARRAY DE TODOS OS ARQUIVOS ENVIADO NA PASTA TEMPORARIA
        $post = $xml->gravaarquivo();

        // GRAVA NO BD
      if (!empty($post->items)):
        foreach ($post->items as $notas)
        {
             //VERIFICA SE JA FOI IMPORTADA ANTES
             $chnotes = $conn->prepare("SELECT * FROM tbl_notas WHERE chave = :CHAVE");
             $chnotes->bindParam(":CHAVE", $notas['chave']);
             $chnotes->execute();
             $check = $chnotes->rowCount();
        
             if ($check == 0 )
                { /* GRAVA A NOTA NA TABELA */ }
             foreach ($notas['itens'] as $iten)
                { /* GRAVA OS PRODUTOS  DA NOTA NA TABELA DE ITENS */ }
        }      
      endif;

    }