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