Skip to content

Commit 5b6cdb1

Browse files
Refactor code structure for improved readability and maintainability
1 parent 96800e8 commit 5b6cdb1

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

app/Helpers/Helper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class Helper
161161
'undangan' => 'Undangan',
162162
'daftar_hadir' => 'Daftar Hadir',
163163
'notula' => 'Notula',
164+
'pulsa' => 'Tanda Terima Pulsa',
164165
];
165166

166167
const JENIS_HONOR = [

app/Models/PulsaKegiatan.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
class PulsaKegiatan extends Model
1414
{
15+
protected $fillable = ['status'];
16+
1517
protected function casts(): array
1618
{
1719
return [
@@ -70,6 +72,7 @@ protected static function booted(): void
7072
$pulsa->tahun = session('year');
7173
$token = uniqid(Str::random(19));
7274
$pulsa->token = $token;
75+
$pulsa->status = 'open';
7376
$pulsa->link = url(config('nova.path')).'/pulsa/'.$token;
7477
$dataKetua = Helper::getDataPegawaiByUserId($pulsa->koordinator_user_id, $pulsa->tanggal);
7578
$pulsa->unit_kerja_id = optional($dataKetua)->unit_kerja_id;

app/Nova/PulsaKegiatan.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
use App\Helpers\Helper;
66
use App\Helpers\Policy;
7+
use App\Nova\Actions\SetStatus;
8+
use Illuminate\Database\Eloquent\Model;
79
use Laravel\Nova\Fields\BelongsTo;
810
use Laravel\Nova\Fields\Date;
911
use Laravel\Nova\Fields\FormData;
1012
use Laravel\Nova\Fields\Select;
13+
use Laravel\Nova\Fields\Status;
1114
use Laravel\Nova\Fields\Text;
15+
use Laravel\Nova\Http\Requests\ActionRequest;
1216
use Laravel\Nova\Http\Requests\NovaRequest;
1317
use Laravel\Nova\Panel;
1418

@@ -130,6 +134,10 @@ public function fields(NovaRequest $request)
130134
->default(Helper::setDefaultPengelola('ppk', $formData->date('tanggal')));
131135
}),
132136
]),
137+
Status::make('Status', 'status')
138+
->loadingWhen(['open'])
139+
->failedWhen([''])
140+
->onlyOnIndex(),
133141

134142
];
135143
}
@@ -171,6 +179,24 @@ public function lenses(NovaRequest $request)
171179
*/
172180
public function actions(NovaRequest $request)
173181
{
174-
return [];
182+
$actions = [];
183+
$actions[] = SetStatus::make()
184+
->confirmButtonText('Ubah Status')
185+
->confirmText('Pastikan form dibuka jika hanya ada perbaikan isian. Yakin akan melanjutkan?')
186+
->setName('Buka Form')
187+
->setStatus('open')
188+
->sole()
189+
->showInline()
190+
->exceptOnIndex()
191+
->canSee(function ($request) {
192+
if ($request instanceof ActionRequest) {
193+
return true;
194+
}
195+
196+
return $this->resource instanceof Model && $this->resource->status !== 'open';
197+
});
198+
199+
return $actions;
200+
175201
}
176202
}

app/Nova/ShareLink.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function fields(NovaRequest $request)
5858
->options(Helper::setOptionTahunDipa()),
5959
Text::make('Link')
6060
->exceptOnForms()
61+
->displayUsing(fn () => 'Salin')
6162
->copyable(),
6263
URL::make('Lihat', fn () => $this->link),
6364
];

app/Policies/PulsaKegiatanPolicy.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function viewAny(): bool
2222
/**
2323
* Determine whether the user can view the model.
2424
*/
25-
public function view(User $user, PulsaKegiatan $honor): bool
25+
public function view(User $user, PulsaKegiatan $pulsa): bool
2626
{
2727
return Policy::make()
2828
->allowedFor('ppk,arsiparis,bendahara,kpa,ppspm,koordinator,anggota')
29-
->withYear($honor->tahun)
29+
->withYear($pulsa->tahun)
3030
->get();
3131
}
3232

@@ -43,24 +43,24 @@ public function create(): bool
4343
/**
4444
* Determine whether the user can update the model.
4545
*/
46-
public function update(User $user, PulsaKegiatan $honor): bool
46+
public function update(User $user, PulsaKegiatan $pulsa): bool
4747
{
4848
return Policy::make()
4949
->allowedFor('koordinator,anggota')
50-
->withYear($honor->tahun)
51-
->andEqual($honor->unit_kerja_id, Helper::getDataPegawaiByUserId($user->id, now())->unit_kerja_id)
50+
->withYear($pulsa->tahun)
51+
->andEqual($pulsa->unit_kerja_id, Helper::getDataPegawaiByUserId($user->id, now())->unit_kerja_id)
5252
->get();
5353
}
5454

5555
/**
5656
* Determine whether the user can delete the model.
5757
*/
58-
public function delete(User $user, PulsaKegiatan $honor): bool
58+
public function delete(User $user, PulsaKegiatan $pulsa): bool
5959
{
6060
return Policy::make()
6161
->allowedFor('koordinator,anggota')
62-
->withYear($honor->tahun)
63-
->andEqual($honor->unit_kerja_id, Helper::getDataPegawaiByUserId($user->id, now())->unit_kerja_id)
62+
->withYear($pulsa->tahun)
63+
->andEqual($pulsa->unit_kerja_id, Helper::getDataPegawaiByUserId($user->id, now())->unit_kerja_id)
6464
->get();
6565
}
6666

@@ -77,10 +77,12 @@ public function replicate(): bool
7777
/**
7878
* Determine whether the user can replicate model.
7979
*/
80-
public function runAction(): bool
80+
public function runAction(User $user, PulsaKegiatan $pulsa): bool
8181
{
8282
return Policy::make()
83-
->allowedFor('koordinator,anggota,ppk')
83+
->allowedFor('koordinator,anggota')
84+
->withYear($pulsa->tahun)
85+
->andEqual($pulsa->unit_kerja_id, Helper::getDataPegawaiByUserId($user->id, now())->unit_kerja_id)
8486
->get();
8587
}
8688
}

database/migrations/2025_07_25_145516_create_pulsa_kegiatans_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function up(): void
1919
$table->string('tahun', 4)->nullable();
2020
$table->string('token', 32)->nullable();
2121
$table->string('link')->nullable();
22+
$table->string('status', 20)->nullable();
2223
$table->mediumInteger('unit_kerja_id')->nullable()->unsigned();
2324
$table->mediumInteger('mata_anggaran_id')->nullable()->unsigned();
2425
$table->mediumInteger('koordinator_user_id')->nullable()->unsigned();
Binary file not shown.

0 commit comments

Comments
 (0)