PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.4
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.4
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / bundles_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 9 months ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 9 months ago carts_helper.php 1 year ago connector_helper.php 9 months ago csv_helper.php 9 months ago customer_helper.php 9 months ago customer_import_helper.php 9 months ago database_helper.php 9 months ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 9 months ago encrypt_helper.php 1 year ago events_helper.php 9 months ago form_helper.php 9 months ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 9 months ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 9 months ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 9 months ago order_intent_helper.php 9 months ago orders_helper.php 1 year ago otp_helper.php 9 months ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 9 months ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 9 months ago short_links_systems_helper.php 9 months ago shortcodes_helper.php 9 months ago sms_helper.php 1 year ago steps_helper.php 9 months ago stripe_connect_helper.php 9 months ago styles_helper.php 9 months ago support_topics_helper.php 1 year ago time_helper.php 9 months ago timeline_helper.php 9 months ago transaction_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 9 months ago version_specific_updates_helper.php 9 months ago whatsapp_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
bundles_helper.php
240 lines
1 <?php
2
3 class OsBundlesHelper {
4
5 public static function get_remaining_slots_for_bundle_order_item($order_item_id){
6 $order_item = new OsOrderItemModel(OsStepsHelper::$booking_object->order_item_id);
7 $bundle = $order_item->build_original_object_from_item_data();
8 $total_allowed = $bundle->quantity_for_service(OsStepsHelper::$booking_object->service_id);
9 $total_booked = count(OsOrdersHelper::get_bookings_for_order_item(OsStepsHelper::$booking_object->order_item_id, OsStepsHelper::$booking_object->service_id, OsBookingHelper::get_non_cancelled_booking_statuses()));
10 return max(0, $total_allowed - $total_booked);
11 }
12
13 public static function generate_order_summary_for_bundle(OsBundleModel $bundle, string $order_item_id, $preselected_booking_id = false): string{
14 $html = '<div class="summary-box main-box">';
15
16 $bundle_services = $bundle->get_services();
17 $bundle_services_descriptions = [];
18 $total_bookable_quantity = 0;
19 foreach ($bundle_services as $service) {
20 $qty = $service->join_attributes['quantity'];
21 $qty_html = $qty > 1 ? ' [' . $qty . ']' : '';
22 $bundle_services_descriptions[] = $service->name . $qty_html;
23 $total_bookable_quantity+= $qty;
24 }
25 $html.= '<div class="summary-box-content is-removable">
26 <div class="sbc-big-item">'.$bundle->name.'</div>
27 <div class="sbc-subtle-item">
28 '.implode(', ', $bundle_services_descriptions).'
29 </div>
30 </div>';
31
32
33 $past_count = 0;
34 $booked_count = 0;
35
36 // translators: %s is the name of the bundle
37 $html.= '<div class="hidden-bundle-items-notice"><div class="hidden-bundle-items-notice-message">'.sprintf(__('Part of a %s bundle.', 'latepoint'), '<strong>"'.$bundle->name.'"</strong>').'</div><div class="hidden-bundle-items-notice-link">'.__('Show Full Bundle', 'latepoint').'</div></div>';
38 $html.= '<div class="bookable-items-breakdown">';
39 foreach ($bundle_services as $service) {
40 $bookings = (strpos($order_item_id, 'new_') === false) ? OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses()) : [];
41 foreach($bookings as $booking){
42 $booked_count++;
43 if(!$booking->is_upcoming()) $past_count++;
44 }
45 // translators: %d is the number of sessions
46 if(count($bundle_services) > 1) $html.= '<div class="bundle-service-info">'.$service->name.' ['.sprintf(__('%d sessions', 'latepoint'), $service->join_attributes['quantity']).']</div>';
47 for($i = 0; $i < $service->join_attributes['quantity']; $i++){
48 $html.= '<div class="order-item-variant-bundle-booking-wrapper">';
49 $booking = isset($bookings[$i]) ? new OsBookingModel($bookings[$i]->id) : OsBookingHelper::prepare_new_from_params(['service_id' => $service->id]);
50 $booking->service_id = $service->id;
51 $is_preselected = (!$booking->is_new_record() && $preselected_booking_id == $booking->id);
52 $html.= OsOrdersHelper::generate_booking_block_for_bundle_order_item($booking, $order_item_id, isset($bookings[$i]), $is_preselected);
53 $html.= '</div>';
54 }
55 if(strpos($order_item_id, 'new_') === false){
56 // existing order, find cancelled bookings
57 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, [LATEPOINT_BOOKING_STATUS_CANCELLED]);
58 if(!empty($cancelled_bookings)){
59 $html.= '<div class="order-item-cancelled-bookings-wrapper">';
60 // translators: %d is the number of cancelled appointments
61 $html.= '<div class="order-item-cancelled-bookings-heading">'.sprintf(_n('%d Cancelled Appointment', '%d Cancelled Appointments', count($cancelled_bookings), 'latepoint'), count($cancelled_bookings)).'</div>';
62 $html.= '<div class="order-item-cancelled-bookings-list">';
63 foreach($cancelled_bookings as $booking){
64 $html.= '<div class="order-item-variant-bundle-booking-wrapper">';
65 $html.= OsOrdersHelper::generate_booking_block_for_bundle_order_item($booking, $order_item_id, true, ($preselected_booking_id == $booking->id));
66 $html.= '</div>';
67 }
68 $html.= '</div>';
69 $html.= '</div>';
70 }
71 }
72 }
73 $html.= '</div>';
74 $html.= '<div class="bookable-items">';
75 for($i = 1; $i <= $total_bookable_quantity; $i++){
76 $is_past = ($i <= $past_count) ? 'is-past' : '';
77 $is_booked = ($i <= $booked_count) ? 'is-booked' : '';
78 $html.= '<div class="bookable-item '.$is_past.' '.$is_booked.'"></div>';
79 }
80 $html.= '</div>';
81
82 $html.= '</div>';
83
84 return $html;
85 }
86
87 public static function generate_summary_for_bundle(OsBundleModel $bundle, $cart_item_id = false, $order_item_id = false, $user_type = LATEPOINT_USER_TYPE_ADMIN){
88 ob_start();
89 ?>
90 <div class="summary-box main-box" <?php if($cart_item_id) echo 'data-cart-item-id="'.esc_attr($cart_item_id).'"'; ?>>
91 <?php
92 $bundle_headings = [];
93 $bundle_headings = apply_filters('latepoint_order_summary_bundle_headings', $bundle_headings, $bundle);
94 if ($bundle_headings) {
95 echo '<div class="summary-box-heading">';
96 foreach ($bundle_headings as $heading) {
97 echo '<div class="sbh-item">' . esc_html($heading) . '</div>';
98 }
99 echo '<div class="sbh-line"></div>';
100 echo '</div>';
101 }
102 $bundle_services = $bundle->get_services();
103 $bundle_services_descriptions = [];
104 $total_bookable_quantity = 0;
105 foreach ($bundle_services as $service) {
106 $qty = $service->join_attributes['quantity'];
107 $qty_html = $qty > 1 ? ' [' . $qty . ']' : '';
108 $bundle_services_descriptions[] = $service->name . $qty_html;
109 $total_bookable_quantity+= $qty;
110 }
111 ?>
112 <div class="summary-box-content <?php if($cart_item_id) echo 'os-cart-item'; ?> is-removable">
113 <?php if($cart_item_id && OsCartsHelper::can_checkout_multiple_items()){ ?>
114 <div class="os-remove-item-from-cart" role="button"
115 tabindex="0"
116 data-confirm-text="<?php esc_attr_e('Are you sure you want to remove this item from your cart?', 'latepoint'); ?>"
117 data-cart-item-id="<?php echo esc_attr($cart_item_id); ?>"
118 data-route="<?php echo esc_attr(OsRouterHelper::build_route_name('carts', 'remove_item_from_cart')); ?>">
119 <div class="os-remove-from-cart-icon"></div>
120 </div>
121 <?php } ?>
122 <div class="sbc-big-item"><?php echo esc_html($bundle->name); ?></div>
123 <div class="sbc-subtle-item">
124 <?php echo esc_html(implode(', ', $bundle_services_descriptions)); ?>
125 </div>
126 </div>
127 <?php if($order_item_id){
128 $past_count = 0;
129 $booked_count = 0;
130 if($user_type == LATEPOINT_USER_TYPE_CUSTOMER){
131 $order_item = new OsOrderItemModel($order_item_id);
132 $order = new OsOrderModel($order_item->order_id);
133 // translators: %s is the order confirmation code
134 echo '<div class="bundle-order-small-info">'.sprintf(esc_html__('Order %s', 'latepoint'), '<a href="#" '.OsCustomerHelper::generate_order_summary_btn($order->id).'>#'.esc_html($order->confirmation_code).'</a>').'</div>';
135 }
136 echo '<div class="bookable-items-breakdown">';
137 foreach ($bundle_services as $service) {
138 $bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses());
139 foreach($bookings as $booking){
140 $booked_count++;
141 if(!$booking->is_upcoming()) $past_count++;
142 }
143 // translators: %d is the number of sessions
144 if(count($bundle_services) > 1) echo '<div class="bundle-service-info">'.esc_html($service->name.' ['.sprintf(__('%d sessions', 'latepoint'), $service->join_attributes['quantity']).']').'</div>';
145 for($i = 0; $i < $service->join_attributes['quantity']; $i++){
146 if(isset($bookings[$i])){
147 $is_past = (!$bookings[$i]->is_upcoming()) ? 'is-past' : '';
148 $trigger_html = ($user_type == LATEPOINT_USER_TYPE_CUSTOMER) ? OsCustomerHelper::generate_booking_summary_preview_btn($bookings[$i]->id) : OsBookingHelper::quick_booking_btn_html($bookings[$i]->id);
149 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-'.esc_attr($bookings[$i]->status).' '.$is_past.'" '.$trigger_html.'>
150 <div class="booking-item-status-pill"></div>
151 <div class="bib-datetime">'.esc_html($bookings[$i]->get_nice_start_datetime()).'</div>
152 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
153 </div>';
154 }else{
155 if($user_type == LATEPOINT_USER_TYPE_CUSTOMER){
156 echo '<div class="order-item-variant-bundle-booking os_trigger_booking" data-hide-side-panel="yes" data-hide-summary="yes" data-order-item-id="'.esc_attr($order_item_id).'" data-selected-service="'.esc_attr($service->id).'"><div class="booking-item-status-pill"></div><div class="bib-label">'.esc_html__('Schedule now', 'latepoint').'</div></div>';
157 }else{
158 echo '<div class="order-item-variant-bundle-booking" '.OsOrdersHelper::quick_order_btn_html(false, ['order_item_id' => $order_item_id, 'service_id' => $service->id]).'><div class="booking-item-status-pill"></div><div class="bib-label">'.esc_html__('Schedule now', 'latepoint').'</div></div>';
159 }
160 }
161 }
162 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item($order_item_id, $service->id, [LATEPOINT_BOOKING_STATUS_CANCELLED]);
163 if(!empty($cancelled_bookings)){
164 echo '<div class="order-item-cancelled-bookings-wrapper">';
165 // translators: %d is the number of cancelled appointments
166 echo '<div class="order-item-cancelled-bookings-heading">'.esc_html(sprintf(_n('%d Cancelled Appointment', '%d Cancelled Appointments', count($cancelled_bookings), 'latepoint'), count($cancelled_bookings))).'</div>';
167 echo '<div class="order-item-cancelled-bookings-list">';
168 foreach($cancelled_bookings as $cancelled_booking){
169 echo '<div class="order-item-variant-bundle-booking-wrapper">';
170 $is_past = (!$cancelled_booking->is_upcoming()) ? 'is-past' : '';
171 $trigger_html = ($user_type == LATEPOINT_USER_TYPE_CUSTOMER) ? OsCustomerHelper::generate_booking_summary_preview_btn($cancelled_booking->id) : OsBookingHelper::quick_booking_btn_html($cancelled_booking->id);
172 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-'.esc_attr($cancelled_booking->status).' '.$is_past.'" '.$trigger_html.'>
173 <div class="booking-item-status-pill"></div>
174 <div class="bib-datetime">'.esc_html($cancelled_booking->get_nice_start_datetime()).'</div>
175 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
176 </div>';
177 echo '</div>';
178 }
179 echo '</div>';
180 echo '</div>';
181 }
182 }
183 echo '</div>';
184 echo '<div class="bookable-items">';
185 for($i = 1; $i <= $total_bookable_quantity; $i++){
186 $is_past = ($i <= $past_count) ? 'is-past' : '';
187 $is_booked = ($i <= $booked_count) ? 'is-booked' : '';
188 echo '<div class="bookable-item '.esc_attr($is_past).' '.esc_attr($is_booked).'"></div>';
189 }
190 echo '</div>';
191
192 }
193 ?>
194 </div>
195 <?php
196 $response_html = ob_get_clean();
197 return $response_html;
198 }
199
200 /**
201 * @param array $item_data
202 * @return OsBundleModel
203 */
204 public static function build_bundle_model_from_item_data(array $item_data): OsBundleModel{
205 $bundle = new OsBundleModel();
206 if(!empty($item_data['bundle_id'])) $bundle = $bundle->load_by_id($item_data['bundle_id']);
207 return $bundle;
208 }
209
210
211 /**
212 * @param OsBundleModel $bundle
213 * @return mixed|void
214 *
215 * Returns full amount to charge in database format 1999.0000
216 *
217 */
218 public static function calculate_full_amount_for_bundle(OsBundleModel $bundle) {
219 $amount = $bundle->charge_amount;
220 $amount = apply_filters('latepoint_full_amount_for_bundle', $amount, $bundle);
221 $amount = OsMoneyHelper::pad_to_db_format($amount);
222 return $amount;
223 }
224
225
226 /**
227 * @param OsBundleModel $bundle
228 * @param array $options
229 * @return mixed|void
230 *
231 * Returns deposit amount to charge in database format 1999.0000
232 *
233 */
234 public static function calculate_deposit_amount_for_bundle(OsBundleModel $bundle) {
235 $amount = $bundle->deposit_amount;
236 $amount = apply_filters('latepoint_deposit_amount_for_bundle', $amount, $bundle);
237 $amount = OsMoneyHelper::pad_to_db_format($amount);
238 return $amount;
239 }
240 }