Skip to content

Commit

Permalink
Merge pull request #253 from jeansilvaofficial/master
Browse files Browse the repository at this point in the history
Correção CTe de anulação
  • Loading branch information
cleitonperin authored Sep 29, 2019
2 parents 0a2e3a3 + 5dfaacc commit 6b9fed8
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 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,50 +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)
{
$modal = $dom->getElementsByTagName($modal)->item(0);
$modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte");
return $dom->saveXML($modal);
if (!empty($modal)) {
$modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte");
return $dom->saveXML($modal);
}
return false;
}

/**
Expand Down

0 comments on commit 6b9fed8

Please sign in to comment.