improved new warehouse stuff
This commit is contained in:
@@ -310,29 +310,69 @@ $formattedValidUntil = $validUntilDate ? date("d.m.Y", $validUntilDate) : date("
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
// --- CALCULATION LOGIC ---
|
||||
|
||||
// Initialize discount variables
|
||||
$discountAmount = 0;
|
||||
$discountPercentage = 0;
|
||||
$subTotalAfterDiscount = $subTotal; // By default, the same as the original subtotal
|
||||
|
||||
// Check if a discount exists and calculate the new amounts
|
||||
if (isset($offer->totalDiscount) && $offer->totalDiscount > 0) {
|
||||
$discountPercentage = $offer->totalDiscount;
|
||||
// Calculate the monetary value of the discount
|
||||
$discountAmount = ($subTotal * $discountPercentage) / 100;
|
||||
// Calculate the subtotal after applying the discount
|
||||
$subTotalAfterDiscount = $subTotal - $discountAmount;
|
||||
}
|
||||
|
||||
// Recalculate VAT and Grand Total based on the potentially discounted subtotal
|
||||
if ($includeTax) {
|
||||
// $vatRate should be a float, e.g., 0.20 for 20%
|
||||
$vatAmount = $subTotalAfterDiscount * $vatRate;
|
||||
$grandTotal = $subTotalAfterDiscount + $vatAmount;
|
||||
} else {
|
||||
$vatAmount = 0; // Ensure VAT is zero if tax is not included
|
||||
$grandTotal = $subTotalAfterDiscount;
|
||||
}
|
||||
|
||||
// --- DISPLAY LOGIC ---
|
||||
?>
|
||||
<table id="summaryTable">
|
||||
<tbody>
|
||||
<tr class="subtotal">
|
||||
<td class="label"><?= $text['summary']['subTotal'] ?>:</td>
|
||||
<td class="value"><?= number_format($subTotal, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
<?php if ($includeTax):
|
||||
|
||||
<?php
|
||||
// Display the discount row only if a discount has been applied
|
||||
if ($discountAmount > 0):
|
||||
// Define a label for the discount. You can add 'discount' to your $text array.
|
||||
$discountLabel = $text['summary']['discount'] ?? 'Rabatt';
|
||||
?>
|
||||
<tr>
|
||||
<td class="label"><?= $discountLabel ?> (<?= number_format($discountPercentage, 0) ?>%):</td>
|
||||
<td class="value">-<?= number_format($discountAmount, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
// Display the VAT row if tax is included
|
||||
if ($includeTax):
|
||||
$vatLabel = str_replace('{VAT_RATE}', number_format($vatRate * 100, 0), $text['summary']['vatFormatted']);
|
||||
?>
|
||||
<tr>
|
||||
<td class="label"><?= $vatLabel ?>:</td>
|
||||
<td class="value"><?= number_format($vatAmount, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
<tr class="grand-total">
|
||||
<td class="label"><?= $text['summary']['total'] ?>:</td>
|
||||
<td class="value"><?= number_format($grandTotal, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
<?php else: // If tax not included, Total is same as Subtotal ?>
|
||||
<tr class="grand-total">
|
||||
<td class="label"><?= $text['summary']['total'] ?>:</td>
|
||||
<td class="value"><?= number_format($grandTotal, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr class="grand-total">
|
||||
<td class="label"><?= $text['summary']['total'] ?>:</td>
|
||||
<td class="value"><?= number_format($grandTotal, 2, ',', '.') ?> <?= $currencySymbol ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user