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 .="";
//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."
";
}
//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 .="";
$str .="* $fet->comment -by ".$fet->user->name;
if(!empty($fet->url)){
$str .="
url").">
";
}
$str .="
";
}
}
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 .="";
$str .= $fetch->user->name."
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();
}
}