Browse Source

Merge branch 'master' of https://git.oslog.id/ordo/adw-backend

pull/3/head
ibnu 2 years ago
parent
commit
af65ea899a
  1. 108
      app/Http/Controllers/ActivityController.php
  2. 4
      app/Http/Controllers/ProjectController.php
  3. 6
      app/Models/Activity.php
  4. 1
      routes/web.php

108
app/Http/Controllers/ActivityController.php

@ -6,6 +6,7 @@ use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\Project;
use App\Models\TemplateGantt;
use App\Models\VersionGantt;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
@ -277,7 +278,112 @@ class ActivityController extends Controller
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}
public function import(Request $request)
{
$data = $request->all();
$data['created_by'] = $this->currentName;
Activity::where('version_gantt_id', $data['ganttId'])->delete();
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$activityStack = [];
foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']);
$endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']);
$input['name'] = $activity_row['name'];
$input['proyek_id'] = $projectId;
$input['version_gantt_id'] = $data['ganttId'];
$input['parent_id'] = null;
$input['start_date'] = $startDate->format('Y-m-d');
$input['end_date'] = $endDate->format('Y-m-d');
$input['duration'] = $activity_row['duration'];
$input['bobot_planning'] = $activity_row['weight'];
$input['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task";
$input['created_by'] = $this->currentName;
if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete();
return response()->json(['status' => 'error', 'message' => 'Input failed on ' . $activity['name'], 'code' => 500], 500);
}
$data['activities'][$i]['activity_id'] = $activity->id;
if ($i == 0) {
$activity->type_activity = "project";
$activity->save();
$activity->level = $activity_row['level'];
array_push($activityStack, $activity);
continue;
}
$activity->level = $activity_row['level'];
if ($lastStack = end($activityStack)) {
$levelLowerThanLastStack = $activity->level < $lastStack->level;
$levelEqualWithLastStack = $activity->level == $lastStack->level;
if ($levelLowerThanLastStack) {
$lastStackIsNotRight = $levelLowerThanLastStack;
do {
array_pop($activityStack);
$lastStack = end($activityStack);
if ($activity->level > $lastStack->level)
$lastStackIsNotRight = false;
} while ($lastStackIsNotRight);
}
if ($levelEqualWithLastStack) {
array_pop($activityStack);
}
}
$activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null;
// there should be better way to except / filter attribute level before save because it's cause error
// cant use except() / filter() on $activity collection somehow
unset($activity->level);
$activity->save();
$activity->level = $activity_row['level'];
if (@$activityStack[count($activityStack) - 1]->level != $activity->level && $activity->level != $data['activities'][$i - 1]['level']) {
array_push($activityStack, $activity);
}
if ($activity->level < @$data['activities'][$i + 1]['level']) {
unset($activity->level);
$activity->type_activity = "project";
$activity->save();
$activity->level = $activity_row['level'];
}
if (!empty($activity_row['predecessor'])) {
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no'));
if (!$predecessorActivity = Activity::find($data['activities'][$key]['activity_id']))
continue;
$predecessorFinishDate = new \DateTime($predecessorActivity->end_date);
$interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date));
$diff = $interval->days;
Link::create([
'created_by' => $this->currentName,
's_activity_id' => $predecessorActivity->id,
't_activity_id' => $activity->id,
'type_link' => 0,
'code_link' => 'FS',
'version_gantt_id' => $data['ganttId'],
'lag' => $diff > 1 ? $diff : null,
]);
}
}
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
}
}

4
app/Http/Controllers/ProjectController.php

@ -245,7 +245,7 @@ class ProjectController extends Controller
$scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual;
$costVariance = (int)$d->rencana_biaya - $rootActivity->biaya_actual ?? 0;
$actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0;
@ -263,7 +263,7 @@ class ProjectController extends Controller
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
}
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek));
$d->plannedCost = $d->rencana_biaya;
$d->plannedCost = (int)$d->rencana_biaya;
$d->actualCost = $actualCost;
$d->lastActivity = $lastActivity ?? "-";
$d->costVariance = $costVariance;

6
app/Models/Activity.php

@ -63,9 +63,9 @@ class Activity extends Model
$data->updatePersentaseProgress();
$data->updateCostActual();
}
if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
$data->updateStartEndDateHeader();
}
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
});
static::deleted(function($data) {

1
routes/web.php

@ -200,6 +200,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial');
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->get('/activity/search', 'ActivityController@search');
$router->post('/activity/import', 'ActivityController@import');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');

Loading…
Cancel
Save