Open MrHinsh opened 1 month ago
GTP converts this to JS as:
// Helper function to calculate student fee
function calculateStudentGraduatedFee(studentsChargable, rateStudentDay, days) {
let studentFee = 0;
if (studentsChargable > 0) {
let baseStudentDayModifier = 2;
for (let si = 1; si <= studentsChargable; si++) {
let baseStudentDayRate = (((baseStudentDayModifier * 2) / 10) + 1) * rateStudentDay;
studentFee += baseStudentDayRate * days;
if (si % 6 === 0) {
baseStudentDayModifier++;
}
}
}
return studentFee;
}
// Helper function to calculate consulting fees
function calculateConsultingFees(baseRateDay, baseDays, traveldays) {
return baseRateDay * (baseDays + traveldays);
}
// Helper function to calculate consulting role modifier
function calculateConsultingRoleModifier(role) {
const roleModifiers = {
training: 3.125,
strategic: 1.5625,
leadership: 1.3333,
tactical: 0.75,
admin: 0.5
};
return roleModifiers[role.toLowerCase()] || 1;
}
// Helper function to calculate consulting level modifier
function calculateConsultingLevelModifier(level) {
const levelModifiers = {
"1": 0.5,
"2": 0.7,
"3": 0.8,
"4": 0.9,
"5": 1
};
return levelModifiers[level] || -1;
}
// Main function to calculate consulting rates
function consultingRates(params) {
const defaults = {
currencySource: "USD", // default currency, replace with actual logic if needed
currencyTarget: "USD", // replace with actual logic
role: "",
level: "5",
hours: 8,
traveldays: 0,
ratemodifyer: "default",
percentage: 100,
wrap: 1,
debug: 0
};
params = Object.assign(defaults, params);
const baseRate = 275;
const baseDays = params.hours / 8;
const baseRateDay = baseRate * 8;
let roleModifier = calculateConsultingRoleModifier(params.role);
let levelModifier = calculateConsultingLevelModifier(params.level);
let outTotal = calculateConsultingFees(baseRateDay, baseDays, params.traveldays);
outTotal *= levelModifier;
outTotal *= roleModifier;
const percentageAsDecimal = params.percentage / 100;
outTotal *= percentageAsDecimal;
return outputRateToHtml(outTotal, params.wrap, params.debug, "");
}
// Main function to calculate display rate
function displayRate2021(params) {
const defaults = {
currencySource: "USD",
currencyTarget: "USD",
scope: "private",
mode: "direct",
delivery: "immersive",
hours: 8,
students: 0,
location: "remote",
traveldays: 0,
coursewarecap: 10,
rate: 200,
ratemodifyer: "default",
output: "total",
percentage: 100,
wrap: 1,
flag: "",
debug: 0
};
params = Object.assign(defaults, params);
let baseRate = 210;
let rateModifier = params.ratemodifyer.toLowerCase();
switch (rateModifier) {
case "advanced":
case "premium":
case "3":
baseRate *= 1.5;
break;
case "intermediate":
case "expert":
case "2":
baseRate *= 1.25;
break;
case "introductory":
case "0":
baseRate *= 0.75;
break;
default:
break;
}
switch (params.delivery.toLowerCase()) {
case "immersive":
baseRate *= params.scope === "private" ? 1.5 : 1;
break;
case "traditional":
baseRate *= params.scope === "private" ? 1.25 : 0.8;
break;
default:
break;
}
const baseRateTraining = baseRate * 2.5;
const baseRateStudentDay = 125;
const BaseRateCoursewareDay = 75;
const baseDays = params.hours / 8;
const baseRateDay = baseRate * 8;
const baseRateTrainingDay = baseRateTraining * 8;
let trainerTotal = baseRateTrainingDay * baseDays;
if (params.location !== "remote") {
trainerTotal += baseRateTrainingDay * params.traveldays;
}
switch (params.mode.toLowerCase()) {
case "public":
trainerTotal *= 0.75;
break;
case "reseller":
trainerTotal *= 0.75;
break;
case "peer":
trainerTotal *= 0.7;
break;
case "cotrainer":
trainerTotal *= 0.4;
break;
default:
break;
}
let studentFee = 0;
let coursewareTotal = 0;
if (params.students > 0) {
coursewareTotal = (params.students > params.coursewarecap ? params.coursewarecap : params.students) * (BaseRateCoursewareDay * baseDays);
const studentsChargable = Math.max(0, params.students - 12);
switch (params.mode.toLowerCase()) {
case "direct":
studentFee = calculateStudentGraduatedFee(studentsChargable, baseRateStudentDay, baseDays);
break;
case "reseller":
studentFee = studentsChargable * (baseRateStudentDay * baseDays);
break;
case "peer":
studentFee = calculateStudentGraduatedFee(studentsChargable, baseRateStudentDay, baseDays) * 0.7;
break;
case "cotrainer":
studentFee = calculateStudentGraduatedFee(studentsChargable, baseRateStudentDay, baseDays) * 0.4;
break;
default:
break;
}
}
let additionalTrainerFee = 0;
if (params.scope === "public" && params.students > 20) {
additionalTrainerFee = baseRateDay * baseDays;
}
let outTotal = 0;
switch (params.output.toLowerCase()) {
case "traineronly":
outTotal = trainerTotal;
break;
case "courseware":
outTotal = coursewareTotal;
break;
case "students":
outTotal = studentFee;
break;
case "trainer":
outTotal = additionalTrainerFee;
break;
default:
outTotal = trainerTotal + coursewareTotal + studentFee + additionalTrainerFee;
break;
}
outTotal *= params.percentage / 100;
return outputRateToHtml(outTotal, params.wrap, params.debug, "");
}
// Helper function to output the final rate in HTML
function outputRateToHtml(outTotal, wrap, debug, debugData) {
if (wrap === 0) {
return Math.round(outTotal);
}
let outputData = outTotal;
if (wrap >= 2) {
outputData = String(outputData).replace(/<bdi>/g, "").replace(/<\/bdi>/g, "");
}
return debug === 1 ? `<span title='${debugData}'>${outputData}</span>` : outputData;
}
The rate calculator is based off my previous work in PHP to create this: