diff --git a/api/v2/get/software_available.php b/api/v2/get/software_available.php index ca139d1..61cad75 100644 --- a/api/v2/get/software_available.php +++ b/api/v2/get/software_available.php @@ -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'] = []; @@ -319,7 +320,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){ if ($show_version) { $available_upgrades++; - + //Check if there's a valid license for this upgrade if ($final_price > 0 && $sw_version_license) { //Check if the license is valid @@ -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"; diff --git a/api/v2/get/software_update.php b/api/v2/get/software_update.php index a7191c3..782aceb 100644 --- a/api/v2/get/software_update.php +++ b/api/v2/get/software_update.php @@ -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 diff --git a/assets/database/STEP3.txt b/assets/database/STEP3.txt index 5c36726..0a71829 100644 --- a/assets/database/STEP3.txt +++ b/assets/database/STEP3.txt @@ -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); diff --git a/assets/images/TSS_invoice_footer.png b/assets/images/TSS_invoice_footer.png index c6129f5..8860ba5 100644 Binary files a/assets/images/TSS_invoice_footer.png and b/assets/images/TSS_invoice_footer.png differ diff --git a/assets/images/TSS_invoice_header.png b/assets/images/TSS_invoice_header.png index aa6ef31..1e8b08e 100644 Binary files a/assets/images/TSS_invoice_header.png and b/assets/images/TSS_invoice_header.png differ diff --git a/assets/mail/email_template_invoice.php b/assets/mail/email_template_invoice.php index 429edea..4b1a2b8 100644 --- a/assets/mail/email_template_invoice.php +++ b/assets/mail/email_template_invoice.php @@ -23,24 +23,6 @@ $message = '
|
- Total Safety Solutions B.V. - Laarakkerweg 8 - 5061 JR OISTERWIJK - Nederland - |
-
- contact-details - Ralf Adams - +31 13 8221480 - ralfadams@totalsafetysolutions.nl - |
-
|
@@ -50,7 +32,10 @@ $message = '
'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].' '.$invoice_data['customer']['country'].' |
-
+
+ contact-details + sales@totalsafetysolutions.nl + |
Laarakkerweg 8
-5061 JR OISTERWIJK
-Nederland
-Ralf Adams
-+31 13 8221480
-ralfadams@totalsafetysolutions.nl
-'.$invoice_data['customer']['name'].'
'.$invoice_data['customer']['street'].'
'.$invoice_data['customer']['zip'].', '.$invoice_data['customer']['city'].'
'.$invoice_data['customer']['country'].'
sales@totalsafetysolutions.nl
+