Completed
Pull Request — master (#76)
by Roberto
03:29
created

EvtAqProd::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtAqProd Event R-2055 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 EvtAqProd 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 = 'evt2055AquisicaoProdRural';
41
        $params->evtTag = 'evtAqProd';
42
        $params->evtAlias = 'R-2055';
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
            "indRetif",
58
            $this->std->indretif,
59
            true
60
        );
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "nrRecibo",
64
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "perApur",
70
            $this->std->perapur,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "tpAmb",
76
            $this->tpAmb,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "procEmi",
82
            $this->procEmi,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "verProc",
88
            $this->verProc,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "retifS1250",
94
            !empty($this->std->retifs1250) ? $this->std->retifs1250 : null,
95
            false
96
        );
97
        $this->node->insertBefore($ideEvento, $ideContri);
98
        
99
        $info = $this->dom->createElement("infoAquisProd");
100
        $ideEstab = $this->dom->createElement("ideEstabAdquir");
101
        $this->dom->addChild(
102
            $ideEstab,
103
            "tpInscAdq",
104
            $this->std->tpinscadq,
105
            true
106
        );
107
        $this->dom->addChild(
108
            $ideEstab,
109
            "nrInscAdq",
110
            $this->std->nrinscadq,
111
            true
112
        );
113
        
114
        $ideprod = $this->dom->createElement("ideProdutor");
115
        $this->dom->addChild(
116
            $ideprod,
117
            "tpInscProd",
118
            $this->std->tpinscprod,
119
            true
120
        );
121
        $this->dom->addChild(
122
            $ideprod,
123
            "nrInscProd",
124
            $this->std->nrinscprod,
125
            true
126
        );
127
        $this->dom->addChild(
128
            $ideprod,
129
            "indOpcCP",
130
            !empty($this->std->indopccp) ? $this->std->indopccp : null,
131
            false
132
        );
133
        foreach($this->std->detaquis as $det) {
134
            $detaq = $this->dom->createElement("detAquis");
135
            $this->dom->addChild(
136
                $detaq,
137
                "indAquis",
138
                $det->indaquis,
139
                true
140
            );
141
            $this->dom->addChild(
142
                $detaq,
143
                "vlrBruto",
144
                number_format($det->vlrbruto, 2, ',', ''),
145
                true
146
            );
147
            $this->dom->addChild(
148
                $detaq,
149
                "vlrCPDescPR",
150
                number_format($det->vlrcpdescpr, 2, ',', ''),
151
                true
152
            );
153
            $this->dom->addChild(
154
                $detaq,
155
                "vlrRatDescPR",
156
                number_format($det->vlrratdescpr, 2, ',', ''),
157
                true
158
            );
159
            $this->dom->addChild(
160
                $detaq,
161
                "vlrSenarDesc",
162
                number_format($det->vlrsenardesc, 2, ',', ''),
163
                true
164
            );
165
            foreach($det->infoprocjud as $jud) {
166
                $procjud = $this->dom->createElement("infoProcJud");
167
                $this->dom->addChild(
168
                    $procjud,
169
                    "nrProcJud",
170
                    $jud->nrprocjud,
171
                    true
172
                );
173
                $this->dom->addChild(
174
                    $procjud,
175
                    "codSusp",
176
                    !empty($jud->codsusp) ? $jud->codsusp : null,
177
                    false
178
                );
179
                $this->dom->addChild(
180
                    $procjud,
181
                    "vlrCPNRet",
182
                    !empty($jud->vlrcpnret) ? number_format($jud->vlrcpnret, 2, ',', '') : null,
183
                    false
184
                );
185
                $this->dom->addChild(
186
                    $procjud,
187
                    "vlrRatNRet",
188
                    !empty($jud->vlrratnret) ? number_format($jud->vlrratnret, 2, ',', '') : null,
189
                    false
190
                );
191
                $this->dom->addChild(
192
                    $procjud,
193
                    "vlrSenarNRet",
194
                    !empty($jud->vlrsenarnret) ? number_format($jud->vlrsenarnret, 2, ',', '') : null,
195
                    false
196
                );
197
                $detaq->appendChild($procjud);
198
            }
199
            $ideprod->appendChild($detaq);
200
        }
201
        $ideEstab->appendChild($ideprod);
202
        $info->appendChild($ideEstab);
203
        $this->node->appendChild($info);
204
        $this->reinf->appendChild($this->node);
205
        //$this->xml = $this->dom->saveXML($this->reinf);
206
        $this->sign($this->evtTag);
207
    }
208
}
209