public function active()
 {
     $subjects = [];
     $fields = [];
     if (FinancialException::whereSemesterId(semester()->id)->whereStudentId($this->student->id)->whereActive(1)->count()) {
         return response()->json(false, 200, [], JSON_NUMERIC_CHECK);
     }
     $this->student->load('registration', 'registration.contactcountry', 'registration.contactcity');
     $subjects = Subject::join('student_subjects as ss', function ($j) {
         $j->on('ss.subject_id', '=', 'subject_subjects.id')->where('student_id', '=', $this->student->id)->where('state', '=', 'study')->where('semester_id', '=', $this->semester->id)->where('payed', '=', 0);
     })->get()->toArray();
     // if() {
     $study_fee = FinancialInvoiceItem::where('slug', 'study_fee')->first();
     $study_fee = $study_fee ? $study_fee->amount : 0;
     // } else {
     // $study_fee = 6;
     // }
     $total_fee = 0;
     foreach ($subjects as &$subject) {
         $subject['fee'] = !$subject['is_quran'] ? $subject['hour'] * $study_fee : $subject['hour'] * 7.5;
         $total_fee += $subject['fee'];
     }
     if ($total_fee > 0) {
         if (!$this->student->registration) {
             return response()->json(false, 200, [], JSON_NUMERIC_CHECK);
         }
         $data = ['key' => 'student', 'value' => $this->student->username, 'transaction_id' => time(), 'amount' => $total_fee, 'bill_to_forename' => $this->student->registration->first_name, 'bill_to_surname' => $this->student->registration->last_name, 'bill_to_email' => $this->student->registration->contact_email, 'bill_to_address_line1' => $this->student->registration->adress, 'bill_to_phone' => $this->student->registration->contact_mobile, 'bill_to_address_city' => $this->student->registration->contactcity ? $this->student->registration->contactcity->name : '', 'bill_to_address_country' => 'OM'];
         $payment = new PaymentGateway($data);
         $fields = $payment->getData();
     }
     if (empty($total_fee)) {
         return response()->json(false, 200, [], JSON_NUMERIC_CHECK);
     }
     return response()->json(compact('subjects', 'fields'), 200, [], JSON_NUMERIC_CHECK);
 }
 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);
 }