Skip to content

Commit 4fbd95e

Browse files
Criação de método para cancelar CT-e
1 parent 30a0600 commit 4fbd95e

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

src/Soap/CancelarCTe.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Simonetti\MultiCTe\Soap;
4+
5+
/**
6+
* Class CancelarCTe
7+
* @package Simonetti\MultiCTe\Soap
8+
*/
9+
class CancelarCTe
10+
{
11+
/**
12+
* @var string
13+
*/
14+
public $cnpjEmpresaAdministradora;
15+
16+
/**
17+
* @var string
18+
*/
19+
public $chaveCTe;
20+
21+
/**
22+
* @var string
23+
*/
24+
public $justificativa;
25+
26+
/**
27+
* @var string
28+
*/
29+
public $token;
30+
}

src/Soap/ConhecimentoDeTransporteEletronico.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,15 @@ public function reenviarCTe(array $parameters)
7171

7272
return $retorno;
7373
}
74+
75+
public function cancelarCTe(array $parameters)
76+
{
77+
$retorno = $this->__soapCall('CancelarCTe', $parameters);
78+
79+
if (!$retorno->CancelarCTeResult->Status) {
80+
throw new \Exception('Erro ao cancelar CT-e : ' . $retorno->CancelarCTeResult->Mensagem . "\n");
81+
}
82+
83+
return $retorno;
84+
}
7485
}

tests/IntegracaoCTe/IntegracaoCteTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use phpDocumentor\Reflection\Types\Integer;
77
use Simonetti\MultiCTe\Soap\AlterarCTe;
8+
use Simonetti\MultiCTe\Soap\CancelarCTe;
89
use Simonetti\MultiCTe\Soap\CTe;
910
use Simonetti\MultiCTe\Soap\IntegracaoCTe;
1011
use Simonetti\MultiCTe\Soap\BuscarPorCodigoCTe;
@@ -51,7 +52,7 @@ public function testDeveriaIntegrarCTeSemErro()
5152

5253
$integrarCTe->cte = new CTe();
5354

54-
$integrarCTe->cte->CFOP = 6932;
55+
5556
$integrarCTe->cte->CodigoIBGECidadeInicioPrestacao = 3204104;
5657
$integrarCTe->cte->CodigoIBGECidadeTerminoPrestacao = 1504422;
5758

@@ -63,7 +64,7 @@ public function testDeveriaIntegrarCTeSemErro()
6364

6465
$integrarCTe->cte->ComponentesDaPrestacao = $componentesPrestacao;
6566

66-
$integrarCTe->cte->DataPrevistaEntrega = '15/11/2016';
67+
$integrarCTe->cte->DataPrevistaEntrega = '30/11/2016';
6768

6869
$destinatario = new Cliente();
6970
$destinatario->Bairro = 'JDIM STA FRANCISCA';
@@ -182,6 +183,7 @@ public function testDeveriaIntegrarCTeSemErro()
182183
$this->assertEquals('Integração realizada com sucesso.', $retorno->IntegrarCTeResult->Mensagem);
183184
}
184185

186+
185187
/**
186188
* @expectedException \Exception
187189
*/
@@ -322,7 +324,7 @@ public function testDeveriaLancarExceptionDevidoFormatacaoErradaCampoMotorista()
322324
public function testDeveriaBuscarPorCodigoCTeSemErro()
323325
{
324326
$busca = new BuscarPorCodigoCTe();
325-
$busca->codigoCTe = 37;
327+
$busca->codigoCTe = 2058;
326328
$busca->tipoIntegracao = 'Emissao';
327329
$busca->tipoRetorno = 'XML_PDF';
328330
$busca->token = $this->token;
@@ -502,4 +504,20 @@ public function testDeveriaGerarExceptionDevidoCodigoCTe()
502504
$retorno = $this->conhecimentoDeTransporteEletronico->alterarDadosCTe(['AlterarCTe' => $alterarCTe]);
503505
}
504506

507+
/**
508+
* @expectedException \Exception
509+
*/
510+
public function testCancelarDeveriaGerarExcecaoDevidoStatusDaCTe()
511+
{
512+
$cancelarCTe = new CancelarCTe();
513+
$cancelarCTe->chaveCTe = '32161125255622000191570010000000281000000287';
514+
$cancelarCTe->justificativa = 'Teste de cancelamento de cte';
515+
$cancelarCTe->cnpjEmpresaAdministradora = '13969629000196';
516+
$cancelarCTe->token = $this->token;
517+
518+
$retorno = $this->conhecimentoDeTransporteEletronico->cancelarCTe(['CancelarCTe' => $cancelarCTe]);
519+
520+
var_dump($retorno);
521+
}
522+
505523
}

0 commit comments

Comments
 (0)