1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Dolibarr\Client\Domain\Proposal; |
5
|
|
|
|
6
|
|
|
use Dolibarr\Client\Domain\Product\Product; |
7
|
|
|
use JMS\Serializer\Annotation as JMS; |
8
|
|
|
use Webmozart\Assert\Assert; |
9
|
|
|
|
10
|
|
|
final class ProposalProduct |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
* |
15
|
|
|
* @JMS\Type("string") |
16
|
|
|
* @JMS\SerializedName("desc") |
17
|
|
|
*/ |
18
|
|
|
private $description; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Unit price. |
22
|
|
|
* |
23
|
|
|
* @var float |
24
|
|
|
* |
25
|
|
|
* @JMS\Type("float") |
26
|
|
|
* @JMS\SerializedName("subprice") |
27
|
|
|
*/ |
28
|
|
|
private $unitPrice; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var float |
32
|
|
|
* |
33
|
|
|
* @JMS\Type("float") |
34
|
|
|
* @JMS\SerializedName("qty") |
35
|
|
|
*/ |
36
|
|
|
private $quantity; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var float |
40
|
|
|
* |
41
|
|
|
* @JMS\Type("float") |
42
|
|
|
* @JMS\SerializedName("tva_tx") |
43
|
|
|
*/ |
44
|
|
|
private $vatRate; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var int |
48
|
|
|
* |
49
|
|
|
* @JMS\Type("int") |
50
|
|
|
* @JMS\SerializedName("fk_product") |
51
|
|
|
*/ |
52
|
|
|
private $productId; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var float |
56
|
|
|
* |
57
|
|
|
* @JMS\Type("float") |
58
|
|
|
* @JMS\SerializedName("remise_percent") |
59
|
|
|
*/ |
60
|
|
|
private $discount; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param float $quantity |
64
|
|
|
* @param int $productId |
65
|
|
|
*/ |
66
|
|
|
public function __construct($quantity, $productId) |
67
|
|
|
{ |
68
|
|
|
Assert::greaterThan($quantity, 0); |
69
|
|
|
Assert::greaterThan($productId, 0); |
70
|
|
|
Assert::integerish($productId); |
71
|
|
|
|
72
|
|
|
$this->quantity = $quantity; |
73
|
|
|
$this->productId = (int)$productId; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function create(Quantity $quantity, Product $product) |
77
|
|
|
{ |
78
|
|
|
$proposalProduct = new self($quantity->getQuantity(), $product->getId()); |
|
|
|
|
79
|
|
|
$proposalProduct->setUnitPrice($product->getPriceHt()); |
80
|
|
|
$proposalProduct->setVatRate($product->getRateVat()); |
81
|
|
|
|
82
|
|
|
return $proposalProduct; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getDescription() |
90
|
|
|
{ |
91
|
|
|
return $this->description; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $description |
96
|
|
|
*/ |
97
|
|
|
public function setDescription($description) |
98
|
|
|
{ |
99
|
|
|
$this->description = $description; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return float |
104
|
|
|
*/ |
105
|
|
|
public function getUnitPrice() |
106
|
|
|
{ |
107
|
|
|
return $this->unitPrice; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param float $unitPrice |
112
|
|
|
*/ |
113
|
|
|
public function setUnitPrice($unitPrice) |
114
|
|
|
{ |
115
|
|
|
$this->unitPrice = $unitPrice; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return float |
120
|
|
|
*/ |
121
|
|
|
public function getQuantity() |
122
|
|
|
{ |
123
|
|
|
return $this->quantity; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param float $quantity |
128
|
|
|
*/ |
129
|
|
|
public function setQuantity($quantity) |
130
|
|
|
{ |
131
|
|
|
$this->quantity = $quantity; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return float |
136
|
|
|
*/ |
137
|
|
|
public function getVatRate() |
138
|
|
|
{ |
139
|
|
|
return $this->vatRate; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param float $vatRate |
144
|
|
|
*/ |
145
|
|
|
public function setVatRate($vatRate) |
146
|
|
|
{ |
147
|
|
|
$this->vatRate = $vatRate; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return int |
152
|
|
|
*/ |
153
|
|
|
public function getProductId() |
154
|
|
|
{ |
155
|
|
|
return $this->productId; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param int $productId |
160
|
|
|
*/ |
161
|
|
|
public function setProductId($productId) |
162
|
|
|
{ |
163
|
|
|
$this->productId = $productId; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return float |
168
|
|
|
*/ |
169
|
|
|
public function getDiscount() |
170
|
|
|
{ |
171
|
|
|
return $this->discount; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param float $discount |
176
|
|
|
*/ |
177
|
|
|
public function setDiscount($discount) |
178
|
|
|
{ |
179
|
|
|
$this->discount = $discount; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|