Skip to content

Commit 041354f

Browse files
authored
Rilis v2507.0.0 (#495)
2 parents 8ad61b6 + cfdf1e6 commit 041354f

24 files changed

+899
-12
lines changed

app/Exports/AdatExport.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Exports;
4+
5+
use Maatwebsite\Excel\Concerns\FromCollection;
6+
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
7+
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
8+
use Maatwebsite\Excel\Concerns\WithHeadings;
9+
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
10+
11+
class AdatExport implements FromCollection, WithHeadings, ShouldAutoSize, WithColumnFormatting
12+
{
13+
protected $data;
14+
15+
public function __construct($data)
16+
{
17+
$this->data = $data;
18+
}
19+
20+
public function collection()
21+
{
22+
return $this->data->map(function ($item, $index) {
23+
$jumlahMarga = $item->marga_count ?? 0;
24+
return [
25+
'no' => $index + 1, // Menambahkan nomor urut berdasarkan index
26+
'nama_adat' => $item->name,
27+
'kode_wilayah' => $item->region->region_code,
28+
'nama_provinsi' => $item->region->region_name,
29+
];
30+
});
31+
}
32+
33+
public function headings(): array
34+
{
35+
return [
36+
'NO',
37+
'NAMA ADAT',
38+
'KODE WILAYAH',
39+
'NAMA PROVINSI',
40+
];
41+
}
42+
43+
public function columnFormats(): array
44+
{
45+
return [
46+
'E' => NumberFormat::FORMAT_NUMBER, // Format kolom E sebagai angka
47+
];
48+
}
49+
}

app/Helpers/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
function pantau_versi()
1313
{
14-
return 'v2506.0.0';
14+
return 'v2507.0.0';
1515
}
1616
}
1717

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Exports\AdatExport;
6+
use App\Http\Controllers\Controller;
7+
use App\Http\Requests\AdatRequest;
8+
use App\Imports\SukuImport;
9+
use App\Models\WilayahAdat;
10+
use App\Models\Region;
11+
use Illuminate\Http\Request;
12+
use Illuminate\Support\Facades\Storage;
13+
use Maatwebsite\Excel\Facades\Excel;
14+
use Yajra\DataTables\DataTables;
15+
16+
class AdatController extends Controller
17+
{
18+
public function index(Request $request)
19+
{
20+
if ($request->excel) {
21+
$paramDatatable = json_decode($request->get('params'), 1);
22+
$request->merge($paramDatatable);
23+
}
24+
25+
if ($request->ajax() || $request->excel) {
26+
$query = DataTables::of(WilayahAdat::with('region'));
27+
if ($request->excel) {
28+
$query->filtering();
29+
30+
return Excel::download(new AdatExport($query->results()), 'Wilayah-WilayahAdat.xlsx');
31+
}
32+
33+
return $query->addIndexColumn()
34+
->addColumn('action', function ($data) {
35+
$edit = '<a href="' . route('adat.edit', $data->id) . '" class="btn btn-sm btn-warning btn-sm"><i class="fas fa-pencil-alt"></i></a>';
36+
$delete = '<button data-href="' . route('adat.destroy', $data->id) . '" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#confirm-delete"><i class="fas fa-trash"></i></button>';
37+
38+
return '<div class="btn btn-group">' . $edit . $delete . '</div>';
39+
})
40+
->rawColumns(['action'])
41+
->make(true);
42+
}
43+
44+
return view('admin.adat.index');
45+
}
46+
47+
public function create()
48+
{
49+
return view('admin.adat.create');
50+
}
51+
52+
public function store(AdatRequest $request)
53+
{
54+
$input = $request->all();
55+
$input['tbl_region_id'] = Region::where('region_code', $input['tbl_region_id'])->where('parent_code', 0)->first()->id;
56+
if (WilayahAdat::create($input)) {
57+
return redirect('adat')->with('success', 'Data berhasil disimpan');
58+
}
59+
60+
return back()->with('error', 'Data gagal disimpan');
61+
}
62+
63+
public function edit($id)
64+
{
65+
return view('admin.adat.edit', [
66+
'adat' => WilayahAdat::with('region')->findOrFail($id),
67+
]);
68+
}
69+
70+
public function update(AdatRequest $request, $id)
71+
{
72+
$input = $request->all();
73+
$input['tbl_region_id'] = Region::where('region_code', $input['tbl_region_id'])->where('parent_code', 0)->first()->id;
74+
$adat = WilayahAdat::findOrFail($id);
75+
76+
if ($adat->update($input)) {
77+
return redirect('adat')->with('success', 'Data berhasil diubah');
78+
}
79+
80+
return back()->with('error', 'Data gagal diubah');
81+
}
82+
83+
public function import()
84+
{
85+
return view('admin.adat.import');
86+
}
87+
88+
public function prosesImport(Request $request)
89+
{
90+
try {
91+
Excel::import(new SukuImport, $request->file('file')->store('temp'));
92+
} catch (\Exception $e) {
93+
report($e);
94+
95+
return back()->with('error', 'Data gagal diimport');
96+
}
97+
98+
// Hapus folder temp ketika sudah selesai
99+
Storage::deleteDirectory('temp');
100+
101+
return redirect('adat')->with('success', 'Data berhasil diimport');
102+
}
103+
104+
public function contohImport()
105+
{
106+
$file = public_path('/assets/import/data_adat.xlsx');
107+
108+
return response()->download($file);
109+
}
110+
111+
public function destroy($id)
112+
{
113+
if (WilayahAdat::destroy($id)) {
114+
return redirect('adat')->with('success', 'Data berhasil dihapus');
115+
}
116+
117+
return redirect('adat')->with('error', 'Data gagal dihapus');
118+
}
119+
}

app/Http/Controllers/Admin/SukuController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function index(Request $request)
2323
}
2424

2525
if ($request->ajax() || $request->excel) {
26-
$query = DataTables::of(Suku::with('region')->withCount('marga'));
26+
$query = DataTables::of(Suku::with('region', 'wilayahAdat')->withCount('marga'));
2727
if ($request->excel) {
2828
$query->filtering();
2929

@@ -71,6 +71,7 @@ public function edit($id)
7171
public function update(SukuRequest $request, $id)
7272
{
7373
$input = $request->all();
74+
$input['tbl_region_id'] = Region::where('region_code', $input['tbl_region_id'])->where('parent_code', 0)->first()->id;
7475
$suku = Suku::findOrFail($id);
7576

7677
if ($suku->update($input)) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\WilayahAdat;
7+
use Illuminate\Http\Request;
8+
9+
class AdatController extends Controller
10+
{
11+
public function index(Request $request)
12+
{
13+
$kodeProv = $request->get('kode_prov');
14+
$search = $request->get('q');
15+
$suku = WilayahAdat::selectRaw('id, name, name as text')
16+
->when($kodeProv, static fn($q) => $q->whereRelation('region', 'region_code', $kodeProv))
17+
->when($search, static fn($q) => $q->where('name', 'like', "%{$search}%"))
18+
->paginate();
19+
20+
return response()->json([
21+
'results' => $suku->items(),
22+
'pagination' => [
23+
'more' => $suku->currentPage() < $suku->lastPage(),
24+
],
25+
]);
26+
}
27+
}

app/Http/Controllers/Api/MargaController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ class MargaController extends Controller
1111
public function index(Request $request)
1212
{
1313
$kodeSuku = $request->get('suku');
14+
$nameSuku = $request->get('name_suku');
1415
$search = $request->get('q');
1516
$marga = Marga::selectRaw('id, name')
1617
->when($kodeSuku, static fn($q) => $q->whereRelation('suku', 'ethnic_group_id', $kodeSuku))
18+
->when($nameSuku, static fn($q) => $q->whereRelation('suku', 'name', $nameSuku))
1719
->when($search, static fn($q) => $q->where('name', 'like', "%{$search}%"))
1820
->paginate();
1921

app/Http/Controllers/Api/SukuController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ class SukuController extends Controller
1111
public function index(Request $request)
1212
{
1313
$kodeProv = $request->get('kode_prov');
14+
$wilayahAdat = $request->get('wilayah_adat');
1415
$search = $request->get('q');
1516
$suku = Suku::selectRaw('id, name, name as text')
1617
->when($kodeProv, static fn($q) => $q->whereRelation('region', 'region_code', $kodeProv))
18+
->when($wilayahAdat, static fn($q) => $q->whereRelation('wilayahAdat', 'name', $wilayahAdat))
1719
->when($search, static fn($q) => $q->where('name', 'like', "%{$search}%"))
1820
->paginate();
1921

app/Http/Requests/AdatRequest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class AdatRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'tbl_region_id' => [
28+
'required',
29+
'numeric',
30+
'exists:tbl_regions,region_code',
31+
],
32+
'name' => 'required|string|min:1|max:100',
33+
];
34+
}
35+
}

app/Http/Requests/SukuRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function rules()
2929
'numeric',
3030
'exists:tbl_regions,region_code',
3131
],
32+
'adat_id' => [
33+
'required',
34+
'numeric',
35+
'exists:adats,id',
36+
],
3237
'name' => 'required|string|min:1|max:100',
3338
];
3439
}

app/Models/Suku.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Suku extends Model
1616
/** {@inheritdoc} */
1717
protected $fillable = [
1818
'tbl_region_id',
19+
'adat_id',
1920
'name',
2021
];
2122

@@ -36,4 +37,9 @@ public function marga(): HasMany
3637
{
3738
return $this->hasMany(Marga::class, 'ethnic_group_id', 'id');
3839
}
40+
41+
public function wilayahAdat()
42+
{
43+
return $this->belongsTo(WilayahAdat::class, 'adat_id');
44+
}
3945
}

0 commit comments

Comments
 (0)