/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //Faculty
     Faculty::created(function ($faculty) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Faculty', 'reference_id' => $faculty->id]);
     });
     Faculty::updated(function ($faculty) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Faculty', 'reference_id' => $faculty->id]);
     });
     Faculty::deleted(function ($faculty) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Faculty', 'reference_id' => $faculty->id]);
     });
     //Year
     Year::created(function ($year) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Year', 'reference_id' => $year->id]);
     });
     Year::updated(function ($year) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Year', 'reference_id' => $year->id]);
     });
     Year::deleted(function ($year) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_Year', 'reference_id' => $year->id]);
     });
     //Term
     Term::created(function ($term) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_term', 'reference_id' => $term->id]);
     });
     Term::updated(function ($term) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_term', 'reference_id' => $term->id]);
     });
     Term::deleted(function ($term) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_term', 'reference_id' => $term->id]);
     });
     //Department
     Department::created(function ($department) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_department', 'reference_id' => $department->id]);
     });
     Department::updated(function ($department) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_department', 'reference_id' => $department->id]);
     });
     Department::deleted(function ($department) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_department', 'reference_id' => $department->id]);
     });
     //Specailty
     Specialty::created(function ($specialty) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_specialty', 'reference_id' => $specialty->id]);
     });
     Specialty::updated(function ($specialty) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_specialty', 'reference_id' => $specialty->id]);
     });
     Specialty::deleted(function ($specialty) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Academystructure_specialty', 'reference_id' => $specialty->id]);
     });
 }
Beispiel #2
0
 function getspecialtystruct($specialty_id = 0)
 {
     $departments = \Modules\Academystructure\Entities\Department::menu()->where('as.id', $specialty_id)->orderBy('af.id')->orderBy('ay.id')->orderBy('at.id')->get();
     $subjects = \Modules\Subject\Entities\Subject::all();
     foreach ($departments as &$department) {
         $department->subjects = $subjects->filter(function ($subject) use($department) {
             $subject_ids = json_decode($department->subject_ids, TRUE);
             return is_array($subject_ids) and in_array($subject->id, $subject_ids);
         });
     }
     return $departments;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     if (Department::count()) {
         return;
     }
     Year::truncate();
     Department::truncate();
     Faculty::truncate();
     Specialty::truncate();
     Term::truncate();
     $specialties = [['name' => 'العلوم الشرعية', 'type' => 'dep', 'code' => 'G'], ['name' => 'الفقه و علومه', 'type' => 'bac', 'code' => 'O'], ['name' => 'الدراسات الاسلامية', 'type' => 'bac', 'code' => 'I']];
     foreach ($specialties as $s) {
         Specialty::create($s);
     }
     $structure = [['name' => 'كلية العلوم الشرعية', 'years' => [['name' => 'السنة الأولى', 'terms' => [['name' => 'الفصل الأول', 'departments' => [['subject_ids' => json_encode([1, 2, 3, 4, 5, 6]), 'spec_id' => 1], ['subject_ids' => json_encode([1, 2, 3, 4, 5, 6]), 'spec_id' => 2], ['subject_ids' => json_encode([1, 2, 3, 4, 5, 6]), 'spec_id' => 3]]], ['name' => 'الفصل الثاني', 'departments' => [['subject_ids' => json_encode([12, 11, 10, 14, 9, 8]), 'spec_id' => 1], ['subject_ids' => json_encode([12, 11, 10, 14, 9, 8]), 'spec_id' => 2], ['subject_ids' => json_encode([12, 11, 10, 14, 9, 8]), 'spec_id' => 3]]]]], ['name' => 'السنة الثانية', 'terms' => [['name' => 'الفصل الثالث', 'departments' => [['subject_ids' => json_encode([15, 16, 17, 18, 19, 20, 21]), 'spec_id' => 1], ['subject_ids' => json_encode([15, 16, 17, 18, 19, 20, 21]), 'spec_id' => 2], ['subject_ids' => json_encode([15, 16, 17, 18, 19, 20, 21]), 'spec_id' => 3]]], ['name' => 'الفصل الرابع', 'departments' => [['subject_ids' => json_encode([22, 23, 24, 29, 26, 27, 29]), 'spec_id' => 1], ['subject_ids' => json_encode([22, 23, 24, 29, 26, 27, 29]), 'spec_id' => 2], ['subject_ids' => json_encode([22, 23, 24, 29, 26, 27, 29]), 'spec_id' => 3]]]]], ['name' => 'السنة الثالثة', 'terms' => [['name' => 'الفصل الخامس', 'departments' => [['subject_ids' => json_encode([31, 32, 33, 34, 30, 35, 36, 39]), 'spec_id' => 2], ['subject_ids' => json_encode([32, 33, 30, 34, 37, 36, 39]), 'spec_id' => 3], ['subject_ids' => json_encode([33, 37]), 'spec_id' => 1]]], ['name' => 'الفصل السادس', 'departments' => [['subject_ids' => json_encode([41, 42, 43, 44, 45, 46, 47, 52]), 'spec_id' => 2], ['subject_ids' => json_encode([31, 50, 46, 47, 48, 49, 51, 52]), 'spec_id' => 3]]]]], ['name' => 'السنة الرابعة', 'terms' => [['name' => 'الفصل السابع', 'departments' => [['subject_ids' => json_encode([53, 54, 55, 56, 57, 58, 59, 77]), 'spec_id' => 2], ['subject_ids' => json_encode([55, 59, 60, 67, 68, 69, 75, 77]), 'spec_id' => 3]]], ['name' => 'الفصل الثامن', 'departments' => [['subject_ids' => json_encode([58, 61, 62, 63, 64, 65, 76, 78]), 'spec_id' => 2], ['subject_ids' => json_encode([58, 66, 70, 71, 72, 73, 74, 78]), 'spec_id' => 3]]]]]]]];
     $last_1_id = null;
     $last_2_id = null;
     $last_3_id = null;
     foreach ($structure as $f) {
         $faculty = Faculty::create(['name' => $f['name']]);
         foreach ($f['years'] as $y) {
             $year = Year::create(['name' => $y['name'], 'faculty_id' => $faculty->id]);
             foreach ($y['terms'] as $t) {
                 $term = Term::create(['year_id' => $year->id, 'name' => $t['name']]);
                 foreach ($t['departments'] as $d) {
                     $department = Department::create(['spec_id' => $d['spec_id'], 'subject_ids' => $d['subject_ids'], 'parent_id' => ${'last_' . $d['spec_id'] . '_id'}, 'term_id' => $term->id]);
                     if ($d['spec_id'] == 1) {
                         $last_1_id = $department->id;
                     } elseif ($d['spec_id'] == 2) {
                         $last_2_id = $department->id;
                     } elseif ($d['spec_id'] == 3) {
                         $last_3_id = $department->id;
                     }
                 }
             }
         }
     }
 }
 /**
  * @desc Delete term
  * @param Department $department (get department that will update from provider route model binding $router->model)
  * @redirct to department index with term_id
  **/
 public function delete(Department $department)
 {
     $department->delete();
     $term_id = $department->term_id;
     return redirect()->route('as.departments.index', [$term_id]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     echo 'start';
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     if (Student::count()) {
         // return;
     }
     Student::where('id', '!=', 10000)->delete();
     // DB::table('students')->where('id', '!=',10000)->delete();
     // StudentHistory::truncate();
     // StudentClassroomHistory::truncate();
     // StudentClassroomSession::truncate();
     StudentHistory::where('student_id', '!=', 10000)->delete();
     $demo_students = [1268, 1276, 1284, 45, 2772, 2803, 2827];
     $active_semester = 9;
     $summer_semesters = [5, 8];
     $quran_subjects = [8, 6, 21, 28, 39, 52];
     $student_status = ['-3', '-4', '-5', '-6'];
     $student_study_states = [1 => 'active', 2 => 'success', 3 => 'fail', 4 => 'stop', 5 => 'repeat', 6 => 'success'];
     $student_states = [1 => 'active', 2 => 'delayed', 3 => 'withdrawn', 4 => 'fired', 5 => 'discontinuous', 6 => 'graduate'];
     // $all_registrations = DB::connection('old')->table('registration')
     //                                       ->select('reg_specialist', 'reg_nationalid')
     //                                       ->orderBy('reg_id', 'DESC')
     //                                       ->get();
     $all_user_subjects = DB::connection('old')->table('user_subject')->select('us_userid', 'us_subid', 'us_semid', 'us_state', 'us_result', 'us_status')->get();
     $new_departments = $new_department = Department::select('ad.id', 'ad.parent_id', 'ay.id AS ay_id', 'as.code')->join('academystructure_terms as at', 'at.id', '=', 'ad.term_id')->join('academystructure_years as ay', function ($j) {
         $j->on('at.year_id', '=', 'ay.id');
         // ->where('ay.id', '=',$academy['academy_year']);
     })->join('academystructure_specialties as as', function ($j) {
         $j->on('as.id', '=', 'ad.spec_id');
         // ->where('as.code', '=', $dep_sepcialty_code);
     })->from('academystructure_departments as ad')->get()->toArray();
     $all_old_academies = $academy = DB::connection('old')->table('sub_academy')->select('academy.*', 'sub_academy.sub_acad_subid')->join('academy', 'sub_acad_academyid', '=', 'academy_id')->get();
     $all_old_academies = array_map(function ($a) {
         return (array) $a;
     }, $all_old_academies);
     $students = DB::connection('old')->table('users')->select('users.*', 'r.reg_id')->where('user_groupid', 3)->where('user_edu_state', '>=', 1)->where('user_study_state', '>=', 1)->where('user_code', '!=', 'student')->leftJoin('registration as r', 'r.reg_nationalid', '=', 'users.user_nationalid')->groupBy('users.user_id')->get();
     $new_students = [];
     $new_histories = [];
     echo 'will loop' . "\n";
     foreach ($students as $student) {
         $gender = substr($student->user_code, 5, 1) == '1' ? 'm' : 'f';
         $new_student = [];
         $new_student['id'] = $student->user_id;
         $new_student['name'] = $student->user_fullname;
         $new_student['email'] = $student->user_email;
         $new_student['mobile'] = $student->user_phone;
         $new_student['national_id'] = $student->user_nationalid;
         $new_student['gender'] = $gender;
         $new_student['state'] = 'active';
         $new_student['study_state'] = 'first';
         $new_student['academystructure_department_id'] = NULL;
         $new_student['registration_id'] = $student->reg_id ? $student->reg_id : NULL;
         $new_student['username'] = $student->user_code;
         $new_student['password'] = bcrypt($student->user_phone);
         // $new_student['created_at'] 				= new DateTime;
         // $new_student['updated_at'] 				= new DateTime;
         $success = false;
         $semesters = array_unique(array_pluck(array_filter($all_user_subjects, function ($user_subject) use($student) {
             return $user_subject->us_userid == $student->user_id;
         }), 'us_semid'));
         asort($semesters);
         $i = 0;
         foreach ($semesters as $semester) {
             // exit(var_dump($semesters));
             $history = ['student_id' => $student->user_id, 'state' => 'active', 'study_state' => 'stop', 'academycycle_semester_id' => $semester];
             $subjects = array_filter($all_user_subjects, function ($user_subject) use($semester, $student) {
                 return $user_subject->us_semid == $semester && $user_subject->us_userid == $student->user_id;
             });
             $subjects = array_map(function ($item) {
                 return (array) $item;
             }, $subjects);
             $subjects = array_map(function ($item) {
                 return array_only($item, ['us_userid', 'us_state', 'us_result', 'us_status', 'us_subid']);
             }, $subjects);
             if (empty($subjects)) {
                 continue;
             }
             $one_subject = [];
             foreach ($subjects as $subject) {
                 if (isset($one_subject['us_subid']) and $subject['us_subid'] > $one_subject['us_subid']) {
                     $one_subject = $subject;
                 } elseif (empty($one_subject)) {
                     $one_subject = $subject;
                 }
             }
             // exit(var_dump($one_subject));
             // $one_subject = end($subjects);
             $academy_where = ['sub_acad_subid' => $one_subject['us_subid']];
             // if($student->user_yearid==3 && $semester>5)  {
             // if($i>4 && $semester>5)  {
             switch ($student->user_department) {
                 case 1:
                     $academy_department = 'اصول الفقة';
                     break;
                 case 2:
                     $academy_department = 'الدرسات الاسلامية';
                     break;
                 case 3:
                     $academy_department = 'عام';
                     break;
             }
             $academy_where['academy_department'] = $academy_department;
             // }
             if ($semester == $active_semester) {
                 $academy = array_filter($all_old_academies, function ($a) use($student) {
                     return $student->user_academyid == $a['academy_id'];
                 });
             } else {
                 $academy = array_filter($all_old_academies, function ($a) use($one_subject, $academy_where) {
                     return empty($academy_where['academy_department']) or $a['academy_department'] == $academy_where['academy_department'];
                 });
             }
             // var_dump($academy_department);
             $academy = current($academy);
             if (empty($academy)) {
                 continue;
             }
             // $dep_sepcialty_code = 'G';
             // new specialty code
             switch ($student->user_department) {
                 case 1:
                     $dep_sepcialty_code = 'O';
                     break;
                 case 2:
                     $dep_sepcialty_code = 'I';
                     break;
                 case 3:
                     $dep_sepcialty_code = 'G';
                     break;
             }
             // var_dump($dep_sepcialty_code). "\n";
             // if($student->user_de)
             //
             // $dep_sepcialty_code = 'G';
             // if($academy['academy_department']=='اصول الفقة') {
             //    $dep_sepcialty_code = 'O';
             //  } elseif($academy['academy_department']=='الدرسات الاسلامية') {
             //    $dep_sepcialty_code = 'I';
             //  }
             // if($academy['academy_id']<=4) {
             //   $student_nationalid = $student->user_nationalid;
             //   $registration = array_filter($all_registrations, function($reg) use ($student_nationalid){
             //       return $reg->reg_nationalid == $student_nationalid;
             //   });
             //   $registration = (array)array_shift($registration);
             //   if(!empty($registration)) {
             //     switch ($registration['reg_specialist']) {
             //       case 'islam':
             //          $dep_sepcialty_code = 'I';
             //         break;
             //         case 'feqh':
             //         $dep_sepcialty_code = 'O';
             //         break;
             //       default:
             //         $dep_sepcialty_code = 'G';
             //         break;
             //     }
             //   }
             // }
             $new_departments_filtered = array_filter($new_departments, function ($d) use($academy, $dep_sepcialty_code) {
                 return $d['ay_id'] == $academy['academy_year'] && $d['code'] == $dep_sepcialty_code;
             });
             if ($academy['academy_term'] == 2) {
                 $new_department = array_pop($new_departments_filtered);
             } else {
                 $new_department = array_shift($new_departments_filtered);
             }
             $history['academystructure_department_id'] = $new_department['id'];
             if (in_array($one_subject['us_result'], $student_status)) {
                 switch ($one_subject['us_result']) {
                     case "-3":
                         $history['state'] = 'withdrawn';
                         break;
                     case "-4":
                         $history['state'] = 'discontinuous';
                         break;
                     case "-5":
                         $history['state'] = 'fired';
                         break;
                     case "-6":
                         $history['state'] = 'delayed';
                         break;
                 }
             }
             $success_total = count(array_filter($subjects, function ($user_subject) {
                 return $user_subject['us_state'] == 'sucess';
             }));
             $failed_total = count(array_filter($subjects, function ($user_subject) {
                 return $user_subject['us_state'] == 'fail';
             }));
             if (!in_array($semester, array_merge($summer_semesters, [$active_semester]))) {
                 if ($failed_total >= 4) {
                     $history['study_state'] = 'fail';
                 } else {
                     $history['study_state'] = 'success';
                 }
             } elseif (in_array($semester, $summer_semesters) && $failed_total > 0) {
                 $history['study_state'] = 'fail';
             } elseif (in_array($semester, $summer_semesters) && $failed_total == 0) {
                 $history['study_state'] = 'success';
             } elseif ($semester == $active_semester) {
                 $history['study_state'] = 'active';
             }
             if ($one_subject['us_status'] == '-1') {
                 $history['study_state'] = 'repeat';
             }
             if ($one_subject['us_result'] == '-6') {
                 $history['study_state'] = 'stop';
             }
             if ($i == count($semesters) - 1) {
                 $history['study_state'] = $student_study_states[$student->user_study_state];
                 $history['state'] = $student_states[$student->user_edu_state];
             }
             // var_dump($history);
             $new_histories[] = $history;
             $i++;
             // end foreach $semesters as $semester
         }
         if (empty($semesters)) {
             $new_department = array_filter($new_departments, function ($d) {
                 return $d['id'] == 3;
             });
             if (!empty($new_department)) {
                 $new_student['academystructure_department_id'] = current($new_department)['id'];
             }
         } else {
             if (isset($new_department['id'])) {
                 $new_student['academystructure_department_id'] = $new_department['id'];
             }
         }
         $new_student['study_state'] = $student_study_states[$student->user_edu_state];
         $new_student['state'] = $student_states[$student->user_study_state];
         $new_students[] = $new_student;
     }
     // var_dump($new_histories);
     foreach (array_chunk($new_students, 1000) as $chunk) {
         DB::table('students')->insert($chunk);
     }
     foreach (array_chunk($new_histories, 1000) as $chunk) {
         DB::table('student_histories')->insert($chunk);
     }
 }
 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{
     // }
 }
Beispiel #7
0
    public function getGrades()
    {
        $student = Student::select('students.*')->with('registration', 'registration.nationalitycountry')->joinTermName()->findOrFail($this->student_id);
        $registration = $student->registration;
        $semesters = get_student_grades($student->id);
        // $gpa = GPA($semesters);
        $gpa = GPA($semesters);
        $valuation = check_final_valuation($gpa);
        $subject_ids = Department::where('spec_id', $student->specialty_id)->pluck('subject_ids');
        $subject_ids = array_unique(json_decode(str_replace("][", ",", implode("", json_decode($subject_ids, TRUE))), TRUE));
        $success_subjects = StudentSubject::whereIn('subject_id', $subject_ids)->where('state', 'success')->groupBy('subject_id')->where('student_id', $student->id)->pluck('subject_id');
        $studied_subjects = StudentSubject::whereIn('subject_id', $subject_ids)->whereIn('state', ['success', 'fail'])->where('student_id', $student->id)->pluck('subject_id');
        $student_hours = Subject::whereIn("id", $subject_ids)->sum('hour');
        $fail_hours = Subject::whereIn("id", $studied_subjects)->sum('hour');
        $success_hours = Subject::whereIn("id", $success_subjects)->sum('hour');
        /** setup pdf library for arabic content */
        $pdf = $this->preparePdf();
        // test some inline CSS
        $pdf->SetFontSize(22);
        // $html = '<table border="0" width="100%"><tbody><tr><td>كشف درجات الطالب : '.$student->name.'</td></tr></tbody></table>';
        // $pdf->writeHTMLCell(210,20,0,10,$html, 0, 0, false, true, "C");
        if ($student->gender == 'f') {
            $name = $student->registration->first_name . ' بنت ' . $student->registration->second_name . ' بن ' . $student->registration->third_name . ' ' . $student->registration->last_name;
        } else {
            $name = $name = $student->registration->first_name . ' بن ' . $student->registration->second_name . ' بن ' . $student->registration->third_name . ' ' . $student->registration->last_name;
        }
        $html = '<table  cellspacing="0" cellpadding="2" border="1">

      <tbody>
      <tr>
          <td bgcolor="#D9DEE4" align="center">اسم الطالب</td>
          <td align="center" colspan="2">' . $name . '</td>
          <td bgcolor="#D9DEE4" align="center">الجنسية</td>
          <td align="center">' . (!empty($registration->nationalitycountry) ? $registration->nationalitycountry->name : 'غير محدد') . '</td>
          <td bgcolor="#D9DEE4" align="center">تاريخ الميلاد</td>
          <td align="center">' . ($registration ? $registration->birthday : "") . '</td>
        </tr>
        <tr>
          <td bgcolor="#D9DEE4" align="center">التخصص</td>
          <td align="center" colspan="2">' . $student->specialty_name . '</td>
          <td bgcolor="#D9DEE4" align="center">الرقم الجامعي</td>
          <td align="center">' . $student->code . '</td>
          <td bgcolor="#D9DEE4" align="center">الحالة الدراسية</td>
          <td  align="center">' . config('students.state.' . $student->state) . '</td>
        </tr>
      <tr>
          <td bgcolor="#D9DEE4" align="center">الساعات المعتمدة</td>
          <td align="center">' . $student_hours . '</td>
          <td bgcolor="#D9DEE4" align="center">الساعات المكتسبة</td>
          <td align="center">' . $success_hours . '</td>
          <td bgcolor="#D9DEE4" align="center" colspan="2">المعدل التراكمي</td>
          <td align="center">' . $gpa . '</td>
        </tr>
        <tr>

          <td bgcolor="#D9DEE4" align="center">الساعات المسجلة</td>
          <td align="center">' . $fail_hours . '</td>
          <td bgcolor="#D9DEE4" align="center">الساعات المحولة</td>
          <td align="center"> ... </td>
          <td bgcolor="#D9DEE4" align="center" colspan="2">التقدير العام</td>
          <td align="center">' . $valuation . '</td>
        </tr>
      </tbody>
    </table>';
        $pdf->SetFontSize(11);
        $chunks = $semesters->groupBy('year_name');
        $accumulation_points = 0;
        $accumulation_hours = 0;
        $break = 1;
        $j = 1;
        // for  each year
        $all_before_failed_subjects = [];
        $before_hours = 0;
        $before_points = 0;
        foreach ($chunks as $i => $chunk) {
            // for each sem
            foreach ($chunk as $term_index => $term) {
                if ($term->semester_id == Semester()->id) {
                    break;
                }
                // donot calculate quran hour if sem <= 7
                $hours = $term->subjects->sum(function ($s) use($term, &$all_before_failed_subjects, &$before_hours, &$before_points) {
                    if ($s->subject_state == 'fail' && ($term->semester_id >= 7 && $s->is_quran || !$s->is_quran)) {
                        $plus_hours = 0;
                        $plus_points = 0;
                        if (isset($all_before_failed_subjects[$s->subject_id])) {
                            $plus_hours = $all_before_failed_subjects[$s->subject_id]['hours'];
                            $plus_points = $all_before_failed_subjects[$s->subject_id]['points'];
                        }
                        $all_before_failed_subjects[$s->subject_id] = ['hours' => $s->subject_hours + $plus_hours, 'points' => $s->details->points + $plus_points];
                    } else {
                        if (in_array($s->subject_id, array_keys($all_before_failed_subjects)) && $s->subject_state == 'success') {
                            $before_hours += $all_before_failed_subjects[$s->subject_id]['hours'];
                            $before_points += $all_before_failed_subjects[$s->subject_id]['points'];
                            unset($all_before_failed_subjects[$s->subject_id]);
                        }
                    }
                    return $term->semester_id >= 7 && $s->is_quran || !$s->is_quran ? $s->subject_hours : 0;
                });
                $points = number_format($term->subjects->sum(function ($s) use($term) {
                    return $term->semester_id >= 7 && $s->is_quran || !$s->is_quran ? $s->details->points : 0;
                }), 2);
                // var_dump($before_hours, $before_points);
                $accumulation_hours += $hours - $before_hours;
                $accumulation_points += $points - $before_points;
                $before_points = 0;
                $before_hours = 0;
                // first or second sem in page
                if ($break % 2 == 1) {
                    $pdf->writeHTMLCell(180, 20, 15, 50, $html, 0, 0, false, true, "C");
                    $pdf->writeHTMLCell(180, 20, 15, 85, view('students::documents._semesters', ["term" => $term, 'accumulation_hours' => $accumulation_hours, 'accumulation_points' => $accumulation_points])->render(), 0, 0, false, true, "C");
                } else {
                    $pdf->writeHTMLCell(180, 20, 15, 85 * 2 + 10, view('students::documents._semesters', ["term" => $term, 'accumulation_hours' => $accumulation_hours, 'accumulation_points' => $accumulation_points])->render(), 0, 0, false, true, "C");
                }
                if ($break % 2 == 0 && $term->semester_id != Semester()->id - 1) {
                    $pdf->AddPage();
                }
                $break++;
            }
            $j++;
        }
        // exit;
        // dd($all_before_failed_subjects);
        // print signeture
        $pdf->SetFontSize(20);
        $html = '<table border="0" width="100%"><tbody><tr><td>القبول و التسجيل</td></tr></tbody></table>';
        $pdf->writeHTMLCell(40, 5, 15, 245, $html, 0, 0, false, true, "C");
        $html = '<table border="0" width="100%"><tbody><tr><td>المشرف العام على التعليم عن بعد</td></tr>
              <tr><td>مستشار معالي وزير الأوقاف والشؤون الدينية</td></tr></tbody></table>';
        $pdf->writeHTMLCell(130, 5, 80, 245, $html, 0, 0, false, true, "C");
        ob_clean();
        return $pdf;
    }
Beispiel #8
0
 /**
  * Handle the event.
  *
  * @param  RegistrationStepChanged  $event
  * @return void
  */
 public function handle(RegistrationStepChanged $event)
 {
     $registration = $event->registration;
     $semester = semester();
     $finish = $semester ? $semester->finish_at : date('Y-m-d');
     if ($semester->order != 'first') {
         $semester = Semester::where('order', 'first')->where('start_at', '>', $finish)->orderBy('start_at', 'ASC')->first();
     }
     if (empty($semester)) {
         return false;
     }
     $registration->load('step', 'student', 'contactcountry', 'files');
     if ($registration->step->enroll == 1 && !$registration->student) {
         $equation_subjects_ids = RegistrationEquationSubject::whereNotNull('subject_id')->where('status', 'accepted')->whereHas('equation', function ($w) use($registration) {
             $w->where('registration_id', $registration->id);
         })->pluck('subject_id')->toArray();
         $subject_ids = [];
         $i = 0;
         $department = 0;
         while (count(array_diff($subject_ids, $equation_subjects_ids)) == 0) {
             $department = Department::where('spec_id', $registration->academystructure_specialty_id)->where(function ($w) use($department) {
                 $w->orWhere('parent_id', !empty($department->id) ? $department->id : 0);
                 $w->orWhereNull('parent_id');
             })->first();
             $subject_ids = json_decode($department->subject_ids, TRUE);
             $i++;
             if ($i == 20) {
                 break;
             }
         }
         if (empty($subject_ids)) {
             return false;
         }
         $subjects = Subject::whereIn('id', $subject_ids)->get();
         $mobile = ($registration->contactcountry ? $registration->contactcountry->calling_code : "968") . $registration->contact_mobile;
         $data = ['username' => $registration->username, 'username_prefix' => $registration->enroll_code, 'password' => bcrypt($registration->contact_mobile), 'name' => $registration->fullname, 'email' => $registration->contact_email, 'mobile' => $mobile, 'state' => 'active', 'study_state' => 'active', 'national_id' => $registration->national_id, 'gender' => $registration->gender, 'registration_id' => $registration->id, 'academystructure_department_id' => $department->id, 'registration_type_id' => $registration->registration_type_id];
         if ($registration->files) {
             $photo = $registration->files->first(function ($key, $value) {
                 return $key == 'photo';
             });
             if ($photo) {
                 // $data['photo'] = asset($photo->file->url());
             }
         }
         Eloquent::unguard();
         $student = Student::create($data);
         $invoiceItem = FinancialInvoiceItem::where('slug', 'study_fee')->first();
         $study_fee = $registration->study_fee > 0 ? $registration->study_fee : $invoiceItem->amount;
         $total_amount = $subjects->sum(function ($s) use($equation_subjects_ids, $study_fee) {
             $amount = 0;
             if (!in_array($s->id, $equation_subjects_ids)) {
                 $amount = !$s->is_quran ? $s->hour * (int) $study_fee : $s->hour * ((int) $study_fee / 2);
             }
             return $amount;
         });
         if ($student) {
             if ($registration->debit && $invoiceItem) {
                 $invoiceData = ['ref_key' => 'registrations', 'ref_value' => $registration->id, 'student_id' => $student->id, 'amount' => $registration->debit, 'type' => 'credit', 'item_id' => $invoiceItem->id, 'pay_type' => 'epay', 'bank_code' => $registration->reason_code, 'transaction_wid' => $registration->transaction_uuid, 'note' => 'ايصال دفع مصاريف التسجيل.'];
                 FinancialInvoice::create($invoiceData);
                 // create debit invoice
                 $invoiceData = ['ref_key' => 'registrations', 'ref_value' => $registration->id, 'student_id' => $student->id, 'amount' => $total_amount, 'type' => 'debit', 'item_id' => $invoiceItem->id, 'pay_type' => 'epay', 'note' => 'فاتةورة التسجيل.'];
                 FinancialInvoice::create($invoiceData);
             }
             foreach ($subjects as $subject) {
                 $subject_state = in_array($subject->id, $equation_subjects_ids) ? 'equal' : 'study';
                 $subject_payed = in_array($subject->id, $equation_subjects_ids) ? 0 : 1;
                 if (!$registration->debit && $registration->step->make_payment) {
                     $subject_payed = 0;
                 }
                 $data = ['student_id' => $student->id, 'subject_id' => $subject->id, 'semester_id' => $semester->id, 'academystructure_department_id' => $department->id, 'state' => $subject_state, 'note' => '', 'payed' => $subject_payed];
                 $studentSubject = StudentSubject::create($data);
             }
             $historyData = ['student_id' => $student->id, 'state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $semester->id, 'academystructure_department_id' => $department->id];
             StudentHistory::create($historyData);
             $this->createStudentEmail($student, $registration->contact_mobile);
             try {
                 if (!empty($photo)) {
                     $student->photo = $photo;
                     $student->save();
                 }
             } catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) {
             }
         }
         //\Log::info('turn to student '.$response);
     }
 }
 public function getPaymentSubjects()
 {
     $registrar = Auth::guard('api_registration')->user();
     $registrar->load('contactcountry');
     $department = Department::where('spec_id', $registrar->academystructure_specialty_id)->where(function ($w) {
         $w->orWhere('parent_id', 0);
         $w->orWhereNull('parent_id');
     })->first();
     $equation_subjects_ids = RegistrationEquationSubject::whereNotNull('subject_id')->where('status', 'accepted')->whereHas('equation', function ($w) use($registrar) {
         $w->where('registration_id', $registrar->id);
     })->pluck('subject_id')->toArray();
     $subject_ids = $department ? json_decode($department->subject_ids, TRUE) : [];
     $subject_ids = array_diff($subject_ids, $equation_subjects_ids);
     $subjects = Subject::select('name', 'hour', 'is_quran')->whereIn('id', $subject_ids)->get()->toArray();
     $study_fee = FinancialInvoiceItem::where('slug', 'study_fee')->first();
     $study_fee = $registrar->study_fee > 0 ? $registrar->study_fee : $study_fee->amount;
     $total_fee = 0;
     foreach ($subjects as &$subject) {
         $subject['fee'] = !$subject['is_quran'] ? $subject['hour'] * $study_fee : $subject['hour'] * ($study_fee / 2);
         $total_fee += $subject['fee'];
     }
     $data = ['key' => 'registration', 'value' => trim($registrar->username), 'transaction_id' => time(), 'amount' => $total_fee, 'bill_to_forename' => trim($registrar->first_name), 'bill_to_surname' => trim($registrar->last_name), 'bill_to_email' => trim($registrar->contact_email), 'bill_to_address_line1' => 'غير متوفر', 'bill_to_phone' => trim($registrar->contact_mobile), 'bill_to_address_city' => trim($registrar->contactcity->name), 'bill_to_address_country' => 'OM'];
     $payment = new PaymentGateway($data);
     $fields = $payment->getData();
     return response()->json(compact('subjects', 'fields'), 200, [], JSON_NUMERIC_CHECK);
 }
Beispiel #10
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'));
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $student = Student::find($this->student_id);
     $currentSemester = semester();
     $summerSemester = Semester::where('id', '>', $currentSemester->id)->where('order', 'summer')->orderBy('id', 'ASC')->first();
     // Log::info($student->id, $currentSemester->id, $summerSemester->id);
     if ($student && $currentSemester && $summerSemester) {
         $nextSemester = Semester::where('id', '>', $currentSemester->id)->where('order', '!=', 'summer')->orderBy('id', 'ASC')->first();
         if (!$nextSemester) {
             return false;
         }
         $current_department_id = $student->academystructure_department_id;
         if ($currentSemester->order != 'summer') {
             $nextDepartment = Department::where('parent_id', $student->academystructure_department_id)->first();
             if ($nextDepartment) {
                 $student->state = 'active';
                 $student->study_state = 'success';
                 $student->academystructure_department_id = $nextDepartment->id;
             }
         }
         $history = StudentHistory::where('student_id', $student->id)->orderBy('id', 'desc')->where('academycycle_semester_id', $currentSemester->id)->first();
         if ($history) {
             $history->study_state = 'success';
             $history->save();
         }
         if ($student->save()) {
             // get current semester subjects and make them fail or success for current semester
             $subjects = StudentSubject::selectRaw("subsub.id as subject_id,SUM(stugr.value) AS subject_points,student_subjects.state as subject_state,subsub.name AS subject_name, subsub.hour AS subject_hours")->join('subject_subjects AS subsub', function ($join) {
                 $join->on('subsub.id', '=', 'student_subjects.subject_id');
             })->where('student_subjects.student_id', $student->id)->leftJoin('student_grades AS stugr', function ($join) use($currentSemester, $student) {
                 $join->on('stugr.subject_id', '=', 'subsub.id')->where('stugr.semester_id', '=', $currentSemester->id)->where('stugr.student_id', '=', $student->id);
             })->whereIn('state', ['study'])->where('student_subjects.semester_id', '=', $currentSemester->id)->where('student_subjects.student_id', $student->id)->groupBy('subsub.id')->get();
             $failed_subjects_ids = [];
             $passed_subjects_ids = [];
             foreach ($subjects as $subject) {
                 if ($subject->subject_points < 50) {
                     $failed_subjects_ids[] = $subject->subject_id;
                 } elseif ($subject->subject_points >= 50) {
                     $passed_subjects_ids[] = $subject->subject_id;
                 }
             }
             StudentSubject::where('student_id', $student->id)->whereIn('subject_id', $failed_subjects_ids)->update(['state' => 'fail']);
             StudentSubject::where('student_id', $student->id)->whereIn('subject_id', $passed_subjects_ids)->update(['state' => 'success']);
             // end success and fail
             if ($currentSemester->order != 'summer' && $nextDepartment) {
                 $next_subject_ids = json_decode($nextDepartment->subject_ids, TRUE);
                 $equal_subject_ids = EqualSubject::whereHas('order', function ($w) use($student) {
                     $w->where('student_id', $student->id);
                 })->pluck('equal_subject_id')->toArray();
                 $next_subject_study_ids = array_diff($next_subject_ids, $equal_subject_ids);
                 $next_subject_equal_ids = array_intersect($next_subject_ids, $equal_subject_ids);
                 $student->subjects()->attach($next_subject_study_ids, ['semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id, 'state' => 'study']);
                 $student->subjects()->attach($next_subject_equal_ids, ['semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id, 'state' => 'equal']);
                 $data = ['state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id];
                 $student->histories()->create($data);
                 // create invoice for student
                 if ($next_subject_equal_ids) {
                     $item = FinancialInvoiceItem::where('slug', 'study_fee')->first();
                     $subjects_count = Subject::whereIn('id', $next_subject_equal_ids)->where('is_quran', 0)->count();
                     $data = ['student_id' => $student->id, 'type' => 'debit', 'item_id' => $item->id, 'pay_type' => NULL, 'semester_id' => $nextSemester->id, 'amount' => $subjects_count * $item->amount];
                     FinancialInvoice::create($data);
                 }
             }
             // move any failed subjects if less than 3 to summer semester
             $all_failed_subjects = StudentSubject::groupBy('subject_id')->where('state', 'fail')->pluck('subject_id')->toArray();
             $all_passed_subjects = StudentSubject::groupBy('subject_id')->where('state', 'success')->pluck('subject_id')->toArray();
             $failed_subjects = array_diff($all_failed_subjects, $all_passed_subjects);
             if (COUNT($failed_subjects) <= 3) {
                 $summerSemester = Semester::where('id', '>', $currentSemester->id)->where('order', 'summer')->orderBy('id', 'ASC')->first();
                 $student->subjects()->attach($failed_subjects, ['semester_id' => $summerSemester->id, 'academystructure_department_id' => $current_department_id, 'state' => 'study']);
                 $data = ['state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $summerSemester->id, 'academystructure_department_id' => $current_department_id];
                 $student->histories()->create($data);
             }
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // echo 'in';
     if (StudentSubject::count()) {
         // return;
     }
     // $user_subjects = DB::connection('old')
     //   ->table('user_subject')
     //   // ->where('us_userid', 148)
     //   ->get();
     // echo DB::connection('old')->table('user_subject')->count();
     // exit;
     // $this->call("OthersTableSeeder");
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     StudentSubject::where('student_id', '!=', 10000)->delete();
     // StudentSubject::truncate();
     StudentGrade::where('student_id', '!=', 10000)->delete();
     // StudentGrade::truncate();
     $all_user_subjects = DB::connection('old')->table('user_subject')->leftJoin('users', 'users.user_id', '=', 'user_subject.us_userid')->select('users.user_academyid', 'us_state', 'us_subid', 'us_userid', 'us_semid', 'us_result')->get();
     // echo 'got it';
     $new_departments = $new_department = Department::select('ad.id', 'ay.id AS ay_id', 'as.code')->join('academystructure_terms as at', 'at.id', '=', 'ad.term_id')->join('academystructure_years as ay', function ($j) {
         $j->on('at.year_id', '=', 'ay.id');
         // ->where('ay.id', '=',$academy['academy_year']);
     })->join('academystructure_specialties as as', function ($j) {
         $j->on('as.id', '=', 'ad.spec_id');
         // ->where('as.code', '=', $dep_sepcialty_code);
     })->from('academystructure_departments as ad')->get()->toArray();
     $all_old_academies = $academy = DB::connection('old')->table('sub_academy')->select('academy_department', 'academy_year', 'academy_term')->select('academy.*', 'sub_academy.sub_acad_subid')->join('academy', 'sub_acad_academyid', '=', 'academy_id')->get();
     $all_old_academies = array_map(function ($a) {
         return (array) $a;
     }, $all_old_academies);
     $student_subjects = [];
     $student_grades = [];
     // var_dump(count($all_user_subjects));
     foreach ($all_user_subjects as $user_subject) {
         $student_subject = [];
         $student_grade = [];
         $state = $user_subject->us_state == 'sucess' ? 'success' : $user_subject->us_state;
         $state = $state == 'edu' ? 'study' : $state;
         $state = $state == 'equ' ? 'equal' : $state;
         if ($user_subject->us_semid == 9) {
             $academy = array_filter($all_old_academies, function ($a) use($user_subject) {
                 return $user_subject->user_academyid == $a['academy_id'];
             });
         } else {
             $academy = array_filter($all_old_academies, function ($a) use($user_subject) {
                 return $user_subject->us_subid == $a['sub_acad_subid'];
             });
         }
         $academy = current($academy);
         if (empty($academy)) {
             continue;
         }
         $dep_sepcialty_code = 'D';
         if ($academy['academy_department'] == 'اصول الفقة') {
             $dep_sepcialty_code = 'O';
         } elseif ($academy['academy_department'] == 'الدرسات الاسلامية') {
             $dep_sepcialty_code = 'I';
         }
         $new_departments_filtered = array_filter($new_departments, function ($d) use($academy, $dep_sepcialty_code) {
             $exist = $d['ay_id'] == $academy['academy_year'] && $d['code'] == $dep_sepcialty_code;
             if ($exist) {
                 // var_dump($d);
             }
             return $exist;
         });
         if ($academy['academy_term'] == 2) {
             $new_department = array_pop($new_departments_filtered);
         } else {
             $new_department = array_shift($new_departments_filtered);
         }
         $student_subject['student_id'] = $user_subject->us_userid;
         $student_subject['subject_id'] = $user_subject->us_subid;
         $student_subject['semester_id'] = $user_subject->us_semid;
         $student_subject['state'] = $state;
         $student_subject['academystructure_department_id'] = $new_department['id'];
         $student_grade['student_id'] = $user_subject->us_userid;
         $student_grade['subject_id'] = $user_subject->us_subid;
         $student_grade['semester_id'] = $user_subject->us_semid;
         $student_grade['notes'] = "تم جلبها من النظام القديم";
         $student_grade['value'] = $user_subject->us_result;
         $student_grade['created_at'] = new DateTime();
         $student_grade['updated_at'] = new DateTime();
         if ($user_subject->us_result >= 0) {
             $student_grades[] = $student_grade;
         }
         $student_subjects[] = $student_subject;
     }
     foreach (array_chunk($student_subjects, 1000) as $chunk) {
         DB::table('student_subjects')->insert($chunk);
     }
     foreach (array_chunk($student_grades, 1000) as $chunk) {
         DB::table('student_grades')->insert($chunk);
     }
 }
Beispiel #13
0
 /**
  * Handle the event.
  *
  * @param  RegistrationStepChanged  $event
  * @return void
  */
 public function handle($event)
 {
     $registration = $event->registration;
     $extra = $event->extra;
     $registration->load('step', 'step.notes', 'period', 'period.year', 'type', 'speciality');
     $step = $registration->step;
     $password = isset($extra['password']) ? $extra['password'] : '';
     if (empty($step->email_template)) {
         return true;
     }
     $notes = [];
     $comment = '';
     if (isset($extra['comment'])) {
         $comment = $extra['comment'];
     }
     if (isset($extra['notes'])) {
         $notes = $extra['notes'];
     }
     /**
      * get next semester
      */
     $firstday = '';
     $semester = semester();
     //Semester::where('id', semester()->id)->orderBy('academycycle_semesters.id', 'ASC')->first();
     if ($semester) {
         $firstday = $semester->start_at;
     }
     /**
      * get subejcts for registrar
      */
     $hours = 0;
     $fees = 0;
     if ($registration->academystructure_specialty_id) {
         $department = Department::where('spec_id', $registration->academystructure_specialty_id)->where(function ($w) {
             $w->orWhere('parent_id', 0);
             $w->orWhereNull('parent_id');
         })->first();
         $equation_subjects_ids = RegistrationEquationSubject::whereNotNull('subject_id')->where('status', 'accepted')->whereHas('equation', function ($w) use($registration) {
             $w->where('registration_id', $registration->id);
         })->pluck('subject_id')->toArray();
         $subject_ids = $department ? json_decode($department->subject_ids, TRUE) : [];
         $subject_ids = array_diff($subject_ids, $equation_subjects_ids);
         $subjects = Subject::select('name', 'hour')->whereIn('id', $subject_ids)->get();
         $hours = $subjects->sum('hour');
         $study_fee = FinancialInvoiceItem::where('slug', 'study_fee')->first();
         $fees = $hours * ($registration->subject_fee > 0 ? $registration->subject_fee : $study_fee->amount);
     }
     $years = 0;
     if ($registration->academystructure_specialty_id) {
         $years = Specialty::selectRaw('COUNT(adt.id) as terms, COUNT(DISTINCT ady.id) as years')->leftJoin('academystructure_departments as adp', 'adp.spec_id', '=', 'asp.id')->leftJoin('academystructure_terms as adt', 'adt.id', '=', 'adp.term_id')->leftJoin('academystructure_years as ady', 'ady.id', '=', 'adt.year_id')->from('academystructure_specialties as asp')->groupBy('asp.id')->where('asp.id', $registration->academystructure_specialty_id)->first()->years;
     }
     /**
      * end get registrar subjects
      */
     $notes_html = '';
     if ($notes = RegistrationStepNote::whereIn('id', $notes)->pluck('content')->toArray()) {
         $notes_html = '<ul><li>' . implode('</li><li>', $notes) . '</li></ul>';
     }
     /*
      *   calculate first term fees
      */
     /*
      *   end fees calculations
      */
     $template = str_replace(['{reg_portal}', '{debit}', '{name}', '{code}', '{mobile}', '{username}', '{year}', '{nid}', '{shortname}', '{specialty}', '{today}', '{hours}', '{firstday}', '{notes}', '{years}', '{fees}', '{comment}', '{password}'], [env('REGSITRAR_EMAIL_EMAIL_VERIFIED_REDIRECT'), $registration->debit, $registration->fullname, $registration->code, $registration->contact_mobile, $registration->username, $registration->period->year->name, $registration->national_id, $registration->shortname, $registration->speciality ? $registration->speciality->name : '', date('Y-m-d'), $hours, $firstday, $notes_html, $years, $fees, $comment, $password], $step->email_template);
     $data = ['fullname' => $registration->fullname, 'template' => $template, 'verification_token' => $registration->verification_token];
     $view = 'email_step';
     if ($step->verify_email == 1) {
         $view = 'email_verification_token';
     }
     if (!empty($registration)) {
         $payload = ['data' => $data, 'send_to' => $registration->contact_email, 'send_to_name' => $registration->fullname, 'subject' => $registration->step->name, 'view' => $view];
         $job = new SendRegistrationStepChangedEmail($payload);
         $this->dispatch($job);
     }
 }
Beispiel #14
0
 public function index()
 {
     $demo_students = [1268, 1276, 1284, 45, 2772, 2803, 2827];
     $active_semester = 7;
     $summer_semester = 5;
     $quran_subjects = [8, 6, 21, 28, 39, 52];
     $student_status = ['-3', '-4', '-5', '-6'];
     $students = DB::connection('old')->table('users')->take(1)->where('user_groupid', 3)->where('user_id', 45)->get();
     foreach ($students as $student) {
         Eloquent::unguard();
         // var_dump($student->user_code);
         $semesters = DB::connection('old')->table('user_subject')->groupBy('us_semid')->where('us_userid', $student->user_id)->pluck('us_semid');
         $success = false;
         foreach ($semesters as $semester) {
             $history = ['student_id' => $student->user_id, 'state' => 'active', 'study_state' => 'stop', 'academycycle_semester_id' => $semester];
             $subjects = DB::connection('old')->table('user_subject')->select('us_state', 'us_result', 'us_status', 'us_academyid', 'us_subid')->whereNotIn('us_subid', $quran_subjects)->where('us_userid', $student->user_id)->where('us_semid', $semester)->get();
             if (empty($subjects)) {
                 continue;
             }
             $one_subject = $subjects[0];
             $academy_where = ['sub_acad_subid' => $one_subject->us_subid];
             if ($student->user_yearid == 3 && $semester > 5) {
                 switch ($student->user_department) {
                     case 1:
                         $academy_department = 'اصول الفقة';
                         break;
                     case 2:
                         $academy_department = 'الدرسات الاسلامية';
                         break;
                     case 3:
                         $academy_department = 'عام';
                         break;
                 }
                 $academy_where['academy_department'] = $academy_department;
             }
             $academy = DB::connection('old')->table('sub_academy')->select('academy.*')->join('academy', 'sub_acad_academyid', '=', 'academy_id')->where($academy_where)->first();
             // var_dump($academy);
             // continue;
             $dep_sepcialty_code = 'G';
             if ($academy->academy_department == 'اصول الفقة') {
                 $dep_sepcialty_code = 'FQH';
             } elseif ($academy->academy_department == 'الدرسات الاسلامية') {
                 $dep_sepcialty_code = 'IST';
             }
             $term_order = 'ASC';
             if ($academy->academy_term == 2) {
                 $term_order = 'DESC';
             }
             $new_department = Department::select('ad.id')->join('academystructure_terms as at', 'at.id', '=', 'ad.term_id')->join('academystructure_years as ay', function ($j) use($academy) {
                 $j->on('at.year_id', '=', 'ay.id')->where('ay.id', '=', $academy->academy_year);
             })->join('academystructure_specialties as as', function ($j) use($dep_sepcialty_code) {
                 $j->on('as.id', '=', 'ad.spec_id')->where('as.code', '=', $dep_sepcialty_code);
             })->from('academystructure_departments as ad')->orderBy('ad.id', $term_order)->first();
             $history['academystructure_department_id'] = $new_department->id;
             if (in_array($one_subject->us_result, $student_status)) {
                 switch ($one_subject->us_result) {
                     case "-3":
                         $history['state'] = 'withdrawn';
                         break;
                     case "-4":
                         $history['state'] = 'discontinuous';
                         break;
                     case "-5":
                         $history['state'] = 'fired';
                         break;
                     case "-6":
                         $history['state'] = 'delayed';
                         break;
                 }
             }
             $success_total = count(array_filter($subjects, function ($element) {
                 return $element->us_state == 'sucess';
             }));
             $failed_total = count(array_filter($subjects, function ($element) {
                 return $element->us_state == 'fail';
             }));
             if (!in_array($semester, [$summer_semester, $active_semester])) {
                 if ($failed_total >= 4) {
                     $history['study_state'] = 'fail';
                 } else {
                     $history['study_state'] = 'success';
                 }
             } elseif ($semester == $summer_semester && $failed_total > 0) {
                 $history['study_state'] = 'fail';
             } elseif ($semester == $summer_semester && $failed_total == 0) {
                 $history['study_state'] = 'success';
             }
             if ($one_subject->us_status == '-1') {
                 $history['study_state'] = 'repeat';
             }
             var_dump($history);
             // end foreach $semesters as $semester
         }
     }
     //return view('students::index');
 }