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.
848 lines
29 KiB
848 lines
29 KiB
<?php |
|
|
|
namespace App\Http\Controllers; |
|
|
|
use DateTime; |
|
use App\Jobs\ProcessSCurve; |
|
use Illuminate\Http\Request; |
|
use App\Models\{ |
|
ReportActivityMaterial, |
|
ProjectToChecklistK3, |
|
FolderDocumentProyek, |
|
ProjectParticipants, |
|
ProductTransaction, |
|
ProjectChecklists, |
|
ProjectMileStone, |
|
RequestMaterial, |
|
ProjectApproval, |
|
CommentActivity, |
|
ActivityDokumen, |
|
UserToActivity, |
|
ShowHideColumn, |
|
ReportActivity, |
|
ProjectCharter, |
|
DokumenProject, |
|
AssignMaterial, |
|
ProjectIssues, |
|
HierarchyFtth, |
|
VersionGantt, |
|
UserToProyek, |
|
ProjectRisks, |
|
ProjectPhase, |
|
ProjectType, |
|
OfficeHours, |
|
AssignTools, |
|
ReportK3, |
|
Activity, |
|
Project, |
|
Holiday, |
|
Company, |
|
Image, |
|
User, |
|
Link |
|
}; |
|
use Illuminate\Database\Query\Builder; |
|
use Illuminate\Support\Facades\{Artisan, DB}; |
|
use App\Helpers\MasterFunctionsHelper; |
|
use Carbon\Carbon; |
|
|
|
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', |
|
'mulai_proyek' => 'required', |
|
'akhir_proyek' => 'required', |
|
'rencana_biaya' => 'required', |
|
'type_proyek_id' => 'required', |
|
]); |
|
DB::beginTransaction(); |
|
try { |
|
$data = $request->all(); |
|
$data['created_by'] = $this->currentName; |
|
$data['created_by_id'] = $this->currentId; |
|
$data['schedule_health'] = 'behind-schedule'; |
|
|
|
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); |
|
} else { |
|
$this->createOfficeHours($result['id']); |
|
$dataResultInsert = Project::where([['nama', $data['nama']], ['mulai_proyek', $data['mulai_proyek']]])->first(); |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); |
|
} |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
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::select( |
|
'income_year', |
|
'value_proyek', |
|
'scoupe_of_work', |
|
'kode_sortname', |
|
'jumlah_stakeholder', |
|
'nama', |
|
'mulai_proyek', |
|
'akhir_proyek', |
|
'area_kerja', |
|
'rencana_biaya', |
|
'biaya_actual', |
|
'company', |
|
'pm_id', |
|
'type_proyek_id', |
|
'divisi_id', |
|
'persentase_progress', |
|
'keterangan', |
|
'durasi_proyek', |
|
'progress_by_worklog', |
|
'currency_symbol', |
|
'late_consequence', |
|
'assumtion', |
|
'currency_code', |
|
'currency_name', |
|
'project_objectives', |
|
'considered_success_when', |
|
'potential_risk', |
|
'testing_environment', |
|
'budget_health', |
|
'phase_id', |
|
'calculation_status', |
|
'md.name as divisi_name', |
|
) |
|
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') |
|
->where('m_proyek.id', $id) |
|
->first(); |
|
if (!$result) { |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} else { |
|
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) { |
|
if ($data->update($request->all())) { |
|
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); |
|
} else { |
|
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500); |
|
} |
|
} else { |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} |
|
} |
|
|
|
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) |
|
{ |
|
DB::beginTransaction(); |
|
$data = Project::find($id); |
|
if ($data) { |
|
$this->deleteRelative($id); |
|
if ($data->delete()) { |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); |
|
} else { |
|
DB::rollBack(); |
|
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); |
|
} |
|
} else { |
|
DB::rollBack(); |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} |
|
} |
|
|
|
private function deleteRelative($project_id) |
|
{ |
|
DB::transaction(function () use ($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(); |
|
ProjectChecklists::where('proyek_id', $project_id)->delete(); |
|
ProjectIssues::where('proyek_id', $project_id)->delete(); |
|
ProjectRisks::where('proyek_id', $project_id)->delete(); |
|
ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); |
|
HierarchyFtth::where('project_id', $project_id)->delete(); |
|
AssignTools::where('proyek_id', $project_id)->delete(); |
|
OfficeHours::where('proyek_id', $project_id)->delete(); |
|
ReportK3::where('proyek_id', $project_id)->delete(); |
|
RequestMaterial::where('proyek_id', $project_id)->delete(); |
|
$this->deleteVersionGantt($project_id); |
|
$this->deleteDokumenProject($project_id); |
|
}, 5); |
|
} |
|
|
|
private function deleteVersionGantt($project_id) |
|
{ |
|
DB::transaction(function () use ($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(); |
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
foreach ($dataRa as $ra) { |
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
|
foreach ($images as $image) { |
|
if (file_exists($destinationPath['pathImage'] . $image->image)) { |
|
unlink($destinationPath['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($destinationPath['pathActivityDocument'] . $ad->file)) { |
|
unlink($destinationPath['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(); |
|
}, 5); |
|
} |
|
|
|
private function deleteDokumenProject($project_id) |
|
{ |
|
DB::transaction(function () use ($project_id) { |
|
$dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get(); |
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
foreach ($dataDokumen as $dokumen) { |
|
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { |
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
} |
|
} |
|
DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['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($destinationPath['pathDocument'] . $dokumen->file)) { |
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
} |
|
} |
|
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
|
}, 5); |
|
} |
|
|
|
public function search(Request $request) |
|
{ |
|
$payload = $request->all(); |
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
|
$builder = $dataBuilder['builder']; |
|
$countBuilder = $dataBuilder['count']; |
|
$dataGet = $builder->get(); |
|
foreach($dataGet as $p) { |
|
$project = Project::find($p->id); |
|
if (!$project) continue; |
|
|
|
$act = Activity::select('persentase_progress as total_progress') |
|
->where([ |
|
['proyek_id', $p->id], |
|
['parent_id', null] |
|
]) |
|
->first(); |
|
if ($act) { |
|
$project->persentase_progress = $act->total_progress; |
|
} else { |
|
$project->persentase_progress = 0; |
|
} |
|
$project->save(); |
|
} |
|
$totalRecord = $countBuilder->count(); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); |
|
} |
|
|
|
public function list() |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$data = Project::select( |
|
'id', |
|
'kode_sortname', |
|
'jumlah_stakeholder', |
|
'nama', |
|
'mulai_proyek', |
|
'akhir_proyek', |
|
'area_kerja', |
|
'lokasi_kantor', |
|
'rencana_biaya', |
|
'biaya_actual', |
|
'company', |
|
'pm_id', |
|
'type_proyek_id', |
|
'divisi_id', |
|
'persentase_progress', |
|
'keterangan', |
|
'durasi_proyek', |
|
'progress_by_worklog', |
|
'status', |
|
'currency_symbol', |
|
'currency_code', |
|
'currency_name', |
|
'project_objectives', |
|
'considered_success_when', |
|
'potential_risk', |
|
'testing_environment', |
|
'currency_code', |
|
'currency_symbol', |
|
'currency_name', |
|
'budget_health', |
|
'phase_id', |
|
'calculation_status', |
|
'created_at', |
|
'created_by', |
|
'updated_at', |
|
'updated_by' |
|
)->orderByDesc('id') |
|
->get(); |
|
$countData = $data->count(); |
|
if (!$data) { |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} |
|
|
|
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); |
|
$totalActualCost = $data->sum('actualCost'); |
|
$manpowers = User::count(); |
|
$projectsOnDanger = Project::where('budget_health', 'overrun')->count(); |
|
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); |
|
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); |
|
$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(); |
|
$projectsByType = DB::table('m_proyek') |
|
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total')) |
|
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') |
|
->groupBy('m_type_proyek.name') |
|
->get(); |
|
DB::commit(); |
|
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 |
|
); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
public function getListProjectTask($id) |
|
{ |
|
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*") |
|
->where("assign_hr_to_activity.user_id", $id) |
|
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') |
|
->groupBy("m_proyek.proyek_id") |
|
->get(); |
|
|
|
if ($data) { |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); |
|
} else { |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} |
|
} |
|
|
|
public function getSCurve(Request $request) |
|
{ |
|
$data = MasterFunctionsHelper::getSCurve($request); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); |
|
} |
|
|
|
// testing |
|
public function calculateSCurvetest(Request $request) |
|
{ |
|
$data = MasterFunctionsHelper::calculateSCurve($request->project_id); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); |
|
} |
|
|
|
public function calculateSCurve(Request $request) |
|
{ |
|
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); |
|
$dcdScurve = json_decode($sCurve['scurve'],true); |
|
$dataScurve = $dcdScurve[0]['data']; |
|
$today = date('Y-m-d'); |
|
$progressPlanBar = 0; |
|
foreach($dataScurve['date'] as $index => $dateArray) { |
|
if (isset($dateArray[0])) { |
|
$date = $dateArray[0]; |
|
if($date <= $today) { |
|
if (isset($dataScurve['percentagePlan'][$index])) { |
|
$progressPlanBar = round($dataScurve['percentagePlan'][$index], 2); |
|
} |
|
} |
|
} |
|
} |
|
$dcdScurve[0]['data']['progressPlanToDay'] = round($progressPlanBar,2); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dcdScurve], 200); |
|
} |
|
|
|
public function sCurveCommand(Request $request) |
|
{ |
|
Artisan::call('calculate:scurve', [ |
|
'project_id' => $request->project_id |
|
]); |
|
} |
|
|
|
public function ActualProgressProjectCommand() { |
|
Artisan::call('calculate:ActualProgressProject'); |
|
} |
|
|
|
public function getLinearSCurve(Request $request) |
|
{ |
|
$data = MasterFunctionsHelper::getLinearSCurve($request); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); |
|
} |
|
|
|
public static function setSyncDate($activity_id, $activity, $report) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$status = AssignMaterial::where('activity_id', $activity_id)->first(); |
|
if (!isset($status)) { |
|
DB::commit(); |
|
return [ |
|
'activity_id' => $activity_id, |
|
'min_date' => new DateTime($activity->start_date), |
|
'max_date' => new DateTime($activity->end_date), |
|
'status' => 'open' |
|
]; |
|
} |
|
if (!isset($status->status_activity)) { |
|
$status->status_activity = 'open'; |
|
} |
|
if ($status->status_activity != 'done') { |
|
$minDate = date_create($report->report_date); |
|
$maxDate = date_create($report->report_date); |
|
date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days")); |
|
} else { |
|
$material = AssignMaterial::where('activity_id', $activity_id)->first(); |
|
$minDate = date_create($material->start_activity); |
|
$maxDate = date_create($material->finish_activity); |
|
} |
|
DB::commit(); |
|
return [ |
|
'activity_id' => $activity_id, |
|
'min_date' => $minDate, |
|
'max_date' => $maxDate, |
|
'status' => $status->status_activity |
|
]; |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
public function synchronizeReport($gantt_id) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$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[] = self::setSyncDate($activity_id, $activity, $dr); |
|
} |
|
} |
|
if ($countReports > 1) { |
|
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); |
|
$reports[] = self::setSyncDate($activity_id, $activity, $firstReport); |
|
} |
|
$successor = Link::where('t_activity_id', $activity->id)->first(); |
|
if ($successor) { |
|
$predecessor = Activity::find($successor->s_activity_id); |
|
$activity->start_date = $predecessor->end_date; |
|
$end_date = new DateTime($activity->start_date); |
|
$end_date->modify("+" . $activity->duration . " days"); |
|
$activity->end_date = $end_date->format("Y-m-d H:i:sO"); |
|
} |
|
$activity->save(); |
|
} |
|
for ($i = 0; $i < count($reports); $i++) { |
|
$activity = Activity::find($reports[$i]['activity_id']); |
|
if ($reports[$i]['status'] != 'done') { |
|
$reports[$i]['max_date']->modify('-1 day'); |
|
} else if ($reports[$i]['status'] == 'done') { |
|
$activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59); |
|
} |
|
$activity->start_date = $reports[$i]['min_date']; //same early |
|
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early |
|
$startDate = new DateTime($activity->start_date); |
|
$endDate = new DateTime($activity->end_date); |
|
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate); |
|
$activity->duration = $duration; |
|
$activity->actual_start = $reports[$i]['min_date']; |
|
$activity->save(); |
|
} |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'message' => 'Synchronize to report success!', 'code' => 200], 200); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
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, |
|
"early_start" => $activity->start_date, |
|
"early_end" => $activity->end_date, |
|
]); |
|
} |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200); |
|
} |
|
|
|
public function setBaselineActivity($activity_id, $gantt_id) |
|
{ |
|
$activity = Activity::where([["version_gantt_id", $gantt_id], ['id', $activity_id]])->first(); |
|
$activity->update([ |
|
"planned_start" => $activity->start_date, |
|
"planned_end" => $activity->end_date, |
|
"early_start" => $activity->start_date, |
|
"early_end" => $activity->end_date, |
|
]); |
|
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200); |
|
} |
|
|
|
|
|
public function getByUser($id) |
|
{ |
|
$userProyek = UserToProyek::query() |
|
->from('assign_hr_to_proyek AS utp') |
|
->where([['is_customer', true], ['user_id', $id]]) |
|
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id') |
|
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id') |
|
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') |
|
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name') |
|
->get(); |
|
$totalRecord = $userProyek->count(); |
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); |
|
} |
|
|
|
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
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); |
|
} |
|
if (!isset($gantt_id)) { |
|
$gantt = MasterFunctionsHelper::getLatestGantt($id); |
|
$ganttId = $gantt['last_gantt_id']; |
|
} else { |
|
$ganttId = $gantt_id; |
|
} |
|
$result->projectManager = User::where('id', $result->pm_id)->value('name'); |
|
|
|
if (isset($s_curve)) { |
|
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); |
|
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); |
|
if ($result['type_proyek_id'] === 9) { |
|
// $actualEndExist = Activity::where('proyek_id', $id)->exists(); |
|
$query = Activity::where('proyek_id', $id); |
|
$maxEndDate = Activity::where('proyek_id', $id)->select('end_date') |
|
->orderBy('end_date', 'desc') |
|
->first(); |
|
} else { |
|
// $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); |
|
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date') |
|
->orderByDesc('end_date') |
|
->first(); |
|
$query = Activity::where('version_gantt_id', $ganttId); |
|
} |
|
} else { |
|
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); |
|
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); |
|
// $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); |
|
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date') |
|
->orderByDesc('end_date') |
|
->first(); |
|
$query = Activity::where('version_gantt_id', $ganttId); |
|
} |
|
|
|
if ($actualStartExist) { |
|
$startDate = $query->orderBy('actual_start')->value('start_date'); |
|
} else { |
|
$startDate = $query->orderBy('start_date')->value('start_date'); |
|
} |
|
// if($actualEndExist) |
|
// { |
|
// // $maxEndDate = $query->max('id'); |
|
// // get last end_date |
|
// // $endDate = $query->where('id',$maxEndDate)->first()->end_date; |
|
|
|
// } |
|
|
|
$plannedStart = Activity::where('version_gantt_id', $ganttId) |
|
->orderBy('planned_start') |
|
->value('planned_start'); |
|
$plannedEnd = Activity::where('version_gantt_id', $ganttId) |
|
->orderByDesc('planned_end') |
|
->value('planned_end'); |
|
if (isset($result->header)) { |
|
$result->header->start_date = $startDate; |
|
$result->header->end_date = $maxEndDate->end_date; |
|
$result->header->planned_start = $plannedStart; |
|
$result->header->planned_end = $plannedEnd; |
|
} |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
public function getOverdueActivities(Request $request) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$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); |
|
} |
|
//TODO possible overdue bug |
|
$endDate = Activity::where('proyek_id', $payload['id']) |
|
->orderByDesc('end_date') |
|
->value('end_date'); |
|
if (isset($payload['till_date'])) { |
|
if (isset($payload['scurve'])) { |
|
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get(); |
|
} else { |
|
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get(); |
|
} |
|
} else { |
|
if (isset($payload['scurve'])) { |
|
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); |
|
} else { |
|
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); |
|
} |
|
} |
|
$result->overdueActivities = $overdueActivities; |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
public function getReportDistribution(Request $request) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$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 = AssignMaterial::query() |
|
->from('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']]); |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
public function getManpower($proyek_id) |
|
{ |
|
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); |
|
return response()->json(['totalRecord' => $manCount]); |
|
} |
|
|
|
public function getAssignedHR($gantt_id) |
|
{ |
|
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') |
|
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') |
|
->where('assign_hr_to_activity.version_gantt_id', $gantt_id) |
|
->get(); |
|
return response()->json(['data' => $results]); |
|
} |
|
|
|
public function dashboard($id) |
|
{ |
|
DB::beginTransaction(); |
|
try { |
|
$data = Project::query() |
|
->from('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', |
|
'mp.budget_health' |
|
) |
|
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') |
|
->where('mp.id', $id) |
|
->first(); |
|
|
|
if (!$data) { |
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
} |
|
|
|
$manpowers = UserToProyek::where('proyek_id', $id)->count(); |
|
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderByDesc('version_gantt_id')->first(); |
|
|
|
$actualCost = @$rootActivity->biaya_actual ?? 0; |
|
$progress = @$rootActivity->persentase_progress ?? 0; |
|
|
|
$commentActivity = CommentActivity::query() |
|
->from('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(); |
|
|
|
$data->actual_cost = $actualCost; |
|
$data->progress = $progress; |
|
$data->comment = $commentActivity; |
|
$data->man_power = $manpowers; |
|
DB::commit(); |
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); |
|
} catch (\Throwable $th) { |
|
DB::rollBack(); |
|
} |
|
} |
|
|
|
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')); |
|
|
|
$info = curl_getinfo($ch); |
|
|
|
$output = curl_exec($ch); |
|
curl_close($ch); |
|
|
|
return json_decode($output); |
|
} |
|
}
|
|
|