Completed
Pull Request — master (#108)
by
unknown
03:48
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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
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 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 = [
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...
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 bool
139
     */
140
    private $additionalDocumentIndicator;
141
142
    /**
143
     * @return array
144
     */
145
    public static function getTypes()
146
    {
147
        return self::$typeNames;
148
    }
149
150
    /**
151
     * @return string
152
     */
153
    public function getTypeName()
154
    {
155
        return self::$typeNames[$this->getType()];
156
    }
157
158
    /**
159
     * @param null|object $attributes
160
     */
161
    public function __construct($attributes = null)
162
    {
163
        if (null !== $attributes) {
164
            if (isset($attributes->FormType)) {
165
                $this->setType($attributes->FormType);
166
            }
167
            if (isset($attributes->InvoiceNumber)) {
168
                $this->setInvoiceNumber($attributes->InvoiceNumber);
169
            }
170
            if (isset($attributes->InvoiceDate)) {
171
                $this->setInvoiceDate(new DateTime($attributes->InvoiceDate));
172
            }
173
            if (isset($attributes->PurchaseOrderNumber)) {
174
                $this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber);
175
            }
176
            if (isset($attributes->TermsOfShipment)) {
177
                $this->setTermsOfShipment($attributes->TermsOfShipment);
178
            }
179
            if (isset($attributes->Comments)) {
180
                $this->setComments($attributes->Comments);
181
            }
182
            if (isset($attributes->CurrencyCode)) {
183
                $this->setCurrencyCode($attributes->CurrencyCode);
184
            }
185
        }
186
    }
187
188
    /**
189
     * @param $type string
190
     *
191
     * @return $this
192
     */
193
    public function setType($type)
194
    {
195
        $this->type = $type;
196
197
        return $this;
198
    }
199
200
    /**
201
     * @return string
202
     */
203
    public function getType()
204
    {
205
        return $this->type;
206
    }
207
208
    /**
209
     * @param $freightCharges FreightCharges
210
     *
211
     * @return $this
212
     */
213
    public function setFreightCharges(FreightCharges $freightCharges)
214
    {
215
        $this->freightCharges = $freightCharges;
216
217
        return $this;
218
    }
219
220
    /**
221
     * @return FreightCharges
222
     */
223
    public function getFreightCharges()
224
    {
225
        return $this->freightCharges;
226
    }
227
228
    /**
229
     * @param $discount Discount
230
     *
231
     * @return $this
232
     */
233
    public function setDiscount(Discount $discount)
234
    {
235
        $this->discount = $discount;
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return Discount
242
     */
243
    public function getDiscount()
244
    {
245
        return $this->discount;
246
    }
247
248
    /**
249
     * @param Product $product
250
     *
251
     * @return $this
252
     */
253
    public function addProduct(Product $product)
254
    {
255
        array_push($this->products, $product);
256
257
        return $this;
258
    }
259
260
    /**
261
     * @return array
262
     */
263
    public function getProducts()
264
    {
265
        return $this->products;
266
    }
267
268
    /**
269
     * @param null|DOMDocument $document
270
     *
271
     * @return DOMElement
272
     */
273
    public function toNode(DOMDocument $document = null)
274
    {
275
        if (null === $document) {
276
            $document = new DOMDocument();
277
        }
278
279
        $node = $document->createElement('InternationalForms');
280
281
        if ($this->getType()) {
282
            $node->appendChild($document->createElement('FormType', $this->getType()));
283
        }
284
        if ($this->getInvoiceNumber() !== null) {
285
            $node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber()));
286
        }
287
        if ($this->getInvoiceDate() !== null) {
288
            $node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd')));
289
        }
290
        if ($this->getPurchaseOrderNumber() !== null) {
291
            $node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber()));
292
        }
293
        if ($this->getTermsOfShipment() !== null) {
294
            $node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment()));
295
        }
296
        if ($this->getReasonForExport() !== null) {
297
            $node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport()));
298
        }
299
        if ($this->getComments() !== null) {
300
            $node->appendChild($document->createElement('Comments', $this->getComments()));
301
        }
302
        if ($this->getCurrencyCode() !== null) {
303
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
304
        }
305
        if ($this->getDiscount() !== null) {
306
            $node->appendChild($this->getDiscount()->toNode($document));
307
        }
308
        if ($this->getFreightCharges() !== null) {
309
            $node->appendChild($this->getFreightCharges()->toNode($document));
310
        }
311
        if ($this->getAdditionalDocumentIndicator() !== null) {
312
            $node->appendChild($document->createElement('AdditionalDocumentIndicator'));
313
        }
314
        foreach ($this->products as $product) {
315
            $node->appendChild($product->toNode($document));
316
        }
317
318
        return $node;
319
    }
320
321
    /**
322
     * @param $number string
323
     *
324
     * @return $this
325
     */
326
    public function setInvoiceNumber($number)
327
    {
328
        $this->invoiceNumber = $number;
329
330
        return $this;
331
    }
332
333
    /**
334
     * @return string
335
     */
336
    public function getInvoiceNumber()
337
    {
338
        return $this->invoiceNumber;
339
    }
340
341
    /**
342
     * @param DateTime $date
343
     *
344
     * @return $this
345
     */
346
    public function setInvoiceDate(DateTime $date)
347
    {
348
        $this->invoiceDate = $date;
349
350
        return $this;
351
    }
352
353
    /**
354
     * @return DateTime
355
     */
356
    public function getInvoiceDate()
357
    {
358
        return $this->invoiceDate;
359
    }
360
361
    /**
362
     * @param $number
363
     *
364
     * @return $this
365
     */
366
    public function setPurchaseOrderNumber($number)
367
    {
368
        $this->purchaseOrderNumber = $number;
369
370
        return $this;
371
    }
372
373
    /**
374
     * @return string
375
     */
376
    public function getPurchaseOrderNumber()
377
    {
378
        return $this->purchaseOrderNumber;
379
    }
380
381
    /**
382
     * @param $terms
383
     *
384
     * @return $this
385
     */
386
    public function setTermsOfShipment($terms)
387
    {
388
        $this->termsOfShipment = $terms;
389
390
        return $this;
391
    }
392
393
    /**
394
     * @return string
395
     */
396
    public function getTermsOfShipment()
397
    {
398
        return $this->termsOfShipment;
399
    }
400
401
    /**
402
     * @param $reason
403
     *
404
     * @return $this
405
     */
406
    public function setReasonForExport($reason)
407
    {
408
        if (strlen($reason) > 20) {
409
            $reason = substr($reason, 0, 20);
410
        }
411
412
        $this->reasonForExport = $reason;
413
414
        return $this;
415
    }
416
417
    /**
418
     * @return string
419
     */
420
    public function getReasonForExport()
421
    {
422
        return $this->reasonForExport;
423
    }
424
425
    /**
426
     * @param $comments
427
     *
428
     * @return $this
429
     */
430 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...
431
    {
432
        if (strlen($comments) > 150) {
433
            $comments = substr($comments, 0, 150);
434
        }
435
436
        $this->comments = $comments;
437
438
        return $this;
439
    }
440
441
    /**
442
     * @return string
443
     */
444
    public function getComments()
445
    {
446
        return $this->comments;
447
    }
448
449
    /**
450
     * @param $code
451
     *
452
     * @return $this
453
     */
454
    public function setCurrencyCode($code)
455
    {
456
        $this->currencyCode = $code;
457
458
        return $this;
459
    }
460
461
    /**
462
     * @return string
463
     */
464
    public function getCurrencyCode()
465
    {
466
        return $this->currencyCode;
467
    }
468
469
    /**
470
     * @param $additionalDocumentIndicator
471
     *
472
     * @return $this
473
     */
474
    public function setAdditionalDocumentIndicator($additionalDocumentIndicator)
475
    {
476
        $this->additionalDocumentIndicator = $additionalDocumentIndicator;
477
    }
478
479
    /**
480
     * @return bool
481
     */
482
    public function getAdditionalDocumentIndicator()
483
    {
484
        return $this->additionalDocumentIndicator;
485
    }
486
}
487