/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $gpa = GPA::find($id);
     $gpa->delete();
     return Redirect::to('/gpa')->with("success", "GPA deleted Succesfully.");
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update()
 {
     $rules = ['written' => 'required', 'mcq' => 'required', 'practical' => 'required', 'ca' => 'required'];
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/mark/edit/' . Input::get('id'))->withErrors($validator);
     } else {
         $gparules = GPA::select('gpa', 'grade', 'markfrom')->get();
         $marks = Marks::find(Input::get('id'));
         $marks->written = Input::get('written');
         $marks->mcq = Input::get('mcq');
         $marks->practical = Input::get('practical');
         $marks->ca = Input::get('ca');
         $totalmark = Input::get('written') + Input::get('mcq') + Input::get('practical') + Input::get('ca');
         $marks->total = $totalmark;
         foreach ($gparules as $gpa) {
             if ($totalmark >= $gpa->markfrom) {
                 $marks->grade = $gpa->gpa;
                 $marks->point = $gpa->grade;
                 break;
             }
         }
         $marks->Absent = Input::get('Absent');
         $marks->save();
         return Redirect::to('/mark/list')->with("success", "Marks Update Sucessfully.");
     }
 }
 public function postgenerate()
 {
     $rules = ['class' => 'required', 'exam' => 'required', 'session' => 'required'];
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/result/generate')->withErrors($validator)->withInput();
     } else {
         $subjects = Subject::select('name', 'code', 'type', 'subgroup')->where('class', '=', Input::get('class'))->get();
         $marksubmit = Marks::select('subject')->where('class', '=', Input::get('class'))->where('session', trim(Input::get('session')))->where('exam', Input::get('exam'))->distinct()->get();
         if (count($subjects) == count($marksubmit)) {
             $fourthsubjectCode = "";
             foreach ($subjects as $subject) {
                 if ($subject->type === "Electives") {
                     $fourthsubjectCode = $subject->code;
                 }
             }
             $students = Student::select('regiNo')->where('class', '=', Input::get('class'))->where('session', '=', trim(Input::get('session')))->get();
             if (count($students) != 0) {
                 $gparules = GPA::select('gpa', 'grade', 'markfrom')->get();
                 $foobar = array();
                 foreach ($students as $student) {
                     $marks = Marks::select('subject', 'grade', 'point', 'total')->where('regiNo', '=', $student->regiNo)->where('exam', '=', Input::get('exam'))->get();
                     if (count($marks) != 0) {
                         $totalpoint = 0;
                         $totalmarks = 0;
                         $subcounter = 0;
                         $banglamark = 0;
                         $englishmark = 0;
                         $isfail = false;
                         foreach ($marks as $mark) {
                             if ($this->getSubGroup($subjects, $mark->subject) === "Bangla") {
                                 $banglamark += $mark->total;
                             } else {
                                 if ($this->getSubGroup($subjects, $mark->subject) === "English") {
                                     $englishmark += $mark->total;
                                 } else {
                                     if ($mark->subject === $fourthsubjectCode) {
                                         if ($mark->point >= 2.0) {
                                             $totalmarks += $mark->total;
                                             $totalpoint += $mark->point - 2;
                                         } else {
                                             $totalmarks += $mark->total;
                                         }
                                         $subcounter--;
                                     } else {
                                         $totalmarks += $mark->total;
                                         $totalpoint += $mark->point;
                                     }
                                 }
                             }
                             $subcounter++;
                             if ($mark->subject !== $fourthsubjectCode && $mark->grade === "F") {
                                 $isfail = true;
                             }
                         }
                         if ($banglamark > 0) {
                             $blmarks = floor($banglamark / 2);
                             $totalmarks += $banglamark;
                             $totalpoint += $this->pointCalculator($blmarks, $gparules);
                             $subcounter--;
                         }
                         if ($englishmark > 0) {
                             $enmarks = floor($englishmark / 2);
                             $totalmarks += $englishmark;
                             $totalpoint += $this->pointCalculator($enmarks, $gparules);
                             $subcounter--;
                         }
                         $grandPoint = $totalpoint / $subcounter;
                         if ($isfail) {
                             $grandGrade = $this->gradnGradeCal(0.0, $gparules);
                         } else {
                             $grandGrade = $this->gradnGradeCal($grandPoint, $gparules);
                         }
                         $merit = new MeritList();
                         $merit->class = Input::get('class');
                         $merit->session = trim(Input::get('session'));
                         $merit->exam = Input::get('exam');
                         $merit->regiNo = $student->regiNo;
                         $merit->totalNo = $totalmarks;
                         $merit->point = $grandPoint;
                         $merit->grade = $grandGrade;
                         $merit->save();
                     } else {
                         return Redirect::to('/result/generate')->withInput()->with("noresult", "This examintaion marks not submited yet!!");
                     }
                 }
             } else {
                 return Redirect::to('/result/generate')->withInput()->with("noresult", "There is no students in this class!!");
             }
             return Redirect::to('/result/generate')->with("success", "Result Generate and Publish Successfull.");
         } else {
             return Redirect::to('/result/generate')->withInput()->with("noresult", "All subjects marks not submited yet!!");
         }
     }
 }