2024-11-01 10:57:50 +01:00

85 Zeilen
2.8 KiB
PHP

<?php
namespace D3\XRechnung\Modules\Application\Model;
use OxidEsales\Eshop\Core\Registry;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\ClientException;
class Order extends Order_parent
{
public function genXRechnung(string $sFilename, int $iSelLang = 0, bool $sendContent = false)
{
$blIsNewOrder = 0;
// setting invoice number
if (!$this->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;
}
}