Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add FWAV, INFO, ITAV, ITBD and XPCD balance types #157

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading