Skip to content

Commit

Permalink
Matching Request added after statement item imported
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Nov 20, 2024
1 parent b9643e5 commit df67562
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 18 deletions.
108 changes: 92 additions & 16 deletions src/Pohoda/RaiffeisenBank/PohodaBankClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($bankAccount, $options = [])
*/
public function sourceString()
{
return substr(__FILE__.'@'.gethostname(), -50);
return substr(__FILE__ . '@' . gethostname(), -50);
}

/**
Expand All @@ -76,7 +76,7 @@ public function sourceString()
public static function checkCertificatePresence($certFile): void
{
if ((file_exists($certFile) === false) || (is_readable($certFile) === false)) {
fwrite(\STDERR, 'Cannot read specified certificate file: '.$certFile.\PHP_EOL);
fwrite(\STDERR, 'Cannot read specified certificate file: ' . $certFile . \PHP_EOL);

exit(1);
}
Expand Down Expand Up @@ -128,8 +128,8 @@ public function setScope($scope): void

break;
case 'this_year':
$this->since = new \DateTime('first day of January '.date('Y'));
$this->until = new \DateTime('last day of December'.date('Y'));
$this->since = new \DateTime('first day of January ' . date('Y'));
$this->until = new \DateTime('last day of December' . date('Y'));

break;
case 'January': // 1
Expand All @@ -140,12 +140,12 @@ public function setScope($scope): void
case 'June': // 6
case 'July': // 7
case 'August': // 8
case 'September':// 9
case 'September': // 9
case 'October': // 10
case 'November': // 11
case 'December': // 12
$this->since = new \DateTime('first day of '.$scope.' '.date('Y'));
$this->until = new \DateTime('last day of '.$scope.' '.date('Y'));
$this->since = new \DateTime('first day of ' . $scope . ' ' . date('Y'));
$this->until = new \DateTime('last day of ' . $scope . ' ' . date('Y'));

break;
case 'auto':
Expand Down Expand Up @@ -175,7 +175,7 @@ public function setScope($scope): void
break;
}

throw new \Exception('Unknown scope '.$scope);
throw new \Exception('Unknown scope ' . $scope);
}

break;
Expand All @@ -194,7 +194,7 @@ public function setScope($scope): void
*/
public function getxRequestId()
{
return $this->getDataValue('account').time();
return $this->getDataValue('account') . time();
}

/**
Expand Down Expand Up @@ -223,8 +223,8 @@ public function checkForTransactionPresence()
public function ensureKSExists($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->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;
}
}
Expand All @@ -246,7 +246,6 @@ public function insertTransactionToPohoda($success)
$this->reset();
// TODO: $result = $this->sync();
$this->takeData($cache);
$this->automaticLiquidation();
$result = $this->addToPohoda();

if ($this->commit()) {
Expand All @@ -257,6 +256,9 @@ public function insertTransactionToPohoda($success)
$producedId = $this->response->producedDetails['id'];
$producedNumber = $this->response->producedDetails['number'];
$producedAction = $this->response->producedDetails['actionType'];

$this->automaticLiquidation($producedNumber);

} else {
echo '';
}
Expand All @@ -266,15 +268,25 @@ public function insertTransactionToPohoda($success)
$producedAction = 'n/a';
}

$this->addStatusMessage('#'.$producedId.' '.$producedAction.' '.$producedNumber, $result ? 'success' : 'error'); // TODO: Parse response for docID
$this->addStatusMessage('#' . $producedId . ' ' . $producedAction . ' ' . $producedNumber, $result ? 'success' : 'error'); // TODO: Parse response for docID


} else {
$this->addStatusMessage('Record with remoteNumber TODO already present in Pohoda', 'warning');
}

return $success;
}

public function automaticLiquidation()
/**
* Enable automatic liquidation.
*
* @see https://www.stormware.cz/schema/version_2/liquidation.xsd for details
* @see https://www.stormware.cz/xml/samples/version_2/import/Banka/Bank_03_v2.0.xml
*
* @return bool
*/
public function automaticLiquidation($producedNumber)
{
/*
Expand All @@ -300,10 +312,74 @@ public function automaticLiquidation()
</lqd:ruleOfPairing>
</lqd:automaticLiquidation>
<ftr:selectedNumbers>
<ftr:number>
<typ:numberRequested>KB0010003</typ:numberRequested>
</ftr:number>
</ftr:selectedNumbers>
*/

$this->requestXml;
file_put_contents($this->xmlCache, $this->generateAutomaticLiquidationXML($producedNumber));

if ($this->debug) {
fpassthru(fopen($this->xmlCache, 'r'));
}

$this->addStatusMessage('Automatic liquidation', 'success');


$this->setPostFields(file_get_contents($this->xmlCache));

if ($this->debug) {
$this->addStatusMessage('validate request by: xmllint --schema ' . \dirname(__DIR__, 3) . '/vendor/vitexsoftware/pohoda-connector/doc/xsd/data.xsd ' . $this->xmlCache . ' --noout', 'debug');
}

return $this->performRequest('/xml');
}

/**
* Generate XML for automatic liquidation.
*
* @return string
*/
public function generateAutomaticLiquidationXML($producedNumber)
{
$xmlString = '<?xml version="1.0" encoding="Windows-1250"?>
<dat:dataPack xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd"
xmlns:lqd="http://www.stormware.cz/schema/version_2/automaticLiquidation.xsd"
xmlns:ftr="http://www.stormware.cz/schema/version_2/filter.xsd"
xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd"
version="2.0" id="01" ico="'.$this->getCompanyId().'" application="Tisk" note="aut. livkidace dokladů tisk z programu Pohoda">
</dat:dataPack>';

$xml = new \SimpleXMLElement($xmlString);

$dataPackItem = $xml->addChild('dat:dataPackItem');
$dataPackItem->addAttribute('version', '2.0');
$dataPackItem->addAttribute('id', '001');

$automaticLiquidation = $dataPackItem->addChild('automaticLiquidation',null,'http://www.stormware.cz/schema/version_2/automaticLiquidation.xsd');
$automaticLiquidation->addAttribute('version', '2.0');

$record = $automaticLiquidation->addChild('record',null,'http://www.stormware.cz/schema/version_2/automaticLiquidation.xsd');

$filter = $record->addChild('filter',null,'http://www.stormware.cz/schema/version_2/filter.xsd');

$selectedNumbers = $filter->addChild('selectedNumbers');

$ftrNumber = $selectedNumbers->addChild('number');

$numberRequested = $ftrNumber->addChild('numberRequested', $producedNumber, 'http://www.stormware.cz/schema/version_2/type.xsd');

$ruleOfPairing = $automaticLiquidation->addChild('lqd:ruleOfPairing',null,'http://www.stormware.cz/schema/version_2/automaticLiquidation.xsd');
$ruleOfPairing->addChild('id', '1','http://www.stormware.cz/schema/version_2/type.xsd');

return $xml->asXML();
}

return 1;
public function getCompanyId() {
return \Ease\Shared::cfg('POHODA_ICO');
}
}
15 changes: 13 additions & 2 deletions src/Pohoda/RaiffeisenBank/Statementor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ class Statementor extends PohodaBankClient

/**
* Downloaded XML statements.
* @var array<string>
*/
private array $statementsXML = [];

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

/**
* Bank Statement Helper
* @param string $bankAccount
* @param array<string,string> $options
*/

public function __construct(string $bankAccount, array $options = [])
{
parent::__construct($bankAccount, $options);
$this->obtainer = new \VitexSoftware\Raiffeisenbank\Statementor($bankAccount);

$this->statementsDir = \Ease\Functions::cfg('STATEMENT_SAVE_DIR', sys_get_temp_dir().'/rb');
$this->statementsDir = \Ease\Shared::cfg('STATEMENT_SAVE_DIR', sys_get_temp_dir().'/rb');

if (file_exists($this->statementsDir) === false) {
mkdir($this->statementsDir, 0777, true);
Expand Down Expand Up @@ -87,6 +95,8 @@ public function importOnline()

/**
* Import Raiffeisen bank XML statement into Pohoda.
*
* @return array<string,array>
*/
public function import(): array
{
Expand Down Expand Up @@ -117,6 +127,7 @@ public function import(): array
echo ''; // WTF?
}
}

}

$this->addStatusMessage($statementNumberLong.' Import done. '.$success.' of '.$entries.' imported');
Expand All @@ -131,7 +142,7 @@ 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
* @param \SimpleXMLElement $entry
*/
public function entryToPohoda($entry): array
{
Expand Down

0 comments on commit df67562

Please sign in to comment.