diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index db4abb9..a159831 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -356,12 +356,19 @@ public function subLocation(Request $request){ public function governmentAgency(Request $request){ if ($request->ajax()) { - $data = GovernmentAgency::all(); + $data = GovernmentAgency::with(['issues'])->get(); return DataTables::of($data) ->addIndexColumn() ->addColumn('issues', function ($data) { - return $data->managementIssues->count(); + $issueCount = $data->issues->count(); + + if($issueCount > 0){ + return $issueCount. ' [Lihat]'; + }else{ + return $issueCount; + } + }) ->addColumn('action', function ($data) { $showUrl = route('dashboard.government.agencies.show', ['id' => encrypt_id($data->id)]); @@ -392,7 +399,7 @@ public function governmentAgency(Request $request){ return $dropdown; }) - ->rawColumns(['action']) + ->rawColumns(['issues', 'action']) ->make(true); } @@ -1722,6 +1729,7 @@ public function issueManagement(Request $request){ $subClassificationParam = $request->input('sub_classification', null); $locationParam = $request->input('location', null); $subLocationParam = $request->input('sub_location', null); + $governmentAgencyParam = $request->input('government_agency', null); if($classificationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('classification_id', decrypt_id($classificationParam))->get(); @@ -1735,6 +1743,12 @@ public function issueManagement(Request $request){ }else if($subLocationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_location_id', decrypt_id($subLocationParam))->get(); + }else if($governmentAgencyParam){ + $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies']) + ->whereHas('governmentAgencies', function ($query) use ($governmentAgencyParam) { + $query->where('issue_managements_government_agencies.government_agency_id', decrypt_id($governmentAgencyParam)); + }) + ->get(); }else{ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->get(); } diff --git a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php index 0f43b03..ca942df 100644 --- a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php +++ b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php @@ -25,13 +25,12 @@ public function create(){ public function store(GovernmentAgencyRequest $request){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $createdGovernmentAgency = GovernmentAgency::create($validatedData); if($createdGovernmentAgency){ - return redirect()->back()->with('success-status', 'Berhasil menambahkan OPD.'); + return redirect()->route('dashboard.government.agencies.index')->with('success-status', 'Berhasil menambahkan OPD.'); }else{ return redirect()->back()->with('failed-status', 'Gagal menambahkan OPD'); } @@ -48,7 +47,6 @@ public function edit($id){ public function update(GovernmentAgencyRequest $request, $id){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $governmentAgency = GovernmentAgency::findOrFail(decrypt_id($id)); diff --git a/app/Http/Controllers/Dashboard/IssueManagementController.php b/app/Http/Controllers/Dashboard/IssueManagementController.php index daea6f2..b9dbce1 100644 --- a/app/Http/Controllers/Dashboard/IssueManagementController.php +++ b/app/Http/Controllers/Dashboard/IssueManagementController.php @@ -23,7 +23,7 @@ public function index(Request $request){ 'sub_classification' => $request->input('sub_classification', null), 'location' => $request->input('location', null), 'sub_location' => $request->input('sub_location', null), - 'agency' => $request->input('agency', null), + 'government_agency' => $request->input('government_agency', null), ]); } diff --git a/app/Http/Requests/ClassificationRequest.php b/app/Http/Requests/ClassificationRequest.php index f8dd5ba..467c265 100644 --- a/app/Http/Requests/ClassificationRequest.php +++ b/app/Http/Requests/ClassificationRequest.php @@ -24,17 +24,26 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + + public function messages(): array { return [ 'name.required' => 'Nama klasifikasi harus diisi.', + 'name.max' => 'Nama klasifikasi tidak boleh lebih dari 100 karakter.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus memiliki nilai aktif atau tidak aktif.', 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', diff --git a/app/Http/Requests/GovernmentAgencyRequest.php b/app/Http/Requests/GovernmentAgencyRequest.php index 5b17fe6..a0cfcea 100644 --- a/app/Http/Requests/GovernmentAgencyRequest.php +++ b/app/Http/Requests/GovernmentAgencyRequest.php @@ -29,4 +29,25 @@ public function rules(): array 'description' => ['nullable'], ]; } + + protected function prepareForValidation() + { + $this->merge([ + 'short_name' => filled($this->short_name) ? $this->short_name : null, + 'location' => filled($this->location) ? $this->location : null, + 'description' => filled($this->description) ? $this->description : null, + ]); + } + + public function messages(): array + { + return [ + 'name.required' => 'Nama OPD harus diisi.', + 'name.max' => 'Nama OPD tidak boleh lebih dari 100 karakter.', + 'short_name.nullable' => 'Singkatan nama boleh kosong jika tidak diperlukan.', + 'short_name.max' => 'Singkatan nama tidak boleh lebih dari 100 karakter.', + 'location.nullable' => 'Lokasi boleh kosong jika tidak diperlukan.', + 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', + ]; + } } diff --git a/app/Http/Requests/LocationRequest.php b/app/Http/Requests/LocationRequest.php index c119be5..3ca14ac 100644 --- a/app/Http/Requests/LocationRequest.php +++ b/app/Http/Requests/LocationRequest.php @@ -23,16 +23,24 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ 'name.required' => 'Nama lokus harus diisi.', + 'name.max' => 'Nama lokus tidak boleh lebih dari 100 karakter.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus memiliki nilai aktif atau tidak aktif.', 'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.', diff --git a/app/Http/Requests/SubClassificationRequest.php b/app/Http/Requests/SubClassificationRequest.php index c661a85..ae05180 100644 --- a/app/Http/Requests/SubClassificationRequest.php +++ b/app/Http/Requests/SubClassificationRequest.php @@ -23,19 +23,27 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'classification_id' => ['required', 'exists:classifications,id'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ - 'name.required' => 'Nama klasifikasi harus diisi.', - 'classification_id.required' => 'Klasifikasi utama harus dipilih.', + 'name.required' => 'Nama sub klasifikasi harus diisi.', + 'name.max' => 'Nama sub klasifikasi tidak boleh lebih dari 100 karakter.', + 'classification_id.required' => 'Klasifikasi harus dipilih.', 'classification_id.exists' => 'Klasifikasi yang dipilih tidak valid.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus bernilai aktif atau tidak aktif.', diff --git a/app/Http/Requests/SubLocationRequest.php b/app/Http/Requests/SubLocationRequest.php index bd8480b..4bff82f 100644 --- a/app/Http/Requests/SubLocationRequest.php +++ b/app/Http/Requests/SubLocationRequest.php @@ -23,18 +23,26 @@ public function authorize(): bool public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['required', 'max:100'], 'location_id' => ['required', 'exists:locations,id'], 'status' => ['required', 'in:0,1'], 'description' => ['nullable'] ]; } + protected function prepareForValidation() + { + $this->merge([ + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages(): array { return [ - 'name.required' => 'Nama lokus harus diisi.', - 'location_id.required' => 'Lokus utama harus dipilih.', + 'name.required' => 'Nama sub lokus harus diisi.', + 'name.max' => 'Nama sub lokus tidak boleh lebih dari 100 karakter.', + 'location_id.required' => 'Lokus harus dipilih.', 'location_id.exists' => 'Lokus yang dipilih tidak valid.', 'status.required' => 'Status harus dipilih.', 'status.in' => 'Status harus bernilai aktif atau tidak aktif.', diff --git a/app/Models/GovernmentAgency.php b/app/Models/GovernmentAgency.php index a2f9dff..1890727 100644 --- a/app/Models/GovernmentAgency.php +++ b/app/Models/GovernmentAgency.php @@ -7,6 +7,7 @@ class GovernmentAgency extends Model { + use SoftDeletes; protected $table = 'government_agencies'; @@ -18,7 +19,7 @@ class GovernmentAgency extends Model 'enhancer_id', ]; - public function managementIssues() + public function issues() { return $this->belongsToMany(IssueManagement::class, 'issue_managements_government_agencies', 'government_agency_id', 'issue_management_id') ->using(IssueManagementGovernmentAgency::class) diff --git a/database/migrations/2025_02_27_014325_create_government_agencies_table.php b/database/migrations/2025_02_27_014325_create_government_agencies_table.php index 122a498..24ec2fd 100644 --- a/database/migrations/2025_02_27_014325_create_government_agencies_table.php +++ b/database/migrations/2025_02_27_014325_create_government_agencies_table.php @@ -20,6 +20,7 @@ public function up(): void $table->unsignedBigInteger('enhancer_id'); $table->foreign('enhancer_id')->references('id')->on('users'); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/seeders/GovernmentAgencySeeder.php b/database/seeders/GovernmentAgencySeeder.php index 7320138..8400db6 100644 --- a/database/seeders/GovernmentAgencySeeder.php +++ b/database/seeders/GovernmentAgencySeeder.php @@ -28,6 +28,7 @@ public function run(): void 'name' => $normalizedAgencyName, // Simpan dengan format aslinya 'created_at' => $agency->created_at, 'updated_at' => $agency->updated_at, + 'deleted_at' => $agency->deleted_at, 'enhancer_id' => $agency->user_id, ]); } diff --git a/resources/views/dashboard/classifications/show.blade.php b/resources/views/dashboard/classifications/show.blade.php index 1c22a5e..7211deb 100644 --- a/resources/views/dashboard/classifications/show.blade.php +++ b/resources/views/dashboard/classifications/show.blade.php @@ -36,7 +36,7 @@ @elseif ($classification->status == 0) Nonaktif @elseif ($classification->status == 1) - Aktif + Aktif @else Tidak Diketahui @endif diff --git a/resources/views/dashboard/government-agencies/create.blade.php b/resources/views/dashboard/government-agencies/create.blade.php index 2953a87..6b48cc1 100644 --- a/resources/views/dashboard/government-agencies/create.blade.php +++ b/resources/views/dashboard/government-agencies/create.blade.php @@ -12,7 +12,7 @@