@ -1,6 +1,7 @@
<?php
namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity;
use App\Models\CommentActivity;
use App\Models\Link;
@ -412,6 +413,39 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function updateSchedule($ganttId){
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activities = Activity::where('version_gantt_id', $ganttId)->get();
if (!$activities)
return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404);
$duration = 0;
foreach ($activities as $key => $activity) {
if (isset($activity->planned_start) & & isset($activity->planned_end)) {
$today = new DateTime();
$endDate = new DateTime($activity->end_date);
$startDate = new DateTime($activity->start_date);
$plannedStart = new DateTime($activity->planned_start);
$plannedEnd = new DateTime($activity->planned_end);
$duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd);
if ($today >= $endDate) {
$endDate = $today;
$rerataBobot = $activity->bobot_planning / $duration;
$bobotActual = $activity->progress * $activity->bobot_planning;
$sisaBobot = $activity->bobot_planning - $bobotActual;
$sisaHari = $sisaBobot / $rerataBobot;
$endDate->modify("+".$sisaHari." Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration;
$activity->end_date = $endDate;
$activity->save();
}
}
}
return response()->json(['status' => 'success', 'message' => 'Activities Updated!', 'code' => 200], 200);
}
public function batchUpdate(Request $request, $ganttId)
{
$entities = $request->all();
@ -428,15 +462,18 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
}
if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']);
}
if(!$activityToUpdate->update($entity['data']))
if (!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done;
} else if ($entity['entity'] == "link"){
} else if ($entity['entity'] == "link") {
$linkToUpdate = $link->firstWhere('id', $entity['data']['id']);
if(!$linkToUpdate->update($entity['data']))
if (!$linkToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500);
}
}