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 / view.html.php
vikappointments / admin / views / ratestest Last commit date
tmpl 2 days ago index.html 2 days ago view.html.php 2 days ago
view.html.php
190 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 /**
15 * VikAppointments rates test view.
16 *
17 * @since 1.6
18 */
19 class VikAppointmentsViewratestest extends JViewVAP
20 {
21 /**
22 * VikAppointments view display method.
23 *
24 * @return void
25 */
26 function display($tpl = null)
27 {
28 $app = JFactory::getApplication();
29 $input = $app->input;
30 $dbo = JFactory::getDbo();
31
32 $layout = $input->get('layout');
33
34 $args = array();
35
36 if ($layout == 'quick')
37 {
38 /**
39 * QUICK LAYOUT
40 */
41
42 $args['id_service'] = $input->getUint('id_service', 0);
43 $args['id_employee'] = $input->getUint('id_employee', 0);
44 $args['checkin'] = $input->getString('checkin', '');
45 $args['people'] = $input->getUint('people', 1);
46
47 $args['id_user'] = $input->getUint('uid', 0);
48 $args['juser'] = $input->getUint('jid', 0);
49 $args['usergroup'] = $input->getUint('usergroup', 0);
50
51 $service = new stdClass;
52
53 $q = $dbo->getQuery(true)
54 ->select($dbo->qn(array('max_capacity', 'priceperpeople')))
55 ->from($dbo->qn('#__vikappointments_service'))
56 ->where($dbo->qn('id') . ' = ' . $args['id_service']);
57
58 $dbo->setQuery($q, 0, 1);
59 $service = $dbo->loadObject();
60
61 if (!$service)
62 {
63 throw new Exception('Service not found', 404);
64 }
65
66 $trace = array('debug' => array());
67
68 if ($args['usergroup'])
69 {
70 // inject property to force usergroup
71 $trace['usergroup'] = $args['usergroup'];
72 }
73 else if ($args['juser'])
74 {
75 // inject property to force the usergroup
76 // related to the specified Joomla user
77 $trace['id_user'] = $args['juser'];
78 }
79 else if ($args['id_user'])
80 {
81 // inject property to force the usergroup
82 // related to the specified customer
83 $q = $dbo->getQuery(true)
84 ->select($dbo->qn('jid'))
85 ->from($dbo->qn('#__vikappointments_users'))
86 ->where($dbo->qn('id') . ' = ' . $args['id_user']);
87
88 $dbo->setQuery($q, 0, 1);
89 $trace['id_user'] = (int) $dbo->loadResult();
90 }
91
92 // auto-calculate the rate for the given parameters
93 $rate = VAPSpecialRates::getRate($args['id_service'], $args['id_employee'], $args['checkin'], $args['people'], $trace);
94
95 $finalcost = $rate;
96
97 if ($service->max_capacity > 1 && $service->priceperpeople == 1)
98 {
99 $finalcost *= $args['people'];
100 }
101
102 // register final cost per user within the trace
103 $trace['finalcostperuser'] = $rate;
104
105 // register final cost within the trace
106 $trace['finalcost'] = $finalcost;
107
108 $this->trace = $trace;
109 $this->rate = $rate;
110 $this->finalCost = $finalcost;
111
112 $this->setLayout($layout);
113 }
114 else
115 {
116 /**
117 * DEFAULT LAYOUT
118 */
119
120 $args['id_service'] = $app->getUserState('ratestest.id_service', 0);
121 $args['id_employee'] = $app->getUserState('ratestest.id_employee', 0);
122 $args['usergroup'] = $app->getUserState('ratestest.usergroup', 0);
123 $args['checkin'] = $app->getUserState('ratestest.checkin', null);
124 $args['people'] = $app->getUserState('ratestest.people', 1);
125 $args['debug'] = $app->getUserState('ratestest.debug', 0);
126
127 // get services
128
129 $services = array();
130
131 $q = $dbo->getQuery(true)
132 ->select($dbo->qn(array('s.id', 's.name', 's.id_group', 's.max_capacity', 's.min_per_res', 's.max_per_res', 's.priceperpeople')))
133 ->select($dbo->qn('g.name', 'group_name'))
134 ->from($dbo->qn('#__vikappointments_service', 's'))
135 ->leftjoin($dbo->qn('#__vikappointments_group', 'g') . ' ON ' . $dbo->qn('s.id_group') . ' = ' . $dbo->qn('g.id'))
136 ->order(array(
137 $dbo->qn('g.ordering') . ' ASC',
138 $dbo->qn('s.ordering') . ' ASC',
139 ));
140
141 $dbo->setQuery($q);
142
143 foreach ($dbo->loadObjectList() as $s)
144 {
145 $id_group = $s->id_group <= 0 ? 0 : (int) $s->id_group;
146
147 if (!isset($services[$id_group]))
148 {
149 $group = new stdClass;
150 $group->id = $id_group;
151 $group->name = $s->group_name;
152 $group->list = array();
153
154 $services[$id_group] = $group;
155 }
156
157 $range = array(1, 1);
158
159 if ($s->max_capacity > 1)
160 {
161 $range = array($s->min_per_res, $s->max_per_res);
162 }
163
164 $service = new stdClass;
165 $service->id = $s->id;
166 $service->name = $s->name;
167 $service->capacity = $range;
168 $service->priceperpeople = $s->priceperpeople;
169
170 $services[$id_group]->list[] = $service;
171 }
172
173 if (isset($services[0]))
174 {
175 // always move services without group at the end of the list
176 $tmp = $services[0];
177 unset($services[0]);
178 $services[0] = $tmp;
179 }
180
181 $this->services = $services;
182 }
183
184 $this->args = $args;
185
186 // display the template (default.php)
187 parent::display($tpl);
188 }
189 }
190