<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Изменение закупки</title>
</head>
<body>

<?php
include 'db_connection.php';

if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["purchase_number"])) {
    $purchase_number = $_GET["purchase_number"];
    $sql_get_purchase = "SELECT * FROM purchases WHERE purchase_number = '$purchase_number'";
    $result_get_purchase = $conn->query($sql_get_purchase);

    if ($result_get_purchase->num_rows > 0) {
        $row = $result_get_purchase->fetch_assoc();
?>

    <h2>Изменение закупки</h2>

    <form method="post" action="update_purchase.php">
        <input type="hidden" name="purchase_number" value="<?php echo $row["purchase_number"]; ?>">
        
        <label for="purchase_date">Дата закупки:</label>
        <input type="date" name="purchase_date" value="<?php echo $row["purchase_date"]; ?>" required><br>

        <label for="client">Клиент:</label>
        <input type="text" name="client" value="<?php echo $row["client"]; ?>" required><br>

        <label for="amount">Сумма:</label>
        <input type="text" name="amount" value="<?php echo $row["amount"]; ?>" required><br>

        <label for="total_kilograms">Общий вес (кг):</label>
        <input type="text" name="total_kilograms" value="<?php echo $row["total_kilograms"]; ?>" required><br>

        <label for="invoice_number">Номер фактуры:</label>
        <input type="text" name="invoice_number" value="<?php echo $row["invoice_number"]; ?>" required><br>

        <input type="submit" name="update_purchase" value="Обновить">
    </form>

<?php
    } else {
        echo "<p>Закупка не найдена</p>";
    }
} else {
    echo "<p>Некорректные данные запроса</p>";
}

$conn->close();
?>

</body>
</html>
