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 $declarationStatement; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var string |
111
|
|
|
*/ |
112
|
|
|
private $currencyCode; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var string |
116
|
|
|
*/ |
117
|
|
|
private $invoiceNumber; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var DateTime |
121
|
|
|
*/ |
122
|
|
|
private $invoiceDate; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var string |
126
|
|
|
*/ |
127
|
|
|
private $purchaseOrderNumber; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var array |
131
|
|
|
*/ |
132
|
|
|
private $products = []; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var Discount |
136
|
|
|
*/ |
137
|
|
|
private $discount; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @var FreightCharges |
141
|
|
|
*/ |
142
|
|
|
private $freightCharges; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @var OtherCharges |
146
|
|
|
*/ |
147
|
|
|
private $otherCharges; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @var string $declarationStatement |
151
|
|
|
*/ |
152
|
|
|
private $declarationStatement; |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return array |
157
|
|
|
*/ |
158
|
|
|
public static function getFormTypes() |
159
|
|
|
{ |
160
|
|
|
return self::$typeNames; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string $type |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getFormTypeName($type) |
169
|
|
|
{ |
170
|
|
|
return self::$typeNames[$type]; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param null|object $attributes |
175
|
4 |
|
*/ |
176
|
|
|
public function __construct($attributes = null) |
177
|
4 |
|
{ |
178
|
2 |
|
if (null !== $attributes) { |
179
|
|
|
if (isset($attributes->FormType)) { |
180
|
|
|
$this->setType($attributes->FormType); |
181
|
2 |
|
} |
182
|
|
|
if (isset($attributes->InvoiceNumber)) { |
183
|
|
|
$this->setInvoiceNumber($attributes->InvoiceNumber); |
184
|
2 |
|
} |
185
|
|
|
if (isset($attributes->InvoiceDate)) { |
186
|
|
|
$this->setInvoiceDate(new DateTime($attributes->InvoiceDate)); |
187
|
2 |
|
} |
188
|
|
|
if (isset($attributes->PurchaseOrderNumber)) { |
189
|
|
|
$this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber); |
190
|
2 |
|
} |
191
|
|
|
if (isset($attributes->TermsOfShipment)) { |
192
|
|
|
$this->setTermsOfShipment($attributes->TermsOfShipment); |
193
|
2 |
|
} |
194
|
|
|
if (isset($attributes->Comments)) { |
195
|
|
|
$this->setComments($attributes->Comments); |
196
|
2 |
|
} |
197
|
|
|
if (isset($attributes->DeclarationStatement)) { |
198
|
|
|
$this->setDeclarationStatement($attributes->DeclarationStatement); |
199
|
2 |
|
} |
200
|
|
|
if (isset($attributes->CurrencyCode)) { |
201
|
|
|
$this->setCurrencyCode($attributes->CurrencyCode); |
202
|
2 |
|
} |
203
|
2 |
|
if (isset($attributes->DeclarationStatement)) { |
204
|
2 |
|
$this->setDeclarationStatement($attributes->DeclarationStatement); |
205
|
2 |
|
|
206
|
4 |
|
} |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param $type string |
212
|
|
|
* |
213
|
|
|
* @return $this |
214
|
|
|
*/ |
215
|
|
|
public function setType($type) |
216
|
|
|
{ |
217
|
|
|
return $this->setTypes([$type]); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param array $types |
222
|
|
|
* |
223
|
|
|
* @return $this |
224
|
|
|
*/ |
225
|
|
|
public function setTypes(array $types) |
226
|
|
|
{ |
227
|
|
|
$this->types = $types; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
2 |
|
* @return string |
234
|
|
|
*/ |
235
|
2 |
|
public function getTypes() |
236
|
|
|
{ |
237
|
|
|
return $this->types; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param $freightCharges FreightCharges |
242
|
|
|
* |
243
|
|
|
* @return $this |
244
|
|
|
*/ |
245
|
|
|
public function setFreightCharges(FreightCharges $freightCharges) |
246
|
|
|
{ |
247
|
|
|
$this->freightCharges = $freightCharges; |
248
|
|
|
|
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
2 |
|
* @return FreightCharges |
254
|
|
|
*/ |
255
|
2 |
|
public function getFreightCharges() |
256
|
|
|
{ |
257
|
|
|
return $this->freightCharges; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @param $discount Discount |
262
|
|
|
* |
263
|
|
|
* @return $this |
264
|
|
|
*/ |
265
|
|
|
public function setDiscount(Discount $discount) |
266
|
|
|
{ |
267
|
|
|
$this->discount = $discount; |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
2 |
|
* @return Discount |
274
|
|
|
*/ |
275
|
2 |
|
public function getDiscount() |
276
|
|
|
{ |
277
|
|
|
return $this->discount; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param \Ups\Entity\OtherCharges $otherCharges |
282
|
|
|
* |
283
|
|
|
* @return $this |
284
|
|
|
*/ |
285
|
|
|
public function setOtherCharges(OtherCharges $otherCharges) |
286
|
|
|
{ |
287
|
|
|
$this->otherCharges = $otherCharges; |
288
|
|
|
|
289
|
|
|
return $this; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @return OtherCharges |
294
|
|
|
*/ |
295
|
|
|
public function getOtherCharges() |
296
|
|
|
{ |
297
|
|
|
return $this->otherCharges; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @param Product $product |
302
|
|
|
* |
303
|
2 |
|
* @return $this |
304
|
|
|
*/ |
305
|
2 |
|
public function addProduct(Product $product) |
306
|
|
|
{ |
307
|
|
|
array_push($this->products, $product); |
308
|
|
|
|
309
|
2 |
|
return $this; |
310
|
|
|
} |
311
|
2 |
|
|
312
|
2 |
|
/** |
313
|
2 |
|
* @return array |
314
|
2 |
|
*/ |
315
|
|
|
public function getProducts() |
316
|
|
|
{ |
317
|
2 |
|
return $this->products; |
318
|
|
|
} |
319
|
|
|
|
320
|
2 |
|
/** |
321
|
|
|
* @param null|DOMDocument $document |
322
|
|
|
* |
323
|
2 |
|
* @return DOMElement |
324
|
|
|
*/ |
325
|
|
|
public function toNode(DOMDocument $document = null) |
326
|
2 |
|
{ |
327
|
|
|
if (null === $document) { |
328
|
|
|
$document = new DOMDocument(); |
329
|
2 |
|
} |
330
|
|
|
|
331
|
|
|
$node = $document->createElement('InternationalForms'); |
332
|
2 |
|
|
333
|
|
|
foreach ($this->getTypes() as $type) { |
334
|
|
|
$node->appendChild($document->createElement('FormType', $type)); |
335
|
2 |
|
} |
336
|
|
|
if ($this->getInvoiceNumber() !== null) { |
337
|
|
|
$node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber())); |
338
|
2 |
|
} |
339
|
|
|
if ($this->getInvoiceDate() !== null) { |
340
|
|
|
$node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd'))); |
341
|
2 |
|
} |
342
|
|
|
if ($this->getPurchaseOrderNumber() !== null) { |
343
|
|
|
$node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber())); |
344
|
2 |
|
} |
345
|
|
|
if ($this->getTermsOfShipment() !== null) { |
346
|
|
|
$node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment())); |
347
|
2 |
|
} |
348
|
1 |
|
if ($this->getReasonForExport() !== null) { |
349
|
1 |
|
$node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport())); |
350
|
2 |
|
} |
351
|
|
|
if ($this->getComments() !== null) { |
352
|
2 |
|
$node->appendChild($document->createElement('Comments', $this->getComments())); |
353
|
|
|
} |
354
|
2 |
|
if ($this->getDeclarationStatement() !== null) { |
355
|
|
|
$node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement())); |
356
|
|
|
} |
357
|
|
|
if ($this->getCurrencyCode() !== null) { |
358
|
|
|
$node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode())); |
359
|
|
|
} |
360
|
|
|
if ($this->getDeclarationStatement() !== null) { |
361
|
|
|
$node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement())); |
362
|
|
|
} |
363
|
|
|
if ($this->getDiscount() !== null) { |
364
|
|
|
$node->appendChild($this->getDiscount()->toNode($document)); |
365
|
|
|
} |
366
|
|
|
if ($this->getFreightCharges() !== null) { |
367
|
|
|
$node->appendChild($this->getFreightCharges()->toNode($document)); |
368
|
|
|
} |
369
|
|
|
if ($this->getOtherCharges() !== null) { |
370
|
|
|
$node->appendChild($this->getOtherCharges()->toNode($document)); |
371
|
|
|
|
372
|
2 |
|
} |
373
|
|
|
foreach ($this->products as $product) { |
374
|
2 |
|
$node->appendChild($product->toNode($document)); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
return $node; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @param $number string |
382
|
|
|
* |
383
|
|
|
* @return $this |
384
|
|
|
*/ |
385
|
|
|
public function setInvoiceNumber($number) |
386
|
|
|
{ |
387
|
|
|
$this->invoiceNumber = $number; |
388
|
|
|
|
389
|
|
|
return $this; |
390
|
|
|
} |
391
|
|
|
|
392
|
2 |
|
/** |
393
|
|
|
* @return string |
394
|
2 |
|
*/ |
395
|
|
|
public function getInvoiceNumber() |
396
|
|
|
{ |
397
|
|
|
return $this->invoiceNumber; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @param DateTime $date |
402
|
|
|
* |
403
|
|
|
* @return $this |
404
|
|
|
*/ |
405
|
|
|
public function setInvoiceDate(DateTime $date) |
406
|
|
|
{ |
407
|
|
|
$this->invoiceDate = $date; |
408
|
|
|
|
409
|
|
|
return $this; |
410
|
|
|
} |
411
|
|
|
|
412
|
2 |
|
/** |
413
|
|
|
* @return DateTime |
414
|
2 |
|
*/ |
415
|
|
|
public function getInvoiceDate() |
416
|
|
|
{ |
417
|
|
|
return $this->invoiceDate; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* @param $number |
422
|
|
|
* |
423
|
|
|
* @return $this |
424
|
|
|
*/ |
425
|
|
|
public function setPurchaseOrderNumber($number) |
426
|
|
|
{ |
427
|
|
|
$this->purchaseOrderNumber = $number; |
428
|
|
|
|
429
|
|
|
return $this; |
430
|
|
|
} |
431
|
|
|
|
432
|
2 |
|
/** |
433
|
|
|
* @return string |
434
|
2 |
|
*/ |
435
|
|
|
public function getPurchaseOrderNumber() |
436
|
|
|
{ |
437
|
|
|
return $this->purchaseOrderNumber; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* @param $terms |
442
|
|
|
* |
443
|
|
|
* @return $this |
444
|
|
|
*/ |
445
|
|
|
public function setTermsOfShipment($terms) |
446
|
|
|
{ |
447
|
|
|
$this->termsOfShipment = $terms; |
448
|
|
|
|
449
|
|
|
return $this; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @return string |
454
|
|
|
*/ |
455
|
|
|
public function getTermsOfShipment() |
456
|
2 |
|
{ |
457
|
|
|
return $this->termsOfShipment; |
458
|
2 |
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* @param $reason |
462
|
|
|
* |
463
|
|
|
* @return $this |
464
|
|
|
*/ |
465
|
|
|
public function setReasonForExport($reason) |
466
|
|
|
{ |
467
|
|
|
if (strlen($reason) > 20) { |
468
|
|
|
$reason = substr($reason, 0, 20); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
$this->reasonForExport = $reason; |
472
|
|
|
|
473
|
|
|
return $this; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @return string |
478
|
|
|
*/ |
479
|
|
|
public function getReasonForExport() |
480
|
2 |
|
{ |
481
|
|
|
return $this->reasonForExport; |
482
|
2 |
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @param $comments |
486
|
|
|
* |
487
|
|
|
* @return $this |
488
|
|
|
*/ |
489
|
|
View Code Duplication |
public function setComments($comments) |
|
|
|
|
490
|
|
|
{ |
491
|
|
|
if (strlen($comments) > 150) { |
492
|
|
|
$comments = substr($comments, 0, 150); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
$this->comments = $comments; |
496
|
|
|
|
497
|
|
|
return $this; |
498
|
|
|
} |
499
|
|
|
|
500
|
2 |
|
/** |
501
|
|
|
* @return string |
502
|
2 |
|
*/ |
503
|
|
|
public function getComments() |
504
|
|
|
{ |
505
|
|
|
return $this->comments; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* @param string $statement |
510
|
|
|
* |
511
|
|
|
* @return $this |
512
|
|
|
*/ |
513
|
|
|
public function setDeclarationStatement($statement) |
514
|
|
|
{ |
515
|
|
|
$this->declarationStatement = $statement; |
516
|
|
|
|
517
|
|
|
return $this; |
518
|
|
|
} |
519
|
|
|
|
520
|
2 |
|
/** |
521
|
|
|
* @return string |
522
|
2 |
|
*/ |
523
|
|
|
public function getDeclarationStatement() |
524
|
|
|
{ |
525
|
|
|
return $this->declarationStatement; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* @param $code |
530
|
|
|
* |
531
|
|
|
* @return $this |
532
|
|
|
*/ |
533
|
|
|
public function setCurrencyCode($code) |
534
|
|
|
{ |
535
|
|
|
$this->currencyCode = $code; |
536
|
|
|
|
537
|
|
|
return $this; |
538
|
2 |
|
} |
539
|
|
|
|
540
|
2 |
|
/** |
541
|
|
|
* @return string |
542
|
|
|
*/ |
543
|
|
|
public function getCurrencyCode() |
544
|
|
|
{ |
545
|
|
|
return $this->currencyCode; |
546
|
|
|
} |
547
|
|
|
|
548
|
3 |
|
/** |
549
|
|
|
* @return string |
550
|
3 |
|
*/ |
551
|
|
|
public function getDeclarationStatement() |
552
|
3 |
|
{ |
553
|
|
|
return $this->declarationStatement; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
public function setDeclarationStatement($statement) |
557
|
|
|
{ |
558
|
4 |
|
$this->declarationStatement = $statement; |
559
|
|
|
|
560
|
4 |
|
return $this; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
} |
564
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.