diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index d681c40..ae74952 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -687,7 +687,7 @@ class MasterFunctionsHelper // } - $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; + $totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0; } catch (\DivisionByZeroError $e) { return response()->json(['message' => $e->getMessage()]); } diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index acd94b0..df66558 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -527,6 +527,17 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } + public function searchAnalysis(Request $request) + { + $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); + $builder = $dataBuilder['builder']; + $dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name') + ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') + ->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') + ->get(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + } // before upload file public function importOld(Request $request) { diff --git a/app/Http/Controllers/ActivityDokumenController.php b/app/Http/Controllers/ActivityDokumenController.php index f3a1143..999e860 100644 --- a/app/Http/Controllers/ActivityDokumenController.php +++ b/app/Http/Controllers/ActivityDokumenController.php @@ -1,95 +1,95 @@ -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); - } -} +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/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 143af38..ebdf8a3 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -304,7 +304,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') + $divisions = Divisi::select('id', 'name', 'color') ->with('children') ->whereNull('parent') ->get(); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index a535093..39042ec 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,6 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; + // $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -274,7 +275,9 @@ class ProjectController extends Controller 'created_by', 'updated_at', 'updated_by' - )->orderBy('id', 'desc')->get(); + )->orderBy('id', 'desc') + // ->where("created_by",$this->currentName) + ->get(); $countData = $data->count(); if(!$data) diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 4a29066..57b8c58 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -18,6 +18,9 @@ class RoleController extends Controller $data = $request->all(); $data['created_by'] = $this->currentName; + if (!isset($data['default_page'])) { + $data['default_page'] = 29; // dashboard + } $result = Role::create($data); diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 2c3a658..a1a9583 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -129,6 +129,16 @@ class UserToActivityController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); } + public function searchAnalysis(Request $request) + { + $dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_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 search(Request $request) { $payload = $request->all(); diff --git a/app/Models/CommentActivity.php b/app/Models/CommentActivity.php index e747af2..0cd259e 100644 --- a/app/Models/CommentActivity.php +++ b/app/Models/CommentActivity.php @@ -1,22 +1,22 @@ -updateActDuration(); - }); - } - - public function updateActDuration(){ - $daysOff = explode(',', $this->config_dayoff); - if (in_array('0', $daysOff)) { - $key = array_search('0', $daysOff, false); - $daysOff[$key] = '7'; - } - $activities = Activity::where('version_gantt_id', $this->id)->get(); - foreach ($activities as $value) { - $exist = Link::where('t_activity_id', $value->id)->exists(); - $startDate = new DateTime($value->start_date); - $endDate = new DateTime($value->end_date); - $duration = $endDate->diff($startDate)->days + 1; - if ($exist) { - $duration--; - } - - // Iterate through each day and subtract the days off - for ($i = 0; $i < $duration; $i++) { - $currentDate = clone $startDate; - $currentDate->modify("+$i day"); - - $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) - - if (in_array($currentDayOfWeek, $daysOff)) { - $duration--; // Subtract one day from the duration for each day off - } - } - - // Update the activity duration - $value->duration = $duration; - $value->save(); - } - } -} +updateActDuration(); + }); + } + + public function updateActDuration(){ + $daysOff = explode(',', $this->config_dayoff); + if (in_array('0', $daysOff)) { + $key = array_search('0', $daysOff, false); + $daysOff[$key] = '7'; + } + $activities = Activity::where('version_gantt_id', $this->id)->get(); + foreach ($activities as $value) { + $exist = Link::where('t_activity_id', $value->id)->exists(); + $startDate = new DateTime($value->start_date); + $endDate = new DateTime($value->end_date); + $duration = $endDate->diff($startDate)->days + 1; + if ($exist) { + $duration--; + } + + // Iterate through each day and subtract the days off + for ($i = 0; $i < $duration; $i++) { + $currentDate = clone $startDate; + $currentDate->modify("+$i day"); + + $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) + + if (in_array($currentDayOfWeek, $daysOff)) { + $duration--; // Subtract one day from the duration for each day off + } + } + + // Update the activity duration + $value->duration = $duration; + $value->save(); + } + } +} diff --git a/routes/web.php b/routes/web.php index 7f62207..73b90db 100644 --- a/routes/web.php +++ b/routes/web.php @@ -197,6 +197,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); $router->put('/user-to-activity/update/{id}', 'UserToActivityController@update'); $router->post('/user-to-activity/search', 'UserToActivityController@search'); + $router->post('/user-to-activity/search-analysis', 'UserToActivityController@searchAnalysis'); $router->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered'); $router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete'); $router->get('/user-to-activity/list', 'UserToActivityController@list'); @@ -204,7 +205,8 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); - $router->get('/activity/search', 'ActivityController@search'); + $router->post('/activity/search', 'ActivityController@search'); + $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld');