<?php

namespace App\Http\Controllers\Dosen;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Models\Periode;
use App\Models\MonevInternal;
use App\Models\JadwalKegiatan;

use Session;
use Alert;
use Auth;

class MonevController extends Controller
{
    public function monev($id)
    {
        $bio      = auth()->user()->rBiodata;
        $nidn      = $bio->noidentitas;
        $periode  = Periode::where('status', 1)->first();
        $jadwal   = JadwalKegiatan::where('periode_id', $periode->periode_id)->where('nama','Monev Internal '.$id)->first();

        $title    = 'Monev Internal '.$id;
        $proposal = MonevInternal::with(['rProposal', 'rJenisMonev'])
                    ->whereHas('rProposal', function ($query) use($nidn){
                        $query->whereHas('rKelompok', function ($query) use($nidn){
                                $query->where('nidn_dosen', $nidn);
                        });
                    })
                    ->whereHas('rJenisMonev', function ($query) use($id){
                        $query->where('nama', 'Monev Internal '.$id);
                    })
                    ->orderBy('created_at')
                    ->get();

               // dd($proposal);
        $data = [
            'proposal'  => $proposal,
            'title'     => $title,
            'jadwal'    => $jadwal,
        ];

        return view('backend.dosen.monev.indexmonev'.$id, $data);
    }

}
