| @@ -724,12 +724,12 @@ | ||
| 724 | 724 | } else if ( is_array( $params['dates_to_check'] ) ) { |
| 725 | 725 | |
| 726 | 726 | $start_day_number = 1; |
| 727 | 727 | |
| 728 | - $today_inix_timestamp = strtotime( $params['dates_to_check'][0] . ' 00:00:00' ); // '2023-09-03 00:00:00' | |
| 728 | + $today_inix_timestamp = strtotime( $params['dates_to_check'][0] . ' 00:00:00 UTC' ); // '2023-09-03 00:00:00' | |
| 729 | 729 | |
| 730 | - $dif_in_days = strtotime( $params['dates_to_check'][ ( count( $params['dates_to_check'] ) - 1 ) ] . ' 00:00:00' ) | |
| 731 | - - strtotime( $params['dates_to_check'][0] . ' 00:00:00' ); | |
| 730 | + $dif_in_days = strtotime( $params['dates_to_check'][ ( count( $params['dates_to_check'] ) - 1 ) ] . ' 00:00:00 UTC' ) | |
| 731 | + - strtotime( $params['dates_to_check'][0] . ' 00:00:00 UTC' ); | |
| 732 | 732 | |
| 733 | 733 | $dif_in_days = $dif_in_days / ( 24 * 60 * 60 ); |
| 734 | 734 | $params['max_days_count'] = ceil( $dif_in_days ) + 1; |
| 735 | 735 | } |
| @@ -959,11 +959,20 @@ | ||
| 959 | 959 | |
| 960 | 960 | // ===================================================================================================== |
| 961 | 961 | // Change over days = |
| 962 | 962 | // ===================================================================================================== |
| 963 | + $is_booking_used_check_in_out_time = null; | |
| 964 | + if ( function_exists( 'wpbc_settings_calendar__preview_is_changeover_enabled' ) ) { | |
| 965 | + $is_booking_used_check_in_out_time = wpbc_settings_calendar__preview_is_changeover_enabled( $resource_id, $params['request_uri'] ); | |
| 966 | + } | |
| 967 | + if ( null === $is_booking_used_check_in_out_time ) { | |
| 968 | + $is_booking_used_check_in_out_time = ( | |
| 969 | + ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) | |
| 970 | + && ( wpbc_is_booking_used_check_in_out_time( $params['request_uri'], $resource_id ) ) | |
| 971 | + ); | |
| 972 | + } | |
| 963 | 973 | if ( |
| 964 | - ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) | |
| 965 | - && ( wpbc_is_booking_used_check_in_out_time( $params[ 'request_uri' ], $resource_id ) ) | |
| 974 | + $is_booking_used_check_in_out_time | |
| 966 | 975 | && ( ! $availability_per_day[ $my_day_tag ][ $resource_id ]->is_day_unavailable ) // And this date still free false |
| 967 | 976 | ) { |
| 968 | 977 | |
| 969 | 978 | /** |
| @@ -1248,8 +1257,9 @@ | ||
| 1248 | 1257 | $temp_status[] = $bookings_status_element; |
| 1249 | 1258 | } |
| 1250 | 1259 | } |
| 1251 | 1260 | $temp_status = array_filter( $temp_status ); // All entries of array equal to FALSE (0, '', '0' ) will be removed. |
| 1261 | + $temp_status_counts = array_count_values( $temp_status ); | |
| 1252 | 1262 | $temp_status = array_unique( $temp_status ); // Erase duplicates |
| 1253 | 1263 | $availability_per_this_day['summary']['status_for_day'] = $temp_status; |
| 1254 | 1264 | |
| 1255 | 1265 | /** |
| @@ -1274,10 +1284,34 @@ | ||
| 1274 | 1284 | // Priority: available > time_slots_booking > full_day_booking |
| 1275 | 1285 | // > season_filter > resource_availability |
| 1276 | 1286 | // > weekday_unavailable > from_today_unavailable > limit_available_from_today |
| 1277 | 1287 | |
| 1278 | - // if at least one booking "available" then day has this status | |
| 1288 | + // Capacity resources can be available even when every child has a check-in/out or full-day status. | |
| 1289 | + $max_capacity = isset( $availability_per_this_day['max_capacity'] ) ? intval( $availability_per_this_day['max_capacity'] ) : 1; | |
| 1290 | + $blocking_statuses = array( | |
| 1291 | + 'full_day_booking', | |
| 1292 | + 'season_filter', | |
| 1293 | + 'resource_availability', | |
| 1294 | + 'weekday_unavailable', | |
| 1295 | + 'from_today_unavailable', | |
| 1296 | + 'limit_available_from_today', | |
| 1297 | + 'change_over', | |
| 1298 | + ); | |
| 1299 | + $blocked_capacity = 0; | |
| 1300 | + foreach ( $blocking_statuses as $blocking_status ) { | |
| 1301 | + $blocked_capacity += isset( $temp_status_counts[ $blocking_status ] ) ? intval( $temp_status_counts[ $blocking_status ] ) : 0; | |
| 1302 | + } | |
| 1303 | + $booked_capacity__before_check_in = $blocked_capacity + ( isset( $temp_status_counts['check_out'] ) ? intval( $temp_status_counts['check_out'] ) : 0 ); | |
| 1304 | + $booked_capacity__after_check_in = $blocked_capacity + ( isset( $temp_status_counts['check_in'] ) ? intval( $temp_status_counts['check_in'] ) : 0 ); | |
| 1305 | + $is_capacity_available_during_change_over = ( | |
| 1306 | + ( $max_capacity > 1 ) | |
| 1307 | + && ( $max_capacity > max( $booked_capacity__before_check_in, $booked_capacity__after_check_in ) ) | |
| 1308 | + && ( ! in_array( 'time_slots_booking', $availability_per_this_day['summary']['status_for_day'] ) ) | |
| 1309 | + ); | |
| 1310 | + | |
| 1311 | + // if at least one resource is available then day has this status | |
| 1279 | 1312 | if ( in_array( 'available', $availability_per_this_day['summary']['status_for_day'] ) ) { $availability_per_this_day['summary']['status_for_day'] = 'available'; |
| 1313 | + } else if ( $is_capacity_available_during_change_over ) { $availability_per_this_day['summary']['status_for_day'] = 'available'; | |
| 1280 | 1314 | } else if ( in_array( 'time_slots_booking', $availability_per_this_day['summary']['status_for_day'] ) ) { $availability_per_this_day['summary']['status_for_day'] = 'time_slots_booking'; |
| 1281 | 1315 | } else if ( ( ! in_array( 'check_out', $availability_per_this_day['summary']['status_for_day'] ) ) |
| 1282 | 1316 | && ( in_array( 'check_in', $availability_per_this_day['summary']['status_for_day'] ) ) ) { $availability_per_this_day['summary']['status_for_day'] = 'check_in'; |
| 1283 | 1317 | } else if ( ( ! in_array( 'check_in', $availability_per_this_day['summary']['status_for_day'] ) ) |