PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / ratestest / tmpl / default.php
vikappointments / admin / views / ratestest / tmpl Last commit date
default.php 6 days ago index.html 6 days ago quick.php 6 days ago
default.php
454 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 JHtml::fetch('vaphtml.assets.select2');
15 JHtml::fetch('vaphtml.assets.fontawesome');
16
17 $args = $this->args;
18
19 $vik = VAPApplication::getInstance();
20
21 ?>
22
23 <div class="ratestest" style="padding: 10px;">
24
25 <form action="index.php" method="post" name="adminForm" id="adminForm">
26
27 <!-- MAIN -->
28
29 <div class="row-fluid">
30
31 <!-- SEARCH -->
32
33 <div class="span6">
34 <?php echo $vik->openEmptyFieldset(); ?>
35
36 <!-- SERVICE - Select -->
37
38 <?php echo $vik->openControl(JText::translate('VAPORDERSERVICE') . '*'); ?>
39 <select name="id_service" id="vap-service-sel" class="required">
40 <option></option>
41 <?php
42 foreach ($this->services as $group)
43 {
44 ?>
45 <optgroup label="<?php echo $group->name ? $group->name : JText::translate('VAPSERVICENOGROUP'); ?>">
46 <?php
47 foreach ($group->list as $service)
48 {
49 ?>
50 <option
51 value="<?php echo $service->id; ?>"
52 data-min="<?php echo $service->capacity[0]; ?>"
53 data-max="<?php echo $service->capacity[1]; ?>"
54 data-perpeople="<?php echo $service->priceperpeople; ?>"
55 <?php echo ($args['id_service'] == $service->id ? 'selected="selected"' : ''); ?>
56 ><?php echo $service->name; ?></option>
57 <?php
58 }
59 ?>
60 </optgroup>
61 <?php
62 }
63 ?>
64 </select>
65 <?php echo $vik->closeControl(); ?>
66
67 <!-- EMPLOYEE - Select -->
68
69 <?php echo $vik->openControl(JText::translate('VAPORDEREMPLOYEE')); ?>
70 <select name="id_employee" id="vap-employee-sel" disabled>
71 <option></option>
72 </select>
73 <?php echo $vik->closeControl(); ?>
74
75 <!-- USER GROUPS - Select -->
76
77 <?php
78 $groups = array();
79 $groups[] = JHtml::fetch('select.option', '', '');
80
81 $groups = array_merge($groups, JHtml::fetch('user.groups', true));
82
83 echo $vik->openControl(JText::translate('VAPUSERGROUPS')); ?>
84 <select name="usergroup" id="vap-usergroup-sel">
85 <?php echo JHtml::fetch('select.options', $groups); ?>
86 </select>
87 <?php echo $vik->closeControl(); ?>
88
89 <!-- CHECKIN - Calendar -->
90
91 <?php
92 $attrs = array(
93 'showTime' => 1,
94 'class' => 'required',
95 );
96
97 $date = $args['checkin'] ? $args['checkin'] : VikAppointments::now();
98
99 echo $vik->openControl(JText::translate('VAPMANAGERESERVATION26') . '*');
100 echo $vik->calendar($date, 'checkin', 'checkin', null, $attrs);
101 echo $vik->closeControl();
102 ?>
103
104 <!-- PEOPLE - Select -->
105
106 <?php echo $vik->openControl(JText::translate('VAPMANAGERESERVATION25')); ?>
107 <select name="people" id="vap-people-sel" disabled>
108 <option value="1">1</option>
109 </select>
110 <?php echo $vik->closeControl(); ?>
111
112 <!-- DEBUG - Checkbox -->
113
114 <?php
115 $yes = $vik->initRadioElement('', '', $args['debug']);
116 $no = $vik->initRadioElement('', '', !$args['debug']);
117
118 echo $vik->openControl('Debug:');
119 echo $vik->radioYesNo('debug', $yes, $no, true);
120 echo $vik->closeControl();
121 ?>
122
123 <!-- SUBMIT - Button -->
124
125 <?php echo $vik->openControl(''); ?>
126 <button type="button" class="btn" onclick="submitRateForm(this);">
127 <?php echo JText::translate('VAPTESTRATES'); ?>
128 </button>
129 <?php echo $vik->closeControl(); ?>
130
131 <?php echo $vik->closeEmptyFieldset(); ?>
132 </div>
133
134 <!-- RESULT -->
135
136 <div class="span6" id="result-wrap" style="display: none;">
137 <?php echo $vik->openEmptyFieldset(); ?>
138
139 <table class="rates-table table" id="rates-table" style="display: none;">
140 <thead>
141 <tr>
142 <th><?php echo JText::translate('JGRID_HEADING_ID'); ?></th>
143 <th><?php echo JText::translate('JDETAILS'); ?></th>
144 <th style="text-align:center;"><?php echo JText::translate('VAPCHDISC'); ?></th>
145 </tr>
146 </thead>
147
148 <tbody></tbody>
149
150 <tfoot></tfoot>
151 </table>
152
153 <?php echo $vik->closeEmptyFieldset(); ?>
154 </div>
155
156 </div>
157
158 <!-- DEBUG -->
159
160 <div class="row-fluid">
161
162 <div style="display: none;" id="debug-wrap">
163 <?php echo $vik->openFieldset(JText::translate('VAPDEBUGRATESFIELDSET')); ?>
164
165 <table class="rates-table table" id="debug-table">
166 <thead>
167 <tr>
168 <th><?php echo JText::translate('JGRID_HEADING_ID'); ?></th>
169 <th><?php echo JText::translate('JDETAILS'); ?></th>
170 <th><?php echo JText::translate('ERROR'); ?></th>
171 </tr>
172 </thead>
173
174 <tbody></tbody>
175
176 <tfoot></tfoot>
177 </table>
178
179 <?php echo $vik->closeFieldset(); ?>
180 </div>
181
182 </div>
183
184 </form>
185
186 </div>
187
188 <?php
189 JText::script('VAPPAYMENTPOSOPT1');
190 JText::script('VAPCONNECTIONLOSTERROR');
191 JText::script('VAPBASECOST');
192 JText::script('VAPCOSTPP');
193 JText::script('VAPFINALCOST');
194 JText::script('VAPDEBUGRATESFOOTER');
195 ?>
196
197 <script>
198
199 var validator = new VikFormValidator('#adminForm');
200 var EMPLOYEES_POOL = {};
201
202 var EMPLOYEE_ID = 0;
203
204 jQuery(function($) {
205
206 $('#vap-service-sel').select2({
207 placeholder: '--',
208 allowClear: false,
209 width: '90%',
210 });
211
212 $('#vap-usergroup-sel').select2({
213 placeholder: '--',
214 allowClear: true,
215 width: '90%',
216 });
217
218 initEmployeeDropdown();
219
220 initPeopleDropdown();
221
222 //
223
224 $('#vap-service-sel').on('change', function() {
225 var sel = $(this).find('option:selected');
226
227 var min = parseInt(sel.data('min'));
228 var max = parseInt(sel.data('max'));
229 var id = parseInt($(this).val());
230
231 buildPeopleDropdown(min, max);
232
233 buildEmployeeDropdown(id);
234 });
235
236 function initEmployeeDropdown() {
237 $('#vap-employee-sel').select2({
238 placeholder: Joomla.JText._('VAPPAYMENTPOSOPT1'),
239 allowClear: true,
240 width: '90%',
241 });
242
243 if (EMPLOYEE_ID > 0) {
244 $('#vap-employee-sel').select2('val', EMPLOYEE_ID);
245 // unset EMPLOYEE ID to avoid re-using every time the service is changed
246 EMPLOYEE_ID = 0;
247 }
248 }
249
250 function initPeopleDropdown() {
251 $('#vap-people-sel').select2({
252 minimumResultsForSearch: -1,
253 allowClear: false,
254 width: '90%',
255 });
256 }
257
258 function buildPeopleDropdown(min, max) {
259 var options = '';
260
261 for (var i = min; i <= max; i++) {
262 options += '<option value="' + i + '">' + i + '</option>\n';
263 }
264
265 $('#vap-people-sel').html(options);
266 $('#vap-people-sel').attr('disabled', min < max ? false : true);
267
268 $('#vap-people-sel').select2('destroy');
269 initPeopleDropdown();
270 }
271
272 function buildEmployeeDropdown(id) {
273 $('#vap-employee-sel').attr('disabled', true);
274
275 if (EMPLOYEES_POOL.hasOwnProperty(id)) {
276 renderEmployeeDropdown(EMPLOYEES_POOL[id]);
277 return;
278 }
279
280 UIAjax.do(
281 '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=service.employeesajax'); ?>',
282 {
283 id_ser: id,
284 all: true,
285 },
286 (obj) => {
287 EMPLOYEES_POOL[id] = obj;
288
289 renderEmployeeDropdown(EMPLOYEES_POOL[id]);
290 },
291 (err) => {
292 console.log(err);
293 alert(Joomla.JText._('VAPCONNECTIONLOSTERROR'));
294 }
295 );
296 }
297
298 function renderEmployeeDropdown(employees) {
299 var options = '<option></option>';
300
301 for (var i = 0; i < employees.length; i++) {
302 options += '<option value="'+employees[i].id+'" data-rate="'+employees[i].rate+'">'+employees[i].nickname+'</option>\n';
303 }
304
305 $('#vap-employee-sel').html(options);
306 $('#vap-employee-sel').attr('disabled', false);
307
308 $('#vap-employee-sel').select2('destroy');
309 initEmployeeDropdown();
310 }
311
312 // fill data with user states
313 <?php if ($args['id_service'] > 0) { ?>
314 $('#vap-service-sel').trigger('change');
315 $('#vap-people-sel').select2('val', <?php echo $args['people']; ?>);
316 EMPLOYEE_ID = <?php echo (int) $args['id_employee']; ?>;
317 <?php } ?>
318
319 });
320
321 function submitRateForm(btn) {
322 jQuery('#result-wrap').show();
323
324 jQuery('#rates-table').hide();
325 jQuery('#debug-wrap').hide();
326
327 if (!validator.validate()) {
328 return false;
329 }
330
331 jQuery(btn).attr('disabled', true);
332
333 UIAjax.do(
334 '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=rate.testajax'); ?>',
335 jQuery('#adminForm').serialize(),
336 (obj) => {
337 // for debug purposes
338 console.log(obj);
339
340 var rates = [];
341 if (obj[1].hasOwnProperty('rates')) {
342 rates = obj[1].rates;
343 }
344
345 buildRatesTable(obj[0], obj[1].basecost, rates);
346
347 if (obj[1].hasOwnProperty('debug')) {
348 buildDebugTable(obj[1].debug);
349 }
350
351 jQuery(btn).attr('disabled', false);
352 },
353 (err) => {
354 console.log(err);
355 alert(Joomla.JText._('VAPCONNECTIONLOSTERROR'));
356
357 jQuery(btn).attr('disabled', false);
358 }
359 );
360 }
361
362 function buildRatesTable(finalCost, baseCost, rates) {
363 var table = jQuery('#rates-table');
364 var tbody = '';
365 var tfoot = '';
366
367 // table body
368 tbody += createTableRow('', Joomla.JText._('VAPBASECOST'), baseCost);
369
370 var attrs = {class: 'rate-child'};
371
372 for (var i = 0; i < rates.length; i++) {
373 var details = rates[i].name;
374 if (rates[i].description.length) {
375 details = [details, rates[i].description];
376 }
377
378 tbody += createTableRow(rates[i].id, details, rates[i].charge, attrs);
379 }
380
381 // table footer
382 var guests = 1;
383
384 var perpeople = parseInt(jQuery('#vap-service-sel option:selected').data('perpeople'));
385 var capacity = parseInt(jQuery('#vap-service-sel option:selected').data('max'));
386
387 if (perpeople == 1 && capacity > 1) {
388 // cost per person
389 tfoot += createTableRow('', Joomla.JText._('VAPCOSTPP'), finalCost);
390 guests = parseInt(jQuery('#vap-people-sel').val());
391 }
392
393 tfoot += createTableRow('', Joomla.JText._('VAPFINALCOST'), finalCost * guests, {class: 'final-cost'});
394
395 // build table and show
396 table.find('tbody').html(tbody);
397 table.find('tfoot').html(tfoot);
398
399 table.show();
400 }
401
402 function buildDebugTable(rows) {
403 var table = jQuery('#debug-table');
404 var tbody = '';
405 var tfoot = '';
406
407 for (var i = 0; i < rows.length; i++) {
408 var details = rows[i].name;
409 if (rows[i].description.length) {
410 details += '<div><small>' + rows[i].description + '</small></div>'
411 }
412
413 tbody += '<tr>\n'+
414 '<td class="debug-id">' + rows[i].id + '</td>\n'+
415 '<td class="debug-details">' + details + '</td>\n'+
416 '<td class="debug-error">' + rows[i].error + '</td>\n'+
417 '</tr>\n';
418 }
419
420 tfoot += '<tr><td colspan="3"><i class="fas fa-life-ring" style="margin-right: 5px;"></i> ' + Joomla.JText._('VAPDEBUGRATESFOOTER') + '</td></tr>';
421
422 // build table and show
423 table.find('tbody').html(tbody);
424 table.find('tfoot').html(tfoot);
425 jQuery('#debug-wrap').show();
426 }
427
428 function createTableRow(id, details, cost, attrs) {
429 var _attrs = '';
430
431 if (attrs) {
432 for (var k in attrs) {
433 _attrs += ' ' + k + '="' + attrs[k] + '"';
434 }
435 }
436
437 var details_html = details;
438
439 if (typeof details != 'string') {
440 // we have an array containing the name and the description
441
442 details_html = details[0];
443 details_html += '<div><small>' + details[1] + '</small></div>';
444 }
445
446 return '<tr' + _attrs + '>\n'+
447 '<td class="rate-id">' + id + '</td>\n'+
448 '<td class="rate-details">' + details_html + '</td>\n'+
449 '<td class="rate-price">' + VAPCurrency.getInstance().format(cost) + '</td>\n'+
450 '</tr>\n';
451 }
452
453 </script>
454