Browse Source

remove unused codes

pull/3/head
Muhammad Sulaiman Yusuf 3 years ago
parent
commit
bdba1a2347
  1. 436
      app/Http/Controllers/ActivityController.php

436
app/Http/Controllers/ActivityController.php

@ -11,7 +11,6 @@ use App\Models\UserToActivity;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\AssignTools; use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\Holiday; use App\Models\Holiday;
use App\Models\ReportActivity; use App\Models\ReportActivity;
@ -33,7 +32,7 @@ class ActivityController extends Controller
} }
return response()->json(['status'=>'success','data'=>$dataGantt,'code'=>200], 200); return response()->json(['status'=>'success','data'=>$dataGantt,'code'=>200], 200);
} }
private function getDataActivity($id) private function getDataActivity($id)
{ {
@ -52,7 +51,7 @@ class ActivityController extends Controller
}else{ }else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
} }
foreach($data as $objRow){ foreach($data as $objRow){
$objRow->text = $objRow->name; $objRow->text = $objRow->name;
if($objRow->parent_id){ if($objRow->parent_id){
@ -153,14 +152,14 @@ class ActivityController extends Controller
$dataPlan = AssignMaterial::where('activity_id', $id)->get(); $dataPlan = AssignMaterial::where('activity_id', $id)->get();
$tmpPercentage1 = []; $tmpPercentage1 = [];
if(!$dataPlan->isEmpty()){ if(!$dataPlan->isEmpty()){
foreach ($dataPlan as $value) { foreach ($dataPlan as $value) {
$qty_plan = $value->qty_planning; $qty_plan = $value->qty_planning;
$status_activity = $value->status_activity; $status_activity = $value->status_activity;
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty"); $getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
$percentage1 = ($getDataVolActual * 100) / $qty_plan; $percentage1 = ($getDataVolActual * 100) / $qty_plan;
if($status_activity == 'done'){ if($status_activity == 'done'){
$tmpPercentage1[] = 100; $tmpPercentage1[] = 100;
} }
else{ else{
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1; $tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
} }
@ -169,7 +168,7 @@ class ActivityController extends Controller
$totalPercentage = array_sum($tmpPercentage1) > 0 ? array_sum($tmpPercentage1) / count($tmpPercentage1) : 0; $totalPercentage = array_sum($tmpPercentage1) > 0 ? array_sum($tmpPercentage1) / count($tmpPercentage1) : 0;
}else{ }else{
$totalPercentage = 0; $totalPercentage = 0;
} }
return $totalPercentage; return $totalPercentage;
@ -343,7 +342,7 @@ class ActivityController extends Controller
} }
if($data){ if($data){
$upactual = false; $upactual = false;
$result = $data->update($dataUpdate); $result = $data->update($dataUpdate);
if($result){ if($result){
if($parent && (int)$parent > 0){ if($parent && (int)$parent > 0){
$this->updateCostPlanning($parent); $this->updateCostPlanning($parent);
@ -376,8 +375,8 @@ class ActivityController extends Controller
return response()->json(['status'=>'failed','message'=>'data activity not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data activity not found!','code'=>400], 400);
die(); die();
} }
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'data activity successfully updated!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data activity successfully updated!','code'=>200], 200);
}else{ }else{
@ -427,7 +426,7 @@ class ActivityController extends Controller
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400); return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200);
@ -507,7 +506,7 @@ class ActivityController extends Controller
{ {
$biayaActual = Activity::where("parent_id", $id)->sum("biaya_actual"); $biayaActual = Activity::where("parent_id", $id)->sum("biaya_actual");
$dataActivity = Activity::find($id); $dataActivity = Activity::find($id);
$dataUpdate = array( $dataUpdate = array(
"biaya_actual" => $biayaActual, "biaya_actual" => $biayaActual,
"updated_by" => $this->currentName "updated_by" => $this->currentName
@ -534,136 +533,21 @@ class ActivityController extends Controller
public function calculateAllCost($activity_id, $proyek_id) public function calculateAllCost($activity_id, $proyek_id)
{ {
$humanCostPlanning = $this->calculateHuman($activity_id, $proyek_id);
$materialCostPlanning = 0; $materialCostPlanning = 0;
$toolsCostPlanning = 0; $toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning; $allCost = $materialCostPlanning + $toolsCostPlanning;
return $allCost; return $allCost;
} }
private function calculateHuman($activity_id, $proyek_id)
{
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate;
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
return $totalCost;
}
private function calculateHumanCost($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanDay($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanHours($human, $activity_id, $proyek_id)
{
$hours = OfficeHours::where("proyek_id", $proyek_id)->first();
$activity = Activity::find($activity_id);
$ganttId = $activity->version_gantt_id;
$verGantt = VersionGantt::find($ganttId);
$holiday = Holiday::where("version_gantt_id", $ganttId)->where("proyek_id", $proyek_id)->pluck("date");
$dateHoliday = $holiday->all();
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$begin = new \DateTime($activity->start_date);
$end = new \DateTime($activity->end_date);
$end = $end->modify( '+1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$totalCost = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDay = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) && !in_array($currentDay, $dateHoliday))
{
$totalHours = $this->getHourInDay($hours, $weekDay);
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost += ($standarRate*$totalHours)*$maxUsed;
}
}
return $totalCost;
}
private function getHourInDay($hours, $day)
{
$totalHours = 0;
switch ($day) {
case 1:
$totalHours = ceil(abs(((strtotime($hours->monday_end)-strtotime($hours->monday_start))/60)/60));
break;
case 2:
$totalHours = ceil(abs(((strtotime($hours->tuesday_end)-strtotime($hours->tuesday_start))/60)/60));
break;
case 3:
$totalHours = ceil(abs(((strtotime($hours->wednesday_end)-strtotime($hours->wednesday_start))/60)/60));
break;
case 4:
$totalHours = ceil(abs(((strtotime($hours->thursday_end)-strtotime($hours->thursday_start))/60)/60));
break;
case 5:
$totalHours = ceil(abs(((strtotime($hours->friday_end)-strtotime($hours->friday_start))/60)/60));
break;
case 6:
$totalHours = ceil(abs(((strtotime($hours->saturday_end)-strtotime($hours->saturday_start))/60)/60));
break;
default:
$totalHours = ceil(abs(((strtotime($hours->sunday_end)-strtotime($hours->sunday_start))/60)/60));
break;
}
return $totalHours;
}
private function calculateMaterial($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost");
return $totalCost;
}
private function calculateTools($activity_id, $proyek_id)
{
}
public function getPercentagePerDay(Request $request) public function getPercentagePerDay(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($allGantt as $val) { foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']); $dataProject = Project::find($val['proyek_id']);
@ -699,7 +583,7 @@ class ActivityController extends Controller
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
} }
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
$end = $end->modify( '+1 day' ); $end = $end->modify( '+1 day' );
@ -712,14 +596,14 @@ class ActivityController extends Controller
}else{ }else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
} }
$totalRencanaBudget = $totalRencanaBudget->sum; $totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0; $currentPercentage = 0;
$dataDate = []; $dataDate = [];
$dataPercen = []; $dataPercen = [];
foreach ($period as $dt) { foreach ($period as $dt) {
$weekDay = $dt->format("w"); $weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d"); $currentDate = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday))
{ {
$totalPercentage = 0; $totalPercentage = 0;
@ -730,7 +614,7 @@ class ActivityController extends Controller
}else{ }else{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
} }
foreach ($dataActivity as $activity) { foreach ($dataActivity as $activity) {
$duration = $activity->duration; $duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){ if($totalRencanaBudget > 0 && $duration > 0){
@ -764,12 +648,12 @@ class ActivityController extends Controller
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
if(isset($dataPayload['gannt_id'])){ if(isset($dataPayload['gannt_id'])){
$allGantt = $dataPayload['gannt_id']; $allGantt = $dataPayload['gannt_id'];
}else{ }else{
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
@ -790,7 +674,7 @@ class ActivityController extends Controller
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
->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['last_gantt_id']) ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->min("plan_date"); ->min("plan_date");
$maxDate = DB::table('assign_material_to_activity as ama') $maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
@ -804,7 +688,7 @@ class ActivityController extends Controller
$interval = \DateInterval::createFromDateString('1 day'); $interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = []; $arr_ActualM = [];
$tempDate = []; $tempDate = [];
$tempPercentage = []; $tempPercentage = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan=0;
$tempTtlPercentActual=0; $tempTtlPercentActual=0;
@ -814,12 +698,12 @@ class ActivityController extends Controller
$currentProgressActivity = 0; $currentProgressActivity = 0;
$currentBCWP = 0; $currentBCWP = 0;
$budgetControlBCWP = 0; $budgetControlBCWP = 0;
foreach ($period as $dt) { foreach ($period as $dt) {
$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['last_gantt_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"))
->get(); ->get();
@ -833,7 +717,7 @@ class ActivityController extends Controller
$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) {
@ -845,13 +729,13 @@ class ActivityController extends Controller
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$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->ttl_qty_plan;
$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;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($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; $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP; $dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
@ -869,34 +753,34 @@ class ActivityController extends Controller
->first(); ->first();
$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;
$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;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
$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'){
if($dt->format("w")==1){ if($dt->format("w")==1){
if($totalACWP > 0 ){ if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP; $budgetControlACWP = $currentACWP + $totalACWP;
} }
if($totalBCWP > 0 ){ if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP; $budgetControlBCWP = $currentBCWP + $totalBCWP;
} }
$tempTtlPercentPlan+= $sumPercentagePlan; $tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual; $tempTtlPercentActual+= $sumPercentageActual;
@ -916,34 +800,39 @@ class ActivityController extends Controller
$tempTtlPercentPlan = 0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0; $tempTtlPercentActual = 0;
} }
}else{ }else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0); $tempDate[] = array($dt->format("Y-m-d"), 0, 0);
} }
} }
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);
} }
$costDeviation = $totalRencanaBudget - $estimatedCost; $costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" =>$tempDate,
"percentage" =>$tempPercentage, "percentage" =>$tempPercentage,
"data_details" =>$arr_ActualM, "data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($totalACWP,0), "acwp" => round($totalACWP,0),
"bcwp" => round($totalBCWP,0), "bcwp" => round($totalBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,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,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN" "potential" => $potential,
) )
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name"=> $dataProject->nama, "proyek_name"=> $dataProject->nama,
"data"=>$dataResponse, "data"=>$dataResponse,
@ -952,196 +841,17 @@ class ActivityController extends Controller
} }
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
public function getCalculateCurvaSBackup(Request $request)
{
$dataPayload = $request->all();
$allGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']);
$holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get();
$dateHoliday = []; //$holiday->all();
foreach ($holidays as $holiday) {
$startH = new \DateTime($holiday->date);
$endH = clone $startH;
$endH->modify('+'.$holiday->duration.' day');
$intervalH = \DateInterval::createFromDateString('1 day');
$periodH = new \DatePeriod($startH, $intervalH, $endH);
foreach ($periodH as $dt) {
$dateHoliday[] = $dt->format("Y-m-d");
}
}
$verGantt = VersionGantt::find($val['last_gantt_id']);
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}else{
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end2 = new \DateTime($maxDate);
$end2 = $end2->modify( '-1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
if($dataHeader){
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}
$totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0;
$currentACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
$currentBCWP = 0;
$budgetControlBCWP = 0;
$dataDate = [];
$dataPercen = [];
$testdata = [];
$countWeek = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d");
$testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate, 'dayof' => $dayOff);
$totalPercentage = isset($totalPercentage) ? $totalPercentage : 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalProgressActivity = isset($totalProgressActivity) ? $totalProgressActivity : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday))
{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
foreach ($dataActivity as $activity) {
$duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){
$totalPercentage += $activity->bobot_planning/$duration;
if($activity->biaya_actual > 0 && $activity->persentase_progress){
$totalACWP += $activity->biaya_actual/$duration;
$totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration;
$totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100;
}
}
}
}
if($currentDate == $end2->format('Y-m-d')){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}else if($weekDay == "0"){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}
}
if(round($budgetControlACWP,0) > $totalRencanaBudget){
$estimatedCost = round($budgetControlACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
$dataResponse = array(
"date" =>$dataDate,
"percentage" =>$dataPercen,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($budgetControlACWP,0),
"bcwp" => round($budgetControlBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($budgetControlACWP,0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse
);
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'test' => array('current'=>$currentDate,'max' =>$end2->format('Y-m-d')), 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400);
}
} }
public function getCalculateCurvaSDays(Request $request) public function getCalculateCurvaSDays(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($allGantt as $val) { foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']); $dataProject = Project::find($val['proyek_id']);
@ -1176,7 +886,7 @@ class ActivityController extends Controller
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
} }
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
$interval = \DateInterval::createFromDateString('1 day'); $interval = \DateInterval::createFromDateString('1 day');
@ -1187,7 +897,7 @@ class ActivityController extends Controller
}else{ }else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
} }
$totalRencanaBudget = $totalRencanaBudget->sum; $totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0; $currentPercentage = 0;
$currentACWP = 0; $currentACWP = 0;
@ -1196,7 +906,7 @@ class ActivityController extends Controller
$dataDate = []; $dataDate = [];
$dataPercen = []; $dataPercen = [];
$testdata = []; $testdata = [];
foreach ($period as $dt) { foreach ($period as $dt) {
$weekDay = $dt->format("w"); $weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d"); $currentDate = $dt->format("Y-m-d");
$testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate); $testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate);
@ -1208,19 +918,19 @@ class ActivityController extends Controller
$totalBCWP = 0; $totalBCWP = 0;
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
foreach ($dataActivity as $activity) { foreach ($dataActivity as $activity) {
$duration = $activity->duration; $duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){ if($totalRencanaBudget > 0 && $duration > 0){
$totalPercentage += $activity->bobot_planning/$duration; $totalPercentage += $activity->bobot_planning/$duration;
if($activity->biaya_actual > 0 && $activity->persentase_progress){ if($activity->biaya_actual > 0 && $activity->persentase_progress){
$totalACWP += $activity->biaya_actual/$duration; $totalACWP += $activity->biaya_actual/$duration;
$totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration; $totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration;
$totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100; $totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100;
} }
} }
} }
$currentPercentage = round(($currentPercentage + $totalPercentage), 0); $currentPercentage = round(($currentPercentage + $totalPercentage), 0);
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP; $currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0); $currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP; $currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
@ -1230,7 +940,7 @@ class ActivityController extends Controller
$dataDate[] = array($currentDate, $currentBCWP, $currentACWP); $dataDate[] = array($currentDate, $currentBCWP, $currentACWP);
$dataPercen[] = array($currentPercentage, $currentProgressActivity); $dataPercen[] = array($currentPercentage, $currentProgressActivity);
}else{ }else{
$dataDate[] = $currentDate; $dataDate[] = $currentDate;
$dataPercen[] = array($currentPercentage,$currentProgressActivity); $dataPercen[] = array($currentPercentage,$currentProgressActivity);
} }
@ -1286,7 +996,7 @@ class ActivityController extends Controller
foreach($activities as $activity) { foreach($activities as $activity) {
$activity_id = $activity->id; $activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count(); $countReports = ReportActivity::where('activity_id', $activity_id)->count();
if ($countReports === 1) { if ($countReports === 1) {
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get(); $dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) { foreach($dataReports as $dr) {
@ -1318,4 +1028,4 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
} }
} }

Loading…
Cancel
Save