diff --git a/app/Http/Controllers/ActivityDokumenController.php b/app/Http/Controllers/ActivityDokumenController.php index d0add21..f3a1143 100644 --- a/app/Http/Controllers/ActivityDokumenController.php +++ b/app/Http/Controllers/ActivityDokumenController.php @@ -7,93 +7,89 @@ use App\Models\ActivityDokumen; class ActivityDokumenController extends Controller { - public function dokumenByActivityId($id){ - if($id && $id!="" && (int)$id > 0){ - $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); - - return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); - } - } - - public function delete($id) - { - if($id && $id!="" && (int)$id > 0){ - $dokumen = ActivityDokumen::find($id); - if($dokumen){ - if(file_exists($this->pathActivityDocument.$dokumen->file)){ - unlink($this->pathActivityDocument.$dokumen->file); - } - $dokumen->delete(); - return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - } - } - - public function uploadProjectDokumen(Request $request) - { - if($request->hasFile('dokumen')){ - $activity_id = $request->activity_id; - $dokumen = $request->file('dokumen'); - $extension = $dokumen->extension(); - $name = $dokumen->getClientOriginalName(); - - $result = $dokumen->move($this->pathActivityDocument, $name); - if($result){ - $data = [ - 'activity_id' => (int)$activity_id, - 'file' => $name, - 'description' => $request->description - ]; - - $result = ActivityDokumen::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200); - }else{ - unlink($this->pathActivityDocument.$name); - return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); - } - - }else{ - return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); - } - } - - public function searchDocProject(Request $request){ - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function downloadDokumen($id) - { - if($id && $id!="" && (int)$id > 0){ - $dokumen = ActivityDokumen::find($id); - if($dokumen){ - if(file_exists($this->pathActivityDocument.$dokumen->file)){ - $pathToFile = $this->pathActivityDocument.$dokumen->file; - return response()->download($pathToFile); - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - } - } + + public function dokumenByActivityId($id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); + + $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); + return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + if(file_exists($this->pathActivityDocument.$document->file)) + unlink($this->pathActivityDocument.$document->file); + + $document->delete(); + return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); + } + + public function uploadProjectDokumen(Request $request) + { + if(!$request->hasFile('dokumen')) + return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); + + $activity_id = $request->activity_id; + $document = $request->file('dokumen'); + $name = $document->getClientOriginalName(); + + $result = $document->move($this->pathActivityDocument, $name); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + + $data = [ + 'activity_id' => (int)$activity_id, + 'file' => $name, + 'description' => $request->description + ]; + + $result = ActivityDokumen::create($data); + + if(!$result){ + unlink($this->pathActivityDocument.$name); + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + } + + return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); + } + + public function searchDocProject(Request $request){ + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function downloadDokumen($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + + if(file_exists($this->pathActivityDocument.$document->file)){ + $pathToFile = $this->pathActivityDocument.$document->file; + return response()->download($pathToFile); + } + + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 6324987..f50d5c2 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -7,21 +7,14 @@ use Illuminate\Http\Request; use App\Models\User; use App\Models\Role; -use App\Models\Project; -use App\Models\UserProject; class AuthController extends Controller { - /** - * Create a new AuthController instance. - * - * @return void - */ public function __construct() { $this->middleware('auth:api', ['except' => ['login']]); } - + public function login(Request $request) { $username = $request->username; @@ -32,13 +25,7 @@ class AuthController extends Controller return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); } - $credentials = array( - "username"=> $username, - "password"=> md5($password) - ); - - $user = User::where('username', $username)->where('password', md5($password)) - ->first(); + $user = User::where('username', $username)->where('password', md5($password))->first(); if($is_mobile){ $fcm_token = $request->fcm_token; @@ -55,7 +42,7 @@ class AuthController extends Controller $hr = User::find($user->id); if($hr){ - $result = $hr->update($dataUpdateFcm); + $hr->update($dataUpdateFcm); } } @@ -65,7 +52,7 @@ class AuthController extends Controller $user->role = $dataRole; } - + if (! $token =Auth::login($user)) { return response()->json(['error' => 'Unauthorized'], 401); } @@ -76,12 +63,12 @@ class AuthController extends Controller protected function respondWithToken($token, $user) { return response()->json([ - 'code' => 200, + 'code' => 200, 'data' => array( 'data_user' => $user, - 'access_token' => $token, + 'access_token' => $token, 'token_type' => 'bearer', - 'expires_in' => auth()->factory()->getTTL() * 60 + 'expires_in' => auth()->factory()->getTTL() * 360 ), ]); } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 9a6b278..2623b1c 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -6,247 +6,220 @@ use Illuminate\Http\Request; use App\Models\Project; use App\Models\Activity; use App\Models\ReportActivity; -use App\Models\UserToActivity; -use DB; +use App\Models\Role; class DashboardController extends Controller { - public function costPlanningActual(Request $request) - { - $dataPayload = $request->all(); - $dataMaxVersionGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); - } - - $dataFinal=[]; - foreach ($dataMaxVersionGantt as $val) { - $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); - $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); - } - - if($dataPayload){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - } - } - - public function getMaxVersionGantt($id){ - $data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first(); - return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name); - } - - public function percentagePlanningActual(Request $request) - { - $dataPayload = $request->all(); - $dataMaxVersionGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); - } - $dataFinal=[]; - foreach ($dataMaxVersionGantt as $val) { - $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); - $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); - - } - - if($dataPayload){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - } - } - - public function list() - { - $data = Role::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - } - } - - - - - - - public function getActivityByProjectId($projectId) { - $output = []; - $data = Activity::select('id')->where('proyek_id', $projectId)->get(); - if (count($data) > 0) { - foreach ($data as $actData) { - $output[] = $actData->id; - } - } - return $output; - } - - /* for statusProyek, I want something output like this - const statusProyek = [ - { - "id": "1", - "proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek - "total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih - "task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih - "day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini) - "percentage": 75 // (task_on_progress / total_task * 100) - }, - { - "id": "2", - "proyek_name": "Pembangunan Jembatan Layang", - "total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11); - "task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355); - "day_left": 0, - "percentage": 100 - }, - ... - ] - */ - public function statusProyek(Request $request) { - $dataPayload = $request->all(); - $reqProject = []; - $dataFinal = []; - - if (!isset($dataPayload['project_id'])) { - return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400); - } - - foreach ($dataPayload['project_id'] as $val) { - $prj["project_id"] = $val; - $prj["activity_id"] = $this->getActivityByProjectId($val); - - $reqProject[] = $prj; - } - - if (count($reqProject) > 0) { - $row = []; - - for ($i=0; $i < count($reqProject); $i++) { - $dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first(); - $last_version_gantt = $dataMaxVersionGantt->last_version_gantt; - $queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first(); - $sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan"); - $count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id"); - $count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id"); - $progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->sum("persentase_progress"); - $count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress"); - - $progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get(); - $current_progress = 0; - foreach($progress_actual as $objRow) { - $current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100; - } - - if (count($reqProject[$i]['activity_id']) > 0) { - for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) { - $sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report"); - } - } - - if (!isset($queryProject->id)) { - return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400); - } - - $now = time(); - $akhir_proyek = strtotime($queryProject->akhir_proyek); - $datediff = $akhir_proyek - $now; - - $mulai_proyek = strtotime($queryProject->mulai_proyek); - $total_kontrak = $akhir_proyek - $mulai_proyek; - - $row["id"] = $queryProject->id; - $row["proyek_name"] = $queryProject->nama; - $row["mulai_proyek"] = $queryProject->mulai_proyek; - $row["akhir_proyek"] = $queryProject->akhir_proyek; - $row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24)); - $row["total_task"] = $sum_jumlah_pekerjaan; - $row["task_on_progress"] = $sum_job_count_report; - $row["count_activity"] = $count_activity; - $row["count_activity_done"] = $count_activity_done; - $row["day_left"] = round($datediff / (60 * 60 * 24)); - $row["percentage"] = round($current_progress,3); - $row["count_progress_percentage"] = $count_progress_percentage; - - $dataFinal[] = $row; - } - } - - if($dataFinal){ - return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400); - } - - } - - public function curvaS(Request $request) - { - $dataPayload = $request->all(); - $dataMaxVersionGantt = []; - foreach ($dataPayload['project_id'] as $val) { - $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); - } - $dataFinal=[]; - foreach ($dataMaxVersionGantt as $val) { - $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); - $totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya'); - $dataBobotPlan =[]; - for ($i=0; $i < count($data); $i++) { - $tmpp = 0; - $tmpa = 0; - $tmpbc = 0; - $tmpac = 0; - for ($x=$i; $x >= 0 ; $x--) { - $tmpp += $data[$x]['bobot_planning']; - $tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100; - $tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100; - $tmpac += $data[$x]['biaya_actual']; - } - - $data[$i]['cal_bobot_p'] = round($tmpp,2); - if($i > 0 ){ - if($data[$i-1]['cal_bobot_a'] != null){ - if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){ - $data[$i]['cal_bobot_a'] = null; - }else{ - $data[$i]['cal_bobot_a'] = round($tmpa,2); - } - }else{ - $data[$i]['cal_bobot_a'] = null; - } - }else{ - $data[$i]['cal_bobot_a'] = round($tmpa,2); - } - $data[$i]['cal_budget_cost'] = round($tmpbc,2); - - if($i > 0 ){ - if($data[$i-1]['cal_actual_cost'] != null){ - if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){ - $data[$i]['cal_actual_cost'] = null; - }else{ - $data[$i]['cal_actual_cost'] = round($tmpac,2); - } - }else{ - $data[$i]['cal_actual_cost'] = null; - } - }else{ - $data[$i]['cal_actual_cost'] = round($tmpac,2); - } - } - - $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); - - } - - if($dataPayload){ - return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - } - } -} \ No newline at end of file + public function costPlanningActual(Request $request) + { + $dataPayload = $request->all(); + $dataMaxVersionGantt = []; + foreach ($dataPayload['project_id'] as $val) { + $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); + } + + $dataFinal=[]; + foreach ($dataMaxVersionGantt as $val) { + $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); + } + + if(!$dataFinal) + return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); + } + + public function getMaxVersionGantt($id){ + $data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first(); + return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name); + } + + public function percentagePlanningActual(Request $request) + { + $dataPayload = $request->all(); + $dataMaxVersionGantt = []; + foreach ($dataPayload['project_id'] as $val) { + $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); + } + $dataFinal=[]; + foreach ($dataMaxVersionGantt as $val) { + $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); + } + + if(!$dataFinal) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); + } + + public function list() + { + $data = Role::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } + + public function getActivityByProjectId($projectId) { + $output = []; + $data = Activity::select('id')->where('proyek_id', $projectId)->get(); + foreach ($data as $actData) { + $output[] = $actData->id; + } + return $output; + } + + /* + const statusProyek = [ + { + "id": "1", + "proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek + "total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih + "task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih + "day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini) + "percentage": 75 // (task_on_progress / total_task * 100) + }, + { + "id": "2", + "proyek_name": "Pembangunan Jembatan Layang", + "total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11); + "task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355); + "day_left": 0, + "percentage": 100 + }, + ... + ] + */ + public function statusProyek(Request $request) { + $dataPayload = $request->all(); + $reqProject = $dataFinal = []; + + if (!isset($dataPayload['project_id'])) + return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400); + + foreach ($dataPayload['project_id'] as $val) { + $prj["project_id"] = $val; + $prj["activity_id"] = $this->getActivityByProjectId($val); + $reqProject[] = $prj; + } + + if (count($reqProject) > 0) { + $row = []; + + for ($i=0; $i < count($reqProject); $i++) { + $dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first(); + $last_version_gantt = $dataMaxVersionGantt->last_version_gantt; + $queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first(); + $sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan"); + $count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id"); + $count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id"); + $count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress"); + $progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get(); + $current_progress = 0; + + foreach($progress_actual as $objRow) { + $current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100; + } + if (count($reqProject[$i]['activity_id']) > 0) { + for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) { + $sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report"); + } + } + if (!isset($queryProject->id)) + return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400); + + $now = time(); + $akhir_proyek = strtotime($queryProject->akhir_proyek); + $datediff = $akhir_proyek - $now; + + $mulai_proyek = strtotime($queryProject->mulai_proyek); + $total_kontrak = $akhir_proyek - $mulai_proyek; + + $row["id"] = $queryProject->id; + $row["proyek_name"] = $queryProject->nama; + $row["mulai_proyek"] = $queryProject->mulai_proyek; + $row["akhir_proyek"] = $queryProject->akhir_proyek; + $row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24)); + $row["total_task"] = $sum_jumlah_pekerjaan; + $row["task_on_progress"] = $sum_job_count_report; + $row["count_activity"] = $count_activity; + $row["count_activity_done"] = $count_activity_done; + $row["day_left"] = round($datediff / (60 * 60 * 24)); + $row["percentage"] = round($current_progress,3); + $row["count_progress_percentage"] = $count_progress_percentage; + + $dataFinal[] = $row; + } + } + + if(empty($dataFinal)) + return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200); + } + + public function curvaS(Request $request) + { + $dataPayload = $request->all(); + $dataMaxVersionGantt = []; + $dataFinal=[]; + + foreach ($dataPayload['project_id'] as $val) { + $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); + } + + foreach ($dataMaxVersionGantt as $val) { + $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); + $totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya'); + + for ($i=0; $i < count($data); $i++) { + $tmpp = $tmpa = $tmpbc = $tmpac = 0; + for ($x=$i; $x >= 0 ; $x--) { + $tmpp += $data[$x]['bobot_planning']; + $tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100; + $tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100; + $tmpac += $data[$x]['biaya_actual']; + } + + $data[$i]['cal_bobot_p'] = round($tmpp,2); + + if($i > 0 ){ + if($data[$i-1]['cal_bobot_a'] != null){ + if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){ + $data[$i]['cal_bobot_a'] = null; + }else{ + $data[$i]['cal_bobot_a'] = round($tmpa,2); + } + }else{ + $data[$i]['cal_bobot_a'] = null; + } + if($data[$i-1]['cal_actual_cost'] != null){ + if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){ + $data[$i]['cal_actual_cost'] = null; + }else{ + $data[$i]['cal_actual_cost'] = round($tmpac,2); + } + }else{ + $data[$i]['cal_actual_cost'] = null; + } + }else{ + $data[$i]['cal_bobot_a'] = round($tmpa,2); + $data[$i]['cal_actual_cost'] = round($tmpac,2); + } + $data[$i]['cal_budget_cost'] = round($tmpbc,2); + } + + $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); + } + + if(!$dataFinal) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200); + } +} diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index 864f0eb..aa265d8 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -6,82 +6,81 @@ use Illuminate\Http\Request; use App\Models\Divisi; class DivisiController extends Controller -{ - public function add(Request $request){ - $this->validate($request, [ - 'name' => 'required', - 'description' => 'required' - ]); - $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = Divisi::create($data); - if($result){ - return response()->json(['status'=>'success','message'=>'Master divisi successfull created','code'=>200]); - }else{ - return response()->json(['status'=>'failed','message'=>'Master divisi failed created','code'=>400]); - } - } - - public function update(Request $request, $id){ - - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - $data = Divisi::find($id); - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'Data Master divisi not found!','code'=>400], 400); - die(); - } - - if($result){ - return response()->json(['status'=>'success','message'=>'Master divisi successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Master divisi failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Divisi::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data Master divisi not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'Master divisi successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Master divisi failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = Divisi::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); - } - } +{ + public function add(Request $request){ + $this->validate($request, [ + 'name' => 'required', + 'description' => 'required' + ]); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + + $result = Divisi::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); + + return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $delete = $data->delete(); + + + if(!$delete) + return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = Divisi::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 437871c..5402bc8 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -14,12 +14,8 @@ use App\Models\ProjectCharter; use App\Models\ProjectApproval; use App\Models\ProjectMileStone; use App\Models\ProjectParticipants; -use App\Models\UserToVersionGantt; -use App\Models\RequestMaterial; use App\Models\ShowHideColumn; -use App\Models\ToolsProject; use App\Models\VersionGantt; -use App\Models\MaterialProject; use App\Models\Image; use App\Models\CommentActivity; use App\Models\Link; @@ -30,214 +26,205 @@ use App\Models\OfficeHours; class ProjectController extends Controller { - public function add(Request $request) - { - $this->validate($request, [ - 'nama' => 'required', - 'mulai_proyek' => 'required', - 'akhir_proyek' => 'required', - 'rencana_biaya' => 'required', - 'type_proyek_id' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Project::create($data); - - if($result){ - $this->createOfficeHours($result->id); - $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); - return response()->json(['status'=>'success','message'=>'add data project successfully!', 'data_result' =>$dataResultInsert, 'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data project failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Project::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Project::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400); - } - } - - private function createOfficeHours($proyek_id) - { - $dataCreate = array( - "proyek_id"=>$proyek_id, - "monday_start"=> "08:00:00", - "monday_end"=> "16:00:00", - "tuesday_start"=> "08:00:00", - "tuesday_end"=> "16:00:00", - "wednesday_start"=> "08:00:00", - "wednesday_end"=> "16:00:00", - "thursday_start"=> "08:00:00", - "thursday_end"=> "16:00:00", - "friday_start"=> "08:00:00", - "friday_end"=> "16:00:00", - "saturday_start"=> "08:00:00", - "saturday_end"=> "16:00:00", - "sunday_start"=> "08:00:00", - "sunday_end"=> "16:00:00", - "created_by"=> $this->currentName - ); - - OfficeHours::create($dataCreate); - - return true; - } - - public function delete($id) - { - $data = Project::find($id); - - if($data){ - $this->deleteRelative($id); - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data project successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data project failed deleted!','code'=>400], 400); - } - } - - private function deleteRelative($project_id) - { - UserToProyek::where('proyek_id', $project_id)->delete(); - UserToActivity::where('proyek_id', $project_id)->delete(); - AssignMaterial::where('proyek_id', $project_id)->delete(); - ProjectCharter::where('proyek_id', $project_id)->delete(); - ProjectApproval::where('proyek_id', $project_id)->delete(); - ProjectMileStone::where('proyek_id', $project_id)->delete(); - ProjectParticipants::where('proyek_id', $project_id)->delete(); - $this->deleteVersionGantt($project_id); - $this->deleteDokumenProject($project_id); - } - - private function deleteVersionGantt($project_id) - { - $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); - $vhIds = $dataVg->all(); - $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); - $activityIds = $activity->all(); - $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); - } - $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); - foreach ($dataAd as $ad) { - if(file_exists($this->pathActivityDocument.$ad->file)){ - unlink($this->pathActivityDocument.$ad->file); - } - } - ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); - CommentActivity::whereIn("activity_id", $activityIds)->delete(); - Holiday::where("proyek_id", $project_id)->delete(); - VersionGantt::where("proyek_id", $project_id)->delete(); - Link::whereIn("version_gantt_id", $vhIds)->delete(); - ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); - Activity::whereIn("version_gantt_id", $vhIds)->delete(); - ReportActivity::whereIn("activity_id", $activityIds)->delete(); - } - - private function deleteDokumenProject($project_id) - { - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); - - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); - - $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); - $ref_ids = $dataFolder->all(); - $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); - foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - } - - DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = Project::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400); - } - } - - public function getListProjectTask($id){ - $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")->where("assign_hr_to_activity.user_id", $id)->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') - ->groupBy("m_proyek.proyek_id")->get(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400); - } - } + + public function add(Request $request) + { + $this->validate($request, [ + 'nama' => 'required', + 'mulai_proyek' => 'required', + 'akhir_proyek' => 'required', + 'rencana_biaya' => 'required', + 'type_proyek_id' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Project::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); + + $this->createOfficeHours($result->id); + $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); + + return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); + } + + public function edit($id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = Project::find($id); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Project::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); + } + + private function createOfficeHours($proyek_id) + { + $dataCreate = array( + "proyek_id"=>$proyek_id, + "monday_start"=> "08:00:00", + "monday_end"=> "16:00:00", + "tuesday_start"=> "08:00:00", + "tuesday_end"=> "16:00:00", + "wednesday_start"=> "08:00:00", + "wednesday_end"=> "16:00:00", + "thursday_start"=> "08:00:00", + "thursday_end"=> "16:00:00", + "friday_start"=> "08:00:00", + "friday_end"=> "16:00:00", + "saturday_start"=> "08:00:00", + "saturday_end"=> "16:00:00", + "sunday_start"=> "08:00:00", + "sunday_end"=> "16:00:00", + "created_by"=> $this->currentName + ); + + OfficeHours::create($dataCreate); + + return true; + } + + public function delete($id) + { + $data = Project::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + $this->deleteRelative($id); + + if(!$data->delete()) + return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + private function deleteRelative($project_id) + { + UserToProyek::where('proyek_id', $project_id)->delete(); + UserToActivity::where('proyek_id', $project_id)->delete(); + AssignMaterial::where('proyek_id', $project_id)->delete(); + ProjectCharter::where('proyek_id', $project_id)->delete(); + ProjectApproval::where('proyek_id', $project_id)->delete(); + ProjectMileStone::where('proyek_id', $project_id)->delete(); + ProjectParticipants::where('proyek_id', $project_id)->delete(); + $this->deleteVersionGantt($project_id); + $this->deleteDokumenProject($project_id); + } + + private function deleteVersionGantt($project_id) + { + $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); + $vhIds = $dataVg->all(); + $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); + $activityIds = $activity->all(); + $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); + foreach ($dataAd as $ad) { + if(file_exists($this->pathActivityDocument.$ad->file)){ + unlink($this->pathActivityDocument.$ad->file); + } + } + ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); + CommentActivity::whereIn("activity_id", $activityIds)->delete(); + Holiday::where("proyek_id", $project_id)->delete(); + VersionGantt::where("proyek_id", $project_id)->delete(); + Link::whereIn("version_gantt_id", $vhIds)->delete(); + ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); + Activity::whereIn("version_gantt_id", $vhIds)->delete(); + ReportActivity::whereIn("activity_id", $activityIds)->delete(); + } + + private function deleteDokumenProject($project_id) + { + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); + + foreach ($dataDokumen as $dokumen) { + if(file_exists($this->pathDocument.$dokumen->file)){ + unlink($this->pathDocument.$dokumen->file); + } + } + DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); + + $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); + $ref_ids = $dataFolder->all(); + $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); + foreach ($dataDokumen as $dokumen) { + if(file_exists($this->pathDocument.$dokumen->file)){ + unlink($this->pathDocument.$dokumen->file); + } + } + + DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = Project::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } + + public function getListProjectTask($id){ + $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") + ->where("assign_hr_to_activity.user_id", $id) + ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') + ->groupBy("m_proyek.proyek_id") + ->get(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); + } } diff --git a/app/Http/Controllers/ProjectDokumenController.php b/app/Http/Controllers/ProjectDokumenController.php index 9b1ab7c..466f09b 100644 --- a/app/Http/Controllers/ProjectDokumenController.php +++ b/app/Http/Controllers/ProjectDokumenController.php @@ -7,93 +7,94 @@ use App\Models\DokumenProject; class ProjectDokumenController extends Controller { - public function dokumenByProyekId($id){ - if($id && $id!="" && (int)$id > 0){ - $dataDokumen = DokumenProject::where("ref_id", $id)->get(); - - return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400); - } - } - - public function delete($id) - { - if($id && $id!="" && (int)$id > 0){ - $dokumen = DokumenProject::find($id); - if($dokumen){ - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); - } - $dokumen->delete(); - return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - } - } - - public function uploadProjectDokumen(Request $request) - { - if($request->hasFile('dokumen')){ - $dokumen = $request->file('dokumen'); - $ref_id = $request->ref_id; - $extension = $dokumen->extension(); - $name = $dokumen->getClientOriginalName(); - - $result = $dokumen->move($this->pathDocument, $name); - if($result){ - $data = [ - 'ref_id' => (int)$ref_id, - 'file' => $name, - 'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' // project-document-in-folder / project-document-out-folder - ]; - - $result = DokumenProject::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200); - }else{ - unlink($this->pathDocument.$name); - return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); - } - - }else{ - return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); - } - } - - public function searchDocProject(Request $request){ - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'document_project'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function downloadDokumen($id) - { - if($id && $id!="" && (int)$id > 0){ - $dokumen = DokumenProject::find($id); - if($dokumen){ - if(file_exists($this->pathDocument.$dokumen->file)){ - $pathToFile = $this->pathDocument.$dokumen->file; - return response()->download($pathToFile); - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); - } - }else{ - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - } - } + public function dokumenByProyekId($id){ + if(empty($id) || !is_int((int)$id)) { + return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400); + } + + $document = DokumenProject::where("ref_id", $id)->get(); + + if(count($document) == 0) + return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404); + + return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) { + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $document = DokumenProject::find($id); + if(!$document){ + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + } + + if(file_exists($this->pathDocument.$document->file)){ + unlink($this->pathDocument.$document->file); + } + + $document->delete(); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + public function uploadProjectDokumen(Request $request) + { + if($request->hasFile('dokumen')){ + $document = $request->file('dokumen'); + $ref_id = $request->ref_id; + $name = $document->getClientOriginalName(); + + $result = $document->move($this->pathDocument, $name); + if($result){ + $data = [ + 'ref_id' => (int)$ref_id, + 'file' => $name, + 'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' + ]; + + $result = DokumenProject::create($data); + + if(!$result){ + unlink($this->pathDocument.$name); + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + } + return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200); + + } + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + } + return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); + } + + public function searchDocProject(Request $request){ + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'document_project'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function downloadDokumen($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = DokumenProject::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + if(!file_exists($this->pathDocument.$document->file)) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + $pathToFile = $this->pathDocument.$document->file; + return response()->download($pathToFile); + } } diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index a1787a8..b420107 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -4,105 +4,98 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Role; + class RoleController extends Controller { - public function add(Request $request) - { - $this->validate($request, [ - 'name' => 'required', - 'description' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Role::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'add data role successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data role failed!','code'=>400], 400); - } - } - - public function edit($id){ - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - die(); - } - - $result = Role::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data role, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Role::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data role successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data role failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Role::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data role successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data role failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_roles'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = Role::all(); - $countData = $data->count(); - - if($data){ - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - } - } + + public function add(Request $request) + { + $this->validate($request, [ + 'name' => 'required', + 'description' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Role::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function edit( $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = Role::find($id); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Role::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Role::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_roles'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = Role::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } }