default.php
6 days ago
default_details.php
6 days ago
default_details_appointments.php
6 days ago
default_details_appointments_modal.php
6 days ago
default_details_appointments_option_modal.php
6 days ago
default_details_appointments_table.php
6 days ago
default_details_billing.php
6 days ago
default_details_order.php
6 days ago
default_details_order_custmail.php
6 days ago
default_fields.php
6 days ago
default_orderstatus.php
6 days ago
default_orderstatus_history.php
6 days ago
default_orderstatus_manage.php
6 days ago
default_usernotes.php
6 days ago
default_usernotes_main.php
6 days ago
default_usernotes_sidebar.php
6 days ago
index.html
6 days ago
default_details_billing.php
227 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.intltel', '[name="purchaser_phone"]'); |
| 15 | |
| 16 | $reservation = $this->reservation; |
| 17 | |
| 18 | $vik = VAPApplication::getInstance(); |
| 19 | |
| 20 | ?> |
| 21 | |
| 22 | <!-- USER - Dropdown --> |
| 23 | |
| 24 | <?php echo $vik->openControl(JText::translate('VAPMANAGERESERVATION38')); ?> |
| 25 | <div> |
| 26 | <input type="hidden" name="id_user" id="vap-users-select" value="<?php echo $reservation->id_user > 0 ? $reservation->id_user : ''; ?>" /> |
| 27 | </div> |
| 28 | |
| 29 | <div class="manage-customer-actions" style="margin-top: 5px;"> |
| 30 | <button type="button" class="btn" id="add-customer-btn" style="<?php echo $reservation->id_user > 0 ? 'display:none;' : ''; ?>"> |
| 31 | <i class="fas fa-user-plus"></i> |
| 32 | <?php echo JText::translate('VAP_ADD_CUSTOMER'); ?> |
| 33 | </button> |
| 34 | |
| 35 | <button type="button" class="btn" id="edit-customer-btn" style="<?php echo $reservation->id_user > 0 ? '' : 'display:none;'; ?>"> |
| 36 | <i class="fas fa-user-edit"></i> |
| 37 | <?php echo JText::translate('VAP_EDIT_CUSTOMER'); ?> |
| 38 | </button> |
| 39 | </div> |
| 40 | <?php echo $vik->closeControl(); ?> |
| 41 | |
| 42 | <!-- NOMINATIVE - Text --> |
| 43 | |
| 44 | <?php echo $vik->openControl(JText::translate('VAPMANAGERESERVATION32')); ?> |
| 45 | <input type="text" name="purchaser_nominative" value="<?php echo $this->escape($reservation->purchaser_nominative); ?>" size="40" /> |
| 46 | <?php echo $vik->closeControl(); ?> |
| 47 | |
| 48 | <!-- MAIL - Text --> |
| 49 | |
| 50 | <?php echo $vik->openControl(JText::translate('VAPMANAGEPACKORDER7')); ?> |
| 51 | <input type="email" name="purchaser_mail" value="<?php echo $this->escape($reservation->purchaser_mail); ?>" size="40" /> |
| 52 | <?php echo $vik->closeControl(); ?> |
| 53 | |
| 54 | <!-- PHONE - Text --> |
| 55 | |
| 56 | <?php echo $vik->openControl(JText::translate('VAPMANAGEPACKORDER8')); ?> |
| 57 | <input type="tel" name="purchaser_phone" value="<?php echo $reservation->purchaser_phone; ?>" /> |
| 58 | |
| 59 | <input type="hidden" name="purchaser_prefix" value="<?php echo $reservation->purchaser_prefix; ?>" /> |
| 60 | <input type="hidden" name="purchaser_country" value="<?php echo $reservation->purchaser_country; ?>" /> |
| 61 | <?php echo $vik->closeControl(); ?> |
| 62 | |
| 63 | <?php |
| 64 | JText::script('VAPMAINTITLENEWCUSTOMER'); |
| 65 | JText::script('VAPMAINTITLEEDITCUSTOMER'); |
| 66 | ?> |
| 67 | |
| 68 | <script> |
| 69 | |
| 70 | jQuery(function($) { |
| 71 | const BILLING_USERS_POOL = {}; |
| 72 | |
| 73 | $('#vap-users-select').select2({ |
| 74 | placeholder: '--', |
| 75 | allowClear: true, |
| 76 | width: '90%', |
| 77 | minimumInputLength: 2, |
| 78 | ajax: { |
| 79 | url: '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=customer.users'); ?>', |
| 80 | dataType: 'json', |
| 81 | type: 'POST', |
| 82 | quietMillis: 50, |
| 83 | data: function(term) { |
| 84 | return { |
| 85 | term: term |
| 86 | }; |
| 87 | }, |
| 88 | results: function(data) { |
| 89 | return { |
| 90 | results: $.map(data, function (item) { |
| 91 | if (!BILLING_USERS_POOL.hasOwnProperty(item.id)) |
| 92 | { |
| 93 | BILLING_USERS_POOL[item.id] = item; |
| 94 | } |
| 95 | |
| 96 | return { |
| 97 | text: item.text || item.billing_name, |
| 98 | id: item.id, |
| 99 | }; |
| 100 | }), |
| 101 | }; |
| 102 | }, |
| 103 | }, |
| 104 | initSelection: function(element, callback) { |
| 105 | // the input tag has a value attribute preloaded that points to a preselected repository's id |
| 106 | // this function resolves that id attribute to an object that select2 can render |
| 107 | // using its formatResult renderer - that way the repository name is shown preselected |
| 108 | if ($(element).val().length) { |
| 109 | callback({text: '<?php echo (empty($reservation->purchaser_nominative) ? '' : addslashes($reservation->purchaser_nominative)); ?>'}); |
| 110 | } |
| 111 | }, |
| 112 | formatSelection: function(data) { |
| 113 | if ($.isEmptyObject(data.billing_name)) { |
| 114 | // display data returned from ajax parsing |
| 115 | return data.text; |
| 116 | } |
| 117 | // display pre-selected value |
| 118 | return data.billing_name; |
| 119 | }, |
| 120 | }); |
| 121 | |
| 122 | $('#vap-users-select').on('change customer.refresh', function() { |
| 123 | var id = $(this).val(); |
| 124 | |
| 125 | if (!id) { |
| 126 | $('#edit-customer-btn').hide(); |
| 127 | $('#add-customer-btn').show(); |
| 128 | } else { |
| 129 | $('#add-customer-btn').hide(); |
| 130 | $('#edit-customer-btn').show(); |
| 131 | } |
| 132 | |
| 133 | if (!BILLING_USERS_POOL.hasOwnProperty(id)) { |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | if (BILLING_USERS_POOL[id].hasOwnProperty('billing_name')) { |
| 138 | $('input[name="purchaser_nominative"]').val(BILLING_USERS_POOL[id].billing_name); |
| 139 | } |
| 140 | |
| 141 | if (BILLING_USERS_POOL[id].hasOwnProperty('billing_mail')) { |
| 142 | $('input[name="purchaser_mail"]').val(BILLING_USERS_POOL[id].billing_mail); |
| 143 | } |
| 144 | |
| 145 | if (BILLING_USERS_POOL[id].hasOwnProperty('billing_phone')) { |
| 146 | $('input[name="purchaser_phone"]').intlTelInput('setNumber', BILLING_USERS_POOL[id].billing_phone).trigger('change'); |
| 147 | } |
| 148 | |
| 149 | if (BILLING_USERS_POOL[id].hasOwnProperty('fields') && typeof CUSTOM_FIELDS_LOOKUP !== 'undefined') { |
| 150 | compileCustomFields(BILLING_USERS_POOL[id].fields); |
| 151 | } |
| 152 | }); |
| 153 | |
| 154 | // save "country code" and "dial code" every time the phone number changes |
| 155 | $('input[name="purchaser_phone"]').on('change countrychange', function() { |
| 156 | var country = $(this).intlTelInput('getSelectedCountryData'); |
| 157 | |
| 158 | if (!country) { |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | if (country.iso2) { |
| 163 | $('input[name="purchaser_country"]').val(country.iso2.toUpperCase()); |
| 164 | } |
| 165 | |
| 166 | if (country.dialCode) { |
| 167 | var dial = '+' + country.dialCode.toString().replace(/^\+/); |
| 168 | |
| 169 | if (country.areaCodes) { |
| 170 | dial += ' ' + country.areaCodes[0]; |
| 171 | } |
| 172 | |
| 173 | $('input[name="purchaser_prefix"]').val(dial); |
| 174 | } |
| 175 | }); |
| 176 | |
| 177 | $('#add-customer-btn').on('click', () => { |
| 178 | $('#jmodal-managecustomer .customer-title').text(Joomla.JText._('VAPMAINTITLENEWCUSTOMER')); |
| 179 | |
| 180 | // add customer URL |
| 181 | let url = 'index.php?option=com_vikappointments&tmpl=component&task=customer.add'; |
| 182 | |
| 183 | // open modal |
| 184 | vapOpenJModal('managecustomer', url, true); |
| 185 | }); |
| 186 | |
| 187 | $('#edit-customer-btn').on('click', () => { |
| 188 | $('#jmodal-managecustomer .customer-title').text(Joomla.JText._('VAPMAINTITLEEDITCUSTOMER')); |
| 189 | |
| 190 | // add customer URL |
| 191 | let url = 'index.php?option=com_vikappointments&tmpl=component&task=customer.edit&cid[]=' + $('#vap-users-select').val(); |
| 192 | |
| 193 | // open modal |
| 194 | vapOpenJModal('managecustomer', url, true); |
| 195 | }); |
| 196 | |
| 197 | $('button[data-role="customer.save"]').on('click', function() { |
| 198 | // trigger click of save button contained in managecustomer view |
| 199 | window.modalCustomerSaveButton.click(); |
| 200 | }); |
| 201 | |
| 202 | $('#jmodal-managecustomer').on('hidden', function() { |
| 203 | // restore default submit function, which might have been |
| 204 | // replaced by the callback used in manage customer view |
| 205 | Joomla.submitbutton = ManageReservationSubmitButtonCallback; |
| 206 | |
| 207 | // check if the customer was saved |
| 208 | if (window.modalSavedCustomerData) { |
| 209 | let data = window.modalSavedCustomerData; |
| 210 | |
| 211 | // register billing details (or update them if already exist) |
| 212 | BILLING_USERS_POOL[data.id] = { |
| 213 | billing_name: data.billing_name, |
| 214 | billing_mail: data.billing_mail, |
| 215 | billing_phone: data.billing_phone, |
| 216 | country_code: data.country_code, |
| 217 | fields: data.fields, |
| 218 | }; |
| 219 | |
| 220 | // insert/update customer |
| 221 | $('#vap-users-select').select2('data', data).trigger('customer.refresh'); |
| 222 | } |
| 223 | }); |
| 224 | }); |
| 225 | |
| 226 | </script> |
| 227 |