|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Genkgo\Camt\Camt052\Decoder; |
|
6
|
|
|
|
|
7
|
|
|
use Genkgo\Camt\Camt052\DTO as Camt052DTO; |
|
8
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
|
9
|
|
|
use Genkgo\Camt\DTO; |
|
10
|
|
|
use Genkgo\Camt\DTO\Account; |
|
11
|
|
|
use Genkgo\Camt\Exception\InvalidMessageException; |
|
12
|
|
|
use Genkgo\Camt\Iban; |
|
13
|
|
|
use SimpleXMLElement; |
|
14
|
|
|
|
|
15
|
|
|
abstract class Message extends BaseMessageDecoder |
|
16
|
8 |
|
{ |
|
17
|
|
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document): void |
|
18
|
8 |
|
{ |
|
19
|
|
|
$reports = []; |
|
20
|
8 |
|
|
|
21
|
8 |
|
$xmlReports = $this->getRootElement($document)->Rpt; |
|
22
|
8 |
|
foreach ($xmlReports as $xmlReport) { |
|
23
|
8 |
|
$report = new Camt052DTO\Report( |
|
24
|
8 |
|
(string) $xmlReport->Id, |
|
25
|
8 |
|
$this->dateDecoder->decode((string) $xmlReport->CreDtTm), |
|
26
|
|
|
$this->getAccount($xmlReport) |
|
|
|
|
|
|
27
|
|
|
); |
|
28
|
8 |
|
|
|
29
|
3 |
|
if (isset($xmlReport->RptPgntn)) { |
|
30
|
3 |
|
$report->setPagination(new DTO\Pagination( |
|
31
|
3 |
|
(string) $xmlReport->RptPgntn->PgNb, |
|
32
|
|
|
('true' === (string) $xmlReport->RptPgntn->LastPgInd) ? true : false |
|
33
|
|
|
)); |
|
34
|
|
|
} |
|
35
|
8 |
|
|
|
36
|
7 |
|
if (isset($xmlReport->AddtlRptInf)) { |
|
37
|
|
|
$report->setAdditionalInformation((string) $xmlReport->AddtlRptInf); |
|
38
|
|
|
} |
|
39
|
8 |
|
|
|
40
|
8 |
|
$this->addCommonRecordInformation($report, $xmlReport); |
|
41
|
8 |
|
$this->recordDecoder->addBalances($report, $xmlReport); |
|
42
|
|
|
$this->recordDecoder->addEntries($report, $xmlReport); |
|
43
|
8 |
|
|
|
44
|
|
|
$reports[] = $report; |
|
45
|
|
|
} |
|
46
|
8 |
|
|
|
47
|
8 |
|
$message->setRecords($reports); |
|
48
|
|
|
} |
|
49
|
8 |
|
|
|
50
|
|
|
protected function getAccount(SimpleXMLElement $xmlRecord): Account |
|
51
|
8 |
|
{ |
|
52
|
3 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
|
53
|
|
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
|
54
|
|
|
} |
|
55
|
8 |
|
|
|
56
|
|
|
if (isset($xmlRecord->Acct->Id->BBAN)) { |
|
57
|
|
|
return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN); |
|
58
|
|
|
} |
|
59
|
8 |
|
|
|
60
|
|
|
if (isset($xmlRecord->Acct->Id->UPIC)) { |
|
61
|
|
|
return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC); |
|
62
|
|
|
} |
|
63
|
8 |
|
|
|
64
|
4 |
|
if (isset($xmlRecord->Acct->Id->PrtryAcct)) { |
|
65
|
|
|
return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id); |
|
66
|
|
|
} |
|
67
|
7 |
|
|
|
68
|
7 |
|
if (isset($xmlRecord->Acct->Id->Othr)) { |
|
69
|
7 |
|
$xmlOtherIdentification = $xmlRecord->Acct->Id->Othr; |
|
70
|
|
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
|
71
|
7 |
|
|
|
72
|
|
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
|
73
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
|
74
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Prtry)) { |
|
78
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
7 |
|
|
|
82
|
|
|
if (isset($xmlOtherIdentification->Issr)) { |
|
83
|
|
|
$otherAccount->setIssuer((string) $xmlOtherIdentification->Issr); |
|
84
|
|
|
} |
|
85
|
7 |
|
|
|
86
|
|
|
return $otherAccount; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
throw new InvalidMessageException('Cannot decode account'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|