query(
'SELECT b.id, b.title, b.selling_price, b.printing_costs, b.isbn_print,
COALESCE(SUM(ba.margin_percent), 0) AS author_margin_percent
FROM books b
LEFT JOIN book_authors ba ON ba.book_id = b.id
WHERE b.isbn_print IS NOT NULL AND b.isbn_print <> ""
GROUP BY b.id
ORDER BY b.title'
)->fetchAll();
$selectedId = filter_var($_GET['book_id'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]) ?: null;
$useAuthorMargin = ($_GET['use_author_margin'] ?? '') === '1';
$discountInput = $_GET['discount_percent'] ?? (string) DEFAULT_AUTHOR_DISCOUNT_PERCENT;
$discountPercent = filter_var($discountInput, FILTER_VALIDATE_FLOAT);
$discountError = $discountPercent === false || $discountPercent < 0 || $discountPercent > 100;
if ($discountError) {
$discountPercent = DEFAULT_AUTHOR_DISCOUNT_PERCENT;
}
$discountRate = (float) $discountPercent / 100;
$retainedRate = 1 - $discountRate;
$selectedBook = null;
foreach ($books as $book) {
if ((int) $book['id'] === $selectedId) {
$selectedBook = $book;
break;
}
}
$calculation = null;
if ($selectedBook !== null) {
if ($useAuthorMargin) {
$discountPercent = (float) $selectedBook['author_margin_percent'];
$discountError = false;
}
$discountRate = (float) $discountPercent / 100;
$retainedRate = 1 - $discountRate;
$grossPrice = (float) $selectedBook['selling_price'];
$printingCosts = (float) $selectedBook['printing_costs'];
$netPrice = $grossPrice / (1 + AUTHOR_PRICE_VAT_RATE);
$revenueBeforeAuthorDiscount = $netPrice - $printingCosts;
$authorDiscount = $revenueBeforeAuthorDiscount * $discountRate;
$retainedRevenue = $revenueBeforeAuthorDiscount * $retainedRate;
$authorPriceNet = $printingCosts + $retainedRevenue;
$authorPriceVat = $authorPriceNet * AUTHOR_PRICE_VAT_RATE;
$authorPriceGross = $authorPriceNet + $authorPriceVat;
$saving = $grossPrice - $authorPriceGross;
$calculation = [
'gross_price' => $grossPrice,
'net_price' => $netPrice,
'printing_costs' => $printingCosts,
'revenue_before_author_discount' => $revenueBeforeAuthorDiscount,
'author_discount' => $authorDiscount,
'discount_percent' => (float) $discountPercent,
'retained_percent' => $retainedRate * 100,
'use_author_margin' => $useAuthorMargin,
'author_margin_percent' => (float) $selectedBook['author_margin_percent'],
'retained_revenue' => $retainedRevenue,
'author_price_net' => $authorPriceNet,
'author_price_vat' => $authorPriceVat,
'author_price_gross' => $authorPriceGross,
'saving' => $saving,
];
}
$token = csrf();
?>
Autorenpreis-Rechner
Autorenpreis: = e($selectedBook['title']) ?>
Berechnung pro Exemplar. Die Zwischenwerte werden ungerundet berechnet und erst für die Anzeige auf Cent gerundet.
| Regulärer Brutto-Preis | = authorPriceMoney($calculation['gross_price']) ?> |
| Regulärer Netto-Preis (Brutto ÷ 1,07) | = authorPriceMoney($calculation['net_price']) ?> |
| Abzüglich Druckkosten | = authorPriceMoney($calculation['printing_costs']) ?> |
| Erlös vor Autorenrabatt | = authorPriceMoney($calculation['revenue_before_author_discount']) ?> |
| Autorenrabatt = number_format($calculation['discount_percent'], 2, ',', '.') ?> %= $calculation['use_author_margin'] ? ' (kumulierte Autorenmarge)' : '' ?> | = authorPriceMoney($calculation['author_discount']) ?> |
| Verbleibender Erlösanteil = number_format($calculation['retained_percent'], 2, ',', '.') ?> % | = authorPriceMoney($calculation['retained_revenue']) ?> |
| Autorenpreis netto (Druckkosten + verbleibender Anteil) | = authorPriceMoney($calculation['author_price_net']) ?> |
| Mehrwertsteuer 7 % auf Autorenpreis | = authorPriceMoney($calculation['author_price_vat']) ?> |
| Autorenpreis brutto | = authorPriceMoney($calculation['author_price_gross']) ?> |
| Ersparnis pro Exemplar | = authorPriceMoney($calculation['saving']) ?> |
Das ausgewählte Buch ist nicht als Printbuch vorhanden.