/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     if (Registration::count()) {
         return;
     }
     Registration::truncate();
     // $this->call("OthersTableSeeder");
     $periods = [['id' => '1', 'name' => 'فترة قبول 2013', 'start_at' => '2013-08-01', 'finish_at' => '2013-10-01', 'code' => 'e2013', 'academycycle_year_id' => '1'], ['id' => '2', 'name' => 'فترة قبول 2014', 'start_at' => '2014-08-01', 'finish_at' => '2014-10-01', 'code' => 'e2014', 'academycycle_year_id' => '2'], ['id' => '3', 'name' => 'فترة قبول 2015', 'start_at' => '2015-08-01', 'finish_at' => '2015-10-01', 'code' => 'e2015', 'academycycle_year_id' => '3']];
     foreach ($periods as $period) {
         //Period::create($period);
     }
     $this->command->info('periods entered!');
     $country = [0 => null, 1 => 613, 4 => 616, 5 => 617, 6 => 618, 7 => 619, 16 => 628, 17 => 629];
     $allstatuses = array("MN" => "إلغاء لعدم سداد الرسوم", "VN" => "إلغاء لعدم إرسال المستندات الموثقه", "MVN" => "إلغاء الطلب لعدم السداد وإرسال المستندات المصدقة", "DX" => "إلغاء الطلب لعدم تحميل المستندات", "XX" => "إلغاء لتكرار الطلب", "CN" => "تم الرفض", "EN" => "طالب منتظم");
     $old_state = ['DM' => 3, 'MW' => 3, 'CO' => 3, 'AP' => 3, 'VC' => 3, 'DN' => 3, 'CW' => 3, 'DU' => 3, 'DC' => 3, 'MN' => 3, 'VN' => 3, 'MVN' => 3, 'DX' => 3, 'XX' => 3, 'CN' => 15, 'EN' => 26];
     $reg_type = ['bachaleor' => 2, 'diplom' => 1, 'takmely' => 3];
     $reg_specialty = ['islam' => 2, 'feqh' => 1, 'general' => 3];
     $reg_stay_type = ['morafek' => 'companion', 'notresident' => 'non_resident', 'tourism' => 'tourism', 'work' => 'work'];
     $registrations = DB::connection('old')->table('registration')->get();
     $all_regs = [];
     foreach ($registrations as $registration) {
         //$new_registration = new Registration();
         $new_registration = [];
         //name
         $new_registration['id'] = $registration->reg_id;
         $new_registration['first_name'] = $registration->reg_firstname;
         $new_registration['second_name'] = $registration->reg_secondname;
         $new_registration['third_name'] = $registration->reg_thirdname;
         $new_registration['fourth_name'] = $registration->reg_fourthname;
         $new_registration['last_name'] = $registration->reg_lastname;
         $new_registration['last_name_latin'] = '';
         $new_registration['fourth_name_latin'] = '';
         $new_registration['third_name_latin'] = '';
         $new_registration['second_name_latin'] = '';
         $new_registration['first_name_latin'] = $registration->reg_englishname;
         //
         $new_registration['registration_type_id'] = $reg_type[$registration->reg_stage];
         $new_registration['academystructure_specialty_id'] = $reg_specialty[$registration->reg_specialist];
         //
         $new_registration['religion'] = $registration->reg_relegion;
         $new_registration['gender'] = $registration->reg_gender == 1 ? 'f' : 'm';
         //birthday
         $new_registration['birthday'] = $registration->reg_birthdate;
         $new_registration['birth_country_id'] = !empty($country[$registration->reg_birthcountryid]) ? $country[$registration->reg_birthcountryid] : 613;
         // nationality
         $new_registration['national_id'] = $registration->reg_nationalid;
         $new_registration['nationality_type'] = $registration->reg_nationality ? 'E' : 'O';
         $new_registration['nationality_country_id'] = !empty($country[$registration->reg_nationalitycountry]) ? $country[$registration->reg_nationalitycountry] : 613;
         //passport
         $new_registration['passeport_number'] = $registration->reg_passportnum;
         $new_registration['passeport_issued'] = $registration->reg_passportstartdate;
         $new_registration['passeport_expire'] = $registration->reg_passportenddate;
         $new_registration['passeport_country_id'] = !empty($country[$registration->reg_passportcountryid]) ? $country[$registration->reg_passportcountryid] : 613;
         //stay
         $new_registration['stay_expire'] = $registration->reg_stayenddate;
         $new_registration['stay_type'] = in_array($registration->reg_staytype, $reg_stay_type) ? $reg_stay_type[$registration->reg_staytype] : 'other';
         //contact
         $new_registration['contact_region'] = $registration->reg_contactregion;
         $new_registration['contact_postalbox'] = $registration->reg_contactpostalbox;
         $new_registration['contact_street'] = $registration->reg_contactstreet;
         $new_registration['contact_home_number'] = $registration->reg_contacthomenum;
         $new_registration['contact_email'] = $registration->reg_contactemail;
         $new_registration['contact_mobile'] = $registration->reg_contactmobile;
         $new_registration['contact_phone'] = $registration->reg_contacthomephone;
         $new_registration['contact_fax'] = $registration->reg_contactfax;
         $new_registration['contact_country_id'] = !empty($country[$registration->reg_contact_countryid]) ? $country[$registration->reg_contact_countryid] : 613;
         $new_registration['contact_city_id'] = $registration->reg_contactcityid > 0 ? $registration->reg_contactcityid : null;
         $new_registration['contact_state_id'] = null;
         //degree
         $new_registration['social_status'] = $registration->reg_socialmarital;
         $new_registration['degree_speciality'] = $registration->reg_eduspecialist;
         $new_registration['degree_institution'] = $registration->reg_eduplace;
         $new_registration['degree_score'] = $registration->reg_edugrade;
         $new_registration['degree_graduation_year'] = $registration->reg_eduendyear;
         $new_registration['degree_country_id'] = !empty($country[$registration->reg_edulevelcountry]) ? $country[$registration->reg_edulevelcountry] : 613;
         //social
         $new_registration['social_job'] = $registration->reg_socialworkjob;
         $new_registration['social_job_status'] = $registration->reg_socialworkstatus;
         $new_registration['social_job_start'] = $registration->reg_socialworkstart;
         $new_registration['social_experience'] = $registration->reg_socialworkexpert;
         $new_registration['social_job_employer'] = $registration->reg_socialworkplace;
         $new_registration['social_job_country_id'] = !empty($country[$registration->reg_socialworkcountryid]) ? $country[$registration->reg_socialworkcountryid] : 613;
         $new_registration['social_job_city_id'] = $registration->reg_socialworkcityid > 0 ? $registration->reg_socialworkcityid : null;
         $reg_socialworksector = '';
         if ($registration->reg_socialworksector == 'public') {
             $reg_socialworksector = 'government';
         }
         if ($registration->reg_socialworksector == 'private') {
             $reg_socialworksector = 'private';
         }
         if ($registration->reg_socialworksector == 'free') {
             $reg_socialworksector = 'freelance';
         }
         $new_registration['social_job_type'] = $reg_socialworksector;
         //others
         $new_registration['email_verified'] = 0;
         $new_registration['verification_token'] = '';
         $new_registration['debit'] = 0;
         //health
         $new_registration['health_status'] = $registration->reg_healthstatus;
         $new_registration['health_disabled_type'] = $registration->reg_healthdisabledtype;
         $new_registration['health_disabled_size'] = $registration->reg_healthdisabledsize;
         //skills
         $new_registration['computer_skills'] = $registration->reg_skillspc;
         $new_registration['internet_skills'] = $registration->reg_skillsnet;
         $new_registration['internet_link'] = $registration->reg_skillsgoodnetline;
         $new_registration['cyber_cafe'] = $registration->reg_skillsnearnet;
         $new_registration['computer_availability'] = $registration->reg_skillshaspc;
         //refrence
         $new_registration['reference'] = $registration->reg_skillsknowus;
         $new_registration['reference_other'] = $registration->reg_skillsknowustext;
         //period and prefix
         $period = '';
         $prefix = '';
         if ($registration->reg_eduyearid == '1') {
             $period = '1';
             $prefix = 'e2013';
         }
         if ($registration->reg_eduyearid == '2') {
             $period = '2';
             $prefix = 'e2014';
         }
         if ($registration->reg_eduyearid == '3') {
             $period = '3';
             $prefix = 'e2015';
         }
         $new_registration['username_prefix'] = $prefix;
         $new_registration['registration_period_id'] = $period;
         //
         $new_registration['registration_step_id'] = $old_state[$registration->reg_curstatus];
         //var_dump($new_registration->toArray());
         //$new_registration->save();
         $new_registration['created_at'] = new DateTime();
         $new_registration['updated_at'] = new DateTime();
         $all_regs[] = $new_registration;
     }
     ///var_dump($all_regs);
     foreach (array_chunk($all_regs, 500) as $chunk) {
         DB::table('registrations')->insert($chunk);
     }
     foreach (Registration::all() as $registration) {
         //$registration->generateCode();
     }
     $this->command->info('registration entered!');
 }