Skip to content

Commit aa14f09

Browse files
committed
refactor tanggal naskah
1 parent 490a9c5 commit aa14f09

File tree

6 files changed

+120
-17
lines changed

6 files changed

+120
-17
lines changed

.tinkerun/inspiring.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
use Illuminate\Support\Carbon;
88

99

10-
JenisNaskah::cache()->get('all')->where('id', 23)->first()->kode_naskah_id
10+
$format_nomor =':derajat-:no_urut/:kode_unit_kerja/:kode_arsip/:tahun';
11+
$replaces=[];
12+
preg_match_all("/:[a-zA-Z0-9_]+/", $format_nomor, $hasil);
13+
foreach ($hasil[0] as $key)
14+
if (($key != ':tahun') && ($key != ':no_urut')) $replaces[$key] = $key;
15+
16+
$format_nomor;
17+
18+
Carbon::createFromFormat('Y-m-d', '2024-01-01')->year;
1119

1220

1321

app/Helpers/Helper.php

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ public static function setOptions($collection, $value, $label, $group = '')
256256
* @param string $derajat
257257
* @return array nomor, nomor_urut, segmen
258258
*/
259-
public static function nomor($tanggal, $tahun, $jenis_naskah_id, $unit_kerja_id, $kode_arsip_id, $derajat)
259+
public static function nomor($tanggal, $jenis_naskah_id, $unit_kerja_id, $kode_arsip_id, $derajat)
260260
{
261+
$tahun = Carbon::createFromFormat('Y-m-d', $tanggal->format('Y-m-d'))->year;
261262
$jenis_naskah = JenisNaskah::cache()->get('all')->where('id', $jenis_naskah_id)->first();
262263
$kode_naskah = KodeNaskah::cache()->get('all')->where('id', $jenis_naskah->kode_naskah_id)->first();
263264
$unit_kerja = UnitKerja::cache()->get('all')->where('id', $unit_kerja_id)->first();
@@ -276,8 +277,8 @@ public static function nomor($tanggal, $tahun, $jenis_naskah_id, $unit_kerja_id,
276277
}
277278
$format = $jenis_naskah->format ?? $kode_naskah->format;
278279
$replaces['<tahun>'] = $tahun;
279-
$replaces['<unit_kerja_id>'] = $unit_kerja->kode;
280-
$replaces['<kode_arsip_id>'] = $kode_arsip->kode;
280+
$replaces['<kode_unit_kerja>'] = $unit_kerja->kode;
281+
$replaces['<kode_arsip>'] = $kode_arsip->kode;
281282
$replaces['<derajat>'] = $derajat;
282283
$nomor = strtr($format, $replaces);
283284

@@ -613,4 +614,105 @@ public static function getSbml($tahun, $bulan, $jenis)
613614

614615
return $nilai;
615616
}
617+
618+
/**
619+
* Mengubah tanggal ke nama hari.
620+
*
621+
* @param Date $tanggal
622+
* @return string
623+
*/
624+
public static function terbilangHari($tanggal)
625+
{
626+
$tanggal = $tanggal->format('Y-m-d');
627+
$hari = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu'];
628+
$num = date('N', strtotime($tanggal));
629+
630+
return $hari[$num - 1];
631+
}
632+
633+
/**
634+
* Mengubah bulan ke nama bulan.
635+
*
636+
* @param Int $bulan
637+
* @return string
638+
*/
639+
public static function terbilangBulan($bulan)
640+
{
641+
return self::$bulan[$bulan];
642+
}
643+
644+
/**
645+
* Mengubah angka ke rupiah.
646+
*
647+
* @param int|float $angka
648+
* @return string
649+
*/
650+
public static function formatRupiah($angka)
651+
{
652+
$hasil = 'Rp.'.self::formatUang($angka);
653+
654+
return $hasil;
655+
}
656+
657+
/**
658+
* Upper case nama tanpa gelar
659+
*
660+
* @param string $nama
661+
* @return string
662+
*/
663+
public static function upperNamaTanpaGelar($nama)
664+
{
665+
$hasil = explode(',', $nama)[0];
666+
667+
return strtoupper($hasil);
668+
}
669+
670+
671+
/**
672+
* Mengubah angka ke format uang.
673+
*
674+
* @param int|float $angka
675+
* @return string
676+
*/
677+
public static function formatUang($angka)
678+
{
679+
$hasil = number_format($angka, 0, ',', '.');
680+
681+
return $hasil;
682+
}
683+
684+
/**
685+
* Generate jangka waktu.
686+
*
687+
* @param DateTime $awal
688+
* @param DateTime $akhir
689+
* @return string
690+
*/
691+
public static function jangkaWaktuHariKalender($awal, $akhir)
692+
{
693+
$selisih = ($awal->diff($akhir))->format('%a') + 1;
694+
695+
return $selisih.' ( '.self::terbilang($selisih).') Hari Kalender';
696+
}
697+
698+
/**
699+
* Format tampilan spesifikasi.
700+
*
701+
* @param array $spesifikasi
702+
* @return array
703+
*/
704+
public static function formatSpek($spesifikasi)
705+
{
706+
// $speks= json_decode($spesifikasi,true);
707+
$spek = collect($spesifikasi);
708+
$spek->transform(function ($item, $index) {
709+
$item['spek_no'] = $index + 1;
710+
if (isset($item['spek_harga'])) $item['spek_harga'] = self::formatRupiah($item['spek_harga']);
711+
if (isset($item['spek_nilai'])) $item['spek_nilai'] = self::formatRupiah($item['spek_nilai']);
712+
return $item;
713+
})->toArray();
714+
return $spek;
715+
}
716+
717+
616718
}

app/Models/NaskahKeluar.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Helpers\Helper;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Support\Carbon;
89
use Illuminate\Support\Facades\Auth;
910

1011
class NaskahKeluar extends Model
@@ -23,14 +24,14 @@ protected static function booted(): void
2324
{
2425
static::saving(function (NaskahKeluar $naskah) {
2526
if ($naskah->isDirty(['kode_naskah_id', 'tanggal'])) {
26-
$nomor = Helper::nomor($naskah->tanggal, session('year'), $naskah->jenis_naskah_id, Auth::user()->unit_kerja_id, $naskah->kode_arsip_id, $naskah->derajat);
27+
$nomor = Helper::nomor($naskah->tanggal, $naskah->jenis_naskah_id, Auth::user()->unit_kerja_id, $naskah->kode_arsip_id, $naskah->derajat);
2728
$naskah->nomor = $nomor['nomor'];
2829
$naskah->no_urut = $nomor['no_urut'];
2930
$naskah->segmen = $nomor['segmen'];
31+
$naskah->tahun = Carbon::createFromFormat('Y-m-d', $naskah->tanggal->format('Y-m-d'))->year;
3032
}
3133
});
32-
static::creating(function (NaskahKeluar $naskah) {
33-
$naskah->tahun = session('year');
34+
static::creating(function (NaskahKeluar $naskah) {
3435
$naskah->unit_kerja_id = Auth::user()->unit_kerja_id;
3536
});
3637
}

app/Nova/NaskahKeluar.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ public function fields(NovaRequest $request)
6262
return [
6363
Date::make('Tanggal Naskah', 'tanggal')
6464
->sortable()
65-
->rules('required', 'before_or_equal:today', function ($attribute, $value, $fail) {
66-
if (Carbon::createFromFormat('Y-m-d', $value)->year != session('year')) {
67-
return $fail('Tanggal harus di tahun berjalan');
68-
}
69-
})
65+
->rules('required', 'before_or_equal:today')
7066
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))
7167
->filterable(),
7268
Text::make('Nomor')

app/Nova/NaskahMasuk.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ public function fields(NovaRequest $request)
6060
return [
6161
Date::make('Tanggal Naskah', 'tanggal')
6262
->sortable()
63-
->rules('required', function ($attribute, $value, $fail) {
64-
if (Carbon::createFromFormat('Y-m-d', $value)->year != session('year')) {
65-
return $fail('Tanggal harus di tahun berjalan');
66-
}
67-
})
63+
->rules('required')
6864
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))
6965
->filterable(),
7066
Text::make('Nomor')

0 commit comments

Comments
 (0)