PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.4.1
LatePoint – Calendar Booking Plugin for Appointments and Events v5.4.1
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 3 months ago agent_helper.php 3 months ago analytics_helper.php 2 months ago auth_helper.php 3 months ago blocks_helper.php 3 months ago booking_helper.php 3 months ago bricks_helper.php 3 months ago bundles_helper.php 3 months ago calendar_helper.php 3 months ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 3 months ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 months ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 2 months ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 3 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 3 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago replacer_helper.php 3 months ago resource_helper.php 3 months ago roles_helper.php 3 months ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 3 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 2 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 2 months ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 2 months ago timeline_helper.php 3 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 3 months ago update_helper.php 2 months ago util_helper.php 3 months ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
bundles_helper.php
262 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() ) {
44 $past_count++;
45 }
46 }
47 // translators: %d is the number of sessions
48 if ( count( $bundle_services ) > 1 ) {
49 $html .= '<div class="bundle-service-info">' . $service->name . ' [' . sprintf( __( '%d sessions', 'latepoint' ), $service->join_attributes['quantity'] ) . ']</div>';
50 }
51 for ( $i = 0; $i < $service->join_attributes['quantity']; $i++ ) {
52 $html .= '<div class="order-item-variant-bundle-booking-wrapper">';
53 $booking = isset( $bookings[ $i ] ) ? new OsBookingModel( $bookings[ $i ]->id ) : OsBookingHelper::prepare_new_from_params( [ 'service_id' => $service->id ] );
54 $booking->service_id = $service->id;
55 $is_preselected = ( ! $booking->is_new_record() && $preselected_booking_id == $booking->id );
56 $html .= OsOrdersHelper::generate_booking_block_for_bundle_order_item( $booking, $order_item_id, isset( $bookings[ $i ] ), $is_preselected );
57 $html .= '</div>';
58 }
59 if ( strpos( $order_item_id, 'new_' ) === false ) {
60 // existing order, find cancelled bookings
61 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item_id, $service->id, [ LATEPOINT_BOOKING_STATUS_CANCELLED ] );
62 if ( ! empty( $cancelled_bookings ) ) {
63 $html .= '<div class="order-item-cancelled-bookings-wrapper">';
64 // translators: %d is the number of cancelled appointments
65 $html .= '<div class="order-item-cancelled-bookings-heading">' . sprintf( _n( '%d Cancelled Appointment', '%d Cancelled Appointments', count( $cancelled_bookings ), 'latepoint' ), count( $cancelled_bookings ) ) . '</div>';
66 $html .= '<div class="order-item-cancelled-bookings-list">';
67 foreach ( $cancelled_bookings as $booking ) {
68 $html .= '<div class="order-item-variant-bundle-booking-wrapper">';
69 $html .= OsOrdersHelper::generate_booking_block_for_bundle_order_item( $booking, $order_item_id, true, ( $preselected_booking_id == $booking->id ) );
70 $html .= '</div>';
71 }
72 $html .= '</div>';
73 $html .= '</div>';
74 }
75 }
76 }
77 $html .= '</div>';
78 $html .= '<div class="bookable-items">';
79 for ( $i = 1; $i <= $total_bookable_quantity; $i++ ) {
80 $is_past = ( $i <= $past_count ) ? 'is-past' : '';
81 $is_booked = ( $i <= $booked_count ) ? 'is-booked' : '';
82 $html .= '<div class="bookable-item ' . $is_past . ' ' . $is_booked . '"></div>';
83 }
84 $html .= '</div>';
85
86 $html .= '</div>';
87
88 return $html;
89 }
90
91 public static function generate_summary_for_bundle( OsBundleModel $bundle, $cart_item_id = false, $order_item_id = false, $user_type = LATEPOINT_USER_TYPE_ADMIN ) {
92 ob_start();
93 ?>
94 <div class="summary-box main-box" <?php if ( $cart_item_id ) {
95 echo 'data-cart-item-id="' . esc_attr( $cart_item_id ) . '"';} ?>>
96 <?php
97 $bundle_headings = [];
98 $bundle_headings = apply_filters( 'latepoint_order_summary_bundle_headings', $bundle_headings, $bundle );
99 if ( $bundle_headings ) {
100 echo '<div class="summary-box-heading">';
101 foreach ( $bundle_headings as $heading ) {
102 echo '<div class="sbh-item">' . esc_html( $heading ) . '</div>';
103 }
104 echo '<div class="sbh-line"></div>';
105 echo '</div>';
106 }
107 $bundle_services = $bundle->get_services();
108 $bundle_services_descriptions = [];
109 $total_bookable_quantity = 0;
110 foreach ( $bundle_services as $service ) {
111 $qty = $service->join_attributes['quantity'];
112 $qty_html = $qty > 1 ? ' [' . $qty . ']' : '';
113 $bundle_services_descriptions[] = $service->name . $qty_html;
114 $total_bookable_quantity += $qty;
115 }
116 ?>
117 <div class="summary-box-content <?php if ( $cart_item_id ) {
118 echo 'os-cart-item';} ?> is-removable">
119 <?php if ( $cart_item_id && OsCartsHelper::can_checkout_multiple_items() ) { ?>
120 <div class="os-remove-item-from-cart" role="button"
121 tabindex="0"
122 data-confirm-text="<?php esc_attr_e( 'Are you sure you want to remove this item from your cart?', 'latepoint' ); ?>"
123 data-cart-item-id="<?php echo esc_attr( $cart_item_id ); ?>"
124 data-route="<?php echo esc_attr( OsRouterHelper::build_route_name( 'carts', 'remove_item_from_cart' ) ); ?>">
125 <div class="os-remove-from-cart-icon"></div>
126 </div>
127 <?php } ?>
128 <div class="sbc-big-item"><?php echo esc_html( $bundle->name ); ?></div>
129 <div class="sbc-subtle-item">
130 <?php echo esc_html( implode( ', ', $bundle_services_descriptions ) ); ?>
131 </div>
132 </div>
133 <?php if ( $order_item_id ) {
134 $past_count = 0;
135 $booked_count = 0;
136 if ( $user_type == LATEPOINT_USER_TYPE_CUSTOMER ) {
137 $order_item = new OsOrderItemModel( $order_item_id );
138 $order = new OsOrderModel( $order_item->order_id );
139 // translators: %s is the order confirmation code
140 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>';
141 }
142 echo '<div class="bookable-items-breakdown">';
143 foreach ( $bundle_services as $service ) {
144 $bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses() );
145 foreach ( $bookings as $booking ) {
146 $booked_count++;
147 if ( ! $booking->is_upcoming() ) {
148 $past_count++;
149 }
150 }
151 // translators: %d is the number of sessions
152 if ( count( $bundle_services ) > 1 ) {
153 echo '<div class="bundle-service-info">' . esc_html( $service->name . ' [' . sprintf( __( '%d sessions', 'latepoint' ), $service->join_attributes['quantity'] ) . ']' ) . '</div>';
154 }
155 for ( $i = 0; $i < $service->join_attributes['quantity']; $i++ ) {
156 if ( isset( $bookings[ $i ] ) ) {
157 $is_past = ( ! $bookings[ $i ]->is_upcoming() ) ? 'is-past' : '';
158 $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 );
159 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-' . esc_attr( $bookings[ $i ]->status ) . ' ' . $is_past . '" ' . $trigger_html . '>
160 <div class="booking-item-status-pill"></div>
161 <div class="bib-datetime">' . esc_html( $bookings[ $i ]->get_nice_start_datetime() ) . '</div>
162 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
163 </div>';
164 } else {
165 if ( $user_type == LATEPOINT_USER_TYPE_CUSTOMER ) {
166 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>';
167 } else {
168 echo '<div class="order-item-variant-bundle-booking" ' . OsOrdersHelper::quick_order_btn_html(
169 false,
170 [
171 'order_item_id' => $order_item_id,
172 'service_id' => $service->id,
173 ]
174 ) . '><div class="booking-item-status-pill"></div><div class="bib-label">' . esc_html__( 'Schedule now', 'latepoint' ) . '</div></div>';
175 }
176 }
177 }
178 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item_id, $service->id, [ LATEPOINT_BOOKING_STATUS_CANCELLED ] );
179 if ( ! empty( $cancelled_bookings ) ) {
180 echo '<div class="order-item-cancelled-bookings-wrapper">';
181 // translators: %d is the number of cancelled appointments
182 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>';
183 echo '<div class="order-item-cancelled-bookings-list">';
184 foreach ( $cancelled_bookings as $cancelled_booking ) {
185 echo '<div class="order-item-variant-bundle-booking-wrapper">';
186 $is_past = ( ! $cancelled_booking->is_upcoming() ) ? 'is-past' : '';
187 $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 );
188 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-' . esc_attr( $cancelled_booking->status ) . ' ' . $is_past . '" ' . $trigger_html . '>
189 <div class="booking-item-status-pill"></div>
190 <div class="bib-datetime">' . esc_html( $cancelled_booking->get_nice_start_datetime() ) . '</div>
191 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
192 </div>';
193 echo '</div>';
194 }
195 echo '</div>';
196 echo '</div>';
197 }
198 }
199 echo '</div>';
200 echo '<div class="bookable-items">';
201 for ( $i = 1; $i <= $total_bookable_quantity; $i++ ) {
202 $is_past = ( $i <= $past_count ) ? 'is-past' : '';
203 $is_booked = ( $i <= $booked_count ) ? 'is-booked' : '';
204 echo '<div class="bookable-item ' . esc_attr( $is_past ) . ' ' . esc_attr( $is_booked ) . '"></div>';
205 }
206 echo '</div>';
207
208 }
209 ?>
210 </div>
211 <?php
212 $response_html = ob_get_clean();
213 return $response_html;
214 }
215
216 /**
217 * @param array $item_data
218 * @return OsBundleModel
219 */
220 public static function build_bundle_model_from_item_data( array $item_data ): OsBundleModel {
221 $bundle = new OsBundleModel();
222 if ( ! empty( $item_data['bundle_id'] ) ) {
223 $loaded = $bundle->load_by_id( $item_data['bundle_id'] );
224 if ( $loaded ) {
225 $bundle = $loaded;
226 }
227 }
228 return $bundle;
229 }
230
231
232 /**
233 * @param OsBundleModel $bundle
234 * @return mixed|void
235 *
236 * Returns full amount to charge in database format 1999.0000
237 *
238 */
239 public static function calculate_full_amount_for_bundle( OsBundleModel $bundle ) {
240 $amount = $bundle->charge_amount;
241 $amount = apply_filters( 'latepoint_full_amount_for_bundle', $amount, $bundle );
242 $amount = OsMoneyHelper::pad_to_db_format( $amount );
243 return $amount;
244 }
245
246
247 /**
248 * @param OsBundleModel $bundle
249 * @param array $options
250 * @return mixed|void
251 *
252 * Returns deposit amount to charge in database format 1999.0000
253 *
254 */
255 public static function calculate_deposit_amount_for_bundle( OsBundleModel $bundle ) {
256 $amount = $bundle->deposit_amount;
257 $amount = apply_filters( 'latepoint_deposit_amount_for_bundle', $amount, $bundle );
258 $amount = OsMoneyHelper::pad_to_db_format( $amount );
259 return $amount;
260 }
261 }
262