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