Implement downgrade prevention for paid software versions and update invoice templates with new contact details
This commit is contained in:
@@ -238,6 +238,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$available_upgrades = 0;
|
||||
$has_priced_options = false;
|
||||
$has_latest_version_different = false;
|
||||
$version_details = []; // Track version details for downgrade prevention
|
||||
|
||||
if (debug) {
|
||||
$debug['version_checks'] = [];
|
||||
@@ -342,6 +343,12 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
// Store version details for downgrade prevention check (after license application)
|
||||
$version_details[] = [
|
||||
'show_version' => true,
|
||||
'final_price' => $final_price
|
||||
];
|
||||
|
||||
// Check for priced options
|
||||
if ($final_price > 0) {
|
||||
$has_priced_options = true;
|
||||
@@ -364,6 +371,48 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
//PREVENT DOWNGRADE FROM PAID VERSION TO FREE VERSION (if config enabled)
|
||||
if (defined('PREVENT_PAID_VERSION_DOWNGRADE') && PREVENT_PAID_VERSION_DOWNGRADE && $current_sw_version) {
|
||||
// Check if user is currently on a paid version (check if there was a paid upgrade path TO current version)
|
||||
$sql = 'SELECT COUNT(*) as paid_to_current
|
||||
FROM products_software_upgrade_paths pup
|
||||
JOIN products_software_versions to_ver ON pup.to_version_id = to_ver.rowID
|
||||
WHERE LOWER(TRIM(LEADING "0" FROM to_ver.version)) = ?
|
||||
AND pup.price > 0
|
||||
AND pup.is_active = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$current_sw_version]);
|
||||
$paid_check = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$is_current_paid_version = ($paid_check['paid_to_current'] > 0);
|
||||
|
||||
if (debug) {
|
||||
$debug['downgrade_prevention'] = [
|
||||
'enabled' => true,
|
||||
'current_version' => $current_sw_version,
|
||||
'is_current_paid_version' => $is_current_paid_version
|
||||
];
|
||||
}
|
||||
|
||||
// If current version is paid, recalculate available_upgrades excluding free versions
|
||||
if ($is_current_paid_version) {
|
||||
$available_upgrades_before = $available_upgrades;
|
||||
$available_upgrades = 0;
|
||||
|
||||
// Recount only paid upgrades (exclude free versions)
|
||||
foreach ($version_details as $detail) {
|
||||
if ($detail['show_version'] && floatval($detail['final_price']) > 0) {
|
||||
$available_upgrades++;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
$debug['downgrade_prevention']['available_upgrades_before'] = $available_upgrades_before;
|
||||
$debug['downgrade_prevention']['available_upgrades_after'] = $available_upgrades;
|
||||
$debug['downgrade_prevention']['message'] = 'Excluded free versions to prevent downgrade from paid version';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Simple logic: if any upgrades are available to show, return "yes"
|
||||
if ($available_upgrades > 0) {
|
||||
$software_available = "yes";
|
||||
|
||||
@@ -441,6 +441,46 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
//PREVENT DOWNGRADE FROM PAID VERSION TO FREE VERSION (if config enabled)
|
||||
if (defined('PREVENT_PAID_VERSION_DOWNGRADE') && PREVENT_PAID_VERSION_DOWNGRADE && $current_sw_version) {
|
||||
// Check if user is currently on a paid version (check if there was a paid upgrade path TO current version)
|
||||
$sql = 'SELECT COUNT(*) as paid_to_current
|
||||
FROM products_software_upgrade_paths pup
|
||||
JOIN products_software_versions to_ver ON pup.to_version_id = to_ver.rowID
|
||||
WHERE LOWER(TRIM(LEADING "0" FROM to_ver.version)) = ?
|
||||
AND pup.price > 0
|
||||
AND pup.is_active = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$current_sw_version]);
|
||||
$paid_check = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$is_current_paid_version = ($paid_check['paid_to_current'] > 0);
|
||||
|
||||
if (debug) {
|
||||
$debug['downgrade_prevention'] = [
|
||||
'enabled' => true,
|
||||
'current_version' => $current_sw_version,
|
||||
'is_current_paid_version' => $is_current_paid_version
|
||||
];
|
||||
}
|
||||
|
||||
// If current version is paid, remove all free versions from the output (except current)
|
||||
if ($is_current_paid_version) {
|
||||
$output = array_filter($output, function($option) {
|
||||
$price = floatval($option['price']);
|
||||
$is_current = $option['is_current'];
|
||||
// Keep if it's the current version OR if it's a paid version
|
||||
return $is_current || $price > 0;
|
||||
});
|
||||
// Re-index array after filtering
|
||||
$output = array_values($output);
|
||||
|
||||
if (debug) {
|
||||
$debug['downgrade_prevention']['filtered_count'] = count($output);
|
||||
$debug['downgrade_prevention']['message'] = 'Removed free versions to prevent downgrade from paid version';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//GENERATE DOWNLOAD TOKENS FOR EACH OPTION
|
||||
foreach ($output as &$option) {
|
||||
// Generate time-based download token
|
||||
|
||||
@@ -3,6 +3,7 @@ define("WARRANTY_MONTHS", 12);
|
||||
define("WARRANTY_ELIGIBILITY_WINDOW", 3);
|
||||
define("WARRANTY_EXTENDED_MONTH", 24);
|
||||
define("SERVICE_MONTHS", 12);
|
||||
define('PREVENT_PAID_VERSION_DOWNGRADE',false);
|
||||
|
||||
// Enable automatice invoice forward to bookkeeping software
|
||||
define('invoice_bookkeeping',false);
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 57 KiB |
@@ -23,24 +23,6 @@ $message = '
|
||||
<h1 style="font-size: 24px; font-weight: bold; color: #2c5f5d; margin: 0 0 25px 0;">' . htmlspecialchars($lbl_invoice) . '</h1>
|
||||
|
||||
<!-- Company Header -->
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-bottom: 25px;">
|
||||
<tr>
|
||||
<td width="50%" style="vertical-align: top; font-size: 13px; line-height: 1.5;">
|
||||
<strong style="color: #2c5f5d; font-size: 14px;">Total Safety Solutions B.V.</strong><br>
|
||||
Laarakkerweg 8<br>
|
||||
5061 JR OISTERWIJK<br>
|
||||
Nederland
|
||||
</td>
|
||||
<td width="50%" style="vertical-align: top; text-align: left;">
|
||||
<strong style="color: #2c5f5d; font-size: 14px;">contact-details</strong><br>
|
||||
Ralf Adams<br>
|
||||
+31 13 8221480<br>
|
||||
ralfadams@totalsafetysolutions.nl
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- Customer -->
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-bottom: 25px;">
|
||||
<tr>
|
||||
<td width="50%" style="vertical-align: top; font-size: 13px; line-height: 1.5;">
|
||||
@@ -50,7 +32,10 @@ $message = '
|
||||
'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].'<br>
|
||||
'.$invoice_data['customer']['country'].'
|
||||
</td>
|
||||
|
||||
<td width="50%" style="vertical-align: top; text-align: left;">
|
||||
<strong style="color: #2c5f5d; font-size: 14px;">contact-details</strong><br>
|
||||
sales@totalsafetysolutions.nl
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -210,21 +210,6 @@ $pdf = '<!DOCTYPE html>
|
||||
|
||||
<div class="invoice-title">' . htmlspecialchars($lbl_invoice) . '</div>
|
||||
|
||||
<div class="company-header">
|
||||
<div class="company-info">
|
||||
<h3>Total Safety Solutions B.V.</h3>
|
||||
<p>Laarakkerweg 8</p>
|
||||
<p>5061 JR OISTERWIJK</p>
|
||||
<p>Nederland</p>
|
||||
</div>
|
||||
<div class="contact-details">
|
||||
<h3>contact-details</h3>
|
||||
<p>Ralf Adams</p>
|
||||
<p>+31 13 8221480</p>
|
||||
<p>ralfadams@totalsafetysolutions.nl</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="company-header">
|
||||
<div class="company-info">
|
||||
<h3>Customer</h3>
|
||||
@@ -233,6 +218,10 @@ $pdf = '<!DOCTYPE html>
|
||||
<p>'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].'</p>
|
||||
<p>'.$invoice_data['customer']['country'].'</p>
|
||||
</div>
|
||||
<div class="contact-details">
|
||||
<h3>contact-details</h3>
|
||||
<p>sales@totalsafetysolutions.nl</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="invoice-details">
|
||||
|
||||
Reference in New Issue
Block a user