270 lines
10 KiB
PHP
270 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Modules\Usulan;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\File;
|
|
use Carbon\Carbon;
|
|
use App\Models\Master\Provinsi;
|
|
use App\Models\Kuesioner;
|
|
use App\Models\KuesionerLog;
|
|
use App\Models\SK;
|
|
use App\Models\Master\Sekolah;
|
|
use App\Models\Master\FormKriteria;
|
|
use App\Models\DokumenAdministrasi;
|
|
|
|
class SKController extends Controller
|
|
{
|
|
|
|
private $template = 'modules.usulan.sk';
|
|
private $route = 'modules.usulan_adiwiyata.sk';
|
|
private $title = 'Penetapan SK';
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
permission('is_read', $this->route, 'module',true);
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
$data['provinsi'] = Provinsi::where('kode_wilayah','010000')->get();
|
|
|
|
return view($this->template.'.index',$data);
|
|
}
|
|
|
|
public function grid(Request $request)
|
|
{
|
|
$kuesioner = Kuesioner::where('level',0)->orderBy('created_at','DESC')->get();
|
|
foreach ($kuesioner as $key => $row) {
|
|
|
|
$action = '';
|
|
|
|
// if($row->status == 4){
|
|
// $action .= '<a href="'.url('usulan/csak/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-edit 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';
|
|
}
|
|
|
|
$penilaian = '';
|
|
$penilaian .= '<span style="width:100%;" class="text-left badge badge-secondary"> Sekolah : '.getNilaiAll('sekolah',$row->ms_sekolah_id).'</span></br>';
|
|
$penilaian .= '<span style="width:100%;" class="text-left badge badge-primary"> Kota : '.getNilaiAll('kota',$row->ms_sekolah_id).'</span></br>';
|
|
$penilaian .= '<span style="width:100%;" class="text-left badge badge-success"> Provinsi : '.getNilaiAll('provinsi',$row->ms_sekolah_id).'</span></br>';
|
|
|
|
$log = KuesionerLog::where('kuesioner_id',$row->KuesionerId)->orderBy('created_at','DESC')->first();
|
|
$progress = '<span class="badge badge-warning">'.str_replace('_',' ',\Str::title($log->step)).'</span>';
|
|
|
|
$sekolah = '';
|
|
$sekolah .= @$row->sekolah->nama_sekolah.'<br>';
|
|
$sekolah .= '<span class="badge badge-success">'.@$row->profile->tingkat->name.'</span> ';
|
|
$sekolah .= '<span class="badge badge-primary">'.@$row->profile->status_sekolah.'</span> ';
|
|
|
|
$sk = SK::whereRaw("sekolah::text LIKE '%".$row->sekolah->MsSekolahId."%'")->first();
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'id' => encode_id($row->id),
|
|
'npsn' => $row->sekolah->npsn,
|
|
'nama' => $sekolah,
|
|
'status_level' => '<span style="width:100%" class="badge badge-secondary">Level '.levelAdiwiyata($row->npsn).'</span>',
|
|
'wilayah' => $row->sekolah->kabupaten->name,
|
|
'penghargaan' => $penghargaan,
|
|
'penilaian' => $penilaian,
|
|
'progress' => $progress,
|
|
'dokumen_administrasi' => '-',
|
|
'tanggal_penetapan' => '<span style="width:100%;" class="text-left badge badge-primary mb-1">Tanggal Penetapan : '.$sk->tanggal_penetapan.'</span> <br> <a style="width:100%!important;" href="'.asset('uploads/'.$sk->file).'" target="_blank" class="btn btn-sm btn-warning"><i class="fal fa-download""></i> Download File SK</a',
|
|
'action' => $action,
|
|
];
|
|
|
|
}
|
|
|
|
return response()->json($_data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
permission('is_create', $this->route, 'module',true);
|
|
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
|
|
return view($this->template.'.form',$data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
try {
|
|
Validator::make($request->all(), [
|
|
'judul' => 'max:200',
|
|
'tanggal_penetapan' => 'date',
|
|
'jenis_usulan' => 'required',
|
|
'sekolah' => 'required',
|
|
'file' => 'required',
|
|
])->validate();
|
|
|
|
if($request->jenis_usulan == '1'){
|
|
$usulan = 'Adiwiyata Kab/Kota';
|
|
}elseif($request->jenis_usulan == '2'){
|
|
$usulan = 'Adiwiyata Provinsi';
|
|
}elseif($request->jenis_usulan == '3'){
|
|
$usulan = 'Adiwiyata Nasional';
|
|
}else{
|
|
return redirect()->back()->with([
|
|
'message' => 'Maaf Kesalahan Input Data!',
|
|
'type' => "error"
|
|
]);
|
|
}
|
|
|
|
if(SK::where('tahun',date('Y'))->where('jenis_usulan',$request->jenis_usulan)->count() > 0){
|
|
return redirect()->back()->with([
|
|
'message' => 'Maaf Penetapan SK Tahun '.date('Y').' Untuk Usulan '.$usulan.' Sudah Ada',
|
|
'type' => "error"
|
|
]);
|
|
}
|
|
|
|
if ($request->hasFile('file')) {
|
|
$file = $request->file('file');
|
|
$destinationPath = public_path('uploads/sk');
|
|
$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('uid').'_'.uniqid('sk_') . '.' . $fileExtension;
|
|
|
|
if (!File::exists($path)) {
|
|
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
|
|
}
|
|
|
|
$filePath = 'sk/' . $current . '/' . $newFilename;
|
|
$uploaded = $file->move($path, $newFilename);
|
|
}
|
|
|
|
$decoded = collect($request->sekolah)->map(function($id) {
|
|
return decode_id($id);
|
|
})->toArray();
|
|
|
|
// dd($decoded);
|
|
|
|
if(@$request->file){
|
|
$sk = SK::updateOrCreate([
|
|
'tahun' => date('Y'),
|
|
'jenis_usulan' => $request->jenis_usulan,
|
|
],[
|
|
'tahun' => date('Y'),
|
|
'nama' => @$request->nama,
|
|
'tanggal_penetapan' => $request->tanggal_penetapan,
|
|
'jenis_usulan' => $request->jenis_usulan,
|
|
'file' => $filePath,
|
|
'deskripsi' => @$request->deskripsi,
|
|
'created_by' => auth()->user()->id,
|
|
'sekolah' => json_encode($decoded),
|
|
]);
|
|
}else{
|
|
$sk = SK::updateOrCreate([
|
|
'tahun' => date('Y'),
|
|
'jenis_usulan' => $request->jenis_usulan,
|
|
],[
|
|
'tahun' => date('Y'),
|
|
'nama' => @$request->nama,
|
|
'tanggal_penetapan' => $request->tanggal_penetapan,
|
|
'jenis_usulan' => $request->jenis_usulan,
|
|
'deskripsi' => @$request->deskripsi,
|
|
'created_by' => auth()->user()->id,
|
|
'sekolah' => json_encode($decoded),
|
|
]);
|
|
}
|
|
|
|
foreach($request->sekolah as $sekolah){
|
|
|
|
$kuesioner = Kuesioner::where('ms_sekolah_id',decode_id($sekolah))->where('status',4)->where('tahun',date('Y'))->first();
|
|
$kuesioner->status = 6;
|
|
$kuesioner->save();
|
|
|
|
//kuesioner log
|
|
$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 = 'penetapan_sk';
|
|
$log->status = 6;
|
|
$log->created_by = auth()->user()->id;
|
|
$log->save();
|
|
}
|
|
|
|
logActivity($request, __('Create',['val' => strtolower(__('Title',['val' => 'Penetapan SK Usulan '.$usulan.' tahun '.date('Y').' oleh '.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"
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|