analytics.php
4 years ago
apiban.php
4 years ago
apilog.php
4 years ago
apiplugin.php
4 years ago
apiuser.php
4 years ago
backup.php
4 years ago
calendar.php
4 years ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
2 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
1 month ago
conversion.php
1 year ago
country.php
4 years ago
coupon.php
4 years ago
coupongroup.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
4 months ago
customf.php
1 year ago
dashboard.php
4 years ago
emplocwdays.php
4 years ago
employee.php
1 year ago
emprates.php
4 years ago
export.php
4 years ago
exportres.php
4 years ago
file.php
4 months ago
findreservation.php
1 month ago
group.php
4 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
4 years ago
langoptiongroup.php
4 years ago
langpackage.php
4 years ago
langpackgroup.php
4 years ago
langpayment.php
4 years ago
langservice.php
4 years ago
langstatuscode.php
4 years ago
langsubscr.php
4 years ago
langtax.php
4 years ago
location.php
4 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
4 years ago
multiorder.php
4 years ago
option.php
4 months ago
optiongroup.php
4 years ago
package.php
2 years ago
packgroup.php
4 years ago
packorder.php
1 year ago
payment.php
4 years ago
rate.php
4 years ago
reportsemp.php
4 years ago
reportsser.php
4 years ago
reservation.php
1 month ago
restriction.php
4 years ago
review.php
4 years ago
service.php
1 year ago
serworkday.php
4 months ago
state.php
4 years ago
statuscode.php
4 years ago
subscription.php
4 years ago
subscrorder.php
4 years ago
tag.php
4 years ago
tax.php
4 years ago
usernote.php
4 years ago
waitinglist.php
4 years ago
webhook.php
4 years ago
wizard.php
1 year ago
multiorder.php
249 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.mvc.controllers.admin'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments multi-order (appointments) controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerMultiorder extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Task used to save the record data set in the request. |
| 25 | * After saving, the user is redirected to the main list. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function saveclose() |
| 30 | { |
| 31 | if ($this->save()) |
| 32 | { |
| 33 | $this->cancel(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Task used to save the record data set in the request. |
| 39 | * After saving, the user is redirected to the management |
| 40 | * page of the record that has been saved. |
| 41 | * |
| 42 | * @return boolean |
| 43 | */ |
| 44 | public function save() |
| 45 | { |
| 46 | $dbo = JFactory::getDbo(); |
| 47 | $app = JFactory::getApplication(); |
| 48 | $input = $app->input; |
| 49 | $user = JFactory::getUser(); |
| 50 | |
| 51 | /** |
| 52 | * Added token validation. |
| 53 | * |
| 54 | * @since 1.7 |
| 55 | */ |
| 56 | if (!JSession::checkToken()) |
| 57 | { |
| 58 | // back to main list, missing CSRF-proof token |
| 59 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 60 | $this->cancel(); |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | $args = array(); |
| 66 | |
| 67 | // get order details |
| 68 | $args['id'] = $input->getUint('id', 0); |
| 69 | $args['id_payment'] = $input->getUint('id_payment', 0); |
| 70 | $args['status'] = $input->getString('status', ''); |
| 71 | $args['status_comment'] = $input->getString('comment', ''); |
| 72 | $args['notifycust'] = $input->getBool('notifycust', false); |
| 73 | $args['notifywl'] = $input->getBool('notifywl', false); |
| 74 | |
| 75 | // get order totals |
| 76 | $args['total_cost'] = $input->getFloat('total_cost', 0); |
| 77 | $args['total_net'] = $input->getFloat('total_net', 0); |
| 78 | $args['total_tax'] = $input->getFloat('total_tax', 0); |
| 79 | $args['payment_charge'] = $input->getFloat('payment_charge', 0); |
| 80 | $args['payment_tax'] = $input->getFloat('payment_tax', 0); |
| 81 | |
| 82 | // get billing details |
| 83 | $args['id_user'] = $input->getUint('id_user', 0); |
| 84 | $args['purchaser_nominative'] = $input->getString('purchaser_nominative', ''); |
| 85 | $args['purchaser_mail'] = $input->getString('purchaser_mail', ''); |
| 86 | $args['purchaser_phone'] = $input->getString('purchaser_phone', ''); |
| 87 | $args['purchaser_prefix'] = $input->getString('purchaser_prefix', ''); |
| 88 | $args['purchaser_country'] = $input->getString('purchaser_country', ''); |
| 89 | |
| 90 | // get actions |
| 91 | $args['add_discount'] = $input->getString('add_discount', ''); |
| 92 | $args['remove_discount'] = $input->getBool('remove_discount', false); |
| 93 | |
| 94 | if ($args['add_discount'] === 'manual') |
| 95 | { |
| 96 | // fetch manual discount from request |
| 97 | $args['add_discount'] = $input->get('manual_discount', [], 'array'); |
| 98 | } |
| 99 | |
| 100 | // check user permissions (do not allow creation) |
| 101 | if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.reservations', 'com_vikappointments') || !$args['id']) |
| 102 | { |
| 103 | // back to main list, not authorised to create/edit records |
| 104 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 105 | $this->cancel(); |
| 106 | |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | // get db model |
| 111 | $order = $this->getModel(); |
| 112 | |
| 113 | // import custom fields requestor and loader (as dependency) |
| 114 | VAPLoader::import('libraries.customfields.requestor'); |
| 115 | |
| 116 | // get relevant custom fields only |
| 117 | $_cf = VAPCustomFieldsLoader::getInstance() |
| 118 | ->noSeparator() |
| 119 | ->noRequiredCheckbox(); |
| 120 | |
| 121 | // get children details |
| 122 | $children = $order->getChildren($args['id'], array('id_employee', 'id_service')); |
| 123 | |
| 124 | $employees = array(); |
| 125 | |
| 126 | foreach ($children as $assoc) |
| 127 | { |
| 128 | // extend custom fields by specifying the selected service |
| 129 | $_cf->forService($assoc->id_service); |
| 130 | |
| 131 | if (!in_array($assoc->id_employee, $employees)) |
| 132 | { |
| 133 | // register employee within the pool |
| 134 | $employees[] = $assoc->id_employee; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (count($employees) == 1) |
| 139 | { |
| 140 | // obtain custom fields assigned to the selected employee only |
| 141 | // in case all the appointments assigned to this multi-order |
| 142 | // refers to the same employee |
| 143 | $_cf->ofEmployee($employees[0]); |
| 144 | } |
| 145 | |
| 146 | // load custom fields from request |
| 147 | $args['custom_f'] = VAPCustomFieldsRequestor::loadForm($_cf->fetch(), $tmp, $strict = false); |
| 148 | |
| 149 | // copy uploads into the apposite column |
| 150 | $args['uploads'] = $tmp['uploads']; |
| 151 | |
| 152 | // register data fetched by the custom fields so that the reservation |
| 153 | // model is able to use them for saving purposes |
| 154 | $args['fields_data'] = $tmp; |
| 155 | |
| 156 | if ($args['notifycust']) |
| 157 | { |
| 158 | /** |
| 159 | * Loads any additional custom text to include within the e-mail notification. |
| 160 | * |
| 161 | * @since 1.6.5 |
| 162 | */ |
| 163 | $custMail = array(); |
| 164 | $custMail['id'] = $input->getUint('custmail_id', 0); |
| 165 | $custMail['name'] = $input->getString('custmail_name', ''); |
| 166 | $custMail['position'] = $input->getString('custmail_position', ''); |
| 167 | $custMail['content'] = JComponentHelper::filterText($input->getRaw('custmail_content', '')); |
| 168 | |
| 169 | if (!empty($custMail['name']) && !empty($custMail['content'])) |
| 170 | { |
| 171 | // create new custom e-mail template (unpublished) |
| 172 | $custMail['published'] = 0; |
| 173 | |
| 174 | // get e-mail text model |
| 175 | $custMailModel = $this->getModel('mailtext'); |
| 176 | // attempt to create new mail text |
| 177 | $mail_id = $custMailModel->save($custMail); |
| 178 | |
| 179 | if ($mail_id) |
| 180 | { |
| 181 | // inject selected custom e-mail within order details |
| 182 | // for being retrieved while generating the notification |
| 183 | $args['mail_custom_text'] = $mail_id; |
| 184 | |
| 185 | /** |
| 186 | * Added the possibility to exclude the default mail custom texts. |
| 187 | * |
| 188 | * @since 1.6.6 |
| 189 | */ |
| 190 | $args['exclude_default_mail_texts'] = $input->getBool('exclude_default_mail_texts', false); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // try to save arguments |
| 196 | $id = $order->save($args); |
| 197 | |
| 198 | if (!$id) |
| 199 | { |
| 200 | // get string error |
| 201 | $error = $order->getError(null, true); |
| 202 | |
| 203 | // display error message |
| 204 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 205 | |
| 206 | $url = 'index.php?option=com_vikappointments&view=managereservation'; |
| 207 | |
| 208 | if ($args['id']) |
| 209 | { |
| 210 | $url .= '&cid[]=' . $args['id']; |
| 211 | } |
| 212 | |
| 213 | // redirect to new/edit page |
| 214 | $this->setRedirect($url); |
| 215 | |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | // display generic successful message |
| 220 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 221 | |
| 222 | // redirect to edit page |
| 223 | $this->setRedirect('index.php?option=com_vikappointments&task=reservation.edit&cid[]=' . $id); |
| 224 | |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Redirects the users to the main records list. |
| 230 | * |
| 231 | * @return void |
| 232 | */ |
| 233 | public function cancel() |
| 234 | { |
| 235 | $input = JFactory::getApplication()->input; |
| 236 | |
| 237 | // check whether a custom return view has been specified |
| 238 | $view = $input->get('from'); |
| 239 | |
| 240 | if (!$view) |
| 241 | { |
| 242 | // back to appointments list by default |
| 243 | $view = 'reservations'; |
| 244 | } |
| 245 | |
| 246 | $this->setRedirect('index.php?option=com_vikappointments&view=' . $view); |
| 247 | } |
| 248 | } |
| 249 |