diff --git a/README.md b/README.md index d14334e..063f39a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ -### XRechnung4OXID +### Installation + +## Datenbank + ALTER TABLE `oxorder` + ADD COLUMN `D3LEITWEGID` VARCHAR(25) NOT NULL COMMENT 'xRechnung' AFTER `OSC_AMAZON_REMARK` + +## Composer + composer require d3/xrechnung:dev-modules/rel_mod_xrechnung + +## Zugangsdaten + Die Zugangdaten hinter https://xrechnung.DOMAIN.TLD/xrechnung.php? entsprechend modifizieren - .env. + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f61f220 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "d3/xrechnung", + "description": "xRechnung", + "type": "oxideshop-module", + "keywords": [ + "oxid", + "modules", + "eShop", + "d3" + ], + "authors": [ + { + "name": "D3 Data Development (Inh. Thomas Dartsch)", + "email": "info@shopmodule.com", + "homepage": "https://www.d3data.de", + "role": "Owner" + } + ], + "support": { + "email": "support@shopmodule.com" + }, + "homepage": "https://www.oxidmodule.com/", + + "require": { + }, + "extra": { + "oxideshop": { + "source-directory": "/src", + "target-directory": "d3/xrechnung" + } + }, + "autoload": { + "psr-4": { + "D3\\XRechnung\\": "../../../source/modules/d3/xrechnung" + } + } +} diff --git a/src/Application/views/admin/blocks/order_overview.tpl b/src/Application/views/admin/blocks/order_overview.tpl new file mode 100644 index 0000000..1154ff7 --- /dev/null +++ b/src/Application/views/admin/blocks/order_overview.tpl @@ -0,0 +1,51 @@ +[{$smarty.block.parent}] + +[{if $edit && $oView->d3CanExport() && $oViewConf->getActiveClassName()|oxlower == 'order_overview'}] +
+
+ [{$oViewConf->getHiddenSid()}] + + + + +
+ xRechnung + + + + + + + + + [{* + + *}] + + + +
+ [{oxmultilang ident= + + :  + +
+ + +
+ + +

+ + +
+
+
+[{/if}] \ No newline at end of file diff --git a/src/Application/views/admin/de/config_lang.php b/src/Application/views/admin/de/config_lang.php new file mode 100644 index 0000000..6b2181d --- /dev/null +++ b/src/Application/views/admin/de/config_lang.php @@ -0,0 +1,29 @@ + + * @link http://www.oxidmodule.com + */ + +// @codeCoverageIgnoreStart + +$sLangName = "Deutsch"; +$iLangNr = 0; + +$aLang = array( + //Navigation + 'charset' => 'UTF-8', + 'SHOP_MODULE_GROUP_d3xrechnung' => 'Einstellungen', + 'SHOP_MODULE_d3xrechnung_PATH_GENERATOR' => 'Pfad xRechnung', + 'SHOP_MODULE_d3xrechnung_HTACCESS_USER' => '.htaccess - User', + 'SHOP_MODULE_d3xrechnung_HTACCESS_PASSWORD' => '.htaccess - Password', +); \ No newline at end of file diff --git a/src/Modules/Application/Controller/Admin/OrderOverview.php b/src/Modules/Application/Controller/Admin/OrderOverview.php new file mode 100644 index 0000000..fb9ce80 --- /dev/null +++ b/src/Modules/Application/Controller/Admin/OrderOverview.php @@ -0,0 +1,58 @@ +getEditObjectId(); + if ($soxId != "-1" && isset($soxId)) { + // load object + $oOrder = oxNew(\OxidEsales\Eshop\Application\Model\Order::class); + if ($oOrder->load($soxId)) { + $oConfig = $this->getConfig(); + $aParams = $oConfig->getRequestParameter("editval"); + + if($aParams["oxorder__d3leitwegid"]) + { + $oOrder->assign( + array('d3leitwegid' => $aParams["oxorder__d3leitwegid"]) + ); + $oOrder->save(); + } + + $oUtils = \OxidEsales\Eshop\Core\Registry::getUtils(); + $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue()); + if(!$sTrimmedBillName) { + return FALSE; + } + else { + $strx=array('#[^a-zA-Z0-9äöüß\040]#','# +#','#ä#','#ö#','#ü#','#ß#'); + $stry=array(' ',' ','ae','oe','ue','ss'); + $sTrimmedBillName=preg_replace($strx,$stry,$sTrimmedBillName); + $sTrimmedBillName=trim($sTrimmedBillName); + $sTrimmedBillName=strtolower($sTrimmedBillName); + } + $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".xml"; + $sFilename = $this->makeValidFileName($sFilename); + ob_start(); + $oOrder->genXRechnung($sFilename, \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("xmllanguage"), false); + + $myConfig = Registry::getConfig(); + + echo file_get_contents($myConfig->getConfigParam('sShopDir')."/export/xml/".$sFilename); + $sXML = ob_get_contents(); + ob_end_clean(); + $oUtils->setHeader("Pragma: public"); + $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + $oUtils->setHeader("Expires: 0"); + $oUtils->setHeader("Content-type: application/xml"); + $oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename); + \OxidEsales\Eshop\Core\Registry::getUtils()->showMessageAndExit($sXML); + } + } + } +} diff --git a/src/Modules/Application/Model/Order.php b/src/Modules/Application/Model/Order.php new file mode 100644 index 0000000..d345bc8 --- /dev/null +++ b/src/Modules/Application/Model/Order.php @@ -0,0 +1,84 @@ +oxorder__oxbillnr->value) { + $this->oxorder__oxbillnr->setValue($this->getNextBillNum()); + $blIsNewOrder = 1; + } + // setting invoice date + if ($this->oxorder__oxbilldate->value == '0000-00-00') { + $this->oxorder__oxbilldate->setValue(date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')))); + $blIsNewOrder = 1; + } + + if ($blIsNewOrder) { + $this->save(); + } + + // adding info data + switch (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('exporttype')) { + case ('xml'): + return $this->getXRechnungXml($sFilename, $this->getId(), $iSelLang, $sendContent); + break; + default: + return $this->getXRechnungXml($sFilename, $this->getId(), $iSelLang, $sendContent); + } + } + + /** + * @param $sOrderId + * @return true + */ + protected function getXRechnungXml(string $sFilename, string $sOrderId, int $iSelLang, bool $sendContent = false) + { + $oConfig = Registry::getConfig(); + $oConfig->getConfigParam('d3xrechnung_PATH_GENERATOR'); + + $sPathDetails = $oConfig->getConfigParam('d3xrechnung_PATH_GENERATOR'); + $sPathDetails .= 'orderid='.$sOrderId; + $sPathDetails .= '&filename='.$sFilename; + $sPathDetails .= '&iSelLang='.$iSelLang; + $sPathDetails .= '&sendContent='.$sendContent; + $sPathDetails .= '&combinexmlpdf=false'; + + $sUser = $oConfig->getConfigParam('d3xrechnung_HTACCESS_USER'); + $sPassword = $oConfig->getConfigParam('d3xrechnung_HTACCESS_PASSWORD'); + + $client = new Client(); + try { + /* + $response = $client->request('GET', $sPathDetails, + ['auth' => ['schmidt', 'tGiVLrBQik!8']] + ); + */ + + $response = $client->request('GET', $sPathDetails, + ['auth' => [$sUser, $sPassword]] + ); + + if($sendContent) { + return $response->getBody(); // '{"id": 1420053, "name": "guzzle", ...}' + } + return true; + } + catch (ClientException $exception) { + $logger = Registry::getLogger(); + $logger->error(Psr7\Message::toString($exception->getRequest()), [$exception]); + $logger->error(Psr7\Message::toString($exception->getResponse()), [$exception]); + } + return true; + } + +} diff --git a/src/metadata.php b/src/metadata.php new file mode 100644 index 0000000..b89401f --- /dev/null +++ b/src/metadata.php @@ -0,0 +1,84 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +use D3\DelUserExtension\Modules\Controller\Admin\userDeletingList; +use D3\DelUserExtension\Modules\Controller\Admin\userDeletingMain; +use D3\DelUserExtension\Modules\Core\Model\ListModel; + +$sMetadataVersion = '2.1'; + +$sModuleId = 'd3xrechnung'; +$logo = '(D3)'; + +/** + * Module information + */ +$aModule = [ + 'id' => $sModuleId, + 'title' => $logo.' Anpassung: xRechnung / Zugferd', + 'description' => [ + 'de' => '
+ Ruft den Generator auf, und gibt die erstellte XML-Datei an den Browser zum Download aus.
+Der Pfad und Zugangsschutz zum Generator wird in der Konfiguration des Moduls hinterlegt. +
+ Pfad: https://xrechnung.DOMAIN.TLD/xrechnung.php?
+ Validierung:https://www.epoconsulting.com/erechnung-sap/xrechnung-validator
+ Tickets: + + ', + 'en' => '', + ], + 'thumbnail' => 'picture.png', + 'version' => '1.0.0', + 'author' => $logo.' Data Development (Inh.: Thomas Dartsch)', + 'email' => 'support@shopmodule.com', + 'url' => 'https://www.oxidmodule.com/', + 'extend' => [ + \OxidEsales\Eshop\Application\Controller\Admin\OrderOverview::class => D3\XRechnung\Modules\Application\Controller\Admin\OrderOverview::class, + \OxidEsales\Eshop\Application\Model\Order::class => \D3\XRechnung\Modules\Application\Model\Order::class + ], + 'templates' => [ + ], + 'settings' => [ + [ + 'group' => 'd3xrechnung', + 'name' => 'd3xrechnung_PATH_GENERATOR', + 'type' => 'str', + 'value' => 'https://xrechnung.DOMAIN.TLD/xrechnung.php?' + ], + [ + 'group' => 'd3xrechnung', + 'name' => 'd3xrechnung_HTACCESS_USER', + 'type' => 'str', + 'value' => '' + ], + [ + 'group' => 'd3xrechnung', + 'name' => 'd3xrechnung_HTACCESS_PASSWORD', + 'type' => 'str', + 'value' => '' + ], + ], + 'blocks' => array( + array( + 'template' => 'order_overview.tpl', + 'block' => 'admin_order_overview_export', + 'file' => 'Application/views/admin/blocks/order_overview.tpl', + 'position' => 100 + ), + ), +]; diff --git a/src/out/img/xrechnung.png b/src/out/img/xrechnung.png new file mode 100644 index 0000000..3fe6b1d Binary files /dev/null and b/src/out/img/xrechnung.png differ diff --git a/src/picture.png b/src/picture.png new file mode 100644 index 0000000..d817ed4 Binary files /dev/null and b/src/picture.png differ