@ -3,11 +3,14 @@ namespace App\Http\Controllers;
use App\Models\Activity;
use App\Models\Activity;
use App\Models\CommentActivity;
use App\Models\CommentActivity;
use App\Models\Holiday;
use App\Models\Link;
use App\Models\Link;
use App\Models\Project;
use App\Models\Project;
use App\Models\ReportActivity;
use App\Models\TemplateGantt;
use App\Models\TemplateGantt;
use App\Models\VersionGantt;
use App\Models\UserToActivity;
use App\Models\UserToActivity;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Http\Request;
class ActivityController extends Controller
class ActivityController extends Controller
@ -32,10 +35,7 @@ class ActivityController extends Controller
$endDate = date_create($dataHeader->end_date);
$endDate = date_create($dataHeader->end_date);
$dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s");
$dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s");
$dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s");
$dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s");
$dataHeader->progress = $dataHeader->persentase_progress / 100;
$dataHeader->type = "project";
$dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start),"Y-m-d H:i:s") : NULL;
$dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end),"Y-m-d H:i:s") : NULL;
$dataHeader->type = "header";
$dataHeader->text = $dataHeader->name;
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$finalData[] = $dataHeader;
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
@ -45,22 +45,20 @@ class ActivityController extends Controller
foreach($data as $objRow){
foreach($data as $objRow){
$type = "project";
$type = "project";
$dataChildren = $this->getChildren($id, $objRow->id);
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
if($objRow->type_activity=="milestone")
if($objRow->type_activity=="milestone")
$type = $objRow->type_activity;
$type = $objRow->type_activity;
if(empty($dataChildren))
if(empty($dataChildren))
$type = "task";
$type = "task";
$objRow->text = $objRow->name;
$objRow->text = $objRow->name;
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
$objRow->start_date = date_format($startDate,"Y-m-d H:i:s");
$objRow->start_date = date_format($startDate,"Y-m-d H:i:s");
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->progress = (int) $objRow->persentase_progress / 100;
$dataChildren = $this->getChildren($id, $objRow->id);
$objRow->type = $type;
$objRow->type = $type;
$finalData[] = $objRow;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
$finalData = array_merge($finalData, $dataChildren);
@ -188,10 +186,7 @@ class ActivityController extends Controller
$parent = $data['parent_id'] ?? null;
$parent = $data['parent_id'] ?? null;
if($parent){
if($parent){
$parentData = Activity::find($parent);
Activity::find($parent)->update(["type_activity"=>"project"]);
if($parentData->parent_id) {
$parentData->update(["type_activity" => "project"]);
}
CommentActivity::where('activity_id', $parent)->delete();
CommentActivity::where('activity_id', $parent)->delete();
UserToActivity::where('activity_id', $parent)->delete();
UserToActivity::where('activity_id', $parent)->delete();
}
}
@ -217,11 +212,16 @@ class ActivityController extends Controller
if(empty($id) || !is_int((int)$id))
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400);
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400);
$updateBobot = tru e;
$updateBobot = fals e;
if(!$data = Activity::find($id))
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404);
$dataUpdate = $request->all();
$dataUpdate = $request->all();
$oldRencanaBiaya = $data->rencana_biaya;
$newRencanaBiaya = str_replace(",",".",$request->rencana_biaya);
if($oldRencanaBiaya != $newRencanaBiaya)
$updateBobot = true;
$dataUpdate['name'] = $request->text;
$dataUpdate['name'] = $request->text;
$dataUpdate['persentase_progress'] = $request->progress*100;
$dataUpdate['persentase_progress'] = $request->progress*100;
$dataUpdate['updated_by'] = $this->currentName;
$dataUpdate['updated_by'] = $this->currentName;
@ -280,35 +280,113 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}
public function import (Request $request)
public function getPercentagePerDay (Request $request)
{
{
$data = $request->all();
$dataPayload = $request->all();
$allGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getLatestGantt($val);
}
$dataFinal=[];
foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']);
$holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get();
$dateHoliday = []; //$holiday->all();
foreach ($holidays as $holiday) {
$startH = new \DateTime($holiday->date);
$endH = clone $startH;
$endH->modify('+'.$holiday->duration.' day');
$intervalH = \DateInterval::createFromDateString('1 day');
$periodH = new \DatePeriod($startH, $intervalH, $endH);
foreach ($periodH as $dt) {
$dateHoliday[] = $dt->format("Y-m-d");
}
}
$verGantt = VersionGantt::find($val['last_gantt_id']);
$configOff = $verGantt->config_dayoff;
if($configOff & & $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}else{
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end = $end->modify( '+1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}
$totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0;
$dataDate = [];
$dataPercen = [];
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) & & !in_array($currentDate, $dateHoliday))
{
$totalPercentage = 0;
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
}else{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
}
foreach ($dataActivity as $activity) {
$duration = $activity->duration;
if($totalRencanaBudget > 0 & & $duration > 0){
$totalPercentage = $totalPercentage + ((($activity->rencana_biaya/$totalRencanaBudget)*100)/$duration);
}
}
$currentPercentage = $currentPercentage + $totalPercentage;
$dataDate[] = $currentDate;
$dataPercen[] = $currentPercentage;
}else{
$dataDate[] = $currentDate;
$dataPercen[] = "dateOff";
}
}
$dataPercentage = array(
"date"=>$dataDate,
"percentage"=>$dataPercen
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataPercentage
);
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400);
}
}
$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']);
< < < < < < < HEAD
$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;
=======
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
{
{
DB::enableQueryLog();
DB::enableQueryLog();
@ -325,26 +403,13 @@ class ActivityController extends Controller
foreach ($allGantt as $keyGantt) {
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$dataProject = Project::find($keyGantt['proyek_id']);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first();
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first();
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
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);
}
< < < < < < < HEAD
$data['activities'][$i]['activity_id'] = $activity->id;
if ($i == 0) {
if($dataHeader){
$activity->type_activity = "project";
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
$activity->save();
}else{
$activity->level = $activity_row['level'];
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
array_push($activityStack, $activity);
continue;
}
}
$activity->level = $activity_row['level'];
=======
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
continue;
continue;
@ -524,67 +589,67 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
if ($lastStack = end($activityStack)) {
private function getLatestGantt($id){
$levelLowerThanLastStack = $activity->level < $lastStack->level;
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$levelEqualWithLastStack = $activity->level == $lastStack->level;
$data = array(
"last_gantt_id" => $maxGanttId,
if ($levelLowerThanLastStack) {
"proyek_id" => $id
$lastStackIsNotRight = $levelLowerThanLastStack;
);
do {
return $data;
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;
public function setBaseline($gantt_id)
// 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
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
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']) {
foreach ($activities as $activity) {
array_push($activityStack, $activity);
$activity->update([
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
]);
}
}
if ($activity->level < @$data['activities'][$i + 1]['level']) {
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
unset($activity->level);
$activity->type_activity = "project";
$activity->save();
$activity->level = $activity_row['level'];
}
}
if (!empty($activity_row['predecessor'])) {
public function synchronizeReport($gantt_id)
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no'));
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
if (!$predecessorActivity = Activity::find($data['activities'][$key]['activity_id']))
$reports = [];
continue;
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) {
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$dr->report_date,
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
}
}
if ($countReports > 1) {
$firstReport = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivity::where('activity_id', $activity_id)->orderByDesc('report_date')->first();
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$firstReport->report_date,
'max_date'=>date_modify(date_create($lastReport->report_date), "1 days")
);
$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);
for ($i=0; $i < count ( $ reports ) ; $ i + + ) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
}
}
}