121 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			121 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers;
 | |
| 
 | |
| use Illuminate\Http\Request;
 | |
| use App\Models\Kuesioner;
 | |
| use App\Models\KuesionerLog;
 | |
| use App\Models\ProfileSekolah;
 | |
| use App\Models\Master\FormKriteria;
 | |
| use App\Models\Penilaian;
 | |
| use App\Models\SK;
 | |
| use App\Models\Usulan;
 | |
| 
 | |
| class HomeController extends Controller
 | |
| {
 | |
|     protected $template = 'modules.dashboard';
 | |
| 
 | |
|     /**
 | |
|      * Create a new controller instance.
 | |
|      *
 | |
|      * @return void
 | |
|      */
 | |
|     public function __construct()
 | |
|     {
 | |
|         $this->middleware('auth');
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Show the application dashboard.
 | |
|      *
 | |
|      * @return \Illuminate\Contracts\Support\Renderable
 | |
|      */
 | |
|     public function index()
 | |
|     {
 | |
|         return view('home');
 | |
|     }
 | |
| 
 | |
|     public function dashboard()
 | |
|     {
 | |
|         $data['title'] = 'Dashboard';
 | |
|         $data['group']  = session('group_alias');
 | |
|         if(session('group_alias') == 'sekolah'){
 | |
|             $data['kuesioner']  = Kuesioner::where('ms_sekolah_id',session('sekolah_id'))->where('tahun',date('Y'))->first();
 | |
|             $data['profile']    = ProfileSekolah::where('ms_sekolah_id',session('sekolah_id'))->first();
 | |
|             $data['page']       = FormKriteria::select('page_number')->groupBy('page_number')->orderBy('page_number','ASC')->pluck('page_number')->count(); 
 | |
|             $data['penilaian']  = Penilaian::select('page_number')->groupBy('page_number')->orderBy('page_number','ASC')->pluck('page_number')->count(); 
 | |
|             $data['sk']         = SK::where('tahun',date('Y'))->where('sekolah','like','%'.session('sekolah_id').'%')->first();
 | |
|             $data['log']  = KuesionerLog::where('kuesioner_id',@$data['kuesioner']->KuesionerId)->orderBy('created_at','DESC')->first();
 | |
| 
 | |
|             return view($this->template.'.sekolah', $data);
 | |
|         }else{
 | |
|             $data['usulan'] = Kuesioner::where('tahun',date('Y'))->get();
 | |
|             $data['total_usulan_kab']       = Kuesioner::where('tahun',date('Y'))->where('level',0)->count();
 | |
|             $data['total_usulan_prov']      = Kuesioner::where('tahun',date('Y'))->where('level',1)->count();
 | |
|             $data['total_usulan_nasional']  = Kuesioner::where('tahun',date('Y'))->where('level',2)->count();
 | |
|             $data['total_usulan_mandiri']   = Kuesioner::where('tahun',date('Y'))->where('level',3)->count();
 | |
| 
 | |
|             $data['total_sekolah_kab']       = Kuesioner::where('tahun',date('Y'))->where('level',0)->where('status',11)->count();
 | |
|             $data['total_sekolah_prov']      = Kuesioner::where('tahun',date('Y'))->where('level',1)->where('status',11)->count();
 | |
|             $data['total_sekolah_nasional']  = Kuesioner::where('tahun',date('Y'))->where('level',2)->where('status',11)->count();
 | |
|             $data['total_sekolah_mandiri']   = Kuesioner::where('tahun',date('Y'))->where('level',3)->where('status',11)->count();
 | |
|             $data['route']                  = 'modules';
 | |
|             return view($this->template.'.admin', $data);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function gridUsulan(Request $request)
 | |
|     {
 | |
|         if(session('kabupaten_id') != ''){
 | |
|             $usulan = Kuesioner::whereHas('sekolah',function($query){
 | |
|                 $query->where('ms_kabupaten_id',session('kabupaten_id'));
 | |
|             })->where('tahun',date('Y'))->get();
 | |
|         }else{
 | |
|             $usulan = Kuesioner::where('tahun',date('Y'))->get();
 | |
|         }
 | |
|         $_data = [];
 | |
|         foreach ($usulan as $key => $row) {
 | |
|             $action = '';
 | |
| 
 | |
|             $sekolah = '';
 | |
|             $sekolah .= @$row->sekolah->nama_sekolah.'<br>';
 | |
|             $sekolah .= '<span class="badge bg-success-light text-success">'.@$row->profile->tingkat->name.'</span> ';
 | |
|             $sekolah .= '<span class="badge bg-primary-light text-primary">'.@$row->profile->status_sekolah.'</span> ';
 | |
| 
 | |
|             if(($row->level+1) == 1){
 | |
|                 $jenis_usulan = '<span class="badge bg-success-light text-success">Adiwiyata Kab/Kota</span>';
 | |
|             }elseif(($row->level+1) == 2){
 | |
|                 $jenis_usulan = '<span class="badge bg-primary-light text-primary">Adiwiyata Provinsi</span>';
 | |
|             }elseif(($row->level+1) == 3){
 | |
|                 $jenis_usulan = '<span class="badge bg-info-light text-info">Adiwiyata Nasional</span>';
 | |
|             }elseif(($row->level+1) == 4){
 | |
|                 $jenis_usulan = '<span class="badge bg-warning-light text-warning">Adiwiyata Mandiri</span>';
 | |
|             }
 | |
| 
 | |
|             if($row->level == 0){
 | |
|                 $usulanAwal = 'Belum Pernah';
 | |
|             }elseif($row->level == 1){
 | |
|                 $usulanAwal = 'Adiwiyata Kab/Kota';
 | |
|             }elseif($row->level == 2){
 | |
|                 $usulanAwal = 'Adiwiyata Provinsi';
 | |
|             }elseif($row->level == 3){
 | |
|                 $usulanAwal = 'Adiwiyata Nasional';
 | |
|             }elseif($row->level == 4){
 | |
|                 $usulanAwal = 'Adiwiyata Mandiri';
 | |
|             }
 | |
| 
 | |
|             
 | |
|             $_data[] = [
 | |
|                 'no'                 => $key+1,
 | |
|                 'nama_sekolah'       => @$sekolah,
 | |
|                 'npsn'               => @$row->sekolah->npsn,
 | |
|                 'kab'                => @$row->sekolah->kabupaten->name,
 | |
|                 'kecamatan'          => @$row->sekolah->kecamatan->name,
 | |
|                 'usulan_sebelumnya'  => @$usulanAwal,
 | |
|                 'pengajuan_usulan'   => @$jenis_usulan,
 | |
|             ];
 | |
|         }
 | |
|         return response()->json($_data);
 | |
|     }
 | |
| }
 |