Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeniorInvoiceImport
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3namespace Domain\Shared\Integrations\Senior;
4
5use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException;
6use Domain\Invoice\DTOs\SeniorInvoiceImportDTO;
7use SoapFault;
8use function __;
9
10class SeniorInvoiceImport extends SeniorImportBase
11{
12    /**
13     * @param string $query
14     * @param int $offset
15     * @param int $limit
16     * @return array
17     * @throws IntegrationSoapSeniorException
18     */
19    public function execute(SeniorInvoiceImportDTO $seniorInvoiceImportDTO, string $lastDate = '', int $offset = 0, int $limit = 1000): array
20    {
21        $wsdlURI = config('integration.url') . '/sapiens_Synccom_br_SoelX_ConferenciaNotasFiscaisEntrada?wsdl';
22        try {
23            $client = new SeniorSoapClient($wsdlURI, $this->options);
24
25            $params = [
26                "limit" => $limit,
27                "offSet" => $offset,
28            ];
29            $filters = array_filter(
30                $seniorInvoiceImportDTO->toArray(),
31                fn ($value) => $value !== null && (!is_string($value) || trim($value) !== '')
32            );
33
34            if($lastDate <> ''){
35                $params = $params + ['datGer' => $lastDate];
36            } else {
37                $params = $params + $filters;
38            }
39
40            $response = $client->listarNotasFiscais(config('integration.user'), config('integration.user_password'), 0, $params);
41
42            $this->verifyErroFromSenior($response, $wsdlURI);
43
44            if(isset($response->notasFiscais)){
45                return is_array($response->notasFiscais)
46                        ? $response->notasFiscais
47                        : [$response->notasFiscais];
48            } else {
49                return [];
50            }
51
52        } catch (SoapFault $soapFault) {
53            throw new IntegrationSoapSeniorException(
54                __("Failure to consume Senior's soap: :message (:wsdl)", [
55                    'message' => $soapFault->getMessage(),
56                    'wsdl' => $wsdlURI,
57                ]),
58                previous: $soapFault
59            );
60        }
61    }
62}