Compare commits
12 Commits
4502f9a298
...
cd10e17259
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd10e17259 | ||
|
|
80e592c639 | ||
|
|
4cf14d46b4 | ||
|
|
817eb3360b | ||
|
|
d92b66185c | ||
|
|
094f9fa6d6 | ||
|
|
bf288013f4 | ||
|
|
1a7703a6cc | ||
|
|
dc931dbb4b | ||
|
|
d74dbb37a7 | ||
|
|
00356f2366 | ||
|
|
0be26178ff |
@@ -11,7 +11,18 @@ use Modules\Location\Models\City;
|
||||
class CitiesExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection(){
|
||||
return City::with('province')->get();
|
||||
$data = City::with('province')->get();
|
||||
|
||||
$data = $data->map(function ($item) {
|
||||
if (in_array($item->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->province->name;
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function map($row): array{
|
||||
@@ -19,7 +30,7 @@ class CitiesExport implements WithColumnFormatting, WithHeadings, FromCollection
|
||||
$row->id,
|
||||
$row->code,
|
||||
$row->name,
|
||||
$row->province->name,
|
||||
$row->province_name,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
@@ -7,11 +7,21 @@ use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Province;
|
||||
|
||||
class DistrictsExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection(){
|
||||
return District::with('city.province')->get();
|
||||
$data = District::with('city.province')->get();
|
||||
|
||||
$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;
|
||||
});
|
||||
}
|
||||
|
||||
public function map($row): array{
|
||||
@@ -20,7 +30,7 @@ class DistrictsExport implements WithColumnFormatting, WithHeadings, FromCollect
|
||||
$row->code,
|
||||
$row->name,
|
||||
$row->city->name,
|
||||
$row->city->province->name,
|
||||
$row->province_name,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
@@ -6,12 +6,22 @@ use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\Village;
|
||||
|
||||
class VillagesExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection(){
|
||||
return Village::with('district.city.province')->get();
|
||||
$data = Village::with('district.city.province')->get();
|
||||
|
||||
$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->district->city->province->name;
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
|
||||
public function map($row): array{
|
||||
@@ -22,7 +32,7 @@ class VillagesExport implements WithColumnFormatting, WithHeadings, FromCollecti
|
||||
$row->postal_code,
|
||||
$row->district->name,
|
||||
$row->district->city->name,
|
||||
$row->district->city->province->name,
|
||||
$row->province_name,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
@@ -80,8 +80,21 @@ class CitiesController extends Controller
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$search = explode('|', $search);
|
||||
if(isset($search[0]) &&!empty($search[0])){
|
||||
$query->where('province_code',$search[0]);
|
||||
if(isset($search[0]) && !empty($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('code', $specialCityCodes);
|
||||
} else if($search[0] == '92.1'){
|
||||
$query->where('province_code', '92')
|
||||
->whereIn('code', $specialCityCodes);
|
||||
} else {
|
||||
// For all other provinces
|
||||
$query->where('province_code', $search[0]);
|
||||
}
|
||||
}
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'LIKE', "%$search[1]%");
|
||||
@@ -121,6 +134,19 @@ class CitiesController extends Controller
|
||||
// Calculate the current page number
|
||||
$currentPage = 0 + 1;
|
||||
|
||||
//maping data for datatables,
|
||||
//jika city code adalah '92.01', '92.04', '92.05', '92.09', '92.10', '92.71' maka province code yang dipilih adalah 92.1
|
||||
$data = $data->map(function ($item) {
|
||||
if (in_array($item->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->province->name;
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
// Apply the search filter again if there is a search filter
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
@@ -138,7 +164,20 @@ class CitiesController extends Controller
|
||||
return Excel::download(new CitiesExport, 'cities.xlsx');
|
||||
}
|
||||
|
||||
public function getCitiesByProvinceId($id){
|
||||
return response()->json(City::where('province_code', $id)->get());
|
||||
public function getCitiesByProvinceId($id)
|
||||
{
|
||||
|
||||
$query = City::query();
|
||||
|
||||
$provinceCode = substr($id, 0, 2);
|
||||
$query->where('province_code', $provinceCode);
|
||||
|
||||
if ($id == '92.1') {
|
||||
$query->whereIn('code', ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71']);
|
||||
} elseif ($id == '92') {
|
||||
$query->whereNotIn('code', ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71']);
|
||||
}
|
||||
|
||||
return response()->json($query->get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +80,23 @@ class DistrictsController extends Controller
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$search = explode('|', $search);
|
||||
if(isset($search[0]) &&!empty($search[0])){
|
||||
$query->where('province_code',$search[0]);
|
||||
if(isset($search[0]) && !empty($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])){
|
||||
$query->where('city_code',$search[1]);
|
||||
}
|
||||
@@ -123,6 +137,15 @@ class DistrictsController extends Controller
|
||||
// Calculate the current page number
|
||||
$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 response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
|
||||
@@ -99,8 +99,21 @@
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$search = explode('|', $search);
|
||||
if(isset($search[0]) &&!empty($search[0])){
|
||||
$query->where('province_code',$search[0]);
|
||||
if(isset($search[0]) && !empty($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])){
|
||||
$query->where('city_code',$search[1]);
|
||||
@@ -146,6 +159,15 @@
|
||||
// Calculate the current page number
|
||||
$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->district->city->province->name;
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
];
|
||||
|
||||
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;
|
||||
} 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';
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
];
|
||||
|
||||
if ($this->method() === 'PUT') {
|
||||
$rules['code'] = 'required|string|max:6|unique:villages,code,' . $this->id;
|
||||
$rules['code'] = 'required|string|max:13|unique:villages,code,' . $this->id;
|
||||
$rules['name'] = 'required|string|max:2554|unique:villages,name,' . $this->id;
|
||||
} else {
|
||||
$rules['code'] = 'required|string|max:6|unique:villages,code';
|
||||
$rules['code'] = 'required|string|max:13|unique:villages,code';
|
||||
$rules['name'] = 'required|string|max:2554|unique:villages,name';
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
use Mattiverse\Userstamps\Traits\Userstamps;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ return new class extends Migration
|
||||
Schema::create('cities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('province_code')->index();
|
||||
$table->string('code');
|
||||
$table->string('code')->index();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
@@ -15,7 +15,7 @@ return new class extends Migration
|
||||
$table->id();
|
||||
$table->string('province_code')->index();
|
||||
$table->string('city_code')->index();
|
||||
$table->string('code');
|
||||
$table->string('code')->index();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
@@ -16,7 +16,7 @@ return new class extends Migration
|
||||
$table->string('province_code')->index();
|
||||
$table->string('city_code')->index();
|
||||
$table->string('district_code')->index();
|
||||
$table->string('code');
|
||||
$table->string('code')->index();
|
||||
$table->string('name');
|
||||
$table->string('alt_name')->nullable();
|
||||
$table->string('postal_code', 5)->nullable();
|
||||
|
||||
@@ -30632,7 +30632,7 @@ INSERT INTO villages (province_code, city_code, district_code, code, name, posta
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.25', '32.15.25.2006', 'Jomin Timur', 41376);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.25', '32.15.25.2007', 'Jomin Barat', 41376);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.25', '32.15.25.2008', 'Sarimulya', 41376);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.25', '32.15.25.2009', 'Cilkampek Utara', 41376);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.25', '32.15.25.2009', 'Cikampek Utara', 41376);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.26', '32.15.26.1001', 'Karawang Wetan', 41314);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.26', '32.15.26.1002', 'Adiarsa Timur', 41314);
|
||||
INSERT INTO villages (province_code, city_code, district_code, code, name, postal_code) VALUES ('32', '32.15', '32.15.26', '32.15.26.1003', 'Palumbonsari', 41314);
|
||||
|
||||
@@ -38,9 +38,8 @@
|
||||
</label>
|
||||
<button class="search btn btn-sm btn-outline btn-primary">
|
||||
<i class="ki-filled ki-setting-4"> </i>
|
||||
<Filters></Filters>
|
||||
</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.cities.export') }}"> Export to Excel </a>
|
||||
<a class="btn btn-sm btn-primary" href="{{ route('locations.cities.create') }}"> Add City </a>
|
||||
</div>
|
||||
@@ -150,7 +149,7 @@
|
||||
province: {
|
||||
title: 'Province',
|
||||
render: (item, data) => {
|
||||
return data.province.name;
|
||||
return data.province_name;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
||||
@@ -42,9 +42,8 @@
|
||||
</label>
|
||||
<button class="search btn btn-sm btn-outline btn-primary">
|
||||
<i class="ki-filled ki-setting-4"> </i>
|
||||
<Filters></Filters>
|
||||
</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-primary" href="{{ route('locations.districts.create') }}"> Add District </a>
|
||||
</div>
|
||||
@@ -165,7 +164,7 @@
|
||||
province: {
|
||||
title: 'Province',
|
||||
render: (item, data) => {
|
||||
return data.city.province.name;
|
||||
return data.province_name;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
||||
@@ -15,34 +15,10 @@
|
||||
<div class="flex">
|
||||
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
||||
<input placeholder="Search provinces" id="search" type="text" value="">
|
||||
|
||||
</label>
|
||||
</div>
|
||||
<div class="border border-r-gray-200"></div>
|
||||
<div class="flex flex-wrap gap-2.5">
|
||||
<select class="select select-sm w-28">
|
||||
<option value="1">
|
||||
Active
|
||||
</option>
|
||||
<option value="2">
|
||||
Disabled
|
||||
</option>
|
||||
<option value="2">
|
||||
Pending
|
||||
</option>
|
||||
</select>
|
||||
<select class="select select-sm w-28">
|
||||
<option value="desc">
|
||||
Latest
|
||||
</option>
|
||||
<option value="asc">
|
||||
Oldest
|
||||
</option>
|
||||
</select>
|
||||
<button class="btn btn-sm btn-outline btn-primary">
|
||||
<i class="ki-filled ki-setting-4"> </i>
|
||||
<Filters></Filters>
|
||||
</button>
|
||||
<div class="h-[24px] border border-r-gray-200"></div>
|
||||
<a class="btn btn-sm btn-light" href="{{ route('locations.provinces.export') }}"> Export to Excel </a>
|
||||
<a class="btn btn-sm btn-primary" href="{{ route('locations.provinces.create') }}"> Add Province </a>
|
||||
</div>
|
||||
@@ -140,6 +116,9 @@
|
||||
},
|
||||
code: {
|
||||
title: 'Code',
|
||||
render: (item, data) => {
|
||||
return `${data.code.substring(0, 2)}`;
|
||||
},
|
||||
},
|
||||
name: {
|
||||
title: 'Province',
|
||||
|
||||
@@ -47,9 +47,8 @@
|
||||
|
||||
<button class="search btn btn-sm btn-outline btn-primary">
|
||||
<i class="ki-filled ki-setting-4"> </i>
|
||||
<Filters></Filters>
|
||||
</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.villages.export') }}"> Export to Excel </a>
|
||||
<a class="btn btn-sm btn-primary" href="{{ route('locations.villages.create') }}"> Add District </a>
|
||||
</div>
|
||||
@@ -192,7 +191,7 @@
|
||||
province: {
|
||||
title: 'Province',
|
||||
render: (item, data) => {
|
||||
return data.district.city.province.name;
|
||||
return data.province_name;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
||||
Reference in New Issue
Block a user