diff --git a/admin/client_prices.php b/admin/client_prices.php index 6a3937c..db9a094 100644 --- a/admin/client_prices.php +++ b/admin/client_prices.php @@ -6,6 +6,8 @@ $pdo = db(); $message = ''; // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['client_id'], $_POST['product_id'])) { + $action = $_POST['form_action'] ?? 'add'; + $clientId = $_POST['client_id']; $productId = $_POST['product_id']; $priceNet = isset($_POST['price_net']) && is_numeric($_POST['price_net']) ? (float)$_POST['price_net'] : null; @@ -19,19 +21,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['client_id'], $_POST[' } if (!empty($clientId) && !empty($productId) && $priceNet !== null && $priceGross !== null) { - // Upsert logic - $stmt = $pdo->prepare("SELECT COUNT(*) FROM client_prices WHERE client_id = :client_id AND product_id = :product_id"); - $stmt->execute(['client_id' => $clientId, 'product_id' => $productId]); - $exists = $stmt->fetchColumn() > 0; - - if ($exists) { + if ($action === 'update') { $stmt = $pdo->prepare("UPDATE client_prices SET price_net = :price_net, price_gross = :price_gross WHERE client_id = :client_id AND product_id = :product_id"); $stmt->execute(['price_net' => $priceNet, 'price_gross' => $priceGross, 'client_id' => $clientId, 'product_id' => $productId]); $message = '