Issues (68)

src/Library/NFePHP.php (22 issues)

1
<?php
2
3
namespace ControleOnline\Library;
4
5
use ControleOnline\Entity\Config;
0 ignored issues
show
The type ControleOnline\Entity\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use ControleOnline\Entity\File;
0 ignored issues
show
The type ControleOnline\Entity\File was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use ControleOnline\Entity\Order;
8
use ControleOnline\Entity\Product;
0 ignored issues
show
The type ControleOnline\Entity\Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use ControleOnline\Entity\SalesInvoiceTax;
0 ignored issues
show
The type ControleOnline\Entity\SalesInvoiceTax was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use ControleOnline\Entity\OrderInvoiceTax;
11
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use NFePHP\Common\Certificate;
0 ignored issues
show
The type NFePHP\Common\Certificate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
0 ignored issues
show
The type Symfony\Component\Securi...e\TokenStorageInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
 AS Security;
15
use NFePHP\CTe\Common\Standardize;
0 ignored issues
show
The type NFePHP\CTe\Common\Standardize was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Symfony\Component\HttpKernel\KernelInterface;
0 ignored issues
show
The type Symfony\Component\HttpKernel\KernelInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
class NFePHP
19
{
20
    protected $make;
21
    protected $model;
22
    protected $tools;
23
    protected $version;
24
25
    public function __construct(
26
        protected EntityManagerInterface $manager,
27
        protected Security $security,
28
        protected KernelInterface $appKernel
29
    ) {}
30
31
    //ide OBRIGATÓRIA
32
    protected function makeIde(Order $order)
33
    {
34
        $provider = $order->getProvider();
35
        $document = $provider->getOneDocument();
36
        //$dhEmi = date("Y-m-d\TH:i:s-03:00"); Para obter a data com diferença de fuso usar 'P'
37
        $dhEmi = date("Y-m-d\TH:i:sP");
38
39
        $numeroCTE = $this->getLastDacte();
40
41
        // CUIDADO: Observe que mesmo os parâmetros fixados abaixo devem ser preenchidos conforme os dados do CT-e, estude a composição da CHAVE para saber o que vai em cada campo
42
        $chave = $this->montaChave(
43
            '43',
44
            date('y', strtotime($dhEmi)),
45
            date('m', strtotime($dhEmi)),
46
            $document->getDOcument(),
47
            $this->tools->model(),
48
            '1',
49
            $numeroCTE,
50
            '1',
51
            '10'
52
        );
53
54
        $cDV = substr($chave, -1);      //Digito Verificador
55
56
        /**
57
         * @todo
58
         */
59
        $ide = new \stdClass();
60
        $ide->cUF = '43'; // Codigo da UF da tabela do IBGE
61
        $ide->cCT = '99999999'; // Codigo numerico que compoe a chave de acesso
62
        $ide->CFOP = '6932'; // Codigo fiscal de operacoes e prestacoes
63
        $ide->natOp = 'PRESTACAO DE SERVICO DE TRANSPORTE A ESTABELECIMENTO FORA DO ESTADO DE ORIGEM'; // Natureza da operacao
64
65
        /**
66
         * @todo
67
         */
68
69
        //$ide->forPag = '';              // 0-Pago; 1-A pagar; 2-Outros
70
        $ide->mod = '57'; // Modelo do documento fiscal: 57 para identificação do CT-e
71
        $ide->serie = '1'; // Serie do CTe
72
        $ide->nCT = $numeroCTE; // Numero do CTe
73
        $ide->dhEmi = $dhEmi; // Data e hora de emissão do CT-e: Formato AAAA-MM-DDTHH:MM:DD
74
        $ide->tpImp = '1'; // Formato de impressao do DACTE: 1-Retrato; 2-Paisagem.
75
        $ide->tpEmis = '1'; // Forma de emissao do CTe: 1-Normal; 4-EPEC pela SVC; 5-Contingência
76
        $ide->cDV = $cDV; // Codigo verificador
77
        $ide->tpAmb = '2'; // 1- Producao; 2-homologacao
78
        $ide->tpCTe = '0'; // 0- CT-e Normal; 1 - CT-e de Complemento de Valores;
79
        // 2 -CT-e de Anulação; 3 - CT-e Substituto
80
        $ide->procEmi = '0'; // Descricao no comentario acima
81
        $ide->verProc = $this->version; // versao do aplicativo emissor
82
        $ide->indGlobalizado = '';
83
        //$ide->refCTE = '';             // Chave de acesso do CT-e referenciado            
84
        $ide->xMunEnv = 'FOZ DO IGUACU'; // Informar PAIS/Municipio para as operações com o exterior.
85
        $ide->UFEnv = 'RS'; // Informar 'EX' para operações com o exterior.
86
        $ide->modal = '01'; // Preencher com:01-Rodoviário; 02-Aéreo; 03-Aquaviário;04-
87
        $ide->tpServ = '0'; // 0- Normal; 1- Subcontratação; 2- Redespacho;
88
        $ide->cMunEnv = $this->getCodMunicipio($ide->xMunEnv, $ide->UFEnv); // Código do município (utilizar a tabela do IBGE)
89
90
91
        /**
92
         * @todo
93
         */
94
        // 3- Redespacho Intermediário; 4- Serviço Vinculado a Multimodal            
95
        $ide->xMunIni = 'FOZ DO IGUACU'; // Informar 'EXTERIOR' para operações com o exterior.
96
        $ide->UFIni = 'RS'; // Informar 'EX' para operações com o exterior.
97
        $ide->cMunFim = '3523909'; // Utilizar a tabela do IBGE. Informar 9999999 para operações com o exterior.
98
        $ide->cMunFim = $this->getCodMunicipio($ide->xMunIni, $ide->UFIni); // Código do município (utilizar a tabela do IBGE)
99
100
101
        /**
102
         * @todo
103
         */
104
        $ide->xMunFim = 'ITU'; // Informar 'EXTERIOR' para operações com o exterior.
105
        $ide->UFFim = 'SP'; // Informar 'EX' para operações com o exterior.
106
        $ide->cMunIni = $this->getCodMunicipio($ide->xMunFim, $ide->UFFim); // Código do município (utilizar a tabela do IBGE)
107
108
        $ide->retira = '1'; // Indicador se o Recebedor retira no Aeroporto; Filial,
109
        // Porto ou Estação de Destino? 0-sim; 1-não
110
        $ide->xDetRetira = ''; // Detalhes do retira
111
        $ide->indIEToma = '1';
112
        $ide->dhCont = ''; // Data e Hora da entrada em contingência; no formato AAAAMM-DDTHH:MM:SS
113
        $ide->xJust = '';                 // Justificativa da entrada em contingência
114
115
        $this->make->tagide($ide);
116
    }
117
118
119
    //toma OBRIGATÓRIA
120
    protected function makeTomador(Order $order)
121
    {
122
123
124
125
        // Indica o "papel" do tomador: 0-Remetente; 1-Expedidor; 2-Recebedor; 3-Destinatário
126
        $toma3 = new \stdClass();
127
        $toma3->toma = '3';
128
        $this->make->tagtoma3($toma3);
129
        //
130
        //$toma4 = new stdClass();
131
        //$toma4->toma = '4'; // 4-Outros; informar os dados cadastrais do tomador quando ele for outros
132
        //$toma4->CNPJ = '11509962000197'; // CNPJ
133
        //$toma4->CPF = ''; // CPF
134
        //$toma4->IE = 'ISENTO'; // Iscricao estadual
135
        //$toma4->xNome = 'RAZAO SOCIAL'; // Razao social ou Nome
136
        //$toma4->xFant = 'NOME FANTASIA'; // Nome fantasia
137
        //$toma4->fone = '5532128202'; // Telefone
138
        //$toma4->email = '[email protected]';   // email
139
        //$cte->tagtoma4($toma4);
140
141
        //endertoma OBRIGATÓRIA
142
        $this->makeTomadorAddress($order);
143
    }
144
145
    protected function makeTomadorAddress(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

145
    protected function makeTomadorAddress(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
    {
147
148
        /**
149
         * @todo
150
         */
151
        $enderToma = new \stdClass();
152
        $enderToma->xLgr = 'Avenida Independência'; // Logradouro
153
        $enderToma->nro = '482'; // Numero
154
        $enderToma->xCpl = ''; // COmplemento
155
        $enderToma->xBairro = 'Centro'; // Bairro
156
        $enderToma->cMun = '4308607'; // Codigo do municipio do IBEGE Informar 9999999 para operações com o exterior
157
        $enderToma->xMun = 'Garibaldi'; // Nome do município (Informar EXTERIOR para operações com o exterior.
158
        $enderToma->CEP = '95720000'; // CEP
159
        $enderToma->UF = 'SP'; //$arr['siglaUF']; // Sigla UF (Informar EX para operações com o exterior.)
160
        $enderToma->cPais = '1058'; // Codigo do país ( Utilizar a tabela do BACEN )
161
        $enderToma->xPais = 'Brasil';                   // Nome do pais
162
        $this->make->tagenderToma($enderToma);
163
    }
164
165
    //emit OBRIGATÓRIA
166
    protected function makeEmit(Order $order)
167
    {
168
        $provider = $order->getProvider();
169
        $document = $provider->getOneDocument();
170
171
        $std = new \stdClass();
172
        $std->IE = '111111111';
173
        $std->IEST = null;
174
        //$std->IM = '95095870';
175
        $std->CNAE = '4642701';
176
        $std->CRT = 1;
177
        $std->CNPJ = '99999999999999';
178
        //$std->CPF = '12345678901'; //NÃO PASSE TAGS QUE NÃO EXISTEM NO CASO
179
180
        $emit = new \stdClass();
181
        $emit->CNPJ = $document->getDOcument(); // CNPJ do emitente
182
        //$emit->IE = '0100072968'; // Inscricao estadual
183
        //$emit->IEST = ""; // Inscricao estadual
184
        $emit->xNome = $provider->getName(); // Razao social
185
        $emit->xFant = $provider->getAlias(); // Nome fantasia
186
187
        $this->make->tagemit($std);
188
189
        //enderEmit OBRIGATÓRIA
190
        $this->makeEmitAddress($order);
191
    }
192
193
    protected function makeEmitAddress(Order $order)
194
    {
195
        $provider = $order->getProvider();
196
        /**
197
         * @var \ControleOnline\Entity\Address $providerAddress
198
         */
199
        $providerAddress = $provider->getAddress()[0];
200
201
        $enderEmit = new \stdClass();
202
        $enderEmit->xLgr = $providerAddress->getStreet()->getStreet(); // Logradouro
203
        $enderEmit->nro = $providerAddress->getNumber(); // Numero
204
        $enderEmit->xCpl = $providerAddress->getComplement(); // Complemento
205
        $enderEmit->xBairro = $providerAddress->getStreet()->getDistrict()->getDistrict(); // Bairro
206
        $enderEmit->xMun = $providerAddress->getStreet()->getDistrict()->getCity()->getCity(); // Nome do municipio            
207
        $enderEmit->CEP = $providerAddress->getStreet()->getCep()->getCep(); // CEP
208
        $enderEmit->UF =  $providerAddress->getStreet()->getDistrict()->getCity()->getState()->getUf(); // Sigla UF
209
        $enderEmit->cMun = $this->getCodMunicipio($enderEmit->xMun, $enderEmit->UF); // Código do município (utilizar a tabela do IBGE)
210
        $enderEmit->fone = $provider->getPhone()[0]->getDdd() . $provider->getPhone()[0]->getPhone(); // Fone
211
        $this->make->tagenderemit($enderEmit);
212
    }
213
    //dest OPCIONAL
214
    protected function makeDest(Order $order)
215
    {
216
        $std = new \stdClass();
217
        $std->xNome = 'Eu Ltda';
218
        $std->CNPJ = '01234123456789';
219
        //$std->CPF = '12345678901';
220
        //$std->idEstrangeiro = 'AB1234';
221
        $std->indIEDest = 9;
222
        //$std->IE = '';
223
        //$std->ISUF = '12345679';
224
        //$std->IM = 'XYZ6543212';
225
        $std->email = '[email protected]';
226
        $dest = $this->make->tagdest($std);
0 ignored issues
show
The assignment to $dest is dead and can be removed.
Loading history...
227
228
229
        $this->makeDestAddress($order);
230
    }
231
    //enderDest OPCIONAL
232
    protected function makeDestAddress(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

232
    protected function makeDestAddress(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
233
    {
234
235
        $std = new \stdClass();
236
        $std->xLgr = 'Avenida Sebastião Diniz';
237
        $std->nro = '458';
238
        $std->xCpl = null;
239
        $std->xBairro = 'CENTRO';
240
        $std->cMun = 1400100;
241
        $std->xMun = 'Boa Vista';
242
        $std->UF = 'RR';
243
        $std->CEP = '69301088';
244
        $std->cPais = 1058;
245
        $std->xPais = 'Brasil';
246
        $std->fone = '1111111111';
247
        $this->make->tagenderdest($std);
248
    }
249
250
    //prod OBRIGATÓRIA
251
    protected function makeProds(Order $order)
252
    {
253
        $orderProducts  = $order->getOrderProducts();
254
        $item = 1;
255
        foreach ($orderProducts as $orderProducts) {
256
            $product = $orderProducts->getProduct();
257
258
            $std = new \stdClass();
259
            $std->item = $item;
260
            $std->cProd = '00341';
261
            $std->cEAN = 'SEM GTIN';
262
            $std->cEANTrib = 'SEM GTIN';
263
            $std->xProd = 'Produto com serviço';
264
            $std->NCM = '96081000';
265
            $std->CFOP = '5933';
266
            $std->uCom = 'JG';
267
            $std->uTrib = 'JG';
268
            $std->cBarra = NULL;
269
            $std->cBarraTrib = NULL;
270
            $std->qCom = '1';
271
            $std->qTrib = '1';
272
            $std->vUnCom = '200';
273
            $std->vUnTrib = '200';
274
            $std->vProd = '200';
275
            $std->vDesc = NULL;
276
            $std->vOutro = NULL;
277
            $std->vSeg = NULL;
278
            $std->vFrete = NULL;
279
            $std->cBenef = NULL;
280
            $std->xPed = NULL;
281
            $std->nItemPed = NULL;
282
            $std->indTot = 1;
283
            $this->make->tagprod($std);
284
            $this->makeImpostos($product, $item);
285
        }
286
    }
287
    protected function makeImpostos(Product $product, $item)
288
    {
289
        $this->makePIS($product, $item);
290
        $this->makeCOFINS($product, $item);
291
        $this->makeISSQN($product, $item);
292
293
        //Imposto
294
        $std = new \stdClass();
295
        $std->item = $item; //item da NFe
296
        $std->vTotTrib = 0;
297
        $this->make->tagimposto($std);
298
299
300
301
        $std = new \stdClass();
302
        $this->make->tagICMSTot($std);
303
304
        $std = new \stdClass();
305
        $std->dCompet = '2010-09-12';
306
        $std->cRegTrib = 6;
307
        $this->make->tagISSQNTot($std);
308
        $this->make->tagISSQNTot($std);
309
    }
310
311
    protected function makeInfNFe($version)
312
    {
313
        //infNFe OBRIGATÓRIA
314
        $std = new \stdClass();
315
        $std->Id = '';
316
        $std->versao =  $version;
317
        $this->make->taginfNFe($std);
318
    }
319
320
    protected function makeISSQN(Product $product, $item)
0 ignored issues
show
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

320
    protected function makeISSQN(/** @scrutinizer ignore-unused */ Product $product, $item)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
321
    {
322
        // Monta a tag de impostos mas não adiciona no xml
323
        $std = new \stdClass();
324
        $std->item = $item; //item da NFe
325
        $std->vBC = 2.0;
326
        $std->vAliq = 8.0;
327
        $std->vISSQN = 0.16;
328
        $std->cMunFG = 1300029;
329
        $std->cMun = 1300029;
330
        $std->cPais = '1058';
331
        $std->cListServ = '01.01';
332
        $std->indISS = 1;
333
        $std->indIncentivo = 2;
334
        // Adiciona a tag de imposto ISSQN no xml
335
        $this->make->tagISSQN($std);
336
    }
337
338
    protected function makePIS(Product $product, $item)
0 ignored issues
show
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

338
    protected function makePIS(/** @scrutinizer ignore-unused */ Product $product, $item)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
339
    {
340
        //PIS
341
        $std = new \stdClass();
342
        $std->item = $item; //item da NFe
343
        $std->CST = '99';
344
        $std->vBC = 200;
345
        $std->pPIS = 0.65;
346
        $std->vPIS = 13;
347
        $this->make->tagPIS($std);
348
    }
349
    protected function makeCOFINS(Product $product, $item)
0 ignored issues
show
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

349
    protected function makeCOFINS(/** @scrutinizer ignore-unused */ Product $product, $item)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
350
    {
351
        //COFINS
352
        $std = new \stdClass();
353
        $std->item = $item; //item da NFe
354
        $std->CST = '99';
355
        $std->vBC = 200;
356
        $std->pCOFINS = 3;
357
        $std->vCOFINS = 60;
358
        $this->make->tagCOFINS($std);
359
    }
360
361
    protected function sign(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

361
    protected function sign(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
362
    {
363
        $this->tools->model($this->model);
364
        //$tools->disableCertValidation(true); //tem que desabilitar
365
        return $this->tools->signNFe($this->make->getXML());
366
    }
367
368
    protected function getCertificate(Order $order)
369
    {
370
        $provider = $order->getProvider();
371
372
        $dacteKey = $this->manager->getRepository(Config::class)->findOneBy([
373
            'people'  => $provider,
374
            'configKey' => 'cert-file'
375
        ]);
376
377
        $dacteKeyPass = $this->manager->getRepository(Config::class)->findOneBy([
378
            'people'  => $provider,
379
            'configKey' => 'cert-pass'
380
        ]);
381
        if (!$dacteKey || !$dacteKeyPass)
382
            throw new \Exception("Key cert is required", 1);
383
384
        $certPath = $dacteKey->getConfigValue();
385
386
        if (! $certPath)
387
            throw new \Exception("Key cert path is invalid: " . $certPath, 1);
388
        $certContent = $this->manager->getRepository(File::class)->find($dacteKey->getConfigValue());
389
        if (!$certContent)
390
            throw new \Exception("Key content on table files is empty " . $certPath, 1);
391
392
        return Certificate::readPfx(
393
            $certContent->getContent(),
394
            $dacteKeyPass->getConfigValue()
395
        );
396
    }
397
398
    protected function getSignData(Order $order)
399
    {
400
401
        $provider = $order->getProvider();
402
        $document = $provider->getOneDocument();
403
404
        /**
405
         * @var \ControleOnline\Entity\Address $providerAddress
406
         */
407
        $providerAddress = $provider->getAddress()[0];
408
409
        $arr = [
410
            "atualizacao" => date('Y-m-d H:m:i'),
411
            "tpAmb" => 2, //2 - Homologação / 1 - Produção
412
            "razaosocial" => $provider->getName(),
413
            "cnpj" => $document->getDocument(),
414
            //"cpf" => "00000000000",
415
            "siglaUF" => $providerAddress->getStreet()->getDistrict()->getCity()->getState()->getUf(),
416
            "schemes" => "PL_CTe_300",
417
            "versao" => $this->version,
418
            "proxyConf" => [
419
                "proxyIp" => "",
420
                "proxyPort" => "",
421
                "proxyUser" => "",
422
                "proxyPass" => ""
423
            ]
424
        ];
425
426
        return json_encode($arr);
427
    }
428
429
    protected function makeTransp(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

429
    protected function makeTransp(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
430
    {
431
        //transp OBRIGATÓRIA
432
        $std = new \stdClass();
433
        $this->make->tagtransp($std);
434
    }
435
436
437
    protected function makePag(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

437
    protected function makePag(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
438
    {
439
        //pag OBRIGATÓRIA
440
        $std = new \stdClass();
441
        $std->vTroco = 0;
442
        $this->make->tagpag($std);
443
    }
444
445
446
    protected function makedetPag(Order $order)
0 ignored issues
show
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

446
    protected function makedetPag(/** @scrutinizer ignore-unused */ Order $order)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
447
    {
448
        //detPag OBRIGATÓRIA
449
        $std = new \stdClass();
450
        $std->indPag = '0';
451
        $std->xPag = NULL;
452
        $std->tPag = '01';
453
        $std->vPag = 2.01;
454
        $this->make->tagdetpag($std);
455
    }
456
    protected function makeInfRespTec()
457
    {
458
459
        $std = new \stdClass();
460
        $std->CNPJ = '99999999999999'; //CNPJ da pessoa jurídica responsável pelo sistema utilizado na emissão do documento fiscal eletrônico
461
        $std->xContato = 'Fulano de Tal'; //Nome da pessoa a ser contatada
462
        $std->email = '[email protected]'; //E-mail da pessoa jurídica a ser contatada
463
        $std->fone = '1155551122'; //Telefone da pessoa jurídica/física a ser contatada
464
        //$std->CSRT = 'G8063VRTNDMO886SFNK5LDUDEI24XJ22YIPO'; //Código de Segurança do Responsável Técnico
465
        //$std->idCSRT = '01'; //Identificador do CSRT
466
        $this->make->taginfRespTec($std);
467
    }
468
469
470
    protected function getCodMunicipio($mun, $uf)
471
    {
472
473
        /**
474
         * @todo
475
         */
476
        $cod['sp'] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cod was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cod = array(); before regardless.
Loading history...
477
            'Guarulhos' => '4108304',
478
            'São Paulo' => '4108304'
479
        ];
480
481
        return $cod[$uf][$mun];
482
    }
483
    protected function getLastDacte()
484
    {
485
        return '127'; //@todo
486
    }
487
488
    protected function montaChave($cUF, $ano, $mes, $cnpj, $mod, $serie, $numero, $tpEmis, $codigo = '')
489
    {
490
        if ($codigo == '') {
491
            $codigo = $numero;
492
        }
493
        $forma = "%02d%02d%02d%s%02d%03d%09d%01d%08d";
494
        $chave = sprintf(
495
            $forma,
496
            $cUF,
497
            $ano,
498
            $mes,
499
            $cnpj,
500
            $mod,
501
            $serie,
502
            $numero,
503
            $tpEmis,
504
            $codigo
505
        );
506
        return $chave . $this->calculaDV($chave);
507
    }
508
509
510
    protected function sendData($xml)
511
    {
512
513
        //Envia lote e autoriza
514
        $axmls[] = $xml;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$axmls was never initialized. Although not strictly required by PHP, it is generally a good practice to add $axmls = array(); before regardless.
Loading history...
515
        $lote = substr(str_replace(',', '', number_format(microtime(true) * 1000000, 0)), 0, 15);
516
        $res = $this->tools->sefazEnviaLote($axmls, $lote);
517
518
        //Converte resposta
519
        $stdCl = new Standardize($res);
520
        //Output array
521
        $arr = $stdCl->toArray();
522
        //print_r($arr);
523
        //Output object
524
        $std = $stdCl->toStd();
525
526
        if ($std->cStat != 103) { //103 - Lote recebido com Sucesso
527
            //processa erros
528
            print_r($arr);
529
        }
530
531
        //Consulta Recibo
532
        $res = $this->tools->sefazConsultaRecibo($std->infRec->nRec);
533
        $stdCl = new Standardize($res);
534
        $arr = $stdCl->toArray();
535
        $std = $stdCl->toStd();
536
        if ($std->protCTe->infProt->cStat == 100) { //Autorizado o uso do CT-e
537
            //adicionar protocolo
538
        }
539
        echo '<pre>';
540
        print_r($arr);
541
    }
542
543
    protected function calculaDV($chave43)
544
    {
545
        $multiplicadores = array(2, 3, 4, 5, 6, 7, 8, 9);
546
        $iCount = 42;
547
        $somaPonderada = 0;
548
        while ($iCount >= 0) {
549
            for ($mCount = 0; $mCount < count($multiplicadores) && $iCount >= 0; $mCount++) {
550
                $num = (int) substr($chave43, $iCount, 1);
551
                $peso = (int) $multiplicadores[$mCount];
552
                $somaPonderada += $num * $peso;
553
                $iCount--;
554
            }
555
        }
556
        $resto = $somaPonderada % 11;
557
        if ($resto == '0' || $resto == '1') {
558
            $cDV = 0;
559
        } else {
560
            $cDV = 11 - $resto;
561
        }
562
        return (string) $cDV;
563
    }
564
565
    public function  getNfNumber($xml)
0 ignored issues
show
The parameter $xml is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

565
    public function  getNfNumber(/** @scrutinizer ignore-unused */ $xml)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
566
    {
567
        return 1;
568
    }
569
570
    protected function persist(Order $order, $xml)
571
    {
572
        $provider = $order->getProvider();
573
        $invoiceTax = new SalesInvoiceTax();
574
        $invoiceTax->setInvoice($xml);
575
        $invoiceTax->setInvoiceNumber($this->getNfNumber($xml));
576
577
        $this->manager->persist($invoiceTax);
578
        $this->manager->flush();
579
580
581
        $orderInvoiceTax = new OrderInvoiceTax();
582
        $orderInvoiceTax->setOrder($order);
583
        $orderInvoiceTax->setInvoiceType(57);
584
        $orderInvoiceTax->setInvoiceTax($invoiceTax);
585
        $orderInvoiceTax->setIssuer($provider);
586
587
        $this->manager->persist($orderInvoiceTax);
588
        $this->manager->flush();
589
    }
590
}
591