diff --git a/Layout/default/WarehouseOffer/PDF_MAIN.php b/Layout/default/WarehouseOffer/PDF_MAIN.php index 478008f14..e61c3d58c 100644 --- a/Layout/default/WarehouseOffer/PDF_MAIN.php +++ b/Layout/default/WarehouseOffer/PDF_MAIN.php @@ -1,81 +1,63 @@ [position1, position2,...]] - * @var float $subTotal Calculated subtotal of all positions - * @var string $offerNumber Offer number - * @var int $offerDate Timestamp of offer creation - * @var int|null $validUntilDate Timestamp of offer validity end, or null - * @var bool $includeTax Whether to calculate and show VAT - * @var float $vatRate The VAT rate (e.g., 0.20 for 20%) - * @var string $offerText Additional text from the offer record - * - * // Bank details are also available but typically used in footer - * @var string $bank_iban - * @var string $bank_bic - * @var string $bank_bank - * @var string $bank_owner + * All variables are passed from WarehouseOfferController->createPDFAction */ -// Set filename for download (optional, can also be set in controller) -// $this->setReturnValue(['filename' => ($offerNumber ?? $offer->id) . "_Angebot.pdf"]); +// --- Helper Functions --- +function formatPrice($price, $currency = '€') { + return number_format($price, 2, ',', '.') . ' ' . $currency; +} -// --- Text Elements (Simple German Example - Extend for EN like in Order) --- +// --- Text Elements --- $texts = [ 'DE' => [ 'title' => 'Angebot', 'offerNumberLabel' => 'Angebotsnr.:', 'offerDateLabel' => 'Datum:', 'editorLabel' => 'Sachbearbeiter:', - 'usageLabel' => 'Zweck:', - 'customerReferenceLabel' => 'Kundenreferenz:', 'validUntilLabel' => 'Gültig bis:', - 'vatLabel' => 'USt-IdNr.:', - 'pageLabel' => 'Seite', // For page numbering in content if needed 'table' => [ 'pos' => 'Pos', 'article' => 'Artikel / Beschreibung', - // 'description' => 'Beschreibung', // Combined with Article 'amount' => 'Menge', 'unit' => 'Einheit', 'unitPrice' => 'Einzelpreis', 'totalPrice' => 'Gesamtpreis' ], - 'paymentTerms' => [ - 'net30' => 'Zahlungsbedingungen: 30 Tage netto', - 'net60' => 'Zahlungsbedingungen: 60 Tage netto', - 'immediate' => 'Zahlungsbedingungen: Sofort fällig' - ], 'summary' => [ 'subTotal' => 'Nettobetrag', - 'vatFormatted' => 'zzgl. {VAT_RATE}% MwSt.', // Placeholder for rate + 'discount' => 'Rabatt', + 'vatFormatted' => 'zzgl. {VAT_RATE}% MwSt.', 'total' => 'Gesamtbetrag', - 'currency' => '€' // Currency symbol + 'alternativeTotal' => 'Summe Alternativpositionen' ], - 'notes' => 'Anmerkungen:', + 'alternativeHeader' => 'Alternativpositionen', + 'notes' => 'Anmerkungen & Konditionen', 'defaultOfferText' => 'Vielen Dank für Ihre Anfrage. Es gelten unsere Allgemeinen Geschäftsbedingungen.', ] - // Add 'EN' => [...] section if needed ]; -// Simple language selection (default to DE) - enhance if customer language is known $lang = 'DE'; $text = $texts[$lang]; -$currencySymbol = $text['summary']['currency']; // --- Calculations --- -$vatAmount = 0; -$grandTotal = $subTotal; -if ($includeTax) { - $vatAmount = $subTotal * $vatRate; - $grandTotal = $subTotal + $vatAmount; +$discountAmount = 0; +$subTotalAfterDiscount = $subTotal; +if (isset($offer->totalDiscount) && $offer->totalDiscount > 0) { + $discountPercentage = $offer->totalDiscount; + $discountAmount = ($subTotal * $discountPercentage) / 100; + $subTotalAfterDiscount = $subTotal - $discountAmount; +} + +$vatAmount = 0; +$grandTotal = $subTotalAfterDiscount; +if ($includeTax) { + $vatAmount = $subTotalAfterDiscount * $vatRate; + $grandTotal = $subTotalAfterDiscount + $vatAmount; } -// Format dates $formattedOfferDate = date("d.m.Y", $offerDate); -$formattedValidUntil = $validUntilDate ? date("d.m.Y", $validUntilDate) : date("d.m.Y", strtotime("+14 days", $offerDate)); +$formattedValidUntil = date("d.m.Y", strtotime("+14 days", $offerDate)); ?> @@ -84,140 +66,41 @@ $formattedValidUntil = $validUntilDate ? date("d.m.Y", $validUntilDate) : date("
| = $text['summary']['subTotal'] ?>: | -= number_format($subTotal, 2, ',', '.') ?> = $currencySymbol ?> | -
= $text['notes'] ?>
-= $text['defaultOfferText'] // Add default closing text ?>
-= $text['paymentTerms'][$offer->paymentTerms] ?? $text['paymentTerms']['immediate'] ?>
-Lieferzeit: nach Vereinbarung.
-= nl2br(htmlspecialchars($offer->closingText ?? '')) ?>
+