Skip to content

Commit

Permalink
Correção CTe de anulação
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Carlos committed Sep 28, 2019
1 parent 7ab6323 commit 5dfaacc
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions src/Common/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -338,56 +338,71 @@ 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;
}
}
return $signed;
}

/**
* @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;
}

/**
Expand Down

0 comments on commit 5dfaacc

Please sign in to comment.