@ -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
@ -35,7 +33,10 @@ 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->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;
@ -280,376 +281,139 @@ 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 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=[];
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);
$data['created_by'] = $this->currentName;
$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;
Activity::where('version_gantt_id', $data['ganttId'])->delete();
$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) {
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$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;
}
$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){
if (!$activity = Activity::create($input)) {
$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::where('version_gantt_id', $data['ganttId'])->delete();
}else{
return response()->json(['status' => 'error', 'message' => 'Input failed on ' . $activity['name'], 'code' => 500], 500);
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}
}
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
$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;
continue;
}
$alreadyHasReport = DB::table('report_activity_material as a')
$activity->level = $activity_row['level'];
->select('a.id')
->join('m_activity as b', 'b.id', '=', 'a.activity_id')
->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->exists();
if(!$alreadyHasReport)
if ($lastStack = end($activityStack)) {
continue;
$levelLowerThanLastStack = $activity->level < $lastStack->level;
$levelEqualWithLastStack = $activity->level == $lastStack->level;
$minDate = DB::table('assign_material_to_activity as ama')
if ($levelLowerThanLastStack) {
->where("ama.proyek_id", $keyGantt['proyek_id'])
$lastStackIsNotRight = $levelLowerThanLastStack;
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
do {
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
array_pop($activityStack);
->min("plan_date");
$lastStack = end($activityStack);
if ($activity->level > $lastStack->level)
$maxDate = DB::table('assign_material_to_activity as ama')
$lastStackIsNotRight = false;
->where("ama.proyek_id", $keyGantt['proyek_id'])
} while ($lastStackIsNotRight);
->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;
$dataTempReport = [];
$sumPercentageActual=0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->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(
'date'=>$dt->format("Y-m-d"),
'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);
}
}
}
if ($levelEqualWithLastStack) {
try {
array_pop($activityStack);
if(round($totalACWP,0) > $totalRencanaBudget){
$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;
$activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null;
if($costDeviation > 0){
// there should be better way to except / filter attribute level before save because it's cause error
$potential = "SAVING";
// cant use except() / filter() on $activity collection somehow
} else {
unset($activity->level);
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
$activity->save();
}
$activity->level = $activity_row['level'];
$dataResponse = array(
"date" =>$tempDate,
"percentage" =>$tempPercentage,
"data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"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(
if (@$activityStack[count($activityStack) - 1]->level != $activity->level & & $activity->level != $data['activities'][$i - 1]['level']) {
"proyek_name"=> $dataProject->nama,
array_push($activityStack, $activity);
"data"=>$dataResponse,
"allGant"=>$allGantt
);
}
}
if ($activity->level < @$data['activities'][$i + 1]['level']) {
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
unset($activity->level);
$activity->type_activity = "project";
$activity->save();
$activity->level = $activity_row['level'];
}
}
private function getLatestGantt($id){
if (!empty($activity_row['predecessor'])) {
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no'));
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
public function setBaseline($gantt_id)
if (!$predecessorActivity = Activity::find($data['activities'][$key]['activity_id']))
{
continue;
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$predecessorFinishDate = new \DateTime($predecessorActivity->end_date);
$interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date));
$diff = $interval->days;
foreach ($activities as $activity) {
Link::create([
$activity->update([
'created_by' => $this->currentName,
"planned_start"=>$activity->start_date,
's_activity_id' => $predecessorActivity->id,
"planned_end"=>$activity->end_date,
'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();
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")
);
}
$result = $document->move($this->pathDocument, $name);
}
if($result){
$data = [
'ref_id' => (int)$ref_id,
'file' => $name,
'type_dokumen' => $request->type_dokumen
];
for ($i=0; $i < count ( $ reports ) ; $ i + + ) {
$result = TmpImport::create($data);
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
if(!$result){
$activity->end_date = $reports[$i]['max_date'];
unlink($this->pathDocument.$name);
$activity->save( );
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
}
}
}