@php
$query_null= \App\Models\OrderDetail::where("status" ,"waiting")
->where("branch_id" ,$branch_id)
->whereNull("period_id")
->where("course_level_id" ,$courseLevel->id);
$seleceted_course_level = \App\Models\CourseLevel::find($courseLevel->id);
// // get all previous levels less than order
$prev_ids =$seleceted_course_level->product->course_levels()->where("level_order" , --$seleceted_course_level->level_order)->pluck("id");
// // get the customers has order with previous levels and waiting or open "not finished the previous level yet"
$customers_has_prev_levels_id_except =\App\Models\OrderDetail::whereIn("status" ,["waiting","open"])->whereIn("course_level_id" , $prev_ids)->pluck("customer_id");
// except the customers has waiting previous levels
$query_null->whereNotIn("customer_id" ,$customers_has_prev_levels_id_except);
$waiting_null =$query_null->count();
$running_count_null=0;
if ( $prev_ids){
$the_prev_level_order_details_null =\App\Models\OrderDetail::where("status" ,"open")
->where("branch_id" ,$branch_id)
->whereNull("period_id")
->whereIn("course_level_id" , $prev_ids)->pluck("id");
// course_customer
if ( $the_prev_level_order_details_null) {
$running_null= \App\Models\CourseCustomer::whereIn("order_detail_id" , $the_prev_level_order_details_null )
->where("status","Open")
->where("confirmation","Confirmed")
// ->whereIn("course_id" , \DB::table('courses_will_be_closed_soon_view')->whereIn("course_level_id",$prev_ids )->pluck("id"))->count();
->leftJoin("courses_will_be_closed_soon_view","courses_will_be_closed_soon_view.id","=","course_customers.course_id")->get();
foreach ( $running_null as $customer_course_y) {
$order_detail_running_null = \App\Models\OrderDetail::where("customer_id" , $customer_course_y->customer_id
)->where("course_level_id" , $courseLevel->id)->where("branch_id" , $branch_id)
->where('status' , 'waiting')->first();
if ( $order_detail_running_null) $running_count_null++;
}
// dump( $running_null);
}
}
@endphp
{{__('messages.Waiting')}} :
{{$waiting_null}}
{{__('messages.InClass')}} :
{{$running_count_null}}
{{__('messages.Min Req')}} : {{$seleceted_course_level->min_customer_registerd}}
{{__('messages.Remaining')}} :
@if ($seleceted_course_level->min_customer_registerd -$waiting_null>0)
{{$seleceted_course_level->min_customer_registerd -$waiting_null}}
@elseif ($seleceted_course_level->min_customer_registerd -$waiting_null ==0)
{{$seleceted_course_level->min_customer_registerd -$waiting_null}}
@else
{{abs($seleceted_course_level->min_customer_registerd -$waiting_null)}}
@endif