update
This commit is contained in:
@@ -50,7 +50,8 @@ final class ReceiptController
|
||||
$order = is_array($details['order'] ?? null) ? $details['order'] : [];
|
||||
$items = is_array($details['items'] ?? null) ? $details['items'] : [];
|
||||
|
||||
$totalGross = $this->receiptService->calculateTotalGross($items);
|
||||
$deliveryPrice = (float) ($order['delivery_price'] ?? 0);
|
||||
$totalGross = $this->receiptService->calculateTotalGross($items, $deliveryPrice);
|
||||
|
||||
$html = $this->template->render('orders/receipt-create', [
|
||||
'title' => $this->translator->get('receipts.create.title'),
|
||||
@@ -64,6 +65,7 @@ final class ReceiptController
|
||||
'configs' => array_values($configs),
|
||||
'seller' => $this->companySettings->getSettings(),
|
||||
'totalGross' => $totalGross,
|
||||
'deliveryPrice' => $deliveryPrice,
|
||||
'existingReceipts' => $existingReceipts,
|
||||
], 'layouts/app');
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ final class ReceiptService
|
||||
$orderReference = $this->resolveOrderReference($config, $order);
|
||||
$sellerSnapshot = $this->buildSellerSnapshot();
|
||||
$buyerSnapshot = $this->buildBuyerSnapshot($addresses);
|
||||
['items' => $itemsSnapshot, 'total_gross' => $totalGross] = $this->buildItemsSnapshot($items);
|
||||
['items' => $itemsSnapshot, 'total_gross' => $totalGross] = $this->buildItemsSnapshot($items, $order);
|
||||
|
||||
$receiptNumber = $this->receipts->getNextNumber(
|
||||
$configId,
|
||||
@@ -93,7 +93,7 @@ final class ReceiptService
|
||||
/**
|
||||
* @param list<array<string, mixed>> $items
|
||||
*/
|
||||
public function calculateTotalGross(array $items): float
|
||||
public function calculateTotalGross(array $items, float $deliveryPrice = 0.0): float
|
||||
{
|
||||
$total = 0.0;
|
||||
foreach ($items as $item) {
|
||||
@@ -101,6 +101,9 @@ final class ReceiptService
|
||||
$price = $item['original_price_with_tax'] !== null ? (float) $item['original_price_with_tax'] : 0.0;
|
||||
$total += $qty * $price;
|
||||
}
|
||||
if ($deliveryPrice > 0) {
|
||||
$total += $deliveryPrice;
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
@@ -246,9 +249,10 @@ final class ReceiptService
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $items
|
||||
* @param array<string, mixed> $order
|
||||
* @return array{items: list<array<string, mixed>>, total_gross: float}
|
||||
*/
|
||||
private function buildItemsSnapshot(array $items): array
|
||||
private function buildItemsSnapshot(array $items, array $order): array
|
||||
{
|
||||
$itemsSnapshot = [];
|
||||
$totalGross = 0.0;
|
||||
@@ -267,6 +271,19 @@ final class ReceiptService
|
||||
];
|
||||
}
|
||||
|
||||
$deliveryPrice = (float) ($order['delivery_price'] ?? 0);
|
||||
if ($deliveryPrice > 0) {
|
||||
$totalGross += $deliveryPrice;
|
||||
$itemsSnapshot[] = [
|
||||
'name' => 'Koszt wysylki',
|
||||
'quantity' => 1.0,
|
||||
'price' => $deliveryPrice,
|
||||
'total' => $deliveryPrice,
|
||||
'sku' => '',
|
||||
'ean' => '',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'items' => $itemsSnapshot,
|
||||
'total_gross' => $totalGross,
|
||||
|
||||
Reference in New Issue
Block a user