perbaikan ekosisitem

This commit is contained in:
2026-05-05 13:38:06 +07:00
parent 154390319a
commit f5913aa049
13 changed files with 260 additions and 31 deletions
@@ -17,9 +17,6 @@ use App\Models\Core\Program;
class ValueBasisDataController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request, string $tabelId): View
{
if (!Gate::any(['super_admin', 'admin'])) {
@@ -68,6 +65,16 @@ class ValueBasisDataController extends Controller
END
) AS \"{$k->kolom}\"
";
} elseif ($k->tipe == 'foreign_key') {
$selects[] = "
MAX(
CASE
WHEN kolom_id = {$k->id}
THEN (select {$k->relasi_kolom_label} from {$k->relasi_tabel} where {$k->relasi_kolom_id} = value_relasi)
ELSE NULL
END
) AS \"{$k->kolom}\"
";
} else {
$selects[] = "
MAX(
@@ -128,9 +135,6 @@ class ValueBasisDataController extends Controller
return view('ekosistem.value-basis-data.index', compact('programList', 'program', 'tabel', 'kolom', 'values', 'ringkasan'));
}
/**
* Show the form for creating a new resource.
*/
public function create(Request $request, string $tabelId): View
{
if (!Gate::any(['super_admin', 'admin'])) {
@@ -158,12 +162,25 @@ class ValueBasisDataController extends Controller
abort(400, 'Program tidak ditemukan.');
}
return view('ekosistem.value-basis-data.add', compact('tabel', 'kolom', 'program'));
$list_relasi = [];
foreach ($kolom as $k) {
if ($k->tipe == 'foreign_key') {
$relasi['kolom_id'] = $k->id;
try {
$options_kolom = DB::table($k->relasi_tabel)->selectRaw($k->relasi_kolom_label . ' as label, ' . $k->relasi_kolom_id . ' as value')->whereNull('deleted_at');
$relasi['options'] = $options_kolom->get();
$relasi['sql'] = $options_kolom->toSql();
} catch (\Throwable $th) {
$relasi['options'] = [];
}
$list_relasi[] = $relasi;
}
}
$list_relasi = collect($list_relasi);
return view('ekosistem.value-basis-data.add', compact('tabel', 'kolom', 'program', 'list_relasi'));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request, string $tabelId): RedirectResponse
{
if (!Gate::any(['super_admin', 'admin'])) {
@@ -216,7 +233,12 @@ class ValueBasisDataController extends Controller
'created_by' => auth()->id(),
'updated_by' => auth()->id(),
];
$values['value_' . $k->tipe] = $validated[$k->kolom] ?? null;
if ($k->tipe == 'foreign_key') {
$values['value_relasi'] = $validated[$k->kolom] ?? null;
} else {
$values['value_' . $k->tipe] = $validated[$k->kolom] ?? null;
}
ValueBasisData::create($values);
}
});
@@ -232,9 +254,6 @@ class ValueBasisDataController extends Controller
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Request $request, string $tabelId, string $id)
{
if (!Gate::any(['super_admin', 'admin'])) {
@@ -275,7 +294,23 @@ class ValueBasisDataController extends Controller
$value_id = $id;
return view('ekosistem.value-basis-data.edit', compact('tabel', 'kolom', 'program', 'values', 'value_id'));
$list_relasi = [];
foreach ($kolom as $k) {
if ($k->tipe == 'foreign_key') {
$relasi['kolom_id'] = $k->id;
try {
$options_kolom = DB::table($k->relasi_tabel)->selectRaw($k->relasi_kolom_label . ' as label, ' . $k->relasi_kolom_id . ' as value')->whereNull('deleted_at');
$relasi['options'] = $options_kolom->get();
$relasi['sql'] = $options_kolom->toSql();
} catch (\Throwable $th) {
$relasi['options'] = [];
}
$list_relasi[] = $relasi;
}
}
$list_relasi = collect($list_relasi);
return view('ekosistem.value-basis-data.edit', compact('tabel', 'kolom', 'program', 'values', 'value_id', 'list_relasi'));
}
/**
@@ -344,11 +379,15 @@ class ValueBasisDataController extends Controller
'created_by' => auth()->id(),
'updated_by' => auth()->id(),
];
$vals['value_' . $k->tipe] = $validated[$k->kolom] ?? null;
if ($k->tipe == 'foreign_key') {
$vals['value_relasi'] = $validated[$k->kolom] ?? null;
} else {
$vals['value_' . $k->tipe] = $validated[$k->kolom] ?? null;
}
ValueBasisData::create($vals);
} else {
$v->update([
'value_' . $k->tipe => $val,
'value_' . ($k->tipe == 'foreign_key' ? 'relasi' : $k->tipe) => $val,
'updated_by' => auth()->id(),
]);
}