/** * Store a newly created resource in storage. * @param Request $request * @return Response */ public function store(Request $request) { $order = new OrderDelay(); $order->fill($request->only('reason')); $order->student_id = $this->student->id; $order->academystructure_department_id = $this->student->academystructure_department_id; $order->semester_id = $this->semester->id; $order->state = 'تقديم'; $order->save(); // create order history record $history = new Orderhistory(); $history->ref_key = 'order_delays'; $history->ref_value = $order->id; $history->state = 'تقديم'; $history->save(); // check if financial item active then create debit record $invoice_item = FinancialInvoiceItem::where('slug', 'delayed_fee')->where('state', 'نشط')->first(); if ($invoice_item) { $invoice_data = ['ref_key' => 'order_delays', 'ref_value' => $order->id, 'student_id' => $this->student->id, 'amount' => $invoice_item->amount, 'type' => 'debit', 'semester_id' => $this->semester->id, 'item_id' => $invoice_item->id, 'note' => 'تكلفة طلب تاجيل دراسة']; FinancialInvoice::create($invoice_data); } if ($request->has('files')) { OrderFile::whereIn('id', array_pluck($request->input('files'), 'id'))->update(['ref_value' => $order->id, 'ref_key' => 'order_delays']); } $order->load('files'); return response()->json($order, 200, [], JSON_NUMERIC_CHECK); }
/** * Boot the application events. * * @return void */ public function boot() { $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); FinancialInvoice::creating(function ($invoice) { $invoice->semester_id = empty($invoice->semester_id) ? semester()->id : $invoice->semester_id; }); }
public function index() { $invoices = FinancialInvoice::select('fi.amount', 'fi.semester_id', 'sem.name', 'fi.id', 'fi.created_at')->where('fi.type', 'credit')->leftJoin('academycycle_semesters as sem', 'sem.id', '=', 'fi.semester_id')->where('fi.student_id', $this->student->id)->groupBy('fi.id')->from('financial_invoices as fi')->get(); foreach ($invoices as $invoice) { $invoice->subjects = StudentSubject::join('subject_subjects as sub', function ($query) { $query->on('sub.id', '=', 'student_subjects.subject_id'); })->select('sub.name', 'sub.hour', 'sub.is_quran')->where('student_id', $this->student->id)->where('semester_id', $invoice->semester_id)->where('student_subjects.state', '!=', 'equal')->groupBy('sub.id')->get(); } return $invoices; }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); if (FinancialInvoice::count()) { return; } DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $invoices = DB::connection('old')->table('invoices')->get(); $invoice_debits = DB::connection('old')->table('invoice_debits')->get(); $invoices_credit = []; $invoices_debit = []; $invoices_credit_debit = []; FinancialInvoice::truncate(); foreach ($invoice_debits as $debit) { $new_invoice = []; $new_invoice['note'] = $debit->description; $new_invoice['pay_type'] = 'epayment'; $new_invoice['type'] = 'debit'; $new_invoice['amount'] = $debit->amount; $new_invoice['student_id'] = $debit->user_id; $new_invoice['semester_id'] = 7; $invoices_credit_debit[] = $new_invoice; if ($debit->paid) { $new_invoice['type'] = 'credit'; $invoices_credit_debit[] = $new_invoice; } } foreach ($invoices as $inv) { $new_invoice = []; $new_invoice['id'] = $inv->inv_id; $new_invoice['student_id'] = $inv->inv_userid ? $inv->inv_userid : NULL; $new_invoice['amount'] = $inv->inv_amount; $new_invoice['type'] = $inv->inv_operation == 'credit' ? 'credit' : 'debit'; $new_invoice['pay_type'] = $inv->inv_type == 'check' ? 'cheque' : $inv->inv_type; $new_invoice['transaction_wid'] = $inv->inv_number; $new_invoice['note'] = $inv->inv_checkpayment_comment; $new_invoice['semester_id'] = $inv->inv_r_semid > 0 ? $inv->inv_r_semid : NULL; $new_invoice['created_at'] = $inv->inv_created == '0000-00-00 00:00:00' ? date('Y-m-d H:i:s') : $inv->inv_created; $invoices_credit[] = $new_invoice; unset($new_invoice['transaction_wid']); unset($new_invoice['id']); unset($new_invoice['note']); $new_invoice['type'] = 'debit'; $invoices_debit[] = $new_invoice; } foreach (array_chunk($invoices_credit, 500) as $chunk) { DB::table('financial_invoices')->insert($chunk); } foreach (array_chunk($invoices_debit, 500) as $chunk) { DB::table('financial_invoices')->insert($chunk); } foreach (array_chunk($invoices_credit_debit, 500) as $chunk) { DB::table('financial_invoices')->insert($chunk); } }
/** * Handle the event. * * @param UserAuthenticated $event * @return void */ public function handle(DelayOrderAccepted $event) { $delay_order = $event->order; //refund debit //create credit invoice if ($delay_order->refund_state > 0) { $moneyback_item = FinancialInvoiceItem::where('slug', 'moneyback_fee')->where('state', 'نشط')->first(); $study_item = FinancialInvoice::whereHas('item', function ($q) { $q->where('slug', 'study_fee'); })->where('semester_id', semester()->id)->where('type', 'debit')->first(); if ($study_item) { $invoiceData = ['ref_key' => 'order_delays', 'ref_value' => $delay_order->id, 'student_id' => $delay_order->student_id, 'amount' => $study_item->amount * $delay_order->refund_state / 100, 'type' => 'credit', 'pay_type' => 'system', 'item_id' => $moneyback_item->id, 'semester_id' => $delay_order->semester_id, 'note' => 'رسوم مستحقة من التأجيل']; FinancialInvoice::create($invoiceData); } } }
/** * 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]); }); }
/** * Handle the event. * * @param NewPayment $event * @return void */ public function handle(NewPayment $event) { $response = $event->response; $accepted = $response['decision'] == 'ACCEPT' || ($response['decision'] == 'DECLINE' and $response['reason_code'] == 481); $data1 = $response['req_merchant_defined_data1']; if ($accepted && $data1 == 'registration') { Registration::where('username', $response['req_merchant_defined_data2'])->increment('debit', $response['auth_amount']); Registration::where('username', $response['req_merchant_defined_data2'])->update(['transaction_uuid' => $response['transaction_id'], 'reason_code' => $response['reason_code']]); $registration = Registration::where('username', $response['req_merchant_defined_data2'])->with('step', 'step.children')->first(); if ($step = $registration->step and !$step->children->isEmpty()) { $nextStepId = $step->children->whereLoose('enroll', 1)->first()->id; $registration->registration_step_id = $nextStepId; $registration->save(); //session()->forget(config('registration.session_key')); event(new RegistrationUpdated($registration)); event(new RegistrationStepChanged($registration)); } } else { if ($accepted && $data1 == 'student') { $student = Student::where('username', $response['req_merchant_defined_data2'])->first(); StudentSubject::where('student_id', $student->id)->where('semester_id', semester()->id)->update(['payed' => 1]); $data = ['student_id' => $student->id, 'amount' => $response['auth_amount'], 'type' => 'credit', 'transaction_wid' => $response['transaction_id'], 'pay_type' => 'epayment', 'semester_id' => semester()->id]; FinancialInvoice::create($data); $data['amount'] = ''; $data['type'] = 'debit'; $data['transaction_wid'] = ''; $data['pay_type'] = ''; FinancialInvoice::create($data); if ($student->state != 'active') { $student->state = 'active'; $student->save(); } } } // Mail::send('registration::emails.new_payment' ,compact('response'), function ($message) { // $message->to('*****@*****.**') // ->subject('new payment '.date('Y-m-d H:i:s')); // }); }
public function store(Request $request) { if ($request->other_reason_text) { $reason = $request->other_reason_text; } else { $reason = $request->reason; } // create order record $withdraw_order = new Withdraw(); $withdraw_order->student_id = student()->id; $withdraw_order->academystructure_department_id = student()->academystructure_department_id; $withdraw_order->semester_id = $request->input('semester_id'); $withdraw_order->state = 'تقديم'; $withdraw_order->reason = $reason; $withdraw_order->bank_name = request('bank_name'); $withdraw_order->bank_account_name = request('bank_account_name'); $withdraw_order->bank_account_number = request('bank_account_number'); $withdraw_order->save(); // create order history record $order_history = new Orderhistory(); $order_history->ref_key = 'order_withdraws'; $order_history->ref_value = $withdraw_order->id; $order_history->state = 'تقديم'; $order_history->save(); // check if financial item active then create debit record $withdraw_item = FinancialInvoiceItem::where('slug', 'withdraw_fee')->where('state', 'نشط')->first(); if ($withdraw_item) { if ($withdraw_item->amount > 0) { $invoiceData = ['ref_key' => 'order_withdraws', 'ref_value' => $delay_order->id, 'student_id' => student()->id, 'amount' => $delaye_item->amount, 'type' => 'debit', 'semester_id' => $request->input('semester_id'), 'item_id' => $delaye_item->id, 'note' => 'تكلفة طلب الانسحاب']; FinancialInvoice::create($invoiceData); } } // update uploaded files if (!empty(request('files'))) { $update_data = ['ref_key' => 'order_withdraws', 'ref_value' => $withdraw_order->id]; OrderFile::whereIn('id', request('files'))->update($update_data); } return redirect()->route('orders.index')->with('success', trans('orders::order.create_success')); }
public function approve($order_id) { $order = OrderChangeDepartment::findOrFail($order_id); $student_id = $order->student_id; $depid = $order->to; $current_dep = $order->from; $StudentHistory = StudentHistory::where('student_id', $student_id)->where('academycycle_semester_id', semester()->id)->update(['academystructure_department_id' => $depid]); $student = Student::with('subjects')->where('id', $student_id)->first(); $student->academystructure_department_id = $depid; $student->save(); $department = Department::findOrFail($current_dep); $current_subject_ids = json_decode($department->subject_ids, TRUE); $current_payed_subject_ids = StudentSubject::select('subject_id')->where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->where('payed', 1)->get(); $cuttent_invoice_amount = 0; if ($current_payed_subject_ids->count() > 0) { $cuttent_invoice_amount = Subject::select(DB::raw('sum(hour*amount) as total_amount'))->whereIn('id', $current_payed_subject_ids)->first(); } $new_department = Department::findOrFail($depid); $new_subject_ids = json_decode($new_department->subject_ids, TRUE); //if($current_dep == 8 or $current_dep == 13 or $current_dep =14 ){ //update department subjects StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->whereIn('subject_id', $current_subject_ids)->update(['state' => 'drop']); foreach ($new_subject_ids as $new_subject_id) { $new_student_subject = new StudentSubject(); $new_student_subject->subject_id = $new_subject_id; $new_student_subject->student_id = $student_id; $new_student_subject->semester_id = semester()->id; $new_student_subject->academystructure_department_id = $depid; $new_student_subject->state = 'study'; $new_student_subject->save(); } if ($current_payed_subject_ids->count() > 0) { $new_payed_subject_ids = StudentSubject::select('subject_id')->where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->get(); $new_invoice_amount = Subject::select(DB::raw('sum(hour*amount) as total_amount'))->whereIn('id', $new_payed_subject_ids)->first(); if ($new_invoice_amount < $cuttent_invoice_amount) { StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['payed' => 1]); $invoiceData = ['ref_key' => 'Order_Change_AC_Departments', 'ref_value' => $order_id, 'student_id' => $student_id, 'amount' => $cuttent_invoice_amount->total_amount - $new_invoice_amount->total_amount, 'type' => 'credit', 'semester_id' => semester()->id, 'note' => 'فرق تغيير التخصص']; FinancialInvoice::create($invoiceData); } if ($new_invoice_amount > $cuttent_invoice_amount) { StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['payed' => 1]); } if ($new_invoice_amount > $cuttent_invoice_amount) { StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->where('subject_id', '!=', 35)->update(['payed' => 1]); } } //updtae remain subjects (not in dep id) to be in same depid StudentSubject::where('semester_id', semester()->id)->where('student_id', $student_id)->where('state', 'study')->update(['academystructure_department_id' => $depid]); $order->state = 1; $order->save(); $msg = 'تم تغيير التخصص '; return redirect()->route('orders.change.department.index')->with('success', $msg); // }else{ // } }
public function getInvoices($background = false) { $student = Student::select('students.*')->joinTermName()->findOrFail($this->student_id); $invoices = FinancialInvoice::where('student_id', $this->student_id)->with('semester')->where('type', 'credit')->get(); $pdf = $this->preparePdf($background); // ---- > $html = '<h2>إيصال بالدفع</h2>'; $pdf->writeHTMLCell(210, 20, 0, 50, $html, 0, 0, false, true, "C"); $pdf->SetFontSize(12); $html = 'بتاريخ : ' . Date::now()->format('l d F Y'); $pdf->writeHTMLCell(60, 10, 150, 40, $html, 0, 0, false, true, "C"); $pdf->SetFontSize(13, 'B'); $html = '<table cellpadding="3"> <tr><td align="right">إسم لطالب</td><td align="right">' . $student->name . '</td></tr> <tr><td align="right">الرقم الجامعي</td><td align="right">' . $student->code . '</td></tr> <tr><td align="right">تاريخ الإلتحاق</td><td align="right">' . Date::parse($student->created_at)->format('l d F Y') . '</td></tr> <tr><td align="right">السنة الدراسية</td><td align="right">' . $student->year_name . '</td></tr> </table>'; $pdf->writeHTMLCell(100, 20, 10, 70, $html, 0, 0, false, true, "R"); $pdf->SetFontSize(15, 'B'); $pdf->writeHTMLCell(170, 20, 20, 110, view('students::documents._invoices', compact('invoices'))->render(), 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, 90, 250, $html, 0, 0, false, true, "C"); ob_clean(); return $pdf; }
public function edit(FinancialInvoice $Invoice, $id) { $invoice = $Invoice->findOrFail($id); return view('Financials::invoices.edit', compact('invoice')); }
public function delete($invoice_id) { $Invoices = FinancialInvoice::findOrFail($invoice_id); $message = 'تم حذف الفاتورة بنجاح'; $Invoices->delete(); return redirect()->route('financials.financials.show', $Invoices->student_id)->with('success', $message); }
/** * 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); } }