Skip to content

Commit

Permalink
Test days for upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
ptruessel committed Dec 5, 2024
1 parent 9a71355 commit a18135e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 50 deletions.
8 changes: 8 additions & 0 deletions config/db/core/V4__testdays-upgrade.sql
Original file line number Diff line number Diff line change
@@ -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;
74 changes: 46 additions & 28 deletions www/backend/core/com/book.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down
7 changes: 6 additions & 1 deletion www/backend/core/com/plans.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions www/backend/core/handler/sysadmin/plans.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -220,8 +226,6 @@ if (structKeyExists(form, "edit_plan")) {
"
)
} else {
free = 0;
}
queryExecute(
Expand All @@ -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}
},
Expand All @@ -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
Expand Down
42 changes: 25 additions & 17 deletions www/backend/core/views/sysadmin/plan_details.cfm
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@

<cfscript>
objSysadmin = new backend.core.com.sysadmin();
qNonDefLng = objSysadmin.getNonDefLng();
</cfscript>


<cfoutput>
<form id="submit_form" method="post" action="#application.mainURL#/sysadm/plans">
<input type="hidden" name="edit_plan" value="#qPlan.intPlanID#">
Expand Down Expand Up @@ -60,26 +52,33 @@
</small>
</div>
<div class="row mb-4">
<div class="col-lg-12">
<div class="col-lg-6">
<label class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="free" <cfif qPlan.blnFree>checked</cfif>>
<span class="form-check-label">Free plan</span>
<span class="form-label">Free plan</span>
</label>
<small class="form-hint">
Activate this plan as "Free". All settings in the "Prices" tab then become ineffective.
</small>
</div>
</div>
<div class="row mb-3">
<div class="col-lg-4">
<div class="col-lg-6">
<label class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="recommended" <cfif qPlan.blnRecommended>checked</cfif>>
<span class="form-check-label">Recommended</span>
<span class="form-label">Recommended</span>
</label>
<small class="form-hint">
Mark this plan as "recommendation".
</small>
</div>
</div>
<div class="row mb-3">
<div class="col-lg-4">
<label class="form-label text-end">Maximum users *</label>
<input type="text" class="form-control text-end" name="max_users" autocomplete="off" maxlength="10" value="#qPlan.intMaxUsers#" placeholder="0" required>
<small class="form-hint">
Enter 0 if you don't want to use the user limit.
</small>
</div>
<div class="col-lg-4">
<label class="form-label text-end">Number of test days *</label>
<cfif qPlan.blnFree>
Expand All @@ -92,10 +91,19 @@
</small>
</div>
<div class="col-lg-4">
<label class="form-label text-end">Maximum users *</label>
<input type="text" class="form-control text-end" name="max_users" autocomplete="off" maxlength="10" value="#qPlan.intMaxUsers#" placeholder="0" required>
<cfif qPlan.blnFree>
<label class="form-check form-switch" style="cursor: not-allowed;" data-bs-toggle="tooltip" data-bs-placement="top" title="Its a free plan">
<input class="form-check-input" type="checkbox" name="test_days_upgrade" disabled>
<span class="form-label">Test days upgrade</span>
</label>
<cfelse>
<label class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="test_days_upgrade" <cfif qPlan.blnTestDaysUpgrade>checked</cfif>>
<span class="form-label">Test days upgrade</span>
</label>
</cfif>
<small class="form-hint">
Enter 0 if you don't want to use the user limit.
Offer test days when upgrading from a free to a paid plan.
</small>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions www/backend/core/views/sysadmin/plans.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<div class="card-body">
<p>
<cfif qPlanGroups.recordCount>
Here you can configure your plans and prices. The <b>default plan</b> indicates that it will be activated immediately when a new registration is made.
Here you can configure your plans and prices. The <b>default plan</b> indicates that it will be activated immediately when a new registration is made without choosing a plan.
<cfelse>
<span class="text-red">You need at least one plan group before you can create plans. <a href="#application.mainURL#/sysadmin/plangroups"><i class="fas fa-long-arrow-alt-right"></i> Manage plan groups</a></span>
</cfif>
Expand Down Expand Up @@ -154,7 +154,7 @@
</div>
</div>
</cfoutput>


</div>

Expand Down

0 comments on commit a18135e

Please sign in to comment.