1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the timechimp bundle package. |
7
|
|
|
* (c) Connect Holland. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace ConnectHolland\TimechimpBundle\Api\Client\Normalizer; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
19
|
|
|
|
20
|
|
|
class InvoiceNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
21
|
|
|
{ |
22
|
|
|
use DenormalizerAwareTrait; |
23
|
|
|
use NormalizerAwareTrait; |
24
|
|
|
|
25
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
26
|
|
|
{ |
27
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\Invoice'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function supportsNormalization($data, $format = null) |
31
|
|
|
{ |
32
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\Invoice'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
36
|
|
|
{ |
37
|
|
|
if (!is_object($data)) { |
38
|
|
|
throw new InvalidArgumentException(sprintf('Given $data is not an object (%s given). We need an object in order to continue denormalize method.', gettype($data))); |
39
|
|
|
} |
40
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Client\Model\Invoice(); |
41
|
|
|
if (property_exists($data, 'id')) { |
42
|
|
|
$object->setId($data->{'id'}); |
43
|
|
|
} |
44
|
|
|
if (property_exists($data, 'clientId')) { |
45
|
|
|
$object->setClientId($data->{'clientId'}); |
46
|
|
|
} |
47
|
|
|
if (property_exists($data, 'companyInvoicePrefix')) { |
48
|
|
|
$object->setCompanyInvoicePrefix($data->{'companyInvoicePrefix'}); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'companyInvoiceId')) { |
51
|
|
|
$object->setCompanyInvoiceId($data->{'companyInvoiceId'}); |
52
|
|
|
} |
53
|
|
|
if (property_exists($data, 'customerId')) { |
54
|
|
|
$object->setCustomerId($data->{'customerId'}); |
55
|
|
|
} |
56
|
|
|
if (property_exists($data, 'status')) { |
57
|
|
|
$object->setStatus($data->{'status'}); |
58
|
|
|
} |
59
|
|
|
if (property_exists($data, 'customerRelationId')) { |
60
|
|
|
$object->setCustomerRelationId($data->{'customerRelationId'}); |
61
|
|
|
} |
62
|
|
|
if (property_exists($data, 'customerName')) { |
63
|
|
|
$object->setCustomerName($data->{'customerName'}); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'customerContactPerson')) { |
66
|
|
|
$object->setCustomerContactPerson($data->{'customerContactPerson'}); |
67
|
|
|
} |
68
|
|
|
if (property_exists($data, 'customerEmail')) { |
69
|
|
|
$object->setCustomerEmail($data->{'customerEmail'}); |
70
|
|
|
} |
71
|
|
|
if (property_exists($data, 'customerAddress')) { |
72
|
|
|
$object->setCustomerAddress($data->{'customerAddress'}); |
73
|
|
|
} |
74
|
|
|
if (property_exists($data, 'customerVatNumber')) { |
75
|
|
|
$object->setCustomerVatNumber($data->{'customerVatNumber'}); |
76
|
|
|
} |
77
|
|
|
if (property_exists($data, 'date')) { |
78
|
|
|
$object->setDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'date'})); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
if (property_exists($data, 'dueDate')) { |
81
|
|
|
$object->setDueDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'dueDate'})); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
if (property_exists($data, 'reference')) { |
84
|
|
|
$object->setReference($data->{'reference'}); |
85
|
|
|
} |
86
|
|
|
if (property_exists($data, 'notes')) { |
87
|
|
|
$object->setNotes($data->{'notes'}); |
88
|
|
|
} |
89
|
|
|
if (property_exists($data, 'total')) { |
90
|
|
|
$object->setTotal($data->{'total'}); |
91
|
|
|
} |
92
|
|
|
if (property_exists($data, 'totalWithoutExchangeRate')) { |
93
|
|
|
$object->setTotalWithoutExchangeRate($data->{'totalWithoutExchangeRate'}); |
94
|
|
|
} |
95
|
|
|
if (property_exists($data, 'totalExTax')) { |
96
|
|
|
$object->setTotalExTax($data->{'totalExTax'}); |
97
|
|
|
} |
98
|
|
|
if (property_exists($data, 'totalExTaxWithoutExchangeRate')) { |
99
|
|
|
$object->setTotalExTaxWithoutExchangeRate($data->{'totalExTaxWithoutExchangeRate'}); |
100
|
|
|
} |
101
|
|
|
if (property_exists($data, 'additionalNotes')) { |
102
|
|
|
$object->setAdditionalNotes($data->{'additionalNotes'}); |
103
|
|
|
} |
104
|
|
|
if (property_exists($data, 'internNotes')) { |
105
|
|
|
$object->setInternNotes($data->{'internNotes'}); |
106
|
|
|
} |
107
|
|
|
if (property_exists($data, 'currency')) { |
108
|
|
|
$object->setCurrency($data->{'currency'}); |
109
|
|
|
} |
110
|
|
|
if (property_exists($data, 'language')) { |
111
|
|
|
$object->setLanguage($data->{'language'}); |
112
|
|
|
} |
113
|
|
|
if (property_exists($data, 'exchangeRate')) { |
114
|
|
|
$object->setExchangeRate($data->{'exchangeRate'}); |
115
|
|
|
} |
116
|
|
|
if (property_exists($data, 'credit')) { |
117
|
|
|
$object->setCredit($data->{'credit'}); |
118
|
|
|
} |
119
|
|
|
if (property_exists($data, 'invoiceRows')) { |
120
|
|
|
$values = []; |
121
|
|
|
foreach ($data->{'invoiceRows'} as $value) { |
122
|
|
|
$values[] = $this->denormalizer->denormalize($value, 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\InvoiceRow', 'json', $context); |
123
|
|
|
} |
124
|
|
|
$object->setInvoiceRows($values); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $object; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function normalize($object, $format = null, array $context = []) |
131
|
|
|
{ |
132
|
|
|
$data = new \stdClass(); |
133
|
|
|
if (null !== $object->getId()) { |
134
|
|
|
$data->{'id'} = $object->getId(); |
135
|
|
|
} |
136
|
|
|
if (null !== $object->getClientId()) { |
137
|
|
|
$data->{'clientId'} = $object->getClientId(); |
138
|
|
|
} |
139
|
|
|
if (null !== $object->getCompanyInvoicePrefix()) { |
140
|
|
|
$data->{'companyInvoicePrefix'} = $object->getCompanyInvoicePrefix(); |
141
|
|
|
} |
142
|
|
|
if (null !== $object->getCompanyInvoiceId()) { |
143
|
|
|
$data->{'companyInvoiceId'} = $object->getCompanyInvoiceId(); |
144
|
|
|
} |
145
|
|
|
if (null !== $object->getCustomerId()) { |
146
|
|
|
$data->{'customerId'} = $object->getCustomerId(); |
147
|
|
|
} |
148
|
|
|
if (null !== $object->getStatus()) { |
149
|
|
|
$data->{'status'} = $object->getStatus(); |
150
|
|
|
} |
151
|
|
|
if (null !== $object->getCustomerRelationId()) { |
152
|
|
|
$data->{'customerRelationId'} = $object->getCustomerRelationId(); |
153
|
|
|
} |
154
|
|
|
if (null !== $object->getCustomerName()) { |
155
|
|
|
$data->{'customerName'} = $object->getCustomerName(); |
156
|
|
|
} |
157
|
|
|
if (null !== $object->getCustomerContactPerson()) { |
158
|
|
|
$data->{'customerContactPerson'} = $object->getCustomerContactPerson(); |
159
|
|
|
} |
160
|
|
|
if (null !== $object->getCustomerEmail()) { |
161
|
|
|
$data->{'customerEmail'} = $object->getCustomerEmail(); |
162
|
|
|
} |
163
|
|
|
if (null !== $object->getCustomerAddress()) { |
164
|
|
|
$data->{'customerAddress'} = $object->getCustomerAddress(); |
165
|
|
|
} |
166
|
|
|
if (null !== $object->getCustomerVatNumber()) { |
167
|
|
|
$data->{'customerVatNumber'} = $object->getCustomerVatNumber(); |
168
|
|
|
} |
169
|
|
|
if (null !== $object->getDate()) { |
170
|
|
|
$data->{'date'} = $object->getDate()->format('Y-m-d\\TH:i:sP'); |
171
|
|
|
} |
172
|
|
|
if (null !== $object->getDueDate()) { |
173
|
|
|
$data->{'dueDate'} = $object->getDueDate()->format('Y-m-d\\TH:i:sP'); |
174
|
|
|
} |
175
|
|
|
if (null !== $object->getReference()) { |
176
|
|
|
$data->{'reference'} = $object->getReference(); |
177
|
|
|
} |
178
|
|
|
if (null !== $object->getNotes()) { |
179
|
|
|
$data->{'notes'} = $object->getNotes(); |
180
|
|
|
} |
181
|
|
|
if (null !== $object->getTotal()) { |
182
|
|
|
$data->{'total'} = $object->getTotal(); |
183
|
|
|
} |
184
|
|
|
if (null !== $object->getTotalWithoutExchangeRate()) { |
185
|
|
|
$data->{'totalWithoutExchangeRate'} = $object->getTotalWithoutExchangeRate(); |
186
|
|
|
} |
187
|
|
|
if (null !== $object->getTotalExTax()) { |
188
|
|
|
$data->{'totalExTax'} = $object->getTotalExTax(); |
189
|
|
|
} |
190
|
|
|
if (null !== $object->getTotalExTaxWithoutExchangeRate()) { |
191
|
|
|
$data->{'totalExTaxWithoutExchangeRate'} = $object->getTotalExTaxWithoutExchangeRate(); |
192
|
|
|
} |
193
|
|
|
if (null !== $object->getAdditionalNotes()) { |
194
|
|
|
$data->{'additionalNotes'} = $object->getAdditionalNotes(); |
195
|
|
|
} |
196
|
|
|
if (null !== $object->getInternNotes()) { |
197
|
|
|
$data->{'internNotes'} = $object->getInternNotes(); |
198
|
|
|
} |
199
|
|
|
if (null !== $object->getCurrency()) { |
200
|
|
|
$data->{'currency'} = $object->getCurrency(); |
201
|
|
|
} |
202
|
|
|
if (null !== $object->getLanguage()) { |
203
|
|
|
$data->{'language'} = $object->getLanguage(); |
204
|
|
|
} |
205
|
|
|
if (null !== $object->getExchangeRate()) { |
206
|
|
|
$data->{'exchangeRate'} = $object->getExchangeRate(); |
207
|
|
|
} |
208
|
|
|
if (null !== $object->getCredit()) { |
209
|
|
|
$data->{'credit'} = $object->getCredit(); |
210
|
|
|
} |
211
|
|
|
if (null !== $object->getInvoiceRows()) { |
212
|
|
|
$values = []; |
213
|
|
|
foreach ($object->getInvoiceRows() as $value) { |
214
|
|
|
$values[] = $this->normalizer->normalize($value, 'json', $context); |
215
|
|
|
} |
216
|
|
|
$data->{'invoiceRows'} = $values; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return $data; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|