Skip to content

Commit

Permalink
Merge pull request #247 from uilhianet/validate_modal
Browse files Browse the repository at this point in the history
validação do cte com base no scheme do modal em especifico
  • Loading branch information
cleitonperin committed Sep 2, 2019
2 parents 66516de + 71f6ead commit d151be1
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions src/Common/Tools.php
Expand Up @@ -338,9 +338,52 @@ public function signCTe($xml)
$signed = $this->addQRCode($dom);
}
$this->isValid($this->versao, $signed, $method);
$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');
break;
case 2:
//Aéreo
$this->isValid($this->versao, $this->getModalXML($dom, 'aereo'), $method . 'ModalAereo');
break;
case 3:
//Aquaviário
$this->isValid($this->versao, $this->getModalXML($dom, 'aquav'), $method . 'ModalAquaviario');
break;
case 4:
//Ferroviário
$this->isValid($this->versao, $this->getModalXML($dom, 'ferrov'), $method . 'ModalFerroviario');
break;
case 5:
//Dutoviário
$this->isValid($this->versao, $this->getModalXML($dom, 'duto'), $method . 'ModalDutoviario');
break;
case 6:
//Multimodal
$this->isValid($this->versao, $this->getModalXML($dom, '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
*/
public function getModalXML($dom, $modal)
{
$modal = $dom->getElementsByTagName($modal)->item(0);
$modal->setAttribute("xmlns", "http://www.portalfiscal.inf.br/cte");
return $dom->saveXML($modal);
}

/**
* @todo
* Corret NFe fields when in contingency mode is set
Expand Down Expand Up @@ -395,7 +438,7 @@ protected function checkContingencyForWebServices($service)
if (array_search($type, $permit[$mod]) === false) {
throw new RuntimeException(
"Esse modo de contingência [$type] não é aceito "
. "para o modelo [$mod]"
. "para o modelo [$mod]"
);
}
}
Expand Down Expand Up @@ -446,7 +489,8 @@ protected function servico(
$sigla = $uf;
if (!$ignoreContingency) {
$contType = $this->contingency->type;
if (!empty($contType)
if (
!empty($contType)
&& ($contType == 'SVRS' || $contType == 'SVSP')
) {
$sigla = $contType;
Expand All @@ -456,15 +500,15 @@ protected function servico(
if ($stdServ === false) {
throw new \RuntimeException(
"Nenhum serviço foi localizado para esta unidade "
. "da federação [$sigla], com o modelo [$this->modelo]."
. "da federação [$sigla], com o modelo [$this->modelo]."
);
}
if (empty($stdServ->$service->url)) {
throw new \RuntimeException(
"Este serviço [$service] não está disponivel para esta "
. "unidade da federação [$uf] ou para este modelo de Nota ["
. $this->modelo
. "]."
. "unidade da federação [$uf] ou para este modelo de Nota ["
. $this->modelo
. "]."
);
}
//recuperação do cUF
Expand Down Expand Up @@ -515,7 +559,7 @@ protected function servico(
protected function sendRequest($request, array $parameters = [])
{
$this->checkSoap();
return (string)$this->soap->send(
return (string) $this->soap->send(
$this->urlService,
$this->urlMethod,
$this->urlAction,
Expand Down

0 comments on commit d151be1

Please sign in to comment.