_booking_box_on_calendar.php
1 year ago
_day.php
1 year ago
_list.php
1 year ago
_month.php
1 year ago
_shared.php
1 year ago
_week.php
1 year ago
_month.php
165 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @var $target_date OsWpDateTime |
| 4 | * @var $today_date OsWpDateTime |
| 5 | * @var $calendar_start OsWpDateTime |
| 6 | * @var $calendar_end OsWpDateTime |
| 7 | * @var $booking_request \LatePoint\Misc\BookingRequest |
| 8 | * @var $calendar_settings array |
| 9 | * @var $agents OsAgentModel[] |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; // Exit if accessed directly |
| 15 | } |
| 16 | ?> |
| 17 | |
| 18 | <?php |
| 19 | if($agents){ ?> |
| 20 | <?php |
| 21 | $agents_head_html = ''; |
| 22 | foreach($agents as $agent){ |
| 23 | $agents_head_html.= |
| 24 | '<div class="ma-head-agent"> |
| 25 | <div class="ma-head-agent-avatar" style="background-image: url('.esc_url($agent->get_avatar_url()).')"></div> |
| 26 | <div class="ma-head-agent-name">'.esc_html($agent->full_name).'</div> |
| 27 | </div>'; |
| 28 | } |
| 29 | $calendar_not_scrollable_class = (count($agents) > 4) ? '' : 'calendar-month-not-scrollable'; |
| 30 | echo '<div class="calendar-month-agents-w '.esc_attr($calendar_not_scrollable_class).'" data-route="'.esc_attr(OsRouterHelper::build_route_name('calendars', 'month_view')).'">'; |
| 31 | echo '<div class="ma-floated-days-w">'; |
| 32 | echo '<div class="ma-head-info"><span>'.esc_html__('Date', 'latepoint').'</span><span>'.esc_html__('Agent', 'latepoint').'</span></div>'; |
| 33 | for($day_date=clone $calendar_start; $day_date<=$calendar_end; $day_date->modify('+1 day')){ |
| 34 | echo '<div class="ma-day ma-day-number-'.esc_attr($day_date->format('N')).' '.(($today_date == $day_date) ? 'is-today' : '').'">'; |
| 35 | echo '<div class="ma-day-info">'; |
| 36 | echo '<span class="ma-day-number">'.esc_html($day_date->format('j')).'</span>'; |
| 37 | echo '<span class="ma-day-weekday">'.esc_html(OsUtilHelper::get_weekday_name_by_number($day_date->format('N'), true)).'</span>'; |
| 38 | echo '</div>'; |
| 39 | echo '</div>'; |
| 40 | } |
| 41 | echo '</div>'; |
| 42 | echo '<div class="ma-days-with-bookings-w">'; |
| 43 | echo '<div class="ma-days-with-bookings-i">'; |
| 44 | echo '<div class="ma-head">'; |
| 45 | echo $agents_head_html; |
| 46 | echo '</div>'; |
| 47 | for($day_date=clone $calendar_start; $day_date<=$calendar_end; $day_date->modify('+1 day')){ |
| 48 | echo '<div class="ma-day ma-day-number-'.esc_attr($day_date->format('N')).' '.(($today_date == $day_date) ? 'is-today' : '').'">'; |
| 49 | foreach($agents as $agent){ |
| 50 | $day_periods = []; |
| 51 | $blocked_blocks = []; |
| 52 | foreach($resources[$day_date->format('Y-m-d')] as $resource){ |
| 53 | // TODO if multiple resources available for this day - merge blocked periods to find intersections - those intersection perons are truly blocked |
| 54 | if($resource->agent_id == $agent->id){ |
| 55 | $day_periods = array_merge($day_periods, $resource->work_time_periods); |
| 56 | foreach($resource->blocked_time_periods as $blocked_time_period){ |
| 57 | $left = max(($blocked_time_period->start_time - $work_boundaries->start_time) / $work_total_minutes * 100, 0); |
| 58 | $right = max(($work_boundaries->end_time - $blocked_time_period->end_time) / $work_total_minutes * 100, 0); |
| 59 | $blocked_blocks[] = ['left' => $left, 'right' => $right]; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | usort($day_periods,function($first,$second){ |
| 66 | return ($first->start_time > $second->start_time) ? 1 : 0; |
| 67 | }); |
| 68 | $day_periods = \LatePoint\Misc\TimePeriod::merge_periods($day_periods); |
| 69 | if($day_periods){ |
| 70 | echo '<div class="ma-day-agent-bookings" '.OsOrdersHelper::quick_order_btn_html(false, array('agent_id' => $agent->id, 'location_id' => $booking_request->location_id, 'start_date' => $day_date->format('Y-m-d'))).'>'; |
| 71 | $off_blocks = []; |
| 72 | foreach($day_periods as $day_period){ |
| 73 | if($day_period->start_time > $work_boundaries->start_time){ |
| 74 | if($off_blocks){ |
| 75 | $right = ($work_boundaries->end_time - $day_period->start_time) / $work_total_minutes * 100; |
| 76 | $off_blocks[count($off_blocks) - 1]['right'] = $right; |
| 77 | }else{ |
| 78 | $right = ($work_boundaries->end_time - $day_period->start_time) / $work_total_minutes * 100; |
| 79 | $off_blocks[] = ['left' => 0, 'right' => $right]; |
| 80 | } |
| 81 | } |
| 82 | if($day_period->end_time < $work_boundaries->end_time){ |
| 83 | $left = ($day_period->end_time - $work_boundaries->start_time) / $work_total_minutes * 100; |
| 84 | $off_blocks[] = ['left' => $left, 'right' => 0]; |
| 85 | } |
| 86 | } |
| 87 | foreach($blocked_blocks as $blocked_block){ |
| 88 | echo '<div class="ma-day-off" style="left:'.esc_attr($blocked_block["left"]).'%; right: '.esc_attr($blocked_block["right"]).'%;"></div>'; |
| 89 | } |
| 90 | foreach($off_blocks as $off_block){ |
| 91 | echo '<div class="ma-day-off" style="left:'.esc_attr($off_block["left"]).'%; right: '.esc_attr($off_block["right"]).'%;"></div>'; |
| 92 | } |
| 93 | echo '<div class="ma-day-work-periods">'; |
| 94 | echo '<div class="ma-day-label">'.esc_html($day_date->format($date_format)).': </div>'; |
| 95 | foreach($day_periods as $day_period){ |
| 96 | echo '<div class="ma-day-work-period">'; |
| 97 | echo esc_html(OsTimeHelper::minutes_to_hours_and_minutes($day_period->start_time).' - '.OsTimeHelper::minutes_to_hours_and_minutes($day_period->end_time)); |
| 98 | echo '</div>'; |
| 99 | } |
| 100 | echo '</div>'; |
| 101 | if($bookings_grouped_by_date_and_agent[$day_date->format('Y-m-d')][$agent->id]){ |
| 102 | $overlaps_count = 1; |
| 103 | $total_attendees_in_group = 0; |
| 104 | $total_bookings_in_group = 0; |
| 105 | $total_bookings = count($bookings_grouped_by_date_and_agent[$day_date->format('Y-m-d')][$agent->id]); |
| 106 | foreach($bookings_grouped_by_date_and_agent[$day_date->format('Y-m-d')][$agent->id] as $index => $booking){ |
| 107 | $next_booking = (($index + 1) < $total_bookings) ? $bookings_grouped_by_date_and_agent[$day_date->format('Y-m-d')][$agent->id][$index + 1] : false; |
| 108 | if(OsBookingHelper::check_if_group_bookings($booking, $next_booking)){ |
| 109 | // skip this output because multiple bookings in the same slot because next booking has the same start and end time |
| 110 | $total_attendees_in_group+= $booking->total_attendees; |
| 111 | $total_bookings_in_group++; |
| 112 | continue; |
| 113 | }else{ |
| 114 | if($booking->end_date && ($booking->start_date != $booking->end_date)){ |
| 115 | $width = (24*60 - $booking->start_time) / $work_total_minutes * 100; |
| 116 | $left = ($booking->start_time - $work_boundaries->start_time) / $work_total_minutes * 100; |
| 117 | }else{ |
| 118 | $width = ($booking->end_time - $booking->start_time) / $work_total_minutes * 100; |
| 119 | $left = ($booking->start_time - $work_boundaries->start_time) / $work_total_minutes * 100; |
| 120 | } |
| 121 | |
| 122 | $max_capacity = OsServiceHelper::get_max_capacity($booking->service); |
| 123 | if($max_capacity > 1){ |
| 124 | $action_html = OsBookingHelper::group_booking_btn_html($booking->id); |
| 125 | }else{ |
| 126 | $action_html = OsBookingHelper::quick_booking_btn_html($booking->id); |
| 127 | } |
| 128 | if($width <= 0 || $left >= 100 || (($left + $width) <= 0)) continue; |
| 129 | if($left < 0){ |
| 130 | $width = $width + $left; |
| 131 | $left = 0; |
| 132 | } |
| 133 | if(($left + $width) > 100) $width = 100 - $left; |
| 134 | |
| 135 | echo '<div class="ma-day-booking" style="left: '.esc_attr($left).'%; width: '.esc_attr($width).'%; background-color: '.esc_attr($booking->service->bg_color).'" '.$action_html.'>'; |
| 136 | $hide_agent_info = true; |
| 137 | include(LATEPOINT_VIEWS_ABSPATH.'dashboard/_booking_info_box_small.php'); |
| 138 | echo '</div>'; |
| 139 | // time overlaps |
| 140 | $overlaps_count = ($next_booking && ($next_booking->start_time < $booking->end_time)) ? $overlaps_count + 1 : 1; |
| 141 | // reset |
| 142 | $total_attendees_in_group = 0; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | echo '</div>'; |
| 147 | }else{ |
| 148 | echo '<div class="ma-day-agent-bookings is-day-off">'; |
| 149 | echo '<div class="ma-day-off full"><span><strong>'.esc_html($day_date->format($date_format)).': </strong>'.esc_html__('Day Off', 'latepoint').'</span></div>'; |
| 150 | echo '</div>'; |
| 151 | } |
| 152 | } |
| 153 | echo '</div>'; |
| 154 | } |
| 155 | echo '</div>'; |
| 156 | echo '</div>'; |
| 157 | echo '</div>'; |
| 158 | }else{ ?> |
| 159 | <div class="no-results-w"> |
| 160 | <div class="icon-w"><i class="latepoint-icon latepoint-icon-grid"></i></div> |
| 161 | <h2><?php esc_html_e('No Agents Created', 'latepoint'); ?></h2> |
| 162 | <a href="<?php echo esc_url(OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'new_form') )); ?>" class="latepoint-btn"><i class="latepoint-icon latepoint-icon-plus-square"></i><span><?php esc_html_e('Create Agent', 'latepoint'); ?></span></a> |
| 163 | </div> |
| 164 | <?php } ?> |
| 165 | <?php include('_shared.php'); ?> |