1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\CfdiToPdf; |
6
|
|
|
|
7
|
|
|
use CfdiUtils\Nodes\NodeInterface; |
8
|
|
|
use RuntimeException; |
9
|
|
|
|
10
|
|
|
class CfdiData |
11
|
|
|
{ |
12
|
|
|
/** @var NodeInterface<NodeInterface> */ |
13
|
|
|
private $comprobante; |
14
|
|
|
|
15
|
|
|
/** @var NodeInterface<NodeInterface> */ |
16
|
|
|
private $emisor; |
17
|
|
|
|
18
|
|
|
/** @var NodeInterface<NodeInterface> */ |
19
|
|
|
private $receptor; |
20
|
|
|
|
21
|
|
|
/** @var NodeInterface<NodeInterface> */ |
22
|
|
|
private $timbreFiscalDigital; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $qrUrl; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
private $tfdSourceString; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* CfdiData constructor. |
32
|
|
|
* |
33
|
|
|
* @param NodeInterface<NodeInterface> $comprobante |
34
|
|
|
* @param string $qrUrl |
35
|
|
|
* @param string $tfdSourceString |
36
|
|
|
*/ |
37
|
5 |
|
public function __construct(NodeInterface $comprobante, string $qrUrl, string $tfdSourceString) |
38
|
|
|
{ |
39
|
5 |
|
$emisor = $comprobante->searchNode('cfdi:Emisor'); |
40
|
5 |
|
if (null === $emisor) { |
41
|
1 |
|
throw new RuntimeException('El CFDI no contiene nodo emisor'); |
42
|
|
|
} |
43
|
4 |
|
$receptor = $comprobante->searchNode('cfdi:Receptor'); |
44
|
4 |
|
if (null === $receptor) { |
45
|
1 |
|
throw new RuntimeException('El CFDI no contiene nodo receptor'); |
46
|
|
|
} |
47
|
3 |
|
$timbreFiscalDigital = $comprobante->searchNode('cfdi:Complemento', 'tfd:TimbreFiscalDigital'); |
48
|
3 |
|
if (null === $timbreFiscalDigital) { |
49
|
1 |
|
throw new RuntimeException('El CFDI no contiene complemento de timbre fiscal digital'); |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
$this->comprobante = $comprobante; |
53
|
2 |
|
$this->emisor = $emisor; |
54
|
2 |
|
$this->receptor = $receptor; |
55
|
2 |
|
$this->timbreFiscalDigital = $timbreFiscalDigital; |
56
|
2 |
|
$this->qrUrl = $qrUrl; |
57
|
2 |
|
$this->tfdSourceString = $tfdSourceString; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return NodeInterface<NodeInterface> |
62
|
|
|
*/ |
63
|
2 |
|
public function comprobante(): NodeInterface |
64
|
|
|
{ |
65
|
2 |
|
return $this->comprobante; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return NodeInterface<NodeInterface> |
70
|
|
|
*/ |
71
|
2 |
|
public function emisor(): NodeInterface |
72
|
|
|
{ |
73
|
2 |
|
return $this->emisor; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return NodeInterface<NodeInterface> |
78
|
|
|
*/ |
79
|
2 |
|
public function receptor(): NodeInterface |
80
|
|
|
{ |
81
|
2 |
|
return $this->receptor; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return NodeInterface<NodeInterface> |
86
|
|
|
*/ |
87
|
2 |
|
public function timbreFiscalDigital(): NodeInterface |
88
|
|
|
{ |
89
|
2 |
|
return $this->timbreFiscalDigital; |
90
|
|
|
} |
91
|
|
|
|
92
|
2 |
|
public function qrUrl(): string |
93
|
|
|
{ |
94
|
2 |
|
return $this->qrUrl; |
95
|
|
|
} |
96
|
|
|
|
97
|
2 |
|
public function tfdSourceString(): string |
98
|
|
|
{ |
99
|
2 |
|
return $this->tfdSourceString; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|