Browse Source

Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into dev-wahyu

pull/1/head
wahyu 11 months ago
parent
commit
14d2b1594b
  1. 6
      app/Console/Commands/CalculateProgressGantt.php
  2. 390
      app/Helpers/MasterFunctionsHelper.php
  3. 32
      app/Http/Controllers/ProjectController.php

6
app/Console/Commands/CalculateProgressGantt.php

@ -19,10 +19,10 @@ class CalculateProgressGantt extends Command
$hierarchy = HierarchyFtth::findOrFail($hierarchy_id); $hierarchy = HierarchyFtth::findOrFail($hierarchy_id);
$project = Project::find($hierarchy->project_id); $project = Project::find($hierarchy->project_id);
$data = MasterFunctionsHelper::CalculateSCurve(null, $hierarchy_id); $data = MasterFunctionsHelper::calculateSCurveForProgressTree($hierarchy_id);
$hierarchy->bobot_planning = end($data[0]['data']['percentagePlan']); $hierarchy->bobot_planning = 100;
$hierarchy->progress = end($data[0]['data']['percentageReal']); $hierarchy->progress =round(((int) end($data[0]['data']['percentageReal']) / (int) end($data[0]['data']['percentagePlan'])) * 100, 2);
$hierarchy->save(); $hierarchy->save();
} }
} }

390
app/Helpers/MasterFunctionsHelper.php

@ -468,9 +468,9 @@ class MasterFunctionsHelper
} }
if ($dataHeader) { if ($dataHeader) {
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); // $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya");
} else { } else {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya"); // $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya");
} }
if (!Activity::where("version_gantt_id", $keyGantt['id'])->first()) if (!Activity::where("version_gantt_id", $keyGantt['id'])->first())
@ -506,16 +506,16 @@ class MasterFunctionsHelper
} }
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = []; // $arr_ActualM = [];
$tempDate = []; $tempDate = [];
$tempPercentagePlan = []; // $tempPercentagePlan = [];
$tempPercentagePlanWhr = []; // $tempPercentagePlanWhr = [];
$tempPercentageReal = []; // $tempPercentageReal = [];
$tempTtlPercentPlan = 0; // $tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0; // $tempTtlPercentActual = 0;
$currentACWP = 0; // $currentACWP = 0;
$currentBCWP = 0; // $currentBCWP = 0;
$dataActivityPlanDate = []; $dataActivityPlanDate = [];
$progressPlanKomulatifWeek = []; $progressPlanKomulatifWeek = [];
$progressActualKomulatifWeek = []; $progressActualKomulatifWeek = [];
@ -551,11 +551,15 @@ class MasterFunctionsHelper
$dataActivityPlan = []; $dataActivityPlan = [];
$dataActivityActual = []; $dataActivityActual = [];
$today = new DateTime(); $today = date('Y-m-d');
$statusCutOfDate = false;
// if (new \DateTime($loopDay) < $today) {
// $statusCutOfDate = true;
// }
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){ if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2); $progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2);
if (new \DateTime($loopDay) < $today) { if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2); // $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2); $progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2);
} }
@ -599,7 +603,7 @@ class MasterFunctionsHelper
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
$progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * $keyActualM->bobot_planning;
}else{ }else{
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
@ -1306,18 +1310,18 @@ class MasterFunctionsHelper
return $dataFinal; return $dataFinal;
} }
public function calculateSCurve($projectId, $hierarchyId = null) public function calculateSCurve($projectId)
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$hierarchyGantts = []; // $hierarchyGantts = [];
if (isset($hierarchyId)) { // if (isset($hierarchyId)) {
$hierarchy = HierarchyFtth::findOrFail($hierarchyId); // $hierarchy = HierarchyFtth::findOrFail($hierarchyId);
$projectId = $hierarchy->project_id; // $projectId = $hierarchy->project_id;
if (isset($hierarchy)) { // // if (isset($hierarchy)) {
$hierarchyGantts = VersionGantt::where('hierarchy_ftth_id', $hierarchyId)->get()->toArray(); // // $hierarchyGantts = VersionGantt::where('hierarchy_ftth_id', $hierarchyId)->get()->toArray();
} // // }
} // }
$dataFinal = []; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
@ -1333,9 +1337,9 @@ class MasterFunctionsHelper
} }
if ($dataHeader) { if ($dataHeader) {
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); // $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya");
} else { } else {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); // $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya");
} }
$minDate = $dataProject->mulai_proyek; $minDate = $dataProject->mulai_proyek;
@ -1382,18 +1386,41 @@ class MasterFunctionsHelper
$tempDate[] = array($dt->format("Y-m-d")); $tempDate[] = array($dt->format("Y-m-d"));
$dataPlanM = []; $dataPlanM = [];
$dataActualM = []; $dataActualM = [];
if (count($hierarchyGantts) > 0) { // if (count($hierarchyGantts) > 0) {
foreach ($hierarchyGantts as $key => $gantt) { // foreach ($hierarchyGantts as $key => $gantt) {
$dataPlanM[] = DB::table('m_activity') // $dataPlanM[] = DB::table('m_activity')
// ->where('type_activity', 'task')
// ->where('bobot_planning', '>', 0)
// ->where('version_gantt_id', $gantt['id'])
// ->whereDate('planned_start', '<=', $loopDay)
// ->whereDate('planned_end', '>=', $loopDay)
// ->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end')
// ->get()->toArray();
// $dataActualM[] = DB::table('report_activity_material as ram')
// ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
// ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
// DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
// DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
// DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
// DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report')
// )
// ->where('ram.report_date', $loopDay)
// ->where('ma.version_gantt_id', $gantt['id'])
// ->get()->toArray();
// }
// } else {
$dataPlanM = DB::table('m_activity')
->where('type_activity', 'task') ->where('type_activity', 'task')
->where('bobot_planning', '>', 0) ->where('bobot_planning', '>', 0)
->where('version_gantt_id', $gantt['id']) ->where('proyek_id', $projectId)
->whereDate('planned_start', '<=', $loopDay) ->whereDate('planned_start', '<=', $loopDay)
->whereDate('planned_end', '>=', $loopDay) ->whereDate('planned_end', '>=', $loopDay)
->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end') ->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end')
->get()->toArray(); ->get();
$dataActualM[] = DB::table('report_activity_material as ram') $dataActualM = DB::table('report_activity_material as ram')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id') ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
@ -1402,22 +1429,248 @@ class MasterFunctionsHelper
DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report') DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report')
) )
->where('ram.report_date', $loopDay) ->where('ram.report_date', $loopDay)
->where('ma.version_gantt_id', $gantt['id']) ->where('ma.proyek_id', $projectId)
->get()->toArray(); ->get();
// }
$dataActivityPlan = [];
$dataActivityActual = [];
$today = date('Y-m-d');
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2);
if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2);
}
$dateWeek[] = [$loopDay];
}
// $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek;
// if (count($dataPlanM) > 0 && count($dataPlanM[0]) > 0) {
foreach ($dataPlanM as $keyPlanM) {
# hitung untuk persentase progress planning
// if($keyPlanM->duration == 0){
// $duration = 2;
// Tanggal awal
$startDate = new DateTime($keyPlanM->planned_start);
// Tanggal akhir
$endDate = new DateTime($keyPlanM->planned_end);
// Menghitung selisih hari
$interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari
$duration = (int) $interval->days+1;
// }else{
// $duration = $keyPlanM->duration + 2;
// }
// $startPlan = new DateTime($keyPlanM->planned_start);
// $endPlan = new DateTime($keyPlanM->planned_end);
// $interval = $startPlan->diff($endPlan);
// // Mengambil hasil selisih hari
// $duration = $interval->days;
// 2023-07-26
$progressPlanWeek = $keyPlanM->bobot_planning / $duration;
$dataActivityPlan[] = array(
'progressPlanDay' => $progressPlanWeek,
'name' => $keyPlanM->name,
'bobot_p' => $keyPlanM->bobot_planning,
'duration' => $keyPlanM->duration
);
$tmpProgressPlanWeek += $progressPlanWeek;
}
// }
// hitung progress actual
// if (count($dataActualM) > 0 && count($dataActualM[0]) > 0) {
foreach ($dataActualM as $keyActualM) {
# hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
$progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100;
}else{
// jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM->qty_actual == 0){
$progressActualWeek = 0;
}else{
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
}
}
if($keyActualM->status_activity == 'done'){
// if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
// }
// if($progressActualWeek > $keyActualM->bobot_planning){
// $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_actual == 0){
// $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){
$progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report;
// }else {
// $progressActualWeek = $progressActualWeek;
// }
// $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek;
// jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report,
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
}
else{
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
}
$dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek,
'qty_act' => $keyActualM->qty_actual,
'bobot_p' => $keyActualM->bobot_planning,
'qty_plan' => $keyActualM->qty_plan,
'status_activity' => $keyActualM->status_activity,
'sum_qty_actual' => $keyActualM->sum_qty_actual,
'name' => $keyActualM->name
);
$tmpProgressActualWeek += $progressActualWeek;
} }
// }
$dataActivityPlanDate[] = array(
"date" => $loopDay,
"statusWeek" => new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday') ? true : false,
"activity-plan" => $dataActivityPlan,
"activity-actual" => $dataActivityActual,
"tmpProgressActualWeek" => $tmpProgressActualWeek,
"progressPlanWeek" => $tmpProgressPlanWeek
);
}
$dataFinal[] = array(
// "date" => $dateWeek,
"proyek_name" => $dataProject->nama,
"data" => ["date" => $dateWeek,
"percentagePlan" => $progressPlanKomulatifWeek,
"percentageReal" => $progressActualKomulatifWeek
// "data_details" => $dataActivityPlanDate
]
);
return $dataFinal;
}
public function calculateSCurveForProgressTree($hierarchyId)
{
DB::enableQueryLog();
// $hierarchyGantts = [];
if (isset($hierarchyId)) {
$hierarchy = HierarchyFtth::findOrFail($hierarchyId);
$projectId = $hierarchy->project_id;
// if (isset($hierarchy)) {
// $hierarchyGantts = VersionGantt::where('hierarchy_ftth_id', $hierarchyId)->get()->toArray();
// }
}
$dataFinal = [];
$dataPayload = [];
$dataPayload['period'] = 'week';
$totalACWP = 0;
$totalBCWP = 0;
$tempPercentage = [];
$dataProject = Project::find($projectId);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first();
if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) {
$dataPayload['end_date'] = $dataProject->akhir_proyek;
}
if ($dataHeader) {
// $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya");
} else { } else {
// $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya");
}
$dataPlanM[] = DB::table('m_activity') $minDate = $dataProject->mulai_proyek;
->where('type_activity', 'task')
->where('bobot_planning', '>', 0) $begin = new \DateTime($minDate);
->where('proyek_id', $projectId) $begin = $begin->modify('-1 day');
if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate . ' Friday');
// $end->modify('next Friday');
// $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged
$interval = new \DateInterval('P1D');
} else {
$maxDate = $dataProject->akhir_proyek;
$end = new \DateTime($maxDate);
$end = new \DateTime($end->format('Y-m-d') . ' Friday');
// $end->modify('next Friday');
// $end->modify('next Friday');
$interval = new \DateInterval('P1D');
}
$period = new \DatePeriod($begin, $interval, $end);
// $arr_ActualM = [];
$tempDate = [];
// $tempPercentagePlan = [];
// $tempPercentagePlanWhr = [];
// $tempPercentageReal = [];
// $tempTtlPercentPlan = 0;
// $tempTtlPercentActual = 0;
// $currentACWP = 0;
// $currentBCWP = 0;
$dataActivityPlanDate = [];
$progressPlanKomulatifWeek = [];
$progressActualKomulatifWeek = [];
$dateWeek = [];
$tmpProgressPlanWeek = 0;
$tmpProgressActualWeek = 0;
foreach ($period as $dt) {
$loopDay = $dt->format("Y-m-d");
//new \Datetime($dt->format("Y-m-d"));
// $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$tempDate[] = array($dt->format("Y-m-d"));
$dataPlanM = [];
$dataActualM = [];
// if (count($hierarchyGantts) > 0) {
// foreach ($hierarchyGantts as $key => $gantt) {
// $dataPlanM[] = DB::table('m_activity')
// ->where('type_activity', 'task')
// ->where('bobot_planning', '>', 0)
// ->where('version_gantt_id', $gantt['id'])
// ->whereDate('planned_start', '<=', $loopDay)
// ->whereDate('planned_end', '>=', $loopDay)
// ->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end')
// ->get()->toArray();
// $dataActualM[] = DB::table('report_activity_material as ram')
// ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
// ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
// DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
// DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
// DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
// DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report')
// )
// ->where('ram.report_date', $loopDay)
// ->where('ma.version_gantt_id', $gantt['id'])
// ->get()->toArray();
// }
// } else {
$dataPlanM = DB::table('m_hierarchy_ftth as mhf')
->join('m_version_gantt as mvg', 'mvg.hierarchy_ftth_id', '=', 'mhf.id')
->join('m_activity as ma', 'ma.version_gantt_id', '=', 'mvg.id')
->where('ma.type_activity', 'task')
->where('ma.bobot_planning', '>', 0)
->where('mhf.project_id', $projectId)
->whereDate('planned_start', '<=', $loopDay) ->whereDate('planned_start', '<=', $loopDay)
->whereDate('planned_end', '>=', $loopDay) ->whereDate('planned_end', '>=', $loopDay)
->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end') ->select('ma.name', 'ma.bobot_planning', 'ma.biaya_actual', 'ma.duration', 'ma.persentase_progress', 'ma.id', 'ma.planned_start', 'ma.planned_end')
->get()->toArray(); ->get();
$dataActualM[] = DB::table('report_activity_material as ram') $dataActualM = DB::table('m_hierarchy_ftth as mhf')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id') ->join('m_version_gantt as mvg', 'mvg.hierarchy_ftth_id', '=', 'mhf.id')
->join('m_activity as ma', 'ma.version_gantt_id', '=', 'mvg.id')
->join('report_activity_material as ram', 'ram.activity_id', '=', 'ma.id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'), DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
@ -1425,24 +1678,25 @@ class MasterFunctionsHelper
DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report') DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report')
) )
->where('ram.report_date', $loopDay) ->where('ram.report_date', $loopDay)
->where('ma.proyek_id', $projectId) // ->where('ma.proyek_id', $projectId)
->get()->toArray(); ->where('mhf.project_id', $projectId)
} ->get();
// }
$dataActivityPlan = []; $dataActivityPlan = [];
$dataActivityActual = []; $dataActivityActual = [];
$today = new DateTime(); $today = date('Y-m-d');
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){ if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2); $progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2);
if (new \DateTime($loopDay) < $today) { if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2); // $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2); $progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2);
} }
$dateWeek[] = [$loopDay]; $dateWeek[] = [$loopDay];
} }
// $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek; // $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek;
if (count($dataPlanM) > 0 && count($dataPlanM[0]) > 0) { // if (count($dataPlanM) > 0 && count($dataPlanM[0]) > 0) {
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
# hitung untuk persentase progress planning # hitung untuk persentase progress planning
// if($keyPlanM->duration == 0){ // if($keyPlanM->duration == 0){
@ -1451,9 +1705,9 @@ class MasterFunctionsHelper
if (count($keyPlanM) == 0) { if (count($keyPlanM) == 0) {
continue; continue;
} }
$startDate = new DateTime($keyPlanM[0]->planned_start); $startDate = new DateTime($keyPlanM->planned_start);
// Tanggal akhir // Tanggal akhir
$endDate = new DateTime($keyPlanM[0]->planned_end); $endDate = new DateTime($keyPlanM->planned_end);
// Menghitung selisih hari // Menghitung selisih hari
$interval = $startDate->diff($endDate); $interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari // Mengambil hasil selisih hari
@ -1468,19 +1722,19 @@ class MasterFunctionsHelper
// // Mengambil hasil selisih hari // // Mengambil hasil selisih hari
// $duration = $interval->days; // $duration = $interval->days;
// 2023-07-26 // 2023-07-26
$progressPlanWeek = $keyPlanM[0]->bobot_planning / $duration; $progressPlanWeek = $keyPlanM->bobot_planning / $duration;
$dataActivityPlan[] = array( $dataActivityPlan[] = array(
'progressPlanDay' => $progressPlanWeek, 'progressPlanDay' => $progressPlanWeek,
'name' => $keyPlanM[0]->name, 'name' => $keyPlanM->name,
'bobot_p' => $keyPlanM[0]->bobot_planning, 'bobot_p' => $keyPlanM->bobot_planning,
'duration' => $keyPlanM[0]->duration 'duration' => $keyPlanM->duration
); );
$tmpProgressPlanWeek += $progressPlanWeek; $tmpProgressPlanWeek += $progressPlanWeek;
} }
} // }
// hitung progress actual // hitung progress actual
if (count($dataActualM) > 0 && count($dataActualM[0]) > 0) { // if (count($dataActualM) > 0 && count($dataActualM[0]) > 0) {
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
if (count($keyPlanM) == 0) { if (count($keyPlanM) == 0) {
continue; continue;
@ -1488,18 +1742,18 @@ class MasterFunctionsHelper
# hitung untuk persentase progress actual # hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM[0]->sum_qty_actual > $keyActualM[0]->qty_plan){ if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
$progressActualWeek = (($keyActualM[0]->qty_actual / $keyActualM[0]->sum_qty_actual) * 100) *$keyActualM[0]->bobot_planning/100; $progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100;
}else{ }else{
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM[0]->qty_actual == 0){ if($keyActualM->qty_actual == 0){
$progressActualWeek = 0; $progressActualWeek = 0;
}else{ }else{
$progressActualWeek = ($keyActualM[0]->qty_actual / $keyActualM[0]->qty_plan) * $keyActualM[0]->bobot_planning; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
} }
} }
if($keyActualM[0]->status_activity == 'done'){ if($keyActualM->status_activity == 'done'){
// if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ // if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
// } // }
@ -1508,7 +1762,7 @@ class MasterFunctionsHelper
// }else if($keyActualM->qty_actual == 0){ // }else if($keyActualM->qty_actual == 0){
// $progressActualWeek = $keyActualM->bobot_planning; // $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){ // }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){
$progressActualWeek = $keyActualM[0]->bobot_planning / $keyActualM[0]->count_report; $progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report;
// }else { // }else {
// $progressActualWeek = $progressActualWeek; // $progressActualWeek = $progressActualWeek;
// } // }
@ -1517,21 +1771,21 @@ class MasterFunctionsHelper
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping // contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
} }
else{ else{
$progressActualWeek = $progressActualWeek > ($keyActualM[0]->bobot_planning*95)/100 ? ($keyActualM[0]->bobot_planning*95)/100 : $progressActualWeek; $progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
} }
$dataActivityActual[] = array( $dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek, 'progressActualDay' => $progressActualWeek,
'qty_act' => $keyActualM[0]->qty_actual, 'qty_act' => $keyActualM->qty_actual,
'bobot_p' => $keyActualM[0]->bobot_planning, 'bobot_p' => $keyActualM->bobot_planning,
'qty_plan' => $keyActualM[0]->qty_plan, 'qty_plan' => $keyActualM->qty_plan,
'status_activity' => $keyActualM[0]->status_activity, 'status_activity' => $keyActualM->status_activity,
'sum_qty_actual' => $keyActualM[0]->sum_qty_actual, 'sum_qty_actual' => $keyActualM->sum_qty_actual,
'name' => $keyActualM[0]->name 'name' => $keyActualM->name
); );
$tmpProgressActualWeek += $progressActualWeek; $tmpProgressActualWeek += $progressActualWeek;
} }
} // }
$dataActivityPlanDate[] = array( $dataActivityPlanDate[] = array(
"date" => $loopDay, "date" => $loopDay,

32
app/Http/Controllers/ProjectController.php

@ -538,16 +538,26 @@ class ProjectController extends Controller
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9) if($result['type_proyek_id'] === 9)
{ {
$actualEndExist = Activity::where('proyek_id', $id)->exists(); // $actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id); // $query = Activity::where('proyek_id', $id);
$maxEndDate = Activity::where('proyek_id', $id)->select('end_date')
->orderBy('end_date', 'desc')
->first();
}else{ }else{
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
->orderBy('end_date', 'desc')
->first();
$query = Activity::where('version_gantt_id', $ganttId); $query = Activity::where('version_gantt_id', $ganttId);
} }
} else { } else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
->orderBy('end_date', 'desc')
->first();
$query = Activity::where('version_gantt_id', $ganttId); $query = Activity::where('version_gantt_id', $ganttId);
} }
@ -556,11 +566,13 @@ class ProjectController extends Controller
} else { } else {
$startDate = $query->orderBy('start_date')->value('start_date'); $startDate = $query->orderBy('start_date')->value('start_date');
} }
if($actualEndExist) // if($actualEndExist)
{ // {
$maxEndDate = $query->max('id'); // // $maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date; // // get last end_date
} // // $endDate = $query->where('id',$maxEndDate)->first()->end_date;
// }
$plannedStart = Activity::where('version_gantt_id', $ganttId) $plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start') ->orderBy('planned_start')
@ -569,7 +581,7 @@ class ProjectController extends Controller
->orderByDesc('planned_end') ->orderByDesc('planned_end')
->value('planned_end'); ->value('planned_end');
$result->header->start_date = $startDate; $result->header->start_date = $startDate;
$result->header->end_date = $endDate; $result->header->end_date = $maxEndDate->end_date;
$result->header->planned_start = $plannedStart; $result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd; $result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200);

Loading…
Cancel
Save