<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\ProfileSekolah as Profile;
use App\Models\Kuesioner;
use App\Models\KuesionerLog;
use App\Models\Master\Provinsi;
use App\Models\Master\Sekolah;
use App\Models\DokumenAdministrasi;

class KuesionerController extends Controller
{
    protected $template = 'modules.kuesioner';
    protected $route = 'modules.kuesioner';

    public function index()
    {
        permission('is_read', $this->route, 'module',true);


        if(session('group_alias') == 'sekolah'){

            $data['profile'] = Profile::where('ms_sekolah_id',session('sekolah_id'))->first();
            if(!@$data['profile']->data_jumlah && !@$data['profile']->penghematan_air && !@$data['profile']->penghematan_listrik){
                return redirect('profile-sekolah/')->with([
                    'message' => 'Silahkan lengkapi data profile sekolah',
                    'type'    => 'error',
                ]);
            }

            return redirect('kuesioner/update/'.encode_id(session('sekolah_id')));
        }

        $data['provinsi'] = Provinsi::where('kode_wilayah','010000')->get();
        $data['title'] = 'Kuesioner Leveling';
        $data['route'] = $this->route;    
        return view($this->template.'.index', $data);
    }

    public function grid(Request $request)
    {
        $_data = [];
        if(session('kabupaten_id') != ''){
            $kuesioner = Kuesioner::whereHas('sekolah',function($query){
                $query->where('ms_kabupaten_id',session('kabupaten_id'));
            })->where('tahun',date('Y'))->get();
        }else{
            $kuesioner = Kuesioner::where('tahun',date('Y'))->get();
        }

        foreach ($kuesioner as $key => $row) {

            $action = '';

            if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
                $action .= '<a href="'.url('kuesioner/update/'.encode_id($row->ms_sekolah_id)).'" data-toggle="tooltip" title="View Data" class="btn btn-xs btn-block btn-primary"><i class="fal fa-eye text-white"></i></a>';
                if($row->tahun == date('Y')){
                    if(session('group_alias') == 'dinas'){
                        if($row->status == 0){
                            $action .= '<a href="#" data-href="'.url('kuesioner/verifikasi/'.encode_id($row->KuesionerId)).'" data-toggle="tooltip" title="Verifikasi Data" class="btn btn-xs btn-block btn-success verifikasi"><i class="fal fa-check text-white"></i></a>';
                            $action .= '<a href="#" data-href="'.url('kuesioner/tolak/'.encode_id($row->KuesionerId)).'" data-toggle="tooltip" title="Verifikasi Data" class="btn btn-xs btn-block btn-danger tolak"><i class="fal fa-times text-white"></i></a>';
                        }
                    }
                }
            }

            if($row->level == 0){
                $penghargaan = '<i class="fal fa-trophy"></i>&nbsp;Belum Pernah';
            }elseif($row->level == 1){
                $penghargaan = '<i class="fal fa-trophy"></i>&nbsp;Adiwiyata Kab/Kota';
            }elseif($row->level == 2){
                $penghargaan = '<i class="fal fa-trophy"></i>&nbsp;Adiwiyata Provinsi';
            }elseif($row->level == 3){
                $penghargaan = '<i class="fal fa-trophy"></i>&nbsp;Adiwiyata Nasional';
            }elseif($row->level == 4){
                $penghargaan = '<i class="fal fa-trophy"></i>&nbsp;Adiwiyata Mandiri';
            }

            $dok = DokumenAdministrasi::where('ms_sekolah_id',$row->ms_sekolah_id)->where('tahun',date('Y'))->first();
            if(@$dok){
                if(@$dok->status == 1){
                    $labelDok = '<span class="badge bg-success text-white">Dokumen Di Verifikasi</span>';
                }elseif(@$dok->status == 2){
                    $labelDok = '<span class="badge bg-danger text-white">Dokumen Di Tolak</span>';
                }else{
                    $labelDok = '<span class="badge bg-danger text-white">Menuggu Verifikasi Dokumen</span>';
                }
            }else{
                $labelDok = '<span class="badge bg-danger text-white">Belum Upload Dokumen</span>';
            }

            $status = '';
            if($row->status == 0){
                $status = '<span class="badge bg-info text-white">Belum Diverifikasi</span>';
            }elseif($row->status == 1){
                $status = '<span class="badge bg-success text-white">Sudah Diverifikasi</span>';
            }elseif($row->status == 2){
                $status = '<span class="badge bg-danger text-white">Ditolak</span>';
            }elseif($row->status == 11){
                $status = '<span class="badge bg-primary text-white">Terbit SK</span>';
            }else{
                $log  = KuesionerLog::where('kuesioner_id',$row->KuesionerId)->orderBy('created_at','DESC')->first();
                $status = '<span class="badge bg-warning text-white">'.str_replace('_',' ',\Str::title($log->step)).'</span>';
            }

            $sekolah = '';
            $sekolah .= @$row->sekolah->nama_sekolah.'<br>';
            $sekolah .= '<span class="badge bg-success-light text-success">'.@$row->profile->tingkat->name.'</span>&nbsp;';
            $sekolah .= '<span class="badge bg-primary-light text-primary mt-1">'.@$row->profile->status_sekolah.'</span>&nbsp;';
            $sekolah .= '<span class="badge bg-info-light text-info">Level '.levelAdiwiyata($row->npsn).'</span>';
            $sekolah .= '<span class="badge bg-secondary text-secondary text-left mt-1">'.@$row->profile->alamat_sekolah.'</span>&nbsp;';
            

            $_data[] = [
                'no'                => $key+1,
                'id'                => encode_id($row->id),
                'npsn'              => $row->sekolah->npsn,
                'nama'              => $sekolah,
                'status_level'      => '<span style="width:100%" class="badge bg-success-light text-success">Level '.levelAdiwiyata($row->npsn).'</span>',
                'wilayah'           => $row->sekolah->kabupaten->name,
                'kecamatan'         => $row->sekolah->kecamatan->name,
                'alamat_sekolah'    => $row->sekolah->alamat_sekolah,
                'tingkat_sekolah'   => $row->sekolah->tingkat->name,
                'status_sekolah'    => $row->sekolah->status,
                'tahun'             => $row->tahun,
                'alamat_sekolah'    => $row->profile->alamat_sekolah,
                'penghargaan'       => $penghargaan,
                'status'            => kuesionerLogStatus($row->KuesionerId),
                'action'            => $action,
            ];

        }

        return response()->json($_data);
    }

    public function update($id = null)
    {
        permission('is_read', $this->route, 'module',true);

        $keyId = @$id ? decode_id(@$id) : session('sekolah_id');

        $data['profile'] = Profile::where('ms_sekolah_id',$keyId)->first();
        if(!@$data['profile']->data_jumlah && !@$data['profile']->penghematan_air && !@$data['profile']->penghematan_listrik){
            return redirect('profile-sekolah/')->with([
                'message' => 'Silahkan lengkapi data profile sekolah',
                'type'    => 'error',
            ]);
        }

        $data['title'] = 'Kuesioner Leveling';
        $data['route'] = $this->route;    
        $kuesioner     = Kuesioner::where('ms_sekolah_id',$keyId)->where('tahun',date('Y'))->first();
        if(@$kuesioner){
            $data['kuesioner'] = $kuesioner;
        }else{
            $kuesioner         = Kuesioner::where('ms_sekolah_id',$keyId)->where('tahun',(date('Y')-1))->first();
            $data['kuesioner'] = $kuesioner;
        }

        $sekolah = Sekolah::where('MsSekolahId',$keyId)->first();
        
        $data['dok'] = DokumenAdministrasi::where('ms_sekolah_id',$keyId)->where('tahun',date('Y'))->first();
        $data['nama_sekolah']   = @$sekolah->nama_sekolah;
        $data['npsn']           = @$sekolah->npsn;
        $data['status']         = @$sekolah->status;
        $data['alamat_sekolah'] = @$sekolah->profile->alamat_sekolah;
        $data['tingkat']        = @$sekolah->profile->tingkat->name;

        $media                                         = json_decode(@$kuesioner->media);
        $data['selectedMediaValues']                   = collect($media)->pluck('value')->toArray(); // Ambil value yang dipilih
        $data['selectedMediaTexts']                    = collect($media)->keyBy('name');

        $materi                                        = json_decode(@$kuesioner->materi);
        $data['selectedMateriValues']                  = collect($materi)->pluck('value')->toArray(); // Ambil value yang dipilih
        $data['selectedMateriTexts']                   = collect($materi)->keyBy('name');

        $komitmen                                      = json_decode(@$kuesioner->komitmen);
        $data['selectedKomitmenValues']                = collect($komitmen)->pluck('value')->toArray(); // Ambil value yang dipilih
        $data['selectedKomitmenTexts']                 = collect($komitmen)->keyBy('name');

        $kegiatan_lingkungan                           = json_decode(@$kuesioner->kegiatan_lingkungan);
        $data['selectedKegiatanLingkunganValues']      = collect($kegiatan_lingkungan)->pluck('value')->toArray(); // Ambil value yang dipilih
        $data['selectedKegiatanLingkunganTexts']       = collect($kegiatan_lingkungan)->keyBy('name');

        $pihak_kegiatan_lingkungan                     = json_decode(@$kuesioner->pihak_kegiatan_lingkungan);
        $data['selectedPihakKegiatanLingkunganValues'] = collect($pihak_kegiatan_lingkungan)->pluck('value')->toArray(); // Ambil value yang dipilih
        $data['selectedPihakKegiatanLingkunganTexts']  = collect($pihak_kegiatan_lingkungan)->keyBy('name');

        return view($this->template.'.form',$data);
    }

    public function store(Request $request)
    {
        // dd(request()->all());
        try {

            $media                         = request()->input('media', []); // Ambil array media
            $mediaText                     = request()->input('media_text', []); // Ambil array media_text
            $materi                        = request()->input('materi', []); // Ambil array materi
            $materiText                    = request()->input('materi_text', []); // Ambil array materi_text
            $komitmen                      = array(request()->input('komitmen')); // Ambil array komitmen
            $komitmenText                  = request()->input('komitmen_text', []); // Ambil array komitmen_text
            $kegiatan_lingkungan           = request()->input('kegiatan_lingkungan', []); // Ambil array kegiatan_lingkungan
            $kegiatan_lingkunganText       = request()->input('kegiatan_lingkungan_text', []); // Ambil array kegiatan_lingkungan_text
            $pihak_kegiatan_lingkungan     = request()->input('pihak_kegiatan_lingkungan', []); // Ambil array pihak_kegiatan_lingkungan
            $pihak_kegiatan_lingkunganText = request()->input('pihak_kegiatan_lingkungan_text', []); // Ambil array pihak_kegiatan_lingkungan_text

            // Buat array mapping berdasarkan media yang dipilih
            $mediaFormatted         = [];
            $materiFormatted        = [];
            $komitmenFormatted      = [];
            $kegiatanFormatted      = [];
            $pihakKegiatanFormatted = [];

            if(@$media){
                //ISIAN MEDIA
                foreach ($media as $value) {
                    if ($value == 1) {
                        $mediaFormatted[] = [
                            'value' => $value,
                            'name'  => 'sosialisasi',
                            'text'  => $mediaText['sosialisasi'] ?? null
                        ];
                    } elseif ($value == 2) {
                        $mediaFormatted[] = [
                            'value' => $value,
                            'name'  => 'bimtek',
                            'text'  => $mediaText['bimtek'] ?? null
                        ];
                    }elseif ($value == 3) {
                        $mediaFormatted[] = [
                            'value' => $value,
                            'name'  => 'webinar',
                            'text'  => $mediaText['webinar'] ?? null
                        ];
                    }elseif ($value == 4) {
                        $mediaFormatted[] = [
                            'value' => $value,
                            'name'  => 'youtube',
                            'text'  => $mediaText['youtube'] ?? null
                        ];
                    }elseif ($value == 5) {
                        $mediaFormatted[] = [
                            'value' => $value,
                            'name'  => 'lainlain',
                            'text'  => $mediaText['lainlain'] ?? null
                        ];
                    }
                }
            }

            if(@$materi){
                //ISIAN MATERI
                foreach ($materi as $value) {
                    if ($value == 1) {
                        $materiFormatted[] = [
                            'value' => $value,
                            'name'  => 'kebijakan',
                            'text'  => $materiText['kebijakan'] ?? null
                        ];
                    } elseif ($value == 2) {
                        $materiFormatted[] = [
                            'value' => $value,
                            'name'  => 'perencanaan',
                            'text'  => $materiText['perencanaan'] ?? null
                        ];
                    }elseif ($value == 3) {
                        $materiFormatted[] = [
                            'value' => $value,
                            'name'  => 'pelaksanaan',
                            'text'  => $materiText['pelaksanaan'] ?? null
                        ];
                    }elseif ($value == 4) {
                        $materiFormatted[] = [
                            'value' => $value,
                            'name'  => 'pemantauan',
                            'text'  => $materiText['pemantauan'] ?? null
                        ];
                    }elseif ($value == 5) {
                        $materiFormatted[] = [
                            'value' => $value,
                            'name'  => 'lainlain',
                            'text'  => $materiText['lainlain'] ?? null
                        ];
                    }
                }
            }
            
            if(@$komitmen){
                //ISIAN KOMITMEN
                foreach ($komitmen as $value) {
                    if ($value == 1) {
                        $komitmenFormatted[] = [
                            'value' => $value,
                            'name'  => 'bersedia',
                            'text'  => $komitmenText['bersedia'] ?? null
                        ];
                    } elseif ($value == 2) {
                        $komitmenFormatted[] = [
                            'value' => $value,
                            'name'  => 'tidak_bersedia',
                            'text'  => $komitmenText['tidak_bersedia'] ?? null
                        ];
                    }
                }
            }

            if(@$kegiatan_lingkungan){
                //ISIAN KEGIATAN
                foreach ($kegiatan_lingkungan as $value) {
                    if ($value == 1) {
                        $kegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'pemilahan_sampah',
                            'text'  => $kegiatan_lingkunganText['pemilahan_sampah'] ?? null
                        ];
                    } elseif ($value == 2) {
                        $kegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'penanaman_pohon',
                            'text'  => $kegiatan_lingkunganText['penanaman_pohon'] ?? null
                        ];
                    }elseif ($value == 3) {
                        $kegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'kegiatan_1',
                            'text'  => $kegiatan_lingkunganText['kegiatan_1'] ?? null
                        ];
                    }elseif ($value == 4) {
                        $kegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'kegiatan_2',
                            'text'  => $kegiatan_lingkunganText['kegiatan_2'] ?? null
                        ];
                    }elseif ($value == 5) {
                        $kegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'kegiatan_3',
                            'text'  => $kegiatan_lingkunganText['kegiatan_3'] ?? null
                        ];
                    }
                }
            }

            if(@$pihak_kegiatan_lingkungan){
                //ISIAN PIHAK KEGIATAN
                foreach ($pihak_kegiatan_lingkungan as $value) {
                    if ($value == 1) {
                        $pihakKegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'internal',
                            'text'  => $pihak_kegiatan_lingkunganText['internal'] ?? null
                        ];
                    } elseif ($value == 2) {
                        $pihakKegiatanFormatted[] = [
                            'value' => $value,
                            'name'  => 'eksternal',
                            'text'  => $pihak_kegiatan_lingkunganText['eksternal'] ?? null
                        ];
                    }
                }
            }

            //rumus level adiwiyata
            $level = 0;
            if($request->level == 0){
                if(($request->tim_adiwiyata == 1) && ($request->info_pblhs == 1)){
                    $level = 0;
                }elseif(($request->tim_adiwiyata == 1) || ($request->info_pblhs == 2)){
                    $level = 1;
                }elseif(($request->tim_adiwiyata == 2) || ($request->info_pblhs == 1)){
                    $level = 1;
                }else{
                    $level = 2;
                }
            }elseif($request->level == 1){
                $level = 3;
            }elseif($request->level == 2){
                $level = 4;
            }elseif($request->level == 3){
                $level = 5;
            }elseif($request->level == 4){
                $level = 6;
            }

            if (@$request->hasFile('file_usulan')) {
                $file = $request->file('file_usulan');
                $fileExtension = $file->getClientOriginalExtension();
                if($fileExtension != 'pdf'){
                    return redirect()->back()->with([
                        'message' => 'Maaf File Harus Berupa PDF!',
                        'type'    => "error"
                    ]);   
                }
            }

            if (@$request->hasFile('tim_adiwiyata_link')) {
                $file = $request->file('tim_adiwiyata_link');
                $destinationPath = public_path('uploads/tim_adiwiyata');
                $current = Carbon::now()->format('Y/m/d');
                $path = $destinationPath . '/' . $current;
                $fileName = $file->getClientOriginalName();
                $fileMime = $file->getClientMimeType();
                $fileExtension = $file->getClientOriginalExtension();
                $fileSize = $file->getSize();
                if($fileExtension != 'pdf'){
                    return redirect()->back()->with([
                        'message' => 'Maaf File Harus Berupa PDF!',
                        'type'    => "error"
                    ]);   
                }
                $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;

                if (!File::exists($path)) {
                    File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
                }

                $filePathTim = 'tim_adiwiyata/' . $current . '/' . $newFilename;
                $uploaded = $file->move($path, $newFilename);
            }

            if (@$request->hasFile('link_sk_adiwiyata')) {
                $file = $request->file('link_sk_adiwiyata');
                $destinationPath = public_path('uploads/sk_adiwiyata');
                $current = Carbon::now()->format('Y/m/d');
                $path = $destinationPath . '/' . $current;
                $fileName = $file->getClientOriginalName();
                $fileMime = $file->getClientMimeType();
                $fileExtension = $file->getClientOriginalExtension();
                $fileSize = $file->getSize();
                if($fileExtension != 'pdf'){
                    return redirect()->back()->with([
                        'message' => 'Maaf File Harus Berupa PDF!',
                        'type'    => "error"
                    ]);   
                }
                $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;

                if (!File::exists($path)) {
                    File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
                }

                $fileSK = 'sk_adiwiyata/' . $current . '/' . $newFilename;
                $uploaded = $file->move($path, $newFilename);
            }
            

            $insert = new Kuesioner;
            $insert->ms_sekolah_id             = session('sekolah_id');
            $insert->created_by                = auth()->user()->id;
            $insert->npsn                      = session('npsn');
            $insert->level                     = @$request->level;
            $insert->tim_adiwiyata             = @$request->tim_adiwiyata;
            $insert->info_pblhs                = @$request->info_pblhs;
            $insert->media                     = json_encode(@$mediaFormatted);
            $insert->materi                    = json_encode(@$materiFormatted);
            $insert->komitmen                  = json_encode(@$komitmenFormatted);
            $insert->kegiatan_lingkungan       = json_encode(@$kegiatanFormatted);
            $insert->pihak_kegiatan_lingkungan = json_encode(@$pihakKegiatanFormatted);
            $insert->tahun                     = date('Y');
            $insert->link_sk_adiwiyata         = @$fileSK;
            $insert->tahun_penghargaan         = @$request->tahun_penghargaan;
            $insert->tim_adiwiyata_nomor_sk    = @$request->tim_adiwiyata_nomor_sk;
            $insert->tim_adiwiyata_link        = @$filePathTim;
            $insert->status                    = 1;
            $insert->save();

            if (@$request->hasFile('link_sk_adiwiyata')) {
                $dok = DokumenAdministrasi::updateOrCreate([
                    'kuesioner_id'  => $insert->KuesionerId,
                    'ms_sekolah_id' => session('sekolah_id'),
                    'npsn'          => session('npsn'),
                    'created_by'    => auth()->user()->id,
                    'tahun'         => date('Y'),
                ],[
                    'kuesioner_id'  => $insert->KuesionerId,
                    'ms_sekolah_id' => session('sekolah_id'),
                    'npsn'          => session('npsn'),
                    'created_by'    => auth()->user()->id,
                    'tahun'         => date('Y'),
                    'link'          => @$fileSK,
                    'status'        => 0,
                ]); 
            }
            

            if (@$request->hasFile('file_usulan')) {
                $file = $request->file('file_usulan');
                $destinationPath = public_path('uploads/file_usulan');
                $current = Carbon::now()->format('Y/m/d');
                $path = $destinationPath . '/' . $current;
                $fileName = $file->getClientOriginalName();
                $fileMime = $file->getClientMimeType();
                $fileExtension = $file->getClientOriginalExtension();
                $fileSize = $file->getSize();
                if($fileExtension != 'pdf'){
                    return redirect()->back()->with([
                        'message' => 'Maaf File Harus Berupa PDF!',
                        'type'    => "error"
                    ]);   
                }
                $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;

                if (!File::exists($path)) {
                    File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
                }

                $filePathUsulan = 'file_usulan/' . $current . '/' . $newFilename;
                $uploaded = $file->move($path, $newFilename);

                $dok = DokumenAdministrasi::updateOrCreate([
                    'kuesioner_id'  => $insert->KuesionerId,
                    'ms_sekolah_id' => session('sekolah_id'),
                    'npsn'          => session('npsn'),
                    'created_by'    => auth()->user()->id,
                    'tahun'         => date('Y'),
                ],[
                    'kuesioner_id'  => $insert->KuesionerId,
                    'ms_sekolah_id' => session('sekolah_id'),
                    'npsn'          => session('npsn'),
                    'created_by'    => auth()->user()->id,
                    'tahun'         => date('Y'),
                    'file_usulan'   => @$filePathUsulan,
                    'status'        => 0,
                ]); 
            }


            //kuesioner log
            $log = new KuesionerLog;
            $log->kuesioner_id   = $insert->KuesionerId;
            $log->ms_sekolah_id  = session('sekolah_id');
            $log->npsn           = session('npsn');
            $log->ms_group_id    = session('group_id');
            $log->step           = 'sekolah_mengisi_kuesioner_leveling';
            $log->status         = 0;
            $log->created_by     = auth()->user()->id;
            $log->save();

            $log = new KuesionerLog;
            $log->kuesioner_id   = $insert->KuesionerId;
            $log->ms_sekolah_id  = session('sekolah_id');
            $log->npsn           = session('npsn');
            $log->ms_group_id    = session('group_id');
            $log->step           = 'menunggu_verifikasi_kuesioner_leveling';
            $log->status         = 1;
            $log->created_by     = auth()->user()->id;
            $log->save();


            logActivity($request, __('Create',['val' => strtolower(__('Title',['val' => 'Kuesioner Leveling User ID : '.auth()->user()->id]))]));

            return redirect()->back()->with([
                    'message' => 'Berhasil update data',
                    'type'    => 'success',
                ]);



        } catch (Exception $e) {
            return redirect()->back()->with([
                     'message' => $e->getMessage(),
                     'type'    => "error"
                ]);   
        }
    }

    public function verifikasi($id)
    {
        $keyId = decode_id($id);

        $kuesioner = Kuesioner::find($keyId);
        $kuesioner->status = 1;
        $kuesioner->save();

        $log = new KuesionerLog;
        $log->kuesioner_id   = $kuesioner->KuesionerId;
        $log->ms_sekolah_id  = $kuesioner->ms_sekolah_id;
        $log->npsn           = $kuesioner->npsn;
        $log->ms_group_id    = session('group_id');
        $log->step           = 'approve_usulan';
        $log->status         = 1;
        $log->created_by     = auth()->user()->id;
        $log->save();

        return response()->json(['status' => true,'message' => 'Data Berhasil Di Update','type' => 'success']);
    }
    public function tolak($id)
    {
        $keyId = decode_id($id);
        $kuesioner = Kuesioner::find($keyId);
        $kuesioner->status = 2;
        $kuesioner->save();

        $log = new KuesionerLog;
        $log->kuesioner_id   = $kuesioner->KuesionerId;
        $log->ms_sekolah_id  = $kuesioner->ms_sekolah_id;
        $log->npsn           = $kuesioner->npsn;
        $log->ms_group_id    = session('group_id');
        $log->step           = 'tolak_usulan';
        $log->status         = 2;
        $log->created_by     = auth()->user()->id;
        $log->save();

        return response()->json(['status' => true,'message' => 'Data Berhasil Di Update','type' => 'success']);
    }
}
