You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
<?php
|
|
|
|
namespace App\Services\Camt\Conversion;
|
|
|
|
use App\Services\Camt\Transaction;
|
|
use App\Services\Shared\Configuration\Configuration;
|
|
use Genkgo\Camt\Camt053\DTO\Statement as CamtStatement;
|
|
use Genkgo\Camt\DTO\Message;
|
|
|
|
class TransactionExtractor
|
|
{
|
|
private Configuration $configuration;
|
|
|
|
/**
|
|
* @param Configuration $configuration
|
|
*/
|
|
public function __construct(Configuration $configuration)
|
|
{
|
|
$this->configuration = $configuration;
|
|
}
|
|
|
|
public function extractTransactions(Message $message): array
|
|
{
|
|
// get transactions from XML file
|
|
$transactions = [];
|
|
$statements = $message->getRecords();
|
|
/** @var CamtStatement $statement */
|
|
foreach ($statements as $statement) { // -> Level B
|
|
$entries = $statement->getEntries();
|
|
foreach ($entries as $entry) { // -> Level C
|
|
$count = count($entry->getTransactionDetails()); // count level D entries.
|
|
if (0 === $count) {
|
|
// TODO Create a single transaction, I guess?
|
|
$transactions[] = new Transaction($this->configuration, $message, $statement, $entry, []);
|
|
}
|
|
if (0 !== $count) {
|
|
$handling = $this->configuration->getGroupedTransactionHandling();
|
|
if ('split' === $handling) {
|
|
$transactions[] = new Transaction($this->configuration, $message, $statement, $entry, $entry->getTransactionDetails());
|
|
}
|
|
if ('single' === $handling) {
|
|
foreach ($entry->getTransactionDetails() as $detail) {
|
|
$transactions[] = new Transaction($this->configuration, $message, $statement, $entry, [$detail]);
|
|
}
|
|
}
|
|
if ('group' === $handling) {
|
|
$transactions[] = new Transaction($this->configuration, $message, $statement, $entry, []);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $transactions;
|
|
}
|
|
|
|
}
|