Wersja ENG dla klienta

This commit is contained in:
Flatlogic Bot 2025-12-12 20:59:55 +00:00
parent 2a062c83f9
commit 389ad2c865
12 changed files with 1236 additions and 32 deletions

View File

@ -22,15 +22,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$new_rate = filter_input(INPUT_POST, 'pln_to_eur_rate', FILTER_VALIDATE_FLOAT);
if ($new_rate !== false && $new_rate > 0) {
$stmt = $db->prepare("UPDATE settings SET value = :value WHERE `key` = 'pln_to_eur_rate'");
$stmt = $db->prepare("INSERT INTO settings (`key`, value) VALUES ('pln_to_eur_rate', :value) ON DUPLICATE KEY UPDATE value = :value");
$stmt->execute([':value' => $new_rate]);
// Verify update, or insert if it failed (e.g., key didn't exist)
if ($stmt->rowCount() === 0) {
$insert_stmt = $db->prepare("INSERT INTO settings (`key`, value) VALUES ('pln_to_eur_rate', :value)");
$insert_stmt->execute([':value' => $new_rate]);
}
$rate = $new_rate;
$message = 'Kurs został zaktualizowany.';
} else {

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -76,8 +76,8 @@ $user_role = get_user_role();
<?php foreach ($cart_products as $item): ?>
<tr>
<td><?= htmlspecialchars($item['name']) ?></td>
<td><?= format_money($item['price_net'], $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($item['price_gross'], $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($item['price_net'], $_SESSION['lang'], $pdo) ?> <?= t('net') ?></td>
<td><?= format_money($item['price_gross'], $_SESSION['lang'], $pdo) ?> <?= t('gross') ?></td>
<td>
<form action="cart_actions.php" method="POST" class="d-inline-flex align-items-center">
<input type="hidden" name="action" value="update">

1194
debug_price.log Normal file

File diff suppressed because it is too large Load Diff

1
gemini_next_response.txt Normal file
View File

@ -0,0 +1 @@
I have fixed the pricing display issue on the product detail and order pages. Please check again.

View File

@ -77,16 +77,20 @@ function upload_error_message($error_code) {
}
function getEffectivePrice(PDO $db, int $productId, ?int $clientId): array {
$logFile = '/home/ubuntu/executor/workspace/debug_price.log';
$vatRate = 1.23;
$net = null;
$gross = null;
$priceFound = false;
file_put_contents($logFile, "---\nSTART getEffectivePrice for product $productId, client $clientId\n", FILE_APPEND);
// Priority A: Try to fetch from client_prices
if ($clientId) {
$stmt = $db->prepare("SELECT price_net, price_gross FROM client_prices WHERE client_id = :client_id AND product_id = :product_id LIMIT 1");
$stmt->execute(['client_id' => $clientId, 'product_id' => $productId]);
$priceRow = $stmt->fetch(PDO::FETCH_ASSOC);
file_put_contents($logFile, "Client price query executed. Found: " . ($priceRow ? json_encode($priceRow) : 'No') . "\n", FILE_APPEND);
if ($priceRow) {
$net = $priceRow['price_net'] !== null ? (float)$priceRow['price_net'] : null;
@ -94,39 +98,48 @@ function getEffectivePrice(PDO $db, int $productId, ?int $clientId): array {
if ($net !== null || $gross !== null) {
$priceFound = true;
file_put_contents($logFile, "Found client price. Net: $net, Gross: $gross\n", FILE_APPEND);
}
}
}
// Priority B: Fallback to product base prices if no client-specific price was found
if (!$priceFound) {
file_put_contents($logFile, "Client price not found or not set, falling back to product price.\n", FILE_APPEND);
$stmt = $db->prepare("SELECT price_net, price_gross FROM products WHERE id = :product_id");
$stmt->execute(['product_id' => $productId]);
$priceRow = $stmt->fetch(PDO::FETCH_ASSOC);
file_put_contents($logFile, "Product price query executed. Found: " . ($priceRow ? json_encode($priceRow) : 'No') . "\n", FILE_APPEND);
if ($priceRow) {
$net = $priceRow['price_net'] !== null ? (float)$priceRow['price_net'] : null;
$gross = $priceRow['price_gross'] !== null ? (float)$priceRow['price_gross'] : null;
file_put_contents($logFile, "Found product price. Net: $net, Gross: $gross\n", FILE_APPEND);
}
}
// If we have one price, calculate the other
if ($gross !== null && $net === null) {
$net = round($gross / $vatRate, 2);
file_put_contents($logFile, "Calculated net from gross. New net: $net\n", FILE_APPEND);
} elseif ($net !== null && $gross === null) {
$gross = round($net * $vatRate, 2);
file_put_contents($logFile, "Calculated gross from net. New gross: $gross\n", FILE_APPEND);
}
// Sanity check: gross must not be less than net. If so, log it and fix it.
if ($gross !== null && $net !== null && $gross < $net) {
error_log("Price inconsistency for product ID $productId: gross ($gross) is less than net ($net). Recalculating net from gross.");
$net = round($gross / $vatRate, 2);
file_put_contents($logFile, "Price inconsistency fixed. New net: $net\n", FILE_APPEND);
}
// Final check for nulls before returning
if ($net === null || $gross === null) {
file_put_contents($logFile, "FINAL: Net or Gross is null. Returning 0.0 for both.\n---\n", FILE_APPEND);
return ['net' => 0.0, 'gross' => 0.0];
}
file_put_contents($logFile, "FINAL: Returning Net: $net, Gross: $gross\n---\n", FILE_APPEND);
return ['net' => $net, 'gross' => $gross];
}

View File

@ -202,15 +202,15 @@ $translations = [
'cart_header' => 'Cart',
'product' => 'Product',
'quantity' => 'Quantity',
'total_price_net' => 'Total price excl. VAT',
'total_price_gross' => 'Total price incl. VAT',
'total_price_net' => 'Total price net',
'total_price_gross' => 'Total price gross',
'empty_cart_message' => 'Your cart is empty.',
'update_quantity_button' => 'Update',
'remove_from_cart_button' => 'Remove',
'checkout_button' => 'Checkout',
'cart_total_header' => 'Cart summary',
'total_net' => 'Total excl. VAT',
'total_gross' => 'Total incl. VAT',
'total_net' => 'Total net',
'total_gross' => 'Total gross',
'checkout_header' => 'Checkout',
'delivery_address_header' => 'Delivery address',
'name' => 'Full name',
@ -314,8 +314,8 @@ $translations = [
'notes' => 'Notes',
'order_details' => 'Order details',
'image' => 'Image',
'unit_price_net' => 'Unit price excl. VAT',
'unit_price_gross' => 'Unit price incl. VAT',
'unit_price_net' => 'Unit price net',
'unit_price_gross' => 'Unit price gross',
'back_to_product_list' => 'Back to product list',
'product_thumbnail_alt' => 'Product thumbnail',
'quantity_label' => 'Quantity',
@ -382,4 +382,4 @@ function t_status($key) {
$translation_key = 'status_' . $key;
}
return t($translation_key);
}
}

View File

@ -56,7 +56,8 @@ try {
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
<?php foreach ($main_products as $product):
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id']);
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id'] ?? null);
if (isset($prices['net'])) {
$image_url = !empty($product['image_path'])
? 'uploads/products/' . htmlspecialchars($product['image_path'])
: 'https://placehold.co/600x400/EEE/31343C?text=' . t('no_image_placeholder');
@ -77,8 +78,8 @@ try {
echo htmlspecialchars(strlen($desc) > 100 ? substr($desc, 0, 100) . '...' : $desc);
?></p>
<div class="mt-auto">
<p class="card-text text-muted small mb-0"><?= format_money($prices['net'], $_SESSION['lang'], $pdo) ?> <?= t('net') ?></p>
<p class="card-text fw-bold fs-5"><?= format_money($prices['gross'], $_SESSION['lang'], $pdo) ?> <?= t('gross') ?></p>
<p class="card-text text-muted small mb-0"><?= format_money($prices['net'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <?= t('net') ?></p>
<p class="card-text fw-bold fs-5"><?= format_money($prices['gross'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <?= t('gross') ?></p>
</div>
</div>
<div class="card-footer bg-white border-top-0 pb-3">
@ -96,7 +97,7 @@ try {
</div>
</div>
</div>
<?php endforeach; ?>
<?php } endforeach; ?>
</div>
<?php if (!empty($accessories)): ?>
@ -104,7 +105,8 @@ try {
<h2 class="mb-4"><?= t('accessories_and_complementary_products') ?></h2>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-4 row-cols-lg-5 g-4">
<?php foreach ($accessories as $product):
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id']);
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id'] ?? null);
if (isset($prices['net'])) {
$image_url = !empty($product['image_path'])
? 'uploads/products/' . htmlspecialchars($product['image_path'])
: 'https://placehold.co/600x400/EEE/31343C?text=' . t('no_image_placeholder');
@ -121,8 +123,8 @@ try {
</a>
</h6>
<div class="mt-auto">
<p class="card-text text-muted small mb-0"><?= format_money($prices['net'], $_SESSION['lang'], $pdo) ?> <?= t('net') ?></p>
<p class="card-text fw-bold"><?= format_money($prices['gross'], $_SESSION['lang'], $pdo) ?> <?= t('gross') ?></p>
<p class="card-text text-muted small mb-0"><?= format_money($prices['net'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <?= t('net') ?></p>
<p class="card-text fw-bold"><?= format_money($prices['gross'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <?= t('gross') ?></p>
</div>
</div>
<div class="card-footer bg-white border-top-0 pb-3">
@ -140,7 +142,7 @@ try {
</div>
</div>
</div>
<?php endforeach; ?>
<?php } endforeach; ?>
</div>
<?php endif; ?>

View File

@ -81,7 +81,7 @@ require_once __DIR__ . '/includes/currency.php';
<p><strong><?= t('order_date') ?>:</strong> <?= date('d.m.Y H:i', strtotime($order['created_at'])) ?></p>
<p><strong><?= t('status') ?>:</strong> <span class="badge bg-info"><?= htmlspecialchars(t_status($order['status'])) ?></span></p>
<p><strong><?= t('payment_method') ?>:</strong> <?= htmlspecialchars(t_status($order['payment_method'])) ?></p>
<p><strong><?= t('total_gross') ?>:</strong> <?= format_money($order['total_amount'], $_SESSION['lang'], $pdo) ?></p>
<p><strong><?= t('total_gross') ?>:</strong> <?= format_money($order['total_amount'], $_SESSION['lang'] ?? 'pl', $pdo) ?></p>
<p><strong><?= t('notes') ?>:</strong> <?= nl2br(htmlspecialchars($order['notes'])) ?></p>
</div>
</div>
@ -111,10 +111,10 @@ require_once __DIR__ . '/includes/currency.php';
<tr>
<td><img src="<?= htmlspecialchars($image_url) ?>" alt="<?= htmlspecialchars($item['product_name']) ?>" style="width: 50px; height: 50px; object-fit: cover;"></td>
<td><?= htmlspecialchars($item['product_name']) ?></td>
<td><?= format_money($unit_price_net, $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($unit_price_gross, $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($unit_price_net, $_SESSION['lang'] ?? 'pl', $pdo) ?></td>
<td><?= format_money($unit_price_gross, $_SESSION['lang'] ?? 'pl', $pdo) ?></td>
<td><?= $item['quantity'] ?></td>
<td><?= format_money($item['line_total'], $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($item['line_total'], $_SESSION['lang'] ?? 'pl', $pdo) ?></td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -56,7 +56,7 @@ require_once 'includes/html_head.php';
<td>#<?= $order['id']; ?></td>
<td><?= date('d.m.Y H:i', strtotime($order['created_at'])); ?></td>
<td><span class="badge bg-info"><?= htmlspecialchars(t_status($order['status'])); ?></span></td>
<td><?= format_money($order['total_amount'], $_SESSION['lang'], $pdo) ?></td>
<td><?= format_money($order['total_amount'], $_SESSION['lang'] ?? 'pl', $pdo) ?></td>
<td>
<a href="order_details.php?id=<?= $order['id']; ?>" class="btn btn-sm btn-outline-primary">
<i class="bi bi-eye"></i> <?= t('btn_view_details') ?>

View File

@ -29,7 +29,7 @@ try {
}
// Get the correct price pair using the centralized function
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id']);
$prices = getEffectivePrice($pdo, $product['id'], $_SESSION['client_id'] ?? null);
// Fetch product images
$img_stmt = $pdo->prepare("SELECT * FROM product_images WHERE product_id = ? ORDER BY is_primary DESC, id ASC");
@ -92,8 +92,8 @@ $page_title = htmlspecialchars($product['name']);
<h1 class="mb-3"><?= htmlspecialchars($product['name']) ?></h1>
<div class="bg-light p-4 rounded mb-4">
<p class="h4 fw-bold mb-1"><?= format_money($prices['gross'], $_SESSION['lang'], $pdo) ?> <span class="fs-6 fw-normal"><?= t('gross') ?></span></p>
<p class="text-muted mb-0"><?= format_money($prices['net'], $_SESSION['lang'], $pdo) ?> <span class="fs-6 fw-normal"><?= t('net') ?></span></p>
<p class="h4 fw-bold mb-1"><?= format_money($prices['gross'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <span class="fs-6 fw-normal"><?= t('gross') ?></span></p>
<p class="text-muted mb-0"><?= format_money($prices['net'], $_SESSION['lang'] ?? 'pl', $pdo) ?> <span class="fs-6 fw-normal"><?= t('net') ?></span></p>
<hr class="my-2">
<small class="text-muted"><?= t('price_per') ?>: <?= t(htmlspecialchars($product['unit'])) ?></small>
</div>