diff --git a/src/Pohoda/RaiffeisenBank/PohodaBankClient.php b/src/Pohoda/RaiffeisenBank/PohodaBankClient.php index fdefa13..4aa61ee 100644 --- a/src/Pohoda/RaiffeisenBank/PohodaBankClient.php +++ b/src/Pohoda/RaiffeisenBank/PohodaBankClient.php @@ -216,13 +216,11 @@ public function getCurrencyCode() */ public function checkForTransactionPresence() { - $this->addStatusMessage('Checking for transaction presence - Not yet implemented', 'debug'); + $this->addStatusMessage('Checking for transaction presence - Not yet implemented', 'warning'); + return false; // !empty($this->getColumnsFromPohoda('id', ['cisDosle' => $this->getDataValue('cisDosle')])); TODO } - /** - * @param string $conSym - */ public function ensureKSExists(string $conSym): void { if (!\array_key_exists($conSym, $this->constSymbols)) { @@ -235,7 +233,7 @@ public function ensureKSExists(string $conSym): void /** * Insert Transaction to Pohoda. * - * @return array> Imported Transactions + * @return array> Imported Transactions */ public function insertTransactionToPohoda(): array { diff --git a/src/Pohoda/RaiffeisenBank/Statementor.php b/src/Pohoda/RaiffeisenBank/Statementor.php index 007afea..bd81ebd 100644 --- a/src/Pohoda/RaiffeisenBank/Statementor.php +++ b/src/Pohoda/RaiffeisenBank/Statementor.php @@ -30,14 +30,14 @@ class Statementor extends PohodaBankClient /** * Downloaded XML statements. * - * @var array + * @var array */ private array $statementsXML = []; /** * Downloaded PDF statements. * - * @var array + * @var array */ private array $statementsPDF = []; @@ -124,7 +124,16 @@ public function import(): array // $this->setDataValue('vypisCisDokl', $statementXML->BkToCstmrStmt->Stmt->Id); // $this->setDataValue('cisSouhrnne', $statementXML->BkToCstmrStmt->Stmt->LglSeqNb); - $inserted = array_merge($inserted, $this->insertTransactionToPohoda()); + try { + $lastInsert = $this->insertTransactionToPohoda(); + + if ($lastInsert) { + $inserted = array_merge($inserted); + ++$success; + } + } catch (\Exception $exc) { + $this->addStatusMessage('Error Inserting Record', 'error'); + } } $this->addStatusMessage($statementNumberLong.' Import done. '.$success.' of '.$entries.' imported'); @@ -144,7 +153,7 @@ public function import(): array public function entryToPohoda($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')); + $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')); $data['note'] = ''; $data['datePayment'] = current((array) $entry->BookgDt->DtTm); // current((array) $entry->ValDt->DtTm); $data['dateStatement'] = current((array) $entry->BookgDt->DtTm); diff --git a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php index 66caff3..586d23a 100644 --- a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php +++ b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php @@ -31,12 +31,12 @@ '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', - ], $argv[1] ?? '../.env'); +], $argv[1] ?? '../.env'); 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 = []; @@ -49,26 +49,26 @@ 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'); foreach ($pdfs as $filename) { $uploadFile = $targetFolder->uploadFile(basename($filename), file_get_contents($filename)); try { $ctx->executeQuery(); - $uploaded = $ctx->getBaseUrl() . '/_layouts/15/download.aspx?SourceUrl=' . urlencode($uploadFile->getServerRelativeUrl()); - $engine->addStatusMessage(_('Uploaded') . ': ' . $uploaded, 'success'); + $uploaded = $ctx->getBaseUrl().'/_layouts/15/download.aspx?SourceUrl='.urlencode($uploadFile->getServerRelativeUrl()); + $engine->addStatusMessage(_('Uploaded').': '.$uploaded, 'success'); } catch (\Exception $exc) { - fwrite(fopen('php://stderr', 'wb'), $exc->getMessage() . \PHP_EOL); + fwrite(fopen('php://stderr', 'wb'), $exc->getMessage().\PHP_EOL); exit(1); } @@ -112,7 +112,7 @@ try { $result = $doc->urlAttachment((int) $id, $sharepointUri, basename($filename)); - $doc->addStatusMessage($importInfo['number'] . ' ' . $sharepointUri, $result ? 'success' : 'error'); + $doc->addStatusMessage($importInfo['number'].' '.$sharepointUri, $result ? 'success' : 'error'); } catch (\Exception $ex) { $engine->addStatusMessage(_('Cannot Update PohodaSQL to attach statements in sharepoint links to invoice'), 'error'); @@ -134,5 +134,4 @@ } } - exit($exitcode);