Segue a colaboração que um colega que não me lembro quem foi que compartilhou…
Favor quem estiver lendo, clique no ícone do “coração” desta postagem para que eu possa estar colaborando com outras respostas…
//IMPORTAR XML DE NOTA FISCAL
<?php function ler_xml_nfe310($arquivo,$cd_empresa,$cd_filial,$chave,$login,$cd_unidade) { //Limpa tabelas $del = "DELETE FROM temp_nfe_entradas_titulos WHERE chv_nfe = '".$chave."'"; sc_exec_sql($del); $del = "DELETE FROM temp_nfe_entradas_itens WHERE chv_nfe = '".$chave."'"; sc_exec_sql($del); $del = "DELETE FROM temp_nfe_entradas WHERE chv_nfe = '".$chave."'"; sc_exec_sql($del); //ide $usuario_inclusao = $login; $prog_inclusao = "funcao_ler_xml_nfe310"; $xml = simplexml_load_file($arquivo); // imprime os atributos do objeto criado if (empty($xml->protNFe->infProt->nProt)) { echo "Arquivo sem dados de autorização!
"; exit; } $chave = $xml->NFe->infNFe->attributes()->Id; $chave = strtr(strtoupper($chave), array("NFE" => NULL)); //============================================================================= // $cUF = $xml->NFe->infNFe->ide->cUF; //41 Código do Estado do Fator gerador $cNF = $xml->NFe->infNFe->ide->cNF; //21284519 Código número da nfe $natOp = $xml->NFe->infNFe->ide->natOp; //V E N D A Resumo da Natureza de operação $indPag = $xml->NFe->infNFe->ide->indPag; //2 0 pagamento à vista; 1 pagamento à prazo; 2 - outros $mod = $xml->NFe->infNFe->ide->mod; //55 Modelo do documento Fiscal $serie = $xml->NFe->infNFe->ide->serie; //2 $nNF = $xml->NFe->infNFe->ide->nNF; //19685 Número da Nota Fiscal $num_doc = $nNF; $dEmi = $xml->NFe->infNFe->ide->dhEmi; //2011-09-06 Data de emissão da Nota Fiscal $dEmi = substr($dEmi,0 , 10); $dt_doc = $dEmi; $dEmi = explode('-', $dEmi); $dEmi = $dEmi[2]."/".$dEmi[1]."/".$dEmi[0]; if (!empty($xml->NFe->infNFe->ide->dhSaiEnt)) { $dSaiEnt = $xml->NFe->infNFe->ide->dhSaiEnt; //2011-09-06 Data de entrada ou saida da Nota Fiscal $dSaiEnt = substr($dSaiEnt,0 , 10); $dt_e_s = $dSaiEnt; $dSaiEnt = explode('-', $dSaiEnt); $dSaiEnt = $dSaiEnt[2]."/".$dSaiEnt[1]."/".$dSaiEnt[0]; } else { $dSaiEnt = $dEmi; $dt_e_s = $dt_doc; } $tpNF = $xml->NFe->infNFe->ide->tpNF; //1 0-entrada / 1-saída $ind_oper = $tpNF; $cMunFG = $xml->NFe->infNFe->ide->cMunFG; //4106407 Código do municipio Tabela do IBGE $tpImp = $xml->NFe->infNFe->ide->tpImp; //1 $tpEmis = $xml->NFe->infNFe->ide->tpEmis; //1 $cDV = $xml->NFe->infNFe->ide->cDV; //0 $tpAmb = trim($xml->NFe->infNFe->ide->tpAmb); //1 if ($tpAmb != 1) { echo "Documento emitido em ambiente de homologação! $tpAmb
"; exit; } $finNFe = $xml->NFe->infNFe->ide->finNFe; //1 $procEmi = $xml->NFe->infNFe->ide->procEmi; //0 $verProc = $xml->NFe->infNFe->ide->verProc; //2.0.0 // $xMotivo = $xml->protNFe->infProt->xMotivo; $nProt = $xml->protNFe->infProt->nProt; // //============================================================================ // Emitente $emit_CPF = $xml->NFe->infNFe->emit->CPF; $emit_CNPJ = $xml->NFe->infNFe->emit->CNPJ; $emit_cnpj_cpf = $emit_CNPJ; if ($emit_CNPJ == '') { if ($emit_CPF != '') { $emit_cnpj_cpf = $emit_CPF; } } $emit_xnome = $xml->NFe->infNFe->emit->xNome; //VILELA, VILELA CIA. LTDA. - AG DUCCI $emit_xnome = strtr(strtoupper($emit_xnome ), array( "à" => "A", "À" => "A", "è" => "E", "È" => "E", "ì" => "I", "Ì" => "I", "ò" => "O", "Ò" => "O", "ù" => "U", "Ù" => "U", "á" => "A", "Á" => "A", "ã" => "A", "Ã" => "A", "é" => "E", "É" => "E", "í" => "I", "Í" => "I", "ó" => "O", "ó" => "O", "ú" => "U", "Ú" => "U", "â" => "A", "Â" => "A", "ê" => "E", "Ê" => "E", "î" => "I", "Î" => "I", "ô" => "O", "Ô" => "O", "û" => "U", "Û" => "U", "Ç" => "C", "ç" => "C", "º" => NULL, "#" => NULL, "&" => "E", '"' => NULL, "'" => NULL, "´" => NULL, "`" => NULL, "¨" => NULL, "*" => NULL, "|" => NULL, "," => NULL, ";" => NULL, "&" => NULL, "%" => NULL, "?" => NULL, "½" => NULL, "¿" => NULL, "Ï" => NULL, '\\' => NULL, "ª" => NULL, "/" => NULL, "$" => NULL)); $emit_xfant = $xml->NFe->infNFe->emit->xFant; //A FAZENDA - AG. DUCCI $emit_xfant = strtr(strtoupper($emit_xfant ), array( "à" => "A", "À" => "A", "è" => "E", "È" => "E", "ì" => "I", "Ì" => "I", "ò" => "O", "Ò" => "O", "ù" => "U", "Ù" => "U", "á" => "A", "Á" => "A", "ã" => "A", "Ã" => "A", "é" => "E", "É" => "E", "í" => "I", "Í" => "I", "ó" => "O", "ó" => "O", "ú" => "U", "Ú" => "U", "â" => "A", "Â" => "A", "ê" => "E", "Ê" => "E", "î" => "I", "Î" => "I", "ô" => "O", "Ô" => "O", "û" => "U", "Û" => "U", "Ç" => "C", "ç" => "C", "º" => NULL, "#" => NULL, "&" => "E", '"' => NULL, "'" => NULL, "´" => NULL, "`" => NULL, "¨" => NULL, "*" => NULL, "|" => NULL, "," => NULL, ";" => NULL, "&" => NULL, "%" => NULL, "?" => NULL, "½" => NULL, "¿" => NULL, "Ï" => NULL, "ª" => NULL, "/" => NULL, '\\' => NULL, "$" => NULL)); // $emit_xlgr = $xml->NFe->infNFe->emit->enderEmit->xLgr; //AV. AGOSTINHO DUCCI , 409 $emit_nro= $xml->NFe->infNFe->emit->enderEmit->nro; //. $emit_xbairro = $xml->NFe->infNFe->emit->enderEmit->xBairro; //PARQUE INDUSTRIAL $emit_cmun = $xml->NFe->infNFe->emit->enderEmit->cMun; //4106407 $emit_xmun = $xml->NFe->infNFe->emit->enderEmit->xMun; //CORNELIO PROCOPIO $emit_uf = $xml->NFe->infNFe->emit->enderEmit->UF; //PR //echo "".$emit_uf."
"; $emit_cep = $xml->NFe->infNFe->emit->enderEmit->CEP; //86300000 $emit_cpais = $xml->NFe->infNFe->emit->enderEmit->cPais; //1058 $emit_xpais = $xml->NFe->infNFe->emit->enderEmit->xPais; //BRASIL $emit_fone = $xml->NFe->infNFe->emit->enderEmit->fone; //4335242165 // $emit_ie = $xml->NFe->infNFe->emit->IE; //9014134104 $emit_IM = $xml->NFe->infNFe->emit->IM; //8636 $emit_cnae = $xml->NFe->infNFe->emit->CNAE; //4789099 $emit_crt = $xml->NFe->infNFe->emit->CRT; //3 // //============================================================================ //dest $dest_cnpj = $xml->NFe->infNFe->dest->CNPJ; //01153928000179 // $dest_xNome = $xml->NFe->infNFe->dest->xNome; //AGROVENETO S.A.- INDUSTRIA DE ALIMENTOS -002825 $dest_IE = $xml->NFe->infNFe->dest->IE; //253323029 //============================================================================ //totais $vl_doc = $xml->NFe->infNFe->total->ICMSTot->vNF; //Total final da nfe $ind_pagto = $indPag; $vl_desc = $xml->NFe->infNFe->total->ICMSTot->vDesc; $vl_merc = $xml->NFe->infNFe->total->ICMSTot->vProd; $vl_abat_nt = 0; $ind_frt = $xml->NFe->infNFe->transp->modFrete; $vl_frt = $xml->NFe->infNFe->total->ICMSTot->vFrete; $vl_seg = $xml->NFe->infNFe->total->ICMSTot->vSeg; $vl_out_da = $xml->NFe->infNFe->total->ICMSTot->vOutro; $vl_bc_icms = $xml->NFe->infNFe->total->ICMSTot->vBC; $vl_icms = $xml->NFe->infNFe->total->ICMSTot->vICMS; $vl_bc_icms_st = $xml->NFe->infNFe->total->ICMSTot->vBCST; $vl_icms_st = $xml->NFe->infNFe->total->ICMSTot->vST; $vl_ipi = $xml->NFe->infNFe->total->ICMSTot->vIPI; $vl_pis = $xml->NFe->infNFe->total->ICMSTot->vPIS; $vl_cofins = $xml->NFe->infNFe->total->ICMSTot->vCOFINS; $vl_pis_st = 0; $vl_cofins_st = 0; $resumo_cfop = $natOp; $dt_inclusao = date("Y-m-d"); $hora_inclusao = date("H:i:s"); $inf_fisco = NULL; if (!empty($xml->NFe->infNFe->infAdic->infAdFisco)) { $inf_fisco = $xml->NFe->infNFe->infAdic->infAdFisco; $inf_fisco = strtr(strtoupper($inf_fisco ), array( "à" => "A", "À" => "A", "è" => "E", "È" => "E", "ì" => "I", "Ì" => "I", "ò" => "O", "Ò" => "O", "ù" => "U", "Ù" => "U", "á" => "A", "Á" => "A", "ã" => "A", "Ã" => "A", "é" => "E", "É" => "E", "í" => "I", "Í" => "I", "ó" => "O", "ó" => "O", "ú" => "U", "Ú" => "U", "â" => "A", "Â" => "A", "ê" => "E", "Ê" => "E", "î" => "I", "Î" => "I", "ô" => "O", "Ô" => "O", "û" => "U", "Û" => "U", "Ç" => "C", "ç" => "C", "º" => NULL, "#" => NULL, "&" => "E", '"' => NULL, "'" => NULL, "´" => NULL, "`" => NULL, "¨" => NULL, "*" => NULL, "|" => NULL, "," => NULL, ";" => NULL, "&" => NULL, "%" => NULL, "?" => NULL, "½" => NULL, "¿" => NULL, "Ï" => NULL, "ª" => NULL, "/" => NULL, '\\' => NULL, "$" => NULL)); } $inf_comp = NULL; if (!empty($xml->NFe->infNFe->infAdic->infCpl)) { $inf_comp = $xml->NFe->infNFe->infAdic->infCpl; $inf_comp = strtr(strtoupper($inf_comp), array( "à" => "A", "À" => "A", "è" => "E", "È" => "E", "ì" => "I", "Ì" => "I", "ò" => "O", "Ò" => "O", "ù" => "U", "Ù" => "U", "á" => "A", "Á" => "A", "ã" => "A", "Ã" => "A", "é" => "E", "É" => "E", "í" => "I", "Í" => "I", "ó" => "O", "ó" => "O", "ú" => "U", "Ú" => "U", "â" => "A", "Â" => "A", "ê" => "E", "Ê" => "E", "î" => "I", "Î" => "I", "ô" => "O", "Ô" => "O", "û" => "U", "Û" => "U", "Ç" => "C", "ç" => "C", "º" => NULL, "#" => NULL, "&" => "E", '"' => NULL, "'" => NULL, "´" => NULL, "`" => NULL, "¨" => NULL, "*" => NULL, "|" => NULL, "," => NULL, ";" => NULL, "&" => NULL, "%" => NULL, "?" => NULL, "½" => NULL, "¿" => NULL, "Ï" => NULL, "ª" => NULL, "/" => NULL, '\\' => NULL, "$" => NULL)); } $protocolo_autorizacao = $nProt; $dt = $xml->protNFe->infProt->dhRecbto; $modfrete = $xml->NFe->infNFe->transp->modFrete; $transp_cnpj = $xml->NFe->infNFe->transp->transporta->CNPJ; $Placa = $xml->NFe->infNFe->transp->veicTransp->placa; $pesob = $xml->NFe->infNFe->transp->vol->pesoB; $pesol = $xml->NFe->infNFe->transp->vol->pesoL; $dt = strtr($dt, "T", " "); $dt_autorizacao = $dt; //============================================================================ //Incluir $cod_part = 0; $insert_fields = array( 'chv_nfe' => "'".$chave."'", 'cd_empresa' => "'".$cd_empresa."'", 'ind_oper' => "'".$ind_oper."'", 'cod_part' => "'".$cod_part."'", 'serie' => "'".$serie."'", 'num_doc' => "'".$num_doc."'", 'dt_doc' => "'".$dt_doc."'", 'dt_e_s' => "'".$dt_e_s."'", 'vl_doc' => "'".$vl_doc."'", 'ind_pagto' => "'".$ind_pagto."'", 'vl_desc' => "'".$vl_desc."'", 'vl_merc' => "'".$vl_merc."'", 'vl_abat_nt' => "'".$vl_abat_nt."'", 'ind_frt' => "'".$ind_frt."'", 'vl_frt' => "'".$vl_frt."'", 'vl_seg' => "'".$vl_seg."'", 'vl_out_da' => "'".$vl_out_da."'", 'vl_bc_icms' => "'".$vl_bc_icms."'", 'vl_icms' => "'".$vl_icms."'", 'vl_bc_icms_st' => "'".$vl_bc_icms_st."'", 'vl_icms_st' => "'".$vl_icms_st."'", 'vl_ipi' => "'".$vl_ipi."'", 'vl_pis' => "'".$vl_pis."'", 'vl_cofins' => "'".$vl_cofins."'", 'vl_pis_st' => "'".$vl_pis_st."'", 'vl_cofins_st' => "'".$vl_cofins_st."'", 'resumo_cfop' => "'".$resumo_cfop."'", 'dt_inclusao' => "'".$dt_inclusao."'", 'hora_inclusao' => "'".$hora_inclusao."'", 'usuario_inclusao' => "'".$usuario_inclusao."'", 'inf_fisco' => "'".$inf_fisco."'", 'inf_comp' => "'".$inf_comp."'", 'protocolo_autorizacao' => "'".$protocolo_autorizacao."'", 'dt_autorizacao' => "'".$dt_autorizacao."'", 'dt_entrada' => "'".$dt_inclusao."'", 'cd_filial' => "'".$cd_filial."'", 'cd_unidade' => "'".$cd_unidade."'", 'emit_cnpj_cpf' => "'".$emit_cnpj_cpf."'", 'emit_xnome' => "'".$emit_xnome."'", 'emit_xfant' => "'".$emit_xfant."'", 'emit_xlgr' => "'".$emit_xlgr."'", 'emit_nro' => "'".$emit_nro."'", 'emit_cnae' => "'".$emit_cnae."'", 'emit_xbairro' => "'".$emit_xbairro."'", 'emit_cmun' => "'".$emit_cmun."'", 'emit_xmun' => "'".$emit_xmun."'", 'emit_uf' => "'".$emit_uf."'", 'emit_cep' => "'".$emit_cep."'", 'emit_cpais' => "'".$emit_cpais."'", 'emit_xpais' => "'".$emit_xpais."'", 'emit_fone' => "'".$emit_fone."'", 'emit_ie' => "'".$emit_ie."'", 'emit_crt' => "'".$emit_crt."'", 'transp_cnpj' => "'".$transp_cnpj."'", 'placa' => "'".$Placa."'", 'modfrete' => "'".$modfrete."'", 'pesob' => "'".$pesob."'", 'pesol' => "'".$pesol."'", ); $insert_table = 'temp_nfe_entradas'; // Insert record $insert_sql = 'INSERT INTO ' . $insert_table . ' (' . implode(', ', array_keys($insert_fields)) . ')' . ' VALUES (' . implode(', ', array_values($insert_fields)) . ')'; sc_exec_sql($insert_sql); //============================================================================ //titulos if (!empty($xml->NFe->infNFe->cobr->dup)) { $id = 0; foreach($xml->NFe->infNFe->cobr->dup as $dup) { $id++; $fatura = $dup->nDup; $parcela_numero = $id; $vencimento = $dup->dVenc; $vlr_parcela = $dup->vDup; // echo "$fatura|$parcela_numero|$vencimento|$vlr_parcela"; $sql_titulos = "INSERT INTO temp_nfe_entradas_titulos (chv_nfe, fatura, parcela_numero, vencimento, vlr_parcela, vencimento_dig, vlr_parcela_dig, excluido) VALUES ('".$chave."', '".$fatura."', '".$parcela_numero."', '".$vencimento."', '".$vlr_parcela."', '".$vencimento."', '".$vlr_parcela."', 'N')"; sc_exec_sql($sql_titulos); } } //============================================================================ //produtos $seq = 0; foreach($xml->NFe->infNFe->det as $item) { $seq++; $codigo = $item->prod->cProd; $xProd = $item->prod->xProd; $xProd = utf8_decode($xProd); $xProd = strtr(strtoupper($xProd ), array( "à" => "A", "À" => "A", "è" => "E", "È" => "E", "ì" => "I", "Ì" => "I", "ò" => "O", "Ò" => "O", "ù" => "U", "Ù" => "U", "á" => "A", "Á" => "A", "ã" => "A", "Ã" => "A", "é" => "E", "É" => "E", "í" => "I", "Í" => "I", "ó" => "O", "ó" => "O", "ú" => "U", "Ú" => "U", "â" => "A", "Â" => "A", "ê" => "E", "Ê" => "E", "î" => "I", "Î" => "I", "ô" => "O", "Ô" => "O", "û" => "U", "Û" => "U", "Ç" => "C", "ç" => "C", "º" => NULL, "#" => NULL, "&" => "E", '"' => NULL, "'" => NULL, "´" => NULL, "`" => NULL, "¨" => NULL, "*" => NULL, "|" => NULL, "," => NULL, ";" => NULL, "&" => NULL, "%" => NULL, "?" => NULL, "½" => NULL, "¿" => NULL, "Ï" => NULL, "ª" => NULL, "/" => NULL, "$" => NULL)); // echo "
$seq|$xProd"; $NCM = $item->prod->NCM; $ean = NULL; if (!empty($item->prod->cEAN)) $ean = $item->prod->cEAN; $CFOP = $item->prod->CFOP; $uCom = $item->prod->uCom; $qCom = $item->prod->qCom; $vUnCom = $item->prod->vUnCom; $vProd = $item->prod->vProd; $xPed = NULL; $nItemPed = NULL; if (isset($item->prod->xPed)) { $xPed = $item->prod->xPed; } if (isset($item->prod->nItemPed)) { $nItemPed = $item->prod->nItemPed; } $vDesc = 0; $despesa_acessoria = 0; if (!empty($item->prod->vDesc)) { $vDesc = $item->prod->vDesc; } if (!empty($item->prod->vOutro)) { $despesa_acessoria = $despesa_acessoria + $item->prod->vOutro; } $vBC_item = $item->imposto->ICMS->ICMS00->vBC; $icms00 = $item->imposto->ICMS->ICMS00; $icms10 = $item->imposto->ICMS->ICMS10; $icms20 = $item->imposto->ICMS->ICMS20; $icms30 = $item->imposto->ICMS->ICMS30; $icms40 = $item->imposto->ICMS->ICMS40; $icms50 = $item->imposto->ICMS->ICMS50; $icms51 = $item->imposto->ICMS->ICMS51; $icms60 = $item->imposto->ICMS->ICMS60; $icms70 = $item->imposto->ICMS->ICMS70; $cst_pis_cofins = ''; $bc_pis_cofins = 0; $aliq_cofins = 0; $vlr_cofins = 0; $aliq_pis = 0; $vlr_pis = 0; $bc_icms = '0'; $pICMS = '0'; $vlr_icms = '0'; $cst_icms = 'NN'; $vl_bc_icms_st = 0; $aliq_st = 0; $vl_icms_st = 0; $predbc = 0; $predbcst = 0; $pmvast = 0; $orig = 0; if (!empty($icms00)) { $bc_icms = $item->imposto->ICMS->ICMS00->vBC; $orig = $item->imposto->ICMS->ICMS00->orig; $pICMS = $item->imposto->ICMS->ICMS00->pICMS; $pICMS = round($pICMS,0); $vlr_icms = $item->imposto->ICMS->ICMS00->vICMS; $cst_icms = "00"; } if(!empty($icms10)) { $orig = $item->imposto->ICMS->ICMS10->orig; $bc_icms = $item->imposto->ICMS->ICMS10->vBC; $pICMS = $item->imposto->ICMS->ICMS10->pICMS; $pICMS = round($pICMS,0); $vlr_icms = $item->imposto->ICMS->ICMS10->vICMS; $cst_icms = "10"; $pmvast = $item->imposto->ICMS->ICMS10->pMVAST; $vl_bc_icms_st = $item->imposto->ICMS->ICMS10->vBCST; $aliq_st = $item->imposto->ICMS->ICMS10->pICMSST; $vl_icms_st = $item->imposto->ICMS->ICMS10->vICMSST; $predbc = $item->imposto->ICMS->ICMS10->pRedBC; $predbcst = $item->imposto->ICMS->ICMS10->pRedBCST; } if (!empty($icms20)) { $bc_icms = $item->imposto->ICMS->ICMS20->vBC; $orig = $item->imposto->ICMS->ICMS20->orig; $pICMS = $item->imposto->ICMS->ICMS20->pICMS; $pICMS = round($pICMS,0); $vlr_icms = $item->imposto->ICMS->ICMS20->vICMS; $cst_icms = "20"; } if(!empty($icms30)) { $bc_icms = "0.00"; $pICMS = "0 "; $vlr_icms = "0.00"; $cst_icms = "30"; $orig = $item->imposto->ICMS->ICMS30->orig; $pmvast = $item->imposto->ICMS->ICMS30->pMVAST; $vl_bc_icms_st = $item->imposto->ICMS->ICMS30->vBCST; $aliq_st = $item->imposto->ICMS->ICMS30->pICMSST; $vl_icms_st = $item->imposto->ICMS->ICMS30->vICMSST; //$predbc = $item->imposto->ICMS->ICMS30->pRedBC; //$predbcst = $item->imposto->ICMS->ICMS30->pRedBCST; } if(!empty($icms40)) { $bc_icms = "0.00"; $pICMS = "0 "; $vlr_icms = "0.00"; $cst_icms = "40"; $orig = $item->imposto->ICMS->ICMS40->orig; } if(!empty($icms50)) { $bc_icms = "0.00"; $pICMS = "0 "; $vlr_icms = "0.00"; $cst_icms = "50"; $orig = $item->imposto->ICMS->ICMS50->orig; } if(!empty($icms51)) { $bc_icms = $item->imposto->ICMS->ICMS51->vBC; $orig = $item->imposto->ICMS->ICMS51->orig; $pICMS = $item->imposto->ICMS->ICMS51->pICMS; $pICMS = round($pICMS,0); $vlr_icms = $item->imposto->ICMS->ICMS51->vICMS; $cst_icms = "51"; } if(!empty($icms60)) { $bc_icms = "0.00"; $pICMS = "0 "; $vlr_icms = "0.00"; $cst_icms = "60"; $orig = $item->imposto->ICMS->ICMS60->orig; } //================================================================ if(!empty($icms70)) { $bc_icms = $item->imposto->ICMS->ICMS70->vBC; $orig = $item->imposto->ICMS->ICMS70->orig; $pICMS = $item->imposto->ICMS->ICMS70->pICMS; $pICMS = round($pICMS,0); $vlr_icms = $item->imposto->ICMS->ICMS70->vICMS; $cst_icms = "70"; $pmvast = $item->imposto->ICMS->ICMS70->pMVAST; $vl_bc_icms_st = $item->imposto->ICMS->ICMS70->vBCST; $aliq_st = $item->imposto->ICMS->ICMS70->pICMSST; $vl_icms_st = $item->imposto->ICMS->ICMS70->vICMSST; $predbc = $item->imposto->ICMS->ICMS70->pRedBC; $predbcst = $item->imposto->ICMS->ICMS70->pRedBCST; } //================================================================ $IPITrib = $item->imposto->IPI->IPITrib; $cod_enq = "999"; $ibc_ipi = 0; $ialiq_ipi = 0; $ivl_ipi = 0; if (!empty($IPITrib)) { $ibc_ipi = $item->imposto->IPI->IPITrib->vBC; $ialiq_ipi = $item->imposto->IPI->IPITrib->pIPI; $ialiq_ipi = round($ialiq_ipi,0); $ivl_ipi = $item->imposto->IPI->IPITrib->vIPI; } if (!empty($item->imposto->IPI->IPINT)) { $IPINT = $item->imposto->IPI->IPINT; $ibc_ipi = 0; $ialiq_ipi = 0; $ivl_ipi = 0; } //Pis if (!empty($item->imposto->PIS->PISNT)) { $cst_pis_cofins = $item->imposto->PIS->PISNT->CST; $bc_pis_cofins = 0; $aliq_pis = 0; $vlr_pis = 0; $aliq_cofins = 0; $vlr_cofins = 0; } if (!empty($item->imposto->PIS->PISAliq)) { $cst_pis_cofins = $item->imposto->PIS->PISAliq->CST; $bc_pis_cofins = $item->imposto->PIS->PISAliq->vBC; $aliq_pis = $item->imposto->PIS->PISAliq->pPIS; $vlr_pis = $item->imposto->PIS->PISAliq->vPIS; $aliq_cofins = $item->imposto->COFINS->COFINSAliq->pCOFINS; $vlr_cofins = $item->imposto->COFINS->COFINSAliq->vCOFINS; } //Declara as variaveis para inclusão. $num_item = $seq; $cod_item = $codigo; $descricao_produto = $xProd; $ncm = $NCM; $ean = $ean; $qtd = $qCom; $unid = $uCom; $vlr_unit = $vUnCom; $vl_item = $vProd; $vl_desc = $vDesc; $cst_icms = $cst_icms; $cfop = $item->prod->CFOP; $vl_bc_icms = $bc_icms; $aliq_icms = $pICMS; $vl_icms = $vlr_icms; $cst_ipi = 0; $cst_pis = $cst_pis_cofins; $vl_bc_pis = $bc_pis_cofins; $aliq_pis = $aliq_pis; $vl_pis = $vlr_pis; $cst_cofins = $cst_pis_cofins; $vl_bc_cofins = $bc_pis_cofins; $aliq_cofins = $aliq_cofins; $vl_cofins = $vlr_cofins; $dt_inclusao = date("Y-m-d"); $hora_inclusao = date("H:i:s"); $vfrete = 0; if (!empty($item->prod->vFrete)) { $vfrete = $item->prod->vFrete; } $vseg = 0; if (!empty($item->prod->vseg)) { $vseg = $item->prod->vseg; } $estoque = "Y"; $sql_itens = "INSERT INTO temp_nfe_entradas_itens ( cd_empresa, chv_nfe, num_item, cod_item, descricao_produto, ncm, ean, qtd, unid, vlr_unit, vl_item, vl_desc, cst_icms, cfop, vl_bc_icms, aliq_icms, vl_icms, cst_ipi, cod_enq, vl_bc_ipi, aliq_ipi, vl_ipi, cst_pis, vl_bc_pis, aliq_pis, vl_pis, cst_cofins, vl_bc_cofins, aliq_cofins, vl_cofins, dt_inclusao, hora_inclusao, vfrete, vseg, cd_filiaL, cd_unidade, vl_bc_icms_st, aliq_st, vl_icms_st, predbc, predbcst, pmvast, despesa_acessoria, estoque, orig, cd_oc, nItemPed) VALUES ( '".$cd_empresa."', '".$chave."', '".$num_item."', '".$cod_item."', '".$descricao_produto."', '".$ncm."', '".$ean."', '".$qtd."', '".$unid."', '".$vlr_unit."', '".$vl_item."', '".$vl_desc."', '".$cst_icms."', '".$cfop."', '".$vl_bc_icms."', '".$aliq_icms."', '".$vl_icms."', '".$cst_ipi."', '".$cod_enq."', '".$ibc_ipi."', '".$ialiq_ipi."', '".$ivl_ipi ."', '".$cst_pis."', '".$vl_bc_pis."', '".$aliq_pis."', '".$vl_pis."', '".$cst_cofins."', '".$vl_bc_cofins."', '".$aliq_cofins."', '".$vl_cofins."', '".$dt_inclusao."', '".$hora_inclusao."', '".$vfrete."', '".$vseg."', '".$cd_filial."', '".$cd_unidade."', '".$vl_bc_icms_st."', '".$aliq_st."', '".$vl_icms_st."', '".$predbc."', '".$predbcst."', '".$pmvast."', '".$despesa_acessoria."', '".$estoque."', '".$orig."', '".$xPed."', '".$nItemPed."' )"; sc_exec_sql($sql_itens); //============================================================================ } } ?>