fix(districts): perbaiki pencarian dan pemetaan provinsi untuk distrik
- Tambahkan penanganan khusus untuk kode kota Papua. - Perbarui aturan validasi untuk kolom kode distrik. - Perbaiki tampilan nama provinsi pada tabel distrik.
This commit is contained in:
@@ -80,9 +80,23 @@ class DistrictsController extends Controller
|
|||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$search = explode('|', $search);
|
$search = explode('|', $search);
|
||||||
if(isset($search[0]) &&!empty($search[0])){
|
if(isset($search[0]) && !empty($search[0])){
|
||||||
$query->where('province_code',$search[0]);
|
// Define special city codes once
|
||||||
|
$specialCityCodes = ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71'];
|
||||||
|
|
||||||
|
// Handle Papua province special cases
|
||||||
|
if($search[0] == '92'){
|
||||||
|
$query->where('province_code', '92')
|
||||||
|
->whereNotIn('city_code', $specialCityCodes);
|
||||||
|
} else if($search[0] == '92.1'){
|
||||||
|
$query->where('province_code', '92')
|
||||||
|
->whereIn('city_code', $specialCityCodes);
|
||||||
|
} else {
|
||||||
|
// For all other provinces
|
||||||
|
$query->where('province_code', $search[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($search[1]) &&!empty($search[1])){
|
if(isset($search[1]) &&!empty($search[1])){
|
||||||
$query->where('city_code',$search[1]);
|
$query->where('city_code',$search[1]);
|
||||||
}
|
}
|
||||||
@@ -123,6 +137,15 @@ class DistrictsController extends Controller
|
|||||||
// Calculate the current page number
|
// Calculate the current page number
|
||||||
$currentPage = 0 + 1;
|
$currentPage = 0 + 1;
|
||||||
|
|
||||||
|
$data = $data->map(function ($item) {
|
||||||
|
if (in_array($item->city_code, ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71'])) {
|
||||||
|
$item->province_name = Province::where('code', '92.1')->first()->name;
|
||||||
|
} else {
|
||||||
|
$item->province_name = $item->city->province->name;
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
|
||||||
// Return the response data as a JSON object
|
// Return the response data as a JSON object
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'draw' => $request->get('draw'),
|
'draw' => $request->get('draw'),
|
||||||
|
|||||||
@@ -18,10 +18,10 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($this->method() === 'PUT') {
|
if ($this->method() === 'PUT') {
|
||||||
$rules['code'] = 'required|string|max:6|unique:districts,code,' . $this->id;
|
$rules['code'] = 'required|string|max:9|unique:districts,code,' . $this->id;
|
||||||
$rules['name'] = 'required|string|max:2554|unique:districts,name,' . $this->id;
|
$rules['name'] = 'required|string|max:2554|unique:districts,name,' . $this->id;
|
||||||
} else {
|
} else {
|
||||||
$rules['code'] = 'required|string|max:6|unique:districts,code';
|
$rules['code'] = 'required|string|max:9|unique:districts,code';
|
||||||
$rules['name'] = 'required|string|max:2554|unique:districts,name';
|
$rules['name'] = 'required|string|max:2554|unique:districts,name';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,8 @@
|
|||||||
</label>
|
</label>
|
||||||
<button class="search btn btn-sm btn-outline btn-primary">
|
<button class="search btn btn-sm btn-outline btn-primary">
|
||||||
<i class="ki-filled ki-setting-4"> </i>
|
<i class="ki-filled ki-setting-4"> </i>
|
||||||
<Filters></Filters>
|
|
||||||
</button>
|
</button>
|
||||||
<div class="h-[24px] border border-r-gray-200"></div>
|
<div class="border border-r-gray-200"></div>
|
||||||
<a class="btn btn-sm btn-light" href="{{ route('locations.districts.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" href="{{ route('locations.districts.export') }}"> Export to Excel </a>
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('locations.districts.create') }}"> Add District </a>
|
<a class="btn btn-sm btn-primary" href="{{ route('locations.districts.create') }}"> Add District </a>
|
||||||
</div>
|
</div>
|
||||||
@@ -165,7 +164,7 @@
|
|||||||
province: {
|
province: {
|
||||||
title: 'Province',
|
title: 'Province',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
return data.city.province.name;
|
return data.province_name;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user