calendarweek.php
3 years ago
cart.php
1 month ago
confirmapp.php
2 years ago
empattachser.php
4 years ago
empeditcoupon.php
4 years ago
empeditcustfield.php
4 years ago
empeditlocation.php
4 years ago
empeditpay.php
4 years ago
empeditprofile.php
5 months ago
empeditservice.php
4 years ago
empeditwdays.php
4 years ago
emplocwdays.php
4 years ago
emplogin.php
2 years ago
employeesearch.php
2 years ago
employeeslist.php
4 years ago
empmakerecur.php
1 month ago
empmanres.php
1 month ago
empsettings.php
2 years ago
empsubscr.php
4 years ago
empsubscrorder.php
1 year ago
index.html
6 years ago
modules.php
1 year ago
order.php
5 months ago
packages.php
4 years ago
packagesconfirm.php
4 years ago
packagesorder.php
1 year ago
servicesearch.php
2 years ago
subscriptions.php
4 years ago
subscrpayment.php
1 year ago
userprofile.php
5 months ago
waitinglist.php
4 years ago
empmanres.php
423 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 | VAPLoader::import('libraries.employee.area.controller'); |
| 15 | |
| 16 | /** |
| 17 | * Employee area edit reservation controller. |
| 18 | * |
| 19 | * @since 1.6 |
| 20 | */ |
| 21 | class VikAppointmentsControllerEmpmanres extends VAPEmployeeAreaController |
| 22 | { |
| 23 | /** |
| 24 | * Task used to access the creation page of a new record. |
| 25 | * |
| 26 | * @return boolean |
| 27 | * |
| 28 | * @since 1.7 |
| 29 | */ |
| 30 | public function add() |
| 31 | { |
| 32 | $app = JFactory::getApplication(); |
| 33 | $auth = VAPEmployeeAuth::getInstance(); |
| 34 | |
| 35 | $data = array(); |
| 36 | $data['id_service'] = $app->input->getUint('id_ser'); |
| 37 | $data['people'] = $app->input->getUint('people'); |
| 38 | $data['day'] = $app->input->getString('day'); |
| 39 | $data['factor'] = $app->input->getUint('duration_factor', null); |
| 40 | |
| 41 | if (!empty($data['day'])) |
| 42 | { |
| 43 | $h = $app->input->getUint('hour', 0); |
| 44 | $m = $app->input->getUint('min', 0); |
| 45 | |
| 46 | // create date instance adjusted to employee timezone |
| 47 | $date = JFactory::getDate($data['day'] . " $h:$m:00", $auth->timezone); |
| 48 | |
| 49 | // get check-in UTC |
| 50 | $data['checkin_ts'] = $date->toSql(); |
| 51 | } |
| 52 | |
| 53 | // strip missing information |
| 54 | $data = array_filter($data); |
| 55 | |
| 56 | // unset user state for being recovered again |
| 57 | $app->setUserState('vap.emparea.reservation.data', $data); |
| 58 | |
| 59 | // check user permissions |
| 60 | if (!$auth->manageReservation()) |
| 61 | { |
| 62 | // back to main list, not authorised to edit records |
| 63 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 64 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | $this->setRedirect('index.php?option=com_vikappointments&view=empmanres'); |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Task used to access the management page of an existing record. |
| 76 | * |
| 77 | * @return boolean |
| 78 | * |
| 79 | * @since 1.7 |
| 80 | */ |
| 81 | public function edit() |
| 82 | { |
| 83 | $app = JFactory::getApplication(); |
| 84 | $auth = VAPEmployeeAuth::getInstance(); |
| 85 | |
| 86 | $data = array(); |
| 87 | $data['id_service'] = $app->input->getUint('id_ser'); |
| 88 | $data['people'] = $app->input->getUint('people'); |
| 89 | $data['day'] = $app->input->getString('day'); |
| 90 | $data['factor'] = $app->input->getUint('duration_factor', null); |
| 91 | |
| 92 | if (!empty($data['day'])) |
| 93 | { |
| 94 | $h = $app->input->getUint('hour', 0); |
| 95 | $m = $app->input->getUint('min', 0); |
| 96 | |
| 97 | // create date instance adjusted to employee timezone |
| 98 | $date = JFactory::getDate($data['day'] . " $h:$m:00", $auth->timezone); |
| 99 | |
| 100 | // get check-in UTC |
| 101 | $data['checkin_ts'] = $date->toSql(); |
| 102 | } |
| 103 | |
| 104 | // strip missing information |
| 105 | $data = array_filter($data); |
| 106 | |
| 107 | // unset user state for being recovered again |
| 108 | $app->setUserState('vap.emparea.reservation.data', $data); |
| 109 | |
| 110 | $cid = $app->input->getUint('cid', array(0)); |
| 111 | |
| 112 | // check user permissions |
| 113 | if (!$auth->manageReservation($cid[0])) |
| 114 | { |
| 115 | // back to main list, not authorised to edit records |
| 116 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 117 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | $this->setRedirect('index.php?option=com_vikappointments&view=empmanres&cid[]=' . $cid[0]); |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Task used to save the record data set in the request. |
| 129 | * After saving, the user is redirected to the main list. |
| 130 | * |
| 131 | * @return void |
| 132 | * |
| 133 | * @since 1.7 |
| 134 | */ |
| 135 | public function saveclose() |
| 136 | { |
| 137 | if ($this->save()) |
| 138 | { |
| 139 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Save reservation details. |
| 145 | * |
| 146 | * @return void |
| 147 | */ |
| 148 | public function save() |
| 149 | { |
| 150 | $app = JFactory::getApplication(); |
| 151 | $input = $app->input; |
| 152 | $auth = VAPEmployeeAuth::getInstance(); |
| 153 | |
| 154 | // always redirect to login page in case of error |
| 155 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 156 | |
| 157 | /** |
| 158 | * Added token validation. |
| 159 | * |
| 160 | * @since 1.7 |
| 161 | */ |
| 162 | if (!JSession::checkToken()) |
| 163 | { |
| 164 | // back to main list, missing CSRF-proof token |
| 165 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 166 | |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | $id_reservation = $input->getUint('id', 0); |
| 171 | |
| 172 | // check user permissions |
| 173 | if (($id_reservation && !$auth->manageReservation($id_reservation)) || (!$id_reservation && !$auth->createReservation())) |
| 174 | { |
| 175 | // back to main list, not authorised to edit records |
| 176 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 177 | |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | $args = array(); |
| 182 | $args['id'] = $id_reservation; |
| 183 | |
| 184 | // DETAILS |
| 185 | |
| 186 | $args['id_service'] = $input->getUint('id_service'); |
| 187 | $args['checkin_ts'] = $input->getString('checkin_ts'); |
| 188 | $args['people'] = $input->getUint('people', 1); |
| 189 | $args['duration'] = $input->getUint('duration'); |
| 190 | $args['sleep'] = $input->getUint('sleep'); |
| 191 | |
| 192 | $args['validate_availability'] = $input->getBool('validate_availability', false); |
| 193 | |
| 194 | // ORDER |
| 195 | |
| 196 | $args['service_price'] = $input->getFloat('service_price', 0); |
| 197 | $args['service_net'] = $input->getFloat('service_net', 0); |
| 198 | $args['service_tax'] = $input->getFloat('service_tax', 0); |
| 199 | $args['service_gross'] = $input->getFloat('service_gross', 0); |
| 200 | $args['tax_breakdown'] = $input->getString('tax_breakdown'); |
| 201 | |
| 202 | $args['total_net'] = $input->getFloat('total_net', 0); |
| 203 | $args['total_tax'] = $input->getFloat('total_tax', 0); |
| 204 | $args['total_cost'] = $input->getFloat('total_cost', 0); |
| 205 | |
| 206 | $args['status'] = $input->getString('status', ''); |
| 207 | $args['id_payment'] = $input->getUint('id_payment', 0); |
| 208 | $args['id_user'] = $input->getUint('id_user', 0); |
| 209 | |
| 210 | $args['notifycust'] = $input->getBool('notifycust', false); |
| 211 | |
| 212 | // OPTIONS |
| 213 | |
| 214 | // get selected options |
| 215 | $args['options'] = $input->get('option_json', array(), 'array'); |
| 216 | // load deleted options |
| 217 | $args['deletedOptions'] = $input->get('option_deleted', array(), 'uint'); |
| 218 | |
| 219 | // NOTES |
| 220 | |
| 221 | $args['notes'] = JComponentHelper::filterText($input->getRaw('notes', '')); |
| 222 | $args['id_notes'] = $input->getUint('id_notes', 0); |
| 223 | |
| 224 | // get payment model |
| 225 | $model = $this->getModel(); |
| 226 | |
| 227 | // try to save arguments |
| 228 | $id = $model->save($args); |
| 229 | |
| 230 | if (!$id) |
| 231 | { |
| 232 | // get string error |
| 233 | $error = $model->getError(null, true); |
| 234 | |
| 235 | // display error message |
| 236 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 237 | |
| 238 | $url = 'index.php?option=com_vikappointments&view=empmanres'; |
| 239 | |
| 240 | if ($id_reservation) |
| 241 | { |
| 242 | $url .= '&cid[]=' . $id_reservation; |
| 243 | } |
| 244 | |
| 245 | // redirect to edit page |
| 246 | $this->setRedirect($url); |
| 247 | |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | // display generic successful message |
| 252 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 253 | |
| 254 | // redirect to edit page |
| 255 | $this->setRedirect('index.php?option=com_vikappointments&task=empmanres.edit&cid[]=' . $id); |
| 256 | |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Deletes a list of selected appointments. |
| 262 | * |
| 263 | * @return void |
| 264 | */ |
| 265 | public function delete() |
| 266 | { |
| 267 | $app = JFactory::getApplication(); |
| 268 | $cid = $app->input->get('cid', array(), 'uint'); |
| 269 | |
| 270 | if ($id = $app->input->getUint('id')) |
| 271 | { |
| 272 | $cid[] = $id; |
| 273 | } |
| 274 | |
| 275 | // always redirect to login page |
| 276 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 277 | |
| 278 | /** |
| 279 | * Added token validation. |
| 280 | * Both GET and POST are supported. |
| 281 | * |
| 282 | * @since 1.7 |
| 283 | */ |
| 284 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 285 | { |
| 286 | // back to main list, missing CSRF-proof token |
| 287 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 288 | |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | try |
| 293 | { |
| 294 | // delete selected records |
| 295 | if ($this->getModel()->delete($cid)) |
| 296 | { |
| 297 | $app->enqueueMessage(JText::translate('VAPEMPRESREMOVED1')); |
| 298 | } |
| 299 | } |
| 300 | catch (Exception $e) |
| 301 | { |
| 302 | // an error occurred |
| 303 | $app->enqueueMessage($e->getMessage(), 'error'); |
| 304 | |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Returns a list of users that match the query. |
| 313 | * The users are filtered using the specified "term" via request. |
| 314 | * If the ID is provided, the specific user will be returned instead. |
| 315 | * |
| 316 | * @return void |
| 317 | */ |
| 318 | function searchusers() |
| 319 | { |
| 320 | $input = JFactory::getApplication()->input; |
| 321 | |
| 322 | /** |
| 323 | * Added token validation. |
| 324 | * |
| 325 | * @since 1.7 |
| 326 | */ |
| 327 | if (!JSession::checkToken()) |
| 328 | { |
| 329 | // missing CSRF-proof token |
| 330 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 331 | } |
| 332 | |
| 333 | $auth = VAPEmployeeAuth::getInstance(); |
| 334 | |
| 335 | if (!$auth->isEmployee()) |
| 336 | { |
| 337 | // not authorised to search the customers |
| 338 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 339 | } |
| 340 | |
| 341 | $search = $input->getString('term', ''); |
| 342 | |
| 343 | // get customers model |
| 344 | $model = $this->getModel('customer'); |
| 345 | |
| 346 | $options = array(); |
| 347 | |
| 348 | /** |
| 349 | * @issue 56 |
| 350 | * In case there is at least a subscription, the website is probably |
| 351 | * configured as a portal. This means that the employees are not related |
| 352 | * each other. So, they shouldn't be able to see the details of the |
| 353 | * customers that booked reservations for other employees. |
| 354 | * |
| 355 | * @since 1.6 |
| 356 | */ |
| 357 | VAPLoader::import('libraries.models.subscriptions'); |
| 358 | if (VAPSubscriptions::has($group = 1)) |
| 359 | { |
| 360 | // has a portal of employees, restrict the customers visibility |
| 361 | $options['id_employee'] = $auth->id; |
| 362 | } |
| 363 | |
| 364 | // search customers |
| 365 | $customers = $model->search($search, $options); |
| 366 | |
| 367 | // send users to caller |
| 368 | $this->sendJSON($customers); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * AJAX end-point used to test how the taxes are applied. |
| 373 | * The task expects the following arguments to be set in request. |
| 374 | * |
| 375 | * @param integer id_tax The tax ID. |
| 376 | * @param float amount The base amount. |
| 377 | * |
| 378 | * @return void |
| 379 | * |
| 380 | * @since 1.7 |
| 381 | */ |
| 382 | function taxajax() |
| 383 | { |
| 384 | $input = JFactory::getApplication()->input; |
| 385 | |
| 386 | /** |
| 387 | * Added token validation. |
| 388 | * |
| 389 | * @since 1.7 |
| 390 | */ |
| 391 | if (!JSession::checkToken()) |
| 392 | { |
| 393 | // missing CSRF-proof token |
| 394 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 395 | } |
| 396 | |
| 397 | $auth = VAPEmployeeAuth::getInstance(); |
| 398 | |
| 399 | // make sure the user is an employee |
| 400 | if (!$auth->isEmployee()) |
| 401 | { |
| 402 | // not authorised |
| 403 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 404 | } |
| 405 | |
| 406 | $id_tax = $input->getUint('id_tax', 0); |
| 407 | $amount = $input->getFloat('amount', 0); |
| 408 | |
| 409 | $options = array(); |
| 410 | $options['id_user'] = $input->getUint('id_user', 0); |
| 411 | $options['lang'] = $input->getString('langtag', null); |
| 412 | $options['subject'] = $input->getString('subject', null); |
| 413 | |
| 414 | VAPLoader::import('libraries.tax.factory'); |
| 415 | |
| 416 | // calculate taxes |
| 417 | $result = VAPTaxFactory::calculate($id_tax, $amount, $options); |
| 418 | |
| 419 | // send result to caller |
| 420 | $this->sendJSON($result); |
| 421 | } |
| 422 | } |
| 423 |