Skip to content

Commit 65b7386

Browse files
committed
add derajat surat
1 parent a5d4d11 commit 65b7386

15 files changed

+289
-17
lines changed

app/Helpers/Helper.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,25 @@ public static function getYearFromDate($tanggal, $typeDate = true)
269269
* @param string $derajat
270270
* @return array nomor, nomor_urut, segmen
271271
*/
272-
public static function nomor($tanggal, $jenis_naskah_id, $unit_kerja_id, $kode_arsip_id, $derajat)
272+
public static function nomor($tanggal, $jenis_naskah_id, $unit_kerja_id = null, $kode_arsip_id = null, $derajat = null)
273273
{
274+
$replaces = [];
274275
$tahun = self::getYearFromDate($tanggal);
276+
$replaces['<tahun>'] = $tahun;
275277
$jenis_naskah = JenisNaskah::cache()->get('all')->where('id', $jenis_naskah_id)->first();
276278
$kode_naskah = KodeNaskah::cache()->get('all')->where('id', $jenis_naskah->kode_naskah_id)->first();
277-
$unit_kerja = UnitKerja::cache()->get('all')->where('id', $unit_kerja_id)->first();
278-
$kode_arsip = KodeArsip::cache()->get('all')->where('id', $kode_arsip_id)->first();
279+
if ($unit_kerja_id !== null) {
280+
$unit_kerja = UnitKerja::cache()->get('all')->where('id', $unit_kerja_id)->first();
281+
$replaces['<kode_unit_kerja>'] = $unit_kerja->kode;
282+
}
283+
if ($kode_arsip_id !== null) {
284+
$kode_arsip = KodeArsip::cache()->get('all')->where('id', $kode_arsip_id)->first();
285+
$replaces['<kode_arsip>'] = $kode_arsip->kode;
286+
}
287+
if ($derajat !== null) {
288+
$replaces['<kode_derajat>'] = $derajat;
289+
}
290+
279291
$naskah = NaskahKeluar::where('tahun', $tahun)->where('kode_naskah_id', $kode_naskah->id);
280292
$max_no_urut = $naskah->max('no_urut');
281293
$max_tanggal = $naskah->max('tanggal') ?? '1970-01-01';
@@ -288,17 +300,14 @@ public static function nomor($tanggal, $jenis_naskah_id, $unit_kerja_id, $kode_a
288300
$segmen = NaskahKeluar::where('tahun', $tahun)->where('kode_naskah_id', $kode_naskah->id)->where('no_urut', $no_urut)->max('segmen') + 1;
289301
$replaces['<no_urut>'] = $no_urut.'.'.$segmen;
290302
}
291-
$format = $jenis_naskah->format ?? $kode_naskah->format;
292-
$replaces['<tahun>'] = $tahun;
293-
$replaces['<kode_unit_kerja>'] = $unit_kerja->kode;
294-
$replaces['<kode_arsip>'] = $kode_arsip->kode;
295-
$replaces['<derajat>'] = $derajat;
303+
$format = $jenis_naskah->format ?? $kode_naskah->format;
296304
$nomor = strtr($format, $replaces);
297305

298306
return [
299307
'nomor' => $nomor,
300308
'no_urut' => $no_urut,
301309
'segmen' => $segmen,
310+
'kode_naskah_id' => $kode_naskah->id
302311
];
303312
}
304313

app/Models/DerajatSurat.php

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

app/Models/TataNaskah.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function kodeNaskah(): HasMany
2929
return $this->hasMany(KodeNaskah::class);
3030
}
3131

32+
public function derajatSurat(): HasMany
33+
{
34+
return $this->hasMany(DerajatSurat::class);
35+
}
36+
3237
public static function cacheEntities(): array
3338
{
3439
return [

app/Nova/DerajatSurat.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace App\Nova;
4+
5+
use Laravel\Nova\Fields\BelongsTo;
6+
use Laravel\Nova\Fields\Text;
7+
use Laravel\Nova\Http\Requests\NovaRequest;
8+
9+
class DerajatSurat extends Resource
10+
{
11+
/**
12+
* The model the resource corresponds to.
13+
*
14+
* @var class-string<\App\Models\DerajatSurat>
15+
*/
16+
public static $model = \App\Models\DerajatSurat::class;
17+
18+
public static function label()
19+
{
20+
return 'Derajat Surat';
21+
}
22+
23+
public static $with = ['tataNaskah'];
24+
25+
public static $displayInNavigation = false;
26+
27+
/**
28+
* The single value that should be used to represent the resource when being displayed.
29+
*
30+
* @var string
31+
*/
32+
public static $title = 'derajat';
33+
34+
/**
35+
* The columns that should be searched.
36+
*
37+
* @var array
38+
*/
39+
public static $search = [
40+
'derajat',
41+
];
42+
43+
/**
44+
* Get the fields displayed by the resource.
45+
*
46+
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
47+
* @return array
48+
*/
49+
public function fields(NovaRequest $request)
50+
{
51+
return [
52+
Text::make('Kode')
53+
->rules('required'),
54+
Text::make('Derajat Surat', 'derajat')
55+
->rules('required'),
56+
BelongsTo::make('Harga Satuan')
57+
->rules('required'),
58+
];
59+
}
60+
61+
/**
62+
* Get the cards available for the request.
63+
*
64+
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
65+
* @return array
66+
*/
67+
public function cards(NovaRequest $request)
68+
{
69+
return [];
70+
}
71+
72+
/**
73+
* Get the filters available for the resource.
74+
*
75+
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
76+
* @return array
77+
*/
78+
public function filters(NovaRequest $request)
79+
{
80+
return [];
81+
}
82+
83+
/**
84+
* Get the lenses available for the resource.
85+
*
86+
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
87+
* @return array
88+
*/
89+
public function lenses(NovaRequest $request)
90+
{
91+
return [];
92+
}
93+
94+
/**
95+
* Get the actions available for the resource.
96+
*
97+
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
98+
* @return array
99+
*/
100+
public function actions(NovaRequest $request)
101+
{
102+
return [];
103+
}
104+
}

app/Nova/IzinKeluar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function fields(NovaRequest $request)
8686
->sortable()
8787
->rules('required', function ($attribute, $value, $fail) {
8888
if (Carbon::createFromFormat('Y-m-d', $value)->year != session('year')) {
89-
return $fail('Tanggal harus di tahun berjalan');
89+
return $fail('Tanggal harus di tahun yang telah dipilih');
9090
}
9191
})
9292
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))

app/Nova/KerangkaAcuan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function utamaFields()
158158
->sortable()
159159
->rules('required', 'before_or_equal:today', function ($attribute, $value, $fail) {
160160
if (Helper::getYearFromDate($value, false) != session('year')) {
161-
return $fail('Tanggal harus di tahun berjalan');
161+
return $fail('Tanggal harus di tahun yang telah dipilih');
162162
}
163163
})
164164
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))

app/Nova/NaskahKeluar.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ public function fields(NovaRequest $request)
6464
->sortable()
6565
->rules('required', 'before_or_equal:today')
6666
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))
67-
->filterable(),
67+
->filterable()
68+
->rules('required', 'before_or_equal:today', function ($attribute, $value, $fail) {
69+
if (Helper::getYearFromDate($value, false) != session('year')) {
70+
return $fail('Tanggal harus di tahun yang telah dipilih');
71+
}
72+
}),
6873
Text::make('Nomor')
6974
->onlyOnDetail(),
7075
Text::make('Tujuan', 'tujuan')

app/Nova/NaskahMasuk.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ public function fields(NovaRequest $request)
6161
->sortable()
6262
->rules('required')
6363
->displayUsing(fn ($tanggal) => Helper::terbilangTanggal($tanggal))
64-
->filterable(),
64+
->filterable()
65+
->rules('required', 'before_or_equal:today', function ($attribute, $value, $fail) {
66+
if (Helper::getYearFromDate($value, false) != session('year')) {
67+
return $fail('Tanggal harus di tahun yang telah dipilih');
68+
}
69+
}),
6570
Text::make('Nomor')
6671
->rules('required'),
6772
Text::make('Pengirim')->rules('required'),

app/Nova/TataNaskah.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class TataNaskah extends Resource
1717
{
1818
use HasTabs;
19-
public static $with = ['kodeNaskah', 'kodeArsip'];
19+
public static $with = ['kodeNaskah', 'kodeArsip', 'derajatSurat'];
2020

2121
public static function label()
2222
{
@@ -64,6 +64,7 @@ public function fields(NovaRequest $request)
6464
Tabs::make('Detail Naskah', [
6565
HasMany::make('Kode Naskah'),
6666
HasMany::make('Kode Arsip'),
67+
HasMany::make('Derajat Surat'),
6768
]),
6869
];
6970
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace App\Policies;
4+
5+
use App\Helpers\Policy;
6+
7+
class DerajatSuratPolicy
8+
{
9+
/**
10+
* Determine whether the user can view any models.
11+
*/
12+
public function viewAny(): bool
13+
{
14+
return Policy::make()
15+
->allowedFor('admin')
16+
->andEqual(request()->is('resources/derajat-surats'), false)
17+
->get();
18+
}
19+
20+
/**
21+
* Determine whether the user can view the model.
22+
*/
23+
public function view(): bool
24+
{
25+
return Policy::make()
26+
->allowedFor('admin')
27+
->get();
28+
}
29+
30+
/**
31+
* Determine whether the user can create models.
32+
*/
33+
public function create(): bool
34+
{
35+
return Policy::make()
36+
->allowedFor('admin')
37+
->get();
38+
}
39+
40+
/**
41+
* Determine whether the user can update the model.
42+
*/
43+
public function update(): bool
44+
{
45+
return Policy::make()
46+
->allowedFor('admin')
47+
->get();
48+
}
49+
50+
/**
51+
* Determine whether the user can delete the model.
52+
*/
53+
public function delete(): bool
54+
{
55+
return Policy::make()
56+
->allowedFor('admin')
57+
->get();
58+
}
59+
60+
/**
61+
* Determine whether the user can restore the model.
62+
*/
63+
public function restore(): bool
64+
{
65+
return Policy::make()
66+
->allowedFor('admin')
67+
->get();
68+
}
69+
70+
/**
71+
* Determine whether the user can permanently delete the model.
72+
*/
73+
public function forceDelete(): bool
74+
{
75+
return Policy::make()
76+
->allowedFor('admin')
77+
->get();
78+
}
79+
80+
/**
81+
* Determine whether the user can replicate the model.
82+
*/
83+
public function replicate(): bool
84+
{
85+
return Policy::make()
86+
->allowedFor('admin')
87+
->get();
88+
}
89+
}

0 commit comments

Comments
 (0)