feat: add journal detail tracking, progress reporting, and notebook signing functionality for intern management
This commit is contained in:
@@ -606,5 +606,114 @@ class CareerController extends Controller
|
||||
'message' => 'Staj sorumlusu onayı güncellendi.'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInternJournalDetails(Request $request)
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
return response()->json(['success' => false, 'message' => 'Yetkisiz işlem.'], 403);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'intern_id' => 'required|integer|exists:career_applications,id',
|
||||
]);
|
||||
|
||||
$intern = CareerApplication::findOrFail($request->intern_id);
|
||||
|
||||
// Get all days calculated
|
||||
$days = self::getInternshipDates($intern->internship_start_date, $intern->internship_total_days);
|
||||
|
||||
// Get saved journal entries
|
||||
$savedEntries = $intern->journalEntries()->get()->keyBy('day_number');
|
||||
|
||||
// Prepare entries list matched by day number
|
||||
$entries = [];
|
||||
$filledDaysCount = 0;
|
||||
|
||||
foreach ($days as $d) {
|
||||
$dayNum = $d['day_number'];
|
||||
$entry = $savedEntries->get($dayNum);
|
||||
|
||||
$hasSaved = $entry && trim($entry->content) !== '';
|
||||
if ($hasSaved) {
|
||||
$filledDaysCount++;
|
||||
}
|
||||
|
||||
$entries[] = [
|
||||
'day_number' => $dayNum,
|
||||
'date' => $d['date'],
|
||||
'formatted_date' => $d['formatted_date'],
|
||||
'filled' => $hasSaved,
|
||||
'entry_id' => $entry ? $entry->id : null,
|
||||
'content' => $entry ? $entry->content : null,
|
||||
'is_retroactive' => $entry ? $entry->is_retroactive : false,
|
||||
'supervisor_approved' => $entry ? (bool)$entry->supervisor_approved : false,
|
||||
'supervisor_name' => $entry ? $entry->supervisor_name : null,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'intern' => [
|
||||
'id' => $intern->id,
|
||||
'name' => $intern->name,
|
||||
'email' => $intern->email,
|
||||
'phone' => $intern->phone,
|
||||
'start_date' => $intern->internship_start_date,
|
||||
'end_date' => $intern->internship_end_date,
|
||||
'total_days' => $intern->internship_total_days,
|
||||
'filled_days' => $filledDaysCount,
|
||||
'notebook_supervisor_signed' => (bool)$intern->notebook_supervisor_signed,
|
||||
'notebook_supervisor_name' => $intern->notebook_supervisor_name,
|
||||
'notebook_unit_signed' => (bool)$intern->notebook_unit_signed,
|
||||
'notebook_unit_name' => $intern->notebook_unit_name,
|
||||
'notebook_approved' => (bool)$intern->notebook_approved,
|
||||
],
|
||||
'entries' => $entries,
|
||||
]);
|
||||
}
|
||||
|
||||
public function toggleNotebookSignature(Request $request)
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
return response()->json(['success' => false, 'message' => 'Yetkisiz işlem.'], 403);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'intern_id' => 'required|integer|exists:career_applications,id',
|
||||
'type' => 'required|string|in:supervisor,unit,approved',
|
||||
'signed' => 'required|boolean',
|
||||
'name' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$intern = CareerApplication::findOrFail($request->intern_id);
|
||||
|
||||
$type = $request->type;
|
||||
$signed = $request->signed;
|
||||
$name = $request->name ?: auth()->user()->name;
|
||||
|
||||
if ($type === 'supervisor') {
|
||||
$intern->notebook_supervisor_signed = $signed;
|
||||
$intern->notebook_supervisor_name = $signed ? $name : null;
|
||||
} elseif ($type === 'unit') {
|
||||
$intern->notebook_unit_signed = $signed;
|
||||
$intern->notebook_unit_name = $signed ? $name : null;
|
||||
} elseif ($type === 'approved') {
|
||||
$intern->notebook_approved = $signed;
|
||||
}
|
||||
|
||||
$intern->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Staj defteri onay durumu güncellendi.',
|
||||
'intern' => [
|
||||
'notebook_supervisor_signed' => (bool)$intern->notebook_supervisor_signed,
|
||||
'notebook_supervisor_name' => $intern->notebook_supervisor_name,
|
||||
'notebook_unit_signed' => (bool)$intern->notebook_unit_signed,
|
||||
'notebook_unit_name' => $intern->notebook_unit_name,
|
||||
'notebook_approved' => (bool)$intern->notebook_approved,
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user