183 lines
7.4 KiB
PHP
183 lines
7.4 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Mehrwertsteuerrechner</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif; /* Arial als Standardschriftart */
|
|
background-color: #fff; /* Weißer Hintergrund */
|
|
color: #333;
|
|
line-height: 1.6;
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
.container {
|
|
max-width: 600px;
|
|
margin: 30px auto;
|
|
background: #fff;
|
|
padding: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
border: 1px solid #a81212; /* Akzentfarbe für den Rand */
|
|
}
|
|
h1 {
|
|
text-align: center;
|
|
color: #a81212; /* Akzentfarbe für Überschrift */
|
|
margin-bottom: 30px;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: bold;
|
|
}
|
|
input[type="text"],
|
|
select {
|
|
width: calc(100% - 22px);
|
|
padding: 10px;
|
|
border: 1px solid #a81212; /* Akzentfarbe für Input-Rand */
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
font-size: 16px;
|
|
}
|
|
input[type="submit"] {
|
|
background-color: #a81212; /* Akzentfarbe für Button */
|
|
color: white;
|
|
padding: 12px 20px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
width: 100%;
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
input[type="submit"]:hover {
|
|
background-color: #8f0e0e; /* Dunklere Akzentfarbe beim Hover */
|
|
}
|
|
.result {
|
|
background-color: #ffe5e5; /* Helles Rot für Erfolgsmeldung */
|
|
border: 1px solid #a81212; /* Akzentfarbe für Rand */
|
|
color: #a81212;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
margin-top: 20px;
|
|
font-size: 1.1em;
|
|
text-align: center;
|
|
}
|
|
.error {
|
|
background-color: #f8d7da; /* Standard Rot für Fehlermeldung */
|
|
border: 1px solid #f5c6cb;
|
|
color: #721c24;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
margin-top: 20px;
|
|
font-size: 1.1em;
|
|
text-align: center;
|
|
}
|
|
footer {
|
|
text-align: center;
|
|
margin-top: 40px;
|
|
font-size: 0.9em;
|
|
color: #777;
|
|
}
|
|
footer a {
|
|
color: #a81212; /* Akzentfarbe für Link im Footer */
|
|
text-decoration: none;
|
|
}
|
|
footer a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Mehrwertsteuerrechner</h1>
|
|
<form action="" method="post">
|
|
<div class="form-group">
|
|
<label for="netto_amount">Nettobetrag:</label>
|
|
<input type="text" id="netto_amount" name="netto_amount" value="<?php echo (!isset($_POST['calculate']) || !empty($errors)) ? (isset($_POST['netto_amount']) ? htmlspecialchars($_POST['netto_amount']) : '') : ''; ?>" placeholder="Optional">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="brutto_amount">Bruttobetrag:</label>
|
|
<input type="text" id="brutto_amount" name="brutto_amount" value="<?php echo (!isset($_POST['calculate']) || !empty($errors)) ? (isset($_POST['brutto_amount']) ? htmlspecialchars($_POST['brutto_amount']) : '') : ''; ?>" placeholder="Optional">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="vat_rate">Mehrwertsteuersatz:</label>
|
|
<select id="vat_rate" name="vat_rate">
|
|
<option value="19" <?php echo (isset($_POST['vat_rate']) && $_POST['vat_rate'] == 19) ? 'selected' : ''; ?>>19% (Regelsatz)</option>
|
|
<option value="7" <?php echo (isset($_POST['vat_rate']) && $_POST['vat_rate'] == 7) ? 'selected' : ''; ?>>7% (Ermäßigter Satz)</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="submit" name="calculate" value="Berechnen">
|
|
</div>
|
|
</form>
|
|
|
|
<?php
|
|
$errors = []; // Initialisiere $errors am Anfang, um es immer verfügbar zu haben
|
|
|
|
if (isset($_POST['calculate'])) {
|
|
$netto_amount_input = trim($_POST['netto_amount']);
|
|
$brutto_amount_input = trim($_POST['brutto_amount']);
|
|
$vat_rate = (float)$_POST['vat_rate'];
|
|
|
|
// Überprüfen, ob mindestens ein Betrag eingegeben wurde
|
|
if (empty($netto_amount_input) && empty($brutto_amount_input)) {
|
|
$errors[] = "Bitte geben Sie entweder einen Netto- oder einen Bruttobetrag ein.";
|
|
}
|
|
|
|
// Überprüfen, ob beide Beträge eingegeben wurden
|
|
if (!empty($netto_amount_input) && !empty($brutto_amount_input)) {
|
|
$errors[] = "Bitte geben Sie nur entweder einen Netto- oder einen Bruttobetrag ein, nicht beide.";
|
|
}
|
|
|
|
$netto_amount = null;
|
|
$brutto_amount = null;
|
|
$vat_amount = null;
|
|
|
|
if (empty($errors)) {
|
|
if (!empty($netto_amount_input)) {
|
|
if (is_numeric(str_replace(',', '.', $netto_amount_input))) {
|
|
$netto_amount = (float)str_replace(',', '.', $netto_amount_input);
|
|
$vat_amount = $netto_amount * ($vat_rate / 100);
|
|
$brutto_amount = $netto_amount + $vat_amount;
|
|
} else {
|
|
$errors[] = "Ungültiger Nettobetrag. Bitte geben Sie eine Zahl ein.";
|
|
}
|
|
} elseif (!empty($brutto_amount_input)) {
|
|
if (is_numeric(str_replace(',', '.', $brutto_amount_input))) {
|
|
$brutto_amount = (float)str_replace(',', '.', $brutto_amount_input);
|
|
$netto_amount = $brutto_amount / (1 + ($vat_rate / 100));
|
|
$vat_amount = $brutto_amount - $netto_amount;
|
|
} else {
|
|
$errors[] = "Ungültiger Bruttobetrag. Bitte geben Sie eine Zahl ein.";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($errors)) {
|
|
echo '<div class="error">';
|
|
foreach ($errors as $error) {
|
|
echo '<p>' . $error . '</p>';
|
|
}
|
|
echo '</div>';
|
|
} elseif ($netto_amount !== null && $brutto_amount !== null && $vat_amount !== null) {
|
|
echo '<div class="result">';
|
|
echo '<h2>Ergebnis:</h2>';
|
|
echo '<p>Nettobetrag: <strong>' . number_format($netto_amount, 2, ',', '.') . ' €</strong></p>';
|
|
echo '<p>Mehrwertsteuer (' . $vat_rate . '%): <strong>' . number_format($vat_amount, 2, ',', '.') . ' €</strong></p>';
|
|
echo '<p>Bruttobetrag: <strong>' . number_format($brutto_amount, 2, ',', '.') . ' €</strong></p>';
|
|
echo '</div>';
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
<footer>
|
|
© <?php echo date("Y"); ?> <a href="https://wachtel-it.de" target="_blank">Philipp Wachtel</a>
|
|
</footer>
|
|
</body>
|
|
</html>
|