Example #1
0
 public function store(Request $request)
 {
     $equation = RegistrationEquation::findOrNew($request->input('id'));
     $equation->fill($request->only('university', 'level', 'grade'));
     $equation->registration_id = $this->user->id;
     $equation->save();
     /** populate files and delete unused] */
     $files_ids = [];
     foreach ($request->input('files') as $file) {
         if (!empty($file['id'])) {
             $files_ids[] = $file['id'];
         }
     }
     RegistrationEquationFile::whereIn('id', $files_ids)->update(['registration_equation_id' => $equation->id]);
     RegistrationEquationFile::whereNotIn('id', $files_ids)->where('registration_equation_id', $equation->id)->delete();
     /** end populate files  */
     /** populate subjects */
     $old_subject_ids = [];
     foreach ($request->input('subjects') as $subject) {
         if (!empty($subject['id'])) {
             $old_subject_ids[] = $subject['id'];
         }
     }
     RegistrationEquationSubject::whereNotIn('id', $old_subject_ids)->where('registration_equation_id', $equation->id)->delete();
     foreach ($request->input('subjects') as $subject) {
         if (empty($subject['id'])) {
             $subject['status'] = 'waiting';
             $equation->subjects()->create($subject);
         } else {
             RegistrationEquationSubject::where('id', $subject['id'])->update($subject);
         }
     }
     /** ned populate subjects */
     $equation->load('files', 'subjects');
     foreach ($equation->files as $file) {
         $attachments = $file->urlsForAttachment('file');
         foreach ($attachments as $key => $attachment) {
             $attachments[$key] = asset($attachment);
         }
         $file->attachments = $attachments;
     }
     // update step and dispatch it
     $next_step = RegistrationStep::find($this->user->registration_step_id)->children()->where('equation_processing', 1)->first();
     if ($next_step) {
         $this->user->registration_step_id = $next_step->id;
         $this->user->save();
         event(new RegistrationStepChanged($this->user, ['comment' => 'تم تغييرها بشكل تلقائي بعد اضافة الطالب لشهادة']));
     }
     //
     return response()->json(compact('equation'), 200, [], JSON_NUMERIC_CHECK);
 }
Example #2
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);
 }
Example #4
0
 public function update($eq_id, Request $request)
 {
     //dd($eq_id);
     $message = 'تم التحديث بنجاح';
     $equations = EqSub::find($eq_id);
     $equations->fill($request->all());
     $eq_id = $equations->registration_equation_id;
     $equations->save();
     if (request('submit') == 'save') {
         return redirect()->back()->with('success', $message);
     } else {
         return redirect()->route('registration.equations.subjects', $eq_id)->with('success', $message);
     }
 }
Example #5
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);
     }
 }