@ -21,8 +21,8 @@ class ActivityController extends Controller
public function getByGanttId($id, $proyek_id)
public function getByGanttId($id, $proyek_id)
{
{
$gantt = VersionGantt::find($id);
$gantt = VersionGantt::find($id);
if (Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
if (Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
if (!$gantt->hierarchy_ftth_id) {
if (!$gantt->hierarchy_ftth_id) {
$this->cloneTemplate($id, $proyek_id);
$this->cloneTemplate($id, $proyek_id);
} else {
} else {
$this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id);
$this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id);
@ -31,46 +31,59 @@ class ActivityController extends Controller
$dataGantt = $this->getDataActivity($id);
$dataGantt = $this->getDataActivity($id);
return response()->json(['status'=>'success','data'=> $dataGantt,'code'=>200], 200);
return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200);
}
}
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();
if($checkHeader > 0){
$finalData = [];
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->progress = $dataHeader->persentase_progress / 100;
$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_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->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL;
$actualStart = $this->getActivityFirst($dataHeader->id);
$dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d");
$actualEnd = $this->getActivityLast($dataHeader->id);
$dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
$dataHeader->type = "header";
$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('sortorder', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
}else{
} else {
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
}
foreach($data as $objRow){
foreach ($data as $objRow) {
$type = "project";
$type = "project";
$dataChildren = $this->getChildren($id, $objRow->id);
$dataChildren = $this->getChildren($id, $objRow->id);
$startDate = date_create($objRow->start_date);
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_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;
$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;
$actualStart = $this->getActivityFirst($objRow->id);
$objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL;
$actualEnd = $this->getActivityLast($objRow->id);
$objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->type = $type;
$objRow->type = $type;
$finalData[] = $objRow;
$finalData[] = $objRow;
@ -79,23 +92,22 @@ class ActivityController extends Controller
$dataLink = Link::where('version_gantt_id', $id)->get();
$dataLink = Link::where('version_gantt_id', $id)->get();
$finalLink = [];
$finalLink = [];
foreach($dataLink as $objRow)
foreach ($dataLink as $objRow) {
{
$dataRow = array(
$dataRow = array(
'id'=>$objRow->id,
'id' => $objRow->id,
'source'=>$objRow->s_activity_id,
'source' => $objRow->s_activity_id,
'target'=>$objRow->t_activity_id,
'target' => $objRow->t_activity_id,
'type'=>$objRow->type_link,
'type' => $objRow->type_link,
'code'=>$objRow->code_link
'code' => $objRow->code_link
);
);
if($objRow->lag)
if ($objRow->lag)
$dataRow['lag'] = $objRow->lag;
$dataRow['lag'] = $objRow->lag;
$finalLink[] = $dataRow;
$finalLink[] = $dataRow;
}
}
$resultData = array(
$resultData = array(
"data"=>$finalData,
"data" => $finalData,
"links"=>$finalLink
"links" => $finalLink
);
);
return $resultData;
return $resultData;
@ -105,23 +117,35 @@ class ActivityController extends Controller
{
{
$finalData = [];
$finalData = [];
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach($data as $objRow){
foreach ($data as $objRow) {
$objRow->parent = $parent_id;
$objRow->parent = $parent_id;
$objRow->text = $objRow->name;
$objRow->text = $objRow->name;
$objRow->progress = (float)$objRow->persentase_progress/100;
$objRow->progress = (float) $objRow->persentase_progress / 100;
$startDate = date_create($objRow->start_date);
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_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;
$dataChildren = $this->getChildren($gantt_id, $objRow->id);
$dataChildren = $this->getChildren($gantt_id, $objRow->id);
if($objRow->type_activity=="milestone"){
if ($objRow->type_activity == "milestone") {
$objRow->type = $objRow->type_activity;
$objRow->type = $objRow->type_activity;
}elseif(empty($dataChildren)){
$objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL;
} elseif (empty($dataChildren)) {
$objRow->type = "task";
$objRow->type = "task";
}else{
$objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL;
$objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL;
if(isset($objRow->actual_start)){
$objRow->auto_scheduling = false;
}
} else {
$objRow->type = "project";
$objRow->type = "project";
$actualStart = $this->getActivityFirst($objRow->id);
$objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL;
$actualEnd = $this->getActivityLast($objRow->id);
$objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
}
}
$finalData[] = $objRow;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
$finalData = array_merge($finalData, $dataChildren);
@ -129,33 +153,62 @@ class ActivityController extends Controller
return $finalData;
return $finalData;
}
}
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) {
public function getActivityFirst($parentId){
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first();
if (!isset($activity)) {
return null;
}
if($activity->type_activity == "task"){
// Log::info("activity ", [$activity]);
return $activity->actual_start;
}else{
return $this->getActivityFirst($activity->id);
}
}
public function getActivityLast($parentId){
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first();
if (!isset($activity)) {
return null;
}
if($activity->type_activity == "task"){
// Log::info("activity ", [$activity]);
return $activity->actual_end;
}else{
return $this->getActivityLast($activity->id);
}
}
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null)
{
$project = Project::find($proyek_id);
$project = Project::find($proyek_id);
if($hierarchy_ftth_id){
if ($hierarchy_ftth_id) {
$gantt = VersionGantt::find($id);
$gantt = VersionGantt::find($id);
$rootActivity = Activity::create([
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'version_gantt_id' => $id,
'proyek_id'=>$proyek_id,
'proyek_id' => $proyek_id,
'name'=> $gantt->name_version,
'name' => $gantt->name_version,
'start_date'=> $project->mulai_proyek,
'start_date' => $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'end_date' => $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'rencana_biaya' => $project->rencana_biaya,
'type_activity'=> 'project',
'type_activity' => 'project',
'created_by'=>$this->currentName,
'created_by' => $this->currentName,
'sortorder'=>1
'sortorder' => 1
]);
]);
} else {
} else {
$rootActivity = Activity::create([
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'version_gantt_id' => $id,
'proyek_id'=>$proyek_id,
'proyek_id' => $proyek_id,
'name'=> $project->nama,
'name' => $project->nama,
'kode_sortname'=>$project->kode_sortname,
'kode_sortname' => $project->kode_sortname,
'start_date'=> $project->mulai_proyek,
'start_date' => $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'end_date' => $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'rencana_biaya' => $project->rencana_biaya,
'type_activity'=> 'project',
'type_activity' => 'project',
'created_by'=>$this->currentName,
'created_by' => $this->currentName,
'sortorder'=>1
'sortorder' => 1
]);
]);
}
}
@ -164,19 +217,19 @@ class ActivityController extends Controller
->orderByRaw('id ASC')
->orderByRaw('id ASC')
->get();
->get();
foreach($resultTypeProject as $objRow){
foreach ($resultTypeProject as $objRow) {
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'type_activity' => $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
'version_gantt_id' => $id,
'parent_id'=>$rootActivity->id,
'parent_id' => $rootActivity->id,
'proyek_id'=>$proyek_id,
'proyek_id' => $proyek_id,
'name'=> $objRow->name_activity,
'name' => $objRow->name_activity,
'start_date'=>date("Y-m-d H:i:s"),
'start_date' => date("Y-m-d H:i:s"),
'end_date'=>date("Y-m-d H:i:s"),
'end_date' => date("Y-m-d H:i:s"),
'created_by'=> $this->currentName,
'created_by' => $this->currentName,
'sortorder'=>$max+ 1
'sortorder' => $max + 1
]);
]);
$this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek);
$this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek);
}
}
@ -185,19 +238,19 @@ class ActivityController extends Controller
private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay)
private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay)
{
{
$data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
$data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
foreach ($data as $objRow) {
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'type_activity' => $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
'version_gantt_id' => $id,
'parent_id'=>$parent_new,
'parent_id' => $parent_new,
'proyek_id'=>$proyek_id,
'proyek_id' => $proyek_id,
'name'=> $objRow->name_activity,
'name' => $objRow->name_activity,
'start_date'=>$firstDay,
'start_date' => $firstDay,
'end_date'=>$firstDay,
'end_date' => $firstDay,
'created_by'=>$this->currentName,
'created_by' => $this->currentName,
'sortorder'=>$max+ 1
'sortorder' => $max + 1
]);
]);
$this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay);
$this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay);
}
}
@ -206,7 +259,7 @@ class ActivityController extends Controller
public function add(Request $request)
public function add(Request $request)
{
{
$this->validate($request, [
$this->validate($request, [
'version_gantt_id'=>'required'
'version_gantt_id' => 'required'
]);
]);
$data = $request->all();
$data = $request->all();
@ -215,75 +268,79 @@ class ActivityController extends Controller
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder');
$max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder');
$data['sortorder'] = $max + 1;
$data['sortorder'] = $max + 1;
if (!isset($data['type_activity'])) {
$data['type_activity'] = "task";
$data['type_activity'] = "task";
}
$parent = $data['parent_id'] ?? null;
$parent = $data['parent_id'] ?? null;
if($parent){
if ($parent) {
$parentData = Activity::find($parent);
$parentData = Activity::find($parent);
if($parentData->parent_id) {
if ($parentData->parent_id) {
$parentData->update(["type_activity" => "project"]);
$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();
}
}
if(!$result = Activity::create($data))
if (!$result = Activity::create($data))
return response()->json(['status'=>'failed','action'=>'error','code'=> 500], 500);
return response()->json(['status' => 'failed', 'action' => 'error', 'code' => 500], 500);
return response()->json(['status'=>'success','action'=>'inserted', 'tid'=>$result->id,'code'=>200], 200);
return response()->json(['status' => 'success', 'action' => 'inserted', 'tid' => $result->id, 'code' => 200], 200);
}
}
public function edit($id){
public function edit($id)
if(empty($id) || !is_int((int)$id))
{
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if (empty($id) || !is_int((int) $id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
if(!$result = Activity::find($id))
if (!$result = Activity::find($id))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $result], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}
}
public function update(Request $request, $id)
public function update(Request $request, $id)
{
{
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 = true;
$updateBobot = true;
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();
$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;
unset($dataUpdate['sortorder']);
unset($dataUpdate['sortorder']);
if($data->type_activity!='header')
if ($data->type_activity != 'header')
$dataUpdate['type_activity'] = $request->type;
$dataUpdate['type_activity'] = $request->type;
if($request->has("target")){
if ($request->has("target")) {
$this->updateOrder($id, $request->target);
$this->updateOrder($id, $request->target);
}
}
if(!$data->update($dataUpdate))
if (!$data->update($dataUpdate))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400);
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed updated!', 'code' => 400], 400);
return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200);
return response()->json(['status' => 'success', 'update_bobot' => $updateBobot, 'data' => $dataUpdate, 'action' => 'updated', 'message' => 'Activity updated!', 'code' => 200], 200);
}
}
private function updateOrder($taskId, $target){
private function updateOrder($taskId, $target)
{
$nextTask = false;
$nextTask = false;
$targetId = $target;
$targetId = $target;
if(strpos($target, "next:") === 0) {
if (strpos($target, "next:") === 0) {
$targetId = substr($target, strlen("next:"));
$targetId = substr($target, strlen("next:"));
$nextTask = true;
$nextTask = true;
}
}
if ($targetId == "null")
if ($targetId == "null")
return;
return;
$targetOrder = Activity::find($targetId)->sortorder;
$targetOrder = Activity::find($targetId)->sortorder;
if ($nextTask)
if ($nextTask)
$targetOrder++;
$targetOrder++;
Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder");
Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder");
@ -293,40 +350,72 @@ class ActivityController extends Controller
$updatedTask->save();
$updatedTask->save();
}
}
public function updateRegular(Request $request, $id){
public function updateRegular(Request $request, $id)
if(empty($id) || !is_int((int)$id))
{
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if (empty($id) || !is_int((int) $id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = Activity::find($id);
$data = Activity::find($id);
if(!$data = Activity::find($id))
if (!$data = Activity::find($id))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data->update($request->all()))
if (!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Activity Updated!','code'=> 200], 200);
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function batchUpdate(Request $request, $ganttId)
{
$entities = $request->all();
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activity = Activity::where('version_gantt_id',$ganttId)->get();
$link = Link::where('version_gantt_id', $ganttId)->get();
if (!$activity)
return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404);
if (!$link)
return response()->json(['status' => 'failed', 'message' => 'Link not found!', 'code' => 404], 404);
foreach ($entities as $entity) {
if ($entity['entity'] == "task") {
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']);
}
if(!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done;
} else if ($entity['entity'] == "link"){
$linkToUpdate = $link->firstWhere('id', $entity['data']['id']);
if(!$linkToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500);
}
}
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
}
public function delete($id)
public function delete($id)
{
{
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);
if(!$data->delete())
if (!$data->delete())
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=> 500], 500);
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500);
return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200);
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200);
}
}
public function getUpdate($id)
public function getUpdate($id)
{
{
if(!$data = Activity::find($id))
if (!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=>400], 400);
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 400], 400);
$data->progress = (float) $data->persentase_progress / 100;
$data->progress = (float) $data->persentase_progress / 100;
$data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya);
$data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya);
return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200);
return response()->json(['status' => 'success', "data" => $data, 'code' => 200], 200);
}
}
public function search(Request $request)
public function search(Request $request)
@ -336,7 +425,7 @@ class ActivityController extends Controller
$countBuilder = $dataBuilder['count'];
$countBuilder = $dataBuilder['count'];
$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);
}
}
// before upload file
// before upload file
@ -349,46 +438,46 @@ class ActivityController extends Controller
Activity::where('version_gantt_id', $data['ganttId'])->delete();
Activity::where('version_gantt_id', $data['ganttId'])->delete();
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$dayOffs = VersionGantt::find( $data['ganttId'])->first()->config_dayoff;
$dayOffs = VersionGantt::where('id', $data['ganttId'])->first()->config_dayoff;
$activityStack = [];
$activityStack = [];
$hasWeight = false;
$hasWeight = false;
foreach ($data['activities'] as $key => $value) {
foreach ($data['activities'] as $key => $value) {
if (isset($value['weight']) & & $value['weight'] != null & & $value['weight'] != 0){
if (isset($value['weight']) & & $value['weight'] != null & & $value['weight'] != 0) {
$hasWeight = true;
$hasWeight = true;
break;
break;
}
}
}
}
if(!$hasWeight) {
if (!$hasWeight) {
foreach ($data['activities'] as $key => $value) {
foreach ($data['activities'] as $key => $value) {
if($key == 0) {
if ($key == 0) {
$data['activities'][$key]['weight'] = 100;
$data['activities'][$key]['weight'] = 100;
} else {
} else {
$parentWeight = 0;
$parentWeight = 0;
$siblingsCount = 1;
$siblingsCount = 1;
$i = $key;
$i = $key;
while($i > 0) {
while ($i > 0) {
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level'] - 1) {
$parentWeight = $data['activities'][$i - 1]['weight'];
$parentWeight = $data['activities'][$i - 1]['weight'];
break;
break;
}
}
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) {
$siblingsCount++;
$siblingsCount++;
}
}
$i--;
$i--;
}
}
$i = $key+ 1;
$i = $key + 1;
while ($i < count ( $ data [ ' activities ' ] ) ) {
while ($i < count ( $ data [ ' activities ' ] ) ) {
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level'] - 1) {
break;
break;
}
}
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) {
$siblingsCount++;
$siblingsCount++;
}
}
$i++;
$i++;
@ -396,7 +485,8 @@ class ActivityController extends Controller
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
}
}
};
}
;
}
}
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
foreach ($data['activities'] as $i => $activity_row) {
foreach ($data['activities'] as $i => $activity_row) {
@ -410,8 +500,8 @@ class ActivityController extends Controller
$endDate->modify('+1 day');
$endDate->modify('+1 day');
// Check if the current day is a day off (Sunday or Saturday)
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int) $endDate->format('w');
$currentDayOfWeek = (int) $endDate->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
continue; // Skip the day off and continue to the next day
continue; // Skip the day off and continue to the next day
}
}
@ -457,8 +547,12 @@ class ActivityController extends Controller
do {
do {
array_pop($activityStack);
array_pop($activityStack);
$lastStack = end($activityStack);
$lastStack = end($activityStack);
if ($lastStack) {
if ($activity->level > $lastStack->level)
if ($activity->level > $lastStack->level)
$lastStackIsNotRight = false;
$lastStackIsNotRight = false;
} else {
$lastStackIsNotRight = false;
}
} while ($lastStackIsNotRight);
} while ($lastStackIsNotRight);
}
}
@ -527,7 +621,8 @@ class ActivityController extends Controller
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
}
}
private function getLatestGantt($id){
private function getLatestGantt($id)
{
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
$data = array(
"last_gantt_id" => $maxGanttId,
"last_gantt_id" => $maxGanttId,
@ -540,20 +635,20 @@ class ActivityController extends Controller
{
{
$dataPayload = $request->all();
$dataPayload = $request->all();
$allGantt = [];
$allGantt = [];
if(isset($dataPayload['gannt_id'])){
if (isset($dataPayload['gannt_id'])) {
$allGantt = $dataPayload['gannt_id'];
$allGantt = $dataPayload['gannt_id'];
}else{
} else {
foreach ($dataPayload['project_id'] as $val) {
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getLatestGantt($val);
$allGantt[] = $this->getLatestGantt($val);
}
}
}
}
$dataFinal=[];
$dataFinal = [];
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();
if($dataHeader){
if ($dataHeader) {
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
$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{
} else {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}
}
$minDate = DB::table('assign_material_to_activity as ama')
$minDate = DB::table('assign_material_to_activity as ama')
@ -574,8 +669,8 @@ class ActivityController extends Controller
$arr_ActualM = [];
$arr_ActualM = [];
$tempDate = [];
$tempDate = [];
$tempPercentage = [];
$tempPercentage = [];
$tempTtlPercentPlan=0;
$tempTtlPercentPlan = 0;
$tempTtlPercentActual=0;
$tempTtlPercentActual = 0;
$currentACWP = 0;
$currentACWP = 0;
$budgetControlACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
$currentProgressActivity = 0;
@ -598,7 +693,7 @@ class ActivityController extends Controller
->get();
->get();
$dataTempPlan = [];
$dataTempPlan = [];
$x = 0;
$x = 0;
$sumPercentagePlan=0;
$sumPercentagePlan = 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
foreach ($dataPlanM as $keyPlanM) {
@ -607,99 +702,100 @@ class ActivityController extends Controller
->where('activity_id', '=', $keyPlanM->activity_id)
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->groupBy('activity_id')
->first();
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan[$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan[$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan[$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan[$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$dataTempPlan[$x]['percentage'] = ($keyPlanM->qty_planning / $sumVolPlan->ttl_qty_plan) * $keyPlanM->bobot_planning;
$sumPercentagePlan+=($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;
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
$dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
$x++;
$x++;
}
}
$w = 0;
$w = 0;
$dataTempReport = [];
$dataTempReport = [];
$sumPercentageActual=0;
$sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) {
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->groupBy('activity_id')
->first();
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport[$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport[$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport[$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
$totalACWP += $keyActualM->biaya_actual / $keyActualM->duration;
$dataTempReport [$w]['totalacwp'] = $totalACWP;
$dataTempReport[$w]['totalacwp'] = $totalACWP;
$w++;
$w++;
}
}
$arr_ActualM[] = array(
$arr_ActualM[] = array(
'date'=>$dt->format("Y-m-d"),
'date' => $dt->format("Y-m-d"),
'percentPlan'=>$sumPercentagePlan,
'percentPlan' => $sumPercentagePlan,
'percentActual'=>$sumPercentageActual,
'percentActual' => $sumPercentageActual,
'plan'=>$dataTempPlan,
'plan' => $dataTempPlan,
'actual'=>$dataTempReport,
'actual' => $dataTempReport,
);
);
if(isset($dataPayload['period']) & & $dataPayload['period'] == 'week'){
if (isset($dataPayload['period']) & & $dataPayload['period'] == 'week') {
if($dt->format("w")==1){
if ($dt->format("w") == 1) {
if($totalACWP > 0 ){
if ($totalACWP > 0) {
$budgetControlACWP = $currentACWP + $totalACWP;
$budgetControlACWP = $currentACWP + $totalACWP;
}
}
if($totalBCWP > 0 ){
if ($totalBCWP > 0) {
$budgetControlBCWP = $currentBCWP + $totalBCWP;
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
}
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$tempTtlPercentActual += $sumPercentageActual;
$currentACWP += $totalACWP;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}else if($dt->format("Y-m-d") == $end2->format("Y-m-d")) {
} else if ($dt->format("Y-m-d") == $end2->format("Y-m-d")) {
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$tempTtlPercentActual += $sumPercentageActual;
$currentACWP += $totalACWP;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempTtlPercentPlan = 0;
$tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0;
$tempTtlPercentActual = 0;
}
}
}else{
} else {
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}
}
}
}
if(round($totalACWP,0) > $totalRencanaBudget){
if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP,0)+0;
$estimatedCost = round($totalACWP, 0) + 0;
}else{
} else {
$estimatedCost = ($totalRencanaBudget+0);
$estimatedCost = ($totalRencanaBudget + 0);
}
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
if ($costDeviation > 0) {
$potential = "SAVING";
$potential = "SAVING";
} else {
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
}
$dataResponse = array(
$dataResponse = array(
"date" =>$tempDate,
"date" => $tempDate,
"percentage" =>$tempPercentage,
"percentage" => $tempPercentage,
"data_details" =>$arr_ActualM,
"data_details" => $arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"budget_control" => array(
"acwp" => round($totalACWP,0),
"current_budget" => $totalRencanaBudget,
"bcwp" => round($totalBCWP,0),
"acwp" => round($totalACWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)),
"bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0,
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"cost_deviation" => $costDeviation,
@ -707,12 +803,12 @@ class ActivityController extends Controller
)
)
);
);
$dataFinal[] = array(
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"proyek_name" => $dataProject->nama,
"data"=>$dataResponse,
"data" => $dataResponse,
"allGant"=>$allGantt
"allGant" => $allGantt
);
);
}
}
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataFinal], 200);
}
}
public function import(Request $request)
public function import(Request $request)
@ -729,34 +825,35 @@ class ActivityController extends Controller
public function uploadTmpImport(Request $request)
public function uploadTmpImport(Request $request)
{
{
if($request->hasFile('dokumen')){
if ($request->hasFile('dokumen')) {
$document = $request->file('dokumen');
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$name = $document->getClientOriginalName();
$result = $document->move($this->pathTmpImport, $name);
$result = $document->move($this->pathTmpImport, $name);
if($result){
if ($result) {
$data = [
$data = [
'gantt_id' => (int)$gantt_id,
'gantt_id' => (int) $gantt_id,
'file' => $name,
'file' => $name,
'type_dokumen' => $request->type_dokumen
'type_dokumen' => $request->type_dokumen
];
];
$result = TmpImport::create($data);
$result = TmpImport::create($data);
if(!$result){
if (!$result) {
unlink($this->pathTmpImport.$name);
unlink($this->pathTmpImport . $name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
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' => 'Upload successful!', 'code' => 200], 200);
}
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400);
}
}
public function importUpdate(Request $request) {
public function importUpdate(Request $request)
{
$data = $request->all();
$data = $request->all();
foreach ($data as $value) {
foreach ($data as $value) {
$activity = Activity::find($value['id']);
$activity = Activity::find($value['id']);
@ -765,6 +862,6 @@ class ActivityController extends Controller
$activity->end_date = $value['end_date'];
$activity->end_date = $value['end_date'];
$activity->save();
$activity->save();
}
}
return response()->json(['status'=>'success','data'=>$request,'message'=>'Update successful!','code'=>200], 200);
return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200);
}
}
}
}