1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NFePHP\EFDReinf\Factories; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class EFD-Reinf EvtTotal Event R-5001 constructor |
7
|
|
|
* |
8
|
|
|
* @category API |
9
|
|
|
* @package NFePHP\EFDReinf |
10
|
|
|
* @copyright NFePHP Copyright (c) 2017 |
11
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPLv3+ |
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
13
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+ |
14
|
|
|
* @author Roberto L. Machado <linux.rlm at gmail dot com> |
15
|
|
|
* @link http://github.com/nfephp-org/sped-efdreinf for the canonical source repository |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use NFePHP\EFDReinf\Common\Factory; |
19
|
|
|
use NFePHP\EFDReinf\Common\FactoryInterface; |
20
|
|
|
use NFePHP\EFDReinf\Common\FactoryId; |
21
|
|
|
use NFePHP\Common\Certificate; |
22
|
|
|
use stdClass; |
23
|
|
|
|
24
|
|
|
class EvtTotalContrib extends Factory implements FactoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Constructor |
28
|
|
|
* @param string $config |
29
|
|
|
* @param stdClass $std |
30
|
|
|
* @param Certificate $certificate |
31
|
|
|
* @param string $data |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
$config, |
35
|
|
|
stdClass $std, |
36
|
|
|
Certificate $certificate = null, |
37
|
|
|
$data = '' |
38
|
|
|
) { |
39
|
|
|
$params = new \stdClass(); |
40
|
|
|
$params->evtName = 'evtTotalContrib'; |
41
|
|
|
$params->evtTag = 'evtTotalContrib'; |
42
|
|
|
$params->evtAlias = 'R-5011'; |
43
|
|
|
parent::__construct($config, $std, $params, $certificate, $data); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Node constructor |
48
|
|
|
*/ |
49
|
|
|
protected function toNode() |
50
|
|
|
{ |
51
|
|
|
$ideContri = $this->node->getElementsByTagName('ideContri')->item(0); |
52
|
|
|
//o idEvento pode variar de evento para evento |
53
|
|
|
//então cada factory individualmente terá de construir o seu |
54
|
|
|
$ideEvento = $this->dom->createElement("ideEvento"); |
55
|
|
|
$this->dom->addChild( |
56
|
|
|
$ideEvento, |
57
|
|
|
"perApur", |
58
|
|
|
$this->std->perapur, |
59
|
|
|
true |
60
|
|
|
); |
61
|
|
|
$this->node->insertBefore($ideEvento, $ideContri); |
62
|
|
|
//tag deste evento em particular |
63
|
|
|
$ideRecRetorno = $this->dom->createElement("ideRecRetorno"); |
64
|
|
|
$ideStatus = $this->dom->createElement("ideStatus"); |
65
|
|
|
$this->dom->addChild( |
66
|
|
|
$ideStatus, |
67
|
|
|
"cdRetorno", |
68
|
|
|
$this->std->cdretorno, |
69
|
|
|
true |
70
|
|
|
); |
71
|
|
|
$this->dom->addChild( |
72
|
|
|
$ideStatus, |
73
|
|
|
"descRetorno", |
74
|
|
|
$this->std->descretorno, |
75
|
|
|
true |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
if (!empty($this->std->regocorrs)) { |
80
|
|
|
foreach ($this->std->regocorrs as $r) { |
81
|
|
|
$regOcorrs = $this->dom->createElement("regOcorrs"); |
82
|
|
|
$this->dom->addChild( |
83
|
|
|
$regOcorrs, |
84
|
|
|
"tpOcorr", |
85
|
|
|
$r->tpocorr, |
86
|
|
|
true |
87
|
|
|
); |
88
|
|
|
$this->dom->addChild( |
89
|
|
|
$regOcorrs, |
90
|
|
|
"localErroAviso", |
91
|
|
|
$r->localerroaviso, |
92
|
|
|
true |
93
|
|
|
); |
94
|
|
|
$this->dom->addChild( |
95
|
|
|
$regOcorrs, |
96
|
|
|
"codResp", |
97
|
|
|
$r->codresp, |
98
|
|
|
true |
99
|
|
|
); |
100
|
|
|
$this->dom->addChild( |
101
|
|
|
$regOcorrs, |
102
|
|
|
"dscResp", |
103
|
|
|
$r->dscresp, |
104
|
|
|
true |
105
|
|
|
); |
106
|
|
|
$ideStatus->appendChild($regOcorrs); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$ideRecRetorno->appendChild($ideStatus); |
110
|
|
|
$this->node->appendChild($ideRecRetorno); |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
$infoRecEv = $this->dom->createElement("infoRecEv"); |
114
|
|
|
$this->dom->addChild( |
115
|
|
|
$infoRecEv, |
116
|
|
|
"dhProcess", |
117
|
|
|
$this->std->dhprocess, |
118
|
|
|
true |
119
|
|
|
); |
120
|
|
|
$this->dom->addChild( |
121
|
|
|
$infoRecEv, |
122
|
|
|
"tpEv", |
123
|
|
|
$this->std->tpev, |
124
|
|
|
true |
125
|
|
|
); |
126
|
|
|
$this->dom->addChild( |
127
|
|
|
$infoRecEv, |
128
|
|
|
"idEv", |
129
|
|
|
$this->std->idev, |
130
|
|
|
true |
131
|
|
|
); |
132
|
|
|
$this->dom->addChild( |
133
|
|
|
$infoRecEv, |
134
|
|
|
"hash", |
135
|
|
|
$this->std->hash, |
136
|
|
|
true |
137
|
|
|
); |
138
|
|
|
$this->node->appendChild($infoRecEv); |
139
|
|
|
|
140
|
|
|
if (!empty($this->std->infototalcontrib)) { |
141
|
|
|
foreach ($this->std->infototalcontrib as $info) { |
142
|
|
|
$infoTotal = $this->dom->createElement("infoTotalContrib"); |
143
|
|
|
$this->dom->addChild( |
144
|
|
|
$infoTotal, |
145
|
|
|
"nrRecArqBase", |
146
|
|
|
$info->nrrecarqbase, |
147
|
|
|
false |
148
|
|
|
); |
149
|
|
|
$this->dom->addChild( |
150
|
|
|
$infoTotal, |
151
|
|
|
"indExistInfo", |
152
|
|
|
$info->indexistinfo, |
153
|
|
|
true |
154
|
|
|
); |
155
|
|
|
$infoTotal = $this->incRTom( |
156
|
|
|
$infoTotal, |
157
|
|
|
!empty($info->rtom) ? $info->rtom : null |
158
|
|
|
); |
159
|
|
|
$infoTotal = $this->incRPrest( |
160
|
|
|
$infoTotal, |
161
|
|
|
!empty($info->rprest) ? $info->rprest : null |
162
|
|
|
); |
163
|
|
|
$infoTotal = $this->incRRecRepAD( |
164
|
|
|
$infoTotal, |
165
|
|
|
!empty($info->rrecrepad) ? $info->rrecrepad : null |
166
|
|
|
); |
167
|
|
|
$infoTotal = $this->incRComl( |
168
|
|
|
$infoTotal, |
169
|
|
|
!empty($info->rcoml) ? $info->rcoml : null |
170
|
|
|
); |
171
|
|
|
$infoTotal = $this->incRCPRB( |
172
|
|
|
$infoTotal, |
173
|
|
|
!empty($info->rcprb) ? $info->rcprb : null |
174
|
|
|
); |
175
|
|
|
$this->node->appendChild($infoTotal); |
176
|
|
|
$infoTotal = null; |
|
|
|
|
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
//$this->node->appendChild($infoContrib); |
|
|
|
|
180
|
|
|
|
181
|
|
|
$this->reinf->appendChild($this->node); |
182
|
|
|
$this->xml = $this->dom->saveXML($this->reinf); |
183
|
|
|
//$this->sign($this->evtTag); |
|
|
|
|
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Include RTom node |
188
|
|
|
* @param \DOMElement $info |
189
|
|
|
* @param \stdClass $rtom |
190
|
|
|
* @return \DOMElement |
191
|
|
|
*/ |
192
|
|
|
protected function incRTom($info, $rtom) |
193
|
|
|
{ |
194
|
|
|
if (empty($rtom)) { |
195
|
|
|
return $info; |
196
|
|
|
} |
197
|
|
|
foreach ($rtom as $r) { |
|
|
|
|
198
|
|
|
$i = $this->dom->createElement("RTom"); |
199
|
|
|
$this->dom->addChild( |
200
|
|
|
$i, |
201
|
|
|
"cnpjPrestador", |
202
|
|
|
$r->cnpjprestador, |
203
|
|
|
true |
204
|
|
|
); |
205
|
|
|
$this->dom->addChild( |
206
|
|
|
$i, |
207
|
|
|
"vlrTotalBaseRet", |
208
|
|
|
number_format($r->vlrtotalbaseret, 2, ',', ''), |
209
|
|
|
true |
210
|
|
|
); |
211
|
|
|
if (!empty($r->infocrtom)) { |
212
|
|
|
foreach ($r->infocrtom as $itom) { |
213
|
|
|
$infoCRTom = $this->dom->createElement("infoCRTom"); |
214
|
|
|
$this->dom->addChild( |
215
|
|
|
$infoCRTom, |
216
|
|
|
"CRTom", |
217
|
|
|
$itom->crtom, |
218
|
|
|
true |
219
|
|
|
); |
220
|
|
|
$this->dom->addChild( |
221
|
|
|
$infoCRTom, |
222
|
|
|
"vlrCRTom", |
223
|
|
|
!empty($itom->vlrcrtom) ? number_format($itom->vlrcrtom, 2, ',', '') : null, |
224
|
|
|
false |
225
|
|
|
); |
226
|
|
|
$this->dom->addChild( |
227
|
|
|
$infoCRTom, |
228
|
|
|
"vlrCRTomSusp", |
229
|
|
|
!empty($itom->vlrcrtomsusp) ? number_format($itom->vlrcrtomsusp, 2, ',', '') : null, |
230
|
|
|
false |
231
|
|
|
); |
232
|
|
|
$i->appendChild($infoCRTom); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
$info->appendChild($i); |
236
|
|
|
} |
237
|
|
|
return $info; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Include RPrest node |
242
|
|
|
* @param \DOMElement $info |
243
|
|
|
* @param \stdClass $rprest |
244
|
|
|
* @return \DOMElement |
245
|
|
|
*/ |
246
|
|
|
protected function incRPrest($info, $rprest) |
247
|
|
|
{ |
248
|
|
|
if (empty($rprest)) { |
249
|
|
|
return $info; |
250
|
|
|
} |
251
|
|
|
foreach ($rprest as $r) { |
|
|
|
|
252
|
|
|
$i = $this->dom->createElement("RPrest"); |
253
|
|
|
$this->dom->addChild( |
254
|
|
|
$i, |
255
|
|
|
"tpInscTomador", |
256
|
|
|
$r->tpinsctomador, |
257
|
|
|
true |
258
|
|
|
); |
259
|
|
|
$this->dom->addChild( |
260
|
|
|
$i, |
261
|
|
|
"nrInscTomador", |
262
|
|
|
$r->nrinsctomador, |
263
|
|
|
true |
264
|
|
|
); |
265
|
|
|
$this->dom->addChild( |
266
|
|
|
$i, |
267
|
|
|
"vlrTotalBaseRet", |
268
|
|
|
number_format($r->vlrtotalbaseret, 2, ',', ''), |
269
|
|
|
true |
270
|
|
|
); |
271
|
|
|
$this->dom->addChild( |
272
|
|
|
$i, |
273
|
|
|
"vlrTotalRetPrinc", |
274
|
|
|
number_format($r->vlrtotalretprinc, 2, ',', ''), |
275
|
|
|
true |
276
|
|
|
); |
277
|
|
|
$this->dom->addChild( |
278
|
|
|
$i, |
279
|
|
|
"vlrTotalRetAdic", |
280
|
|
|
!empty($r->vlrtotalretadic) ? number_format($r->vlrtotalretadic, 2, ',', '') : null, |
281
|
|
|
false |
282
|
|
|
); |
283
|
|
|
$this->dom->addChild( |
284
|
|
|
$i, |
285
|
|
|
"vlrTotalNRetPrinc", |
286
|
|
|
!empty($r->vlrtotalnretprinc) ? number_format($r->vlrtotalnretprinc, 2, ',', '') : null, |
287
|
|
|
false |
288
|
|
|
); |
289
|
|
|
$this->dom->addChild( |
290
|
|
|
$i, |
291
|
|
|
"vlrTotalNRetAdic", |
292
|
|
|
!empty($r->vlrtotalnretadic) ? number_format($r->vlrtotalnretadic, 2, ',', '') : null, |
293
|
|
|
false |
294
|
|
|
); |
295
|
|
|
$info->appendChild($i); |
296
|
|
|
} |
297
|
|
|
return $info; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Include RRecRepAD node |
302
|
|
|
* @param \DOMElement $info |
303
|
|
|
* @param \stdClass $rrecrepad |
304
|
|
|
* @return \DOMElement |
305
|
|
|
*/ |
306
|
|
|
protected function incRRecRepAD($info, $rrecrepad) |
307
|
|
|
{ |
308
|
|
|
if (empty($rrecrepad)) { |
309
|
|
|
return $info; |
310
|
|
|
} |
311
|
|
|
foreach ($rrecrepad as $r) { |
|
|
|
|
312
|
|
|
$i = $this->dom->createElement("RRecRepAD"); |
313
|
|
|
$this->dom->addChild( |
314
|
|
|
$i, |
315
|
|
|
"cnpjAssocDesp", |
316
|
|
|
$r->cnpjassocdesp, |
317
|
|
|
true |
318
|
|
|
); |
319
|
|
|
$this->dom->addChild( |
320
|
|
|
$i, |
321
|
|
|
"vlrTotalRep", |
322
|
|
|
number_format($r->vlrtotalrep, 2, ',', ''), |
323
|
|
|
true |
324
|
|
|
); |
325
|
|
|
$this->dom->addChild( |
326
|
|
|
$i, |
327
|
|
|
"CRRecRepAD", |
328
|
|
|
$r->crrecrepad, |
329
|
|
|
true |
330
|
|
|
); |
331
|
|
|
$this->dom->addChild( |
332
|
|
|
$i, |
333
|
|
|
"vlrCRRecRepAD", |
334
|
|
|
number_format($r->vlrcrrecrepad, 2, ',', ''), |
335
|
|
|
true |
336
|
|
|
); |
337
|
|
|
$this->dom->addChild( |
338
|
|
|
$i, |
339
|
|
|
"vlrCRRecRepADSusp", |
340
|
|
|
!empty($r->vlrcrrecrepadsusp) ? number_format($r->vlrcrrecrepadsusp, 2, ',', '') : null, |
341
|
|
|
false |
342
|
|
|
); |
343
|
|
|
$info->appendChild($i); |
344
|
|
|
} |
345
|
|
|
return $info; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Include RComl node |
350
|
|
|
* @param \DOMElement $info |
351
|
|
|
* @param \stdClass $rcoml |
352
|
|
|
* @return \DOMElement |
353
|
|
|
*/ |
354
|
|
|
protected function incRComl($info, $rcoml) |
355
|
|
|
{ |
356
|
|
|
if (empty($rcoml)) { |
357
|
|
|
return $info; |
358
|
|
|
} |
359
|
|
|
foreach ($rcoml as $r) { |
|
|
|
|
360
|
|
|
$i = $this->dom->createElement("RComl"); |
361
|
|
|
$this->dom->addChild( |
362
|
|
|
$i, |
363
|
|
|
"CRComl", |
364
|
|
|
$r->crcoml, |
365
|
|
|
true |
366
|
|
|
); |
367
|
|
|
$this->dom->addChild( |
368
|
|
|
$i, |
369
|
|
|
"vlrCRComl", |
370
|
|
|
number_format($r->vlrcrcoml, 2, ',', ''), |
371
|
|
|
true |
372
|
|
|
); |
373
|
|
|
$this->dom->addChild( |
374
|
|
|
$i, |
375
|
|
|
"vlrCRComlSusp", |
376
|
|
|
!empty($r->vlrcrcomlsusp) ? number_format($r->vlrcrcomlsusp, 2, ',', '') : null, |
377
|
|
|
false |
378
|
|
|
); |
379
|
|
|
$info->appendChild($i); |
380
|
|
|
} |
381
|
|
|
return $info; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Include RCPRB node |
386
|
|
|
* @param \DOMElement $info |
387
|
|
|
* @param \stdClass $rcprb |
388
|
|
|
* @return \DOMElement |
389
|
|
|
*/ |
390
|
|
|
protected function incRCPRB($info, $rcprb) |
391
|
|
|
{ |
392
|
|
|
if (empty($rcprb)) { |
393
|
|
|
return $info; |
394
|
|
|
} |
395
|
|
|
foreach ($rcprb as $r) { |
|
|
|
|
396
|
|
|
$i = $this->dom->createElement("RCPRB"); |
397
|
|
|
$this->dom->addChild( |
398
|
|
|
$i, |
399
|
|
|
"CRCPRB", |
400
|
|
|
$r->crcprb, |
401
|
|
|
true |
402
|
|
|
); |
403
|
|
|
$this->dom->addChild( |
404
|
|
|
$i, |
405
|
|
|
"vlrCRCPRB", |
406
|
|
|
number_format($r->vlrcrcprb, 2, ',', ''), |
407
|
|
|
true |
408
|
|
|
); |
409
|
|
|
$this->dom->addChild( |
410
|
|
|
$i, |
411
|
|
|
"vlrCRCPRBSusp", |
412
|
|
|
!empty($r->vlrcrcprbsusp) ? number_format($r->vlrcrcprbsusp, 2, ',', '') : null, |
413
|
|
|
false |
414
|
|
|
); |
415
|
|
|
$info->appendChild($i); |
416
|
|
|
} |
417
|
|
|
return $info; |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.