update
parent
9d6a0c3e65
commit
78a7943ce2
|
@ -142,6 +142,7 @@ if (!function_exists('status_kuesioner')) {
|
|||
//3 = selesai kelengkapan data
|
||||
//4 = Validasi Diteruskan
|
||||
//5 = Validasi Dikembalikan
|
||||
//6 = Terbit SK
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use App\Models\Master\Kabupaten;
|
|||
use App\Models\Master\Kecamatan;
|
||||
use App\Models\Master\Sekolah;
|
||||
use App\Models\Penilaian;
|
||||
use App\Models\Kuesioner;
|
||||
|
||||
class AjaxController extends Controller
|
||||
{
|
||||
|
@ -27,6 +28,17 @@ class AjaxController extends Controller
|
|||
return response()->json($data);
|
||||
}
|
||||
}
|
||||
public function getSekolahSK(Request $request)
|
||||
{
|
||||
$kuesioner = Kuesioner::where('level',($request->data-1))->where('tahun',date('Y'))->where('status',4)->get();
|
||||
$data = [];
|
||||
foreach ($kuesioner as $key => $value) {
|
||||
$data[$key]['id'] = encode_id($value->ms_sekolah_id);
|
||||
$data[$key]['name'] = $value->sekolah->nama_sekolah;
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
public function getForm(Request $request)
|
||||
{
|
||||
if(@$request->sekolah){
|
||||
|
|
|
@ -4,9 +4,13 @@ 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;
|
||||
|
@ -103,7 +107,128 @@ class SKController extends Controller
|
|||
*/
|
||||
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"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SK extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'sk';
|
||||
protected $primaryKey = 'SkId';
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sk', function (Blueprint $table) {
|
||||
$table->id('SkId');
|
||||
$table->string('nama')->nullable();
|
||||
$table->json('sekolah');
|
||||
$table->year('tahun');
|
||||
$table->integer('jenis_usulan');
|
||||
$table->date('tanggal_penetapan');
|
||||
$table->string('file');
|
||||
$table->text('deskripsi')->nullable();
|
||||
$table->integer('status')->default(0);
|
||||
$table->integer('created_by');
|
||||
$table->timestampsTz();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('s_k_s');
|
||||
}
|
||||
};
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -12,32 +12,46 @@
|
|||
<div id="panel-4" class="panel">
|
||||
<div class="panel-container show">
|
||||
<div class="panel-content">
|
||||
<form method="POST" action="{{route($route.'.store')}}">
|
||||
<form method="POST" action="{{route($route.'.store')}}" enctype="multipart/form-data">
|
||||
{{csrf_field()}}
|
||||
<div class="form-group">
|
||||
<label class="label">Judul SK</label>
|
||||
<input type="text" name="nama" class="form-control">
|
||||
<small class="text-muted"><i>(Opsional)</i></small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="label">Tanggal Penetapan SK</label>
|
||||
<input type="date" name="tanggal_penetapan" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="label">Data Tahun</label>
|
||||
<input type="text" name="tahun" value="{{date('Y')}}" disabled class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="label">Jenis Usulan</label>
|
||||
<select class="select2 form-control" name="usulan" required>
|
||||
<select class="select2 form-control usulan" name="jenis_usulan" required>
|
||||
<option value="">Pilih Jenis Usulan</option>
|
||||
<option value="">Kota</option>
|
||||
<option value="">Provinsi</option>
|
||||
<option value="">Nasional</option>
|
||||
<option value="1">Adiwiyata Kab/Kota</option>
|
||||
<option value="2">Adiwiyata Provinsi</option>
|
||||
<option value="3">Adiwiyata Nasional</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="label">Pilih Sekolah</label>
|
||||
<select class="select2 form-control" multiple name="sekolah[]" required>
|
||||
<select class="select2 form-control sekolah" multiple name="sekolah[]" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="label">File SK</label>
|
||||
<input type="file" name="file" class="form-control" required>
|
||||
<input type="file" name="file" accept=".pdf" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary"><i class="fal fa-upload"></i> Upload Data</button>
|
||||
<label class="label">Deskripsi</label>
|
||||
<textarea name="deskripsi" class="form-control"></textarea>
|
||||
<small class="text-muted"><i>(Opsional)</i></small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary"><i class="fal fa-loading"></i> Proses Data</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -47,4 +61,38 @@
|
|||
</div>
|
||||
@endsection
|
||||
@section('page-js')
|
||||
<script type="text/javascript">
|
||||
$('.usulan').on('change',function(){
|
||||
var jenis_usulan = $(this).find(':selected').val();
|
||||
let base_url = "{{url('/')}}";
|
||||
$.ajax({
|
||||
url: base_url+'/getSekolahSK', // Ganti dengan URL API-mu
|
||||
type: 'POST', // Bisa juga 'POST' kalau perlu
|
||||
data: {
|
||||
_token:'{{csrf_token()}}',
|
||||
data: jenis_usulan
|
||||
}, // Kirim number sebagai parameter
|
||||
dataType: 'json', // Format respons JSON
|
||||
beforeSend: function () {
|
||||
$('#loading-spinner').show(); // Menampilkan spinner
|
||||
},
|
||||
success: function (response) {
|
||||
// toastr.success("Berhasil menyimpan data", 'Success!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
|
||||
|
||||
let $select = $('.sekolah');
|
||||
$select.empty(); // kosongkan dulu
|
||||
|
||||
$.each(response, function(index, item) {
|
||||
$select.append('<option value="' + item.id + '">' + item.name + '</option>');
|
||||
});
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
toastr.error("Maaf Terjadi Kesalahan Menyimpan Data", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
|
||||
},
|
||||
complete: function () {
|
||||
$('#loading-spinner').hide(); // Sembunyikan spinner setelah request selesai
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
|
@ -30,6 +30,7 @@ Route::get('profile-sekolah',[ProfileController::class,'index'])->name('profile.
|
|||
Route::get('profile-sekolah/grid',[ProfileController::class,'grid'])->name('profile.grid');
|
||||
Route::post('profile-sekolah',[ProfileController::class,'store'])->name('profile.store');
|
||||
Route::post('getForm',[AjaxController::class,'getForm'])->name('getForm');
|
||||
Route::post('getSekolahSK',[AjaxController::class,'getSekolahSK'])->name('getSekolahSK');
|
||||
|
||||
Route::name('master.')->prefix('master')->group(function () {
|
||||
Route::resource('indikator',IndikatorController::class);
|
||||
|
|
Loading…
Reference in New Issue