dolibarr.exportzugferd/index.php
data 6e33cc7096 Version 2.0 - ZUGFeRD PDF-Einbettung
- ZUGFeRD/Factur-X XML-Generierung (EN16931)
- XRechnung 3.0 Unterstützung
- PDF-Einbettung (echtes ZUGFeRD-PDF)
- Option XML nach Einbettung zu löschen
- ODT-Template Unterstützung
- E-Mail Anhang Funktion
- XML-Vorschau

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 15:36:15 +01:00

155 lines
4.9 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file index.php
* \ingroup exportzugferd
* \brief Home page for ExportZugferd module
*/
// Load Dolibarr environment
$res = 0;
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
$tmp2 = realpath(__FILE__);
$i = strlen($tmp) - 1;
$j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
$i--;
$j--;
}
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
}
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
}
if (!$res && file_exists("../main.inc.php")) {
$res = @include "../main.inc.php";
}
if (!$res && file_exists("../../main.inc.php")) {
$res = @include "../../main.inc.php";
}
if (!$res) {
die("Include of main fails");
}
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
// Security check
if (!$user->hasRight('exportzugferd', 'read')) {
accessforbidden();
}
$langs->loadLangs(array('exportzugferd@exportzugferd', 'bills'));
/*
* View
*/
$form = new Form($db);
llxHeader('', $langs->trans('ExportZugferd'), '', '', 0, 0, '', '', '', 'mod-exportzugferd page-index');
print load_fiche_titre($langs->trans('ExportZugferd'), '', 'fa-file-export');
print '<div class="fichecenter">';
print '<div class="fichethirdleft">';
// Info box
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="2">' . $langs->trans('Information') . '</td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td class="titlefield">' . $langs->trans('ZugferdProfile') . '</td>';
print '<td>' . getDolGlobalString('EXPORTZUGFERD_PROFILE', 'EN16931') . '</td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td>' . $langs->trans('AutoGenerateZugferd') . '</td>';
print '<td>' . yn(getDolGlobalInt('EXPORTZUGFERD_AUTO_GENERATE')) . '</td>';
print '</tr>';
print '</table>';
print '</div>';
print '</div>';
print '<div class="fichetwothirdright">';
// Recent invoices with ZUGFeRD
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="4">' . $langs->trans('RecentInvoicesWithZugferd') . '</td>';
print '</tr>';
// Get recent invoices
$sql = "SELECT f.rowid, f.ref, f.datef, f.total_ttc, s.nom as socname";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
$sql .= " WHERE f.entity IN (" . getEntity('invoice') . ")";
$sql .= " ORDER BY f.datef DESC";
$sql .= " LIMIT 10";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0) {
while ($obj = $db->fetch_object($resql)) {
$invoice = new Facture($db);
$invoice->fetch($obj->rowid);
// Check if XML exists
$dir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$hasXML = file_exists($dir . '/factur-x.xml') || file_exists($dir . '/xrechnung-' . $obj->ref . '.xml');
print '<tr class="oddeven">';
print '<td>' . $invoice->getNomUrl(1) . '</td>';
print '<td>' . htmlspecialchars($obj->socname) . '</td>';
print '<td class="right">' . price($obj->total_ttc) . ' ' . $conf->currency . '</td>';
print '<td class="right">';
if ($hasXML) {
print '<span class="badge badge-status4">' . $langs->trans('ZugferdXMLFile') . '</span>';
} else {
print '<a class="button buttongen" href="' . dol_buildpath('/exportzugferd/download.php', 1) . '?id=' . $obj->rowid . '&action=generate_xml">';
print $langs->trans('GenerateZugferdXML');
print '</a>';
}
print '</td>';
print '</tr>';
}
} else {
print '<tr class="oddeven"><td colspan="4" class="opacitymedium">' . $langs->trans('NoRecordFound') . '</td></tr>';
}
$db->free($resql);
} else {
dol_print_error($db);
}
print '</table>';
print '</div>';
print '</div>';
print '</div>';
llxFooter();
$db->close();