@php
$query= \App\Models\OrderDetail::where("status" ,"waiting")
->where("branch_id" ,$branch_id)
->where("period_id" ,$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-1)->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->whereNotIn("customer_id" ,$customers_has_prev_levels_id_except);
$waiting =$query->count();
$running_count=0;
if ( $prev_ids){
$the_prev_level_order_details =\App\Models\OrderDetail::where("status" ,"open")
->where("branch_id" ,$branch_id)
->where("period_id" ,$period->id)
->whereIn("course_level_id" , $prev_ids)->pluck("id");
// course_customer
if ( $the_prev_level_order_details) {
$running= \App\Models\CourseCustomer::whereIn("order_detail_id" , $the_prev_level_order_details )
->where("status","Open")
->where("confirmation","Confirmed")
// ->whereIn("course_id" , DB::table('courses_will_be_closed_soon_view')->pluck("id"))->count();
->leftJoin("courses_will_be_closed_soon_view","courses_will_be_closed_soon_view.id","=","course_customers.course_id")->get();
foreach ( $running as $customer_course_x) {
$order_detail_running = \App\Models\OrderDetail::where("customer_id" , $customer_course_x->customer_id)
->where("course_level_id" , $courseLevel->id)
->where("branch_id" , $branch_id)
->where('status' , 'waiting')->first();
if ( $order_detail_running) $running_count++;
}
// dump($running);
}
}
@endphp
{{__('messages.Waiting')}} :
{{$waiting}}
{{__('messages.InClass')}} :
{{$running_count}}
{{__('messages.Min Req')}} :
{{$seleceted_course_level->min_customer_registerd}}
{{__('messages.Remaining')}} :
@if ($seleceted_course_level->min_customer_registerd -$waiting>0)
{{$seleceted_course_level->min_customer_registerd -$waiting}}
@elseif ($seleceted_course_level->min_customer_registerd -$waiting ==0)
{{$seleceted_course_level->min_customer_registerd -$waiting}}
@else
{{abs($seleceted_course_level->min_customer_registerd -$waiting)}}
@endif