PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
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 1 week ago auth_helper.php 6 days ago blocks_helper.php 3 weeks ago booking_helper.php 4 days ago bricks_helper.php 3 months ago bundles_helper.php 4 days ago calendar_helper.php 3 days ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 1 month ago customer_import_helper.php 1 month ago database_helper.php 1 week 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 weeks 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 3 weeks 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 2 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 2 months ago plugin_version_update_helper.php 2 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago razorpay_connect_helper.php 1 week ago replacer_helper.php 3 months ago resource_helper.php 4 days ago roles_helper.php 3 weeks ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 1 week ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 weeks ago sms_helper.php 3 months ago steps_helper.php 1 week ago stripe_connect_helper.php 1 week ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 2 months ago timeline_helper.php 2 months ago transaction_helper.php 1 month ago transaction_intent_helper.php 3 months ago util_helper.php 1 month ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 1 month ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
bundles_helper.php
263 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-nonce="<?php echo esc_attr( wp_create_nonce( 'remove_item_from_cart' ) ); ?>"
125 data-route="<?php echo esc_attr( OsRouterHelper::build_route_name( 'carts', 'remove_item_from_cart' ) ); ?>">
126 <div class="os-remove-from-cart-icon"></div>
127 </div>
128 <?php } ?>
129 <div class="sbc-big-item"><?php echo esc_html( $bundle->name ); ?></div>
130 <div class="sbc-subtle-item">
131 <?php echo esc_html( implode( ', ', $bundle_services_descriptions ) ); ?>
132 </div>
133 </div>
134 <?php if ( $order_item_id ) {
135 $past_count = 0;
136 $booked_count = 0;
137 if ( $user_type == LATEPOINT_USER_TYPE_CUSTOMER ) {
138 $order_item = new OsOrderItemModel( $order_item_id );
139 $order = new OsOrderModel( $order_item->order_id );
140 // translators: %s is the order confirmation code
141 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>';
142 }
143 echo '<div class="bookable-items-breakdown">';
144 foreach ( $bundle_services as $service ) {
145 $bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item_id, $service->id, OsBookingHelper::get_non_cancelled_booking_statuses() );
146 foreach ( $bookings as $booking ) {
147 $booked_count++;
148 if ( ! $booking->is_upcoming() ) {
149 $past_count++;
150 }
151 }
152 // translators: %d is the number of sessions
153 if ( count( $bundle_services ) > 1 ) {
154 echo '<div class="bundle-service-info">' . esc_html( $service->name . ' [' . sprintf( __( '%d sessions', 'latepoint' ), $service->join_attributes['quantity'] ) . ']' ) . '</div>';
155 }
156 for ( $i = 0; $i < $service->join_attributes['quantity']; $i++ ) {
157 if ( isset( $bookings[ $i ] ) ) {
158 $is_past = ( ! $bookings[ $i ]->is_upcoming() ) ? 'is-past' : '';
159 $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 );
160 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-' . esc_attr( $bookings[ $i ]->status ) . ' ' . $is_past . '" ' . $trigger_html . '>
161 <div class="booking-item-status-pill"></div>
162 <div class="bib-datetime">' . esc_html( $bookings[ $i ]->get_nice_start_datetime() ) . '</div>
163 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
164 </div>';
165 } else {
166 if ( $user_type == LATEPOINT_USER_TYPE_CUSTOMER ) {
167 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>';
168 } else {
169 echo '<div class="order-item-variant-bundle-booking" ' . OsOrdersHelper::quick_order_btn_html(
170 false,
171 [
172 'order_item_id' => $order_item_id,
173 'service_id' => $service->id,
174 ]
175 ) . '><div class="booking-item-status-pill"></div><div class="bib-label">' . esc_html__( 'Schedule now', 'latepoint' ) . '</div></div>';
176 }
177 }
178 }
179 $cancelled_bookings = OsOrdersHelper::get_bookings_for_order_item( $order_item_id, $service->id, [ LATEPOINT_BOOKING_STATUS_CANCELLED ] );
180 if ( ! empty( $cancelled_bookings ) ) {
181 echo '<div class="order-item-cancelled-bookings-wrapper">';
182 // translators: %d is the number of cancelled appointments
183 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>';
184 echo '<div class="order-item-cancelled-bookings-list">';
185 foreach ( $cancelled_bookings as $cancelled_booking ) {
186 echo '<div class="order-item-variant-bundle-booking-wrapper">';
187 $is_past = ( ! $cancelled_booking->is_upcoming() ) ? 'is-past' : '';
188 $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 );
189 echo '<div class="order-item-variant-bundle-booking is-booked bundle-booking-status-' . esc_attr( $cancelled_booking->status ) . ' ' . $is_past . '" ' . $trigger_html . '>
190 <div class="booking-item-status-pill"></div>
191 <div class="bib-datetime">' . esc_html( $cancelled_booking->get_nice_start_datetime() ) . '</div>
192 <div class="bib-icon"><i class="latepoint-icon latepoint-icon-arrow-right"></i></div>
193 </div>';
194 echo '</div>';
195 }
196 echo '</div>';
197 echo '</div>';
198 }
199 }
200 echo '</div>';
201 echo '<div class="bookable-items">';
202 for ( $i = 1; $i <= $total_bookable_quantity; $i++ ) {
203 $is_past = ( $i <= $past_count ) ? 'is-past' : '';
204 $is_booked = ( $i <= $booked_count ) ? 'is-booked' : '';
205 echo '<div class="bookable-item ' . esc_attr( $is_past ) . ' ' . esc_attr( $is_booked ) . '"></div>';
206 }
207 echo '</div>';
208
209 }
210 ?>
211 </div>
212 <?php
213 $response_html = ob_get_clean();
214 return $response_html;
215 }
216
217 /**
218 * @param array $item_data
219 * @return OsBundleModel
220 */
221 public static function build_bundle_model_from_item_data( array $item_data ): OsBundleModel {
222 $bundle = new OsBundleModel();
223 if ( ! empty( $item_data['bundle_id'] ) ) {
224 $loaded = $bundle->load_by_id( $item_data['bundle_id'] );
225 if ( $loaded ) {
226 $bundle = $loaded;
227 }
228 }
229 return $bundle;
230 }
231
232
233 /**
234 * @param OsBundleModel $bundle
235 * @return mixed|void
236 *
237 * Returns full amount to charge in database format 1999.0000
238 *
239 */
240 public static function calculate_full_amount_for_bundle( OsBundleModel $bundle ) {
241 $amount = $bundle->charge_amount;
242 $amount = apply_filters( 'latepoint_full_amount_for_bundle', $amount, $bundle );
243 $amount = OsMoneyHelper::pad_to_db_format( $amount );
244 return $amount;
245 }
246
247
248 /**
249 * @param OsBundleModel $bundle
250 * @param array $options
251 * @return mixed|void
252 *
253 * Returns deposit amount to charge in database format 1999.0000
254 *
255 */
256 public static function calculate_deposit_amount_for_bundle( OsBundleModel $bundle ) {
257 $amount = $bundle->deposit_amount;
258 $amount = apply_filters( 'latepoint_deposit_amount_for_bundle', $amount, $bundle );
259 $amount = OsMoneyHelper::pad_to_db_format( $amount );
260 return $amount;
261 }
262 }
263