180 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			180 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			PHP
		
	
	
<?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 App\Models\ProfileSekolah as Profile;
 | 
						|
use App\Models\Master\Sekolah;
 | 
						|
use App\Models\Master\Provinsi;
 | 
						|
 | 
						|
class ProfileController extends Controller
 | 
						|
{
 | 
						|
    protected $template = 'modules.profile';
 | 
						|
    protected $route = 'modules.profile';
 | 
						|
 | 
						|
    public function index()
 | 
						|
    {
 | 
						|
        permission('is_read', $this->route, 'module',true);
 | 
						|
 | 
						|
        $data['title'] = 'Profile Sekolah';
 | 
						|
        $data['route'] = $this->route;
 | 
						|
        if(session('group_alias') == 'sekolah'){
 | 
						|
 | 
						|
            $profile = Profile::where('user_id',auth()->user()->id)->first();
 | 
						|
            $jumlah = json_decode($profile->data_jumlah);
 | 
						|
            $data['jumlah_peserta_didik']         = @$jumlah->jumlah_peserta_didik;
 | 
						|
            $data['jumlah_tenaga_pendidik']       = @$jumlah->jumlah_tenaga_pendidik;
 | 
						|
            $data['jumlah_tenaga_kependidikan']   = @$jumlah->jumlah_tenaga_kependidikan;
 | 
						|
            $data['jumlah_warga_sekolah_lainnya'] = @$jumlah->jumlah_warga_sekolah_lainnya;
 | 
						|
            $data['jumlah_biopori']               = @$jumlah->jumlah_biopori;
 | 
						|
            $data['jumlah_sumur_resapan']         = @$jumlah->jumlah_sumur_resapan;
 | 
						|
            $data['jumlah_pohon']                 = @$jumlah->jumlah_pohon;
 | 
						|
 | 
						|
            $air = json_decode($profile->penghematan_air);
 | 
						|
            $data['air_sebelum_pblhs'] = @$air->air_sebelum_pblhs;
 | 
						|
            $data['air_setelah_pblhs'] = @$air->air_setelah_pblhs;
 | 
						|
 | 
						|
            $listrik = json_decode($profile->penghematan_listrik);
 | 
						|
            $data['listrik_sebelum_pblhs'] = @$listrik->listrik_sebelum_pblhs;
 | 
						|
            $data['listrik_setelah_pblhs'] = @$listrik->listrik_setelah_pblhs;
 | 
						|
            $data['luas_ruangan_ac']       = @$listrik->luas_ruangan_ac;
 | 
						|
            $data['luas_ruangan_non_ac']   = @$listrik->luas_ruangan_non_ac;
 | 
						|
            $data['jumlah_kader']          = @$listrik->jumlah_kader;
 | 
						|
            
 | 
						|
            return view($this->template.'.sekolah', $data);
 | 
						|
        }else{
 | 
						|
            $data['provinsi'] = Provinsi::where('kode_wilayah','010000')->get();
 | 
						|
            return view($this->template.'.admin', $data);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function grid(Request $request)
 | 
						|
    {
 | 
						|
        $profile = Profile::groupBy('ms_sekolah_id')->pluck('ms_sekolah_id')->toArray();
 | 
						|
        $sekolah = Sekolah::whereIn('MsSekolahId',$profile)->get();
 | 
						|
        foreach ($sekolah as $key => $row) {
 | 
						|
 | 
						|
            $action = '';
 | 
						|
 | 
						|
            if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
 | 
						|
                $action .= '<a href="'.url('profile-sekolah/update/'.encode_id($row->id)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-xs btn-block btn-primary"><i class="fal fa-pencil text-white"></i></a>';
 | 
						|
            }
 | 
						|
 | 
						|
            if($row->level == 0){
 | 
						|
                $penghargaan = '<i class="fal fa-trophy"></i> Belum Pernah';
 | 
						|
            }elseif($row->level == 1){
 | 
						|
                $penghargaan = '<i class="fal fa-trophy"></i> Adiwiyata Kab/Kota';
 | 
						|
            }elseif($row->level == 2){
 | 
						|
                $penghargaan = '<i class="fal fa-trophy"></i> Adiwiyata Provinsi';
 | 
						|
            }elseif($row->level == 3){
 | 
						|
                $penghargaan = '<i class="fal fa-trophy"></i> Adiwiyata Nasional';
 | 
						|
            }elseif($row->level == 4){
 | 
						|
                $penghargaan = '<i class="fal fa-trophy"></i> Adiwiyata Mandiri';
 | 
						|
            }
 | 
						|
 | 
						|
            $_data[] = [
 | 
						|
                'no'                => $key+1,
 | 
						|
                'id'                => encode_id($row->id),
 | 
						|
                'npsn'              => $row->npsn,
 | 
						|
                'nama'              => $row->nama_sekolah,
 | 
						|
                'status_level'      => '<span class="badge badge-success">Level '.levelAdiwiyata($row->npsn).'</span>',
 | 
						|
                'wilayah'           => $row->kabupaten->name,
 | 
						|
                'tanggal_level'     => '-',
 | 
						|
                'penghargaan'       => $penghargaan,
 | 
						|
                'dok'               => '',
 | 
						|
                'kriteria'          => '',
 | 
						|
                'jenis_usulan'      => 'Nasional',
 | 
						|
                'usulkan_csa'       => 'Diusulkan/ Proses Penilaian',
 | 
						|
                'perpanjang_csa'    => '-',
 | 
						|
                'action'    => $action,
 | 
						|
            ];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        return response()->json($_data);
 | 
						|
    }
 | 
						|
 | 
						|
    public function store(Request $request)
 | 
						|
    {
 | 
						|
        permission('is_update', $this->route, 'module',true);
 | 
						|
 | 
						|
        try {
 | 
						|
            Validator::make($request->all(), [
 | 
						|
                'jumlah_peserta_didik'         => 'required',
 | 
						|
                'jumlah_tenaga_pendidik'       => 'required',
 | 
						|
                'jumlah_tenaga_kependidikan'   => 'required',
 | 
						|
                'jumlah_warga_sekolah_lainnya' => 'required',
 | 
						|
                'jumlah_biopori'               => 'required',
 | 
						|
                'jumlah_sumur_resapan'         => 'required',
 | 
						|
                'jumlah_pohon'                 => 'required',
 | 
						|
 | 
						|
                'air_sebelum_pblhs'            => 'required',
 | 
						|
                'air_setelah_pblhs'            => 'required',
 | 
						|
 | 
						|
                'listrik_sebelum_pblhs'        => 'required',
 | 
						|
                'listrik_setelah_pblhs'        => 'required',
 | 
						|
                'luas_ruangan_ac'              => 'required',
 | 
						|
                'luas_ruangan_non_ac'          => 'required',
 | 
						|
                'jumlah_kader'                 => 'required',
 | 
						|
            ],[
 | 
						|
                'jumlah_peserta_didik.required'         => 'Jumlah Peserta Didik Tidak Boleh Kosong',
 | 
						|
                'jumlah_tenaga_pendidik.required'       => 'Jumlah Tenaga Pendidik Tidak Boleh Kosong',
 | 
						|
                'jumlah_tenaga_kependidikan.required'   => 'Jumlah Tenaga Kependidikan Tidak Boleh Kosong',
 | 
						|
                'jumlah_warga_sekolah_lainnya.required' => 'Jumlah Warga Sekolah Lainnya Tidak Boleh Kosong',
 | 
						|
                'jumlah_biopori.required'               => 'Jumlah Biopori Tidak Boleh Kosong',
 | 
						|
                'jumlah_sumur_resapan.required'         => 'Jumlah Sumur Resapan Tidak Boleh Kosong',
 | 
						|
                'jumlah_pohon.required'                 => 'Jumlah Pohon Tidak Boleh Kosong',
 | 
						|
 | 
						|
                'air_sebelum_pblhs.required'            => 'Penghematan Air Sebelum PBLHS Tidak Boleh Kosong',
 | 
						|
                'air_setelah_pblhs.required'            => 'Penghematan Air Setelah PBLHS Tidak Boleh Kosong',
 | 
						|
 | 
						|
                'listrik_sebelum_pblhs.required'        => 'Penghematan Listrik Sebelum PBLHS Tidak Boleh Kosong',
 | 
						|
                'listrik_setelah_pblhs.required'        => 'Penghematan Listrik Setelah PBLHS Tidak Boleh Kosong',
 | 
						|
                'luas_ruangan_ac.required'              => 'Penghematan Listrik Luas Ruangan Ber-AC Tidak Boleh Kosong',
 | 
						|
                'luas_ruangan_non_ac.required'          => 'Penghematan Listrik Luas Ruangan Non-AC Tidak Boleh Kosong',
 | 
						|
                'jumlah_kader.required'                 => 'Jumlah Kader Tidak Boleh Kosong',
 | 
						|
            ])->validate();
 | 
						|
 | 
						|
            // dd($request->all());
 | 
						|
 | 
						|
            $jumlah = [];
 | 
						|
            $jumlah['jumlah_peserta_didik']         = $request->jumlah_peserta_didik;
 | 
						|
            $jumlah['jumlah_tenaga_pendidik']       = $request->jumlah_tenaga_pendidik;
 | 
						|
            $jumlah['jumlah_tenaga_kependidikan']   = $request->jumlah_tenaga_kependidikan;
 | 
						|
            $jumlah['jumlah_warga_sekolah_lainnya'] = $request->jumlah_warga_sekolah_lainnya;
 | 
						|
            $jumlah['jumlah_biopori']               = $request->jumlah_biopori;
 | 
						|
            $jumlah['jumlah_sumur_resapan']         = $request->jumlah_sumur_resapan;
 | 
						|
            $jumlah['jumlah_pohon']                 = $request->jumlah_pohon;
 | 
						|
 | 
						|
            $air = [];
 | 
						|
            $air['air_sebelum_pblhs'] = $request->air_sebelum_pblhs;
 | 
						|
            $air['air_setelah_pblhs'] = $request->air_setelah_pblhs;
 | 
						|
 | 
						|
            $listrik = [];
 | 
						|
            $listrik['listrik_sebelum_pblhs'] = $request->listrik_sebelum_pblhs;
 | 
						|
            $listrik['listrik_setelah_pblhs'] = $request->listrik_setelah_pblhs;
 | 
						|
            $listrik['luas_ruangan_ac']       = $request->luas_ruangan_ac;
 | 
						|
            $listrik['luas_ruangan_non_ac']   = $request->luas_ruangan_non_ac;
 | 
						|
            $listrik['jumlah_kader']          = $request->jumlah_kader;
 | 
						|
 | 
						|
 | 
						|
            $profile = Profile::where('user_id',auth()->user()->id)->first();
 | 
						|
            $profile->data_jumlah           = json_encode($jumlah);
 | 
						|
            $profile->penghematan_air       = json_encode($air);
 | 
						|
            $profile->penghematan_listrik   = json_encode($listrik);
 | 
						|
            $profile->save();
 | 
						|
 | 
						|
            logActivity($request, __('Insert',['val' => strtolower(__('Title',['user' => auth()->user()->id]))]));
 | 
						|
            return redirect()->back()->with('message', __('Berhasil Update Data'))->with('type', 'success');
 | 
						|
        } catch (Exception $e) {
 | 
						|
            throw new GeneralException(__('Maaf Terjadi Kesalahan'));
 | 
						|
        }
 | 
						|
 | 
						|
        
 | 
						|
    }
 | 
						|
}
 |