Browse Source

Fix progress s curve

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
43468b0654
  1. 74
      app/Helpers/MasterFunctionsHelper.php

74
app/Helpers/MasterFunctionsHelper.php

@ -120,9 +120,11 @@ 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.' Monday'); $begin = new \DateTime($minDate.' Monday');
$begin->modify('last Monday');
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');
/* $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('P7D');
@ -133,6 +135,7 @@ class MasterFunctionsHelper {
->where('a.version_gantt_id', '=', $keyGantt['id']) ->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday'); $end = new \DateTime($maxDate. ' Friday');
$end->modify('next Friday');
$end->modify('next Friday'); $end->modify('next Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} }
@ -152,14 +155,35 @@ class MasterFunctionsHelper {
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");
$dataPlanM = DB::table('assign_material_to_activity as ama') // $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') // ->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') // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id']) // ->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['id']) // ->where('a.version_gantt_id', '=', $keyGantt['id'])
->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('ama.plan_date', '>', $minSevenDays) // ->whereDate('ama.plan_date', '>', $minSevenDays)
->get(); // ->get();
$activities = DB::table('m_activity AS a')
->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'])
->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('amta.plan_date', '>', $minSevenDays)
->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();
$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')
@ -175,23 +199,33 @@ class MasterFunctionsHelper {
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity') $sumVolPlan = DB::table(function ($query) use ($keyGantt) {
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) $query->select('a.*')
->where('activity_id', '=', $keyPlanM->activity_id) ->from('m_activity AS a')
->groupBy('activity_id') ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
->first(); ->where('a.type_activity', 'task')
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; ->where('a.bobot_planning', '>', 0)
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; ->where('a.version_gantt_id', $keyGantt['id'])
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; ->unionAll(function ($query) use ($keyGantt){
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; $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');
$dataTempPlan [$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration; $dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try { try {
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; $dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; $sumPercentagePlan+= $keyPlanM->bobot_planning;
if(isset($keyPlanM->duration) && $keyPlanM->duration > 0) if(isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
else else

Loading…
Cancel
Save