HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/breadsecret.com/test1.php
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo phpinfo();

require_once('wp-load.php'); 
session_start();
date_default_timezone_set("Asia/Hong_Kong"); 
global $wpdb, $sitepress;

$a = get_custom_calendar_date_info(date("Y-m-d"));
print_r($a);

/*

$begin_date = "2024-07-15";
$end_date = "2024-07-16";
$group_by = "cateogry";

echo "<div id='summary_content'></div>";
echo "<table id='dataTable' class='stripe hover cell-border' style='width:100%' cellpadding='3'>"; //draw table
$arr_result = array();


$total_item = 0;

$total_wholesale_qty = 0;
$total_wholesale_amount = 0;

$total_individual_qty = 0;
$total_individual_amount = 0;

$total_qty = 0;
$total_amount = 0;


if($group_by=="product") {

	echo "<thead>";
		echo "<tr style='text-align: center;'>";
			echo "<th>SKU</th>";		
			echo "<th>Name</th>";
			echo "<th>Wholesale Qty</th>";
			echo "<th>Wholesale Amount (HKD)</th>";      
			echo "<th>Individual Qty</th>";
			echo "<th>Individual Amount (HKD)</th>";                  
			echo "<th>Total Qty</th>";
			echo "<th>Total Amount (HKD)</th>";
		echo "</tr>";
	echo "</thead>";	


	$sql = "SELECT `stock_sku`, `type`, SUM(qty) as ttl_qty, SUM(price) as ttl_amount FROM sales_figure WHERE order_date >= '".$begin_date." 00:00:00' AND order_date <= '".$end_date." 23:59:59' GROUP BY CONCAT(`stock_sku`, '-', `type`) ORDER BY `stock_sku` ASC";

	$figure = $wpdb->get_results($sql);

	foreach($figure as $line) {
		$arr_result[$line->stock_sku][$line->type]['qty'] = $line->ttl_qty;
		$arr_result[$line->stock_sku][$line->type]['amount'] = $line->ttl_amount;
	}

	echo "<tbody>";
	foreach($arr_result as $sku=>$data) {

		$total_item++;
		$product = wc_get_product(wc_get_product_id_by_sku($sku));

		$line_total_qty = $data['wholesale']['qty']+$data['individual']['qty'];
		$line_total_amount = $data['wholesale']['amount']+$data['individual']['amount'];

		echo "<tr>";
			echo "<td nowrap>".$sku."</td>";
			echo "<td nowrap>".$product->get_name()."</td>";				
			echo "<td nowrap class='text-right'>".number_format($data['wholesale']['qty'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['wholesale']['amount'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['individual']['qty'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['individual']['amount'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($line_total_qty,2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($line_total_amount,2,".",",")."</td>";
		echo "</tr>";

		$total_wholesale_qty += $data['wholesale']['qty'];
		$total_wholesale_amount += $data['wholesale']['amount'];
		
		$total_individual_qty += $data['individual']['qty'];
		$total_individual_amount += $data['individual']['amount'];
		
		$total_qty += $line_total_qty;
		$total_amount += $line_total_amount;

	}
	echo "</tbody>";
	echo "<tfoot>";
		echo "<tr>";
			echo "<th>Total</th>"; 		
			echo "<th align='center' class='text-right'></th>";
			echo "<th align='center' class='text-right'>".number_format($total_wholesale_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_wholesale_amount,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_individual_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_individual_amount,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_amount,2,".",",")."</th>";                        
		echo "</tr>";
	echo "</tfoot>";
} else {

	echo "<thead>";
		echo "<tr style='text-align: center;'>";
			echo "<th>Category</th>";	
            echo "<th>Wholesale Qty</th>";
            echo "<th>Wholesale Amount (HKD)</th>";      
            echo "<th>Individual Qty</th>";
            echo "<th>Individual Amount (HKD)</th>";                  
			echo "<th>Total Qty</th>";
			echo "<th>Total Amount (HKD)</th>";
		echo "</tr>";
	echo "</thead>";	
	
	echo "<tbody>";

	$sql = "SELECT `custom_category`, `type`, SUM(qty) as ttl_qty, SUM(price) as ttl_amount FROM sales_figure WHERE order_date >= '".$begin_date." 00:00:00' AND order_date <= '".$end_date." 23:59:59' GROUP BY CONCAT(`custom_category`, '-', `type`) ORDER BY `custom_category` ASC";

	$figure = $wpdb->get_results($sql);

	foreach($figure as $line) {
		$arr_result[$line->custom_category][$line->type]['qty'] = $line->ttl_qty;
		$arr_result[$line->custom_category][$line->type]['amount'] = $line->ttl_amount;
	}

	echo "<tbody>";
	foreach($arr_result as $custom_category=>$data) {

		$total_item++;

		$line_total_qty = $data['wholesale']['qty']+$data['individual']['qty'];
		$line_total_amount = $data['wholesale']['amount']+$data['individual']['amount'];

		echo "<tr>";
			echo "<td nowrap>".$custom_category."</td>";			
			echo "<td nowrap class='text-right'>".number_format($data['wholesale']['qty'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['wholesale']['amount'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['individual']['qty'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($data['individual']['amount'],2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($line_total_qty,2,".",",")."</td>";
			echo "<td nowrap class='text-right'>".number_format($line_total_amount,2,".",",")."</td>";
		echo "</tr>";

		$total_wholesale_qty += $data['wholesale']['qty'];
		$total_wholesale_amount += $data['wholesale']['amount'];
		
		$total_individual_qty += $data['individual']['qty'];
		$total_individual_amount += $data['individual']['amount'];
		
		$total_qty += $line_total_qty;
		$total_amount += $line_total_amount;

	}
	echo "</tbody>";
	echo "<tfoot>";
		echo "<tr>";
			echo "<th>Total</th>"; 		
			echo "<th align='center' class='text-right'>".number_format($total_wholesale_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_wholesale_amount,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_individual_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_individual_amount,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_qty,2,".",",")."</th>";
			echo "<th align='center' class='text-right'>".number_format($total_amount,2,".",",")."</th>";                        
		echo "</tr>";
	echo "</tfoot>";

}

echo "</table>";

*/