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; }
/** * 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); } }
/** * 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); } } } }
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); }
/** * 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); } }