<?php
include "database/database.php"; // Include your database connection
include "database/data.php"; // Include your database connection

// Update package_price
$sql = "UPDATE `$product` SET package_price = (buy * rate) + profit + trans";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
}

// Update unit_price
$sql = "UPDATE `$product` SET unit_price = IF(unit != 0, package_price / unit, 0)";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
}

// Update pieces_price with a check for division by zero
$sql = "UPDATE `$product` SET pieces_price = IF(pieces != 0, unit_price / pieces, 0)";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
}

// Update round_package_price to round to the nearest higher multiple of 100
$sql = "UPDATE `$product` SET round_package_price = CEIL(package_price / 100) * 100";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
    echo "Error in query: " . $connection->error . "<br>";
}

// Update round_unit_price to round to the nearest higher multiple of 100
$sql = "UPDATE `$product` SET round_unit_price = CEIL(unit_price / 100) * 100";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
    echo "Error in query: " . $connection->error . "<br>";
}

// Update round_pieces_price to round to the nearest higher multiple of 100
$sql = "UPDATE `$product` SET round_pieces_price = CEIL(pieces_price / 100) * 100";
if (!$connection->query($sql)) {
    error_log("Error updating $product_data: " . $connection->error);
    echo "Error in query: " . $connection->error . "<br>";
}
?>
