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:
parent
0e345ba8ca
commit
f11aeb2f7d
2 changed files with 60 additions and 15 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -341,33 +341,57 @@ echo "<table id='servermonitor' class='tablesorter' data-sortlist='[[0,0],[3,1]]
|
|||
//default is it never expires
|
||||
$expiration_dates = "This Server Will NEVER Expire";
|
||||
//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);
|
||||
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 = "<font color='green'>" . read_expire($expire_date) . "</font>";
|
||||
$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 = "<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
|
||||
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>";
|
||||
}
|
||||
|
||||
// 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 = "<font color='yellow'>". read_expire($expire_date) . "</font><a href='home.php?m=billing&p=cart'> Invoice</a>";
|
||||
}
|
||||
// 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 = "<font color='red'> SUSPENDED </font><a href='home.php?m=billing&p=cart'> Invoice</a>";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue