@extends('adminlte::page')
@section('content_header')
    @notifyCss
    @notifyJs
@stop
@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card card-primary">
                <div class="card-header">
                    <h3 class="card-title">View Schedule</h3>
                </div>
                @include('notify::messages')
                <!-- /.card-header -->
                <!-- form start -->
                <form id="userregform" class="form-horizontal" action="{{URL::to('/schedule_participants_attendance_post')}}" method="post" autocomplete="off" enctype="multipart/form-data">
                  {{ csrf_field() }}
                  <div class="card-body">
                      <div class="col-12">
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Organisation</label><br>
                                  {{$schedules->organisation->organisation_name}}
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Department</label><br>
                                  @if(isset($schedules->department_id))
                                    {{$schedules->department->department_name}}
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Section</label><br>
                                  @if(isset($schedules->section_id))
                                    {{$schedules->section->section_name}}
                                  @endif
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Material Type</label><br>
                                  {{$schedules->material_type->material_type_name}}
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Training Title</label><br>
                                  {{$schedules->training_title}}
                                  <input type="hidden" name="schedule_id" id="schedule_id" value="{{$schedules->id}}">
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Venue</label><br>
                                  {{$schedules->venue}}
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Training Period</label><br>
                                  @php
                                    $period_from = $schedules->period_from;
                                    $period_to = $schedules->period_to;
                                    if($period_from)
                                    {
                                        $period_from_display = date("d-M-Y", strtotime($period_from));
                                    }
                                    if($period_to)
                                    {
                                        $period_to_display = date("d-M-Y", strtotime($period_to));
                                    }
                                    echo $period_from_display." to ".$period_to_display;
                                  @endphp 
                                  
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Min & Max seats for training</label><br>
                                  @php
                                    $min_seat_training = $schedules->min_seat_training;
                                    $max_seat_training = $schedules->max_seat_training;
                                    
                                    echo $min_seat_training." & ".$max_seat_training;
                                  @endphp 
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Roles</label><br>
                                  {{$schedules->training_title}}
                              </div>
                          </div>
                          <div class="form-group row">
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Whether Registration is Needed?</label><br>
                                  @if($schedules->registration_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Question and Answers for Training</label><br>
                                  @if($schedules->question_answer_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif
                              </div>
                              <div class="col-3">
                                  <label for="exampleInputEmail1">Reviews and Feedback Needed?</label><br>
                                  @if($schedules->review_status==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif                                  
                              </div>
                              <div class="col-3">
                                <label for="exampleInputEmail1">Training Certificates Needed?</label><br>
                                  @if($schedules->training_certificates==1)
                                    @php
                                      echo "Yes";
                                    @endphp
                                  @else
                                    @php
                                      echo "No";
                                    @endphp
                                  @endif   
                              </div>
                          </div>
                          @php
                            $period_from_str=strtotime($period_from);
                            $today_str = strtotime(date("Y-m-d"));
                            $att_flag =0;
                          @endphp
                            
                          <div id="listroledata" style="padding: 10px;">
                            @if($period_from_str>$today_str)
                              <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                                <tr>
                                  <td colspan="3"style=" text-align: center;"> 
                                    <span style="color: red;"><b>Training Not Started.</b></span>                                   
                                  </td>
                                </tr>
                              </table>
                            @else
                              <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                                  <thead>
                                      <tr class="success">
                                        <th width="10%">Slno</th>
                                        <th>Participant Name</th>
                                        @foreach($training_date as $training_date_val)
                                        <th>
                                          {{$training_date_val}}
                                        </th>
                                        @endforeach
                                      </tr>
                                  </thead>
                                  <tbody>                                    
                                      @php
                                        $n= 0;
                                        $att_flag =0;
                                      @endphp
                                      @if(isset($schedules->schedule_participants))
                                        @foreach($schedules->schedule_participants as $schedule_participant)
                                          @php
                                            $n++;
                                            $participant_id = $schedule_participant->user_id;
                                          @endphp
                                          <tr>
                                            <td>{{$n}}</td>
                                            <td>{{$schedule_participant->users->name}}</td>
                                            @foreach($training_date as $training_date_val)
                                              @php
                                                $date_training_value = date("Y-m-d", strtotime($training_date_val));
                                              @endphp
                                            <td>
                                              @php
                                                $today = date("Y-m-d");
                                                $today_str = strtotime($today);
                                                $period_from_str = strtotime($period_from);
                                              @endphp
                                              @if($today_str>=$period_from_str)
                                                @php
                                                  $att_flag = 1;
                                                @endphp
                                                @if($attendance_status[$participant_id][$date_training_value]==1)
                                                <input type="checkbox" checked="checked" name="{{$participant_id}}attendance_status{{$training_date_val}}" id="{{$participant_id}}attendance_status{{$training_date_val}}" data-toggle="toggle" data-on="Present" data-off="Absent" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                                @else
                                                <input type="checkbox" name="{{$participant_id}}attendance_status{{$training_date_val}}" id="{{$participant_id}}attendance_status{{$training_date_val}}" data-toggle="toggle" data-on="Present" data-off="Absent" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                                @endif
                                              @endif
                                            </td>
                                            @endforeach
                                          </tr>
                                        @endforeach
                                      @else
                                        <tr>
                                          <td colspan="3" style=" text-align: center;">
                                              <span style="color: red;">No Participants are assigned yet !!!</span>
                                          </td>
                                        </tr>
                                      @endif                                   
                                  </tbody>
                              </table>
                            @endif
                          </div>                        
                      </div>
                  </div>
                  <!-- /.card-body -->
                  <div class="card-footer">
                    @if($att_flag==1)
                    <button type="submit" class="btn btn-primary pull-right">Submit Attendance</button>
                    @endif
                  </div>
                </form>
            </div>
        </div>        
    </div>
    
@stop
