laudeco /
dolibarr-api-client
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dolibarr\Client\Service; |
||
| 4 | |||
| 5 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 6 | use Dolibarr\Client\Domain\Product\ProductId; |
||
| 7 | use Dolibarr\Client\Domain\Resource\ApiResource; |
||
| 8 | use Dolibarr\Client\Domain\Resource\ResourceId; |
||
| 9 | use Dolibarr\Client\Domain\StockMovement\StockMovement; |
||
| 10 | use Dolibarr\Client\Domain\StockMovement\StockMovementId; |
||
| 11 | use Dolibarr\Client\Domain\Warehouse\WarehouseId; |
||
| 12 | use Dolibarr\Client\Exception\ApiException; |
||
| 13 | use Dolibarr\Client\HttpClient\HttpClientInterface; |
||
| 14 | use JMS\Serializer\SerializerInterface; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @author Laurent De Coninck <[email protected]> |
||
| 18 | */ |
||
| 19 | final class StockMovementsService extends AbstractService |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param HttpClientInterface $httpClient |
||
| 24 | * @param SerializerInterface $serializerInterface |
||
| 25 | */ |
||
| 26 | public function __construct(HttpClientInterface $httpClient, SerializerInterface $serializerInterface) |
||
| 27 | { |
||
| 28 | parent::__construct($httpClient, $serializerInterface, new ApiResource('stockmovements')); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param StockMovement $movement |
||
| 33 | * |
||
| 34 | * @return StockMovementId |
||
| 35 | * |
||
| 36 | * @throws ApiException |
||
| 37 | */ |
||
| 38 | public function create(StockMovement $movement) |
||
| 39 | { |
||
| 40 | $resourceId = new ResourceId($this->post($this->serialize($movement))); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | |||
| 42 | return StockMovementId::fromResourceId($resourceId); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param WarehouseId $warehouseId |
||
| 47 | * |
||
| 48 | * @return ArrayCollection|StockMovement[] |
||
| 49 | * |
||
| 50 | * @throws ApiException |
||
| 51 | */ |
||
| 52 | public function getByWarehouse(WarehouseId $warehouseId) |
||
| 53 | { |
||
| 54 | $resources = $this->getList(['query' => [ |
||
| 55 | 'sqlfilters' => 'fk_entrepot='.$warehouseId->getId() |
||
| 56 | ]]); |
||
| 57 | |||
| 58 | return $this->deserializeCollection($resources, StockMovement::class); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param ProductId $productId |
||
| 63 | * |
||
| 64 | * @return ArrayCollection|StockMovement[] |
||
| 65 | * |
||
| 66 | * @throws ApiException |
||
| 67 | */ |
||
| 68 | public function getByProduct(ProductId $productId) |
||
| 69 | { |
||
| 70 | $resources = $this->getList(['query' => [ |
||
| 71 | 'sqlfilters' => 'fk_product='.$productId->getId() |
||
| 72 | ]]); |
||
| 73 | |||
| 74 | return $this->deserializeCollection($resources, StockMovement::class); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |