417 lines
14 KiB
PHP
417 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* Buchung Eingabe/Bearbeitung
|
|
*
|
|
* @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/class/html.formother.class.php';
|
|
dol_include_once('/steuer/class/buchung.class.php');
|
|
|
|
$langs->loadLangs(array("steuer@steuer", "bills", "compta"));
|
|
|
|
$id = GETPOSTINT('id');
|
|
$ref = GETPOST('ref', 'alpha');
|
|
$action = GETPOST('action', 'aZ09');
|
|
$confirm = GETPOST('confirm', 'alpha');
|
|
$cancel = GETPOST('cancel', 'aZ09');
|
|
$backtopage = GETPOST('backtopage', 'alpha');
|
|
|
|
// Objekt initialisieren
|
|
$object = new SteuerBuchung($db);
|
|
|
|
// Laden, wenn ID oder Ref
|
|
if ($id > 0 || !empty($ref)) {
|
|
$object->fetch($id, $ref);
|
|
}
|
|
|
|
/*
|
|
* Actions
|
|
*/
|
|
|
|
if ($cancel) {
|
|
if (!empty($backtopage)) {
|
|
header("Location: ".$backtopage);
|
|
exit;
|
|
}
|
|
$action = '';
|
|
}
|
|
|
|
// Neue Buchung erstellen
|
|
if ($action == 'add' && !$cancel) {
|
|
$error = 0;
|
|
|
|
$object->datum = dol_mktime(0, 0, 0, GETPOSTINT('datummonth'), GETPOSTINT('datumday'), GETPOSTINT('datumyear'));
|
|
$object->belegnummer = GETPOST('belegnummer', 'alpha');
|
|
$object->beschreibung = GETPOST('beschreibung', 'alpha');
|
|
$object->fk_konto = GETPOSTINT('fk_konto');
|
|
$object->typ = GETPOST('typ', 'alpha');
|
|
$object->ust_satz = GETPOSTFLOAT('ust_satz');
|
|
$object->zahlungsart = GETPOST('zahlungsart', 'alpha');
|
|
$object->fk_soc = GETPOSTINT('fk_soc');
|
|
$object->note_private = GETPOST('note_private', 'restricthtml');
|
|
|
|
// Betrag berechnen
|
|
$betrag_eingabe = GETPOST('betrag_eingabe', 'alpha');
|
|
$betrag = price2num(GETPOST('betrag', 'alpha'));
|
|
|
|
if ($betrag_eingabe == 'brutto') {
|
|
$object->betrag_brutto = $betrag;
|
|
$object->betrag_netto = $betrag / (1 + $object->ust_satz / 100);
|
|
$object->betrag_ust = $object->betrag_brutto - $object->betrag_netto;
|
|
} else {
|
|
$object->betrag_netto = $betrag;
|
|
$object->betrag_ust = $betrag * $object->ust_satz / 100;
|
|
$object->betrag_brutto = $object->betrag_netto + $object->betrag_ust;
|
|
}
|
|
|
|
// Validierung
|
|
if (empty($object->datum)) {
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesaliases("Date")), null, 'errors');
|
|
$error++;
|
|
}
|
|
if (empty($object->beschreibung)) {
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesaliases("Description")), null, 'errors');
|
|
$error++;
|
|
}
|
|
if (empty($object->fk_konto)) {
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesaliases("Account")), null, 'errors');
|
|
$error++;
|
|
}
|
|
if ($betrag <= 0) {
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesaliases("Amount")), null, 'errors');
|
|
$error++;
|
|
}
|
|
|
|
if (!$error) {
|
|
$result = $object->create($user);
|
|
if ($result > 0) {
|
|
setEventMessages($langs->trans("BuchungCreated"), null, 'mesgs');
|
|
header("Location: ".dol_buildpath('/steuer/buchung_card.php', 1).'?id='.$result);
|
|
exit;
|
|
} else {
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
$action = 'create';
|
|
}
|
|
} else {
|
|
$action = 'create';
|
|
}
|
|
}
|
|
|
|
// Buchung aktualisieren
|
|
if ($action == 'update' && !$cancel) {
|
|
$error = 0;
|
|
|
|
$object->datum = dol_mktime(0, 0, 0, GETPOSTINT('datummonth'), GETPOSTINT('datumday'), GETPOSTINT('datumyear'));
|
|
$object->belegnummer = GETPOST('belegnummer', 'alpha');
|
|
$object->beschreibung = GETPOST('beschreibung', 'alpha');
|
|
$object->fk_konto = GETPOSTINT('fk_konto');
|
|
$object->typ = GETPOST('typ', 'alpha');
|
|
$object->ust_satz = GETPOSTFLOAT('ust_satz');
|
|
$object->zahlungsart = GETPOST('zahlungsart', 'alpha');
|
|
$object->fk_soc = GETPOSTINT('fk_soc');
|
|
$object->note_private = GETPOST('note_private', 'restricthtml');
|
|
|
|
// Betrag berechnen
|
|
$betrag_eingabe = GETPOST('betrag_eingabe', 'alpha');
|
|
$betrag = price2num(GETPOST('betrag', 'alpha'));
|
|
|
|
if ($betrag_eingabe == 'brutto') {
|
|
$object->betrag_brutto = $betrag;
|
|
$object->betrag_netto = $betrag / (1 + $object->ust_satz / 100);
|
|
$object->betrag_ust = $object->betrag_brutto - $object->betrag_netto;
|
|
} else {
|
|
$object->betrag_netto = $betrag;
|
|
$object->betrag_ust = $betrag * $object->ust_satz / 100;
|
|
$object->betrag_brutto = $object->betrag_netto + $object->betrag_ust;
|
|
}
|
|
|
|
if (!$error) {
|
|
$result = $object->update($user);
|
|
if ($result > 0) {
|
|
setEventMessages($langs->trans("BuchungUpdated"), null, 'mesgs');
|
|
header("Location: ".dol_buildpath('/steuer/buchung_card.php', 1).'?id='.$object->id);
|
|
exit;
|
|
} else {
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
$action = 'edit';
|
|
}
|
|
} else {
|
|
$action = 'edit';
|
|
}
|
|
}
|
|
|
|
// Löschen bestätigen
|
|
if ($action == 'confirm_delete' && $confirm == 'yes') {
|
|
$result = $object->delete($user);
|
|
if ($result > 0) {
|
|
setEventMessages($langs->trans("BuchungDeleted"), null, 'mesgs');
|
|
header("Location: ".dol_buildpath('/steuer/buchung_list.php', 1));
|
|
exit;
|
|
} else {
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
}
|
|
}
|
|
|
|
/*
|
|
* View
|
|
*/
|
|
|
|
$form = new Form($db);
|
|
|
|
$title = $langs->trans("Buchung");
|
|
if ($action == 'create') {
|
|
$title = $langs->trans("NeueBuchung");
|
|
}
|
|
|
|
llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-steuer page-buchung-card');
|
|
|
|
// Konten laden
|
|
$konten_einnahmen = SteuerBuchung::getKonten($db, 'einnahme');
|
|
$konten_ausgaben = SteuerBuchung::getKonten($db, 'ausgabe');
|
|
$konten_alle = SteuerBuchung::getKonten($db);
|
|
|
|
// USt-Sätze
|
|
$ust_saetze = array(
|
|
0 => '0% (steuerfrei)',
|
|
7 => '7% (ermäßigt)',
|
|
19 => '19% (Regelsteuersatz)'
|
|
);
|
|
|
|
// Zahlungsarten
|
|
$zahlungsarten = array(
|
|
'bank' => $langs->trans("Bank"),
|
|
'bar' => $langs->trans("Cash"),
|
|
'paypal' => 'PayPal',
|
|
'kreditkarte' => $langs->trans("CreditCard"),
|
|
'lastschrift' => $langs->trans("DirectDebit"),
|
|
'sonstige' => $langs->trans("Other")
|
|
);
|
|
|
|
// Buchungstypen
|
|
$typen = array(
|
|
'einnahme' => $langs->trans("Einnahme"),
|
|
'ausgabe' => $langs->trans("Ausgabe")
|
|
);
|
|
|
|
// Formular: Neue Buchung oder Bearbeiten
|
|
if ($action == 'create' || $action == 'edit') {
|
|
|
|
print load_fiche_titre($action == 'create' ? $langs->trans("NeueBuchung") : $langs->trans("EditBuchung"), '', 'steuer.png@steuer');
|
|
|
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="action" value="'.($action == 'create' ? 'add' : 'update').'">';
|
|
if ($action == 'edit') {
|
|
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
|
}
|
|
if ($backtopage) {
|
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
|
}
|
|
|
|
print dol_get_fiche_head(array(), '', '', 0, '');
|
|
|
|
print '<table class="border centpercent tableforfieldcreate">';
|
|
|
|
// Typ (Einnahme/Ausgabe)
|
|
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Typ").'</td><td>';
|
|
print $form->selectarray('typ', $typen, GETPOSTISSET('typ') ? GETPOST('typ') : $object->typ, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200');
|
|
print '</td></tr>';
|
|
|
|
// Datum
|
|
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
|
|
print $form->selectDate(GETPOSTISSET('datumday') ? dol_mktime(0, 0, 0, GETPOSTINT('datummonth'), GETPOSTINT('datumday'), GETPOSTINT('datumyear')) : ($object->datum ? $object->datum : dol_now()), 'datum', 0, 0, 0, '', 1, 1);
|
|
print '</td></tr>';
|
|
|
|
// Belegnummer
|
|
print '<tr><td>'.$langs->trans("Belegnummer").'</td><td>';
|
|
print '<input type="text" name="belegnummer" class="minwidth200" value="'.dol_escape_htmltag(GETPOSTISSET('belegnummer') ? GETPOST('belegnummer') : $object->belegnummer).'">';
|
|
print '</td></tr>';
|
|
|
|
// Beschreibung
|
|
print '<tr><td class="fieldrequired">'.$langs->trans("Description").'</td><td>';
|
|
print '<input type="text" name="beschreibung" class="minwidth400" value="'.dol_escape_htmltag(GETPOSTISSET('beschreibung') ? GETPOST('beschreibung') : $object->beschreibung).'">';
|
|
print '</td></tr>';
|
|
|
|
// Konto
|
|
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
|
|
print $form->selectarray('fk_konto', $konten_alle, GETPOSTISSET('fk_konto') ? GETPOSTINT('fk_konto') : $object->fk_konto, 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
|
|
print '</td></tr>';
|
|
|
|
// Betrag
|
|
print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td>';
|
|
$betrag_wert = GETPOSTISSET('betrag') ? GETPOST('betrag') : ($object->betrag_brutto > 0 ? $object->betrag_brutto : '');
|
|
print '<input type="text" name="betrag" class="minwidth100" value="'.dol_escape_htmltag($betrag_wert).'"> EUR ';
|
|
print '<select name="betrag_eingabe" class="flat">';
|
|
print '<option value="brutto"'.((GETPOST('betrag_eingabe') == 'brutto' || !GETPOSTISSET('betrag_eingabe')) ? ' selected' : '').'>'.$langs->trans("TTC").' (Brutto)</option>';
|
|
print '<option value="netto"'.(GETPOST('betrag_eingabe') == 'netto' ? ' selected' : '').'>'.$langs->trans("HT").' (Netto)</option>';
|
|
print '</select>';
|
|
print '</td></tr>';
|
|
|
|
// USt-Satz
|
|
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
|
|
print $form->selectarray('ust_satz', $ust_saetze, GETPOSTISSET('ust_satz') ? GETPOST('ust_satz') : ($object->ust_satz !== null ? (int)$object->ust_satz : 19), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200');
|
|
print '</td></tr>';
|
|
|
|
// Zahlungsart
|
|
print '<tr><td>'.$langs->trans("PaymentMode").'</td><td>';
|
|
print $form->selectarray('zahlungsart', $zahlungsarten, GETPOSTISSET('zahlungsart') ? GETPOST('zahlungsart') : $object->zahlungsart, 1, 0, 0, '', 0, 0, 0, '', 'minwidth200');
|
|
print '</td></tr>';
|
|
|
|
// Kunde/Lieferant
|
|
print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
|
|
print $form->select_company(GETPOSTISSET('fk_soc') ? GETPOSTINT('fk_soc') : $object->fk_soc, 'fk_soc', '', 1, 0, 0, array(), 0, 'minwidth300');
|
|
print '</td></tr>';
|
|
|
|
// Notiz
|
|
print '<tr><td>'.$langs->trans("Note").'</td><td>';
|
|
print '<textarea name="note_private" class="minwidth400" rows="3">'.dol_escape_htmltag(GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private).'</textarea>';
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
|
|
print dol_get_fiche_end();
|
|
|
|
print '<div class="center">';
|
|
print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
|
|
print ' ';
|
|
print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
} elseif ($object->id > 0) {
|
|
// Anzeige der Buchung
|
|
|
|
// Löschen bestätigen
|
|
if ($action == 'delete') {
|
|
print $form->formconfirm(
|
|
$_SERVER["PHP_SELF"].'?id='.$object->id,
|
|
$langs->trans("DeleteBuchung"),
|
|
$langs->trans("ConfirmDeleteBuchung"),
|
|
'confirm_delete',
|
|
'',
|
|
0,
|
|
1
|
|
);
|
|
}
|
|
|
|
print load_fiche_titre($langs->trans("Buchung").' '.$object->ref, '', 'steuer.png@steuer');
|
|
|
|
print dol_get_fiche_head(array(), '', '', 0, '');
|
|
|
|
print '<table class="border centpercent tableforfield">';
|
|
|
|
// Referenz
|
|
print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
|
|
print '<td>'.$object->ref.'</td></tr>';
|
|
|
|
// Typ
|
|
print '<tr><td>'.$langs->trans("Typ").'</td>';
|
|
print '<td>'.$typen[$object->typ].'</td></tr>';
|
|
|
|
// Datum
|
|
print '<tr><td>'.$langs->trans("Date").'</td>';
|
|
print '<td>'.dol_print_date($object->datum, 'day').'</td></tr>';
|
|
|
|
// Belegnummer
|
|
print '<tr><td>'.$langs->trans("Belegnummer").'</td>';
|
|
print '<td>'.$object->belegnummer.'</td></tr>';
|
|
|
|
// Beschreibung
|
|
print '<tr><td>'.$langs->trans("Description").'</td>';
|
|
print '<td>'.$object->beschreibung.'</td></tr>';
|
|
|
|
// Konto
|
|
print '<tr><td>'.$langs->trans("Account").'</td>';
|
|
print '<td>'.$object->konto_nummer.' - '.$object->konto_bezeichnung.'</td></tr>';
|
|
|
|
// Beträge
|
|
print '<tr><td>'.$langs->trans("AmountHT").' (Netto)</td>';
|
|
print '<td class="amount">'.price($object->betrag_netto, 0, $langs, 1, 2, 2, 'EUR').'</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans("VAT").' ('.(int)$object->ust_satz.'%)</td>';
|
|
print '<td class="amount">'.price($object->betrag_ust, 0, $langs, 1, 2, 2, 'EUR').'</td></tr>';
|
|
|
|
print '<tr><td>'.$langs->trans("AmountTTC").' (Brutto)</td>';
|
|
print '<td class="amount"><strong>'.price($object->betrag_brutto, 0, $langs, 1, 2, 2, 'EUR').'</strong></td></tr>';
|
|
|
|
// Zahlungsart
|
|
if ($object->zahlungsart) {
|
|
print '<tr><td>'.$langs->trans("PaymentMode").'</td>';
|
|
print '<td>'.(isset($zahlungsarten[$object->zahlungsart]) ? $zahlungsarten[$object->zahlungsart] : $object->zahlungsart).'</td></tr>';
|
|
}
|
|
|
|
// Kunde/Lieferant
|
|
if ($object->fk_soc > 0) {
|
|
$soc = new Societe($db);
|
|
$soc->fetch($object->fk_soc);
|
|
print '<tr><td>'.$langs->trans("ThirdParty").'</td>';
|
|
print '<td>'.$soc->getNomUrl(1).'</td></tr>';
|
|
}
|
|
|
|
// Notiz
|
|
if ($object->note_private) {
|
|
print '<tr><td>'.$langs->trans("Note").'</td>';
|
|
print '<td>'.nl2br($object->note_private).'</td></tr>';
|
|
}
|
|
|
|
// Erstellt am/von
|
|
print '<tr><td>'.$langs->trans("DateCreation").'</td>';
|
|
print '<td>'.dol_print_date($object->date_creation, 'dayhour').'</td></tr>';
|
|
|
|
print '</table>';
|
|
|
|
print dol_get_fiche_end();
|
|
|
|
// Aktionen
|
|
print '<div class="tabsAction">';
|
|
print '<a class="butAction" href="'.dol_buildpath('/steuer/buchung_list.php', 1).'"><i class="fa fa-arrow-left paddingright"></i>'.$langs->trans("Back").'</a>';
|
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>';
|
|
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
|
|
print '</div>';
|
|
|
|
} else {
|
|
// Keine Buchung gefunden
|
|
print $langs->trans("RecordNotFound");
|
|
print '<br><br>';
|
|
print '<div class="tabsAction">';
|
|
print '<a class="butAction" href="'.dol_buildpath('/steuer/buchung_list.php', 1).'"><i class="fa fa-arrow-left paddingright"></i>'.$langs->trans("Back").'</a>';
|
|
print '</div>';
|
|
}
|
|
|
|
llxFooter();
|
|
$db->close();
|