Browse Source

move s curve calc to helper

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
f46d6bcb8d
  1. 262
      app/Helpers/MasterFunctionsHelper.php
  2. 153
      app/Http/Controllers/DashboardBoDController.php
  3. 264
      app/Http/Controllers/ProjectController.php

262
app/Helpers/MasterFunctionsHelper.php

@ -2,10 +2,13 @@
namespace App\Helpers;
use App\Models\Activity;
use App\Models\Project;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\DB;
class MasterFunctionsHelper {
public static function curlReq($url, $token = ""){
if(!$token)
$token = config('api.adw_token');
@ -29,4 +32,261 @@ class MasterFunctionsHelper {
return json_decode($output);
}
public function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
// dipake di dashboard project & bod
public function getSCurve($request){
$allGantt = [];
if(!is_int($request)){
$dataPayload = $request->all();
if(isset($dataPayload['gantt_id'])){
$allGantt = $dataPayload['gantt_id'];
}else{
$allGantt[] = MasterFunctionsHelper::getLatestGantt($dataPayload['project_id']);
}
} else {
$allGantt[] = MasterFunctionsHelper::getLatestGantt($request);
}
foreach($allGantt as $gantt){
$gantt = VersionGantt::where('id', $gantt['last_gantt_id'])->first()->toArray();
if($gantt['calculation_type'] == 'simple') {
// to do
} else {
return MasterFunctionsHelper::calculateProgressBasedOnReportMaterial($gantt);
}
}
}
public function calculateProgressBasedOnReportMaterial($keyGantt)
{
DB::enableQueryLog();
$dataFinal=[];
$dataPayload = [];
$dataPayload['period'] = 'week';
$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();
if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){
$dataPayload['end_date'] = $dataProject->akhir_proyek;
}
if($dataHeader){
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->sum("rencana_biaya");
}else{
$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())
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();
if(!$alreadyHasReport)
return $dataFinal;
$minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first();
$begin = new \DateTime($minDate.' Monday');
if(isset($dataPayload['end_date'])){
$maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate);
/* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D');
} else {
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday');
$interval = new \DateInterval('P7D');
}
$period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = [];
$tempDate = [];
$tempPercentagePlan = [];
$tempPercentagePlanWhr = [];
$tempPercentageReal = [];
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$currentACWP = 0;
$currentBCWP = 0;
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$dataPlanM = DB::table('assign_material_to_activity as ama')
->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['id'])
->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('ama.plan_date', '>', $minSevenDays)
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', '<=',$dt->format("Y-m-d"))
->whereDate('ram.report_date', '>',$minSevenDays)
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan=0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try {
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual=0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
try {
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
} 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,
);
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){
if($tempTtlPercentActual >= 100)
$tempTtlPercentActual = 100;
if($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
}
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){
break;
}
}else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2);
$tempPercentageReal[] = round($sumPercentageActual, 2);
}
$tempDate[] = array($dt->format("Y-m-d"));
}
try {
if(round($totalACWP,0) > $totalRencanaBudget){
$estimatedCost = round($totalACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
} catch (\DivisionByZeroError $e) {
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";
}
$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(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse,
"gantt"=>$keyGantt
);
return $dataFinal;
}
}

153
app/Http/Controllers/DashboardBoDController.php

@ -2,15 +2,12 @@
namespace App\Http\Controllers;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Divisi;
use App\Models\Project;
use App\Models\ProjectPhase;
use App\Models\ReportActivityMaterial;
use App\Models\User;
use App\Models\UserToVersionGantt;
use App\Models\VersionGantt;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
@ -129,7 +126,7 @@ class DashboardBoDController extends Controller
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach($projects as $project) {
$project->scurve = $this->getSCurve($project->id);
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
try {
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$return['warning'] += 1;
@ -156,7 +153,7 @@ class DashboardBoDController extends Controller
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get();
foreach($projects as $project) {
$project->scurve = $this->getSCurve($project->id);
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$warning++;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
@ -302,144 +299,6 @@ class DashboardBoDController extends Controller
], 200);
}
private function getSCurve($project_id)
{
DB::enableQueryLog();
$dataPayload = [
'project_id' => $project_id,
'period' => 'week',
];
$allGantt[] = $this->getLatestGantt($dataPayload['project_id']);
$dataResponse=[];
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
continue;
$alreadyHasReport = DB::table('report_activity_material as a')
->select('a.id')
->join('m_activity as b', 'b.id', '=', 'a.activity_id')
->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->exists();
if(!$alreadyHasReport)
continue;
/* $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start"); */
$minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->whereNull('parent_id')->pluck('start_date')->first();
$begin = new \DateTime($minDate.' Monday');
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday');
$interval = new \DateInterval('P7D');
$period = new \DatePeriod($begin, $interval, $end);
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$tempPercentagePlan = [];
$tempPercentageReal = [];
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$dataPlanM = DB::table('assign_material_to_activity as ama')
->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('ama.plan_date', '>', $minSevenDays)
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', '<=',$dt->format("Y-m-d"))
->whereDate('ram.report_date', '>',$minSevenDays)
->get();
$sumPercentagePlan=0;
foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
try {
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
}
$sumPercentageActual=0;
foreach ($dataActualM as $keyActualM) {
try {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage(), 'q' => $sumVolActual]);
}
}
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){
if($tempTtlPercentActual >= 100)
$tempTtlPercentActual = 100;
if($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
}
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){
break;
}
}
$plannedPercentage = end($tempPercentagePlan);
$progressPercentage = end($tempPercentageReal);
$difference = $plannedPercentage - $progressPercentage;
$dataResponse = array(
'planned' => $plannedPercentage == false ? 0 : $plannedPercentage,
'progress' => $progressPercentage == false ? 0 : $progressPercentage,
'difference' => $difference,
);
}
return $dataResponse;
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
public function getDetailExpenditure($year = '%'){
$year = $this->interpolateYear($year);
@ -447,7 +306,7 @@ class DashboardBoDController extends Controller
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach($projects as $project){
$lastGantt = $this->getLatestGantt($project->id);
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if($project->kode_sortname != ""){
$resp = $this->getInvoiceIntegration($project->kode_sortname);
@ -459,9 +318,9 @@ class DashboardBoDController extends Controller
$project->pm = User::find($project->pm_id);
/* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */
$project->scurve = $this->getSCurve($project->id);
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->lastGanttId = $this->getLatestGantt($project->id);
$project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id);
}
return response()->json([

264
app/Http/Controllers/ProjectController.php

@ -309,261 +309,6 @@ class ProjectController extends Controller
], 200);
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
public function getSCurve(Request $request)
{
DB::enableQueryLog();
$dataPayload = $request->all();
$allGantt = [];
if(isset($dataPayload['gantt_id'])){
$allGantt = $dataPayload['gantt_id'];
}else{
$allGantt[] = $this->getLatestGantt($dataPayload['project_id']);
}
$dataFinal=[];
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first();
if(isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek){
$dataPayload['end_date'] = $dataProject->akhir_proyek;
}
if($dataHeader){
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}else{
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}
if(!Activity::where("version_gantt_id", $keyGantt['last_gantt_id'])->first())
continue;
$alreadyHasReport = DB::table('report_activity_material as a')
->select('a.id')
->join('m_activity as b', 'b.id', '=', 'a.activity_id')
->where('b.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->exists();
if(!$alreadyHasReport)
continue;
/* $minDate = DB::table('assign_material_to_activity as ama') */
/* ->where("ama.proyek_id", $keyGantt['proyek_id']) */
/* ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') */
/* ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) */
/* ->min("plan_date"); */
/* $minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->min("planned_start"); */
$minDate = Activity::where('version_gantt_id', $keyGantt['last_gantt_id'])->whereNull('parent_id')->pluck('start_date')->first();
/* print_r($minDate); exit(); */
$begin = new \DateTime($minDate.' Monday');
if(isset($dataPayload['end_date'])){
$maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate);
/* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D');
} else {
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday');
$interval = new \DateInterval('P7D');
}
$period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = [];
$tempDate = [];
$tempPercentagePlan = [];
$tempPercentagePlanWhr = [];
$tempPercentageReal = [];
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$currentACWP = 0;
$currentBCWP = 0;
/* foreach($period as $x){ */
/* echo $x->format("Y-m-d")."\n"; */
/* } exit(); */
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$dataPlanM = DB::table('assign_material_to_activity as ama')
->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
/* ->whereDate('ama.plan_date', $dt->format("Y-m-d")) */
->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('ama.plan_date', '>', $minSevenDays)
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', '<=',$dt->format("Y-m-d"))
->whereDate('ram.report_date', '>',$minSevenDays)
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan=0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try {
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual=0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
try {
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
} 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,
);
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
if($tempTtlPercentPlan >= 100 || $tempTtlPercentActual >= 100){
if($tempTtlPercentActual >= 100)
$tempTtlPercentActual = 100;
if($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
}
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100){
break;
}
}else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2);
$tempPercentageReal[] = round($sumPercentageActual, 2);
}
$tempDate[] = array($dt->format("Y-m-d"));
}
/* print_r($tempDate); exit(); */
try {
if(round($totalACWP,0) > $totalRencanaBudget){
$estimatedCost = round($totalACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
} catch (\DivisionByZeroError $e) {
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";
}
$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(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse,
"allGant"=>$allGantt
);
}
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
public function detail($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -573,7 +318,7 @@ class ProjectController extends Controller
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = $this->getLatestGantt($id);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
@ -663,8 +408,6 @@ class ProjectController extends Controller
$response = MasterFunctionsHelper::curlReq($url);
if($response->data->project_no == "")
return response()->json(['status'=>'error', 'message' => 'Project '.$search.' not found!', 'code'=>404], 404);
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
}
@ -689,5 +432,10 @@ class ProjectController extends Controller
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
}
public function getSCurve(Request $request){
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
}

Loading…
Cancel
Save