Upload Pariwisata dan report pariwisata

This commit is contained in:
2025-02-17 23:58:31 +07:00
parent 8c236c460d
commit ecc243d1cc
27 changed files with 1258 additions and 5 deletions

View File

@@ -0,0 +1,118 @@
<?php
namespace App\Http\Controllers\Data;
use App\Http\Controllers\Controller;
use App\Models\Tourism;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class TourismController extends Controller
{
/**
* Display a listing of the resource
*/
public function index()
{
return view('data.tourisms.index');
}
/**
* show the form for creating a new rsource.
*/
public function bulkCreate()
{
return view('data.tourisms.form-upload');
}
/**
* Show th form for creating a new resource
*/
public function create()
{
$title = 'Pariwisata';
$subtitle = 'Create Data';
// Mengambil data untuk dropdown
$dropdownOptions = [
'village_name' => DB::table('villages')->orderBy('village_name')->pluck('village_name', 'village_code'),
'district_name' => DB::table('districts')->orderBy('district_name')->pluck('district_name', 'district_code'),
'business_type_id' => DB::table('business_type')->orderBy('business_type')->pluck('business_type', 'id'),
];
$fields = $this->getFields();
$fieldTypes = $this->getFieldTypes();
$apiUrl = url('/api/tourisms');
return view('data.tourisms.form', compact('title', 'subtitle', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions'));
}
/**
* show the form for editing the specified resource.
*/
public function edit($id)
{
$title = 'Pariwisata';
$subtitle = 'Create Data';
$modelInstance = Tourism::find($id);
// Pastikan model ditemukan
if (!$modelInstance) {
return redirect()->route('tourisms.index') ->with('error', 'Pariwisata tidak ditemukan');
}
// Mengambil dan memetakan village_name dan district_name
$village = DB::table('villages')->where('village_code', $modelInstance->village_code)->first();
$modelInstance->village_name = $village ? $village->village_name : null;
$district = DB::table('districts')->where('district_code', $modelInstance->district_code)->first();
$modelInstance->district_name = $district ? $district->district_name : null;
$business_type = DB::table('business_type')->where('id', $modelInstance->business_type_id)->first();
$modelInstance->business_scale_id = $business_type ? $business_type->id : null;
$dropdownOptions = [
'village_name' => DB::table('villages')->orderBy('village_name')->pluck('village_name', 'village_code'),
'district_name' => DB::table('districts')->orderBy('district_name')->pluck('district_name', 'district_code'),
'business_type_id' => DB::table('business_type')->orderBy('business_type')->pluck('business_type', 'id'),
];
$fields = $this->getFields();
$fieldTypes = $this->getFieldTypes();
$apiUrl = url('/api/tourisms');
return view('data.tourisms.form', compact('title', 'subtitle', 'modelInstance', 'fields', 'fieldTypes', 'apiUrl', 'dropdownOptions'));
}
private function getFields()
{
return [
"business_name" => "Nama Usaha",
"project_name" => "Nama Project",
"business_address" => "Alamat Usaha",
"district_name" => "Kecamatan",
"village_name" => "Desa",
"land_area" => "Luas Tanah",
"investment_amount" => "Jumlah Investasi",
"number_of_employee" => "TKI",
"business_type_id" => "Jenis Usaha",
];
}
private function getFieldTypes()
{
return [
"business_name" => "text",
"project_name" => "text",
"business_address" => "textarea",
"district_name" => "combobox",
"village_name" => "combobox",
"land_area" => "text",
"investment_amount" => "text",
"number_of_employee" => "text",
"business_type_id" => "select",
];
}
}