1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity\Tradeability; |
4
|
|
|
|
5
|
|
|
use DomDocument; |
6
|
|
|
use DomElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class Shipment implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
const TRANSPORT_MODE_AIR = 1; |
12
|
|
|
const TRANSPORT_MODE_GROUND = 2; |
13
|
|
|
const TRANSPORT_MODE_RAIL = 3; |
14
|
|
|
const TRANSPORT_MODE_OCEAN = 4; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $originCountryCode; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $originStateProvinceCode; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $destinationCountryCode; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $destinationStateProvinceCode; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
private $transportationMode; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var FreightCharges |
43
|
|
|
*/ |
44
|
|
|
private $freightCharges; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var mixed |
48
|
|
|
*/ |
49
|
|
|
private $additionalInsurance; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $products = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
private $resultCurrencyCode; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var |
63
|
|
|
*/ |
64
|
|
|
private $transactionReferenceId; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var int |
68
|
|
|
*/ |
69
|
|
|
private $tariffCodeAlert; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param null|DOMDocument $document |
73
|
|
|
* |
74
|
|
|
* @return DOMNode |
75
|
|
|
*/ |
76
|
|
|
public function toNode(DOMDocument $document = null) |
77
|
|
|
{ |
78
|
|
|
if (null === $document) { |
79
|
|
|
$document = new DOMDocument(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$node = $document->createElement('Shipment'); |
83
|
|
|
|
84
|
|
|
if ($this->getFreightCharges() instanceof FreightCharges) { |
85
|
|
|
$node->appendChild($this->getFreightCharges()->toNode($document)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// Then the required values |
89
|
|
|
$node->appendChild($document->createElement('OriginCountryCode', $this->getOriginCountryCode())); |
90
|
|
|
$node->appendChild($document->createElement('DestinationCountryCode', $this->getDestinationCountryCode())); |
91
|
|
|
|
92
|
|
|
// Then the optional values |
93
|
|
|
if ($this->getOriginStateProvinceCode() !== null) { |
94
|
|
|
$node->appendChild( |
95
|
|
|
$document->createElement( |
96
|
|
|
'OriginStateProvinceCode', |
97
|
|
|
$this->getOriginStateProvinceCode() |
98
|
|
|
) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
if ($this->getDestinationStateProvinceCode() !== null) { |
102
|
|
|
$node->appendChild( |
103
|
|
|
$document->createElement( |
104
|
|
|
'DestinationStateProvinceCode', |
105
|
|
|
$this->getDestinationStateProvinceCode() |
106
|
|
|
) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
if ($this->getTransportationMode() !== null) { |
110
|
|
|
$node->appendChild($document->createElement('TransportationMode', $this->getTransportationMode())); |
111
|
|
|
} |
112
|
|
|
if ($this->getResultCurrencyCode() !== null) { |
113
|
|
|
$node->appendChild($document->createElement('ResultCurrencyCode', $this->getResultCurrencyCode())); |
114
|
|
|
} |
115
|
|
|
if ($this->getTariffCodeAlert() !== null) { |
116
|
|
|
$node->appendChild($document->createElement('TariffCodeAlert', $this->getTariffCodeAlert())); |
117
|
|
|
} |
118
|
|
|
if ($this->getTransactionReferenceId() !== null) { |
119
|
|
|
$node->appendChild($document->createElement('TransactionReferenceID', $this->getTransactionReferenceId())); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// Then products array |
123
|
|
|
foreach ($this->products as $product) { |
124
|
|
|
$node->appendChild($product->toNode($document)); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// Return created node |
128
|
|
|
return $node; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return mixed |
133
|
|
|
*/ |
134
|
|
|
public function getAdditionalInsurance() |
135
|
|
|
{ |
136
|
|
|
return $this->additionalInsurance; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param mixed $additionalInsurance |
141
|
|
|
* |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function setAdditionalInsurance($additionalInsurance) |
145
|
|
|
{ |
146
|
|
|
$this->additionalInsurance = $additionalInsurance; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return FreightCharges |
153
|
|
|
*/ |
154
|
|
|
public function getFreightCharges() |
155
|
|
|
{ |
156
|
|
|
return $this->freightCharges; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param FreightCharges $freightCharges |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setFreightCharges($freightCharges) |
164
|
|
|
{ |
165
|
|
|
$this->freightCharges = $freightCharges; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getOriginCountryCode() |
174
|
|
|
{ |
175
|
|
|
return $this->originCountryCode; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $originCountryCode |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
|
|
public function setOriginCountryCode($originCountryCode) |
183
|
|
|
{ |
184
|
|
|
$this->originCountryCode = $originCountryCode; |
185
|
|
|
|
186
|
|
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function getDestinationCountryCode() |
193
|
|
|
{ |
194
|
|
|
return $this->destinationCountryCode; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $destinationCountryCode |
199
|
|
|
* @return $this |
200
|
|
|
*/ |
201
|
|
|
public function setDestinationCountryCode($destinationCountryCode) |
202
|
|
|
{ |
203
|
|
|
$this->destinationCountryCode = $destinationCountryCode; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
public function getOriginStateProvinceCode() |
212
|
|
|
{ |
213
|
|
|
return $this->originStateProvinceCode; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param string $originStateProvinceCode |
218
|
|
|
* @return $this |
219
|
|
|
*/ |
220
|
|
|
public function setOriginStateProvinceCode($originStateProvinceCode) |
221
|
|
|
{ |
222
|
|
|
$this->originStateProvinceCode = $originStateProvinceCode; |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return string |
229
|
|
|
*/ |
230
|
|
|
public function getDestinationStateProvinceCode() |
231
|
|
|
{ |
232
|
|
|
return $this->destinationStateProvinceCode; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param string $destinationStateProvinceCode |
237
|
|
|
* @return $this |
238
|
|
|
*/ |
239
|
|
|
public function setDestinationStateProvinceCode($destinationStateProvinceCode) |
240
|
|
|
{ |
241
|
|
|
$this->destinationStateProvinceCode = $destinationStateProvinceCode; |
242
|
|
|
|
243
|
|
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return int |
248
|
|
|
*/ |
249
|
|
|
public function getTransportationMode() |
250
|
|
|
{ |
251
|
|
|
return $this->transportationMode; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param int $transportationMode |
256
|
|
|
* @return $this |
257
|
|
|
*/ |
258
|
|
|
public function setTransportationMode($transportationMode) |
259
|
|
|
{ |
260
|
|
|
$this->transportationMode = $transportationMode; |
261
|
|
|
|
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
|
|
public function getResultCurrencyCode() |
269
|
|
|
{ |
270
|
|
|
return $this->resultCurrencyCode; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param string $resultCurrencyCode |
275
|
|
|
* @return $this |
276
|
|
|
*/ |
277
|
|
|
public function setResultCurrencyCode($resultCurrencyCode) |
278
|
|
|
{ |
279
|
|
|
$this->resultCurrencyCode = $resultCurrencyCode; |
280
|
|
|
|
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return int |
286
|
|
|
*/ |
287
|
|
|
public function getTariffCodeAlert() |
288
|
|
|
{ |
289
|
|
|
return $this->tariffCodeAlert; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param int $tariffCodeAlert |
294
|
|
|
* @return Shipment |
295
|
|
|
*/ |
296
|
|
|
public function setTariffCodeAlert($tariffCodeAlert) |
297
|
|
|
{ |
298
|
|
|
$this->tariffCodeAlert = $tariffCodeAlert; |
299
|
|
|
|
300
|
|
|
return $this; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @return mixed |
305
|
|
|
*/ |
306
|
|
|
public function getTransactionReferenceId() |
307
|
|
|
{ |
308
|
|
|
return $this->transactionReferenceId; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param mixed $transactionReferenceId |
313
|
|
|
* @return $this |
314
|
|
|
*/ |
315
|
|
|
public function setTransactionReferenceId($transactionReferenceId) |
316
|
|
|
{ |
317
|
|
|
$this->transactionReferenceId = $transactionReferenceId; |
318
|
|
|
|
319
|
|
|
return $this; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @return array |
324
|
|
|
*/ |
325
|
|
|
public function getProducts() |
326
|
|
|
{ |
327
|
|
|
return $this->products; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @param array $products |
332
|
|
|
* @return $this |
333
|
|
|
*/ |
334
|
|
|
public function setProducts($products) |
335
|
|
|
{ |
336
|
|
|
$this->products = $products; |
337
|
|
|
|
338
|
|
|
return $this; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param Product $product |
343
|
|
|
* @return $this |
344
|
|
|
*/ |
345
|
|
|
public function addProduct(Product $product) |
346
|
|
|
{ |
347
|
|
|
array_push($this->products, $product); |
348
|
|
|
|
349
|
|
|
return $this; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|