trim($_POST['template_name'] ?? ''),
'customer_id' => (int)($_POST['customer_id'] ?? 0),
'interval_type' => $_POST['interval_type'] ?? 'monthly',
'start_date' => $_POST['start_date'] ?? date('Y-m-d'),
'end_date' => $_POST['end_date'] ?: null,
'next_due_date' => $_POST['next_due_date'] ?? date('Y-m-d'),
'vat_mode' => $settings['vat_mode'] ?? 'klein',
'vat_rate' => (float)($settings['default_vat_rate'] ?? 19.0),
'is_active' => !empty($_POST['is_active']),
'notes_internal' => $_POST['notes_internal'] ?? ''
];
// Validierung
if (empty($data['template_name'])) {
$error = 'Bitte einen Namen eingeben.';
} elseif ($data['customer_id'] <= 0) {
$error = 'Bitte einen Kunden auswählen.';
} else {
// Positionen sammeln
$newItems = [];
$count = isset($_POST['item_desc']) ? count($_POST['item_desc']) : 0;
for ($i = 0; $i < $count; $i++) {
$desc = trim($_POST['item_desc'][$i] ?? '');
$qty = (float)($_POST['item_qty'][$i] ?? 0);
$price = (float)($_POST['item_price'][$i] ?? 0);
if ($desc !== '' && $qty > 0) {
$newItems[] = [
'position_no' => count($newItems) + 1,
'description' => $desc,
'quantity' => $qty,
'unit_price' => $price
];
}
}
if (empty($newItems)) {
$error = 'Bitte mindestens eine Position ausfüllen.';
} else {
$template_id = save_recurring_template($id, $data);
save_recurring_template_items($template_id, $newItems);
header('Location: ' . url_for('recurring.php'));
exit;
}
}
}
?>
= $id ? 'Abo-Vorlage bearbeiten' : 'Neue Abo-Vorlage' ?>
= htmlspecialchars($error) ?>
Generierte Rechnungen
Noch keine Rechnungen generiert.
| Datum |
Fälligkeit |
Rechnungsnr. |
Betrag |
Aktion |
| = date('d.m.Y H:i', strtotime($entry['generated_at'])) ?> |
= date('d.m.Y', strtotime($entry['due_date'])) ?> |
= htmlspecialchars($entry['invoice_number'] ?? '-') ?> |
= $entry['total_gross'] ? number_format($entry['total_gross'], 2, ',', '.') . ' €' : '-' ?> |
PDF
|