|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Billogram\Model\Customer; |
|
4
|
|
|
|
|
5
|
|
|
use Billogram\Model\CreatableFromArray; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class Customer implements CreatableFromArray |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
private $customerNo; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $name; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $notes; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $orgNo; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $vatNo; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var CustomerContact |
|
39
|
|
|
*/ |
|
40
|
|
|
private $contact; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var CustomerBillingAddress |
|
44
|
|
|
*/ |
|
45
|
|
|
private $address; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var CustomerDeliveryAddress |
|
49
|
|
|
*/ |
|
50
|
|
|
private $deliveryAddress; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var \DateTime |
|
54
|
|
|
*/ |
|
55
|
|
|
private $createdAt; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var \DateTime |
|
59
|
|
|
*/ |
|
60
|
|
|
private $updatedAt; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
private $companyType; |
|
66
|
|
|
|
|
67
|
8 |
|
public function __construct() |
|
68
|
|
|
{ |
|
69
|
8 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return int |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCustomerNo() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->customerNo; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $customerNo |
|
81
|
|
|
* |
|
82
|
|
|
* @return Customer |
|
83
|
|
|
*/ |
|
84
|
2 |
|
public function withCustomerNo(int $customerNo) |
|
85
|
|
|
{ |
|
86
|
2 |
|
$new = clone $this; |
|
87
|
2 |
|
$new->customerNo = $customerNo; |
|
88
|
|
|
|
|
89
|
2 |
|
return $new; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getName() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->name; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string $name |
|
102
|
|
|
* |
|
103
|
|
|
* @return Customer |
|
104
|
|
|
*/ |
|
105
|
2 |
|
public function withName(string $name) |
|
106
|
|
|
{ |
|
107
|
2 |
|
$new = clone $this; |
|
108
|
2 |
|
$new->name = $name; |
|
109
|
|
|
|
|
110
|
2 |
|
return $new; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getNotes() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->notes; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param string $notes |
|
123
|
|
|
* |
|
124
|
|
|
* @return Customer |
|
125
|
|
|
*/ |
|
126
|
2 |
|
public function withNotes(string $notes) |
|
127
|
|
|
{ |
|
128
|
2 |
|
$new = clone $this; |
|
129
|
2 |
|
$new->notes = $notes; |
|
130
|
|
|
|
|
131
|
2 |
|
return $new; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getOrgNo() |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->orgNo; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param string $orgNo |
|
144
|
|
|
* |
|
145
|
|
|
* @return Customer |
|
146
|
|
|
*/ |
|
147
|
2 |
|
public function withOrgNo(string $orgNo) |
|
148
|
|
|
{ |
|
149
|
2 |
|
$new = clone $this; |
|
150
|
2 |
|
$new->orgNo = $orgNo; |
|
151
|
|
|
|
|
152
|
2 |
|
return $new; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getVatNo() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->vatNo; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $vatNo |
|
165
|
|
|
* |
|
166
|
|
|
* @return Customer |
|
167
|
|
|
*/ |
|
168
|
2 |
|
public function withVatNo(string $vatNo) |
|
169
|
|
|
{ |
|
170
|
2 |
|
$new = clone $this; |
|
171
|
2 |
|
$new->vatNo = $vatNo; |
|
172
|
|
|
|
|
173
|
2 |
|
return $new; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return CustomerContact |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getContact() |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->contact; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param CustomerContact $contact |
|
186
|
|
|
* |
|
187
|
|
|
* @return Customer |
|
188
|
|
|
*/ |
|
189
|
2 |
|
public function withContact(CustomerContact $contact) |
|
190
|
|
|
{ |
|
191
|
2 |
|
$new = clone $this; |
|
192
|
2 |
|
$new->contact = $contact; |
|
193
|
|
|
|
|
194
|
2 |
|
return $new; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @return CustomerBillingAddress |
|
199
|
|
|
*/ |
|
200
|
|
|
public function getAddress() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->address; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param CustomerBillingAddress $address |
|
207
|
|
|
* |
|
208
|
|
|
* @return Customer |
|
209
|
|
|
*/ |
|
210
|
2 |
|
public function withAddress(CustomerBillingAddress $address) |
|
211
|
|
|
{ |
|
212
|
2 |
|
$new = clone $this; |
|
213
|
2 |
|
$new->address = $address; |
|
214
|
|
|
|
|
215
|
2 |
|
return $new; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return CustomerDeliveryAddress |
|
220
|
|
|
*/ |
|
221
|
|
|
public function getDeliveryAddress() |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->deliveryAddress; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @param CustomerDeliveryAddress $deliveryAddress |
|
228
|
|
|
* |
|
229
|
|
|
* @return Customer |
|
230
|
|
|
*/ |
|
231
|
2 |
|
public function withDeliveryAddress(CustomerDeliveryAddress $deliveryAddress) |
|
232
|
|
|
{ |
|
233
|
2 |
|
$new = clone $this; |
|
234
|
2 |
|
$new->deliveryAddress = $deliveryAddress; |
|
235
|
|
|
|
|
236
|
2 |
|
return $new; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @return string |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getCompanyType() |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->companyType; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param string $companyType |
|
249
|
|
|
* |
|
250
|
|
|
* @return Customer |
|
251
|
|
|
*/ |
|
252
|
2 |
|
public function withCompanyType(string $companyType) |
|
253
|
|
|
{ |
|
254
|
2 |
|
$new = clone $this; |
|
255
|
2 |
|
$new->companyType = $companyType; |
|
256
|
|
|
|
|
257
|
2 |
|
return $new; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @return \DateTime |
|
262
|
|
|
*/ |
|
263
|
|
|
public function getCreatedAt(): \DateTime |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->createdAt; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @return \DateTime |
|
270
|
|
|
*/ |
|
271
|
|
|
public function getUpdatedAt(): \DateTime |
|
272
|
|
|
{ |
|
273
|
|
|
return $this->updatedAt; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @param \DateTime $updatedAt |
|
278
|
|
|
*/ |
|
279
|
|
|
public function setUpdatedAt(\DateTime $updatedAt) |
|
280
|
|
|
{ |
|
281
|
|
|
$this->updatedAt = $updatedAt; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
8 |
|
public static function createFromArray(array $data): Customer |
|
285
|
|
|
{ |
|
286
|
8 |
|
$customer = new self(); |
|
287
|
8 |
|
if (array_key_exists('data', $data)) { |
|
288
|
4 |
|
$data = $data['data']; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
8 |
|
if (isset($data['address'])) { |
|
292
|
6 |
|
$customer->address = CustomerBillingAddress::createFromArray($data['address']); |
|
293
|
|
|
} |
|
294
|
8 |
|
if (isset($data['contact'])) { |
|
295
|
3 |
|
$customer->contact = CustomerContact::createFromArray($data['contact']); |
|
296
|
|
|
} |
|
297
|
8 |
|
if (isset($data['delivery_address'])) { |
|
298
|
3 |
|
$customer->deliveryAddress = CustomerDeliveryAddress::createFromArray($data['delivery_address']); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
8 |
|
$customer->customerNo = $customerArray['customer_no'] ?? null; |
|
302
|
8 |
|
$customer->name = $customerArray['name'] ?? null; |
|
303
|
8 |
|
$customer->notes = $customerArray['notes'] ?? null; |
|
304
|
8 |
|
$customer->orgNo = $customerArray['org_no'] ?? null; |
|
305
|
8 |
|
$customer->vatNo = $customerArray['vat_no'] ?? null; |
|
306
|
|
|
|
|
307
|
8 |
|
$customer->createdAt = $customerArray['created_at'] ?? null; |
|
308
|
8 |
|
$customer->updatedAt = $customerArray['updated_at'] ?? null; |
|
309
|
8 |
|
$customer->companyType = $customerArray['company_type'] ?? null; |
|
310
|
|
|
|
|
311
|
8 |
|
return $customer; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
4 |
|
public function toArray() |
|
315
|
|
|
{ |
|
316
|
4 |
|
$data = []; |
|
317
|
4 |
|
if ($this->customerNo !== null) { |
|
318
|
2 |
|
$data['customer_no'] = $this->customerNo; |
|
319
|
|
|
} |
|
320
|
4 |
|
if ($this->name !== null) { |
|
321
|
2 |
|
$data['name'] = $this->name; |
|
322
|
|
|
} |
|
323
|
4 |
|
if ($this->notes !== null) { |
|
324
|
2 |
|
$data['notes'] = $this->notes; |
|
325
|
|
|
} |
|
326
|
4 |
|
if ($this->orgNo !== null) { |
|
327
|
2 |
|
$data['org_no'] = $this->orgNo; |
|
328
|
|
|
} |
|
329
|
4 |
|
if ($this->vatNo !== null) { |
|
330
|
2 |
|
$data['vat_no'] = $this->vatNo ?? null; |
|
331
|
|
|
} |
|
332
|
4 |
|
if ($this->contact !== null) { |
|
333
|
2 |
|
$data['contact'] = $this->contact->toArray(); |
|
334
|
|
|
} |
|
335
|
4 |
|
if ($this->address !== null) { |
|
336
|
2 |
|
$data['address'] = $this->address->toArray(); |
|
337
|
|
|
} |
|
338
|
4 |
|
if ($this->deliveryAddress !== null) { |
|
339
|
2 |
|
$data['delivery_address'] = $this->deliveryAddress->toArray(); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
4 |
|
return $data; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|