Browse Source

Merge branch 'master' of https://git.oslog.id/ibnu/generic-ospro-backend into dev-wahyun

pull/1/head
wahyun 1 year ago
parent
commit
c1443907b3
  1. 75
      app/Http/Controllers/ActivityController.php

75
app/Http/Controllers/ActivityController.php

@ -1,4 +1,5 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use DateTime; use DateTime;
@ -37,7 +38,8 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200); return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200);
} }
public function activitySCurve($proyek_id, $gantt_id){ public function activitySCurve($proyek_id, $gantt_id)
{
// "data": [ // "data": [
// { // {
@ -122,7 +124,6 @@ class ActivityController extends Controller
); );
return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200); return response()->json(['status' => 'success', 'data' => $resultData, 'code' => 200], 200);
} }
private function getDataActivity($id) private function getDataActivity($id)
@ -212,7 +213,7 @@ class ActivityController extends Controller
->where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get(); ->where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach ($data as $objRow) { foreach ($data as $objRow) {
$objRow->parent = $parent_id; $objRow->parent = $parent_id;
$objRow->progress = (float) $objRow->bobot_planning /100; $objRow->progress = (float) $objRow->bobot_planning / 100;
// $objRow->start_date1 = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL; // $objRow->start_date1 = isset($objRow->start) ? date_format(date_create($objRow->start), "d-m-Y H:i") : NULL;
// $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL; // $objRow->end_date1 = isset($objRow->end) ? date_format(date_create($objRow->end), "d-m-Y H:i") : NULL;
@ -264,7 +265,7 @@ class ActivityController extends Controller
$objRow->type = "task"; $objRow->type = "task";
$objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL; $objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL;
$objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL; $objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL;
if(isset($objRow->actual_start)){ if (isset($objRow->actual_start)) {
$objRow->auto_scheduling = false; $objRow->auto_scheduling = false;
} }
} else { } else {
@ -281,36 +282,36 @@ class ActivityController extends Controller
return $finalData; return $finalData;
} }
public function getActivityFirst($parentId){ public function getActivityFirst($parentId)
{
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first(); $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first();
if (!isset($activity)) { if (!isset($activity)) {
return null; return null;
} }
if($activity->type_activity == "task"){ if ($activity->type_activity == "task") {
// Log::info("activity ", [$activity]); // Log::info("activity ", [$activity]);
return $activity->actual_start; return $activity->actual_start;
}else{ } else {
return $this->getActivityFirst($activity->id); return $this->getActivityFirst($activity->id);
} }
} }
public function getFirstLastDateActivity($id, $params){ public function getFirstLastDateActivity($id, $params)
if($params == "start"){ {
if ($params == "start") {
$data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get(); $data = Activity::select('id', 'parent_id', 'name', 'actual_start')->where('parent_id', $id)->get();
}else{ } else {
$data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get(); $data = Activity::select('id', 'parent_id', 'name', 'actual_end')->where('parent_id', $id)->get();
} }
$parent = Activity::findOrFail($id); $parent = Activity::findOrFail($id);
$dataFinal=[]; $dataFinal = [];
foreach ($data as $val) { foreach ($data as $val) {
$activity = $this->getchildActivityForActual($val->id, $params); $activity = $this->getchildActivityForActual($val->id, $params);
$dataFinal[] = $val; $dataFinal[] = $val;
$dataFinal = array_merge($dataFinal, $activity); $dataFinal = array_merge($dataFinal, $activity);
} }
if($params == "start"){ if ($params == "start") {
$actualStartValues = array_column(array_filter($dataFinal, function($item) { $actualStartValues = array_column(array_filter($dataFinal, function ($item) {
return isset($item['actual_start']); return isset($item['actual_start']);
}), 'actual_start'); }), 'actual_start');
$returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null;
@ -318,8 +319,8 @@ class ActivityController extends Controller
$parent->actual_start = $returnActualStartOrEnd; $parent->actual_start = $returnActualStartOrEnd;
$parent->save(); $parent->save();
} }
}else{ } else {
$actualEndValues = array_column(array_filter($dataFinal, function($item) { $actualEndValues = array_column(array_filter($dataFinal, function ($item) {
return isset($item['actual_end']); return isset($item['actual_end']);
}), 'actual_end'); }), 'actual_end');
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) && count($actualEndValues) > 0 ? max($actualEndValues) : null; $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) && count($actualEndValues) > 0 ? max($actualEndValues) : null;
@ -333,14 +334,15 @@ class ActivityController extends Controller
return $returnActualStartOrEnd; return $returnActualStartOrEnd;
} }
public function getchildActivityForActual($parent, $params){ public function getchildActivityForActual($parent, $params)
if($params == "start"){ {
if ($params == "start") {
$activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get(); $activity = Activity::select('id', 'actual_start')->where('parent_id', $parent)->get();
}else{ } else {
$activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get(); $activity = Activity::select('id', 'actual_end')->where('parent_id', $parent)->get();
} }
$temp = []; $temp = [];
foreach($activity as $val1){ foreach ($activity as $val1) {
$getChild = $this->getchildActivityForActual($val1->id, $params); $getChild = $this->getchildActivityForActual($val1->id, $params);
$temp[] = $val1; $temp[] = $val1;
$temp = array_merge($temp, $getChild); $temp = array_merge($temp, $getChild);
@ -348,18 +350,18 @@ class ActivityController extends Controller
return $temp; return $temp;
} }
public function getActivityLast($parentId){ public function getActivityLast($parentId)
{
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first(); $activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first();
if (!isset($activity)) { if (!isset($activity)) {
return null; return null;
} }
if($activity->type_activity == "task"){ if ($activity->type_activity == "task") {
// Log::info("activity ", [$activity]); // Log::info("activity ", [$activity]);
return $activity->actual_end; return $activity->actual_end;
}else{ } else {
return $this->getActivityLast($activity->id); return $this->getActivityLast($activity->id);
} }
} }
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null)
@ -547,7 +549,8 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
} }
public function updateSchedule($ganttId){ public function updateSchedule($ganttId)
{
if (empty($ganttId) || !is_int((int) $ganttId)) if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -574,10 +577,10 @@ class ActivityController extends Controller
$endDate = $today; $endDate = $today;
$bobotPlanning = (int) $activity->bobot_planning; $bobotPlanning = (int) $activity->bobot_planning;
$rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0; $rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0;
$bobotActual = (int) $activity->persentase_progress/100 * $bobotPlanning; $bobotActual = (int) $activity->persentase_progress / 100 * $bobotPlanning;
$sisaBobot = $bobotPlanning - $bobotActual; $sisaBobot = $bobotPlanning - $bobotActual;
$sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0;
$endDate->modify("+".ceil($sisaHari)." Days"); $endDate->modify("+" . ceil($sisaHari) . " Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration; $activity->duration = $actualDuration;
$activity->end_date = $endDate; $activity->end_date = $endDate;
@ -593,7 +596,7 @@ class ActivityController extends Controller
$entities = $request->all(); $entities = $request->all();
if (empty($ganttId) || !is_int((int) $ganttId)) if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activity = Activity::where('version_gantt_id',$ganttId)->get(); $activity = Activity::where('version_gantt_id', $ganttId)->get();
$link = Link::where('version_gantt_id', $ganttId)->get(); $link = Link::where('version_gantt_id', $ganttId)->get();
if (!$activity) if (!$activity)
return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404);
@ -604,7 +607,7 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text']; $entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
$entity['data']['type_activity'] = $entity['data']['type']; $entity['data']['type_activity'] = $entity['data']['type'] ?? 'task';
if (isset($entity['data']['rencana_biaya'])) { if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
} }
@ -640,8 +643,8 @@ class ActivityController extends Controller
AssignMaterial::where('activity_id', $activity_id)->delete(); AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
foreach ($dataAd as $ad) { foreach ($dataAd as $ad) {
if(file_exists($this->pathActivityDocument.$ad->file)){ if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument.$ad->file); unlink($this->pathActivityDocument . $ad->file);
} }
} }
ActivityDokumen::where("activity_id", $activity_id)->delete(); ActivityDokumen::where("activity_id", $activity_id)->delete();
@ -677,7 +680,7 @@ class ActivityController extends Controller
// ->where('m_activity.persentase_progress', '>', 0) // ->where('m_activity.persentase_progress', '>', 0)
->groupByRaw('m_activity.name') ->groupByRaw('m_activity.name')
->get(); ->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200);
} }
public function searchAnalysis(Request $request) public function searchAnalysis(Request $request)
@ -718,7 +721,7 @@ class ActivityController extends Controller
->groupBy('assign_material_to_activity.id') ->groupBy('assign_material_to_activity.id')
->groupBy('user_names.user_name') ->groupBy('user_names.user_name')
->get(); ->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet], 200);
} }
// before upload file // before upload file
public function importOld(Request $request) public function importOld(Request $request)
@ -777,8 +780,7 @@ class ActivityController extends Controller
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
} }
} };
;
} }
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
foreach ($data['activities'] as $i => $activity_row) { foreach ($data['activities'] as $i => $activity_row) {
@ -1137,7 +1139,6 @@ class ActivityController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); 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' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200);
} }
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
} }

Loading…
Cancel
Save