Passed
Push — master ( c6af21...89b92c )
by Roberto
52s
created

EvtContratAvNP   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 189
ccs 0
cts 133
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B toNode() 0 146 4
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtContratAvNP Event S-1270 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 EvtContratAvNP extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtContratAvNP';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1270';
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
        $evtContratAvNP = $this->dom->createElement("evtContratAvNP");
76
77
        $att            = $this->dom->createAttribute('Id');
78
79
        $att->value     = $evtid;
80
81
        $evtContratAvNP->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
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
96
            false
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
129
        $this->node->insertBefore($ideEvento, $ideEmpregador);
130
131
        if (isset($this->std->remunavnp)) {
132
            foreach ($this->std->remunavnp as $remun) {
133
                $remunAvNP = $this->dom->createElement("remunAvNP");
134
135
                $this->dom->addChild(
136
                    $remunAvNP,
137
                    "tpInsc",
138
                    $remun->tpinsc,
139
                    true
140
                );
141
142
                $this->dom->addChild(
143
                    $remunAvNP,
144
                    "nrInsc",
145
                    $remun->nrinsc,
146
                    true
147
                );
148
149
                $this->dom->addChild(
150
                    $remunAvNP,
151
                    "codLotacao",
152
                    $remun->codlotacao,
153
                    true
154
                );
155
156
                $this->dom->addChild(
157
                    $remunAvNP,
158
                    "vrBcCp00",
159
                    $remun->vrbccp00,
160
                    true
161
                );
162
163
                $this->dom->addChild(
164
                    $remunAvNP,
165
                    "vrBcCp15",
166
                    $remun->vrbccp15,
167
                    true
168
                );
169
170
                $this->dom->addChild(
171
                    $remunAvNP,
172
                    "vrBcCp20",
173
                    $remun->vrbccp20,
174
                    true
175
                );
176
177
                $this->dom->addChild(
178
                    $remunAvNP,
179
                    "vrBcCp25",
180
                    $remun->vrbccp25,
181
                    true
182
                );
183
184
                $this->dom->addChild(
185
                    $remunAvNP,
186
                    "vrBcCp13",
187
                    $remun->vrbccp13,
188
                    true
189
                );
190
191
                $this->dom->addChild(
192
                    $remunAvNP,
193
                    "vrBcFgts",
194
                    $remun->vrbcfgts,
195
                    true
196
                );
197
198
                $this->dom->addChild(
199
                    $remunAvNP,
200
                    "vrDescCP",
201
                    $remun->vrdesccp,
202
                    true
203
                );
204
205
                $this->node->appendChild($remunAvNP);
206
            }
207
        }
208
209
        $this->eSocial->appendChild($this->node);
210
        $this->sign();
211
    }
212
}
213