Browse Source

Merge pull request 'add status filter' (#191) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#191
pull/3/head
ibnu 1 year ago
parent
commit
1554814ab0
  1. 20
      app/Helpers/MasterFunctionsHelper.php
  2. 37
      app/Http/Controllers/ActivityController.php
  3. 26
      app/Http/Controllers/PresenceController.php
  4. 30
      app/Http/Controllers/ProjectController.php
  5. 16
      app/Http/Controllers/UserToActivityController.php
  6. 2
      app/Models/UserToActivity.php
  7. 1
      routes/web.php

20
app/Helpers/MasterFunctionsHelper.php

@ -36,6 +36,26 @@ class MasterFunctionsHelper
return json_decode($output); 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) public function getLatestGantt($id)
{ {
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");

37
app/Http/Controllers/ActivityController.php

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity; use App\Models\Activity;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
@ -412,6 +413,39 @@ 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){
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) public function batchUpdate(Request $request, $ganttId)
{ {
$entities = $request->all(); $entities = $request->all();
@ -428,6 +462,9 @@ 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;
if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
}
if (isset($entity['data']['target'])) { if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']); $this->updateOrder($entity['data']['id'], $entity['data']['target']);
} }

26
app/Http/Controllers/PresenceController.php

@ -260,13 +260,17 @@ class PresenceController extends Controller
// geom ada di table activity // geom ada di table activity
// $clock_time = // $clock_time =
$user = HumanResource::find($params->user_id); $user = HumanResource::find($params->user_id);
$geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") $geomQuery = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id")
->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id")
->where("ahta.user_id", $params->user_id) ->where("ahta.user_id", $params->user_id)
->whereNotNull("ma.geom") ->whereNotNull("ma.geom")
->whereDate("ma.start_date", "<=", $params->time) ->whereDate("ma.start_date", "<=", $params->time)
->whereDate("ma.end_date", ">=", $params->time) ->whereDate("ma.end_date", ">=", $params->time);
->get(); if (isset($params->report_k3['proyek_id'])) {
$geom = $geomQuery->where("ma.proyek_id", $params->report_k3['proyek_id'])->get();
} else {
$geom = $geomQuery->get();
}
$temp = []; $temp = [];
if (count($geom) > 0) { if (count($geom) > 0) {
foreach($geom as $dataGeom){ foreach($geom as $dataGeom){
@ -342,6 +346,13 @@ class PresenceController extends Controller
"status_assign" => true "status_assign" => true
); );
} }
} else {
// bypass work area restriction
$temp[]=array(
"activity_id" => null,
"boundary" => true,
"status_assign" => true
);
} }
} }
// assign and not in boundary // assign and not in boundary
@ -356,6 +367,14 @@ class PresenceController extends Controller
} }
} }
else{ else{
if ($user->status_boundary) {
// bypass work area restriction
$temp[]=array(
"activity_id" => null,
"boundary" => true,
"status_assign" => true
);
} else {
// not assign // not assign
$temp[]=array( $temp[]=array(
"activity_id" => null, "activity_id" => null,
@ -363,6 +382,7 @@ class PresenceController extends Controller
"status_assign" => false "status_assign" => false
); );
} }
}
return $temp; return $temp;
} }

30
app/Http/Controllers/ProjectController.php

@ -416,17 +416,21 @@ class ProjectController extends Controller
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
} }
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
} }
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) { for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
}
if($reports[$i]['status'] != 'done'){ if($reports[$i]['status'] != 'done'){
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ }else if($reports[$i]['status'] == 'done'){
@ -434,22 +438,14 @@ class ProjectController extends Controller
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date']; $activity->actual_start = $reports[$i]['min_date'];
$activity->save(); $activity->save();
} }
foreach($activities as $activity) {
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
} }

16
app/Http/Controllers/UserToActivityController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial;
use Datatables; use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
@ -41,6 +42,8 @@ class UserToActivityController extends Controller
"activity_id" => $request->activity_id, "activity_id" => $request->activity_id,
"role_proyek_id" => $users_role[$index], "role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"start_date" => $request->start_date,
"end_date" => $request->end_date,
"created_by" => $this->currentName, "created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id "version_gantt_id" => $request->version_gantt_id
); );
@ -140,6 +143,7 @@ class UserToActivityController extends Controller
if (isset($join_column)) { if (isset($join_column)) {
$startDate = $join_column['start_date']; $startDate = $join_column['start_date'];
$endDate = $join_column['end_date']; $endDate = $join_column['end_date'];
$status = $join_column['status'];
$startDate = date("Y-m-d H:i:sO", strtotime($startDate)); $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $endDate = date("Y-m-d H:i:sO", strtotime($endDate));
$builder->where(function ($query) use ($startDate, $endDate) { $builder->where(function ($query) use ($startDate, $endDate) {
@ -154,6 +158,16 @@ class UserToActivityController extends Controller
}); });
} }
$dataGet = $builder->get(); $dataGet = $builder->get();
if (isset($status) && $status != "") {
$filteredData = [];
foreach ($dataGet as $value) {
$assignMaterial = AssignMaterial::where('activity_id', $value->activity_id)->first();
if ($assignMaterial->status_activity == $status) {
$filteredData[] = $value;
}
}
$dataGet = $filteredData;
}
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
@ -204,7 +218,7 @@ class UserToActivityController extends Controller
public function datatables(Request $request){ public function datatables(Request $request){
$id_activity = $request->query('idact'); $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_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") ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity) ->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', 'version_gantt_id',
'role_proyek_id', 'role_proyek_id',
'activity_id', 'activity_id',
'start_date',
'end_date',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', '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-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add'); $router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit'); $router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');

Loading…
Cancel
Save