diff --git a/Makefile b/Makefile index aa6be47..b61627a 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ key-info: @echo "key: $(KEY)" @echo "crt: $(CRT)" -dist-clean: clean +distclean: clean rm -rf vendor prepare: vendor/ondrejnov/eet/README.md @@ -62,7 +62,7 @@ eetcli.phar: info: eetcli.phar phar list -f eetcli.phar -i '\.(ini|p12|pem|crt|dist)$$' -distphar: bin/eetcli.phar +distphar: key crt bin/eetcli.phar bin/eetcli.phar: mkdir -p bin php -dphar.readonly=0 vendor/bin/box build -c box-dist.json diff --git a/bin/eetcli b/bin/eetcli index 7ad0306..9286924 100755 Binary files a/bin/eetcli and b/bin/eetcli differ diff --git a/composer.lock b/composer.lock index 917af44..904c658 100644 --- a/composer.lock +++ b/composer.lock @@ -47,16 +47,16 @@ }, { "name": "robrichards/wse-php", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/robrichards/wse-php.git", - "reference": "45e8efd82ac0a873735b2158e44917d699db6740" + "reference": "5dde350ec77930f2ff6c1bb15c4d9e257b1d2496" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/robrichards/wse-php/zipball/45e8efd82ac0a873735b2158e44917d699db6740", - "reference": "45e8efd82ac0a873735b2158e44917d699db6740", + "url": "https://api.github.com/repos/robrichards/wse-php/zipball/5dde350ec77930f2ff6c1bb15c4d9e257b1d2496", + "reference": "5dde350ec77930f2ff6c1bb15c4d9e257b1d2496", "shasum": "" }, "require": { @@ -87,7 +87,7 @@ "soap", "ws-addressing" ], - "time": "2016-10-21T21:28:31+00:00" + "time": "2017-03-09T16:42:34+00:00" }, { "name": "robrichards/xmlseclibs", @@ -174,16 +174,16 @@ "packages-dev": [ { "name": "doctrine/annotations", - "version": "v1.3.1", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558" + "reference": "54cacc9b81758b14e3ce750f205a393d52339e97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/bd4461328621bde0ae6b1b2675fbc6aca4ceb558", - "reference": "bd4461328621bde0ae6b1b2675fbc6aca4ceb558", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/54cacc9b81758b14e3ce750f205a393d52339e97", + "reference": "54cacc9b81758b14e3ce750f205a393d52339e97", "shasum": "" }, "require": { @@ -192,7 +192,7 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^5.6.1" + "phpunit/phpunit": "^5.7" }, "type": "library", "extra": { @@ -238,7 +238,7 @@ "docblock", "parser" ], - "time": "2016-12-30T15:59:45+00:00" + "time": "2017-02-24T16:22:25+00:00" }, { "name": "doctrine/lexer", @@ -1011,21 +1011,24 @@ }, { "name": "seld/jsonlint", - "version": "1.5.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "19495c181d6d53a0a13414154e52817e3b504189" + "reference": "791f8c594f300d246cdf01c6b3e1e19611e301d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/19495c181d6d53a0a13414154e52817e3b504189", - "reference": "19495c181d6d53a0a13414154e52817e3b504189", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/791f8c594f300d246cdf01c6b3e1e19611e301d8", + "reference": "791f8c594f300d246cdf01c6b3e1e19611e301d8", "shasum": "" }, "require": { "php": "^5.3 || ^7.0" }, + "require-dev": { + "phpunit/phpunit": "^4.5" + }, "bin": [ "bin/jsonlint" ], @@ -1053,20 +1056,20 @@ "parser", "validator" ], - "time": "2016-11-14T17:59:58+00:00" + "time": "2017-03-06T16:42:24+00:00" }, { "name": "symfony/console", - "version": "v3.2.4", + "version": "v3.2.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0e5e6899f82230fcb1153bcaf0e106ffaa44b870" + "reference": "28fb243a2b5727774ca309ec2d92da240f1af0dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0e5e6899f82230fcb1153bcaf0e106ffaa44b870", - "reference": "0e5e6899f82230fcb1153bcaf0e106ffaa44b870", + "url": "https://api.github.com/repos/symfony/console/zipball/28fb243a2b5727774ca309ec2d92da240f1af0dd", + "reference": "28fb243a2b5727774ca309ec2d92da240f1af0dd", "shasum": "" }, "require": { @@ -1116,20 +1119,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-02-16T14:07:22+00:00" + "time": "2017-03-06T19:30:27+00:00" }, { "name": "symfony/debug", - "version": "v3.2.4", + "version": "v3.2.5", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "9b98854cb45bc59d100b7d4cc4cf9e05f21026b9" + "reference": "b90c9f91ad8ac37d9f114e369042d3226b34dc1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/9b98854cb45bc59d100b7d4cc4cf9e05f21026b9", - "reference": "9b98854cb45bc59d100b7d4cc4cf9e05f21026b9", + "url": "https://api.github.com/repos/symfony/debug/zipball/b90c9f91ad8ac37d9f114e369042d3226b34dc1a", + "reference": "b90c9f91ad8ac37d9f114e369042d3226b34dc1a", "shasum": "" }, "require": { @@ -1173,20 +1176,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2017-02-16T16:34:18+00:00" + "time": "2017-02-18T17:28:00+00:00" }, { "name": "symfony/finder", - "version": "v3.2.4", + "version": "v3.2.5", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "8c71141cae8e2957946b403cc71a67213c0380d6" + "reference": "92d7476d2df60cd851a3e13e078664b1deb8ce10" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/8c71141cae8e2957946b403cc71a67213c0380d6", - "reference": "8c71141cae8e2957946b403cc71a67213c0380d6", + "url": "https://api.github.com/repos/symfony/finder/zipball/92d7476d2df60cd851a3e13e078664b1deb8ce10", + "reference": "92d7476d2df60cd851a3e13e078664b1deb8ce10", "shasum": "" }, "require": { @@ -1222,7 +1225,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-02-21T09:12:04+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -1285,16 +1288,16 @@ }, { "name": "symfony/process", - "version": "v3.2.4", + "version": "v3.2.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856" + "reference": "68bfa8c83f24c0ac04ea7193bcdcda4519f41892" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856", - "reference": "0ab87c1e7570b3534a6e51eb4ca8e9f6d7327856", + "url": "https://api.github.com/repos/symfony/process/zipball/68bfa8c83f24c0ac04ea7193bcdcda4519f41892", + "reference": "68bfa8c83f24c0ac04ea7193bcdcda4519f41892", "shasum": "" }, "require": { @@ -1330,7 +1333,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-02-16T14:07:22+00:00" + "time": "2017-03-04T12:23:14+00:00" }, { "name": "tedivm/jshrink", diff --git a/doc/EETFile.md b/doc/EETFile.md index 8bc5ebd..2c64026 100644 --- a/doc/EETFile.md +++ b/doc/EETFile.md @@ -19,6 +19,15 @@ EET soubor je v podstatě ini soubor. Dá se editovat jakýmkoliv textovým edit u nových EET souborů, které mohou být vytvářeny externím programem, například účetním. EET soubory obsahující další údaje jsou sice stále textové soubory, ale jejich modifikací se mohou stát neplatnými díky porušení bezpečnostních kodů. +### Status +Status účtenky: + + * 0 - nová účtenka + * 1 - odeslaná + * 2 - neodeslaná kvůli chybě + * 3 - odeslaná pouze v ověřovacím režimu bez FIK + + ### Příklad EET souboru ve stavu připraveném k odeslání (vytvořený např. externím programem) ``` [eetfile] @@ -45,7 +54,7 @@ celk_trzba=10 ``` [eetfile] version=1.0 -status=1 +status=2 lasterror=4 lasterrorcode=Neplatny podpis SOAP zpravy prostredi=produkcni @@ -69,8 +78,8 @@ bkp=31383964343362382d38393936633730332d31663832316662612d39323939643061662d6536 [eetfile] version=1.0 status=1 -lasterror=4 -lasterrorcode=Neplatny podpis SOAP zpravy +lasterror= +lasterrorcode= prostredi=produkcni [eet] diff --git a/eetcli.php b/eetcli.php index aec4963..5443fa2 100755 --- a/eetcli.php +++ b/eetcli.php @@ -114,6 +114,8 @@ . "25\t Uctenka je nova (vysledek testu)" . PHP_EOL . "26\t Uctenka jiz byla zaslana (vysledek testu)" . PHP_EOL . "27\t Kontrolni soucty v EET souboru nesedi" . PHP_EOL + . "29\t EET uctenka neodeslana kvuli chybe" . PHP_EOL + . "30\t EET soubor odeslan v overovacim rezimu" . PHP_EOL . PHP_EOL); Config::addOpt(null, "key", Config::C_REQUIRED, "Certificate private key (pem format)", __DIR__ . "/keys/EET_CA1_Playground-CZ1212121218.pem"); @@ -167,7 +169,7 @@ Console::debug("Posilam EET soubor na etrzby: " . Config::getOpt("send-eet") . PHP_EOL); $dispatcher = Util::initDispatcher($eet->playground, $eet->overovaci); $r = $eet->toReceipt($dispatcher); - if ($eet->status != 2) { + if ($eet->status != EETFile::STATUS_SENT) { try { $fik = $dispatcher->send($r, $eet->overovaci); $codes = Util::getCheckCodes($dispatcher, $r, $eet->playground, $eet->overovaci); @@ -178,6 +180,7 @@ $r->bkp = $bkp; $r->pkp = $pkp; $eet->fromReceipt($r); + $eet->setStatus(EETFile::STATUS_SENT); $eet->save(); Console::out(Util::expandMacros(Config::getOpt("format"), $r)); } catch (Exception $e) { @@ -188,7 +191,7 @@ $r->bkp = $bkp; $r->pkp = $pkp; $eet->fromReceipt($r); - $eet->setStatus(1); + $eet->setStatus(EETFile::STATUS_ERR); $eet->setErrorCode($e->getCode()); $eet->setError($e->getMessage()); $eet->save(); @@ -262,17 +265,21 @@ Console::error($e->getCode(), $e->getMessage() . "\n"); } switch ($eet->status) { - case 0: + case EETFile::STATUS_NEW: Console::out("Nova\n"); $status = Util::E_NEW; break; - case 1: - Console::out("Neodeslana\n"); + case EETFile::STATUS_SENT: + Console::out("Odeslana\n"); $status = Util::E_ALREADYSENT; break; - case 2: - Console::out("Odeslana\n"); - $status = Util::E_SENT; + case EETFile::STATUS_ERR: + Console::out("Neodeslana (chyba)\n"); + $status = Util::E_SENTERR; + break; + case EETFile::STATUS_OVEROVACI: + Console::out("Odeslana pouze v overovacim rezimu\n"); + $status = Util::E_SENTOVEROVACI; break; } if ($status == 2) { @@ -306,7 +313,7 @@ try { $eet = New EETFile($file, EETFile::MODE_W, Config::getOpt("neprodukcni"), Config::getOpt("overovaci")); $eet->fromReceipt($r); - $eet->setStatus(0); + $eet->setStatus(EETFile::STATUS_NEW); } catch (Exception $e) { Console::error(Util::eetCodeToError($e->getCode()), $e->getMessage() . PHP_EOL); } @@ -363,7 +370,7 @@ $r->bkp = $bkp; $r->pkp = $pkp; $eet->fromReceipt($r); - $eet->setStatus(1); + $eet->setStatus(EETFile::STATUS_ERR); $eet->setErrorCode($e->getCode()); $eet->setError($e->getMessage()); $eet->save(); @@ -380,11 +387,11 @@ if ($file) { $eet->fromReceipt($r); if (Config::getOpt("overovaci")) { - $eet->setStatus(1); + $eet->setStatus(EETFile::STATUS_OVEROVACI); $eet->setErrorCode(0); $eet->setError("Overovaci"); } else { - $eet->setStatus(2); + $eet->setStatus(EETFile::STATUS_SENT); } $eet->save(); } diff --git a/inc/EETFile.class.php b/inc/EETFile.class.php index 4ef80a7..7cea78f 100644 --- a/inc/EETFile.class.php +++ b/inc/EETFile.class.php @@ -38,6 +38,11 @@ class EETFile { const MODE_W = 2; // Write only (create) const MODE_RW = 3; // RW const MODE_D = 4; // Dry (create object only) + + const STATUS_NEW = 0; // Nova uctenka + const STATUS_SENT = 1; // Uspesne odeslana uctenka + const STATUS_ERR = 2; // Neuspesne odeslana uctenka + const STATUS_OVEROVACI = 3; // Zaslana pouze jako overovaci rezim (bez fiku) /* * Typy polozek k odeslani @@ -114,13 +119,6 @@ public function __construct($filename, $mode = self::MODE_D, $playground = false switch ($mode) { case self::MODE_R: self::load(); - if (array_key_exists("fik", $this->items)) { - $this->status = 2; - } elseif (array_key_exists("pkp", $this->items)) { - $this->status = 1; - } else { - $this->status = 0; - } break; case self::MODE_W: if (file_exists($this->filename)) { @@ -181,10 +179,10 @@ public function save() { ); foreach ($this->ITEMS as $key => $options) { if ($options & self::I_REQUIRED) { - self::puts($f, $key . "=" . $this->items[$key] . PHP_EOL); + self::puts($f, $key . '="' . $this->items[$key] . '"' . PHP_EOL); } elseif ($options & self::I_OPTIONAL) { if (array_key_exists($key, $this->items)) { - self::puts($f, $key . "=" . $this->items[$key] . PHP_EOL); + self::puts($f, $key . '="' . $this->items[$key] . '"' . PHP_EOL); } } } diff --git a/inc/Util.class.php b/inc/Util.class.php index 0ec88a3..79365b5 100644 --- a/inc/Util.class.php +++ b/inc/Util.class.php @@ -40,6 +40,8 @@ class Util { const E_LOCK = 24; const E_NEW = 25; const E_SENT = 26; + const E_SENTERR = 29; + const E_SENTOVEROVACI = 30; const E_CHECKCODES = 27; private static $tmpfiles;