22
33namespace App \Nova ;
44
5+ use App \Helpers \Helper ;
6+ use App \Helpers \Policy ;
7+ use App \Nova \UnitKerja ;
8+ use Laravel \Nova \Fields \BelongsTo ;
9+ use Laravel \Nova \Fields \Date ;
10+ use Laravel \Nova \Fields \FormData ;
11+ use Laravel \Nova \Fields \Select ;
12+ use Laravel \Nova \Fields \Text ;
513use Laravel \Nova \Http \Requests \NovaRequest ;
14+ use Laravel \Nova \Panel ;
615
716class PulsaKegiatan extends Resource
817{
@@ -13,20 +22,23 @@ class PulsaKegiatan extends Resource
1322 */
1423 public static $ model = \App \Models \PulsaKegiatan::class;
1524
25+ public static $ with = ['mataAnggaran ' , 'jenisPulsa ' , 'unitKerja ' ];
26+
1627 public static function label ()
1728 {
18- return 'PulsaKegiatan ' ;
29+ return 'Pulsa Kegiatan ' ;
1930 }
2031
2132 /**
2233 * The single value that should be used to represent the resource when being displayed.
2334 *
2435 * @var string
2536 */
26- public static $ title = 'id ' ;
37+ public static $ title = 'kegiatan ' ;
2738
28- public function subtitle (){
29- return $ this ->id ;
39+ public function subtitle ()
40+ {
41+ return Helper::terbilangBulan ($ this ->bulan ).' ' .$ this ->tahun ;
3042 }
3143
3244 /**
@@ -35,26 +47,100 @@ public function subtitle(){
3547 * @var array
3648 */
3749 public static $ search = [
38- 'id ' ,
50+ 'kegiatan ' , ' bulan ' , ' mataAnggaran.mak ' ,
3951 ];
4052
53+ public static function indexQuery (NovaRequest $ request , $ query )
54+ {
55+ $ query ->where ('tahun ' , session ('year ' ));
56+ if (Policy::make ()->allowedFor ('ppk,arsiparis,bendahara,kpa,ppspm ' )->get ()) {
57+ return $ query ;
58+ } elseif (Policy::make ()->allowedFor ('koordinator,anggota ' )->get ()) {
59+ return $ query ->where ('unit_kerja_id ' , Helper::getDataPegawaiByUserId ($ request ->user ()->id , now ())->unit_kerja_id );
60+ }
61+
62+ return $ query ;
63+ }
64+
4165 /**
4266 * Get the fields displayed by the resource.
4367 *
44- * @param \Laravel\Nova\Http\Requests\NovaRequest $request
4568 * @return array
4669 */
4770 public function fields (NovaRequest $ request )
4871 {
4972 return [
50-
73+ Panel::make ('Keterangan SPJ ' , [
74+ Text::make ('Nama Kegiatan ' , 'kegiatan ' )
75+ ->rules ('required ' , 'max:255 ' )
76+ ->sortable ()
77+ ->help ('Nama Kegiatan yang akan dibayarkan pulsanya. Contoh: Pelatihan Sakernas Februri 2025 ' ),
78+ Date::make ('Tanggal SPJ Tanda Terima ' , 'tanggal ' )
79+ ->rules ('required ' )
80+ ->hideFromIndex ()
81+ ->displayUsing (fn ($ tanggal ) => Helper::terbilangTanggal ($ tanggal )),
82+ BelongsTo::make ('Unit Kerja ' , 'unitKerja ' , UnitKerja::class)
83+ ->showOnIndex (fn () => Policy::make ()->allowedFor ('ppk,ppspm,bendahara ' )->get ())
84+ ->exceptOnForms (),
85+ ]),
86+ Panel::make ('Keterangan Pembayaran Pulsa ' , [
87+ Select::make ('Bulan Pelaksanaan ' , 'bulan ' )
88+ ->options (Helper::BULAN )
89+ ->displayUsingLabels ()
90+ ->rules ('required ' )
91+ ->sortable ()
92+ ->searchable ()
93+ ->filterable (),
94+ Select::make ('Jenis Kegiatan ' , 'jenis_pulsa_id ' )
95+ ->dependsOn (['tanggal ' ], function (Select $ field , NovaRequest $ request , FormData $ form ) {
96+ $ field
97+ ->options (Helper::setOptionJenisPulsa ($ form ->tanggal ));
98+
99+ })
100+ ->rules ('required ' )
101+ ->searchable ()
102+ ->onlyOnForms (),
103+ Text::make ('Link Upload Tanda Terima Pulsa ' , 'link ' )
104+ ->displayUsing (fn () => 'Salin ' )
105+ ->exceptOnForms ()
106+ ->copyable (),
107+ ]),
108+ Panel::make ('Anggaran ' , [
109+ BelongsTo::make ('Item Mata Anggaran ' , 'mataAnggaran ' , MataAnggaran::class)
110+ ->hideFromIndex ()
111+ ->withSubtitles ()
112+ ->searchable ()
113+ ->rules ('required ' ),
114+ ]),
115+ Panel::make ('Penanda Tangan ' , [
116+ Select::make ('Pembuat Daftar ' , 'koordinator_user_id ' )
117+ ->searchable ()
118+ ->hideFromIndex ()
119+ ->rules ('required ' )
120+ ->displayUsing (fn ($ id ) => optional (Helper::getPegawaiByUserId ($ id ))->name )
121+ ->dependsOn (['tanggal ' ], function (Select $ field , NovaRequest $ request , FormData $ formData ) {
122+ $ field ->options (Helper::setOptionPengelola ('koordinator ' , $ formData ->date ('tanggal ' )))
123+ ->default (Helper::setDefaultPengelola ('koordinator ' , $ formData ->date ('tanggal ' )));
124+
125+ }),
126+ Select::make ('Pejabat Pembuat Komitmen ' , 'ppk_user_id ' )
127+ ->searchable ()
128+ ->hideFromIndex ()
129+ ->rules ('required ' )
130+ ->displayUsing (fn ($ id ) => optional (Helper::getPegawaiByUserId ($ id ))->name )
131+ ->dependsOn (['tanggal ' ], function (Select $ field , NovaRequest $ request , FormData $ formData ) {
132+ $ field ->options (Helper::setOptionPengelola ('ppk ' , $ formData ->date ('tanggal ' )))
133+ ->default (Helper::setDefaultPengelola ('ppk ' , $ formData ->date ('tanggal ' )));
134+
135+ }),
136+ ]),
137+
51138 ];
52139 }
53140
54141 /**
55142 * Get the cards available for the request.
56143 *
57- * @param \Laravel\Nova\Http\Requests\NovaRequest $request
58144 * @return array
59145 */
60146 public function cards (NovaRequest $ request )
@@ -65,7 +151,6 @@ public function cards(NovaRequest $request)
65151 /**
66152 * Get the filters available for the resource.
67153 *
68- * @param \Laravel\Nova\Http\Requests\NovaRequest $request
69154 * @return array
70155 */
71156 public function filters (NovaRequest $ request )
@@ -76,7 +161,6 @@ public function filters(NovaRequest $request)
76161 /**
77162 * Get the lenses available for the resource.
78163 *
79- * @param \Laravel\Nova\Http\Requests\NovaRequest $request
80164 * @return array
81165 */
82166 public function lenses (NovaRequest $ request )
@@ -87,7 +171,6 @@ public function lenses(NovaRequest $request)
87171 /**
88172 * Get the actions available for the resource.
89173 *
90- * @param \Laravel\Nova\Http\Requests\NovaRequest $request
91174 * @return array
92175 */
93176 public function actions (NovaRequest $ request )
0 commit comments