| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/clients/client2/arni-solutions.de/web/invoice/ |
Upload File : |
<?php
$config = require 'config.php';
$editInvoice = isset($_GET['edit']) ? $_GET['edit'] : null;
$editData = array();
if ($editInvoice && file_exists('invoices.txt')) {
$lines = file('invoices.txt', FILE_IGNORE_NEW_LINES);
$capture = false;
foreach ($lines as $line) {
if ($line === '### START ###') {
$capture = true;
$current = array();
continue;
}
if ($line === '### END ###') {
$capture = false;
if ((isset($current['invoice_number']) ? $current['invoice_number'] : '') === $editInvoice) {
$editData = $current;
break;
}
}
if ($capture) {
if (strpos($line, 'item:') === 0) {
$current['items'][] = explode('|', substr($line, 5));
} else {
$parts = explode(':', $line, 2);
$key = $parts[0];
$val = isset($parts[1]) ? $parts[1] : '';
$current[$key] = $val;
}
}
}
}
$counterFile = 'counter.txt';
if (!file_exists($counterFile)) file_put_contents($counterFile, '2025-0001');
$invoiceNumber = isset($editData['invoice_number']) ? $editData['invoice_number'] : trim(file_get_contents($counterFile));
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Rechnung erstellen</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container my-5">
<div class="card shadow">
<div class="card-body">
<h1 class="card-title mb-4">Rechnung erstellen</h1>
<form action="generate_invoice.php" method="post" target="_blank">
<div class="row">
<div class="col-2">
<label class="form-label">Rechnungsnummer</label>
<input type="text" class="form-control" name="invoice_number" value="<?php echo htmlspecialchars($invoiceNumber); ?>" required>
</div>
<div class="col-2">
<label class="form-label">Rechnungsdatum</label>
<input type="date" class="form-control" name="invoice_date" value="<?php echo htmlspecialchars(isset($editData['invoice_date']) ? $editData['invoice_date'] : date('Y-m-d')); ?>" required>
</div>
<div class="col-2">
<label class="form-label">Leistungsdatum</label>
<input type="date" class="form-control" name="delivery_date" value="<?php echo htmlspecialchars(isset($editData['delivery_date']) ? $editData['delivery_date'] : date('Y-m-d')); ?>" required>
</div>
<div class="col-6">
<label class="form-label">Empfänger</label>
<select name="recipient" class="form-select" required>
<?php foreach ($config['recipients'] as $name => $details): ?>
<option value="<?php echo htmlspecialchars($name); ?>" <?php echo (isset($editData['recipient']) && $editData['recipient'] === $name) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($name); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-12 mt-5">
<h5>Produkte</h5>
<div class="row mb-3 g-2">
<div class="col-md-9">
<select id="product_selector" class="form-select">
<?php foreach ($config['products'] as $name => $data): ?>
<option value="<?php echo htmlspecialchars($name); ?>"><?php echo htmlspecialchars($name); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<button type="button" class="btn btn-primary w-100" onclick="addSelectedProduct()">Produkt hinzufügen</button>
</div>
</div>
<div id="products" class="mb-4"></div>
<button type="submit" class="btn btn-success">PDF generieren</button>
</div>
</div>
</form>
</div>
</div>
</div>
<script>
const productData = <?php echo json_encode($config['products']); ?>;
function addSelectedProduct() {
const selector = document.getElementById("product_selector");
const selectedName = selector.value;
if (!selectedName || !productData[selectedName]) return;
const product = productData[selectedName];
addProductRow(selectedName, 1, product.price, product.description);
}
function addProductRow(name, quantity, price, description) {
const container = document.getElementById("products");
const row = document.createElement("div");
row.className = "row g-2 align-items-start mb-3 border-bottom pb-3";
// Optionen für Mengen-Select (1-99)
let quantityOptions = '';
for (let i = 1; i <= 99; i++) {
quantityOptions += `<option value="${i}" ${i == quantity ? 'selected' : ''}>${i}</option>`;
}
row.innerHTML = `
<div class="col-md-1">
<select name="product_quantity[]" class="form-select">${quantityOptions}</select>
</div>
<div class="col-md-9">
<input type="hidden" name="product_name[]" value="${name}">
<strong>${name}</strong><br>
<textarea name="product_description[]" class="form-control mt-1" rows="2">${description}</textarea>
</div>
<div class="col-md-1">
<input type="number" name="product_price[]" class="form-control" value="${price}" readonly>
</div>
<div class="col-md-1 text-end">
<button type="button" class="btn btn-outline-danger" onclick="this.closest('.row').remove()">✖</button>
</div>
`;
container.appendChild(row);
}
<?php if (!empty($editData['items'])): ?>
window.onload = function() {
<?php foreach ($editData['items'] as $item): ?>
addProductRow("<?php echo addslashes($item[0]); ?>", <?php echo (int)$item[1]; ?>, <?php echo (float)$item[2]; ?>, "<?php echo isset($item[3]) ? addslashes($item[3]) : ''; ?>");
<?php endforeach; ?>
};
<?php endif; ?>
</script>
</body>
</html>