1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Genkgo\Camt\Camt053\Decoder; |
6
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt053\DTO as Camt053DTO; |
8
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
9
|
|
|
use Genkgo\Camt\DTO; |
10
|
|
|
use Genkgo\Camt\Iban; |
11
|
|
|
use SimpleXMLElement; |
12
|
|
|
|
13
|
|
|
class Message extends BaseMessageDecoder |
14
|
|
|
{ |
15
|
12 |
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document): void |
16
|
|
|
{ |
17
|
12 |
|
$statements = []; |
18
|
|
|
|
19
|
12 |
|
$xmlStatements = $this->getRootElement($document)->Stmt; |
20
|
12 |
|
foreach ($xmlStatements as $xmlStatement) { |
21
|
12 |
|
$statement = new Camt053DTO\Statement( |
22
|
12 |
|
(string) $xmlStatement->Id, |
23
|
12 |
|
$this->dateDecoder->decode((string) $xmlStatement->CreDtTm), |
24
|
12 |
|
$this->getAccount($xmlStatement) |
|
|
|
|
25
|
|
|
); |
26
|
|
|
|
27
|
12 |
|
if (isset($xmlStatement->StmtPgntn)) { |
28
|
6 |
|
$statement->setPagination(new DTO\Pagination( |
29
|
6 |
|
(string) $xmlStatement->StmtPgntn->PgNb, |
30
|
6 |
|
('true' === (string) $xmlStatement->StmtPgntn->LastPgInd) ? true : false |
31
|
|
|
)); |
32
|
|
|
} |
33
|
|
|
|
34
|
12 |
|
if (isset($xmlStatement->AddtlStmtInf)) { |
35
|
11 |
|
$statement->setAdditionalInformation((string) $xmlStatement->AddtlStmtInf); |
36
|
|
|
} |
37
|
|
|
|
38
|
12 |
|
$this->addCommonRecordInformation($statement, $xmlStatement); |
|
|
|
|
39
|
12 |
|
$this->recordDecoder->addBalances($statement, $xmlStatement); |
|
|
|
|
40
|
12 |
|
$this->recordDecoder->addEntries($statement, $xmlStatement); |
|
|
|
|
41
|
|
|
|
42
|
12 |
|
$statements[] = $statement; |
43
|
|
|
} |
44
|
|
|
|
45
|
12 |
|
$message->setRecords($statements); |
46
|
12 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
13 |
|
public function getRootElement(SimpleXMLElement $document): SimpleXMLElement |
52
|
|
|
{ |
53
|
13 |
|
return $document->BkToCstmrStmt; |
54
|
|
|
} |
55
|
|
|
|
56
|
12 |
|
protected function getAccount(SimpleXMLElement $xmlRecord): DTO\Account |
57
|
|
|
{ |
58
|
12 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
59
|
10 |
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
60
|
|
|
} |
61
|
|
|
|
62
|
7 |
|
$xmlOtherIdentification = $xmlRecord->Acct->Id->Othr; |
63
|
7 |
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
64
|
|
|
|
65
|
7 |
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
66
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
67
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Prtry)) { |
71
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
7 |
|
if (isset($xmlOtherIdentification->Issr)) { |
76
|
|
|
$otherAccount->setIssuer((string) $xmlOtherIdentification->Issr); |
77
|
|
|
} |
78
|
|
|
|
79
|
7 |
|
return $otherAccount; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|