Skip to content

Commit

Permalink
add pengajuan on personel
Browse files Browse the repository at this point in the history
  • Loading branch information
punkestu committed Jan 3, 2025
1 parent d4a6b25 commit 8f195c1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/Http/Controllers/PersonelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public function index()
$cabang_id = request()->get('cabang_id');
$cabang = request()->get('cabang');
if ($nik == "" && $name == "" && $cabang == "") {
$personels = Personel::limit($limit)->offset($page * $limit)->get();
$personels = Personel::with(['cabang', 'lokasiCabang', 'lokasiInduk', 'pengajuan_pindah' => [
'lokasiAwal',
'lokasiTujuan',
]])->limit($limit)->offset($page * $limit)->get();
$cabangs = Cabang::all();
if (!$cabangs) abort(404);
return view('personel.index', [
Expand All @@ -36,7 +39,10 @@ public function index()
],
]);
}
$personels = Personel::where('nik', 'like', $nik . '%')->where('name', 'like', '%' . $name . '%');
$personels = Personel::with(['cabang', 'lokasiCabang', 'lokasiInduk', 'pengajuan_pindah' => [
'lokasiAwal',
'lokasiTujuan',
]])->where('nik', 'like', $nik . '%')->where('name', 'like', '%' . $name . '%');
if ($cabang != "") {
$personels = $personels->where('cabang_id', $cabang_id);
}
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Personel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public function lokasiInduk()
{
return $this->belongsTo(Cabang::class, 'lokasi_induk');
}

public function pengajuan_pindah()
{
return $this->hasMany(Pengajuan::class, 'nik', 'nik')->where('status', '=', 'diajukan')->orderBy('created_at', 'desc');
}
}
58 changes: 57 additions & 1 deletion resources/views/personel/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ class="py-2.5 px-5 ms-3 text-sm font-medium text-gray-900 focus:outline-none bg-
</form>
</div>
</div>
<div id="detail-pindah-modal" tabindex="-1" aria-hidden="true"
class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
<div class="relative p-4 w-full max-w-2xl max-h-full">
<!-- Modal content -->
<div class="relative bg-white rounded-lg shadow ">
<!-- Modal header -->
<div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t ">
<h3 class="text-xl font-semibold text-gray-900 ">
Detail Data Pindah
</h3>
<button type="button"
class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center"
data-modal-hide="detail-pindah-modal">
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 14 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
</svg>
<span class="sr-only">Close modal</span>
</button>
</div>
<!-- Modal body -->
<div id="body" class="p-4 md:p-5 space-y-4">

</div>
</div>
</div>
</div>
<main class="min-h-screen">
<div class="text-xl font-semibold text-gray-800 px-4 py-2 bg-gray-100 flex gap-4">
<a href="/personel" class="underline">Personel</a>
Expand Down Expand Up @@ -191,6 +219,9 @@ class="flex items-center justify-center px-4 py-2 text-white text-sm bg-blue-500
<th scope="col" class="px-6 py-3">
Tidak Pindah
</th>
<th scope="col" class="px-6 py-3">
Pengajuan Pindah
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -283,11 +314,19 @@ class="flex items-center justify-center px-4 py-2 text-white text-sm bg-blue-500
{{ $personel->job_text }}
</td>
<td class="px-6 py-4">
{{ $personel->magang ? "Magang" : "Karyawan" }}
{{ $personel->magang ? 'Magang' : 'Karyawan' }}
</td>
<td class="px-6 py-4">
{{ $personel->tidak_pindah ? 'Tidak pindah sampai ' . date('j F, Y', strtotime($personel->expired)) : '-' }}
</td>
<td class="px-6 py-4">
@if (count($personel->pengajuan_pindah) > 0)
<button data-modal-target="detail-pindah-modal" data-modal-toggle="detail-pindah-modal"
onclick='setPindahDetail(@json($personel->pengajuan_pindah))'>✅</button>
@else
-
@endif
</td>
</tr>
@endforeach
</tbody>
Expand All @@ -297,6 +336,8 @@ class="flex items-center justify-center px-4 py-2 text-white text-sm bg-blue-500
<a @if ($page > 0) href="?page={{ $page - 1 }}" @endif>Back</a>
<a href="?page={{ $page + 1 }}">Next</a>
</div>


</main>
@include('components.footer')
<script src="/script/nav.js"></script>
Expand Down Expand Up @@ -329,6 +370,21 @@ function selectCabang(e) {
document.getElementById('cabang-suggestion').classList.remove('flex');
}
function setPindahDetail(dataPindah) {
const body = document.querySelector('#detail-pindah-modal #body');
body.innerHTML = '';
dataPindah.forEach(data => {
const div = `
<div class="flex gap-2 border mb-2 px-2 py-1">
<span>Dari: ${data.lokasi_awal.nama}</span>
<span>Ke: ${data.lokasi_tujuan.nama}</span>
<span>Diajukan: ${data.created_at}</span>
</div>
`;
body.innerHTML += div;
});
}
const body = document.querySelector('body');
body.addEventListener('click', function(e) {
if (!e.target.closest('#cabang-suggestion') && !e.target.closest('#cabang-search')) {
Expand Down

0 comments on commit 8f195c1

Please sign in to comment.