Browse Source

clean controllers

pull/3/head
Muhammad Sulaiman Yusuf 3 years ago
parent
commit
00b8602cab
  1. 90
      app/Http/Controllers/ActivityDokumenController.php
  2. 19
      app/Http/Controllers/AuthController.php
  3. 83
      app/Http/Controllers/DashboardController.php
  4. 63
      app/Http/Controllers/DivisiController.php
  5. 87
      app/Http/Controllers/ProjectController.php
  6. 87
      app/Http/Controllers/ProjectDokumenController.php
  7. 71
      app/Http/Controllers/RoleController.php

90
app/Http/Controllers/ActivityDokumenController.php

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

19
app/Http/Controllers/AuthController.php

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

83
app/Http/Controllers/DashboardController.php

@ -6,8 +6,7 @@ use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\Activity;
use App\Models\ReportActivity;
use App\Models\UserToActivity;
use DB;
use App\Models\Role;
class DashboardController extends Controller
{
@ -25,11 +24,10 @@ class DashboardController extends Controller
$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'=>'failed','message'=>'Data not found','code'=> 404], 404);
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 getMaxVersionGantt($id){
@ -48,14 +46,12 @@ class DashboardController extends Controller
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();
$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{
if(!$dataFinal)
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 list()
@ -63,30 +59,22 @@ class DashboardController extends Controller
$data = Role::all();
$countData = $data->count();
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
if(!$data)
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'=>$data, 'totalRecord'=>$countData], 200);
}
public function getActivityByProjectId($projectId) {
$output = [];
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
if (count($data) > 0) {
foreach ($data as $actData) {
$output[] = $actData->id;
}
}
return $output;
}
/* for statusProyek, I want something output like this
/*
const statusProyek = [
{
"id": "1",
@ -109,17 +97,14 @@ class DashboardController extends Controller
*/
public function statusProyek(Request $request) {
$dataPayload = $request->all();
$reqProject = [];
$dataFinal = [];
$reqProject = $dataFinal = [];
if (!isset($dataPayload['project_id'])) {
if (!isset($dataPayload['project_id']))
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
}
foreach ($dataPayload['project_id'] as $val) {
$prj["project_id"] = $val;
$prj["activity_id"] = $this->getActivityByProjectId($val);
$reqProject[] = $prj;
}
@ -133,24 +118,20 @@ class DashboardController extends Controller
$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");
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$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");
$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;
foreach($progress_actual as $objRow) {
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
if (count($reqProject[$i]['activity_id']) > 0) {
for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) {
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
}
}
if (!isset($queryProject->id)) {
if (!isset($queryProject->id))
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
}
$now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
@ -176,31 +157,28 @@ class DashboardController extends Controller
}
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}else{
if(empty($dataFinal))
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}
public function curvaS(Request $request)
{
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
$dataFinal=[];
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
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();
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
$dataBobotPlan =[];
for ($i=0; $i < count($data); $i++) {
$tmpp = 0;
$tmpa = 0;
$tmpbc = 0;
$tmpac = 0;
$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;
@ -209,6 +187,7 @@ class DashboardController extends Controller
}
$data[$i]['cal_bobot_p'] = round($tmpp,2);
if($i > 0 ){
if($data[$i-1]['cal_bobot_a'] != null){
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
@ -219,12 +198,6 @@ class DashboardController extends Controller
}else{
$data[$i]['cal_bobot_a'] = null;
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
}
$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;
@ -235,18 +208,18 @@ class DashboardController extends Controller
$data[$i]['cal_actual_cost'] = null;
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
$data[$i]['cal_budget_cost'] = round($tmpbc,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{
if(!$dataFinal)
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);
}
}

63
app/Http/Controllers/DivisiController.php

@ -12,64 +12,64 @@ class DivisiController extends Controller
'name' => 'required',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'Master divisi successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'Master divisi failed created','code'=>400]);
}
if(!$result)
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){
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);
}
$data = Divisi::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Data Master divisi not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Master divisi successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Master divisi failed updated!','code'=>400], 400);
}
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
}
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);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data Master divisi not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'Master divisi successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Master divisi failed deleted!','code'=>400], 400);
}
if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
@ -78,10 +78,9 @@ class DivisiController extends Controller
$data = Divisi::all();
$countData = $data->count();
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400);
}
}
}

87
app/Http/Controllers/ProjectController.php

@ -14,12 +14,8 @@ use App\Models\ProjectCharter;
use App\Models\ProjectApproval;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\UserToVersionGantt;
use App\Models\RequestMaterial;
use App\Models\ShowHideColumn;
use App\Models\ToolsProject;
use App\Models\VersionGantt;
use App\Models\MaterialProject;
use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
@ -30,6 +26,7 @@ use App\Models\OfficeHours;
class ProjectController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
@ -46,51 +43,43 @@ class ProjectController extends Controller
$result = Project::create($data);
if($result){
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
$this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
return response()->json(['status'=>'success','message'=>'add data project successfully!', 'data_result' =>$dataResultInsert, 'code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project failed!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
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);
die();
}
$result = Project::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400);
}
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','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==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = Project::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400);
die();
}
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
if($result){
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
}
private function createOfficeHours($proyek_id)
@ -123,20 +112,15 @@ class ProjectController extends Controller
{
$data = Project::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$this->deleteRelative($id);
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400);
die();
}
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
if($delete){
return response()->json(['status'=>'success','message'=>'data project successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project failed deleted!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
private function deleteRelative($project_id)
@ -210,11 +194,13 @@ class ProjectController extends Controller
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
@ -223,21 +209,22 @@ class ProjectController extends Controller
$data = Project::all();
$countData = $data->count();
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400);
}
}
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();
$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);
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);
}
}
}

87
app/Http/Controllers/ProjectDokumenController.php

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

71
app/Http/Controllers/RoleController.php

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

Loading…
Cancel
Save