File: /var/www/html/breadsecret.com/ssi_table.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('wp-load.php');
date_default_timezone_set("Asia/Hong_Kong");
global $wpdb, $current_site, $sitepress;
$result = $wpdb->get_results("SELECT * FROM stock_init Order By start_date DESC, sku ASC LIMIT 300");
?>
<div class="container" style='padding-left: 0px; padding-right: 0px'>
<div>
<table id='dataTable' class='stripe hover' style='width:100%'>
<thead>
<tr style='background-color:#333333; color:#ffffff;'>
<th>Sku</th>
<th>Name</th>
<th>Description</th>
<th>Start Date</th>
<th>End Date</th>
<th>Unavailable Weekdays</th>
<th>Unavailable Days after Holiday</th>
<th>Default Daily Stock Qty</th>
<th>In Stock Qty</th>
<th></th>
<th>Min. Prod. Qty</th>
<th>Oven Qty</th>
<th>Unit</th>
<th>Packing Qty</th>
<th>Packing Unit</th>
<th>Formula</th>
<th>Show in Home Page</th>
<th>Home Page Sort Seq.</th>
<th>Show in App</th>
<th>Show in Preparation List</th>
<!--<th>Cost/Price<br>Ratio</th>-->
<th>Ingredients</th>
<th>Suggested Ingredients Content from Recipe</th>
<th>Preparation Day</th>
<th>Status</th>
<!--<th>Remove<br>Sku</th>-->
<!-- <th>BOM</th>
<th>BOP</th> -->
</tr>
</thead>
<tbody>
<?php
$weekMap = array('', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
foreach($result as $row){
$view_url = "https://www.breadsecret.com/ssd/?id=".$row->id;
$product_id = 0;
if(has_slave_sku($row->sku)){
$skus = get_salve_sku($row->sku);
//$product_id = wc_get_product_id_by_sku($skuObj[0]->slave_sku);
foreach($skus as $skuObj){
$sku = $skuObj->slave_sku;
$id = wc_get_product_id_by_sku($sku);
if($product_id==0){
$product_id = $id;
}
}
} else {
$product_id = wc_get_product_id_by_sku($row->sku);
}
$productObject = wc_get_product( $product_id );
$zh_product_id = 0;
$trid = $sitepress->get_element_trid($product_id, 'post_product');
$translations = $sitepress->get_element_translations($trid, 'product');
foreach( $translations as $lang=>$translation){
if($translation->language_code == "zh-hant")
$zh_product_id = $translation->element_id;
}
$score = get_post_meta($product_id, '_lets_review_final_score_100', true);
$onoff = get_post_meta($product_id, '_lets_review_onoff', true);
if($onoff=="1"){
$checked = "checked";
} else {
$checked = "";
}
if($row->show_in_app=="Y"){
$showapp = "checked";
} else {
$showapp = "";
}
if($row->show_in_preparation_list=="Y"){
$showpreparationlist = "checked";
} else {
$showpreparationlist = "";
}
echo "<tr ";
if($productObject->get_status()!="publish") {
echo "style='background-color: #ddd;'";
}
echo ">";
echo "<td class='sku_column pointer' align='center' id='row_".$row->id."'>".$row->sku."</td>";
echo "<td class='pointer'>".$productObject->get_name()."</td>";
echo "<td class='pointer' id='row_".$row->id."'>".$row->description."</td>";
echo "<td align='center'>".($row->start_date=='0000-00-00'?'':$row->start_date)."</td>";
echo "<td align='center'>".($row->end_date=='0000-00-00'?'∞':$row->end_date)."</td>";
echo "<td>";
foreach(explode(",", $row->block_dayofweek) as $weekday){
echo $weekMap[$weekday];
echo "<br>";
}
echo "</td>";
$arr_block_days_after_holiday = explode(",", $row->block_date_from_holiday);
array_shift($arr_block_days_after_holiday);
echo "<td>";
foreach($arr_block_days_after_holiday as $days_after_holiday){
echo $days_after_holiday." day(s)";
echo "<br>";
}
echo "</td>";
echo "<td align='center'>".$row->limits." (".$row->packing_unit.")</td>";
$productResult = $wpdb->get_results("SELECT * FROM inventory_product WHERE sku_id = '".$row->id."' LIMIT 1");
$productObj = $productResult[0];
$unit_name = get_unit_name(1, $productObj->id);
if(empty($unit_name)){
$stock_qty = 0;
echo "<td align='center'>Incomplete Recipe</td>";
echo "<td align='center'></td>";
} else {
$stock_qty = $productObj->stock_qty;
echo "<td align='center'>".$stock_qty."</td>";
echo "<td align='center'>".$unit_name."</td>";
}
echo "<td align='center'>".$row->min_production_qty."</td>";
echo "<td align='center'>".$row->oven_qty."</td>";
echo "<td align='center'>".$row->display_unit."</td>";
echo "<td align='center'>".$row->unit_qty."</td>";
echo "<td align='center'>".$row->packing_unit."</td>";
echo "<td>".$row->custom_formula."</td>";
echo "<td align='center'>".$checked."</td>";
echo "<td align='center'>".$score."</td>";
echo "<td align='center'>".$showapp."</td>";
echo "<td align='center'>".$showpreparationlist."</td>";
/*
echo "<td align='center'>";
echo "<button id='btn-".$row->id."' type='button' class='btn btn-sm btn-outline-dark btnRemove'>X</button>";
echo "</td>";
*/
/*
$statistic = getProductPriceCostInfo($row->id);
echo "<td align='center'>";
echo $statistic['ratio'].($statistic['ratio']=="N/A"?"":"%");
echo "</td>";
*/
echo "<td>";
echo $row->ingredient;
echo "</td>";
echo "<td>";
echo getIngredientLabel(1, $productObj->id, $productObj->production_qty);
echo "</td>";
echo "<td>";
echo $row->preparation_day;
echo "</td>";
echo "<td>";
echo $productObject->get_status();
echo "</td>";
/*
echo "<td align='center'>";
echo "<button id='bom_".$row->id."' type='button' class='btn btn-sm ".$btnBOMClass." btnBOM'><i class='fas fa-clipboard-list'></i></button>";
echo "</td>";
echo "<td align='center'>";
echo "<button id='bop_".$row->id."' type='button' class='btn btn-sm ".$btnBOPClass." btnBOP'><i class='fas fa-clipboard-list'></i></button>";
echo "</td>";
*/
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>