Passed
Push — master ( ada905...4ef9b4 )
by Roberto
50s
created

EvtComProd   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 281
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 281
ccs 0
cts 205
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
C toNode() 0 238 11
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtComProd Event S-1260 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
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-esocial for the canonical source repository
16
 */
17
18
use NFePHP\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtComProd extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtComProd';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1260';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $evtid = FactoryId::build(
69
            $this->tpInsc,
70
            $this->nrInsc,
71
            $this->date,
72
            $this->sequencial
73
        );
74
75
        $evtComProd = $this->dom->createElement("evtComProd");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtComProd->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
        $this->dom->addChild(
87
            $ideEvento,
88
            "indRetif",
89
            $this->std->indretif,
90
            true
91
        );
92
        $this->dom->addChild(
93
            $ideEvento,
94
            "nrRecibo",
95
            $this->std->nrrecibo,
96
            true
97
        );
98
        $this->dom->addChild(
99
            $ideEvento,
100
            "indApuracao",
101
            $this->std->indapuracao,
102
            true
103
        );
104
        $this->dom->addChild(
105
            $ideEvento,
106
            "perApur",
107
            $this->std->perapur,
108
            true
109
        );
110
        $this->dom->addChild(
111
            $ideEvento,
112
            "tpAmb",
113
            $this->tpAmb,
114
            true
115
        );
116
        $this->dom->addChild(
117
            $ideEvento,
118
            "procEmi",
119
            $this->procEmi,
120
            true
121
        );
122
        $this->dom->addChild(
123
            $ideEvento,
124
            "verProc",
125
            $this->verProc,
126
            true
127
        );
128
        $this->node->insertBefore($ideEvento, $ideEmpregador);
129
130
        $infoComProd = $this->dom->createElement("infoComProd");
131
132
        $ideEstabel = $this->dom->createElement("ideEstabel");
133
134
        $this->dom->addChild(
135
            $ideEstabel,
136
            "nrInscEstabRural",
137
            $this->std->estabelecimento->nrinscestabrural,
138
            true
139
        );
140
141
        $tpComerc = $this->dom->createElement("tpComerc");
142
143
        $this->dom->addChild(
144
            $tpComerc,
145
            "indComerc",
146
            $this->std->estabelecimento->indcomerc,
147
            true
148
        );
149
150
        $this->dom->addChild(
151
            $tpComerc,
152
            "vrTotCom",
153
            $this->std->estabelecimento->vrtotcom,
154
            true
155
        );
156
157
        if (isset($this->std->estabelecimento->ideadquir)) {
158
            foreach ($this->std->estabelecimento->ideadquir as $adquir) {
159
                $ideAdquir = $this->dom->createElement("ideAdquir");
160
161
                $this->dom->addChild(
162
                    $ideAdquir,
163
                    "tpInsc",
164
                    $adquir->tpinsc,
165
                    true
166
                );
167
168
                $this->dom->addChild(
169
                    $ideAdquir,
170
                    "nrInsc",
171
                    $adquir->nrinsc,
172
                    true
173
                );
174
175
                $this->dom->addChild(
176
                    $ideAdquir,
177
                    "vrComerc",
178
                    $adquir->vrcomerc,
179
                    true
180
                );
181
182
                if (isset($adquir->nfs)) {
183
                    foreach ($adquir->nfs as $nf) {
184
                        $nfs = $this->dom->createElement("nfs");
185
186
                        $this->dom->addChild(
187
                            $nfs,
188
                            "serie",
189
                            !empty($nf->serie) ? $nf->serie : null,
190
                            false
191
                        );
192
193
                        $this->dom->addChild(
194
                            $nfs,
195
                            "nrDocto",
196
                            $nf->nrdocto,
197
                            true
198
                        );
199
200
                        $this->dom->addChild(
201
                            $nfs,
202
                            "dtEmisNF",
203
                            $nf->dtemisnf,
204
                            true
205
                        );
206
207
                        $this->dom->addChild(
208
                            $nfs,
209
                            "vlrBruto",
210
                            $nf->vlrbruto,
211
                            true
212
                        );
213
214
                        $this->dom->addChild(
215
                            $nfs,
216
                            "vrCPDescPR",
217
                            $nf->vrcpdescpr,
218
                            true
219
                        );
220
221
                        $this->dom->addChild(
222
                            $nfs,
223
                            "vrRatDescPR",
224
                            $nf->vrratdescpr,
225
                            true
226
                        );
227
228
                        $this->dom->addChild(
229
                            $nfs,
230
                            "vrSenarDesc",
231
                            $nf->vrsenardesc,
232
                            true
233
                        );
234
235
                        $ideAdquir->appendChild($nfs);
236
                    }
237
                }
238
239
                $tpComerc->appendChild($ideAdquir);
240
            }
241
        }
242
243
        if (isset($this->std->infoprocjud)) {
244
            foreach ($this->std->infoprocjud as $procjud) {
245
                $infoProcJud = $this->dom->createElement("infoProcJud");
246
247
                $this->dom->addChild(
248
                    $infoProcJud,
249
                    "tpProc",
250
                    $procjud->tpproc,
251
                    true
252
                );
253
254
                $this->dom->addChild(
255
                    $infoProcJud,
256
                    "nrProc",
257
                    $procjud->nrproc,
258
                    true
259
                );
260
261
                $this->dom->addChild(
262
                    $infoProcJud,
263
                    "codSusp",
264
                    $procjud->codsusp,
265
                    true
266
                );
267
268
                $this->dom->addChild(
269
                    $infoProcJud,
270
                    "vrCPSusp",
271
                    !empty($procjud->vrcpsusp) ? $procjud->vrcpsusp : null,
272
                    false
273
                );
274
275
                $this->dom->addChild(
276
                    $infoProcJud,
277
                    "vrRatSusp",
278
                    !empty($procjud->vrratsusp) ? $procjud->vrratsusp : null,
279
                    false
280
                );
281
282
                $this->dom->addChild(
283
                    $infoProcJud,
284
                    "vrSenarSusp",
285
                    !empty($procjud->vrsenarsusp) ? $procjud->vrsenarsusp : null,
286
                    false
287
                );
288
289
                $tpComerc->appendChild($infoProcJud);
290
            }
291
        }
292
293
294
        $ideEstabel->appendChild($tpComerc);
295
296
        $infoComProd->appendChild($ideEstabel);
297
298
        $this->node->appendChild($infoComProd);
299
300
301
        $this->eSocial->appendChild($this->node);
302
        $this->sign();
303
    }
304
}
305