diff --git a/admin/edit_client.php b/admin/edit_client.php index 688e511..9ab6b7d 100644 --- a/admin/edit_client.php +++ b/admin/edit_client.php @@ -116,6 +116,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $address = $_POST['address'] ?? ''; $city = $_POST['city'] ?? ''; $zip_code = $_POST['zip_code'] ?? ''; + $language = $_POST['language'] ?? 'pl'; if (empty($name)) { $errorMessage = 'Nazwa klienta jest wymagana.'; @@ -123,36 +124,39 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { if ($isNewClient) { $credit_limit = (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') ? ($_POST['credit_limit'] ?? 0) : 0; - $stmt = $db->prepare("INSERT INTO clients (name, nip, street, city, postal_code, credit_limit, credit_balance) VALUES (:name, :tax_id, :address, :city, :zip_code, :credit_limit, :credit_limit)"); + $stmt = $db->prepare("INSERT INTO clients (name, nip, street, city, postal_code, language, credit_limit, credit_balance) VALUES (:name, :tax_id, :address, :city, :zip_code, :language, :credit_limit, :credit_limit)"); $params = [ 'name' => $name, 'tax_id' => $tax_id, 'address' => $address, 'city' => $city, 'zip_code' => $zip_code, + 'language' => $language, 'credit_limit' => $credit_limit ]; } else { if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') { $credit_limit = $_POST['credit_limit'] ?? $client['credit_limit']; - $stmt = $db->prepare("UPDATE clients SET name = :name, nip = :tax_id, street = :address, city = :city, postal_code = :zip_code, credit_limit = :credit_limit WHERE id = :id"); + $stmt = $db->prepare("UPDATE clients SET name = :name, nip = :tax_id, street = :address, city = :city, postal_code = :zip_code, language = :language, credit_limit = :credit_limit WHERE id = :id"); $params = [ 'name' => $name, 'tax_id' => $tax_id, 'address' => $address, 'city' => $city, 'zip_code' => $zip_code, + 'language' => $language, 'credit_limit' => $credit_limit, 'id' => $clientId ]; } else { - $stmt = $db->prepare("UPDATE clients SET name = :name, nip = :tax_id, street = :address, city = :city, postal_code = :zip_code WHERE id = :id"); + $stmt = $db->prepare("UPDATE clients SET name = :name, nip = :tax_id, street = :address, city = :city, postal_code = :zip_code, language = :language WHERE id = :id"); $params = [ 'name' => $name, 'tax_id' => $tax_id, 'address' => $address, 'city' => $city, 'zip_code' => $zip_code, + 'language' => $language, 'id' => $clientId ]; } @@ -218,6 +222,13 @@ $page_title = $pageTitle; +
+ + +
diff --git a/cart.php b/cart.php index 11dbcab..8a1d0f3 100644 --- a/cart.php +++ b/cart.php @@ -22,6 +22,8 @@ if (!empty($cart)) { $stmt->execute($product_ids); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); + $lang = $_SESSION['lang'] ?? 'pl'; + foreach ($products as $product) { $quantity = $cart[$product['id']]; @@ -29,7 +31,7 @@ if (!empty($cart)) { $price_net = $price_info['net']; $price_gross = $price_info['gross']; - $line_total_gross = $price_gross * $quantity; + $line_total = ($lang === 'en') ? ($price_net * $quantity) : ($price_gross * $quantity); $cart_products[] = [ 'id' => $product['id'], @@ -37,10 +39,10 @@ if (!empty($cart)) { 'price_net' => $price_net, 'price_gross' => $price_gross, 'quantity' => $quantity, - 'line_total' => $line_total_gross, + 'line_total' => $line_total, ]; - $total_price += $line_total_gross; + $total_price += $line_total; } } catch (PDOException $e) { die(t('db_connection_error') . $e->getMessage()); @@ -102,7 +104,7 @@ $user_role = get_user_role(); - + diff --git a/checkout.php b/checkout.php index 3352739..795730e 100644 --- a/checkout.php +++ b/checkout.php @@ -31,7 +31,9 @@ if (!empty($cart)) { $stmt->execute($product_ids); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); + $lang = $_SESSION['lang'] ?? 'pl'; $is_supplier_delivery = false; + foreach ($products as $product) { $quantity = $cart[$product['id']]; @@ -39,7 +41,8 @@ if (!empty($cart)) { $price_net = $price_info['net']; $price_gross = $price_info['gross']; - $line_total = $price_gross * $quantity; + $line_total = ($lang === 'en') ? ($price_net * $quantity) : ($price_gross * $quantity); + $cart_products[] = [ 'id' => $product['id'], 'name' => $product['name'], @@ -87,7 +90,7 @@ require_once __DIR__ . '/includes/header.php'; - + @@ -103,7 +106,7 @@ require_once __DIR__ . '/includes/header.php'; - : + : diff --git a/debug_price.log b/debug_price.log index 5eed4b5..9e4a20b 100644 --- a/debug_price.log +++ b/debug_price.log @@ -15179,3 +15179,480 @@ Client price query executed. Found: {"price_net":"837.40","price_gross":"1030.00 Found client price. Net: 837.4, Gross: 1030 FINAL: Returning Net: 837.4, Gross: 1030 --- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 1, client 1 +Client price query executed. Found: {"price_net":"837.40","price_gross":"1030.00"} +Found client price. Net: 837.4, Gross: 1030 +FINAL: Returning Net: 837.4, Gross: 1030 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 1, client 1 +Client price query executed. Found: {"price_net":"837.40","price_gross":"1030.00"} +Found client price. Net: 837.4, Gross: 1030 +FINAL: Returning Net: 837.4, Gross: 1030 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 1, client 1 +Client price query executed. Found: {"price_net":"837.40","price_gross":"1030.00"} +Found client price. Net: 837.4, Gross: 1030 +FINAL: Returning Net: 837.4, Gross: 1030 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 1, client 1 +Client price query executed. Found: {"price_net":"837.40","price_gross":"1030.00"} +Found client price. Net: 837.4, Gross: 1030 +FINAL: Returning Net: 837.4, Gross: 1030 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 3, client 1 +Client price query executed. Found: {"price_net":"32.52","price_gross":"40.00"} +Found client price. Net: 32.52, Gross: 40 +FINAL: Returning Net: 32.52, Gross: 40 +--- +--- +START getEffectivePrice for product 4, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client 1 +Client price query executed. Found: No +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- +--- +START getEffectivePrice for product 2, client 1 +Client price query executed. Found: {"price_net":"1056.91","price_gross":"1300.00"} +Found client price. Net: 1056.91, Gross: 1300 +FINAL: Returning Net: 1056.91, Gross: 1300 +--- diff --git a/generate_order_pdf.php b/generate_order_pdf.php index dee5550..d0e329a 100644 --- a/generate_order_pdf.php +++ b/generate_order_pdf.php @@ -20,7 +20,7 @@ if (!is_logged_in()) { exit; } -$stmt = db()->prepare("SELECT o.*, c.name as client_name, c.email as client_email FROM orders o JOIN clients c ON o.client_id = c.id WHERE o.id = ?"); +$stmt = db()->prepare("SELECT o.*, c.name as client_name, c.email as client_email, c.language as client_language FROM orders o JOIN clients c ON o.client_id = c.id WHERE o.id = ?"); $stmt->execute([$order_id]); $order = $stmt->fetch(PDO::FETCH_ASSOC); @@ -128,8 +128,16 @@ $pdf->Ln($headerRowHeight); $pdf->SetFont('DejaVu', '', 12); $vatRate = 1.23; foreach ($order_items as $item) { - $unit_price_gross = (float)$item['unit_price']; - $unit_price_net = $unit_price_gross / $vatRate; + $client_language = $order['client_language']; + $vatRate = 1.23; + + if ($client_language === 'en') { + $unit_price_net = (float)$item['unit_price']; + $unit_price_gross = $unit_price_net * $vatRate; + } else { + $unit_price_gross = (float)$item['unit_price']; + $unit_price_net = $unit_price_gross / $vatRate; + } // --- Cell data --- $widths = [70, 30, 30, 30, 30]; diff --git a/includes/i18n.php b/includes/i18n.php index bb58bd3..8985131 100644 --- a/includes/i18n.php +++ b/includes/i18n.php @@ -120,6 +120,7 @@ $translations = [ 'update_button' => 'Zaktualizuj', 'remove_button' => 'Usuń', 'total_gross_label' => 'Razem (brutto):', + 'total_net_label' => 'Razem (netto):', 'proceed_to_checkout' => 'Przejdź do zamówienia', 'db_connection_error' => 'Błąd połączenia z bazą danych: ', 'price_per' => 'Cena za', @@ -326,6 +327,7 @@ $translations = [ 'update_button' => 'Update', 'remove_button' => 'Remove', 'total_gross_label' => 'Total (gross):', + 'total_net_label' => 'Total (net):', 'proceed_to_checkout' => 'Proceed to checkout', 'db_connection_error' => 'Database connection error: ', 'price_per' => 'Price per', diff --git a/order_process.php b/order_process.php index d9344c3..f6cda57 100644 --- a/order_process.php +++ b/order_process.php @@ -28,14 +28,14 @@ try { // 1. Get product details from the database $product_ids = array_keys($cart); $placeholders = implode(',', array_fill(0, count($product_ids), '?')); - $stmt = $pdo->prepare("SELECT id, price, units_per_pallet FROM products WHERE id IN ($placeholders)"); + $stmt = $pdo->prepare("SELECT id, price, units_per_pallet, name FROM products WHERE id IN ($placeholders)"); $stmt->execute($product_ids); $products_by_id = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_ASSOC); - // 2. Calculate total amount - $total_amount_gross = 0; + $total_amount = 0; $client_id = $_SESSION['client_id'] ?? null; + $lang = $_SESSION['lang'] ?? 'pl'; $order_items_data = []; @@ -45,15 +45,24 @@ try { $product = $products_by_id[$product_id]; $price_info = getEffectivePrice($pdo, $product_id, $client_id); + $price_net = $price_info['net']; $price_gross = $price_info['gross']; - $total_amount_gross += $price_gross * $quantity; + if ($lang === 'en') { + $unit_price = $price_net; + } else { + $unit_price = $price_gross; + } + + $line_total = $unit_price * $quantity; + $total_amount += $line_total; $order_items_data[] = [ 'product_id' => $product_id, 'quantity' => $quantity, - 'unit_price' => $price_gross, // Save gross price - 'line_total' => $price_gross * $quantity, + 'unit_price' => $unit_price, + 'line_total' => $line_total, + 'name' => $product['name'], ]; $units_per_pallet = $product['units_per_pallet']; @@ -72,11 +81,11 @@ try { $stmt->execute([$client_id]); $credit_info = $stmt->fetch(); - if (!$credit_info || !$credit_info['credit_enabled'] || $credit_info['credit_balance'] < $total_amount_gross) { + if (!$credit_info || !$credit_info['credit_enabled'] || $credit_info['credit_balance'] < $total_amount) { throw new Exception('Invalid payment method or insufficient credit.'); } - $new_balance = $credit_info['credit_balance'] - $total_amount_gross; + $new_balance = $credit_info['credit_balance'] - $total_amount; $stmt = $pdo->prepare('UPDATE clients SET credit_balance = ? WHERE id = ?'); $stmt->execute([$new_balance, $client_id]); } @@ -87,7 +96,7 @@ try { ); $stmt->execute([ $client_id, - $total_amount_gross, + $total_amount, $_POST['payment_method'], $delivery_source, $_POST['notes'], @@ -131,7 +140,7 @@ try { // Register transaction with P24 $p24_data = [ 'sessionId' => $p24_session_id, - 'amount' => (int)($total_amount_gross * 100), // Amount in grosze + 'amount' => (int)($total_amount * 100), // Amount in grosze 'description' => "Order #" . $order_id, 'email' => $client_email, 'client' => $client_name, @@ -162,16 +171,13 @@ try { } elseif (isset($response['error'])) { $error_message = $response['error']; } - redirect_with_error('checkout.php', 'Błąd podczas przetwarzania zamówienia: ' . $error_message); + redirect_with_error('checkout.php', 'Error processing order: ' . $error_message); } } $pdo->commit(); // 6. Send email notifications - - - // --- Data Fetching for Emails --- $user_id = $_SESSION['user_id'] ?? null; $stmt = $pdo->prepare('SELECT email FROM users WHERE id = ?'); $stmt->execute([$user_id]); @@ -183,27 +189,24 @@ try { $client = $stmt->fetch(); $client_company_name = $client['name'] ?? 'N/A'; - $product_ids_for_names = array_map(function($item) { return $item['product_id']; }, $order_items_data); - $placeholders = implode(',', array_fill(0, count($product_ids_for_names), '?')); - $stmt = $pdo->prepare("SELECT id, name FROM products WHERE id IN ($placeholders)"); - $stmt->execute($product_ids_for_names); - $products_by_id_for_email = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); - $order_details_link = get_site_url() . '/order_details.php?id=' . $order_id; $admin_order_details_link = get_site_url() . '/admin/order_details.php?id=' . $order_id; $admin_email = getenv('MAIL_TO') ?: 'admin@example.com'; - // --- Email Sending Logic --- - $site_name = get_site_url(); // Or your site name + $site_name = get_site_url(); $lang = get_lang(); + $products_by_id_for_email = []; + foreach($order_items_data as $item){ + $products_by_id_for_email[$item['product_id']] = $item['name']; + } + if ($client_email) { - // 1. Client - Order Confirmation $data_client = [ 'order_id' => $order_id, 'order_items' => $order_items_data, 'products' => $products_by_id_for_email, - 'total_amount_gross' => $total_amount_gross, + 'total_amount' => $total_amount, 'payment_method' => $_POST['payment_method'], 'order_details_link' => $order_details_link, 'site_name' => $site_name, @@ -211,22 +214,21 @@ try { ]; MailService::sendTemplatedMail($client_email, $lang, 'order_confirmation', $data_client); - // 3. Client - Payment Instructions (Bank Transfer) if ($_POST['payment_method'] === 'bank_transfer') { - // Fetch bank details from the settings table $stmt = $pdo->query("SELECT `key`, `value` FROM settings WHERE `key` IN ('bank_name', 'bank_account_number')"); $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); $bank_name = $settings['bank_name'] ?? ''; $bank_account_number = $settings['bank_account_number'] ?? ''; - $bank_account_details = "Bank: " . $bank_name . "\nAccount Number: " . $bank_account_number; + $bank_account_details = "Bank: " . $bank_name . " +Account Number: " . $bank_account_number; $transfer_title = "Order #{$order_id}"; $payment_deadline = date('Y-m-d', strtotime('+7 days')); $data_bank = [ 'order_id' => $order_id, - 'total_amount_gross' => $total_amount_gross, + 'total_amount' => $total_amount, 'bank_account_details' => $bank_account_details, 'transfer_title' => $transfer_title, 'payment_deadline' => $payment_deadline, @@ -236,11 +238,10 @@ try { MailService::sendTemplatedMail($client_email, $lang, 'payment_instructions', $data_bank); } - // 6. Client - Credit Payment Confirmation if ($_POST['payment_method'] === 'credit') { $data_credit = [ 'order_id' => $order_id, - 'total_amount_gross' => $total_amount_gross, + 'total_amount' => $total_amount, 'new_balance' => $new_balance, 'order_details_link' => $order_details_link, 'site_name' => $site_name, @@ -250,21 +251,25 @@ try { } } - // 2. Admin - New Order Notification $data_admin = [ 'order_id' => $order_id, 'client_company_name' => $client_company_name, - 'total_amount_gross' => $total_amount_gross, + 'total_amount' => $total_amount, 'payment_method' => $_POST['payment_method'], 'delivery_source' => $delivery_source, 'admin_order_details_link' => $admin_order_details_link, 'site_name' => $site_name, 'pdo' => $pdo, ]; - MailService::sendTemplatedMail($admin_email, 'en', 'admin_new_order', $data_admin); // Admin email in English + MailService::sendTemplatedMail($admin_email, 'en', 'admin_new_order', $data_admin); - // 7. Supplier - New Order Items - $stmt = $pdo->prepare("\n SELECT p.supplier_id, s.name as supplier_name, s.email as supplier_email, p.name as product_name, oi.quantity\n FROM order_items oi\n JOIN products p ON oi.product_id = p.id\n JOIN suppliers s ON p.supplier_id = s.id\n WHERE oi.order_id = ? AND p.supplier_id IS NOT NULL\n "); + $stmt = $pdo->prepare(" + SELECT p.supplier_id, s.name as supplier_name, s.email as supplier_email, p.name as product_name, oi.quantity + FROM order_items oi + JOIN products p ON oi.product_id = p.id + JOIN suppliers s ON p.supplier_id = s.id + WHERE oi.order_id = ? AND p.supplier_id IS NOT NULL + "); $stmt->execute([$order_id]); $supplier_items = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -288,16 +293,14 @@ try { 'site_name' => $site_name, 'pdo' => $pdo, ]; - MailService::sendTemplatedMail($supplier_data['email'], 'en', 'supplier_new_order_items', $data_supplier); // Supplier email in English + MailService::sendTemplatedMail($supplier_data['email'], 'en', 'supplier_new_order_items', $data_supplier); } } - // 8. Clear the cart and store order ID in session for the confirmation page unset($_SESSION['cart']); $_SESSION['latest_order_id'] = $order_id; - // 9. Redirect to confirmation page header('Location: order_confirmation.php'); exit; @@ -305,18 +308,18 @@ try { if ($pdo->inTransaction()) { $pdo->rollBack(); } - // In a real application, log this error - die("Błąd podczas przetwarzania zamówienia: " . $e->getMessage()); + error_log("Error in order_process.php: " . $e->getMessage()); + die("Error processing order. Please try again later."); } catch (PDOException $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } - // In a real application, log this error - die("Błąd podczas przetwarzania zamówienia: " . $e->getMessage()); + error_log("PDOError in order_process.php: " . $e->getMessage()); + die("Error processing order. Please try again later."); } catch (Throwable $t) { if ($pdo->inTransaction()) { $pdo->rollBack(); } - die("An unexpected error occurred: " . $t->getMessage()); -} - + error_log("Fatal error in order_process.php: " . $t->getMessage()); + die("An unexpected error occurred. Please try again later."); +} \ No newline at end of file diff --git a/templates/mail/en/admin_new_order.php b/templates/mail/en/admin_new_order.php index 5ebcaad..abaeb2c 100644 --- a/templates/mail/en/admin_new_order.php +++ b/templates/mail/en/admin_new_order.php @@ -4,7 +4,7 @@ /** * @var int $order_id * @var string $client_company_name - * @var float $total_amount_gross + * @var float $total_amount * @var string $payment_method * @var string $delivery_source * @var string $admin_order_details_link @@ -14,7 +14,7 @@

A new order has been placed.

Order ID:

Client:

-

Total Amount:

+

Total Amount:

Payment Method:

Delivery Source:

View order details:

\ No newline at end of file diff --git a/templates/mail/en/credit_payment_confirmation.php b/templates/mail/en/credit_payment_confirmation.php index ad6b049..25a37c3 100644 --- a/templates/mail/en/credit_payment_confirmation.php +++ b/templates/mail/en/credit_payment_confirmation.php @@ -3,13 +3,13 @@ /** * @var int $order_id - * @var float $total_amount_gross + * @var float $total_amount * @var float $new_balance * @var string $order_details_link */ ?>

Hello,

-

We confirm that your payment of for order # has been successfully processed using your trade credit.

+

We confirm that your payment of for order # has been successfully processed using your trade credit.

Your new credit balance is .

You can view your order details here:

\ No newline at end of file diff --git a/templates/mail/en/order_confirmation.php b/templates/mail/en/order_confirmation.php index fb5a482..236a460 100644 --- a/templates/mail/en/order_confirmation.php +++ b/templates/mail/en/order_confirmation.php @@ -4,7 +4,7 @@ /** * @var int $order_id * @var string $product_list_html - * @var float $total_amount_gross + * @var float $total_amount * @var string $payment_method * @var string $order_details_link */ @@ -18,7 +18,7 @@
  • (Quantity: )
  • -

    Total:

    +

    Total:

    Payment Method:

    You can view your order details here:

    Thank you for your business!

    \ No newline at end of file diff --git a/templates/mail/en/payment_instructions.php b/templates/mail/en/payment_instructions.php index 139f0b5..02c131d 100644 --- a/templates/mail/en/payment_instructions.php +++ b/templates/mail/en/payment_instructions.php @@ -3,7 +3,7 @@ /** * @var int $order_id - * @var float $total_amount_gross + * @var float $total_amount * @var string $bank_account_details * @var string $transfer_title * @var string $payment_deadline @@ -12,7 +12,7 @@

    Hello,

    Please use the following details to make a bank transfer for your order #.

    -

    Amount:

    +

    Amount:

    Bank Details:

    Transfer Title:

    diff --git a/templates/mail/pl/credit_payment_confirmation.php b/templates/mail/pl/credit_payment_confirmation.php index 7e310e8..7a03af0 100644 --- a/templates/mail/pl/credit_payment_confirmation.php +++ b/templates/mail/pl/credit_payment_confirmation.php @@ -3,13 +3,13 @@ /** * @var int $order_id - * @var float $total_amount_gross + * @var float $total_amount * @var float $new_balance * @var string $order_details_link */ ?>

    Dzień dobry,

    -

    Potwierdzamy, że Twoja płatność w wysokości za zamówienie # została pomyślnie przetworzona przy użyciu kredytu kupieckiego.

    +

    Potwierdzamy, że Twoja płatność w wysokości za zamówienie # została pomyślnie przetworzona przy użyciu kredytu kupieckiego.

    Twoje nowe saldo kredytowe wynosi .

    Możesz zobaczyć szczegóły zamówienia tutaj:

    \ No newline at end of file diff --git a/templates/mail/pl/order_confirmation.php b/templates/mail/pl/order_confirmation.php index 116706f..d23bc24 100644 --- a/templates/mail/pl/order_confirmation.php +++ b/templates/mail/pl/order_confirmation.php @@ -4,7 +4,7 @@ /** * @var int $order_id * @var string $product_list_html - * @var float $total_amount_gross + * @var float $total_amount * @var string $payment_method * @var string $order_details_link */ @@ -18,7 +18,7 @@
  • (Ilość: )
  • -

    Suma:

    +

    Suma:

    Metoda płatności:

    Możesz zobaczyć szczegóły zamówienia tutaj:

    Dziękujemy za zakupy!

    \ No newline at end of file diff --git a/templates/mail/pl/payment_instructions.php b/templates/mail/pl/payment_instructions.php index 73489b7..af1de8d 100644 --- a/templates/mail/pl/payment_instructions.php +++ b/templates/mail/pl/payment_instructions.php @@ -3,7 +3,7 @@ /** * @var int $order_id - * @var float $total_amount_gross + * @var float $total_amount * @var string $bank_account_details * @var string $transfer_title * @var string $payment_deadline @@ -12,7 +12,7 @@

    Dzień dobry,

    Proszę użyć poniższych danych do wykonania przelewu bankowego za zamówienie #.

    -

    Kwota:

    +

    Kwota:

    Dane bankowe:

    Tytuł przelewu: