From 0e345ba8caf3c72acc04f861a3a877c98e5c185f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 03:18:14 +0000 Subject: [PATCH 1/3] Initial plan From f11aeb2f7d9c127f1c26ff329350bc794c2da078 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 03:25:58 +0000 Subject: [PATCH 2/3] Fix server end_date display with color coding and improve cron-shop automation Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- modules/billing/cron-shop.php | 37 +++++++++++++++++++------ modules/gamemanager/server_monitor.php | 38 +++++++++++++++++++++----- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/modules/billing/cron-shop.php b/modules/billing/cron-shop.php index 523c7d10..d9e22eb1 100644 --- a/modules/billing/cron-shop.php +++ b/modules/billing/cron-shop.php @@ -114,6 +114,11 @@ if (is_array($upcoming_expirations)) { " . 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 $settings = $db->getSettings(); $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 // ================================================================================== // Find servers that: -// - Are currently installed (active) +// - Are currently installed or renew (active) // - Have passed their end_date // - Have at least one unpaid invoice $servers_to_suspend = $db->resultQuery(" @@ -146,7 +151,7 @@ $servers_to_suspend = $db->resultQuery(" FROM " . $table_prefix . "billing_orders o 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 - WHERE o.status = 'installed' + WHERE o.status IN ('installed', 'renew') AND o.end_date IS NOT NULL AND UNIX_TIMESTAMP(o.end_date) < {$suspend_date} AND i.status = 'unpaid' @@ -247,9 +252,12 @@ if (is_array($servers_to_delete)) { // Remove the game home files from remote server $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 . "'@'localhost'"); + @$db->query("DROP DATABASE IF EXISTS user_" . $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' 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"); // Send deletion email @@ -420,16 +433,24 @@ else SET status='deleted' WHERE order_id=".$db->realEscapeSingle($user_home['order_id'])); - + // Set order as not installed $db->query( "UPDATE " . $table_prefix . "billing_orders SET home_id=0 WHERE order_id=".$db->realEscapeSingle($user_home['order_id'])); - // remove userid and table from database - $db->query( "DROP USER 'server_" .$home_id ."'@'%'"); - $db->query( "DROP USER 'server_" .$home_id ."'@'localhost'"); - $db->query( "DROP DATABASE server_" .$home_id); + // Mark all unpaid invoices for this order as deleted + $db->query("UPDATE " . $table_prefix . "billing_invoices + SET status='deleted' + 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 $db->logger( "AUTO-CLEAN: DELETED server " . $home_id); diff --git a/modules/gamemanager/server_monitor.php b/modules/gamemanager/server_monitor.php index a1008fec..e51d676b 100644 --- a/modules/gamemanager/server_monitor.php +++ b/modules/gamemanager/server_monitor.php @@ -341,33 +341,57 @@ echo "resultQuery($query); if(!is_null($results[0]['status'])) { //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']; - $expiration_dates = "" . read_expire($expire_date) . ""; + $expire_date = strtotime($results[0]['end_date']); + $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 = "" . read_expire($expire_date) . ""; + } elseif($days_until_expiry <= 7 && $days_until_expiry > 3) { + // 7 days or less (but more than 3) before expiration - YELLOW + $expiration_dates = "" . read_expire($expire_date) . ""; + } elseif($days_until_expiry < 0) { + // Already expired - RED + $expiration_dates = "" . read_expire($expire_date) . " (EXPIRED)"; + } else { + // More than 7 days - GREEN + $expiration_dates = "" . read_expire($expire_date) . ""; } + } + + // renew status - renewal invoice created, server still running + if($results[0]['status'] == 'renew') + { + $expire_date = strtotime($results[0]['end_date']); + $expiration_dates = "". read_expire($expire_date) . " Renew Invoice"; + } + // in-cart its expire, invoice printed 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 = "". read_expire($expire_date) . " Invoice"; } // invoiced its expire, invoice printed if($results[0]['status'] == 'invoiced') { - $expire_date = $results[0]['finish_date']; + $expire_date = strtotime($results[0]['end_date']); $expiration_dates = "". read_expire($expire_date) . " Invoice"; } // suspended its suspended, invoice still available if($results[0]['status'] == 'suspended') { - $expire_date = $results[0]['finish_date']; + $expire_date = strtotime($results[0]['end_date']); $expiration_dates = " SUSPENDED Invoice"; } From a5f5b5acc4a6b55be2e08a319cf85ce9cc000ef5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 03:27:26 +0000 Subject: [PATCH 3/3] Fix finish_date to end_date in database_mysqli.php Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- includes/database_mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/database_mysqli.php b/includes/database_mysqli.php index 5dc71c49..1dd3ba22 100644 --- a/includes/database_mysqli.php +++ b/includes/database_mysqli.php @@ -3712,7 +3712,7 @@ class OGPDatabaseMySQL extends OGPDatabase $ed = $dateTime->getTimestamp(); } $type = $type != "group" ? $type : "user_group"; - $query = sprintf("UPDATE `%sbilling_orders` SET `finish_date` = '%s' WHERE `home_id` = %d", + $query = sprintf("UPDATE `%sbilling_orders` SET `end_date` = '%s' WHERE `home_id` = %d", $this->table_prefix, $ed, $this->realEscapeSingle($home_id));