Completed
Push — master ( 20e80f...9e4566 )
by Joachim
08:10
created

Label::setExternalId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Loevgaard\PakkelabelsBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * @ORM\Entity
9
 * @ORM\Table(name="pakkelabels_labels")
10
 */
11
class Label
12
{
13
    const STATUS_PENDING_NORMALIZATION = 'pending_normalization';
14
    const STATUS_PENDING_CREATION = 'pending_creation';
15
    const STATUS_ERROR = 'error';
16
    const STATUS_SUCCESS = 'success';
17
18
    const LABEL_FORMAT_A4_PDF = 'a4_pdf';
19
    const LABEL_FORMAT_10_X_19_PDF = '10x19_pdf';
20
    const LABEL_FORMAT_PNG = 'png';
21
    const LABEL_FORMAT_ZPL = 'zpl';
22
23
    /**
24
     * @var int
25
     *
26
     * @ORM\Id
27
     * @ORM\GeneratedValue
28
     * @ORM\Column(type="integer")
29
     */
30
    protected $id;
31
32
    /**
33
     * This is the shipment id from Pakkelabels
34
     *
35
     * @var int
36
     *
37
     * @ORM\Column(type="integer", unique=true)
38
     */
39
    protected $externalId;
40
41
    /**
42
     * @var string
43
     *
44
     * @ORM\Column(type="string")
45
     */
46
    protected $status;
47
48
    /**
49
     * @var string
50
     *
51
     * @ORM\Column(type="text", nullable=true)
52
     */
53
    protected $error;
54
55
    /**
56
     * The shipping method property is used in normalization. We check the mappings table to see
57
     * if there is a shipping method matching this. If there is, we will populate the product code
58
     * and services codes properties
59
     *
60
     * @var string
61
     *
62
     * @ORM\Column(type="string", nullable=true)
63
     */
64
    protected $shippingMethod;
65
66
    /**************************
67
     * Pakkelabels properties *
68
     *************************/
69
    /**
70
     * @var string
71
     *
72
     * @ORM\Column(type="string", nullable=true)
73
     */
74
    protected $orderId;
75
76
    /**
77
     * @var string
78
     *
79
     * @ORM\Column(type="string", nullable=true)
80
     */
81
    protected $reference;
82
83
    /**
84
     * @var string
85
     *
86
     * @ORM\Column(type="string", nullable=true)
87
     */
88
    protected $source;
89
90
    /**
91
     * @var boolean
92
     *
93
     * @ORM\Column(type="boolean")
94
     */
95
    protected $ownAgreement;
96
97
    /**
98
     * @var string
99
     *
100
     * @ORM\Column(type="string", nullable=true)
101
     */
102
    protected $labelFormat;
103
104
    /**
105
     * @var string
106
     *
107
     * @ORM\Column(type="string")
108
     */
109
    protected $productCode;
110
111
    /**
112
     * @var string
113
     *
114
     * @ORM\Column(type="string")
115
     */
116
    protected $serviceCodes;
117
118
    /**
119
     * @var boolean
120
     *
121
     * @ORM\Column(type="boolean")
122
     */
123
    protected $automaticSelectServicePoint;
124
125
    /**
126
     * @var string
127
     *
128
     * @ORM\Column(type="string")
129
     */
130
    protected $servicePointId;
131
132
    /**
133
     * @var boolean
134
     *
135
     * @ORM\Column(type="boolean")
136
     */
137
    protected $smsNotification;
138
139
    /**
140
     * @var boolean
141
     *
142
     * @ORM\Column(type="boolean")
143
     */
144
    protected $emailNotification;
145
146
    /**
147
     * @var string
148
     *
149
     * @ORM\Column(type="string")
150
     */
151
    protected $senderName;
152
153
    /**
154
     * @var string
155
     *
156
     * @ORM\Column(type="string")
157
     */
158
    protected $senderAddress1;
159
160
    /**
161
     * @var string
162
     *
163
     * @ORM\Column(type="string", nullable=true)
164
     */
165
    protected $senderAddress2;
166
167
    /**
168
     * @var string
169
     *
170
     * @ORM\Column(type="string")
171
     */
172
    protected $senderCountryCode;
173
174
    /**
175
     * @var string
176
     *
177
     * @ORM\Column(type="string")
178
     */
179
    protected $senderZipCode;
180
181
    /**
182
     * @var string
183
     *
184
     * @ORM\Column(type="string")
185
     */
186
    protected $senderCity;
187
188
    /**
189
     * @var string
190
     *
191
     * @ORM\Column(type="string", nullable=true)
192
     */
193
    protected $senderAttention;
194
195
    /**
196
     * @var string
197
     *
198
     * @ORM\Column(type="string")
199
     */
200
    protected $senderEmail;
201
202
    /**
203
     * @var string
204
     *
205
     * @ORM\Column(type="string")
206
     */
207
    protected $senderTelephone;
208
209
    /**
210
     * @var string
211
     *
212
     * @ORM\Column(type="string")
213
     */
214
    protected $senderMobile;
215
216
    /**
217
     * @var string
218
     *
219
     * @ORM\Column(type="string")
220
     */
221
    protected $receiverName;
222
223
    /**
224
     * @var string
225
     *
226
     * @ORM\Column(type="string")
227
     */
228
    protected $receiverAddress1;
229
230
    /**
231
     * @var string
232
     *
233
     * @ORM\Column(type="string", nullable=true)
234
     */
235
    protected $receiverAddress2;
236
237
    /**
238
     * @var string
239
     *
240
     * @ORM\Column(type="string")
241
     */
242
    protected $receiverCountryCode;
243
244
    /**
245
     * @var string
246
     *
247
     * @ORM\Column(type="string")
248
     */
249
    protected $receiverZipCode;
250
251
    /**
252
     * @var string
253
     *
254
     * @ORM\Column(type="string")
255
     */
256
    protected $receiverCity;
257
258
    /**
259
     * @var string
260
     *
261
     * @ORM\Column(type="string", nullable=true)
262
     */
263
    protected $receiverAttention;
264
265
    /**
266
     * @var string
267
     *
268
     * @ORM\Column(type="string")
269
     */
270
    protected $receiverEmail;
271
272
    /**
273
     * @var string
274
     *
275
     * @ORM\Column(type="string")
276
     */
277
    protected $receiverTelephone;
278
279
    /**
280
     * @var string
281
     *
282
     * @ORM\Column(type="string")
283
     */
284
    protected $receiverMobile;
285
286
    /**
287
     * @var string
288
     *
289
     * @ORM\Column(type="text", nullable=true)
290
     */
291
    protected $receiverInstruction;
292
293
    public function __construct()
294
    {
295
        $this->status = static::STATUS_PENDING_NORMALIZATION;
296
        $this->smsNotification = false;
297
        $this->emailNotification = false;
298
    }
299
300
    public function arrayForApi() : array
301
    {
302
        $data = [
303
            'order_id' => $this->orderId,
304
            'reference' => $this->reference,
305
            'source' => $this->source,
306
            'own_agreement' => $this->ownAgreement,
307
            'label_format' => $this->labelFormat,
308
            'product_code' => $this->productCode,
309
            'service_codes' => $this->serviceCodes,
310
            'automatic_select_service_point' => $this->automaticSelectServicePoint,
311
            'sms_notification' => $this->smsNotification,
312
            'email_notification' => $this->emailNotification,
313
            'service_point' => [
314
                'id' => $this->servicePointId
315
            ],
316
            'sender' => [
317
                'name' => $this->senderName,
318
                'address1' => $this->senderAddress1,
319
                'address2' => $this->senderAddress2,
320
                'country_code' => $this->senderCountryCode,
321
                'zipcode' => $this->senderZipCode,
322
                'city' => $this->senderCity,
323
                'attention' => $this->senderAttention,
324
                'email' => $this->senderEmail,
325
                'telephone' => $this->senderTelephone,
326
                'mobile' => $this->senderMobile
327
            ],
328
            'receiver' => [
329
                'name' => $this->receiverName,
330
                'address1' => $this->receiverAddress1,
331
                'address2' => $this->receiverAddress2,
332
                'country_code' => $this->receiverCountryCode,
333
                'zipcode' => $this->receiverZipCode,
334
                'city' => $this->receiverCity,
335
                'attention' => $this->receiverAttention,
336
                'email' => $this->receiverEmail,
337
                'telephone' => $this->receiverTelephone,
338
                'mobile' => $this->receiverMobile,
339
                'instruction' => $this->receiverInstruction
340
            ],
341
            'parcels' => [
342
                [
343
                    'weight' => 1000
344
                ]
345
            ]
346
        ];
347
348
        $data = array_filter($data, function($elm) {
349
            return !is_null($elm);
350
        });
351
352
        return $data;
353
    }
354
355
    public function markAsError(string $error)
356
    {
357
        $this->error = $error;
358
        $this->status = static::STATUS_ERROR;
359
    }
360
361
    public function markAsSuccess()
362
    {
363
        $this->error = null;
364
        $this->status = static::STATUS_SUCCESS;
365
    }
366
367
    /*********************
368
     * Getters / Setters *
369
     ********************/
370
    /**
371
     * @return int
372
     */
373
    public function getId(): int
374
    {
375
        return $this->id;
376
    }
377
378
    /**
379
     * @param int $id
380
     * @return Label
381
     */
382
    public function setId(int $id)
383
    {
384
        $this->id = $id;
385
        return $this;
386
    }
387
388
    /**
389
     * @return int
390
     */
391
    public function getExternalId(): int
392
    {
393
        return $this->externalId;
394
    }
395
396
    /**
397
     * @param int $externalId
398
     * @return Label
399
     */
400
    public function setExternalId(int $externalId)
401
    {
402
        $this->externalId = $externalId;
403
        return $this;
404
    }
405
406
    /**
407
     * @return string
408
     */
409
    public function getStatus(): string
410
    {
411
        return $this->status;
412
    }
413
414
    /**
415
     * @param string $status
416
     * @return Label
417
     */
418
    public function setStatus(string $status)
419
    {
420
        $this->status = $status;
421
        return $this;
422
    }
423
424
    /**
425
     * @return string
426
     */
427
    public function getError(): string
428
    {
429
        return $this->error;
430
    }
431
432
    /**
433
     * @param string $error
434
     * @return Label
435
     */
436
    public function setError(string $error)
437
    {
438
        $this->error = $error;
439
        return $this;
440
    }
441
442
    /**
443
     * @return string
444
     */
445
    public function getShippingMethod(): string
446
    {
447
        return $this->shippingMethod;
448
    }
449
450
    /**
451
     * @param string $shippingMethod
452
     * @return Label
453
     */
454
    public function setShippingMethod(string $shippingMethod)
455
    {
456
        $this->shippingMethod = $shippingMethod;
457
        return $this;
458
    }
459
460
    /**
461
     * @return string
462
     */
463
    public function getOrderId(): string
464
    {
465
        return $this->orderId;
466
    }
467
468
    /**
469
     * @param string $orderId
470
     * @return Label
471
     */
472
    public function setOrderId(string $orderId)
473
    {
474
        $this->orderId = $orderId;
475
        return $this;
476
    }
477
478
    /**
479
     * @return string
480
     */
481
    public function getReference(): string
482
    {
483
        return $this->reference;
484
    }
485
486
    /**
487
     * @param string $reference
488
     * @return Label
489
     */
490
    public function setReference(string $reference)
491
    {
492
        $this->reference = $reference;
493
        return $this;
494
    }
495
496
    /**
497
     * @return string
498
     */
499
    public function getSource(): string
500
    {
501
        return $this->source;
502
    }
503
504
    /**
505
     * @param string $source
506
     * @return Label
507
     */
508
    public function setSource(string $source)
509
    {
510
        $this->source = $source;
511
        return $this;
512
    }
513
514
    /**
515
     * @return bool
516
     */
517
    public function isOwnAgreement(): bool
518
    {
519
        return $this->ownAgreement;
520
    }
521
522
    /**
523
     * @param bool $ownAgreement
524
     * @return Label
525
     */
526
    public function setOwnAgreement(bool $ownAgreement)
527
    {
528
        $this->ownAgreement = $ownAgreement;
529
        return $this;
530
    }
531
532
    /**
533
     * @return string
534
     */
535
    public function getLabelFormat(): string
536
    {
537
        return $this->labelFormat;
538
    }
539
540
    /**
541
     * @param string $labelFormat
542
     * @return Label
543
     */
544
    public function setLabelFormat(string $labelFormat)
545
    {
546
        $this->labelFormat = $labelFormat;
547
        return $this;
548
    }
549
550
    /**
551
     * @return string
552
     */
553
    public function getProductCode(): string
554
    {
555
        return $this->productCode;
556
    }
557
558
    /**
559
     * @param string $productCode
560
     * @return Label
561
     */
562
    public function setProductCode(string $productCode)
563
    {
564
        $this->productCode = $productCode;
565
        return $this;
566
    }
567
568
    /**
569
     * @return string
570
     */
571
    public function getServiceCodes(): string
572
    {
573
        return $this->serviceCodes;
574
    }
575
576
    /**
577
     * @param string $serviceCodes
578
     * @return Label
579
     */
580
    public function setServiceCodes(string $serviceCodes)
581
    {
582
        $this->serviceCodes = $serviceCodes;
583
        return $this;
584
    }
585
586
    /**
587
     * @return bool
588
     */
589
    public function isAutomaticSelectServicePoint(): bool
590
    {
591
        return $this->automaticSelectServicePoint;
592
    }
593
594
    /**
595
     * @param bool $automaticSelectServicePoint
596
     * @return Label
597
     */
598
    public function setAutomaticSelectServicePoint(bool $automaticSelectServicePoint)
599
    {
600
        $this->automaticSelectServicePoint = $automaticSelectServicePoint;
601
        return $this;
602
    }
603
604
    /**
605
     * @return string
606
     */
607
    public function getServicePointId(): string
608
    {
609
        return $this->servicePointId;
610
    }
611
612
    /**
613
     * @param string $servicePointId
614
     * @return Label
615
     */
616
    public function setServicePointId(string $servicePointId)
617
    {
618
        $this->servicePointId = $servicePointId;
619
        return $this;
620
    }
621
622
    /**
623
     * @return bool
624
     */
625
    public function isSmsNotification(): bool
626
    {
627
        return $this->smsNotification;
628
    }
629
630
    /**
631
     * @param bool $smsNotification
632
     * @return Label
633
     */
634
    public function setSmsNotification(bool $smsNotification)
635
    {
636
        $this->smsNotification = $smsNotification;
637
        return $this;
638
    }
639
640
    /**
641
     * @return bool
642
     */
643
    public function isEmailNotification(): bool
644
    {
645
        return $this->emailNotification;
646
    }
647
648
    /**
649
     * @param bool $emailNotification
650
     * @return Label
651
     */
652
    public function setEmailNotification(bool $emailNotification)
653
    {
654
        $this->emailNotification = $emailNotification;
655
        return $this;
656
    }
657
658
    /**
659
     * @return string
660
     */
661
    public function getSenderName(): string
662
    {
663
        return $this->senderName;
664
    }
665
666
    /**
667
     * @param string $senderName
668
     * @return Label
669
     */
670
    public function setSenderName(string $senderName)
671
    {
672
        $this->senderName = $senderName;
673
        return $this;
674
    }
675
676
    /**
677
     * @return string
678
     */
679
    public function getSenderAddress1(): string
680
    {
681
        return $this->senderAddress1;
682
    }
683
684
    /**
685
     * @param string $senderAddress1
686
     * @return Label
687
     */
688
    public function setSenderAddress1(string $senderAddress1)
689
    {
690
        $this->senderAddress1 = $senderAddress1;
691
        return $this;
692
    }
693
694
    /**
695
     * @return string
696
     */
697
    public function getSenderAddress2(): string
698
    {
699
        return $this->senderAddress2;
700
    }
701
702
    /**
703
     * @param string $senderAddress2
704
     * @return Label
705
     */
706
    public function setSenderAddress2(string $senderAddress2)
707
    {
708
        $this->senderAddress2 = $senderAddress2;
709
        return $this;
710
    }
711
712
    /**
713
     * @return string
714
     */
715
    public function getSenderCountryCode(): string
716
    {
717
        return $this->senderCountryCode;
718
    }
719
720
    /**
721
     * @param string $senderCountryCode
722
     * @return Label
723
     */
724
    public function setSenderCountryCode(string $senderCountryCode)
725
    {
726
        $this->senderCountryCode = $senderCountryCode;
727
        return $this;
728
    }
729
730
    /**
731
     * @return string
732
     */
733
    public function getSenderZipCode(): string
734
    {
735
        return $this->senderZipCode;
736
    }
737
738
    /**
739
     * @param string $senderZipCode
740
     * @return Label
741
     */
742
    public function setSenderZipCode(string $senderZipCode)
743
    {
744
        $this->senderZipCode = $senderZipCode;
745
        return $this;
746
    }
747
748
    /**
749
     * @return string
750
     */
751
    public function getSenderCity(): string
752
    {
753
        return $this->senderCity;
754
    }
755
756
    /**
757
     * @param string $senderCity
758
     * @return Label
759
     */
760
    public function setSenderCity(string $senderCity)
761
    {
762
        $this->senderCity = $senderCity;
763
        return $this;
764
    }
765
766
    /**
767
     * @return string
768
     */
769
    public function getSenderAttention(): string
770
    {
771
        return $this->senderAttention;
772
    }
773
774
    /**
775
     * @param string $senderAttention
776
     * @return Label
777
     */
778
    public function setSenderAttention(string $senderAttention)
779
    {
780
        $this->senderAttention = $senderAttention;
781
        return $this;
782
    }
783
784
    /**
785
     * @return string
786
     */
787
    public function getSenderEmail(): string
788
    {
789
        return $this->senderEmail;
790
    }
791
792
    /**
793
     * @param string $senderEmail
794
     * @return Label
795
     */
796
    public function setSenderEmail(string $senderEmail)
797
    {
798
        $this->senderEmail = $senderEmail;
799
        return $this;
800
    }
801
802
    /**
803
     * @return string
804
     */
805
    public function getSenderTelephone(): string
806
    {
807
        return $this->senderTelephone;
808
    }
809
810
    /**
811
     * @param string $senderTelephone
812
     * @return Label
813
     */
814
    public function setSenderTelephone(string $senderTelephone)
815
    {
816
        $this->senderTelephone = $senderTelephone;
817
        return $this;
818
    }
819
820
    /**
821
     * @return string
822
     */
823
    public function getSenderMobile(): string
824
    {
825
        return $this->senderMobile;
826
    }
827
828
    /**
829
     * @param string $senderMobile
830
     * @return Label
831
     */
832
    public function setSenderMobile(string $senderMobile)
833
    {
834
        $this->senderMobile = $senderMobile;
835
        return $this;
836
    }
837
838
    /**
839
     * @return string
840
     */
841
    public function getReceiverName(): string
842
    {
843
        return $this->receiverName;
844
    }
845
846
    /**
847
     * @param string $receiverName
848
     * @return Label
849
     */
850
    public function setReceiverName(string $receiverName)
851
    {
852
        $this->receiverName = $receiverName;
853
        return $this;
854
    }
855
856
    /**
857
     * @return string
858
     */
859
    public function getReceiverAddress1(): string
860
    {
861
        return $this->receiverAddress1;
862
    }
863
864
    /**
865
     * @param string $receiverAddress1
866
     * @return Label
867
     */
868
    public function setReceiverAddress1(string $receiverAddress1)
869
    {
870
        $this->receiverAddress1 = $receiverAddress1;
871
        return $this;
872
    }
873
874
    /**
875
     * @return string
876
     */
877
    public function getReceiverAddress2(): string
878
    {
879
        return $this->receiverAddress2;
880
    }
881
882
    /**
883
     * @param string $receiverAddress2
884
     * @return Label
885
     */
886
    public function setReceiverAddress2(string $receiverAddress2)
887
    {
888
        $this->receiverAddress2 = $receiverAddress2;
889
        return $this;
890
    }
891
892
    /**
893
     * @return string
894
     */
895
    public function getReceiverCountryCode(): string
896
    {
897
        return $this->receiverCountryCode;
898
    }
899
900
    /**
901
     * @param string $receiverCountryCode
902
     * @return Label
903
     */
904
    public function setReceiverCountryCode(string $receiverCountryCode)
905
    {
906
        $this->receiverCountryCode = $receiverCountryCode;
907
        return $this;
908
    }
909
910
    /**
911
     * @return string
912
     */
913
    public function getReceiverZipCode(): string
914
    {
915
        return $this->receiverZipCode;
916
    }
917
918
    /**
919
     * @param string $receiverZipCode
920
     * @return Label
921
     */
922
    public function setReceiverZipCode(string $receiverZipCode)
923
    {
924
        $this->receiverZipCode = $receiverZipCode;
925
        return $this;
926
    }
927
928
    /**
929
     * @return string
930
     */
931
    public function getReceiverCity(): string
932
    {
933
        return $this->receiverCity;
934
    }
935
936
    /**
937
     * @param string $receiverCity
938
     * @return Label
939
     */
940
    public function setReceiverCity(string $receiverCity)
941
    {
942
        $this->receiverCity = $receiverCity;
943
        return $this;
944
    }
945
946
    /**
947
     * @return string
948
     */
949
    public function getReceiverAttention(): string
950
    {
951
        return $this->receiverAttention;
952
    }
953
954
    /**
955
     * @param string $receiverAttention
956
     * @return Label
957
     */
958
    public function setReceiverAttention(string $receiverAttention)
959
    {
960
        $this->receiverAttention = $receiverAttention;
961
        return $this;
962
    }
963
964
    /**
965
     * @return string
966
     */
967
    public function getReceiverEmail(): string
968
    {
969
        return $this->receiverEmail;
970
    }
971
972
    /**
973
     * @param string $receiverEmail
974
     * @return Label
975
     */
976
    public function setReceiverEmail(string $receiverEmail)
977
    {
978
        $this->receiverEmail = $receiverEmail;
979
        return $this;
980
    }
981
982
    /**
983
     * @return string
984
     */
985
    public function getReceiverTelephone(): string
986
    {
987
        return $this->receiverTelephone;
988
    }
989
990
    /**
991
     * @param string $receiverTelephone
992
     * @return Label
993
     */
994
    public function setReceiverTelephone(string $receiverTelephone)
995
    {
996
        $this->receiverTelephone = $receiverTelephone;
997
        return $this;
998
    }
999
1000
    /**
1001
     * @return string
1002
     */
1003
    public function getReceiverMobile(): string
1004
    {
1005
        return $this->receiverMobile;
1006
    }
1007
1008
    /**
1009
     * @param string $receiverMobile
1010
     * @return Label
1011
     */
1012
    public function setReceiverMobile(string $receiverMobile)
1013
    {
1014
        $this->receiverMobile = $receiverMobile;
1015
        return $this;
1016
    }
1017
1018
    /**
1019
     * @return string
1020
     */
1021
    public function getReceiverInstruction(): string
1022
    {
1023
        return $this->receiverInstruction;
1024
    }
1025
1026
    /**
1027
     * @param string $receiverInstruction
1028
     * @return Label
1029
     */
1030
    public function setReceiverInstruction(string $receiverInstruction)
1031
    {
1032
        $this->receiverInstruction = $receiverInstruction;
1033
        return $this;
1034
    }
1035
}
1036