1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DOMDocument; |
7
|
|
|
use DOMElement; |
8
|
|
|
use Ups\NodeInterface; |
9
|
|
|
|
10
|
|
|
class InternationalForms implements NodeInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $types = [ |
16
|
|
|
self::TYPE_INVOICE |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Form Types. |
21
|
|
|
*/ |
22
|
|
|
const TYPE_INVOICE = '01'; |
23
|
|
|
const TYPE_CO = '03'; |
24
|
|
|
const TYPE_NAFTA_CO = '04'; |
25
|
|
|
const TYPE_PARTIAL_INVOICE = '05'; |
26
|
|
|
const TYPE_PACKINGLIST = '06'; |
27
|
|
|
const TYPE_CUSTOMER_GENERATED_FORMS = '07'; |
28
|
|
|
const TYPE_AIR_FREIGHT_PACKING_LIST = '08'; |
29
|
|
|
const TYPE_CN22_FORMS = '09'; |
30
|
|
|
const TYPE_UPS_PREMIUM_CARE = '10'; |
31
|
|
|
const TYPE_EEI_SHIPMENT_WITH_RETURN_SERVICE = '11'; |
32
|
|
|
|
33
|
|
|
private static $typeNames = [ |
34
|
|
|
'01' => 'Invoice', |
35
|
|
|
'03' => 'CO', |
36
|
|
|
'04' => 'NAFTA CO', |
37
|
|
|
'05' => 'Partial Invoice', |
38
|
|
|
'06' => 'Packinglist', |
39
|
|
|
'07' => 'Customer Generated Forms', |
40
|
|
|
'08' => 'Air Freight Packing List', |
41
|
|
|
'09' => 'CN22 Forms', |
42
|
|
|
'10' => 'UPS Premium Care', |
43
|
|
|
'11' => 'EEI. For shipment with return service', |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $termsOfShipment; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Terms of Shipment. |
53
|
|
|
*/ |
54
|
|
|
const TOS_COST_AND_FREIGHT = 'CFR'; |
55
|
|
|
const TOS_COST_INSURANCE_AND_FREIGHT = 'CIF'; |
56
|
|
|
const TOS_CARRIAGE_AND_INSURANCE_PAID = 'CIP'; |
57
|
|
|
const TOS_CARRIAGE_PAID_TO = 'CPT'; |
58
|
|
|
const TOS_DELIVERED_AT_FRONTIER = 'DAF'; |
59
|
|
|
const TOS_DELIVERY_DUTY_PAID = 'DDP'; |
60
|
|
|
const TOS_DELIVERY_DUTY_UNPAID = 'DDU'; |
61
|
|
|
const TOS_DELIVERED_EX_QUAY = 'DEQ'; |
62
|
|
|
const TOS_DELIVERED_EX_SHIP = 'DES'; |
63
|
|
|
const TOS_EX_WORKS = 'EXW'; |
64
|
|
|
const TOS_FREE_ALONGSIDE_SHIP = 'FAS'; |
65
|
|
|
const TOS_FREE_CARRIER = 'FCA'; |
66
|
|
|
const TOS_FREE_ON_BOARD = 'FOB'; |
67
|
|
|
|
68
|
|
|
private static $termsOfShipmentNames = [ |
|
|
|
|
69
|
|
|
'CFR' => 'Cost and Freight', |
70
|
|
|
'CIF' => 'Cost, Insurance and Freight', |
71
|
|
|
'CIP' => 'Carriage and Insurance Paid', |
72
|
|
|
'CPT' => 'Carriage Paid To', |
73
|
|
|
'DAF' => 'Delivered at Frontier', |
74
|
|
|
'DDP' => 'Delivery Duty Paid', |
75
|
|
|
'DDU' => 'Delivery Duty Unpaid', |
76
|
|
|
'DEQ' => 'Delivered Ex Quay', |
77
|
|
|
'DES' => 'Delivered Ex Ship', |
78
|
|
|
'EXW' => 'Ex Works', |
79
|
|
|
'FAS' => 'Free Alongside Ship', |
80
|
|
|
'FCA' => 'Free Carrier', |
81
|
|
|
'FOB' => 'Free On Board', |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var string |
86
|
|
|
*/ |
87
|
|
|
private $reasonForExport; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Reasons for export. |
91
|
|
|
*/ |
92
|
|
|
const RFE_SALE = 'SALE'; |
93
|
|
|
const RFE_GIFT = 'GIFT'; |
94
|
|
|
const RFE_SAMPLE = 'SAMPLE'; |
95
|
|
|
const RFE_RETURN = 'RETURN'; |
96
|
|
|
const RFE_REPAIR = 'REPAIR'; |
97
|
|
|
const RFE_INTERCOMPANYDATA = 'INTERCOMPANYDATA'; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
private $comments; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
private $currencyCode; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var string |
111
|
|
|
*/ |
112
|
|
|
private $invoiceNumber; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var DateTime |
116
|
|
|
*/ |
117
|
|
|
private $invoiceDate; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var string |
121
|
|
|
*/ |
122
|
|
|
private $purchaseOrderNumber; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var array |
126
|
|
|
*/ |
127
|
|
|
private $products = []; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var Discount |
131
|
|
|
*/ |
132
|
|
|
private $discount; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var FreightCharges |
136
|
|
|
*/ |
137
|
|
|
private $freightCharges; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @var bool |
141
|
|
|
*/ |
142
|
|
|
private $additionalDocumentIndicator; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @var EEIFilingOption |
146
|
|
|
*/ |
147
|
|
|
private $eeiFilingOption; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
|
|
public static function getFormTypes() |
153
|
|
|
{ |
154
|
|
|
return self::$typeNames; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $type |
159
|
|
|
* |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getFormTypeName($type) |
163
|
|
|
{ |
164
|
|
|
return self::$typeNames[$type]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param null|object $attributes |
169
|
|
|
*/ |
170
|
4 |
|
public function __construct($attributes = null) |
171
|
|
|
{ |
172
|
4 |
|
if (null !== $attributes) { |
173
|
2 |
|
if (isset($attributes->FormType)) { |
174
|
|
|
$this->setType($attributes->FormType); |
175
|
|
|
} |
176
|
2 |
|
if (isset($attributes->InvoiceNumber)) { |
177
|
|
|
$this->setInvoiceNumber($attributes->InvoiceNumber); |
178
|
|
|
} |
179
|
2 |
|
if (isset($attributes->InvoiceDate)) { |
180
|
|
|
$this->setInvoiceDate(new DateTime($attributes->InvoiceDate)); |
181
|
|
|
} |
182
|
2 |
|
if (isset($attributes->PurchaseOrderNumber)) { |
183
|
|
|
$this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber); |
184
|
|
|
} |
185
|
2 |
|
if (isset($attributes->TermsOfShipment)) { |
186
|
|
|
$this->setTermsOfShipment($attributes->TermsOfShipment); |
187
|
|
|
} |
188
|
2 |
|
if (isset($attributes->Comments)) { |
189
|
|
|
$this->setComments($attributes->Comments); |
190
|
|
|
} |
191
|
2 |
|
if (isset($attributes->CurrencyCode)) { |
192
|
|
|
$this->setCurrencyCode($attributes->CurrencyCode); |
193
|
|
|
} |
194
|
2 |
|
if (isset($attributes->EEIFilingOption)) { |
195
|
2 |
|
$this->setEEIFilingOption(new EEIFilingOption($attributes->EEIFilingOption)); |
196
|
2 |
|
} |
197
|
2 |
|
} |
198
|
4 |
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param $type string |
202
|
|
|
* |
203
|
|
|
* @return $this |
204
|
|
|
*/ |
205
|
|
|
public function setType($type) |
206
|
|
|
{ |
207
|
|
|
return $this->setTypes([$type]); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param array $types |
212
|
|
|
* |
213
|
|
|
* @return $this |
214
|
|
|
*/ |
215
|
|
|
public function setTypes(array $types) |
216
|
|
|
{ |
217
|
|
|
$this->types = $types; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
2 |
|
public function getTypes() |
226
|
|
|
{ |
227
|
2 |
|
return $this->types; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param $freightCharges FreightCharges |
232
|
|
|
* |
233
|
|
|
* @return $this |
234
|
|
|
*/ |
235
|
|
|
public function setFreightCharges(FreightCharges $freightCharges) |
236
|
|
|
{ |
237
|
|
|
$this->freightCharges = $freightCharges; |
238
|
|
|
|
239
|
|
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return FreightCharges |
244
|
|
|
*/ |
245
|
2 |
|
public function getFreightCharges() |
246
|
|
|
{ |
247
|
2 |
|
return $this->freightCharges; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param $discount Discount |
252
|
|
|
* |
253
|
|
|
* @return $this |
254
|
|
|
*/ |
255
|
|
|
public function setDiscount(Discount $discount) |
256
|
|
|
{ |
257
|
|
|
$this->discount = $discount; |
258
|
|
|
|
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @return Discount |
264
|
|
|
*/ |
265
|
2 |
|
public function getDiscount() |
266
|
|
|
{ |
267
|
2 |
|
return $this->discount; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param Product $product |
272
|
|
|
* |
273
|
|
|
* @return $this |
274
|
|
|
*/ |
275
|
|
|
public function addProduct(Product $product) |
276
|
|
|
{ |
277
|
|
|
array_push($this->products, $product); |
278
|
|
|
|
279
|
|
|
return $this; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return array |
284
|
|
|
*/ |
285
|
|
|
public function getProducts() |
286
|
|
|
{ |
287
|
|
|
return $this->products; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param null|DOMDocument $document |
292
|
|
|
* |
293
|
|
|
* @return DOMElement |
294
|
|
|
*/ |
295
|
2 |
|
public function toNode(DOMDocument $document = null) |
296
|
|
|
{ |
297
|
2 |
|
if (null === $document) { |
298
|
|
|
$document = new DOMDocument(); |
299
|
|
|
} |
300
|
|
|
|
301
|
2 |
|
$node = $document->createElement('InternationalForms'); |
302
|
|
|
|
303
|
2 |
|
foreach ($this->getTypes() as $type) { |
304
|
2 |
|
$node->appendChild($document->createElement('FormType', $type)); |
305
|
2 |
|
} |
306
|
2 |
|
if ($this->getInvoiceNumber() !== null) { |
307
|
|
|
$node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber())); |
308
|
|
|
} |
309
|
2 |
|
if ($this->getInvoiceDate() !== null) { |
310
|
|
|
$node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd'))); |
311
|
|
|
} |
312
|
2 |
|
if ($this->getPurchaseOrderNumber() !== null) { |
313
|
|
|
$node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber())); |
314
|
|
|
} |
315
|
2 |
|
if ($this->getTermsOfShipment() !== null) { |
316
|
|
|
$node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment())); |
317
|
|
|
} |
318
|
2 |
|
if ($this->getReasonForExport() !== null) { |
319
|
|
|
$node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport())); |
320
|
|
|
} |
321
|
2 |
|
if ($this->getComments() !== null) { |
322
|
|
|
$node->appendChild($document->createElement('Comments', $this->getComments())); |
323
|
|
|
} |
324
|
2 |
|
if ($this->getCurrencyCode() !== null) { |
325
|
|
|
$node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode())); |
326
|
|
|
} |
327
|
2 |
|
if ($this->getDiscount() !== null) { |
328
|
|
|
$node->appendChild($this->getDiscount()->toNode($document)); |
329
|
|
|
} |
330
|
2 |
|
if ($this->getFreightCharges() !== null) { |
331
|
|
|
$node->appendChild($this->getFreightCharges()->toNode($document)); |
332
|
|
|
} |
333
|
2 |
|
if ($this->getAdditionalDocumentIndicator() !== null) { |
334
|
|
|
$node->appendChild($document->createElement('AdditionalDocumentIndicator')); |
335
|
|
|
} |
336
|
2 |
|
if ($this->getEEIFilingOption() !== null) { |
337
|
1 |
|
$node->appendChild($this->getEEIFilingOption()->toNode($document)); |
338
|
1 |
|
} |
339
|
2 |
|
foreach ($this->products as $product) { |
340
|
|
|
$node->appendChild($product->toNode($document)); |
341
|
2 |
|
} |
342
|
|
|
|
343
|
2 |
|
return $node; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param $number string |
348
|
|
|
* |
349
|
|
|
* @return $this |
350
|
|
|
*/ |
351
|
|
|
public function setInvoiceNumber($number) |
352
|
|
|
{ |
353
|
|
|
$this->invoiceNumber = $number; |
354
|
|
|
|
355
|
|
|
return $this; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @return string |
360
|
|
|
*/ |
361
|
2 |
|
public function getInvoiceNumber() |
362
|
|
|
{ |
363
|
2 |
|
return $this->invoiceNumber; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @param DateTime $date |
368
|
|
|
* |
369
|
|
|
* @return $this |
370
|
|
|
*/ |
371
|
|
|
public function setInvoiceDate(DateTime $date) |
372
|
|
|
{ |
373
|
|
|
$this->invoiceDate = $date; |
374
|
|
|
|
375
|
|
|
return $this; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return DateTime |
380
|
|
|
*/ |
381
|
2 |
|
public function getInvoiceDate() |
382
|
|
|
{ |
383
|
2 |
|
return $this->invoiceDate; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @param $number |
388
|
|
|
* |
389
|
|
|
* @return $this |
390
|
|
|
*/ |
391
|
|
|
public function setPurchaseOrderNumber($number) |
392
|
|
|
{ |
393
|
|
|
$this->purchaseOrderNumber = $number; |
394
|
|
|
|
395
|
|
|
return $this; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @return string |
400
|
|
|
*/ |
401
|
2 |
|
public function getPurchaseOrderNumber() |
402
|
|
|
{ |
403
|
2 |
|
return $this->purchaseOrderNumber; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @param $terms |
408
|
|
|
* |
409
|
|
|
* @return $this |
410
|
|
|
*/ |
411
|
|
|
public function setTermsOfShipment($terms) |
412
|
|
|
{ |
413
|
|
|
$this->termsOfShipment = $terms; |
414
|
|
|
|
415
|
|
|
return $this; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @return string |
420
|
|
|
*/ |
421
|
2 |
|
public function getTermsOfShipment() |
422
|
|
|
{ |
423
|
2 |
|
return $this->termsOfShipment; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @param $reason |
428
|
|
|
* |
429
|
|
|
* @return $this |
430
|
|
|
*/ |
431
|
|
|
public function setReasonForExport($reason) |
432
|
|
|
{ |
433
|
|
|
if (strlen($reason) > 20) { |
434
|
|
|
$reason = substr($reason, 0, 20); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
$this->reasonForExport = $reason; |
438
|
|
|
|
439
|
|
|
return $this; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return string |
444
|
|
|
*/ |
445
|
2 |
|
public function getReasonForExport() |
446
|
|
|
{ |
447
|
2 |
|
return $this->reasonForExport; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @param $comments |
452
|
|
|
* |
453
|
|
|
* @return $this |
454
|
|
|
*/ |
455
|
|
View Code Duplication |
public function setComments($comments) |
|
|
|
|
456
|
|
|
{ |
457
|
|
|
if (strlen($comments) > 150) { |
458
|
|
|
$comments = substr($comments, 0, 150); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
$this->comments = $comments; |
462
|
|
|
|
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return string |
468
|
|
|
*/ |
469
|
2 |
|
public function getComments() |
470
|
|
|
{ |
471
|
2 |
|
return $this->comments; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* @param $code |
476
|
|
|
* |
477
|
|
|
* @return $this |
478
|
|
|
*/ |
479
|
|
|
public function setCurrencyCode($code) |
480
|
|
|
{ |
481
|
|
|
$this->currencyCode = $code; |
482
|
|
|
|
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* @return string |
488
|
|
|
*/ |
489
|
2 |
|
public function getCurrencyCode() |
490
|
|
|
{ |
491
|
2 |
|
return $this->currencyCode; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* @param $additionalDocumentIndicator |
496
|
|
|
* |
497
|
|
|
* @return $this |
498
|
|
|
*/ |
499
|
|
|
public function setAdditionalDocumentIndicator($additionalDocumentIndicator) |
500
|
|
|
{ |
501
|
|
|
$this->additionalDocumentIndicator = $additionalDocumentIndicator; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @return bool |
506
|
|
|
*/ |
507
|
2 |
|
public function getAdditionalDocumentIndicator() |
508
|
|
|
{ |
509
|
2 |
|
return $this->additionalDocumentIndicator; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* @param EEIFilingOption $eeiFilingOption |
514
|
|
|
* |
515
|
|
|
* @return $this |
516
|
|
|
*/ |
517
|
3 |
|
public function setEEIFilingOption(EEIFilingOption $eeiFilingOption) |
518
|
|
|
{ |
519
|
3 |
|
$this->eeiFilingOption = $eeiFilingOption; |
520
|
|
|
|
521
|
3 |
|
return $this; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @return EEIFilingOption |
526
|
|
|
*/ |
527
|
4 |
|
public function getEEIFilingOption() |
528
|
|
|
{ |
529
|
4 |
|
return $this->eeiFilingOption; |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.