345 lines
13 KiB
PHP
345 lines
13 KiB
PHP
<?php
|
|
/**
|
|
* Buchungsliste
|
|
*
|
|
* @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/buchung.class.php');
|
|
dol_include_once('/steuer/class/euer.class.php');
|
|
|
|
$langs->loadLangs(array("steuer@steuer", "bills", "compta"));
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$massaction = GETPOST('massaction', 'alpha');
|
|
$confirm = GETPOST('confirm', 'alpha');
|
|
$toselect = GETPOST('toselect', 'array');
|
|
|
|
// Filter
|
|
$jahr = GETPOSTINT('jahr');
|
|
if (empty($jahr)) {
|
|
$jahr = date('Y');
|
|
}
|
|
$monat = GETPOSTINT('monat');
|
|
$typ = GETPOST('search_typ', 'alpha');
|
|
$search_ref = GETPOST('search_ref', 'alpha');
|
|
$search_beschreibung = GETPOST('search_beschreibung', 'alpha');
|
|
|
|
// Sortierung
|
|
$sortfield = GETPOST('sortfield', 'aZ09comma');
|
|
$sortorder = GETPOST('sortorder', 'aZ09comma');
|
|
if (empty($sortfield)) {
|
|
$sortfield = 'datum';
|
|
}
|
|
if (empty($sortorder)) {
|
|
$sortorder = 'DESC';
|
|
}
|
|
|
|
// Pagination
|
|
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
|
|
if (empty($page) || $page < 0) {
|
|
$page = 0;
|
|
}
|
|
$offset = $limit * $page;
|
|
|
|
/*
|
|
* View
|
|
*/
|
|
|
|
$form = new Form($db);
|
|
$euer = new EUeR($db);
|
|
|
|
llxHeader('', $langs->trans("Buchungen"), '', '', 0, 0, '', '', '', 'mod-steuer page-buchung-list');
|
|
|
|
print load_fiche_titre($langs->trans("Buchungen"), '', 'steuer.png@steuer');
|
|
|
|
// Datumsgrenzen für SQL
|
|
if ($monat > 0) {
|
|
$datum_von = $jahr.'-'.sprintf('%02d', $monat).'-01';
|
|
$datum_bis = date('Y-m-t', strtotime($datum_von));
|
|
} else {
|
|
$datum_von = $jahr.'-01-01';
|
|
$datum_bis = $jahr.'-12-31';
|
|
}
|
|
|
|
// SQL für manuelle Buchungen
|
|
$sql = "SELECT b.rowid, b.ref, b.datum, b.belegnummer, b.beschreibung,";
|
|
$sql .= " b.betrag_netto, b.betrag_ust, b.betrag_brutto, b.typ,";
|
|
$sql .= " k.kontonummer, k.bezeichnung as konto_bezeichnung,";
|
|
$sql .= " 'manuell' as quelle";
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."steuer_buchung as b";
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."steuer_konto as k ON b.fk_konto = k.rowid";
|
|
$sql .= " WHERE b.entity = ".((int) $conf->entity);
|
|
$sql .= " AND b.status = 1";
|
|
$sql .= " AND b.datum BETWEEN '".$db->escape($datum_von)."' AND '".$db->escape($datum_bis)."'";
|
|
|
|
if ($typ) {
|
|
$sql .= " AND b.typ = '".$db->escape($typ)."'";
|
|
}
|
|
if ($search_ref) {
|
|
$sql .= " AND b.ref LIKE '%".$db->escape($search_ref)."%'";
|
|
}
|
|
if ($search_beschreibung) {
|
|
$sql .= " AND b.beschreibung LIKE '%".$db->escape($search_beschreibung)."%'";
|
|
}
|
|
|
|
// UNION mit Rechnungen (Einnahmen)
|
|
$sql .= " UNION ALL ";
|
|
$sql .= "SELECT f.rowid, f.ref, COALESCE(pf.datep, f.datef) as datum, f.ref as belegnummer,";
|
|
$sql .= " CONCAT('Rechnung: ', s.nom) as beschreibung,";
|
|
$sql .= " f.total_ht as betrag_netto, f.total_tva as betrag_ust, f.total_ttc as betrag_brutto,";
|
|
$sql .= " 'einnahme' as typ, '' as kontonummer, '' as konto_bezeichnung,";
|
|
$sql .= " 'facture' as quelle";
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid";
|
|
$sql .= " WHERE f.entity = ".((int) $conf->entity);
|
|
$sql .= " AND f.fk_statut IN (2, 3)";
|
|
$sql .= " AND COALESCE(pf.datep, f.datef) BETWEEN '".$db->escape($datum_von)."' AND '".$db->escape($datum_bis)."'";
|
|
if ($typ == 'ausgabe') {
|
|
$sql .= " AND 1=0"; // Keine Einnahmen bei Ausgaben-Filter
|
|
}
|
|
if ($search_beschreibung) {
|
|
$sql .= " AND s.nom LIKE '%".$db->escape($search_beschreibung)."%'";
|
|
}
|
|
$sql .= " GROUP BY f.rowid";
|
|
|
|
// UNION mit Lieferantenrechnungen (Ausgaben)
|
|
$sql .= " UNION ALL ";
|
|
$sql .= "SELECT f.rowid, f.ref, COALESCE(pf.datep, f.datef) as datum, COALESCE(f.ref_supplier, f.ref) as belegnummer,";
|
|
$sql .= " CONCAT('Lieferant: ', s.nom) as beschreibung,";
|
|
$sql .= " f.total_ht as betrag_netto, f.total_tva as betrag_ust, f.total_ttc as betrag_brutto,";
|
|
$sql .= " 'ausgabe' as typ, '' as kontonummer, '' as konto_bezeichnung,";
|
|
$sql .= " 'facture_fourn' as quelle";
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid";
|
|
$sql .= " WHERE f.entity = ".((int) $conf->entity);
|
|
$sql .= " AND f.fk_statut IN (2)";
|
|
$sql .= " AND COALESCE(pf.datep, f.datef) BETWEEN '".$db->escape($datum_von)."' AND '".$db->escape($datum_bis)."'";
|
|
if ($typ == 'einnahme') {
|
|
$sql .= " AND 1=0"; // Keine Ausgaben bei Einnahmen-Filter
|
|
}
|
|
if ($search_beschreibung) {
|
|
$sql .= " AND s.nom LIKE '%".$db->escape($search_beschreibung)."%'";
|
|
}
|
|
$sql .= " GROUP BY f.rowid";
|
|
|
|
// Sortierung und Limit
|
|
$sql_count = "SELECT COUNT(*) as total FROM (".$sql.") as combined";
|
|
$sql .= " ORDER BY ".$sortfield." ".$sortorder;
|
|
$sql .= " LIMIT ".$limit." OFFSET ".$offset;
|
|
|
|
// Gesamtzahl ermitteln
|
|
$resql_count = $db->query($sql_count);
|
|
$nbtotalofrecords = 0;
|
|
if ($resql_count) {
|
|
$obj = $db->fetch_object($resql_count);
|
|
$nbtotalofrecords = $obj->total;
|
|
}
|
|
|
|
// Filter-Formular
|
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="searchform">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
|
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
|
|
|
print '<div class="div-table-responsive-no-min">';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<td>'.$langs->trans("Year").'</td>';
|
|
print '<td>'.$langs->trans("Month").'</td>';
|
|
print '<td>'.$langs->trans("Typ").'</td>';
|
|
print '<td></td>';
|
|
print '</tr>';
|
|
print '<tr class="oddeven">';
|
|
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 '<td>';
|
|
print '<select name="monat" class="flat minwidth100">';
|
|
print '<option value="0"'.($monat == 0 ? ' selected' : '').'>'.$langs->trans("WholeYear").'</option>';
|
|
for ($m = 1; $m <= 12; $m++) {
|
|
print '<option value="'.$m.'"'.($m == $monat ? ' selected' : '').'>'.dol_print_date(mktime(0, 0, 0, $m, 1, 2000), '%B').'</option>';
|
|
}
|
|
print '</select>';
|
|
print '</td>';
|
|
print '<td>';
|
|
print '<select name="search_typ" class="flat minwidth100">';
|
|
print '<option value="">'.$langs->trans("All").'</option>';
|
|
print '<option value="einnahme"'.($typ == 'einnahme' ? ' selected' : '').'>'.$langs->trans("Einnahmen").'</option>';
|
|
print '<option value="ausgabe"'.($typ == 'ausgabe' ? ' selected' : '').'>'.$langs->trans("Ausgaben").'</option>';
|
|
print '</select>';
|
|
print '</td>';
|
|
print '<td>';
|
|
print '<input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
|
|
print ' <a href="'.dol_buildpath('/steuer/buchung_card.php', 1).'?action=create" class="butAction">'.$langs->trans("NeueBuchung").'</a>';
|
|
print '</td>';
|
|
print '</tr>';
|
|
print '</table>';
|
|
print '</div>';
|
|
|
|
print '<br>';
|
|
|
|
// Haupttabelle
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "ref", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "datum", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("Belegnummer", $_SERVER["PHP_SELF"], "belegnummer", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "beschreibung", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "kontonummer", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("Typ", $_SERVER["PHP_SELF"], "typ", "", $param, "", $sortfield, $sortorder);
|
|
print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "betrag_netto", "", $param, 'class="right"', $sortfield, $sortorder);
|
|
print_liste_field_titre("VAT", $_SERVER["PHP_SELF"], "betrag_ust", "", $param, 'class="right"', $sortfield, $sortorder);
|
|
print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "betrag_brutto", "", $param, 'class="right"', $sortfield, $sortorder);
|
|
print '</tr>';
|
|
|
|
$resql = $db->query($sql);
|
|
if ($resql) {
|
|
$num = $db->num_rows($resql);
|
|
$total_einnahmen = 0;
|
|
$total_ausgaben = 0;
|
|
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
print '<tr class="oddeven">';
|
|
|
|
// Ref mit Link
|
|
print '<td class="nowraponall">';
|
|
if ($obj->quelle == 'manuell') {
|
|
print '<a href="'.dol_buildpath('/steuer/buchung_card.php', 1).'?id='.$obj->rowid.'">'.$obj->ref.'</a>';
|
|
} elseif ($obj->quelle == 'facture') {
|
|
print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.$obj->rowid.'">'.$obj->ref.'</a>';
|
|
print ' <span class="badge badge-info">Rechnung</span>';
|
|
} elseif ($obj->quelle == 'facture_fourn') {
|
|
print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.$obj->rowid.'">'.$obj->ref.'</a>';
|
|
print ' <span class="badge badge-warning">Lieferant</span>';
|
|
}
|
|
print '</td>';
|
|
|
|
// Datum
|
|
print '<td>'.dol_print_date($db->jdate($obj->datum), 'day').'</td>';
|
|
|
|
// Belegnummer
|
|
print '<td>'.$obj->belegnummer.'</td>';
|
|
|
|
// Beschreibung
|
|
print '<td>'.dol_trunc($obj->beschreibung, 50).'</td>';
|
|
|
|
// Konto
|
|
print '<td>'.$obj->kontonummer.($obj->kontonummer ? ' - ' : '').$obj->konto_bezeichnung.'</td>';
|
|
|
|
// Typ
|
|
print '<td>';
|
|
if ($obj->typ == 'einnahme') {
|
|
print '<span class="badge badge-status4">'.$langs->trans("Einnahme").'</span>';
|
|
} else {
|
|
print '<span class="badge badge-status1">'.$langs->trans("Ausgabe").'</span>';
|
|
}
|
|
print '</td>';
|
|
|
|
// Beträge
|
|
print '<td class="right nowraponall">'.price($obj->betrag_netto, 0, $langs, 1, 2, 2).'</td>';
|
|
print '<td class="right nowraponall">'.price($obj->betrag_ust, 0, $langs, 1, 2, 2).'</td>';
|
|
print '<td class="right nowraponall amount">'.price($obj->betrag_brutto, 0, $langs, 1, 2, 2).'</td>';
|
|
|
|
print '</tr>';
|
|
|
|
// Summen
|
|
if ($obj->typ == 'einnahme') {
|
|
$total_einnahmen += $obj->betrag_netto;
|
|
} else {
|
|
$total_ausgaben += $obj->betrag_netto;
|
|
}
|
|
}
|
|
|
|
// Summenzeile
|
|
print '<tr class="liste_total">';
|
|
print '<td colspan="6"><strong>'.$langs->trans("Total").'</strong></td>';
|
|
print '<td class="right nowraponall"><strong>'.price($total_einnahmen - $total_ausgaben, 0, $langs, 1, 2, 2).'</strong></td>';
|
|
print '<td></td>';
|
|
print '<td></td>';
|
|
print '</tr>';
|
|
|
|
print '</table>';
|
|
|
|
// Pagination
|
|
print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
|
|
|
|
} else {
|
|
dol_print_error($db);
|
|
}
|
|
|
|
print '</form>';
|
|
|
|
// Zusammenfassung
|
|
print '<br>';
|
|
print '<div class="div-table-responsive-no-min">';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th colspan="2">'.$langs->trans("Summary").' '.$jahr.'</th>';
|
|
print '</tr>';
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("TotalEinnahmen").'</td>';
|
|
print '<td class="right amount">'.price($total_einnahmen, 0, $langs, 1, 2, 2, 'EUR').'</td>';
|
|
print '</tr>';
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("TotalAusgaben").'</td>';
|
|
print '<td class="right amount">'.price($total_ausgaben, 0, $langs, 1, 2, 2, 'EUR').'</td>';
|
|
print '</tr>';
|
|
print '<tr class="liste_total">';
|
|
$gewinn = $total_einnahmen - $total_ausgaben;
|
|
$color = $gewinn >= 0 ? 'amountpaymentcomplete' : 'amountremaintopay';
|
|
print '<td><strong>'.($gewinn >= 0 ? $langs->trans("Gewinn") : $langs->trans("Verlust")).'</strong></td>';
|
|
print '<td class="right amount '.$color.'"><strong>'.price($gewinn, 0, $langs, 1, 2, 2, 'EUR').'</strong></td>';
|
|
print '</tr>';
|
|
print '</table>';
|
|
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();
|