From 768421428cb07d68e44973d24d2ad30f0873d54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Thu, 12 Dec 2024 15:22:54 +0100 Subject: [PATCH 1/2] require 'OFFICE365_TENANT', 'OFFICE365_PATH', 'OFFICE365_SITE' to be set --- src/pohodaSQL-raiffeisenbank-statements-sharepoint.php | 1 + src/raiffeisenbank-statements-sharepoint-checker.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php index 39bdb54..9933e74 100644 --- a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php +++ b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php @@ -30,6 +30,7 @@ $options = getopt('o::e::', ['output::environment::']); Shared::init( [ + 'OFFICE365_TENANT', 'OFFICE365_PATH', 'OFFICE365_SITE', 'POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO', 'CERT_FILE', 'CERT_PASS', 'XIBMCLIENTID', 'ACCOUNT_NUMBER', 'DB_CONNECTION', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', diff --git a/src/raiffeisenbank-statements-sharepoint-checker.php b/src/raiffeisenbank-statements-sharepoint-checker.php index 3f50baf..0adee22 100644 --- a/src/raiffeisenbank-statements-sharepoint-checker.php +++ b/src/raiffeisenbank-statements-sharepoint-checker.php @@ -30,8 +30,8 @@ $options = getopt('o::e::', ['output::environment::']); Shared::init( [ + 'OFFICE365_TENANT', 'OFFICE365_PATH', 'OFFICE365_SITE', 'CERT_FILE', 'CERT_PASS', 'XIBMCLIENTID', 'ACCOUNT_NUMBER', - 'DB_CONNECTION', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', ], \array_key_exists('environment', $options) ? $options['environment'] : '../.env', ); From 51abede64fc2e41bef97b1a3965719363697b030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Thu, 12 Dec 2024 19:48:22 +0100 Subject: [PATCH 2/2] v1.2.0 release MultiCurrency support --- debian/changelog | 11 ++++- .../2461feac-a694-4171-a37e-069fe3f56cef.svg | 6 +-- ...ffeisenbank_statements.multiflexi.app.json | 14 +++++- ...ffeisenbank_sharepoint.multiflexi.app.json | 6 +++ ...nts_sharepoint_checker.multiflexi.app.json | 6 +++ .../RaiffeisenBank/PohodaBankClient.php | 2 +- src/Pohoda/RaiffeisenBank/Statementor.php | 44 ++++++++++++++++++- ...ffeisenbank-offline-statement-importer.php | 6 +-- src/pohoda-raiffeisenbank-statements.php | 2 + ...L-raiffeisenbank-statements-sharepoint.php | 13 +++++- 10 files changed, 96 insertions(+), 14 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3e44787..838aaab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,16 @@ -pohoda-raiffeisenbank (1.1.3) UNRELEASED; urgency=medium +pohoda-raiffeisenbank (1.2.0) UNRELEASED; urgency=medium + * ACCOUNT_CURRENCY support added + + -- Thu, 12 Dec 2024 19:46:43 +0100 + +pohoda-raiffeisenbank (1.1.3) jammy; urgency=medium + + [ vitezslav.dvorak@spojenet.cz ] * bankIDS processed now * Fail with correct exitpode - -- Mon, 09 Dec 2024 11:37:42 +0100 + -- Thu, 12 Dec 2024 19:46:38 +0100 pohoda-raiffeisenbank (1.1.1) jammy; urgency=medium diff --git a/multiflexi/2461feac-a694-4171-a37e-069fe3f56cef.svg b/multiflexi/2461feac-a694-4171-a37e-069fe3f56cef.svg index 26395ae..0c97cc7 100644 --- a/multiflexi/2461feac-a694-4171-a37e-069fe3f56cef.svg +++ b/multiflexi/2461feac-a694-4171-a37e-069fe3f56cef.svg @@ -411,7 +411,7 @@ inkscape:current-layer="g2598" inkscape:document-units="mm" inkscape:cy="240.92138" - inkscape:cx="514.16764" + inkscape:cx="457.5991" inkscape:zoom="0.9899495" inkscape:pageshadow="2" inkscape:pageopacity="0.0" @@ -814,10 +814,10 @@ x="8.4725313" y="27.181726" id="text404" - transform="matrix(2.5247766,0,0,1.9633661,-71.0398,-6.1897403)">{ } + id="tspan591">{ } currency; } /** diff --git a/src/Pohoda/RaiffeisenBank/Statementor.php b/src/Pohoda/RaiffeisenBank/Statementor.php index a4f1bff..4ea4478 100644 --- a/src/Pohoda/RaiffeisenBank/Statementor.php +++ b/src/Pohoda/RaiffeisenBank/Statementor.php @@ -25,6 +25,8 @@ class Statementor extends PohodaBankClient public string $scope = ''; private \VitexSoftware\Raiffeisenbank\Statementor $obtainer; private string $statementsDir; + private string $currency = ''; + private string $statementLine = 'MAIN'; /** * Downloaded XML statements. @@ -93,7 +95,7 @@ public function getStatementFilenames(string $format): array public function getStatements() { - return $this->obtainer->getStatements(); + return $this->obtainer->getStatements($this->currency, $this->statementLine); } public function download($format) @@ -179,6 +181,17 @@ public function import(string $bankIds = ''): array return $inserted; } + public static function simpleXmlAttributes(\SimpleXMLElement $item): array + { + $attributes = []; + + foreach ($item->attributes() as $key => $value) { + $attributes[$key] = (string) $value; + } + + return $attributes; + } + /** * Parse Ntry element and convert into \Pohoda\Banka data. * @@ -198,7 +211,15 @@ public function entryToPohoda(\SimpleXMLElement $entry): array $data['bankType'] = $moveTrans[trim((string) $entry->CdtDbtInd)]; // $data['cisDosle', strval($entry->NtryRef)); // $data['datVyst', new \DateTime($entry->BookgDt->DtTm)); - $data['homeCurrency'] = ['priceNone' => abs((float) $entry->Amt)]; // "price3", "price3Sum", "price3VAT", "priceHigh", "priceHighSum", "priceHighVAT", "priceLow", "priceLowSum", "priceLowVAT", "priceNone", "round" + + $amountAttributes = self::simpleXmlAttributes($entry->Amt); + + if (\array_key_exists('Ccy', $amountAttributes) && $amountAttributes['Ccy'] !== 'CZK') { + $data['foreignCurrency'] = ['priceSum' => abs((float) $entry->Amt)]; // "price3", "price3Sum", "price3VAT", "priceHigh", "priceHighSum", "priceHighVAT", "priceLow", "priceLowSum", "priceLowVAT", "priceNone", "round" + $data['foreignCurrency']['currency'] = $amountAttributes['Ccy']; + } else { + $data['homeCurrency'] = ['priceNone' => abs((float) $entry->Amt)]; // "price3", "price3Sum", "price3VAT", "priceHigh", "priceHighSum", "priceHighVAT", "priceLow", "priceLowSum", "priceLowVAT", "priceNone", "round" + } // TODO $data['foreignCurrency', abs(floatval($entry->Amt))); // $data['account', $this->bank); @@ -426,4 +447,23 @@ public function takeXmlStatementFile(string $xmlFilePath): void { $this->statementsXML[basename($xmlFilePath)] = $xmlFilePath; } + + public function setCurrency(string $currency): void + { + $this->currency = $currency; + } + + public function setStatementLine(string $line): void + { + switch ($line) { + case 'MAIN': + case 'ADDITIONAL': + $this->statementLine = $line; + + break; + + default: + throw new \InvalidArgumentException('Wrong statement line: '.$line); + } + } } diff --git a/src/pohoda-raiffeisenbank-offline-statement-importer.php b/src/pohoda-raiffeisenbank-offline-statement-importer.php index 47dbe40..3a45c57 100644 --- a/src/pohoda-raiffeisenbank-offline-statement-importer.php +++ b/src/pohoda-raiffeisenbank-offline-statement-importer.php @@ -19,12 +19,12 @@ \define('APP_NAME', 'Pohoda RaiffeisenBank Offline Statements'); -$statementFile = 'statement.xml'; // TODO: specify by commandline - +$options = getopt('i::e::', ['input::environment::']); +$statementFile = \array_key_exists('output', $options) ? $options['output'] : \Ease\Shared::cfg('STATEMENT_FILE', 'php://stdin'); /** * Get today's Statements list. */ -\Ease\Shared::init(['POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO', 'POHODA_BANK_IDS', 'ACCOUNT_NUMBER'], $argv[1] ?? '../.env'); +\Ease\Shared::init(['POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO', 'POHODA_BANK_IDS', 'ACCOUNT_NUMBER'], \array_key_exists('environment', $options) ? $options['environment'] : '../.env'); $engine = new Statementor(\Ease\Shared::cfg('ACCOUNT_NUMBER')); $engine->logBanner('', 'Importing file: '.$statementFile); diff --git a/src/pohoda-raiffeisenbank-statements.php b/src/pohoda-raiffeisenbank-statements.php index 7183ac9..7970dbc 100644 --- a/src/pohoda-raiffeisenbank-statements.php +++ b/src/pohoda-raiffeisenbank-statements.php @@ -15,6 +15,8 @@ namespace Pohoda\RaiffeisenBank; +use Ease\Shared; + require_once '../vendor/autoload.php'; \define('APP_NAME', 'Pohoda RaiffeisenBank Statements'); diff --git a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php index 9933e74..ba6f48a 100644 --- a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php +++ b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php @@ -42,7 +42,16 @@ PohodaBankClient::checkCertificatePresence(Shared::cfg('CERT_FILE')); $engine = new Statementor(Shared::cfg('ACCOUNT_NUMBER')); $engine->setScope(Shared::cfg('IMPORT_SCOPE', 'last_month')); -$engine->logBanner('', 'Scope: '.$engine->scope); + +if (Shared::cfg('STATEMENT_LINE')) { + $engine->setStatementLine(Shared::cfg('STATEMENT_LINE')); +} + +if (Shared::cfg('ACCOUNT_CURRENCY')) { + $engine->setCurrency(Shared::cfg('ACCOUNT_CURRENCY')); +} + +$engine->logBanner(Shared::cfg('ACCOUNT_CURRENCY'), 'Scope: '.$engine->scope); $exitcode = 0; $fileUrls = []; $report = [ @@ -55,7 +64,7 @@ $pdfStatements = $engine->downloadPDF(); } catch (\VitexSoftware\Raiffeisenbank\ApiException $exc) { $report['mesage'] = $exc->getMessage(); - + $pdfStatements = []; $exitcode = $exc->getCode(); if (!$exitcode) {