instrumen koperasi
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Koperasi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Koperasi\PengurusKoperasi;
|
||||
|
||||
class PengurusKoperasiController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = PengurusKoperasi::query();
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where('nama_lengkap', 'like', "%{$search}%")
|
||||
->orWhere('nama_koperasi', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
$perPage = $request->get('per_page', 10);
|
||||
$pengurus = $query->latest()->paginate($perPage);
|
||||
|
||||
$totalPengurus = PengurusKoperasi::count();
|
||||
$totalKoperasi = PengurusKoperasi::distinct('nama_koperasi')->count('nama_koperasi');
|
||||
$totalJabatan = PengurusKoperasi::distinct('posisi_dalam_koperasi')->count('posisi_dalam_koperasi');
|
||||
|
||||
return view('koperasi.profil.index', compact(
|
||||
'pengurus',
|
||||
'totalPengurus',
|
||||
'totalKoperasi',
|
||||
'totalJabatan',
|
||||
));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('koperasi.profil.add');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$pengurus = PengurusKoperasi::findOrFail($id);
|
||||
return view('koperasi.profil.edit', compact('pengurus'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'posisi_dalam_koperasi' => 'required|string|max:255',
|
||||
'tahun_bergabung' => 'nullable|integer',
|
||||
'no_hp' => 'nullable|string|max:20',
|
||||
'alamat_tinggal' => 'nullable|string',
|
||||
'nama_koperasi' => 'required|string|max:255',
|
||||
'jenis_koperasi' => 'required|string|max:255',
|
||||
'jenis_koperasi_lainnya'=> 'nullable|string|max:255',
|
||||
'alamat_koperasi' => 'nullable|string',
|
||||
'skala_operasi' => 'required|string|max:255',
|
||||
'tahun_berdiri' => 'nullable|integer',
|
||||
'jumlah_anggota_awal' => 'nullable|integer',
|
||||
'jumlah_anggota_dewasa' => 'nullable|integer',
|
||||
'jumlah_anggota_anak' => 'nullable|integer',
|
||||
'jumlah_pengurus' => 'nullable|integer',
|
||||
'shu_2025' => 'nullable|numeric',
|
||||
'shu_2024' => 'nullable|numeric',
|
||||
'shu_2023' => 'nullable|numeric',
|
||||
]);
|
||||
|
||||
if ($validatedData['jenis_koperasi'] === 'Lainnya' && !empty($validatedData['jenis_koperasi_lainnya'])) {
|
||||
$validatedData['jenis_koperasi'] = $validatedData['jenis_koperasi_lainnya'];
|
||||
}
|
||||
unset($validatedData['jenis_koperasi_lainnya']);
|
||||
|
||||
$pengurus = PengurusKoperasi::findOrFail($id);
|
||||
$pengurus->update($validatedData);
|
||||
|
||||
return redirect()->route('koperasi.pengurus.index')
|
||||
->with('success', 'Profil Koperasi berhasil diperbarui!');
|
||||
}
|
||||
|
||||
public function survey(Request $request, $id)
|
||||
{
|
||||
$pengurus = PengurusKoperasi::findOrFail($id);
|
||||
$step = $request->query('step', 1);
|
||||
|
||||
if ($step == 1) {
|
||||
return view('koperasi.kelembagaan-aktor.index', compact('pengurus'));
|
||||
} elseif ($step == 2) {
|
||||
return view('koperasi.rantai-nilai-akses-pasar.index', compact('pengurus'));
|
||||
} elseif ($step == 3) {
|
||||
return view('koperasi.sosial-ekonomi.index', compact('pengurus'));
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function surveyStore(Request $request, $id)
|
||||
{
|
||||
$pengurus = PengurusKoperasi::findOrFail($id);
|
||||
$step = $request->query('step', 1);
|
||||
$data = $request->except(['_token', 'pengurus_koperasi_id']);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = json_encode($value);
|
||||
}
|
||||
}
|
||||
|
||||
$pengurus->update($data);
|
||||
|
||||
if ($step == 1) {
|
||||
if ($request->has('agregasi_komoditas') && str_contains($data['agregasi_komoditas'], 'Tidak terlibat')) {
|
||||
return redirect()->route('koperasi.pengurus.survey', ['id' => $id, 'step' => 3])
|
||||
->with('success', 'Data Kelembagaan tersimpan! (Melewati Rantai Nilai)');
|
||||
}
|
||||
|
||||
return redirect()->route('koperasi.pengurus.survey', ['id' => $id, 'step' => 2])
|
||||
->with('success', 'Data Kelembagaan berhasil disimpan!');
|
||||
}
|
||||
|
||||
if ($step == 2) {
|
||||
return redirect()->route('koperasi.pengurus.survey', ['id' => $id, 'step' => 3])
|
||||
->with('success', 'Data Rantai Nilai berhasil disimpan!');
|
||||
}
|
||||
|
||||
if ($step == 3) {
|
||||
return redirect()->route('koperasi.pengurus.index')
|
||||
->with('success', 'Seluruh data survei berhasil diselesaikan dan disimpan!');
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'posisi_dalam_koperasi' => 'required|string|max:255',
|
||||
'tahun_bergabung' => 'nullable|integer',
|
||||
'no_hp' => 'nullable|string|max:20',
|
||||
'alamat_tinggal' => 'nullable|string',
|
||||
'nama_koperasi' => 'required|string|max:255',
|
||||
'jenis_koperasi' => 'required|string|max:255',
|
||||
'jenis_koperasi_lainnya'=> 'nullable|string|max:255',
|
||||
'alamat_koperasi' => 'nullable|string',
|
||||
'skala_operasi' => 'required|string|max:255',
|
||||
'tahun_berdiri' => 'nullable|integer',
|
||||
'jumlah_anggota_awal' => 'nullable|integer',
|
||||
'jumlah_anggota_dewasa' => 'nullable|integer',
|
||||
'jumlah_anggota_anak' => 'nullable|integer',
|
||||
'jumlah_pengurus' => 'nullable|integer',
|
||||
'shu_2025' => 'nullable|numeric',
|
||||
'shu_2024' => 'nullable|numeric',
|
||||
'shu_2023' => 'nullable|numeric',
|
||||
]);
|
||||
|
||||
if ($validatedData['jenis_koperasi'] === 'Lainnya' && !empty($validatedData['jenis_koperasi_lainnya'])) {
|
||||
$validatedData['jenis_koperasi'] = $validatedData['jenis_koperasi_lainnya'];
|
||||
}
|
||||
unset($validatedData['jenis_koperasi_lainnya']);
|
||||
|
||||
$pengurus = PengurusKoperasi::create($validatedData);
|
||||
|
||||
return redirect()->route('koperasi.pengurus.index')
|
||||
->with('success', 'Profil Koperasi berhasil ditambahkan! Silakan klik tombol hijau untuk mulai survei.');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$pengurus = PengurusKoperasi::findOrFail($id);
|
||||
$pengurus->delete();
|
||||
|
||||
return redirect()->route('koperasi.pengurus.index')
|
||||
->with('success', 'Data pengurus koperasi berhasil dihapus!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user