Browse Source

countDays, schedule, hr date

pull/3/head
wahyu 1 year ago
parent
commit
1bb91826ae
  1. 20
      app/Helpers/MasterFunctionsHelper.php
  2. 34
      app/Http/Controllers/ActivityController.php
  3. 16
      app/Http/Controllers/ProjectController.php
  4. 4
      app/Http/Controllers/UserToActivityController.php
  5. 2
      app/Models/UserToActivity.php
  6. 1
      routes/web.php

20
app/Helpers/MasterFunctionsHelper.php

@ -36,6 +36,26 @@ class MasterFunctionsHelper
return json_decode($output);
}
public static function countDays($ganttId, $start, $end){
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;
$diff = date_diff($start, $end);
$endCount = clone $end;
$duration = $diff->days + 1;
$daysRemaining = $duration;
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endCount->modify('-1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int) $endCount->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
// continue; // Skip the day off and continue to the next day
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
}
return $duration;
}
public function getLatestGantt($id)
{
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");

34
app/Http/Controllers/ActivityController.php

@ -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();

16
app/Http/Controllers/ProjectController.php

@ -438,23 +438,9 @@ class ProjectController extends Controller
}
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$dayOffs = VersionGantt::where('id', $activity->version_gantt_id)->first()->config_dayoff;
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$diff = date_diff($startDate, $endDate);
$duration = $diff->days + 1;
$daysRemaining = $duration;
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endDate->modify('-1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int) $endDate->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
// continue; // Skip the day off and continue to the next day
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
}
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date'];
$activity->save();

4
app/Http/Controllers/UserToActivityController.php

@ -42,6 +42,8 @@ class UserToActivityController extends Controller
"activity_id" => $request->activity_id,
"role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id,
"start_date" => $request->start_date,
"end_date" => $request->end_date,
"created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id
);
@ -216,7 +218,7 @@ class UserToActivityController extends Controller
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
$data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity)

2
app/Models/UserToActivity.php

@ -18,6 +18,8 @@ class UserToActivity extends Model
'version_gantt_id',
'role_proyek_id',
'activity_id',
'start_date',
'end_date',
'created_at',
'created_by',
'updated_at',

1
routes/web.php

@ -209,6 +209,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');

Loading…
Cancel
Save