Yusuf
2 years ago
5 changed files with 608 additions and 998 deletions
@ -1,361 +1,362 @@ |
|||||||
<?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\User; |
use App\Models\User; |
||||||
use App\Models\AssignMaterial; |
use App\Models\AssignMaterial; |
||||||
use App\Models\DokumenProject; |
use App\Models\DokumenProject; |
||||||
use App\Models\FolderDocumentProyek; |
use App\Models\FolderDocumentProyek; |
||||||
use App\Models\ProjectCharter; |
use App\Models\ProjectCharter; |
||||||
use App\Models\ProjectApproval; |
use App\Models\ProjectApproval; |
||||||
use App\Models\ProjectPhase; |
use App\Models\ProjectPhase; |
||||||
use App\Models\ProjectType; |
use App\Models\ProjectType; |
||||||
use App\Models\ProjectMileStone; |
use App\Models\ProjectMileStone; |
||||||
use App\Models\ProjectParticipants; |
use App\Models\ProjectParticipants; |
||||||
use App\Models\ShowHideColumn; |
use App\Models\ShowHideColumn; |
||||||
use App\Models\VersionGantt; |
use App\Models\VersionGantt; |
||||||
use App\Models\Image; |
use App\Models\Image; |
||||||
use App\Models\CommentActivity; |
use App\Models\CommentActivity; |
||||||
use App\Models\Link; |
use App\Models\Link; |
||||||
use App\Models\ActivityDokumen; |
use App\Models\ActivityDokumen; |
||||||
use App\Models\Holiday; |
use App\Models\Holiday; |
||||||
use App\Models\ReportActivity; |
use App\Models\ReportActivity; |
||||||
use App\Models\OfficeHours; |
use App\Models\OfficeHours; |
||||||
use DB; |
use DB; |
||||||
|
|
||||||
class ProjectController extends Controller |
class ProjectController extends Controller |
||||||
{ |
{ |
||||||
|
|
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'nama' => 'required', |
'nama' => 'required', |
||||||
'mulai_proyek' => 'required', |
'mulai_proyek' => 'required', |
||||||
'akhir_proyek' => 'required', |
'akhir_proyek' => 'required', |
||||||
'rencana_biaya' => 'required', |
'rencana_biaya' => 'required', |
||||||
'type_proyek_id' => 'required' |
'type_proyek_id' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
|
|
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = Project::create($data); |
$result = Project::create($data); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); |
||||||
|
|
||||||
$this->createOfficeHours($result->id); |
$this->createOfficeHours($result->id); |
||||||
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); |
$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); |
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
public function edit($id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$result = Project::find($id); |
$result = Project::find($id); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
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'=>$result], 200); |
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id) |
public function update(Request $request, $id) |
||||||
{ |
{ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$data = Project::find($id); |
$data = Project::find($id); |
||||||
|
|
||||||
if(!$data) |
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); |
||||||
|
|
||||||
$result = $data->update($request->all()); |
$result = $data->update($request->all()); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); |
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); |
||||||
} |
} |
||||||
|
|
||||||
private function createOfficeHours($proyek_id) |
private function createOfficeHours($proyek_id) |
||||||
{ |
{ |
||||||
$dataCreate = array( |
$dataCreate = array( |
||||||
"proyek_id"=>$proyek_id, |
"proyek_id"=>$proyek_id, |
||||||
"monday_start"=> "08:00:00", |
"monday_start"=> "08:00:00", |
||||||
"monday_end"=> "16:00:00", |
"monday_end"=> "16:00:00", |
||||||
"tuesday_start"=> "08:00:00", |
"tuesday_start"=> "08:00:00", |
||||||
"tuesday_end"=> "16:00:00", |
"tuesday_end"=> "16:00:00", |
||||||
"wednesday_start"=> "08:00:00", |
"wednesday_start"=> "08:00:00", |
||||||
"wednesday_end"=> "16:00:00", |
"wednesday_end"=> "16:00:00", |
||||||
"thursday_start"=> "08:00:00", |
"thursday_start"=> "08:00:00", |
||||||
"thursday_end"=> "16:00:00", |
"thursday_end"=> "16:00:00", |
||||||
"friday_start"=> "08:00:00", |
"friday_start"=> "08:00:00", |
||||||
"friday_end"=> "16:00:00", |
"friday_end"=> "16:00:00", |
||||||
"saturday_start"=> "08:00:00", |
"saturday_start"=> "08:00:00", |
||||||
"saturday_end"=> "16:00:00", |
"saturday_end"=> "16:00:00", |
||||||
"sunday_start"=> "08:00:00", |
"sunday_start"=> "08:00:00", |
||||||
"sunday_end"=> "16:00:00", |
"sunday_end"=> "16:00:00", |
||||||
"created_by"=> $this->currentName |
"created_by"=> $this->currentName |
||||||
); |
); |
||||||
|
|
||||||
OfficeHours::create($dataCreate); |
OfficeHours::create($dataCreate); |
||||||
|
|
||||||
return true; |
return true; |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
$data = Project::find($id); |
$data = Project::find($id); |
||||||
|
|
||||||
if(!$data) |
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); |
||||||
|
|
||||||
$this->deleteRelative($id); |
$this->deleteRelative($id); |
||||||
|
|
||||||
if(!$data->delete()) |
if(!$data->delete()) |
||||||
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
private function deleteRelative($project_id) |
private function deleteRelative($project_id) |
||||||
{ |
{ |
||||||
UserToProyek::where('proyek_id', $project_id)->delete(); |
UserToProyek::where('proyek_id', $project_id)->delete(); |
||||||
UserToActivity::where('proyek_id', $project_id)->delete(); |
UserToActivity::where('proyek_id', $project_id)->delete(); |
||||||
AssignMaterial::where('proyek_id', $project_id)->delete(); |
AssignMaterial::where('proyek_id', $project_id)->delete(); |
||||||
ProjectCharter::where('proyek_id', $project_id)->delete(); |
ProjectCharter::where('proyek_id', $project_id)->delete(); |
||||||
ProjectApproval::where('proyek_id', $project_id)->delete(); |
ProjectApproval::where('proyek_id', $project_id)->delete(); |
||||||
ProjectMileStone::where('proyek_id', $project_id)->delete(); |
ProjectMileStone::where('proyek_id', $project_id)->delete(); |
||||||
ProjectParticipants::where('proyek_id', $project_id)->delete(); |
ProjectParticipants::where('proyek_id', $project_id)->delete(); |
||||||
$this->deleteVersionGantt($project_id); |
$this->deleteVersionGantt($project_id); |
||||||
$this->deleteDokumenProject($project_id); |
$this->deleteDokumenProject($project_id); |
||||||
} |
} |
||||||
|
|
||||||
private function deleteVersionGantt($project_id) |
private function deleteVersionGantt($project_id) |
||||||
{ |
{ |
||||||
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); |
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); |
||||||
$vhIds = $dataVg->all(); |
$vhIds = $dataVg->all(); |
||||||
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); |
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); |
||||||
$activityIds = $activity->all(); |
$activityIds = $activity->all(); |
||||||
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); |
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); |
||||||
foreach ($dataRa as $ra) { |
foreach ($dataRa as $ra) { |
||||||
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
||||||
foreach ($images as $image) { |
foreach ($images as $image) { |
||||||
if(file_exists($this->pathImage.$image->image)){ |
if(file_exists($this->pathImage.$image->image)){ |
||||||
unlink($this->pathImage.$image->image); |
unlink($this->pathImage.$image->image); |
||||||
} |
} |
||||||
} |
} |
||||||
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
||||||
} |
} |
||||||
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
||||||
foreach ($dataAd as $ad) { |
foreach ($dataAd as $ad) { |
||||||
if(file_exists($this->pathActivityDocument.$ad->file)){ |
if(file_exists($this->pathActivityDocument.$ad->file)){ |
||||||
unlink($this->pathActivityDocument.$ad->file); |
unlink($this->pathActivityDocument.$ad->file); |
||||||
} |
} |
||||||
} |
} |
||||||
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
||||||
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
||||||
Holiday::where("proyek_id", $project_id)->delete(); |
Holiday::where("proyek_id", $project_id)->delete(); |
||||||
VersionGantt::where("proyek_id", $project_id)->delete(); |
VersionGantt::where("proyek_id", $project_id)->delete(); |
||||||
Link::whereIn("version_gantt_id", $vhIds)->delete(); |
Link::whereIn("version_gantt_id", $vhIds)->delete(); |
||||||
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); |
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); |
||||||
Activity::whereIn("version_gantt_id", $vhIds)->delete(); |
Activity::whereIn("version_gantt_id", $vhIds)->delete(); |
||||||
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
||||||
} |
} |
||||||
|
|
||||||
private function deleteDokumenProject($project_id) |
private function deleteDokumenProject($project_id) |
||||||
{ |
{ |
||||||
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); |
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); |
||||||
|
|
||||||
foreach ($dataDokumen as $dokumen) { |
foreach ($dataDokumen as $dokumen) { |
||||||
if(file_exists($this->pathDocument.$dokumen->file)){ |
if(file_exists($this->pathDocument.$dokumen->file)){ |
||||||
unlink($this->pathDocument.$dokumen->file); |
unlink($this->pathDocument.$dokumen->file); |
||||||
} |
} |
||||||
} |
} |
||||||
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
||||||
|
|
||||||
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
||||||
$ref_ids = $dataFolder->all(); |
$ref_ids = $dataFolder->all(); |
||||||
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
||||||
foreach ($dataDokumen as $dokumen) { |
foreach ($dataDokumen as $dokumen) { |
||||||
if(file_exists($this->pathDocument.$dokumen->file)){ |
if(file_exists($this->pathDocument.$dokumen->file)){ |
||||||
unlink($this->pathDocument.$dokumen->file); |
unlink($this->pathDocument.$dokumen->file); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); |
||||||
} |
} |
||||||
|
|
||||||
public function search(Request $request) |
public function search(Request $request) |
||||||
{ |
{ |
||||||
$payload = $request->all(); |
$payload = $request->all(); |
||||||
|
|
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); |
||||||
$builder = $dataBuilder['builder']; |
$builder = $dataBuilder['builder']; |
||||||
$countBuilder = $dataBuilder['count']; |
$countBuilder = $dataBuilder['count']; |
||||||
$dataGet = $builder->get(); |
$dataGet = $builder->get(); |
||||||
$totalRecord = $countBuilder->count(); |
$totalRecord = $countBuilder->count(); |
||||||
|
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function list() |
public function list() |
||||||
{ |
{ |
||||||
$data = Project::orderBy('id', 'desc')->get(); |
$data = Project::orderBy('id', 'desc')->get(); |
||||||
$countData = $data->count(); |
$countData = $data->count(); |
||||||
|
|
||||||
if(!$data) |
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); |
||||||
|
|
||||||
$scheduleWarningThreshold = 10; |
$scheduleWarningThreshold = 10; |
||||||
$scheduleDangerThreshold = 5; |
$scheduleDangerThreshold = 5; |
||||||
foreach($data as $d){ |
foreach($data as $d){ |
||||||
$progress = $costVariance = $actualCost = 0; |
$progress = $costVariance = $actualCost = 0; |
||||||
$lastActivity = null; |
$lastActivity = null; |
||||||
$scheduleHealth = "on-track"; |
$scheduleHealth = "on-track"; |
||||||
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); |
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); |
||||||
if($rootActivity){ |
if($rootActivity){ |
||||||
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; |
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; |
||||||
$actualCost = $rootActivity->biaya_actual ?? 0; |
$actualCost = $rootActivity->biaya_actual ?? 0; |
||||||
$progress = $rootActivity->persentase_progress ?? 0; |
$progress = $rootActivity->persentase_progress ?? 0; |
||||||
|
|
||||||
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); |
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); |
||||||
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); |
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); |
||||||
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); |
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); |
||||||
$daysRemaining = $date2->diff($date1); |
$daysRemaining = $date2->diff($date1); |
||||||
$daysRemaining = $daysRemaining->d; |
$daysRemaining = $daysRemaining->d; |
||||||
|
|
||||||
if($daysRemaining <= $scheduleDangerThreshold) { |
if($daysRemaining <= $scheduleDangerThreshold) { |
||||||
$scheduleHealth = "danger"; |
$scheduleHealth = "danger"; |
||||||
} elseif ($daysRemaining <= $scheduleWarningThreshold) { |
} elseif ($daysRemaining <= $scheduleWarningThreshold) { |
||||||
$scheduleHealth = "warning"; |
$scheduleHealth = "warning"; |
||||||
} |
} |
||||||
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); |
|
||||||
} |
$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->lastActivity = $lastActivity ?? "-"; |
||||||
$d->plannedCost = $d->rencana_biaya; |
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); |
||||||
$d->actualCost = $actualCost; |
$d->scheduleHealth = $scheduleHealth; |
||||||
$d->lastActivity = $lastActivity ?? "-"; |
|
||||||
//$d->lastActivity = $daysRemaining . " -- " . $lastActivity . "\n" . $date1 . "\n" . $date2; |
$d->plannedCost = $d->rencana_biaya; |
||||||
$d->costVariance = $costVariance; |
$d->actualCost = $actualCost; |
||||||
$d->costHealth = $d->budget_health; |
$d->costVariance = $costVariance; |
||||||
$d->scheduleHealth = $scheduleHealth; |
$d->costHealth = $d->budget_health; |
||||||
$d->progress = $progress; |
|
||||||
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; |
$d->progress = $progress; |
||||||
} |
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; |
||||||
|
} |
||||||
$totalPlannedCost = $data->sum('plannedCost'); |
} |
||||||
$totalActualCost = $data->sum('actualCost'); |
|
||||||
// $manpowers = User::where('employee_type', 'employee')->count(); |
$totalPlannedCost = $data->sum('plannedCost'); |
||||||
$manpowers = User::count(); |
$totalActualCost = $data->sum('actualCost'); |
||||||
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); |
$manpowers = User::count(); |
||||||
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); |
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); |
||||||
try { |
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); |
||||||
$projectsByPhase = DB::table('m_proyek') |
try { |
||||||
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) |
$projectsByPhase = DB::table('m_proyek') |
||||||
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') |
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) |
||||||
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') |
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') |
||||||
->get(); |
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') |
||||||
} catch (\Exception $e) { |
->get(); |
||||||
return response()->json(['message' => $e->getMessage()]); |
} catch (\Exception $e) { |
||||||
} |
return response()->json(['message' => $e->getMessage()]); |
||||||
try { |
} |
||||||
$projectsByType = DB::table('m_proyek') |
try { |
||||||
->select('m_type_proyek.name', DB::raw('count(*) as total')) |
$projectsByType = DB::table('m_proyek') |
||||||
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') |
->select('m_type_proyek.name', DB::raw('count(*) as total')) |
||||||
->groupBy('m_type_proyek.name') |
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') |
||||||
->get(); |
->groupBy('m_type_proyek.name') |
||||||
} catch (\Exception $e) { |
->get(); |
||||||
return response()->json(['message' => $e->getMessage()]); |
} catch (\Exception $e) { |
||||||
} |
return response()->json(['message' => $e->getMessage()]); |
||||||
|
} |
||||||
return response()->json( |
|
||||||
[ |
return response()->json( |
||||||
'status'=>'success', |
[ |
||||||
'code'=>200, |
'status'=>'success', |
||||||
'data'=>$data, |
'code'=>200, |
||||||
'totalRecord'=>$countData, |
'data'=>$data, |
||||||
'totalPlannedCost' => $totalPlannedCost, |
'totalRecord'=>$countData, |
||||||
'totalActualCost' => $totalActualCost, |
'totalPlannedCost' => $totalPlannedCost, |
||||||
'totalRevenue' => $totalPlannedCost - $totalActualCost, |
'totalActualCost' => $totalActualCost, |
||||||
'manpowers' => $manpowers, |
'totalRevenue' => $totalPlannedCost - $totalActualCost, |
||||||
'projectPhases' => $projectPhases, |
'manpowers' => $manpowers, |
||||||
'projectsByPhase' => $projectsByPhase, |
'projectPhases' => $projectPhases, |
||||||
'projectTypes' => $projectTypes, |
'projectsByPhase' => $projectsByPhase, |
||||||
'projectsByType' => $projectsByType, |
'projectTypes' => $projectTypes, |
||||||
], 200); |
'projectsByType' => $projectsByType, |
||||||
} |
], 200); |
||||||
|
} |
||||||
public function getListProjectTask($id){ |
|
||||||
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") |
public function getListProjectTask($id){ |
||||||
->where("assign_hr_to_activity.user_id", $id) |
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") |
||||||
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') |
->where("assign_hr_to_activity.user_id", $id) |
||||||
->groupBy("m_proyek.proyek_id") |
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') |
||||||
->get(); |
->groupBy("m_proyek.proyek_id") |
||||||
|
->get(); |
||||||
if(!$data) |
|
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
if(!$data) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); |
|
||||||
} |
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); |
||||||
|
} |
||||||
public function dashboard($id) |
|
||||||
{ |
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', |
$data = DB::table('m_proyek as mp') |
||||||
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') |
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', |
||||||
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') |
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') |
||||||
->where('mp.id', $id) |
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') |
||||||
->get(); |
->where('mp.id', $id) |
||||||
$countData = $data->count(); |
->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(); |
$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; |
if($rootActivity){ |
||||||
$progress = $rootActivity->persentase_progress ?? 0; |
$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', |
$commentActivity = DB::table('m_comment_activity as mca') |
||||||
'ma.name as activity') |
->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', |
||||||
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') |
'ma.name as activity') |
||||||
->where('ma.proyek_id', $id) |
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') |
||||||
->orderBy('comment_by') |
->where('ma.proyek_id', $id) |
||||||
->take(2) |
->orderBy('comment_by') |
||||||
->get(); |
->take(2) |
||||||
|
->get(); |
||||||
foreach ($data as $val) { |
|
||||||
$dataRes['kode_sortname'] = $val->kode_sortname; |
foreach ($data as $val) { |
||||||
$dataRes['name_project'] = $val->name_project; |
$dataRes['kode_sortname'] = $val->kode_sortname; |
||||||
$dataRes['start'] = $val->start; |
$dataRes['name_project'] = $val->name_project; |
||||||
$dataRes['finish'] = $val->finish; |
$dataRes['start'] = $val->start; |
||||||
$dataRes['rencana_biaya'] = $val->rencana_biaya; |
$dataRes['finish'] = $val->finish; |
||||||
$dataRes['company'] = $val->company; |
$dataRes['rencana_biaya'] = $val->rencana_biaya; |
||||||
$dataRes['currency_symbol'] = $val->currency_symbol; |
$dataRes['company'] = $val->company; |
||||||
// get firstname |
$dataRes['currency_symbol'] = $val->currency_symbol; |
||||||
$arr = explode(" ", $val->pm); |
// get firstname |
||||||
$dataRes['pm'] = $arr[0]; |
$arr = explode(" ", $val->pm); |
||||||
$dataRes['budget_health'] = $val->budget_health; |
$dataRes['pm'] = $arr[0]; |
||||||
$dataRes['actual_cost'] = $actualCost; |
$dataRes['budget_health'] = $val->budget_health; |
||||||
$dataRes['progress'] = $progress; |
$dataRes['actual_cost'] = $actualCost; |
||||||
$dataRes['comment'] = $commentActivity; |
$dataRes['progress'] = $progress; |
||||||
$dataRes['man_power'] = $manpowers; |
$dataRes['comment'] = $commentActivity; |
||||||
} |
$dataRes['man_power'] = $manpowers; |
||||||
|
} |
||||||
if(!$data) |
|
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
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); |
|
||||||
} |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataRes, '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; |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue