getMessage(); } } $entry = null; if ($id) { $entry = get_journal_entry($id); if ($entry) { $year_id = $entry['year_id']; $month = $entry['month']; } } // POST: Speichern if ($_SERVER['REQUEST_METHOD'] === 'POST') { $year_id = (int)$_POST['year_id']; $save_and_new = isset($_POST['save_and_new']); $id_post = !empty($_POST['id']) ? (int)$_POST['id'] : null; $data = [ 'year_id' => $year_id, 'entry_date' => $_POST['entry_date'] ?? '', 'description' => $_POST['description'] ?? '', 'attachment_note' => $_POST['attachment_note'] ?? '', 'amount' => $_POST['amount'] ?? 0, 'supplier_id' => $_POST['supplier_id'] ?? null, 'sort_order' => $_POST['sort_order'] ?? 0, ]; if (!$data['entry_date'] || !$data['description']) { $error = 'Datum und Text sind Pflichtfelder.'; } else { // Kontenverteilung aus POST parsen $accounts = []; $acct_types = $_POST['acct_type'] ?? []; $acct_sides = $_POST['acct_side'] ?? []; $acct_amounts = $_POST['acct_amount'] ?? []; $acct_rev_ids = $_POST['acct_rev_id'] ?? []; $acct_exp_ids = $_POST['acct_exp_id'] ?? []; $acct_notes = $_POST['acct_note'] ?? []; for ($i = 0; $i < count($acct_types); $i++) { if (empty($acct_types[$i]) || (float)($acct_amounts[$i] ?? 0) == 0) continue; $accounts[] = [ 'account_type' => $acct_types[$i], 'side' => $acct_sides[$i] ?? 'soll', 'amount' => (float)($acct_amounts[$i] ?? 0), 'revenue_category_id' => !empty($acct_rev_ids[$i]) ? (int)$acct_rev_ids[$i] : null, 'expense_category_id' => !empty($acct_exp_ids[$i]) ? (int)$acct_exp_ids[$i] : null, 'note' => $acct_notes[$i] ?? '', ]; } if (empty($accounts)) { $error = 'Mindestens eine Kontenbuchung ist erforderlich.'; } else { try { $saved_id = save_journal_entry($id_post, $data, $accounts); if ($save_and_new) { $month = (int)date('n', strtotime($data['entry_date'])); header('Location: ' . url_for('journal_entry.php?year_id=' . $year_id . '&month=' . $month . '&msg=gespeichert')); exit; } else { header('Location: ' . url_for('journal.php?year_id=' . $year_id . '&month=' . (int)date('n', strtotime($data['entry_date'])))); exit; } } catch (\Exception $e) { $error = 'Fehler beim Speichern: ' . $e->getMessage(); } } } } if (isset($_GET['msg'])) { $msg = 'Buchung gespeichert.'; } // Daten laden $years = get_journal_years(); $account_options = get_journal_account_options(); // Wenn kein year_id, das erste offene Jahr nehmen if (!$year_id && $years) { foreach ($years as $y) { if (!$y['is_closed']) { $year_id = $y['id']; break; } } if (!$year_id) $year_id = $years[0]['id']; } $current_year = null; foreach ($years as $y) { if ($y['id'] == $year_id) { $current_year = $y; break; } } // Konto-Optionen als JSON für JavaScript $acct_options_json = json_encode($account_options); ?> Buchung <?= $entry ? 'bearbeiten' : 'erstellen' ?>

PIRP

Monatsansicht Jahressummen Suche

Bitte zuerst ein Jahr anlegen.

Automatisch erstellt aus Rechnungszahlung: Rechnung PDF Automatisch erstellt aus Ausgabe: Ausgabe bearbeiten

Kontenverteilung

Konto S/H Betrag Notiz
Abbrechen