1/**
2 * Usage: [displayrate2021 location="remote|onsite" mode="public|direct|reseller|peer|cotrainer" scope="private|public" type="training|consulting" hours='8' rate='200' ratemodifyer='none|Introductory|Beginner|Intermediate|Advanced' students='0' traveldays="1" coursewarecap="10", output="total|traineronly|courseware|students|trainer" percentage="0"]
3 */
4
5function calculateStudentGraduatedFee($studentsChargable, $rateStudentDay, $days) {
6 $studentFee = 0;
7 if ($studentsChargable > 0)
8 {
9 //echo "Students Chargeable: $studentsChargable <br />";
10 $baseStudentDayModifyer = 2;
11 for ($si = 1; $si < $studentsChargable+1; $si++)
12 {
13 $baseStudentDayRate = ((($baseStudentDayModifyer*2) / 10)+1) * $rateStudentDay;
14 //echo "Student[$si]:";
15 $studentFee = $studentFee + (($baseStudentDayRate) * $days);
16 //echo "[$baseStudentDayModifyer]$studentFee";
17 if ($si % 6 == 0)
18 {
19 $baseStudentDayModifyer++;
20 //echo "[increment]";
21 }
22 //echo "<br />";
23 }
24 }
25 return $studentFee;
26}
27
28function calculateConsultingFees($mode, $baseRateDay, $baseDays, $traveldays) {
29 $consultingTotal = 0;
30 $consultingTotal= $baseRateDay * ($baseDays + $traveldays);
31 return $consultingTotal;
32}
33
34
35function calculateConsultingRoleModifier($role)
36{
37 $roleModifyer = 0;
38 switch (strtolower($role))
39 {
40 case "training":
41 $roleModifyer = 3.125;
42 break;
43 case "strategic":
44 $roleModifyer = 1.5625;
45 break;
46 case "leadership":
47 $roleModifyer = 1.3333;
48 break;
49 case "tactical":
50 $roleModifyer = 0.75;
51 break;
52 case "admin":
53 $roleModifyer = 0.5;
54 break;
55 default:
56 $roleModifyer = 1;
57 break;
58 }
59 return $roleModifyer;
60}
61
62function calculateConsultingLevelModifyer($level)
63{
64 $levelModifyer = 0;
65 switch ($level)
66 {
67 case "1":
68 $levelModifyer = 0.5;
69 break;
70 case "2":
71 $levelModifyer = 0.7;
72 break;
73 case "3":
74 $levelModifyer = 0.8;
75 break;
76 case "4":
77 $levelModifyer = 0.9;
78 break;
79 case "5":
80 $levelModifyer = 1;
81 break;
82 default:
83 $levelModifyer = -1;
84 break;
85 }
86 return $levelModifyer;
87}
88
89function consultingRates($params, $content = null) {
90 // default parameters
91 extract(shortcode_atts(array(
92 'currancySource' => get_option('woocommerce_currency'),
93 'currancyTarget' => \get_woocommerce_currency(),
94 'role' => "",
95 'level' => "5",
96 'hours' => 8,
97 'traveldays' => 0,
98 'ratemodifyer' => 'default',
99 'percentage' => 100,
100 'wrap' => 1,
101 'debug' => 0
102 ), $params));
103
104 $debugData .= "[consultingRates currancySource=$currancySource currancyTarget=$currancyTarget role=$role level=$level hours=$hours traveldays=$traveldays ratemodifyer=$ratemodifyer ]" ;
105
106 $debugData = "";
107 $outTotal = 0;
108 $baseRate = 275;
109 $baseDays = ($hours /8);
110 $baseRateDay = $baseRate * 8;
111
112 $debugData .= "[calculateConsultingRoleModifier role[$role] ";
113 $roleModifyer = calculateConsultingRoleModifier($role);
114 $debugData .= "roleModifyer[$roleModifyer] ] ";
115
116 $debugData .= "[calculateConsultingLevelModifyer level[$level] ";
117 $levelModifyer = calculateConsultingLevelModifyer($level);
118 $debugData .= "levelModifyer[$levelModifyer] ] ";
119
120 $debugData .= "[calculateConsultingFees baseRateDay[$baseRateDay] baseDays[$baseDays] traveldays[$traveldays] ";
121 $outTotal = calculateConsultingFees("direct", $baseRateDay, $baseDays, $traveldays);
122 $debugData .= "outTotal[$outTotal] ] ";
123
124 $outTotal = $outTotal * $levelModifyer;
125 $outTotal = $outTotal * $roleModifyer;
126 $percentageAsDecimal = $percentage / 100;
127 $outTotal = $outTotal * $percentageAsDecimal;
128 $debugData = $debugData . " outTotal[$outTotal] " ;
129 return outputRateToHtml($outTotal, $wrap, $debug, $debugData);
130}
131
132add_shortcode('consultingRates','consultingRates');
133
134
135function displayrate2021($params, $content = null) {
136 // default parameters
137 extract(shortcode_atts(array(
138 'currancySource' => get_option('woocommerce_currency'),
139 'currancyTarget' => \get_woocommerce_currency(),
140 'scope' => 'private',
141 'mode' => 'direct',
142 'delivery' => "immersive",
143 'hours' => 8,
144 'students' => 0,
145 'location' => 'remote',
146 'traveldays' => 0,
147 'coursewarecap' => 10,
148 'rate' => 200,
149 'ratemodifyer' => 'default',
150 'output' => 'total',
151 'percentage' => 100,
152 'wrap' => 1,
153 'flag' => '',
154 'debug' => 0
155 ), $params));
156 //
157//$fmt = new NumberFormatter( 'es_MX', NumberFormatter::CURRENCY );
158//$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, $currancyTarget);
159//$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
160
161 $baseRate = 210;//$rate; // GBP/hour
162 $ratemodifyerlower = strtolower($ratemodifyer);
163 switch (strtolower($ratemodifyerlower))
164 {
165 case "advanced":
166 case "premium":
167 case "3":
168 $baseRate = $baseRate * 1.5;
169 break;
170 case "intermediate":
171 case "expert":
172 case "2":
173 $baseRate = $baseRate * 1.25;
174 break;
175 case "introductory":
176 case "0":
177 $baseRate = $baseRate * 0.75;
178 break;
179 default:
180 //do nothing
181 }
182
183 switch (strtolower($delivery))
184 {
185 case "immersive":
186 if ($scope == "private")
187 {
188 $baseRate = $baseRate * 1.50;
189 } else
190 {
191 $baseRate = $baseRate * 1;
192 }
193 break;
194 case "traditional":
195 if ($scope == "private")
196 {
197 $baseRate = $baseRate * 1.25;
198 } else
199 {
200 $baseRate = $baseRate * 0.8;
201 }
202 break;
203 default:
204 //do nothing
205 }
206
207
208 $baseRateTraining = $baseRate * 2.5;
209 $baseRateStudentDay = 125; // GBP/student/day
210 $BaseRateCoursewareDay = 75; // GBP/student/day
211 //echo "Courseware: $BaseRateCoursewareDay <br />";
212
213 $baseRateResellerModifyer = 0.75;
214 $baseRateTrainingResellerModifyer = 0.75;
215 $baseRatePeerModifyer = 0.70;
216 $baseRateTrainingPeerModifyer = 0.60;
217 $baseRateCoTrainerModifyer = 0.40;
218 $baseRateTrainingCoTrainerModifyer = 0.40;
219
220 $baseDays = ($hours /8);
221 $baseRateDay = $baseRate * 8;
222 $baseRateTrainingDay = $baseRateTraining * 8;
223
224 $outTotal = 0;
225
226 $additionalTrainerFee = 0;
227
228 $trainingTotal = 0;
229 $StudentExtra = 0;
230 // Trainer Fee
231 $trainerTotal = $baseRateTrainingDay * $baseDays;
232 if($location!=="remote")
233 {
234 $trainerTotal = $trainerTotal + ($baseRateTrainingDay * $traveldays);
235 }
236 // modifyer for Mode
237 //echo "[mode:$mode][START][trainerTotal=$trainerTotal]<br />";
238 switch (strtolower($mode))
239 {
240 case "direct":
241 //do nothing
242 break;
243 case "public":
244 $trainerTotal = (($baseRateTrainingDay /8) * $baseDays) * 0.75; // This applies a 70% modifyer to the public market rate as it was too high.
245 break;
246 case "reseller":
247 // discount for reselling
248 $trainerTotal = $trainerTotal * $baseRateTrainingResellerModifyer;
249 break;
250 case "peer":
251 $trainerTotal = $trainerTotal * $baseRateTrainingPeerModifyer;
252 break;
253 case "cotrainer":
254 $trainerTotal = $trainerTotal * $baseRateTrainingCoTrainerModifyer;
255 break;
256 default:
257 $trainerTotal = -1;
258 }
259 //echo "[mode:$mode][END][trainerTotal=$trainerTotal]<br />";
260
261 // Add per student fees
262 $studentFee = 0;
263 $coursewareTotal = 0;
264 if ($students > 0)
265 {
266 // courseware fee
267 $coursewareTotal = 0;
268 if ($scope == "private" && $students > $coursewarecap)
269 {
270 $coursewareTotal = $coursewarecap * ($BaseRateCoursewareDay * $baseDays);
271 }
272 else
273 {
274 $coursewareTotal = $students * ($BaseRateCoursewareDay * $baseDays);
275 }
276
277 //students
278 $studentsChargable = 0;
279 if ($students > 12)
280 {
281 $studentsChargable = ($students-12);
282 }
283
284 // modifyer for Mode
285 switch (strtolower($mode))
286 {
287 case "direct":
288 // escelating student fee per 4
289 $studentFee = calculateStudentGraduatedFee($studentsChargable,$baseRateStudentDay, $baseDays);
290 break;
291 case "reseller":
292 // discount for reselling
293 // simple all students at same rate
294 $studentFee = $studentsChargable * ($baseRateStudentDay * $baseDays) ;
295 break;
296 case "peer":
297 // discount for reselling
298 $studentFee = calculateStudentGraduatedFee($studentsChargable,$baseRateStudentDay, $baseDays) * $baseRateTrainingPeerModifyer;
299 break;
300 case "cotrainer":
301 $studentFee = calculateStudentGraduatedFee($studentsChargable,$baseRateStudentDay, $baseDays) * $baseRateTrainingCoTrainerModifyer;
302 break;
303 default:
304 $studentFee = -1;
305 }
306
307
308
309 // Add second trainer
310 $additionalTrainerFee = 0;
311 if ($scope == "public" && $students > 20)
312 {
313 $additionalTrainerFee = ($baseRateDay * $baseDays);
314 }
315 }
316
317 switch (strtolower($output))
318 {
319 case "traineronly":
320 $outTotal = $trainerTotal;
321 break;
322 case "courseware":
323 $outTotal = $coursewareTotal;
324 break;
325 case "students":
326 $outTotal = $studentFee;
327 break;
328 case "trainer":
329 $outTotal = $additionalTrainerFee;
330 break;
331 default:
332 $outTotal = $trainerTotal + $coursewareTotal + $studentFee + $additionalTrainerFee;
333 }
334
335
336 $percentageAsDecimal = $percentage / 100;
337 $outTotal = $outTotal * $percentageAsDecimal;
338 //$outTotal = $percentage;
339 $debugData = "currancySource[$currancySource] currancyTarget[$currancyTarget] flag[$flag] scope[$scope] mode[$mode] hours[$hours] students[$students] location[$location] traveldays[$traveldays] coursewarecap[$coursewarecap] rate[$rate] ratemodifyer[$ratemodifyer] output[$output] outTotal[$outTotal] " ;
340 if ($flag == "raw" || $wrap == 0 )
341 {
342 return round($outTotal);
343 }
344 return outputRateToHtml($outTotal, $wrap, $debug, $debugData);
345}
346
347function outputRateToHtml($outTotal, $wrap, $debug, $debugData) {
348 // currancy convertion and return
349 //$outTotal = \WOOMC\API::convert($outTotal, $currancyTarget, $currancySource);
350 //
351
352 $flag = $_GET["flag"];
353 //echo "Flag: " . $flag . "<br />";
354 if ($flag == "raw" || $wrap == 0 )
355 {
356 return round($outTotal);
357 }
358 $outputData = "";
359 if ($wrap >= 1)
360 {
361 $outTotal = do_shortcode( '[wcpbc_convert amount="' . $outTotal . '"]');
362 //$outTotal = \wc_price($outTotal,array('currency' => $currancyTarget,'decimals' => null));
363 if ($wrap >= 2)
364 {
365 $outTotal = str_replace('<bdi>', '', $outTotal);
366 $outTotal = str_replace('</bdi>', '', $outTotal);
367 }
368 }
369 if ($debug == 1)
370 {
371 $outputData = "<span title='$debugData'>$outTotal</span>";
372 }
373 else
374 {
375 $outputData = $outTotal;
376 }
377 return $outputData;
378}
379
380
381add_shortcode('displayrate2021','displayrate2021');