Fix server end_date display with color coding and improve cron-shop automation

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-29 03:25:58 +00:00
parent 0e345ba8ca
commit f11aeb2f7d
2 changed files with 60 additions and 15 deletions

View file

@ -114,6 +114,11 @@ if (is_array($upcoming_expirations)) {
" . intval($order['qty']) . " " . intval($order['qty']) . "
)"); )");
// Mark order status as 'renew' to indicate renewal invoice was created
$db->query("UPDATE " . $table_prefix . "billing_orders
SET status='renew'
WHERE order_id={$order_id}");
// Send renewal notice email // Send renewal notice email
$settings = $db->getSettings(); $settings = $db->getSettings();
$subject = "Renewal Invoice for " . $order['home_name'] . " - " . $panel_settings['panel_name']; $subject = "Renewal Invoice for " . $order['home_name'] . " - " . $panel_settings['panel_name'];
@ -138,7 +143,7 @@ if (is_array($upcoming_expirations)) {
// STEP 2: SUSPEND SERVERS THAT ARE EXPIRED AND HAVE UNPAID INVOICES // STEP 2: SUSPEND SERVERS THAT ARE EXPIRED AND HAVE UNPAID INVOICES
// ================================================================================== // ==================================================================================
// Find servers that: // Find servers that:
// - Are currently installed (active) // - Are currently installed or renew (active)
// - Have passed their end_date // - Have passed their end_date
// - Have at least one unpaid invoice // - Have at least one unpaid invoice
$servers_to_suspend = $db->resultQuery(" $servers_to_suspend = $db->resultQuery("
@ -146,7 +151,7 @@ $servers_to_suspend = $db->resultQuery("
FROM " . $table_prefix . "billing_orders o FROM " . $table_prefix . "billing_orders o
LEFT JOIN " . $table_prefix . "users u ON o.user_id = u.user_id LEFT JOIN " . $table_prefix . "users u ON o.user_id = u.user_id
INNER JOIN " . $table_prefix . "billing_invoices i ON o.order_id = i.order_id INNER JOIN " . $table_prefix . "billing_invoices i ON o.order_id = i.order_id
WHERE o.status = 'installed' WHERE o.status IN ('installed', 'renew')
AND o.end_date IS NOT NULL AND o.end_date IS NOT NULL
AND UNIX_TIMESTAMP(o.end_date) < {$suspend_date} AND UNIX_TIMESTAMP(o.end_date) < {$suspend_date}
AND i.status = 'unpaid' AND i.status = 'unpaid'
@ -247,9 +252,12 @@ if (is_array($servers_to_delete)) {
// Remove the game home files from remote server // Remove the game home files from remote server
$remote->remove_home($home_info['home_path']); $remote->remove_home($home_info['home_path']);
// Drop database and user if they exist // Drop database and user if they exist (both user_#### and server_#### formats)
@$db->query("DROP USER 'user_" . $home_id . "'@'%'");
@$db->query("DROP USER 'user_" . $home_id . "'@'localhost'");
@$db->query("DROP USER 'server_" . $home_id . "'@'%'"); @$db->query("DROP USER 'server_" . $home_id . "'@'%'");
@$db->query("DROP USER 'server_" . $home_id . "'@'localhost'"); @$db->query("DROP USER 'server_" . $home_id . "'@'localhost'");
@$db->query("DROP DATABASE IF EXISTS user_" . $home_id);
@$db->query("DROP DATABASE IF EXISTS server_" . $home_id); @$db->query("DROP DATABASE IF EXISTS server_" . $home_id);
} }
@ -258,6 +266,11 @@ if (is_array($servers_to_delete)) {
SET status='deleted', home_id='0' SET status='deleted', home_id='0'
WHERE order_id={$order_id}"); WHERE order_id={$order_id}");
// Mark all unpaid invoices for this order as deleted
$db->query("UPDATE " . $table_prefix . "billing_invoices
SET status='deleted'
WHERE order_id={$order_id} AND status='unpaid'");
$db->logger("BILLING-CRON: DELETED server {$home_id} for order {$order_id} after 7 days suspended"); $db->logger("BILLING-CRON: DELETED server {$home_id} for order {$order_id} after 7 days suspended");
// Send deletion email // Send deletion email
@ -426,10 +439,18 @@ else
SET home_id=0 SET home_id=0
WHERE order_id=".$db->realEscapeSingle($user_home['order_id'])); WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
// remove userid and table from database // Mark all unpaid invoices for this order as deleted
$db->query( "DROP USER 'server_" .$home_id ."'@'%'"); $db->query("UPDATE " . $table_prefix . "billing_invoices
$db->query( "DROP USER 'server_" .$home_id ."'@'localhost'"); SET status='deleted'
$db->query( "DROP DATABASE server_" .$home_id); WHERE order_id=".$db->realEscapeSingle($user_home['order_id'])." AND status='unpaid'");
// remove userid and table from database (both user_#### and server_#### formats)
@$db->query( "DROP USER 'user_" .$home_id ."'@'%'");
@$db->query( "DROP USER 'user_" .$home_id ."'@'localhost'");
@$db->query( "DROP USER 'server_" .$home_id ."'@'%'");
@$db->query( "DROP USER 'server_" .$home_id ."'@'localhost'");
@$db->query( "DROP DATABASE IF EXISTS user_" .$home_id);
@$db->query( "DROP DATABASE IF EXISTS server_" .$home_id);
//logger //logger
$db->logger( "AUTO-CLEAN: DELETED server " . $home_id); $db->logger( "AUTO-CLEAN: DELETED server " . $home_id);

View file

@ -341,33 +341,57 @@ echo "<table id='servermonitor' class='tablesorter' data-sortlist='[[0,0],[3,1]]
//default is it never expires //default is it never expires
$expiration_dates = "This Server Will NEVER Expire"; $expiration_dates = "This Server Will NEVER Expire";
//get all orders thare are active or invoiced //get all orders thare are active or invoiced
$query = "SELECT * FROM ogp_billing_orders WHERE home_id = " . $server_home['home_id'] . " AND status IN ('paid', 'invoiced', 'suspended', 'in-cart', 'unknown')" ; $query = "SELECT * FROM ogp_billing_orders WHERE home_id = " . $server_home['home_id'] . " AND status IN ('installed', 'paid', 'renew', 'invoiced', 'suspended', 'in-cart', 'unknown')" ;
$results = $db->resultQuery($query); $results = $db->resultQuery($query);
if(!is_null($results[0]['status'])) if(!is_null($results[0]['status']))
{ {
//there is an end date //there is an end date
if($results[0]['status'] == 'paid') if($results[0]['status'] == 'installed' || $results[0]['status'] == 'paid')
{ {
$expire_date = $results[0]['finish_date']; $expire_date = strtotime($results[0]['end_date']);
$expiration_dates = "<font color='green'>" . read_expire($expire_date) . "</font>"; $current_time = time();
$days_until_expiry = floor(($expire_date - $current_time) / 86400);
// Color coding based on time until expiration
if($days_until_expiry <= 3 && $days_until_expiry >= 0) {
// 3 days or less before expiration - RED
$expiration_dates = "<font color='red'>" . read_expire($expire_date) . "</font>";
} elseif($days_until_expiry <= 7 && $days_until_expiry > 3) {
// 7 days or less (but more than 3) before expiration - YELLOW
$expiration_dates = "<font color='yellow'>" . read_expire($expire_date) . "</font>";
} elseif($days_until_expiry < 0) {
// Already expired - RED
$expiration_dates = "<font color='red'>" . read_expire($expire_date) . " (EXPIRED)</font>";
} else {
// More than 7 days - GREEN
$expiration_dates = "<font color='green'>" . read_expire($expire_date) . "</font>";
} }
}
// renew status - renewal invoice created, server still running
if($results[0]['status'] == 'renew')
{
$expire_date = strtotime($results[0]['end_date']);
$expiration_dates = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Renew Invoice</a>";
}
// in-cart its expire, invoice printed // in-cart its expire, invoice printed
if($results[0]['status'] == 'in-cart' || $results[0]['status'] == 'unknown') if($results[0]['status'] == 'in-cart' || $results[0]['status'] == 'unknown')
{ {
$expire_date = $results[0]['finish_date']; $expire_date = strtotime($results[0]['end_date']);
$expiration_dates = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Invoice</a>"; $expiration_dates = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Invoice</a>";
} }
// invoiced its expire, invoice printed // invoiced its expire, invoice printed
if($results[0]['status'] == 'invoiced') if($results[0]['status'] == 'invoiced')
{ {
$expire_date = $results[0]['finish_date']; $expire_date = strtotime($results[0]['end_date']);
$expiration_dates = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Invoice</a>"; $expiration_dates = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Invoice</a>";
} }
// suspended its suspended, invoice still available // suspended its suspended, invoice still available
if($results[0]['status'] == 'suspended') if($results[0]['status'] == 'suspended')
{ {
$expire_date = $results[0]['finish_date']; $expire_date = strtotime($results[0]['end_date']);
$expiration_dates = "<font color='red'> SUSPENDED </font><a href='home.php?m=billing&p=cart'> Invoice</a>"; $expiration_dates = "<font color='red'> SUSPENDED </font><a href='home.php?m=billing&p=cart'> Invoice</a>";
} }