Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SeniorWarehouseInputImport | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Shared\Integrations\Senior; |
| 4 | |
| 5 | use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException; |
| 6 | use Domain\Product\DTOs\SeniorOriginsProductsDTO; |
| 7 | use Domain\StockIO\DTOs\SeniorSyncInputWarehouseDTO; |
| 8 | use SoapFault; |
| 9 | use function __; |
| 10 | |
| 11 | class SeniorWarehouseInputImport |
| 12 | { |
| 13 | /** |
| 14 | * @param SeniorOriginsProductsDTO $seniorOriginsProductsDTO |
| 15 | * @return array |
| 16 | * @throws IntegrationSoapSeniorException |
| 17 | */ |
| 18 | public function execute(SeniorSyncInputWarehouseDTO $seniorSyncInputWarehouseDTO, string $datAlt, int $offset = 0, int $limit = 1000): array |
| 19 | { |
| 20 | $options = array( |
| 21 | 'exceptions' => true, |
| 22 | 'trace' => 1, |
| 23 | 'cache_wsdl' => WSDL_CACHE_NONE, |
| 24 | 'stream_context' => stream_context_create(array( |
| 25 | 'http' => array( |
| 26 | 'timeout' => 60, |
| 27 | ), |
| 28 | )), |
| 29 | ); |
| 30 | |
| 31 | $wsdlURI = config('integration.url') . '/sapiens_Synccom_br_soelx_MovimentoEstoque?wsdl'; |
| 32 | |
| 33 | try { |
| 34 | $params = [ |
| 35 | 'codDep' => $seniorSyncInputWarehouseDTO->codDep, |
| 36 | 'codDer' => $seniorSyncInputWarehouseDTO->codDer, |
| 37 | 'codEmp' => $seniorSyncInputWarehouseDTO->codEmp, |
| 38 | 'codPro' => $seniorSyncInputWarehouseDTO->codPro, |
| 39 | 'datAlt' => $seniorSyncInputWarehouseDTO->datAlt ?? $datAlt, |
| 40 | 'offSet' => $offset, |
| 41 | 'limit' => $limit |
| 42 | ]; |
| 43 | |
| 44 | $client = new SeniorSoapClient($wsdlURI, $options); |
| 45 | |
| 46 | $response = $client->ListarMovimentosAlmoxarifado(config('integration.user'), config('integration.user_password'), 0, $params); |
| 47 | if (isset($response->erroExecucao) || $response->statusProcesso != 1) { |
| 48 | throw new IntegrationSoapSeniorException( |
| 49 | __("Senior's SOAP request returned with an error: :message (:wsdl)", [ |
| 50 | 'message' => $response->erroExecucao ?? $response->mensagemProcesso, |
| 51 | 'wsdl' => $wsdlURI, |
| 52 | ]), |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | if(isset($response->movimentos)){ |
| 57 | return is_array($response->movimentos) |
| 58 | ? $response->movimentos |
| 59 | : [$response->movimentos]; |
| 60 | } else { |
| 61 | return []; |
| 62 | } |
| 63 | } catch (SoapFault $soapFault) { |
| 64 | throw new IntegrationSoapSeniorException( |
| 65 | __("Failure to consume Senior's soap: :message (:wsdl)", [ |
| 66 | 'message' => $soapFault->getMessage(), |
| 67 | 'wsdl' => $wsdlURI, |
| 68 | ]), |
| 69 | previous: $soapFault |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 | } |