--
--
Você recebeu esta mensagem porque está inscrito no Grupo "NFePHP".
Para Postar: nfe...@googlegroups.com
Para Sair do Grupo: nfephp+unsubscribe@googlegroups.com
Link: http://groups.google.com.br/group/nfephp?hl=pt-BR
-------
Repositório: https://github.com/nfephp-org/nfephp
---
Você recebeu essa mensagem porque está inscrito em um tópico no grupo "NFePHP" dos Grupos do Google.
Para cancelar inscrição nesse tópico, acesse https://groups.google.com/d/topic/nfephp/d0-durfm3XU/unsubscribe.
Para cancelar inscrição nesse grupo e todos os seus tópicos, envie um e-mail para nfephp+unsubscribe@googlegroups.com.
Para mais opções, acesse https://groups.google.com/d/optout.
Para Sair do Grupo: nfephp+un...@googlegroups.com
Link: http://groups.google.com.br/group/nfephp?hl=pt-BR
-------
Repositório: https://github.com/nfephp-org/nfephp
---
Você recebeu essa mensagem porque está inscrito em um tópico no grupo "NFePHP" dos Grupos do Google.
Para cancelar inscrição nesse tópico, acesse https://groups.google.com/d/topic/nfephp/d0-durfm3XU/unsubscribe.
Para cancelar inscrição nesse grupo e todos os seus tópicos, envie um e-mail para nfephp+un...@googlegroups.com.
<?php
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, cachehack=".time());
header("Cache-Control: no-store, must-revalidate");
header("Cache-Control: post-check=-1, pre-check=-1", false);
#Include the connect.php file
session_start();
include ('../../conect.php');
date_default_timezone_set('America/Cuiaba');
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
clearstatcache();
function clearSpecialChars($str) {
$str=utf8_decode($str);
$clear_array = array("." => "", "-" => "", "á" => "a" , "é" => "e" , "í" => "i" , "ó" => "o" , "ú" => "u" ,
"à" => "a" , "è" => "e" , "ì" => "i" , "ò" => "o" , "ù" => "ù" ,
"ã" => "a" , "õ" => "o" , "â" => "a" , "ê" => "e" , "î" => "i" , "ô" => "o" , "û" => "u" ,
"," => "" , "!" => "" , "#" => "" , "%" => "", "¬" => "" , "{" => "" , "}" => "" ,
"^" => "" , "´" => "" , "`" => "" , "" => "" , "/" => "" , ";" => "" , ":" => "" , "?" => "" ,
"¹" => "1" , "²" => "2" , "³" => "3" , "ª" => "a" , "º" => "o" , "ç" => "c" , "ü" => "u" ,
"ä" => "a" ,"ï" => "i" , "ö" => "o" , "ë" => "e" , "$" => "s" , "ÿ" => "y" , "w" => "w" , "<" => "" ,
">" => "" ,"[" => "" , "]" => "" , "&" => "e" , " " => " " , "'" => '' , '"' => "" , '1' => '1' ,
'2' => '2' , '3' => '3' , '4' => '4' , '5' => '5' , '6' => '6' , '7' => '7' , '8' => '8' , '9' => '9' ,
'0' => '0' ,'á' => 'a' , 'Á' => 'A' , 'é' => 'e' , 'É' => 'E' , 'í' => 'i' , 'Í' => 'i' , 'ó' => 'o' ,
'Ó' => 'O' , 'ú' => 'u' , 'Ú' => 'U' , 'â' => 'â' , 'â' => 'â' , 'ê' => 'ê' , 'Ê' => 'â' ,
'ô' => 'ô' , 'Ô' => 'â' , 'à' => 'a' , 'À' => 'â' , 'ç' => 'c' , 'Ç' => 'C' , 'ã' => 'a' ,
'Ã' => 'ã' , 'õ' => 'o' , 'Õ' => 'o' );
foreach($clear_array as $key=>$val){
$str = str_replace($key, $val, $str);
}
return $str;
}
function soNumero($str) {
return preg_replace("/[^0-9]/", "", $str);
}
require_once '../../../nfephp-org/bootstrap.php';
use App\Helpers\HeaderFunctions;
use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\Common\Soap\SoapCurl;
use NFePHP\NFe\Make;
$nfe = new Make();
$sql = "Select cf.*,
cad.cad_razaosoc,
cad.cad_cpfcnpj,
cad.CAD_INSCEST,
est.est_sigla
from configura_sis cf
inner join cadastros cad on (cad.id = id_emp)
inner join estado est on (est.est_codigo = cad.est_codigo)
where id_emp = $_GET[emp]";
//echo $sql;
$res = $bd->prepare($sql);
$res->Execute();
$linha = $res->fetch(PDO::FETCH_ASSOC);
$certificado = file_get_contents($linha["CFS_CAMINHO_CERTIFICADO"].$linha["CFS_NOME_CERTIFICADO"]);
$senha = $linha["CFS_SENHA_CERTIFICADO"];
$sql = "Select * From GERANFESEFAZ(:nfe) where idnfe is not null ";
$res = $bd->Prepare($sql);
$res->bindParam(':nfe', $_GET["IDNFE"], PDO::PARAM_INT);
$res->Execute();
//echo $_GET["IDNFE"];
$lin = $res->fetch(PDO::FETCH_ASSOC);
$caminho_nfe = $lin["TBS_CAMINHO"];
$pedido = $lin["NUM_PEDIDO"];
$obs_tes = $lin["OBS_TES"];
$obs_contrato = $lin["OBS_CONTRATO"];
$pastames = Explode("-", $lin["DATA_NFE"]);
$pastames = $pastames[0].$pastames[1];
//echo $caminho_nfe;
$std = new stdClass();
$std->versao = '4.00'; //versão do layout
$std->Id = 'NFe'.$lin["CHAVE_NFE"];//se o Id de 44 digitos não for passado será gerado automaticamente
$std->pk_nItem = null; //deixe essa variavel sempre como NULL
$elem = $nfe->taginfNFe($std);
$std = new stdClass();
$std->cUF = $lin["UF_EMP_EMIT"];
$std->cNF = str_pad($lin["IDNFE"], 6, '0', STR_PAD_LEFT);
$std->natOp = clearSpecialChars($lin["DESC_OPERACAO"]);
//$std->indPag = 0; //NÃO EXISTE MAIS NA VERSÃO 4.00
$std->mod = $lin["MODELO"];
$std->serie = $lin["SERIE"];
$std->nNF = $lin["NUM_NOTA"];
$std->dhEmi = $lin["DATA_NFE"].'T'.date("H:i:sP");
$std->dhSaiEnt = $lin["DATA_NFE"].'T'.date("H:i:sP");
$std->tpNF = $lin["TIPO_NOTA"];
if (($lin["DEST_CNPJ"] == $lin["CNPJ_EMP_EMIT"]) && ($lin["REC_SIGLA"] != $lin["DEST_SIGLA"]))
{
$std->idDest = 2;
} ELSE {$std->idDest = $lin["CD_UF_DESTINAT"];}
$std->cMunFG = $lin["CID_COD_EMIT"];
$std->tpImp = $lin["TIPO_DOCUMENTO"];
$std->tpEmis = $_GET["tpEmis"];
$std->cDV = 2;
$std->tpAmb = $_GET["ambiente"];
$std->finNFe = $_GET["finalidade"];
$std->indFinal = 0;
$std->indPres = 9;
$std->procEmi = '0';
$std->verProc = '4.00';
$std->dhCont = null;
$std->xJust = null;
$elem = $nfe->tagide($std);
//referenciando notas
/*$std = new stdClass();
$std->refNFe = '35150271780456000160550010000253101000253101';
$elem = $nfe->tagrefNFe($std);*/
//Node referente a Nota Fiscal referenciada modelo 1 ou 2
/*$std = new stdClass();
$std->cUF = 35;
$std->AAMM = 1412;
$std->CNPJ = '52297850000105';
$std->mod = '01';
$std->serie = 3;
$std->nNF = 587878;
$elem = $nfe->tagrefNF($std);*/
//Node referente a Nota Fiscal referenciada de produtor rural
/*$std = new stdClass();
$std->cUF = 35;
$std->AAMM = 1502;
$std->IE = 'ISENTO';
$std->mod = '04';
$std->serie = 0;
$std->nNF = 5578;
$elem = $nfe->tagrefNFP($std);*/
//referenciando cte
/*$std = new stdClass();
$std->refCTe = '35150268252816000146570010000016161002008472';
$elem = $nfe->tagrefCTe($std);*/
//referenciamento de ecf
/*$std = new stdClass();
$std->mod = '2C';
$std->nECF = 788;
$std->nCOO = 114;
$elem = $nfe->tagrefECF($std);*/
$std = new stdClass();
$std->xNome = clearSpecialChars($linha["CAD_RAZAOSOC"]);
$std->xFant = clearSpecialChars($linha["CAD_RAZAOSOC"]);
$std->IE = clearSpecialChars($linha["CAD_INSCEST"]);
$std->IEST = null;
$std->IM = null ;
$std->CNAE = null;
$std->CRT = 3;
$std->CNPJ = clearSpecialChars($linha["CAD_CPFCNPJ"]); //indicar apenas um CNPJ ou CPF
$std->CPF = null;
$elem = $nfe->tagemit($std);
//endereco emitente
$std = new stdClass();
$std->xLgr = clearSpecialChars($lin["ENDERECO_EMP_EMIT"]);
$std->nro = clearSpecialChars($lin["NUM_END_EMIT"]);
$std->xCpl = clearSpecialChars($lin["COMP_EMIT"]);
$std->xBairro = clearSpecialChars($lin["BAIRRO_EMIT"]);
$std->cMun = clearSpecialChars($lin["CID_COD_EMIT"]);
$std->xMun = clearSpecialChars($lin["CIDADE_EMP_EMIT"]);
$std->UF = $lin["SIGLA_UF_EMIT"];
$std->CEP = clearSpecialChars($lin["CEP_EMP_EMIT"]);
$std->cPais = 1058;
$std->xPais = 'BRASIL';
$std->fone = soNumero($lin["FONE_EMIT"]);
$elem = $nfe->tagenderEmit($std);
//dados do destinatario
$std = new stdClass();
$std->xNome = clearSpecialChars($lin["DEST_RAZAOSOC"]);
$std->indIEDest = '1';
$std->IE = clearSpecialChars($lin["DEST_ID"]);;
$std->ISUF = clearSpecialChars($lin["DEST_SUFRAMA"]);
$std->IM = clearSpecialChars($lin["DEST_IM"]);;
$std->email = $lin["DEST_EMAIL"];
if ($lin["DEST_SIGLA"]<> 'EX')
{
if ($lin["DEST_TIPO_PESSOA"] == 'J') {
$std->CNPJ = clearSpecialChars($lin["DEST_CNPJ"]);
$std->CPF = Null;
$std->idEstrangeiro = Null;
}
if ($lin["DEST_TIPO_PESSOA"] == 'F')
{
$std->CNPJ = Null;
$std->CPF = clearSpecialChars($lin["DEST_CNPJ"]);
$std->idEstrangeiro = Null;
}
} else {
$std->idEstrangeiro;
$std->CNPJ = Null;
$std->CPF = Null;
}
$elem = $nfe->tagdest($std);
//endereco do destinatario
$std = new stdClass();
$std->xLgr = clearSpecialChars($lin["DEST_ENDERECO"]);
$std->nro = clearSpecialChars($lin["DEST_NUMERO"]);
$std->xCpl = clearSpecialChars($lin["DEST_COMPLEMENTO"]);
$std->xBairro = clearSpecialChars($lin["DEST_BAIRRO"]);
$std->cMun = $lin["DEST_IBGE_CID"];
$std->xMun = clearSpecialChars($lin["DEST_CIDADE"]);
$std->UF = $lin["DEST_SIGLA"];
$std->CEP = $lin["DEST_CEP"];
$std->cPais = $lin["DEST_PAIZ"];
$std->xPais = clearSpecialChars($lin["DEST_XPAIZ"]);
$std->fone = soNumero($lin["DEST_FONE"]);
$elem = $nfe->tagenderDest($std);
//LOCAL DE RETIRADA
/*
$std = new stdClass();
$std->xLgr;
$std->nro;
$std->xCpl;
$std->xBairro;
$std->cMun;
$std->xMun;
$std->UF;
$std->CNPJ; //indicar apenas um CNPJ ou CPF
$std->CPF = null;
$elem = $nfe->tagretirada($std);*/
if ($lin["DEST_CNPJ"] != $lin["REC_CPFCNPJ"])
{
//Identificação do local de Entrega (se diferente do destinatário)
$std = new stdClass();
if ($_GET["finalidade"] == 4 ){
$std->xLgr = clearSpecialChars($lin["DEST_ENDERECO"]);
$std->nro = clearSpecialChars($lin["DEST_NUMERO"]);
$std->xCpl = clearSpecialChars($lin["DEST_COMPLEMENTO"]);
$std->xBairro = clearSpecialChars($lin["DEST_BAIRRO"]);
$std->cMun = clearSpecialChars($lin["DEST_IBGE_CID"]);
$std->xMun = clearSpecialChars($lin["DEST_CIDADE"]);
$std->UF = $lin["DEST_SIGLA"];
} else {
$std->xLgr = clearSpecialChars($lin["REC_ENDRECO"]);
$std->nro = clearSpecialChars($lin["REC_NUMERO"]);
$std->xCpl = clearSpecialChars($lin["REC_COMPLEMENTO"]);
$std->xBairro = clearSpecialChars($lin["REC_BAIRRO"]);
$std->cMun = clearSpecialChars($lin["REC_CID_IBGE"]);
$std->xMun = clearSpecialChars($lin["REC_CIDADE"]);
$std->UF = $lin["REC_SIGLA"];
}
if ($lin["DEST_TIPO_PESSOA"] == 'J') {
$std->CNPJ = clearSpecialChars($lin["REC_CPFCNPJ"]);
$std->CPF = null;
}
if ($lin["DEST_TIPO_PESSOA"] == 'F') {
$CNPJ = '';
if ($_GET["finalidade"] == 4 ){
$std->CNPJ = null;
$std->CPF = clearSpecialChars($lin["DEST_CNPJ"]);
} ELSE
{$std->CPF = clearSpecialChars($lin["REC_CPFCNPJ"]);}
}
//$resp = $nfe->tagentrega($CNPJ, $CPF, $xLgr, $nro, $xCpl, $xBairro, $cMun, $xMun, $UF);
$elem = $nfe->tagentrega($std);
}
//pessoas autorizadas a acessar o xml
/*$std = new stdClass();
$std->CNPJ = '12345678901234'; //indicar um CNPJ ou CPF
$std->CPF = null;
$elem = $nfe->tagautXML($std);*/
$res->Execute();
//node responssavel por inserir os dados do produto
$record = $res->fetchAll();
$n = 0;
$VL_TOTAL = 0;
$VL_TOTAL_ICMS = 0;
$VL_TOTAL_PIS = 0;
$VL_TOTAL_IPI = 0;
$VL_TOTAL_COF = 0;
$VL_BASE_ICMS = 0;
$VL_BASE_PIS = 0;
$VL_BASE_IPI = 0;
$VL_BASE_COF = 0;
$quantidade = 0;
foreach ($record as $lin)
{
$n++;
$std = new stdClass();
$std->item = $n; //item da NFe
$std->cProd = str_pad($lin["PROD_ID"], 5, '0', STR_PAD_LEFT);
$std->cEAN = null;
$std->xProd = clearSpecialChars($lin["PROD_NOME"]);
$std->NCM = $lin["PROD_NCM"];
$std->cBenf = null; //incluido no layout 4.00
$std->EXTIPI = null;
$std->CFOP = $lin["CFOP"];
$std->uCom = $lin["PROD_UNIDADE"];
if ($lin["PROD_UNIDADE"] == 'TON')
{
$std->qCom = number_format( $lin["PROD_QUANTIDADE"]/1000, 2, '.', '');
$std->vUnCom = $lin["PROD_VALOR_UNIT"]*1000;
}
if ($lin["PROD_UNIDADE"] == 'KG')
{
$std->qCom = number_format( $lin["PROD_QUANTIDADE"], 2, '.', '');
$std->vUnCom = $lin["PROD_VALOR_UNIT"];
}
$std->vProd = number_format( $lin["PROD_VALOR_TOTAL"], 2, '.', '');
$std->cEANTrib = str_pad($lin["PROD_BARRAS"], 13, '0', STR_PAD_LEFT);
$std->uTrib = $lin["PROD_UNIDADE"];
if ($lin["PROD_UNIDADE"] == 'TON') {$std->qTrib = number_format( $lin["PROD_QUANTIDADE"]/1000, 2, '.', '');}
if ($lin["PROD_UNIDADE"] == 'KG') {$std->qTrib = number_format( $lin["PROD_QUANTIDADE"], 2, '.', '');}
//$qTrib = number_format( $lin["PROD_QUANTIDADE"], 2, '.', '');
$quantidade = $quantidade + $lin["PROD_QUANTIDADE"];
if ($lin["PROD_UNIDADE"] == 'TON') {$std->vUnTrib = $lin["PROD_VALOR_UNIT"]*1000;}
if ($lin["PROD_UNIDADE"] == 'KG') {$std->vUnTrib = $lin["PROD_VALOR_UNIT"];}
$std->vFrete = null;
$std->vSeg = null;
$std->vDesc = null;
$std->vOutro = null;
$std->indTot = '1';
$std->xPed = $lin["NUM_PEDIDO"];
$std->nItemPed = $n;
$std->nFCI = null;
$elem = $nfe->tagprod($std);
//Node de informações adicionais do produto
$std = new stdClass();
$std->item = $n; //item da NFe
$std->infAdProd = $lin["PROD_DESCRICAO"].'.';
$elem = $nfe->taginfAdProd($std);
//Node com a Nomenclatura de Valor Aduaneiro e Estatística do item da NFe
/*$std = new stdClass();
$std->item = $n; //item da NFe
$std->NVE;
$elem = $nfe->tagNVE($std);*/
//Node de detalhamento do Especificador da Substituição Tributária do item da NFe
/*$std = new stdClass();
$std->item = $n; //item da NFe
$std->CEST;
$std->indEscala; //incluido no layout 4.00
$std->CNPJFab; //incluido no layout 4.00
$elem = $nfe->tagCEST($std);*/
//node RECOPI
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->nRECOPI;
$elem = $nfe->tagRECOPI($std);
//Node com informações da Declaração de Importação do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->nDI;
$std->dDI;
$std->xLocDesemb;
$std->UFDesemb;
$std->dDesemb;
$std->tpViaTransp;
$std->vAFRMM;
$std->tpIntermedio;
$std->CNPJ;
$std->UFTerceiro;
$std->cExportador;
$elem = $nfe->tagDI($std);
//Node de Adições relativas as DI do item
$std = new stdClass();
$std->item = $n; //item da NFe
$std->nDI; //numero da DI
$std->nAdicao;
$std->nSeqAdic
$std->cFabricante
$std->vDescDI;
$std->nDraw;
$elem = $nfe->tagadi($std);*/
//Node com informações de exportação para o item
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->nRE;
$std->chNFe;
$std->qExport;
$std->nDraw;*/
//
$data = gmDate('Y-m-d');
$std = new stdClass();
$std->item = $n; //item da NFe
$std->nLote = gmdate('dmYhms');
$std->qLote = $quantidade;
$std->dFab = gmdate('d-m-Y');
$data = DateTime::createFromFormat('Y-m-d', $data);
$data->add(new DateInterval('P2Y')); // 2 dias
$data->format('d/m/Y');
$std->dVal = $data->format('Y-m-d');
$std->cAgreg = gmdate('dmYhms');
$elem = $nfe->tagRastro($std);
//Node inicial dos Tributos incidentes no Produto ou Serviço do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->vTotTrib = number_format(($lin["VL_ICMS"] + $lin["VL_PIS"] + $lin["VL_IPI"] + $lin["VL_COFINS"]), 2, '.', '') ;
$elem = $nfe->tagimposto($std);
//Node com informações do ICMS do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->orig = '0';
$std->CST = $lin["CST_ICMS"]; // Tributado Integralmente
$std->modBC = $lin["MOD_BC"];
if ($lin["PERCENT_ICMS_REDUC"] > 0)
{$std->pRedBC = 100 - $lin["PERCENT_ICMS_REDUC"];} ELSE
{$std->pRedBC = null;};
$std->vBC = number_format($lin["BASE_ICMS"], 2, '.', ''); // = $qTrib * $vUnTrib
$std->pICMS = number_format($lin["PERCENT_ICMS"], 2, '.', ''); // Alíquota do Estado de GO p/ 'NCM 2203.00.00 - Cervejas de Malte, inclusive Chope'
$std->vICMS = number_format($lin["VL_ICMS"], 2, '.', ''); // = $vBC * ( $pICMS / 100 )
$std->pFCP = null;
$std->vFCP = null;
$std->vBCFCP = null;
$std->modBCST = null;
$std->pMVAST = null;
$std->pRedBCST = null;
$std->vBCST = null;
$std->pICMSST = null;
$std->vICMSST = null;
$std->vBCFCPST = null;
$std->pFCPST = null;
$std->vFCPST = null;
$std->vICMSDeson= null;
$std->motDesICMS= null;
$std->vICMSOp = null;
$std->pDif = null;
$std->vICMSDif = null;
$std->vBCSTRet = null;
$std->pST = null;
$std->vICMSSTRet= null;
$std->vBCFCPSTRet= null;
$std->pFCPSTRet = null;
$std->vFCPSTRet = null;
$elem = $nfe->tagICMS($std);
//Node com informações da partilha do ICMS entre a UF de origem e UF de destino ou a UF definida na legislação.
/*//$std = new stdClass();
$std->item = 1; //item da NFe
$std->orig = 0;
$std->CST = '90';
$std->modBC = 0;
$std->vBC = 1000.00;
$std->pRedBC = null;
$std->pICMS = 18.00;
$std->vICMS = 180.00;
$std->modBCST = 1000.00;
$std->pMVAST = 40.00;
$std->pRedBCST = null;
$std->vBCST = 1400.00;
$std->pICMSST = 10.00;
$std->vICMSST = 140.00;
$std->pBCOp = 10.00;
$std->UFST = 'RJ';
$elem = $nfe->tagICMSPart($std);*/
//Node Repasse de ICMS ST retido anteriormente em operações interestaduais com repasses através do Substituto Tributário
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->orig = 0;
$std->CST = '60';
$std->vBCSTRet = 1000.00;
$std->vICMSSTRet = 190.00;
$std->vBCSTDest = 1000.00;
$std->vICMSSTDest = 1.00;
$elem = $nfe->tagICMSSN($std);*/
//Node referente Tributação ICMS pelo Simples Nacional do item da NFe
/*$std = new stdClass();
$std->item = $n; //item da NFe
$std->orig = 0;
$std->CSOSN = '101';
$std->pCredSN = 2.00;
$std->vCredICMSSN = 20.00;
$std->modBCST = null;
$std->pMVAST = null;
$std->pRedBCST = null;
$std->vBCST = null;
$std->pICMSST = null;
$std->vICMSST = null;
$std->vBCFCPST = null; //incluso no layout 4.00
$std->pFCPST = null; //incluso no layout 4.00
$std->vFCPST = null; //incluso no layout 4.00
$std->pCredSN = null;
$std->vCredICMSSN = null;
$std->pCredSN = null;
$std->vCredICMSSN = null;
$std->vBCSTRet = null;
$std->pST = null;
$std->vICMSSTRet = null;
$std->vBCFCPSTRet = null; //incluso no layout 4.00
$std->pFCPSTRet = null; //incluso no layout 4.00
$std->vFCPSTRet = null; //incluso no layout 4.00
$std->modBC = null;
$std->vBC = null;
$std->pRedBC = null;
$std->pICMS = null;
$std->vICMS = null;
$elem = $nfe->tagICMSSN($std);*/
//Node de informação do ICMS Interestadual do item na NFe
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->vBCUFDest = 100.00;
$std->vBCFCPUFDest = 100.00;
$std->pFCPUFDest = 1.00;
$std->pICMSUFDest = 18.00;
$std->pICMSInter = 12.00;
$std->pICMSInterPart = 80.00;
$std->vFCPUFDest = 1.00;
$std->vICMSUFDest = 14.44;
$std->vICMSFRemet = 3.56;
$elem = $nfe->tagICMSUFDest($std);*/
//Node referente ao IPI do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->clEnq = null;
$std->CNPJProd = null;
$std->cSelo = null;
$std->qSelo = null;
$std->cEnq = '999';
$std->CST = $lin["CST_IPI"];
$std->vIPI = number_format($lin["VL_IPI"], 2, '.', '');
$std->vBC = number_format($lin["BASE_IPI"], 2, '.', '');
$std->pIPI = number_format($lin["PERCENT_IPI"], 2, '.', '');
$std->qUnid = null;
$std->vUnid = null;
$elem = $nfe->tagIPI($std);
//Node Imposto de Importação do item da NFe
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->vBC = 1000.00;
$std->vDespAdu = 100.00;
$std->vII = 220.00;
$std->vIOF = null;
$elem = $nfe->tagPIS($std);*/
//Node PIS do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->CST = $lin["CST_PIS"];
$std->vBC = number_format($lin["BASE_PIS"], 2, '.', '');
$std->pPIS = number_format($lin["PERCENT_PIS"], 2, '.', '');
$std->vPIS = number_format($lin["VL_PIS"], 2, '.', '');
if ($std->CST != 49){
$std->qBCProd = number_format($lin["PROD_QUANTIDADE"], 2, '.', '');
$std->vAliqProd = number_format($lin["PERCENT_PIS"], 2, '.', '');
if ($std->CST == 72)
{
$std->qBCProd = null;
$std->vAliqProd = null;
}
}
else {
$qBCProd = null;
$vAliqProd = null;
}
$elem = $nfe->tagPIS($std);
//Node PIS Substituição Tributária do item da NFe
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->vPIS = 16.00;
$std->vBC = 1000.00
$std->pPIS = 1.60;
$std->qBCProd = null;
$std->vAliqProd = null;
$elem = $nfe->tagPISST($std);*/
//Node COFINS do item da NFe
$std = new stdClass();
$std->item = $n; //item da NFe
$std->CST = $lin["CST_COFINS"];
$std->vBC = $vBC = number_format($lin["BASE_COF"], 2, '.', '');
$std->pCOFINS = number_format($lin["PERCENT_COF"], 2, '.', '');
$std->vCOFINS = number_format($lin["VL_COFINS"], 2, '.', '');
if ($std->CST != 49){
$std->qBCProd = number_format($lin["PROD_QUANTIDADE"], 2, '.', '');
$std->vAliqProd = number_format($lin["PERCENT_PIS"], 2, '.', '');
if ($std->CST == 72)
{
$std->qBCProd = null;
$std->vAliqProd = null;
}
}
else {
$std->qBCProd = null;
$std->vAliqProd = null;
}
$elem = $nfe->tagCOFINS($std);
//Node COFINS Substituição Tributária do item da NFe
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->vCOFINS = 289.30;
$std->vBC = 2893.00;
$std->pCOFINS = 10.00;
$std->qBCProd = null;
$std->vAliqProd = null;
$elem = $nfe->tagCOFINSST($std);*/
//Node ISSQN do item da NFe
/*$std = new stdClass();
$std->item = 1; //item da NFe
$std->vBC = 1000.00;
$std->vAliq = 5.00;
$std->vISSQN = 50.00;
$std->cMunFG = '3518800'
$std->cListServ = '12.23'
$std->vDeducao = null;
$std->vOutro = null;
$std->vDescIncond = null;
$std->vDescCond = null;
$std->vISSRet = null;
$std->indISS = 2;
$std->cServico = '123';
$std->cMun = '3518800';
$std->cPais = '1058';
$std->nProcesso = null;
$std->indIncentivo = 2;
$elem = $nfe->tagISSQN($std);*/
$VL_TOTAL = $VL_TOTAL + number_format($lin["PROD_VALOR_TOTAL"], 2, '.', '');
$VL_TOTAL_ICMS = $VL_TOTAL_ICMS + number_format($lin["VL_ICMS"], 2, '.', '');
$VL_TOTAL_PIS = $VL_TOTAL_PIS + number_format($lin["VL_PIS"], 2, '.', '');
$VL_TOTAL_IPI = $VL_TOTAL_IPI + number_format($lin["VL_IPI"], 2, '.', '');
$VL_TOTAL_COF = $VL_TOTAL_COF + number_format($lin["VL_COFINS"], 2, '.', '');
$VL_BASE_ICMS = $VL_BASE_ICMS + number_format($lin["BASE_ICMS"], 2, '.', '');
$VL_BASE_PIS = $VL_BASE_PIS + number_format($lin["BASE_PIS"], 2, '.', '');
$VL_BASE_IPI = $VL_BASE_IPI + number_format($lin["BASE_IPI"], 2, '.', '');
$VL_BASE_COF = $VL_BASE_COF + number_format($lin["BASE_COF"], 2, '.', '');
}
$res->Execute();
$lin = $res->fetch(PDO::FETCH_ASSOC);
//Inicialização de váriaveis não declaradas...
$vII = isset($vII) ? $vII : 0;
$vIPI = isset($vIPI) ? $vIPI : 0;
$vIOF = isset($vIOF) ? $vIOF : 0;
$vPIS = isset($vPIS) ? $vPIS : 0;
$vCOFINS = isset($vCOFINS) ? $vCOFINS : 0;
$vICMS = isset($vICMS) ? $vICMS : 0;
$vBCST = isset($vBCST) ? $vBCST : 0;
$vST = isset($vST) ? $vST : 0;
$vISS = isset($vISS) ? $vISS : 0;
//total
$vBC = number_format($VL_BASE_ICMS, 2, '.', '');
$vICMS = number_format($VL_TOTAL_ICMS, 2, '.', '');
$vICMSDeson = '0.00';
$vBCST = '0';
$vST = '0';
$vProd = number_format($VL_TOTAL, 2, '.', '');
$vFrete = '0';
$vSeg = '0.00';
$vDesc = '0.00';
$vII = '0.00';
$vIPI = number_format($VL_TOTAL_IPI, 2, '.', '');
$vPIS = number_format($VL_TOTAL_PIS, 2, '.', '');
$vCOFINS = number_format($VL_TOTAL_COF, 2, '.', '');
$vOutro = '0.00';
$vNF = number_format($vProd-$vDesc-$vICMSDeson+$vST+$vSeg+$vFrete+$vOutro+$vII+$vIPI, 2, '.', '');
$vTotTrib = ''; //number_format($vICMS+$vST+$vII+$vIPI+$vPIS+$vCOFINS+$vIOF+$vISS, 2, '.', '');
$vISS = 0.00;
$std = new stdClass();
$std->vBC = number_format($VL_BASE_ICMS, 2, '.', '');
$std->vICMS = number_format($VL_TOTAL_ICMS, 2, '.', '');
$std->vICMSDesonv = number_format($VL_BASE_ICMS, 2, '.', '');
$std->vFCP = number_format($VL_BASE_ICMS, 2, '.', ''); //incluso no layout 4.00
$std->vBCST = 0;
$std->vST = 0;
$std->vFCPST = 0; //incluso no layout 4.00
$std->vFCPSTRet = 0; //incluso no layout 4.00
$std->vProd = number_format($VL_TOTAL, 2, '.', '');
$std->vFrete = 0;
$std->vSeg = 0;
$std->vDesc = 0;
$std->vII = 0;
$std->vIPI = number_format($VL_TOTAL_IPI, 2, '.', '');
$std->vIPIDevol = 0; //incluso no layout 4.00
$std->vPIS = number_format($VL_TOTAL_PIS, 2, '.', '');
$std->vCOFINS = number_format($VL_TOTAL_COF, 2, '.', '');
$std->vOutro = 0;
$std->vNF = number_format($std->vProd-$std->vDesc-$std->vICMSDesonv+$std->vST+$std->vSeg+$std->vFrete+$std->vOutro+$std->vII+$std->vIPI, 2, '.', '');;
$std->vTotTrib = number_format($VL_TOTAL_ICMS, 2, '.', '');
$elem = $nfe->tagICMSTot($std);
//echo $_GET["IDNFE"];
//Node de Totais referentes ao ISSQN
/*$std = new stdClass();
$std->vServ = 1000.00;
$std->vBC = 1000.00;
$std->vISS = 10.00;
$std->vPIS = 2.00;
$std->vCOFINS = 6.00;
$std->dCompet = '2017-09-12';
$std->vDeducao = 10.00;
$std->vOutro = 10.00;
$std->vDescIncond = null;
$std->vDescCond = null;
$std->vISSRet = null;
$std->cRegTrib = 5;
$elem = $nfe->tagISSQNTot($std);*/
/*$std = new stdClass();
$std->vRetPIS = 100.00;
$std->vRetCOFINS = 100.00;
$std->vRetCSLL = 100.00;
$std->vBCIRRF = 100.00;
$std->vIRRF = 100.00;
$std->vBCRetPrev = 100.00;
$std->vRetPrev = 100.00;
$elem = $nfe->tagtransp($std);*/
//Node indicativo da forma de frete
$std = new stdClass();
$std->modFrete = $lin["FRETE_POR_CONTA"];
$elem = $nfe->tagtransp($std);
//if ($lin["TIPO_FRETE"] == 'CIF'){ $resp = $nfe->tagtransporta($CNPJ, $CPF, $xNome, $IE, $xEnder, $xMun, $UF);}
//if (($lin["TIPO_FRETE"] == 'FOB') and ($lin["TRANSP_FOB"] == 1)){ $resp = $nfe->tagtransporta($CNPJ, $CPF, $xNome, $IE, $xEnder, $xMun, $UF);}
$std = new stdClass();
$std->xNome = clearSpecialChars($lin["TRANSP_NOME"]);
$std->IE = clearSpecialChars($lin["TRANSP_IE"]);
$std->xEnder = clearSpecialChars($lin["TRANSP_ENDE"]);
$std->xMun = clearSpecialChars($lin["TRANSP_CIDADE"]);
$std->UF = $lin["TRANSP_UF"];
if ($lin["TRANSP_TP_PESSOA"] == 'J')
{
$std->CNPJ = soNumero($lin["TRANSP_CNPJ"]);//só pode haver um ou CNPJ ou CPF, se um deles é especificado o outro deverá ser null
$std->CPF = Null;
}
if ($lin["TRANSP_TP_PESSOA"] == 'F')
{
$std->CNPJ = Null;//só pode haver um ou CNPJ ou CPF, se um deles é especificado o outro deverá ser null
$std->CPF = soNumero($lin["TRANSP_CNPJ"]);
}
$elem = $nfe->tagtransporta($std);
//Node para informação do veículo trator
$std = new stdClass();
$std->placa = clearSpecialChars($lin["VEI_PLACA"]);
$std->UF = $lin["VEI_UF"];
$std->RNTC = $lin["VEI_RNTRC"];
$elem = $nfe->tagveicTransp($std);
$sql = "Select
tbc.tbc_placa,
tbc.tbc_chassis,
tbc.tbc_renavam,
coalesce(tbc.tbc_uf, 'MT') as tbc_uf
from tb_carratas tbc
where tbc.vei_codigo = :vei_codigo ";
//echo $sql;
$bd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$res = $bd->prepare($sql);
$res->bindParam(':vei_codigo', $lin["VEI_CODIGO"], PDO::PARAM_INT);
try
{
if (!$res->Execute()) {echo 'Erro ao tentar criar xml';} else
{
list($erro, $erro_driver, $mensagem_driver) = $bd->errorInfo();
};
$res->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo $e->getMessage();
}
if ($lin["VEI_CODIGO"] > 0) {
while ($ln = $res->fetch(PDO::FETCH_ASSOC))
{
$std = new stdClass();
$std->placa = clearSpecialChars($lin["TBC_PLACA"]);
$std->UF = $lin["TBC_UF"];
$std->RNTC = $lin["VEI_RNTRC"];
$std->vagao = null;
$std->balsa = null;
$elem = $nfe->tagreboque($std);
}
}
if ($lin["PROD_UNIDADE"] == 'TON') {$qVol = number_format( $quantidade/1000, 0, '.', '');}
if ($lin["PROD_UNIDADE"] == 'KG') {$qVol = number_format( $quantidade, 0, '.', '');}
//Node com as informações dos volumes transportados
$std = new stdClass();
$std->item = $n; //indicativo do numero do volume
$std->qVol = $qVol;
$std->esp = 'Volume';
$std->marca = null;
$std->nVol = null;
$std->pesoL = number_format( $quantidade, 0, '.', '');
$std->pesoB = null;
$elem = $nfe->tagvol($std);
//Node com a identificação dos lacres, referentes ao volume
$std = new stdClass();
$std->item = null; //indicativo do numero do volume
$std->nLacre = null;
$elem = $nfe->taglacres($std);
$sqfat = " select
fin.fin_valor_previsto,
fin.fin_codigo
from financeiro fin where fin.ped_id = :pedido
and fin.fin_data_prevista >= current_date ";
//echo $sqfat;
$rfat = $bd->Prepare($sqfat);
$rfat->bindParam(':pedido', $pedido, PDO::PARAM_INT);
$rfat->Execute();
$fatl = $rfat->fetchAll();
if ($lin["TIPO_COMPLEMENTO"] != 2)
{
$nFat = $lin["NUM_NOTA"];
$vOrig = number_format($VL_TOTAL, 2, '.', '');
$vDesc = 0;
$vLiq = number_format(($vOrig - $vDesc), 2, '.', '');
$std = new stdClass();
$std->nFat = $lin["NUM_NOTA"];
$std->vOrig = $vOrig;
$std->vDesc = null;
$std->vLiq = $vLiq;
$elem = $nfe->tagfat($std);
$std = new stdClass();
$std->nDup = $lin["NUM_NOTA"];
$std->dVenc = $lin["DATA_VENC"];
$std->vDup = number_format($vLiq, '2', '.', '');
$elem = $nfe->tagdup($std);
/*}
if (count($fatl) > 0)
{
foreach ($fatl as $linhaf)
{
$std = new stdClass();
$std->nDup = $lin["FIN_CODIGO"];
$std->dVenc = $linhaf["FIN_DATA_PREVISTA"];
$std->vDup = number_format($linhaf["FIN_VALOR_PREVISTO"], '2', '.', '');
$elem = $nfe->tagdup($std);
}
}*/
}
//Node com o detalhamento da forma de pagamento OBRIGATÓRIO para NFCe
/*$std = new stdClass();
$std->tPag = '03';
$std->vPag = 200.00;
$std->CNPJ = '12345678901234';
$std->tBand = '01';
$std->cAut = '3333333';
$std->tpIntegra = 1; //incluso no layout 4.00
$elem = $nfe->tagdetPag($std);*/
$std = new stdClass();
$federal = number_format($VL_TOTAL_PIS+$VL_TOTAL_IPI+$VL_TOTAL_COF, 2, ',', '.');
$estadual = number_format($VL_TOTAL_ICMS+$vST, 2, ',', '.');
$municipal = number_format($vISS, 2, ',', '.');
//$totalT = number_format(($federal+$estadual+$municipal), 2, ',', '.');
$textoIBPT = "Valor Aprox. Tributos R$ - {$federal} Federal, {$estadual} Estadual e {$municipal} Municipal.";
//Informações Adicionais
//$infAdFisco = "SAIDA COM SUSPENSAO DO IPI CONFORME ART 29 DA LEI 10.637";
$std->infAdFisco = "{".$obs_tes." }";
$std->infCpl = "Contrato/Pedido N {".$pedido."} - {$textoIBPT} - {".$obs_contrato."} - {".$lin["OBS_NOTA"]. "};{" .$lin["CND"]. "} PROCON - MT Av. Historiador Rubens de Mendonca, 917 - Bairro Araes Cuiaba - MT CEP: 78.0080-00 PABX/Telefone: (65) 3613-8500 e 151" ;
$elem = $nfe->taginfAdic($std);
$std = new stdClass();
$std->xCampo = '';
$std->xTexto = '';
$elem = $nfe->tagobsFisco($std);
//Node com dados de exportação.
/*$std = new stdClass();
$std->UFSaidaPais = 'PR';
$std->xLocExporta = 'Paranagua';
$std->xLocDespacho = 'Informação do Recinto Alfandegado';
$elem = $nfe->tagexporta($std);*/
$caminho = '';
if ($_GET["ambiente"]==2){$caminho = 'homologacao';} else {$caminho = 'producao';}
$chave = $lin["CHAVE_NFE"];
$result = $nfe->montaNFe();
$xml = $nfe->getXML();
//Echo $xml;
$filename = $caminho_nfe."nfe/{$caminho}/assinadas/{$chave}-nfe.xml"; // Ambiente Windows
$configJson = file_get_contents($caminho_nfe."nfe/13191431000205/config.json");
/*$tools = new Tools($configJson, $certificate);
$tools->model('55');
$tools->assina($xml);*/
assinarXml($xml, $certificado, $senha, $filename, $configJson);
function assinarXml($xml, $certificado, $senha, $filename, $config)
{
$tools = new Tools($config, Certificate::readPfx($certificado, $senha));
$tools->model(55);
$tools->version('4.00');
$xml = $tools->signNFe($xml);
$filename = $filename; // caminho para o xml assinado
file_put_contents($filename, $xml); // coloca o $xml assinado dentro do arquivo
chmod($filename, 0777);
return $xml;
}
file_put_contents($filename, $xml);
?>
--
--
Você recebeu esta mensagem porque está inscrito no Grupo "NFePHP".
Para Postar: nfe...@googlegroups.com
Para Sair do Grupo: nfephp+unsubscribe@googlegroups.com
Link: http://groups.google.com.br/group/nfephp?hl=pt-BR
-------
Repositório: https://github.com/nfephp-org/nfephp
---
Você recebeu essa mensagem porque está inscrito em um tópico no grupo "NFePHP" dos Grupos do Google.
Para cancelar inscrição nesse tópico, acesse https://groups.google.com/d/topic/nfephp/d0-durfm3XU/unsubscribe.
Para cancelar inscrição nesse grupo e todos os seus tópicos, envie um e-mail para nfephp+unsubscribe@googlegroups.com.
Galera.. blz? tenho o mesmo tipo de problema, alguém pode me ajudar?
--
--
Você recebeu esta mensagem porque está inscrito no Grupo "NFePHP".
Para Postar: nfe...@googlegroups.com
Para Sair do Grupo: nfephp+un...@googlegroups.com
Link: http://groups.google.com.br/group/nfephp?hl=pt-BR
-------
Repositórios: https://github.com/nfephp-org
---
Você recebeu essa mensagem porque está inscrito no grupo "NFePHP" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para nfephp+un...@googlegroups.com.