Browse Source

Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into dev-wahyu

pull/3/head
wahyu 1 year ago
parent
commit
09d524b5e3
  1. 348
      app/Http/Controllers/BroadcastController.php
  2. 13
      app/Http/Controllers/DivisiController.php
  3. 392
      app/Http/Controllers/HumanResourceController.php
  4. 310
      app/Http/Controllers/MenuController.php
  5. 136
      app/Http/Controllers/ProjectChecklistsController.php
  6. 61
      app/Http/Controllers/ProjectController.php
  7. 136
      app/Http/Controllers/ProjectIssuesController.php
  8. 137
      app/Http/Controllers/ProjectRisksController.php
  9. 207
      app/Http/Controllers/RoleController.php
  10. 467
      app/Http/Controllers/UserToProyekController.php
  11. 108
      app/Models/Project.php
  12. 23
      app/Models/ProjectChecklists.php
  13. 23
      app/Models/ProjectIssues.php
  14. 24
      app/Models/ProjectRisks.php
  15. 28
      routes/web.php

348
app/Http/Controllers/BroadcastController.php

@ -1,171 +1,177 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Broadcast; use App\Models\Broadcast;
use App\Models\User; use App\Models\User;
use App\Services\FCMService; use App\Services\FCMService;
class BroadcastController extends Controller class BroadcastController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$data = $request->all(); $data = $request->all();
$data['status_send'] = true; $data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName; if (isset($data['send_to_id'])) {
if (isset($data['send_to_id'])) { $idArray = $data['send_to_id'];
$idArray = $data['send_to_id']; if (is_array($data['send_to_id'])) {
if (is_array($data['send_to_id'])) { $data['send_to_id'] = implode(", ", $idArray);
$data['send_to_id'] = implode(", ", $idArray); }
} }
} $result = Broadcast::create($data);
// dd($data); if($result){
$result = Broadcast::create($data); $data['status_send'] !== "registered" ? $this->sendNotification($data) : '';
if($result){ return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200);
$this->sendNotification($data); }else{
return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400);
}else{ }
return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); }
}
} 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(!$id || (int) $id < 0 || $id==""){ die();
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); }
die();
} $result = Broadcast::find($id);
$result = Broadcast::find($id); if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
if($result){ }else{
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); }
}
} public function update(Request $request, $id)
{
public function update(Request $request, $id) if(!$id || (int) $id < 0 || $id==""){
{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$id || (int) $id < 0 || $id==""){ }
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} $data = Broadcast::find($id);
$data = Broadcast::find($id); $status_send = $request->status_send;
if($data){ if($status_send === 'resend' || $status_send === 'send' && !empty($data))
$result = $data->update($request->all()); {
}else{ $data['status_send'] = $status_send;
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); $this->sendNotification($data);
die(); }
}
if($data){
$result = $data->update($request->all());
if($result){ }else{
return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400);
}else{ die();
return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); }
}
}
if($result){
public function delete($id) return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200);
{ }else{
$data = Broadcast::find($id); return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400);
}
if($data){ }
$delete = $data->delete();
}else{ public function delete($id)
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); {
die(); $data = Broadcast::find($id);
}
if($data){
$delete = $data->delete();
if($delete){ }else{
return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400);
}else{ die();
return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); }
}
}
if($delete){
public function search(Request $request) return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200);
{ }else{
$payload = $request->all(); return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400);
$dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); }
$builder = $dataBuilder['builder']; }
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); public function search(Request $request)
$totalRecord = $countBuilder->count(); {
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $payload = $request->all();
} $dataBuilder = $this->setUpPayload($payload, 'm_broadcast');
$builder = $dataBuilder['builder'];
public function list() $countBuilder = $dataBuilder['count'];
{ $dataGet = $builder->get();
$data = Broadcast::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'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); public function list()
}else{ {
return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); $data = Broadcast::all();
} $countData = $data->count();
}
if($data){
public function sendNotification($data) return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
{ }else{
// send_to_type (all, roles, user) return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400);
if (isset($data['send_to_type'])) { }
switch ($data['send_to_type']) { }
case 'all':
$users = User::whereNotNull('fcm_token')->get(); public function sendNotification($data)
if (isset($users)) { {
foreach ($users as $user) { // send_to_type (all, roles, user)
FCMService::send( if (isset($data['send_to_type'])) {
$user->fcm_token, switch ($data['send_to_type']) {
[ case 'all':
'title' => $data['title_notif'], $users = User::whereNotNull('fcm_token')->get();
'body' => $data['message_notif'], if (isset($users)) {
] foreach ($users as $user) {
); FCMService::send(
} $user->fcm_token,
} [
break; 'title' => $data['title_notif'],
'body' => $data['message_notif'],
case 'roles': ]
$users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); );
if (isset($users)) { }
foreach ($users as $user) { }
FCMService::send( break;
$user->fcm_token,
[ case 'roles':
'title' => $data['title_notif'], $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get();
'body' => $data['message_notif'], if (isset($users)) {
] foreach ($users as $user) {
); FCMService::send(
} $user->fcm_token,
} [
break; 'title' => $data['title_notif'],
'body' => $data['message_notif'],
case 'users': ]
$idArray = explode(", ", $data['send_to_id']); );
foreach ($idArray as $key => $value) { }
$user = User::where("id", $value)->whereNotNull('fcm_token')->first(); }
if (isset($user)) { break;
FCMService::send(
$user->fcm_token, case 'users':
[ $idArray = explode(", ", $data['send_to_id']);
'title' => $data['title_notif'], foreach ($idArray as $key => $value) {
'body' => $data['message_notif'], $user = User::where("id", $value)->whereNotNull('fcm_token')->first();
] if (isset($user)) {
); FCMService::send(
} $user->fcm_token,
} [
break; 'title' => $data['title_notif'],
'body' => $data['message_notif'],
default: ]
# code... );
break; }
} }
} break;
}
} default:
# code...
break;
}
}
}
}

13
app/Http/Controllers/DivisiController.php

@ -19,9 +19,9 @@ class DivisiController extends Controller
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'string|required|unique:m_divisi,name',
'description' => 'string', 'description' => 'nullable|string',
'parent' => 'integer' 'parent' => 'nullable|integer'
]); ]);
$data = $request->all(); $data = $request->all();
@ -39,8 +39,15 @@ class DivisiController extends Controller
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$this->validate($request, [
'name' => 'string|required',
'description' => 'nullable|string',
'parent' => 'nullable|integer'
]);
$data = Divisi::find($id); $data = Divisi::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : '';
if(!$data) if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);

392
app/Http/Controllers/HumanResourceController.php

@ -1,193 +1,199 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\HumanResource; use App\Models\HumanResource;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
class HumanResourceController extends Controller class HumanResourceController extends Controller
{ {
public function add(Request $request){ public function add(Request $request)
$this->validate($request, [ {
'role_id' => 'required', $this->validate($request, [
'name' => 'required', 'role_id' => 'required',
'ktp_number' => 'required', 'name' => 'required',
'employee_type' => 'required' 'ktp_number' => 'required|numeric|unique:m_users,ktp_number',
]); 'employee_type' => 'required'
]);
$data = $request->all();
$data = $request->all();
if(isset($request->password) && $request->password!=""){
$data['password'] = md5($request->password); if (isset($request->password) && $request->password != "") {
} $data['password'] = md5($request->password);
}
$result = HumanResource::create($data);
$result = HumanResource::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfull created','code'=>200]); if ($result) {
}else{ return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed created','code'=>400]); } else {
} return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]);
} }
}
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); {
die(); if (!$id || (int) $id < 0 || $id == "") {
} return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
$result = HumanResource::find($id); }
if($result){ $result = HumanResource::find($id);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ if ($result) {
return response()->json(['status'=>'failed','message'=>'failed get data human resource, please try again later!','code'=>400], 400); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} } else {
} return response()->json(['status' => 'failed', 'message' => 'failed get data human resource, please try again later!', 'code' => 400], 400);
}
public function update(Request $request, $id){ }
if(!$id || (int) $id < 0 || $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 == "") {
$humanresource = HumanResource::find($id); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = $request->all(); $humanresource = HumanResource::find($id);
if(isset($request->password) && $request->password!="" ){ $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : '';
$data['password'] = md5($request->password); $request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
} $request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){ $data = $request->all();
return response()->json(['status'=>'failed','message'=>'Username already exists!','code'=>400], 400);
} if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
if($humanresource){ }
$result = $humanresource->update($data);
}else{ if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) {
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
die(); }
}
if ($humanresource) {
if($result){ $result = $humanresource->update($data);
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully updated!','code'=>200], 200); } else {
}else{ return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed updated!','code'=>400], 400); die();
} }
}
if ($result) {
public function delete($id) return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
{ } else {
$data = HumanResource::find($id); return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400);
}
if($data){ }
$delete = $data->delete();
}else{ public function delete($id)
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); {
die(); $data = HumanResource::find($id);
}
if ($data) {
$delete = $data->delete();
if($delete){ } else {
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully deleted!','code'=>200], 200); return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
}else{ die();
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed deleted!','code'=>400], 400); }
}
}
if ($delete) {
public function search(Request $request) return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully deleted!', 'code' => 200], 200);
{ } else {
$payload = $request->all(); return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed deleted!', 'code' => 400], 400);
$dataBuilder = $this->setUpPayload($payload, 'm_users'); }
$builder = $dataBuilder['builder']; }
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); public function search(Request $request)
$totalRecord = $countBuilder->count(); {
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $payload = $request->all();
} $dataBuilder = $this->setUpPayload($payload, 'm_users');
$builder = $dataBuilder['builder'];
public function list() $countBuilder = $dataBuilder['count'];
{ $dataGet = $builder->get();
$data = HumanResource::select('id', 'name')->get(); $totalRecord = $countBuilder->count();
$countData = $data->count(); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); public function list()
}else{ {
return response()->json(['status'=>'failed','message'=>'failed get list human resource, please try again later!','code'=>400], 400); $data = HumanResource::select('id', 'name', 'role_id')->get();
} $countData = $data->count();
}
if ($data) {
public function select(Request $request){ return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
$search = $request->query('search'); return response()->json(['status' => 'failed', 'message' => 'failed get list human resource, please try again later!', 'code' => 400], 400);
}
$idActivity = (int)$request->query('idact'); }
$idProyek = (int)$request->query('idProyek');
public function select(Request $request)
$forbidden = []; {
if($idActivity && $idActivity > 0){ $search = $request->query('search');
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){ $idActivity = (int)$request->query('idact');
$forbidden[] = $val->user_id; $idProyek = (int)$request->query('idProyek');
}
} $forbidden = [];
if ($search && !empty($search)) { if ($idActivity && $idActivity > 0) {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') foreach ($dataF as $val) {
->where("assign_hr_to_proyek.proyek_id", $idProyek) $forbidden[] = $val->user_id;
->where(function ($query) { }
$query->where("assign_hr_to_proyek.is_customer", "!=", true) }
->orWhereNull("assign_hr_to_proyek.is_customer");
}) if ($search && !empty($search)) {
->where("m_users.name", 'like', '%' . $search . '%') $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
->whereNotIn("m_users.id", $forbidden)->get(); ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
} else { ->where("assign_hr_to_proyek.proyek_id", $idProyek)
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") ->where(function ($query) {
->where("assign_hr_to_proyek.proyek_id", $idProyek) $query->where("assign_hr_to_proyek.is_customer", "!=", true)
->where(function ($query) { ->orWhereNull("assign_hr_to_proyek.is_customer");
$query->where("assign_hr_to_proyek.is_customer", "!=", true) })
->orWhereNull("assign_hr_to_proyek.is_customer"); ->where("m_users.name", 'like', '%' . $search . '%')
}) ->whereNotIn("m_users.id", $forbidden)->get();
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') } else {
->whereNotIn("m_users.id", $forbidden) $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
->get(); ->where("assign_hr_to_proyek.proyek_id", $idProyek)
} ->where(function ($query) {
$query->where("assign_hr_to_proyek.is_customer", "!=", true)
return response()->json($data); ->orWhereNull("assign_hr_to_proyek.is_customer");
} })
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
public function checkOldPassword(Request $request, $id) ->whereNotIn("m_users.id", $forbidden)
{ ->get();
if(!$id || (int) $id < 0 || $id==""){ }
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die(); return response()->json($data);
} }
$data = $request->all(); public function checkOldPassword(Request $request, $id)
{
if(isset($request->old_password) && $request->old_password!="" ){ if (!$id || (int) $id < 0 || $id == "") {
$result = HumanResource::find($id); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data['old_password'] = md5($request->old_password); die();
if($data['old_password'] !== $result->password) { }
return response()->json(['status'=>'failed','message'=>"old password seems doesn't match in records. please try again.",'code'=>400], 400);
} $data = $request->all();
elseif($data['old_password'] === $result->password) {
return response()->json(['status'=>'success','message'=>"old password match",'data'=>$result,'code'=>200], 200); if (isset($request->old_password) && $request->old_password != "") {
} $result = HumanResource::find($id);
} $data['old_password'] = md5($request->old_password);
else { if ($data['old_password'] !== $result->password) {
return response()->json(['status'=>'failed','message'=>'old_password is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => "old password seems doesn't match in records. please try again.", 'code' => 400], 400);
} } elseif ($data['old_password'] === $result->password) {
} return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200);
}
public function sync(){ } else {
Artisan::call('sync:integration-human-resources'); return response()->json(['status' => 'failed', 'message' => 'old_password is required!', 'code' => 400], 400);
} }
} }
public function sync()
{
Artisan::call('sync:integration-human-resources');
}
}

310
app/Http/Controllers/MenuController.php

@ -1,151 +1,159 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Menu; use App\Models\Menu;
use App\Models\RoleMenu; use App\Models\RoleMenu;
class MenuController extends Controller class MenuController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'icon' => 'required', 'icon' => 'required',
'name' => 'required', 'name' => 'string|required|unique:m_menu,name',
'url' => 'required', 'url' => 'required|unique:m_menu,url',
'sequence' => 'required', 'sequence' => 'required|integer',
]); ]);
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$result = Menu::create($data); $result = Menu::create($data);
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400);
} }
} }
public function edit($id){ public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $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(); die();
} }
$result = Menu::find($id); $result = Menu::find($id);
if($result){ if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $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);
} }
$this->validate($request, [
$data = Menu::find($id); 'icon' => 'required',
'name' => 'string|required',
if($data){ 'url' => 'required',
$result = $data->update($request->all()); 'sequence' => 'required|integer',
}else{ ]);
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); $data = Menu::find($id);
die();
} $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : '';
$request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : '';
if($result){ if($data){
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); $result = $data->update($request->all());
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
} die();
} }
public function delete($id)
{ if($result){
$data = Menu::find($id); return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200);
}else{
if($data){ return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400);
$delete = $data->delete(); }
}else{ }
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die(); public function delete($id)
} {
$data = Menu::find($id);
if($delete){ if($data){
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
} die();
} }
public function search(Request $request)
{ if($delete){
$payload = $request->all(); return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200);
$dataBuilder = $this->setUpPayload($payload, 'm_menu'); }else{
$builder = $dataBuilder['builder']; return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400);
$countBuilder = $dataBuilder['count']; }
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); public function search(Request $request)
} {
$payload = $request->all();
public function listMenu($id) $dataBuilder = $this->setUpPayload($payload, 'm_menu');
{ $builder = $dataBuilder['builder'];
$dataParent = RoleMenu::select("m_menu.*") $countBuilder = $dataBuilder['count'];
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') $dataGet = $builder->get();
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') $totalRecord = $countBuilder->count();
->whereNull('m_menu.parent_id') return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
->where('m_roles.id', $id) }
->orderBy('m_menu.sequence', 'ASC')
->get(); public function listMenu($id)
{
$finalData = []; $dataParent = RoleMenu::select("m_menu.*")
foreach($dataParent as $data){ ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
$data->children = $this->getChildrenMenu($data->id, $id); ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
$finalData[] = $data; ->whereNull('m_menu.parent_id')
} ->where('m_roles.id', $id)
->orderBy('m_menu.sequence', 'ASC')
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); ->get();
}
$finalData = [];
protected function getChildrenMenu($id, $role_id) foreach($dataParent as $data){
{ $data->children = $this->getChildrenMenu($data->id, $id);
$dataChildren = RoleMenu::select("m_menu.*") $finalData[] = $data;
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') }
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id) return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200);
->where('m_menu.parent_id', $id) }
->orderBy('m_menu.sequence', 'ASC')
->get(); protected function getChildrenMenu($id, $role_id)
$children = []; {
if($dataChildren){ $dataChildren = RoleMenu::select("m_menu.*")
foreach($dataChildren as $data) ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
{ ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
$data->children = $this->getChildrenMenu($data->id, $role_id); ->where('m_roles.id', $role_id)
$children[] = $data; ->where('m_menu.parent_id', $id)
} ->orderBy('m_menu.sequence', 'ASC')
} ->get();
return $children; $children = [];
} if($dataChildren){
foreach($dataChildren as $data)
public function list() {
{ $data->children = $this->getChildrenMenu($data->id, $role_id);
$data = Menu::all(); $children[] = $data;
$countData = $data->count(); }
}
if($data){ return $children;
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }
}else{
return response()->json(['status'=>'failed','message'=>'failed get list menu, please try again later!','code'=>400], 400); public function list()
} {
} $data = Menu::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 menu, please try again later!','code'=>400], 400);
}
}
}

136
app/Http/Controllers/ProjectChecklistsController.php

@ -0,0 +1,136 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectChecklists;
class ProjectChecklistsController extends Controller
{
public function add(Request $request)
{
if ($request->status_exist==="") {
$request->merge(['status_exist' => true]);
}
$this->validate($request, [
'proyek_id' => 'required',
'item' => 'required|string',
'status_exist' => 'boolean'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectChecklists::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = ProjectChecklists::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 participants, please try again later!','code'=>400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = ProjectChecklists::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectChecklists::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectChecklists::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectChecklists::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_checklist');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = ProjectChecklists::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 project participants, please try again later!','code'=>400], 400);
}
}
}

61
app/Http/Controllers/ProjectController.php

@ -3,35 +3,38 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use DateTime; use DateTime;
use Illuminate\Http\Request; use App\Models\Link;
use App\Models\User;
use App\Models\Image;
use App\Models\Holiday;
use App\Models\Project; use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity; use App\Models\Activity;
use App\Models\UserToActivity; use App\Jobs\ProcessSCurve;
use App\Models\User; use App\Models\OfficeHours;
use App\Models\ProjectType;
use App\Models\ProjectPhase;
use App\Models\UserToProyek;
use App\Models\VersionGantt;
use Illuminate\Http\Request;
use App\Models\ProjectIssues;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectCharter; use App\Models\ProjectCharter;
use App\Models\ProjectApproval; use App\Models\ReportActivity;
use App\Models\ProjectPhase;
use App\Models\ProjectType;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\ShowHideColumn; use App\Models\ShowHideColumn;
use App\Models\VersionGantt; use App\Models\UserToActivity;
use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\ActivityDokumen; use App\Models\ActivityDokumen;
use App\Models\Holiday; use App\Models\CommentActivity;
use App\Models\ReportActivity; use App\Models\ProjectApproval;
use App\Models\OfficeHours; use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\ProjectRisks;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use App\Jobs\ProcessSCurve;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -66,11 +69,22 @@ class ProjectController extends Controller
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
} }
public function edit($id){ public function edit($id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = Project::find($id); $result = Project::query()
->from('m_proyek AS mp')
->where('mp.id', $id)
->selectRaw('kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,lokasi_kantor,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status');
if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
}
$result = $result->first();
if(!$result) if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
@ -146,6 +160,9 @@ class ProjectController extends Controller
ProjectApproval::where('proyek_id', $project_id)->delete(); ProjectApproval::where('proyek_id', $project_id)->delete();
ProjectMileStone::where('proyek_id', $project_id)->delete(); ProjectMileStone::where('proyek_id', $project_id)->delete();
ProjectParticipants::where('proyek_id', $project_id)->delete(); ProjectParticipants::where('proyek_id', $project_id)->delete();
ProjectChecklists::where('proyek_id', $project_id)->delete();
ProjectIssues::where('proyek_id', $project_id)->delete();
ProjectRisks::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id); $this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id); $this->deleteDokumenProject($project_id);
} }

136
app/Http/Controllers/ProjectIssuesController.php

@ -0,0 +1,136 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectIssues;
class ProjectIssuesController extends Controller
{
public function add(Request $request)
{
if ($request->level_issue === "") {
$request->merge(['level_issue' => 0]);
}
$this->validate($request, [
'proyek_id' => 'required',
'description' => 'required|string',
'level_issue' => 'required|integer'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectIssues::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = ProjectIssues::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 participants, please try again later!','code'=>400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = ProjectIssues::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectIssues::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectIssues::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectIssues::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_issue');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = ProjectIssues::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 project participants, please try again later!','code'=>400], 400);
}
}
}

137
app/Http/Controllers/ProjectRisksController.php

@ -0,0 +1,137 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectRisks;
class ProjectRisksController extends Controller
{
public function add(Request $request)
{
if ($request->level_risk === "") {
$request->merge(['level_risk' => 0]);
}
$this->validate($request, [
'proyek_id' => 'required',
'level_risk' => 'required|integer',
'description' => 'required|string',
'preventive_risk' => 'required|string'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectRisks::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants failed!','code'=>400], 400);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = ProjectRisks::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 participants, please try again later!','code'=>400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = ProjectRisks::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectRisks::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectRisks::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectRisks::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_risk');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = ProjectRisks::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 project participants, please try again later!','code'=>400], 400);
}
}
}

207
app/Http/Controllers/RoleController.php

@ -1,101 +1,106 @@
<?php <?php
namespace App\Http\Controllers; 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, [ $this->validate($request, [
'name' => 'required', 'name' => 'string|required|unique:m_roles,name',
'description' => '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) if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
} }
public function edit( $id){ public function edit( $id){
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Role::find($id); $result = Role::find($id);
if(!$result) if(!$result)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Role::find($id); $this->validate($request, [
'name' => 'string|required',
if(!$data) 'description' => 'required'
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); ]);
$data = Role::find($id);
$result = $data->update($request->all()); $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_roles,name']) : '';
if(!$result) if(!$data)
return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); $result = $data->update($request->all());
}
if(!$result)
public function delete($id) return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500);
{
if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); }
$data = Role::find($id); public function delete($id)
{
if(!$data) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$delete = $data->delete(); $data = Role::find($id);
if(!$delete) if(!$data)
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); $delete = $data->delete();
}
if(!$delete)
public function search(Request $request) return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500);
{
$payload = $request->all(); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
$builder = $dataBuilder['builder']; public function search(Request $request)
$countBuilder = $dataBuilder['count']; {
$dataGet = $builder->get(); $payload = $request->all();
$totalRecord = $countBuilder->count();
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
public function list() $totalRecord = $countBuilder->count();
{
$data = Role::all(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$countData = $data->count(); }
if(!$data) public function list()
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); {
$data = Role::all();
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $countData = $data->count();
}
} 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);
}
}

467
app/Http/Controllers/UserToProyekController.php

@ -1,214 +1,253 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\ReportActivity; use App\Models\ReportActivity;
use App\Models\Image; use App\Models\Image;
class UserToProyekController extends Controller class UserToProyekController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'user_id' => 'required', 'user_id' => 'required',
'proyek_id' => 'required' 'proyek_id' => 'required'
]); ]);
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$result = UserToProyek::create($data); $result = UserToProyek::create($data);
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400);
} }
} }
public function edit($id){ public function addMultiple(Request $request){
if(!$id || (int) $id < 0 || $id==""){ $user_IDs = $request->user_id;
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die(); $data = UserToProyek::where("proyek_id", $request->proyek_id);
}
if($data){
$result = UserToProyek::find($id); $data->delete();
}
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); if(is_array($user_IDs) && count($user_IDs) > 0){
}else{ $countRes = 0;
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); foreach($user_IDs as $item){
}
} $dataInsert = array(
"user_id" => $item,
public function update(Request $request, $id) "proyek_id" => $request->proyek_id,
{ "created_by" => $this->currentName,
if(!$id || (int) $id < 0 || $id==""){ 'is_customer'=>true
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); );
}
$result = UserToProyek::create($dataInsert);
$data = UserToProyek::find($id);
if($result){
if($data){ $countRes++;
$result = $data->update($request->all()); }else{
}else{ $countRes--;
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); }
die(); }
} if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{
if($result){ return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]);
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); }
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
} }
}
}
public function delete($id)
{ public function edit($id){
$data = UserToProyek::find($id); if(!$id || (int) $id < 0 || $id==""){
if($data){ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$userId = $data->user_id; die();
$proyekId = $data->proyek_id; }
$delete = $data->delete();
if($delete){ $result = UserToProyek::find($id);
$this->deleteRelative($proyekId, $userId);
} if($result){
}else{ return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); }else{
die(); return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400);
} }
}
if($delete){ public function update(Request $request, $id)
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); {
}else{ if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} }
}
$data = UserToProyek::find($id);
private function deleteRelative($proyekId, $userId)
{ if($data){
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); $result = $data->update($request->all());
foreach ($uta as $value) { }else{
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
foreach ($dataRa as $ra) { die();
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); }
foreach ($images as $image) {
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image); if($result){
} return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
} }else{
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
} }
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); }
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); public function delete($id)
} {
$data = UserToProyek::find($id);
public function search(Request $request) if($data){
{ $userId = $data->user_id;
$payload = $request->all(); $proyekId = $data->proyek_id;
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); $delete = $data->delete();
$builder = $dataBuilder['builder']; if($delete){
$countBuilder = $dataBuilder['count']; $this->deleteRelative($proyekId, $userId);
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count(); }else{
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
} die();
}
public function list()
{
$data = UserToProyek::all(); if($delete){
$countData = $data->count(); return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
if($data){ return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400);
} private function deleteRelative($proyekId, $userId)
} {
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
public function select(Request $request){ foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$search = $request->query('search'); foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
$idProyek = (int)$request->query('idProyek'); foreach ($images as $image) {
$idActivity = (int)$request->query('idact'); if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
$include = []; }
}
if($idActivity && $idActivity > 0){ Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); }
foreach($dataF as $val){ ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
$include[] = $val->user_id; }
} UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
} }
if($search && !empty($search)){ public function search(Request $request)
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') {
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); $payload = $request->all();
}else{ $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek');
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
if($data instanceof \Illuminate\Database\Eloquent\Collection){ $totalRecord = $countBuilder->count();
$pm = array( return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
"id"=>$this->currentId, }
"name"=> "Project Manager"
); public function list()
$data->push($pm); {
} $data = UserToProyek::all();
$countData = $data->count();
return response()->json($data);
} if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
private function curlReq($url, $token){ }else{
$ch = curl_init(); return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400);
$headers = [ }
'Authorization: '.$token }
];
curl_setopt($ch, CURLOPT_URL, $url); public function select(Request $request){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $search = $request->query('search');
$response = curl_exec($ch); $idProyek = (int)$request->query('idProyek');
if ($response === false) $idActivity = (int)$request->query('idact');
$response = curl_error($ch);
curl_close($ch); $include = [];
return json_decode($response); if($idActivity && $idActivity > 0){
} $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
public function getEmployeeIntegration(Request $request) { $include[] = $val->user_id;
$search = urlencode($request->name); }
if(empty($search)) }
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); if($search && !empty($search)){
$token = config('api.adw_token'); $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
$firstResponse = $this->curlReq($url, $token); ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get();
}else{
if($firstResponse->total == 0) $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); }
$data = $firstResponse->data; if($data instanceof \Illuminate\Database\Eloquent\Collection){
return response()->json([$data]); $pm = array(
$currentPage = 1; "id"=>$this->currentId,
"name"=> "Project Manager"
if($firstResponse->last_page > 0) { );
do { $data->push($pm);
$currentPage++; }
$response = $this->curlReq($url.'&page='.$currentPage, $token);
foreach($response->data as $d){ return response()->json($data);
array_push($data, $d); }
}
} while ($currentPage < $firstResponse->last_page); private function curlReq($url, $token){
} $ch = curl_init();
$headers = [
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); 'Authorization: '.$token
} ];
} curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
public function getEmployeeIntegration(Request $request) {
$search = urlencode($request->name);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH');
$token = config('api.adw_token');
$firstResponse = $this->curlReq($url, $token);
if($firstResponse->total == 0)
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404);
$data = $firstResponse->data;
return response()->json([$data]);
$currentPage = 1;
if($firstResponse->last_page > 0) {
do {
$currentPage++;
$response = $this->curlReq($url.'&page='.$currentPage, $token);
foreach($response->data as $d){
array_push($data, $d);
}
} while ($currentPage < $firstResponse->last_page);
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200);
}
}

108
app/Models/Project.php

@ -1,54 +1,54 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Project extends Model class Project extends Model
{ {
protected $table = 'm_proyek'; protected $table = 'm_proyek';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'kode_sortname', 'kode_sortname',
'jumlah_stakeholder', 'jumlah_stakeholder',
'nama', 'nama',
'mulai_proyek', 'mulai_proyek',
'akhir_proyek', 'akhir_proyek',
'area_kerja', 'area_kerja',
'lokasi_kantor', 'lokasi_kantor',
'rencana_biaya', 'rencana_biaya',
'biaya_actual', 'biaya_actual',
'company', 'company',
'pm_id', 'pm_id',
'type_proyek_id', 'type_proyek_id',
'divisi_id', 'divisi_id',
'persentase_progress', 'persentase_progress',
'keterangan', 'keterangan',
'durasi_proyek', 'durasi_proyek',
'progress_by_worklog', 'progress_by_worklog',
'status', 'status',
'currency_simbol', 'currency_symbol',
'currency_code', 'currency_code',
'currency_name', 'currency_name',
'project_objectives', 'project_objectives',
'considered_success_when', 'considered_success_when',
'potential_risk', 'potential_risk',
'testing_environment', 'testing_environment',
'currency_code', 'budget_health',
'currency_symbol', 'phase_id',
'currency_name', 'late_consequence',
'budget_health', 'assumtion',
'phase_id', 'calculation_status',
'calculation_status', 'structur_organization',
'scurve', 'scurve',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
]; ];
} }

23
app/Models/ProjectChecklists.php

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectChecklists extends Model
{
protected $table = 'project_charter_checklist';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'item',
'status_exist',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

23
app/Models/ProjectIssues.php

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectIssues extends Model
{
protected $table = 'project_charter_issue';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'description',
'level_issue',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

24
app/Models/ProjectRisks.php

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectRisks extends Model
{
protected $table = 'project_charter_risk';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'description',
'level_risk',
'preventive_risk',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

28
routes/web.php

@ -292,6 +292,33 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete');
$router->get('/rate-sallary/list', 'RateSallaryController@list'); $router->get('/rate-sallary/list', 'RateSallaryController@list');
$router->post('/project-checklists/add', 'ProjectChecklistsController@add');
$router->get('/project-checklists/edit/{id}', 'ProjectChecklistsController@edit');
$router->put('/project-checklists/update/{id}', 'ProjectChecklistsController@update');
$router->post('/project-checklists/search', 'ProjectChecklistsController@search');
$router->delete('/project-checklists/delete/{id}', 'ProjectChecklistsController@delete');
$router->delete('/project-checklists/delete-by-proyek/{id}', 'ProjectChecklistsController@deleteByProyek');
$router->get('/project-checklists/list', 'ProjectChecklistsController@list');
$router->get('/project-checklists/{where}/{val}', 'ProjectChecklistsController@customWhere');
$router->post('/project-issues/add', 'ProjectIssuesController@add');
$router->get('/project-issues/edit/{id}', 'ProjectIssuesController@edit');
$router->put('/project-issues/update/{id}', 'ProjectIssuesController@update');
$router->post('/project-issues/search', 'ProjectIssuesController@search');
$router->delete('/project-issues/delete/{id}', 'ProjectIssuesController@delete');
$router->delete('/project-issues/delete-by-proyek/{id}', 'ProjectIssuesController@deleteByProyek');
$router->get('/project-issues/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere');
$router->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
$router->put('/project-issues/update/{id}', 'ProjectRisksController@update');
$router->post('/project-risks/search', 'ProjectRisksController@search');
$router->delete('/project-risks/delete/{id}', 'ProjectRisksController@delete');
$router->delete('/project-risks/delete-by-proyek/{id}', 'ProjectRisksController@deleteByProyek');
$router->get('/project-risks/list', 'ProjectRisksController@list');
$router->get('/project-risks/{where}/{val}', 'ProjectRisksController@customWhere');
$router->post('/project-participants/add', 'ProjectParticipantsController@add'); $router->post('/project-participants/add', 'ProjectParticipantsController@add');
$router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit');
$router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update');
@ -381,6 +408,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); $router->get('/report-k3-detail/list', 'ReportK3DetailController@list');
$router->post('/user-to-proyek/add', 'UserToProyekController@add'); $router->post('/user-to-proyek/add', 'UserToProyekController@add');
$router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple');
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search'); $router->post('/user-to-proyek/search', 'UserToProyekController@search');

Loading…
Cancel
Save