Completed
Pull Request — master (#155)
by
unknown
04:40 queued 36s
created

setAdditionalDocumentIndicator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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 = [
0 ignored issues
show
Unused Code introduced by
The property $termsOfShipmentNames is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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
        $this->types = $types;
217
218
        return $this;
219
    }
220
221
    /**
222
     * @return string
223
     */
224 2
    public function getTypes()
225
    {
226 2
        return $this->types;
227
    }
228
229
    /**
230
     * @param $freightCharges FreightCharges
231
     *
232
     * @return $this
233
     */
234
    public function setFreightCharges(FreightCharges $freightCharges)
235
    {
236
        $this->freightCharges = $freightCharges;
237
238
        return $this;
239
    }
240
241
    /**
242
     * @return FreightCharges
243
     */
244 2
    public function getFreightCharges()
245
    {
246 2
        return $this->freightCharges;
247
    }
248
249
    /**
250
     * @param $discount Discount
251
     *
252
     * @return $this
253
     */
254
    public function setDiscount(Discount $discount)
255
    {
256
        $this->discount = $discount;
257
258
        return $this;
259
    }
260
261
    /**
262
     * @return Discount
263
     */
264 2
    public function getDiscount()
265
    {
266 2
        return $this->discount;
267
    }
268
269
    /**
270
     * @param Product $product
271
     *
272
     * @return $this
273
     */
274
    public function addProduct(Product $product)
275
    {
276
        array_push($this->products, $product);
277
278
        return $this;
279
    }
280
281
    /**
282
     * @return array
283
     */
284
    public function getProducts()
285
    {
286
        return $this->products;
287
    }
288
289
    /**
290
     * @param null|DOMDocument $document
291
     *
292
     * @return DOMElement
293
     */
294 2
    public function toNode(DOMDocument $document = null)
295
    {
296 2
        if (null === $document) {
297
            $document = new DOMDocument();
298
        }
299
300 2
        $node = $document->createElement('InternationalForms');
301
302 2
        foreach ($this->getTypes() as $type) {
303 2
            $node->appendChild($document->createElement('FormType', $type));
304 2
        }
305 2
        if ($this->getInvoiceNumber() !== null) {
306
            $node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber()));
307
        }
308 2
        if ($this->getInvoiceDate() !== null) {
309
            $node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd')));
310
        }
311 2
        if ($this->getPurchaseOrderNumber() !== null) {
312
            $node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber()));
313
        }
314 2
        if ($this->getTermsOfShipment() !== null) {
315
            $node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment()));
316
        }
317 2
        if ($this->getReasonForExport() !== null) {
318
            $node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport()));
319
        }
320 2
        if ($this->getComments() !== null) {
321
            $node->appendChild($document->createElement('Comments', $this->getComments()));
322
        }
323 2
        if ($this->getCurrencyCode() !== null) {
324
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
325
        }
326 2
        if ($this->getDiscount() !== null) {
327
            $node->appendChild($this->getDiscount()->toNode($document));
328
        }
329 2
        if ($this->getFreightCharges() !== null) {
330
            $node->appendChild($this->getFreightCharges()->toNode($document));
331
        }
332 2
        if ($this->getAdditionalDocumentIndicator() !== null) {
333
            $node->appendChild($document->createElement('AdditionalDocumentIndicator'));
334
        }
335 2
        if ($this->getEEIFilingOption() !== null) {
336 1
            $node->appendChild($this->getEEIFilingOption()->toNode($document));
337 1
        }
338 2
        foreach ($this->products as $product) {
339
            $node->appendChild($product->toNode($document));
340 2
        }
341
342 2
        return $node;
343
    }
344
345
    /**
346
     * @param $number string
347
     *
348
     * @return $this
349
     */
350
    public function setInvoiceNumber($number)
351
    {
352
        $this->invoiceNumber = $number;
353
354
        return $this;
355
    }
356
357
    /**
358
     * @return string
359
     */
360 2
    public function getInvoiceNumber()
361
    {
362 2
        return $this->invoiceNumber;
363
    }
364
365
    /**
366
     * @param DateTime $date
367
     *
368
     * @return $this
369
     */
370
    public function setInvoiceDate(DateTime $date)
371
    {
372
        $this->invoiceDate = $date;
373
374
        return $this;
375
    }
376
377
    /**
378
     * @return DateTime
379
     */
380 2
    public function getInvoiceDate()
381
    {
382 2
        return $this->invoiceDate;
383
    }
384
385
    /**
386
     * @param $number
387
     *
388
     * @return $this
389
     */
390
    public function setPurchaseOrderNumber($number)
391
    {
392
        $this->purchaseOrderNumber = $number;
393
394
        return $this;
395
    }
396
397
    /**
398
     * @return string
399
     */
400 2
    public function getPurchaseOrderNumber()
401
    {
402 2
        return $this->purchaseOrderNumber;
403
    }
404
405
    /**
406
     * @param $terms
407
     *
408
     * @return $this
409
     */
410
    public function setTermsOfShipment($terms)
411
    {
412
        $this->termsOfShipment = $terms;
413
414
        return $this;
415
    }
416
417
    /**
418
     * @return string
419
     */
420 2
    public function getTermsOfShipment()
421
    {
422 2
        return $this->termsOfShipment;
423
    }
424
425
    /**
426
     * @param $reason
427
     *
428
     * @return $this
429
     */
430
    public function setReasonForExport($reason)
431
    {
432
        if (strlen($reason) > 20) {
433
            $reason = substr($reason, 0, 20);
434
        }
435
436
        $this->reasonForExport = $reason;
437
438
        return $this;
439
    }
440
441
    /**
442
     * @return string
443
     */
444 2
    public function getReasonForExport()
445
    {
446 2
        return $this->reasonForExport;
447
    }
448
449
    /**
450
     * @param $comments
451
     *
452
     * @return $this
453
     */
454 View Code Duplication
    public function setComments($comments)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
455
    {
456
        if (strlen($comments) > 150) {
457
            $comments = substr($comments, 0, 150);
458
        }
459
460
        $this->comments = $comments;
461
462
        return $this;
463
    }
464
465
    /**
466
     * @return string
467
     */
468 2
    public function getComments()
469
    {
470 2
        return $this->comments;
471
    }
472
473
    /**
474
     * @param $code
475
     *
476
     * @return $this
477
     */
478
    public function setCurrencyCode($code)
479
    {
480
        $this->currencyCode = $code;
481
482
        return $this;
483
    }
484
485
    /**
486
     * @return string
487
     */
488 2
    public function getCurrencyCode()
489
    {
490 2
        return $this->currencyCode;
491
    }
492
493
    /**
494
     * @param $additionalDocumentIndicator
495
     *
496
     * @return $this
497
     */
498
    public function setAdditionalDocumentIndicator($additionalDocumentIndicator)
499
    {
500
        $this->additionalDocumentIndicator = $additionalDocumentIndicator;
501
    }
502
503
    /**
504
     * @return bool
505
     */
506 2
    public function getAdditionalDocumentIndicator()
507
    {
508 2
        return $this->additionalDocumentIndicator;
509
    }
510
511
    /**
512
     * @param EEIFilingOption $eeiFilingOption
513
     *
514
     * @return $this
515
     */
516 3
    public function setEEIFilingOption(EEIFilingOption $eeiFilingOption)
517
    {
518 3
        $this->eeiFilingOption = $eeiFilingOption;
519
520 3
        return $this;
521
    }
522
523
    /**
524
     * @return EEIFilingOption
525
     */
526 4
    public function getEEIFilingOption()
527
    {
528 4
        return $this->eeiFilingOption;
529
    }
530
}
531