Browse Source

bod schedule health

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
466732b918
  1. 190
      app/Http/Controllers/DashboardBoDController.php

190
app/Http/Controllers/DashboardBoDController.php

@ -3,6 +3,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Project; use App\Models\Project;
use App\Models\Activity;
use App\Models\VersionGantt;
use App\Models\Divisi; use App\Models\Divisi;
use App\Models\ProjectPhase; use App\Models\ProjectPhase;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
@ -121,30 +123,52 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
// to do
public function getTotalProjectPerScheduleHealth($year = '%'){ public function getTotalProjectPerScheduleHealth($year = '%'){
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
// get data plan (vol) in %
// get data actual in % $return = [
return response()->json([ 'behind-schedule' => 0,
'data' => [ 'warning' => 0,
'behind-schedule' => rand(0,10), 'on-schedule' => 0,
'warning' => rand(0,10), ];
'on-schedule' => rand(0,10),
] $projects = Project::where('mulai_proyek', 'like', $year)->get();
], 200); foreach($projects as $project) {
$project->scurve = $this->getSCurve($project->id);
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$return['warning'] += 1;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$return['behind-schedule'] += 1;
elseif(@$project->scurve['difference'] == 0)
$return['on-schedule'] += 1;
}
return response()->json(['data' => $return], 200);
} }
// todo
public function getTotalProjectScheduleHealthPerDivision($year = '%'){ public function getTotalProjectScheduleHealthPerDivision($year = '%'){
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get(); $divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){ foreach($divisions as $division){
$scheduleData = new Collection(); $scheduleData = new Collection();
$scheduleData->prepend(rand(0, 10), 'behindSchedule'); $behindSchedule = $warning = $onSchedule = 0;
$scheduleData->prepend(rand(0, 10), 'warning');
$scheduleData->prepend(rand(0, 10), 'onSchedule'); $projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get();
foreach($projects as $project) {
$project->scurve = $this->getSCurve($project->id);
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$warning++;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$behindSchedule++;
elseif(@$project->scurve['difference'] == 0)
$onSchedule++;
}
$scheduleData->prepend($behindSchedule, 'behindSchedule');
$scheduleData->prepend($warning, 'warning');
$scheduleData->prepend($onSchedule, 'onSchedule');
$division->scheduleData = $scheduleData; $division->scheduleData = $scheduleData;
} }
return response()->json([ return response()->json([
@ -279,5 +303,143 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
private function getSCurve($project_id)
{
DB::enableQueryLog();
$dataPayload = [
'project_id' => $project_id,
'period' => 'week',
];
$allGantt[] = $this->getLatestGantt($dataPayload['project_id']);
$dataResponse=[];
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$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())
continue;
$alreadyHasReport = DB::table('report_activity_material as a')
->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)
continue;
$minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start");
$begin = new \DateTime($minDate.' Monday');
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday');
$interval = new \DateInterval('P7D');
$period = new \DatePeriod($begin, $interval, $end);
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$tempPercentagePlan = [];
$tempPercentageReal = [];
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$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"))
->whereDate('ama.plan_date', '>', $minSevenDays)
->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"))
->whereDate('ram.report_date', '>',$minSevenDays)
->get();
$sumPercentagePlan=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();
try {
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
}
$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();
try {
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
}
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){
if($tempTtlPercentActual >= 100)
$tempTtlPercentActual = 100;
if($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
}
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){
break;
}
}
$plannedPercentage = end($tempPercentagePlan);
$progressPercentage = end($tempPercentageReal);
$difference = $plannedPercentage - $progressPercentage;
$dataResponse = array(
'planned' => $plannedPercentage,
'progress' => $progressPercentage,
'difference' => $difference,
);
}
return $dataResponse;
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
} }

Loading…
Cancel
Save