public function addStudentAttendance() { $inputs = Input::all(); for ($i = 0; $i < $inputs['totalStudents']; $i++) { $isAttendanceExists = Attendance::getDaysAttendanceForStudent($inputs['student_' . $i], $inputs['batch_' . $i], $inputs['attendanceDate_' . $i]); if ($isAttendanceExists) { $isAttendanceExists->status = $inputs['attendance_for_user' . $i]; $isAttendanceExists->save(); } else { $attendanceData = new Attendance(); $attendanceData->attendance_date = $inputs['attendanceDate_' . $i]; $attendanceData->batch_id = $inputs['batch_' . $i]; $attendanceData->student_id = $inputs['student_' . $i]; $attendanceData->status = $inputs['attendance_for_user' . $i]; $attendanceData->save(); } } return Response::json(array("status" => "success")); }
static function getAttendanceTable($batchId) { $studentsInBatch = StudentClasses::with('Students')->where('batch_id', '=', $batchId)->get(array('student_id', 'enrollment_start_date', 'enrollment_end_date')); $studentBatchDates = array(); $i = 0; foreach ($studentsInBatch as $student) { $studentBatchDates[$i]['Student'] = $student; $studentBatchDates[$i]['Attendance'] = BatchSchedule::where("batch_id", '=', $batchId)->where('schedule_date', '>=', $student->enrollment_start_date)->where('schedule_date', '<=', $student->enrollment_end_date)->get(); $batchdates = BatchSchedule::where("batch_id", '=', $batchId)->where('schedule_date', '>=', $student->enrollment_start_date)->where('schedule_date', '<=', $student->enrollment_end_date)->get(); $attendanceIncrement = 0; $presentDays = 0; $eaDays = 0; $absentDays = 0; $totalSessions = 0; foreach ($batchdates as $date) { /* echo "<pre>"; print_r($student); echo "</pre>"; */ $attendance = Attendance::getDaysAttendanceForStudent($student->student_id, $batchId, $date->schedule_date); $studentBatchDates[$i]['Attendance'][$attendanceIncrement]['attendStat'] = $attendance; $studentBatchDates[$i]['Attendance'][$attendanceIncrement]['attenddate'] = $date->schedule_date; if ($attendance) { if ($attendance->status == "P") { $presentDays++; } if ($attendance->status == "EA") { $eaDays++; } if ($attendance->status == "A") { $absentDays++; } } $attendanceIncrement++; $totalSessions++; } $studentBatchDates[$i]['statistics']['present'] = $presentDays; $studentBatchDates[$i]['statistics']['absent'] = $absentDays; $studentBatchDates[$i]['statistics']['ea'] = $eaDays; $studentBatchDates[$i]['statistics']['totalSessions'] = $totalSessions; /* echo "<pre>"; print_r(DB::getQueryLog()); print_r($studentBatchDates[$i]); echo "</pre>"; */ $i++; } /* echo "<pre>"; print_r($studentBatchDates); echo "</pre>"; exit(); */ return $studentBatchDates; }