@ -3,14 +3,12 @@ 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\UserToActivity;
use App\Models\VersionGantt;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\DB;
use App\Models\UserToActivity;
use App\Models\TmpImport;
use Illuminate\Http\Request;
use Illuminate\Http\Request;
class ActivityController extends Controller
class ActivityController extends Controller
@ -28,14 +26,17 @@ class ActivityController extends Controller
private function getDataActivity($id)
private function getDataActivity($id)
{
{
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = [];
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = [];
if($checkHeader > 0){
if($checkHeader > 0){
$dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first();
$dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first();
$startDate = date_create($dataHeader->start_date);
$startDate = date_create($dataHeader->start_date);
$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->type = "project";
$dataHeader->progress = $dataHeader->persentase_progress / 100;
$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,20 +46,22 @@ 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 = (int) $objRow->persentase_progress / 100;
$objRow->progress = $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);
@ -186,7 +189,10 @@ class ActivityController extends Controller
$parent = $data['parent_id'] ?? null;
$parent = $data['parent_id'] ?? null;
if($parent){
if($parent){
Activity::find($parent)->update(["type_activity"=>"project"]);
$parentData = Activity::find($parent);
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();
}
}
@ -212,16 +218,11 @@ 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 = fals e;
$updateBobot = tru 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;
@ -278,378 +279,141 @@ class ActivityController extends Controller
$dataGet = $builder->get();
$dataGet = $builder->get();
$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);
}
}
public function getPercentagePerDay (Request $request)
public function import (Request $request)
{
{
$dataPayload = $request->all();
$data = $request->all();
$allGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getLatestGantt($val);
}
$dataFinal=[];
$data['created_by'] = $this->currentName;
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);
Activity::where('version_gantt_id', $data['ganttId'])->delete();
$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;
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$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){
$activityStack = [];
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);
}
}
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']);
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
$input['name'] = $activity_row['name'];
{
$input['proyek_id'] = $projectId;
DB::enableQueryLog();
$input['version_gantt_id'] = $data['ganttId'];
$dataPayload = $request->all();
$input['parent_id'] = null;
$allGantt = [];
$input['start_date'] = $startDate->format('Y-m-d');
if(isset($dataPayload['gannt_id'])){
$input['end_date'] = $endDate->format('Y-m-d');
$allGantt = $dataPayload['gannt_id'];
$input['duration'] = $activity_row['duration'];
}else{
$input['bobot_planning'] = $activity_row['weight'];
foreach ($dataPayload['project_id'] as $val) {
$input['persentase_progress'] = 0;
$allGantt[] = $this->getLatestGantt($val);
$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);
}
}
}
$dataFinal=[];
foreach ($allGantt as $keyGantt) {
$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();
if($dataHeader){
$data['activities'][$i]['activity_id'] = $activity->id;
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}else{
if ($i == 0) {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
$activity->type_activity = "project";
$activity->save();
$activity->level = $activity_row['level'];
array_push($activityStack, $activity);
continue;
}
}
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
$activity->level = $activity_row['level'];
continue;
if ($lastStack = end($activityStack)) {
$alreadyHasReport = DB::table('report_activity_material as a')
$levelLowerThanLastStack = $activity->level < $lastStack->level;
->select('a.id')
$levelEqualWithLastStack = $activity->level == $lastStack->level;
->join('m_activity as b', 'b.id', '=', 'a.activity_id')
->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->exists();
if(!$alreadyHasReport)
continue;
$minDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->min("plan_date");
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date");
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end2 = new \DateTime($maxDate);
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin->modify('-1 days'), $interval, $end);
$arr_ActualM = [];
$tempDate = [];
$tempPercentage = [];
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$currentACWP = 0;
$currentBCWP = 0;
foreach ($period as $dt) {
$dataPlanM = DB::table('assign_material_to_activity as ama')
->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->whereDate('ama.plan_date', $dt->format("Y-m-d"))
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', $dt->format("Y-m-d"))
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan=0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
$x++;
}
$w = 0;
if ($levelLowerThanLastStack) {
$dataTempReport = [];
$lastStackIsNotRight = $levelLowerThanLastStack;
$sumPercentageActual=0;
do {
foreach ($dataActualM as $keyActualM) {
array_pop($activityStack);
$sumVolActual = DB::table('assign_material_to_activity')
$lastStack = end($activityStack);
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
if ($activity->level > $lastStack->level)
->where('activity_id', '=', $keyActualM->activity_id)
$lastStackIsNotRight = false;
->groupBy('activity_id')
} while ($lastStackIsNotRight);
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
try {
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
$dataTempReport [$w]['totalacwp'] = $totalACWP;
$w++;
}
}
$arr_ActualM[] = array(
if ($levelEqualWithLastStack) {
'date'=>$dt->format("Y-m-d"),
array_pop($activityStack);
'percentPlan'=>$sumPercentagePlan,
'percentActual'=>$sumPercentageActual,
'plan'=>$dataTempPlan,
'actual'=>$dataTempReport,
);
if(isset($dataPayload['period']) & & $dataPayload['period'] == 'week'){
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}
}
}
}
$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'];
try {
if (@$activityStack[count($activityStack) - 1]->level != $activity->level & & $activity->level != $data['activities'][$i - 1]['level']) {
if(round($totalACWP,0) > $totalRencanaBudget){
array_push($activityStack, $activity);
$estimatedCost = round($totalACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
} catch (\Exception $e) {
return response()->json([
'message' => $e->getMessage(),
"line" => 566,
'gantt' => $keyGantt,
]);
}
$estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget;
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
}
$dataResponse = array(
if ($activity->level < @$data['activities'][$i + 1]['level']) {
"date" =>$tempDate,
unset($activity->level);
"percentage" =>$tempPercentage,
$activity->type_activity = "project";
"data_details" =>$arr_ActualM,
$activity->save();
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
$activity->level = $activity_row['level'];
"acwp" => round($totalACWP,0),
}
"bcwp" => round($totalBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $potential,
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse,
"allGant"=>$allGantt
);
}
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
if (!empty($activity_row['predecessor'])) {
$activity->update([
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no'));
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
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(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
}
}
public function synchronizeReport($gantt_id)
public function uploadTmpImport(Request $request)
{
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
if($request->hasFile('dokumen')){
$reports = [];
$document = $request->file('dokumen');
$ref_id = $request->ref_id;
foreach($activities as $activity) {
$name = $document->getClientOriginalName();
$activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count();
$result = $document->move($this->pathDocument, $name);
if ($countReports === 1) {
if($result){
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
$data = [
foreach($dataReports as $dr) {
'ref_id' => (int)$ref_id,
$reports[] = array(
'file' => $name,
'activity_id'=>$activity_id,
'type_dokumen' => $request->type_dokumen
'min_date'=>$dr->report_date,
];
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
$result = TmpImport::create($data);
if(!$result){
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
}
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
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")
);
}
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
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);
}
}
}
}