Example #1
0
 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);
 }
 /**
  * Remove the specified resource from storage.
  * @return Response
  */
 public function destroy($exception_id)
 {
     $exceptions = FinancialException::with('students')->findOrFail($exception_id);
     $exceptions = $exceptions->findOrFail($exception_id);
     $exceptions->delete();
     return redirect()->route('financials.exceptions.index');
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //Financial
     Financial::created(function ($fanancial) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_fanancial', 'reference_id' => $fanancial->id]);
     });
     Financial::updated(function ($fanancial) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_fanancial', 'reference_id' => $fanancial->id]);
     });
     Financial::deleted(function ($fanancial) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_fanancial', 'reference_id' => $fanancial->id]);
     });
     //FinancialInvoice
     FinancialInvoice::created(function ($invoice) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoice', 'reference_id' => $invoice->id]);
     });
     FinancialInvoice::updated(function ($invoice) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoice', 'reference_id' => $invoice->id]);
     });
     FinancialInvoice::deleted(function ($invoice) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoice', 'reference_id' => $invoice->id]);
     });
     //FinancialInvoiceItem
     FinancialInvoiceItem::created(function ($invoiceitem) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoiceitem', 'reference_id' => $invoiceitem->id]);
     });
     FinancialInvoiceItem::updated(function ($invoiceitem) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoiceitem', 'reference_id' => $invoiceitem->id]);
     });
     FinancialInvoiceItem::deleted(function ($invoiceitem) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_invoiceitem', 'reference_id' => $invoiceitem->id]);
     });
     //FinancialException
     FinancialException::created(function ($excuse) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_execptions', 'reference_id' => $excuse->id]);
     });
     FinancialException::updated(function ($excuse) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_execptions', 'reference_id' => $excuse->id]);
     });
     FinancialException::deleted(function ($excuse) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Financial_execptions', 'reference_id' => $excuse->id]);
     });
 }