Esempio n. 1
0
 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'));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     if (Withdraw::count()) {
         // return;
     }
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Equal::truncate();
     Delay::truncate();
     Withdraw::truncate();
     OrderFile::truncate();
     Orderhistory::truncate();
     // $this->call("OthersTableSeeder");
     $old_reason = ["notunderstand" => "عدم استيعاب أسلوب الدراسة عن بعد", "nointernet" => "عدم توافر إنترنت جيد أو مركز خدمات كمبيوتر قريب من السكن", "nomoney" => "عدم إمكانية تحمل الرسوم الدراسية", "baby" => "الولادة / رعاية مولود جديد", "sick" => "المرض", "familysick" => "مرض أحد الأقارب من الدرجة الأولى (الأب، الأم، الزوج، الأخ، الأخت، الابن، الابنة)", "work" => "السفر لدواعي العمل", "family" => "ظروف عائلية", "personal" => "السفر لأسباب شخصية", "workz" => "ظروف العمل"];
     $old_state = ["UN" => "تقديم", "OC" => "مكتمل", "ONC" => "غير مكتمل", "NCON" => "الغاء لعدم الاستكمال", "AC" => "قبول", "NC" => "رفض"];
     $country = [0 => null, 1 => 147, 2 => 1, 3 => 234, 4 => 226, 5 => 4, 6 => 140, 7 => 125, 8 => 211, 9 => 137, 10 => 206, 11 => 253, 12 => 269, 13 => 197, 14 => 118, 15 => 14, 16 => 182, 17 => 225, 18 => 248, 19 => 106, 20 => 114, 21 => 83, 22 => 121, 23 => 218];
     $old_equal_state = [0 => "متقدم", 1 => "مكتمل", 2 => "غير مكتمل", 3 => "قبول كلى", 4 => "قبول جزئى", 5 => "رفض كلى", 7 => "الغاء"];
     $old_certificat = [1 => "دبلوم", 2 => "بكالوريوس", 3 => "ماجستير", 4 => "دكتوراه", 5 => "لم أكمل متطلبات الحصول على الدرجة العلمية"];
     //get all Withdraw order expected REP state (dublicate order)
     //$orders = DB::connection('old')->table('withdrawls')->where('wd_type',0)->where('wd_status','<>','REP')->get();
     $orders = [];
     foreach ($orders as $order) {
         $new_Withdraw = new Withdraw();
         //$new_Withdraw->id = $order->wd_id;
         $new_Withdraw->student_id = $order->wd_userid;
         $new_Withdraw->reason = in_array($order->wd_reasons, $old_reason) ? $old_reason[$order->wd_reasons] : $order->wd_reasons;
         $new_Withdraw->semester_id = $order->wd_semid > 0 ? $order->wd_semid : NULL;
         $new_Withdraw->state = $old_state[$order->wd_status];
         $new_Withdraw->bank_name = $order->wd_bankname;
         $new_Withdraw->bank_account_name = $order->wd_bankfullname;
         $new_Withdraw->bank_account_number = $order->wd_banknum;
         $new_Withdraw->refund_state = 100;
         $new_Withdraw->created_at = $order->wd_created;
         $new_Withdraw->updated_at = $order->wd_created;
         $new_Withdraw->save();
         $files = DB::connection('old')->table('withdrawls_attachments')->where('wda_wdid', $order->wd_id)->get();
         foreach ($files as $file) {
             $new_file = new OrderFile();
             $new_file->ref_key = 'order_withdraws';
             $new_file->ref_value = $order->wd_id;
             //path = iis/assets/forms/
             //$new_file->file = $file->wda_file;
             $new_file->created_at = $file->wda_created;
             $new_file->updated_at = $file->wda_created;
             $new_file->save();
         }
     }
     $this->command->info('withdraw order transfered!');
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //get all Delay order expected REP state (dublicate order)
     $orders = DB::connection('old')->table('withdrawls')->where('wd_type', 1)->where('wd_userid', '!=', 1356)->where('wd_status', '<>', 'REP')->get();
     foreach ($orders as $order) {
         $new_Delay = new Delay();
         //$new_Delay->id = $order->wd_id;
         $new_Delay->student_id = $order->wd_userid;
         $new_Delay->reason = in_array($order->wd_reasons, $old_reason) ? $old_reason[$order->wd_reasons] : $order->wd_reasons;
         $new_Delay->semester_id = $order->wd_semid > 0 ? $order->wd_semid : null;
         $new_Delay->state = $old_state[$order->wd_status];
         $student_info = DB::table('students')->find($order->wd_userid);
         if (!$student_info) {
             echo "This user does not exist " . $order->wd_userid;
         }
         $new_Delay->academystructure_department_id = $student_info->state == 'delayed' ? $student_info->academystructure_department_id : null;
         $new_Delay->refund_state = 100;
         $new_Delay->created_at = $order->wd_created;
         $new_Delay->updated_at = $order->wd_created;
         $new_Delay->save();
         $files = DB::connection('old')->table('withdrawls_attachments')->where('wda_wdid', $order->wd_id)->get();
         foreach ($files as $file) {
             $new_file = new OrderFile();
             $new_file->ref_key = 'order_delays';
             $new_file->ref_value = $order->wd_id;
             //path = iis/assets/forms/
             //$new_file->file = $file->wda_file;
             $new_file->created_at = $file->wda_created;
             $new_file->updated_at = $file->wda_created;
             $new_file->save();
         }
     }
     $this->command->info('delay order transfered!');
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //get all Equation order
     $Eorders = DB::connection('old')->table('user_equation')->whereNotIn('ue_userid', [2943, 2947])->get();
     foreach ($Eorders as $Eorder) {
         $new_Equal = new Equal();
         $new_Equal->id = $Eorder->ue_id;
         $new_Equal->student_id = $Eorder->ue_userid;
         $new_Equal->semester_id = null;
         $new_Equal->grade = is_numeric($Eorder->ue_finalestimate) ? $Eorder->ue_finalestimate : '';
         $new_Equal->country_id = $country[$Eorder->ue_cityid];
         $new_Equal->state = $old_equal_state[$Eorder->ue_curstatus];
         $new_Equal->certificate = $old_certificat[$Eorder->ue_edulevel];
         $new_Equal->old_institute = $Eorder->ue_studyedulevel == 'iis' ? 'كلية العلوم الشرعية' : $Eorder->ue_studyeduleveltext;
         $new_Equal->created_at = $Eorder->ue_date;
         $new_Equal->updated_at = $Eorder->ue_date;
         $new_Equal->save();
         //////////////////////////////////File
         $new_file = new OrderFile();
         $new_file->ref_key = 'order_equals';
         $new_file->ref_value = $Eorder->ue_id;
         //path = iis/assets/equationsubject/
         //$new_file->file = $files->ue_file;
         $new_file->created_at = $Eorder->ue_date;
         $new_file->updated_at = $Eorder->ue_date;
         $new_file->save();
     }
     $this->command->info('Equals order transfered!');
     //get all Equation Subject
     $Eqsubjects = DB::connection('old')->table('equation_subjects_new')->whereNotIn('es_ueid', [174, 204])->get();
     $all_eqsubject = [];
     foreach ($Eqsubjects as $Eqsubject) {
         $new_Eqsubject = [];
         $new_Eqsubject['equal_order_id'] = $Eqsubject->es_ueid;
         $new_Eqsubject['subject_name'] = $Eqsubject->es_name;
         $new_Eqsubject['subject_code'] = $Eqsubject->es_code;
         $new_Eqsubject['hours'] = is_numeric($Eqsubject->es_hours) ? $Eqsubject->es_hours : null;
         $new_Eqsubject['degree'] = is_numeric($Eqsubject->es_degree) ? $Eqsubject->es_degree : null;
         $new_Eqsubject['max_degree'] = is_numeric($Eqsubject->es_alldegree) ? $Eqsubject->es_alldegree : null;
         $new_Eqsubject['equal_subject_id'] = $Eqsubject->es_subjects;
         $new_Eqsubject['created_at'] = '2001-01-01';
         $new_Eqsubject['updated_at'] = '2001-01-01';
         $all_eqsubject[] = $new_Eqsubject;
     }
     foreach (array_chunk($all_eqsubject, 10) as $Eqsubject_group) {
         DB::table('order_equal_subjects')->insert($Eqsubject_group);
     }
     $this->command->info('Equal subjects transfered!');
 }