Browse Source

report analysis user group update

pull/1/head
farhantock 11 months ago
parent
commit
519136114f
  1. 227
      app/Http/Controllers/UserToActivityController.php

227
app/Http/Controllers/UserToActivityController.php

@ -11,7 +11,8 @@ use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
{ {
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'user_id' => 'required' 'user_id' => 'required'
@ -20,24 +21,25 @@ class UserToActivityController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
if(!UserToActivity::create($data)) if (!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500]);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
} }
public function addMultiple(Request $request){ public function addMultiple(Request $request)
{
$users_id = $request->user_id; $users_id = $request->user_id;
$users_role = $request->role_proyek_id; $users_role = $request->role_proyek_id;
// $data = UserToActivity::where("activity_id", $request->activity_id); // $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){ // if($data){
// $data->delete(); // $data->delete();
// } // }
if(is_array($users_id) && count($users_id) > 0){ if (is_array($users_id) && count($users_id) > 0) {
$countRes = 0; $countRes = 0;
foreach($users_id as $index => $item){ foreach ($users_id as $index => $item) {
$dataInsert = array( $dataInsert = array(
"user_id" => $item, "user_id" => $item,
"activity_id" => $request->activity_id, "activity_id" => $request->activity_id,
@ -45,89 +47,91 @@ class UserToActivityController extends Controller
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"start_date" => $request->start_date, "start_date" => $request->start_date,
"end_date" => $request->end_date, "end_date" => $request->end_date,
"created_by" => $this->currentName, "created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id "version_gantt_id" => $request->version_gantt_id
); );
$result = UserToActivity::create($dataInsert); $result = UserToActivity::create($dataInsert);
if($result){ if ($result) {
$countRes++; $countRes++;
}else{ } else {
$countRes--; $countRes--;
} }
} }
if($countRes == 0) if ($countRes == 0)
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500]);
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array( $dataUpdateCost = array(
"rencana_biaya"=>$allCost, "rencana_biaya" => $allCost,
"updated_by"=> $this->currentName "updated_by" => $this->currentName
); );
$actUpdate = Activity::find($request->activity_id); $actUpdate = Activity::find($request->activity_id);
if($actUpdate){ if ($actUpdate) {
$actUpdate->update($dataUpdateCost); $actUpdate->update($dataUpdateCost);
if($actUpdate->parent_id){ if ($actUpdate->parent_id) {
$this->updatedCostPlanning($actUpdate->parent_id); $this->updatedCostPlanning($actUpdate->parent_id);
} }
} }
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
}else{ } else {
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
} }
} }
private function updatedCostPlanning($parent_id) { private function updatedCostPlanning($parent_id)
{
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id) ->where("parent_id", $parent_id)
->first(); ->first();
if($parent = Activity::find($parent_id)){ if ($parent = Activity::find($parent_id)) {
$parent->update([ $parent->update([
"rencana_biaya" => $sumBiaya->sum, "rencana_biaya" => $sumBiaya->sum,
]); ]);
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = UserToActivity::find($id); $data = UserToActivity::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data->update($request->all())); if (!$data->update($request->all()));
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} }
public function delete($id) public function delete($id)
{ {
$data = UserToActivity::find($id); $data = UserToActivity::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data user to activity gantt Project not found!', 'code' => 400], 400);
if($data->delete()){ if ($data->delete()) {
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} }
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
} }
public function edit($id){ public function edit($id)
if(!$id || (int) $id < 0 || $id==""){ {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$result = UserToActivity::find($id); $result = UserToActivity::find($id);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); 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); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function searchAnalysis(Request $request) public function searchAnalysis(Request $request)
@ -135,14 +139,21 @@ class UserToActivityController extends Controller
$dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity'); $dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual')); $builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual'));
$builder->groupBy("m_activity.id"); $builder->groupBy("m_activity.name");
$builder->groupBy("selfTable.id"); $builder->groupBy("m_activity.persentase_progress");
$builder->groupBy("selfTable.start_date"); $builder->groupBy("m_activity.actual_start");
$builder->groupBy("selfTable.end_date"); $builder->groupBy("m_activity.actual_end");
$builder->groupBy("m_users.name"); $builder->groupBy("m_activity.planned_start");
$builder->groupBy("assign_material_to_activity.id"); $builder->groupBy("m_activity.planned_end");
$builder->groupBy("m_version_gantt.name_version"); $builder->groupBy("m_activity.start_date");
$builder->groupBy("m_activity.end_date");
$builder->groupBy("m_activity.duration");
$builder->groupBy("selfTable.id");
$builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date");
$builder->groupBy("assign_material_to_activity.qty_planning");
$builder->groupBy("m_version_gantt.name_version");
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
@ -165,7 +176,7 @@ class UserToActivityController extends Controller
$status = $join_column['status']; $status = $join_column['status'];
$startDate = date("Y-m-d H:i:sO", strtotime($startDate)); $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $endDate = date("Y-m-d H:i:sO", strtotime($endDate));
$builder->where(function ($query) use ($startDate, $endDate) { $builder->where(function ($query) use ($startDate, $endDate) {
$query $query
->where('m_proyek.mulai_proyek', '>=', $startDate) ->where('m_proyek.mulai_proyek', '>=', $startDate)
->where('m_proyek.akhir_proyek', '<=', $endDate) ->where('m_proyek.akhir_proyek', '<=', $endDate)
@ -188,22 +199,33 @@ class UserToActivityController extends Controller
$dataGet = $filteredData; $dataGet = $filteredData;
} }
// $totalRecord = $countBuilder->count(); // $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>count($dataGet)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => count($dataGet)], 200);
} }
public function activityUser(Request $request){ public function activityUser(Request $request)
{
$payload = $request->all(); $payload = $request->all();
$activity = DB::table('m_activity as ma') $activity = DB::table('m_activity as ma')
->select('ahta.id', 'ma.id as activity_id', 'ma.proyek_id', 'ma.name as join_second_name', 'ma.start_date as join_second_start_date', ->select(
'ma.end_date as join_second_end_date', 'ma.persentase_progress', 'mvg.name_version', 'mp.nama as nama_proyek', 'mp.type_proyek_id') 'ahta.id',
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id') 'ma.id as activity_id',
->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id') 'ma.proyek_id',
->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id') 'ma.name as join_second_name',
->where('ahta.user_id', $payload['user_id']) 'ma.start_date as join_second_start_date',
->where('ma.start_date', '<=', $payload['end_date']) 'ma.end_date as join_second_end_date',
->where('ma.end_date', '>=', $payload['start_date']) 'ma.persentase_progress',
->where('ma.proyek_id', $payload['proyek_id']) 'mvg.name_version',
->get(); 'mp.nama as nama_proyek',
'mp.type_proyek_id'
)
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id')
->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id')
->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id')
->where('ahta.user_id', $payload['user_id'])
->where('ma.start_date', '<=', $payload['end_date'])
->where('ma.end_date', '>=', $payload['start_date'])
->where('ma.proyek_id', $payload['proyek_id'])
->get();
if ($payload['status'] != "") { if ($payload['status'] != "") {
$filteredData = []; $filteredData = [];
@ -215,7 +237,7 @@ class UserToActivityController extends Controller
} }
$activity = $filteredData; $activity = $filteredData;
} }
return response()->json(['status'=>'success','code'=>200,'data'=>$activity, 'totalRecord'=>count($activity)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $activity, 'totalRecord' => count($activity)], 200);
} }
public function list() public function list()
@ -223,46 +245,47 @@ class UserToActivityController extends Controller
$data = UserToActivity::all(); $data = UserToActivity::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); 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) public function listFiltered(Request $request)
{ {
$startDate = $request->start_date; $startDate = $request->start_date;
$endDate = $request->end_date; $endDate = $request->end_date;
$userId = $request->user_id; $userId = $request->user_id;
$proyekId = $request->proyek_id; $proyekId = $request->proyek_id;
if (isset($proyekId)) { 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') $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') ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate) ->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate) ->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId) ->where('assign_hr_to_activity.user_id', '=', $userId)
->where('assign_hr_to_activity.proyek_id', '=', $proyekId) ->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get(); ->get();
}else { } 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') $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') ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate) ->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate) ->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId) ->where('assign_hr_to_activity.user_id', '=', $userId)
->get(); ->get();
} }
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); 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){ public function datatables(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name") $data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "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_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
@ -271,8 +294,8 @@ class UserToActivityController extends Controller
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->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>'; $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; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);

Loading…
Cancel
Save