fix pbg task add toggle and rab krk dlh

This commit is contained in:
arifal
2025-08-19 13:00:40 +07:00
parent d7e9f44b20
commit 2cbc4172da
17 changed files with 894 additions and 239 deletions

View File

@@ -132,39 +132,48 @@ class PbgTaskController extends Controller
}
$validated = $request->validate([
'name' => 'required|string|max:255',
'owner_name' => 'required|string|max:255',
'name' => 'nullable|string|max:255',
'owner_name' => 'nullable|string|max:255',
'application_type' => ['nullable', new Enum(PbgTaskApplicationTypes::class)],
'condition' => 'required|string|max:255',
'registration_number' => 'required|string|max:255',
'document_number' => 'required|string|max:255',
'condition' => 'nullable|string|max:255',
'registration_number' => 'nullable|string|max:255',
'document_number' => 'nullable|string|max:255',
'status' => ['nullable', new Enum(PbgTaskStatus::class)],
'address' => 'required|string|max:255',
'address' => 'nullable|string|max:255',
'slf_status_name' => 'nullable|string|max:255',
'function_type' => 'required|string|max:255',
'consultation_type' => 'required|string|max:255',
'due_date' => 'nullable|date|after_or_equal:today',
'function_type' => 'nullable|string|max:255',
'consultation_type' => 'nullable|string|max:255',
'due_date' => 'nullable|date',
'is_valid' => 'nullable|boolean',
]);
$statusLabel = $validated['status'] !== null ? PbgTaskStatus::getLabel($validated['status']) : null;
$applicationLabel = $validated['application_type'] !== null ? PbgTaskApplicationTypes::getLabel($validated['application_type']) : null;
$pbg_task->update([
'name' => $validated['name'],
'owner_name' => $validated['owner_name'],
'application_type' => $validated['application_type'],
'application_type_name' => $applicationLabel, // Automatically set application_type_name
'condition' => $validated['condition'],
'registration_number' => $validated['registration_number'],
'document_number' => $validated['document_number'],
'status' => $validated['status'],
'status_name' => $statusLabel, // Automatically set status_name
'address' => $validated['address'],
'slf_status_name' => $validated['slf_status_name'],
'function_type' => $validated['function_type'],
'consultation_type' => $validated['consultation_type'],
'due_date' => $validated['due_date'],
]);
// Prepare update data - only include fields that are actually provided
$updateData = [];
foreach ($validated as $key => $value) {
if ($value !== null || $request->has($key)) {
$updateData[$key] = $value;
}
}
// Handle special cases for labels
if (isset($updateData['status'])) {
$updateData['status_name'] = $statusLabel;
}
if (isset($updateData['application_type'])) {
$updateData['application_type_name'] = $applicationLabel;
}
// Handle is_valid specifically
if ($request->has('is_valid')) {
$updateData['is_valid'] = $validated['is_valid'];
}
$pbg_task->update($updateData);
return response()->json([
"success"=> true,
"message"=> "Data berhasil diubah",