UserController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. namespace App\Http\Controllers\User;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\User;
  7. use App\Models\Note;
  8. use Auth;
  9. use DB;
  10. use App\Models\Attendance;
  11. use Excel;
  12. class UserController extends Controller
  13. {
  14. public function index(){
  15. $user_id = Auth::id();
  16. $user_info = User::find($user_id);
  17. return view('user.profile',compact('user_info'));
  18. }
  19. public function update_profile(Request $request)
  20. {
  21. $this->validate($request, [
  22. 'address' => 'required',
  23. 'per_address' => 'required',
  24. 'mob' => 'required',
  25. 'email' => 'required',
  26. 'joining_date' => 'required',
  27. 'fb' => 'required',
  28. 'skype' => 'required',
  29. 'linkedIn' => 'required',
  30. 'emrgncy_contact' => 'required',
  31. 'emrgncy_contact_phone' => 'required',
  32. ]);
  33. $user_id = Auth::id();
  34. $user_info = User::find($user_id);
  35. $destinationPath = public_path('user/');
  36. $older_user_img= $user_info->image;
  37. if($request->file('user_image') !=''){
  38. if($older_user_img !=''){
  39. @unlink($destinationPath.'/'.$older_user_img);
  40. }
  41. } else {
  42. $user_info->image=$older_user_img;
  43. }
  44. $user_info->address = $request->input('address');
  45. $user_info->per_address = $request->input('per_address');
  46. $user_info->mob = $request->input('mob');
  47. $user_info->mob2 = $request->input('mob2');
  48. $user_info->email = $request->input('email');
  49. $user_info->email2 = $request->input('email2');
  50. $user_info->joining_date = $request->input('joining_date');
  51. $user_info->fb = $request->input('fb');
  52. $user_info->skype = $request->input('skype');
  53. $user_info->linkedIn = $request->input('linkedIn');
  54. $user_info->emrgncy_contact = $request->input('emrgncy_contact');
  55. $user_info->emrgncy_contact_phone = $request->input('emrgncy_contact_phone');
  56. $user_info->save();
  57. if($request->file('user_image') !=''){
  58. $file=$request->file('user_image');
  59. $originalName =$file->getClientOriginalName();
  60. $extension = $file->getClientOriginalExtension();
  61. $imageName = 'user_'.$user_id.'.'.$extension;
  62. $file->move($destinationPath, $imageName);
  63. $image_name=$imageName;
  64. DB::table('users')->where('id','=',$user_id)->update(array('image'=>$image_name));
  65. }
  66. return redirect()->action('User\UserController@index')->with('success','Profile Updated successfully');
  67. }
  68. public function group(){
  69. return "group";
  70. }
  71. public function add_note(Request $req)
  72. {
  73. $note = $req->note;
  74. $date_time = $req->date_time;
  75. $sav = new Note;
  76. $sav->note = $note;
  77. $sav->user_id = Auth::user()->id;
  78. $sav->time = $date_time;
  79. $sav->save();
  80. return redirect()->back();
  81. }
  82. public function change_note_status($id){
  83. $ch = Note::find($id);
  84. if($ch->status == 1){
  85. $ch->status = 0;
  86. }
  87. else{
  88. $ch->status = 1;
  89. }
  90. $ch->save();
  91. return redirect()->back();
  92. }
  93. public function remove_note($id){
  94. $del = Note::find($id)->delete();
  95. return redirect()->back();
  96. }
  97. public function attend_entry()
  98. {
  99. $title="Attendance Entry";
  100. return view('user.list',compact('title'));
  101. }
  102. public function attendace_sheet_entry(Request $request)
  103. {
  104. date_default_timezone_set("Asia/Dhaka");
  105. //
  106. //
  107. if($request->file('import_file') !=''){
  108. $path = $request->file('import_file')->getRealPath();
  109. $data = Excel::load($path, function($reader) {})->get();
  110. if(!empty($data) && $data->count()){
  111. foreach ($data->toArray() as $key => $value) {
  112. if( (int)$value['user_id'] == 1)
  113. {
  114. $user_name = 'Reza';
  115. }
  116. else if((int)$value['user_id'] == 2)
  117. {
  118. $user_name = 'Mamun';
  119. }
  120. else if((int)$value['user_id'] == 3)
  121. {
  122. $user_name = 'Golam Sayed';
  123. }
  124. else if((int)$value['user_id'] == 4)
  125. {
  126. $user_name = 'Akib';
  127. }
  128. else if((int)$value['user_id'] == 5)
  129. {
  130. $user_name = 'Masum';
  131. }
  132. else if((int)$value['user_id'] == 6)
  133. {
  134. $user_name = 'Helal';
  135. }
  136. else if((int)$value['user_id'] == 7)
  137. {
  138. $user_name = 'Zeba';
  139. }
  140. else if((int)$value['user_id'] == 8)
  141. {
  142. $user_name = 'Shabuj';
  143. }
  144. else if((int)$value['user_id'] == 9)
  145. {
  146. $user_name = 'Hasib';
  147. }
  148. else if((int)$value['user_id'] == 10)
  149. {
  150. $user_name = 'Tipu';
  151. }
  152. else if((int)$value['user_id'] == 11)
  153. {
  154. $user_name = 'Niloy';
  155. }
  156. else if((int)$value['user_id'] == 12)
  157. {
  158. $user_name = 'Nishat';
  159. }
  160. else if((int)$value['user_id'] == 13)
  161. {
  162. $user_name = 'Jamil';
  163. }
  164. else if((int)$value['user_id'] == 14)
  165. {
  166. $user_name = 'Shamim';
  167. }
  168. else if((int)$value['user_id'] == 15)
  169. {
  170. $user_name = 'Payer';
  171. }
  172. $att_time = date('Y-m-d H:i:s',strtotime($value['attendance_time']));
  173. $absent_count=(int)$value['absent_count'];
  174. if($user_name != 'Hasib'){
  175. $insert[] = ['user_id'=>(int)$value['user_id'],'user_name' => $user_name, 'attendance_time' =>$att_time,'absent_count'=>$absent_count,'status'=>(int)$value['status']];
  176. }
  177. }
  178. if(!empty($insert)){
  179. Attendance::insert($insert);
  180. return redirect()->action('User\UserController@attend_entry')->with('success', 'Data Added!');
  181. }
  182. }
  183. }
  184. return back()->with('success','Please Check your file, Something is wrong there.');
  185. }
  186. public function leave_apply()
  187. {
  188. $title = "Apply For Leave";
  189. $leave_type = DB::table('leave_type_head')->where('is_published','=',1)->get();
  190. $users = User::where('utype',1)->where('active',1)->orderBy('name','ASC')->get();
  191. return view('user.leave',compact('title','leave_type','users'));
  192. }
  193. public function leave_req(Request $request)
  194. {
  195. $purpose= $request->purpose;
  196. $apply_to= 2;
  197. $from= $request->get('from',date('Y-m-d H:i:s'));
  198. $to= $request->get('to',date('Y-m-d H:i:s'));
  199. $from_day = strtotime($from);
  200. $to_day = strtotime($to);
  201. $days_between = (ceil(abs( $to_day - $from_day) / 86400))+1;
  202. $description = $request->description;
  203. $approval = 0;
  204. $created_at = date('Y-m-d H:i:s');
  205. $user_id = Auth::id();
  206. DB::table('leave_req')->insert(array(
  207. 'purpose'=>$purpose,
  208. 'apply_to'=>$apply_to,
  209. 'from'=>$from,
  210. 'to'=>$to,
  211. 'days'=>$days_between,
  212. 'description'=>$description,
  213. 'approval'=>$approval,
  214. 'created_at'=>$created_at,
  215. 'user_id'=>$user_id,
  216. ));
  217. return redirect()->action('User\UserController@leave_apply')->with('success','Sccessfully Sent !');
  218. }
  219. }