Skip to content

Commit

Permalink
Merge pull request #157 from DannyvdSluijs/Add-missing-balance-types
Browse files Browse the repository at this point in the history
feat: Add FWAV, INFO, ITAV, ITBD and XPCD balance types
  • Loading branch information
PowerKiKi authored Aug 6, 2024
2 parents 08ff6d7 + e634866 commit 127adca
Show file tree
Hide file tree
Showing 8 changed files with 643 additions and 23 deletions.
35 changes: 35 additions & 0 deletions src/DTO/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class Balance

public const TYPE_CLOSING_AVAILABLE = 'closing_available';

public const TYPE_FORWARD_AVAILABLE = 'forward_available';

public const TYPE_INFORMATION = 'information';

public const TYPE_INTERIM = 'interim';

public const TYPE_INTERIM_AVAILABLE = 'interim_available';

public const TYPE_EXPECTED_CREDIT = 'expected_credit';

private Money $amount;

private string $type;
Expand Down Expand Up @@ -64,4 +74,29 @@ public static function closingAvailable(Money $amount, DateTimeImmutable $date):
{
return new self(self::TYPE_CLOSING_AVAILABLE, $amount, $date);
}

public static function forwardAvailable(Money $amount, DateTimeImmutable $date): self
{
return new self(self::TYPE_FORWARD_AVAILABLE, $amount, $date);
}

public static function information(Money $amount, DateTimeImmutable $date): self
{
return new self(self::TYPE_INFORMATION, $amount, $date);
}

public static function interim(Money $amount, DateTimeImmutable $date): self
{
return new self(self::TYPE_INTERIM, $amount, $date);
}

public static function interimAvailable(Money $amount, DateTimeImmutable $date): self
{
return new self(self::TYPE_INTERIM_AVAILABLE, $amount, $date);
}

public static function expectedCredit(Money $amount, DateTimeImmutable $date): self
{
return new self(self::TYPE_EXPECTED_CREDIT, $amount, $date);
}
}
36 changes: 36 additions & 0 deletions src/Decoder/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ public function addBalances(RecordWithBalances $record, SimpleXMLElement $xmlRec
$date
));

break;
case 'FWAV':
$record->addBalance(DTO\Balance::forwardAvailable(
$money,
$date
));

break;
case 'INFO':
$record->addBalance(DTO\Balance::information(
$money,
$date
));

break;
case 'ITAV':
$record->addBalance(DTO\Balance::interimAvailable(
$money,
$date
));

break;
case 'ITBD':
$record->addBalance(DTO\Balance::interim(
$money,
$date
));

break;

case 'XPCD':
$record->addBalance(DTO\Balance::expectedCredit(
$money,
$date
));

break;
default:
break;
Expand Down
27 changes: 7 additions & 20 deletions test/Unit/RegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ protected function tearDown(): void
/**
* @dataProvider providerRegression
*/
public function testRegression(string $file): void
public function testRegression(string $file, string $expectedFile): void
{
$reader = new Reader(Config::getDefault());
$message = $reader->readFile($file);

$dumper = new Dumper();
$actual = $dumper->dump($message);
$expectedFile = str_replace('.xml', '.json', $file);

$this->assertFile($expectedFile, $actual);
}
Expand All @@ -58,23 +57,11 @@ private function assertFile(string $file, string $actualContent): void

public static function providerRegression(): iterable
{
yield ['test/data/camt052.v1.xml'];
yield ['test/data/camt052.v2.other-account.xml'];
yield ['test/data/camt052.v2.xml'];
yield ['test/data/camt052.v4.xml'];
yield ['test/data/camt052.v6.xml'];
yield ['test/data/camt052.v8.xml'];
yield ['test/data/camt053.v2.five.decimals.xml'];
yield ['test/data/camt053.v2.minimal.ultimate.xml'];
yield ['test/data/camt053.v2.minimal.xml'];
yield ['test/data/camt053.v2.multi.statement.xml'];
yield ['test/data/camt053.v3.xml'];
yield ['test/data/camt053.v4.xml'];
yield ['test/data/camt053.v8.xml'];
yield ['test/data/camt054.v2.xml'];
yield ['test/data/camt054.v4.xml'];
yield ['test/data/camt054.v8-with-UETR.xml'];
yield ['test/data/camt054.v8-with-financial-institution.xml'];
yield ['test/data/camt054.v8.xml'];
foreach ((glob('test/data/*.xml') ?: []) as $file) {
$expectedFile = str_replace('.xml', '.json', $file);
if (is_file($expectedFile)) {
yield $file => [$file, $expectedFile];
}
}
}
}
19 changes: 18 additions & 1 deletion test/data/camt052.v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@
"getIdentification": "CH2801234000123456789"
},
"getAdditionalInformation": "Additional Information",
"getBalances": [],
"getBalances": [
{
"__CLASS__": "Genkgo\\Camt\\DTO\\Balance",
"getAmount": {
"__CLASS__": "Money\\Money",
"getAmount": "1002215",
"getCurrency": {
"__CLASS__": "Money\\Currency",
"getCode": "CHF"
}
},
"getDate": {
"__CLASS__": "DateTimeImmutable",
"0": "2016-06-14T00:00:00+00:00"
},
"getType": "interim"
}
],
"getCopyDuplicateIndicator": "CODU",
"getCreatedOn": {
"__CLASS__": "DateTimeImmutable",
Expand Down
19 changes: 18 additions & 1 deletion test/data/camt052.v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@
"getIdentification": "CH2801234000123456789"
},
"getAdditionalInformation": "Additional Information",
"getBalances": [],
"getBalances": [
{
"__CLASS__": "Genkgo\\Camt\\DTO\\Balance",
"getAmount": {
"__CLASS__": "Money\\Money",
"getAmount": "1002215",
"getCurrency": {
"__CLASS__": "Money\\Currency",
"getCode": "CHF"
}
},
"getDate": {
"__CLASS__": "DateTimeImmutable",
"0": "2020-04-04T00:00:00+00:00"
},
"getType": "interim"
}
],
"getCopyDuplicateIndicator": "CODU",
"getCreatedOn": {
"__CLASS__": "DateTimeImmutable",
Expand Down
2 changes: 1 addition & 1 deletion test/data/camt052.v6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Amt Ccy="CHF">10022.15</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<DtTm>2020-04-04T13:45:34.414+02:00</DtTm>
<Dt>2020-04-04</Dt>
</Dt>
</Bal>
<Ntry>
Expand Down
Loading

0 comments on commit 127adca

Please sign in to comment.