You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
729 lines
27 KiB
729 lines
27 KiB
<?php |
|
|
|
namespace App\Http\Controllers; |
|
|
|
use App\Models\Activity; |
|
use App\Models\ActivityDokumen; |
|
use App\Models\AssignMaterial; |
|
use App\Models\CommentActivity; |
|
use App\Models\DokumenProject; |
|
use App\Models\FolderDocumentProyek; |
|
use App\Models\Holiday; |
|
use App\Models\Image; |
|
use App\Models\Link; |
|
use App\Models\OfficeHours; |
|
use App\Models\Project; |
|
use App\Models\ProjectApproval; |
|
use App\Models\ProjectCharter; |
|
use App\Models\ProjectMileStone; |
|
use App\Models\ProjectParticipants; |
|
use App\Models\ProjectPhase; |
|
use App\Models\ProjectType; |
|
use App\Models\ReportActivity; |
|
use App\Models\ReportActivityMaterial; |
|
use App\Models\ShowHideColumn; |
|
use App\Models\User; |
|
use App\Models\UserToActivity; |
|
use App\Models\UserToProyek; |
|
use App\Models\VersionGantt; |
|
use Illuminate\Http\Request; |
|
use Illuminate\Support\Facades\DB; |
|
|
|
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; |
|
|
|
class ProjectController extends Controller |
|
{ |
|
|
|
public function add(Request $request) |
|
{ |
|
$this->validate($request, [ |
|
'nama' => 'required', |
|
'mulai_proyek' => 'required', |
|
'akhir_proyek' => 'required', |
|
'rencana_biaya' => 'required', |
|
'type_proyek_id' => 'required' |
|
]); |
|
|
|
$data = $request->all(); |
|
|
|
$data['created_by'] = $this->currentName; |
|
|
|
if(empty($data['phase_id'])) |
|
$data['phase_id'] = 1; |
|
|
|
$result = Project::create($data); |
|
|
|
if(!$result) |
|
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); |
|
|
|
$this->createOfficeHours($result->id); |
|
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); |
|
|
|
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); |
|
} |
|
|
|
public function edit($id){ |
|
if(empty($id) || !is_int((int)$id)) |
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
|
|
$result = Project::find($id); |
|
|
|
if(!$result) |
|
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
|
|
|
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); |
|
} |
|
|
|
public function update(Request $request, $id) |
|
{ |
|
if(empty($id) || !is_int((int)$id)) |
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
|
|
$data = Project::find($id); |
|
|
|
if(!$data) |
|
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
|
|
|
$result = $data->update($request->all()); |
|
|
|
if(!$result) |
|
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); |
|
|
|
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); |
|
} |
|
|
|
private function createOfficeHours($proyek_id) |
|
{ |
|
$dataCreate = array( |
|
"proyek_id"=>$proyek_id, |
|
"monday_start"=> "08:00:00", |
|
"monday_end"=> "16:00:00", |
|
"tuesday_start"=> "08:00:00", |
|
"tuesday_end"=> "16:00:00", |
|
"wednesday_start"=> "08:00:00", |
|
"wednesday_end"=> "16:00:00", |
|
"thursday_start"=> "08:00:00", |
|
"thursday_end"=> "16:00:00", |
|
"friday_start"=> "08:00:00", |
|
"friday_end"=> "16:00:00", |
|
"saturday_start"=> "08:00:00", |
|
"saturday_end"=> "16:00:00", |
|
"sunday_start"=> "08:00:00", |
|
"sunday_end"=> "16:00:00", |
|
"created_by"=> $this->currentName |
|
); |
|
|
|
OfficeHours::create($dataCreate); |
|
|
|
return true; |
|
} |
|
|
|
public function delete($id) |
|
{ |
|
$data = Project::find($id); |
|
|
|
if(!$data) |
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
|
|
|
$this->deleteRelative($id); |
|
|
|
if(!$data->delete()) |
|
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); |
|
|
|
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
|
} |
|
|
|
private function deleteRelative($project_id) |
|
{ |
|
UserToProyek::where('proyek_id', $project_id)->delete(); |
|
UserToActivity::where('proyek_id', $project_id)->delete(); |
|
AssignMaterial::where('proyek_id', $project_id)->delete(); |
|
ProjectCharter::where('proyek_id', $project_id)->delete(); |
|
ProjectApproval::where('proyek_id', $project_id)->delete(); |
|
ProjectMileStone::where('proyek_id', $project_id)->delete(); |
|
ProjectParticipants::where('proyek_id', $project_id)->delete(); |
|
$this->deleteVersionGantt($project_id); |
|
$this->deleteDokumenProject($project_id); |
|
} |
|
|
|
private function deleteVersionGantt($project_id) |
|
{ |
|
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); |
|
$vhIds = $dataVg->all(); |
|
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); |
|
$activityIds = $activity->all(); |
|
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); |
|
foreach ($dataRa as $ra) { |
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
|
foreach ($images as $image) { |
|
if(file_exists($this->pathImage.$image->image)){ |
|
unlink($this->pathImage.$image->image); |
|
} |
|
} |
|
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
|
} |
|
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
|
foreach ($dataAd as $ad) { |
|
if(file_exists($this->pathActivityDocument.$ad->file)){ |
|
unlink($this->pathActivityDocument.$ad->file); |
|
} |
|
} |
|
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
|
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
|
Holiday::where("proyek_id", $project_id)->delete(); |
|
VersionGantt::where("proyek_id", $project_id)->delete(); |
|
Link::whereIn("version_gantt_id", $vhIds)->delete(); |
|
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); |
|
Activity::whereIn("version_gantt_id", $vhIds)->delete(); |
|
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
|
} |
|
|
|
private function deleteDokumenProject($project_id) |
|
{ |
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); |
|
|
|
foreach ($dataDokumen as $dokumen) { |
|
if(file_exists($this->pathDocument.$dokumen->file)){ |
|
unlink($this->pathDocument.$dokumen->file); |
|
} |
|
} |
|
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
|
|
|
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
|
$ref_ids = $dataFolder->all(); |
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
|
foreach ($dataDokumen as $dokumen) { |
|
if(file_exists($this->pathDocument.$dokumen->file)){ |
|
unlink($this->pathDocument.$dokumen->file); |
|
} |
|
} |
|
|
|
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
|
} |
|
|
|
public function search(Request $request) |
|
{ |
|
$payload = $request->all(); |
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
|
$builder = $dataBuilder['builder']; |
|
$countBuilder = $dataBuilder['count']; |
|
$dataGet = $builder->get(); |
|
$totalRecord = $countBuilder->count(); |
|
|
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
|
} |
|
|
|
public function list() |
|
{ |
|
$data = Project::orderBy('id', 'desc')->get(); |
|
$countData = $data->count(); |
|
|
|
if(!$data) |
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
|
|
|
$scheduleWarningThreshold = 10; |
|
$scheduleDangerThreshold = 5; |
|
foreach($data as $d){ |
|
$progress = $costVariance = $actualCost = 0; |
|
$lastActivity = null; |
|
$scheduleHealth = "on-track"; |
|
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); |
|
if($rootActivity){ |
|
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; |
|
$actualCost = $rootActivity->biaya_actual ?? 0; |
|
$progress = $rootActivity->persentase_progress ?? 0; |
|
|
|
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); |
|
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); |
|
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); |
|
$daysRemaining = $date2->diff($date1); |
|
$daysRemaining = $daysRemaining->d; |
|
|
|
if($daysRemaining <= $scheduleDangerThreshold) { |
|
$scheduleHealth = "danger"; |
|
} elseif ($daysRemaining <= $scheduleWarningThreshold) { |
|
$scheduleHealth = "warning"; |
|
} |
|
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); |
|
} |
|
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); |
|
$d->plannedCost = $d->rencana_biaya; |
|
$d->actualCost = $actualCost; |
|
$d->lastActivity = $lastActivity ?? "-"; |
|
$d->costVariance = $costVariance; |
|
$d->costHealth = $d->budget_health; |
|
$d->scheduleHealth = $scheduleHealth; |
|
$d->progress = $progress; |
|
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; |
|
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; |
|
$d->projectManager = DB::table('m_proyek') |
|
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') |
|
->where('m_proyek.id', $d->id) |
|
->pluck('m_users.name') |
|
->first(); |
|
if($d->area_kerja != ''){ |
|
$d->geolocation = $this->httpReq($d->area_kerja); |
|
$d->geolocation = []; |
|
} else { |
|
$d->geolocation = []; |
|
} |
|
} |
|
|
|
$totalPlannedCost = $data->sum('plannedCost'); |
|
$totalActualCost = $data->sum('actualCost'); |
|
$manpowers = User::count(); |
|
$projectsOnDanger = Project::where('budget_health', 'danger')->count(); |
|
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); |
|
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); |
|
try { |
|
$projectsByPhase = DB::table('m_proyek') |
|
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) |
|
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') |
|
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') |
|
->get(); |
|
} catch (\DivisionByZeroError $e) { |
|
return response()->json(['message' => $e->getMessage()]); |
|
} |
|
try { |
|
$projectsByType = DB::table('m_proyek') |
|
->select('m_type_proyek.name', DB::raw('count(*) as total')) |
|
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') |
|
->groupBy('m_type_proyek.name') |
|
->get(); |
|
} catch (\DivisionByZeroError $e) { |
|
return response()->json(['message' => $e->getMessage()]); |
|
} |
|
|
|
return response()->json( |
|
[ |
|
'status'=>'success', |
|
'code'=>200, |
|
'data'=>$data, |
|
'totalRecord'=>$countData, |
|
'totalPlannedCost' => $totalPlannedCost, |
|
'totalActualCost' => $totalActualCost, |
|
'totalRevenue' => $totalPlannedCost - $totalActualCost, |
|
'manpowers' => $manpowers, |
|
'projectsOnDanger'=> $projectsOnDanger, |
|
'projectPhases' => $projectPhases, |
|
'projectsByPhase' => $projectsByPhase, |
|
'projectTypes' => $projectTypes, |
|
'projectsByType' => $projectsByType, |
|
], 200); |
|
} |
|
|
|
private function httpReq($search){ |
|
$ch = curl_init(); |
|
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); |
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); |
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
curl_setopt($ch, CURLOPT_VERBOSE, true); |
|
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); |
|
|
|
$output = curl_exec($ch); |
|
curl_close($ch); |
|
|
|
return json_decode($output); |
|
} |
|
|
|
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); |
|
|
|
$result = Project::find($id); |
|
|
|
if(!$result) |
|
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
|
|
|
$gantt = $this->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); |
|
} |
|
|
|
public function synchronizeReport($gantt_id) |
|
{ |
|
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); |
|
$reports = []; |
|
|
|
foreach($activities as $activity) { |
|
$activity_id = $activity->id; |
|
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); |
|
if ($countReports === 1) { |
|
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); |
|
foreach($dataReports as $dr) { |
|
$reports[] = array( |
|
'activity_id'=>$activity_id, |
|
'min_date'=>$dr->report_date, |
|
'max_date'=>date_modify(date_create($dr->report_date), "1 days") |
|
); |
|
} |
|
} |
|
if ($countReports > 1) { |
|
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); |
|
$lastReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderByDesc('report_date')->first(); |
|
$reports[] = array( |
|
'activity_id'=>$activity_id, |
|
'min_date'=>$firstReport->report_date, |
|
'max_date'=>date_modify(date_create($lastReport->report_date), "1 days") |
|
); |
|
} |
|
$activity->reports = $reports; |
|
} |
|
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ |
|
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ |
|
|
|
for ($i=0; $i < count($reports); $i++) { |
|
$activity = Activity::find($reports[$i]['activity_id']); |
|
$activity->start_date = $reports[$i]['min_date']; |
|
$activity->end_date = $reports[$i]['max_date']; |
|
$activity->save(); |
|
} |
|
|
|
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); |
|
} |
|
|
|
public function setBaseline($gantt_id) |
|
{ |
|
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); |
|
|
|
foreach ($activities as $activity) { |
|
$activity->update([ |
|
"planned_start"=>$activity->start_date, |
|
"planned_end"=>$activity->end_date, |
|
]); |
|
} |
|
|
|
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); |
|
} |
|
|
|
public function getOverdueActivities(Request $request){ |
|
$payload = $request->all(); |
|
if(empty($payload['id']) || !is_int((int)$payload['id'])) |
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
|
|
$result = Project::find($payload['id']); |
|
|
|
if(!$result) |
|
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); |
|
|
|
if(isset($payload['till_date'])) |
|
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); |
|
else |
|
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); |
|
|
|
$result->overdueActivities = $overdueActivities; |
|
|
|
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); |
|
} |
|
|
|
private function curlReq($url, $token){ |
|
$ch = curl_init(); |
|
$headers = [ |
|
'Authorization: '.$token |
|
]; |
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
|
|
$response = curl_exec($ch); |
|
if ($response === false) |
|
$response = curl_error($ch); |
|
curl_close($ch); |
|
|
|
return json_decode($response); |
|
} |
|
|
|
public function getInvoiceIntegration(Request $request) { |
|
$search = urlencode($request->search); |
|
if(empty($search)) |
|
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); |
|
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); |
|
$token = config('api.adw_token'); |
|
$response = $this->curlReq($url, $token); |
|
|
|
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); |
|
} |
|
|
|
public function getReportDistribution(Request $request){ |
|
$payload = $request->all(); |
|
|
|
if(empty($payload['project_id']) || !is_int((int)$payload['project_id'])) |
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
|
|
$reports = DB::table('assign_material_to_activity as ama') |
|
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit', |
|
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') |
|
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') |
|
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') |
|
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') |
|
->join('m_users as u', 'u.id', '=', 'ram.user_id') |
|
->where('ama.proyek_id', '=', $payload['project_id']) |
|
->whereNotNull('ram.lat') |
|
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]) |
|
->get(); |
|
|
|
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); |
|
} |
|
} |
|
|
|
|