From a18135e05394f176631dee73685225b285d83ddd Mon Sep 17 00:00:00 2001 From: ptruessel Date: Thu, 5 Dec 2024 13:07:21 +0100 Subject: [PATCH] Test days for upgrades --- config/db/core/V4__testdays-upgrade.sql | 8 ++ www/backend/core/com/book.cfc | 74 ++++++++++++------- www/backend/core/com/plans.cfc | 7 +- www/backend/core/handler/sysadmin/plans.cfm | 10 ++- .../core/views/sysadmin/plan_details.cfm | 42 ++++++----- www/backend/core/views/sysadmin/plans.cfm | 4 +- 6 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 config/db/core/V4__testdays-upgrade.sql diff --git a/config/db/core/V4__testdays-upgrade.sql b/config/db/core/V4__testdays-upgrade.sql new file mode 100644 index 00000000..ef896222 --- /dev/null +++ b/config/db/core/V4__testdays-upgrade.sql @@ -0,0 +1,8 @@ +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +ALTER TABLE `plans` +ADD COLUMN `blnTestDaysUpgrade` tinyint NULL DEFAULT 0 AFTER `intNumTestDays`; + + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/www/backend/core/com/book.cfc b/www/backend/core/com/book.cfc index 0254a4e0..d6ce7be2 100644 --- a/www/backend/core/com/book.cfc +++ b/www/backend/core/com/book.cfc @@ -400,41 +400,59 @@ component displayname="book" output="false" { // Define the start date local.startDate = dateFormat(now(), "yyyy-mm-dd"); - // Define the end date - if (local.recurring eq "monthly") { - local.endDate = dateFormat(dateAdd("m", 1, local.startDate), "yyyy-mm-dd"); - local.planPrice = local.bookingData.priceMonthly; - } else if (local.recurring eq "yearly") { - local.endDate = dateFormat(dateAdd("yyyy", 1, local.startDate), "yyyy-mm-dd"); - local.planPrice = local.bookingData.priceYearly; - } + // If the plan does provide test days and the test days also count for upgrades + if (local.bookingData.testDays gt 0 and local.bookingData.testDaysUpgrade) { + + local.endDate = dateFormat(dateAdd("d", local.bookingData.testDays, local.startDate), "yyyy-mm-dd"); + local.status = "test"; + local.recurring = "test"; + + local.amountToPay = 0; + + local.messageStruct['title'] = local.getTrans('titUpgrade'); + local.messageStruct['message'] = local.getTrans('txtYouAreUpgrading'); + local.messageStruct['button'] = local.getTrans('btnYesUpgrade'); + - // If the product was booked via SysAdmin and we have to make an invoice, we must set the status to "payment" - if (local.makeInvoice and !local.chargeInvoice) { - local.status = "payment"; } else { - local.status = "active"; - } - // Get the amount to pay - local.calculateUpgrade = calculateUpgrade(arguments.customerID, local.newProductID, local.recurring); - local.priceBeforeVat = local.calculateUpgrade.toPayNow ?: local.planPrice; + // Define the end date + if (local.recurring eq "monthly") { + local.endDate = dateFormat(dateAdd("m", 1, local.startDate), "yyyy-mm-dd"); + local.planPrice = local.bookingData.priceMonthly; + } else if (local.recurring eq "yearly") { + local.endDate = dateFormat(dateAdd("yyyy", 1, local.startDate), "yyyy-mm-dd"); + local.planPrice = local.bookingData.priceYearly; + } - local.amountToPay = local.objPrices.getPriceData(local.priceBeforeVat).priceAfterVAT; + // If the product was booked via SysAdmin and we have to make an invoice, we must set the status to "payment" + if (local.makeInvoice and !local.chargeInvoice) { + local.status = "payment"; + } else { + local.status = "active"; + } - local.messageStruct['title'] = local.getTrans('titUpgrade'); - local.messageStruct['message'] = local.getTrans('txtYouAreUpgrading'); - local.messageStruct['button'] = local.getTrans('btnYesUpgrade'); + // Get the amount to pay + local.calculateUpgrade = calculateUpgrade(arguments.customerID, local.newProductID, local.recurring); + local.priceBeforeVat = local.calculateUpgrade.toPayNow ?: local.planPrice; - // Set some invoice variables - local.invoiceTitle = local.getTrans('titUpgrade') & ": " & local.productName; - local.invoiceCurrency = local.bookingData.currency; - local.invoiceLanguage = variables.language; + local.amountToPay = local.objPrices.getPriceData(local.priceBeforeVat).priceAfterVAT; + + local.messageStruct['title'] = local.getTrans('titUpgrade'); + local.messageStruct['message'] = local.getTrans('txtYouAreUpgrading'); + local.messageStruct['button'] = local.getTrans('btnYesUpgrade'); + + // Set some invoice variables + local.invoiceTitle = local.getTrans('titUpgrade') & ": " & local.productName; + local.invoiceCurrency = local.bookingData.currency; + local.invoiceLanguage = variables.language; + + if (local.recurring eq "onetime") { + local.invoicePositionTitle = local.productName; + } else { + local.invoicePositionTitle = local.productName & ' ' & lsDateFormat(local.getTime.utc2local(utcDate=local.startDate)) & ' - ' & lsDateFormat(local.getTime.utc2local(utcDate=local.endDate)); + } - if (local.recurring eq "onetime") { - local.invoicePositionTitle = local.productName; - } else { - local.invoicePositionTitle = local.productName & ' ' & lsDateFormat(local.getTime.utc2local(utcDate=local.startDate)) & ' - ' & lsDateFormat(local.getTime.utc2local(utcDate=local.endDate)); } diff --git a/www/backend/core/com/plans.cfc b/www/backend/core/com/plans.cfc index a06aab63..f09ca6f6 100644 --- a/www/backend/core/com/plans.cfc +++ b/www/backend/core/com/plans.cfc @@ -174,6 +174,7 @@ component displayname="plans" output="false" { COALESCE(plans.blnRecommended,0) as blnRecommended, COALESCE(plans.intMaxUsers,0) as intMaxUsers, COALESCE(plans.intNumTestDays,0) as intNumTestDays, + COALESCE(plans.blnTestDaysUpgrade,0) as blnTestDaysUpgrade, COALESCE(plan_prices.decPriceMonthly,0) as decPriceMonthly, COALESCE(plan_prices.decPriceYearly,0) as decPriceYearly, COALESCE(plan_prices.blnOnRequest,0) as blnOnRequest, @@ -342,7 +343,8 @@ component displayname="plans" output="false" { local.structPlan['bookingLinkO'] = ''; local.structPlan['recommended'] = 0; local.structPlan['maxUsers'] = 0; - local.structPlan['testDays'] = 0; + local.structPlan['testDaysUpgrade'] = 0; + local.structPlan['recommended'] = 0; local.structPlan['priceMonthly'] = 0; local.structPlan['priceYearly'] = 0; local.structPlan['onRequest'] = 0; @@ -381,6 +383,9 @@ component displayname="plans" output="false" { if (isNumeric(local.getPlan.intNumTestDays)) { local.structPlan['testDays'] = local.getPlan.intNumTestDays; } + if (isBoolean(local.getPlan.blnTestDaysUpgrade)) { + local.structPlan['testDaysUpgrade'] = local.getPlan.blnTestDaysUpgrade; + } if (isNumeric(local.getPlan.decPriceMonthly)) { local.structPlan['priceMonthly'] = local.getPlan.decPriceMonthly; } diff --git a/www/backend/core/handler/sysadmin/plans.cfm b/www/backend/core/handler/sysadmin/plans.cfm index e179ab59..87f2398e 100644 --- a/www/backend/core/handler/sysadmin/plans.cfm +++ b/www/backend/core/handler/sysadmin/plans.cfm @@ -195,12 +195,18 @@ if (structKeyExists(form, "edit_plan")) { max_users = form.max_users; desc = form.desc; + free = 0; recommended = structKeyExists(form, "recommended") ? 1 : 0; + test_days_upgrade = structKeyExists(form, "test_days_upgrade") ? 1 : 0; + if (test_days lte 0) { + test_days_upgrade = 0; + } if (structKeyExists(form, "free")) { free = 1; test_days = 0; + test_days_upgrade = 0; // Set all prices to 0 queryExecute( @@ -220,8 +226,6 @@ if (structKeyExists(form, "edit_plan")) { " ) - } else { - free = 0; } queryExecute( @@ -236,6 +240,7 @@ if (structKeyExists(form, "edit_plan")) { recommended: {type: "boolean", value: recommended}, free: {type: "boolean", value: free}, test_days: {type: "numeric", value: test_days}, + test_days_upgrade: {type: "boolean", value: test_days_upgrade}, max_users: {type: "numeric", value: max_users}, planID: {type: "numeric", value: form.edit_plan} }, @@ -248,6 +253,7 @@ if (structKeyExists(form, "edit_plan")) { strButtonName = :button_name, strBookingLink = :booking_link, intNumTestDays = :test_days, + blnTestDaysUpgrade = :test_days_upgrade, blnRecommended = :recommended, blnFree = :free, intMaxUsers = :max_users diff --git a/www/backend/core/views/sysadmin/plan_details.cfm b/www/backend/core/views/sysadmin/plan_details.cfm index 053f2987..3e2e4008 100644 --- a/www/backend/core/views/sysadmin/plan_details.cfm +++ b/www/backend/core/views/sysadmin/plan_details.cfm @@ -1,12 +1,4 @@ - - - objSysadmin = new backend.core.com.sysadmin(); - qNonDefLng = objSysadmin.getNonDefLng(); - - - -
@@ -60,26 +52,33 @@
-
+
Activate this plan as "Free". All settings in the "Prices" tab then become ineffective.
-
-
-
+
Mark this plan as "recommendation".
+
+
+
+ + + + Enter 0 if you don't want to use the user limit. + +
@@ -92,10 +91,19 @@
- - + + + + > + Test days upgrade + + - Enter 0 if you don't want to use the user limit. + Offer test days when upgrading from a free to a paid plan.
diff --git a/www/backend/core/views/sysadmin/plans.cfm b/www/backend/core/views/sysadmin/plans.cfm index 3363a322..7ecb58c4 100644 --- a/www/backend/core/views/sysadmin/plans.cfm +++ b/www/backend/core/views/sysadmin/plans.cfm @@ -64,7 +64,7 @@

- Here you can configure your plans and prices. The default plan indicates that it will be activated immediately when a new registration is made. + Here you can configure your plans and prices. The default plan indicates that it will be activated immediately when a new registration is made without choosing a plan. You need at least one plan group before you can create plans. Manage plan groups @@ -154,7 +154,7 @@

- +