/** * Make consumidor block * @param DomDocumentNFePHP $dest * @return string */ protected function consumidor($dest) { //DADOS DO CONSUMIDOR if (!isset($dest)) { return ''; } $enderDest = $dest->getElementsByTagName("enderDest")->item(0); $consNome = $this->pSimpleGetValue($dest, "xNome"); $consFone = $this->pSimpleGetValue($enderDest, "fone"); $foneLen = strlen($consFone); if ($foneLen > 0) { $fone2 = substr($consFone, 0, $foneLen - 4); $fone1 = substr($consFone, 0, $foneLen - 8); $consFone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($consFone, -4); } else { $consFone = ''; } $consLgr = $this->pSimpleGetValue($enderDest, "xLgr"); $consNro = $this->pSimpleGetValue($enderDest, "nro"); $consCpl = $this->pSimpleGetValue($enderDest, "xCpl", " - "); $consBairro = $this->pSimpleGetValue($enderDest, "xBairro"); $consCEP = $this->pFormat($this->pSimpleGetValue($enderDest, "CEP")); $consMun = $this->pSimpleGetValue($enderDest, "xMun"); $consUF = $this->pSimpleGetValue($enderDest, "UF"); $considEstrangeiro = $this->pSimpleGetValue($dest, "idEstrangeiro"); $consCPF = $this->pSimpleGetValue($dest, "CPF"); $consCNPJ = $this->pSimpleGetValue($dest, "CNPJ"); $consDoc = $consCPF . $consCNPJ . $considEstrangeiro; //documentos do consumidor $consHtml = ''; $consHtml .= "<table width='100%'>\n"; $consHtml .= "<tr>\n<td>CONSUMIDOR</td>\n</tr>\n"; $consHtml .= "<tr>\n<td>CNPJ/CPF/ID Estrangeiro : " . htmlspecialchars($consDoc) . "</td>\n</tr>\n"; $consHtml .= "<tr>\n<td>" . htmlspecialchars($consNome) . "</td>\n</tr>\n"; $consHtml .= "<tr>\n"; $consHtml .= "<td>" . htmlspecialchars($consLgr . ", " . $consNro . $consCpl) . "<BR>\n" . htmlspecialchars($consBairro . " - " . $consCEP) . "<BR>\n" . htmlspecialchars($consMun . " - " . $consUF . " " . "Fone/Fax: " . $consFone) . "</td>\n"; $consHtml .= "</tr>\n"; $consHtml .= "</table>\n"; return $consHtml; }
/** * anfavea * Função para transformar o campo cdata do padrão ANFAVEA para * texto imprimível * @param string $cdata campo CDATA * @return string conteúdo do campo CDATA como string */ private function pAnfavea($cdata = '') { if ($cdata == '') { return ''; } //remove qualquer texto antes ou depois da tag CDATA $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata); $cdata = str_replace(']]>', '</CDATA>', $cdata); $cdata = preg_replace('/\\s\\s+/', ' ', $cdata); $cdata = str_replace("> <", "><", $cdata); $len = strlen($cdata); $startPos = strpos($cdata, '<'); if ($startPos === false) { return $cdata; } for ($x = $len; $x > 0; $x--) { if (substr($cdata, $x, 1) == '>') { $endPos = $x; break; } } if ($startPos > 0) { $parte1 = substr($cdata, 0, $startPos); } else { $parte1 = ''; } $parte2 = substr($cdata, $startPos, $endPos - $startPos + 1); if ($endPos < $len) { $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1); } else { $parte3 = ''; } $texto = trim($parte1) . ' ' . trim($parte3); if (strpos($parte2, '<CDATA>') === false) { $cdata = '<CDATA>' . $parte2 . '</CDATA>'; } else { $cdata = $parte2; } //carrega o xml CDATA em um objeto DOM $dom = new DomDocumentNFePHP(); $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG); //$xml = $dom->saveXML(); //grupo CDATA infADprod $id = $dom->getElementsByTagName('id')->item(0); $div = $dom->getElementsByTagName('div')->item(0); $entg = $dom->getElementsByTagName('entg')->item(0); $dest = $dom->getElementsByTagName('dest')->item(0); $ctl = $dom->getElementsByTagName('ctl')->item(0); $ref = $dom->getElementsByTagName('ref')->item(0); if (isset($id)) { if ($id->hasAttributes()) { foreach ($id->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($div)) { if ($div->hasAttributes()) { foreach ($div->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($entg)) { if ($entg->hasAttributes()) { foreach ($entg->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($dest)) { if ($dest->hasAttributes()) { foreach ($dest->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($ctl)) { if ($ctl->hasAttributes()) { foreach ($ctl->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($ref)) { if ($ref->hasAttributes()) { foreach ($ref->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } //grupo CADATA infCpl $t = $dom->getElementsByTagName('transmissor')->item(0); $r = $dom->getElementsByTagName('receptor')->item(0); $versao = !empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ? 'Versao:' . $dom->getElementsByTagName('versao')->item(0)->nodeValue . ' ' : ''; $especieNF = !empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ? 'Especie:' . $dom->getElementsByTagName('especieNF')->item(0)->nodeValue . ' ' : ''; $fabEntrega = !empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ? 'Entrega:' . $dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue . ' ' : ''; $dca = !empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ? 'dca:' . $dom->getElementsByTagName('dca')->item(0)->nodeValue . ' ' : ''; $texto .= "" . $versao . $especieNF . $fabEntrega . $dca; if (isset($t)) { if ($t->hasAttributes()) { $texto .= " Transmissor "; foreach ($t->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } if (isset($r)) { if ($r->hasAttributes()) { $texto .= " Receptor "; foreach ($r->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; $texto .= " {$name} : {$value}"; } } } return $texto; }
/** * Make consumidor block * @param DomDocumentNFePHP $dest * @return string */ protected function consumidor($dest) { //DADOS DO CONSUMIDOR $consHtml = ''; $consHtml .= "<table width='100%'>\n"; if (!isset($dest)) { $consHtml .= "<tr><td colspan=\"3\">" . htmlspecialchars('CONSUMIDOR NÃO IDENTIFICADO') . ".</td></tr>\n"; } else { $enderDest = $dest->getElementsByTagName("enderDest")->item(0); $consNome = $this->pSimpleGetValue($dest, "xNome"); $consFone = $this->pSimpleGetValue($enderDest, "fone"); $foneLen = strlen($consFone); if ($foneLen == 10) { $consFone = $this->pFormat($consFone, "(##) ####-####"); } elseif ($foneLen == 11) { $consFone = $this->pFormat($consFone, "(##) #####-####"); } $consLgr = $this->pSimpleGetValue($enderDest, "xLgr"); $consNro = $this->pSimpleGetValue($enderDest, "nro"); $consCpl = $this->pSimpleGetValue($enderDest, "xCpl", " - "); $consBairro = $this->pSimpleGetValue($enderDest, "xBairro"); $consCEP = $this->pFormat($this->pSimpleGetValue($enderDest, "CEP")); $consMun = $this->pSimpleGetValue($enderDest, "xMun"); $consUF = $this->pSimpleGetValue($enderDest, "UF"); $consCNPJ = $this->pSimpleGetValue($dest, "CNPJ"); $consCPF = $this->pSimpleGetValue($dest, "CPF"); $considEstrangeiro = $this->pSimpleGetValue($dest, "idEstrangeiro"); //CNPJ, CPF ou ID Estrageiro if (!empty($consCNPJ)) { $consCNPJ = $this->pFormat($consCNPJ, "###.###.###-##"); $consHtml .= "<tr><td colspan=\"3\">CONSUMIDOR CNPJ: {consCNPJ} " . htmlspecialchars($consNome) . "</td></tr>\n"; } elseif (!empty($consCPF)) { $consCPF = $this->pFormat($consCPF, "##.###.###/####-##"); $consHtml .= "<tr><td colspan=\"3\">CONSUMIDOR CPF: {consCPF} " . htmlspecialchars($consNome) . "</td></tr>\n"; } elseif (!empty($considEstrangeiro)) { $consHtml .= "<tr><td colspan=\"3\">CONSUMIDOR Id. Estrangeiro: {considEstrangeiro} " . htmlspecialchars($consNome) . "</td></tr>\n"; } if (!empty($consLgr) && !empty($consBairro) && !empty($consMun) && !empty($consUF)) { $consHtml .= "<tr>\n"; $consHtml .= "<td colspan=\"3\">" . htmlspecialchars("{$consLgr}, {$consNro}, {$consCpl}, {$consBairro}") . "<br>\n" . htmlspecialchars("{$consMun}-{$consUF}") . "<br>\n" . htmlspecialchars("CEP: {$consCEP} - Tel.: {$consFone}") . "</td>\n"; $consHtml .= "</tr>\n"; } } $consHtml .= "</table>\n"; return $consHtml; }