Upload Pariwisata dan report pariwisata
This commit is contained in:
117
app/Http/Controllers/Api/TourismController.php
Normal file
117
app/Http/Controllers/Api/TourismController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Tourism;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\TourismRequest;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\TourismResource;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Imports\TourismImport;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TourismController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
info($request);
|
||||
$perPage = $request->input('per_page', 15);
|
||||
$search = $request->input('search', '');
|
||||
|
||||
$query = Tourism::query();
|
||||
$tourisms = $query->paginate($perPage);
|
||||
|
||||
$tourisms->getCollection()->transform(function ($tourisms) {
|
||||
$village = DB::table('villages')->where('village_code', $tourisms->village_code)->first();
|
||||
$tourisms->village_name = $village ? $village->village_name : null;
|
||||
|
||||
$district = DB::table('districts')->where('district_code', $tourisms->district_code)->first();
|
||||
$tourisms->district_name = $district ? $district->district_name : null;
|
||||
|
||||
$business_type = DB::table('business_type')->where('id', $tourisms->business_type_id)->first();
|
||||
$tourisms->business_type = $business_type ? $business_type->business_type : null;
|
||||
return $tourisms;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'data' => TourismResource::collection($tourisms),
|
||||
'meta' => [
|
||||
'total' => $tourisms->total(),
|
||||
'per_page' => $tourisms->perPage(),
|
||||
'current_page' => $tourisms->currentPage(),
|
||||
'last_page' => $tourisms->lastPage(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(TourismRequest $request): Tourism
|
||||
{
|
||||
return Tourism::create($request->validated());
|
||||
}
|
||||
|
||||
/**
|
||||
* Import advertisements from Excel or CSV
|
||||
*/
|
||||
public function importFromFile(Request $request)
|
||||
{
|
||||
//Validasi file
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'required|mimes:xlsx, xls|max:10240'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'message' => 'File validation failed.',
|
||||
'errors' => $validator->errors()
|
||||
], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$file = $request->file('file');
|
||||
Excel::import(new TourismImport, $file);
|
||||
return response()->json([
|
||||
'message' => 'File uploaded and imported successfully!'
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'message' => 'Error during file import.',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Tourism $tourism): Tourism
|
||||
{
|
||||
return $tourism;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(TourismRequest $request, Tourism $tourism): Tourism
|
||||
{
|
||||
$tourism->update($request->validated());
|
||||
|
||||
return $tourism;
|
||||
}
|
||||
|
||||
public function destroy(Tourism $tourism): Response
|
||||
{
|
||||
$tourism->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
118
app/Http/Controllers/Data/TourismController.php
Normal file
118
app/Http/Controllers/Data/TourismController.php
Normal 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",
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -37,9 +37,9 @@ class UmkmController extends Controller
|
||||
$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_scale' => DB::table('business_scale')->orderBy('business_scale')->pluck('business_scale', 'id'),
|
||||
'permit_status' => DB::table('permit_status')->orderBy('permit_status')->pluck('permit_status', 'id'),
|
||||
'business_form' => DB::table('business_form')->orderBy('business_form')->pluck('business_form', 'id')
|
||||
'business_scale_id' => DB::table('business_scale')->orderBy('business_scale')->pluck('business_scale', 'id'),
|
||||
'permit_status_id' => DB::table('permit_status')->orderBy('permit_status')->pluck('permit_status', 'id'),
|
||||
'business_form_id' => DB::table('business_form')->orderBy('business_form')->pluck('business_form', 'id')
|
||||
];
|
||||
|
||||
$fields = $this->getFields();
|
||||
@@ -60,7 +60,7 @@ class UmkmController extends Controller
|
||||
$modelInstance = Umkm::find($id);
|
||||
// Pastikan model ditemukan
|
||||
if (!$modelInstance) {
|
||||
return redirect()->route('umkm.index')->with('error', 'umkm not found');
|
||||
return redirect()->route('umkm.index')->with('error', 'Umkm not found');
|
||||
}
|
||||
|
||||
// Mengambil dan memetakan village_name dan district_name
|
||||
|
||||
21
app/Http/Controllers/Report/ReportTourismController.php
Normal file
21
app/Http/Controllers/Report/ReportTourismController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Report;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BusinessTypeCount;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReportTourismController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listring of the resource
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$businessTypeCounts = BusinessTypeCount::all();
|
||||
info($businessTypeCounts);
|
||||
return view('report.tourisms.index', compact('businessTypeCounts'));
|
||||
}
|
||||
}
|
||||
41
app/Http/Requests/TourismRequest.php
Normal file
41
app/Http/Requests/TourismRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TourismRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'jenis_proyek' => 'string',
|
||||
'nib' => 'string',
|
||||
'business_name' => 'required|string',
|
||||
'status_penanaman_modal' => 'string',
|
||||
'business_form' => 'string',
|
||||
'uraian_resiko_proyek' => 'string',
|
||||
'project_name' => 'required|string',
|
||||
'business_address' => 'required|string',
|
||||
'district_code' => 'required|string',
|
||||
'village_code' => 'required|string',
|
||||
'land_area' => 'required|string',
|
||||
'investment_amount' => 'required|string',
|
||||
'number_of_employee' => 'required|string',
|
||||
'business_type_id' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Http/Resources/TourismResource.php
Normal file
19
app/Http/Resources/TourismResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TourismResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user