From 7ab63230791b401c61e85d4ce225592569e4c43b Mon Sep 17 00:00:00 2001 From: Jean Carlos Date: Fri, 27 Sep 2019 15:45:55 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Corre=C3=A7=C3=A3o=20CTe=20de=20anula=C3=A7?= =?UTF-8?q?=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Tools.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Common/Tools.php b/src/Common/Tools.php index 81aed120..10c83f12 100644 --- a/src/Common/Tools.php +++ b/src/Common/Tools.php @@ -379,8 +379,14 @@ public function signCTe($xml) */ public function getModalXML($dom, $modal) { - $modal = $dom->getElementsByTagName($modal)->item(0); - $modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte"); + if (isset($dom->getElementsByTagName($modal)->item(0)->nodeValue)) { + $modal = $dom->getElementsByTagName($modal)->item(0); + $modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte"); + } else { + $modal = $dom->getElementsByTagName('Signature')->item(0); + $modal->setAttribute("xmlns", "http://www.w3.org/2000/09/xmldsig#"); + } + return $dom->saveXML($modal); } From 5dfaacc7edd76a450a1ee524cf094b36c9071e68 Mon Sep 17 00:00:00 2001 From: Jean Carlos Date: Sat, 28 Sep 2019 09:10:58 -0400 Subject: [PATCH 2/2] =?UTF-8?q?Corre=C3=A7=C3=A3o=20CTe=20de=20anula=C3=A7?= =?UTF-8?q?=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Tools.php | 51 ++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Common/Tools.php b/src/Common/Tools.php index 10c83f12..ba013f9a 100644 --- a/src/Common/Tools.php +++ b/src/Common/Tools.php @@ -307,7 +307,7 @@ public function validKeyByUF($chave) /** * Sign CTe - * @param string $xml CTe xml content + * @param string $xml CTe xml content * @return string singed CTe xml * @throws RuntimeException */ @@ -338,32 +338,50 @@ public function signCTe($xml) $signed = $this->addQRCode($dom); } $this->isValid($this->versao, $signed, $method); - $modal = (int) $dom->getElementsByTagName('modal')->item(0)->nodeValue; + $modal = (int)$dom->getElementsByTagName('modal')->item(0)->nodeValue; if ($modelo != 67) { switch ($modal) { case 1: //Rodoviário - $this->isValid($this->versao, $this->getModalXML($dom, 'rodo'), $method . 'ModalRodoviario'); + $rodo = $this->getModalXML($dom, 'rodo'); + if ($rodo) { + $this->isValid($this->versao, $rodo, $method . 'ModalRodoviario'); + } break; case 2: //Aéreo - $this->isValid($this->versao, $this->getModalXML($dom, 'aereo'), $method . 'ModalAereo'); + $aereo = $this->getModalXML($dom, 'aereo'); + if ($aereo) { + $this->isValid($this->versao, $aereo, $method . 'ModalAereo'); + } break; case 3: //Aquaviário - $this->isValid($this->versao, $this->getModalXML($dom, 'aquav'), $method . 'ModalAquaviario'); + $aquav = $this->getModalXML($dom, 'aquav'); + if ($aquav) { + $this->isValid($this->versao, $aquav, $method . 'ModalAquaviario'); + } break; case 4: //Ferroviário - $this->isValid($this->versao, $this->getModalXML($dom, 'ferrov'), $method . 'ModalFerroviario'); + $ferrov = $this->getModalXML($dom, 'ferrov'); + if ($ferrov) { + $this->isValid($this->versao, $ferrov, $method . 'ModalFerroviario'); + } break; case 5: //Dutoviário - $this->isValid($this->versao, $this->getModalXML($dom, 'duto'), $method . 'ModalDutoviario'); + $duto = $this->getModalXML($dom, 'duto'); + if ($duto) { + $this->isValid($this->versao, $duto, $method . 'ModalDutoviario'); + } break; case 6: //Multimodal - $this->isValid($this->versao, $this->getModalXML($dom, 'multimodal'), $method . 'MultiModal'); + $multimodal = $this->getModalXML($dom, 'multimodal'); + if ($multimodal) { + $this->isValid($this->versao, $multimodal, $method . 'MultiModal'); + } break; } } @@ -371,23 +389,20 @@ public function signCTe($xml) } /** - * @todo - * Retorna o xml do modal especifico * @param string $Dom CTe xml content * @param string $xml CTe xml content - * @return string + * @return string|bool + * @todo + * Retorna o xml do modal especifico */ public function getModalXML($dom, $modal) { - if (isset($dom->getElementsByTagName($modal)->item(0)->nodeValue)) { - $modal = $dom->getElementsByTagName($modal)->item(0); + $modal = $dom->getElementsByTagName($modal)->item(0); + if (!empty($modal)) { $modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte"); - } else { - $modal = $dom->getElementsByTagName('Signature')->item(0); - $modal->setAttribute("xmlns", "http://www.w3.org/2000/09/xmldsig#"); + return $dom->saveXML($modal); } - - return $dom->saveXML($modal); + return false; } /**