123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace App\Http\Controllers\User;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Http\Controllers\Controller;
- use App\User;
- use App\Models\Note;
- use Auth;
- use DB;
- use App\Models\Attendance;
- use Excel;
- class UserController extends Controller
- {
- public function index(){
- $user_id = Auth::id();
- $user_info = User::find($user_id);
- return view('user.profile',compact('user_info'));
- }
- public function update_profile(Request $request)
- {
- $this->validate($request, [
- 'address' => 'required',
- 'per_address' => 'required',
- 'mob' => 'required',
- 'email' => 'required',
- 'joining_date' => 'required',
- 'fb' => 'required',
- 'skype' => 'required',
- 'linkedIn' => 'required',
- 'emrgncy_contact' => 'required',
- 'emrgncy_contact_phone' => 'required',
- ]);
- $user_id = Auth::id();
- $user_info = User::find($user_id);
- $destinationPath = public_path('user/');
- $older_user_img= $user_info->image;
-
- if($request->file('user_image') !=''){
- if($older_user_img !=''){
- @unlink($destinationPath.'/'.$older_user_img);
- }
- } else {
- $user_info->image=$older_user_img;
- }
- $user_info->address = $request->input('address');
- $user_info->per_address = $request->input('per_address');
- $user_info->mob = $request->input('mob');
- $user_info->mob2 = $request->input('mob2');
- $user_info->email = $request->input('email');
- $user_info->email2 = $request->input('email2');
- $user_info->joining_date = $request->input('joining_date');
- $user_info->fb = $request->input('fb');
- $user_info->skype = $request->input('skype');
- $user_info->linkedIn = $request->input('linkedIn');
- $user_info->emrgncy_contact = $request->input('emrgncy_contact');
- $user_info->emrgncy_contact_phone = $request->input('emrgncy_contact_phone');
- $user_info->save();
- if($request->file('user_image') !=''){
- $file=$request->file('user_image');
- $originalName =$file->getClientOriginalName();
- $extension = $file->getClientOriginalExtension();
- $imageName = 'user_'.$user_id.'.'.$extension;
- $file->move($destinationPath, $imageName);
- $image_name=$imageName;
- DB::table('users')->where('id','=',$user_id)->update(array('image'=>$image_name));
- }
- return redirect()->action('User\UserController@index')->with('success','Profile Updated successfully');
- }
- public function group(){
- return "group";
- }
- public function add_note(Request $req)
- {
- $note = $req->note;
- $date_time = $req->date_time;
- $sav = new Note;
- $sav->note = $note;
- $sav->user_id = Auth::user()->id;
- $sav->time = $date_time;
- $sav->save();
- return redirect()->back();
- }
- public function change_note_status($id){
- $ch = Note::find($id);
- if($ch->status == 1){
- $ch->status = 0;
- }
- else{
- $ch->status = 1;
- }
- $ch->save();
- return redirect()->back();
- }
- public function remove_note($id){
- $del = Note::find($id)->delete();
- return redirect()->back();
- }
- public function attend_entry()
- {
- $title="Attendance Entry";
- return view('user.list',compact('title'));
- }
- public function attendace_sheet_entry(Request $request)
- {
- date_default_timezone_set("Asia/Dhaka");
- //
- //
- if($request->file('import_file') !=''){
- $path = $request->file('import_file')->getRealPath();
- $data = Excel::load($path, function($reader) {})->get();
- if(!empty($data) && $data->count()){
- foreach ($data->toArray() as $key => $value) {
- if( (int)$value['user_id'] == 1)
- {
- $user_name = 'Reza';
- }
- else if((int)$value['user_id'] == 2)
- {
- $user_name = 'Mamun';
- }
- else if((int)$value['user_id'] == 3)
- {
- $user_name = 'Golam Sayed';
- }
- else if((int)$value['user_id'] == 4)
- {
- $user_name = 'Akib';
- }
- else if((int)$value['user_id'] == 5)
- {
- $user_name = 'Masum';
- }
- else if((int)$value['user_id'] == 6)
- {
- $user_name = 'Helal';
- }
- else if((int)$value['user_id'] == 7)
- {
- $user_name = 'Zeba';
- }
- else if((int)$value['user_id'] == 8)
- {
- $user_name = 'Shabuj';
- }
- else if((int)$value['user_id'] == 9)
- {
- $user_name = 'Hasib';
- }
- else if((int)$value['user_id'] == 10)
- {
- $user_name = 'Tipu';
- }
- else if((int)$value['user_id'] == 11)
- {
- $user_name = 'Niloy';
- }
- else if((int)$value['user_id'] == 12)
- {
- $user_name = 'Nishat';
- }
- else if((int)$value['user_id'] == 13)
- {
- $user_name = 'Jamil';
- }
- else if((int)$value['user_id'] == 14)
- {
- $user_name = 'Shamim';
- }
- else if((int)$value['user_id'] == 15)
- {
- $user_name = 'Payer';
- }
- $att_time = date('Y-m-d H:i:s',strtotime($value['attendance_time']));
- $absent_count=(int)$value['absent_count'];
- if($user_name != 'Hasib'){
- $insert[] = ['user_id'=>(int)$value['user_id'],'user_name' => $user_name, 'attendance_time' =>$att_time,'absent_count'=>$absent_count,'status'=>(int)$value['status']];
- }
-
- }
-
- if(!empty($insert)){
- Attendance::insert($insert);
- return redirect()->action('User\UserController@attend_entry')->with('success', 'Data Added!');
-
- }
- }
- }
- return back()->with('success','Please Check your file, Something is wrong there.');
- }
- public function leave_apply()
- {
- $title = "Apply For Leave";
- $leave_type = DB::table('leave_type_head')->where('is_published','=',1)->get();
- $users = User::where('utype',1)->where('active',1)->orderBy('name','ASC')->get();
- return view('user.leave',compact('title','leave_type','users'));
- }
- public function leave_req(Request $request)
- {
- $purpose= $request->purpose;
- $apply_to= 2;
- $from= $request->get('from',date('Y-m-d H:i:s'));
- $to= $request->get('to',date('Y-m-d H:i:s'));
- $from_day = strtotime($from);
- $to_day = strtotime($to);
- $days_between = (ceil(abs( $to_day - $from_day) / 86400))+1;
- $description = $request->description;
- $approval = 0;
- $created_at = date('Y-m-d H:i:s');
- $user_id = Auth::id();
- DB::table('leave_req')->insert(array(
- 'purpose'=>$purpose,
- 'apply_to'=>$apply_to,
- 'from'=>$from,
- 'to'=>$to,
- 'days'=>$days_between,
- 'description'=>$description,
- 'approval'=>$approval,
- 'created_at'=>$created_at,
- 'user_id'=>$user_id,
- ));
- return redirect()->action('User\UserController@leave_apply')->with('success','Sccessfully Sent !');
- }
- }
|