EmployeeController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use DB;
  7. use Redirect;
  8. use Input;
  9. use Validator;
  10. use App\Models\Employee;
  11. use App\Models\PayrollHistory;
  12. use App\Models\EmployeeEducation;
  13. use App\Models\EmployeeDocument;
  14. use App\Models\EducationLevel;
  15. use App\Models\DocumentType;
  16. use App\Models\Grade;
  17. use App\Models\Designation;
  18. use App\Models\EmploymentDetail;
  19. use App\Models\employee_reference;
  20. use App\Models\EmployeeWorkExperience;
  21. use App\Models\PayrollStructure;
  22. use App\Models\GradeStructure;
  23. use App\Models\PayrollStructureDetail;
  24. use App\Models\Role;
  25. use App\User;
  26. class EmployeeController extends Controller
  27. {
  28. public function index()
  29. {
  30. $data['title'] = "Employee management";
  31. $data['all'] = Employee::with('user')->orderBy('name','ASC')->get();
  32. return view('admin.employee.employee',$data);
  33. }
  34. public function create()
  35. {
  36. $data['title'] = "Employee management";
  37. $data['all_document'] = DocumentType::where('status',1)->orderBy('document_name','ASC')->get();
  38. $data['all_level'] = EducationLevel::where('status',1)->orderBy('level_name','ASC')->get();
  39. $data['all_grade'] = grade::where('status',1)->orderBy('name','ASC')->get();
  40. $data['all_designation'] = Designation::where('status',1)->orderBy('name','ASC')->get();
  41. return view('admin.employee.employee_add',$data);
  42. }
  43. public function store(Request $request)
  44. {
  45. //dd($request->all());
  46. $this->validate($request,[
  47. 'name' => 'required',
  48. 'personal_email' => 'required|email|unique:employees,personal_email',
  49. 'phone' => 'required',
  50. 'present_address' => 'required',
  51. 'birth_day' => 'required',
  52. 'joining_date' => 'required',
  53. 'current_designation' => 'required',
  54. 'salary_grade' => 'required'
  55. ]);
  56. $user_id = \Auth::user()->id;
  57. $employee_info = new Employee;
  58. $employee_info->name = $request->name;
  59. $employee_info->personal_email = $request->personal_email;
  60. $employee_info->phone = $request->phone;
  61. $employee_info->phone2 = $request->phonetwo;
  62. $employee_info->present_address = $request->present_address;
  63. $employee_info->per_address = $request->per_address;
  64. $employee_info->birth_day = $request->birth_day;
  65. $employee_info->note = $request->note;
  66. $employee_info->facebook = $request->facebook;
  67. $employee_info->skype = $request->skype;
  68. $employee_info->linkedin = $request->linkedin;
  69. $employee_info->added_by = $user_id;
  70. $employee_info->status = 1;
  71. if (!empty($request->file('image'))) {
  72. $file =$request->file('image');
  73. $destPath = 'assets/document/employee/';
  74. $fileName = $file->getClientOriginalName();
  75. $newFile = "employee_".date('d_m_y_h_m_s')."_".$fileName;
  76. $file->move($destPath, $newFile);
  77. $employee_info->image = $newFile;
  78. }
  79. $employee_info->save();
  80. $emp_details = new EmploymentDetail;
  81. $emp_details->employee_id = $employee_info->id;
  82. $emp_details->designation_id = $request->current_designation;
  83. $emp_details->grade_id = $request->salary_grade;
  84. $emp_details->joining_date = $request->joining_date;
  85. $emp_details->type = "1";
  86. $emp_details->added_by = $user_id;
  87. $emp_details->save();
  88. $prst = new PayrollStructure;
  89. $prst->employee_id = $employee_info->id;
  90. $prst->grade_id = $request->salary_grade;
  91. $prst->type = "1";
  92. $prst->date = $request->joining_date;
  93. $prst->added_by = $user_id;
  94. $prst->save();
  95. if (!empty($request->file('file') && !empty($request->document_id))) {
  96. $files = $request->file('file');
  97. foreach($files as $key => $file) {
  98. $destinationPath = 'assets/document/employeedocument/';
  99. $extension = $file->getClientOriginalExtension();
  100. $filename = $file->getClientOriginalName();
  101. $newFileName = "document_".date('d_m_y_h_m_s')."_".$filename;
  102. $file->move($destinationPath, $newFileName);
  103. $document = new EmployeeDocument;
  104. $document->document_id = $request['document_id'][$key];
  105. $document->employee_id = $employee_info->id;
  106. $document->file = $newFileName;
  107. $document->status = 1;
  108. $document->added_by = $user_id ;
  109. $document->save();
  110. }
  111. }
  112. if (!empty($request->edu_level) && !empty($request->institute) && !empty($request->major) && !empty($request->marks) && !empty($request->passing_year) ) {
  113. $input = $request->all();
  114. $condition = $input['edu_level'];
  115. foreach ($condition as $key => $condition) {
  116. $student = new EmployeeEducation;
  117. $student->edu_level_id = $input['edu_level'][$key];
  118. $student->institute_name = $input['institute'][$key];
  119. $student->major = $input['major'][$key];
  120. $student->marks = $input['marks'][$key];
  121. $student->passing_year = $input['passing_year'][$key];
  122. $student->duration = $input['duration'][$key];
  123. $student->employee_id = $employee_info->id ;
  124. $student->status = 1 ;
  125. $student->added_by = $user_id ;
  126. $student->save();
  127. }
  128. }
  129. if (!empty($request->org_name) && !empty($request->org_contact) && !empty($request->designation) && !empty($request->start_date) && !empty($request->end_date) ) {
  130. $input = $request->all();
  131. $condition = $input['org_name'];
  132. foreach ($condition as $key => $condition) {
  133. $ewe = new EmployeeWorkExperience;
  134. $ewe->org_name = $input['org_name'][$key];
  135. $ewe->org_contact = $input['org_contact'][$key];
  136. $ewe->designation_id = $input['designation'][$key];
  137. $ewe->start_date = $input['start_date'][$key];
  138. $ewe->end_date = $input['end_date'][$key];
  139. $ewe->employee_id = $employee_info->id ;
  140. $ewe->added_by = $user_id ;
  141. $ewe->save();
  142. }
  143. }
  144. if ($request->person_name !="" && $request->relation !="" && $request->phone1 !="" && $request->address !="" ) {
  145. $input = $request->all();
  146. $condition = $input['person_name'];
  147. foreach ($condition as $key => $condition) {
  148. $employee_ref = new employee_reference;
  149. $employee_ref->person_name = $input['person_name'][$key];
  150. $employee_ref->relation = $input['relation'][$key];
  151. $employee_ref->phone1 = $input['phone1'][$key];
  152. $employee_ref->phone2 = $input['phone2'][$key];
  153. $employee_ref->email = $input['email'][$key];
  154. $employee_ref->address = $input['address'][$key];
  155. $employee_ref->employee_id = $employee_info->id ;
  156. $employee_ref->status = 1 ;
  157. $employee_ref->added_by = $user_id ;
  158. $employee_ref->save();
  159. }
  160. }
  161. return redirect('admin/employee')->with('msg','Data Insert Successful!');
  162. }
  163. public function show($id)
  164. {
  165. $data['title'] = "Employee Information";
  166. $data['employee'] = Employee::find($id);
  167. $data['emp_details'] = EmploymentDetail::with(['designation','grade'])->where('employee_id',$id)->orderBy('id','DESC')->first();
  168. $data['emp_history'] = EmploymentDetail::with(['designation','grade'])->where('employee_id',$id)->orderBy('id','ASC')->get();
  169. $data['emp_star'] = EmploymentDetail::where('employee_id',$id)->where('type',2)->select('id')->get();
  170. $data['employee_ewe'] = EmployeeWorkExperience::with('designation')->where('employee_id',$id)->orderBy('start_date','DESC')->get();
  171. $data['pay_history'] = PayrollHistory::where('employee_id',$id)->orderBy('id','DESC')->get();
  172. $data['ref_info'] = employee_reference::where('employee_id',$id)->first();
  173. $data['employee_document'] = EmployeeDocument::with('document_type')->where('employee_id',$id)->get();
  174. $data['employee_education'] = EmployeeEducation::with('education_name')->where('employee_id',$id)->get();
  175. $data['last_education'] = EmployeeEducation::with('education_name')->where('employee_id',$id)->orderBy('passing_year','DESC')->first();
  176. $data['employee_ref'] = employee_reference::where('employee_id',$id)->get();
  177. return view('admin.employee.employee_view',$data);
  178. }
  179. public function editEmployee($id)
  180. {
  181. $data['title'] = "Employee Edit";
  182. $data['all_document'] = DocumentType::where('status',1)->orderBy('document_name','ASC')->get();
  183. $data['all_level'] = EducationLevel::where('status',1)->orderBy('level_name','ASC')->get();
  184. $data['employee'] = Employee::find($id);
  185. $data['employee_document'] = EmployeeDocument::where('employee_id',$id)->get();
  186. $data['all_grade'] = grade::where('status',1)->orderBy('name','ASC')->get();
  187. $data['all_designation'] = Designation::where('status',1)->orderBy('name','ASC')->get();
  188. $data['emp_details'] = EmploymentDetail::where('employee_id',$id)->orderBy('id','ASC')->get();
  189. $data['employee_ewe'] = EmployeeWorkExperience::where('employee_id',$id)->orderBy('start_date','DESC')->get();
  190. $data['employee_education'] = EmployeeEducation::where('employee_id',$id)->get();
  191. $data['employee_ref'] = employee_reference::where('employee_id',$id)->get();
  192. return view('admin.employee.employee_edit',$data);
  193. }
  194. public function update(Request $request, $id)
  195. {
  196. $user_id = \Auth::user()->id;
  197. $this->validate($request,[
  198. 'name' => 'required',
  199. 'personal_email' => 'required|email',
  200. 'phone' => 'required',
  201. 'present_address' => 'required',
  202. 'birth_day' => 'required'
  203. ]);
  204. $user_id = \Auth::user()->id;
  205. $employee_info = Employee::find($id);
  206. $employee_info->name = $request->name;
  207. $employee_info->personal_email = $request->personal_email;
  208. $employee_info->phone = $request->phone;
  209. $employee_info->phone2 = $request->phonetwo;
  210. $employee_info->present_address = $request->present_address;
  211. $employee_info->per_address = $request->per_address;
  212. $employee_info->birth_day = $request->birth_day;
  213. $employee_info->note = $request->note;
  214. $employee_info->facebook = $request->facebook;
  215. $employee_info->skype = $request->skype;
  216. $employee_info->linkedin = $request->linkedin;
  217. $employee_info->updated_by = $user_id;
  218. if (!empty($request->file('image'))) {
  219. $file =$request->file('image');
  220. $destPath = 'assets/document/employee/';
  221. $fileName = $file->getClientOriginalName();
  222. $newFile = "employee_".date('d_m_y_h_m_s')."_".$fileName;
  223. $file->move($destPath, $newFile);
  224. $employee_info->image = $newFile;
  225. }
  226. $employee_info->save();
  227. // if not add new Employment History
  228. if (!empty($request->joining_date) && !empty($request->current_designation) && !empty($request->salary_grade)) {
  229. $input = $request->all();
  230. $condition = $input['joining_date'];
  231. foreach ($condition as $key => $condition) {
  232. $emp_we_id = $input['emp_we_id'][$key];
  233. $emp_details =EmploymentDetail::find($emp_we_id);
  234. $emp_details->designation_id = $input['current_designation'][$key];
  235. $emp_details->grade_id = $input['salary_grade'][$key];
  236. $emp_details->joining_date = $input['joining_date'][$key];
  237. $emp_details->updated_by = $user_id ;
  238. $emp_details->save();
  239. }
  240. //Payroll Structure
  241. $find = PayrollStructure::where('employee_id',$employee_info->id)->first();
  242. if ($find==NULL) {
  243. $prst = new PayrollStructure;
  244. $prst->employee_id = $employee_info->id;
  245. $prst->grade_id = $emp_details->grade_id;
  246. $prst->date =$emp_details->joining_date;
  247. $prst->added_by = $user_id;
  248. $prst->type = 1;
  249. $prst->save();
  250. }
  251. else{
  252. $prstu = PayrollStructure::find($find->id);
  253. $prstu->grade_id = $emp_details->grade_id;
  254. $prstu->date =$emp_details->joining_date;
  255. $prstu->updated_by = $user_id;
  256. $prstu->type = 1;
  257. $prstu->update();
  258. }
  259. }
  260. // if add new Employment History
  261. if (!empty($request->new_emp_we_id)) {
  262. if (!empty($request->joining_date_new) && !empty($request->current_designation_new) && !empty($request->salary_grade_new)) {
  263. $input = $request->all();
  264. $condition = $input['joining_date_new'];
  265. foreach ($condition as $key => $condition) {
  266. $emp_details_new = new EmploymentDetail;
  267. $emp_details_new->employee_id = $id;
  268. $emp_details_new->designation_id = $input['current_designation_new'][$key];
  269. $emp_details_new->grade_id = $input['salary_grade_new'][$key];
  270. $emp_details_new->joining_date = $input['joining_date_new'][$key];
  271. $emp_details_new->type = 2 ;
  272. $emp_details_new->added_by = $user_id ;
  273. $emp_details_new->save();
  274. }
  275. //Payroll Structure
  276. $find = PayrollStructure::where('employee_id',$employee_info->id)->first();
  277. if ($find==NULL) {
  278. $prst = new PayrollStructure;
  279. $prst->employee_id = $employee_info->id;
  280. $prst->grade_id = $emp_details_new->grade_id;
  281. $prst->date =$emp_details_new->joining_date;
  282. $prst->type = 2;
  283. $prst->added_by = $user_id;
  284. $prst->save();
  285. if ($prst->save()) {
  286. PayrollStructureDetail::where('structure_id',$prst->id)->delete();
  287. }
  288. }
  289. else{
  290. $prstu = PayrollStructure::find($find->id);
  291. $prstu->employee_id = $employee_info->id;
  292. $prstu->grade_id = $emp_details_new->grade_id;
  293. $prstu->date =$emp_details_new->joining_date;
  294. $prstu->type = 2;
  295. $prstu->updated_by = $user_id;
  296. $prstu->update();
  297. if ($prstu->update()) {
  298. PayrollStructureDetail::where('structure_id',$prstu->id)->delete();
  299. }
  300. }
  301. }
  302. }
  303. // if not add new File Upload
  304. if (!empty($request->document_id) && !empty($request->file('file'))) {
  305. $files = $request->file('file');
  306. foreach($files as $key => $file) {
  307. $emp_doc_id= $request['emp_doc_id'][$key];
  308. $document =EmployeeDocument::find($emp_doc_id);
  309. if (!empty($request['file'][$key])) {
  310. $destinationPath = 'assets/document/employeedocument/';
  311. $filename = $file->getClientOriginalName();
  312. $newFileName = "document_".date('d_m_y_h_m_s')."_".$filename;
  313. $file->move($destinationPath, $newFileName);
  314. $document->file = $newFileName;
  315. }
  316. $document->document_id = $request['document_id'][$key];
  317. $document->updated_by = $user_id ;
  318. $document->save();
  319. }
  320. }
  321. // if add new File Upload
  322. if (!empty($request->new_doc_id)) {
  323. if (!empty($request->file('file_new') && !empty($request->document_id_new))) {
  324. $files = $request->file('file_new');
  325. foreach($files as $key => $file) {
  326. $destinationPath = 'assets/document/employeedocument/';
  327. $filename = $file->getClientOriginalName();
  328. $newFileName = "document_".date('d_m_y_h_m_s')."_".$filename;
  329. $file->move($destinationPath, $newFileName);
  330. $document = new EmployeeDocument;
  331. $document->document_id = $request['document_id_new'][$key];
  332. $document->employee_id = $id;
  333. $document->file = $newFileName;
  334. $document->status = 1;
  335. $document->added_by = $user_id ;
  336. $document->save();
  337. }
  338. }
  339. }
  340. // if not add new Academic Information
  341. if (!empty($request->edu_level) && !empty($request->institute) && !empty($request->major) && !empty($request->marks) && !empty($request->passing_year) ) {
  342. $input = $request->all();
  343. $condition = $input['edu_level'];
  344. foreach ($condition as $key => $condition) {
  345. $emp_edu_id = $input['emp_edu_id'][$key];
  346. $student =EmployeeEducation::find($emp_edu_id);
  347. $student->edu_level_id = $input['edu_level'][$key];
  348. $student->institute_name = $input['institute'][$key];
  349. $student->major = $input['major'][$key];
  350. $student->marks = $input['marks'][$key];
  351. $student->passing_year = $input['passing_year'][$key];
  352. $student->duration = $input['duration'][$key];
  353. $student->updated_by = $user_id ;
  354. $student->save();
  355. }
  356. }
  357. // if add new Academic Information
  358. if (!empty($request->new_edu_id)) {
  359. if (!empty($request->edu_level_new) && !empty($request->institute_new) && !empty($request->major_new) && !empty($request->marks_new) && !empty($request->passing_year_new) ) {
  360. $input = $request->all();
  361. $condition = $input['edu_level_new'];
  362. foreach ($condition as $key => $condition) {
  363. $student = new EmployeeEducation;
  364. $student->edu_level_id = $input['edu_level_new'][$key];
  365. $student->institute_name = $input['institute_new'][$key];
  366. $student->major = $input['major_new'][$key];
  367. $student->marks = $input['marks_new'][$key];
  368. $student->passing_year = $input['passing_year_new'][$key];
  369. $student->duration = $input['duration_new'][$key];
  370. $student->employee_id = $id ;
  371. $student->status = 1 ;
  372. $student->added_by = $user_id ;
  373. $student->save();
  374. }
  375. }
  376. }
  377. // if not add new Work Experience
  378. if (!empty($request->org_name) && !empty($request->org_contact) && !empty($request->designation) && !empty($request->start_date) && !empty($request->end_date) ) {
  379. $input = $request->all();
  380. $condition = $input['org_name'];
  381. foreach ($condition as $key => $condition) {
  382. $emp_exp_id = $input['emp_exp_id'][$key];
  383. $ewe = EmployeeWorkExperience::find($emp_exp_id);
  384. $ewe->org_name = $input['org_name'][$key];
  385. $ewe->org_contact = $input['org_contact'][$key];
  386. $ewe->designation_id = $input['designation'][$key];
  387. $ewe->start_date = $input['start_date'][$key];
  388. $ewe->end_date = $input['end_date'][$key];
  389. $ewe->updated_by = $user_id ;
  390. $ewe->save();
  391. }
  392. }
  393. // if add new Work Experience
  394. if (!empty($request->org_name_new) && !empty($request->org_contact_new) && !empty($request->designation_new) && !empty($request->start_date_new) && !empty($request->end_date_new) ) {
  395. $input = $request->all();
  396. $condition = $input['org_name_new'];
  397. foreach ($condition as $key => $condition) {
  398. $ewe = new EmployeeWorkExperience;
  399. $ewe->org_name = $input['org_name_new'][$key];
  400. $ewe->org_contact = $input['org_contact_new'][$key];
  401. $ewe->designation_id = $input['designation_new'][$key];
  402. $ewe->start_date = $input['start_date_new'][$key];
  403. $ewe->end_date = $input['end_date_new'][$key];
  404. $ewe->employee_id = $employee_info->id ;
  405. $ewe->added_by = $user_id ;
  406. $ewe->save();
  407. }
  408. }
  409. // if not add new Reference / Emergence Contact
  410. if (!empty($request->person_name) && !empty($request->relation) && !empty($request->phone1) && !empty($request->address)) {
  411. $input = $request->all();
  412. $condition = $input['person_name'];
  413. foreach ($condition as $key => $condition) {
  414. $emp_ref_id = $input['emp_ref_id'][$key];
  415. $student =employee_reference::find($emp_ref_id);
  416. $student->person_name = $input['person_name'][$key];
  417. $student->relation = $input['relation'][$key];
  418. $student->phone1 = $input['phone1'][$key];
  419. $student->phone2 = $input['phone2'][$key];
  420. $student->email = $input['email'][$key];
  421. $student->address = $input['address'][$key];
  422. $student->updated_by = $user_id ;
  423. $student->save();
  424. }
  425. }
  426. // if add new Reference / Emergence Contact
  427. if (!empty($request->new_ref_id)) {
  428. if (!empty($request->person_name_new) && !empty($request->relation_new) && !empty($request->phone1_new) && !empty($request->address_new)) {
  429. $input = $request->all();
  430. $condition = $input['person_name_new'];
  431. foreach ($condition as $key => $condition) {
  432. $employee_ref = new employee_reference;
  433. $employee_ref->person_name = $input['person_name_new'][$key];
  434. $employee_ref->relation = $input['relation_new'][$key];
  435. $employee_ref->phone1 = $input['phone1_new'][$key];
  436. $employee_ref->phone2 = $input['phone2_new'][$key];
  437. $employee_ref->email = $input['email_new'][$key];
  438. $employee_ref->address = $input['address_new'][$key];
  439. $employee_ref->employee_id = $employee_info->id ;
  440. $employee_ref->status = 1 ;
  441. $employee_ref->added_by = $user_id ;
  442. $employee_ref->save();
  443. }
  444. }
  445. }
  446. return redirect('admin/employee')->with('msg','Data Updated Successful!');
  447. }
  448. /**
  449. * Remove the specified resource from storage.
  450. *
  451. * @param int $id
  452. * @return \Illuminate\Http\Response
  453. */
  454. public function destroy($id)
  455. {
  456. Employee::whereId($id)->delete();
  457. EmploymentDetail::where('employee_id',$id)->delete();
  458. EmployeeWorkExperience::where('employee_id',$id)->delete();
  459. EmployeeEducation::where('employee_id',$id)->delete();
  460. EmployeeDocument::where('employee_id',$id)->delete();
  461. PayrollStructure::where('employee_id',$id)->delete();
  462. return redirect('admin/employee')->with('msg','Successfully Deleted!');
  463. }
  464. public function statusUpdate($id)
  465. {
  466. $employee = Employee::find($id);
  467. if($employee->status == 0){
  468. $employee->status = 1;
  469. $status = 'published';
  470. }else{
  471. $employee->status = 0;
  472. $status = 'unpublished';
  473. }
  474. $user_id = \Auth::user()->id;
  475. $employee->approved_by = $user_id;
  476. $employee->update();
  477. }
  478. public function addUser($id)
  479. {
  480. $data['title'] = "Employee to User";
  481. $data['employee'] = Employee::find($id);
  482. $data['roles']=Role::orderBy('name','ASC')->get();
  483. return view('admin.employee.employee_to_user',$data);
  484. }
  485. public function addToUser(Request $request,$id)
  486. {
  487. $this->validate($request,[
  488. 'email' => 'required|email|unique:users,email',
  489. 'password' => 'required',
  490. 'confirm_password' => 'required|same:password',
  491. 'role' => 'required',
  492. ]);
  493. $employee = Employee::find($id);
  494. $name = $employee->name;
  495. $email = $request->email;
  496. $phone = $employee->phone;
  497. $present_address = $employee->present_address;
  498. $per_address = $employee->per_address;
  499. $facebook = $employee->facebook;
  500. $skype = $employee->skype;
  501. $linkedin = $employee->linkedin;
  502. $password = bcrypt($request->password);
  503. $user = new User;
  504. $user->name = $name;
  505. $user->email = $email;
  506. $user->password = $password;
  507. $user->mob = $phone;
  508. $user->address = $present_address;
  509. $user->per_address = $per_address;
  510. $user->fb = $facebook;
  511. $user->skype = $skype;
  512. $user->linkedin = $linkedin;
  513. $user->employee_id = $employee->id;
  514. $user->active = 1;;
  515. $user->utype = 2;
  516. $user->save();
  517. if (!empty($request->input('role'))) {
  518. $user->attachRole($request->role);
  519. }
  520. return redirect('admin/employee')->with('msg','Employee To User Add Successful !');
  521. }
  522. public function changePassword(Request $request)
  523. {
  524. $this->validate($request,[
  525. 'password' => 'required',
  526. 'password_confirmation' => 'required|same:password',
  527. ]);
  528. $emp_id = $request->emp_id;
  529. $password = bcrypt($request->password);
  530. $user = User::find($emp_id);
  531. $user->password = $password;
  532. $user->update();
  533. return redirect('admin/employee')->with('msg','Password Change Successful !');
  534. }
  535. public function rejoining(Request $request)
  536. {
  537. $user_id = \Auth::user()->id;
  538. $emp_id = $request->emp_id;
  539. $emp_data = EmploymentDetail::where('employee_id',$emp_id)->orderBy('id','DESC')->first();
  540. $findre = PayrollStructure::where('employee_id',$emp_id)->first();
  541. $emp = Employee::find($emp_id);
  542. $emp->status = 4;
  543. $emp->added_by = $user_id;
  544. $emp->save();
  545. $rejoining = new EmploymentDetail;
  546. $rejoining->employee_id = $emp_id;
  547. $rejoining->designation_id = $emp_data->designation_id;
  548. $rejoining->grade_id = $emp_data->grade_id;
  549. $rejoining->joining_date = $request->rejoining_date;
  550. $rejoining->type = 4;
  551. $rejoining->added_by = $user_id;
  552. $rejoining->save();
  553. $prstre = PayrollStructure::find($findre->id);
  554. $prstre->type = 4;
  555. $prstre->update();
  556. return redirect()->back()->with('msg','Employee Rejoining Successfully. !');
  557. }
  558. }