Esempio n. 1
0
    public function semester_report($semester_id)
    {
        $statistics = StudentSubject::select(DB::raw('sum(subject_subjects.amount * subject_subjects.hour) as amount,
					 				sum(subject_subjects.hour) as hours,
									academystructure_years.name as year_name ,
									term_id ,
									payed ,
									count(distinct(students.id)) as studentcount'))->where('semester_id', $semester_id)->where('student_subjects.state', 'study')->where('students.state', 'active')->where('students.free_percent', '=', 0)->whereIn('students.study_state', ['active', 'repeat'])->join('students', 'students.id', '=', 'student_subjects.student_id')->join('subject_subjects', 'subject_subjects.id', '=', 'student_subjects.subject_id')->join('academystructure_departments', 'academystructure_departments.id', '=', 'students.academystructure_department_id')->join('academystructure_terms', 'academystructure_departments.term_id', '=', 'academystructure_terms.id')->join('academystructure_years', 'academystructure_terms.year_id', '=', 'academystructure_years.id')->groupBy('academystructure_years.id')->groupBy('payed')->get();
        //return $statistics ;
        $free_study = Student::where('free_percent', '>', 0)->where('state', 'active')->get();
        return view('financials::reports.semester', compact('statistics', 'free_study'));
    }
 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{
     // }
 }
Esempio n. 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'));
 }