diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 2c66323..9685c98 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -311,7 +311,7 @@ class MasterFunctionsHelper ->groupBy('activity_id') ->first(); $weekCount = $keyPlanM->duration / 7; - $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + $weeklyPlan = $weekCount > 0 ? $sumVolPlan->ttl_qty_plan / $weekCount : 0; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; @@ -853,6 +853,7 @@ class MasterFunctionsHelper $arr_ActualM = []; $tempDate = []; + $tempPercentage = []; $tempPercentagePlan = []; $tempPercentagePlanWhr = []; $tempPercentageReal = []; @@ -861,7 +862,8 @@ class MasterFunctionsHelper $currentACWP = 0; $currentBCWP = 0; - + $totalACWP = 0; + $totalBCWP = 0; foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index ea48586..21dc80c 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -1,22 +1,23 @@ json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - + $this->deleteRelative($id); if (!$data->delete()) return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); } + private function deleteRelative($activity_id) + { + UserToActivity::where('activity_id', $activity_id)->delete(); + AssignMaterial::where('activity_id', $activity_id)->delete(); + $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); + foreach ($dataAd as $ad) { + if(file_exists($this->pathActivityDocument.$ad->file)){ + unlink($this->pathActivityDocument.$ad->file); + } + } + ActivityDokumen::where("activity_id", $activity_id)->delete(); + } + public function getUpdate($id) { if (!$data = Activity::find($id)) @@ -544,24 +558,40 @@ class ActivityController extends Controller { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $builder = $dataBuilder['builder']; - $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', 'assign_hr_to_activity.id', - 'm_version_gantt.name_version', 'm_users.name as user_name', - DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', - 'assign_material_to_activity.id as join_third_id') - ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') - ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') - ->leftJoin('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') - ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') - ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') - ->groupBy("selfTable.id") - ->groupBy("selfTable.name") - ->groupBy("selfTable.persentase_progress") - ->groupBy("m_version_gantt.name_version") - ->groupBy("m_users.name") - ->groupBy("assign_material_to_activity.qty_planning") - ->groupBy("assign_material_to_activity.id") - ->groupBy("assign_hr_to_activity.id") - ->get(); + $dataGet = $builder->select( + 'selfTable.name', + 'persentase_progress', + 'selfTable.start_date', + 'selfTable.end_date', + 'selfTable.planned_start', + 'selfTable.planned_end', + 'selfTable.actual_start', + 'selfTable.actual_end', + 'duration', + 'm_version_gantt.name_version', + DB::raw('user_names.user_name as user_name'), + DB::raw('SUM(report_activity_material.qty) as qty'), + 'assign_material_to_activity.qty_planning', + 'assign_material_to_activity.id as join_third_id' + ) + ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') + ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') + ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') + ->leftJoin(DB::raw('(SELECT activity_id, STRING_AGG(m_users.name, \',\') as user_name + FROM assign_hr_to_activity + LEFT JOIN m_users ON assign_hr_to_activity.user_id = m_users.id + GROUP BY activity_id) as user_names'), function ($join) { + $join->on('user_names.activity_id', '=', 'selfTable.id'); + }) + ->groupBy('selfTable.id') + ->groupBy('selfTable.name') + ->groupBy('selfTable.persentase_progress') + ->groupBy('m_version_gantt.name_version') + ->groupBy('assign_material_to_activity.qty_planning') + ->groupBy('assign_material_to_activity.id') + ->groupBy('user_names.user_name') + ->get(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); } // before upload file diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 2de808e..deb8065 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -136,6 +136,9 @@ class DashboardBoDController extends Controller foreach ($projects as $index => $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; + $planningProgress = 0; + $actualProgress = 0; + if ($project->scurve && $project->scurve[0]) { $planningArray = $project->scurve[0]['data']['percentagePlan']; $actualArray = $project->scurve[0]['data']['percentageReal']; @@ -178,6 +181,9 @@ class DashboardBoDController extends Controller foreach ($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; + $planningProgress = 0; + $actualProgress = 0; + if ($project->scurve && $project->scurve[0]) { $planningArray = $project->scurve[0]['data']['percentagePlan']; $actualArray = $project->scurve[0]['data']['percentageReal']; diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 39042ec..ca92810 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -9,13 +9,17 @@ use App\Models\Image; use App\Models\Holiday; use App\Models\Project; use App\Models\Activity; +use App\Models\ReportK3; use App\Jobs\ProcessSCurve; +use App\Models\AssignTools; use App\Models\OfficeHours; use App\Models\ProjectType; use App\Models\ProjectPhase; +use App\Models\ProjectRisks; use App\Models\UserToProyek; use App\Models\VersionGantt; use Illuminate\Http\Request; +use App\Models\HierarchyFtth; use App\Models\ProjectIssues; use App\Models\AssignMaterial; use App\Models\DokumenProject; @@ -26,13 +30,14 @@ use App\Models\UserToActivity; use App\Models\ActivityDokumen; use App\Models\CommentActivity; use App\Models\ProjectApproval; +use App\Models\RequestMaterial; use App\Models\ProjectMileStone; use App\Models\ProjectChecklists; use Illuminate\Support\Facades\DB; use App\Models\ProjectParticipants; use App\Models\FolderDocumentProyek; +use App\Models\ProjectToChecklistK3; use App\Helpers\MasterFunctionsHelper; -use App\Models\ProjectRisks; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; @@ -45,7 +50,7 @@ class ProjectController extends Controller { $this->validate($request, [ 'nama' => 'required', - 'mulai_proyek' => 'required', + 'mulai_proyek' => 'required', 'akhir_proyek' => 'required', 'rencana_biaya' => 'required', 'type_proyek_id' => 'required' @@ -163,6 +168,12 @@ class ProjectController extends Controller ProjectChecklists::where('proyek_id', $project_id)->delete(); ProjectIssues::where('proyek_id', $project_id)->delete(); ProjectRisks::where('proyek_id', $project_id)->delete(); + ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); + HierarchyFtth::where('project_id', $project_id)->delete(); + AssignTools::where('proyek_id', $project_id)->delete(); + OfficeHours::where('proyek_id', $project_id)->delete(); + ReportK3::where('proyek_id', $project_id)->delete(); + RequestMaterial::where('proyek_id', $project_id)->delete(); $this->deleteVersionGantt($project_id); $this->deleteDokumenProject($project_id); } @@ -519,12 +530,18 @@ class ProjectController extends Controller if (isset($s_curve)) { $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); - $actualEndExist = Activity::where('proyek_id', $id)->whereNotNull('actual_end')->exists(); - $query = Activity::where('proyek_id', $id); + if($result['type_proyek_id'] === 9) + { + $actualEndExist = Activity::where('proyek_id', $id)->exists(); + $query = Activity::where('proyek_id', $id); + }else{ + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); + $query = Activity::where('version_gantt_id', $ganttId); + } } else { $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); - $actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); + $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); $query = Activity::where('version_gantt_id', $ganttId); } @@ -533,11 +550,10 @@ class ProjectController extends Controller } else { $startDate = $query->orderBy('start_date')->value('start_date'); } - - if ($actualEndExist) { - $endDate = $query->orderByDesc('actual_end')->value('end_date'); - } else { - $endDate = $query->orderByDesc('end_date')->value('end_date'); + if($actualEndExist) + { + $maxEndDate = $query->max('id'); + $endDate = $query->where('id',$maxEndDate)->first()->end_date; } $plannedStart = Activity::where('version_gantt_id', $ganttId) diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index c3fe398..c5fabab 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -2,8 +2,15 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Models\Link; +use App\Models\Holiday; +use App\Models\Activity; use App\Models\VersionGantt; +use Illuminate\Http\Request; +use App\Models\ShowHideColumn; +use App\Models\UserToActivity; +use App\Models\UserToVersionGantt; +use App\Models\ActivityProgressLog; class VersionGanttController extends Controller { @@ -49,6 +56,7 @@ class VersionGanttController extends Controller if($data){ $delete = $data->delete(); + $this->deleteRelative($data['id']); }else{ return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); die(); @@ -62,6 +70,17 @@ class VersionGanttController extends Controller } } + private function deleteRelative($version_gantt_id) + { + UserToActivity::where('version_gantt_id', $version_gantt_id)->delete(); + Activity::where('version_gantt_id', $version_gantt_id)->delete(); + ShowHideColumn::where('version_gantt_id', $version_gantt_id)->delete(); + Link::where('version_gantt_id', $version_gantt_id)->delete(); + UserToVersionGantt::where('version_gantt_id', $version_gantt_id)->delete(); + Holiday::where('version_gantt_id', $version_gantt_id)->delete(); + ActivityProgressLog::where('version_gantt_id', $version_gantt_id)->delete(); + } + public function edit($id){ if(!$id || (int) $id < 0 || $id==""){ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);