Skip to content

Commit

Permalink
better catch in case of mServer import step
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Nov 26, 2024
1 parent 2c084d0 commit b090b0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/Pohoda/RaiffeisenBank/PohodaBankClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -235,7 +233,7 @@ public function ensureKSExists(string $conSym): void
/**
* Insert Transaction to Pohoda.
*
* @return array<int, array<string,string>> Imported Transactions
* @return array<int, array<string, string>> Imported Transactions
*/
public function insertTransactionToPohoda(): array
{
Expand Down
17 changes: 13 additions & 4 deletions src/Pohoda/RaiffeisenBank/Statementor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class Statementor extends PohodaBankClient
/**
* Downloaded XML statements.
*
* @var array<string,string>
* @var array<string, string>
*/
private array $statementsXML = [];

/**
* Downloaded PDF statements.
*
* @var array<string,string>
* @var array<string, string>
*/
private array $statementsPDF = [];

Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions src/pohodaSQL-raiffeisenbank-statements-sharepoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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);
}
Expand Down Expand Up @@ -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');

Expand All @@ -134,5 +134,4 @@
}
}


exit($exitcode);

0 comments on commit b090b0c

Please sign in to comment.