Newer
Older
<?php
use QUI\ERP\Accounting\Invoice\Handler;
use QUI\ERP\Accounting\Invoice\Utils\Invoice as InvoiceUtils;
use horstoeko\zugferd\ZugferdProfiles;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use Symfony\Component\HttpFoundation\Response;
define('QUIQQER_SYSTEM', true);
define('QUIQQER_AJAX', true);
require_once dirname(__FILE__, 5) . '/header.php';
$User = QUI::getUserBySession();
if (!$User->canUseBackend()) {
exit;
}
if (empty($_REQUEST['invoice'])) {
exit;
}
if (empty($_REQUEST['type'])) {
exit;
}
$invoiceHash = $_REQUEST['invoice'];
$type = mb_strtoupper($_REQUEST['type']);
$profileMap = [
'PROFILE_BASIC' => ZugferdProfiles::PROFILE_BASIC,
'PROFILE_BASICWL' => ZugferdProfiles::PROFILE_BASICWL,
'PROFILE_EN16931' => ZugferdProfiles::PROFILE_EN16931,
'PROFILE_EXTENDED' => ZugferdProfiles::PROFILE_EXTENDED,
'PROFILE_XRECHNUNG' => ZugferdProfiles::PROFILE_XRECHNUNG,
'PROFILE_XRECHNUNG_2' => ZugferdProfiles::PROFILE_XRECHNUNG_2,
'PROFILE_XRECHNUNG_2_1' => ZugferdProfiles::PROFILE_XRECHNUNG_2_1,
'PROFILE_XRECHNUNG_2_2' => ZugferdProfiles::PROFILE_XRECHNUNG_2_2,
'PROFILE_MINIMUM' => ZugferdProfiles::PROFILE_MINIMUM,
'PROFILE_XRECHNUNG_2_3' => ZugferdProfiles::PROFILE_XRECHNUNG_2_3,
'PROFILE_XRECHNUNG_3' => ZugferdProfiles::PROFILE_XRECHNUNG_3,
];
try {
$Invoice = Handler::getInstance()->getInvoiceByHash($invoiceHash);
$fileName = InvoiceUtils::getInvoiceFilename($Invoice);
$defaultTemplates = Defaults::conf('output', 'default_templates');
$defaultTemplates = json_decode($defaultTemplates, true);
if (!empty($defaultTemplates['Invoice'])) {
$templateProvider = $defaultTemplates['Invoice']['provider'];
$templateId = $defaultTemplates['Invoice']['id'];
}
$Request = QUI::getRequest();
$Request->query->set('id', $invoiceHash);
$Request->query->set('t', 'Invoice');
$Request->query->set('ep', 'quiqqer/invoice');
$Request->query->set('tpl', $templateId);
$Request->query->set('tplpr', $templateProvider);
include dirname(__FILE__, 4) . '/erp/bin/output/backend/download.php';
} else {
$document = InvoiceUtils::getElectronicInvoice($Invoice, $profileMap[$type]);
$content = $document->getContent();
$contentType = 'application/xml';
$fileName .= '.xml';
$response = new Response($content);
$response->headers->set('Content-Type', $contentType);
$response->headers->set('Content-Disposition', 'attachment; filename="' . $fileName . '"');
$response->headers->set('Content-Length', strlen($content));
$response->send();
}