@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 Details</h3>
                </div>
                @include('notify::messages')
                <!-- /.card-header -->
                <!-- form start -->
                <form id="userregform" class="form-horizontal" action="{{URL::to('/particiapant_certificate_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"));
                            $display_flag= 0;
                          @endphp
                          <div id="listroledata" style="padding: 10px;">
                            @if($period_from_str>$today_str)
                              @php
                                $display_flag = 0;
                              @endphp
                              <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
                              @php
                                $display_flag = 1;
                              @endphp
                              <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>
                                        <th>Number of Presnt Days</th>
                                        <th>Number of Absent Days</th>
                                        <th></th>
                                        <th></th>
                                      </tr>
                                  </thead>
                                  <tbody>
                                    @php
                                      $n= 0;
                                      $schedule_participant_id = "";
                                    @endphp
                                    @if(isset($schedules->schedule_participants))
                                      @foreach($schedules->schedule_participants as $schedule_participant)
                                        @php
                                          $n++;
                                          $participant_id = $schedule_participant->user_id;
                                          $schedule_id = $schedule_participant->schedule_id;
                                        @endphp
                                        <tr>
                                          <td>{{$n}}</td>
                                          <td>{{$schedule_participant->users->name}}</td>
                                          <td>
                                            {{$participant_present_attendance[$participant_id]}}
                                          </td>
                                          <td>
                                            {{$participant_absent_attendance[$participant_id]}}
                                          </td>
                                          <td>
                                            @if($certificate_status_marked[$participant_id]==1)
                                            <input type="checkbox" checked="checked" name="{{$participant_id}}certificate" id="{{$participant_id}}certificate" value="1">
                                            @else
                                            <input type="checkbox" name="{{$participant_id}}certificate" id="{{$participant_id}}certificate" value="1">
                                            @endif
                                          </td>
                                          <td>
                                            @if($certificate_status_marked[$participant_id]==1)
                                              @php
                                                $schedule_participant_id = $schedule_id."~".$participant_id;
                                              @endphp
                                              <a href="{{URL::to('/certificatepreview')}}/{{$schedule_participant_id}}" class="btn btn-xs btn-info pull-right" target="_blank">View Certificate</a>
                                            @endif
                                          </td>
                                        </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($display_flag==1)
                    <button type="submit" class="btn btn-primary pull-right">Generate Certificate</button>
                    @endif
                  </div>
                </form>
            </div>
        </div>        
    </div>
    
@stop
