crud penelitian sumber

parent 465d51d9
......@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
use App\Models\Biodata;
use Exception;
use Illuminate\Http\Request;
use App\Models\Admin\MsBidangPenelitianKategori as MsBidangPenelitianKategori;
class GetDataController extends Controller
{
......@@ -23,14 +22,18 @@ class GetDataController extends Controller
public function getChildren(Request $request)
{
$class = 'App\\Models\\Admin\\'.$request->parent;
$parent = $class::query()->with('children')->find(decrypt($request->id));
$children = $parent->children;
$str = '';
foreach ($children as $child) {
$str .= '<option value="'.encrypt($child->id).'">'.$child->nama.'</option>';
}
if(!is_null($request->id)){
$class = 'App\\Models\\Admin\\'.$request->parent;
$parent = $class::query()->with('children')->find(decrypt($request->id));
$children = $parent->children;
$str = '';
foreach ($children as $child) {
$str .= '<option value="'.encrypt($child->id).'">'.$child->nama.'</option>';
}
return response($str, 200);
}
$str = '';
return response($str, 200);
}
}
......@@ -3,8 +3,17 @@
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Admin\MsBidangPenelitianKategori;
use App\Models\Admin\MsInstitusi;
use App\Models\Admin\MsTujuanSosialKategori;
use App\Models\Biodata;
use App\Models\User\PenelitianSumber;
use App\Models\User\PenelitianSumberAnggota;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Validator;
class PenelitianSumberDanaController extends Controller
{
......@@ -15,7 +24,9 @@ class PenelitianSumberDanaController extends Controller
*/
public function index()
{
return view('user.penelitiansumber.index');
$data['rs'] = PenelitianSumber::query()->with(['bidang', 'tujuan', 'institusi'])->orderBy('updated_at', 'desc')->get();
$data['sumber_dana'] = PenelitianSumber::SUMBER_DANA;
return view('user.penelitiansumber.index', $data);
}
/**
......@@ -25,7 +36,25 @@ class PenelitianSumberDanaController extends Controller
*/
public function create()
{
return view('user.penelitiansumber.create');
$data['kategori_bidang'] = MsBidangPenelitianKategori::query()->orderBy('namabidang', 'asc')->get();
$data['kategori_tujuan'] = MsTujuanSosialKategori::query()->orderBy('namatujuan', 'asc')->get();
$data['institusi'] = MsInstitusi::query()->orderBy('nama', 'asc')->get();
$data['jenis'] = PenelitianSumber::JENIS_PENELITIAN;
$data['sumber'] = PenelitianSumber::SUMBER_DANA;
$data['edit'] = false;
return view('user.penelitiansumber.create', $data);
}
public function simpan(Request $request)
{
// try{
// $penelitian =
// }
}
public function cekSimpan(Request $request)
{
# code...
}
/**
......@@ -35,7 +64,66 @@ class PenelitianSumberDanaController extends Controller
*/
public function store(Request $request)
{
dd($request->all());
$data = $request->except('_token');
Validator::make($data, PenelitianSumber::RULES, PenelitianSumber::ERROR_MESSAGES)->validate();
$data['userid_created'] = Auth::user()->id;
$data['userid_updated'] = Auth::user()->id;
$data['bidang_id'] = decrypt($data['bidang_id']);
$data['tujuan_id'] = decrypt($data['tujuan_id']);
$data['institusi_id'] = decrypt($data['institusi_id']);
try{
$penelitian = PenelitianSumber::query()->create($data);
return redirect()->route('penelitiansumber.next-form', ['id' => encrypt($penelitian->id)]);
}
catch(Exception $ex){
return redirect()->back()->withInput();
}
return redirect()->back()->withInput();
}
public function nextForm(Request $request, $id)
{
$anggota = PenelitianSumberAnggota::query()->with('biodata')->where('penelitiansumber_id', decrypt($id))->get();
if(count($anggota) < 1 || is_null($request->next_state)){
$data['id'] = $id;
$data['keanggotaan'] = PenelitianSumberAnggota::KEANGGOTAAN;
$data['dosen_anggota'] = $anggota->whereIn('jenis', ['t', 'd']);
$data['non_dosen_anggota'] = $anggota->whereIn('jenis', ['l']);
return view('user.penelitiansumber.create_anggota', $data);
}
else if($request->next_state == 'finish' && count($anggota) > 0){
return redirect()->route('penelitiansumber.index');
}
}
public function editAnggota(Request $request, $id)
{
$anggota = PenelitianSumberAnggota::query()->with('biodata')->where('penelitiansumber_id', decrypt($id))->get();
$data['id'] = $id;
$data['keanggotaan'] = PenelitianSumberAnggota::KEANGGOTAAN;
$data['dosen_anggota'] = $anggota->whereIn('jenis', ['t', 'd']);
$data['non_dosen_anggota'] = $anggota->whereIn('jenis', ['l']);
return view('user.penelitiansumber.create_anggota', $data);
}
public function deleteAnggota(Request $request)
{
try{
$anggota = PenelitianSumberAnggota::query()->find(decrypt($request->id))->delete();
return response('Success', 200);
}
catch(Exception $ex){
return response('Error', 500);
}
}
/**
......@@ -58,6 +146,14 @@ class PenelitianSumberDanaController extends Controller
*/
public function edit($id)
{
$data['kategori_bidang'] = MsBidangPenelitianKategori::query()->orderBy('namabidang', 'asc')->get();
$data['kategori_tujuan'] = MsTujuanSosialKategori::query()->orderBy('namatujuan', 'asc')->get();
$data['institusi'] = MsInstitusi::query()->orderBy('nama', 'asc')->get();
$data['jenis'] = PenelitianSumber::JENIS_PENELITIAN;
$data['sumber'] = PenelitianSumber::SUMBER_DANA;
$data['edit'] = true;
$data['data'] = PenelitianSumber::query()->find(decrypt($id));
return view('user.penelitiansumber.create', $data);
}
/**
......@@ -69,6 +165,22 @@ class PenelitianSumberDanaController extends Controller
*/
public function update(Request $request, $id)
{
$data = $request->except('_token');
Validator::make($data, PenelitianSumber::RULES, PenelitianSumber::ERROR_MESSAGES)->validate();
$data['userid_updated'] = Auth::user()->id;
$data['bidang_id'] = decrypt($data['bidang_id']);
$data['tujuan_id'] = decrypt($data['tujuan_id']);
$data['institusi_id'] = decrypt($data['institusi_id']);
try{
PenelitianSumber::query()->find(decrypt($id))->update($data);
return redirect()->route('penelitiansumber.index');
}
catch(Exception $ex){
return redirect()->back()->withInput();
}
}
/**
......@@ -80,27 +192,97 @@ class PenelitianSumberDanaController extends Controller
*/
public function destroy($id)
{
try{
DB::beginTransaction();
$penelitian = PenelitianSumber::query()->find(decrypt($id));
$anggota = $penelitian->anggota;
$anggota->delete();
$penelitian->delete();
DB::commit();
return redirect()->route('penelitiansumber.index');
}
catch(Exception $ex){
DB::rollBack();
return redirect()->route('penelitiansumber.index');
}
}
public function getRowAnggota(Request $request)
public function simpanAnggota(Request $request, $id)
{
$allAnggota = PenelitianSumberAnggota::where('penelitiansumber_id', decrypt($id))->get();
$anggota = $allAnggota->where('nidn', $request->nidn);
$ketua = $allAnggota->where('peran', PenelitianSumberAnggota::KEANGGOTAAN['k']);
if( count($ketua) > 0 && $request->keanggotaan == PenelitianSumberAnggota::KEANGGOTAAN['k']){
return response('Ketua tidak boleh lebih dari satu', 500);
}
if(count($anggota) < 1){
$dosen = Biodata::query()->where('nidn', $request->nidn)->first();
$data = $this->arrayDataAnggota($request);
$store = $this->getStoredArrayDataAnggota($request, $id, $dosen);
if(is_null($dosen) && $request->name == 'dosen'){
return response('NIDN tidak terdaftar sebagai dosen atau belum tervalidasi', 500);
}
elseif(!is_null($dosen) && $request->name == 'non_dosen'){
return response('NIDN terdaftar sebagai dosen', 500);
}
try{
Validator::make($store, PenelitianSumberAnggota::RULES, PenelitianSumberAnggota::ERROR_MESSAGES)->validate();
$anggota = PenelitianSumberAnggota::query()->create($store);
$data['id'] = $anggota->id;
return view('user.penelitiansumber.row_anggota', $data);
}
catch(Exception $ex){
return response('Data yang diberikan tidak lengkap atau tidak valid', 500);
}
}
return response('Data sudah ada', 500);
}
private function arrayDataAnggota(Request $request)
{
$data['no'] = $request->no;
$data['nama'] = $request->nama;
$data['keanggotaan'] = $request->keanggotaan;
$data['prodi'] = $request->prodi;
$data['nidn'] = encrypt($request->nidn);
$data['name'] = $request->name;
return $data;
}
public function getStoredArrayDataAnggota(Request $request, $id, $dosen)
{
$store['penelitiansumber_id'] = decrypt($id);
$store['nidn'] = $request->nidn;
$store['peran'] = $request->keanggotaan;
$dosen = Biodata::query()->where('nidn', $request->nidn)->first();
if (!is_null($dosen) && $request->name == 'dosen') {
$data['name'] = $request->name;
$data['nama'] = $request->nama;
$data['jenis'] = encrypt($dosen->jenis);
$store['jenis'] = $dosen->jenis;
$store['nama'] = $dosen->nama;
} elseif (is_null($dosen) && $request->name == 'non_dosen') {
$data['name'] = $request->name;
$data['jenis'] = encrypt('l');
$store['jenis'] = 'l';
$store['institusi'] = $request->prodi;
$store['nama'] = $request->nama;
}
return view('user.penelitiansumber.row_anggota', $data);
return $store;
}
}
<?php
namespace App\Models\Admin;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MsInstitusi extends Model
{
use HasFactory;
use UuidTrait;
public $incrementing = false;
protected $table = 'ms_institusi';
protected $keyType = 'string';
protected $fillable = ['nama', 'kode', 'created_at', 'updated_at', 'userid_created', 'userid_updated'];
}
<?php
namespace App\Models\Admin;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MsTujuanSosial extends Model
{
use HasFactory;
use UuidTrait;
public $incrementing = false;
protected $table = 'ms_tujuan_sosial';
protected $keyType = 'string';
protected $fillable = ['nama', 'created_at', 'updated_at', 'userid_created', 'userid_updated'];
}
<?php
namespace App\Models\Admin;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MsTujuanSosialKategori extends Model
{
use HasFactory;
use UuidTrait;
public $incrementing = false;
protected $table = 'ms_tujuan_sosial_kategori';
protected $keyType = 'string';
protected $fillable = ['namatujuan', 'created_at', 'updated_at', 'userid_created', 'userid_updated'];
public function children()
{
return $this->hasMany(MsTujuanSosial::class, 'id_tujuan_kategori', 'id');
}
}
<?php
namespace App\Models\User;
use App\Models\Admin\MsBidangPenelitian;
use App\Models\Admin\MsInstitusi;
use App\Models\Admin\MsTujuanSosial;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PenelitianSumber extends Model
{
use HasFactory;
use UuidTrait;
public $incrementing = false;
protected $table = 'penelitiansumber';
protected $keyType = 'string';
protected $fillable = [
'judul', 'jenis', 'bidang_id', 'tujuan_id', 'sumberdana', 'institusi_id', 'jumlah_dana', 'userid_created', 'userid_updated', 'created_at', 'updated_at',
];
public const RULES = [
'judul' => 'required',
'jenis' => 'required',
'bidang_id' => 'required',
'tujuan_id' => 'required',
'sumberdana' => 'required',
'institusi_id' => 'required',
'jumlah_dana' => 'required',
];
public const ERROR_MESSAGES = [
'judul.required' => 'judul tidak boleh kosong',
'jenis.required' => 'jenis tidak boleh kosong',
'bidang_id.required' => 'bidang id tidak boleh kosong',
'tujuan_id.required' => 'tujuan id tidak boleh kosong',
'sumberdana.required' => 'sumberdana tidak boleh kosong',
'institusi_id.required' => 'institusi tidak boleh kosong',
'jumlah_dana.required' => 'jumlah dana tidak boleh kosong',
];
public const JENIS_PENELITIAN = [
'Penelitian Dasar',
'Penelitian Terapan',
'Pengembangan Eksperimental'
];
public const SUMBER_DANA = [
'DN' => 'Dalam Negeri',
'LN' => 'Luar Negeri'
];
public function bidang()
{
return $this->belongsTo(MsBidangPenelitian::class, 'bidang_id', 'id');
}
public function tujuan()
{
return $this->belongsTo(MsTujuanSosial::class, 'tujuan_id', 'id');
}
public function institusi()
{
return $this->belongsTo(MsInstitusi::class, 'institusi_id', 'id');
}
public function anggota()
{
return $this->hasMany(PenelitianSumberAnggota::class, 'penelitiansumber_id', 'id');
}
}
<?php
namespace App\Models\User;
use App\Models\Biodata;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PenelitianSumberAnggota extends Model
{
use HasFactory;
use UuidTrait;
public $incrementing = false;
protected $table = 'penelitiansumber_anggota';
protected $keyType = 'string';
protected $fillable = [
'nama', 'penelitiansumber_id', 'nidn', 'peran', 'tugas', 'institusi', 'jenis', 'userid_created', 'userid_updated', 'created_at', 'updated_at',
];
public const RULES = [
'penelitiansumber_id' => 'required',
'nidn' => 'required',
'peran' => 'required'
];
public const ERROR_MESSAGES = [
'penelitiansumber_id.required' => 'penelitiansumber tidak boleh kosong',
'nidn.required' => 'nidn tidak boleh kosong',
'peran.required' => 'peran tidak boleh kosong'
];
public const KEANGGOTAAN = [
'k'=>'Ketua',
'a'=>'Anggota'
];
public function biodata()
{
return $this->belongsTo(Biodata::class, 'nidn', 'nidn');
}
}
......@@ -21,127 +21,37 @@
<table id="zero-config" class="table table-hover" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>No.</th>
<th>Judul</th>
<th>Jenis</th>
<th>Bidang</th>
<th>Sumber Dana</th>
<th>Institusi</th>
<th>Jumlah Dana</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$433,060</td>
</tr>
<tr>
<td>Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>2008/11/28</td>
<td>$162,700</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New York</td>
<td>61</td>
<td>2012/12/02</td>
<td>$372,000</td>
</tr>
<tr>
<td>Herrod Chandler</td>
<td>Sales Assistant</td>
<td>San Francisco</td>
<td>59</td>
<td>2012/08/06</td>
<td>$137,500</td>
</tr>
<tr>
<td>Rhona Davidson</td>
<td>Integration Specialist</td>
<td>Tokyo</td>
<td>55</td>
<td>2010/10/14</td>
<td>$327,900</td>
</tr>
<tr>
<td>Colleen Hurst</td>
<td>Javascript Developer</td>
<td>San Francisco</td>
<td>39</td>
<td>2009/09/15</td>
<td>$205,500</td>
</tr>
<tr>
<td>Sonya Frost</td>
<td>Software Engineer</td>
<td>Edinburgh</td>
<td>23</td>
<td>2008/12/13</td>
<td>$103,600</td>
</tr>
<tr>
<td>Jena Gaines</td>
<td>Office Manager</td>
<td>London</td>
<td>30</td>
<td>2008/12/19</td>
<td>$90,560</td>
</tr>
<tr>
<td>Quinn Flynn</td>
<td>Support Lead</td>
<td>Edinburgh</td>
<td>22</td>
<td>2013/03/03</td>
<td>$342,000</td>
</tr>
<tr>
<td>Charde Marshall</td>
<td>Regional Director</td>
<td>San Francisco</td>
<td>36</td>
<td>2008/10/16</td>
<td>$470,600</td>
</tr>
<tr>
<td>Haley Kennedy</td>
<td>Senior Marketing Designer</td>
<td>London</td>
<td>43</td>
<td>2012/12/18</td>
<td>$313,500</td>
</tr>
@foreach ($rs as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->judul }}</td>
<td>{{ $item->jenis }}</td>
<td>{{ $item->bidang->nama }}</td>
<td>{{ $sumber_dana[$item->sumberdana] }}</td>
<td>{{ $item->institusi->nama }}</td>
<td>{{ $item->jumlah_dana }}</td>
<td>
<a class="btn btn-sm btn-warning" href="{{ route('penelitiansumber.edit', ['penelitiansumber' => encrypt($item->id)]) }}">Edit</a>
<a class="btn btn-sm btn-warning" href="{{ route('penelitiansumber.edit-anggota', ['id' => encrypt($item->id)]) }}">Edit Anggota</a>
<button class="btn btn-sm btn-danger delete" type="button" data-target="form_penelitian_{{ $loop->iteration }}">Hapus</button>
<form id="form_penelitian_{{ $loop->iteration }}" action="{{ route('penelitiansumber.destroy', ['penelitiansumber' => encrypt($item->id)]) }}" method="POST">
{{ method_field('DELETE') }}
@csrf
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
......@@ -167,5 +77,26 @@
"lengthMenu": [10, 20, 50],
"pageLength": 10
});
$("body").on("click", ".delete", function (e) {
e.preventDefault();
var id = $(this).data('target');
Swal.fire({
title: "Apakah Anda Yakin?",
text: "Anda akan menghapus data ini!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No"
}).then((result) => {
if (result.value) {
Swal.close();
$("#"+id).submit();
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal.fire('Dibatalkan', 'Data batal dihapus', 'error');
}
});
});
</script>
@endsection
<tr>
<td><input type="text" name="{{ $name }}[{{ $no }}][nidn]" value="{{ $nidn }}" hidden> {{ $no }}</td>
@php
$token = Str::random(10)
@endphp
<tr id="{{ $name }}_{{ $token }}">
<td>{{ $no }}</td>
<td>{{ $nama }}</td>
<td>
{{ $prodi }}
@if ($name == 'non_dosen')
<input type="text" name="{{ $name }}[{{ $no }}][institusi]" value="{{ $prodi }}" hidden>
@endif
<input type="text" name="{{ $name }}[{{ $no }}][jenis]" value="{{ encrypt($jenis) }}" hidden>
</td>
<td class="text-center"><span class="text-success"><input type="text" name="{{ $name }}[{{ $no }}][peran]" value="{{ $keanggotaan }}" hidden> {{ $keanggotaan }}</span></td>
<td class="text-center">{{ $keanggotaan }}</td>
<td>
<button class="btn btn-sm btn-danger" type="button" onclick="deleteAnggota('{{ encrypt($id) }}', '{{ $name }}_{{ $token }}')">Hapus</button>
</td>
</tr>
......@@ -39,7 +39,7 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
})->name('dashboard');
Route::get('/get-biodata', [GetDataController::class, 'getBiodata'])->name('get-biodata');
Route::get('/get-row-anggota', [PenelitianSumberDanaController::class, 'getRowAnggota'])->name('get-row-anggota');
// Route::get('/get-row-anggota', [PenelitianSumberDanaController::class, 'getRowAnggota'])->name('get-row-anggota');
Route::get('/get-children', [GetDataController::class, 'getChildren'])->name('get-children');
Route::resource('/bukuajar', BukuAjarController::class);
......@@ -47,6 +47,11 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::resource('/kekayaanintelek', KekayaanIntelController::class);
Route::resource('/kontrakkerja', KontrakKerjaController::class);
Route::resource('/penelitiansumber', PenelitianSumberDanaController::class);
Route::get('/penelitiansumber/next-form/{id}', [PenelitianSumberDanaController::class, 'nextForm'])->name('penelitiansumber.next-form');
Route::get('/penelitiansumber/edit-anggota/{id}', [PenelitianSumberDanaController::class, 'editAnggota'])->name('penelitiansumber.edit-anggota');
Route::post('/penelitiansumber/simpan-anggota/{id}', [PenelitianSumberDanaController::class, 'simpanAnggota'])->name('penelitiansumber.simpan-anggota');
Route::post('/penelitiansumber/delete-anggota', [PenelitianSumberDanaController::class, 'deleteAnggota'])->name('penelitiansumber.delete-anggota');
Route::post('/penelitiansumber/cek-simpan-anggota', [PenelitianSumberDanaController::class, 'cekSimpanAnggota'])->name('penelitiansumber.cek-simpan-anggota');
Route::resource('/penelitiasing', PenelitiAsingController::class);
Route::resource('/publikasiartikel', PublikasiArtikelController::class);
Route::resource('/publikasijurnal', PublikasiJurnalController::class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment