nest('child', 'content.others.team.index', $param); return $this->bsGetView('content.others.team.index', $param); } public function company(Request $request) { $param['table'] = route('others.dataTable')."?type=company"; // return view('home')->nest('child', 'content.others.company.index', $param); return $this->bsGetView('content.others.company.index', $param); } public function company_store(Request $request) { DB::beginTransaction(); try { if($request->get_id) { $company = CompanyModel::find($request->get_id); $company->user_upd_id = Auth::user()->id; $company->company_name = $request->company_name; $company->company_code = $request->company_code; $company->address = $request->address; $company->phone_no = $request->phone_no; $company->email = $request->email; $company->pic_name = $request->pic_name; if($request->hasFile('logo_url')){ $destination_path = public_path('gallery'); $image_path = public_path($company->logo_url); if(File::exists($image_path)) { File::delete($image_path); } $files = $request->file('logo_url'); $filename = 'User_'.date('Ymd')."_".date('His').'.'.$files->getClientOriginalExtension(); $upload_success = $files->move($destination_path, $filename); $company->logo_url = '/gallery/'.$filename; } $company->save(); } else { $company = new CompanyModel(); // $get_max = DB::table('master_company')->max('id'); // $company->id = $get_max+1; $company->user_crt_id = Auth::user()->id; $company->company_name = $request->company_name; $company->company_code = $request->company_code; $company->address = $request->address; $company->phone_no = $request->phone_no; $company->email = $request->email; $company->pic_name = $request->pic_name; if($request->hasFile('logo_url')){ $destination_path = public_path('gallery'); $files = $request->file('logo_url'); $filename = 'LogoC_'.date('Ymd')."_".date('His').'.'.$files->getClientOriginalExtension(); $upload_success = $files->move($destination_path, $filename); $company->logo_url = '/gallery/'.$filename; } // $company->save(); if($company->save()) { $nameStatus = array('Assigned', 'On Progress', 'Done', 'Inactive'); $noI = 1; $data = []; for($i=0; $i $noI++, 'definition' => $nameStatus[$i], 'is_active' => true, 'company_id' => $company->id, ]; } $status = StatusModel::insert($data); $nameCritical = array('Low', 'Medium', 'High', 'Critical', 'Very Critical'); $bobotCritical = array('0.25', '0.5', '1', '1.25', '1.5'); $noJ = 1; $dataJ = []; for($j=0; $j $noJ++, 'definition' => $nameCritical[$j], 'is_active' => true, 'company_id' => $company->id, 'bobot' => $bobotCritical[$j], ]; } $critical = CriticalLevelModel::insert($dataJ); $arrayBudget = array( [ 'id' => 1, 'definition' => 'BudgetAwal', 'is_shown' => false, 'tx_type' => 'Kr', 'operator' => '+', 'rev_operator' => '-', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 2, 'definition' => 'Transportasi', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 3, 'definition' => 'Akomodasi', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 4, 'definition' => 'Konsumsi', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 5, 'definition' => 'Insentif Perjalanan Dinas', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 6, 'definition' => 'Pembelian Inventaris', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 7, 'definition' => 'Pembelian Software', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 8, 'definition' => 'Penyesuaian Budget', 'is_shown' => true, 'tx_type' => 'Kr', 'operator' => '+', 'rev_operator' => '-', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 9, 'definition' => 'Pengurangan Budget', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ], [ 'id' => 10, 'definition' => 'Lainnya', 'is_shown' => true, 'tx_type' => 'Db', 'operator' => '-', 'rev_operator' => '+', 'is_active' => true, 'company_id' => $company->id ] ); $budget = BudgetTypeModel::insert($arrayBudget); $nameTeamRole = array('PM', 'Deputi PM', 'Member'); $noK = 1; $dataK = []; for($k=0; $k $noK++, 'definition' => $nameTeamRole[$k], 'is_active' => true, 'company_id' => $company->id, ]; } $team_role = TeamRoleModel::insert($dataK); // $lastIdTaskType = DB::table('ref_task_type')->max('id'); $arrayTaskType = array( [ // 'id' => $lastIdTaskType+1, 'definition' => 'Teknologi Informasi', 'is_active' => true, 'company_id' => $company->id, ], [ // 'id' => $lastIdTaskType+2, 'definition' => 'Bisnis', 'is_active' => true, 'company_id' => $company->id, ], [ // 'id' => $lastIdTaskType+3, 'definition' => 'Operation', 'is_active' => true, 'company_id' => $company->id, ], [ // 'id' => $lastIdTaskType+4, 'definition' => 'Satuan Pengendalian Intern', 'is_active' => true, 'company_id' => $company->id, ], ); JenisTaskModel::insert($arrayTaskType); $user = new User(); $get_max = DB::table('master_user')->max('id'); // $user->id = $get_max+1; $codeGenerate = str_pad($get_max+1, 5, 0, STR_PAD_LEFT); $userCode = 'adm_7'.$company->id.$codeGenerate; $user->user_crt_id = Auth::user()->id; $user->password = bcrypt('welcome1'); $user->full_name = 'Administrator '. $company->company_name; $user->user_code = $userCode; $user->unit_id = 1; $user->is_active = true; $user->is_onholiday = false; $user->role_id = 6; $user->company_id = $company->id; $user->save(); } } //code... DB::commit(); return response()->json([ 'rc' => 0, 'rm' => 'sukses' ]); } catch (\Throwable $e) { //throw $th; DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function company_get($id) { $data['data'] = DB::table('master_company')->where('id', $id)->first(); $data['list_user'] = DB::table('master_user')->where('company_id', $id)->get(); return response()->json($data); } public function client(Request $request) { $param['table'] = route('others.dataTable')."?type=client"; // return view('home')->nest('child', 'content.others.client.index', $param); return $this->bsGetView('content.others.client.index', $param); } public function client_store(Request $request) { DB::beginTransaction(); try { if($request->get_id) { $client = ClientModel::find($request->get_id); } else { $client = new ClientModel(); } if($request->hasFile('logo_url')){ // $destination_path = public_path('gallery'); // $image_path = public_path($client->logo_url); // if(File::exists($image_path)) { // File::delete($image_path); // } $files = $request->file('logo_url'); SpaceController::deleteFile($client->logo_url); $urlDoc = SpaceController::uploadFile($files, 'client', []); $client->logo_url = $urlDoc; // $filename = 'Client_'.date('Ymd')."_".date('His').'.'.$files->getClientOriginalExtension(); // $upload_success = $files->move($destination_path, $filename); } $client->client_name = $request->client_name; $client->address = $request->address; $client->is_active = $request->is_active; $client->save(); //code... DB::commit(); return response()->json([ 'rc' => 0, 'rm' => 'sukses' ]); } catch (\Throwable $e) { //throw $th; DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function client_get($id) { $data['data'] = DB::table('master_client')->where('id', $id)->first(); return response()->json($data); } public function user(Request $request) { $param['table'] = route('others.dataTable')."?type=user"; // return view('home')->nest('child', 'content.others.user.index', $param); return $this->bsGetView('content.others.user.index', $param); } public function user_store(Request $request) { DB::beginTransaction(); try { if($request->get_id) { $user = User::find($request->get_id); $user->user_upd_id = Auth::user()->id; } else { $user = new User(); // $get_max = DB::table('master_user')->max('id'); // $user->id = $get_max+1; $user->user_crt_id = Auth::user()->id; $user->password = bcrypt('welcome1'); } $user->email = $request->email; $user->full_name = $request->full_name; $user->user_code = $request->user_code; // $user->unit_id = $request->unit_id; $user->is_active = $request->is_active; // $user->is_onholiday = false; $user->role_id = $request->role_id; $user->division_id = $request->division_id; // $user->phone_number = $request->phone_number; // $user->company_id = Auth::user()->company_id; if($request->is_external) { $user->client_id = $request->client_id; } if($request->hasFile('foto_profil')){ // $destination_path = public_path('gallery'); // $image_path = public_path($user->image_url); // if(File::exists($image_path)) { // File::delete($image_path); // } SpaceController::deleteFile($user->image_url); $files = $request->file('foto_profil'); $urlDoc = SpaceController::uploadFile($files, 'profile', []); // $filename = 'User_'.date('Ymd')."_".date('His').'.'.$files->getClientOriginalExtension(); // $upload_success = $files->move($destination_path, $filename); // $user->image_url = '/gallery/'.$filename; $user->image_url = $urlDoc; } $user->save(); //code... DB::commit(); return response()->json([ 'rc' => 0, 'rm' => 'sukses' ]); } catch (\Throwable $e) { //throw $th; DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function user_get($id) { $data = DB::table('master_user')->where('id', $id)->first(); $data->image_url = SpaceController::getFile($data->image_url); return response()->json($data); } public function user_delete(Request $request) { $get_id = $request->input('id'); DB::beginTransaction(); try { //code... $user = User::find($get_id); SpaceController::deleteFile($user->image_url); User::find($get_id)->delete(); DB::commit(); return response()->json([ 'rc' => 0, 'data' => 'Data Berhasil Dihapus' ]); } catch (\Throwable $e) { DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function user_reset(Request $request) { DB::beginTransaction(); try { //code... $user = User::find(Auth::user()->id); $user->password = Hash::make('welcome1'); $user->save(); DB::commit(); return response()->json([ 'rc' => 0, 'data' => 'Data Berhasil Dihapus' ]); } catch (\Throwable $e) { DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function user_change(Request $request) { DB::beginTransaction(); try { //code... $user = User::find(Auth::user()->id); if(Hash::check($request->password, $user->password)) { return response()->json([ 'rc' => 99, 'data' => 'Password tidak boleh sama dengan password existing' ]); } else { $user->password = Hash::make($request->password); $user->save(); } DB::commit(); return response()->json([ 'rc' => 0, 'data' => 'Data Berhasil Dihapus' ]); } catch (\Throwable $e) { DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function user_change_password(Request $request) { DB::beginTransaction(); try { $user = User::find(Auth::user()->id); $oldPassCheck = Hash::check($request->input('oldPassword'), $user->password); if ($oldPassCheck == false) { return response()->json([ 'rc' => 99, 'data' => 'Password Lama Salah.' ]); } if ($request->input('newPassword') != $request->input('confirmPassword')) { return response()->json([ 'rc' => 99, 'data' => 'Password Baru dan Konfirmasi Password Harus Sama' ]); } if(Hash::check($request->input('newPassword'), $user->password)) { return response()->json([ 'rc' => 99, 'data' => 'Password tidak boleh sama dengan password existing' ]); } $regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$^"; if (preg_match($regexp, $request->input('newPassword'))){ $user->password = Hash::make($request->input('newPassword')); $user->save(); DB::commit(); return response()->json([ 'rc' => 0, 'data' => "Password Baru Berhasil Tersimpan" ]); } else { return response()->json([ 'rc' => 99, 'data' => "Gagal, Format password baru tidak sesuai dengan ketentuan" ]); } } catch (\Throwable $e) { DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function user_change_pp(Request $request) { DB::beginTransaction(); try { //code... $user = User::find(Auth::user()->id); if($request->hasFile('foto_profil_change_pp')){ SpaceController::deleteFile($user->image_url); // $destination_path = public_path('gallery'); // $image_path = public_path($user->image_url); // if(File::exists($image_path)) { // File::delete($image_path); // } $files = $request->file('foto_profil_change_pp'); $urlDoc = SpaceController::uploadFile($files, 'user', []); $user->image_url = $urlDoc; // $filename = 'User_'.date('Ymd')."_".date('His').'.'.$files->getClientOriginalExtension(); // $upload_success = $files->move($destination_path, $filename); // $user->image_url = '/gallery/'.$filename; } $user->full_name = $request->full_name_change; $user->user_code = $request->user_code_change; $user->phone_number = $request->phone_number_change; $user->save(); DB::commit(); return response()->json([ 'rc' => 0, 'data' => 'Data Berhasil Dihapus' ]); } catch (\Throwable $e) { DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function data(Request $request) { $type = $request->get('type'); $keyword = $request->get('keyword'); switch ($type) { case 'mngTeam': # code... $dataTeam = DB::table('master_project as mp') ->leftJoin('master_unit as mu','mu.id','=','mp.unit_owner_id') ->leftJoin('master_company as mc','mc.id','=','mp.company_id') ->leftJoin('master_team as mt','mt.team_code','=','mp.team_code') ->leftJoin('master_user as muser','muser.id','=','mt.member_id') ->leftJoin('ref_team_role as rtr', function($join) { $join->on('rtr.id','=','mt.team_role_id'); $join->on('rtr.company_id','=','mt.company_id'); }) ->select("mp.project_name","mp.project_code",DB::raw("(case when (mp.logo_url is not null) then mp.logo_url else mc.logo_url end) as logo_url"), "mu.unit_name", DB::raw("json_agg(json_build_object('team_role_id', rtr.id, 'nama', muser.full_name,'profil_pict', muser.image_url,'team_role', rtr.definition)) as list_team"),"mt.team_code") ->where('mp.company_id', Auth::user()->company_id) ->when ( !is_null($keyword), function ($query) use($keyword) { return $query->whereRaw("(LOWER(mp.project_name) LIKE '%" . strtolower($keyword) . "%' OR LOWER(mp.team_code) LIKE '%" . strtolower($keyword) . "%')"); }) ->groupByRaw('mp.project_name, mp.project_code, mu.unit_name, mp.logo_url, mc.logo_url, mt.team_code, mp.id') ->orderBy('mp.id', 'desc') ->paginate(3); $param['team'] = $dataTeam; $param['paginateLinks'] = (string) $dataTeam->links(); break; } return response()->json([ 'rc' => 200, 'data' => $param ]); } public function dataTable(Request $request) { $type = $request->get('type'); switch ($type) { case 'mngTeam': $data = DB::select("select mu.full_name, mu.image_url, mt.team_code, rtr.definition, mp.project_name, mt.is_active from master_team mt join master_project mp on mp.team_code = mt.team_code join master_user mu on mu.id = mt.member_id join ref_team_role rtr on rtr.id = mt.team_role_id and rtr.company_id = mp.company_id order by mt.team_code, mt.member_id"); # code... break; case 'company': if(Auth::user()->role_id == 7) { $data = DB::select("select mc.*, (select user_code from master_user where company_id = mc.id and role_id = 6 order by id limit 1) as user_code from master_company mc"); } else { $data = DB::select("select mc.*, (select user_code from master_user where company_id = mc.id and role_id = 6 order by id limit 1) as user_code from master_company mc where mc.id = ?",[Auth::user()->company_id]); } break; case 'user': if(Auth::user()->role_id==5) { $data = DB::select("select mu.*, rr.definition as role_name, mc.client_name, rd.definition as division_name from master_user mu join ref_role rr on rr.id = mu.role_id left join master_client mc on mc.id = mu.client_id left join ref_division rd on rd.id = mu.division_id where rr.is_external = true order by mu.id desc"); } else { $data = DB::select("select mu.*, rr.definition as role_name, mc.client_name, rd.definition as division_name from master_user mu join ref_role rr on rr.id = mu.role_id left join master_client mc on mc.id = mu.client_id left join ref_division rd on rd.id = mu.division_id where rr.is_external = false order by mu.id desc"); } break; case 'client': $data = DB::select("select * from master_client"); break; } return DataTables::of($data) // ->addIndexColumn() ->addColumn('member_name',function($data) use ($type) { if($type=='mngTeam') { $image_url = asset('assets/media/logos/no_img.png'); if($data->image_url) { // $image_url = $data->image_url; $image_url = SpaceController::getFile($data->image_url); } return '
'.$data->full_name.' '.$data->definition.'
'; } else if($type == 'company') { $logo_url = asset('assets/media/logos/no_img.png'); if($data->logo_url) { // $logo_url = $data->logo_url; $image_url = SpaceController::getFile($data->logo_url); } return '
'.$data->company_name.' '.$data->company_code.'
'; } else if($type == 'user') { $image_url = asset('assets/media/logos/no_img.png'); if($data->image_url) { // $image_url = $data->image_url; $image_url = SpaceController::getFile($data->image_url); } return '
'.$data->user_code.' '.$data->full_name.'
'; } else if($type == 'client') { $logo_url = asset('assets/media/logos/no_img.png'); if($data->logo_url) { // $logo_url = $data->logo_url; $logo_url = SpaceController::getFile($data->logo_url); } return ' '; } }) ->editColumn('division_name', function($data) use($type) { if($type=='user') { return $data->division_name?$data->division_name:'-'; } }) ->editColumn('is_active', function($data) use ($type) { if($type=='mngTeam' || $type=='user' || $type=='client') { return $data->is_active?'Aktif':'Non Aktif'; } }) ->addColumn('action', function ($data) use ($type, $request) { $btn = ''; if($type=='user') { $btn .= ' '; $btn .= ' '; } else if($type=='company') { $btn .= ' '; $btn .= ' '; } else if($type=='client') { $btn .= ' '; } /* $btn .= ' '; */ return ' '; }) ->rawColumns(['action','member_name']) ->make(true); } }