369 lines
10 KiB
PHP
369 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* WISO Steuer Export
|
|
*
|
|
* Exportiert Buchungen im CSV-Format für WISO Steuer Software
|
|
*
|
|
* @package steuer
|
|
*/
|
|
|
|
// 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 && 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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="action" value="export">';
|
|
|
|
print '<div class="div-table-responsive-no-min">';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th colspan="2">'.$langs->trans("ExportSettings").'</th>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td style="width: 200px;">'.$langs->trans("Year").'</td>';
|
|
print '<td>';
|
|
print '<select name="jahr" class="flat minwidth100">';
|
|
for ($y = date('Y'); $y >= date('Y') - 5; $y--) {
|
|
print '<option value="'.$y.'"'.($y == $jahr ? ' selected' : '').'>'.$y.'</option>';
|
|
}
|
|
print '</select>';
|
|
print '</td>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("ExportFormat").'</td>';
|
|
print '<td>';
|
|
print '<select name="format" class="flat minwidth300">';
|
|
print '<option value="wiso_euer"'.($format == 'wiso_euer' ? ' selected' : '').'>'.$langs->trans("WISOEUeRFormat").'</option>';
|
|
print '<option value="datev"'.($format == 'datev' ? ' selected' : '').'>'.$langs->trans("DATEVFormat").'</option>';
|
|
print '<option value="ustva_csv"'.($format == 'ustva_csv' ? ' selected' : '').'>'.$langs->trans("UStVACSV").'</option>';
|
|
print '</select>';
|
|
print '</td>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td colspan="2">';
|
|
print '<input type="submit" class="button button-save" value="'.$langs->trans("Export").'">';
|
|
print '</td>';
|
|
print '</tr>';
|
|
|
|
print '</table>';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
print '<br>';
|
|
|
|
// Format-Beschreibungen
|
|
print '<div class="div-table-responsive-no-min">';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th colspan="2">'.$langs->trans("ExportFormatInfo").'</th>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td style="width: 200px;"><strong>'.$langs->trans("WISOEUeRFormat").'</strong></td>';
|
|
print '<td>'.$langs->trans("WISOEUeRFormatDesc").'</td>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td><strong>'.$langs->trans("DATEVFormat").'</strong></td>';
|
|
print '<td>'.$langs->trans("DATEVFormatDesc").'</td>';
|
|
print '</tr>';
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td><strong>'.$langs->trans("UStVACSV").'</strong></td>';
|
|
print '<td>'.$langs->trans("UStVACSVDesc").'</td>';
|
|
print '</tr>';
|
|
|
|
print '</table>';
|
|
print '</div>';
|
|
|
|
// Vorschau
|
|
print '<br>';
|
|
print '<h3>'.$langs->trans("PreviewData").' '.$jahr.'</h3>';
|
|
|
|
$euer = new EUeR($db);
|
|
$buchungen = $euer->getBuchungsliste($jahr.'-01-01', $jahr.'-12-31', 'alle');
|
|
|
|
print '<div class="div-table-responsive">';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>'.$langs->trans("Date").'</th>';
|
|
print '<th>'.$langs->trans("Ref").'</th>';
|
|
print '<th>'.$langs->trans("Description").'</th>';
|
|
print '<th>'.$langs->trans("Typ").'</th>';
|
|
print '<th class="right">'.$langs->trans("Netto").'</th>';
|
|
print '<th class="right">'.$langs->trans("VAT").'</th>';
|
|
print '<th class="right">'.$langs->trans("Brutto").'</th>';
|
|
print '</tr>';
|
|
|
|
$count = 0;
|
|
$max_preview = 20;
|
|
foreach ($buchungen as $buchung) {
|
|
if ($count >= $max_preview) {
|
|
print '<tr class="oddeven"><td colspan="7" class="center opacitymedium">... '.$langs->trans("AndMore", count($buchungen) - $max_preview).'</td></tr>';
|
|
break;
|
|
}
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.dol_print_date(strtotime($buchung['datum']), 'day').'</td>';
|
|
print '<td>'.$buchung['ref'].'</td>';
|
|
print '<td>'.dol_trunc($buchung['beschreibung'], 40).'</td>';
|
|
print '<td>';
|
|
if ($buchung['buchungstyp'] == 'einnahme') {
|
|
print '<span class="badge badge-status4">'.$langs->trans("Einnahme").'</span>';
|
|
} else {
|
|
print '<span class="badge badge-status1">'.$langs->trans("Ausgabe").'</span>';
|
|
}
|
|
print '</td>';
|
|
print '<td class="right">'.price($buchung['netto'], 0, $langs, 1, 2, 2).'</td>';
|
|
print '<td class="right">'.price($buchung['steuer'], 0, $langs, 1, 2, 2).'</td>';
|
|
print '<td class="right amount">'.price($buchung['brutto'], 0, $langs, 1, 2, 2).'</td>';
|
|
print '</tr>';
|
|
|
|
$count++;
|
|
}
|
|
|
|
print '<tr class="liste_total">';
|
|
print '<td colspan="4"><strong>'.$langs->trans("Total").': '.count($buchungen).' '.$langs->trans("Buchungen").'</strong></td>';
|
|
print '<td colspan="3"></td>';
|
|
print '</tr>';
|
|
|
|
print '</table>';
|
|
print '</div>';
|
|
|
|
// Hinweise
|
|
print '<br>';
|
|
print '<div class="opacitymedium">';
|
|
print '<strong>'.$langs->trans("ExportHinweise").':</strong><br>';
|
|
print '- '.$langs->trans("ExportHinweis1").'<br>';
|
|
print '- '.$langs->trans("ExportHinweis2").'<br>';
|
|
print '- '.$langs->trans("ExportHinweis3").'<br>';
|
|
print '</div>';
|
|
|
|
// Zurück-Button
|
|
print '<br>';
|
|
print '<div class="tabsAction">';
|
|
print '<a class="butAction" href="'.dol_buildpath('/steuer/steuerindex.php', 1).'"><i class="fa fa-arrow-left paddingright"></i>'.$langs->trans("Back").'</a>';
|
|
print '</div>';
|
|
|
|
llxFooter();
|
|
$db->close();
|