@@ -29,13 +29,13 @@ |
||
| 29 | 29 | /** @var array */ |
| 30 | 30 | protected static $extensions = []; |
| 31 | 31 | |
| 32 | - /** |
|
| 32 | + /** |
|
| 33 | 33 | * @param string $uploadDir |
| 34 | 34 | * @param string $fileTypeDir |
| 35 | 35 | * @param bool $monthYearPath |
| 36 | 36 | * @example $u = new Upload("storage/uploads", "importadas"); |
| 37 | 37 | */ |
| 38 | - public function __construct(string $uploadDir, string $fileTypeDir, string $importDir, string $errorDir, bool $monthYearPath = true) |
|
| 38 | + public function __construct(string $uploadDir, string $fileTypeDir, string $importDir, string $errorDir, bool $monthYearPath = true) |
|
| 39 | 39 | { |
| 40 | 40 | $this->dir($uploadDir); |
| 41 | 41 | $this->dir("{$uploadDir}/{$importDir}"); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $nota = (object) $nota; |
| 62 | 62 | |
| 63 | 63 | while(($arquivo = $directory->read()) !== false) |
| 64 | - { |
|
| 64 | + { |
|
| 65 | 65 | if (empty($arquivo) || $arquivo == '..' || $arquivo == '.') continue; |
| 66 | 66 | |
| 67 | 67 | $lexml = $this->path .'/'. $arquivo; |
@@ -69,24 +69,24 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $environ = $xml->NFe->infNFe->ide->tpAmb; |
| 71 | 71 | |
| 72 | - if (empty($xml->protNFe->infProt->nProt)) |
|
| 73 | - { |
|
| 74 | - echo "<h4>Arquivo sem dados de Protocolo!</h4>"; |
|
| 75 | - rename($lexml,"./{$this->pathError}/$arquivo"); |
|
| 76 | - continue; |
|
| 77 | - } |
|
| 78 | - if ($environ != 1) //se diferente de 1 ( 1 = Produção 2 = Homologação ) |
|
| 79 | - { |
|
| 80 | - echo "<h4>Documento emitido em ambiente de homologação!</h4>"; |
|
| 81 | - rename($lexml,"./{$this->pathError}/$arquivo"); |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - ++$p; |
|
| 86 | - $nota->items[$p] = $this->mapa( $xml ); |
|
| 87 | - rename($lexml,"./{$this->pathImport}/$arquivo"); |
|
| 88 | - |
|
| 89 | - } |
|
| 72 | + if (empty($xml->protNFe->infProt->nProt)) |
|
| 73 | + { |
|
| 74 | + echo "<h4>Arquivo sem dados de Protocolo!</h4>"; |
|
| 75 | + rename($lexml,"./{$this->pathError}/$arquivo"); |
|
| 76 | + continue; |
|
| 77 | + } |
|
| 78 | + if ($environ != 1) //se diferente de 1 ( 1 = Produção 2 = Homologação ) |
|
| 79 | + { |
|
| 80 | + echo "<h4>Documento emitido em ambiente de homologação!</h4>"; |
|
| 81 | + rename($lexml,"./{$this->pathError}/$arquivo"); |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + ++$p; |
|
| 86 | + $nota->items[$p] = $this->mapa( $xml ); |
|
| 87 | + rename($lexml,"./{$this->pathImport}/$arquivo"); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | return $nota; |
| 92 | 92 | } |
@@ -201,95 +201,95 @@ discard block |
||
| 201 | 201 | $vOutro = $xml->NFe->infNFe->total->ICMSTot->vOutro; |
| 202 | 202 | |
| 203 | 203 | $dadosnfe = [ |
| 204 | - //IDE |
|
| 205 | - "chave" => "$chave", |
|
| 206 | - "cUF" => "$cUF", |
|
| 207 | - "cNF" => "$cNF", |
|
| 208 | - "natOp" => "$natOp", |
|
| 209 | - "indPag" => "$indPag", |
|
| 210 | - "mod" => "$mod", |
|
| 211 | - "serie" => "$serie", |
|
| 212 | - "nNF" => "$nNF", |
|
| 213 | - "dhEmi" => "$dhEmi", |
|
| 214 | - "dhSaiEnt" => "$dhSaiEnt", |
|
| 215 | - "tpNF" => "$tpNF", |
|
| 216 | - "cMunFG" => "$cMunFG", |
|
| 217 | - "tpImp" => "$tpImp", |
|
| 218 | - "tpEmis" => "$tpEmis", |
|
| 219 | - "cDV" => "$cDV", |
|
| 220 | - "finNFe" => "$finNFe", |
|
| 221 | - "procEmi" => "$procEmi", |
|
| 222 | - "verProc" => "$verProc", |
|
| 223 | - "tpAmb" => "$tpAmb", |
|
| 224 | - |
|
| 225 | - //INFPROT |
|
| 226 | - "xMotivo" => "$xMotivo", |
|
| 227 | - "nProt" => "$nProt", |
|
| 228 | - |
|
| 229 | - //EMIT |
|
| 230 | - "emit_cpf_cnpj" => "$emit_cpf_cnpj", |
|
| 231 | - "emit_xNome" => "$emit_xNome", |
|
| 232 | - "emit_xFant" => "$emit_xFant", |
|
| 233 | - "emit_ie" => "$emit_IE", |
|
| 234 | - |
|
| 235 | - //ENDEREMIT |
|
| 236 | - "emit_xLgr" => "$emit_xLgr", |
|
| 237 | - "emit_nro" => "$emit_nro", |
|
| 238 | - "emit_comp" => "$emit_comp", |
|
| 239 | - "emit_xBairro" => "$emit_xBairro", |
|
| 240 | - "emit_cMun" => "$emit_cMun", |
|
| 241 | - "emit_xMun" => "$emit_xMun", |
|
| 242 | - "emit_UF" => "$emit_UF", |
|
| 243 | - "emit_CEP" => "$emit_CEP", |
|
| 244 | - "emit_cPais" => "$emit_cPais", |
|
| 245 | - "emit_xPais" => "$emit_xPais", |
|
| 246 | - "emit_fone" => "$emit_fone", |
|
| 247 | - |
|
| 248 | - //DEST |
|
| 249 | - "dest_cpf_cnpj" => "$dest_cpf_cnpj", |
|
| 250 | - "dest_xNome" => "$dest_xNome", |
|
| 251 | - "dest_xFant" => "$dest_xFant", |
|
| 252 | - "dest_IE" => "$dest_IE", |
|
| 253 | - |
|
| 254 | - //ENDERDEST |
|
| 255 | - "dest_xLgr" => "$dest_xLgr", |
|
| 256 | - "dest_nro" => "$dest_nro", |
|
| 257 | - "dest_xBairro" => "$dest_xBairro", |
|
| 258 | - "dest_cMun" => "$dest_cMun", |
|
| 259 | - "dest_xMun" => "$dest_xMun", |
|
| 260 | - "dest_UF" => "$dest_UF", |
|
| 261 | - "dest_CEP" => "$dest_CEP", |
|
| 262 | - "dest_cPais" => "$dest_cPais", |
|
| 263 | - "dest_xPais" => "$dest_xPais", |
|
| 264 | - "dest_fone" => "$dest_fone", |
|
| 265 | - |
|
| 266 | - //TRANSP |
|
| 267 | - "transp_mod" => "$transp_mod", |
|
| 268 | - "transp_cpf_cnpj" => "$transp_cpf_cnpj", |
|
| 269 | - "transp_xNome" => "$transp_xNome", |
|
| 270 | - "transp_IE" => "$transp_IE", |
|
| 271 | - |
|
| 272 | - //VOL |
|
| 273 | - "transp_qVol" => "$transp_qVol", |
|
| 274 | - "transp_esp" => "$transp_esp", |
|
| 275 | - "transp_marca" => "$transp_marca", |
|
| 276 | - |
|
| 277 | - //VEICTRANSP |
|
| 278 | - "transp_placa" => "$transp_placa", |
|
| 279 | - "transp_UF" => "$transp_UF", |
|
| 280 | - |
|
| 281 | - //TOTAL |
|
| 282 | - "vBC" => "$vBC", |
|
| 283 | - "vICMS" => "$vICMS", |
|
| 284 | - "vBCST" => "$vBCST", |
|
| 285 | - "vST" => "$vST", |
|
| 286 | - "vProd" => "$vProd", |
|
| 287 | - "vNF" => "$vNF", |
|
| 288 | - "vFrete" => "$vFrete", |
|
| 289 | - "vSeg" => "$vSeg", |
|
| 290 | - "vDesc" => "$vDesc", |
|
| 291 | - "vIPI" => "$vIPI", |
|
| 292 | - "vOutro" => "$vOutro" |
|
| 204 | + //IDE |
|
| 205 | + "chave" => "$chave", |
|
| 206 | + "cUF" => "$cUF", |
|
| 207 | + "cNF" => "$cNF", |
|
| 208 | + "natOp" => "$natOp", |
|
| 209 | + "indPag" => "$indPag", |
|
| 210 | + "mod" => "$mod", |
|
| 211 | + "serie" => "$serie", |
|
| 212 | + "nNF" => "$nNF", |
|
| 213 | + "dhEmi" => "$dhEmi", |
|
| 214 | + "dhSaiEnt" => "$dhSaiEnt", |
|
| 215 | + "tpNF" => "$tpNF", |
|
| 216 | + "cMunFG" => "$cMunFG", |
|
| 217 | + "tpImp" => "$tpImp", |
|
| 218 | + "tpEmis" => "$tpEmis", |
|
| 219 | + "cDV" => "$cDV", |
|
| 220 | + "finNFe" => "$finNFe", |
|
| 221 | + "procEmi" => "$procEmi", |
|
| 222 | + "verProc" => "$verProc", |
|
| 223 | + "tpAmb" => "$tpAmb", |
|
| 224 | + |
|
| 225 | + //INFPROT |
|
| 226 | + "xMotivo" => "$xMotivo", |
|
| 227 | + "nProt" => "$nProt", |
|
| 228 | + |
|
| 229 | + //EMIT |
|
| 230 | + "emit_cpf_cnpj" => "$emit_cpf_cnpj", |
|
| 231 | + "emit_xNome" => "$emit_xNome", |
|
| 232 | + "emit_xFant" => "$emit_xFant", |
|
| 233 | + "emit_ie" => "$emit_IE", |
|
| 234 | + |
|
| 235 | + //ENDEREMIT |
|
| 236 | + "emit_xLgr" => "$emit_xLgr", |
|
| 237 | + "emit_nro" => "$emit_nro", |
|
| 238 | + "emit_comp" => "$emit_comp", |
|
| 239 | + "emit_xBairro" => "$emit_xBairro", |
|
| 240 | + "emit_cMun" => "$emit_cMun", |
|
| 241 | + "emit_xMun" => "$emit_xMun", |
|
| 242 | + "emit_UF" => "$emit_UF", |
|
| 243 | + "emit_CEP" => "$emit_CEP", |
|
| 244 | + "emit_cPais" => "$emit_cPais", |
|
| 245 | + "emit_xPais" => "$emit_xPais", |
|
| 246 | + "emit_fone" => "$emit_fone", |
|
| 247 | + |
|
| 248 | + //DEST |
|
| 249 | + "dest_cpf_cnpj" => "$dest_cpf_cnpj", |
|
| 250 | + "dest_xNome" => "$dest_xNome", |
|
| 251 | + "dest_xFant" => "$dest_xFant", |
|
| 252 | + "dest_IE" => "$dest_IE", |
|
| 253 | + |
|
| 254 | + //ENDERDEST |
|
| 255 | + "dest_xLgr" => "$dest_xLgr", |
|
| 256 | + "dest_nro" => "$dest_nro", |
|
| 257 | + "dest_xBairro" => "$dest_xBairro", |
|
| 258 | + "dest_cMun" => "$dest_cMun", |
|
| 259 | + "dest_xMun" => "$dest_xMun", |
|
| 260 | + "dest_UF" => "$dest_UF", |
|
| 261 | + "dest_CEP" => "$dest_CEP", |
|
| 262 | + "dest_cPais" => "$dest_cPais", |
|
| 263 | + "dest_xPais" => "$dest_xPais", |
|
| 264 | + "dest_fone" => "$dest_fone", |
|
| 265 | + |
|
| 266 | + //TRANSP |
|
| 267 | + "transp_mod" => "$transp_mod", |
|
| 268 | + "transp_cpf_cnpj" => "$transp_cpf_cnpj", |
|
| 269 | + "transp_xNome" => "$transp_xNome", |
|
| 270 | + "transp_IE" => "$transp_IE", |
|
| 271 | + |
|
| 272 | + //VOL |
|
| 273 | + "transp_qVol" => "$transp_qVol", |
|
| 274 | + "transp_esp" => "$transp_esp", |
|
| 275 | + "transp_marca" => "$transp_marca", |
|
| 276 | + |
|
| 277 | + //VEICTRANSP |
|
| 278 | + "transp_placa" => "$transp_placa", |
|
| 279 | + "transp_UF" => "$transp_UF", |
|
| 280 | + |
|
| 281 | + //TOTAL |
|
| 282 | + "vBC" => "$vBC", |
|
| 283 | + "vICMS" => "$vICMS", |
|
| 284 | + "vBCST" => "$vBCST", |
|
| 285 | + "vST" => "$vST", |
|
| 286 | + "vProd" => "$vProd", |
|
| 287 | + "vNF" => "$vNF", |
|
| 288 | + "vFrete" => "$vFrete", |
|
| 289 | + "vSeg" => "$vSeg", |
|
| 290 | + "vDesc" => "$vDesc", |
|
| 291 | + "vIPI" => "$vIPI", |
|
| 292 | + "vOutro" => "$vOutro" |
|
| 293 | 293 | ]; |
| 294 | 294 | |
| 295 | 295 | $i =0; |
@@ -13,28 +13,28 @@ discard block |
||
| 13 | 13 | //NORMALIZA O ARRAY PARA ENVIAR PARA CADASTRO |
| 14 | 14 | if ($_FILES) |
| 15 | 15 | {
|
| 16 | - $nfe = $_FILES["xml"]; |
|
| 17 | - for ($i = 0; $i < count($nfe["type"]); $i++) |
|
| 18 | - {
|
|
| 16 | + $nfe = $_FILES["xml"]; |
|
| 17 | + for ($i = 0; $i < count($nfe["type"]); $i++) |
|
| 18 | + {
|
|
| 19 | 19 | foreach (array_keys($nfe) as $keys) |
| 20 | - {
|
|
| 20 | + {
|
|
| 21 | 21 | $nfeFiles[$i][$keys] = $nfe[$keys][$i]; |
| 22 | - } |
|
| 23 | - } |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - //CORRE PELO ARRAY NORMALIZADO E FAZ O UPLOAD |
|
| 26 | - foreach ($nfeFiles as $file) |
|
| 27 | - {
|
|
| 25 | + //CORRE PELO ARRAY NORMALIZADO E FAZ O UPLOAD |
|
| 26 | + foreach ($nfeFiles as $file) |
|
| 27 | + {
|
|
| 28 | 28 | $upload = $xml->upload($file); |
| 29 | - // var_dump( $file); |
|
| 30 | - } |
|
| 29 | + // var_dump( $file); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | //PEGA O ARRAY DE TODOS OS ARQUIVOS ENVIADO NA PASTA TEMPORARIA |
| 33 | 33 | |
| 34 | 34 | $post = $xml->gravaarquivo(); |
| 35 | 35 | |
| 36 | 36 | // GRAVA NO BD |
| 37 | - if (!empty($post->items)): |
|
| 37 | + if (!empty($post->items)): |
|
| 38 | 38 | foreach ($post->items as $notas) |
| 39 | 39 | {
|
| 40 | 40 | //VERIFICA SE JA FOI IMPORTADA ANTES |
@@ -81,28 +81,28 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - foreach ($notas['itens'] as $iten) |
|
| 85 | - {
|
|
| 86 | - $stmt = $conn->prepare("INSERT INTO tbl_itens_nota (
|
|
| 84 | + foreach ($notas['itens'] as $iten) |
|
| 85 | + {
|
|
| 86 | + $stmt = $conn->prepare("INSERT INTO tbl_itens_nota (
|
|
| 87 | 87 | id_nota, codigo, nome, codigo_barra, ncm, cfop, un_medida, qtd, vl_unidade, vl_total) |
| 88 | 88 | VALUES ( |
| 89 | 89 | :IDNOTA, :CODIGO, :NOME, :BARRAS, :NCM, :CFOP, :UNM, :QTD, :VLUN, :VLTOTAL)"); |
| 90 | - $stmt->bindParam(":IDNOTA", $idNota);
|
|
| 91 | - $stmt->bindParam(":CODIGO", $iten['codigo']);
|
|
| 92 | - $stmt->bindParam(":NOME", $iten['xProd']);
|
|
| 93 | - $stmt->bindParam(":BARRAS", $iten['cean']);
|
|
| 94 | - $stmt->bindParam(":NCM", $iten['NCM']);
|
|
| 95 | - $stmt->bindParam(":CFOP", $iten['CFOP']);
|
|
| 96 | - $stmt->bindParam(":UNM", $iten['uCom']);
|
|
| 97 | - $stmt->bindParam(":QTD", $iten['indTot']);
|
|
| 98 | - $stmt->bindParam(":VLUN", $iten['vUnCom']);
|
|
| 99 | - $stmt->bindParam(":VLTOTAL", $iten['vProd']);
|
|
| 100 | - $stmt->execute(); |
|
| 101 | - } // endforeach; |
|
| 90 | + $stmt->bindParam(":IDNOTA", $idNota);
|
|
| 91 | + $stmt->bindParam(":CODIGO", $iten['codigo']);
|
|
| 92 | + $stmt->bindParam(":NOME", $iten['xProd']);
|
|
| 93 | + $stmt->bindParam(":BARRAS", $iten['cean']);
|
|
| 94 | + $stmt->bindParam(":NCM", $iten['NCM']);
|
|
| 95 | + $stmt->bindParam(":CFOP", $iten['CFOP']);
|
|
| 96 | + $stmt->bindParam(":UNM", $iten['uCom']);
|
|
| 97 | + $stmt->bindParam(":QTD", $iten['indTot']);
|
|
| 98 | + $stmt->bindParam(":VLUN", $iten['vUnCom']);
|
|
| 99 | + $stmt->bindParam(":VLTOTAL", $iten['vProd']);
|
|
| 100 | + $stmt->execute(); |
|
| 101 | + } // endforeach; |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | } |
| 105 | - endif; |
|
| 105 | + endif; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | |