yusuf
2 years ago
14 changed files with 632 additions and 811 deletions
Binary file not shown.
@ -1,292 +1,390 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Project; |
use App\Models\Project; |
||||||
use App\Models\UserToProyek; |
use App\Models\UserToProyek; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use App\Models\UserToActivity; |
use App\Models\UserToActivity; |
||||||
use App\Models\AssignMaterial; |
use App\Models\User; |
||||||
use App\Models\DokumenProject; |
use App\Models\AssignMaterial; |
||||||
use App\Models\FolderDocumentProyek; |
use App\Models\DokumenProject; |
||||||
use App\Models\ProjectCharter; |
use App\Models\FolderDocumentProyek; |
||||||
use App\Models\ProjectApproval; |
use App\Models\ProjectCharter; |
||||||
use App\Models\ProjectMileStone; |
use App\Models\ProjectApproval; |
||||||
use App\Models\ProjectParticipants; |
use App\Models\ProjectPhase; |
||||||
use App\Models\ShowHideColumn; |
use App\Models\ProjectType; |
||||||
use App\Models\VersionGantt; |
use App\Models\ProjectMileStone; |
||||||
use App\Models\Image; |
use App\Models\ProjectParticipants; |
||||||
use App\Models\CommentActivity; |
use App\Models\ShowHideColumn; |
||||||
use App\Models\Link; |
use App\Models\VersionGantt; |
||||||
use App\Models\ActivityDokumen; |
use App\Models\Image; |
||||||
use App\Models\Holiday; |
use App\Models\CommentActivity; |
||||||
use App\Models\ReportActivity; |
use App\Models\Link; |
||||||
use App\Models\OfficeHours; |
use App\Models\ActivityDokumen; |
||||||
use DB; |
use App\Models\Holiday; |
||||||
|
use App\Models\ReportActivity; |
||||||
class ProjectController extends Controller |
use App\Models\OfficeHours; |
||||||
{ |
use DB; |
||||||
|
|
||||||
public function add(Request $request) |
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; |
||||||
{ |
|
||||||
$this->validate($request, [ |
class ProjectController extends Controller |
||||||
'nama' => 'required', |
{ |
||||||
'mulai_proyek' => 'required', |
|
||||||
'akhir_proyek' => 'required', |
public function add(Request $request) |
||||||
'rencana_biaya' => 'required', |
{ |
||||||
'type_proyek_id' => 'required' |
$this->validate($request, [ |
||||||
]); |
'nama' => 'required', |
||||||
|
'mulai_proyek' => 'required', |
||||||
$data = $request->all(); |
'akhir_proyek' => 'required', |
||||||
|
'rencana_biaya' => 'required', |
||||||
$data['created_by'] = $this->currentName; |
'type_proyek_id' => 'required' |
||||||
|
]); |
||||||
$result = Project::create($data); |
|
||||||
|
$data = $request->all(); |
||||||
if(!$result) |
|
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$this->createOfficeHours($result->id); |
$result = Project::create($data); |
||||||
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); |
|
||||||
|
if(!$result) |
||||||
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); |
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); |
||||||
} |
|
||||||
|
$this->createOfficeHours($result->id); |
||||||
public function edit($id){ |
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); |
||||||
if(empty($id) || !is_int((int)$id)) |
|
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); |
||||||
|
} |
||||||
$result = Project::find($id); |
|
||||||
|
public function edit($id){ |
||||||
if(!$result) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); |
$result = Project::find($id); |
||||||
} |
|
||||||
|
if(!$result) |
||||||
public function update(Request $request, $id) |
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
||||||
{ |
|
||||||
if(empty($id) || !is_int((int)$id)) |
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
} |
||||||
|
|
||||||
$data = Project::find($id); |
public function update(Request $request, $id) |
||||||
|
{ |
||||||
if(!$data) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$result = $data->update($request->all()); |
$data = Project::find($id); |
||||||
|
|
||||||
if(!$result) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); |
$result = $data->update($request->all()); |
||||||
} |
|
||||||
|
if(!$result) |
||||||
private function createOfficeHours($proyek_id) |
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); |
||||||
{ |
|
||||||
$dataCreate = array( |
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); |
||||||
"proyek_id"=>$proyek_id, |
} |
||||||
"monday_start"=> "08:00:00", |
|
||||||
"monday_end"=> "16:00:00", |
private function createOfficeHours($proyek_id) |
||||||
"tuesday_start"=> "08:00:00", |
{ |
||||||
"tuesday_end"=> "16:00:00", |
$dataCreate = array( |
||||||
"wednesday_start"=> "08:00:00", |
"proyek_id"=>$proyek_id, |
||||||
"wednesday_end"=> "16:00:00", |
"monday_start"=> "08:00:00", |
||||||
"thursday_start"=> "08:00:00", |
"monday_end"=> "16:00:00", |
||||||
"thursday_end"=> "16:00:00", |
"tuesday_start"=> "08:00:00", |
||||||
"friday_start"=> "08:00:00", |
"tuesday_end"=> "16:00:00", |
||||||
"friday_end"=> "16:00:00", |
"wednesday_start"=> "08:00:00", |
||||||
"saturday_start"=> "08:00:00", |
"wednesday_end"=> "16:00:00", |
||||||
"saturday_end"=> "16:00:00", |
"thursday_start"=> "08:00:00", |
||||||
"sunday_start"=> "08:00:00", |
"thursday_end"=> "16:00:00", |
||||||
"sunday_end"=> "16:00:00", |
"friday_start"=> "08:00:00", |
||||||
"created_by"=> $this->currentName |
"friday_end"=> "16:00:00", |
||||||
); |
"saturday_start"=> "08:00:00", |
||||||
|
"saturday_end"=> "16:00:00", |
||||||
OfficeHours::create($dataCreate); |
"sunday_start"=> "08:00:00", |
||||||
|
"sunday_end"=> "16:00:00", |
||||||
return true; |
"created_by"=> $this->currentName |
||||||
} |
); |
||||||
|
|
||||||
public function delete($id) |
OfficeHours::create($dataCreate); |
||||||
{ |
|
||||||
$data = Project::find($id); |
return true; |
||||||
|
} |
||||||
if(!$data) |
|
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
public function delete($id) |
||||||
|
{ |
||||||
$this->deleteRelative($id); |
$data = Project::find($id); |
||||||
|
|
||||||
if(!$data->delete()) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
$this->deleteRelative($id); |
||||||
} |
|
||||||
|
if(!$data->delete()) |
||||||
private function deleteRelative($project_id) |
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); |
||||||
{ |
|
||||||
UserToProyek::where('proyek_id', $project_id)->delete(); |
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||||
UserToActivity::where('proyek_id', $project_id)->delete(); |
} |
||||||
AssignMaterial::where('proyek_id', $project_id)->delete(); |
|
||||||
ProjectCharter::where('proyek_id', $project_id)->delete(); |
private function deleteRelative($project_id) |
||||||
ProjectApproval::where('proyek_id', $project_id)->delete(); |
{ |
||||||
ProjectMileStone::where('proyek_id', $project_id)->delete(); |
UserToProyek::where('proyek_id', $project_id)->delete(); |
||||||
ProjectParticipants::where('proyek_id', $project_id)->delete(); |
UserToActivity::where('proyek_id', $project_id)->delete(); |
||||||
$this->deleteVersionGantt($project_id); |
AssignMaterial::where('proyek_id', $project_id)->delete(); |
||||||
$this->deleteDokumenProject($project_id); |
ProjectCharter::where('proyek_id', $project_id)->delete(); |
||||||
} |
ProjectApproval::where('proyek_id', $project_id)->delete(); |
||||||
|
ProjectMileStone::where('proyek_id', $project_id)->delete(); |
||||||
private function deleteVersionGantt($project_id) |
ProjectParticipants::where('proyek_id', $project_id)->delete(); |
||||||
{ |
$this->deleteVersionGantt($project_id); |
||||||
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); |
$this->deleteDokumenProject($project_id); |
||||||
$vhIds = $dataVg->all(); |
} |
||||||
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); |
|
||||||
$activityIds = $activity->all(); |
private function deleteVersionGantt($project_id) |
||||||
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); |
{ |
||||||
foreach ($dataRa as $ra) { |
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); |
||||||
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
$vhIds = $dataVg->all(); |
||||||
foreach ($images as $image) { |
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); |
||||||
if(file_exists($this->pathImage.$image->image)){ |
$activityIds = $activity->all(); |
||||||
unlink($this->pathImage.$image->image); |
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); |
||||||
} |
foreach ($dataRa as $ra) { |
||||||
} |
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
||||||
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
foreach ($images as $image) { |
||||||
} |
if(file_exists($this->pathImage.$image->image)){ |
||||||
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
unlink($this->pathImage.$image->image); |
||||||
foreach ($dataAd as $ad) { |
} |
||||||
if(file_exists($this->pathActivityDocument.$ad->file)){ |
} |
||||||
unlink($this->pathActivityDocument.$ad->file); |
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
||||||
} |
} |
||||||
} |
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
||||||
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
foreach ($dataAd as $ad) { |
||||||
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
if(file_exists($this->pathActivityDocument.$ad->file)){ |
||||||
Holiday::where("proyek_id", $project_id)->delete(); |
unlink($this->pathActivityDocument.$ad->file); |
||||||
VersionGantt::where("proyek_id", $project_id)->delete(); |
} |
||||||
Link::whereIn("version_gantt_id", $vhIds)->delete(); |
} |
||||||
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); |
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
||||||
Activity::whereIn("version_gantt_id", $vhIds)->delete(); |
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
||||||
ReportActivity::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(); |
||||||
private function deleteDokumenProject($project_id) |
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); |
||||||
{ |
Activity::whereIn("version_gantt_id", $vhIds)->delete(); |
||||||
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); |
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
||||||
|
} |
||||||
foreach ($dataDokumen as $dokumen) { |
|
||||||
if(file_exists($this->pathDocument.$dokumen->file)){ |
private function deleteDokumenProject($project_id) |
||||||
unlink($this->pathDocument.$dokumen->file); |
{ |
||||||
} |
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); |
||||||
} |
|
||||||
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
foreach ($dataDokumen as $dokumen) { |
||||||
|
if(file_exists($this->pathDocument.$dokumen->file)){ |
||||||
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
unlink($this->pathDocument.$dokumen->file); |
||||||
$ref_ids = $dataFolder->all(); |
} |
||||||
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
} |
||||||
foreach ($dataDokumen as $dokumen) { |
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
||||||
if(file_exists($this->pathDocument.$dokumen->file)){ |
|
||||||
unlink($this->pathDocument.$dokumen->file); |
$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) { |
||||||
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
if(file_exists($this->pathDocument.$dokumen->file)){ |
||||||
} |
unlink($this->pathDocument.$dokumen->file); |
||||||
|
} |
||||||
public function search(Request $request) |
} |
||||||
{ |
|
||||||
$payload = $request->all(); |
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
||||||
|
} |
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
|
||||||
$builder = $dataBuilder['builder']; |
public function search(Request $request) |
||||||
$countBuilder = $dataBuilder['count']; |
{ |
||||||
$dataGet = $builder->get(); |
$payload = $request->all(); |
||||||
$totalRecord = $countBuilder->count(); |
|
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
$builder = $dataBuilder['builder']; |
||||||
} |
$countBuilder = $dataBuilder['count']; |
||||||
|
$dataGet = $builder->get(); |
||||||
public function list() |
$totalRecord = $countBuilder->count(); |
||||||
{ |
|
||||||
$data = Project::orderBy('id', 'desc')->get(); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
$countData = $data->count(); |
} |
||||||
|
|
||||||
if(!$data) |
public function list() |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
{ |
||||||
|
$data = Project::orderBy('id', 'desc')->get(); |
||||||
$costWarningThreshold = 50000000; |
$countData = $data->count(); |
||||||
$costDangerThreshold = 25000000; |
|
||||||
$scheduleWarningThreshold = 10; |
if(!$data) |
||||||
$scheduleDangerThreshold = 5; |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
foreach($data as $d){ |
|
||||||
$progress = $costVariance = $actualCost = 0; |
$scheduleWarningThreshold = 10; |
||||||
$lastActivity = null; |
$scheduleDangerThreshold = 5; |
||||||
$scheduleHealth = "on-track"; |
foreach($data as $d){ |
||||||
$costHealth = "on-budget"; |
$progress = $costVariance = $actualCost = 0; |
||||||
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); |
$lastActivity = null; |
||||||
if($rootActivity){ |
$scheduleHealth = "on-track"; |
||||||
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; |
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); |
||||||
$actualCost = $rootActivity->biaya_actual ?? 0; |
if($rootActivity){ |
||||||
$progress = $rootActivity->persentase_progress ?? 0; |
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; |
||||||
/* |
$actualCost = $rootActivity->biaya_actual ?? 0; |
||||||
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); |
$progress = $rootActivity->persentase_progress ?? 0; |
||||||
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); |
|
||||||
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); |
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); |
||||||
$daysRemaining = $date2->diff($date1); |
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); |
||||||
$daysRemaining = $daysRemaining->d; |
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); |
||||||
|
$daysRemaining = $date2->diff($date1); |
||||||
if($daysRemaining <= $scheduleDangerThreshold) { |
$daysRemaining = $daysRemaining->d; |
||||||
$scheduleHealth = "danger"; |
|
||||||
} elseif ($daysRemaining <= $scheduleWarningThreshold) { |
if($daysRemaining <= $scheduleDangerThreshold) { |
||||||
$scheduleHealth = "warning"; |
$scheduleHealth = "danger"; |
||||||
} |
} elseif ($daysRemaining <= $scheduleWarningThreshold) { |
||||||
|
$scheduleHealth = "warning"; |
||||||
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); |
} |
||||||
*/ |
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); |
||||||
if($costVariance <= $costDangerThreshold) { |
} |
||||||
$costHealth = "danger"; |
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); |
||||||
} elseif ($costVariance <= $costWarningThreshold) { |
$d->plannedCost = $d->rencana_biaya; |
||||||
$costHealth = "warning"; |
$d->actualCost = $actualCost; |
||||||
} |
$d->lastActivity = $lastActivity ?? "-"; |
||||||
} |
$d->costVariance = $costVariance; |
||||||
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); |
$d->costHealth = $d->budget_health; |
||||||
$d->plannedCost = $d->rencana_biaya; |
$d->scheduleHealth = $scheduleHealth; |
||||||
$d->actualCost = $actualCost; |
$d->progress = $progress; |
||||||
//$d->lastActivity = $lastActivity ?? "-"; |
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; |
||||||
//$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; |
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; |
||||||
$d->costVariance = $costVariance; |
$d->projectManager = DB::table('m_proyek') |
||||||
$d->costHealth = $costHealth; |
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') |
||||||
//$d->scheduleHealth = $scheduleHealth; |
->where('m_proyek.id', $d->id) |
||||||
$d->progress = $progress . "%"; |
->pluck('m_users.name') |
||||||
} |
->first(); |
||||||
|
if($d->area_kerja != ''){ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
$d->geolocation = $this->httpReq($d->area_kerja); |
||||||
} |
} else { |
||||||
|
$d->geolocation = ''; |
||||||
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') |
$totalPlannedCost = $data->sum('plannedCost'); |
||||||
->groupBy("m_proyek.proyek_id") |
$totalActualCost = $data->sum('actualCost'); |
||||||
->get(); |
$manpowers = User::count(); |
||||||
|
$projectsOnDanger = Project::where('budget_health', 'danger')->count(); |
||||||
if(!$data) |
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); |
||||||
|
try { |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); |
$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') |
||||||
public function dashboard($id) |
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') |
||||||
{ |
->get(); |
||||||
$data = DB::table('m_proyek as mp') |
} catch (\Exception $e) { |
||||||
->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') |
return response()->json(['message' => $e->getMessage()]); |
||||||
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') |
} |
||||||
->where('mp.id', $id) |
try { |
||||||
->get(); |
$projectsByType = DB::table('m_proyek') |
||||||
$countData = $data->count(); |
->select('m_type_proyek.name', DB::raw('count(*) as total')) |
||||||
|
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') |
||||||
if(!$data) |
->groupBy('m_type_proyek.name') |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
->get(); |
||||||
|
} catch (\Exception $e) { |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
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); |
||||||
|
} |
||||||
|
|
||||||
|
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'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); |
||||||
|
} |
||||||
|
|
||||||
|
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', 'mp.budget_health') |
||||||
|
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') |
||||||
|
->where('mp.id', $id) |
||||||
|
->get(); |
||||||
|
$countData = $data->count(); |
||||||
|
|
||||||
|
$manpowers = UserToProyek::where('proyek_id', $id)->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['actual_cost'] = $actualCost; |
||||||
|
$dataRes['progress'] = $progress; |
||||||
|
$dataRes['comment'] = $commentActivity; |
||||||
|
$dataRes['man_power'] = $manpowers; |
||||||
|
} |
||||||
|
|
||||||
|
if(!$data) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, 'totalRecord'=>$countData], 200); |
||||||
|
} |
||||||
|
|
||||||
|
private function httpReq($search){ |
||||||
|
$ch = curl_init(); |
||||||
|
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); |
||||||
|
|
||||||
|
// SSL important |
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); |
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||||||
|
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||||||
|
|
||||||
|
$output = curl_exec($ch); |
||||||
|
curl_close($ch); |
||||||
|
|
||||||
|
return json_decode($output); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
@ -0,0 +1,84 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Controllers; |
||||||
|
|
||||||
|
use Illuminate\Http\Request; |
||||||
|
use App\Models\ProjectPhase; |
||||||
|
|
||||||
|
class ProjectPhaseController extends Controller |
||||||
|
{ |
||||||
|
public function add(Request $request) |
||||||
|
{ |
||||||
|
$this->validate($request, [ |
||||||
|
'name' => 'required' |
||||||
|
]); |
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
|
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
|
if(!ProjectPhase::create($data)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function edit($id){ |
||||||
|
if(!$id || (int) $id < 0 || $id=="") |
||||||
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$result = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function update(Request $request, $id) |
||||||
|
{ |
||||||
|
if(!$id || (int) $id < 0 || $id=="") |
||||||
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data->update($request->all())) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
|
||||||
|
if(!$data = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project phase not found!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data->delete()) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function search(Request $request) |
||||||
|
{ |
||||||
|
$payload = $request->all(); |
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); |
||||||
|
$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 = ProjectPhase::all(); |
||||||
|
$countData = $data->count(); |
||||||
|
|
||||||
|
if(!$data) |
||||||
|
return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -1,39 +1,39 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Middleware; |
namespace App\Http\Middleware; |
||||||
|
|
||||||
use Closure; |
use Closure; |
||||||
|
|
||||||
class CorsMiddleware |
class CorsMiddleware |
||||||
{ |
{ |
||||||
/** |
/** |
||||||
* Handle an incoming request. |
* Handle an incoming request. |
||||||
* |
* |
||||||
* @param \Illuminate\Http\Request $request |
* @param \Illuminate\Http\Request $request |
||||||
* @param \Closure $next |
* @param \Closure $next |
||||||
* @return mixed |
* @return mixed |
||||||
*/ |
*/ |
||||||
public function handle($request, Closure $next) |
public function handle($request, Closure $next) |
||||||
{ |
{ |
||||||
$headers = [ |
$headers = [ |
||||||
'Access-Control-Allow-Origin' => '*', |
'Access-Control-Allow-Origin' => '*', |
||||||
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', |
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', |
||||||
'Access-Control-Allow-Credentials' => 'true', |
'Access-Control-Allow-Credentials' => 'true', |
||||||
'Access-Control-Max-Age' => '86400', |
'Access-Control-Max-Age' => '86400', |
||||||
'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With, Application' |
'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With, Application' |
||||||
]; |
]; |
||||||
|
|
||||||
if ($request->isMethod('OPTIONS')) |
if ($request->isMethod('OPTIONS')) |
||||||
{ |
{ |
||||||
return response()->json('{"method":"OPTIONS"}', 200, $headers); |
return response()->json('{"method":"OPTIONS"}', 200, $headers); |
||||||
} |
} |
||||||
|
|
||||||
$response = $next($request); |
$response = $next($request); |
||||||
foreach($headers as $key => $value) |
foreach($headers as $key => $value) |
||||||
{ |
{ |
||||||
$response->headers->set($key, $value); |
$response->headers->set($key, $value); |
||||||
} |
} |
||||||
|
|
||||||
return $response; |
return $response; |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,17 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
|
class ProjectPhase extends Model |
||||||
|
{ |
||||||
|
protected $table = 'm_proyek_phase'; |
||||||
|
|
||||||
|
const CREATED_AT = 'created_at'; |
||||||
|
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
<?php |
||||||
|
return [ |
||||||
|
'precision' => 5, |
||||||
|
'cost_health_warning_threshold' => 20000000, |
||||||
|
'cost_health_danger_threshold' => 0, |
||||||
|
'schedule_health_warning_threshold' => 30, |
||||||
|
'schedule_health_danger_threshold' => 0, |
||||||
|
]; |
||||||
|
?> |
Loading…
Reference in new issue