Skip to content

Commit 977afb0

Browse files
Merge pull request #12 from tecnospeed/MAN-187
Adicionando suporte a rota Empresa; Adicionando IE para o Prestador.
2 parents 78e2ef7 + 73a92b2 commit 977afb0

File tree

6 files changed

+147
-25
lines changed

6 files changed

+147
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ composer.phar
22
/vendor/
33
/report/
44
teste.php
5+
.phpunit.result.cache
56
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
67
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
78
# composer.lock

examples/nfse.prestador.create.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
<?php
22

3-
require '../vendor/autoload.php';
3+
require '/home/thiago_ribeiro/Projetos/github.com/plugnotas-php/vendor/autoload.php';
44

55
use TecnoSpeed\Plugnotas\Nfse\Prestador;
66
use TecnoSpeed\Plugnotas\Configuration;
77
use TecnoSpeed\Plugnotas\Communication\CallApi;
88

99
try {
1010
$prestador = Prestador::fromArray([
11-
'cpfCnpj' => '00.000.000/0001-91',
11+
'cpfCnpj' => '80.681.272/0001-33',
1212
'inscricaoMunicipal' => '123456',
1313
'razaoSocial' => 'Razao Social do Prestador',
14+
'simplesNacional' => true,
1415
'endereco' => [
1516
'logradouro' => 'Rua de Teste',
1617
'numero' => '1234',
1718
'codigoCidade' => '4115200',
18-
'cep' => '87.050-800'
19+
'cep' => '87.050-800',
20+
'estado' => 'PR',
21+
'bairro' => 'CENTRO'
22+
],
23+
'nfse' => [
24+
'ativo' => true
1925
]
2026
]);
2127

22-
$configuration = new Configuration();
28+
$configuration = new Configuration(Configuration::TYPE_ENVIRONMENT_SANDBOX);
2329
$response = $prestador->send($configuration);
2430

2531
var_dump($response);

src/Common/Nfse.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace TecnoSpeed\Plugnotas\Common;
4+
5+
use TecnoSpeed\Plugnotas\Abstracts\BuilderAbstract;
6+
use TecnoSpeed\Plugnotas\Error\ValidationError;
7+
use Respect\Validation\Validator as v;
8+
9+
class Nfse extends BuilderAbstract
10+
{
11+
private $ativo;
12+
private $tipoContrato;
13+
14+
public function setAtivo($ativo)
15+
{
16+
if (
17+
is_null($ativo) ||
18+
!v::boolVal()->validate($ativo)
19+
) {
20+
throw new ValidationError(
21+
'Ativo é requerido para o cadastro de NFS-e.'
22+
);
23+
}
24+
25+
$this->ativo = $ativo;
26+
}
27+
28+
public function getAtivo()
29+
{
30+
return $this->ativo;
31+
}
32+
33+
public function setTipoContrato($tipoContrato)
34+
{
35+
if (
36+
!is_null($tipoContrato) &&
37+
!($tipoContrato === 0 ||
38+
$tipoContrato === 1)
39+
){
40+
throw new ValidationError(
41+
'Valor inválido para o TipoContrato. Valores aceitos: null, 0, 1'
42+
);
43+
}
44+
45+
$this->tipoContrato = $tipoContrato;
46+
}
47+
48+
public function getTipoContrato()
49+
{
50+
return $this->tipoContrato;
51+
}
52+
}

src/Nfse/Prestador.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use TecnoSpeed\Plugnotas\Error\RequiredError;
1414
use TecnoSpeed\Plugnotas\Error\ValidationError;
1515
use TecnoSpeed\Plugnotas\Traits\Communication;
16+
use TecnoSpeed\Plugnotas\Common\Nfse;
1617

1718
class Prestador extends BuilderAbstract
1819
{
@@ -25,12 +26,14 @@ class Prestador extends BuilderAbstract
2526
private $incentivadorCultural;
2627
private $incentivoFiscal;
2728
private $inscricaoMunicipal;
29+
private $inscricaoEstadual;
2830
private $nomeFantasia;
2931
private $razaoSocial;
3032
private $regimeTributario;
3133
private $regimeTributarioEspecial;
3234
private $simplesNacional;
3335
private $telefone;
36+
private $nfse;
3437

3538
public function setCertificado($certificado)
3639
{
@@ -107,6 +110,16 @@ public function getEndereco()
107110
return $this->endereco;
108111
}
109112

113+
public function setNfse(Nfse $nfse)
114+
{
115+
$this->nfse = $nfse;
116+
}
117+
118+
public function getNfse()
119+
{
120+
return $this->nfse;
121+
}
122+
110123
public function setIncentivadorCultural($incentivadorCultural)
111124
{
112125
$this->incentivadorCultural = $incentivadorCultural;
@@ -129,11 +142,6 @@ public function getIncentivoFiscal()
129142

130143
public function setInscricaoMunicipal($inscricaoMunicipal)
131144
{
132-
if (is_null($inscricaoMunicipal)) {
133-
throw new ValidationError(
134-
'Inscrição municipal é requerida para NFSe.'
135-
);
136-
}
137145
$this->inscricaoMunicipal = $inscricaoMunicipal;
138146
}
139147

@@ -142,6 +150,16 @@ public function getInscricaoMunicipal()
142150
return $this->inscricaoMunicipal;
143151
}
144152

153+
public function setInscricaoEstadual($inscricaoEstadual)
154+
{
155+
$this->inscricaoEstadual = $inscricaoEstadual;
156+
}
157+
158+
public function getInscricaoEstadual()
159+
{
160+
return $this->inscricaoEstadual;
161+
}
162+
145163
public function setNomeFantasia($nomeFantasia)
146164
{
147165
$this->nomeFantasia = $nomeFantasia;
@@ -229,6 +247,10 @@ public static function fromArray($data)
229247
$data['endereco'] = Endereco::fromArray($data['endereco']);
230248
}
231249

250+
if (array_key_exists('nfse', $data)) {
251+
$data['nfse'] = Nfse::fromArray($data['nfse']);
252+
}
253+
232254
return Hydrate::toObject(self::class, $data);
233255
}
234256

@@ -238,7 +260,6 @@ public function validate()
238260
if(
239261
!v::allOf(
240262
v::keyNested('cpfCnpj'),
241-
v::keyNested('inscricaoMunicipal'),
242263
v::keyNested('razaoSocial'),
243264
v::keyNested('simplesNacional'),
244265
v::keyNested('endereco.logradouro'),
@@ -260,6 +281,6 @@ public function send(Configuration $configuration)
260281
$this->validate();
261282

262283
$communication = $this->getCallApiInstance($configuration);
263-
return $communication->send('POST', '/nfse/prestador', $this->toArray(true));
284+
return $communication->send('POST', '/empresa', $this->toArray(true));
264285
}
265286
}

tests/Builders/NfseBuilderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use TecnoSpeed\Plugnotas\Builders\NfseBuilder;
77
use TecnoSpeed\Plugnotas\Common\Endereco;
88
use TecnoSpeed\Plugnotas\Common\Telefone;
9+
use TecnoSpeed\Plugnotas\Common\Nfse;
910
use TecnoSpeed\Plugnotas\Error\InvalidTypeError;
1011
use TecnoSpeed\Plugnotas\Error\ValidationError;
1112
use TecnoSpeed\Plugnotas\Nfse\CidadePrestacao;

tests/Nfse/PrestadorTest.php

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\TestCase;
1111
use TecnoSpeed\Plugnotas\Common\Endereco;
1212
use TecnoSpeed\Plugnotas\Common\Telefone;
13+
use TecnoSpeed\Plugnotas\Common\Nfse;
1314
use TecnoSpeed\Plugnotas\Communication\CallApi;
1415
use TecnoSpeed\Plugnotas\Configuration;
1516
use TecnoSpeed\Plugnotas\Error\InvalidTypeError;
@@ -85,17 +86,6 @@ public function testWithNullRazaoSocial()
8586
$prestador->setRazaoSocial(null);
8687
}
8788

88-
/**
89-
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setInscricaoMunicipal
90-
*/
91-
public function testWithNullIncricaoMunicipal()
92-
{
93-
$this->expectException(ValidationError::class);
94-
$this->expectExceptionMessage('Inscrição municipal é requerida para NFSe.');
95-
$prestador = new Prestador();
96-
$prestador->setInscricaoMunicipal(null);
97-
}
98-
9989
/**
10090
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail
10191
*/
@@ -121,6 +111,7 @@ public function testWithInvalidEmail()
121111
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getRegimeTributarioEspecial
122112
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getSimplesNacional
123113
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getTelefone
114+
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getNfse
124115
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCertificado
125116
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCpfCnpj
126117
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail
@@ -134,6 +125,7 @@ public function testWithInvalidEmail()
134125
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setRegimeTributarioEspecial
135126
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setSimplesNacional
136127
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setTelefone
128+
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setNfse
137129
*/
138130
public function testValidPrestadorCreation()
139131
{
@@ -151,6 +143,10 @@ public function testValidPrestadorCreation()
151143

152144
$telefone = new Telefone('44', '1234-1234');
153145

146+
$nfse = new Nfse();
147+
$nfse->setAtivo(true);
148+
$nfse->setTipoContrato(1);
149+
154150
$prestador = new Prestador();
155151
$prestador->setCertificado('5b855b0926ddb251e0f0ef42');
156152
$prestador->setCpfCnpj('00.000.000/0001-91');
@@ -165,7 +161,8 @@ public function testValidPrestadorCreation()
165161
$prestador->setRegimeTributarioEspecial(0);
166162
$prestador->setSimplesNacional(0);
167163
$prestador->setTelefone($telefone);
168-
164+
$prestador->setNfse($nfse);
165+
169166
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42');
170167
$this->assertSame($prestador->getCpfCnpj(), '00000000000191');
171168
$this->assertSame($prestador->getEmail(), '[email protected]');
@@ -179,7 +176,9 @@ public function testValidPrestadorCreation()
179176
$this->assertSame($prestador->getRegimeTributarioEspecial(), 0);
180177
$this->assertSame($prestador->getSimplesNacional(), 0);
181178
$this->assertSame($prestador->getTelefone()->getDdd(), '44');
182-
$this->assertSame($prestador->getTelefone()->getNumero(), '12341234');
179+
$this->assertSame($prestador->getTelefone()->getNumero(), '12341234');
180+
$this->assertSame($prestador->getNfse()->getAtivo(), true);
181+
$this->assertSame($prestador->getNfse()->getTipoContrato(), 1);
183182
}
184183

185184
/**
@@ -193,6 +192,44 @@ public function testBuildFromArray()
193192
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42');
194193
}
195194

195+
/**
196+
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
197+
*/
198+
public function testBuildFromArrayWithNfse()
199+
{
200+
$data = [
201+
'certificado' => '5b855b0926ddb251e0f0ef42',
202+
'nfse' => [
203+
'ativo' => true,
204+
'tipoContrato' => 1
205+
]
206+
];
207+
$prestador = Prestador::fromArray($data);
208+
$this->assertInstanceOf(Prestador::class, $prestador);
209+
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42');
210+
$this->assertInstanceOf(Nfse::class, $prestador->getNfse());
211+
}
212+
213+
/**
214+
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
215+
*/
216+
public function testBuildFromArrayWithNfseInvalid()
217+
{
218+
$this->expectExceptionMessage(
219+
'Valor inválido para o TipoContrato. Valores aceitos: null, 0, 1'
220+
);
221+
222+
$data = [
223+
'certificado' => '5b855b0926ddb251e0f0ef42',
224+
'nfse' => [
225+
'ativo' => true,
226+
'tipoContrato' => 3
227+
]
228+
];
229+
$prestador = Prestador::fromArray($data);
230+
$prestador->validate();
231+
}
232+
196233
/**
197234
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
198235
*/
@@ -248,7 +285,6 @@ public function testValidateWithValidObject()
248285
{
249286
$data = [
250287
'cpfCnpj' => '00.000.000/0001-91',
251-
'inscricaoMunicipal' => '123456',
252288
'razaoSocial' => 'Razao Social do Prestador',
253289
'simplesNacional' => false,
254290
'endereco' => [
@@ -295,10 +331,15 @@ public function testSend()
295331
'codigoCidade' => '4115200',
296332
'cep' => '87.050-800'
297333
]);
334+
$nfse = Nfse::fromArray([
335+
'ativo' => true,
336+
'tipoContrato' => 1
337+
]);
298338
$prestador->setCpfCnpj('00.000.000/0001-91');
299339
$prestador->setInscricaoMunicipal('123456');
300340
$prestador->setRazaoSocial('Razao Social do Prestador');
301341
$prestador->setEndereco($endereco);
342+
$prestador->setNfse($nfse);
302343
$prestador->setSimplesNacional(false);
303344
$response = $prestador->send($configuration);
304345

0 commit comments

Comments
 (0)