From d3fe6befb2e6edf7578aba4007ae5a6d6cfe12a2 Mon Sep 17 00:00:00 2001 From: CyberVitexus Date: Tue, 3 Dec 2024 00:46:13 +0100 Subject: [PATCH] v1.1.1 release: code cleanup. PohodaSQL attachnent fix --- composer.json | 2 +- debian/changelog | 10 +++- debian/control | 2 +- .../RaiffeisenBank/PohodaBankClient.php | 30 +++--------- src/Pohoda/RaiffeisenBank/Statementor.php | 47 ++++++++++++------- src/Pohoda/RaiffeisenBank/Transactor.php | 6 ++- ...L-raiffeisenbank-statements-sharepoint.php | 2 +- ...isenbank-statements-sharepoint-checker.php | 28 ++++++----- 8 files changed, 67 insertions(+), 60 deletions(-) diff --git a/composer.json b/composer.json index f9ff5ff..4deaeb3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "bin": ["src/pohoda-raiffeisenbank-transactions.php", "src/pohoda-raiffeisenbank-setup.php"], "require": { "vgrem/php-spo": "^3", - "vitexsoftware/pohoda-connector": "^0.4", + "vitexsoftware/pohoda-connector": "^0.5", "vitexsoftware/rbczpremiumapi": "dev-main", "spojenet/pohoda-sql": "dev-main" }, diff --git a/debian/changelog b/debian/changelog index a74ed4a..09cb41b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,14 @@ -pohoda-raiffeisenbank (1.1.0) UNRELEASED; urgency=medium +pohoda-raiffeisenbank (1.1.1) UNRELEASED; urgency=medium + + * code cleanup. PohodaSQL attachnent fix + + -- vitex Tue, 03 Dec 2024 00:45:54 +0100 + +pohoda-raiffeisenbank (1.1.0) jammy; urgency=medium * raiffeisenbank-statements-sharepoint-checker added - -- vitex Thu, 28 Nov 2024 17:58:36 +0100 + -- vitex Tue, 03 Dec 2024 00:45:03 +0100 pohoda-raiffeisenbank (1.0.0) jammy; urgency=medium diff --git a/debian/control b/debian/control index 0af80bc..51ab028 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: https://github.com/Spoje-NET/pohoda-raiffeisenbank Package: pohoda-raiffeisenbank Architecture: all Multi-Arch: foreign -Depends: ${misc:Depends}, ${shlibs:Depends}, php-vitexsoftware-rbczpremiumapi, php-spojenet-pohoda-sql, php-vitexsoftware-pohoda-connector +Depends: ${misc:Depends}, ${shlibs:Depends}, php-vitexsoftware-rbczpremiumapi, php-spojenet-pohoda-sql, php-vitexsoftware-pohoda-connector (>= 0.5.0) Description: Import Raiffeisenbank statements into Pohoda See your Bank Account Statements in Pohoda diff --git a/src/Pohoda/RaiffeisenBank/PohodaBankClient.php b/src/Pohoda/RaiffeisenBank/PohodaBankClient.php index fa32136..58c81a9 100644 --- a/src/Pohoda/RaiffeisenBank/PohodaBankClient.php +++ b/src/Pohoda/RaiffeisenBank/PohodaBankClient.php @@ -15,6 +15,8 @@ namespace Pohoda\RaiffeisenBank; +use Ease\Shared; + /** * Description of ApiClient. * @@ -31,18 +33,9 @@ abstract class PohodaBankClient extends \mServer\Bank * DateTime Formating eg. 2021-08-01T10:00:00.0Z. */ public static string $dateFormat = 'Y-m-d'; - - /** - * @var \Riesenia\Pohoda\Banka - */ - public ?\Riesenia\Pohoda\Agenda $requestXml; - - // public Response $response; TODO: Update - protected $constantor; - protected $constSymbols; protected \DateTime $since; protected \DateTime $until; - protected $bank; + protected string $bank; /** * Transaction Handler. @@ -69,7 +62,7 @@ public function sourceString() } /** - * Try to check certificate readibilty. + * Try to check certificate readability. * * @param string $certFile path to certificate */ @@ -149,7 +142,7 @@ public function setScope($scope): void break; case 'auto': - $latestRecord = $this->getColumnsFromPohoda(['id', 'lastUpdate'], ['limit' => 1, 'order' => 'lastUpdate@A', 'source' => $this->sourceString(), 'banka' => $this->bank]); + $latestRecord = $this->getColumnsFromPohoda(['id', 'lastUpdate'], ['limit' => 1, 'order' => 'lastUpdate@A', 'source' => $this->sourceString(), 'bank' => $this->bank]); if (\array_key_exists(0, $latestRecord) && \array_key_exists('lastUpdate', $latestRecord[0])) { $this->since = $latestRecord[0]['lastUpdate']; @@ -204,7 +197,7 @@ public function getxRequestId() */ public function getCurrencyCode() { - return \Ease\Shared::cfg('ACCOUNT_CURRENCY', 'CZK'); + return Shared::cfg('ACCOUNT_CURRENCY', 'CZK'); } /** @@ -221,15 +214,6 @@ public function checkForTransactionPresence() return false; // !empty($this->getColumnsFromPohoda('id', ['cisDosle' => $this->getDataValue('cisDosle')])); TODO } - public function ensureKSExists(string $conSym): void - { - if (!\array_key_exists($conSym, $this->constSymbols)) { - $this->constantor->insertToPohoda(['kod' => $conSym, 'poznam' => 'Created by Raiffeisen Bank importer', 'nazev' => '?!?!? '.$conSym]); - $this->constantor->addStatusMessage('New constant '.$conSym.' created in flexibee', 'warning'); - $this->constSymbols[$conSym] = $conSym; - } - } - /** * Insert Transaction to Pohoda. * @@ -381,6 +365,6 @@ public function generateAutomaticLiquidationXML($producedNumber) public function getCompanyId(): string { - return \Ease\Shared::cfg('POHODA_ICO'); + return Shared::cfg('POHODA_ICO'); } } diff --git a/src/Pohoda/RaiffeisenBank/Statementor.php b/src/Pohoda/RaiffeisenBank/Statementor.php index d92d70a..bb16ce9 100644 --- a/src/Pohoda/RaiffeisenBank/Statementor.php +++ b/src/Pohoda/RaiffeisenBank/Statementor.php @@ -73,26 +73,25 @@ public function importXML(string $xmlFile) return $this->import(); } - - /** - * Get List of Statement files - * + * Get List of Statement files. + * * @param string $format xml|pdf + * * @return array */ - public function getStatementFilenames(string $format): array { + public function getStatementFilenames(string $format): array + { foreach ($this->getStatements() as $statement) { - $statementFilenames[] = str_replace('/', '_', $statement->statementNumber) . '_' . - $statement->accountNumber . '_' . - $statement->accountId . '_' . - $statement->currency . '_' . $statement->dateFrom . '.' . $format; + $statementFilenames[] = str_replace('/', '_', $statement->statementNumber).'_'. + $statement->accountNumber.'_'. + $statement->accountId.'_'. + $statement->currency.'_'.$statement->dateFrom.'.'.$format; } return $statementFilenames; } - public function getStatements() { return $this->obtainer->getStatements(); @@ -103,6 +102,11 @@ public function download($format) return $this->obtainer->download($this->statementsDir, $this->getStatements(), $format); } + /** + * Download Raiffeisen bank XML statement. + * + * @return array List of downloaded XML files + */ public function downloadXML(): array { $this->statementsXML = $this->download('xml'); @@ -110,6 +114,11 @@ public function downloadXML(): array return $this->statementsXML; } + /** + * Download Raiffeisen bank PDF statement. + * + * @return array List of downloaded PDF files + */ public function downloadPDF(): array { $this->statementsPDF = $this->download('pdf'); @@ -118,7 +127,7 @@ public function downloadPDF(): array } /** - * @return array + * @return array> List of inserted records */ public function importOnline() { @@ -158,7 +167,7 @@ public function import(): array $lastInsert = $this->insertTransactionToPohoda(); if ($lastInsert) { - $inserted = array_merge($lastInsert); + $inserted[key($lastInsert)] = current($lastInsert); ++$success; } } catch (\Exception $exc) { @@ -178,9 +187,9 @@ public function import(): array * @see https://cbaonline.cz/upload/1425-standard-xml-cba-listopad-2020.pdf * @see https://www.stormware.cz/xml/schema/version_2/bank.xsd * - * @param \SimpleXMLElement $entry + * @return array|string> */ - public function entryToPohoda($entry): array + public function entryToPohoda(\SimpleXMLElement $entry): array { $data['symPar'] = current((array) $entry->NtryRef); $data['intNote'] = 'Imported by '.\Ease\Shared::AppName().' '.\Ease\Shared::AppVersion().' Import Job '.\Ease\Shared::cfg('MULTIFLEXI_JOB_ID', \Ease\Shared::cfg('JOB_ID', 'n/a')); @@ -404,12 +413,14 @@ public function getXmlStatements() { return $this->statementsXML; } - - public function getSince(): \DateTime { + + public function getSince(): \DateTime + { return $this->since; } - - public function getUntil(): \DateTime { + + public function getUntil(): \DateTime + { return $this->until; } } diff --git a/src/Pohoda/RaiffeisenBank/Transactor.php b/src/Pohoda/RaiffeisenBank/Transactor.php index be1c687..78f6b2f 100644 --- a/src/Pohoda/RaiffeisenBank/Transactor.php +++ b/src/Pohoda/RaiffeisenBank/Transactor.php @@ -88,7 +88,11 @@ public function import(): void foreach ($allTransactions as $transaction) { // $this->dataReset(); $this->takeTransactionData($transaction); - $success = $this->insertTransactionToPohoda($success); + + if ($this->insertTransactionToPohoda()) { + ++$success; + } + $this->reset(); } diff --git a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php index 196df52..65947e0 100644 --- a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php +++ b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php @@ -146,7 +146,7 @@ } } -$written = file_put_contents($destination, json_encode($report, \Ease\Shared::cfg('DEBUG') ? \JSON_PRETTY_PRINT : 0)); +$written = file_put_contents($destination, json_encode($report, Shared::cfg('DEBUG') ? \JSON_PRETTY_PRINT : 0)); $engine->addStatusMessage(sprintf(_('Saving result to %s'), $destination), $written ? 'success' : 'error'); exit($exitcode); diff --git a/src/raiffeisenbank-statements-sharepoint-checker.php b/src/raiffeisenbank-statements-sharepoint-checker.php index cfaa09d..2a01db1 100644 --- a/src/raiffeisenbank-statements-sharepoint-checker.php +++ b/src/raiffeisenbank-statements-sharepoint-checker.php @@ -29,18 +29,18 @@ */ $options = getopt('o::e::', ['output::environment::']); Shared::init( - [ - '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', + [ + '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', ); $destination = \array_key_exists('output', $options) ? $options['output'] : Shared::cfg('RESULT_FILE', 'php://stdout'); 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); +$engine->logBanner('', 'Scope: '.$engine->scope); $exitcode = 0; $fileUrls = []; $report = [ @@ -48,33 +48,35 @@ 'until' => $engine->getUntil()->format('Y-m-d'), 'since' => $engine->getSince()->format('Y-m-d'), 'missing' => [], - 'existing' => [] + 'existing' => [], ]; $pdfStatements = $engine->getStatementFilenames('pdf'); if ($pdfStatements) { - if (Shared::cfg('OFFICE365_USERNAME', false) && Shared::cfg('OFFICE365_PASSWORD', false)) { $credentials = new UserCredentials(Shared::cfg('OFFICE365_USERNAME'), Shared::cfg('OFFICE365_PASSWORD')); - $engine->addStatusMessage('Using OFFICE365_USERNAME ' . Shared::cfg('OFFICE365_USERNAME') . ' and OFFICE365_PASSWORD', 'debug'); + $engine->addStatusMessage('Using OFFICE365_USERNAME '.Shared::cfg('OFFICE365_USERNAME').' and OFFICE365_PASSWORD', 'debug'); } else { $credentials = new ClientCredential(Shared::cfg('OFFICE365_CLIENTID'), Shared::cfg('OFFICE365_CLSECRET')); - $engine->addStatusMessage('Using OFFICE365_CLIENTID ' . Shared::cfg('OFFICE365_CLIENTID') . ' and OFFICE365_CLSECRET', 'debug'); + $engine->addStatusMessage('Using OFFICE365_CLIENTID '.Shared::cfg('OFFICE365_CLIENTID').' and OFFICE365_CLSECRET', 'debug'); } - $ctx = (new ClientContext('https://' . Shared::cfg('OFFICE365_TENANT') . '.sharepoint.com/sites/' . Shared::cfg('OFFICE365_SITE')))->withCredentials($credentials); + $ctx = (new ClientContext('https://'.Shared::cfg('OFFICE365_TENANT').'.sharepoint.com/sites/'.Shared::cfg('OFFICE365_SITE')))->withCredentials($credentials); $targetFolder = $ctx->getWeb()->getFolderByServerRelativeUrl(Shared::cfg('OFFICE365_PATH')); - $engine->addStatusMessage('ServiceRootUrl: ' . $ctx->getServiceRootUrl(), 'debug'); + $engine->addStatusMessage('ServiceRootUrl: '.$ctx->getServiceRootUrl(), 'debug'); $sharepointFilesRaw = $targetFolder->getFiles()->get()->executeQuery(); + $sharepointFiles = []; + + // @phpstan-ignore foreach.nonIterable foreach ($sharepointFilesRaw as $fileInSharepint) { $sharepointFiles[$fileInSharepint->getName()] = $fileInSharepint->getServerRelativeUrl(); } foreach ($pdfStatements as $pdfStatement) { - if (array_key_exists($pdfStatement, $sharepointFiles)) { + if (\array_key_exists($pdfStatement, $sharepointFiles)) { $engine->addStatusMessage(sprintf('File %s exists in SharePoint', $pdfStatement), 'success'); $report['existing'][] = $pdfStatement; } else {