Browse Source

Add formatting

pull/3/head
Wahyu Ramadhan 1 year ago
parent
commit
7cf1cca8ec
  1. 477
      app/Helpers/MasterFunctionsHelper.php

477
app/Helpers/MasterFunctionsHelper.php

@ -9,17 +9,19 @@ use App\Models\HierarchyFtth;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class MasterFunctionsHelper { class MasterFunctionsHelper
{
public static function curlReq($url, $token = ""){ public static function curlReq($url, $token = "")
if(!$token) {
if (!$token)
$token = config('api.adw_token'); $token = config('api.adw_token');
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
$headers = [ $headers = [
'Authorization: '.$token 'Authorization: ' . $token
]; ];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -34,9 +36,10 @@ class MasterFunctionsHelper {
return json_decode($output); return json_decode($output);
} }
public function getLatestGantt($id){ public function getLatestGantt($id)
{
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
if(!$maxGanttId){ if (!$maxGanttId) {
$data = array( $data = array(
"proyek_id" => $id "proyek_id" => $id
); );
@ -50,19 +53,20 @@ class MasterFunctionsHelper {
} }
// dipake di dashboard project & bod // dipake di dashboard project & bod
public function getSCurve($request){ public function getSCurve($request)
{
$allGantt = []; $allGantt = [];
if(!is_int($request)){ if (!is_int($request)) {
$dataPayload = $request->all(); $dataPayload = $request->all();
if(isset($dataPayload['gantt_id'])){ if (isset($dataPayload['gantt_id'])) {
$allGantt[] = $dataPayload['gantt_id']; $allGantt[] = $dataPayload['gantt_id'];
}else{ } else {
$allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']); $allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']);
} }
} else { } else {
$allGantt[] = MasterFunctionsHelper::getLatestGantt($request); $allGantt[] = MasterFunctionsHelper::getLatestGantt($request);
} }
foreach($allGantt as $gantt){ foreach ($allGantt as $gantt) {
if (!isset($gantt['last_gantt_id'])) { if (!isset($gantt['last_gantt_id'])) {
$ganttId = $gantt; $ganttId = $gantt;
} else { } else {
@ -73,7 +77,7 @@ class MasterFunctionsHelper {
// Log::info('gantt '.$value.' index '.$key); // Log::info('gantt '.$value.' index '.$key);
// } // }
if (isset($gantt['calculation_type'])) { if (isset($gantt['calculation_type'])) {
if($gantt['calculation_type'] == 'simple') { if ($gantt['calculation_type'] == 'simple') {
// to do // to do
return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt); return MasterFunctionsHelper::calculateProgressBasedOnSimple($gantt);
} else { } else {
@ -83,7 +87,8 @@ class MasterFunctionsHelper {
} }
} }
public function getLinearSCurve($request){ public function getLinearSCurve($request)
{
$ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); $ftths = HierarchyFtth::where('project_id', $request->project_id)->get();
$ttlProgress = 0; $ttlProgress = 0;
$ttlPlanning = 0; $ttlPlanning = 0;
@ -98,9 +103,9 @@ class MasterFunctionsHelper {
$minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first();
$maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first();
$begin = new \DateTime($minDate->mulai_proyek. ' Monday'); $begin = new \DateTime($minDate->mulai_proyek . ' Monday');
$end = new \DateTime($maxDate->akhir_proyek. ' Friday'); $end = new \DateTime($maxDate->akhir_proyek . ' Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
@ -108,8 +113,8 @@ class MasterFunctionsHelper {
$dates = iterator_to_array($period); $dates = iterator_to_array($period);
$count = count($dates); $count = count($dates);
$avgProgress = $ttlProgress/$ttlPlanning/$count*100; $avgProgress = $ttlProgress / $ttlPlanning / $count * 100;
$avgPlanning = $ttlPlanning/$ttlPlanning/$count*100; $avgPlanning = $ttlPlanning / $ttlPlanning / $count * 100;
$progressData = []; $progressData = [];
$planningData = []; $planningData = [];
$dates = []; $dates = [];
@ -117,7 +122,7 @@ class MasterFunctionsHelper {
$tempPlanning = 0; $tempPlanning = 0;
array_push($progressData, round($tempProgress, 2)); array_push($progressData, round($tempProgress, 2));
array_push($planningData, round($tempPlanning, 2)); array_push($planningData, round($tempPlanning, 2));
foreach($period as $p){ foreach ($period as $p) {
$tempProgress += $avgProgress; $tempProgress += $avgProgress;
$tempPlanning += $avgPlanning; $tempPlanning += $avgPlanning;
array_push($progressData, round($tempProgress, 2)); array_push($progressData, round($tempProgress, 2));
@ -132,7 +137,7 @@ class MasterFunctionsHelper {
); );
$dataFinal[] = array( $dataFinal[] = array(
"data"=>$dataResponse, "data" => $dataResponse,
); );
return $dataFinal; return $dataFinal;
} }
@ -141,7 +146,7 @@ class MasterFunctionsHelper {
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$dataFinal=[]; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
$dataPayload['period'] = 'week'; $dataPayload['period'] = 'week';
$totalACWP = 0; $totalACWP = 0;
@ -150,17 +155,17 @@ class MasterFunctionsHelper {
$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') $alreadyHasReport = DB::table('report_activity_material as a')
@ -174,14 +179,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.' Monday'); $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'];
$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('P7D');
} else { } else {
$maxDate = DB::table('assign_material_to_activity as ama') $maxDate = DB::table('assign_material_to_activity as ama')
@ -189,7 +194,7 @@ class MasterFunctionsHelper {
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->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'); $end->modify('next Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
@ -201,8 +206,8 @@ class MasterFunctionsHelper {
$tempPercentagePlan = []; $tempPercentagePlan = [];
$tempPercentagePlanWhr = []; $tempPercentagePlanWhr = [];
$tempPercentageReal = []; $tempPercentageReal = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual=0; $tempTtlPercentActual = 0;
$currentACWP = 0; $currentACWP = 0;
$currentBCWP = 0; $currentBCWP = 0;
@ -225,7 +230,7 @@ class MasterFunctionsHelper {
->where('a.type_activity', 'task') ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']) ->where('a.version_gantt_id', $keyGantt['id'])
->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');
@ -234,7 +239,7 @@ class MasterFunctionsHelper {
->where('a.type_activity', 'task') ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']) ->where('a.version_gantt_id', $keyGantt['id'])
->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) ->whereDate('a.start_date', '<=', $dt->format("Y-m-d"))
->whereDate('a.start_date', '>', $minSevenDays) ->whereDate('a.start_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')
->union($activities) ->union($activities)
@ -245,12 +250,12 @@ class MasterFunctionsHelper {
->join('m_activity as a', 'a.id', '=', 'ram.activity_id') ->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['id']) ->where('a.version_gantt_id', '=', $keyGantt['id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id']) ->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d"))
->whereDate('ram.report_date', '>',$minSevenDays) ->whereDate('ram.report_date', '>', $minSevenDays)
->get(); ->get();
$dataTempPlan = []; $dataTempPlan = [];
$x = 0; $x = 0;
$sumPercentagePlan=0; $sumPercentagePlan = 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
@ -262,7 +267,7 @@ class MasterFunctionsHelper {
->where('a.type_activity', 'task') ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']) ->where('a.version_gantt_id', $keyGantt['id'])
->unionAll(function ($query) use ($keyGantt){ ->unionAll(function ($query) use ($keyGantt) {
$query->select('a.*') $query->select('a.*')
->from('m_activity AS a') ->from('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')
@ -273,20 +278,20 @@ class MasterFunctionsHelper {
->orderBy('id', 'asc'); ->orderBy('id', 'asc');
}, 'subquery') }, 'subquery')
->sum('bobot_planning'); ->sum('bobot_planning');
$dataTempPlan [$x]['activity_id'] = $keyPlanM->id; $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; $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->bobot_planning; $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan+= $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
$totalBCWP = 0; $totalBCWP = 0;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP; $dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
@ -295,7 +300,7 @@ class MasterFunctionsHelper {
$w = 0; $w = 0;
$dataTempReport = []; $dataTempReport = [];
$sumPercentageActual=0; $sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity') $sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
@ -306,14 +311,14 @@ class MasterFunctionsHelper {
->where('activity_id', $keyActualM->activity_id) ->where('activity_id', $keyActualM->activity_id)
->sum('qty'); ->sum('qty');
$reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport[$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport[$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date; $dataTempReport[$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; $dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration; $dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
try { try {
// assign_material_to_activity // assign_material_to_activity
$checkStatusActivity = DB::table('assign_material_to_activity') $checkStatusActivity = DB::table('assign_material_to_activity')
@ -321,18 +326,18 @@ class MasterFunctionsHelper {
->where('activity_id', '=', $keyActualM->activity_id) ->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC') ->orderBy('status_activity', 'ASC')
->first(); ->first();
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual+=($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($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if($checkStatusActivity->status_activity == 'done'){ if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; $sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}else{ } else {
if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ 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 += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}else{ } else {
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} }
} }
@ -345,24 +350,24 @@ class MasterFunctionsHelper {
// } // }
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
$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,
'percentActual'=> $sumPercentageActual, 'percentActual' => $sumPercentageActual,
'plan'=>$dataTempPlan, 'plan' => $dataTempPlan,
'actual'=>$dataTempReport, 'actual' => $dataTempReport,
); );
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($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= $keyGantt['progress'];){
// if($tempTtlPercentActual >= 100) // if($tempTtlPercentActual >= 100)
@ -372,7 +377,7 @@ class MasterFunctionsHelper {
// if($tempTtlPercentActual >= $keyGantt['progress']) // if($tempTtlPercentActual >= $keyGantt['progress'])
// $tempTtlPercentActual = $keyGantt['progress']; // $tempTtlPercentActual = $keyGantt['progress'];
if($tempTtlPercentPlan >= 100) if ($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100; $tempTtlPercentPlan = 100;
// $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual
@ -381,25 +386,25 @@ class MasterFunctionsHelper {
$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];
$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);
$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;
}else{ } else {
$estimatedCost = ($totalRencanaBudget+0); $estimatedCost = ($totalRencanaBudget + 0);
} }
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json([ return response()->json([
@ -411,22 +416,23 @@ 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";
} }
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" => $tempDate,
"percentage" =>$tempPercentage, "percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan, "percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal, "percentageReal" => $tempPercentageReal,
"data_details" =>$arr_ActualM, "data_details" => $arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" => array(
"acwp" => round($totalACWP,0), "current_budget" => $totalRencanaBudget,
"bcwp" => round($totalBCWP,0), "acwp" => round($totalACWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), "bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0, "add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost, "estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation, "cost_deviation" => $costDeviation,
@ -435,9 +441,9 @@ class MasterFunctionsHelper {
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name"=> $dataProject->nama, "proyek_name" => $dataProject->nama,
"data"=>$dataResponse, "data" => $dataResponse,
"gantt"=>$keyGantt "gantt" => $keyGantt
); );
return $dataFinal; return $dataFinal;
@ -447,7 +453,7 @@ class MasterFunctionsHelper {
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$dataFinal=[]; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
$dataPayload['period'] = 'week'; $dataPayload['period'] = 'week';
$totalACWP = 0; $totalACWP = 0;
@ -456,13 +462,13 @@ class MasterFunctionsHelper {
$dataProject = Project::find($projectId); $dataProject = Project::find($projectId);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->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", $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");
} }
@ -475,12 +481,12 @@ class MasterFunctionsHelper {
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$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'];
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
$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('P7D');
} else { } else {
// $maxDate = DB::table('assign_material_to_activity as ama') // $maxDate = DB::table('assign_material_to_activity as ama')
@ -500,8 +506,8 @@ class MasterFunctionsHelper {
$tempPercentagePlan = []; $tempPercentagePlan = [];
$tempPercentagePlanWhr = []; $tempPercentagePlanWhr = [];
$tempPercentageReal = []; $tempPercentageReal = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual=0; $tempTtlPercentActual = 0;
$currentACWP = 0; $currentACWP = 0;
$currentBCWP = 0; $currentBCWP = 0;
@ -522,7 +528,7 @@ class MasterFunctionsHelper {
->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')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->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');
@ -530,7 +536,7 @@ class MasterFunctionsHelper {
->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')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->whereDate('a.start_date', '<=',$dt->format("Y-m-d")) ->whereDate('a.start_date', '<=', $dt->format("Y-m-d"))
->whereDate('a.start_date', '>', $minSevenDays) ->whereDate('a.start_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')
->union($activities) ->union($activities)
@ -540,23 +546,23 @@ class MasterFunctionsHelper {
->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')
->where('a.proyek_id', '=', $projectId) ->where('a.proyek_id', '=', $projectId)
->whereDate('ram.report_date', '<=',$dt->format("Y-m-d")) ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d"))
->whereDate('ram.report_date', '>',$minSevenDays) ->whereDate('ram.report_date', '>', $minSevenDays)
->get(); ->get();
$dataTempPlan = []; $dataTempPlan = [];
$x = 0; $x = 0;
$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){ $sumVolPlan = DB::table(function ($query) {
$query->select('a.*') $query->select('a.*')
->from('m_activity AS a') ->from('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')
->where('a.bobot_planning', '>', 0) ->where('a.bobot_planning', '>', 0)
->unionAll(function ($query){ ->unionAll(function ($query) {
$query->select('a.*') $query->select('a.*')
->from('m_activity AS a') ->from('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')
@ -565,20 +571,20 @@ class MasterFunctionsHelper {
})->orderBy('id', 'asc'); })->orderBy('id', 'asc');
}, 'subquery') }, 'subquery')
->sum('bobot_planning'); ->sum('bobot_planning');
$dataTempPlan [$x]['activity_id'] = $keyPlanM->id; $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; $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->bobot_planning; $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan+= $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
$totalBCWP = 0; $totalBCWP = 0;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP; $dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
@ -587,7 +593,7 @@ class MasterFunctionsHelper {
$w = 0; $w = 0;
$dataTempReport = []; $dataTempReport = [];
$sumPercentageActual=0; $sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity') $sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
@ -598,14 +604,14 @@ class MasterFunctionsHelper {
->where('activity_id', $keyActualM->activity_id) ->where('activity_id', $keyActualM->activity_id)
->sum('qty'); ->sum('qty');
$reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport[$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport[$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date; $dataTempReport[$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; $dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration; $dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
try { try {
// assign_material_to_activity // assign_material_to_activity
$checkStatusActivity = DB::table('assign_material_to_activity') $checkStatusActivity = DB::table('assign_material_to_activity')
@ -613,18 +619,18 @@ class MasterFunctionsHelper {
->where('activity_id', '=', $keyActualM->activity_id) ->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC') ->orderBy('status_activity', 'ASC')
->first(); ->first();
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual+=($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($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if($checkStatusActivity->status_activity == 'done'){ if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual+=$keyActualM->bobot_planning/$reportCount; $sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}else{ } else {
if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1 || (int)$sumVolActual->ttl_qty_plan == (int)$sumReportActual){ 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 += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}else{ } else {
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} }
} }
@ -637,34 +643,34 @@ class MasterFunctionsHelper {
// } // }
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
$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,
'percentActual'=> $sumPercentageActual, 'percentActual' => $sumPercentageActual,
'plan'=>$dataTempPlan, 'plan' => $dataTempPlan,
'actual'=>$dataTempReport, 'actual' => $dataTempReport,
); );
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan+= $sumPercentagePlan; $tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual; $tempTtlPercentActual += $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];
$tempPercentageReal[] = round($tempTtlPercentActual, 2); $tempPercentageReal[] = round($tempTtlPercentActual, 2);
}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);
$tempPercentageReal[] = round($sumPercentageActual, 2); $tempPercentageReal[] = round($sumPercentageActual, 2);
} }
@ -672,10 +678,10 @@ class MasterFunctionsHelper {
} }
try { try {
if(round($totalACWP,0) > $totalRencanaBudget){ if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP,0)+0; $estimatedCost = round($totalACWP, 0) + 0;
}else{ } else {
$estimatedCost = ($totalRencanaBudget+0); $estimatedCost = ($totalRencanaBudget + 0);
} }
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json([ return response()->json([
@ -686,22 +692,23 @@ 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";
} }
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" => $tempDate,
"percentage" =>$tempPercentage, "percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan, "percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal, "percentageReal" => $tempPercentageReal,
"data_details" =>$arr_ActualM, "data_details" => $arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" => array(
"acwp" => round($totalACWP,0), "current_budget" => $totalRencanaBudget,
"bcwp" => round($totalBCWP,0), "acwp" => round($totalACWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), "bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0, "add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost, "estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation, "cost_deviation" => $costDeviation,
@ -710,33 +717,34 @@ class MasterFunctionsHelper {
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name"=> $dataProject->nama, "proyek_name" => $dataProject->nama,
"data"=>$dataResponse, "data" => $dataResponse,
); );
return $dataFinal; return $dataFinal;
} }
public function calculateProgressBasedOnSimple($keyGantt){ public function calculateProgressBasedOnSimple($keyGantt)
{
DB::enableQueryLog(); DB::enableQueryLog();
$dataFinal=[]; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
$dataPayload['period'] = 'week'; $dataPayload['period'] = 'week';
$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') // $alreadyHasReport = DB::table('report_activity_material as a')
@ -750,11 +758,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');
if(isset($dataPayload['end_date'])){ if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date']; $maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
/* $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');
} else { } else {
// $maxDate = DB::table('assign_material_to_activity as ama') // $maxDate = DB::table('assign_material_to_activity as ama')
@ -763,7 +771,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
$maxDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('end_date')->first(); $maxDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('end_date')->first();
$end = new \DateTime($maxDate. ' Friday'); $end = new \DateTime($maxDate . ' Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} }
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
@ -773,8 +781,8 @@ class MasterFunctionsHelper {
$tempPercentagePlan = []; $tempPercentagePlan = [];
$tempPercentagePlanWhr = []; $tempPercentagePlanWhr = [];
$tempPercentageReal = []; $tempPercentageReal = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual=0; $tempTtlPercentActual = 0;
$currentACWP = 0; $currentACWP = 0;
$currentBCWP = 0; $currentBCWP = 0;
@ -789,7 +797,7 @@ class MasterFunctionsHelper {
->where('proyek_id', '=', $keyGantt['proyek_id']) ->where('proyek_id', '=', $keyGantt['proyek_id'])
->where('type_activity', '=', 'task') ->where('type_activity', '=', 'task')
->where('version_gantt_id', '=', $keyGantt['id']) ->where('version_gantt_id', '=', $keyGantt['id'])
->whereDate('start_date', '<=',$dt->format("Y-m-d")) ->whereDate('start_date', '<=', $dt->format("Y-m-d"))
->whereDate('start_date', '>', $minSevenDays) ->whereDate('start_date', '>', $minSevenDays)
->get(); ->get();
@ -800,31 +808,31 @@ class MasterFunctionsHelper {
->where('a.type_activity', '=', 'task') ->where('a.type_activity', '=', 'task')
->where('mapl.variance', '>', 0) ->where('mapl.variance', '>', 0)
->where('a.proyek_id', '=', $keyGantt['proyek_id']) ->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('mapl.created_at', '<=',$dt->format("Y-m-d")) ->whereDate('mapl.created_at', '<=', $dt->format("Y-m-d"))
->whereDate('mapl.created_at', '>',$minSevenDays) ->whereDate('mapl.created_at', '>', $minSevenDays)
->get(); ->get();
$dataTempPlan = []; $dataTempPlan = [];
$x = 0; $x = 0;
$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) {
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; $dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['qty_plan'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->start_date; $dataTempPlan[$x]['plan_date'] = $keyPlanM->start_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_date; $dataTempPlan[$x]['start_activity'] = $keyPlanM->start_date;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['ttl_plan'] = $keyPlanM->bobot_planning;
$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->bobot_planning; $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan+=$keyPlanM->bobot_planning; $sumPercentagePlan += $keyPlanM->bobot_planning;
$totalBCWP += 0; $totalBCWP += 0;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP; $dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
@ -833,62 +841,62 @@ class MasterFunctionsHelper {
$w = 0; $w = 0;
$dataTempReport = []; $dataTempReport = [];
$sumPercentageActual=0; $sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('m_activity_progress_log') $sumVolActual = DB::table('m_activity_progress_log')
->select('id', DB::raw('SUM(variance) as ttl_percen_act')) ->select('id', DB::raw('SUM(variance) as ttl_percen_act'))
->where('id', '=', $keyActualM->id_progress_log) ->where('id', '=', $keyActualM->id_progress_log)
->groupBy('id') ->groupBy('id')
->first(); ->first();
$dataTempReport [$w]['id_progress_log'] = $keyActualM->id_progress_log; $dataTempReport[$w]['id_progress_log'] = $keyActualM->id_progress_log;
// $dataTempReport [$w]['qty'] = $keyActualM->qty; // $dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->created_at; $dataTempReport[$w]['report_date'] = $keyActualM->created_at;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
// $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_percen_act ? $sumVolActual->ttl_percen_act : 0; // $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_percen_act ? $sumVolActual->ttl_percen_act : 0;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration; $dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
try { try {
$dataTempReport [$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act/100)*$keyActualM->bobot_planning : 0; $dataTempReport[$w]['percentage'] = $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0;
$sumPercentageActual+=$sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act/100)*$keyActualM->bobot_planning : 0; $sumPercentageActual += $sumVolActual->ttl_percen_act ? ($sumVolActual->ttl_percen_act / 100) * $keyActualM->bobot_planning : 0;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; $totalACWP += $keyActualM->biaya_actual / $keyActualM->duration;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
$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,
'percentActual'=>$sumPercentageActual, 'percentActual' => $sumPercentageActual,
'plan'=>$dataTempPlan, 'plan' => $dataTempPlan,
'actual'=>$dataTempReport, 'actual' => $dataTempReport,
); );
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 >= 100){ if ($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100) {
if($tempTtlPercentActual >= 100) if ($tempTtlPercentActual >= 100)
$tempTtlPercentActual = 100; $tempTtlPercentActual = 100;
if($tempTtlPercentPlan >= 100) if ($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100; $tempTtlPercentPlan = 100;
} }
$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];
$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);
$tempPercentageReal[] = round($sumPercentageActual, 2); $tempPercentageReal[] = round($sumPercentageActual, 2);
} }
@ -896,10 +904,10 @@ class MasterFunctionsHelper {
} }
try { try {
if(round($totalACWP,0) > $totalRencanaBudget){ if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP,0)+0; $estimatedCost = round($totalACWP, 0) + 0;
}else{ } else {
$estimatedCost = ($totalRencanaBudget+0); $estimatedCost = ($totalRencanaBudget + 0);
} }
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json([ return response()->json([
@ -911,22 +919,23 @@ 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";
} }
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" => $tempDate,
"percentage" =>$tempPercentage, "percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan, "percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal, "percentageReal" => $tempPercentageReal,
"data_details" =>$arr_ActualM, "data_details" => $arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" => array(
"acwp" => round($totalACWP,0), "current_budget" => $totalRencanaBudget,
"bcwp" => round($totalBCWP,0), "acwp" => round($totalACWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), "bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0, "add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost, "estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation, "cost_deviation" => $costDeviation,
@ -935,9 +944,9 @@ class MasterFunctionsHelper {
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name"=> $dataProject->nama, "proyek_name" => $dataProject->nama,
"data"=>$dataResponse, "data" => $dataResponse,
"gantt"=>$keyGantt, "gantt" => $keyGantt,
); );
return $dataFinal; return $dataFinal;

Loading…
Cancel
Save