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\Normalizer; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
18
|
|
|
|
19
|
|
|
class InvoiceNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
20
|
|
|
{ |
21
|
|
|
use DenormalizerAwareTrait; |
22
|
|
|
use NormalizerAwareTrait; |
23
|
|
|
|
24
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
25
|
|
|
{ |
26
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Invoice'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Invoice'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
35
|
|
|
{ |
36
|
|
|
if (!is_object($data)) { |
37
|
|
|
return null; |
38
|
|
|
} |
39
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Model\Invoice(); |
40
|
|
|
if (property_exists($data, 'id') && $data->{'id'} !== null) { |
41
|
|
|
$object->setId($data->{'id'}); |
42
|
|
|
} elseif (property_exists($data, 'id') && $data->{'id'} === null) { |
43
|
|
|
$object->setId(null); |
44
|
|
|
} |
45
|
|
|
if (property_exists($data, 'clientId') && $data->{'clientId'} !== null) { |
46
|
|
|
$object->setClientId($data->{'clientId'}); |
47
|
|
|
} elseif (property_exists($data, 'clientId') && $data->{'clientId'} === null) { |
48
|
|
|
$object->setClientId(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'companyInvoicePrefix') && $data->{'companyInvoicePrefix'} !== null) { |
51
|
|
|
$object->setCompanyInvoicePrefix($data->{'companyInvoicePrefix'}); |
52
|
|
|
} elseif (property_exists($data, 'companyInvoicePrefix') && $data->{'companyInvoicePrefix'} === null) { |
53
|
|
|
$object->setCompanyInvoicePrefix(null); |
54
|
|
|
} |
55
|
|
|
if (property_exists($data, 'companyInvoiceId') && $data->{'companyInvoiceId'} !== null) { |
56
|
|
|
$object->setCompanyInvoiceId($data->{'companyInvoiceId'}); |
57
|
|
|
} elseif (property_exists($data, 'companyInvoiceId') && $data->{'companyInvoiceId'} === null) { |
58
|
|
|
$object->setCompanyInvoiceId(null); |
59
|
|
|
} |
60
|
|
|
if (property_exists($data, 'customerId') && $data->{'customerId'} !== null) { |
61
|
|
|
$object->setCustomerId($data->{'customerId'}); |
62
|
|
|
} elseif (property_exists($data, 'customerId') && $data->{'customerId'} === null) { |
63
|
|
|
$object->setCustomerId(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'status') && $data->{'status'} !== null) { |
66
|
|
|
$object->setStatus($data->{'status'}); |
67
|
|
|
} elseif (property_exists($data, 'status') && $data->{'status'} === null) { |
68
|
|
|
$object->setStatus(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'customerRelationId') && $data->{'customerRelationId'} !== null) { |
71
|
|
|
$object->setCustomerRelationId($data->{'customerRelationId'}); |
72
|
|
|
} elseif (property_exists($data, 'customerRelationId') && $data->{'customerRelationId'} === null) { |
73
|
|
|
$object->setCustomerRelationId(null); |
74
|
|
|
} |
75
|
|
|
if (property_exists($data, 'customerName') && $data->{'customerName'} !== null) { |
76
|
|
|
$object->setCustomerName($data->{'customerName'}); |
77
|
|
|
} elseif (property_exists($data, 'customerName') && $data->{'customerName'} === null) { |
78
|
|
|
$object->setCustomerName(null); |
79
|
|
|
} |
80
|
|
|
if (property_exists($data, 'customerContactPerson') && $data->{'customerContactPerson'} !== null) { |
81
|
|
|
$object->setCustomerContactPerson($data->{'customerContactPerson'}); |
82
|
|
|
} elseif (property_exists($data, 'customerContactPerson') && $data->{'customerContactPerson'} === null) { |
83
|
|
|
$object->setCustomerContactPerson(null); |
84
|
|
|
} |
85
|
|
|
if (property_exists($data, 'customerEmail') && $data->{'customerEmail'} !== null) { |
86
|
|
|
$object->setCustomerEmail($data->{'customerEmail'}); |
87
|
|
|
} elseif (property_exists($data, 'customerEmail') && $data->{'customerEmail'} === null) { |
88
|
|
|
$object->setCustomerEmail(null); |
89
|
|
|
} |
90
|
|
|
if (property_exists($data, 'customerAddress') && $data->{'customerAddress'} !== null) { |
91
|
|
|
$object->setCustomerAddress($data->{'customerAddress'}); |
92
|
|
|
} elseif (property_exists($data, 'customerAddress') && $data->{'customerAddress'} === null) { |
93
|
|
|
$object->setCustomerAddress(null); |
94
|
|
|
} |
95
|
|
|
if (property_exists($data, 'customerVatNumber') && $data->{'customerVatNumber'} !== null) { |
96
|
|
|
$object->setCustomerVatNumber($data->{'customerVatNumber'}); |
97
|
|
|
} elseif (property_exists($data, 'customerVatNumber') && $data->{'customerVatNumber'} === null) { |
98
|
|
|
$object->setCustomerVatNumber(null); |
99
|
|
|
} |
100
|
|
|
if (property_exists($data, 'date') && $data->{'date'} !== null) { |
101
|
|
|
$object->setDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'date'})); |
102
|
|
|
} elseif (property_exists($data, 'date') && $data->{'date'} === null) { |
103
|
|
|
$object->setDate(null); |
104
|
|
|
} |
105
|
|
|
if (property_exists($data, 'dueDate') && $data->{'dueDate'} !== null) { |
106
|
|
|
$object->setDueDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'dueDate'})); |
107
|
|
|
} elseif (property_exists($data, 'dueDate') && $data->{'dueDate'} === null) { |
108
|
|
|
$object->setDueDate(null); |
109
|
|
|
} |
110
|
|
|
if (property_exists($data, 'reference') && $data->{'reference'} !== null) { |
111
|
|
|
$object->setReference($data->{'reference'}); |
112
|
|
|
} elseif (property_exists($data, 'reference') && $data->{'reference'} === null) { |
113
|
|
|
$object->setReference(null); |
114
|
|
|
} |
115
|
|
|
if (property_exists($data, 'notes') && $data->{'notes'} !== null) { |
116
|
|
|
$object->setNotes($data->{'notes'}); |
117
|
|
|
} elseif (property_exists($data, 'notes') && $data->{'notes'} === null) { |
118
|
|
|
$object->setNotes(null); |
119
|
|
|
} |
120
|
|
|
if (property_exists($data, 'total') && $data->{'total'} !== null) { |
121
|
|
|
$object->setTotal($data->{'total'}); |
122
|
|
|
} elseif (property_exists($data, 'total') && $data->{'total'} === null) { |
123
|
|
|
$object->setTotal(null); |
124
|
|
|
} |
125
|
|
|
if (property_exists($data, 'totalWithoutExchangeRate') && $data->{'totalWithoutExchangeRate'} !== null) { |
126
|
|
|
$object->setTotalWithoutExchangeRate($data->{'totalWithoutExchangeRate'}); |
127
|
|
|
} elseif (property_exists($data, 'totalWithoutExchangeRate') && $data->{'totalWithoutExchangeRate'} === null) { |
128
|
|
|
$object->setTotalWithoutExchangeRate(null); |
129
|
|
|
} |
130
|
|
|
if (property_exists($data, 'totalExTax') && $data->{'totalExTax'} !== null) { |
131
|
|
|
$object->setTotalExTax($data->{'totalExTax'}); |
132
|
|
|
} elseif (property_exists($data, 'totalExTax') && $data->{'totalExTax'} === null) { |
133
|
|
|
$object->setTotalExTax(null); |
134
|
|
|
} |
135
|
|
|
if (property_exists($data, 'totalExTaxWithoutExchangeRate') && $data->{'totalExTaxWithoutExchangeRate'} !== null) { |
136
|
|
|
$object->setTotalExTaxWithoutExchangeRate($data->{'totalExTaxWithoutExchangeRate'}); |
137
|
|
|
} elseif (property_exists($data, 'totalExTaxWithoutExchangeRate') && $data->{'totalExTaxWithoutExchangeRate'} === null) { |
138
|
|
|
$object->setTotalExTaxWithoutExchangeRate(null); |
139
|
|
|
} |
140
|
|
|
if (property_exists($data, 'additionalNotes') && $data->{'additionalNotes'} !== null) { |
141
|
|
|
$object->setAdditionalNotes($data->{'additionalNotes'}); |
142
|
|
|
} elseif (property_exists($data, 'additionalNotes') && $data->{'additionalNotes'} === null) { |
143
|
|
|
$object->setAdditionalNotes(null); |
144
|
|
|
} |
145
|
|
|
if (property_exists($data, 'internNotes') && $data->{'internNotes'} !== null) { |
146
|
|
|
$object->setInternNotes($data->{'internNotes'}); |
147
|
|
|
} elseif (property_exists($data, 'internNotes') && $data->{'internNotes'} === null) { |
148
|
|
|
$object->setInternNotes(null); |
149
|
|
|
} |
150
|
|
|
if (property_exists($data, 'currency') && $data->{'currency'} !== null) { |
151
|
|
|
$object->setCurrency($data->{'currency'}); |
152
|
|
|
} elseif (property_exists($data, 'currency') && $data->{'currency'} === null) { |
153
|
|
|
$object->setCurrency(null); |
154
|
|
|
} |
155
|
|
|
if (property_exists($data, 'language') && $data->{'language'} !== null) { |
156
|
|
|
$object->setLanguage($data->{'language'}); |
157
|
|
|
} elseif (property_exists($data, 'language') && $data->{'language'} === null) { |
158
|
|
|
$object->setLanguage(null); |
159
|
|
|
} |
160
|
|
|
if (property_exists($data, 'exchangeRate') && $data->{'exchangeRate'} !== null) { |
161
|
|
|
$object->setExchangeRate($data->{'exchangeRate'}); |
162
|
|
|
} elseif (property_exists($data, 'exchangeRate') && $data->{'exchangeRate'} === null) { |
163
|
|
|
$object->setExchangeRate(null); |
164
|
|
|
} |
165
|
|
|
if (property_exists($data, 'credit') && $data->{'credit'} !== null) { |
166
|
|
|
$object->setCredit($data->{'credit'}); |
167
|
|
|
} elseif (property_exists($data, 'credit') && $data->{'credit'} === null) { |
168
|
|
|
$object->setCredit(null); |
169
|
|
|
} |
170
|
|
|
if (property_exists($data, 'invoiceRows') && $data->{'invoiceRows'} !== null) { |
171
|
|
|
$values = []; |
172
|
|
|
foreach ($data->{'invoiceRows'} as $value) { |
173
|
|
|
$values[] = $this->denormalizer->denormalize($value, 'ConnectHolland\\TimechimpBundle\\Api\\Model\\InvoiceRow', 'json', $context); |
174
|
|
|
} |
175
|
|
|
$object->setInvoiceRows($values); |
176
|
|
|
} elseif (property_exists($data, 'invoiceRows') && $data->{'invoiceRows'} === null) { |
177
|
|
|
$object->setInvoiceRows(null); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $object; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function normalize($object, $format = null, array $context = []) |
184
|
|
|
{ |
185
|
|
|
$data = new \stdClass(); |
186
|
|
|
if (null !== $object->getId()) { |
187
|
|
|
$data->{'id'} = $object->getId(); |
188
|
|
|
} else { |
189
|
|
|
$data->{'id'} = null; |
190
|
|
|
} |
191
|
|
|
if (null !== $object->getClientId()) { |
192
|
|
|
$data->{'clientId'} = $object->getClientId(); |
193
|
|
|
} else { |
194
|
|
|
$data->{'clientId'} = null; |
195
|
|
|
} |
196
|
|
|
if (null !== $object->getCompanyInvoicePrefix()) { |
197
|
|
|
$data->{'companyInvoicePrefix'} = $object->getCompanyInvoicePrefix(); |
198
|
|
|
} else { |
199
|
|
|
$data->{'companyInvoicePrefix'} = null; |
200
|
|
|
} |
201
|
|
|
if (null !== $object->getCompanyInvoiceId()) { |
202
|
|
|
$data->{'companyInvoiceId'} = $object->getCompanyInvoiceId(); |
203
|
|
|
} else { |
204
|
|
|
$data->{'companyInvoiceId'} = null; |
205
|
|
|
} |
206
|
|
|
if (null !== $object->getCustomerId()) { |
207
|
|
|
$data->{'customerId'} = $object->getCustomerId(); |
208
|
|
|
} else { |
209
|
|
|
$data->{'customerId'} = null; |
210
|
|
|
} |
211
|
|
|
if (null !== $object->getStatus()) { |
212
|
|
|
$data->{'status'} = $object->getStatus(); |
213
|
|
|
} else { |
214
|
|
|
$data->{'status'} = null; |
215
|
|
|
} |
216
|
|
|
if (null !== $object->getCustomerRelationId()) { |
217
|
|
|
$data->{'customerRelationId'} = $object->getCustomerRelationId(); |
218
|
|
|
} else { |
219
|
|
|
$data->{'customerRelationId'} = null; |
220
|
|
|
} |
221
|
|
|
if (null !== $object->getCustomerName()) { |
222
|
|
|
$data->{'customerName'} = $object->getCustomerName(); |
223
|
|
|
} else { |
224
|
|
|
$data->{'customerName'} = null; |
225
|
|
|
} |
226
|
|
|
if (null !== $object->getCustomerContactPerson()) { |
227
|
|
|
$data->{'customerContactPerson'} = $object->getCustomerContactPerson(); |
228
|
|
|
} else { |
229
|
|
|
$data->{'customerContactPerson'} = null; |
230
|
|
|
} |
231
|
|
|
if (null !== $object->getCustomerEmail()) { |
232
|
|
|
$data->{'customerEmail'} = $object->getCustomerEmail(); |
233
|
|
|
} else { |
234
|
|
|
$data->{'customerEmail'} = null; |
235
|
|
|
} |
236
|
|
|
if (null !== $object->getCustomerAddress()) { |
237
|
|
|
$data->{'customerAddress'} = $object->getCustomerAddress(); |
238
|
|
|
} else { |
239
|
|
|
$data->{'customerAddress'} = null; |
240
|
|
|
} |
241
|
|
|
if (null !== $object->getCustomerVatNumber()) { |
242
|
|
|
$data->{'customerVatNumber'} = $object->getCustomerVatNumber(); |
243
|
|
|
} else { |
244
|
|
|
$data->{'customerVatNumber'} = null; |
245
|
|
|
} |
246
|
|
|
if (null !== $object->getDate()) { |
247
|
|
|
$data->{'date'} = $object->getDate()->format('Y-m-d\\TH:i:s'); |
248
|
|
|
} else { |
249
|
|
|
$data->{'date'} = null; |
250
|
|
|
} |
251
|
|
|
if (null !== $object->getDueDate()) { |
252
|
|
|
$data->{'dueDate'} = $object->getDueDate()->format('Y-m-d\\TH:i:s'); |
253
|
|
|
} else { |
254
|
|
|
$data->{'dueDate'} = null; |
255
|
|
|
} |
256
|
|
|
if (null !== $object->getReference()) { |
257
|
|
|
$data->{'reference'} = $object->getReference(); |
258
|
|
|
} else { |
259
|
|
|
$data->{'reference'} = null; |
260
|
|
|
} |
261
|
|
|
if (null !== $object->getNotes()) { |
262
|
|
|
$data->{'notes'} = $object->getNotes(); |
263
|
|
|
} else { |
264
|
|
|
$data->{'notes'} = null; |
265
|
|
|
} |
266
|
|
|
if (null !== $object->getTotal()) { |
267
|
|
|
$data->{'total'} = $object->getTotal(); |
268
|
|
|
} else { |
269
|
|
|
$data->{'total'} = null; |
270
|
|
|
} |
271
|
|
|
if (null !== $object->getTotalWithoutExchangeRate()) { |
272
|
|
|
$data->{'totalWithoutExchangeRate'} = $object->getTotalWithoutExchangeRate(); |
273
|
|
|
} else { |
274
|
|
|
$data->{'totalWithoutExchangeRate'} = null; |
275
|
|
|
} |
276
|
|
|
if (null !== $object->getTotalExTax()) { |
277
|
|
|
$data->{'totalExTax'} = $object->getTotalExTax(); |
278
|
|
|
} else { |
279
|
|
|
$data->{'totalExTax'} = null; |
280
|
|
|
} |
281
|
|
|
if (null !== $object->getTotalExTaxWithoutExchangeRate()) { |
282
|
|
|
$data->{'totalExTaxWithoutExchangeRate'} = $object->getTotalExTaxWithoutExchangeRate(); |
283
|
|
|
} else { |
284
|
|
|
$data->{'totalExTaxWithoutExchangeRate'} = null; |
285
|
|
|
} |
286
|
|
|
if (null !== $object->getAdditionalNotes()) { |
287
|
|
|
$data->{'additionalNotes'} = $object->getAdditionalNotes(); |
288
|
|
|
} else { |
289
|
|
|
$data->{'additionalNotes'} = null; |
290
|
|
|
} |
291
|
|
|
if (null !== $object->getInternNotes()) { |
292
|
|
|
$data->{'internNotes'} = $object->getInternNotes(); |
293
|
|
|
} else { |
294
|
|
|
$data->{'internNotes'} = null; |
295
|
|
|
} |
296
|
|
|
if (null !== $object->getCurrency()) { |
297
|
|
|
$data->{'currency'} = $object->getCurrency(); |
298
|
|
|
} else { |
299
|
|
|
$data->{'currency'} = null; |
300
|
|
|
} |
301
|
|
|
if (null !== $object->getLanguage()) { |
302
|
|
|
$data->{'language'} = $object->getLanguage(); |
303
|
|
|
} else { |
304
|
|
|
$data->{'language'} = null; |
305
|
|
|
} |
306
|
|
|
if (null !== $object->getExchangeRate()) { |
307
|
|
|
$data->{'exchangeRate'} = $object->getExchangeRate(); |
308
|
|
|
} else { |
309
|
|
|
$data->{'exchangeRate'} = null; |
310
|
|
|
} |
311
|
|
|
if (null !== $object->getCredit()) { |
312
|
|
|
$data->{'credit'} = $object->getCredit(); |
313
|
|
|
} else { |
314
|
|
|
$data->{'credit'} = null; |
315
|
|
|
} |
316
|
|
|
if (null !== $object->getInvoiceRows()) { |
317
|
|
|
$values = []; |
318
|
|
|
foreach ($object->getInvoiceRows() as $value) { |
319
|
|
|
$values[] = $this->normalizer->normalize($value, 'json', $context); |
320
|
|
|
} |
321
|
|
|
$data->{'invoiceRows'} = $values; |
322
|
|
|
} else { |
323
|
|
|
$data->{'invoiceRows'} = null; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
return $data; |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|