Browse Source

Merge pull request 'staging' (#190) from staging into master

Reviewed-on: ordo/adw-backend#190
pull/3/head
ibnu 1 year ago
parent
commit
d76dc2e8d8
  1. 1962
      app/Helpers/MasterFunctionsHelper.php
  2. 1826
      app/Http/Controllers/ActivityController.php
  3. 436
      app/Http/Controllers/AssignMaterialController.php
  4. 348
      app/Http/Controllers/BroadcastController.php
  5. 4
      app/Http/Controllers/DashboardBoDController.php
  6. 212
      app/Http/Controllers/DivisiController.php
  7. 7
      app/Http/Controllers/HumanResourceController.php
  8. 310
      app/Http/Controllers/MenuController.php
  9. 1238
      app/Http/Controllers/PresenceController.php
  10. 136
      app/Http/Controllers/ProjectChecklistsController.php
  11. 152
      app/Http/Controllers/ProjectController.php
  12. 136
      app/Http/Controllers/ProjectIssuesController.php
  13. 137
      app/Http/Controllers/ProjectRisksController.php
  14. 18
      app/Http/Controllers/ReportActivityMaterialController.php
  15. 207
      app/Http/Controllers/RoleController.php
  16. 204
      app/Http/Controllers/RoleMenuController.php
  17. 419
      app/Http/Controllers/UserToActivityController.php
  18. 467
      app/Http/Controllers/UserToProyekController.php
  19. 492
      app/Models/Activity.php
  20. 92
      app/Models/AssignMaterial.php
  21. 108
      app/Models/Project.php
  22. 23
      app/Models/ProjectChecklists.php
  23. 23
      app/Models/ProjectIssues.php
  24. 24
      app/Models/ProjectRisks.php
  25. 146
      app/Models/ReportActivityMaterial.php
  26. 30
      routes/web.php

1962
app/Helpers/MasterFunctionsHelper.php

File diff suppressed because it is too large Load Diff

1826
app/Http/Controllers/ActivityController.php

File diff suppressed because it is too large Load Diff

436
app/Http/Controllers/AssignMaterialController.php

@ -1,215 +1,221 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\AssignMaterial;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use Datatables;
class AssignMaterialController extends Controller
{
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'material_id' => 'required',
'qty_planning' => 'required'
]);
$activity = Activity::where('id', $request->activity_id)->first();
$checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty;
if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
}
$start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date)));
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['budget'] = $checkStock->price;
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']);
if ($planDate >= $startDate) {
$result = AssignMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400);
}
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = AssignMaterial::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
if($result)
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
}
public function delete($id)
{
$data = AssignMaterial::where('id', $id)->first();
if($data->delete())
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = AssignMaterial::find($id);
if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = AssignMaterial::all();
$countData = $data->count();
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500);
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$type = $request->query('type') ?? "material";
$data = AssignMaterial::select(
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)
->where('assign_material_to_activity.type', $type)
->orderBy('plan_date', 'desc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function datatablesForReportActivity(Request $request){
$id_activity = $request->query('idact');
$data =
AssignMaterial::select(
AssignMaterial::raw('SUM(qty_planning) as qty_planning'),
"m.description as material_name",
"assign_material_to_activity.activity_id",
"assign_material_to_activity.type"
// "assign_material_to_activity.material_id",
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description")
->groupBy("assign_material_to_activity.activity_id")
->groupBy("assign_material_to_activity.type")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('qty_sum', function($row){
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
->groupBy("m.description")
->where("m.description", strval($row->material_name))
->where("ram.activity_id", $row->activity_id)->first();
return $val_qty_act ? $val_qty_act->qty_sum : '-';
})
->addColumn('status_activity', function($row){
$val_status = AssignMaterial::select("status_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_status ? $val_status->status_activity : null;
})
->addColumn('start_activity', function($row){
$val_start = AssignMaterial::select("start_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_start ? $val_start->start_activity : null;
})
->addColumn('finish_activity', function($row){
$val_finish = AssignMaterial::select("finish_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_finish ? $val_finish->finish_activity : null;
})
->addColumn('uom', function($row){
$val_uom = RequestMaterial::select("uom")
->where('description', '=', $row->material_name)->first();
return $val_uom ? $val_uom->uom : null;
})
->addColumn('assign_material_id', function($row){
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
return $assignMaterial ? $assignMaterial->id : null;
})
->addColumn('action', function($row){
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function ForReportActivityByMaterial(Request $request){
$id_activity = $request->idact;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)->get();
foreach ($data as $key) {
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
}
$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 Assign material, please try again later!','code'=>400], 400);
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\AssignMaterial;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use Datatables;
class AssignMaterialController extends Controller
{
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'material_id' => 'required',
'qty_planning' => 'required'
]);
$activity = Activity::where('id', $request->activity_id)->first();
$checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty;
if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
}
$start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date)));
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['budget'] = $checkStock->price;
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']);
if ($planDate >= $startDate) {
$result = AssignMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400);
}
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = AssignMaterial::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
if($result)
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
}
public function delete($id)
{
$data = AssignMaterial::where('id', $id)->first();
$reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get();
if (isset($reports)) {
foreach ($reports as $report) {
$report->delete();
}
}
if($data->delete())
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = AssignMaterial::find($id);
if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = AssignMaterial::all();
$countData = $data->count();
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500);
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$type = $request->query('type') ?? "material";
$data = AssignMaterial::select(
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)
->where('assign_material_to_activity.type', $type)
->orderBy('plan_date', 'desc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function datatablesForReportActivity(Request $request){
$id_activity = $request->query('idact');
$data =
AssignMaterial::select(
AssignMaterial::raw('SUM(qty_planning) as qty_planning'),
"m.description as material_name",
"assign_material_to_activity.activity_id",
"assign_material_to_activity.type"
// "assign_material_to_activity.material_id",
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description")
->groupBy("assign_material_to_activity.activity_id")
->groupBy("assign_material_to_activity.type")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('qty_sum', function($row){
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
->groupBy("m.description")
->where("m.description", strval($row->material_name))
->where("ram.activity_id", $row->activity_id)->first();
return $val_qty_act ? $val_qty_act->qty_sum : '-';
})
->addColumn('status_activity', function($row){
$val_status = AssignMaterial::select("status_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_status ? $val_status->status_activity : null;
})
->addColumn('start_activity', function($row){
$val_start = AssignMaterial::select("start_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_start ? $val_start->start_activity : null;
})
->addColumn('finish_activity', function($row){
$val_finish = AssignMaterial::select("finish_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_finish ? $val_finish->finish_activity : null;
})
->addColumn('uom', function($row){
$val_uom = RequestMaterial::select("uom")
->where('description', '=', $row->material_name)->first();
return $val_uom ? $val_uom->uom : null;
})
->addColumn('assign_material_id', function($row){
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
return $assignMaterial ? $assignMaterial->id : null;
})
->addColumn('action', function($row){
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function ForReportActivityByMaterial(Request $request){
$id_activity = $request->idact;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)->get();
foreach ($data as $key) {
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
}
$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 Assign material, please try again later!','code'=>400], 400);
}
}
}

348
app/Http/Controllers/BroadcastController.php

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

4
app/Http/Controllers/DashboardBoDController.php

@ -271,7 +271,7 @@ class DashboardBoDController extends Controller
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name')
$divisions = Divisi::select('id', 'name','parent')
->with('children')
->whereNull('parent')
->get();
@ -358,4 +358,4 @@ class DashboardBoDController extends Controller
'total_manpowers' => User::count()
], 200);
}
}
}

212
app/Http/Controllers/DivisiController.php

@ -1,99 +1,113 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
class DivisiController extends Controller
{
private function getAllChildren($divisi, $depth = 0, $array = []) {
$divisi->depth = $depth;
array_push($array, $divisi);
foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array);
}
return $array;
}
public function add(Request $request){
$this->validate($request, [
'name' => 'required',
'description' => 'string',
'parent' => 'integer'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]);
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
}
public function search()
{
return $this->list();
// cant use builder for this case
}
public function list()
{
$parentMenus = Divisi::whereNull('parent')->with('children')->get();
$divisions = [];
foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu);
foreach($childs as $d){
$d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){
$d->displayName = '--' . $d->displayName ;
}
array_push($divisions, $d);
}
}
$countData = count($divisions);
if($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
class DivisiController extends Controller
{
private function getAllChildren($divisi, $depth = 0, $array = []) {
$divisi->depth = $depth;
array_push($array, $divisi);
foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array);
}
return $array;
}
public function add(Request $request){
$this->validate($request, [
'name' => 'string|required|unique:m_divisi,name',
'description' => 'nullable|string',
'parent' => 'nullable|integer'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]);
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
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);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : '';
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
//return $this->list();
// cant use builder for this case
}
public function list()
{
$parentMenus = Divisi::with('children')->whereNull('parent')->get();
$divisions = [];
foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu);
foreach($childs as $d){
$d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){
$d->displayName = '--' . $d->displayName ;
}
array_push($divisions, $d);
}
}
$countData = count($divisions);
if($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200);
}
}

7
app/Http/Controllers/HumanResourceController.php

@ -15,7 +15,7 @@ class HumanResourceController extends Controller
$this->validate($request, [
'role_id' => 'required',
'name' => 'required',
'ktp_number' => 'required',
'ktp_number' => 'required|numeric|unique:m_users,ktp_number',
'employee_type' => 'required'
]);
@ -56,9 +56,12 @@ class HumanResourceController extends Controller
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$humanresource = HumanResource::find($id);
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : '';
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$data = $request->all();
if (isset($request->password) && $request->password != "") {

310
app/Http/Controllers/MenuController.php

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

1238
app/Http/Controllers/PresenceController.php

File diff suppressed because it is too large Load Diff

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);
}
}
}

152
app/Http/Controllers/ProjectController.php

@ -2,35 +2,39 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Image;
use App\Models\Holiday;
use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity;
use App\Models\UserToActivity;
use App\Models\User;
use App\Jobs\ProcessSCurve;
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\DokumenProject;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectCharter;
use App\Models\ProjectApproval;
use App\Models\ProjectPhase;
use App\Models\ProjectType;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\ReportActivity;
use App\Models\ShowHideColumn;
use App\Models\VersionGantt;
use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\Holiday;
use App\Models\ReportActivity;
use App\Models\OfficeHours;
use App\Models\CommentActivity;
use App\Models\ProjectApproval;
use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists;
use Illuminate\Support\Facades\DB;
use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ProjectRisks;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use App\Jobs\ProcessSCurve;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -65,11 +69,22 @@ class ProjectController extends Controller
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
public function edit($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function edit($id)
{
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)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
@ -145,6 +160,9 @@ class ProjectController extends Controller
ProjectApproval::where('proyek_id', $project_id)->delete();
ProjectMileStone::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->deleteDokumenProject($project_id);
}
@ -349,7 +367,16 @@ class ProjectController extends Controller
}
public static function setSyncDate($activity_id, $activity, $report) {
$status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first();
$status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) {
$reports = array(
'activity_id' => $activity_id,
'min_date' => new DateTime($activity->start_date),
'max_date' => new DateTime($activity->end_date),
'status' => 'open'
);
return $reports;
}
if (!isset($status->status_activity)) {
$status->status_activity = 'open';
}
@ -389,7 +416,6 @@ class ProjectController extends Controller
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
}
$activity->reports = $reports;
}
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
@ -412,6 +438,18 @@ class ProjectController extends Controller
$activity->save();
}
foreach($activities as $activity) {
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
@ -459,7 +497,7 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail($id){
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -467,37 +505,49 @@ class ProjectController extends Controller
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
} else {
$ganttId = $gantt_id;
}
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
// dd($result->header->start_date);
$ganttId = $gantt['last_gantt_id'];
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists();
if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('proyek_id', $id)->whereNotNull('actual_end')->exists();
$query = Activity::where('proyek_id', $id);
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if ($actualStartExist) {
$startDate = Activity::where('version_gantt_id', $ganttId)
->orderBy('actual_start')
->value('start_date');
} else {
$startDate = Activity::where('version_gantt_id', $ganttId)
->orderBy('start_date')
->value('start_date');
}
if ($actualEndExist) {
$endDate = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('actual_end')
->value('end_date');
} else {
$endDate = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('end_date')
->value('end_date');
}
if ($actualEndExist) {
$endDate = $query->orderByDesc('actual_end')->value('end_date');
} else {
$endDate = $query->orderByDesc('end_date')->value('end_date');
}
$plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200);
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200);
}
public function getOverdueActivities(Request $request){

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);
}
}
}

18
app/Http/Controllers/ReportActivityMaterialController.php

@ -59,6 +59,14 @@ class ReportActivityMaterialController extends Controller
"updated_by" => $this->currentName
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
} else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array(
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
}
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
@ -114,12 +122,14 @@ class ReportActivityMaterialController extends Controller
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource")
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity")
->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id")
->join("m_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
@ -131,7 +141,9 @@ class ReportActivityMaterialController extends Controller
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn;
})
->rawColumns(['action'])->make(true);

207
app/Http/Controllers/RoleController.php

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

204
app/Http/Controllers/RoleMenuController.php

@ -1,102 +1,102 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\RoleMenu;
class RoleMenuController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'menu_id' => 'required',
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = RoleMenu::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','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 = RoleMenu::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = RoleMenu::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
}
}
public function deleteByRole($id)
{
$data = RoleMenu::where("role_id", $id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 't_roles_menu');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\RoleMenu;
class RoleMenuController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'menu_id' => 'required',
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = RoleMenu::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','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 = RoleMenu::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = RoleMenu::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
}
}
public function deleteByRole($id)
{
$data = RoleMenu::where("role_id", $id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 't_roles_menu');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}

419
app/Http/Controllers/UserToActivityController.php

@ -1,199 +1,220 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToActivity;
use App\Models\Activity;
use Datatables;
class UserToActivityController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
if(!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
}
public function addMultiple(Request $request){
$users_id = $request->user_id;
$users_role = $request->role_proyek_id;
// $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){
// $data->delete();
// }
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0;
foreach($users_id as $index => $item){
$dataInsert = array(
"user_id" => $item,
"activity_id" => $request->activity_id,
"role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id
);
$result = UserToActivity::create($dataInsert);
if($result){
$countRes++;
}else{
$countRes--;
}
}
if($countRes == 0)
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]);
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array(
"rencana_biaya"=>$allCost,
"updated_by"=> $this->currentName
);
$actUpdate = Activity::find($request->activity_id);
if($actUpdate){
$actUpdate->update($dataUpdateCost);
if($actUpdate->parent_id){
$this->updatedCostPlanning($actUpdate->parent_id);
}
}
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}
}
private function updatedCostPlanning($parent_id) {
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id)
->first();
if($parent = Activity::find($parent_id)){
$parent->update([
"rencana_biaya" => $sumBiaya->sum,
]);
}
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = UserToActivity::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(!$data->update($request->all()));
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
}
public function delete($id)
{
$data = UserToActivity::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
if($data->delete()){
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = UserToActivity::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = UserToActivity::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 user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function listFiltered(Request $request)
{
$startDate = $request->start_date;
$endDate = $request->end_date;
$userId = $request->user_id;
$proyekId = $request->proyek_id;
if (isset($proyekId)) {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId)
->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get();
}else {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId)
->get();
}
$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 user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToActivity;
use App\Models\Activity;
use Datatables;
class UserToActivityController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
if(!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
}
public function addMultiple(Request $request){
$users_id = $request->user_id;
$users_role = $request->role_proyek_id;
// $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){
// $data->delete();
// }
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0;
foreach($users_id as $index => $item){
$dataInsert = array(
"user_id" => $item,
"activity_id" => $request->activity_id,
"role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id
);
$result = UserToActivity::create($dataInsert);
if($result){
$countRes++;
}else{
$countRes--;
}
}
if($countRes == 0)
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]);
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array(
"rencana_biaya"=>$allCost,
"updated_by"=> $this->currentName
);
$actUpdate = Activity::find($request->activity_id);
if($actUpdate){
$actUpdate->update($dataUpdateCost);
if($actUpdate->parent_id){
$this->updatedCostPlanning($actUpdate->parent_id);
}
}
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}
}
private function updatedCostPlanning($parent_id) {
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id)
->first();
if($parent = Activity::find($parent_id)){
$parent->update([
"rencana_biaya" => $sumBiaya->sum,
]);
}
}
public function update(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = UserToActivity::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(!$data->update($request->all()));
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
}
public function delete($id)
{
$data = UserToActivity::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
if($data->delete()){
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = UserToActivity::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function search(Request $request)
{
$payload = $request->all();
if (isset($payload['join_column'])) {
$join_column = $payload['join_column'];
unset($payload['join_column']);
}
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
if (isset($join_column)) {
$startDate = $join_column['start_date'];
$endDate = $join_column['end_date'];
$startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate));
$builder->where(function ($query) use ($startDate, $endDate) {
$query
->where('m_proyek.mulai_proyek', '>=', $startDate)
->where('m_proyek.akhir_proyek', '<=', $endDate)
->where(function ($query) use ($endDate, $startDate) {
$query
->where('m_activity.start_date', '>=', $startDate)
->where('m_activity.end_date', '<=', $endDate);
});
});
}
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = UserToActivity::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 user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function listFiltered(Request $request)
{
$startDate = $request->start_date;
$endDate = $request->end_date;
$userId = $request->user_id;
$proyekId = $request->proyek_id;
if (isset($proyekId)) {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId)
->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get();
}else {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId)
->get();
}
$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 user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}

467
app/Http/Controllers/UserToProyekController.php

@ -1,214 +1,253 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Image;
class UserToProyekController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToProyek::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek 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 = UserToProyek::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, 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 = UserToProyek::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = UserToProyek::find($id);
if($data){
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($proyekId, $userId);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
}
}
private function deleteRelative($proyekId, $userId)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
foreach ($dataRa as $ra) {
$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);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
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 search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = UserToProyek::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 assign hr to proyek, please try again later!','code'=>400], 400);
}
}
public function select(Request $request){
$search = $request->query('search');
$idProyek = (int)$request->query('idProyek');
$idActivity = (int)$request->query('idact');
$include = [];
if($idActivity && $idActivity > 0){
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
$include[] = $val->user_id;
}
}
if($search && !empty($search)){
$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();
}else{
$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();
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
$pm = array(
"id"=>$this->currentId,
"name"=> "Project Manager"
);
$data->push($pm);
}
return response()->json($data);
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'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);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Image;
class UserToProyekController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToProyek::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400);
}
}
public function addMultiple(Request $request){
$user_IDs = $request->user_id;
$data = UserToProyek::where("proyek_id", $request->proyek_id);
if($data){
$data->delete();
}
if(is_array($user_IDs) && count($user_IDs) > 0){
$countRes = 0;
foreach($user_IDs as $item){
$dataInsert = array(
"user_id" => $item,
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
'is_customer'=>true
);
$result = UserToProyek::create($dataInsert);
if($result){
$countRes++;
}else{
$countRes--;
}
}
if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]);
}
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = UserToProyek::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, 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 = UserToProyek::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = UserToProyek::find($id);
if($data){
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($proyekId, $userId);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
}
}
private function deleteRelative($proyekId, $userId)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
foreach ($dataRa as $ra) {
$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);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
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 search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = UserToProyek::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 assign hr to proyek, please try again later!','code'=>400], 400);
}
}
public function select(Request $request){
$search = $request->query('search');
$idProyek = (int)$request->query('idProyek');
$idActivity = (int)$request->query('idact');
$include = [];
if($idActivity && $idActivity > 0){
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
$include[] = $val->user_id;
}
}
if($search && !empty($search)){
$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();
}else{
$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();
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
$pm = array(
"id"=>$this->currentId,
"name"=> "Project Manager"
);
$data->push($pm);
}
return response()->json($data);
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'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);
}
}

492
app/Models/Activity.php

@ -1,246 +1,246 @@
<?php
namespace App\Models;
use App\Models\AssignMaterial;
use App\Models\ActivityProgressLog;
use App\Models\AssignTools;
use App\Models\ReportActivityMaterial;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class Activity extends Model
{
protected $table = 'm_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
// persentase bobot gak kepake yg dipakenya bobot_planning
protected $fillable = [
'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date',
'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress',
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan',
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end',
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
];
protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
];
public function getStartDateAttribute($value)
{
if ($value instanceof \DateTime) {
return Carbon::instance($value)
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public function getEndDateAttribute($value)
{
if ($value instanceof \DateTime) {
return Carbon::instance($value)
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public static function boot() {
parent::boot();
static::updating(function($data) {
$data->logPersentaseProgress();
});
static::updated(function($data) {
$data->updateBobot();
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
});
static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
$data->updateBobot(true);
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});
}
private function updateBobot($isDelete = false)
{
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->whereNull('parent_id')
->first();
if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id)
continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly();
}
} else {
if($parent = Activity::find($this->parent_id)){
$totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning');
$parent->update([
"bobot_planning" => $totalChildWeight
]);
}
}
}
private function updateCostActual()
{
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual");
$this->biaya_actual = $actualCost;
if($parent = Activity::find($this->parent_id)){
$parent->update([
"biaya_actual" => $actualCost
]);
}
}
private function updatePersentaseProgress()
{
if($parent = Activity::find($this->parent_id)){
$parentActWeight = $parent->bobot_planning;
if ($parentActWeight == 0) {
$parent->update([
"persentase_progress" => 0
]);
return;
}
$totalChildProportionalProgress = 0;
$childs = Activity::where("parent_id", $parent->id)->get();
foreach($childs as $child){
$currentActWeight = $child->bobot_planning;
$currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress;
$totalChildProportionalProgress += $currentActProportionalProgress;
}
$parent->update([
"persentase_progress" => $totalChildProportionalProgress
]);
}
}
private function updateCostPlanning() {
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("parent_id", $this->parent_id)
->first();
$this->rencana_biaya = $sumBiaya->sum;
if($parent = Activity::find($this->parent_id)){
$parent->update([
"rencana_biaya" => $sumBiaya->sum,
]);
}
}
private function logPersentaseProgress()
{
ActivityProgressLog::create([
'version_gantt_id' => $this->version_gantt_id,
'activity_id' => request()->id,
'old_percentage' => $this->persentase_progress,
'new_percentage' => request()->persentase_progress,
'variance' => $this->persentase_progress - request()->persentase_progress,
'created_by'=> "system"
]);
}
private function updateStartEndDateHeader()
{
$earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first();
$latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first();
if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) {
$header->start_date = $earliestStartDate;
$header->end_date = $latestEndDate;
$header->saveQuietly();
}
}
public function getJobsDoneAttribute()
{
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0;
if($dataPlan->isEmpty())
return 0;
if($dataPlan[0]->status_activity == 'done')
return 100;
return $this->persentase_progress;
}
public function getAssignHrAttribute()
{
return Arr::flatten(UserToActivity::select("u.name as name")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $this->id)
->get()
->toArray());
}
public function getAssignMaterialAttribute()
{
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "material")
->get()
->toArray());
}
public function getAssignExpenseAttribute()
{
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "expense")
->get()
->toArray());
}
public function getAssignToolsAttribute()
{
return Arr::flatten(AssignTools::select("m.name as name")
->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")
->where('assign_tools_to_activity.activity_id', $this->id)
->get()
->toArray());
}
}
<?php
namespace App\Models;
use App\Models\AssignMaterial;
use App\Models\ActivityProgressLog;
use App\Models\AssignTools;
use App\Models\ReportActivityMaterial;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class Activity extends Model
{
protected $table = 'm_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
// persentase bobot gak kepake yg dipakenya bobot_planning
protected $fillable = [
'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date',
'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress',
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan',
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end',
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
];
protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
];
public function getStartDateAttribute($value)
{
if ($value instanceof \DateTime) {
return Carbon::instance($value)
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public function getEndDateAttribute($value)
{
if ($value instanceof \DateTime) {
return Carbon::instance($value)
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public static function boot() {
parent::boot();
static::updating(function($data) {
$data->logPersentaseProgress();
});
static::updated(function($data) {
$data->updateBobot();
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
});
static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
$data->updateBobot(true);
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});
}
private function updateBobot($isDelete = false)
{
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->whereNull('parent_id')
->first();
if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id)
continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly();
}
} else {
if($parent = Activity::find($this->parent_id)){
$totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning');
$parent->update([
"bobot_planning" => $totalChildWeight
]);
}
}
}
private function updateCostActual()
{
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual");
$this->biaya_actual = $actualCost;
if($parent = Activity::find($this->parent_id)){
$parent->update([
"biaya_actual" => $actualCost
]);
}
}
private function updatePersentaseProgress()
{
if($parent = Activity::find($this->parent_id)){
$parentActWeight = $parent->bobot_planning;
if ($parentActWeight == 0) {
$parent->update([
"persentase_progress" => 0
]);
return;
}
$totalChildProportionalProgress = 0;
$childs = Activity::where("parent_id", $parent->id)->get();
foreach($childs as $child){
$currentActWeight = $child->bobot_planning;
$currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress;
$totalChildProportionalProgress += $currentActProportionalProgress;
}
$parent->update([
"persentase_progress" => $totalChildProportionalProgress
]);
}
}
private function updateCostPlanning() {
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("parent_id", $this->parent_id)
->first();
$this->rencana_biaya = $sumBiaya->sum;
if($parent = Activity::find($this->parent_id)){
$parent->update([
"rencana_biaya" => $sumBiaya->sum,
]);
}
}
private function logPersentaseProgress()
{
ActivityProgressLog::create([
'version_gantt_id' => $this->version_gantt_id,
'activity_id' => request()->id,
'old_percentage' => $this->persentase_progress,
'new_percentage' => request()->persentase_progress,
'variance' => $this->persentase_progress - request()->persentase_progress,
'created_by'=> "system"
]);
}
private function updateStartEndDateHeader()
{
$earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first();
$latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first();
if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) {
$header->start_date = $earliestStartDate;
$header->end_date = $latestEndDate;
$header->saveQuietly();
}
}
public function getJobsDoneAttribute()
{
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0;
if($dataPlan->isEmpty())
return 0;
if($dataPlan[0]->status_activity == 'done')
return 100;
return $this->persentase_progress;
}
public function getAssignHrAttribute()
{
return Arr::flatten(UserToActivity::select("u.name as name")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $this->id)
->get()
->toArray());
}
public function getAssignMaterialAttribute()
{
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "material")
->get()
->toArray());
}
public function getAssignExpenseAttribute()
{
return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "expense")
->get()
->toArray());
}
public function getAssignToolsAttribute()
{
return Arr::flatten(AssignTools::select("m.name as name")
->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")
->where('assign_tools_to_activity.activity_id', $this->id)
->get()
->toArray());
}
}

92
app/Models/AssignMaterial.php

@ -1,46 +1,46 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model
{
protected $table = 'assign_material_to_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning',
'budget', 'plan_date', 'status_activity', 'type',
'created_at', 'created_by', 'updated_at', 'updated_by'
];
protected $casts = [
'id' => 'integer',
'budget' => 'string',
];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first();
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity->save();
});
static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();
});
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model
{
protected $table = 'assign_material_to_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning',
'budget', 'plan_date', 'status_activity', 'type',
'created_at', 'created_by', 'updated_at', 'updated_by'
];
protected $casts = [
'id' => 'integer',
'budget' => 'string',
];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first();
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity->save();
});
static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();
});
}
}

108
app/Models/Project.php

@ -1,54 +1,54 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'm_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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',
'status',
'currency_simbol',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'currency_code',
'currency_symbol',
'currency_name',
'budget_health',
'phase_id',
'calculation_status',
'scurve',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'm_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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',
'status',
'currency_symbol',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'budget_health',
'phase_id',
'late_consequence',
'assumtion',
'calculation_status',
'structur_organization',
'scurve',
'created_at',
'created_by',
'updated_at',
'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'
];
}

146
app/Models/ReportActivityMaterial.php

@ -1,73 +1,73 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Carbon\Carbon;
class ReportActivityMaterial extends Model
{
protected $table = 'report_activity_material';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id',
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
public function getReportDateAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
if($dataPlan[0]->status_activity == 'done'){
$percentage = 100;
} else {
$totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan;
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
}
$activity->update([
"persentase_progress" => $percentage,
"biaya_actual" => $biayaActual,
]);
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
$totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan;
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
$activity->save();
});
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Carbon\Carbon;
class ReportActivityMaterial extends Model
{
protected $table = 'report_activity_material';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id',
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
public function getReportDateAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
}
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
if($dataPlan[0]->status_activity == 'done'){
$percentage = 100;
} else {
$totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan;
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
}
$activity->update([
"persentase_progress" => $percentage,
"biaya_actual" => $biayaActual,
]);
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
$totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan;
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
$activity->save();
});
}
}

30
routes/web.php

@ -58,7 +58,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}', 'ProjectController@detail');
$router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
@ -292,6 +292,33 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete');
$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->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit');
$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->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->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search');

Loading…
Cancel
Save