CProjectController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use Auth;
  7. use App\Models\AssignProject;
  8. use App\Models\Project;
  9. use App\Models\ActivityLog;
  10. use App\Models\ProjAttachment;
  11. use App\Models\Task;
  12. use App\User;
  13. use Illuminate\Support\Facades\File;
  14. class CProjectController extends Controller
  15. {
  16. public function index(){
  17. $data['title'] = "Client panel";
  18. $user_id = Auth::user()->id;
  19. $data['projj'] = AssignProject::with('proj_name','one_user','assigned')->where('user_id',$user_id)->orderBy('id','desc')->get();
  20. return view('client.cprojects',$data);
  21. }
  22. public function add_project(Request $request){
  23. $proj_name = $request->proj_name;
  24. $description = $request->description;
  25. date_default_timezone_set("Asia/Dhaka");
  26. $cdate = date('Y-m-d H:i:s');
  27. $client_id = Auth::user()->id;
  28. $sav = new Project;
  29. $sav->name = $proj_name;
  30. $sav->client_id = $client_id;
  31. $sav->description = $description;
  32. $sav->created_time = $cdate;
  33. $sav->created_by = $client_id;
  34. $sav->save();
  35. $lastInsertedId = $sav->id;
  36. $sav = new AssignProject;
  37. $sav->proj_id = $lastInsertedId;
  38. $sav->user_id = $client_id;
  39. $sav->assign_time = $cdate;
  40. $sav->assign_by = $client_id;
  41. $sav->active = 1;
  42. $sav->save();
  43. $msg = "Project:$proj_name created.";
  44. $this->project_log($msg,$lastInsertedId); //call function
  45. return redirect()->back()->with('message','Success');
  46. }
  47. public function add_file(Request $req){
  48. $file = $req->file('file');
  49. $proj_id = $req->proj_id;
  50. date_default_timezone_set("Asia/Dhaka");
  51. if ($req->hasFile('file')) {
  52. $extension = $file->getClientOriginalExtension();
  53. $os = array("jpg", "jpeg", "png", "pdf", "doc", "docx", "txt", "psd");
  54. if (in_array($extension, $os)){
  55. $name = $file->getClientOriginalName();
  56. $newFileName = $newFileName = "proj_".date('d_m_y_h_m_s').".".$extension;;
  57. $fileee = $file->move('assets/document/project/', $newFileName);
  58. //echo $newFileName;
  59. $cat = new ProjAttachment;
  60. $cat->url = $newFileName;
  61. $cat->uploader_id = Auth::user()->id;
  62. $cat->proj_id = $proj_id;
  63. $cat->name = $name;
  64. $cat->save();
  65. $msg = "Add document: $name";
  66. $this->project_log($msg,$proj_id); //call function
  67. }
  68. }
  69. }
  70. public function remove_proj($id)
  71. {
  72. $del = Project::find($id);
  73. $del->tasks()->delete();
  74. $del->documents()->delete();
  75. $del->proj_assign()->delete();
  76. $del->delete();
  77. return redirect()->back()->with('data','Delete successfully !!');
  78. }
  79. public function remove_proj_document($id)
  80. {
  81. $del = ProjAttachment::find($id);
  82. if (File::exists('assets/document/project/'.$del->url) && !empty($del->url))
  83. {
  84. File::delete('assets/document/project/'.$del->url);
  85. $msg = "Document: $del->name removed.";
  86. $this->project_log($msg,$del->proj_id); //call function
  87. $del->delete();
  88. }
  89. return redirect()->back()->with('data','Delete successfully !!');
  90. }
  91. public function project_details($id){
  92. $data['title'] = "Client Project Details";
  93. $data['users'] = User::where('active',1)->get();
  94. $data['groups'] = '';
  95. $data['project_id'] = $id;
  96. $data['self'] = Project::find($id);
  97. $data['proj_assign_user'] = AssignProject::with('one_user')->where('active',1)->where('proj_id',$id)->get();
  98. $data['documents'] = ProjAttachment::where('proj_id',$id)->orderBy('id','desc')->get();
  99. $data['tasks'] = Task::where('status',1)->where('proj_id',$id)->get();
  100. $data['in_process'] = Task::where('status',2)->where('proj_id',$id)->get();
  101. $data['complete'] = Task::where('status',3)->where('proj_id',$id)->get();
  102. $data['check'] = Task::where('status',4)->where('proj_id',$id)->get();
  103. $data['bug'] = Task::where('status',5)->where('proj_id',$id)->get();
  104. $data['done'] = Task::where('status',6)->where('proj_id',$id)->get();
  105. $data['logss'] = ActivityLog::with('one_user')->where('proj_id',$id)->orderBy('created_at','DESC')->take(20)->get();
  106. return view('client.cproject_details',$data);
  107. }
  108. public function project_log($msg,$proj_id)
  109. {
  110. date_default_timezone_set("Asia/Dhaka");
  111. $assign_time = date('Y-m-d H:i:s');
  112. $sav = new ActivityLog;
  113. $sav->msg = $msg;
  114. $sav->proj_id = $proj_id;
  115. $sav->logged_user_id = Auth::user()->id;
  116. $sav->created_at = $assign_time;
  117. $sav->save();
  118. }
  119. }