ID User
This commit is contained in:
parent
99dfe31f64
commit
66aa728745
|
|
@ -70,6 +70,57 @@ public function index(Request $request)
|
||||||
return view('pegawai.index', compact('pegawai', 'stats', 'allJabatan', 'allKantor'));
|
return view('pegawai.index', compact('pegawai', 'stats', 'allJabatan', 'allKantor'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function generateIdKaryawan($tglBergabung, $idDivisi, $idJabatan)
|
||||||
|
{
|
||||||
|
// 1. Ambil Tahun & Bulan (YYYYMM)
|
||||||
|
$date = \Carbon\Carbon::parse($tglBergabung);
|
||||||
|
$yearMonth = $date->format('Ym');
|
||||||
|
|
||||||
|
// 2. Ambil 2 huruf dari Divisi & Jabatan (XXYY)
|
||||||
|
$divisi = Divisi::find($idDivisi);
|
||||||
|
$jabatan = Jabatan::find($idJabatan);
|
||||||
|
|
||||||
|
$kodeDivisi = 'XX';
|
||||||
|
if ($divisi) {
|
||||||
|
$words = explode(' ', $divisi->nama_divisi);
|
||||||
|
if (count($words) >= 2) {
|
||||||
|
$kodeDivisi = strtoupper(substr($words[0], 0, 1) . substr($words[1], 0, 1));
|
||||||
|
} else {
|
||||||
|
$kodeDivisi = strtoupper(substr($divisi->nama_divisi, 0, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$kodeJabatan = 'YY';
|
||||||
|
if ($jabatan) {
|
||||||
|
$words = explode(' ', $jabatan->nama_jabatan);
|
||||||
|
if (count($words) >= 2) {
|
||||||
|
$kodeJabatan = strtoupper(substr($words[0], 0, 1) . substr($words[1], 0, 1));
|
||||||
|
} else {
|
||||||
|
$kodeJabatan = strtoupper(substr($jabatan->nama_jabatan, 0, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$kodeTengah = $kodeDivisi . $kodeJabatan;
|
||||||
|
|
||||||
|
// 3. Generate Nomor Urut (NNN) per tahun bergabun
|
||||||
|
$yearStarts = $date->copy()->startOfYear()->toDateString();
|
||||||
|
$yearEnds = $date->copy()->endOfYear()->toDateString();
|
||||||
|
|
||||||
|
$lastUser = User::whereBetween('tgl_bergabung', [$yearStarts, $yearEnds])
|
||||||
|
->whereNotNull('nik')
|
||||||
|
->orderBy('id', 'desc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$nextNumber = 1;
|
||||||
|
if ($lastUser && preg_match('/-(\d{3})$/', $lastUser->nik, $matches)) {
|
||||||
|
$nextNumber = intval($matches[1]) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nomorUrut = str_pad($nextNumber, 3, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
// Format: MPG-202603-ITST-001
|
||||||
|
return "MPG-{$yearMonth}-{$kodeTengah}-{$nomorUrut}";
|
||||||
|
}
|
||||||
|
|
||||||
public function store(StorePegawaiRequest $request)
|
public function store(StorePegawaiRequest $request)
|
||||||
{
|
{
|
||||||
$data = $request->validated();
|
$data = $request->validated();
|
||||||
|
|
@ -78,6 +129,10 @@ public function store(StorePegawaiRequest $request)
|
||||||
$data['foto'] = $request->file('foto')->store('foto-profil', 'public');
|
$data['foto'] = $request->file('foto')->store('foto-profil', 'public');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate ID Karyawan Otomatis
|
||||||
|
$tglBergabung = $data['tgl_bergabung'] ?? now()->toDateString();
|
||||||
|
$data['nik'] = $this->generateIdKaryawan($tglBergabung, $data['id_divisi'], $data['id_jabatan']);
|
||||||
|
|
||||||
$data['password'] = Hash::make('Mpg123!');
|
$data['password'] = Hash::make('Mpg123!');
|
||||||
$data['status_aktif'] = 1;
|
$data['status_aktif'] = 1;
|
||||||
$data['sisa_cuti'] = 12;
|
$data['sisa_cuti'] = 12;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ public function authorize(): bool
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'nik' => ['required', 'numeric', 'unique:users,nik'],
|
|
||||||
'nama_lengkap' => ['required', 'string', 'max:255'],
|
'nama_lengkap' => ['required', 'string', 'max:255'],
|
||||||
'email' => ['required', 'email', 'unique:users,email'],
|
'email' => ['required', 'email', 'unique:users,email'],
|
||||||
'no_telp' => ['nullable', 'string', 'max:20'],
|
'no_telp' => ['nullable', 'string', 'max:20'],
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
|
||||||
|
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<x-input label="Nomor Induk Kewarganegaraan (NIK)" name="nik"
|
<x-input label="ID Karyawan" name="nik"
|
||||||
placeholder="Masukkan NIK sesuai KTP" required />
|
placeholder="Otomatis dibuat oleh sistem" readonly class="bg-slate-50 opacity-70 cursor-not-allowed" />
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<x-input label="Nama Lengkap" name="nama_lengkap" placeholder="Masukkan nama sesuai KTP" required />
|
<x-input label="Nama Lengkap" name="nama_lengkap" placeholder="Masukkan nama sesuai KTP" required />
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
<h3 class="text-lg font-bold text-slate-800 mb-4 block w-full">Informasi Pribadi</h3>
|
<h3 class="text-lg font-bold text-slate-800 mb-4 block w-full">Informasi Pribadi</h3>
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<x-input label="Nomor Induk Kewarganegaraan (NIK)" name="nik" value="{{ $pegawai->nik }}"
|
<x-input label="ID Karyawan" name="nik" value="{{ $pegawai->nik }}"
|
||||||
readonly class="bg-slate-50 opacity-70" />
|
readonly class="bg-slate-50 opacity-70 cursor-not-allowed" />
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<x-input label="Nama Lengkap" name="nama_lengkap" value="{{ $pegawai->nama_lengkap }}" required />
|
<x-input label="Nama Lengkap" name="nama_lengkap" value="{{ $pegawai->nama_lengkap }}" required />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue