Skip to content

Commit 71d2410

Browse files
committed
Versi 3.0.0
1 parent 62d1468 commit 71d2410

27 files changed

+943
-89
lines changed

app/Console/Commands/SimpedeCache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Models\Announcement;
56
use App\Models\DataPegawai;
67
use App\Models\DerajatNaskah;
78
use App\Models\Dipa;
@@ -25,6 +26,7 @@
2526
use App\Models\Pengelola;
2627
use App\Models\RateTranslok;
2728
use App\Models\SkTranslok;
29+
use App\Models\TargetKkp;
2830
use App\Models\TargetSerapanAnggaran;
2931
use App\Models\TataNaskah;
3032
use App\Models\Template;
@@ -55,6 +57,7 @@ class SimpedeCache extends Command
5557
*/
5658
public function handle()
5759
{
60+
Announcement::cache()->updateAll();
5861
DataPegawai::cache()->updateAll();
5962
DerajatNaskah::cache()->updateAll();
6063
Dipa::cache()->updateAll();
@@ -78,6 +81,7 @@ public function handle()
7881
Pengelola::cache()->updateAll();
7982
RateTranslok::cache()->updateAll();
8083
SkTranslok::cache()->updateAll();
84+
TargetKkp::cache()->updateAll();
8185
TargetSerapanAnggaran::cache()->updateAll();
8286
TataNaskah::cache()->updateAll();
8387
Template::cache()->updateAll();

app/Helpers/Helper.php

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
use App\Models\Pengelola;
3030
use App\Models\TataNaskah;
3131
use App\Models\Template;
32+
use App\Models\UangPersediaan;
3233
use App\Models\UnitKerja;
3334
use App\Models\User;
3435
use App\Models\WhatsappGroup;
36+
use DateTime;
3537
use Illuminate\Support\Carbon;
3638
use Illuminate\Support\Facades\Auth;
3739
use Illuminate\Support\Facades\Cache;
@@ -64,6 +66,15 @@ class Helper
6466
'Lainnya' => 'Lainnya',
6567
];
6668

69+
const JENIS_UP = [
70+
'GTUP NIHIL',
71+
'GUP NIHIL',
72+
'GUP KKP',
73+
'TUP',
74+
'GUP',
75+
'UP',
76+
];
77+
6778
const AKUN_PERJALANAN = [
6879
'524111',
6980
'524113',
@@ -76,12 +87,6 @@ class Helper
7687
'kkp' => 'KKP',
7788
];
7889

79-
const JENIS_UANG_PERSEDIAAN = [
80-
'gup' => 'GUP',
81-
'kkp' => 'KKP',
82-
];
83-
84-
8590
const JENIS_KEGIATAN = [
8691
'Libur' => 'Libur',
8792
'Deadline' => 'Deadline',
@@ -1972,6 +1977,42 @@ public static function getLatestTataNaskahId($tanggal)
19721977
return optional(TataNaskah::cache()->get('all')->where('tanggal', '<=', $tanggal)->sortByDesc('tanggal')->first())->id;
19731978
}
19741979

1980+
public static function getLatestUangPersediaan($tahun, array $jenis)
1981+
{
1982+
$dipa = Dipa::cache()
1983+
->get('all')
1984+
->where('tahun', $tahun)
1985+
->first();
1986+
$dipaId = optional($dipa)->id;
1987+
1988+
$latestUp = UangPersediaan::where('dipa_id', $dipaId)
1989+
->whereIn('jenis', $jenis)
1990+
->whereNowOrPast('tanggal')
1991+
->latest('tanggal')
1992+
->first();
1993+
1994+
return $latestUp;
1995+
}
1996+
1997+
public static function getLatestUp($tahun)
1998+
{
1999+
return self::getLatestUangPersediaan($tahun, ['UP']);
2000+
}
2001+
2002+
public static function getLatestGup($tahun)
2003+
{
2004+
$gup = self::getLatestUangPersediaan($tahun, ['GUP']);
2005+
2006+
return $gup ?? self::getLatestUp($tahun);
2007+
}
2008+
2009+
public static function getLatestTup($tahun)
2010+
{
2011+
$tup = self::getLatestUangPersediaan($tahun, ['TUP', 'GTUP NIHIL']);
2012+
2013+
return $tup === 'GTUP NIHIL' ? null : $tup;
2014+
}
2015+
19752016
/**
19762017
* Get the latest Harga Satuan ID based on the given date.
19772018
*
@@ -2300,7 +2341,7 @@ public static function setOptionBarangPersediaan()
23002341
public static function sendReminder($reminder, $method = 'auto')
23012342
{
23022343
$kegiatan = $reminder->daftarKegiatan;
2303-
$hari = floor(($method === 'auto' ? $reminder->tanggal : now())->diffInDays($kegiatan->awal));
2344+
$hari = floor(($method === 'auto' ? $reminder->tanggal : now())->diffInDays($kegiatan->awal, true));
23042345
$pesan = strtr($kegiatan->pesan, [
23052346
'{judul}' => $hari > 0 ? '[Reminder Deadline (H-'.$hari.')]' : '[Reminder Deadline]',
23062347
'{tanggal}' => self::terbilangTanggal($kegiatan->awal),
@@ -2343,4 +2384,71 @@ public static function version(): string
23432384
return $version;
23442385
});
23452386
}
2387+
2388+
public static function hitungPeriodeGup($tanggalGup): array
2389+
{
2390+
if (isset($tanggalGup)) {
2391+
$date = $tanggalGup;
2392+
2393+
$bulan = (int) $date->format('m');
2394+
$tahun = (int) $date->format('Y');
2395+
$hari = (int) $date->format('d');
2396+
2397+
$daysInCurrentMonth = cal_days_in_month(CAL_GREGORIAN, $bulan, $tahun);
2398+
2399+
// Cari bulan berikutnya
2400+
$nextMonth = $bulan + 1;
2401+
$nextYear = $tahun;
2402+
if ($nextMonth > 12) {
2403+
$nextMonth = 1;
2404+
$nextYear++;
2405+
}
2406+
$daysInNextMonth = cal_days_in_month(CAL_GREGORIAN, $nextMonth, $nextYear);
2407+
2408+
if ($hari == $daysInCurrentMonth) {
2409+
// Jika tanggal terakhir bulan → pakai tanggal terakhir bulan berikutnya
2410+
$endDate = new DateTime("$nextYear-$nextMonth-$daysInNextMonth");
2411+
$days = $daysInNextMonth;
2412+
} else {
2413+
// Jika bukan tanggal terakhir → pakai tanggal sama di bulan berikutnya
2414+
// Hati-hati jika bulan berikutnya tidak punya tanggal tsb (misalnya 30 Feb)
2415+
$endDay = min($hari, $daysInNextMonth);
2416+
$endDate = new DateTime("$nextYear-$nextMonth-$endDay");
2417+
$days = $daysInCurrentMonth;
2418+
}
2419+
2420+
return [
2421+
'awal' => Carbon::instance($date),
2422+
'akhir' => Carbon::instance($endDate),
2423+
'hari' => $days,
2424+
];
2425+
2426+
}
2427+
2428+
return [
2429+
'awal' => '-',
2430+
'akhir' => '-',
2431+
'hari' => 0,
2432+
];
2433+
2434+
}
2435+
2436+
public static function setReminderForUangPersediaan($jenis, $tanggal)
2437+
{
2438+
2439+
$kegiatan = new DaftarKegiatan;
2440+
$kegiatan->jenis = 'Deadline';
2441+
$kegiatan->kegiatan = $jenis === 'gup' ? 'SPM Penggantian UP (GUP)' : 'SPM Pertanggungjawaban TUP (GTUP)';
2442+
$kegiatan->awal = $tanggal;
2443+
$kegiatan->akhir = $tanggal;
2444+
$kegiatan->wa_group_id = [['id' => '6287814885714-1605499798@g.us']];
2445+
$kegiatan->pesan = "*{judul}*\n\nDeadline : {tanggal}\nPerihal : {kegiatan}\nPenanggung jawab: *{pj}*\n\nMohon untuk segera membuat ".($jenis === 'gup' ? 'SPM Penggantian UP (GUP)' : 'SPM Pertanggungjawaban TUP (GTUP)')." sebelum tanggal ({tanggal}).\ndengan memperhatikan jumlah minimum yang telah ditentukan.\n\nTerimakasih ✨✨";
2446+
$kegiatan->waktu_reminder = [
2447+
['hari' => 3, 'referensi_waktu' => 'HK', 'waktu_kirim' => '08:00:00'],
2448+
['hari' => 1, 'referensi_waktu' => 'HK', 'waktu_kirim' => '08:00:00'],
2449+
];
2450+
$kegiatan->daftar_kegiatanable_id = 1;
2451+
$kegiatan->daftar_kegiatanable_type = 'App\\Models\\UnitKerja';
2452+
$kegiatan->save();
2453+
}
23462454
}

app/Models/Dipa.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ protected function casts(): array
1818
'tanggal' => 'date',
1919
'tanggal_revisi' => 'date',
2020
'tanggal_realisasi' => 'date',
21+
'tanggal_nihil' => 'date',
2122
];
2223
}
2324

@@ -34,6 +35,16 @@ public function jenisBelanja(): HasMany
3435
return $this->hasMany(JenisBelanja::class);
3536
}
3637

38+
public function targetKkp(): HasMany
39+
{
40+
return $this->hasMany(TargetKkp::class);
41+
}
42+
43+
public function uangPersediaan(): HasMany
44+
{
45+
return $this->hasMany(UangPersediaan::class);
46+
}
47+
3748
/**
3849
* Get the daftar kamus anggaran.
3950
*/
@@ -70,9 +81,25 @@ protected static function booted(): void
7081
JenisBelanja::destroy($jenisIds);
7182
JenisBelanja::cache()->enable();
7283
JenisBelanja::cache()->updateAll();
84+
$kkpIds = TargetKkp::where('dipa_id', $dipa->id)->pluck('id');
85+
TargetKkp::cache()->disable();
86+
TargetKkp::destroy($kkpIds);
87+
TargetKkp::cache()->enable();
88+
TargetKkp::cache()->updateAll();
89+
$uangPersediaan = UangPersediaan::where('dipa_id', $dipa->id)->pluck('id');
90+
UangPersediaan::destroy($uangPersediaan);
7391
$realisasiIds = RealisasiAnggaran::where('dipa_id', $dipa->id)->pluck('id');
7492
RealisasiAnggaran::destroy($realisasiIds);
7593
});
94+
static::created(function (Dipa $dipa) {
95+
foreach (range(1, 12) as $bulan) {
96+
$targetKkp = new TargetKkp;
97+
$targetKkp->dipa_id = $dipa->id;
98+
$targetKkp->bulan = $bulan;
99+
$targetKkp->nilai = 0;
100+
$targetKkp->save();
101+
}
102+
});
76103
}
77104

78105
public static function getByTahun($tahun)

app/Models/JenisBelanja.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected static function booted(): void
4848
$targetSerapan = new TargetSerapanAnggaran;
4949
$targetSerapan->jenis_belanja_id = $jenis->id;
5050
$targetSerapan->bulan = $bulan;
51-
$targetSerapan->nilai = 100;
51+
$targetSerapan->nilai = 0;
5252
$targetSerapan->save();
5353
}
5454
});

app/Models/TargetKkp.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
use Mostafaznv\LaraCache\CacheEntity;
8+
use Mostafaznv\LaraCache\Traits\LaraCache;
9+
10+
class TargetKkp extends Model
11+
{
12+
use LaraCache;
13+
14+
public static function cacheEntities(): array
15+
{
16+
return [
17+
CacheEntity::make('all')
18+
->cache(function () {
19+
return TargetKkp::all();
20+
}),
21+
];
22+
}
23+
24+
public function dipa(): BelongsTo
25+
{
26+
return $this->belongsTo(Dipa::class);
27+
}
28+
}

app/Models/UangPersediaan.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace App\Models;
44

55
use Illuminate\Database\Eloquent\Model;
6-
use Mostafaznv\LaraCache\CacheEntity;
7-
use Mostafaznv\LaraCache\Traits\LaraCache;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
87

98
class UangPersediaan extends Model
109
{
11-
use LaraCache;
10+
protected $fillable = [
11+
'dipa_id', 'nomor_sp2d',
12+
];
1213

1314
protected function casts(): array
1415
{
@@ -17,13 +18,8 @@ protected function casts(): array
1718
];
1819
}
1920

20-
public static function cacheEntities(): array
21+
public function dipa(): BelongsTo
2122
{
22-
return [
23-
CacheEntity::make('all')
24-
->cache(function () {
25-
return UangPersediaan::all();
26-
}),
27-
];
23+
return $this->belongsTo(Dipa::class);
2824
}
2925
}

0 commit comments

Comments
 (0)