UProjectController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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\Models\Project;
  7. use App\Models\AssignProject;
  8. use App\Models\Group;
  9. use App\Models\Task;
  10. use App\Models\ActivityLog;
  11. use App\Models\Notification;
  12. use App\Models\ProjAttachment;
  13. use App\Models\Note;
  14. use App\User;
  15. use Auth;
  16. use Illuminate\Support\Facades\File;
  17. use Illuminate\Support\Facades\DB;
  18. class UProjectController extends Controller
  19. {
  20. public function index(){
  21. $data['title'] = "User panel";
  22. $data['login_user_id'] = Auth::user()->id;
  23. $user_id = Auth::user()->id;
  24. $project_id = Project::where('is_active',1)->where('client_id',$user_id)->pluck('id')->toArray();
  25. //dd($project_id);
  26. // $data['projj'] = AssignProject::with('proj_name.tasks','one_user','assigned')->whereHas('proj_name', function($a){return $a->where('is_active',1);})->where('user_id',$user_id)->orderBy('id','desc')->get();
  27. //dd($data['projj']);
  28. $data['tasks'] = Task::with('company_name')->where('user_id',$user_id)->where('status','<',6)->orderBy('assign_time','desc')->get();
  29. $data['notes'] = Note::where('user_id',$user_id)->orderBy('time')->get();
  30. $chk = AssignProject::where('pm_status',1)->where('user_id',$user_id)->get();
  31. $proj_id_ary = array();
  32. if(count($chk) > 0)
  33. {
  34. foreach($chk as $info)
  35. {
  36. array_push($proj_id_ary, $info->proj_id);
  37. }
  38. $data['pm_created_task'] = Task::whereIn('proj_id',$proj_id_ary)->where('status',1)->get();
  39. $data['pm_inprocess_task'] = Task::whereIn('proj_id',$proj_id_ary)->where('status',2)->get();
  40. }
  41. return view('user.uprojects',$data);
  42. }
  43. public function add_file(Request $req){
  44. $file = $req->file('file');
  45. $proj_id = $req->proj_id;
  46. date_default_timezone_set("Asia/Dhaka");
  47. if ($req->hasFile('file')) {
  48. $extension = $file->getClientOriginalExtension();
  49. $os = array("jpg", "jpeg", "png", "pdf", "doc", "docx", "txt", "psd");
  50. if (in_array($extension, $os)){
  51. $name = $file->getClientOriginalName();
  52. $newFileName = $newFileName = "proj_".date('d_m_y_h_m_s').".".$extension;;
  53. $fileee = $file->move('assets/document/project/', $newFileName);
  54. //echo $newFileName;
  55. $cat = new ProjAttachment;
  56. $cat->url = $newFileName;
  57. $cat->uploader_id = Auth::user()->id;
  58. $cat->proj_id = $proj_id;
  59. $cat->name = $name;
  60. $cat->save();
  61. $msg = "Add document: $name";
  62. $this->project_log($msg,$proj_id); //call function
  63. //notification
  64. $projj_name = Project::find($proj_id)->name;
  65. $adminss = User::where('utype',1)->get();
  66. foreach($adminss as $info){
  67. $msg = "File:$name added in Proj:$projj_name by ".Auth::user()->name;
  68. $this->notification($info->id, $msg);
  69. }
  70. $ass_usr = AssignProject::where('proj_id',$proj_id)->get();
  71. if(count($ass_usr) > 0){
  72. foreach($ass_usr as $info){
  73. $msg = "File:$name added in Proj:$projj_name by ".Auth::user()->name;
  74. $this->notification($info->user_id, $msg);
  75. }
  76. }
  77. }
  78. }
  79. }
  80. public function uproj_inprocess_pending_task($id){
  81. $data['title'] = "Project details";
  82. $data['users'] = User::where('active',1)->get();
  83. $data['groups'] = Group::where('user_id',0)->get();
  84. $data['self'] = Project::find($id);
  85. $data['project_id'] = $id;
  86. $data['documents'] = ProjAttachment::where('proj_id',$id)->orderBy('id','desc')->get();
  87. $data['proj_assign_user'] = AssignProject::with('one_user')->where('active',1)->where('proj_id',$id)->get();
  88. $user_id = Auth::User()->id;
  89. $chk_pm = AssignProject::where('proj_id',$id)->where('user_id',$user_id)->where('pm_status',1)->get();
  90. if(count($chk_pm) > 0)
  91. {
  92. $data['pending'] = Task::where('proj_id',$id)->where('status',1)->get();
  93. $data['in_process'] = Task::where('proj_id',$id)->whereIn('status',[2,3,4,5])->get();
  94. }
  95. else
  96. {
  97. $data['pending'] = Task::whereIn('user_id', [$user_id,0])->where('proj_id',$id)->where('status',1)->get();
  98. $data['in_process'] = Task::where('user_id',$user_id)->where('proj_id',$id)->whereIn('status',[2,3,4,5])->get();
  99. }
  100. $data['logss'] = ActivityLog::with('one_user')->where('proj_id',$id)->orderBy('created_at','DESC')->take(20)->get();
  101. return view('user.uproj_inprocess_pending_task',$data);
  102. }
  103. public function uproject_details($id){
  104. $data['title'] = "Project details";
  105. $data['users'] = User::where('active',1)->get();
  106. $data['groups'] = Group::where('user_id',0)->get();
  107. $data['self'] = Project::find($id);
  108. $data['project_id'] = $id;
  109. $data['documents'] = ProjAttachment::where('proj_id',$id)->orderBy('id','desc')->get();
  110. $data['proj_assign_user'] = AssignProject::with('one_user')->where('active',1)->where('proj_id',$id)->get();
  111. $user_id = Auth::User()->id;
  112. $chk_pm = AssignProject::where('proj_id',$id)->where('user_id',$user_id)->where('pm_status',1)->get();
  113. if(count($chk_pm) > 0)
  114. {
  115. $data['tasks'] = Task::where('proj_id',$id)->where('status',1)->get();
  116. $data['in_process'] = Task::where('proj_id',$id)->where('status',2)->get();
  117. $data['complete'] = Task::where('proj_id',$id)->where('status',3)->get();
  118. $data['check'] = Task::where('proj_id',$id)->where('status',4)->get();
  119. $data['bug'] = Task::where('proj_id',$id)->where('status',5)->get();
  120. $data['done'] = Task::where('proj_id',$id)->where('status',6)->get();
  121. }
  122. else
  123. {
  124. $data['tasks'] = Task::whereIn('user_id', [$user_id,0])->where('proj_id',$id)->where('status',1)->get();
  125. $data['in_process'] = Task::where('user_id',$user_id)->where('proj_id',$id)->where('status',2)->get();
  126. $data['complete'] = Task::where('user_id',$user_id)->where('proj_id',$id)->where('status',3)->get();
  127. $data['check'] = Task::where('user_id',$user_id)->where('proj_id',$id)->where('status',4)->get();
  128. $data['bug'] = Task::where('user_id',$user_id)->where('proj_id',$id)->where('status',5)->get();
  129. $data['done'] = Task::where('user_id',$user_id)->where('proj_id',$id)->where('status',6)->get();
  130. }
  131. $data['logss'] = ActivityLog::with('one_user')->where('proj_id',$id)->orderBy('created_at','DESC')->take(20)->get();
  132. return view('user.uproject_details',$data);
  133. }
  134. public function assign_project(Request $req)
  135. {
  136. $proj_id = $req->proj_id;
  137. $type = $req->types;
  138. $group_id = $req->group_id;
  139. $user_id = $req->user_id;
  140. date_default_timezone_set("Asia/Dhaka");
  141. $assign_time = date('Y-m-d H:i:s');
  142. /*
  143. 1=Created;
  144. 2=in process;
  145. 3=Completed;
  146. 4=checking;
  147. 5=bugfixing;
  148. 5=done;
  149. */
  150. if($type == 1){
  151. $all = Group::where('depend_on',$group_id)->where('active','>',0)->get();
  152. foreach($all as $info)
  153. {
  154. $sav = new AssignProject;
  155. $sav->proj_id = $proj_id;
  156. $sav->user_id = $info->user_id;
  157. $sav->assign_time = $assign_time;
  158. $sav->assign_by = Auth::user()->id;
  159. $sav->active = 1;
  160. $sav->save();
  161. $u_name = $this->get_user_name($info->user_id); //call function
  162. $msg = $u_name." assigned.";
  163. $this->project_log($msg,$proj_id); //call function
  164. }
  165. }
  166. elseif($type == 2){
  167. $sav = new AssignProject;
  168. $sav->proj_id = $proj_id;
  169. $sav->user_id = $user_id;
  170. $sav->assign_time = $assign_time;
  171. $sav->assign_by = Auth::user()->id;
  172. $sav->active = 1;
  173. $sav->save();
  174. $u_name = $this->get_user_name($user_id); //call function
  175. $msg = $u_name." assigned.";
  176. $this->project_log($msg,$proj_id); //call function
  177. }
  178. else{
  179. return redirect()->back()->with('msg','Select type first..');
  180. }
  181. return redirect()->back()->with('msg','Add successfully!');
  182. }
  183. public function remove_proj_user($id)
  184. {
  185. $del = AssignProject::find($id);
  186. $u_name = $this->get_user_name($del->user_id); //call function
  187. $msg = "$u_name removed.";
  188. $this->project_log($msg,$del->proj_id); //call function
  189. $del->delete();
  190. //echo $msg;
  191. return redirect()->back();
  192. }
  193. public function project_log($msg,$proj_id)
  194. {
  195. date_default_timezone_set("Asia/Dhaka");
  196. $assign_time = date('Y-m-d H:i:s');
  197. $sav = new ActivityLog;
  198. $sav->msg = $msg;
  199. $sav->proj_id = $proj_id;
  200. $sav->logged_user_id = Auth::user()->id;
  201. $sav->created_at = $assign_time;
  202. $sav->save();
  203. }
  204. public function get_user_name($id){
  205. $fetch = User::find($id);
  206. return $fetch->name;
  207. }
  208. public function remove_proj_document($id)
  209. {
  210. $del = ProjAttachment::find($id);
  211. //for notification
  212. $proj_id = $del->proj_id;
  213. $name = $del->name;
  214. if (File::exists('assets/document/project/'.$del->url) && !empty($del->url))
  215. {
  216. File::delete('assets/document/project/'.$del->url);
  217. $msg = "Document: $del->name removed.";
  218. $this->project_log($msg,$del->proj_id); //call function
  219. $del->delete();
  220. //notification
  221. $projj_name = Project::find($proj_id)->name;
  222. $adminss = User::where('utype',1)->get();
  223. foreach($adminss as $info){
  224. $msg = "File:$name removed from Proj:$projj_name by ".Auth::user()->name;
  225. $this->notification($info->id, $msg);
  226. }
  227. $ass_usr = AssignProject::where('proj_id',$proj_id)->get();
  228. if(count($ass_usr) > 0){
  229. foreach($ass_usr as $info){
  230. $msg = "File:$name removed from Proj:$projj_name by ".Auth::user()->name;
  231. $this->notification($info->user_id, $msg);
  232. }
  233. }
  234. }
  235. return redirect()->back()->with('data','Delete successfully !!');
  236. }
  237. public function notification($user_id,$msg){
  238. $sav = new Notification;
  239. $sav->user_id = $user_id;
  240. $sav->msg = $msg;
  241. $sav->status = 1;
  242. $sav->save();
  243. }
  244. public function change_task_status($id)
  245. {
  246. $new_value;
  247. $msg;
  248. $start_time;
  249. $end_time;
  250. $prv_value=DB::table('task')->where('id','=',$id)->first();
  251. if($prv_value->status==1)
  252. {
  253. $new_value= 2;
  254. date_default_timezone_set("Asia/Dhaka");
  255. $start_time = date('Y-m-d H:i:s');
  256. }
  257. else if($prv_value->status > 1 && $prv_value->status < 6)
  258. {
  259. $new_value= 6;
  260. $end_time = date('Y-m-d H:i:s');
  261. }
  262. if($new_value==2){
  263. DB::table('task')->where('id','=',$id)->update(array('status'=>$new_value,'start_time'=>$start_time));
  264. } else if($new_value ==6){
  265. DB::table('task')->where('id','=',$id)->update(array('status'=>$new_value,'closing_time'=>$end_time));
  266. }
  267. return redirect()->back();
  268. }
  269. }