|
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\Xml\Contract\XmlDocumentInterface; |
|
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 XmlDocumentInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected readonly XmlDocumentInterface $xmlDocument; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Constructor del sobre de documentos tributarios para su envío. |
|
47
|
|
|
* |
|
48
|
|
|
* @param XmlDocumentInterface $xmlDocument |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(XmlDocumentInterface $xmlDocument) |
|
52
|
|
|
{ |
|
53
|
|
|
$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
|
|
|
public function getXmlDocument(): XmlDocumentInterface |
|
68
|
|
|
{ |
|
69
|
|
|
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
|
|
|
public function getRutEmisor(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutEmisor'); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritDoc} |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getRunMandatario(): string |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutEnvia'); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritDoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getRutReceptor(): string |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->xmlDocument->query('//SetDTE/Caratula/RutReceptor'); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritDoc} |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getAutorizacionDte(): AutorizacionDteInterface |
|
116
|
|
|
{ |
|
117
|
|
|
$fechaResolucion = $this->xmlDocument->query('//SetDTE/Caratula/FchResol'); |
|
118
|
|
|
$numeroResolucion = (int) $this->xmlDocument->query('//SetDTE/Caratula/NroResol'); |
|
119
|
|
|
|
|
120
|
|
|
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
|
|
|
public function getXmlDocumentos(): array |
|
145
|
|
|
{ |
|
146
|
|
|
$documentos = []; |
|
147
|
|
|
|
|
148
|
|
|
$documentsNodes = $this->getXmlDocument()->getElementsByTagName('DTE'); |
|
149
|
|
|
|
|
150
|
|
|
foreach ($documentsNodes as $documentNode) { |
|
151
|
|
|
$documentos[] = $documentNode->C14N(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
return $documentos; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|