1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-library package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Library\Core\ThirdParty\SkiData\Parser; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\Exception\IntegerArgumentException; |
15
|
|
|
use WBW\Library\Core\Argument\Helper\BooleanHelper; |
16
|
|
|
use WBW\Library\Core\Argument\Helper\IntegerHelper; |
17
|
|
|
use WBW\Library\Core\ThirdParty\SkiData\Exception\TooLongDataException; |
18
|
|
|
use WBW\Library\Core\ThirdParty\SkiData\Model\Customer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Customer parser. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Library\Core\ThirdParty\SkiData\Parser |
25
|
|
|
*/ |
26
|
|
|
class CustomerParser extends AbstractParser { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Constructor. |
30
|
|
|
*/ |
31
|
|
|
public function __construct() { |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Parse a customer entity. |
37
|
|
|
* |
38
|
|
|
* @param Customer $entity The customer. |
39
|
|
|
* @return string Returns the parsed customer. |
40
|
|
|
* @throws TooLongDataException Throws a too long data exception if a data is too long. |
41
|
|
|
*/ |
42
|
|
|
public function parseEntity(Customer $entity): string { |
43
|
|
|
|
44
|
|
|
$output = [ |
45
|
|
|
$this->encodeInteger($entity->getCustomerNumber(), 9), |
46
|
|
|
$this->encodeString($entity->getTitle(), 10), |
47
|
|
|
$this->encodeString($entity->getSurname(), 25), |
48
|
|
|
$this->encodeString($entity->getFirstname(), 25), |
49
|
|
|
$this->encodeString($entity->getStreet(), 25), |
50
|
|
|
$this->encodeString($entity->getPCode(), 10), |
51
|
|
|
$this->encodeString($entity->getCity(), 25), |
52
|
|
|
$this->encodeString($entity->getCountry(), 3), |
53
|
|
|
$this->encodeString($entity->getTaxCode(), 16), |
54
|
|
|
$this->encodeString($entity->getIdDocumentNo(), 15), |
55
|
|
|
$this->encodeString($entity->getTelephone(), 20), |
56
|
|
|
$this->encodeString($entity->getRentalAgreementNo(), 20), |
57
|
|
|
$this->encodeDate($entity->getBeginDate()), |
58
|
|
|
$this->encodeDate($entity->getTerminationDate()), |
59
|
|
|
$this->encodeInteger($entity->getDeposit(), 12), |
60
|
|
|
$this->encodeInteger($entity->getMaximumLevel(), 4), |
61
|
|
|
$this->encodeString($entity->getRemarks(), 50), |
62
|
|
|
$this->encodeDateTime($entity->getDatetimeLastModification()), |
63
|
|
|
$this->encodeBoolean($entity->getBlocked()), |
64
|
|
|
$this->encodeDate($entity->getBlockedDate()), |
65
|
|
|
$this->encodeBoolean($entity->getDeletedRecord()), |
66
|
|
|
$this->encodeBoolean($entity->getTicketReturnAllowed()), |
67
|
|
|
$this->encodeBoolean($entity->getGroupCounting()), |
68
|
|
|
$this->encodeBoolean($entity->getEntryMaxLevelAllowed()), |
69
|
|
|
$this->encodeBoolean($entity->getMaxLevelCarPark()), |
70
|
|
|
$this->encodeString($entity->getRemarks2(), 50), |
71
|
|
|
$this->encodeString($entity->getRemarks3(), 50), |
72
|
|
|
$this->encodeString($entity->getDivision(), 25), |
73
|
|
|
$this->encodeString($entity->getEmail(), 120), |
74
|
|
|
$this->encodeBoolean($entity->getCountingNeutralCards()), |
75
|
|
|
$this->encodeString($entity->getNationality(), 3), |
76
|
|
|
$this->encodeString($entity->getAccountingNumber(), 20), |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
return implode(";", $output); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Parse a line. |
84
|
|
|
* |
85
|
|
|
* @param string $line The line. |
86
|
|
|
* @return Customer Returns a customer. |
87
|
|
|
* @throws IntegerArgumentException Throws an integer argument exception. |
88
|
|
|
*/ |
89
|
|
|
public function parseLine(string $line): Customer { |
90
|
|
|
|
91
|
|
|
$data = explode(";", $line); |
92
|
|
|
|
93
|
|
|
$i = -1; |
94
|
|
|
|
95
|
|
|
$model = new Customer(); |
96
|
|
|
$model->setCustomerNumber(IntegerHelper::parseString($data[++$i])); |
97
|
|
|
$model->setTitle($this->decodeString($data[++$i])); |
98
|
|
|
$model->setSurname($this->decodeString($data[++$i])); |
99
|
|
|
$model->setFirstname($this->decodeString($data[++$i])); |
100
|
|
|
$model->setStreet($this->decodeString($data[++$i])); |
101
|
|
|
$model->setPCode($this->decodeString($data[++$i])); |
102
|
|
|
$model->setCity($this->decodeString($data[++$i])); |
103
|
|
|
$model->setCountry($this->decodeString($data[++$i])); |
104
|
|
|
$model->setTaxCode($this->decodeString($data[++$i])); |
105
|
|
|
$model->setIdDocumentNo($this->decodeString($data[++$i])); |
106
|
|
|
$model->setTelephone($this->decodeString($data[++$i])); |
107
|
|
|
$model->setRentalAgreementNo($this->decodeString($data[++$i])); |
108
|
|
|
$model->setBeginDate($this->decodeDate($data[++$i])); |
109
|
|
|
$model->setTerminationDate($this->decodeDate($data[++$i])); |
110
|
|
|
$model->setDeposit(IntegerHelper::parseString($data[++$i])); |
111
|
|
|
$model->setMaximumLevel(IntegerHelper::parseString($data[++$i])); |
112
|
|
|
$model->setRemarks($this->decodeString($data[++$i])); |
113
|
|
|
$model->setDatetimeLastModification($this->decodeDateTime($data[++$i])); |
114
|
|
|
$model->setBlocked(BooleanHelper::parseString($data[++$i])); |
115
|
|
|
$model->setBlockedDate($this->decodeDate($data[++$i])); |
116
|
|
|
$model->setDeletedRecord(BooleanHelper::parseString($data[++$i])); |
117
|
|
|
$model->setTicketReturnAllowed(BooleanHelper::parseString($data[++$i])); |
118
|
|
|
$model->setGroupCounting(BooleanHelper::parseString($data[++$i])); |
119
|
|
|
$model->setEntryMaxLevelAllowed(BooleanHelper::parseString($data[++$i])); |
120
|
|
|
$model->setMaxLevelCarPark(BooleanHelper::parseString($data[++$i])); |
121
|
|
|
$model->setRemarks2($this->decodeString($data[++$i])); |
122
|
|
|
$model->setRemarks3($this->decodeString($data[++$i])); |
123
|
|
|
$model->setDivision($this->decodeString($data[++$i])); |
124
|
|
|
$model->setEmail($this->decodeString($data[++$i])); |
125
|
|
|
$model->setCountingNeutralCards(BooleanHelper::parseString($data[++$i])); |
126
|
|
|
$model->setNationality($this->decodeString($data[++$i])); |
127
|
|
|
$model->setAccountingNumber($this->decodeString($data[++$i])); |
128
|
|
|
|
129
|
|
|
return $model; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|