Browse Source

remove unused codes

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

304
app/Http/Controllers/ActivityController.php

@ -11,7 +11,6 @@ use App\Models\UserToActivity;
use App\Models\CommentActivity;
use App\Models\AssignMaterial;
use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\VersionGantt;
use App\Models\Holiday;
use App\Models\ReportActivity;
@ -534,128 +533,13 @@ class ActivityController extends Controller
public function calculateAllCost($activity_id, $proyek_id)
{
$humanCostPlanning = $this->calculateHuman($activity_id, $proyek_id);
$materialCostPlanning = 0;
$toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning;
$allCost = $materialCostPlanning + $toolsCostPlanning;
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)
{
$dataPayload = $request->all();
@ -928,6 +812,11 @@ class ActivityController extends Controller
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array(
"date" =>$tempDate,
@ -940,7 +829,7 @@ class ActivityController extends Controller
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"
"potential" => $potential,
)
);
@ -955,185 +844,6 @@ class ActivityController extends Controller
}
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)
{
$dataPayload = $request->all();

Loading…
Cancel
Save