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 && 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.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
dol_include_once('/steuer/class/euer.class.php');
$langs->loadLangs(array("steuer@steuer", "bills", "compta", "exports"));
$jahr = GETPOSTINT('jahr');
if (empty($jahr)) {
$jahr = date('Y');
}
$action = GETPOST('action', 'aZ09');
$format = GETPOST('format', 'alpha');
if (empty($format)) {
$format = 'wiso_euer';
}
/*
* Actions
*/
// Export durchführen
if ($action == 'export') {
$euer = new EUeR($db);
$buchungen = $euer->getBuchungsliste($jahr.'-01-01', $jahr.'-12-31', 'alle');
if ($format == 'wiso_euer') {
// WISO EÜR Format (CSV)
$filename = 'euer_export_'.$jahr.'_'.date('Ymd').'.csv';
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Cache-Control: no-cache, no-store, must-revalidate');
$output = fopen('php://output', 'w');
// BOM für Excel UTF-8
fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
// Header
fputcsv($output, array(
'Datum',
'Belegnummer',
'Beschreibung',
'Einnahme/Ausgabe',
'Netto',
'USt/VSt',
'Brutto',
'USt-Satz',
'Kontonummer',
'Partner'
), ';');
// Daten
foreach ($buchungen as $buchung) {
fputcsv($output, array(
date('d.m.Y', strtotime($buchung['datum'])),
$buchung['ref'],
$buchung['beschreibung'],
$buchung['buchungstyp'] == 'einnahme' ? 'Einnahme' : 'Ausgabe',
number_format($buchung['netto'], 2, ',', ''),
number_format($buchung['steuer'], 2, ',', ''),
number_format($buchung['brutto'], 2, ',', ''),
'19', // Standard, könnte erweitert werden
'', // Kontonummer
$buchung['partner']
), ';');
}
fclose($output);
exit;
} elseif ($format == 'datev') {
// DATEV-Format (vereinfacht)
$filename = 'datev_export_'.$jahr.'_'.date('Ymd').'.csv';
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Cache-Control: no-cache, no-store, must-revalidate');
$output = fopen('php://output', 'w');
// BOM für Excel UTF-8
fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
// DATEV Header (vereinfacht)
fputcsv($output, array(
'Umsatz',
'Soll/Haben',
'Konto',
'Gegenkonto',
'BU-Schlüssel',
'Belegdatum',
'Belegfeld 1',
'Buchungstext'
), ';');
foreach ($buchungen as $buchung) {
$soll_haben = $buchung['buchungstyp'] == 'einnahme' ? 'H' : 'S';
$konto = $buchung['buchungstyp'] == 'einnahme' ? '8400' : '4900';
$gegenkonto = '1200'; // Bank
fputcsv($output, array(
number_format($buchung['brutto'], 2, ',', ''),
$soll_haben,
$konto,
$gegenkonto,
'', // BU-Schlüssel
date('dm', strtotime($buchung['datum'])),
$buchung['ref'],
$buchung['beschreibung']
), ';');
}
fclose($output);
exit;
} elseif ($format == 'ustva_csv') {
// UStVA Werte als CSV
$filename = 'ustva_'.$jahr.'_'.date('Ymd').'.csv';
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Cache-Control: no-cache, no-store, must-revalidate');
$output = fopen('php://output', 'w');
fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
// Header
fputcsv($output, array(
'Monat',
'Kz81 (Umsätze 19%)',
'Kz86 (Umsätze 7%)',
'USt 19%',
'USt 7%',
'Kz66 (Vorsteuer)',
'Zahllast'
), ';');
// Monatliche Werte
for ($m = 1; $m <= 12; $m++) {
$euer->berechneAusDolibarr($jahr, $m, $m);
$kz81 = 0;
$kz86 = 0;
$ust19 = 0;
$ust7 = 0;
foreach ($euer->einnahmen as $einnahme) {
$ust_satz = isset($einnahme['ust_satz']) ? $einnahme['ust_satz'] : 19;
if ($ust_satz == 19) {
$kz81 += $einnahme['netto'];
$ust19 += isset($einnahme['ust']) ? $einnahme['ust'] : 0;
} elseif ($ust_satz == 7) {
$kz86 += $einnahme['netto'];
$ust7 += isset($einnahme['ust']) ? $einnahme['ust'] : 0;
}
}
$zahllast = ($ust19 + $ust7) - $euer->vst_summe;
fputcsv($output, array(
date('F', mktime(0, 0, 0, $m, 1, $jahr)),
number_format(round($kz81), 0, ',', ''),
number_format(round($kz86), 0, ',', ''),
number_format($ust19, 2, ',', ''),
number_format($ust7, 2, ',', ''),
number_format($euer->vst_summe, 2, ',', ''),
number_format($zahllast, 2, ',', '')
), ';');
}
fclose($output);
exit;
}
}
/*
* View
*/
$form = new Form($db);
llxHeader('', $langs->trans("WISOExport"), '', '', 0, 0, '', '', '', 'mod-steuer page-export-wiso');
print load_fiche_titre($langs->trans("WISOExport"), '', 'steuer.png@steuer');
// Export-Formular
print '
';
print '
';
// Format-Beschreibungen
print '';
print '
';
print '';
print '| '.$langs->trans("ExportFormatInfo").' | ';
print '
';
print '';
print '| '.$langs->trans("WISOEUeRFormat").' | ';
print ''.$langs->trans("WISOEUeRFormatDesc").' | ';
print '
';
print '';
print '| '.$langs->trans("DATEVFormat").' | ';
print ''.$langs->trans("DATEVFormatDesc").' | ';
print '
';
print '';
print '| '.$langs->trans("UStVACSV").' | ';
print ''.$langs->trans("UStVACSVDesc").' | ';
print '
';
print '
';
print '
';
// Vorschau
print '
';
print ''.$langs->trans("PreviewData").' '.$jahr.'
';
$euer = new EUeR($db);
$buchungen = $euer->getBuchungsliste($jahr.'-01-01', $jahr.'-12-31', 'alle');
print '';
print '
';
print '';
print '| '.$langs->trans("Date").' | ';
print ''.$langs->trans("Ref").' | ';
print ''.$langs->trans("Description").' | ';
print ''.$langs->trans("Typ").' | ';
print ''.$langs->trans("Netto").' | ';
print ''.$langs->trans("VAT").' | ';
print ''.$langs->trans("Brutto").' | ';
print '
';
$count = 0;
$max_preview = 20;
foreach ($buchungen as $buchung) {
if ($count >= $max_preview) {
print '| ... '.$langs->trans("AndMore", count($buchungen) - $max_preview).' |
';
break;
}
print '';
print '| '.dol_print_date(strtotime($buchung['datum']), 'day').' | ';
print ''.$buchung['ref'].' | ';
print ''.dol_trunc($buchung['beschreibung'], 40).' | ';
print '';
if ($buchung['buchungstyp'] == 'einnahme') {
print ''.$langs->trans("Einnahme").'';
} else {
print ''.$langs->trans("Ausgabe").'';
}
print ' | ';
print ''.price($buchung['netto'], 0, $langs, 1, 2, 2).' | ';
print ''.price($buchung['steuer'], 0, $langs, 1, 2, 2).' | ';
print ''.price($buchung['brutto'], 0, $langs, 1, 2, 2).' | ';
print '
';
$count++;
}
print '';
print '| '.$langs->trans("Total").': '.count($buchungen).' '.$langs->trans("Buchungen").' | ';
print ' | ';
print '
';
print '
';
print '
';
// Hinweise
print '
';
print '';
print ''.$langs->trans("ExportHinweise").':
';
print '- '.$langs->trans("ExportHinweis1").'
';
print '- '.$langs->trans("ExportHinweis2").'
';
print '- '.$langs->trans("ExportHinweis3").'
';
print '
';
// Zurück-Button
print '
';
print '';
llxFooter();
$db->close();