<?php

include '../includes/config.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $invoice_number = intval($_POST['invoice_number']);
    $sales_man = trim($_POST['sales_man']);

    $sql = "UPDATE `stock_sale` SET `sales_man` = :sales_man WHERE `invoice` = :invoice";

    try {
        $stmt = $conn->prepare($sql);

        $stmt->bindParam(':sales_man', $sales_man);
        $stmt->bindParam(':invoice', $invoice_number, PDO::PARAM_INT);

        if ($stmt->execute()) {
            echo "Salesman updated successfully.";
        } else {
            echo "Failed to update salesman.";
        }
    } catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
}
