Пример #1
0
 public function index()
 {
     if ($subjects = Cache::get('student_' . $this->student->id . '_api_subjects')) {
         return response()->json($subjects, 200, [], JSON_NUMERIC_CHECK);
     }
     $subjects = Subject::select('subject_subjects.id', 'subject_subjects.name', 'subject_subjects.is_quran', 'subject_subjects.hour', 'qp.start as quranPageStart', 'qp.part as partTitle', 'qp.end as quranPageEnd')->leftJoin('quran_pages as qp', 'qp.subject_id', '=', 'subject_subjects.id')->whereHas('students', function ($query) {
         $query->where('students.id', $this->student->id)->whereIn('student_subjects.state', ['study', 'fail', 'success'])->where('semester_id', $this->semester->id);
     })->with(['lessons' => function ($query) {
         $query->orderBy('lesson_order', 'ASC')->select('name', 'type', 'id', 'subject_subject_id', 'lesson_order');
     }, 'lessons.elements' => function ($query) {
         $query->select('id', 'value', 'type', 'title', 'subject_lesson_id', 'file_file_name', 'file_file_size', 'file_content_type', 'file_updated_at');
     }])->get();
     Cache::put('student_' . $this->student->id . '_api_subjects', $subjects, 600);
     return response()->json($subjects, 200, [], JSON_NUMERIC_CHECK);
 }
Пример #2
0
    public function index(Request $request)
    {
        $subjects = Subject::select('*');
        if (request('QB_subject')) {
            $subjects->where('id', request('QB_subject'));
        }
        if (request('QB_year_term')) {
            $subjects->whereIn('id', explode(',', request('QB_year_term')));
        }
        $subjects = $subjects->paginate(20);
        $year_term = year::join('academystructure_terms', 'academystructure_years.id', '=', 'academystructure_terms.year_id')->join('academystructure_departments', 'academystructure_terms.id', '=', 'academystructure_departments.term_id')->select(\DB::raw('CONCAT(academystructure_years.name, "-", academystructure_terms.name) as name,
													GROUP_CONCAT(DISTINCT(academystructure_departments.subject_ids)) as sid'))->groupBy('academystructure_terms.name', 'academystructure_years.name')->orderBy('academystructure_terms.id', 'desc')->get()->toArray();
        $year_term_options;
        foreach ($year_term as $key => &$aa) {
            $a = implode(',', array_unique(array_merge(json_decode(str_replace('],[', ',', $aa['sid']), TRUE))));
            $year_term_options[$a] = $aa['name'];
        }
        $subject_list = Subject::pluck('name', 'id')->toArray();
        return view('subject::subjects.index', compact('subjects', 'subject_list', 'year_term_options'));
    }
Пример #3
0
 public function subjectexam(Request $request)
 {
     $subjects = Subject::lists('name', 'id')->toArray();
     $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();
     $year_term = Year::join('academystructure_terms', 'academystructure_years.id', '=', 'academystructure_terms.year_id')->join('academystructure_departments', 'academystructure_terms.id', '=', 'academystructure_departments.term_id')->select(\DB::raw('CONCAT(academystructure_years.name, "-", academystructure_terms.name) as name,
                                     GROUP_CONCAT(DISTINCT(academystructure_departments.subject_ids)) as sid'))->groupBy('academystructure_terms.name', 'academystructure_years.name')->get()->toArray();
     $year_term_options;
     foreach ($year_term as $key => &$aa) {
         $a = implode(',', array_unique(array_merge(json_decode(str_replace('],[', ',', $aa['sid']), TRUE))));
         $year_term_options[$a] = $aa['name'];
     }
     $spec_id = Specialty::join('academystructure_departments', 'academystructure_departments.spec_id', '=', 'academystructure_specialties.id')->select(\DB::raw('academystructure_specialties.name as name,
                                     GROUP_CONCAT(DISTINCT(academystructure_departments.id)) as sid'))->groupBy('academystructure_departments.spec_id')->pluck('name', 'sid')->toArray();
     $types = config('exams.types');
     $filter_semester_id = 0;
     if (request('exam_semester')) {
         $filter_semester_id = request('exam_semester');
     } else {
         $filter_semester_id = semester()->id;
     }
     if (request('spec_id')) {
         $search_spec_id = explode(',', request('spec_id'));
         $statistics = Exam::with(['subject', 'results' => function ($q) use($search_spec_id) {
             $q->whereHas('student', function ($query) use($search_spec_id) {
                 $query->whereIn('students.academystructure_department_id', $search_spec_id);
             });
         }])->where('active', 1)->where('semester_id', $filter_semester_id)->where('finish_at', '=<', date("Y/m/d H:i:s"));
         $subject_students = Subject::select('id')->withCount(['students' => function ($q) use($filter_semester_id, $search_spec_id) {
             $q->where('semester_id', $filter_semester_id);
             $q->where('students.state', 'active');
             $q->where('student_subjects.state', 'study');
             $q->whereIn('students.academystructure_department_id', $search_spec_id);
         }])->pluck('students_count', 'id')->toArray();
     } else {
         $statistics = Exam::with(['subject', 'results'])->where('active', 1)->where('semester_id', $filter_semester_id)->where('finish_at', '<', date("Y/m/d H:i:s"));
         $subject_students = Subject::select('id')->withCount(['students' => function ($q) use($filter_semester_id) {
             $q->where('semester_id', $filter_semester_id);
             $q->where('students.state', 'active');
             $q->where('student_subjects.state', 'study');
         }])->pluck('students_count', 'id')->toArray();
     }
     if (request('exam_year_term')) {
         $statistics->whereIn('subject_id', explode(',', request('exam_year_term')));
     }
     if (request('exam_subject')) {
         $statistics->where('subject_id', request('exam_subject'));
     }
     if (request('exam_type')) {
         $statistics->where('type', request('exam_type'));
     }
     $statistics = $statistics->get();
     return view('exams::reports.subjectexam', compact('subjects', 'semesters', 'year_term_options', 'types', 'statistics', 'subject_students', 'spec_id'));
 }
 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{
     // }
 }
Пример #5
0
 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);
 }
Пример #6
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);
     }
 }