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