Browse Source

update tmp import

pull/3/head
ibnu 2 years ago
parent
commit
2f9609c05d
  1. 466
      app/Http/Controllers/ActivityController.php
  2. 1
      app/Http/Controllers/Controller.php
  3. 14
      app/Http/Controllers/DivisiController.php
  4. 203
      app/Http/Controllers/ProjectController.php
  5. 17
      app/Models/TmpImport.php

466
app/Http/Controllers/ActivityController.php

@ -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 = false; $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();
$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"); if ($levelEqualWithLastStack) {
array_pop($activityStack);
$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);
} }
} }
$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(
"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 ($activity->level < @$data['activities'][$i + 1]['level']) {
"proyek_name"=> $dataProject->nama, unset($activity->level);
"data"=>$dataResponse, $activity->type_activity = "project";
"allGant"=>$allGantt $activity->save();
); $activity->level = $activity_row['level'];
} }
if (!empty($activity_row['predecessor'])) {
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no'));
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); 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,
]);
}
} }
private function getLatestGantt($id){ return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
} }
public function setBaseline($gantt_id) public function uploadTmpImport(Request $request)
{ {
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); if($request->hasFile('dokumen')){
$document = $request->file('dokumen');
$ref_id = $request->ref_id;
$name = $document->getClientOriginalName();
foreach ($activities as $activity) { $result = $document->move($this->pathDocument, $name);
$activity->update([ if($result){
"planned_start"=>$activity->start_date, $data = [
"planned_end"=>$activity->end_date, 'ref_id' => (int)$ref_id,
]); 'file' => $name,
} 'type_dokumen' => $request->type_dokumen
];
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); $result = TmpImport::create($data);
}
public function synchronizeReport($gantt_id) if(!$result){
{ unlink($this->pathDocument.$name);
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
$reports = [];
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) {
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$dr->report_date,
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
} }
} 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);
} }
} }

1
app/Http/Controllers/Controller.php

@ -11,6 +11,7 @@ class Controller extends BaseController
{ {
protected $pathImage = "assets/image/"; protected $pathImage = "assets/image/";
protected $pathDocument = "assets/file/project/"; protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/import/";
protected $pathActivityDocument = "assets/file/activity/"; protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth', protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];

14
app/Http/Controllers/DivisiController.php

@ -20,8 +20,8 @@ class DivisiController extends Controller
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'required',
'description' => 'string' 'description' => 'string',
// 'parent' => 'integer' 'parent' => 'integer'
]); ]);
$data = $request->all(); $data = $request->all();
@ -72,18 +72,8 @@ class DivisiController extends Controller
public function search() public function search()
{ {
<<<<<<< HEAD
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
=======
return $this->list(); return $this->list();
// cant use builder for this case // cant use builder for this case
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
} }
public function list() public function list()

203
app/Http/Controllers/ProjectController.php

@ -2,32 +2,30 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper; use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ActivityDokumen; use App\Models\UserToActivity;
use App\Models\User;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\CommentActivity;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek; use App\Models\FolderDocumentProyek;
use App\Models\Holiday;
use App\Models\Image;
use App\Models\Link;
use App\Models\OfficeHours;
use App\Models\Project;
use App\Models\ProjectApproval;
use App\Models\ProjectCharter; use App\Models\ProjectCharter;
use App\Models\ProjectMileStone; use App\Models\ProjectApproval;
use App\Models\ProjectParticipants;
use App\Models\ProjectPhase; use App\Models\ProjectPhase;
use App\Models\ProjectType; use App\Models\ProjectType;
use App\Models\ReportActivity; use App\Models\ProjectMileStone;
use App\Models\ReportActivityMaterial; use App\Models\ProjectParticipants;
use App\Models\ShowHideColumn; use App\Models\ShowHideColumn;
use App\Models\User;
use App\Models\UserToActivity;
use App\Models\UserToProyek;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use Illuminate\Http\Request; use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\ActivityDokumen;
use App\Models\Holiday;
use App\Models\ReportActivity;
use App\Models\OfficeHours;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -215,20 +213,6 @@ class ProjectController 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 getManpower($proyek_id){
$manPower = UserToProyek::where('proyek_id', $proyek_id)->get();
$manCount = $manPower->count();
return response()->json(['data'=>$manPower, 'totalRecord'=>$manCount]);
}
public function getAssignedHR($gantt_id){
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data'=>$results]);
}
public function list() public function list()
{ {
$data = Project::orderBy('id', 'desc')->get(); $data = Project::orderBy('id', 'desc')->get();
@ -245,7 +229,7 @@ class ProjectController extends Controller
$scheduleHealth = "on-track"; $scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){ if($rootActivity){
$costVariance = (int)$d->rencana_biaya - $rootActivity->biaya_actual ?? 0; $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual;
$actualCost = $rootActivity->biaya_actual ?? 0; $actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0; $progress = $rootActivity->persentase_progress ?? 0;
@ -263,7 +247,7 @@ class ProjectController extends Controller
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
} }
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek));
$d->plannedCost = (int)$d->rencana_biaya; $d->plannedCost = $d->rencana_biaya;
$d->actualCost = $actualCost; $d->actualCost = $actualCost;
$d->lastActivity = $lastActivity ?? "-"; $d->lastActivity = $lastActivity ?? "-";
$d->costVariance = $costVariance; $d->costVariance = $costVariance;
@ -272,18 +256,6 @@ class ProjectController extends Controller
$d->progress = $progress; $d->progress = $progress;
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null;
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0;
<<<<<<< HEAD
$d->projectManager = DB::table('m_proyek')
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id')
->where('m_proyek.id', $d->id)
->pluck('m_users.name')
->first();
$d->geolocation = [];
}
$totalPlannedCost = $data->sum('plannedCost');
$totalActualCost = $data->sum('actualCost');
=======
$d->projectManager = DB::table('m_proyek') $d->projectManager = DB::table('m_proyek')
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id')
->where('m_proyek.id', $d->id) ->where('m_proyek.id', $d->id)
@ -299,7 +271,6 @@ class ProjectController extends Controller
$totalPlannedCost = $data->sum('plannedCost'); $totalPlannedCost = $data->sum('plannedCost');
$totalActualCost = $data->sum('actualCost'); $totalActualCost = $data->sum('actualCost');
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$manpowers = User::count(); $manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'danger')->count(); $projectsOnDanger = Project::where('budget_health', 'danger')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
@ -310,7 +281,7 @@ class ProjectController extends Controller
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get(); ->get();
} catch (\DivisionByZeroError $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
try { try {
@ -319,7 +290,7 @@ class ProjectController extends Controller
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name') ->groupBy('m_type_proyek.name')
->get(); ->get();
} catch (\DivisionByZeroError $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
@ -341,136 +312,19 @@ class ProjectController extends Controller
], 200); ], 200);
} }
public function detail($id){ public function getListProjectTask($id){
if(empty($id) || !is_int((int)$id)) $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
$result = Project::find($id); ->groupBy("m_proyek.proyek_id")
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
<<<<<<< HEAD
public function synchronizeReport($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivityMaterial::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 = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivityMaterial::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")
);
}
$activity->reports = $reports;
}
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
]);
}
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
}
public function getOverdueActivities(Request $request){
$payload = $request->all();
if(empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($payload['id']);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
//TODO possible overdue bug
if(isset($payload['till_date']))
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get();
else
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
$result->overdueActivities = $overdueActivities;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function getInvoiceIntegration(Request $request) {
$search = urlencode($request->search);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url);
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
}
public function getReportDistribution(Request $request){
$payload = $request->all();
if(empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']])
->get(); ->get();
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); if(!$data)
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
public function getSCurve(Request $request){ return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
} }
=======
public function dashboard($id) public function dashboard($id)
{ {
$data = DB::table('m_proyek as mp') $data = DB::table('m_proyek as mp')
@ -523,6 +377,5 @@ class ProjectController extends Controller
return json_decode($output); return json_decode($output);
} }
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
} }

17
app/Models/TmpImport.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TmpImport extends Model
{
protected $table = 'tmp_import';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'created_by';
protected $fillable = [
'file', 'type_dokumen', 'gantt_id', 'created_at', 'created_by'
];
}
Loading…
Cancel
Save