File: /var/www/html/breadsecret.com_bak20260330/prints.php
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
require_once('wp-load.php');
session_start();
date_default_timezone_set("Asia/Hong_Kong");
global $wpdb, $sitepress;
$arr_data = array();
$arr_data['input']=$_POST;
$weekarray=array("日","一","二","三","四","五","六");
// set production summary data
foreach($arr_data['input']['desc'] as $idx=>$product_name){
if($arr_data['input']['qty'][$idx]>0){
$arr_data['output']['summary'][]=array("name"=>$product_name,"unit_qty"=>$arr_data['input']['unit_qty'][$idx],"qty"=>$arr_data['input']['qty'][$idx]);
}
}
$arr_temp_data = array();
foreach($arr_data['input']['qty'] as $qty_idx=>$qty){
$skuObj = get_sku_init_info_by_id($arr_data['input']['sku_id'][$qty_idx]);
if(!empty($qty) && $skuObj->show_in_preparation_list=="Y"){
$temp_data = getIngredientDataArrayNew(1,$arr_data['input']['product_id'][$qty_idx],$qty);
if(!isset($temp_data['extra'])){
$arr_temp_data[] = $temp_data;
} else {
$temp_data_copy = $temp_data;
unset($temp_data['extra']);
$arr_temp_data[] = $temp_data;
foreach($temp_data_copy['extra'] as $extra_product_first_level) { // 1st level
if(!isset($extra_product_first_level['extra'])){
$arr_temp_data[] = $extra_product_first_level;
} else {
$extra_product_first_level_copy = $extra_product_first_level;
unset($extra_product_first_level['extra']);
$arr_temp_data[] = $extra_product_first_level;
foreach($extra_product_first_level_copy['extra'] as $extra_product_second_level) { // 2nd level
if(!isset($extra_product_second_level['extra'])){
$arr_temp_data[] = $extra_product_second_level;
} else {
$extra_product_second_level_copy = $extra_product_second_level;
unset($extra_product_second_level['extra']);
$arr_temp_data[] = $extra_product_second_level;
foreach($extra_product_second_level_copy['extra'] as $extra_product_third_level) { // 3rd level
if(!isset($extra_product_third_level['extra'])){
$arr_temp_data[] = $extra_product_third_level;
} else {
$extra_product_third_level_copy = $extra_product_third_level;
unset($extra_product_third_level['extra']);
$arr_temp_data[] = $extra_product_third_level;
foreach($extra_product_third_level_copy['extra'] as $extra_product_forth_level) { // 4th level
if(!isset($extra_product_forth_level['extra'])){
$arr_temp_data[] = $extra_product_forth_level;
} else {
$extra_product_forth_level_copy = $extra_product_forth_level;
unset($extra_product_forth_level['extra']);
$arr_temp_data[] = $extra_product_forth_level;
}
} // end 4th level
}
} // end 3rd level
}
} // end 2nd level
}
} // end first level
}
}
}
// sum up qty of the same sfproduct item
$resultArr = array();
foreach($arr_temp_data as $dataArr) {
$key = array_search($dataArr['product_name'], array_column($resultArr, 'product_name'));
if($key!==false){
$resultArr[$key]['product_qty'] += $dataArr['product_qty'];
foreach($resultArr[$key]['items'] as $idx=>$lineItem){
$resultArr[$key]['items'][$idx]['product_qty'] += $dataArr['items'][$idx]['product_qty'];
}
} else {
$resultArr[] = $dataArr;
}
}
// 分類
foreach($resultArr as $result_idx=>$itemData){
if($itemData['component_type_id']==1) {
$arr_data['output']['recipe'][] = $itemData;
} elseif($itemData['component_type_id']==2) {
$arr_data['output']['sfproduct'][] = $itemData;
}
}
// sorting (sf product)
usort($arr_data['output']['sfproduct'],function($a,$b){
return $a['group'] <=> $b['group']
?: $a['product_name'] <=> $b['product_name'];
});
// sorting (recipe)
usort($arr_data['output']['recipe'],function($a,$b){
return $a['group'] <=> $b['group']
?: $a['product_name'] <=> $b['product_name'];
});
echo "<pre>";
// print_r($arr_data['output']['sfproduct']);
echo "</pre>";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo "<fieldset style='width:500px'>";
echo "<h3>生產總結 ".date('j/n',strtotime($arr_data['input']['delivery_date']))." (".$weekarray[date("w", strtotime($arr_data['input']['delivery_date']))].")</h3>";
echo drawSummaryTable($arr_data['output']['summary']);
echo "<div style='height:1in;'></div>";
echo "</fieldset>";
echo "<br><br><hr><br><br>";
echo "<fieldset style='width:500px'>";
echo "<h3>半成品 ".date('j/n',strtotime($arr_data['input']['delivery_date']))." (".$weekarray[date("w", strtotime($arr_data['input']['delivery_date']))].")</h3>";
$lastGroup = "";
foreach($arr_data['output']['sfproduct'] as $idx=>$itemData){
if($itemData['visible']==1) {
if($lastGroup!="" && $itemData['group']!=$lastGroup){
//echo "<div style='height:1in;'><hr></div>";
echo "<div><hr style='
height: 2px;
background-color: black;
position: absolute;
margin-top: -50px;
width: 500;
'></div>";
}
echo drawRecipeTable($itemData);
$lastGroup = $itemData['group'];
echo "<div style='height:1in;'></div>";
}
}
echo "</fieldset>";
echo "<br><br><hr><br><br>";
echo "<fieldset style='width:500px'>";
echo "<h3>成品 ".date('j/n',strtotime($arr_data['input']['delivery_date']))." (".$weekarray[date("w", strtotime($arr_data['input']['delivery_date']))].")</h3>";
foreach($arr_data['output']['recipe'] as $idx=>$itemData){
if($itemData['visible']==1) {
echo drawRecipeTable($itemData);
echo "<div style='height:1in;'></div>";
}
}
echo "</fieldset>";
?>