<?php
require_once("dbconn.php");
require_once("phpFunctions.php");

$headers = [
	"Author",
	"Last Update",
	"Effectivity Date", 
	"Customer Name",
	"Egg Tray Charge",
	"Shipping Charge",
	"Other Charges",
	"Remarks",
	"JMB",
	"XLR",
	"LRG",
	"MED",
	"SML",
	"PUL",
	"PWE",
	"SPW",
	"B1",
	"B2",
	"B3",
	"Dirty"
];

echo "<table id='MyTable_pldrsi' class='ui display hover' style='display: none;'>";
echo "<thead><tr>";
foreach ($headers as $index => $headerText) 
{
	echo "<th class='bg-light text-uppercase align-baseline'>{$headerText}</th>";
}
echo "</tr></thead><tbody>";

$result = executeQuery($conn, "SELECT * FROM pricelist WHERE is_deleted = FALSE AND is_current = TRUE ORDER BY pl_customer_name");

if ($result === false) { 
	throw new Exception("Error executing query: " . $conn->error);
} 

while ($row = mysqli_fetch_assoc($result)) 
{
    echo "<tr class='pl-clickable' data-id=" . $row["id"] . ">";
	echo "<td>" . $row["addedby_user"] . "</td>";
	echo "<td>" . $row["lastupdateby_user"] . "</td>";
	echo "<td>" . $row["pl_effectivity_date"] . "</td>";
	echo "<td>" . $row["pl_customer_name"] . "</td>";
	echo "<td>" . ($row["pl_eggtray_charge"] == 0 ? "" : "&#8369;" . number_format($row["pl_eggtray_charge"], 2)) . "</td>";
	echo "<td>" . ($row["pl_shipping_charge"] == 0 ? "" : "&#8369;" . number_format($row["pl_shipping_charge"], 2)) . "</td>";
	echo "<td>" . ($row["pl_other_charges"] == 0 ? "" : "&#8369;" . number_format($row["pl_other_charges"], 2)) . "</td>";
	echo "<td>" . ($row["pl_other_charges_remark"] == "NA" ? "" : $row["pl_other_charges_remark"]) . "</td>";
	echo "<td>" . ($row["pl_JMB"] === 0 ? "" : "&#8369;" . number_format($row["pl_JMB"], 2)) . "</td>";
	echo "<td>" . ($row["pl_XLR"] === 0 ? "" : "&#8369;" . number_format($row["pl_XLR"], 2)) . "</td>";
	echo "<td>" . ($row["pl_LRG"] === 0 ? "" : "&#8369;" . number_format($row["pl_LRG"], 2)) . "</td>";
	echo "<td>" . ($row["pl_MED"] === 0 ? "" : "&#8369;" . number_format($row["pl_MED"], 2)) . "</td>";
	echo "<td>" . ($row["pl_SML"] === 0 ? "" : "&#8369;" . number_format($row["pl_SML"], 2)) . "</td>";
	echo "<td>" . ($row["pl_PUL"] === 0 ? "" : "&#8369;" . number_format($row["pl_PUL"], 2)) . "</td>";
	echo "<td>" . ($row["pl_PWE"] === 0 ? "" : "&#8369;" . number_format($row["pl_PWE"], 2)) . "</td>";
	echo "<td>" . ($row["pl_SPW"] === 0 ? "" : "&#8369;" . number_format($row["pl_SPW"], 2)) . "</td>";
	echo "<td>" . ($row["pl_B1"] === 0 ? "" : "&#8369;" . number_format($row["pl_B1"], 2)) . "</td>";
	echo "<td>" . ($row["pl_B2"] === 0 ? "" : "&#8369;" . number_format($row["pl_B2"], 2)) . "</td>";
	echo "<td>" . ($row["pl_B3"] === 0 ? "" : "&#8369;" . number_format($row["pl_B3"], 2)) . "</td>";
	echo "<td>" . ($row["pl_Dirty"] === 0 ? "" : "&#8369;" . number_format($row["pl_Dirty"], 2)) . "</td>";
	echo "</tr>";
}
echo "</tbody></table>";
?>