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