Browse Source

update calculate curva with day

pull/1/head
ibnu 1 year ago
parent
commit
de9b52592d
  1. 394
      app/Helpers/MasterFunctionsHelper.php
  2. 1
      app/Http/Controllers/ActivityController.php
  3. 21
      rest-client.http

394
app/Helpers/MasterFunctionsHelper.php

@ -165,41 +165,26 @@ class MasterFunctionsHelper
public function calculateProgressBasedOnReportMaterialOld($keyGantt) public function calculateProgressBasedOnReportMaterialOld($keyGantt)
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$dataFinal = []; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
$dataPayload['period'] = 'week'; $dataPayload['period'] = 'week';
$totalACWP = 0; $totalACWP = 0;
$totalBCWP = 0; $totalBCWP = 0;
$tempPercentage = []; $tempPercentage = [];
$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['id'])->first(); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first();
if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) {
$dataPayload['end_date'] = $dataProject->akhir_proyek; $dataPayload['end_date'] = $dataProject->akhir_proyek;
} }
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())
return $dataFinal; return $dataFinal;
$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['id'])
->exists();
// note : delete this
// if(!$alreadyHasReport)
// return $dataFinal;
$minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first();
$begin = new \DateTime($minDate);
$begin = new \DateTime($minDate . ' Monday');
$begin->modify('last Monday'); $begin->modify('last Monday');
if (isset($dataPayload['end_date'])) { if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date']; $maxDate = $dataPayload['end_date'];
@ -226,7 +211,6 @@ class MasterFunctionsHelper
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} }
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = []; $arr_ActualM = [];
$tempDate = []; $tempDate = [];
$tempPercentagePlan = []; $tempPercentagePlan = [];
@ -234,23 +218,12 @@ class MasterFunctionsHelper
$tempPercentageReal = []; $tempPercentageReal = [];
$tempTtlPercentPlan = 0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0; $tempTtlPercentActual = 0;
$currentACWP = 0; $currentACWP = 0;
$currentBCWP = 0; $currentBCWP = 0;
foreach ($period as $dt) { foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$tempDate[] = array($dt->format("Y-m-d")); $tempDate[] = array($dt->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['id'])
// ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
// ->whereDate('ama.plan_date', '>', $minSevenDays)
// ->get();
$activities = DB::table('m_activity AS a') $activities = DB::table('m_activity AS a')
->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task') ->where('a.type_activity', 'task')
@ -259,7 +232,6 @@ class MasterFunctionsHelper
->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d"))
->whereDate('amta.plan_date', '>', $minSevenDays) ->whereDate('amta.plan_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id');
$dataPlanM = DB::table('m_activity AS a') $dataPlanM = DB::table('m_activity AS a')
->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task') ->where('a.type_activity', 'task')
@ -270,7 +242,6 @@ class MasterFunctionsHelper
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id')
->union($activities) ->union($activities)
->get(); ->get();
$dataActualM = DB::table('report_activity_material as ram') $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') ->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') ->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
@ -284,7 +255,6 @@ class MasterFunctionsHelper
$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) {
// $sumVolPlan = DB::table(function ($query) use ($keyGantt) { // $sumVolPlan = DB::table(function ($query) use ($keyGantt) {
// $query->select('a.*') // $query->select('a.*')
@ -309,9 +279,21 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyPlanM->id) ->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id') ->groupBy('activity_id')
->first(); ->first();
$weekCount = $keyPlanM->duration / $keyPlanM->duration; if($keyPlanM->duration){
$weeklyPlan = $weekCount > 0 ? $sumVolPlan->ttl_qty_plan / $weekCount : 0; $weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration;
}else{
// $weeklyProgress = 0;
$weekCount = 1 / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
}
// $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0; // $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0;
// $weeklyProgress = $weeklyPlan * $keyPlanM->bobot_planning; // $weeklyProgress = $weeklyPlan * $keyPlanM->bobot_planning;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
@ -333,7 +315,6 @@ class MasterFunctionsHelper
} }
$x++; $x++;
} }
$w = 0; $w = 0;
$dataTempReport = []; $dataTempReport = [];
$sumPercentageActual = 0; $sumPercentageActual = 0;
@ -384,8 +365,6 @@ class MasterFunctionsHelper
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// } // }
// } // }
$totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0; $totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
@ -393,7 +372,6 @@ class MasterFunctionsHelper
$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,
@ -401,42 +379,30 @@ class MasterFunctionsHelper
'plan' => $dataTempPlan, 'plan' => $dataTempPlan,
'actual' => $dataTempReport, 'actual' => $dataTempReport,
); );
$today = new DateTime();
$date = new DateTime($dt->format("Y-m-d"));
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual; $tempTtlPercentActual += $sumPercentageActual;
// if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){
// if($tempTtlPercentActual >= 100)
// $tempTtlPercentActual = 100;
// if($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
// if($tempTtlPercentActual >= $keyGantt['progress'])
// $tempTtlPercentActual = $keyGantt['progress'];
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
// $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $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));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
if ($date < $today) {
$tempPercentageReal[] = round($tempTtlPercentActual, 2); $tempPercentageReal[] = round($tempTtlPercentActual, 2);
}
if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
break; break;
} }
} else { } else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentagePlan[] = round($sumPercentagePlan, 2);
if ($date < $today) {
$tempPercentageReal[] = round($sumPercentageActual, 2); $tempPercentageReal[] = round($sumPercentageActual, 2);
} }
} }
}
try { try {
if (round($totalACWP, 0) > $totalRencanaBudget) { if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP, 0) + 0; $estimatedCost = round($totalACWP, 0) + 0;
@ -451,14 +417,12 @@ class MasterFunctionsHelper
]); ]);
} }
$estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget;
$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";
} }
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array( $dataResponse = array(
@ -478,13 +442,11 @@ class MasterFunctionsHelper
"potential" => $potential, "potential" => $potential,
) )
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name" => $dataProject->nama, "proyek_name" => $dataProject->nama,
"data" => $dataResponse, "data" => $dataResponse,
"gantt" => $keyGantt "gantt" => $keyGantt
); );
return $dataFinal; return $dataFinal;
} }
@ -517,14 +479,14 @@ class MasterFunctionsHelper
$minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first();
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$begin->modify('last Monday'); $begin = $begin->modify('-1 day');
if (isset($dataPayload['end_date'])) { if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date']; $maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday'); // $end->modify('next Friday');
$end->modify('next Friday'); // $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P1D');
} else { } else {
$actualMaxDate = DB::table('assign_material_to_activity as ama') $actualMaxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
@ -538,9 +500,9 @@ class MasterFunctionsHelper
->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity' ->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity'
$maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate));
$end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday');
$end->modify('next Friday'); // $end->modify('next Friday');
$end->modify('next Friday'); // $end->modify('next Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P1D');
} }
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
@ -554,245 +516,113 @@ class MasterFunctionsHelper
$currentACWP = 0; $currentACWP = 0;
$currentBCWP = 0; $currentBCWP = 0;
$dataActivityPlanDate = [];
$progressPlanKomulatifWeek = [];
$progressActualKomulatifWeek = [];
$dateWeek = [];
$tmpProgressPlanWeek = 0;
$tmpProgressActualWeek = 0;
foreach ($period as $dt) { foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d")); $loopDay = $dt->format("Y-m-d");
$minSevenDays = $minSevenDays->modify('-7 day')->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")); $tempDate[] = array($dt->format("Y-m-d"));
$activities = DB::table('m_activity AS a') $dataPlanM = DB::table('m_activity')
->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') ->where('type_activity', 'task')
->where('a.type_activity', 'task') ->where('bobot_planning', '>', 0)
->where('a.bobot_planning', '>', 0) ->where('version_gantt_id', $keyGantt['id'])
->where('a.version_gantt_id', $keyGantt['id']) ->whereDate('planned_start', '<=', $loopDay)
->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) ->whereDate('planned_end', '>=', $loopDay)
->whereDate('amta.plan_date', '>', $minSevenDays) ->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id')
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id');
$dataPlanM = DB::table('m_activity AS a')
->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id'])
->whereDate('a.start_date', '<=', $dt->format("Y-m-d"))
->whereDate('a.start_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id')
->union($activities)
->get(); ->get();
$dataActualM = DB::table('report_activity_material as ram') $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 ma', 'ma.id', '=', 'ram.activity_id')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id') ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
->where('a.version_gantt_id', '=', $keyGantt['id']) DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
->where('a.proyek_id', '=', $keyGantt['proyek_id']) DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity')
->whereDate('ram.report_date', '>', $minSevenDays) )
->where('ram.report_date', $loopDay)
->where('ma.version_gantt_id', $keyGantt['id'])
->get(); ->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan = 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) { $dataActivityPlan = [];
// $sumVolPlan = DB::table(function ($query) use ($keyGantt) { $dataActivityActual = [];
// $query->select('a.*') $today = new DateTime();
// ->from('m_activity AS a') if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){
// ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
// ->where('a.type_activity', 'task')
// ->where('a.bobot_planning', '>', 0)
// ->where('a.version_gantt_id', $keyGantt['id'])
// ->unionAll(function ($query) use ($keyGantt) {
// $query->select('a.*')
// ->from('m_activity AS a')
// ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id')
// ->where('a.type_activity', 'task')
// ->where('a.bobot_planning', '>', 0)
// ->where('a.version_gantt_id', $keyGantt['id']);
// })
// ->orderBy('id', 'asc');
// }, 'subquery')
// ->sum('bobot_planning');
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id')
->first();
if($keyPlanM->duration){
$weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration;
}else{
// $weeklyProgress = 0;
$weekCount = 1 / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2);
if (new \DateTime($loopDay) < $today) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2);
} }
$dateWeek[] = [$loopDay];
// $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0; // $tmpProgressPlanWeek = 0;
// $weeklyProgress = $weeklyPlan * $keyPlanM->bobot_planning; // $tmpProgressActualWeek = 0;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan;
$dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan[$x]['duration'] = $keyPlanM->duration;
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try {
$dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan += $weeklyProgress;
if (isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
else
$totalBCWP = 0;
$dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
} }
$x++; // $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek;
foreach ($dataPlanM as $keyPlanM) {
# hitung untuk persentase progress planning
$dataActivityPlan[] = array(
'progressPlanDay' => $keyPlanM->bobot_planning / $keyPlanM->duration,
'name' => $keyPlanM->name,
'bobot_p' => $keyPlanM->bobot_planning,
'duration' => $keyPlanM->duration
);
$tmpProgressPlanWeek += $keyPlanM->bobot_planning / $keyPlanM->duration;
} }
$w = 0; // hitung progress actual
$dataTempReport = [];
$sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity') # hitung untuk persentase progress actual
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
->where('activity_id', '=', $keyActualM->activity_id) if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
->groupBy('activity_id') $progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100;
->first(); }else{
$sumReportActual = DB::table('report_activity_material') $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
->where('activity_id', $keyActualM->activity_id) }
->sum('qty'); if($keyActualM->status_activity == 'done'){
$reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek;
$dataTempReport[$w]['activity_id'] = $keyActualM->activity_id; }
$dataTempReport[$w]['qty'] = $keyActualM->qty; else{
$dataTempReport[$w]['report_date'] = $keyActualM->report_date; $progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
$dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning; }
$dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; $dataActivityActual[] = array(
$dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual; 'progressActualDay' => $progressActualWeek,
$dataTempReport[$w]['duration'] = $keyActualM->duration; 'qty_act' => $keyActualM->qty_actual,
$dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress; 'bobot_p' => $keyActualM->bobot_planning,
try { 'qty_plan' => $keyActualM->qty_plan,
// assign_material_to_activity 'status_activity' => $keyActualM->status_activity,
$checkStatusActivity = DB::table('assign_material_to_activity') 'sum_qty_actual' => $keyActualM->sum_qty_actual,
->select('activity_id', 'status_activity') 'name' => $keyActualM->name
->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC')
->first();
$dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
$sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}
}
// }else {
// if($checkStatusActivity->status_activity == 'done'){
// $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning;
// }else{
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// }
// }
$totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0;
} catch (\DivisionByZeroError $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,
); );
$today = new DateTime();
$date = new DateTime($dt->format("Y-m-d"));
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
$currentACWP += $totalACWP; $tmpProgressActualWeek += $progressActualWeek;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
if ($date < $today) {
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
}
if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
break;
}
} else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2);
if ($date < $today) {
$tempPercentageReal[] = round($sumPercentageActual, 2);
}
}
} }
try { $dataActivityPlanDate[] = array(
if (round($totalACWP, 0) > $totalRencanaBudget) { "date" => $loopDay,
$estimatedCost = round($totalACWP, 0) + 0; "statusWeek" => new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday') ? true : false,
} else { "activity-plan" => $dataActivityPlan,
$estimatedCost = ($totalRencanaBudget + 0); "activity-actual" => $dataActivityActual,
} "tmpProgressActualWeek" => $tmpProgressActualWeek,
} catch (\DivisionByZeroError $e) { "progressPlanWeek" => $tmpProgressPlanWeek
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";
} }
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal,
"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( $dataFinal[] = array(
// "date" => $dateWeek,
"proyek_name" => $dataProject->nama, "proyek_name" => $dataProject->nama,
"data" => $dataResponse, "data" => ["date" => $dateWeek,
"percentagePlan" => $progressPlanKomulatifWeek,
"percentageActual" => $progressActualKomulatifWeek,
"data_details" => $dataActivityPlanDate
],
"gantt" => $keyGantt "gantt" => $keyGantt
); );

1
app/Http/Controllers/ActivityController.php

@ -604,6 +604,7 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text']; $entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
$entity['data']['type_activity'] = $entity['data']['type'];
if (isset($entity['data']['rencana_biaya'])) { if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']); $entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
} }

21
rest-client.http

@ -1,4 +1,4 @@
@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9iYWNrZW5kLnRlc3RcL2FwaVwvbG9naW4iLCJpYXQiOjE3MDA0NTA1ODYsImV4cCI6MTcwMTA1NTM4NiwibmJmIjoxNzAwNDUwNTg2LCJqdGkiOiJack9MMU04UGdKWGkwTUU1Iiwic3ViIjoxLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.fyg6CyiCAcX3GD4iSy8urkHpZEJ4mnXSXQc4NKC8U9A @token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9iYWNrZW5kLnRlc3RcL2FwaVwvbG9naW4iLCJpYXQiOjE3MDEzNzMzNzQsImV4cCI6MTcwMTk3ODE3NCwibmJmIjoxNzAxMzczMzc0LCJqdGkiOiJhbkJWOHIwUDZndFRXZk5KIiwic3ViIjoxNzg4LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.QCiXq-62da7Sdk7sEb_J0apEij_R6IQgZVYG9iL6M8g
@tokenS = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZHctYXBpLm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjkxNTcyMTIwLCJleHAiOjE2OTIxNzY5MjAsIm5iZiI6MTY5MTU3MjEyMCwianRpIjoiVUdqbnhLRVdlZzYyTTBnayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.5QqK0dLW5jzbVOkSCSW0mFo0K7ycGOBW9NCG_2Zldm4 @tokenS = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZHctYXBpLm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjkxNTcyMTIwLCJleHAiOjE2OTIxNzY5MjAsIm5iZiI6MTY5MTU3MjEyMCwianRpIjoiVUdqbnhLRVdlZzYyTTBnayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.5QqK0dLW5jzbVOkSCSW0mFo0K7ycGOBW9NCG_2Zldm4
@ -18,8 +18,8 @@ POST {{hostname}}/login
content-type: application/json content-type: application/json
{ {
"username": "admin", "username": "testing",
"password": "1nt3gr4s14" "password": "testing123"
} }
###### Tools Req ###### Tools Req
@ -835,8 +835,9 @@ POST {{hostname}}/project/s-curve-command-test
Authorization: Bearer {{token}} Authorization: Bearer {{token}}
content-type: application/json content-type: application/json
{"period":"week","project_id":"129","gantt_id":"862"} # {"period":"week","project_id":"137","gantt_id":"916"}
### {"period":"week","project_id":"129","gantt_id":"862"} # {"period":"week","project_id":"129","gantt_id":"862"}
{"period":"week","project_id":"140","gantt_id":"1103"}
### ###
POST {{hostname}}/project/calculate-s-curve POST {{hostname}}/project/calculate-s-curve
@ -851,8 +852,14 @@ POST {{hostname}}/project/get-s-curve
Authorization: Bearer {{token}} Authorization: Bearer {{token}}
content-type: application/json content-type: application/json
{"period":"week","project_id":"129","gantt_id":"800"} {"project_id":"164","gantt_id":"973","period":"week"}
### {"period":"week","project_id":"135","gantt_id":"891"} ### {"period":"week","project_id":"129","gantt_id":"800"}
#######
GET {{hostname}}/activity/s-curve/137/892
Authorization: Bearer {{token}}
content-type: application/json
### ###
GET https://adw-api.ospro.id/api/request-material/get-material-integration?name=c GET https://adw-api.ospro.id/api/request-material/get-material-integration?name=c

Loading…
Cancel
Save