public function approve($order_id)
 {
     $order = OrderChangeDepartment::findOrFail($order_id);
     $student_id = $order->student_id;
     $depid = $order->to;
     $current_dep = $order->from;
     $StudentHistory = StudentHistory::where('student_id', $student_id)->where('academycycle_semester_id', semester()->id)->update(['academystructure_department_id' => $depid]);
     $student = Student::with('subjects')->where('id', $student_id)->first();
     $student->academystructure_department_id = $depid;
     $student->save();
     $department = Department::findOrFail($current_dep);
     $current_subject_ids = json_decode($department->subject_ids, TRUE);
     $current_payed_subject_ids = StudentSubject::select('subject_id')->where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->where('payed', 1)->get();
     $cuttent_invoice_amount = 0;
     if ($current_payed_subject_ids->count() > 0) {
         $cuttent_invoice_amount = Subject::select(DB::raw('sum(hour*amount) as total_amount'))->whereIn('id', $current_payed_subject_ids)->first();
     }
     $new_department = Department::findOrFail($depid);
     $new_subject_ids = json_decode($new_department->subject_ids, TRUE);
     //if($current_dep == 8 or $current_dep == 13 or $current_dep =14 ){
     //update department subjects
     StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->whereIn('subject_id', $current_subject_ids)->update(['state' => 'drop']);
     foreach ($new_subject_ids as $new_subject_id) {
         $new_student_subject = new StudentSubject();
         $new_student_subject->subject_id = $new_subject_id;
         $new_student_subject->student_id = $student_id;
         $new_student_subject->semester_id = semester()->id;
         $new_student_subject->academystructure_department_id = $depid;
         $new_student_subject->state = 'study';
         $new_student_subject->save();
     }
     if ($current_payed_subject_ids->count() > 0) {
         $new_payed_subject_ids = StudentSubject::select('subject_id')->where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->get();
         $new_invoice_amount = Subject::select(DB::raw('sum(hour*amount) as total_amount'))->whereIn('id', $new_payed_subject_ids)->first();
         if ($new_invoice_amount < $cuttent_invoice_amount) {
             StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['payed' => 1]);
             $invoiceData = ['ref_key' => 'Order_Change_AC_Departments', 'ref_value' => $order_id, 'student_id' => $student_id, 'amount' => $cuttent_invoice_amount->total_amount - $new_invoice_amount->total_amount, 'type' => 'credit', 'semester_id' => semester()->id, 'note' => 'فرق تغيير التخصص'];
             FinancialInvoice::create($invoiceData);
         }
         if ($new_invoice_amount > $cuttent_invoice_amount) {
             StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['payed' => 1]);
         }
         if ($new_invoice_amount > $cuttent_invoice_amount) {
             StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->where('subject_id', '!=', 35)->update(['payed' => 1]);
         }
     }
     //updtae remain subjects (not in dep id)  to be in same depid
     StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['academystructure_department_id' => $depid]);
     $order->state = 1;
     $order->save();
     $msg = 'تم تغيير التخصص ';
     return redirect()->route('orders.change.department.index')->with('success', $msg);
     //  }else{
     // }
 }
Пример #2
0
    public function index($student_id = 0, Request $request)
    {
        $semester_id = request('semester_id', semester()->id);
        $student = Student::with(['subjects' => function ($query) use($semester_id, $request) {
            if ($request->has('name')) {
                $query->where('name', 'LIKE', '%' . request('name') . '%');
            }
            if ($request->has('state')) {
                $query->where('state', request('state'));
            }
            $query->wherePivot('semester_id', $semester_id);
        }])->find($student_id);
        $semesters = Semester::select(\DB::raw('CONCAT(academycycle_semesters.name , "-", academycycle_years.name) as name ,
					 academycycle_semesters.id as id'))->join('academycycle_years', 'academycycle_years.id', '=', 'academycycle_semesters.academycycle_year_id')->pluck('name', 'id')->toArray();
        return view('students::subjects.index', compact('student', 'semesters'));
    }
Пример #3
0
 public function show($student_id)
 {
     $student = Student::with(['classrooms', 'registration', 'registration.type', 'department', 'subjects'])->select('students.*')->joinTermName()->findOrFail($student_id);
     $grades = StudentGrade::with('semester', 'subject')->inCurrentSemester()->where('student_id', $student->id)->get();
     $registration = $student->registration;
     //$study_plan = getspecialtystruct(1);
     if ($student->department->spec_id) {
         $study_plan = getspecialtystruct($student->department->spec_id);
     } else {
         $study_plan = getspecialtystruct(2);
     }
     //dd($study_plan);
     $departments = Department::select(\DB::raw('GROUP_CONCAT(subject_ids) as sid , id as name'))->where('spec_id', 1)->get()->toArray();
     $departments_subjects;
     foreach ($departments as $key => &$aa) {
         $a = implode(',', array_unique(array_merge(json_decode(str_replace('],[', ',', $aa['sid']), TRUE))));
         $departments_subjects = explode(',', $a);
     }
     $student_subjects = StudentSubject::select(\DB::raw('GROUP_CONCAT(subject_id) as sid'))->where('student_id', $student_id)->where('state', 'success')->get()->toArray();
     $student_subject_ids = explode(',', $student_subjects[0]['sid']);
     $result = array_diff($departments_subjects, $student_subject_ids);
     $complete_deplome_subjects = empty($result);
     return view('students::students.show', compact('student', 'registration', 'grades', 'study_plan', 'study_subject', 'state_complite_sub', 'complete_deplome_subjects'));
 }
Пример #4
0
 public function unloadexam($subject_id, $exam_type, $msg = 0)
 {
     $exam_ids = Exam::select('id')->where('subject_id', $subject_id)->where('type', $exam_type)->get()->toArray();
     $statistics = Student::with(['examresults' => function ($q) use($exam_ids) {
         $q->whereIn('exam_id', $exam_ids);
         $q->where('filename', '');
     }])->whereHas('examresults', function ($q) use($exam_ids) {
         $q->whereIn('exam_id', $exam_ids);
         $q->where('filename', '');
     });
     if ($msg == 1) {
         $statistics = $statistics->pluck('username')->toArray();
         return redirect()->route('students.messages.create', compact('statistics'));
     }
     $statistics = $statistics->get();
     return view('exams::reports.unloadexam', compact('statistics', 'subject_id', 'exam_type'));
 }
Пример #5
0
 private function prepQuery($input = [])
 {
     // dd(substr($input['code'],0,3));
     $input['username'] = (!empty($input['code']) and substr($input['code'], 0, 3) != 'e20' and strlen($input['code']) >= 5) ? strtoupper(substr($input['code'], -5, 5)) : (!empty($input['code']) ? $input['code'] : null);
     if (empty($input['username'])) {
         unset($input['username']);
     }
     unset($input['code']);
     $students = Student::with('attendances')->select('students.*', 'academystructure_departments.term_id', 'academystructure_departments.spec_id', 'registrations.nationality_country_id', \DB::raw('GROUP_CONCAT(academystructure_departments.spec_id, "") as sps'), 'registrations.contact_country_id', 'registrations.nationality_city_id')->leftJoin('academystructure_departments', 'academystructure_departments.id', '=', 'students.academystructure_department_id')->leftJoin('registrations', 'registrations.id', '=', 'students.registration_id')->orderBy('students.id', 'desc')->where('state', 'active');
     $filters = ['username', 'email', 'name', 'state', 'mobile', 'national_id', 'gender', 'state', 'study_state'];
     if (!empty($input)) {
         foreach ($filters as $filter) {
             if (!empty($input[$filter])) {
                 $students->where("students." . $filter, 'LIKE', "%" . $input[$filter] . "%");
             }
         }
     }
     /*
     		if(!empty($input)) {
     			foreach ($filters as $filter) {
     				if(!empty($input[$filter]) && !in_array($filter, ['name'])) {
     					$students->where("students.".$filter, 'LIKE',"%".$input[$filter]."%");
     				} elseif($filter=='name' && !empty($input['name'])) {
     					$name_array = explode(' ',$input[$filter]);
     					$students->where(function($query) use ($name_array) {
     						foreach($name_array as $name_chunk)
     						$query->orWhere('students.name', 'LIKE', '%'.$name_chunk.'%');
     					});
     				}
     			}
     		}
     */
     if (request('year_term')) {
         $students->where('academystructure_departments.term_id', request('year_term'));
     }
     if (request('spec_id')) {
         $students->where('academystructure_departments.spec_id', request('spec_id'));
     }
     if (request('nationality_country_id')) {
         $students->where('registrations.nationality_country_id', request('nationality_country_id'));
     }
     if (request('contact_country_id')) {
         $students->where('registrations.contact_country_id', request('contact_country_id'));
     }
     if (request('nationality_city_id')) {
         $students->where('registrations.nationality_city_id', request('nationality_city_id'));
     }
     $students = $students->joinTermName()->groupBy('students.id');
     return $students;
 }
Пример #6
0
 public function students($classroom_id, $student_id = null)
 {
     $classroom = Classroom::findOrFail($classroom_id);
     //->has('students', '<=', 'classrooms.attendees_limit')
     $classrooms = Classroom::select(DB::raw('CONCAT(hour , "-", code , "-" , day) as code , id'))->where('subject_subject_id', $classroom->subject_subject_id)->whereIn('classrooms.gender', [$classroom->gender, 'b'])->inCurrentSemester()->pluck('code', 'id')->toArray();
     $days = $this->days;
     foreach ($classrooms as $key => $value) {
         $day = substr($value, -1);
         $new_day = $days[$day];
         $classrooms[$key] = substr_replace($classrooms[$key], $new_day, -1);
     }
     $subjects = Subject::where('id', $classroom->subject_subject_id)->first()->name;
     $students = Student::with(['classrooms' => function ($query) use($classroom_id, $student_id) {
         return $query->where('classrooms.id', $classroom_id);
     }]);
     if (isset($student_id)) {
         $students = $students->whereHas('classrooms', function ($query) use($classroom_id, $student_id) {
             $query->where('classrooms.id', $classroom_id)->where('students.username', $student_id);
         })->get();
     } else {
         $students = $students->whereHas('classrooms', function ($query) use($classroom_id, $student_id) {
             $query->where('classrooms.id', $classroom_id);
         })->get();
     }
     // dd($classrooms);
     return view('classrooms::classrooms.students', compact('students', 'classroom', 'classrooms', 'subjects'));
 }