1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatEET; |
4
|
|
|
|
5
|
|
|
use SlevomatEET\Cryptography\CryptographyService; |
6
|
|
|
|
7
|
|
|
class EvidenceRequest |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** @var \DateTimeImmutable */ |
11
|
|
|
private $sendDate; |
12
|
|
|
|
13
|
|
|
/** @var mixed[] */ |
14
|
|
|
private $header; |
15
|
|
|
|
16
|
|
|
/** @var mixed[] */ |
17
|
|
|
private $body; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
private $pkpCode; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $bkpCode; |
24
|
|
|
|
25
|
4 |
|
public function __construct(Receipt $receipt, Configuration $configuration, CryptographyService $cryptographyService) |
26
|
|
|
{ |
27
|
4 |
|
$this->sendDate = new \DateTimeImmutable(); |
28
|
4 |
|
$this->header = [ |
|
|
|
|
29
|
4 |
|
'uuid_zpravy' => $receipt->getUuid()->toString(), |
30
|
4 |
|
'dat_odesl' => Formatter::formatDateTime($this->sendDate), |
31
|
4 |
|
'prvni_zaslani' => $receipt->isFirstSend(), |
32
|
4 |
|
'overeni' => $configuration->isVerificationMode(), |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$body = [ |
36
|
4 |
|
'dic_popl' => $configuration->getVatId(), |
37
|
4 |
|
'dic_poverujiciho' => $receipt->getDelegatedVatId(), |
38
|
4 |
|
'id_provoz' => $configuration->getPremiseId(), |
39
|
4 |
|
'id_pokl' => $configuration->getCashRegisterId(), |
40
|
4 |
|
'porad_cis' => $receipt->getReceiptNumber(), |
41
|
4 |
|
'dat_trzby' => Formatter::formatDateTime($receipt->getReceiptTime()), |
42
|
4 |
|
'celk_trzba' => Formatter::formatAmount($receipt->getTotalPrice()), |
43
|
4 |
|
'zakl_nepodl_dph' => Formatter::formatAmount($receipt->getPriceZeroVat()), |
44
|
4 |
|
'zakl_dan1' => Formatter::formatAmount($receipt->getPriceStandardVat()), |
45
|
4 |
|
'dan1' => Formatter::formatAmount($receipt->getVatStandard()), |
46
|
4 |
|
'zakl_dan2' => Formatter::formatAmount($receipt->getPriceFirstReducedVat()), |
47
|
4 |
|
'dan2' => Formatter::formatAmount($receipt->getVatFirstReduced()), |
48
|
4 |
|
'zakl_dan3' => Formatter::formatAmount($receipt->getPriceSecondReducedVat()), |
49
|
4 |
|
'dan3' => Formatter::formatAmount($receipt->getVatSecondReduced()), |
50
|
4 |
|
'cest_sluz' => Formatter::formatAmount($receipt->getPriceTravelService()), |
51
|
4 |
|
'pouzit_zboz1' => Formatter::formatAmount($receipt->getPriceUsedGoodsStandardVat()), |
52
|
4 |
|
'pouzit_zboz2' => Formatter::formatAmount($receipt->getPriceUsedGoodsFirstReduced()), |
53
|
4 |
|
'pouzit_zboz3' => Formatter::formatAmount($receipt->getPriceUsedGoodsSecondReduced()), |
54
|
4 |
|
'urceno_cerp_zuct' => Formatter::formatAmount($receipt->getPriceForSubsequentSettlement()), |
55
|
4 |
|
'cerp_zuct' => Formatter::formatAmount($receipt->getPriceUsedSubsequentSettlement()), |
56
|
4 |
|
'rezim' => $configuration->getEvidenceMode()->getValue(), |
57
|
|
|
]; |
58
|
4 |
|
$this->body = array_filter($body, function ($value): bool { |
59
|
4 |
|
return $value !== null; |
60
|
4 |
|
}); |
61
|
|
|
|
62
|
4 |
|
$this->pkpCode = $cryptographyService->getPkpCode($this->body); |
63
|
4 |
|
$this->bkpCode = $cryptographyService->getBkpCode($this->pkpCode); |
64
|
4 |
|
} |
65
|
|
|
|
66
|
4 |
|
public function getRequestData(): array |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
4 |
|
'Hlavicka' => $this->header, |
70
|
4 |
|
'Data' => $this->body, |
71
|
|
|
'KontrolniKody' => [ |
72
|
|
|
'pkp' => [ |
73
|
4 |
|
'_' => $this->pkpCode, |
74
|
4 |
|
'digest' => 'SHA256', |
75
|
4 |
|
'cipher' => 'RSA2048', |
76
|
4 |
|
'encoding' => 'base64', |
77
|
|
|
], |
78
|
|
|
'bkp' => [ |
79
|
4 |
|
'_' => $this->bkpCode, |
80
|
4 |
|
'digest' => 'SHA1', |
81
|
4 |
|
'encoding' => 'base16', |
82
|
|
|
], |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function getSendDate(): \DateTimeImmutable |
88
|
|
|
{ |
89
|
1 |
|
return $this->sendDate; |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function getHeader(): array |
93
|
|
|
{ |
94
|
1 |
|
return $this->header; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
public function getBody(): array |
98
|
|
|
{ |
99
|
1 |
|
return $this->body; |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
public function getPkpCode(): string |
103
|
|
|
{ |
104
|
1 |
|
return $this->pkpCode; |
105
|
|
|
} |
106
|
|
|
|
107
|
2 |
|
public function getBkpCode(): string |
108
|
|
|
{ |
109
|
2 |
|
return $this->bkpCode; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..