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