Browse Source

clean controllers

pull/3/head
Muhammad Sulaiman Yusuf 3 years ago
parent
commit
00b8602cab
  1. 174
      app/Http/Controllers/ActivityDokumenController.php
  2. 27
      app/Http/Controllers/AuthController.php
  3. 455
      app/Http/Controllers/DashboardController.php
  4. 155
      app/Http/Controllers/DivisiController.php
  5. 415
      app/Http/Controllers/ProjectController.php
  6. 179
      app/Http/Controllers/ProjectDokumenController.php
  7. 191
      app/Http/Controllers/RoleController.php

174
app/Http/Controllers/ActivityDokumenController.php

@ -7,93 +7,89 @@ use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller class ActivityDokumenController extends Controller
{ {
public function dokumenByActivityId($id){
if($id && $id!="" && (int)$id > 0){ public function dokumenByActivityId($id){
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}else{ $dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
} }
}
public function delete($id)
public function delete($id) {
{ if(empty($id) || !is_int((int)$id))
if($id && $id!="" && (int)$id > 0){ return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$dokumen = ActivityDokumen::find($id);
if($dokumen){ $document = ActivityDokumen::find($id);
if(file_exists($this->pathActivityDocument.$dokumen->file)){
unlink($this->pathActivityDocument.$dokumen->file); if(!$document)
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$dokumen->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); if(file_exists($this->pathActivityDocument.$document->file))
}else{ unlink($this->pathActivityDocument.$document->file);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} $document->delete();
}else{ return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); }
}
} public function uploadProjectDokumen(Request $request)
{
public function uploadProjectDokumen(Request $request) if(!$request->hasFile('dokumen'))
{ return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
if($request->hasFile('dokumen')){
$activity_id = $request->activity_id; $activity_id = $request->activity_id;
$dokumen = $request->file('dokumen'); $document = $request->file('dokumen');
$extension = $dokumen->extension(); $name = $document->getClientOriginalName();
$name = $dokumen->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name);
$result = $dokumen->move($this->pathActivityDocument, $name);
if($result){ if(!$result)
$data = [ return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
'activity_id' => (int)$activity_id,
'file' => $name, $data = [
'description' => $request->description 'activity_id' => (int)$activity_id,
]; 'file' => $name,
'description' => $request->description
$result = ActivityDokumen::create($data); ];
if($result){ $result = ActivityDokumen::create($data);
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
}else{ if(!$result){
unlink($this->pathActivityDocument.$name); unlink($this->pathActivityDocument.$name);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
} }
}else{ return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); }
}
}else{ public function searchDocProject(Request $request){
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); $payload = $request->all();
}
} $dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
$builder = $dataBuilder['builder'];
public function searchDocProject(Request $request){ $countBuilder = $dataBuilder['count'];
$payload = $request->all(); $dataGet = $builder->get();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); $totalRecord = $countBuilder->count();
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); public function downloadDokumen($id)
} {
if(empty($id) || !is_int((int)$id))
public function downloadDokumen($id) return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
{
if($id && $id!="" && (int)$id > 0){ $document = ActivityDokumen::find($id);
$dokumen = ActivityDokumen::find($id);
if($dokumen){ if(!$document)
if(file_exists($this->pathActivityDocument.$dokumen->file)){ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
$pathToFile = $this->pathActivityDocument.$dokumen->file;
return response()->download($pathToFile); if(file_exists($this->pathActivityDocument.$document->file)){
}else{ $pathToFile = $this->pathActivityDocument.$document->file;
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->download($pathToFile);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
}
}
} }

27
app/Http/Controllers/AuthController.php

@ -7,21 +7,14 @@ use Illuminate\Http\Request;
use App\Models\User; use App\Models\User;
use App\Models\Role; use App\Models\Role;
use App\Models\Project;
use App\Models\UserProject;
class AuthController extends Controller class AuthController extends Controller
{ {
/**
* Create a new AuthController instance.
*
* @return void
*/
public function __construct() public function __construct()
{ {
$this->middleware('auth:api', ['except' => ['login']]); $this->middleware('auth:api', ['except' => ['login']]);
} }
public function login(Request $request) public function login(Request $request)
{ {
$username = $request->username; $username = $request->username;
@ -32,13 +25,7 @@ class AuthController extends Controller
return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400);
} }
$credentials = array( $user = User::where('username', $username)->where('password', md5($password))->first();
"username"=> $username,
"password"=> md5($password)
);
$user = User::where('username', $username)->where('password', md5($password))
->first();
if($is_mobile){ if($is_mobile){
$fcm_token = $request->fcm_token; $fcm_token = $request->fcm_token;
@ -55,7 +42,7 @@ class AuthController extends Controller
$hr = User::find($user->id); $hr = User::find($user->id);
if($hr){ if($hr){
$result = $hr->update($dataUpdateFcm); $hr->update($dataUpdateFcm);
} }
} }
@ -65,7 +52,7 @@ class AuthController extends Controller
$user->role = $dataRole; $user->role = $dataRole;
} }
if (! $token =Auth::login($user)) { if (! $token =Auth::login($user)) {
return response()->json(['error' => 'Unauthorized'], 401); return response()->json(['error' => 'Unauthorized'], 401);
} }
@ -76,12 +63,12 @@ class AuthController extends Controller
protected function respondWithToken($token, $user) protected function respondWithToken($token, $user)
{ {
return response()->json([ return response()->json([
'code' => 200, 'code' => 200,
'data' => array( 'data' => array(
'data_user' => $user, 'data_user' => $user,
'access_token' => $token, 'access_token' => $token,
'token_type' => 'bearer', 'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60 'expires_in' => auth()->factory()->getTTL() * 360
), ),
]); ]);
} }

455
app/Http/Controllers/DashboardController.php

@ -6,247 +6,220 @@ use Illuminate\Http\Request;
use App\Models\Project; use App\Models\Project;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportActivity; use App\Models\ReportActivity;
use App\Models\UserToActivity; use App\Models\Role;
use DB;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function costPlanningActual(Request $request) public function costPlanningActual(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$dataMaxVersionGantt = []; $dataMaxVersionGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($dataMaxVersionGantt as $val) { foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
} }
if($dataPayload){ if(!$dataFinal)
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
} }
}
public function getMaxVersionGantt($id){
public function getMaxVersionGantt($id){ $data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first();
$data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first(); return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name);
return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name); }
}
public function percentagePlanningActual(Request $request)
public function percentagePlanningActual(Request $request) {
{ $dataPayload = $request->all();
$dataPayload = $request->all(); $dataMaxVersionGantt = [];
$dataMaxVersionGantt = []; foreach ($dataPayload['project_id'] as $val) {
foreach ($dataPayload['project_id'] as $val) { $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); }
} $dataFinal=[];
$dataFinal=[]; foreach ($dataMaxVersionGantt as $val) {
foreach ($dataMaxVersionGantt as $val) { $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); }
} if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
if($dataPayload){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
} public function list()
} {
$data = Role::all();
public function list() $countData = $data->count();
{
$data = Role::all(); if(!$data)
$countData = $data->count(); return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
if($data){ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); public function getActivityByProjectId($projectId) {
} $output = [];
} $data = Activity::select('id')->where('proyek_id', $projectId)->get();
foreach ($data as $actData) {
$output[] = $actData->id;
}
return $output;
}
public function getActivityByProjectId($projectId) { /*
$output = []; const statusProyek = [
$data = Activity::select('id')->where('proyek_id', $projectId)->get(); {
if (count($data) > 0) { "id": "1",
foreach ($data as $actData) { "proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek
$output[] = $actData->id; "total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih
} "task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih
} "day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini)
return $output; "percentage": 75 // (task_on_progress / total_task * 100)
} },
{
/* for statusProyek, I want something output like this "id": "2",
const statusProyek = [ "proyek_name": "Pembangunan Jembatan Layang",
{ "total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11);
"id": "1", "task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355);
"proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek "day_left": 0,
"total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih "percentage": 100
"task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih },
"day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini) ...
"percentage": 75 // (task_on_progress / total_task * 100) ]
}, */
{ public function statusProyek(Request $request) {
"id": "2", $dataPayload = $request->all();
"proyek_name": "Pembangunan Jembatan Layang", $reqProject = $dataFinal = [];
"total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11);
"task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355); if (!isset($dataPayload['project_id']))
"day_left": 0, return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
"percentage": 100
}, foreach ($dataPayload['project_id'] as $val) {
... $prj["project_id"] = $val;
] $prj["activity_id"] = $this->getActivityByProjectId($val);
*/ $reqProject[] = $prj;
public function statusProyek(Request $request) { }
$dataPayload = $request->all();
$reqProject = []; if (count($reqProject) > 0) {
$dataFinal = []; $row = [];
if (!isset($dataPayload['project_id'])) { for ($i=0; $i < count($reqProject); $i++) {
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400); $dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first();
} $last_version_gantt = $dataMaxVersionGantt->last_version_gantt;
$queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first();
foreach ($dataPayload['project_id'] as $val) { $sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$prj["project_id"] = $val; $count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$prj["activity_id"] = $this->getActivityByProjectId($val); $count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$reqProject[] = $prj; $progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
} $current_progress = 0;
if (count($reqProject) > 0) { foreach($progress_actual as $objRow) {
$row = []; $current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
for ($i=0; $i < count($reqProject); $i++) { if (count($reqProject[$i]['activity_id']) > 0) {
$dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first(); for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) {
$last_version_gantt = $dataMaxVersionGantt->last_version_gantt; $sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
$queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first(); }
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan"); }
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id"); if (!isset($queryProject->id))
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id"); return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
$progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->sum("persentase_progress");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress"); $now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get(); $datediff = $akhir_proyek - $now;
$current_progress = 0;
foreach($progress_actual as $objRow) { $mulai_proyek = strtotime($queryProject->mulai_proyek);
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100; $total_kontrak = $akhir_proyek - $mulai_proyek;
}
$row["id"] = $queryProject->id;
if (count($reqProject[$i]['activity_id']) > 0) { $row["proyek_name"] = $queryProject->nama;
for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) { $row["mulai_proyek"] = $queryProject->mulai_proyek;
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report"); $row["akhir_proyek"] = $queryProject->akhir_proyek;
} $row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24));
} $row["total_task"] = $sum_jumlah_pekerjaan;
$row["task_on_progress"] = $sum_job_count_report;
if (!isset($queryProject->id)) { $row["count_activity"] = $count_activity;
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400); $row["count_activity_done"] = $count_activity_done;
} $row["day_left"] = round($datediff / (60 * 60 * 24));
$row["percentage"] = round($current_progress,3);
$now = time(); $row["count_progress_percentage"] = $count_progress_percentage;
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$datediff = $akhir_proyek - $now; $dataFinal[] = $row;
}
$mulai_proyek = strtotime($queryProject->mulai_proyek); }
$total_kontrak = $akhir_proyek - $mulai_proyek;
if(empty($dataFinal))
$row["id"] = $queryProject->id; return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
$row["proyek_name"] = $queryProject->nama;
$row["mulai_proyek"] = $queryProject->mulai_proyek; return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
$row["akhir_proyek"] = $queryProject->akhir_proyek; }
$row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24));
$row["total_task"] = $sum_jumlah_pekerjaan; public function curvaS(Request $request)
$row["task_on_progress"] = $sum_job_count_report; {
$row["count_activity"] = $count_activity; $dataPayload = $request->all();
$row["count_activity_done"] = $count_activity_done; $dataMaxVersionGantt = [];
$row["day_left"] = round($datediff / (60 * 60 * 24)); $dataFinal=[];
$row["percentage"] = round($current_progress,3);
$row["count_progress_percentage"] = $count_progress_percentage; foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
$dataFinal[] = $row; }
}
} foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
if($dataFinal){ $totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}else{ for ($i=0; $i < count($data); $i++) {
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400); $tmpp = $tmpa = $tmpbc = $tmpac = 0;
} for ($x=$i; $x >= 0 ; $x--) {
$tmpp += $data[$x]['bobot_planning'];
} $tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
$tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100;
public function curvaS(Request $request) $tmpac += $data[$x]['biaya_actual'];
{ }
$dataPayload = $request->all();
$dataMaxVersionGantt = []; $data[$i]['cal_bobot_p'] = round($tmpp,2);
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); if($i > 0 ){
} if($data[$i-1]['cal_bobot_a'] != null){
$dataFinal=[]; if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
foreach ($dataMaxVersionGantt as $val) { $data[$i]['cal_bobot_a'] = null;
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); }else{
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya'); $data[$i]['cal_bobot_a'] = round($tmpa,2);
$dataBobotPlan =[]; }
for ($i=0; $i < count($data); $i++) { }else{
$tmpp = 0; $data[$i]['cal_bobot_a'] = null;
$tmpa = 0; }
$tmpbc = 0; if($data[$i-1]['cal_actual_cost'] != null){
$tmpac = 0; if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
for ($x=$i; $x >= 0 ; $x--) { $data[$i]['cal_actual_cost'] = null;
$tmpp += $data[$x]['bobot_planning']; }else{
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100; $data[$i]['cal_actual_cost'] = round($tmpac,2);
$tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100; }
$tmpac += $data[$x]['biaya_actual']; }else{
} $data[$i]['cal_actual_cost'] = null;
}
$data[$i]['cal_bobot_p'] = round($tmpp,2); }else{
if($i > 0 ){ $data[$i]['cal_bobot_a'] = round($tmpa,2);
if($data[$i-1]['cal_bobot_a'] != null){ $data[$i]['cal_actual_cost'] = round($tmpac,2);
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){ }
$data[$i]['cal_bobot_a'] = null; $data[$i]['cal_budget_cost'] = round($tmpbc,2);
}else{ }
$data[$i]['cal_bobot_a'] = round($tmpa,2);
} $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}else{ }
$data[$i]['cal_bobot_a'] = null;
} if(!$dataFinal)
}else{ return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
$data[$i]['cal_bobot_a'] = round($tmpa,2);
} return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
$data[$i]['cal_budget_cost'] = round($tmpbc,2); }
}
if($i > 0 ){
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
$data[$i]['cal_actual_cost'] = null;
}else{
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}else{
$data[$i]['cal_actual_cost'] = null;
}
}else{
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if($dataPayload){
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
}

155
app/Http/Controllers/DivisiController.php

@ -6,82 +6,81 @@ use Illuminate\Http\Request;
use App\Models\Divisi; use App\Models\Divisi;
class DivisiController extends Controller class DivisiController extends Controller
{ {
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'required',
'description' => 'required' 'description' => 'required'
]); ]);
$data = $request->all();
$data['created_by'] = $this->currentName; $data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if($result){ $result = Divisi::create($data);
return response()->json(['status'=>'success','message'=>'Master divisi successfull created','code'=>200]);
}else{ if(!$result)
return response()->json(['status'=>'failed','message'=>'Master divisi failed created','code'=>400]); return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
}
} return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]);
}
public function update(Request $request, $id){
public function update(Request $request, $id){
if(!$id || (int) $id < 0 || $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 = Divisi::find($id); $data = Divisi::find($id);
if($data){
$result = $data->update($request->all()); if(!$data)
}else{ return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Data Master divisi not found!','code'=>400], 400);
die(); $result = $data->update($request->all());
}
if(!$result)
if($result){ return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Master divisi successfully updated!','code'=>200], 200);
}else{ return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'Master divisi failed updated!','code'=>400], 400); }
}
} public function delete($id)
{
public function delete($id) if(empty($id) || !is_int((int)$id))
{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
$data = Divisi::find($id);
if($data){
$delete = $data->delete(); if(!$data)
}else{ return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'data Master divisi not found!','code'=>400], 400);
die(); $delete = $data->delete();
}
if(!$delete)
if($delete){ return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Master divisi successfully deleted!','code'=>200], 200);
}else{ return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Master divisi failed deleted!','code'=>400], 400); }
}
} public function search(Request $request)
{
public function search(Request $request) $payload = $request->all();
{
$payload = $request->all(); $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); $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 = Divisi::all(); $data = Divisi::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if(!$data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
} }
}
} }

415
app/Http/Controllers/ProjectController.php

@ -14,12 +14,8 @@ use App\Models\ProjectCharter;
use App\Models\ProjectApproval; use App\Models\ProjectApproval;
use App\Models\ProjectMileStone; use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants; use App\Models\ProjectParticipants;
use App\Models\UserToVersionGantt;
use App\Models\RequestMaterial;
use App\Models\ShowHideColumn; use App\Models\ShowHideColumn;
use App\Models\ToolsProject;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\MaterialProject;
use App\Models\Image; use App\Models\Image;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
@ -30,214 +26,205 @@ use App\Models\OfficeHours;
class ProjectController extends Controller class ProjectController extends Controller
{ {
public function add(Request $request)
{ public function add(Request $request)
$this->validate($request, [ {
'nama' => 'required', $this->validate($request, [
'mulai_proyek' => 'required', 'nama' => 'required',
'akhir_proyek' => 'required', 'mulai_proyek' => 'required',
'rencana_biaya' => 'required', 'akhir_proyek' => 'required',
'type_proyek_id' => 'required' 'rencana_biaya' => '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){
$this->createOfficeHours($result->id); if(!$result)
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'add data project successfully!', 'data_result' =>$dataResultInsert, 'code'=>200], 200);
}else{ $this->createOfficeHours($result->id);
return response()->json(['status'=>'failed','message'=>'add data project failed!','code'=>400], 400); $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
}
} return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ public function edit($id){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if(empty($id) || !is_int((int)$id))
die(); 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'=>'success','code'=>200,'data'=>$result], 200);
}else{ return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400); }
}
} public function update(Request $request, $id)
{
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);
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); $data = Project::find($id);
}
if(!$data)
$data = Project::find($id); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if($data){ $result = $data->update($request->all());
$result = $data->update($request->all());
}else{ if(!$result)
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
die();
} return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
}
if($result){ private function createOfficeHours($proyek_id)
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200); {
}else{ $dataCreate = array(
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400); "proyek_id"=>$proyek_id,
} "monday_start"=> "08:00:00",
} "monday_end"=> "16:00:00",
"tuesday_start"=> "08:00:00",
private function createOfficeHours($proyek_id) "tuesday_end"=> "16:00:00",
{ "wednesday_start"=> "08:00:00",
$dataCreate = array( "wednesday_end"=> "16:00:00",
"proyek_id"=>$proyek_id, "thursday_start"=> "08:00:00",
"monday_start"=> "08:00:00", "thursday_end"=> "16:00:00",
"monday_end"=> "16:00:00", "friday_start"=> "08:00:00",
"tuesday_start"=> "08:00:00", "friday_end"=> "16:00:00",
"tuesday_end"=> "16:00:00", "saturday_start"=> "08:00:00",
"wednesday_start"=> "08:00:00", "saturday_end"=> "16:00:00",
"wednesday_end"=> "16:00:00", "sunday_start"=> "08:00:00",
"thursday_start"=> "08:00:00", "sunday_end"=> "16:00:00",
"thursday_end"=> "16:00:00", "created_by"=> $this->currentName
"friday_start"=> "08:00:00", );
"friday_end"=> "16:00:00",
"saturday_start"=> "08:00:00", OfficeHours::create($dataCreate);
"saturday_end"=> "16:00:00",
"sunday_start"=> "08:00:00", return true;
"sunday_end"=> "16:00:00", }
"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())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
if($data){
$this->deleteRelative($id); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
$delete = $data->delete(); }
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); private function deleteRelative($project_id)
die(); {
} UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete();
if($delete){ ProjectCharter::where('proyek_id', $project_id)->delete();
return response()->json(['status'=>'success','message'=>'data project successfully deleted!','code'=>200], 200); ProjectApproval::where('proyek_id', $project_id)->delete();
}else{ ProjectMileStone::where('proyek_id', $project_id)->delete();
return response()->json(['status'=>'failed','message'=>'data project failed deleted!','code'=>400], 400); ProjectParticipants::where('proyek_id', $project_id)->delete();
} $this->deleteVersionGantt($project_id);
} $this->deleteDokumenProject($project_id);
}
private function deleteRelative($project_id)
{ private function deleteVersionGantt($project_id)
UserToProyek::where('proyek_id', $project_id)->delete(); {
UserToActivity::where('proyek_id', $project_id)->delete(); $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
AssignMaterial::where('proyek_id', $project_id)->delete(); $vhIds = $dataVg->all();
ProjectCharter::where('proyek_id', $project_id)->delete(); $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
ProjectApproval::where('proyek_id', $project_id)->delete(); $activityIds = $activity->all();
ProjectMileStone::where('proyek_id', $project_id)->delete(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
ProjectParticipants::where('proyek_id', $project_id)->delete(); foreach ($dataRa as $ra) {
$this->deleteVersionGantt($project_id); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
$this->deleteDokumenProject($project_id); foreach ($images as $image) {
} if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
private function deleteVersionGantt($project_id) }
{ }
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
$vhIds = $dataVg->all(); }
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
$activityIds = $activity->all(); foreach ($dataAd as $ad) {
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); if(file_exists($this->pathActivityDocument.$ad->file)){
foreach ($dataRa as $ra) { unlink($this->pathActivityDocument.$ad->file);
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); }
foreach ($images as $image) { }
if(file_exists($this->pathImage.$image->image)){ ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
unlink($this->pathImage.$image->image); CommentActivity::whereIn("activity_id", $activityIds)->delete();
} Holiday::where("proyek_id", $project_id)->delete();
} VersionGantt::where("proyek_id", $project_id)->delete();
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); Link::whereIn("version_gantt_id", $vhIds)->delete();
} ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); Activity::whereIn("version_gantt_id", $vhIds)->delete();
foreach ($dataAd as $ad) { ReportActivity::whereIn("activity_id", $activityIds)->delete();
if(file_exists($this->pathActivityDocument.$ad->file)){ }
unlink($this->pathActivityDocument.$ad->file);
} private function deleteDokumenProject($project_id)
} {
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
CommentActivity::whereIn("activity_id", $activityIds)->delete();
Holiday::where("proyek_id", $project_id)->delete(); foreach ($dataDokumen as $dokumen) {
VersionGantt::where("proyek_id", $project_id)->delete(); if(file_exists($this->pathDocument.$dokumen->file)){
Link::whereIn("version_gantt_id", $vhIds)->delete(); unlink($this->pathDocument.$dokumen->file);
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); }
Activity::whereIn("version_gantt_id", $vhIds)->delete(); }
ReportActivity::whereIn("activity_id", $activityIds)->delete(); DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
}
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
private function deleteDokumenProject($project_id) $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-out-folder")->where('ref_id', $project_id)->get(); foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){
foreach ($dataDokumen as $dokumen) { unlink($this->pathDocument.$dokumen->file);
if(file_exists($this->pathDocument.$dokumen->file)){ }
unlink($this->pathDocument.$dokumen->file); }
}
} DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); }
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); public function search(Request $request)
$ref_ids = $dataFolder->all(); {
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); $payload = $request->all();
foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ $dataBuilder = $this->setUpPayload($payload, 'm_proyek');
unlink($this->pathDocument.$dokumen->file); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
} return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function search(Request $request)
{ public function list()
$payload = $request->all(); {
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $data = Project::all();
$builder = $dataBuilder['builder']; $countData = $data->count();
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); if(!$data)
$totalRecord = $countBuilder->count(); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
public function list()
{ public function getListProjectTask($id){
$data = Project::all(); $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
$countData = $data->count(); ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
if($data){ ->groupBy("m_proyek.proyek_id")
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); ->get();
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400); 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 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'=>'failed get list project, please try again later!','code'=>400], 400);
}
}
} }

179
app/Http/Controllers/ProjectDokumenController.php

@ -7,93 +7,94 @@ use App\Models\DokumenProject;
class ProjectDokumenController extends Controller class ProjectDokumenController extends Controller
{ {
public function dokumenByProyekId($id){ public function dokumenByProyekId($id){
if($id && $id!="" && (int)$id > 0){ if(empty($id) || !is_int((int)$id)) {
$dataDokumen = DokumenProject::where("ref_id", $id)->get(); return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400);
}
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}else{ $document = DokumenProject::where("ref_id", $id)->get();
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400);
} if(count($document) == 0)
} return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404);
public function delete($id) return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200);
{ }
if($id && $id!="" && (int)$id > 0){
$dokumen = DokumenProject::find($id); public function delete($id)
if($dokumen){ {
if(file_exists($this->pathDocument.$dokumen->file)){ if(empty($id) || !is_int((int)$id)) {
unlink($this->pathDocument.$dokumen->file); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} }
$dokumen->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); $document = DokumenProject::find($id);
}else{ if(!$document){
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); if(file_exists($this->pathDocument.$document->file)){
} unlink($this->pathDocument.$document->file);
} }
public function uploadProjectDokumen(Request $request) $document->delete();
{
if($request->hasFile('dokumen')){ return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
$dokumen = $request->file('dokumen'); }
$ref_id = $request->ref_id;
$extension = $dokumen->extension(); public function uploadProjectDokumen(Request $request)
$name = $dokumen->getClientOriginalName(); {
if($request->hasFile('dokumen')){
$result = $dokumen->move($this->pathDocument, $name); $document = $request->file('dokumen');
if($result){ $ref_id = $request->ref_id;
$data = [ $name = $document->getClientOriginalName();
'ref_id' => (int)$ref_id,
'file' => $name, $result = $document->move($this->pathDocument, $name);
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' // project-document-in-folder / project-document-out-folder if($result){
]; $data = [
'ref_id' => (int)$ref_id,
$result = DokumenProject::create($data); 'file' => $name,
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document'
if($result){ ];
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
}else{ $result = DokumenProject::create($data);
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); if(!$result){
} unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}else{ }
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
}
}else{ }
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
} }
} return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
public function searchDocProject(Request $request){
$payload = $request->all(); public function searchDocProject(Request $request){
$dataBuilder = $this->setUpPayload($payload, 'document_project'); $payload = $request->all();
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $dataBuilder = $this->setUpPayload($payload, 'document_project');
$dataGet = $builder->get(); $builder = $dataBuilder['builder'];
$totalRecord = $countBuilder->count(); $countBuilder = $dataBuilder['count'];
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $dataGet = $builder->get();
} $totalRecord = $countBuilder->count();
public function downloadDokumen($id) return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
{ }
if($id && $id!="" && (int)$id > 0){
$dokumen = DokumenProject::find($id); public function downloadDokumen($id)
if($dokumen){ {
if(file_exists($this->pathDocument.$dokumen->file)){ if(empty($id) || !is_int((int)$id))
$pathToFile = $this->pathDocument.$dokumen->file; return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
return response()->download($pathToFile);
}else{ $document = DokumenProject::find($id);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} if(!$document)
}else{ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} if(!file_exists($this->pathDocument.$document->file))
}else{ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
} $pathToFile = $this->pathDocument.$document->file;
} return response()->download($pathToFile);
}
} }

191
app/Http/Controllers/RoleController.php

@ -4,105 +4,98 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Role; use App\Models\Role;
class RoleController extends Controller class RoleController extends Controller
{ {
public function add(Request $request)
{ public function add(Request $request)
$this->validate($request, [ {
'name' => 'required', $this->validate($request, [
'description' => 'required' 'name' => 'required',
]); 'description' => 'required'
]);
$data = $request->all();
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = Role::create($data);
$result = Role::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data role successfully!','code'=>200], 200); if(!$result)
}else{ return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500);
return response()->json(['status'=>'failed','message'=>'add data role failed!','code'=>400], 400);
} return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
} }
public function edit($id){ public function edit( $id){
if(!$id || (int) $id < 0 || $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);
die();
} $result = Role::find($id);
$result = Role::find($id); if(!$result)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get data role, please try again later!','code'=>400], 400);
} public function update(Request $request, $id)
} {
if(empty($id) || !is_int((int)$id))
public function update(Request $request, $id) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
{
if(!$id || (int) $id < 0 || $id==""){ $data = Role::find($id);
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
$data = Role::find($id);
$result = $data->update($request->all());
if($data){
$result = $data->update($request->all()); if(!$result)
}else{ return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500);
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400);
die(); return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
} }
public function delete($id)
if($result){ {
return response()->json(['status'=>'success','message'=>'data role successfully updated!','code'=>200], 200); if(empty($id) || !is_int((int)$id))
}else{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'data role failed updated!','code'=>400], 400);
} $data = Role::find($id);
}
if(!$data)
public function delete($id) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
{
$data = Role::find($id); $delete = $data->delete();
if($data){ if(!$delete)
$delete = $data->delete(); return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500);
}else{
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
die(); }
}
public function search(Request $request)
{
if($delete){ $payload = $request->all();
return response()->json(['status'=>'success','message'=>'data role successfully deleted!','code'=>200], 200);
}else{ $dataBuilder = $this->setUpPayload($payload, 'm_roles');
return response()->json(['status'=>'failed','message'=>'data role failed deleted!','code'=>400], 400); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
public function search(Request $request)
{ return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$payload = $request->all(); }
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
$builder = $dataBuilder['builder']; public function list()
$countBuilder = $dataBuilder['count']; {
$dataGet = $builder->get(); $data = Role::all();
$totalRecord = $countBuilder->count(); $countData = $data->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
public function list()
{ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$data = Role::all(); }
$countData = $data->count();
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
} }

Loading…
Cancel
Save