PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / classes / class.booking-calendar-ajax.php

class.booking-calendar-ajax.php in Easy Hotel – Powerful Hotel Booking 2.0.2, at admin/includes/classes/class.booking-calendar-ajax.php

466 lines 25.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use SureCart\Models\Order;
3 use SureCart\Models\Checkout;
4 use SureCart\Models\PaymentMethod;
5 use SureCart\Models\ManualPaymentMethod;
6 use SureCart\Models\Customer;
7 use SureCart\Models\ShippingMethod;
8
9 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
10
11 class ESHB_Booking_Calendar_Ajax {
12 public function __construct() {
13 add_action( "wp_ajax_eshb_get_booking_data_tables", [$this, 'eshb_get_booking_data'] );
14 add_action( "wp_ajax_eshb_get_accomodation_meta", [$this, 'eshb_get_accomodation_meta'] );
15 add_action( "wp_ajax_nopriv_eshb_get_accomodation_meta", [$this, 'eshb_get_accomodation_meta'] );
16 }
17
18 public function eshb_get_booking_data() {
19
20 check_ajax_referer( ESHB_Helper::generate_secure_nonce_action('eshb_global_nonce_action'), 'nonce' );
21
22 if (isset($_REQUEST['post']) && get_post_type(sanitize_text_field(wp_unslash($_REQUEST['post']))) == 'eshb_booking') {
23 $post_id = intval(sanitize_text_field(wp_unslash($_REQUEST['post'])));
24
25 $eshb_settings = get_option( 'eshb_settings' );
26 $booking_type = $eshb_settings['booking-type'];
27
28 // Retrieve and display your custom data for the eshb_booking post type
29 $booking_metaboxes = get_post_meta($post_id, 'eshb_booking_metaboxes', true);
30
31 $hotel_core = new ESHB_Core();
32 $currency_symbol = html_entity_decode($hotel_core->get_eshb_currency_symbol());
33 $accomodation_id = $booking_metaboxes['booking_accomodation_id'];
34 $accomodation_title = get_the_title($accomodation_id);
35 $booking_start_date = $booking_metaboxes['booking_start_date'];
36 $booking_end_date = $booking_metaboxes['booking_end_date'];
37
38 $time_slot = !empty($booking_metaboxes['booking_start_time']) && !empty($booking_metaboxes['booking_end_time']) ? ESHB_Helper::format_to_wp_time($booking_metaboxes['booking_start_time']) . ' - ' . ESHB_Helper::format_to_wp_time($booking_metaboxes['booking_end_time']) : '';
39
40 $adult_quantity = !empty($booking_metaboxes['adult_quantity']) ? $booking_metaboxes['adult_quantity'] : 0;
41 $children_quantity = !empty($booking_metaboxes['children_quantity']) ? $booking_metaboxes['children_quantity'] : 0;
42 $room_quantity = !empty($booking_metaboxes['room_quantity']) ? $booking_metaboxes['room_quantity'] : 1;
43 $extra_bed_quantity = !empty($booking_metaboxes['extra_bed_quantity']) ? $booking_metaboxes['extra_bed_quantity'] : 0;
44 $extra_services = !empty($booking_metaboxes['extra_services_html']) ? $booking_metaboxes['extra_services_html'] : '';
45
46 $base_price = !empty($booking_metaboxes['base_price']) ? $booking_metaboxes['base_price'] : 0;
47 $subtotal_price = !empty($booking_metaboxes['subtotal_price']) ? $booking_metaboxes['subtotal_price'] : 0;
48 $extra_bed_price = !empty($booking_metaboxes['extra_bed_price']) ? $booking_metaboxes['extra_bed_price'] : 0;
49 $total_price = !empty($booking_metaboxes['total_price']) ? $booking_metaboxes['total_price'] : $subtotal_price;
50 $total_paid = !empty($booking_metaboxes['total_paid']) ? $booking_metaboxes['total_paid'] : 0;
51 $deposit_amount = !empty($booking_metaboxes['deposit_amount']) ? $booking_metaboxes['deposit_amount'] : 0;
52 $due_amount = $subtotal_price - $total_paid;
53
54 $extra_services_charge = !empty($booking_metaboxes['extra_service_price']) ? $booking_metaboxes['extra_service_price'] : 0;
55
56 // Customer Details
57
58 $order_id = !empty($booking_metaboxes['order_id']) ? $booking_metaboxes['order_id'] : '';
59 $order = '';
60
61 $billing_data = [];
62
63 if(class_exists('WooCommerce') && wc_get_order($order_id)){
64 $order = wc_get_order($order_id);
65 if($order){
66 $billing_data['order_status'] = $order->get_status();
67 $billing_data['first_name'] = $order->get_billing_first_name();
68 $billing_data['last_name'] = $order->get_billing_last_name();
69 $billing_data['customer_name'] = trim($billing_data['first_name'] . ' ' . $billing_data['last_name']); // Concatenate first and last name
70 $payment_gateways = WC()->payment_gateways->payment_gateways();
71 $payment_method_code = $order->get_payment_method();
72 $payment_gateway = $payment_gateways[ $payment_method_code ];
73 $billing_data['payment_method_name'] = $payment_gateway->get_title();
74 $billing_data['billing_email'] = $order->get_billing_email();
75 $billing_data['billing_phone'] = $order->get_billing_phone();
76 $billing_data['billing_company'] = $order->get_billing_company();
77 $billing_data['billing_city'] = $order->get_billing_city();
78 $billing_data['billing_state'] = $order->get_billing_state();
79 $billing_data['billing_postcode'] = $order->get_billing_postcode();
80 $billing_data['billing_country'] = $order->get_billing_country();
81 $billing_data['billing_address_1'] = $order->get_billing_address_1();
82 $billing_data['billing_address_2'] = $order->get_billing_address_2();
83 }
84 }else {
85 $order = $booking_metaboxes;
86 $customer = !empty($booking_metaboxes['customer']) ? $booking_metaboxes['customer'] : [];
87
88 if(!empty($customer)){
89 $billing_data['order_status'] = $booking_metaboxes['booking_status'];
90 $billing_data['customer_name'] = $customer['name']; // Concatenate first and last name
91 $billing_data['payment_method_name'] = esc_html__('N/A', 'easy-hotel');
92 $billing_data['billing_email'] = $customer['email'];
93 $billing_data['billing_phone'] = $customer['phone'];
94 }
95 }
96
97 $billing_data = apply_filters( 'eshb_billing_data_booking_view', $billing_data, $order_id, $booking_type);
98 $hotel_core = new ESHB_Core();
99
100 ?>
101 <div class="booking-details">
102 <h3><?php esc_html_e('Rooms & Services', 'easy-hotel') ?></h3>
103
104 <table class="wp-list-table widefat fixed striped">
105 <thead>
106 <tr>
107 <th><?php esc_html_e('Field', 'easy-hotel') ?></th>
108 <th><?php esc_html_e('Value', 'easy-hotel') ?></th>
109 </tr>
110 </thead>
111 <tbody>
112 <tr>
113 <td><?php esc_html_e('Booking Date', 'easy-hotel') ?></td>
114 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( get_the_date('Y-m-d', $post_id) ) ), 'easy-hotel'); ?></td>
115 </tr>
116 <tr>
117 <td><?php esc_html_e('Booking Start Date', 'easy-hotel') ?></td>
118 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( $booking_start_date ) ), 'easy-hotel'); ?></td>
119 </tr>
120 <tr>
121 <td><?php esc_html_e('Booking End Date', 'easy-hotel') ?></td>
122 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( $booking_end_date ) ), 'easy-hotel'); ?></td>
123 </tr>
124 <?php
125 if(!empty($time_slot)) {
126
127 ?>
128 <tr>
129 <td><?php esc_html_e('Time Slot', 'easy-hotel') ?></td>
130 <td><?php echo esc_html($time_slot); ?></td>
131 </tr>
132 <?php
133 }
134 ?>
135 <tr>
136 <td><?php esc_html_e('Room', 'easy-hotel') ?></td>
137 <td><?php echo esc_html($accomodation_title); ?></td>
138 </tr>
139 <tr>
140 <td><?php esc_html_e('Number of Rooms', 'easy-hotel') ?></td>
141 <td><?php echo esc_html($room_quantity); ?></td>
142 </tr>
143 <tr>
144 <td><?php esc_html_e('Number of Extra Beds', 'easy-hotel') ?></td>
145 <td><?php echo esc_html($extra_bed_quantity); ?></td>
146 </tr>
147 <tr>
148 <td><?php esc_html_e('Adults', 'easy-hotel') ?></td>
149 <td><?php echo esc_html($adult_quantity); ?></td>
150 </tr>
151 <tr>
152 <td><?php esc_html_e('Childrens', 'easy-hotel') ?></td>
153 <td><?php echo esc_html($children_quantity); ?></td>
154 </tr>
155 <?php
156 if(!empty($extra_services)){
157 ?>
158 <tr>
159 <td><?php esc_html_e('Extra Services', 'easy-hotel') ?></td>
160 <td><?php echo esc_html($extra_services); ?></td>
161 </tr>
162 <?php
163 }
164 ?>
165 </tbody>
166 </table>
167 <?php
168 if(count($billing_data) > 0) {
169 ?>
170 <h3><?php esc_html_e('Customer & Billings', 'easy-hotel') ?></h3>
171 <table class="wp-list-table widefat fixed striped">
172 <thead>
173 <tr>
174 <th><?php esc_html_e('Field', 'easy-hotel') ?></th>
175 <th><?php esc_html_e('Value', 'easy-hotel') ?></th>
176 </tr>
177 </thead>
178 <tbody>
179 <?php if ( !empty($billing_data['customer_name']) ) : ?>
180 <tr>
181 <td><?php esc_html_e('Name', 'easy-hotel') ?></td>
182 <td><?php echo esc_html($billing_data['customer_name']); ?></td>
183 </tr>
184 <?php endif; ?>
185
186 <?php if ( !empty($billing_data['billing_email']) ) : ?>
187 <tr>
188 <td><?php esc_html_e('Email Address', 'easy-hotel') ?></td>
189 <td><?php echo esc_html($billing_data['billing_email']); ?></td>
190 </tr>
191 <?php endif; ?>
192
193 <?php if ( !empty($billing_data['billing_phone']) ) : ?>
194 <tr>
195 <td><?php esc_html_e('Phone Number', 'easy-hotel') ?></td>
196 <td><?php echo esc_html($billing_data['billing_phone']); ?></td>
197 </tr>
198 <?php endif; ?>
199
200 <?php if ( !empty($billing_data['billing_company']) ) : ?>
201 <tr>
202 <td><?php esc_html_e('Company', 'easy-hotel') ?></td>
203 <td><?php echo esc_html($billing_data['billing_company']); ?></td>
204 </tr>
205 <?php endif; ?>
206
207 <?php if ( !empty($billing_data['billing_city']) ) : ?>
208 <tr>
209 <td><?php esc_html_e('City', 'easy-hotel') ?></td>
210 <td><?php echo esc_html($billing_data['billing_city']); ?></td>
211 </tr>
212 <?php endif; ?>
213
214 <?php if ( !empty($billing_data['billing_state']) ) : ?>
215 <tr>
216 <td><?php esc_html_e('State', 'easy-hotel') ?></td>
217 <td><?php echo esc_html($billing_data['billing_state']); ?></td>
218 </tr>
219 <?php endif; ?>
220
221 <?php if ( !empty($billing_data['billing_postcode']) ) : ?>
222 <tr>
223 <td><?php esc_html_e('Post Code', 'easy-hotel') ?></td>
224 <td><?php echo esc_html($billing_data['billing_postcode']); ?></td>
225 </tr>
226 <?php endif; ?>
227
228 <?php if ( !empty($billing_data['billing_country']) ) : ?>
229 <tr>
230 <td><?php esc_html_e('Country', 'easy-hotel') ?></td>
231 <td><?php echo esc_html($billing_data['billing_country']); ?></td>
232 </tr>
233 <?php endif; ?>
234
235 <?php if ( !empty($billing_data['billing_address_1']) ) : ?>
236 <tr>
237 <td><?php esc_html_e('Address One', 'easy-hotel') ?></td>
238 <td><?php echo esc_html($billing_data['billing_address_1']); ?></td>
239 </tr>
240 <?php endif; ?>
241
242 <?php if ( !empty($billing_data['billing_address_2']) ) : ?>
243 <tr>
244 <td><?php esc_html_e('Address Two', 'easy-hotel') ?></td>
245 <td><?php echo esc_html($billing_data['billing_address_2']); ?></td>
246 </tr>
247 <?php endif; ?>
248 </tbody>
249 </table>
250 <?php
251 }
252 ?>
253
254 <h3><?php esc_html_e('Payment', 'easy-hotel') ?></h3>
255 <table class="wp-list-table widefat fixed striped">
256 <thead>
257 <tr>
258 <th><?php esc_html_e('Field', 'easy-hotel') ?></th>
259 <th><?php esc_html_e('Value', 'easy-hotel') ?></th>
260 </tr>
261 </thead>
262 <tbody>
263 <?php
264 if(!empty($billing_data['order_status'])) {
265 ?>
266 <tr>
267 <td><?php esc_html_e('Payment Status', 'easy-hotel') ?></td>
268 <td><?php echo esc_html(ucfirst(strtolower($billing_data['order_status']))); ?></td>
269 </tr>
270 <?php
271 }
272
273 if(!empty($billing_data['payment_method_name'])) {
274 ?>
275 <tr>
276 <td><?php esc_html_e('Payment Method', 'easy-hotel') ?></td>
277 <td><?php echo esc_html(ucfirst(strtolower($billing_data['payment_method_name']))); ?></td>
278 </tr>
279 <?php
280 }
281 ?>
282
283 <tr>
284 <td><?php esc_html_e('Base Price', 'easy-hotel') ?></td>
285 <td><?php echo esc_html($hotel_core->eshb_price($base_price)); ?></td>
286 </tr>
287 <?php
288 if(!empty($extra_bed_price)){
289 ?>
290 <tr>
291 <td><?php esc_html_e('Extra Bed Price', 'easy-hotel') ?></td>
292 <td><?php echo esc_html($hotel_core->eshb_price($extra_bed_price)); ?></td>
293 </tr>
294 <?php
295 }
296 if(!empty($extra_services_charge)){
297 ?>
298 <tr>
299 <td><?php esc_html_e('Service Charge', 'easy-hotel') ?></td>
300 <td><?php echo esc_html($hotel_core->eshb_price($extra_services_charge)); ?></td>
301 </tr>
302 <?php
303 }
304 ?>
305 <tr>
306 <td><?php esc_html_e('SubTotal', 'easy-hotel') ?></td>
307 <td><?php echo esc_html($hotel_core->eshb_price($subtotal_price)); ?></td>
308 </tr>
309
310
311 <?php
312
313 if(!empty($deposit_amount)){
314 ?>
315 <tr>
316 <td><?php esc_html_e('Initial Deposit', 'easy-hotel') ?></td>
317 <td><?php echo esc_html($hotel_core->eshb_price($deposit_amount)); ?></td>
318 </tr>
319 <?php
320 }
321 if(!empty($due_amount)){
322 ?>
323 <tr>
324 <td><?php esc_html_e('Due', 'easy-hotel') ?></td>
325 <td><?php echo esc_html($hotel_core->eshb_price($due_amount)); ?></td>
326 </tr>
327 <?php
328 }
329 ?>
330 <tr>
331 <td><?php esc_html_e('Total Paid', 'easy-hotel') ?></td>
332 <td><?php echo esc_html($hotel_core->eshb_price($total_paid)); ?></td>
333 </tr>
334
335 </tbody>
336 </table>
337
338 <?php
339 // after_eshb_booking_details_html
340 do_action( 'after_eshb_booking_details_html', $order_id );
341 ?>
342 </div>
343 <?php
344 } else if(isset($_REQUEST['post']) && get_post_type(sanitize_text_field(wp_unslash($_REQUEST['post']))) == 'eshb_ical_booking'){
345
346 $booking_id = !empty($_REQUEST['post']) ? sanitize_text_field(wp_unslash($_REQUEST['post'])) : '';
347 $booking_start_date = get_post_meta($booking_id, 'start', true);
348 $booking_end_date = get_post_meta($booking_id, 'end', true);
349 $uid = get_post_meta($booking_id, 'uid', true);
350 $accomodation_id = get_post_meta($booking_id, 'accomodation_id', true);
351 $source_id = get_post_meta($booking_id, 'source_id', true);
352 $uid = get_post_meta($booking_id, 'uid', true);
353 $calendar_name = get_post_meta($booking_id, 'calendar_name', true);
354 $summary = get_post_meta( $booking_id, 'summary', true );
355 $ical_sources = get_post_meta($accomodation_id, 'ical_sources', true);
356 $ical_sources = $ical_sources ? $ical_sources : []; // Set to empty array if not set
357 $ical_source = array_filter($ical_sources, function($ical_source) use ($source_id) {
358 return isset($ical_source['id']) && $ical_source['id'] == $source_id;
359 });
360 // Get the first matched item safely
361 $ical_source = reset($ical_source);
362 $ical_url = $ical_source['url'];
363
364
365 ?>
366 <div class="wrap">
367 <h3><?php esc_html_e('Ical Booking', 'easy-hotel') ?></h3>
368 <table class="wp-list-table widefat fixed striped">
369 <thead>
370 <tr>
371 <th><?php esc_html_e('Field', 'easy-hotel') ?></th>
372 <th><?php esc_html_e('Value', 'easy-hotel') ?></th>
373 </tr>
374 </thead>
375 <tbody>
376 <tr>
377 <td><?php esc_html_e('Booking Date', 'easy-hotel') ?></td>
378 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( get_the_date('Y-m-d', $booking_id) ) )); ?></td>
379 </tr>
380 <tr>
381 <td><?php esc_html_e('Check-in Date', 'easy-hotel') ?></td>
382 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( $booking_start_date ) )); ?></td>
383 </tr>
384 <tr>
385 <td><?php esc_html_e('Check-out Date', 'easy-hotel') ?></td>
386 <td><?php echo esc_html(date_i18n( get_option('date_format'), strtotime( $booking_end_date ) )); ?></td>
387 </tr>
388 <tr>
389 <td><?php esc_html_e('Summary', 'easy-hotel') ?></td>
390 <td><?php echo esc_html( $summary, 'easy-hotel' ); ?></td>
391 </tr>
392 <tr>
393 <td><?php esc_html_e('Calendar Name', 'easy-hotel') ?></td>
394 <td><?php echo esc_html( $calendar_name ); ?></td>
395 </tr>
396 <tr>
397 <td><?php esc_html_e('UID', 'easy-hotel') ?></td>
398 <td><?php echo esc_html( $uid ); ?></td>
399 </tr>
400 <tr>
401 <td><?php esc_html_e('Ical Source ID', 'easy-hotel') ?></td>
402 <td><?php echo esc_html( $source_id ); ?></td>
403 </tr>
404 <tr>
405 <td><?php esc_html_e('Ical Url', 'easy-hotel') ?></td>
406 <td><a href="<?php echo esc_html( $ical_url ); ?>" target="_blank"><?php echo esc_html( $ical_url ); ?></a></td>
407 </tr>
408 </tbody>
409 </table>
410 </div>
411 <?php
412
413 }else{
414 // Handle the case when the post type is not eshb_booking
415 echo '<div class="error"><p>' . esc_html__('Invalid post type.', 'easy-hotel') . '</p></div>';
416 }
417 wp_die(); // This is required to terminate immediately and return a proper response
418 }
419
420 public function eshb_get_accomodation_meta(){
421
422 check_ajax_referer( ESHB_Helper::generate_secure_nonce_action('eshb_global_nonce_action'), 'nonce' );
423
424 if (isset($_REQUEST['accomodationId']) && get_post_type(sanitize_text_field(wp_unslash($_REQUEST['accomodationId']))) == 'eshb_accomodation') {
425 $accomodation_id = intval(sanitize_text_field(wp_unslash($_REQUEST['accomodationId'])));
426
427 $eshb_min_max_settings = get_option( 'eshb_min_max_settings', []);
428 $required_min_nights = !empty($eshb_min_max_settings['required_min_nights']) ? $eshb_min_max_settings['required_min_nights'] : 1;
429 $required_max_nights = !empty($eshb_min_max_settings['required_max_nights']) ? $eshb_min_max_settings['required_max_nights'] : 999;
430
431 $eshb_week_settings = get_option( 'eshb_week_settings', [] );
432 $string_check_in_day_error_msg = !empty($eshb_week_settings['string_check_in_day_error_msg']) ? $eshb_week_settings['string_check_in_day_error_msg'] : '';
433
434 // accomodation details metadata
435 $eshb_booking = new ESHB_Booking();
436 $eshb_accomodation_metaboxes = [];
437 $start_date = isset($_POST['startDate']) ? sanitize_text_field( wp_unslash($_POST['startDate']) ) : '';
438 $end_date = isset($_POST['endDate']) ? sanitize_text_field( wp_unslash($_POST['endDate']) ) : '';
439 $eshb_accomodation_metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true);
440 $available_rooms = $eshb_booking->get_available_room_count_by_date_range($accomodation_id, $start_date, $end_date);
441 $eshb_accomodation_metaboxes['available_rooms'] = $available_rooms;
442
443
444 $eshb_translations = [
445 'maximumCapacity' => __('Maximum Capacity', 'easy-hotel'),
446 'availableCapacity' => __('Available Capacity', 'easy-hotel'),
447 'availableRoom' => __('Available Room', 'easy-hotel'),
448 'maximumAdultAndChildrenCapacity' => __('Maximum Adult and Children Capacity', 'easy-hotel'),
449 ];
450
451 wp_send_json_success( [
452 'requiredMinNights' => $required_min_nights,
453 'requiredMaxNights' => $required_max_nights,
454 'checkInDayErrorMsg' => $string_check_in_day_error_msg,
455 'currentAccomodationMeta' => $eshb_accomodation_metaboxes,
456 'translations' => $eshb_translations
457 ]);
458
459 die();
460
461 }else{
462 wp_send_json_error( 'invalid accomodation id' );
463 }
464 }
465 }
466 new ESHB_Booking_Calendar_Ajax();