Grade Generate
Controller
public function retakeStore(Request $request)
{
$request->validate([
'student_id'=>'required',
'students_id'=>'required',
'name'=>'required',
'number'=>'required',
'semesters_id'=>'required',
'subjects_id'=>'required',
],
[
'students_id.required'=>"The Student ID is not valid",
]
);
$old_data=Results::where('subjects_id','=',$request->subjects_id)->where('student_id','=',$request->student_id)->where('exams_id','=',$request->exams_id)->first();
if($old_data){
$data=$request->all();
$old_data->update($data);
}else{
$data=$request->all();
Results::create($data);
}
// create final grade
if($request->exams_id==1){
$mid=Results::where('subjects_id',$request->subjects_id)->where('students_id',$request->students_id)->where('exams_id','=','2')->first();
$finalgrade=Finalgrades::where('subjects_id',$request->subjects_id)->where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id)->first();
if($finalgrade){
if($mid){
$cr=50;
$finalmark=$mid->number+$request->class_test+$request->assignment+$request->attendance+$request->number;
$finalgrade->obtain_number=$finalmark;
if($finalmark > ($cr*$mid->credit)){
return back()->with('warning',"Maximum number $cr*$mid->credit Please input less then $cr*$mid->credit+1");
}
else{
if($finalmark>= (($cr*$mid->credit*80)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A+";
$finalgrade->grade_point="4.00";
}
elseif((($cr*$mid->credit*79.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*70)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A";
$finalgrade->grade_point="3.75";
}
elseif((($cr*$mid->credit*69.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*65)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "A-";
$finalgrade->grade_point= "3.50";
}
elseif((($cr*$mid->credit*64.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*60)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B+";
$finalgrade->grade_point= "3.25";
}elseif((($cr*$mid->credit*59.99)/100) >= $finalmark && $finalmark>= (($cr*$mid->credit*55)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B";
$finalgrade->grade_point= "300";
}elseif((($cr*$mid->credit*54.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*50)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B-";
$finalgrade->grade_point= "2.75";
}elseif((($cr*$mid->credit*49.99)/100) >= $finalmark && $finalmark >=(($cr*$mid->credit*45)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c+";
$finalgrade->grade_point= "2.50";
}elseif((($cr*$mid->credit*44.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*40)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c";
$finalgrade->grade_point= "2.25";
}elseif((($cr*$mid->credit*39.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*33)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "D";
$finalgrade->grade_point= "2.00";
}
else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "F";
$finalgrade->grade_point= "0.00";
}
}
}else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "I";
$finalgrade->grade_point= "0.00";
$finalgrade->obtain_number=$request->class_test+$request->assignment+$request->attendance+$request->number;
}
}else{
$finalgrade=new Finalgrades;
if($mid){
$cr=50;
$finalmark=$mid->number+$request->class_test+$request->assignment+$request->attendance+$request->number;
$finalgrade->obtain_number=$finalmark;
if($finalmark > ($cr*$mid->credit)){
return back()->with('warning',"Maximum number $cr*$mid->credit Please input less then $cr*$mid->credit+1");
}
else{
if($finalmark>= (($cr*$mid->credit*80)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A+";
$finalgrade->grade_point="4.00";
}
elseif((($cr*$mid->credit*79.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*70)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A";
$finalgrade->grade_point="3.75";
}
elseif((($cr*$mid->credit*69.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*65)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "A-";
$finalgrade->grade_point= "3.50";
}
elseif((($cr*$mid->credit*64.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*60)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B+";
$finalgrade->grade_point= "3.25";
}elseif((($cr*$mid->credit*59.99)/100) >= $finalmark && $finalmark>= (($cr*$mid->credit*55)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B";
$finalgrade->grade_point= "300";
}elseif((($cr*$mid->credit*54.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*50)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B-";
$finalgrade->grade_point= "2.75";
}elseif((($cr*$mid->credit*49.99)/100) >= $finalmark && $finalmark >=(($cr*$mid->credit*45)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c+";
$finalgrade->grade_point= "2.50";
}elseif((($cr*$mid->credit*44.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*40)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c";
$finalgrade->grade_point= "2.25";
}elseif((($cr*$mid->credit*39.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*33)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "D";
$finalgrade->grade_point= "2.00";
}
else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "F";
$finalgrade->grade_point= "0.00";
}
}
}else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "I";
$finalgrade->grade_point= "0.00";
$finalgrade->obtain_number=$request->class_test+$request->assignment+$request->attendance+$request->number;
}
}
$teacher_id=Sentinel::getUser()->email;
$finalgrade->students_id=$request->students_id;
$finalgrade->student_id=$request->student_id;
$finalgrade->faculties_id=$request->faculties_id;
$finalgrade->semesters_id=$request->semesters_id;
$finalgrade->subjects_id=$request->subjects_id;
$finalgrade->sub_code=$request->sub_code;
$finalgrade->sub_name=$request->sub_name;
$finalgrade->credit=$request->credit;
$finalgrade->teacher_id= $teacher_id;
$finalgrade->save();
// Semester Pomossion
$stdfac=Students::find($request->students_id);
$semsub=Subjects::where('faculties_id',$stdfac->faculties_id)->where('semesters_id',$request->semesters_id)->get();
$reultsub=Finalgrades::where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id)->where('promotion','yes')->get();
if(count($semsub)==count($reultsub)){
if(Studentpromotions::where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id+1)->first()){
}else{
$promotion=new Studentpromotions;
$promotion->students_id=$request->students_id;
$promotion->semesters_id=$request->semesters_id+1;
$promotion->save();
}
}
}elseif($request->exams_id==2){
$mid=Results::where('subjects_id',$request->subjects_id)->where('students_id',$request->students_id)->where('exams_id','=','1')->first();
$finalgrade=Finalgrades::where('subjects_id',$request->subjects_id)->where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id)->first();
if($finalgrade){
if($mid){
$cr=50;
$finalmark=$mid->number+$mid->class_test+$mid->assignment+$mid->attendance+$request->number;
$finalgrade->obtain_number=$finalmark;
if($finalmark > ($cr*$mid->credit)){
return back()->with('warning',"Maximum number $cr*$mid->credit Please input less then $cr*$mid->credit+1");
}
else{
if($finalmark>= (($cr*$mid->credit*80)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A+";
$finalgrade->grade_point="4.00";
}
elseif((($cr*$mid->credit*79.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*70)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter="A";
$finalgrade->grade_point="3.75";
}
elseif((($cr*$mid->credit*69.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*65)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "A-";
$finalgrade->grade_point= "3.50";
}
elseif((($cr*$mid->credit*64.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*60)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B+";
$finalgrade->grade_point= "3.25";
}elseif((($cr*$mid->credit*59.99)/100) >= $finalmark && $finalmark>= (($cr*$mid->credit*55)/100) ){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B";
$finalgrade->grade_point= "300";
}elseif((($cr*$mid->credit*54.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*50)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "B-";
$finalgrade->grade_point= "2.75";
}elseif((($cr*$mid->credit*49.99)/100) >= $finalmark && $finalmark >=(($cr*$mid->credit*45)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c+";
$finalgrade->grade_point= "2.50";
}elseif((($cr*$mid->credit*44.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*40)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "c";
$finalgrade->grade_point= "2.25";
}elseif((($cr*$mid->credit*39.99)/100) >= $finalmark && $finalmark >= (($cr*$mid->credit*33)/100)){
$finalgrade->promotion="yes";
$finalgrade->grade_letter= "D";
$finalgrade->grade_point= "2.00";
}
else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "F";
$finalgrade->grade_point= "0.00";
}
}
}else{
$finalgrade->promotion="not";
$finalgrade->grade_letter= "I";
$finalgrade->grade_point= "0.00";
$finalgrade->obtain_number=$request->number;
}
$teacher_id=Sentinel::getUser()->email;
$finalgrade->students_id=$request->students_id;
$finalgrade->student_id=$request->student_id;
$finalgrade->faculties_id=$request->faculties_id;
$finalgrade->semesters_id=$request->semesters_id;
$finalgrade->subjects_id=$request->subjects_id;
$finalgrade->sub_code=$request->sub_code;
$finalgrade->sub_name=$request->sub_name;
$finalgrade->credit=$request->credit;
$finalgrade->teacher_id= $teacher_id;
$finalgrade->save();
// Semester Pomossion
$stdfac=Students::find($request->students_id);
$semsub=Subjects::where('faculties_id',$stdfac->faculties_id)->where('semesters_id',$request->semesters_id)->get();
$reultsub=Finalgrades::where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id)->where('promotion','yes')->get();
if(count($semsub)==count($reultsub)){
if(Studentpromotions::where('students_id',$request->students_id)->where('semesters_id',$request->semesters_id+1)->first()){
}else{
$promotion=new Studentpromotions;
$promotion->students_id=$request->students_id;
$promotion->semesters_id=$request->semesters_id+1;
$promotion->save();
}
}
}
}
return back()->with('success','Result submit successfully');
}
No comments