@ -7,11 +7,13 @@ use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity;
use App\Models\UserToActivity;
use App\Models\User;
use App\Models\AssignMaterial;
use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectCharter;
use App\Models\ProjectApproval;
use App\Models\ProjectPhase;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\ShowHideColumn;
@ -213,21 +215,18 @@ class ProjectController extends Controller
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$costWarningThreshold = 50000000;
$costDangerThreshold = 25000000;
$scheduleWarningThreshold = 10;
$scheduleDangerThreshold = 5;
foreach($data as $d){
$progress = $costVariance = $actualCost = 0;
$lastActivity = null;
$scheduleHealth = "on-track";
$costHealth = "on-budget";
$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)));
@ -239,27 +238,47 @@ class ProjectController extends Controller
} elseif ($daysRemaining < = $scheduleWarningThreshold) {
$scheduleHealth = "warning";
}
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
*/
if($costVariance < = $costDangerThreshold) {
$costHealth = "danger";
} elseif ($costVariance < = $costWarningThreshold) {
$costHealth = "warning";
}
}
$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->lastActivity = $lastActivity ?? "-";
//$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2;
$d->costVariance = $costVariance;
$d->costHealth = $costHealth;
//$d->scheduleHealth = $scheduleHealth;
$d->progress = $progress . "%";
$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;
}
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$totalPlannedCost = $data->sum('plannedCost');
$totalActualCost = $data->sum('actualCost');
$manpowers = User::where('employee_type', 'employee')->count();
$projectPhases = ProjectPhase::orderBy('order', '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 (\Exception $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,
'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase,
], 200);
}
public function getListProjectTask($id){
@ -278,15 +297,48 @@ class ProjectController extends Controller
public function dashboard($id)
{
$data = DB::table('m_proyek as mp')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', 'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish',
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health')
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->get();
$countData = $data->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){
$actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0;
}
$commentActivity = DB::table('m_comment_activity as mca')
->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created',
'ma.name as activity')
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id)
->orderBy('comment_by')
->take(2)
->get();
foreach ($data as $val) {
$dataRes['kode_sortname'] = $val->kode_sortname;
$dataRes['name_project'] = $val->name_project;
$dataRes['start'] = $val->start;
$dataRes['finish'] = $val->finish;
$dataRes['rencana_biaya'] = $val->rencana_biaya;
$dataRes['company'] = $val->company;
$dataRes['currency_symbol'] = $val->currency_symbol;
// get firstname
$arr = explode(" ", $val->pm);
$dataRes['pm'] = $arr[0];
$dataRes['budget_health'] = $val->budget_health;
$dataRes['actualCost'] = $actualCost;
$dataRes['progress'] = $progress;
$dataRes['comment'] = $commentActivity;
}
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes , 'totalRecord'=>$countData], 200);
}
}