123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace App\Http\Controllers\Client;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Http\Controllers\Controller;
- use App\Models\Task;
- use App\Models\Project;
- use App\Models\ActivityLog;
- use App\Models\Notification;
- use App\Models\Comment;
- use App\Models\AssignProject;
- use Auth;
- use App\User;
- class CTaskController extends Controller
- {
- public function add_task(Request $request){
-
- $name = $request->name;
- $proj_id = $request->proj_id;
- $description = $request->description;
- $estimated_time = $request->estimated_time;
- $task_type = $request->task_type;
- date_default_timezone_set("Asia/Dhaka");
- $cdate = date('Y-m-d H:i:s');
- $sav = new Task;
- $sav->name = $name;
- $sav->type = $task_type;
- $sav->proj_id = $proj_id;
- $sav->description = $description;
- $sav->created_time = $cdate;
- $sav->created_by = Auth::user()->id;
- $sav->status = 1;
- $sav->save();
- //last insert id
- $task_id = $sav->id;
- //activity log
- $msg = "Task: $name created.";
- $this->project_log($msg,$proj_id); //call function
- $this->task_log($msg,$task_id,$proj_id); //call function
- //notification
- $fet_pro = Project::find($proj_id);
- $projj_name = $fet_pro->name;
- $adminss = User::where('utype',1)->get();
-
- $post_by_name = Auth::user()->name;
- $post_by_id = Auth::user()->id;
- $msg = "Task:$name created in Proj:$projj_name by ".$post_by_name;
- foreach($adminss as $info){
- $this->notification($info->id, $msg);
- }
- $ass_usr = AssignProject::where('proj_id',$proj_id)->get();
- if(count($ass_usr) > 0){
- foreach($ass_usr as $info){
- if($info->user_id != $post_by_id){
- $this->notification($info->user_id, $msg);
- }
- }
- }
- //--end notification
- return redirect()->back()->with('message','Success');
- }
- public function remove_task($id)
- {
- $del = Task::find($id);
- //activity log
- $msg = "Task:".$del->name." removed.";
- $this->project_log($msg,$del->proj_id); //call function
- //notification
- $projj_name = Project::find($del->proj_id)->name;
- $name = $del->name;
- $adminss = User::where('utype',1)->get();
-
- $post_by_name = Auth::user()->name;
- $post_by_id = Auth::user()->id;
- $msg = "Task:$name removed from Proj:$projj_name by ".$post_by_name;
- foreach($adminss as $info){
- $this->notification($info->id, $msg);
- }
-
- $ass_usr = AssignProject::where('proj_id',$del->proj_id)->get();
- if(count($ass_usr) > 0){
- foreach($ass_usr as $info){
- if($info->user_id != $post_by_id){
- $this->notification($info->user_id, $msg);
- }
- }
- }
- //end notification
- $del->delete();
- return redirect()->back()->with('data','Delete successfully !!');
- }
- public function user_list_for_task_assign(Request $req){
- $proj_id = $req->proj_id;
- $task_id = $req->task_id;
- $all = AssignProject::with('one_user')->where('proj_id',$proj_id)->get();
- $str = "";
- $str .="<select>";
- foreach($all as $info){
- $str .="<option value={$info->user_id}>".$info->one_user->name."</option>";
- }
- $str .="</select>";
- //getting status of this task
- $task_sta = Task::find($task_id);
- $task_status = $task_sta->status;
- if(!empty($task_sta->description))
- {
- $details = $task_sta->description;
- }
- else{
- $details = "No details...";
- }
- //tast already assigned user
- $str1 = $this->fetch_task_assign_user($task_id); //call function
- //activity log fetch
- $logss = ActivityLog::with('one_user')->where('task_id',$task_id)->orderBy('id','DESC')->get();
- $str_log = "";
- foreach($logss as $log){
- $str_log .="* $log->msg -".$log->one_user->name."<br>";
- }
- //comments fetch
- $str_comment = $this->fetch_comments($task_id);
- $data[0] = $str;
- $data[1] = $str1;
- $data[2] = $str_log;
- $data[3] = $str_comment;
- $data[4] = $task_status;
- $data[5] = $details;
- return $data;
- }
- public function add_task_comment(Request $req){
- $comment = $req->comment;
- $task_id = $req->task_id;
- date_default_timezone_set("Asia/Dhaka");
- $assign_time = date('Y-m-d H:i:s');
- if(!empty($comment) && $task_id > 0){
- $sav = new Comment;
- $sav->comment = $comment;
- $sav->task_id = $task_id;
- $sav->date_time = $assign_time;
- $sav->post_by = Auth::user()->id;
- $sav->save();
- }
- //activity log
- $task_info = Task::find($task_id);
- $task_name = $task_info->name;
- $proj_id = $task_info->proj_id;
- $user_id = $task_info->user_id;
- $msg = "$comment -added to $task_name.";
- $this->task_log($msg,$task_id,$proj_id); //call function
- //notification
- $fetch_proj = Project::find($proj_id);
- $projj_name = $fetch_proj->name;
- $adminss = User::where('utype',1)->get();
- $notification_post_by = Auth::user()->name;
- $noti_post_by_id = Auth::user()->id;
- $msg = "A comment added in Task:$task_name of Proj:$projj_name by ".$notification_post_by;
-
- foreach($adminss as $info){
- $this->notification($info->id, $msg);
- }
-
- $this->notification($user_id, $msg);
- //--------end notification
- $str = $this->fetch_comments($task_id);
- return $str;
- }
- public function fetch_comments($task_id){
- $fetch = Comment::with('user')->where('task_id',$task_id)->orderBy('id','DESC')->get();
- $str = "";
- if(count($fetch) > 0){
-
- foreach($fetch as $fet)
- {
- $immmgg = "assets/document/task/$fet->url";
- $str .="<input type='hidden' value=".$fet->id.">";
- $str .="* $fet->comment -by ".$fet->user->name;
-
- if(!empty($fet->url)){
- $str .="<br/><a target='_blank' href=".url("assets/document/task/$fet->url").">
- <img height='150' width='120' src='".asset($immmgg)."'></a>";
- }
-
- $str .="<span style='color:#FD4B39;cursor:pointer;margin-left:10px' data-id='".$fet->id."' class='edit_comment pull-right'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></span>
- <span style='color:#FD4B39;cursor:pointer;' data-id='".$fet->id."' class='remove_comment'><i class='fa fa-times pull-right' aria-hidden='true'></i></span><br/>";
- }
- }
- return $str;
- }
- public function change_to_process(Request $req)
- {
- $task_id = $req->task_id;
- $status = $req->status;
- date_default_timezone_set("Asia/Dhaka");
- $t_time = date('Y-m-d H:i:s');
- $sav = Task::find($task_id);
- $sav->status = $status;
- $task_name = $sav->name;
- if($status == 2){
- $sav->start_time = $t_time;
- }
- elseif($status == 6){
- $sav->closing_time = $t_time;
- }
- //fetch proj_id for activity log
- $proj_id = $sav->proj_id;
-
- if($sav->save())
- {
- $text = "";
- if($status == 2){ $text = "in-process"; }
- elseif($status == 3){ $text = "completed"; }
- elseif($status == 4){ $text = "checking"; }
- elseif($status == 5){ $text = "bug-fixing"; }
- elseif($status == 6){ $text = "done"; }
- $msg = "$task_name -Change status to: $text";
- $this->task_log($msg,$task_id,$proj_id); //call function
-
- return "Yes";
- }
- else{
- return "No";
- }
- }
- public function task_log($msg,$task_id,$proj_id)
- {
- date_default_timezone_set("Asia/Dhaka");
- $assign_time = date('Y-m-d H:i:s');
- $sav = new ActivityLog;
- $sav->msg = $msg;
- $sav->task_id = $task_id;
- $sav->proj_id = $proj_id;
- $sav->logged_user_id = Auth::user()->id;
- $sav->created_at = $assign_time;
- $sav->save();
- }
- public function project_log($msg,$proj_id)
- {
- date_default_timezone_set("Asia/Dhaka");
- $assign_time = date('Y-m-d H:i:s');
- $sav = new ActivityLog;
- $sav->msg = $msg;
- $sav->proj_id = $proj_id;
- $sav->logged_user_id = Auth::user()->id;
- $sav->created_at = $assign_time;
- $sav->save();
- }
- public function fetch_task_assign_user($task_id)
- {
- $fetch = Task::with('user')->find($task_id);
- $str = "";
- if($fetch->user_id > 0){
- $str .="<input type='hidden' value=".$fetch->id.">";
- $str .= $fetch->user->name."<br>Estimated time: ".$fetch->estimated_time;
- }
- else{
- $str .= "No user assigned";
- }
- return $str;
- }
- public function notification($user_id,$msg){
- $sav = new Notification;
- $sav->user_id = $user_id;
- $sav->msg = $msg;
- $sav->status = 1;
- $sav->save();
- }
- }
|