Skip to content

Commit

Permalink
feat: implementar OrdensDeProducao e atualizar entidades de Produtos
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Sep 6, 2024
1 parent fa74803 commit 3d94d4b
Show file tree
Hide file tree
Showing 54 changed files with 1,304 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
para PHP 8.2+. O mais completo existente.

Atualizado com a versão `v301` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-05-22)).
Atualizado com a versão `v303` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-06-19)).

## Instalação

Expand Down Expand Up @@ -66,7 +66,7 @@ Quase todas as entidades do Bling atualmente são permitidas para interação. S
- [x] Notas Fiscais de Serviço Eletrônicas (`->nfses`)
- [x] Notas Fiscais Eletrônicas (`->nfes`)
- [x] Notificações (`->notificacoes`)
- [ ] Ordens de produção (`->ordensDeProducao`)
- [x] Ordens de produção (`->ordensDeProducao`)
- [x] Pedidos - Compras (`->pedidosCompras`)
- [x] Pedidos - Vendas (`->pedidosVendas`)
- [x] Produtos (`->produtos`)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alebatistella/bling-erp-api",
"description": "Pacote de integração com a API do Bling ERP",
"type": "library",
"version": "1.14.2",
"version": "1.15.0",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions src/Bling.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use AleBatistella\BlingErpApi\Entities\Nfes\Nfes;
use AleBatistella\BlingErpApi\Entities\Nfses\Nfses;
use AleBatistella\BlingErpApi\Entities\Notificacoes\Notificacoes;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\OrdensDeProducao;
use AleBatistella\BlingErpApi\Entities\PedidosCompras\PedidosCompras;
use AleBatistella\BlingErpApi\Entities\PedidosVendas\PedidosVendas;
use AleBatistella\BlingErpApi\Entities\Produtos\Produtos;
Expand Down Expand Up @@ -76,6 +77,7 @@
* @property Nfses $nfses
* @property Nfes $nfes
* @property Notificacoes $notificacoes
* @property OrdensDeProducao $ordensDeProducao
* @property PedidosCompras $pedidosCompras
* @property PedidosVendas $pedidosVendas
* @property Produtos $produtos
Expand Down Expand Up @@ -157,6 +159,7 @@ public function __get(string $name)
'nfses' => $this->getModule(Nfses::class),
'nfes' => $this->getModule(Nfes::class),
'notificacoes' => $this->getModule(Notificacoes::class),
'ordensDeProducao' => $this->getModule(OrdensDeProducao::class),
'pedidosCompras' => $this->getModule(PedidosCompras::class),
'pedidosVendas' => $this->getModule(PedidosVendas::class),
'produtos' => $this->getModule(Produtos::class),
Expand Down
15 changes: 15 additions & 0 deletions src/BlingTest.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use AleBatistella\BlingErpApi\Entities\Nfes\Nfes;
use AleBatistella\BlingErpApi\Entities\Nfses\Nfses;
use AleBatistella\BlingErpApi\Entities\Notificacoes\Notificacoes;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\OrdensDeProducao;
use AleBatistella\BlingErpApi\Entities\PedidosCompras\PedidosCompras;
use AleBatistella\BlingErpApi\Entities\PedidosVendas\PedidosVendas;
use AleBatistella\BlingErpApi\Entities\Produtos\Produtos;
Expand Down Expand Up @@ -466,6 +467,20 @@ public function testShouldGetNotificacoesCorrectly(): void
$this->assertInstanceOf($expected, $actual);
}

/**
* Testa obter a entidade Ordens de Produção.
*
* @return void
*/
public function testShouldGetOrdensDeProducaoCorrectly(): void
{
$expected = OrdensDeProducao::class;

$actual = $this->getInstance()->ordensDeProducao;

$this->assertInstanceOf($expected, $actual);
}

/**
* Testa obter a entidade Pedidos de Compras.
*
Expand Down
7 changes: 5 additions & 2 deletions src/Entities/Empresas/Schema/Get/GetResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
/**
* Constrói o objeto.
*
* @param ?string $id
* @param ?string $nome
* @param ?string $cnpj
* @param ?string $email
* @param ?string $dataContrato
*/
public function __construct(
public ?string $id,
public ?string $nome,
public ?string $cnpj,
public ?string $email,
) {
}
public ?string $dataContrato,
) {}
}
4 changes: 3 additions & 1 deletion src/Entities/Empresas/__tests__/get/response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"data": {
"id": "436c56a5679921f5f13a3d6433561773",
"nome": "Empresa Teste LTDA",
"cnpj": "12.345.657/8910-11",
"email": "empresa@email.com"
"email": "empresa@email.com",
"dataContrato": "2024-12-31"
}
}
176 changes: 176 additions & 0 deletions src/Entities/OrdensDeProducao/OrdensDeProducao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\OrdensDeProducao;

use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Get\GetParams;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Create\CreateResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Delete\DeleteResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Find\FindResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\GenerateOverDemand\GenerateOverDemandResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Get\GetResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Update\UpdateResponse;
use AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\ChangeSituation\ChangeSituationResponse;
use AleBatistella\BlingErpApi\Entities\Shared\BaseEntity;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Request\RequestOptions;
use AleBatistella\BlingErpApi\Exceptions\BlingApiException;
use AleBatistella\BlingErpApi\Exceptions\BlingInternalException;

/**
* Entidade para interação com ordens de produção.
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o
*/
class OrdensDeProducao extends BaseEntity
{
/**
* Remove uma ordem de produção.
*
* @param int $idOrdemProducao ID da ordem de produção
*
* @return null
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/delete_ordens_producao__idOrdemProducao_
*/
public function delete(int $idOrdemProducao): null
{
$response = $this->repository->destroy(
new RequestOptions(
endpoint: "ordens-producao/$idOrdemProducao"
)
);

return DeleteResponse::fromResponse($response);
}

/**
* Obtém ordens de produção.
*
* @param GetParams|array|null $params Parâmetros para a busca
*
* @return GetResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/get_ordens_producao
*/
public function get(GetParams|array|null $params = null): GetResponse
{
$response = $this->repository->index(
new RequestOptions(
endpoint: "ordens-producao",
queryParams: $params
)
);

return GetResponse::fromResponse($response);
}

/**
* Obtém uma ordem de produção.
*
* @param int $idOrdemProducao ID da ordem de produção
*
* @return FindResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/get_ordens_producao__idOrdemProducao_
*/
public function find(int $idOrdemProducao): FindResponse
{
$response = $this->repository->show(
new RequestOptions(
endpoint: "ordens-producao/$idOrdemProducao",
)
);

return FindResponse::fromResponse($response);
}

/**
* Cria uma ordem de produção.
*
* @param array $body Corpo da requisição
*
* @return CreateResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/post_ordens_producao
*/
public function create(array $body): CreateResponse
{
$response = $this->repository->store(
new RequestOptions(
endpoint: "ordens-producao",
body: $body
)
);

return CreateResponse::fromResponse($response);
}

/**
* Gera ordens de produção sob demanda.
*
* @return GenerateOverDemandResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/post_ordens_producao_gerar_sob_demanda
*/
public function generateOverDemand(): GenerateOverDemandResponse
{
$response = $this->repository->store(
new RequestOptions(
endpoint: "ordens-producao/gerar-sob-demanda"
)
);

return GenerateOverDemandResponse::fromResponse($response);
}

/**
* Altera uma ordem de produção.
*
* @param int $idOrdemProducao ID da ordem de produção
* @param array $body Corpo da requisição
*
* @return UpdateResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/put_ordens_producao__idOrdemProducao_
*/
public function update(int $idOrdemProducao, array $body): null
{
$response = $this->repository->replace(
new RequestOptions(
endpoint: "ordens-producao/$idOrdemProducao",
body: $body
)
);

return UpdateResponse::fromResponse($response);
}


/**
* Altera a situação de uma ordem de produção.
*
* @param int $idOrdemProducao ID da ordem de produção
* @param array $body Corpo da requisição
*
* @return ChangeSituationResponse
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/put_ordens_producao__idOrdemProducao__situacoes
*/
public function changeSituation(int $idOrdemProducao, array $body): null
{
$response = $this->repository->replace(
new RequestOptions(
endpoint: "ordens-producao/$idOrdemProducao/situacoes",
body: $body
)
);

return ChangeSituationResponse::fromResponse($response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\ChangeSituation;

use AleBatistella\BlingErpApi\Entities\Shared\BaseResponseRootObject;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Request\ResponseOptions;

/**
* Resposta da alteração da situação de uma ordem de produção pelo ID.
*/
readonly final class ChangeSituationResponse extends BaseResponseRootObject
{
/**
* @inheritDoc
*/
public static function fromResponse(ResponseOptions $response): null
{
if (!is_null($response->body?->content)) {
static::throwForInconsistentResponseOptions($response);
}

return null;
}
}
34 changes: 34 additions & 0 deletions src/Entities/OrdensDeProducao/Schema/Create/CreateResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Create;

use AleBatistella\BlingErpApi\Entities\Shared\BaseResponseRootObject;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Request\ResponseOptions;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Schema\Id;

/**
* Resposta da criação de uma ordem de produção.
*/
readonly final class CreateResponse extends BaseResponseRootObject
{
/**
* Constrói o objeto.
*
* @param Id $data
*/
public function __construct(
public Id $data
) {}

/**
* @inheritDoc
*/
public static function fromResponse(ResponseOptions $response): static
{
if (is_null($response->body?->content)) {
static::throwForInconsistentResponseOptions($response);
}

return self::from($response->body->content);
}
}
24 changes: 24 additions & 0 deletions src/Entities/OrdensDeProducao/Schema/Delete/DeleteResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\OrdensDeProducao\Schema\Delete;

use AleBatistella\BlingErpApi\Entities\Shared\BaseResponseRootObject;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Request\ResponseOptions;

/**
* Resposta da remoção de uma ordem de produção pelo ID.
*/
readonly final class DeleteResponse extends BaseResponseRootObject
{
/**
* @inheritDoc
*/
public static function fromResponse(ResponseOptions $response): null
{
if (!is_null($response->body?->content)) {
static::throwForInconsistentResponseOptions($response);
}

return null;
}
}
Loading

0 comments on commit 3d94d4b

Please sign in to comment.