1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* LibreDTE: Biblioteca PHP (Núcleo). |
7
|
|
|
* Copyright (C) LibreDTE <https://www.libredte.cl> |
8
|
|
|
* |
9
|
|
|
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo |
10
|
|
|
* bajo los términos de la Licencia Pública General Affero de GNU publicada por |
11
|
|
|
* la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o |
12
|
|
|
* (a su elección) cualquier versión posterior de la misma. |
13
|
|
|
* |
14
|
|
|
* Este programa se distribuye con la esperanza de que sea útil, pero SIN |
15
|
|
|
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD |
16
|
|
|
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública |
17
|
|
|
* General Affero de GNU para obtener una información más detallada. |
18
|
|
|
* |
19
|
|
|
* Debería haber recibido una copia de la Licencia Pública General Affero de |
20
|
|
|
* GNU junto a este programa. |
21
|
|
|
* |
22
|
|
|
* En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace libredte\lib\Core\Package\Billing\Component\Document\Entity; |
26
|
|
|
|
27
|
|
|
use Derafu\Lib\Core\Package\Prime\Component\Xml\Contract\XmlInterface; |
28
|
|
|
use libredte\lib\Core\Package\Billing\Component\Document\Contract\SobreEnvioInterface; |
29
|
|
|
use libredte\lib\Core\Package\Billing\Component\TradingParties\Contract\AutorizacionDteInterface; |
30
|
|
|
use libredte\lib\Core\Package\Billing\Component\TradingParties\Entity\AutorizacionDte; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Entidad que representa un sobre de envío de documentos al SII o intercambio |
34
|
|
|
* entre contribuyentes. |
35
|
|
|
*/ |
36
|
|
|
class SobreEnvio implements SobreEnvioInterface |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Instancia del documento XML asociado a los datos. |
40
|
|
|
* |
41
|
|
|
* @var XmlInterface |
42
|
|
|
*/ |
43
|
|
|
protected readonly XmlInterface $xmlDocument; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor del sobre de documentos tributarios para su envío. |
47
|
|
|
* |
48
|
|
|
* @param XmlInterface $xmlDocument |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
5 |
|
public function __construct(XmlInterface $xmlDocument) |
52
|
|
|
{ |
53
|
5 |
|
$this->xmlDocument = $xmlDocument; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function __toString(): string |
60
|
|
|
{ |
61
|
|
|
return $this->getId(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
5 |
|
public function getXmlDocument(): XmlInterface |
68
|
|
|
{ |
69
|
5 |
|
return $this->xmlDocument; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function saveXml(): string |
76
|
|
|
{ |
77
|
|
|
return $this->xmlDocument->saveXml(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function getId(): string |
84
|
|
|
{ |
85
|
|
|
return 'LibreDTE_SetDoc'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
1 |
|
public function getRutEmisor(): string |
92
|
|
|
{ |
93
|
1 |
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutEmisor'); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
1 |
|
public function getRunMandatario(): string |
100
|
|
|
{ |
101
|
1 |
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutEnvia'); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
1 |
|
public function getRutReceptor(): string |
108
|
|
|
{ |
109
|
1 |
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutReceptor'); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
1 |
|
public function getAutorizacionDte(): AutorizacionDteInterface |
116
|
|
|
{ |
117
|
1 |
|
$fechaResolucion = $this->xmlDocument->query('//SetDTE/Caratula/FchResol'); |
118
|
1 |
|
$numeroResolucion = (int) $this->xmlDocument->query('//SetDTE/Caratula/NroResol'); |
119
|
|
|
|
120
|
1 |
|
return new AutorizacionDte($fechaResolucion, $numeroResolucion); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
|
|
public function getFechaFirma(): string |
127
|
|
|
{ |
128
|
|
|
return $this->xmlDocument->query('//SetDTE/Caratula/TmstFirmaEnv'); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* {@inheritdoc} |
133
|
|
|
*/ |
134
|
|
|
public function getResumen(): array |
135
|
|
|
{ |
136
|
|
|
$SubTotDTE = $this->xmlDocument->query('//SetDTE/Caratula/SubTotDTE'); |
137
|
|
|
|
138
|
|
|
return isset($SubTotDTE[0]) ? $SubTotDTE : [$SubTotDTE]; |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritdoc} |
143
|
|
|
*/ |
144
|
5 |
|
public function getXmlDocumentos(): array |
145
|
|
|
{ |
146
|
5 |
|
$documentos = []; |
147
|
|
|
|
148
|
5 |
|
$documentsNodes = $this->getXmlDocument()->getElementsByTagName('DTE'); |
149
|
|
|
|
150
|
5 |
|
foreach ($documentsNodes as $documentNode) { |
151
|
5 |
|
$documentos[] = $documentNode->C14N(); |
152
|
|
|
} |
153
|
|
|
|
154
|
5 |
|
return $documentos; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|