<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'db_connection.php';

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["add_sale"])) {
    $invoice_number_sale = $_POST["invoice_number_sale"];
    $buyer = $_POST["buyer"];
    $sale_date = $_POST["sale_date"];
    $total_weight = $_POST["total_weight"];
    $sale_amount = $_POST["sale_amount"];
    $profit_percentage = $_POST["profit_percentage"];

    $sql_insert_sale = "INSERT INTO sales (invoice_number, buyer, sale_date, total_weight, sale_amount, profit_percentage)
                        VALUES ('$invoice_number_sale', '$buyer', '$sale_date', '$total_weight', '$sale_amount', '$profit_percentage')";

    if ($conn->query($sql_insert_sale) === TRUE) {
        echo "Данные успешно добавлены в таблицу продаж.";
    } else {
        echo "Ошибка: " . $sql_insert_sale . "<br>" . $conn->error;
    }
}

$conn->close();
header("Location: display_data.php");
exit();
?>
