options(MYSQLI_OPT_CONNECT_TIMEOUT, 4);
// Check connection
if ($conn->connect_error) {
$data = ['stock' => "Connection failed for $id $sku: " . $conn->connect_error];
echo json_encode( $data );
return;
}
if(!$custid)
{
$sql = "SELECT ps.item_number as SKU, stk.item_description as Description, FORMAT (stk.available_quantity, 0) as Stock, concat(\"$\", FORMAT (ps.price, 2)) as \"List Price\" FROM microlab_test.v_price_sheets as ps inner join microlab_test.v_item_sites as stk on ps.item_number = stk.item_number WHERE ps.price_sheet_name = \"Microlab T1\"";
}
else
{
$sql = "SELECT cp.item_number as SKU, stk.item_description as Description, FORMAT (stk.available_quantity, 0) as Stock, concat(\"$\", FORMAT (cp.price, 2)) as Price FROM microlab_test.v_customer_price_sheets as cp inner join microlab_test.v_item_sites as stk on cp.item_number = stk.item_number WHERE stk.site = \"Microlab/FXR\" AND cp.customer_number = $custid";
}
if ($result = $conn->query($sql))
{
$skuArray = "var skuArray = [";
$comma = "";
echo "
";
echo "
";
$fields = $result->fetch_fields();
foreach($fields as $field)
{
echo "